Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / northbridge / intel / e7501 / debug.c
1 /*
2  * generic debug code, used by mainboard specific romstage.c
3  *
4  */
5 #if 1
6 static void print_debug_pci_dev(unsigned dev)
7 {
8         print_debug("PCI: ");
9         print_debug_hex8((dev >> 16) & 0xff);
10         print_debug_char(':');
11         print_debug_hex8((dev >> 11) & 0x1f);
12         print_debug_char('.');
13         print_debug_hex8((dev >> 8) & 7);
14 }
15
16 static inline void print_pci_devices(void)
17 {
18         device_t dev;
19         for(dev = PCI_DEV(0, 0, 0);
20                 dev <= PCI_DEV(0xff, 0x1f, 0x7);
21                 dev += PCI_DEV(0,0,1)) {
22                 uint32_t id;
23                 id = pci_read_config32(dev, PCI_VENDOR_ID);
24                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
25                         (((id >> 16) & 0xffff) == 0xffff) ||
26                         (((id >> 16) & 0xffff) == 0x0000)) {
27                         continue;
28                 }
29                 print_debug_pci_dev(dev);
30                 print_debug("\n");
31         }
32 }
33
34 static void dump_pci_device(unsigned dev)
35 {
36         int i;
37         print_debug_pci_dev(dev);
38
39         for(i = 0; i < 256; i++) {
40                 unsigned char val;
41                 if ((i & 0x0f) == 0) {
42 #if CONFIG_USE_PRINTK_IN_CAR
43                         printk(BIOS_DEBUG, "\n%02x:",i);
44 #else
45                         print_debug("\n");
46                         print_debug_hex8(i);
47                         print_debug_char(':');
48 #endif
49                 }
50                 val = pci_read_config8(dev, i);
51 #if CONFIG_USE_PRINTK_IN_CAR
52                 printk(BIOS_DEBUG, " %02x", val);
53 #else
54                 print_debug_char(' ');
55                 print_debug_hex8(val);
56 #endif
57         }
58         print_debug("\n");
59 }
60
61 static inline void dump_pci_devices(void)
62 {
63         device_t dev;
64         for(dev = PCI_DEV(0, 0, 0);
65                 dev <= PCI_DEV(0xff, 0x1f, 0x7);
66                 dev += PCI_DEV(0,0,1)) {
67                 uint32_t id;
68                 id = pci_read_config32(dev, PCI_VENDOR_ID);
69                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
70                         (((id >> 16) & 0xffff) == 0xffff) ||
71                         (((id >> 16) & 0xffff) == 0x0000)) {
72                         continue;
73                 }
74                 dump_pci_device(dev);
75         }
76 }
77
78 static inline void dump_pci_devices_on_bus(unsigned busn)
79 {
80         device_t dev;
81         for(dev = PCI_DEV(busn, 0, 0);
82                 dev <= PCI_DEV(busn, 0x1f, 0x7);
83                 dev += PCI_DEV(0,0,1)) {
84                 uint32_t id;
85                 id = pci_read_config32(dev, PCI_VENDOR_ID);
86                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
87                         (((id >> 16) & 0xffff) == 0xffff) ||
88                         (((id >> 16) & 0xffff) == 0x0000)) {
89                         continue;
90                 }
91                 dump_pci_device(dev);
92         }
93 }
94
95 static inline void dump_spd_registers(const struct mem_controller *ctrl)
96 {
97         int i;
98         print_debug("\n");
99         for(i = 0; i < 4; i++) {
100                 unsigned device;
101                 device = ctrl->channel0[i];
102                 if (device) {
103                         int j;
104 #if CONFIG_USE_PRINTK_IN_CAR
105                         printk(BIOS_DEBUG, "dimm: %02x.0: %02x", i, device);
106 #else
107                         print_debug("dimm: ");
108                         print_debug_hex8(i);
109                         print_debug(".0: ");
110                         print_debug_hex8(device);
111 #endif
112                         for(j = 0; j < 128; j++) {
113                                 int status;
114                                 unsigned char byte;
115                                 if ((j & 0xf) == 0) {
116 #if CONFIG_USE_PRINTK_IN_CAR
117                                         printk(BIOS_DEBUG, "\n%02x: ", j);
118 #else
119                                         print_debug("\n");
120                                         print_debug_hex8(j);
121                                         print_debug(": ");
122 #endif
123                                 }
124                                 status = smbus_read_byte(device, j);
125                                 if (status < 0) {
126                                         break;
127                                 }
128                                 byte = status & 0xff;
129 #if CONFIG_USE_PRINTK_IN_CAR
130                                 printk(BIOS_DEBUG, "%02x ", byte);
131 #else
132                                 print_debug_hex8(byte);
133                                 print_debug_char(' ');
134 #endif
135                         }
136                         print_debug("\n");
137                 }
138                 device = ctrl->channel1[i];
139                 if (device) {
140                         int j;
141 #if CONFIG_USE_PRINTK_IN_CAR
142                         printk(BIOS_DEBUG, "dimm: %02x.1: %02x", i, device);
143 #else
144                         print_debug("dimm: ");
145                         print_debug_hex8(i);
146                         print_debug(".1: ");
147                         print_debug_hex8(device);
148 #endif
149                         for(j = 0; j < 128; j++) {
150                                 int status;
151                                 unsigned char byte;
152                                 if ((j & 0xf) == 0) {
153 #if CONFIG_USE_PRINTK_IN_CAR
154                                         printk(BIOS_DEBUG, "\n%02x: ", j);
155 #else
156                                         print_debug("\n");
157                                         print_debug_hex8(j);
158                                         print_debug(": ");
159 #endif
160                                 }
161                                 status = smbus_read_byte(device, j);
162                                 if (status < 0) {
163                                         break;
164                                 }
165                                 byte = status & 0xff;
166 #if CONFIG_USE_PRINTK_IN_CAR
167                                 printk(BIOS_DEBUG, "%02x ", byte);
168 #else
169                                 print_debug_hex8(byte);
170                                 print_debug_char(' ');
171 #endif
172                         }
173                         print_debug("\n");
174                 }
175         }
176 }
177 static inline void dump_smbus_registers(void)
178 {
179         unsigned device;
180         print_debug("\n");
181         for(device = 1; device < 0x80; device++) {
182                 int j;
183                 if( smbus_read_byte(device, 0) < 0 ) continue;
184 #if CONFIG_USE_PRINTK_IN_CAR
185                 printk(BIOS_DEBUG, "smbus: %02x", device);
186 #else
187                 print_debug("smbus: ");
188                 print_debug_hex8(device);
189 #endif
190                 for(j = 0; j < 256; j++) {
191                         int status;
192                         unsigned char byte;
193                         status = smbus_read_byte(device, j);
194                         if (status < 0) {
195                                 break;
196                         }
197                         if ((j & 0xf) == 0) {
198 #if CONFIG_USE_PRINTK_IN_CAR
199                                 printk(BIOS_DEBUG, "\n%02x: ",j);
200 #else
201                                 print_debug("\n");
202                                 print_debug_hex8(j);
203                                 print_debug(": ");
204 #endif
205                         }
206                         byte = status & 0xff;
207 #if CONFIG_USE_PRINTK_IN_CAR
208                         printk(BIOS_DEBUG, "%02x ", byte);
209 #else
210                         print_debug_hex8(byte);
211                         print_debug_char(' ');
212 #endif
213                 }
214                 print_debug("\n");
215         }
216 }
217
218 static inline void dump_io_resources(unsigned port)
219 {
220
221         int i;
222 #if CONFIG_USE_PRINTK_IN_CAR
223         printk(BIOS_DEBUG, "%04x:\n", port);
224 #else
225         print_debug_hex16(port);
226         print_debug(":\n");
227 #endif
228         for(i=0;i<256;i++) {
229                 uint8_t val;
230                 if ((i & 0x0f) == 0) {
231 #if CONFIG_USE_PRINTK_IN_CAR
232                         printk(BIOS_DEBUG, "%02x:", i);
233 #else
234                         print_debug_hex8(i);
235                         print_debug_char(':');
236 #endif
237                 }
238                 val = inb(port);
239 #if CONFIG_USE_PRINTK_IN_CAR
240                 printk(BIOS_DEBUG, " %02x",val);
241 #else
242                 print_debug_char(' ');
243                 print_debug_hex8(val);
244 #endif
245                 if ((i & 0x0f) == 0x0f) {
246                         print_debug("\n");
247                 }
248                 port++;
249         }
250 }
251
252 static inline void dump_mem(unsigned start, unsigned end)
253 {
254         unsigned i;
255         print_debug("dump_mem:");
256         for(i=start;i<end;i++) {
257                 if((i & 0xf)==0) {
258 #if CONFIG_USE_PRINTK_IN_CAR
259                         printk(BIOS_DEBUG, "\n%08x:", i);
260 #else
261                         print_debug("\n");
262                         print_debug_hex32(i);
263                         print_debug(":");
264 #endif
265                 }
266 #if CONFIG_USE_PRINTK_IN_CAR
267                 printk(BIOS_DEBUG, " %02x", (unsigned char)*((unsigned char *)i));
268 #else
269                 print_debug(" ");
270                 print_debug_hex8((unsigned char)*((unsigned char *)i));
271 #endif
272         }
273         print_debug("\n");
274  }
275 #endif