1#include <spd.h>
2
3static void print_reg(unsigned char index)
4{
5 unsigned char data;
6
7 outb(index, 0x2e);
8 data = inb(0x2f);
9 print_debug("0x");
10 print_debug_hex8(index);
11 print_debug(": 0x");
12 print_debug_hex8(data);
13 print_debug("\n");
14 return;
15}
16
17static void xbus_en(void)
18{
19
20 outb(0x07, 0x2e);
21 outb(0x0f, 0x2f);
22 outb(0x30, 0x2e);
23 outb(0x01, 0x2f);
24 return;
25}
26
27static void setup_func(unsigned char func)
28{
29
30 outb(0x07, 0x2e);
31 outb(func, 0x2f);
32
33 print_reg(0x30);
34 print_reg(0x60);
35 print_reg(0x61);
36 print_reg(0x62);
37 print_reg(0x63);
38 print_reg(0x70);
39 print_reg(0x71);
40 print_reg(0x74);
41 print_reg(0x75);
42 return;
43}
44
45static void siodump(void)
46{
47 int i;
48 unsigned char data;
49
50 print_debug("\n*** SERVER I/O REGISTERS ***\n");
51 for (i=0x10; i<=0x2d; i++) {
52 print_reg((unsigned char)i);
53 }
54#if 0
55 print_debug("\n*** XBUS REGISTERS ***\n");
56 setup_func(0x0f);
57 for (i=0xf0; i<=0xff; i++) {
58 print_reg((unsigned char)i);
59 }
60
61 print_debug("\n*** SERIAL 1 CONFIG REGISTERS ***\n");
62 setup_func(0x03);
63 print_reg(0xf0);
64
65 print_debug("\n*** SERIAL 2 CONFIG REGISTERS ***\n");
66 setup_func(0x02);
67 print_reg(0xf0);
68
69#endif
70 print_debug("\n*** GPIO REGISTERS ***\n");
71 setup_func(0x07);
72 for (i=0xf0; i<=0xf8; i++) {
73 print_reg((unsigned char)i);
74 }
75 print_debug("\n*** GPIO VALUES ***\n");
76 data = inb(0x68a);
77 print_debug("\nGPDO 4: 0x");
78 print_debug_hex8(data);
79 data = inb(0x68b);
80 print_debug("\nGPDI 4: 0x");
81 print_debug_hex8(data);
82 print_debug("\n");
83
84#if 0
85
86 print_debug("\n*** WATCHDOG TIMER REGISTERS ***\n");
87 setup_func(0x0a);
88 print_reg(0xf0);
89
90 print_debug("\n*** FAN CONTROL REGISTERS ***\n");
91 setup_func(0x09);
92 print_reg(0xf0);
93 print_reg(0xf1);
94
95 print_debug("\n*** RTC REGISTERS ***\n");
96 setup_func(0x10);
97 print_reg(0xf0);
98 print_reg(0xf1);
99 print_reg(0xf3);
100 print_reg(0xf6);
101 print_reg(0xf7);
102 print_reg(0xfe);
103 print_reg(0xff);
104
105 print_debug("\n*** HEALTH MONITORING & CONTROL REGISTERS ***\n");
106 setup_func(0x14);
107 print_reg(0xf0);
108#endif
109 return;
110}
111
112static void print_debug_pci_dev(unsigned dev)
113{
114 print_debug("PCI: ");
115 print_debug_hex8((dev >> 16) & 0xff);
116 print_debug_char(':');
117 print_debug_hex8((dev >> 11) & 0x1f);
118 print_debug_char('.');
119 print_debug_hex8((dev >> 8) & 7);
120}
121
122static void print_pci_devices(void)
123{
124 device_t dev;
125 for(dev = PCI_DEV(0, 0, 0);
126 dev <= PCI_DEV(0, 0x1f, 0x7);
127 dev += PCI_DEV(0,0,1)) {
128 uint32_t id;
129 id = pci_read_config32(dev, PCI_VENDOR_ID);
130 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
131 (((id >> 16) & 0xffff) == 0xffff) ||
132 (((id >> 16) & 0xffff) == 0x0000)) {
133 continue;
134 }
135 print_debug_pci_dev(dev);
136 print_debug("\n");
137 }
138}
139
140static void dump_pci_device(unsigned dev)
141{
142 int i;
143 print_debug_pci_dev(dev);
144 print_debug("\n");
145
146 for(i = 0; i <= 255; i++) {
147 unsigned char val;
148 if ((i & 0x0f) == 0) {
149 print_debug_hex8(i);
150 print_debug_char(':');
151 }
152 val = pci_read_config8(dev, i);
153 print_debug_char(' ');
154 print_debug_hex8(val);
155 if ((i & 0x0f) == 0x0f) {
156 print_debug("\n");
157 }
158 }
159}
160
161static void dump_bar14(unsigned dev)
162{
163 int i;
164 unsigned long bar;
165
166 print_debug("BAR 14 Dump\n");
167
168 bar = pci_read_config32(dev, 0x14);
169 for(i = 0; i <= 0x300; i+=4) {
170#if 0
171 unsigned char val;
172 if ((i & 0x0f) == 0) {
173 print_debug_hex8(i);
174 print_debug_char(':');
175 }
176 val = pci_read_config8(dev, i);
177#endif
178 if((i%4)==0) {
179 print_debug("\n");
180 print_debug_hex16(i);
181 print_debug_char(' ');
182 }
183 print_debug_hex32(read32(bar + i));
184 print_debug_char(' ');
185 }
186 print_debug("\n");
187}
188
189static void dump_pci_devices(void)
190{
191 device_t dev;
192 for(dev = PCI_DEV(0, 0, 0);
193 dev <= PCI_DEV(0, 0x1f, 0x7);
194 dev += PCI_DEV(0,0,1)) {
195 uint32_t id;
196 id = pci_read_config32(dev, PCI_VENDOR_ID);
197 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
198 (((id >> 16) & 0xffff) == 0xffff) ||
199 (((id >> 16) & 0xffff) == 0x0000)) {
200 continue;
201 }
202 dump_pci_device(dev);
203 }
204}
205
206#if 0
207static void dump_spd_registers(const struct mem_controller *ctrl)
208{
209 int i;
210 print_debug("\n");
211 for(i = 0; i < 4; i++) {
212 unsigned device;
213 device = ctrl->channel0[i];
214 if (device) {
215 int j;
216 print_debug("dimm: ");
217 print_debug_hex8(i);
218 print_debug(".0: ");
219 print_debug_hex8(device);
220 for(j = 0; j < 256; j++) {
221 int status;
222 unsigned char byte;
223 if ((j & 0xf) == 0) {
224 print_debug("\n");
225 print_debug_hex8(j);
226 print_debug(": ");
227 }
228 status = smbus_read_byte(device, j);
229 if (status < 0) {
230 print_debug("bad device\n");
231 break;
232 }
233 byte = status & 0xff;
234 print_debug_hex8(byte);
235 print_debug_char(' ');
236 }
237 print_debug("\n");
238 }
239 device = ctrl->channel1[i];
240 if (device) {
241 int j;
242 print_debug("dimm: ");
243 print_debug_hex8(i);
244 print_debug(".1: ");
245 print_debug_hex8(device);
246 for(j = 0; j < 256; j++) {
247 int status;
248 unsigned char byte;
249 if ((j & 0xf) == 0) {
250 print_debug("\n");
251 print_debug_hex8(j);
252 print_debug(": ");
253 }
254 status = smbus_read_byte(device, j);
255 if (status < 0) {
256 print_debug("bad device\n");
257 break;
258 }
259 byte = status & 0xff;
260 print_debug_hex8(byte);
261 print_debug_char(' ');
262 }
263 print_debug("\n");
264 }
265 }
266}
267#endif
268
269void dump_spd_registers(void)
270{
271 unsigned device;
272 device = DIMM0;
273 while(device <= DIMM7) {
274 int status = 0;
275 int i;
276 print_debug("\n");
277 print_debug("dimm ");
278 print_debug_hex8(device);
279
280 for(i = 0; (i < 256) ; i++) {
281 unsigned char byte;
282 if ((i % 16) == 0) {
283 print_debug("\n");
284 print_debug_hex8(i);
285 print_debug(": ");
286 }
287 status = smbus_read_byte(device, i);
288 if (status < 0) {
289 print_debug("bad device: ");
290 print_debug_hex8(-status);
291 print_debug("\n");
292 break;
293 }
294 print_debug_hex8(status);
295 print_debug_char(' ');
296 }
297 device++;
298 print_debug("\n");
299 }
300}
301
302void dump_ipmi_registers(void)
303{
304 unsigned device;
305 device = 0x42;
306 while(device <= 0x42) {
307 int status = 0;
308 int i;
309 print_debug("\n");
310 print_debug("ipmi ");
311 print_debug_hex8(device);
312
313 for(i = 0; (i < 8) ; i++) {
314 unsigned char byte;
315 status = smbus_read_byte(device, 2);
316 if (status < 0) {
317 print_debug("bad device: ");
318 print_debug_hex8(-status);
319 print_debug("\n");
320 break;
321 }
322 print_debug_hex8(status);
323 print_debug_char(' ');
324 }
325 device++;
326 print_debug("\n");
327 }
328}
329