]> Joshua Wise's Git repositories - netwatch.git/blob - ich2/smm-open-ich2.c
Don't necessarily wait for data.
[netwatch.git] / ich2 / smm-open-ich2.c
1 #include "reg-82815.h"
2 #include <unistd.h>
3 #include <getopt.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 /***********************************************************************
8  * DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED
9  *
10  * This should be replaced by ../util/smram-ich2 once it's verified to work properly.
11  */
12
13 unsigned long memsz[] = {
14         0,                      // 0
15         32*1024*1024,           // 1
16         32*1024*1024,           // 2
17         48*1024*1024,           // 3
18         64*1024*1024,           // 4
19         64*1024*1024,           // 5
20         96*1024*1024,           // 6
21         128*1024*1024,          // 7
22         128*1024*1024,          // 8
23         128*1024*1024,          // 9
24         128*1024*1024,          // A
25         192*1024*1024,          // B
26         256*1024*1024,          // C
27         256*1024*1024,          // D
28         256*1024*1024,          // E
29         512*1024*1024           // F
30 };
31
32 void dump(unsigned char smramc, unsigned char drp, unsigned char drp2) {
33
34         unsigned int tom = 0;
35         int usmm, lsmm;
36
37         printf("SMRAMC: %02x\n", smramc);
38
39         tom += memsz[drp & 0xF];
40         tom += memsz[drp >> 4];
41         tom += memsz[drp2 & 0xF];
42         
43         printf("Top of DRAM: %08x\n", tom);
44         
45         usmm = (smramc >> 4) & 0x3;
46         lsmm = (smramc >> 2) & 0x3;
47         
48         switch (usmm)
49         {
50         case 0:
51                 printf("TSEG and HSEG both off\n");
52                 break;
53         case 1:
54                 printf("TSEG off, HSEG %s\n", lsmm ? "off" : "on");
55                 break;
56         case 2:
57                 printf("TSEG 512KB (%08x - %08x), HSEG %s\n",
58                         tom - 512 * 1024, tom - 1, lsmm ? "off" : "on");
59                 break;
60         case 3:
61                 printf("TSEG 1MB (%08x - %08x), HSEG %s\n",
62                         tom - 1 * 1024 * 1024, tom - 1, lsmm ? "off" : "on");
63                 break;
64         }
65         
66         switch (lsmm)
67         {
68         case 0:
69                 printf("ABSEG disabled\n");
70                 break;
71         case 1:
72                 printf("ABSEG enabled as system RAM\n");
73                 break;
74         case 2:
75                 printf("ABSEG enabled for SMM code only\n");
76                 break;
77         case 3:
78                 printf("ABSEG enabled for both SMM code and data\n");
79                 break;
80         }
81 }
82
83 static struct option longopts[] = {
84         { "open",       no_argument,    NULL,   'o'     },
85         { "close",      no_argument,    NULL,   'c'     },
86         { "smram",      no_argument,    NULL,   's'     },
87         { "dump",       no_argument,    NULL,   'd'     },
88         { NULL,         0,              NULL,   0       }
89 };
90
91 #define OP_DUMP 1
92 #define OP_SET 2
93
94 void usage(int argc, char **argv)
95 {
96         printf("Usage: %s [ --dump ] [ --open | --close | --smram=value ]\n",
97                 argv[0]);
98         exit(1);
99 }
100
101 int main(int argc, char **argv)
102 {
103         unsigned char smramc, drp, drp2;
104
105         if (geteuid() != 0)
106         {
107                 printf("This program must be run as root, dumbass.\n");
108                 return 1;
109         }
110         
111         smramc = pci_read8(0, 0, 0, SMRAMC);
112         drp = pci_read8(0, 0, 0, DRP);
113         drp2 = pci_read8(0, 0, 0, DRP2);
114         
115         if (smramc & SMRAMC_LOCK)
116         {
117                 printf("SMRAM is locked, cannot load anything :-(\n");
118                 return 1;
119         }
120
121         int ch;
122         int op = 0;
123         int new_smramc = smramc;
124
125         while ((ch = getopt_long(argc, argv, "ocsd:", longopts, NULL)) != -1)
126         {
127                 switch (ch)
128                 {
129                 case 's':
130                         if (op & OP_SET) usage(argc, argv);
131                         op |= OP_SET;
132                         new_smramc = strtoul(optarg, 0, 0);
133                         break;
134                 case 'o':
135                         if (op & OP_SET) usage(argc, argv);
136                         op |= OP_SET;
137                         /* Set LSMM to 01 (ABseg = system RAM) */
138                         new_smramc = (smramc & 0xF0) | 0x04;
139                         break;
140                 case 'c':
141                         if (op & OP_SET) usage(argc, argv);
142                         op |= OP_SET;
143                         /* Set LSMM to 11 (ABseg = SMM RAM) */
144                         new_smramc = (smramc & 0xF0) | 0x0C;
145                         break;
146                 case 'd':
147                         op |= OP_DUMP;
148                         break;
149                 default:
150                         usage(argc, argv);
151                 }
152         }
153
154         if (!op) usage(argc, argv);
155
156         if (op & OP_DUMP)
157         {
158                 dump(smramc, drp, drp2);
159         }
160
161         if (op & OP_SET)
162         {
163                 pci_write8(0, 0, 0, SMRAMC, new_smramc);
164                 if (op & OP_DUMP)
165                 {
166                         printf("SMRAM set to 0x%02x\n", new_smramc);
167                 }
168         }
169         
170         return 0;
171 }
This page took 0.037772 seconds and 4 git commands to generate.