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