blob: 32a14289fb58bead1d7ff8b0bb3ddf95719321ee [file] [log] [blame]
Yinghai Lu70093f72004-07-01 03:55:03 +00001/*
Stefan Reinauer38f147e2010-02-08 12:20:50 +00002 * generic debug code, used by mainboard specific romstage.c
Yinghai Lu70093f72004-07-01 03:55:03 +00003 *
4 */
5#if 1
6static void print_debug_pci_dev(unsigned dev)
7{
Stefan Reinauer65b72ab2015-01-05 12:59:54 -08008 printk(BIOS_DEBUG, "PCI: %02x:%02x.%x",
9 (dev >> 16) & 0xff, (dev >> 11) & 0x1f, (dev >> 8) & 7);
Yinghai Lu70093f72004-07-01 03:55:03 +000010}
11
Stefan Reinauer23836e22010-04-15 12:39:29 +000012static inline void print_pci_devices(void)
Yinghai Lu70093f72004-07-01 03:55:03 +000013{
14 device_t dev;
Stefan Reinauer14e22772010-04-27 06:56:47 +000015 for(dev = PCI_DEV(0, 0, 0);
16 dev <= PCI_DEV(0xff, 0x1f, 0x7);
Yinghai Lu70093f72004-07-01 03:55:03 +000017 dev += PCI_DEV(0,0,1)) {
18 uint32_t id;
19 id = pci_read_config32(dev, PCI_VENDOR_ID);
20 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
21 (((id >> 16) & 0xffff) == 0xffff) ||
22 (((id >> 16) & 0xffff) == 0x0000)) {
23 continue;
24 }
25 print_debug_pci_dev(dev);
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080026 printk(BIOS_DEBUG, "\n");
Yinghai Lu70093f72004-07-01 03:55:03 +000027 }
28}
29
30static void dump_pci_device(unsigned dev)
31{
32 int i;
33 print_debug_pci_dev(dev);
Stefan Reinauer14e22772010-04-27 06:56:47 +000034
arch import user (historical)6ca76362005-07-06 17:17:25 +000035 for(i = 0; i < 256; i++) {
Yinghai Lu70093f72004-07-01 03:55:03 +000036 unsigned char val;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080037 if ((i & 0x0f) == 0)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000038 printk(BIOS_DEBUG, "\n%02x:",i);
Yinghai Lu70093f72004-07-01 03:55:03 +000039 val = pci_read_config8(dev, i);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000040 printk(BIOS_DEBUG, " %02x", val);
Yinghai Lu70093f72004-07-01 03:55:03 +000041 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080042 printk(BIOS_DEBUG, "\n");
Yinghai Lu70093f72004-07-01 03:55:03 +000043}
44
Stefan Reinauer23836e22010-04-15 12:39:29 +000045static inline void dump_pci_devices(void)
Yinghai Lu70093f72004-07-01 03:55:03 +000046{
47 device_t dev;
Stefan Reinauer14e22772010-04-27 06:56:47 +000048 for(dev = PCI_DEV(0, 0, 0);
49 dev <= PCI_DEV(0xff, 0x1f, 0x7);
Yinghai Lu70093f72004-07-01 03:55:03 +000050 dev += PCI_DEV(0,0,1)) {
51 uint32_t id;
52 id = pci_read_config32(dev, PCI_VENDOR_ID);
53 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
54 (((id >> 16) & 0xffff) == 0xffff) ||
55 (((id >> 16) & 0xffff) == 0x0000)) {
56 continue;
57 }
58 dump_pci_device(dev);
59 }
60}
61
Stefan Reinauer23836e22010-04-15 12:39:29 +000062static inline void dump_pci_devices_on_bus(unsigned busn)
arch import user (historical)6ca76362005-07-06 17:17:25 +000063{
64 device_t dev;
65 for(dev = PCI_DEV(busn, 0, 0);
66 dev <= PCI_DEV(busn, 0x1f, 0x7);
67 dev += PCI_DEV(0,0,1)) {
68 uint32_t id;
69 id = pci_read_config32(dev, PCI_VENDOR_ID);
70 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
71 (((id >> 16) & 0xffff) == 0xffff) ||
72 (((id >> 16) & 0xffff) == 0x0000)) {
73 continue;
74 }
75 dump_pci_device(dev);
76 }
77}
78
Stefan Reinauer23836e22010-04-15 12:39:29 +000079static inline void dump_spd_registers(const struct mem_controller *ctrl)
Yinghai Lu70093f72004-07-01 03:55:03 +000080{
81 int i;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080082 printk(BIOS_DEBUG, "\n");
Yinghai Lu70093f72004-07-01 03:55:03 +000083 for(i = 0; i < 4; i++) {
84 unsigned device;
85 device = ctrl->channel0[i];
86 if (device) {
87 int j;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000088 printk(BIOS_DEBUG, "dimm: %02x.0: %02x", i, device);
arch import user (historical)6ca76362005-07-06 17:17:25 +000089 for(j = 0; j < 128; j++) {
Yinghai Lu70093f72004-07-01 03:55:03 +000090 int status;
91 unsigned char byte;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080092 if ((j & 0xf) == 0)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000093 printk(BIOS_DEBUG, "\n%02x: ", j);
Yinghai Lu70093f72004-07-01 03:55:03 +000094 status = smbus_read_byte(device, j);
95 if (status < 0) {
Yinghai Lu70093f72004-07-01 03:55:03 +000096 break;
97 }
98 byte = status & 0xff;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000099 printk(BIOS_DEBUG, "%02x ", byte);
Yinghai Lu70093f72004-07-01 03:55:03 +0000100 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800101 printk(BIOS_DEBUG, "\n");
Yinghai Lu70093f72004-07-01 03:55:03 +0000102 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000103 device = ctrl->channel1[i];
104 if (device) {
105 int j;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000106 printk(BIOS_DEBUG, "dimm: %02x.1: %02x", i, device);
arch import user (historical)6ca76362005-07-06 17:17:25 +0000107 for(j = 0; j < 128; j++) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000108 int status;
109 unsigned char byte;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800110 if ((j & 0xf) == 0)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000111 printk(BIOS_DEBUG, "\n%02x: ", j);
Yinghai Lu70093f72004-07-01 03:55:03 +0000112 status = smbus_read_byte(device, j);
113 if (status < 0) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000114 break;
115 }
116 byte = status & 0xff;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000117 printk(BIOS_DEBUG, "%02x ", byte);
Yinghai Lu70093f72004-07-01 03:55:03 +0000118 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800119 printk(BIOS_DEBUG, "\n");
Yinghai Lu70093f72004-07-01 03:55:03 +0000120 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000121 }
122}
Stefan Reinauer23836e22010-04-15 12:39:29 +0000123static inline void dump_smbus_registers(void)
Yinghai Lu70093f72004-07-01 03:55:03 +0000124{
arch import user (historical)6ca76362005-07-06 17:17:25 +0000125 unsigned device;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800126 printk(BIOS_DEBUG, "\n");
arch import user (historical)6ca76362005-07-06 17:17:25 +0000127 for(device = 1; device < 0x80; device++) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000128 int j;
arch import user (historical)6ca76362005-07-06 17:17:25 +0000129 if( smbus_read_byte(device, 0) < 0 ) continue;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000130 printk(BIOS_DEBUG, "smbus: %02x", device);
Yinghai Lu70093f72004-07-01 03:55:03 +0000131 for(j = 0; j < 256; j++) {
Stefan Reinauer14e22772010-04-27 06:56:47 +0000132 int status;
Yinghai Lu70093f72004-07-01 03:55:03 +0000133 unsigned char byte;
arch import user (historical)6ca76362005-07-06 17:17:25 +0000134 status = smbus_read_byte(device, j);
135 if (status < 0) {
136 break;
137 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800138 if ((j & 0xf) == 0)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000139 printk(BIOS_DEBUG, "\n%02x: ",j);
Yinghai Lu70093f72004-07-01 03:55:03 +0000140 byte = status & 0xff;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000141 printk(BIOS_DEBUG, "%02x ", byte);
Yinghai Lu70093f72004-07-01 03:55:03 +0000142 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800143 printk(BIOS_DEBUG, "\n");
Stefan Reinauer14e22772010-04-27 06:56:47 +0000144 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000145}
arch import user (historical)6ca76362005-07-06 17:17:25 +0000146
Stefan Reinauer14e22772010-04-27 06:56:47 +0000147static inline void dump_io_resources(unsigned port)
arch import user (historical)6ca76362005-07-06 17:17:25 +0000148{
149
150 int i;
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000151 printk(BIOS_DEBUG, "%04x:\n", port);
arch import user (historical)6ca76362005-07-06 17:17:25 +0000152 for(i=0;i<256;i++) {
153 uint8_t val;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800154 if ((i & 0x0f) == 0)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000155 printk(BIOS_DEBUG, "%02x:", i);
arch import user (historical)6ca76362005-07-06 17:17:25 +0000156 val = inb(port);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000157 printk(BIOS_DEBUG, " %02x",val);
arch import user (historical)6ca76362005-07-06 17:17:25 +0000158 if ((i & 0x0f) == 0x0f) {
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800159 printk(BIOS_DEBUG, "\n");
arch import user (historical)6ca76362005-07-06 17:17:25 +0000160 }
161 port++;
162 }
163}
164
Stefan Reinauer23836e22010-04-15 12:39:29 +0000165static inline void dump_mem(unsigned start, unsigned end)
arch import user (historical)6ca76362005-07-06 17:17:25 +0000166{
167 unsigned i;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800168 printk(BIOS_DEBUG, "dump_mem:");
arch import user (historical)6ca76362005-07-06 17:17:25 +0000169 for(i=start;i<end;i++) {
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800170 if((i & 0xf)==0)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000171 printk(BIOS_DEBUG, "\n%08x:", i);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000172 printk(BIOS_DEBUG, " %02x", (unsigned char)*((unsigned char *)i));
arch import user (historical)6ca76362005-07-06 17:17:25 +0000173 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800174 printk(BIOS_DEBUG, "\n");
arch import user (historical)6ca76362005-07-06 17:17:25 +0000175 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000176#endif