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
24 #include "amdfam10_pci.c"
26 static inline void print_debug_addr(const char *str, void *val)
28 #if CACHE_AS_RAM_ADDRESS_DEBUG == 1
29 printk(BIOS_DEBUG, "------Address debug: %s%p------\n", str, val);
33 static void print_debug_pci_dev(u32 dev)
35 #if CONFIG_PCI_BUS_SEGN_BITS==0
36 printk(BIOS_DEBUG, "PCI: %02x:%02x.%02x", (dev>>20) & 0xff, (dev>>15) & 0x1f, (dev>>12) & 0x7);
38 printk(BIOS_DEBUG, "PCI: %04x:%02x:%02x.%02x", (dev>>28) & 0x0f, (dev>>20) & 0xff, (dev>>15) & 0x1f, (dev>>12) & 0x7);
42 static inline void print_pci_devices(void)
45 for(dev = PCI_DEV(0, 0, 0);
46 dev <= PCI_DEV(0xff, 0x1f, 0x7);
47 dev += PCI_DEV(0,0,1)) {
49 id = pci_read_config32(dev, PCI_VENDOR_ID);
50 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
51 (((id >> 16) & 0xffff) == 0xffff) ||
52 (((id >> 16) & 0xffff) == 0x0000)) {
55 print_debug_pci_dev(dev);
56 printk(BIOS_DEBUG, " %04x:%04x\n", (id & 0xffff), (id>>16));
57 if(((dev>>12) & 0x07) == 0) {
59 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
60 if((hdr_type & 0x80) != 0x80) {
61 dev += PCI_DEV(0,0,7);
67 static inline void print_pci_devices_on_bus(u32 busn)
70 for(dev = PCI_DEV(busn, 0, 0);
71 dev <= PCI_DEV(busn, 0x1f, 0x7);
72 dev += PCI_DEV(0,0,1)) {
74 id = pci_read_config32(dev, PCI_VENDOR_ID);
75 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
76 (((id >> 16) & 0xffff) == 0xffff) ||
77 (((id >> 16) & 0xffff) == 0x0000)) {
80 print_debug_pci_dev(dev);
81 printk(BIOS_DEBUG, " %04x:%04x\n", (id & 0xffff), (id>>16));
82 if(((dev>>12) & 0x07) == 0) {
84 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
85 if((hdr_type & 0x80) != 0x80) {
86 dev += PCI_DEV(0,0,7);
94 static void dump_pci_device_range(u32 dev, u32 start_reg, u32 size)
97 print_debug_pci_dev(dev);
99 int end = start_reg + size;
101 for(i = start_reg; i < end; i+=4) {
103 if ((i & 0x0f) == 0) {
104 printk(BIOS_DEBUG, "\n%04x:",i);
106 val = pci_read_config32(dev, i);
108 printk(BIOS_DEBUG, " %02x", val & 0xff);
114 static void dump_pci_device(u32 dev)
116 dump_pci_device_range(dev, 0, 4096);
118 static void dump_pci_device_index_wait_range(u32 dev, u32 index_reg, u32 start,
122 int end = start + size;
123 print_debug_pci_dev(dev);
124 print_debug(" -- index_reg="); print_debug_hex32(index_reg);
126 for(i = start; i < end; i++) {
129 printk(BIOS_DEBUG, "\n%02x:",i);
130 val = pci_read_config32_index_wait(dev, index_reg, i);
132 printk(BIOS_DEBUG, " %02x", val & 0xff);
139 static inline void dump_pci_device_index_wait(u32 dev, u32 index_reg)
141 dump_pci_device_index_wait_range(dev, index_reg, 0, 0x54);
142 dump_pci_device_index_wait_range(dev, index_reg, 0x100, 0x08); //DIMM1 when memclk > 400Hz
143 // dump_pci_device_index_wait_range(dev, index_reg, 0x200, 0x08); //DIMM2
144 // dump_pci_device_index_wait_range(dev, index_reg, 0x300, 0x08); //DIMM3
148 static inline void dump_pci_device_index(u32 dev, u32 index_reg, u32 type, u32 length)
151 print_debug_pci_dev(dev);
153 print_debug(" index reg: "); print_debug_hex16(index_reg); print_debug(" type: "); print_debug_hex8(type);
157 for(i = 0; i < length; i++) {
159 if ((i & 0x0f) == 0) {
160 printk(BIOS_DEBUG, "\n%02x:",i);
162 val = pci_read_config32_index(dev, index_reg, i|type);
163 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);
195 static inline void dump_pci_devices_on_bus(u32 busn)
198 for(dev = PCI_DEV(busn, 0, 0);
199 dev <= PCI_DEV(busn, 0x1f, 0x7);
200 dev += PCI_DEV(0,0,1)) {
202 id = pci_read_config32(dev, PCI_VENDOR_ID);
203 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
204 (((id >> 16) & 0xffff) == 0xffff) ||
205 (((id >> 16) & 0xffff) == 0x0000)) {
208 dump_pci_device(dev);
210 if(((dev>>12) & 0x07) == 0) {
212 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
213 if((hdr_type & 0x80) != 0x80) {
214 dev += PCI_DEV(0,0,7);
220 #if CONFIG_DEBUG_SMBUS
222 static void dump_spd_registers(const struct mem_controller *ctrl)
226 for(i = 0; i < DIMM_SOCKETS; i++) {
228 device = ctrl->spd_addr[i];
231 printk(BIOS_DEBUG, "dimm: %02x.0: %02x", i, device);
232 for(j = 0; j < 128; j++) {
235 if ((j & 0xf) == 0) {
236 printk(BIOS_DEBUG, "\n%02x: ", j);
238 status = smbus_read_byte(device, j);
242 byte = status & 0xff;
243 printk(BIOS_DEBUG, "%02x ", byte);
247 device = ctrl->spd_addr[i+DIMM_SOCKETS];
250 printk(BIOS_DEBUG, "dimm: %02x.1: %02x", i, device);
251 for(j = 0; j < 128; j++) {
254 if ((j & 0xf) == 0) {
255 printk(BIOS_DEBUG, "\n%02x: ", j);
257 status = smbus_read_byte(device, j);
261 byte = status & 0xff;
262 printk(BIOS_DEBUG, "%02x ", byte);
268 static void dump_smbus_registers(void)
272 for(device = 1; device < 0x80; device++) {
274 if( smbus_read_byte(device, 0) < 0 ) continue;
275 printk(BIOS_DEBUG, "smbus: %02x", device);
276 for(j = 0; j < 256; j++) {
279 status = smbus_read_byte(device, j);
283 if ((j & 0xf) == 0) {
284 printk(BIOS_DEBUG, "\n%02x: ",j);
286 byte = status & 0xff;
287 printk(BIOS_DEBUG, "%02x ", byte);
293 static inline void dump_io_resources(u32 port)
298 printk(BIOS_DEBUG, "%04x:\n", port);
301 if ((i & 0x0f) == 0) {
302 printk(BIOS_DEBUG, "%02x:", i);
305 printk(BIOS_DEBUG, " %02x",val);
306 if ((i & 0x0f) == 0x0f) {
313 static inline void dump_mem(u32 start, u32 end)
316 print_debug("dump_mem:");
317 for(i=start;i<end;i++) {
319 printk(BIOS_DEBUG, "\n%08x:", i);
321 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));