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 void udelay_tsc(u32 us);
28 static void print_debug_addr(const char *str, void *val)
30 #if CACHE_AS_RAM_ADDRESS_DEBUG == 1
31 printk(BIOS_DEBUG, "------Address debug: %s%x------\n", str, val);
35 static void print_debug_pci_dev(u32 dev)
37 #if CONFIG_PCI_BUS_SEGN_BITS==0
38 printk(BIOS_DEBUG, "PCI: %02x:%02x.%02x", (dev>>20) & 0xff, (dev>>15) & 0x1f, (dev>>12) & 0x7);
40 printk(BIOS_DEBUG, "PCI: %04x:%02x:%02x.%02x", (dev>>28) & 0x0f, (dev>>20) & 0xff, (dev>>15) & 0x1f, (dev>>12) & 0x7);
44 static void print_pci_devices(void)
47 for(dev = PCI_DEV(0, 0, 0);
48 dev <= PCI_DEV(0xff, 0x1f, 0x7);
49 dev += PCI_DEV(0,0,1)) {
51 id = pci_read_config32(dev, PCI_VENDOR_ID);
52 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
53 (((id >> 16) & 0xffff) == 0xffff) ||
54 (((id >> 16) & 0xffff) == 0x0000)) {
57 print_debug_pci_dev(dev);
58 printk(BIOS_DEBUG, " %04x:%04x\n", (id & 0xffff), (id>>16));
59 if(((dev>>12) & 0x07) == 0) {
61 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
62 if((hdr_type & 0x80) != 0x80) {
63 dev += PCI_DEV(0,0,7);
69 static void print_pci_devices_on_bus(u32 busn)
72 for(dev = PCI_DEV(busn, 0, 0);
73 dev <= PCI_DEV(busn, 0x1f, 0x7);
74 dev += PCI_DEV(0,0,1)) {
76 id = pci_read_config32(dev, PCI_VENDOR_ID);
77 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
78 (((id >> 16) & 0xffff) == 0xffff) ||
79 (((id >> 16) & 0xffff) == 0x0000)) {
82 print_debug_pci_dev(dev);
83 printk(BIOS_DEBUG, " %04x:%04x\n", (id & 0xffff), (id>>16));
84 if(((dev>>12) & 0x07) == 0) {
86 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
87 if((hdr_type & 0x80) != 0x80) {
88 dev += PCI_DEV(0,0,7);
96 static void dump_pci_device_range(u32 dev, u32 start_reg, u32 size)
99 print_debug_pci_dev(dev);
101 int end = start_reg + size;
103 for(i = start_reg; i < end; i+=4) {
105 if ((i & 0x0f) == 0) {
106 printk(BIOS_DEBUG, "\n%04x:",i);
108 val = pci_read_config32(dev, i);
110 printk(BIOS_DEBUG, " %02x", val & 0xff);
116 static void dump_pci_device(u32 dev)
118 dump_pci_device_range(dev, 0, 4096);
120 static u32 pci_read_config32_index_wait(device_t dev, u32 index_reg, u32 index);
121 static void dump_pci_device_index_wait_range(u32 dev, u32 index_reg, u32 start,
125 int end = start + size;
126 print_debug_pci_dev(dev);
127 print_debug(" -- index_reg="); print_debug_hex32(index_reg);
129 for(i = start; i < end; i++) {
132 printk(BIOS_DEBUG, "\n%02x:",i);
133 val = pci_read_config32_index_wait(dev, index_reg, i);
135 printk(BIOS_DEBUG, " %02x", val & 0xff);
142 static void dump_pci_device_index_wait(u32 dev, u32 index_reg)
144 dump_pci_device_index_wait_range(dev, index_reg, 0, 0x54);
145 dump_pci_device_index_wait_range(dev, index_reg, 0x100, 0x08); //DIMM1 when memclk > 400Hz
146 // dump_pci_device_index_wait_range(dev, index_reg, 0x200, 0x08); //DIMM2
147 // dump_pci_device_index_wait_range(dev, index_reg, 0x300, 0x08); //DIMM3
151 static void dump_pci_device_index(u32 dev, u32 index_reg, u32 type, u32 length)
154 print_debug_pci_dev(dev);
156 print_debug(" index reg: "); print_debug_hex16(index_reg); print_debug(" type: "); print_debug_hex8(type);
160 for(i = 0; i < length; i++) {
162 if ((i & 0x0f) == 0) {
163 printk(BIOS_DEBUG, "\n%02x:",i);
165 val = pci_read_config32_index(dev, index_reg, i|type);
166 printk(BIOS_DEBUG, " %08x", val);
172 static void dump_pci_devices(void)
175 for(dev = PCI_DEV(0, 0, 0);
176 dev <= PCI_DEV(0xff, 0x1f, 0x7);
177 dev += PCI_DEV(0,0,1)) {
179 id = pci_read_config32(dev, PCI_VENDOR_ID);
180 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
181 (((id >> 16) & 0xffff) == 0xffff) ||
182 (((id >> 16) & 0xffff) == 0x0000)) {
185 dump_pci_device(dev);
187 if(((dev>>12) & 0x07) == 0) {
189 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
190 if((hdr_type & 0x80) != 0x80) {
191 dev += PCI_DEV(0,0,7);
198 static void dump_pci_devices_on_bus(u32 busn)
201 for(dev = PCI_DEV(busn, 0, 0);
202 dev <= PCI_DEV(busn, 0x1f, 0x7);
203 dev += PCI_DEV(0,0,1)) {
205 id = pci_read_config32(dev, PCI_VENDOR_ID);
206 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
207 (((id >> 16) & 0xffff) == 0xffff) ||
208 (((id >> 16) & 0xffff) == 0x0000)) {
211 dump_pci_device(dev);
213 if(((dev>>12) & 0x07) == 0) {
215 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
216 if((hdr_type & 0x80) != 0x80) {
217 dev += PCI_DEV(0,0,7);
223 #if CONFIG_DEBUG_SMBUS
225 static void dump_spd_registers(const struct mem_controller *ctrl)
229 for(i = 0; i < DIMM_SOCKETS; i++) {
231 device = ctrl->spd_addr[i];
234 printk(BIOS_DEBUG, "dimm: %02x.0: %02x", i, device);
235 for(j = 0; j < 128; j++) {
238 if ((j & 0xf) == 0) {
239 printk(BIOS_DEBUG, "\n%02x: ", j);
241 status = smbus_read_byte(device, j);
245 byte = status & 0xff;
246 printk(BIOS_DEBUG, "%02x ", byte);
250 device = ctrl->spd_addr[i+DIMM_SOCKETS];
253 printk(BIOS_DEBUG, "dimm: %02x.1: %02x", i, device);
254 for(j = 0; j < 128; j++) {
257 if ((j & 0xf) == 0) {
258 printk(BIOS_DEBUG, "\n%02x: ", j);
260 status = smbus_read_byte(device, j);
264 byte = status & 0xff;
265 printk(BIOS_DEBUG, "%02x ", byte);
271 static void dump_smbus_registers(void)
275 for(device = 1; device < 0x80; device++) {
277 if( smbus_read_byte(device, 0) < 0 ) continue;
278 printk(BIOS_DEBUG, "smbus: %02x", device);
279 for(j = 0; j < 256; j++) {
282 status = smbus_read_byte(device, j);
286 if ((j & 0xf) == 0) {
287 printk(BIOS_DEBUG, "\n%02x: ",j);
289 byte = status & 0xff;
290 printk(BIOS_DEBUG, "%02x ", byte);
296 static void dump_io_resources(u32 port)
301 printk(BIOS_DEBUG, "%04x:\n", port);
304 if ((i & 0x0f) == 0) {
305 printk(BIOS_DEBUG, "%02x:", i);
308 printk(BIOS_DEBUG, " %02x",val);
309 if ((i & 0x0f) == 0x0f) {
316 static void dump_mem(u32 start, u32 end)
319 print_debug("dump_mem:");
320 for(i=start;i<end;i++) {
322 printk(BIOS_DEBUG, "\n%08x:", i);
324 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));