2  * SMRAM access utility for ICH2 chipset
 
   3  * NetWatch system management mode administration console
 
   5  * Copyright (c) 2008 Jacob Potter and Joshua Wise.  All rights reserved.
 
   6  * This program is free software; you can redistribute and/or modify it under
 
   7  * the terms found in the file LICENSE in the root of this source tree. 
 
  12 #include "reg-82815.h"
 
  16 static unsigned long memsz[] = {
 
  35 unsigned int smram_tseg_length(void) {
 
  39         smramc = pci_read8(0, 0, 0, SMRAMC);
 
  41         usmm = (smramc >> 4) & 0x3;
 
  57 void * smram_tseg_start(void) {
 
  58         unsigned char drp, drp2;
 
  61         drp = pci_read8(0, 0, 0, DRP);
 
  62         drp2 = pci_read8(0, 0, 0, DRP2);
 
  64         tom += memsz[drp & 0xF];
 
  65         tom += memsz[drp >> 4];
 
  66         tom += memsz[drp2 & 0xF];
 
  68         return (void *)(tom - smram_tseg_length());
 
  73 void smram_aseg_dump(void) {
 
  75         unsigned char smramc, drp, drp2;
 
  79         smramc = pci_read8(0, 0, 0, SMRAMC);
 
  80         drp = pci_read8(0, 0, 0, DRP);
 
  81         drp2 = pci_read8(0, 0, 0, DRP2);
 
  83         printf("SMRAMC: %02x\n", smramc);
 
  85         tom += memsz[drp & 0xF];
 
  86         tom += memsz[drp >> 4];
 
  87         tom += memsz[drp2 & 0xF];
 
  89         printf("Top of DRAM: %08x\n", tom);
 
  91         usmm = (smramc >> 4) & 0x3;
 
  92         lsmm = (smramc >> 2) & 0x3;
 
  97                 printf("TSEG and HSEG both off\n");
 
 100                 printf("TSEG off, HSEG %s\n", lsmm ? "off" : "on");
 
 103                 printf("TSEG 512KB (%08x - %08x), HSEG %s\n",
 
 104                         tom - 512 * 1024, tom - 1, lsmm ? "off" : "on");
 
 107                 printf("TSEG 1MB (%08x - %08x), HSEG %s\n",
 
 108                         tom - 1 * 1024 * 1024, tom - 1, lsmm ? "off" : "on");
 
 115                 printf("ABSEG disabled\n");
 
 118                 printf("ABSEG enabled as system RAM\n");
 
 121                 printf("ABSEG enabled for SMM code only\n");
 
 124                 printf("ABSEG enabled for both SMM code and data\n");
 
 132         unsigned char smramc = pci_read8(0, 0, 0, SMRAMC);
 
 134         return (smramc & SMRAMC_LOCK) ? 1 : 0;
 
 137 smram_state_t smram_save_state()
 
 139         return pci_read8(0, 0, 0, SMRAMC);
 
 142 void smram_restore_state(smram_state_t state)
 
 144         pci_write8(0, 0, 0, SMRAMC, state); 
 
 147 int smram_aseg_set_state (int open) {
 
 148         unsigned char smramc;
 
 153         smramc = pci_read8(0, 0, 0, SMRAMC);
 
 157         case SMRAM_ASEG_CLOSED:
 
 158                 smramc = (smramc & 0xF0) | 0x00;
 
 160         case SMRAM_ASEG_OPEN:
 
 161                 smramc = (smramc & 0xF0) | 0x04;
 
 163         case SMRAM_ASEG_SMMCODE:
 
 164                 smramc = (smramc & 0xF0) | 0x08;
 
 166         case SMRAM_ASEG_SMMONLY:
 
 167                 smramc = (smramc & 0xF0) | 0x0C;
 
 173         pci_write8(0, 0, 0, SMRAMC, smramc);
 
 178 int smram_tseg_set_state (int open) {
 
 179         unsigned char smramc;
 
 184         smramc = pci_read8(0, 0, 0, SMRAMC);
 
 188         case SMRAM_TSEG_OPEN:
 
 189                 smramc = (smramc & 0x8F) | 0x00;
 
 195         pci_write8(0, 0, 0, SMRAMC, smramc);