1 /* Compile and dump the device tree */
2 /* SPDX-License-Identifier: GPL-2.0-only */
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
,
10 .enable_resources
= 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
];
31 memcpy(buffer
, "<null>", 7);
33 switch(dev
->path
.type
) {
34 case DEVICE_PATH_ROOT
:
35 memcpy(buffer
, "Root Device", 12);
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
));
45 sprintf(buffer
, "PCI: %02x:%02x.%01x",
47 PCI_SLOT(dev
->path
.pci
.devfn
),
48 PCI_FUNC(dev
->path
.pci
.devfn
));
52 sprintf(buffer
, "PNP: %04x.%01x",
53 dev
->path
.pnp
.port
, dev
->path
.pnp
.device
);
56 sprintf(buffer
, "I2C: %02x:%02x",
58 dev
->path
.i2c
.device
);
60 case DEVICE_PATH_APIC
:
61 sprintf(buffer
, "APIC: %02x",
62 dev
->path
.apic
.apic_id
);
64 case DEVICE_PATH_IOAPIC
:
65 sprintf(buffer
, "IOAPIC: %02x",
66 dev
->path
.ioapic
.ioapic_id
);
68 case DEVICE_PATH_DOMAIN
:
69 sprintf(buffer
, "DOMAIN: %04x",
70 dev
->path
.domain
.domain
);
72 case DEVICE_PATH_CPU_CLUSTER
:
73 sprintf(buffer
, "CPU_CLUSTER: %01x",
74 dev
->path
.cpu_cluster
.cluster
);
77 sprintf(buffer
, "CPU: %02x", dev
->path
.cpu
.id
);
79 case DEVICE_PATH_CPU_BUS
:
80 sprintf(buffer
, "CPU_BUS: %02x", dev
->path
.cpu_bus
.id
);
82 case DEVICE_PATH_MMIO
:
83 sprintf(buffer
, "MMIO: %08x", dev
->path
.mmio
.addr
);
86 printf("Unknown device path type: %d\n",
95 void show_devs_tree(struct device
*dev
, int debug_level
, int depth
, int linknum
)
97 char depth_str
[20] = "";
99 struct device
*sibling
;
102 for (i
= 0; i
< depth
; i
++)
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
);
130 show_devs_tree(root
, debug_level
, 0, -1);
133 void show_all_devs(int debug_level
, const char *msg
)
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":"");
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
155 cc -I ../src -I ../src/include -I ../src/arch/arm/include/ -include build/mainboard/google/snow/static.c showdt.c