7 unsigned long memsz[] = {
26 void dump(unsigned char smramc, unsigned char drp, unsigned char drp2) {
31 printf("SMRAMC: %02x\n", smramc);
33 tom += memsz[drp & 0xF];
34 tom += memsz[drp >> 4];
35 tom += memsz[drp2 & 0xF];
37 printf("Top of DRAM: %08x\n", tom);
39 usmm = (smramc >> 4) & 0x3;
40 lsmm = (smramc >> 2) & 0x3;
45 printf("TSEG and HSEG both off\n");
48 printf("TSEG off, HSEG %s\n", lsmm ? "off" : "on");
51 printf("TSEG 512KB (%08x - %08x), HSEG %s\n",
52 tom - 512 * 1024, tom - 1, lsmm ? "off" : "on");
55 printf("TSEG 1MB (%08x - %08x), HSEG %s\n",
56 tom - 1 * 1024 * 1024, tom - 1, lsmm ? "off" : "on");
63 printf("ABSEG disabled\n");
66 printf("ABSEG enabled as system RAM\n");
69 printf("ABSEG enabled for SMM code only\n");
72 printf("ABSEG enabled for both SMM code and data\n");
77 static struct option longopts[] = {
78 { "open", no_argument, NULL, 'o' },
79 { "close", no_argument, NULL, 'c' },
80 { "smram", no_argument, NULL, 's' },
81 { "dump", no_argument, NULL, 'd' },
88 void usage(int argc, char **argv)
90 printf("Usage: %s [ --dump ] [ --open | --close | --smram=value ]\n",
95 int main(int argc, char **argv)
97 unsigned char smramc, drp, drp2;
101 printf("This program must be run as root, dumbass.\n");
105 smramc = pci_read8(0, 0, 0, SMRAMC);
106 drp = pci_read8(0, 0, 0, DRP);
107 drp2 = pci_read8(0, 0, 0, DRP2);
109 if (smramc & SMRAMC_LOCK)
111 printf("SMRAM is locked, cannot load anything :-(\n");
117 int new_smramc = smramc;
119 while ((ch = getopt_long(argc, argv, "ocsd:", longopts, NULL)) != -1)
124 if (op & OP_SET) usage(argc, argv);
126 new_smramc = strtoul(optarg, 0, 0);
129 if (op & OP_SET) usage(argc, argv);
131 /* Set LSMM to 01 (ABseg = system RAM) */
132 new_smramc = (smramc & 0xF0) | 0x04;
135 if (op & OP_SET) usage(argc, argv);
137 /* Set LSMM to 11 (ABseg = SMM RAM) */
138 new_smramc = (smramc & 0xF0) | 0x0C;
148 if (!op) usage(argc, argv);
152 dump(smramc, drp, drp2);
157 pci_write8(0, 0, 0, SMRAMC, new_smramc);
160 printf("SMRAM set to 0x%02x\n", new_smramc);