Some more DIMM0 related cleanups and deduplication.
[coreboot.git] / src / mainboard / dell / s1850 / debug.c
1 #include <spd.h>
2
3 static 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
17 static void xbus_en(void)
18 {
19         /* select the XBUS function in the SIO */
20         outb(0x07, 0x2e);
21         outb(0x0f, 0x2f);
22         outb(0x30, 0x2e);
23         outb(0x01, 0x2f);
24         return;
25 }
26
27 static void setup_func(unsigned char func)
28 {
29         /* select the function in the SIO */
30         outb(0x07, 0x2e);
31         outb(func, 0x2f);
32         /* print out the regs */
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
45 static 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
112 static 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
122 static 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
140 static 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
161 static 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
189 static 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 void dump_spd_registers(void)
207 {
208         unsigned device;
209         device = DIMM0;
210         while(device <= DIMM7) {
211                 int status = 0;
212                 int i;
213                 print_debug("\n");
214                 print_debug("dimm ");
215                 print_debug_hex8(device);
216
217                 for(i = 0; (i < 256) ; i++) {
218                         unsigned char byte;
219                         if ((i % 16) == 0) {
220                                 print_debug("\n");
221                                 print_debug_hex8(i);
222                                 print_debug(": ");
223                         }
224                         status = smbus_read_byte(device, i);
225                         if (status < 0) {
226                                  print_debug("bad device: ");
227                                  print_debug_hex8(-status);
228                                  print_debug("\n");
229                                  break;
230                         }
231                         print_debug_hex8(status);
232                         print_debug_char(' ');
233                 }
234                 device++;
235                 print_debug("\n");
236         }
237 }
238
239 void show_dram_slots(void)
240 {
241         unsigned device;
242         device = DIMM0;
243         while(device <= DIMM7) {
244                  int status = 0;
245                 int i;
246                 print_debug("\n");
247                 print_debug("dimm ");
248                 print_debug_hex8(device);
249
250                 status = smbus_read_byte(device, 0);
251                 if (status < 0) {
252                         print_debug("bad device: ");
253                 } else {
254                         print_debug("present: ");
255                 }
256                 print_debug_hex8(status);
257                 print_debug("\n");
258                 device++;
259                 print_debug("\n");
260         }
261 }
262
263 void dump_ipmi_registers(void)
264 {
265         unsigned device;
266         device = 0x42;
267         while(device <= 0x42) {
268                 int status = 0;
269                 int i;
270                 print_debug("\n");
271                 print_debug("ipmi ");
272                 print_debug_hex8(device);
273
274                 for(i = 0; (i < 8) ; i++) {
275                         unsigned char byte;
276                         status = smbus_read_byte(device, 2);
277                         if (status < 0) {
278                                  print_debug("bad device: ");
279                                  print_debug_hex8(-status);
280                                  print_debug("\n");
281                                  break;
282                         }
283                         print_debug_hex8(status);
284                         print_debug_char(' ');
285                 }
286                 device++;
287                 print_debug("\n");
288         }
289 }