AMD binaryPI: Use madt_ioapic_from_hw()
[coreboot.git] / util / showdevicetree / showdt.c
blob961a69d9a3ba38e8d2b6d390f7f964e1e3477ca4
1 /* Compile and dump the device tree */
2 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdio.h>
4 /* you can't include string.h due to conflicts with coreboot prototypes. */
5 void *memcpy(void *m1, void *m2, size_t s);
7 struct device_operations default_dev_ops_root = {
8 .read_resources = NULL,
9 .set_resources = NULL,
10 .enable_resources = NULL,
11 .init = NULL,
12 .scan_bus = NULL,
13 .reset_bus = NULL,
16 extern struct device dev_root;
17 struct device *all_devices = &dev_root;
19 const char mainboard_name[] = "showdt";
22 * Warning: This function uses a static buffer. Don't call it more than once
23 * from the same print statement!
25 const char *dev_path(device_t dev)
27 static char buffer[DEVICE_PATH_MAX];
29 buffer[0] = '\0';
30 if (!dev) {
31 memcpy(buffer, "<null>", 7);
32 } else {
33 switch(dev->path.type) {
34 case DEVICE_PATH_ROOT:
35 memcpy(buffer, "Root Device", 12);
36 break;
37 case DEVICE_PATH_PCI:
38 #if CONFIG_PCI_BUS_SEGN_BITS
39 sprintf(buffer, "PCI: %04x:%02x:%02x.%01x",
40 dev->bus->secondary >> 8,
41 dev->bus->secondary & 0xff,
42 PCI_SLOT(dev->path.pci.devfn),
43 PCI_FUNC(dev->path.pci.devfn));
44 #else
45 sprintf(buffer, "PCI: %02x:%02x.%01x",
46 dev->bus->secondary,
47 PCI_SLOT(dev->path.pci.devfn),
48 PCI_FUNC(dev->path.pci.devfn));
49 #endif
50 break;
51 case DEVICE_PATH_PNP:
52 sprintf(buffer, "PNP: %04x.%01x",
53 dev->path.pnp.port, dev->path.pnp.device);
54 break;
55 case DEVICE_PATH_I2C:
56 sprintf(buffer, "I2C: %02x:%02x",
57 dev->bus->secondary,
58 dev->path.i2c.device);
59 break;
60 case DEVICE_PATH_APIC:
61 sprintf(buffer, "APIC: %02x",
62 dev->path.apic.apic_id);
63 break;
64 case DEVICE_PATH_IOAPIC:
65 sprintf(buffer, "IOAPIC: %02x",
66 dev->path.ioapic.ioapic_id);
67 break;
68 case DEVICE_PATH_DOMAIN:
69 sprintf(buffer, "DOMAIN: %04x",
70 dev->path.domain.domain);
71 break;
72 case DEVICE_PATH_CPU_CLUSTER:
73 sprintf(buffer, "CPU_CLUSTER: %01x",
74 dev->path.cpu_cluster.cluster);
75 break;
76 case DEVICE_PATH_CPU:
77 sprintf(buffer, "CPU: %02x", dev->path.cpu.id);
78 break;
79 case DEVICE_PATH_CPU_BUS:
80 sprintf(buffer, "CPU_BUS: %02x", dev->path.cpu_bus.id);
81 break;
82 case DEVICE_PATH_MMIO:
83 sprintf(buffer, "MMIO: %08x", dev->path.mmio.addr);
84 break;
85 default:
86 printf("Unknown device path type: %d\n",
87 dev->path.type);
88 break;
91 return buffer;
95 void show_devs_tree(struct device *dev, int debug_level, int depth, int linknum)
97 char depth_str[20] = "";
98 int i;
99 struct device *sibling;
100 struct bus *link;
102 for (i = 0; i < depth; i++)
103 depth_str[i] = ' ';
104 depth_str[i] = '\0';
106 printf("%s%s: enabled %d%s\n",
107 depth_str, dev_path(dev), dev->enabled,
108 dev->chip_ops ? ":has a chip":"");
110 for (link = dev->link_list; link; link = link->next) {
111 for (sibling = link->children; sibling;
112 sibling = sibling->sibling)
113 show_devs_tree(sibling, debug_level, depth + 1, i);
117 void show_all_devs_tree(int debug_level, const char *msg)
119 printf("Show all devs in tree form...%s\n", msg);
121 show_devs_tree(all_devices, debug_level, 0, -1);
124 void show_devs_subtree(struct device *root, int debug_level, const char *msg)
126 printf("Show all devs in subtree %s...%s\n",
127 dev_path(root), msg);
129 printf("%s\n", msg);
130 show_devs_tree(root, debug_level, 0, -1);
133 void show_all_devs(int debug_level, const char *msg)
135 struct device *dev;
137 printf("Show all devs...%s\n", msg);
138 for (dev = all_devices; dev; dev = dev->next) {
139 printf("%s: enabled %d%s\n",
140 dev_path(dev), dev->enabled,
141 dev->chip_ops ? ":has a chip":"");
145 main()
147 show_all_devs(1, "");
148 show_all_devs_tree(1, "");
152 * Example: (yank this and paste into M-x compile in emacs)
153 * or tail -2 showdt.c | head -1 |sh
154 * or whatever.
155 cc -I ../src -I ../src/include -I ../src/arch/arm/include/ -include build/mainboard/google/snow/static.c showdt.c