2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Advanced Micro Devices, Inc.
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; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Generic FAM10 debug code, used by mainboard specific romstage.c
27 static inline void print_debug_addr(const char *str, void *val)
30 printk(BIOS_DEBUG, "------Address debug: %s%p------\n", str, val);
34 static void print_debug_pci_dev(u32 dev)
36 #if CONFIG_PCI_BUS_SEGN_BITS==0
37 printk(BIOS_DEBUG, "PCI: %02x:%02x.%02x", (dev>>20) & 0xff, (dev>>15) & 0x1f, (dev>>12) & 0x7);
39 printk(BIOS_DEBUG, "PCI: %04x:%02x:%02x.%02x", (dev>>28) & 0x0f, (dev>>20) & 0xff, (dev>>15) & 0x1f, (dev>>12) & 0x7);
43 static inline void print_pci_devices(void)
46 for(dev = PCI_DEV(0, 0, 0);
47 dev <= PCI_DEV(0xff, 0x1f, 0x7);
48 dev += PCI_DEV(0,0,1)) {
50 id = pci_read_config32(dev, PCI_VENDOR_ID);
51 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
52 (((id >> 16) & 0xffff) == 0xffff) ||
53 (((id >> 16) & 0xffff) == 0x0000)) {
56 print_debug_pci_dev(dev);
57 printk(BIOS_DEBUG, " %04x:%04x\n", (id & 0xffff), (id>>16));
58 if(((dev>>12) & 0x07) == 0) {
60 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
61 if((hdr_type & 0x80) != 0x80) {
62 dev += PCI_DEV(0,0,7);
68 static inline void print_pci_devices_on_bus(u32 busn)
71 for(dev = PCI_DEV(busn, 0, 0);
72 dev <= PCI_DEV(busn, 0x1f, 0x7);
73 dev += PCI_DEV(0,0,1)) {
75 id = pci_read_config32(dev, PCI_VENDOR_ID);
76 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
77 (((id >> 16) & 0xffff) == 0xffff) ||
78 (((id >> 16) & 0xffff) == 0x0000)) {
81 print_debug_pci_dev(dev);
82 printk(BIOS_DEBUG, " %04x:%04x\n", (id & 0xffff), (id>>16));
83 if(((dev>>12) & 0x07) == 0) {
85 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
86 if((hdr_type & 0x80) != 0x80) {
87 dev += PCI_DEV(0,0,7);
93 static void dump_pci_device_range(u32 dev, u32 start_reg, u32 size)
96 print_debug_pci_dev(dev);
98 int end = start_reg + size;
100 for(i = start_reg; i < end; i+=4) {
102 if ((i & 0x0f) == 0) {
103 printk(BIOS_DEBUG, "\n%04x:",i);
105 val = pci_read_config32(dev, i);
107 printk(BIOS_DEBUG, " %02x", val & 0xff);
114 static void dump_pci_device(u32 dev)
116 dump_pci_device_range(dev, 0, 4096);
119 static void dump_pci_device_index_wait_range(u32 dev, u32 index_reg, u32 start,
123 int end = start + size;
124 print_debug_pci_dev(dev);
125 print_debug(" -- index_reg="); print_debug_hex32(index_reg);
127 for(i = start; i < end; i++) {
130 printk(BIOS_DEBUG, "\n%02x:",i);
131 val = pci_read_config32_index_wait(dev, index_reg, i);
133 printk(BIOS_DEBUG, " %02x", val & 0xff);
141 static inline void dump_pci_device_index_wait(u32 dev, u32 index_reg)
143 dump_pci_device_index_wait_range(dev, index_reg, 0, 0x54);
144 dump_pci_device_index_wait_range(dev, index_reg, 0x100, 0x08); //DIMM1 when memclk > 400Hz
145 // dump_pci_device_index_wait_range(dev, index_reg, 0x200, 0x08); //DIMM2
146 // dump_pci_device_index_wait_range(dev, index_reg, 0x300, 0x08); //DIMM3
149 static inline void dump_pci_device_index(u32 dev, u32 index_reg, u32 type, u32 length)
152 print_debug_pci_dev(dev);
154 print_debug(" index reg: "); print_debug_hex16(index_reg); print_debug(" type: "); print_debug_hex8(type);
158 for(i = 0; i < length; i++) {
160 if ((i & 0x0f) == 0) {
161 printk(BIOS_DEBUG, "\n%02x:",i);
163 val = pci_read_config32_index(dev, index_reg, i|type);
164 printk(BIOS_DEBUG, " %08x", val);
169 static inline void dump_pci_devices(void)
172 for(dev = PCI_DEV(0, 0, 0);
173 dev <= PCI_DEV(0xff, 0x1f, 0x7);
174 dev += PCI_DEV(0,0,1)) {
176 id = pci_read_config32(dev, PCI_VENDOR_ID);
177 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
178 (((id >> 16) & 0xffff) == 0xffff) ||
179 (((id >> 16) & 0xffff) == 0x0000)) {
182 dump_pci_device(dev);
184 if(((dev>>12) & 0x07) == 0) {
186 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
187 if((hdr_type & 0x80) != 0x80) {
188 dev += PCI_DEV(0,0,7);
194 static inline void dump_pci_devices_on_bus(u32 busn)
197 for(dev = PCI_DEV(busn, 0, 0);
198 dev <= PCI_DEV(busn, 0x1f, 0x7);
199 dev += PCI_DEV(0,0,1)) {
201 id = pci_read_config32(dev, PCI_VENDOR_ID);
202 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
203 (((id >> 16) & 0xffff) == 0xffff) ||
204 (((id >> 16) & 0xffff) == 0x0000)) {
207 dump_pci_device(dev);
209 if(((dev>>12) & 0x07) == 0) {
211 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
212 if((hdr_type & 0x80) != 0x80) {
213 dev += PCI_DEV(0,0,7);
219 #if CONFIG_DEBUG_SMBUS
221 static void dump_spd_registers(const struct mem_controller *ctrl)
225 for(i = 0; i < DIMM_SOCKETS; i++) {
227 device = ctrl->spd_addr[i];
230 printk(BIOS_DEBUG, "dimm: %02x.0: %02x", i, device);
231 for(j = 0; j < 128; j++) {
234 if ((j & 0xf) == 0) {
235 printk(BIOS_DEBUG, "\n%02x: ", j);
237 status = smbus_read_byte(device, j);
241 byte = status & 0xff;
242 printk(BIOS_DEBUG, "%02x ", byte);
246 device = ctrl->spd_addr[i+DIMM_SOCKETS];
249 printk(BIOS_DEBUG, "dimm: %02x.1: %02x", i, device);
250 for(j = 0; j < 128; j++) {
253 if ((j & 0xf) == 0) {
254 printk(BIOS_DEBUG, "\n%02x: ", j);
256 status = smbus_read_byte(device, j);
260 byte = status & 0xff;
261 printk(BIOS_DEBUG, "%02x ", byte);
267 static void dump_smbus_registers(void)
271 for(device = 1; device < 0x80; device++) {
273 if( smbus_read_byte(device, 0) < 0 ) continue;
274 printk(BIOS_DEBUG, "smbus: %02x", device);
275 for(j = 0; j < 256; j++) {
278 status = smbus_read_byte(device, j);
282 if ((j & 0xf) == 0) {
283 printk(BIOS_DEBUG, "\n%02x: ",j);
285 byte = status & 0xff;
286 printk(BIOS_DEBUG, "%02x ", byte);
292 static inline void dump_io_resources(u32 port)
297 printk(BIOS_DEBUG, "%04x:\n", port);
300 if ((i & 0x0f) == 0) {
301 printk(BIOS_DEBUG, "%02x:", i);
304 printk(BIOS_DEBUG, " %02x",val);
305 if ((i & 0x0f) == 0x0f) {
312 static inline void dump_mem(u32 start, u32 end)
315 print_debug("dump_mem:");
316 for(i=start;i<end;i++) {
318 printk(BIOS_DEBUG, "\n%08x:", i);
320 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));