Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / mainboard / dell / s1850 / 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 void dump_spd_registers(void)
209 {
210         unsigned device;
211         device = SMBUS_MEM_DEVICE_START;
212         while(device <= SMBUS_MEM_DEVICE_END) {
213                 int status = 0;
214                 int i;
215                 print_debug("\n");
216                 print_debug("dimm ");
217                 print_debug_hex8(device);
218
219                 for(i = 0; (i < 256) ; i++) {
220                         unsigned char byte;
221                         if ((i % 16) == 0) {
222                                 print_debug("\n");
223                                 print_debug_hex8(i);
224                                 print_debug(": ");
225                         }
226                         status = smbus_read_byte(device, i);
227                         if (status < 0) {
228                                  print_debug("bad device: ");
229                                  print_debug_hex8(-status);
230                                  print_debug("\n");
231                                  break;
232                         }
233                         print_debug_hex8(status);
234                         print_debug_char(' ');
235                 }
236                 device += SMBUS_MEM_DEVICE_INC;
237                 print_debug("\n");
238         }
239 }
240
241 void show_dram_slots(void)
242 {
243         unsigned device;
244         device = SMBUS_MEM_DEVICE_START;
245         while(device <= SMBUS_MEM_DEVICE_END) {
246                  int status = 0;
247                 int i;
248                 print_debug("\n");
249                 print_debug("dimm ");
250                 print_debug_hex8(device);
251
252                 status = smbus_read_byte(device, 0);
253                 if (status < 0) {
254                         print_debug("bad device: ");
255                 } else {
256                         print_debug("present: ");
257                 }
258                 print_debug_hex8(status);
259                 print_debug("\n");
260                 device += SMBUS_MEM_DEVICE_INC;
261                 print_debug("\n");
262         }
263 }
264
265 void dump_ipmi_registers(void)
266 {
267         unsigned device;
268         device = 0x42;
269         while(device <= 0x42) {
270                 int status = 0;
271                 int i;
272                 print_debug("\n");
273                 print_debug("ipmi ");
274                 print_debug_hex8(device);
275
276                 for(i = 0; (i < 8) ; i++) {
277                         unsigned char byte;
278                         status = smbus_read_byte(device, 2);
279                         if (status < 0) {
280                                  print_debug("bad device: ");
281                                  print_debug_hex8(-status);
282                                  print_debug("\n");
283                                  break;
284                         }
285                         print_debug_hex8(status);
286                         print_debug_char(' ');
287                 }
288                 device += SMBUS_MEM_DEVICE_INC;
289                 print_debug("\n");
290         }
291 }