2 * Compile and dump the device tree
4 * Copyright 2013 Google Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 /* you can't include string.h due to conflicts with coreboot prototypes. */
17 void *memcpy(void *m1
, void *m2
, size_t s
);
19 struct device_operations default_dev_ops_root
= {
20 .read_resources
= NULL
,
21 .set_resources
= NULL
,
22 .enable_resources
= NULL
,
28 extern struct device dev_root
;
29 struct device
*all_devices
= &dev_root
;
31 const char mainboard_name
[] = "showdt";
34 * Warning: This function uses a static buffer. Don't call it more than once
35 * from the same print statement!
37 const char *dev_path(device_t dev
)
39 static char buffer
[DEVICE_PATH_MAX
];
43 memcpy(buffer
, "<null>", 7);
45 switch(dev
->path
.type
) {
46 case DEVICE_PATH_ROOT
:
47 memcpy(buffer
, "Root Device", 12);
50 #if CONFIG_PCI_BUS_SEGN_BITS
51 sprintf(buffer
, "PCI: %04x:%02x:%02x.%01x",
52 dev
->bus
->secondary
>> 8,
53 dev
->bus
->secondary
& 0xff,
54 PCI_SLOT(dev
->path
.pci
.devfn
),
55 PCI_FUNC(dev
->path
.pci
.devfn
));
57 sprintf(buffer
, "PCI: %02x:%02x.%01x",
59 PCI_SLOT(dev
->path
.pci
.devfn
),
60 PCI_FUNC(dev
->path
.pci
.devfn
));
64 sprintf(buffer
, "PNP: %04x.%01x",
65 dev
->path
.pnp
.port
, dev
->path
.pnp
.device
);
68 sprintf(buffer
, "I2C: %02x:%02x",
70 dev
->path
.i2c
.device
);
72 case DEVICE_PATH_APIC
:
73 sprintf(buffer
, "APIC: %02x",
74 dev
->path
.apic
.apic_id
);
76 case DEVICE_PATH_IOAPIC
:
77 sprintf(buffer
, "IOAPIC: %02x",
78 dev
->path
.ioapic
.ioapic_id
);
80 case DEVICE_PATH_DOMAIN
:
81 sprintf(buffer
, "DOMAIN: %04x",
82 dev
->path
.domain
.domain
);
84 case DEVICE_PATH_CPU_CLUSTER
:
85 sprintf(buffer
, "CPU_CLUSTER: %01x",
86 dev
->path
.cpu_cluster
.cluster
);
89 sprintf(buffer
, "CPU: %02x", dev
->path
.cpu
.id
);
91 case DEVICE_PATH_CPU_BUS
:
92 sprintf(buffer
, "CPU_BUS: %02x", dev
->path
.cpu_bus
.id
);
94 case DEVICE_PATH_MMIO
:
95 sprintf(buffer
, "MMIO: %08x", dev
->path
.mmio
.addr
);
98 printf("Unknown device path type: %d\n",
107 void show_devs_tree(struct device
*dev
, int debug_level
, int depth
, int linknum
)
109 char depth_str
[20] = "";
111 struct device
*sibling
;
114 for (i
= 0; i
< depth
; i
++)
118 printf("%s%s: enabled %d%s\n",
119 depth_str
, dev_path(dev
), dev
->enabled
,
120 dev
->chip_ops
? ":has a chip":"");
122 for (link
= dev
->link_list
; link
; link
= link
->next
) {
123 for (sibling
= link
->children
; sibling
;
124 sibling
= sibling
->sibling
)
125 show_devs_tree(sibling
, debug_level
, depth
+ 1, i
);
129 void show_all_devs_tree(int debug_level
, const char *msg
)
131 printf("Show all devs in tree form...%s\n", msg
);
133 show_devs_tree(all_devices
, debug_level
, 0, -1);
136 void show_devs_subtree(struct device
*root
, int debug_level
, const char *msg
)
138 printf("Show all devs in subtree %s...%s\n",
139 dev_path(root
), msg
);
142 show_devs_tree(root
, debug_level
, 0, -1);
145 void show_all_devs(int debug_level
, const char *msg
)
149 printf("Show all devs...%s\n", msg
);
150 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
151 printf("%s: enabled %d%s\n",
152 dev_path(dev
), dev
->enabled
,
153 dev
->chip_ops
? ":has a chip":"");
159 show_all_devs(1, "");
160 show_all_devs_tree(1, "");
164 * Example: (yank this and paste into M-x compile in emacs)
165 * or tail -2 showdt.c | head -1 |sh
167 cc -I ../src -I ../src/include -I ../src/arch/arm/include/ -include build/mainboard/google/snow/static.c showdt.c