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