blob: c085c874c94cde5e7e50b80e745ff1cf5e00c110 [file] [log] [blame]
Martin Roth5474eb12018-05-26 19:22:33 -06001/*
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älkki93b4ed92012-04-18 21:13:33 +030013
14#include <device/pci_def.h>
15#include <console/console.h>
16#include <stdlib.h>
17#include <arch/io.h>
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030018#include <spd.h>
19
20#include "raminit.h"
21#include "debug.h"
22
Stefan Reinauerb15975b2011-10-21 12:57:59 -070023/*
24 * generic debug code, used by mainboard specific romstage.c
25 *
26 */
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030027
28void print_debug_pci_dev(unsigned dev)
Stefan Reinauerb15975b2011-10-21 12:57:59 -070029{
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080030 printk(BIOS_DEBUG, "PCI: %02x:%02x.%x",
31 (dev >> 16) & 0xff, (dev >> 11) & 0x1f, (dev >> 8) & 7);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070032}
33
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030034void print_pci_devices(void)
Stefan Reinauerb15975b2011-10-21 12:57:59 -070035{
Antonello Dettori7ea0fe52016-09-03 10:45:33 +020036 pci_devfn_t dev;
Elyes HAOUAS12df9502016-08-23 21:29:48 +020037 for (dev = PCI_DEV(0, 0, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070038 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 Reinauer65b72ab2015-01-05 12:59:54 -080048 printk(BIOS_DEBUG, "\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -070049 }
50}
51
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030052void dump_pci_device(unsigned dev)
Stefan Reinauerb15975b2011-10-21 12:57:59 -070053{
54 int i;
55 print_debug_pci_dev(dev);
56
Elyes HAOUAS12df9502016-08-23 21:29:48 +020057 for (i = 0; i < 256; i++) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -070058 unsigned char val;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080059 if ((i & 0x0f) == 0)
Elyes HAOUAS93095522016-09-17 21:05:10 +020060 printk(BIOS_DEBUG, "\n%02x:",i);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070061 val = pci_read_config8(dev, i);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070062 printk(BIOS_DEBUG, " %02x", val);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070063 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080064 printk(BIOS_DEBUG, "\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -070065}
66
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +030067void dump_pci_devices(void)
Stefan Reinauerb15975b2011-10-21 12:57:59 -070068{
Antonello Dettori7ea0fe52016-09-03 10:45:33 +020069 pci_devfn_t dev;
Elyes HAOUAS12df9502016-08-23 21:29:48 +020070 for (dev = PCI_DEV(0, 0, 0);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070071 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älkki93b4ed92012-04-18 21:13:33 +030084void dump_pci_devices_on_bus(unsigned busn)
Stefan Reinauerb15975b2011-10-21 12:57:59 -070085{
Antonello Dettori7ea0fe52016-09-03 10:45:33 +020086 pci_devfn_t dev;
Elyes HAOUAS93095522016-09-17 21:05:10 +020087 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 HAOUAS22710a62016-09-20 19:16:55 +020093 (((id >> 16) & 0xffff) == 0xffff) ||
94 (((id >> 16) & 0xffff) == 0x0000)) {
Elyes HAOUAS93095522016-09-17 21:05:10 +020095 continue;
96 }
97 dump_pci_device(dev);
98 }
Stefan Reinauerb15975b2011-10-21 12:57:59 -070099}
100
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +0300101void dump_spd_registers(const struct mem_controller *ctrl)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700102{
103 int i;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800104 printk(BIOS_DEBUG, "\n");
Elyes HAOUAS12df9502016-08-23 21:29:48 +0200105 for (i = 0; i < 4; i++) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700106 unsigned device;
107 device = ctrl->channel0[i];
108 if (device) {
109 int j;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700110 printk(BIOS_DEBUG, "dimm: %02x.0: %02x", i, device);
Elyes HAOUAS12df9502016-08-23 21:29:48 +0200111 for (j = 0; j < 128; j++) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700112 int status;
113 unsigned char byte;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800114 if ((j & 0xf) == 0)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700115 printk(BIOS_DEBUG, "\n%02x: ", j);
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +0300116 status = spd_read_byte(device, j);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700117 if (status < 0) {
118 break;
119 }
120 byte = status & 0xff;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700121 printk(BIOS_DEBUG, "%02x ", byte);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700122 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800123 printk(BIOS_DEBUG, "\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700124 }
125 device = ctrl->channel1[i];
126 if (device) {
127 int j;
Elyes HAOUAS93095522016-09-17 21:05:10 +0200128 printk(BIOS_DEBUG, "dimm: %02x.1: %02x", i, device);
Elyes HAOUAS12df9502016-08-23 21:29:48 +0200129 for (j = 0; j < 128; j++) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700130 int status;
131 unsigned char byte;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800132 if ((j & 0xf) == 0)
Elyes HAOUAS93095522016-09-17 21:05:10 +0200133 printk(BIOS_DEBUG, "\n%02x: ", j);
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +0300134 status = spd_read_byte(device, j);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700135 if (status < 0) {
136 break;
137 }
138 byte = status & 0xff;
Elyes HAOUAS93095522016-09-17 21:05:10 +0200139 printk(BIOS_DEBUG, "%02x ", byte);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700140 }
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800141 printk(BIOS_DEBUG, "\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700142 }
143 }
144}
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +0300145void dump_smbus_registers(void)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700146{
147 unsigned device;
Elyes HAOUAS93095522016-09-17 21:05:10 +0200148 printk(BIOS_DEBUG, "\n");
149 for (device = 1; device < 0x80; device++) {
150 int j;
Elyes HAOUAS12df9502016-08-23 21:29:48 +0200151 if ( spd_read_byte(device, 0) < 0 ) continue;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700152 printk(BIOS_DEBUG, "smbus: %02x", device);
Elyes HAOUAS93095522016-09-17 21:05:10 +0200153 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 Reinauerb15975b2011-10-21 12:57:59 -0700158 break;
Elyes HAOUAS93095522016-09-17 21:05:10 +0200159 }
160 if ((j & 0xf) == 0)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700161 printk(BIOS_DEBUG, "\n%02x: ",j);
Elyes HAOUAS93095522016-09-17 21:05:10 +0200162 byte = status & 0xff;
163 printk(BIOS_DEBUG, "%02x ", byte);
164 }
165 printk(BIOS_DEBUG, "\n");
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700166 }
167}
168
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +0300169void dump_io_resources(unsigned port)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700170{
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700171 int i;
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700172 printk(BIOS_DEBUG, "%04x:\n", port);
Elyes HAOUAS93095522016-09-17 21:05:10 +0200173 for (i = 0; i < 256; i++) {
174 uint8_t val;
175 if ((i & 0x0f) == 0)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700176 printk(BIOS_DEBUG, "%02x:", i);
Elyes HAOUAS93095522016-09-17 21:05:10 +0200177 val = inb(port);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700178 printk(BIOS_DEBUG, " %02x",val);
Elyes HAOUAS93095522016-09-17 21:05:10 +0200179 if ((i & 0x0f) == 0x0f) {
180 printk(BIOS_DEBUG, "\n");
181 }
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700182 port++;
Elyes HAOUAS93095522016-09-17 21:05:10 +0200183 }
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700184}
185
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +0300186void dump_mem(unsigned start, unsigned end)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700187{
Elyes HAOUAS93095522016-09-17 21:05:10 +0200188 unsigned i;
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800189 printk(BIOS_DEBUG, "dump_mem:");
Elyes HAOUAS93095522016-09-17 21:05:10 +0200190 for (i = start; i < end; i++) {
Elyes HAOUAS12df9502016-08-23 21:29:48 +0200191 if ((i & 0xf)==0)
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700192 printk(BIOS_DEBUG, "\n%08x:", i);
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700193 printk(BIOS_DEBUG, " %02x", (unsigned char)*((unsigned char *)i));
Elyes HAOUAS93095522016-09-17 21:05:10 +0200194 }
195 printk(BIOS_DEBUG, "\n");
Kyösti Mälkki93b4ed92012-04-18 21:13:33 +0300196}