4083add6f1b2ded8ecb6fc1e263be406ed195d7b
[coreboot.git] / src / northbridge / intel / i855 / debug.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2003 Ronald G. Minnich
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 /*
22  * generic K8 debug code, used by mainboard specific romstage.c
23  *
24  */
25 #if 1
26 /*
27 static void print_debug_pci_dev(unsigned dev)
28 {
29         print_debug("PCI: ");
30         print_debug_hex8((dev >> 16) & 0xff);
31         print_debug_char(':');
32         print_debug_hex8((dev >> 11) & 0x1f);
33         print_debug_char('.');
34         print_debug_hex8((dev >> 8) & 7);
35 }
36 */
37
38
39 static void print_debug_pci_dev(unsigned dev)
40 {
41         print_debug("PCI: ");
42         print_debug_hex8((dev >> 20) & 0xff);
43         print_debug_char(':');
44         print_debug_hex8((dev >> 15) & 0x1f);
45         print_debug_char('.');
46         print_debug_hex8((dev >> 12) & 0x07);
47 }
48
49 static void print_pci_devices(void)
50 {
51         device_t dev;
52         for(dev = PCI_DEV(0, 0, 0); 
53                 dev <= PCI_DEV(0, 0x1f, 0x7); 
54                 dev += PCI_DEV(0,0,1)) {
55                 uint32_t id;
56                 id = pci_read_config32(dev, PCI_VENDOR_ID);
57                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
58                         (((id >> 16) & 0xffff) == 0xffff) ||
59                         (((id >> 16) & 0xffff) == 0x0000)) {
60                         continue;
61                 }
62                 print_debug_pci_dev(dev);
63                 print_debug("\r\n");
64         }
65 }
66
67 static void dump_pci_device(unsigned dev)
68 {
69         int i;
70         print_debug_pci_dev(dev);
71         print_debug("\r\n");
72         
73         for(i = 0; i <= 255; i++) {
74                 unsigned char val;
75                 if ((i & 0x0f) == 0) {
76                         print_debug_hex8(i);
77                         print_debug_char(':');
78                 }
79                 val = pci_read_config8(dev, i);
80                 print_debug_char(' ');
81                 print_debug_hex8(val);
82                 if ((i & 0x0f) == 0x0f) {
83                         print_debug("\r\n");
84                 }
85         }
86 }
87
88 static void dump_pci_devices(void)
89 {
90         device_t dev;
91         for(dev = PCI_DEV(0, 0, 0); 
92                 dev <= PCI_DEV(0, 0x1f, 0x7); 
93                 dev += PCI_DEV(0,0,1)) {
94                 uint32_t id;
95                 id = pci_read_config32(dev, PCI_VENDOR_ID);
96                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
97                         (((id >> 16) & 0xffff) == 0xffff) ||
98                         (((id >> 16) & 0xffff) == 0x0000)) {
99                         continue;
100                 }
101                 dump_pci_device(dev);
102         }
103 }
104
105 static void dump_spd_registers(const struct mem_controller *ctrl)
106 {
107         int i;
108         print_debug("\r\n");
109         for(i = 0; i < 2; i++) {
110                 unsigned device;
111                 device = ctrl->channel0[i];
112                 if (device) {
113                         int j;
114                         print_debug("dimm: "); 
115                         print_debug_hex8(i); 
116                         print_debug(".0: ");
117                         print_debug_hex8(device);
118                         for(j = 0; j < 256; j++) {
119                                 int status;
120                                 unsigned char byte;
121                                 if ((j & 0xf) == 0) {
122                                         print_debug("\r\n");
123                                         print_debug_hex8(j);
124                                         print_debug(": ");
125                                 }
126                                 status = smbus_read_byte(device, j);
127                                 if (status < 0) {
128                                         print_debug("bad device\r\n");
129                                         break;
130                                 }
131                                 byte = status & 0xff;
132                                 print_debug_hex8(byte);
133                                 print_debug_char(' ');
134                         }
135                         print_debug("\r\n");
136                 }
137 #if 0
138                 device = ctrl->channel1[i];
139                 if (device) {
140                         int j;
141                         print_debug("dimm: "); 
142                         print_debug_hex8(i); 
143                         print_debug(".1: ");
144                         print_debug_hex8(device);
145                         for(j = 0; j < 256; j++) {
146                                 int status;
147                                 unsigned char byte;
148                                 if ((j & 0xf) == 0) {
149                                         print_debug("\r\n");
150                                         print_debug_hex8(j);
151                                         print_debug(": ");
152                                 }
153                                 status = smbus_read_byte(device, j);
154                                 if (status < 0) {
155                                         print_debug("bad device\r\n");
156                                         break;
157                                 }
158                                 byte = status & 0xff;
159                                 print_debug_hex8(byte);
160                                 print_debug_char(' ');
161                         }
162                         print_debug("\r\n");
163                 }
164 #endif
165         }
166 }
167 static void dump_smbus_registers(void)
168 {
169         int i;
170         print_debug("\r\n");
171         for(i = 1; i < 0x80; i++) {
172                 unsigned device;
173                 device = i;
174                 int j;
175                 print_debug("smbus: ");
176                 print_debug_hex8(device);
177                 for(j = 0; j < 256; j++) {
178                         int status; 
179                         unsigned char byte;
180                         if ((j & 0xf) == 0) {
181                                 print_debug("\r\n");
182                                 print_debug_hex8(j);
183                                 print_debug(": ");
184                         }
185                         status = smbus_read_byte(device, j);
186                         if (status < 0) {
187                                 print_debug("bad device\r\n");
188                                 break;
189                         }
190                         byte = status & 0xff;
191                         print_debug_hex8(byte);
192                         print_debug_char(' ');
193                 }
194                 print_debug("\r\n");
195         }       
196 }
197 #endif