Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-8
[coreboot.git] / src / northbridge / amd / amdk8 / debug.c
1 /*
2  * generic K8 debug code, used by mainboard specific auto.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 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(" ");
31                 print_debug_hex16(id & 0xffff);
32                 print_debug(" ");
33                 print_debug_hex16((id>>16) & 0xffff);
34                 print_debug("\r\n");
35         }
36 }
37
38 static void dump_pci_device(unsigned dev)
39 {
40         int i;
41         print_debug_pci_dev(dev);
42         print_debug("\r\n");
43         
44         for(i = 0; i < 256; i++) {
45                 unsigned char val;
46                 if ((i & 0x0f) == 0) {
47                         print_debug_hex8(i);
48                         print_debug_char(':');
49                 }
50                 val = pci_read_config8(dev, i);
51                 print_debug_char(' ');
52                 print_debug_hex8(val);
53                 if ((i & 0x0f) == 0x0f) {
54                         print_debug("\r\n");
55                 }
56         }
57 }
58
59 static void dump_pci_devices(void)
60 {
61         device_t dev;
62         for(dev = PCI_DEV(0, 0, 0); 
63                 dev <= PCI_DEV(0xff, 0x1f, 0x7); 
64                 dev += PCI_DEV(0,0,1)) {
65                 uint32_t id;
66                 id = pci_read_config32(dev, PCI_VENDOR_ID);
67                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
68                         (((id >> 16) & 0xffff) == 0xffff) ||
69                         (((id >> 16) & 0xffff) == 0x0000)) {
70                         continue;
71                 }
72                 dump_pci_device(dev);
73         }
74 }
75
76 static void dump_pci_devices_on_bus(unsigned busn)
77 {
78         device_t dev;
79         for(dev = PCI_DEV(busn, 0, 0);
80                 dev <= PCI_DEV(busn, 0x1f, 0x7);
81                 dev += PCI_DEV(0,0,1)) {
82                 uint32_t id;
83                 id = pci_read_config32(dev, PCI_VENDOR_ID);
84                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
85                         (((id >> 16) & 0xffff) == 0xffff) ||
86                         (((id >> 16) & 0xffff) == 0x0000)) {
87                         continue;
88                 }
89                 dump_pci_device(dev);
90         }
91 }
92
93 static void dump_spd_registers(const struct mem_controller *ctrl)
94 {
95         int i;
96         print_debug("\r\n");
97         for(i = 0; i < 4; i++) {
98                 unsigned device;
99                 device = ctrl->channel0[i];
100                 if (device) {
101                         int j;
102                         print_debug("dimm: "); 
103                         print_debug_hex8(i); 
104                         print_debug(".0: ");
105                         print_debug_hex8(device);
106                         for(j = 0; j < 128; j++) {
107                                 int status;
108                                 unsigned char byte;
109                                 if ((j & 0xf) == 0) {
110                                         print_debug("\r\n");
111                                         print_debug_hex8(j);
112                                         print_debug(": ");
113                                 }
114                                 status = smbus_read_byte(device, j);
115                                 if (status < 0) {
116                                         print_debug("bad device\r\n");
117                                         break;
118                                 }
119                                 byte = status & 0xff;
120                                 print_debug_hex8(byte);
121                                 print_debug_char(' ');
122                         }
123                         print_debug("\r\n");
124                 }
125                 device = ctrl->channel1[i];
126                 if (device) {
127                         int j;
128                         print_debug("dimm: "); 
129                         print_debug_hex8(i); 
130                         print_debug(".1: ");
131                         print_debug_hex8(device);
132                         for(j = 0; j < 128; j++) {
133                                 int status;
134                                 unsigned char byte;
135                                 if ((j & 0xf) == 0) {
136                                         print_debug("\r\n");
137                                         print_debug_hex8(j);
138                                         print_debug(": ");
139                                 }
140                                 status = smbus_read_byte(device, j);
141                                 if (status < 0) {
142                                         print_debug("bad device\r\n");
143                                         break;
144                                 }
145                                 byte = status & 0xff;
146                                 print_debug_hex8(byte);
147                                 print_debug_char(' ');
148                         }
149                         print_debug("\r\n");
150                 }
151         }
152 }
153 static void dump_smbus_registers(void)
154 {
155         int i;
156         print_debug("\r\n");
157         for(i = 1; i < 0x80; i++) {
158                 unsigned device;
159                 device = i;
160                 int j;
161                 print_debug("smbus: ");
162                 print_debug_hex8(device);
163                 for(j = 0; j < 256; j++) {
164                         int status; 
165                         unsigned char byte;
166                         if ((j & 0xf) == 0) {
167                                 print_debug("\r\n");
168                                 print_debug_hex8(j);
169                                 print_debug(": ");
170                         }
171                         status = smbus_read_byte(device, j);
172                         if (status < 0) {
173                                 print_debug("bad device status=");
174                                 print_debug_hex32(status);
175                                 print_debug("\r\n");
176                                 break;
177                         }
178                         byte = status & 0xff;
179                         print_debug_hex8(byte);
180                         print_debug_char(' ');
181                 }
182                 print_debug("\r\n");
183         }       
184 }
185
186 static void dump_io_resources(unsigned port) 
187 {
188
189         int i;
190         udelay(2000);
191         print_debug_hex16(port);
192         print_debug(":\r\n");
193         for(i=0;i<256;i++) {
194                 uint8_t val;
195                 if ((i & 0x0f) == 0) {
196                         print_debug_hex8(i);
197                         print_debug_char(':');
198                 }
199                 val = inb(port);
200                 print_debug_char(' ');
201                 print_debug_hex8(val);
202                 if ((i & 0x0f) == 0x0f) {
203                         print_debug("\r\n");
204                 }
205                 port++;
206         }
207 }
208 #endif