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