xref: /aosp_15_r20/external/coreboot/src/northbridge/intel/i945/debug.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <spd.h>
4 #include <device/pci_ops.h>
5 #include <device/pci_def.h>
6 #include <device/smbus_host.h>
7 #include <console/console.h>
8 #include "i945.h"
9 
print_pci_devices(void)10 void print_pci_devices(void)
11 {
12 	pci_devfn_t dev;
13 	for (dev = PCI_DEV(0, 0, 0); dev <= PCI_DEV(0, 0x1f, 0x7); dev += PCI_DEV(0, 0, 1)) {
14 		uint32_t id;
15 		id = pci_read_config32(dev, PCI_VENDOR_ID);
16 		if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
17 			(((id >> 16) & 0xffff) == 0xffff) ||
18 			(((id >> 16) & 0xffff) == 0x0000)) {
19 			continue;
20 		}
21 		printk(BIOS_DEBUG, "PCI: %02x:%02x.%02x", (dev >> 20) & 0xff,
22 			(dev >> 15) & 0x1f, (dev >> 12) & 7);
23 		printk(BIOS_DEBUG, " [%04x:%04x]\n", id & 0xffff, id >> 16);
24 	}
25 }
26 
dump_pci_device(unsigned int dev)27 void dump_pci_device(unsigned int dev)
28 {
29 	int i;
30 
31 	printk(BIOS_DEBUG, "PCI: %02x:%02x.%02x\n", (dev >> 20) & 0xff, (dev >> 15) & 0x1f,
32 		(dev >> 12) & 7);
33 
34 	for (i = 0; i <= 255; i++) {
35 		unsigned char val;
36 		if ((i & 0x0f) == 0)
37 			printk(BIOS_DEBUG, "%02x:", i);
38 		val = pci_read_config8(dev, i);
39 		printk(BIOS_DEBUG, " %02x", val);
40 		if ((i & 0x0f) == 0x0f)
41 			printk(BIOS_DEBUG, "\n");
42 	}
43 }
44 
dump_pci_devices(void)45 void dump_pci_devices(void)
46 {
47 	pci_devfn_t dev;
48 	for (dev = PCI_DEV(0, 0, 0); dev <= PCI_DEV(0, 0x1f, 0x7); dev += PCI_DEV(0, 0, 1)) {
49 		uint32_t id;
50 		id = pci_read_config32(dev, PCI_VENDOR_ID);
51 		if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
52 			(((id >> 16) & 0xffff) == 0xffff) ||
53 			(((id >> 16) & 0xffff) == 0x0000)) {
54 			continue;
55 		}
56 		dump_pci_device(dev);
57 	}
58 }
59 
dump_spd_registers(u8 spd_map[4])60 void dump_spd_registers(u8 spd_map[4])
61 {
62 	for (unsigned int d = 0; d < 4; d++) {
63 		const unsigned int device = spd_map[d];
64 		if (device == 0)
65 			continue;
66 
67 		int status = 0;
68 		int i;
69 		printk(BIOS_DEBUG, "\ndimm %02x", device);
70 
71 		for (i = 0; (i < 256); i++) {
72 			if ((i % 16) == 0)
73 				printk(BIOS_DEBUG, "\n%02x: ", i);
74 			status = smbus_read_byte(device, i);
75 			if (status < 0) {
76 				printk(BIOS_DEBUG, "bad device: %02x\n", -status);
77 				break;
78 			}
79 			printk(BIOS_DEBUG, "%02x ", status);
80 		}
81 		printk(BIOS_DEBUG, "\n");
82 	}
83 }
84