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