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