2 * SMRAM control utility for ICH2 northbridge
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"
18 /***********************************************************************
19 * DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED
21 * This should be replaced by ../util/smram-ich2 once it's verified to work properly.
24 unsigned long memsz[] = {
43 void dump(unsigned char smramc, unsigned char drp, unsigned char drp2) {
48 printf("SMRAMC: %02x\n", smramc);
50 tom += memsz[drp & 0xF];
51 tom += memsz[drp >> 4];
52 tom += memsz[drp2 & 0xF];
54 printf("Top of DRAM: %08x\n", tom);
56 usmm = (smramc >> 4) & 0x3;
57 lsmm = (smramc >> 2) & 0x3;
62 printf("TSEG and HSEG both off\n");
65 printf("TSEG off, HSEG %s\n", lsmm ? "off" : "on");
68 printf("TSEG 512KB (%08x - %08x), HSEG %s\n",
69 tom - 512 * 1024, tom - 1, lsmm ? "off" : "on");
72 printf("TSEG 1MB (%08x - %08x), HSEG %s\n",
73 tom - 1 * 1024 * 1024, tom - 1, lsmm ? "off" : "on");
80 printf("ABSEG disabled\n");
83 printf("ABSEG enabled as system RAM\n");
86 printf("ABSEG enabled for SMM code only\n");
89 printf("ABSEG enabled for both SMM code and data\n");
94 static struct option longopts[] = {
95 { "open", no_argument, NULL, 'o' },
96 { "close", no_argument, NULL, 'c' },
97 { "smram", no_argument, NULL, 's' },
98 { "dump", no_argument, NULL, 'd' },
105 void usage(int argc, char **argv)
107 printf("Usage: %s [ --dump ] [ --open | --close | --smram=value ]\n",
112 int main(int argc, char **argv)
114 unsigned char smramc, drp, drp2;
118 printf("This program must be run as root, dumbass.\n");
122 smramc = pci_read8(0, 0, 0, SMRAMC);
123 drp = pci_read8(0, 0, 0, DRP);
124 drp2 = pci_read8(0, 0, 0, DRP2);
126 if (smramc & SMRAMC_LOCK)
128 printf("SMRAM is locked, cannot load anything :-(\n");
134 int new_smramc = smramc;
136 while ((ch = getopt_long(argc, argv, "ocsd:", longopts, NULL)) != -1)
141 if (op & OP_SET) usage(argc, argv);
143 new_smramc = strtoul(optarg, 0, 0);
146 if (op & OP_SET) usage(argc, argv);
148 /* Set LSMM to 01 (ABseg = system RAM) */
149 new_smramc = (smramc & 0xF0) | 0x04;
152 if (op & OP_SET) usage(argc, argv);
154 /* Set LSMM to 11 (ABseg = SMM RAM) */
155 new_smramc = (smramc & 0xF0) | 0x0C;
165 if (!op) usage(argc, argv);
169 dump(smramc, drp, drp2);
174 pci_write8(0, 0, 0, SMRAMC, new_smramc);
177 printf("SMRAM set to 0x%02x\n", new_smramc);