2f7d5342a1b7bb0bc4a6578746afe18c76d58ebc
[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 static void print_debug_pci_dev(unsigned dev)
22 {
23         print_debug("PCI: ");
24         print_debug_hex8((dev >> 20) & 0xff);
25         print_debug_char(':');
26         print_debug_hex8((dev >> 15) & 0x1f);
27         print_debug_char('.');
28         print_debug_hex8((dev >> 12) & 0x07);
29 }
30
31 static inline void print_pci_devices(void)
32 {
33         device_t dev;
34         for(dev = PCI_DEV(0, 0, 0);
35                 dev <= PCI_DEV(0, 0x1f, 0x7);
36                 dev += PCI_DEV(0,0,1)) {
37                 uint32_t id;
38                 id = pci_read_config32(dev, PCI_VENDOR_ID);
39                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
40                         (((id >> 16) & 0xffff) == 0xffff) ||
41                         (((id >> 16) & 0xffff) == 0x0000)) {
42                         continue;
43                 }
44                 print_debug_pci_dev(dev);
45                 print_debug("\n");
46         }
47 }
48
49 static void dump_pci_device(unsigned dev)
50 {
51         int i;
52         print_debug_pci_dev(dev);
53         print_debug("\n");
54
55         for(i = 0; i <= 255; i++) {
56                 unsigned char val;
57                 if ((i & 0x0f) == 0) {
58                         print_debug_hex8(i);
59                         print_debug_char(':');
60                 }
61                 val = pci_read_config8(dev, i);
62                 print_debug_char(' ');
63                 print_debug_hex8(val);
64                 if ((i & 0x0f) == 0x0f) {
65                         print_debug("\n");
66                 }
67         }
68 }
69
70 static inline void dump_pci_devices(void)
71 {
72         device_t dev;
73         for(dev = PCI_DEV(0, 0, 0);
74                 dev <= PCI_DEV(0, 0x1f, 0x7);
75                 dev += PCI_DEV(0,0,1)) {
76                 uint32_t id;
77                 id = pci_read_config32(dev, PCI_VENDOR_ID);
78                 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
79                         (((id >> 16) & 0xffff) == 0xffff) ||
80                         (((id >> 16) & 0xffff) == 0x0000)) {
81                         continue;
82                 }
83                 dump_pci_device(dev);
84         }
85 }
86
87 static inline void dump_spd_registers(const struct mem_controller *ctrl)
88 {
89         int i;
90         print_debug("\n");
91         for(i = 0; i < 2; i++) {
92                 unsigned device;
93                 device = ctrl->channel0[i];
94                 if (device) {
95                         int j;
96                         print_debug("dimm: ");
97                         print_debug_hex8(i);
98                         print_debug(".0: ");
99                         print_debug_hex8(device);
100                         for(j = 0; j < 256; j++) {
101                                 int status;
102                                 unsigned char byte;
103                                 if ((j & 0xf) == 0) {
104                                         print_debug("\n");
105                                         print_debug_hex8(j);
106                                         print_debug(": ");
107                                 }
108                                 status = smbus_read_byte(device, j);
109                                 if (status < 0) {
110                                         print_debug("bad device\n");
111                                         break;
112                                 }
113                                 byte = status & 0xff;
114                                 print_debug_hex8(byte);
115                                 print_debug_char(' ');
116                         }
117                         print_debug("\n");
118                 }
119         }
120 }
121
122 static inline void dump_smbus_registers(void)
123 {
124         int i;
125         print_debug("\n");
126         for(i = 1; i < 0x80; i++) {
127                 unsigned device;
128                 device = i;
129                 int j;
130                 print_debug("smbus: ");
131                 print_debug_hex8(device);
132                 for(j = 0; j < 256; j++) {
133                         int status;
134                         unsigned char byte;
135                         if ((j & 0xf) == 0) {
136                                 print_debug("\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\n");
143                                 break;
144                         }
145                         byte = status & 0xff;
146                         print_debug_hex8(byte);
147                         print_debug_char(' ');
148                 }
149                 print_debug("\n");
150         }
151 }