blob: 7784ec02dea614c765eba9048b7a65720678b92d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassd9f9a892015-06-23 15:38:35 -06002/*
3 * Copyright (c) 2015 Google, Inc
Simon Glassd9f9a892015-06-23 15:38:35 -06004 */
5
6#include <common.h>
7#include <dm.h>
8#include <mapmem.h>
9#include <dm/root.h>
Masahiro Yamada77018de2017-06-22 17:10:11 +090010#include <dm/util.h>
Jean-Jacques Hiblot9bb6c7f2018-08-09 16:17:43 +020011#include <dm/uclass-internal.h>
Simon Glassd9f9a892015-06-23 15:38:35 -060012
13static void show_devices(struct udevice *dev, int depth, int last_flag)
14{
15 int i, is_last;
16 struct udevice *child;
Simon Glassf03341f2020-12-22 19:30:22 -070017 u32 flags = dev->flags;
Simon Glassd9f9a892015-06-23 15:38:35 -060018
Liviu Dudau764cae52018-10-15 10:03:06 +010019 /* print the first 20 characters to not break the tree-format. */
Simon Glassf03341f2020-12-22 19:30:22 -070020 printf(IS_ENABLED(CONFIG_SPL_BUILD) ? " %s %d [ %c ] %s " :
21 " %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name,
Jean-Jacques Hiblot9bb6c7f2018-08-09 16:17:43 +020022 dev_get_uclass_index(dev, NULL),
Simon Glassf03341f2020-12-22 19:30:22 -070023 flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
Simon Glassd9f9a892015-06-23 15:38:35 -060024
25 for (i = depth; i >= 0; i--) {
26 is_last = (last_flag >> i) & 1;
27 if (i) {
28 if (is_last)
29 printf(" ");
30 else
31 printf("| ");
32 } else {
33 if (is_last)
34 printf("`-- ");
35 else
36 printf("|-- ");
37 }
38 }
39
40 printf("%s\n", dev->name);
41
42 list_for_each_entry(child, &dev->child_head, sibling_node) {
43 is_last = list_is_last(&child->sibling_node, &dev->child_head);
44 show_devices(child, depth + 1, (last_flag << 1) | is_last);
45 }
46}
47
48void dm_dump_all(void)
49{
50 struct udevice *root;
51
52 root = dm_root();
53 if (root) {
Simon Glassdf604242018-12-05 18:42:52 -070054 printf(" Class Index Probed Driver Name\n");
Liviu Dudau764cae52018-10-15 10:03:06 +010055 printf("-----------------------------------------------------------\n");
Simon Glassd9f9a892015-06-23 15:38:35 -060056 show_devices(root, -1, 0);
57 }
58}
59
60/**
61 * dm_display_line() - Display information about a single device
62 *
63 * Displays a single line of information with an option prefix
64 *
65 * @dev: Device to display
66 */
Jean-Jacques Hiblot9bb6c7f2018-08-09 16:17:43 +020067static void dm_display_line(struct udevice *dev, int index)
Simon Glassd9f9a892015-06-23 15:38:35 -060068{
Patrick Delaunay68148972019-09-30 10:19:13 +020069 printf("%-3i %c %s @ %08lx", index,
Simon Glassd9f9a892015-06-23 15:38:35 -060070 dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
71 dev->name, (ulong)map_to_sysmem(dev));
Simon Glassf7eca612020-12-16 21:20:31 -070072 if (dev->sqq != -1)
73 printf(", seq %d", dev_seq(dev));
Simon Glassd9f9a892015-06-23 15:38:35 -060074 puts("\n");
75}
76
77void dm_dump_uclass(void)
78{
79 struct uclass *uc;
80 int ret;
81 int id;
82
83 for (id = 0; id < UCLASS_COUNT; id++) {
84 struct udevice *dev;
Jean-Jacques Hiblot9bb6c7f2018-08-09 16:17:43 +020085 int i = 0;
Simon Glassd9f9a892015-06-23 15:38:35 -060086
87 ret = uclass_get(id, &uc);
88 if (ret)
89 continue;
90
91 printf("uclass %d: %s\n", id, uc->uc_drv->name);
92 if (list_empty(&uc->dev_head))
93 continue;
Liviu Dudau6f386222018-09-28 14:12:55 +010094 uclass_foreach_dev(dev, uc) {
Jean-Jacques Hiblot9bb6c7f2018-08-09 16:17:43 +020095 dm_display_line(dev, i);
96 i++;
Simon Glassd9f9a892015-06-23 15:38:35 -060097 }
98 puts("\n");
99 }
100}
Sean Anderson02827572020-01-17 14:48:09 -0500101
Niel Fourie39832fb2020-03-24 16:17:05 +0100102void dm_dump_driver_compat(void)
Sean Anderson02827572020-01-17 14:48:09 -0500103{
104 struct driver *d = ll_entry_start(struct driver, driver);
105 const int n_ents = ll_entry_count(struct driver, driver);
106 struct driver *entry;
107 const struct udevice_id *match;
108
109 puts("Driver Compatible\n");
110 puts("--------------------------------\n");
111 for (entry = d; entry < d + n_ents; entry++) {
Ovidiu Panait8dada7f2020-04-05 19:47:41 +0300112 match = entry->of_match;
113
114 printf("%-20.20s", entry->name);
115 if (match) {
116 printf(" %s", match->compatible);
117 match++;
118 }
119 printf("\n");
120
121 for (; match && match->compatible; match++)
122 printf("%-20.20s %s\n", "", match->compatible);
Sean Anderson02827572020-01-17 14:48:09 -0500123 }
124}
Niel Fourie39832fb2020-03-24 16:17:05 +0100125
126void dm_dump_drivers(void)
127{
128 struct driver *d = ll_entry_start(struct driver, driver);
129 const int n_ents = ll_entry_count(struct driver, driver);
130 struct driver *entry;
131 struct udevice *udev;
132 struct uclass *uc;
133 int i;
134
135 puts("Driver uid uclass Devices\n");
136 puts("----------------------------------------------------------\n");
137
138 for (entry = d; entry < d + n_ents; entry++) {
139 uclass_get(entry->id, &uc);
140
141 printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
142 uc ? uc->uc_drv->name : "<no uclass>");
143
144 if (!uc) {
145 puts("\n");
146 continue;
147 }
148
149 i = 0;
150 uclass_foreach_dev(udev, uc) {
151 if (udev->driver != entry)
152 continue;
153 if (i)
154 printf("%-51.51s", "");
155
156 printf("%-25.25s\n", udev->name);
157 i++;
158 }
159 if (!i)
160 puts("<none>\n");
161 }
162}
163
164void dm_dump_static_driver_info(void)
165{
166 struct driver_info *drv = ll_entry_start(struct driver_info,
167 driver_info);
168 const int n_ents = ll_entry_count(struct driver_info, driver_info);
169 struct driver_info *entry;
170
171 puts("Driver Address\n");
172 puts("---------------------------------\n");
173 for (entry = drv; entry != drv + n_ents; entry++) {
174 printf("%-25.25s @%08lx\n", entry->name,
Simon Glass71fa5b42020-12-03 16:55:18 -0700175 (ulong)map_to_sysmem(entry->plat));
Niel Fourie39832fb2020-03-24 16:17:05 +0100176 }
177}