Martin Roth | 5474eb1 | 2018-05-26 19:22:33 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 13 | |
| 14 | #include <device/pci_def.h> |
| 15 | #include <console/console.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <arch/io.h> |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 18 | #include <spd.h> |
| 19 | |
| 20 | #include "raminit.h" |
| 21 | #include "debug.h" |
| 22 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 23 | /* |
| 24 | * generic debug code, used by mainboard specific romstage.c |
| 25 | * |
| 26 | */ |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 27 | |
| 28 | void print_debug_pci_dev(unsigned dev) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 29 | { |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 30 | printk(BIOS_DEBUG, "PCI: %02x:%02x.%x", |
| 31 | (dev >> 16) & 0xff, (dev >> 11) & 0x1f, (dev >> 8) & 7); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 34 | void print_pci_devices(void) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 35 | { |
Antonello Dettori | 7ea0fe5 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 36 | pci_devfn_t dev; |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 37 | for (dev = PCI_DEV(0, 0, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 38 | dev <= PCI_DEV(0xff, 0x1f, 0x7); |
| 39 | dev += PCI_DEV(0,0,1)) { |
| 40 | uint32_t id; |
| 41 | id = pci_read_config32(dev, PCI_VENDOR_ID); |
| 42 | if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) || |
| 43 | (((id >> 16) & 0xffff) == 0xffff) || |
| 44 | (((id >> 16) & 0xffff) == 0x0000)) { |
| 45 | continue; |
| 46 | } |
| 47 | print_debug_pci_dev(dev); |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 48 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 52 | void dump_pci_device(unsigned dev) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 53 | { |
| 54 | int i; |
| 55 | print_debug_pci_dev(dev); |
| 56 | |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 57 | for (i = 0; i < 256; i++) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 58 | unsigned char val; |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 59 | if ((i & 0x0f) == 0) |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 60 | printk(BIOS_DEBUG, "\n%02x:",i); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 61 | val = pci_read_config8(dev, i); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 62 | printk(BIOS_DEBUG, " %02x", val); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 63 | } |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 64 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 67 | void dump_pci_devices(void) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 68 | { |
Antonello Dettori | 7ea0fe5 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 69 | pci_devfn_t dev; |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 70 | for (dev = PCI_DEV(0, 0, 0); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 71 | dev <= PCI_DEV(0xff, 0x1f, 0x7); |
| 72 | dev += PCI_DEV(0,0,1)) { |
| 73 | uint32_t id; |
| 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)) { |
| 78 | continue; |
| 79 | } |
| 80 | dump_pci_device(dev); |
| 81 | } |
| 82 | } |
| 83 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 84 | void dump_pci_devices_on_bus(unsigned busn) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 85 | { |
Antonello Dettori | 7ea0fe5 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 86 | pci_devfn_t dev; |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 87 | for (dev = PCI_DEV(busn, 0, 0); |
| 88 | dev <= PCI_DEV(busn, 0x1f, 0x7); |
| 89 | dev += PCI_DEV(0,0,1)) { |
| 90 | uint32_t id; |
| 91 | id = pci_read_config32(dev, PCI_VENDOR_ID); |
| 92 | if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) || |
Elyes HAOUAS | 22710a6 | 2016-09-20 19:16:55 +0200 | [diff] [blame] | 93 | (((id >> 16) & 0xffff) == 0xffff) || |
| 94 | (((id >> 16) & 0xffff) == 0x0000)) { |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 95 | continue; |
| 96 | } |
| 97 | dump_pci_device(dev); |
| 98 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 101 | void dump_spd_registers(const struct mem_controller *ctrl) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 102 | { |
| 103 | int i; |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 104 | printk(BIOS_DEBUG, "\n"); |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 105 | for (i = 0; i < 4; i++) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 106 | unsigned device; |
| 107 | device = ctrl->channel0[i]; |
| 108 | if (device) { |
| 109 | int j; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 110 | printk(BIOS_DEBUG, "dimm: %02x.0: %02x", i, device); |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 111 | for (j = 0; j < 128; j++) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 112 | int status; |
| 113 | unsigned char byte; |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 114 | if ((j & 0xf) == 0) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 115 | printk(BIOS_DEBUG, "\n%02x: ", j); |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 116 | status = spd_read_byte(device, j); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 117 | if (status < 0) { |
| 118 | break; |
| 119 | } |
| 120 | byte = status & 0xff; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 121 | printk(BIOS_DEBUG, "%02x ", byte); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 122 | } |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 123 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 124 | } |
| 125 | device = ctrl->channel1[i]; |
| 126 | if (device) { |
| 127 | int j; |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 128 | printk(BIOS_DEBUG, "dimm: %02x.1: %02x", i, device); |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 129 | for (j = 0; j < 128; j++) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 130 | int status; |
| 131 | unsigned char byte; |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 132 | if ((j & 0xf) == 0) |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 133 | printk(BIOS_DEBUG, "\n%02x: ", j); |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 134 | status = spd_read_byte(device, j); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 135 | if (status < 0) { |
| 136 | break; |
| 137 | } |
| 138 | byte = status & 0xff; |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 139 | printk(BIOS_DEBUG, "%02x ", byte); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 140 | } |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 141 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 145 | void dump_smbus_registers(void) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 146 | { |
| 147 | unsigned device; |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 148 | printk(BIOS_DEBUG, "\n"); |
| 149 | for (device = 1; device < 0x80; device++) { |
| 150 | int j; |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 151 | if ( spd_read_byte(device, 0) < 0 ) continue; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 152 | printk(BIOS_DEBUG, "smbus: %02x", device); |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 153 | for (j = 0; j < 256; j++) { |
| 154 | int status; |
| 155 | unsigned char byte; |
| 156 | status = spd_read_byte(device, j); |
| 157 | if (status < 0) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 158 | break; |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 159 | } |
| 160 | if ((j & 0xf) == 0) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 161 | printk(BIOS_DEBUG, "\n%02x: ",j); |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 162 | byte = status & 0xff; |
| 163 | printk(BIOS_DEBUG, "%02x ", byte); |
| 164 | } |
| 165 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 169 | void dump_io_resources(unsigned port) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 170 | { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 171 | int i; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 172 | printk(BIOS_DEBUG, "%04x:\n", port); |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 173 | for (i = 0; i < 256; i++) { |
| 174 | uint8_t val; |
| 175 | if ((i & 0x0f) == 0) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 176 | printk(BIOS_DEBUG, "%02x:", i); |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 177 | val = inb(port); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 178 | printk(BIOS_DEBUG, " %02x",val); |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 179 | if ((i & 0x0f) == 0x0f) { |
| 180 | printk(BIOS_DEBUG, "\n"); |
| 181 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 182 | port++; |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 183 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 186 | void dump_mem(unsigned start, unsigned end) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 187 | { |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 188 | unsigned i; |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 189 | printk(BIOS_DEBUG, "dump_mem:"); |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 190 | for (i = start; i < end; i++) { |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 191 | if ((i & 0xf)==0) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 192 | printk(BIOS_DEBUG, "\n%08x:", i); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 193 | printk(BIOS_DEBUG, " %02x", (unsigned char)*((unsigned char *)i)); |
Elyes HAOUAS | 9309552 | 2016-09-17 21:05:10 +0200 | [diff] [blame] | 194 | } |
| 195 | printk(BIOS_DEBUG, "\n"); |
Kyösti Mälkki | 93b4ed9 | 2012-04-18 21:13:33 +0300 | [diff] [blame] | 196 | } |