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