]> Joshua Wise's Git repositories - netwatch.git/commitdiff
smm-open-ich2 updates
authorJacob Potter <jacob@J4CBO-MBP.WV.CC.CMU.EDU>
Fri, 5 Sep 2008 20:06:26 +0000 (16:06 -0400)
committerJacob Potter <jacob@J4CBO-MBP.WV.CC.CMU.EDU>
Fri, 5 Sep 2008 20:06:26 +0000 (16:06 -0400)
ich2/smm-open-ich2.c

index 1e1f79ceab3348550b41f53a3c26d779cba4959a..e76fcfce140659e1211aed905a1318e4a660a7d9 100644 (file)
@@ -1,5 +1,8 @@
 #include "reg-82815.h"
 #include "reg-82815.h"
+#include <unistd.h>
+#include <getopt.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 unsigned long memsz[] = {
        0,                      // 0
 
 unsigned long memsz[] = {
        0,                      // 0
@@ -20,29 +23,19 @@ unsigned long memsz[] = {
        512*1024*1024           // F
 };
 
        512*1024*1024           // F
 };
 
-int main(int argc, char **argv)
-{
-       unsigned char smramc, drp, drp2;
+void dump(unsigned char smramc, unsigned char drp, unsigned char drp2) {
+
        unsigned int tom = 0;
        int usmm, lsmm;
        unsigned int tom = 0;
        int usmm, lsmm;
-       
-       smramc = pci_read8(0, 0, 0, SMRAMC);
-       drp = pci_read8(0, 0, 0, DRP);
-       drp2 = pci_read8(0, 0, 0, DRP2);
-       
+
+       printf("SMRAMC: %02x\n", smramc);
+
        tom += memsz[drp & 0xF];
        tom += memsz[drp >> 4];
        tom += memsz[drp2 & 0xF];
        
        printf("Top of DRAM: %08x\n", tom);
        
        tom += memsz[drp & 0xF];
        tom += memsz[drp >> 4];
        tom += memsz[drp2 & 0xF];
        
        printf("Top of DRAM: %08x\n", tom);
        
-       printf("SMRAMC: %02x\n", smramc);
-       if (smramc & SMRAMC_LOCK)
-       {
-               printf("SMRAM is locked, cannot load anything :-(\n");
-               return 1;
-       }
-       
        usmm = (smramc >> 4) & 0x3;
        lsmm = (smramc >> 2) & 0x3;
        
        usmm = (smramc >> 4) & 0x3;
        lsmm = (smramc >> 2) & 0x3;
        
@@ -55,10 +48,12 @@ int main(int argc, char **argv)
                printf("TSEG off, HSEG %s\n", lsmm ? "off" : "on");
                break;
        case 2:
                printf("TSEG off, HSEG %s\n", lsmm ? "off" : "on");
                break;
        case 2:
-               printf("TSEG 512KB (%08x - %08x), HSEG %s\n", tom - 512 * 1024, tom - 1, lsmm ? "off" : "on");
+               printf("TSEG 512KB (%08x - %08x), HSEG %s\n",
+                       tom - 512 * 1024, tom - 1, lsmm ? "off" : "on");
                break;
        case 3:
                break;
        case 3:
-               printf("TSEG 1MB (%08x - %08x), HSEG %s\n", tom - 1 * 1024 * 1024, tom - 1, lsmm ? "off" : "on");
+               printf("TSEG 1MB (%08x - %08x), HSEG %s\n",
+                       tom - 1 * 1024 * 1024, tom - 1, lsmm ? "off" : "on");
                break;
        }
        
                break;
        }
        
@@ -77,20 +72,93 @@ int main(int argc, char **argv)
                printf("ABSEG enabled for both SMM code and data\n");
                break;
        }
                printf("ABSEG enabled for both SMM code and data\n");
                break;
        }
+}
+
+static struct option longopts[] = {
+       { "open",       no_argument,    NULL,   'o'     },
+       { "close",      no_argument,    NULL,   'c'     },
+       { "smram",      no_argument,    NULL,   's'     },
+       { "dump",       no_argument,    NULL,   'd'     },
+       { NULL,         0,              NULL,   0       }
+};
+
+#define OP_DUMP 1
+#define OP_SET 2
+
+void usage(int argc, char **argv)
+{
+       printf("Usage: %s [ --dump ] [ --open | --close | --smram=value ]\n",
+               argv[0]);
+       exit(1);
+}
+
+int main(int argc, char **argv)
+{
+       unsigned char smramc, drp, drp2;
+
+       if (geteuid() != 0)
+       {
+               printf("This program must be run as root, dumbass.\n");
+               return 1;
+       }
        
        
+       smramc = pci_read8(0, 0, 0, SMRAMC);
+       drp = pci_read8(0, 0, 0, DRP);
+       drp2 = pci_read8(0, 0, 0, DRP2);
        
        
-       if (argc < 2)
+       if (smramc & SMRAMC_LOCK)
        {
        {
-               smramc &= 0xC0;
-               smramc |= 0x04;
-       
-               pci_write8(0, 0, 0, SMRAMC, smramc);
-               printf("With any luck, ABSEG is now enabled as system RAM... enjoy!\n");
-       } else {
-               smramc = strtoul(argv[1], 0, 0);
-               
-               pci_write8(0, 0, 0, SMRAMC, smramc);
-               printf("OK, set it up as you like.\n");
+               printf("SMRAM is locked, cannot load anything :-(\n");
+               return 1;
+       }
+
+       int ch;
+       int op = 0;
+       int new_smramc = smramc;
+
+       while ((ch = getopt_long(argc, argv, "ocsd:", longopts, NULL)) != -1)
+       {
+               switch (ch)
+               {
+               case 's':
+                       if (op & OP_SET) usage(argc, argv);
+                       op |= OP_SET;
+                       new_smramc = strtoul(optarg, 0, 0);
+                       break;
+               case 'o':
+                       if (op & OP_SET) usage(argc, argv);
+                       op |= OP_SET;
+                       /* Set LSMM to 01 (ABseg = system RAM) */
+                       new_smramc = (smramc & 0xF0) | 0x04;
+                       break;
+               case 'c':
+                       if (op & OP_SET) usage(argc, argv);
+                       op |= OP_SET;
+                       /* Set LSMM to 11 (ABseg = SMM RAM) */
+                       new_smramc = (smramc & 0xF0) | 0x0C;
+                       break;
+               case 'd':
+                       op |= OP_DUMP;
+                       break;
+               default:
+                       usage(argc, argv);
+               }
+       }
+
+       if (!op) usage(argc, argv);
+
+       if (op & OP_DUMP)
+       {
+               dump(smramc, drp, drp2);
+       }
+
+       if (op & OP_SET)
+       {
+               pci_write8(0, 0, 0, SMRAMC, new_smramc);
+               if (op & OP_DUMP)
+               {
+                       printf("SMRAM set to 0x%02x\n", new_smramc);
+               }
        }
        
        return 0;
        }
        
        return 0;
This page took 0.033262 seconds and 4 git commands to generate.