blob: 1c1f7e4d3082b73ce7d6c2154a6b7642d9611b13 [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 Glass6211d762020-12-19 10:40:10 -070017 u32 flags = dev_get_flags(dev);
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
Sean Andersonf69a3302022-03-30 12:26:40 -040042 device_foreach_child(child, dev) {
Simon Glassd9f9a892015-06-23 15:38:35 -060043 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
Simon Glassd94d7432022-05-08 04:39:19 -060048void dm_dump_tree(void)
Simon Glassd9f9a892015-06-23 15:38:35 -060049{
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 Glass6211d762020-12-19 10:40:10 -070070 dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ',
Simon Glassd9f9a892015-06-23 15:38:35 -060071 dev->name, (ulong)map_to_sysmem(dev));
Simon Glass5e349922020-12-19 10:40:09 -070072 if (dev->seq_ != -1)
Simon Glassf7eca612020-12-16 21:20:31 -070073 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);
Liviu Dudau6f386222018-09-28 14:12:55 +010092 uclass_foreach_dev(dev, uc) {
Jean-Jacques Hiblot9bb6c7f2018-08-09 16:17:43 +020093 dm_display_line(dev, i);
94 i++;
Simon Glassd9f9a892015-06-23 15:38:35 -060095 }
96 puts("\n");
97 }
98}
Sean Anderson02827572020-01-17 14:48:09 -050099
Niel Fourie39832fb2020-03-24 16:17:05 +0100100void dm_dump_driver_compat(void)
Sean Anderson02827572020-01-17 14:48:09 -0500101{
102 struct driver *d = ll_entry_start(struct driver, driver);
103 const int n_ents = ll_entry_count(struct driver, driver);
104 struct driver *entry;
105 const struct udevice_id *match;
106
107 puts("Driver Compatible\n");
108 puts("--------------------------------\n");
109 for (entry = d; entry < d + n_ents; entry++) {
Ovidiu Panait8dada7f2020-04-05 19:47:41 +0300110 match = entry->of_match;
111
112 printf("%-20.20s", entry->name);
113 if (match) {
114 printf(" %s", match->compatible);
115 match++;
116 }
117 printf("\n");
118
119 for (; match && match->compatible; match++)
120 printf("%-20.20s %s\n", "", match->compatible);
Sean Anderson02827572020-01-17 14:48:09 -0500121 }
122}
Niel Fourie39832fb2020-03-24 16:17:05 +0100123
124void dm_dump_drivers(void)
125{
126 struct driver *d = ll_entry_start(struct driver, driver);
127 const int n_ents = ll_entry_count(struct driver, driver);
128 struct driver *entry;
129 struct udevice *udev;
130 struct uclass *uc;
Simon Glass4e456c42021-05-13 19:39:24 -0600131 int ret;
Niel Fourie39832fb2020-03-24 16:17:05 +0100132 int i;
133
134 puts("Driver uid uclass Devices\n");
135 puts("----------------------------------------------------------\n");
136
137 for (entry = d; entry < d + n_ents; entry++) {
Simon Glass4e456c42021-05-13 19:39:24 -0600138 ret = uclass_get(entry->id, &uc);
Niel Fourie39832fb2020-03-24 16:17:05 +0100139
140 printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
Simon Glass4e456c42021-05-13 19:39:24 -0600141 !ret ? uc->uc_drv->name : "<no uclass>");
Niel Fourie39832fb2020-03-24 16:17:05 +0100142
Simon Glass4e456c42021-05-13 19:39:24 -0600143 if (ret) {
Niel Fourie39832fb2020-03-24 16:17:05 +0100144 puts("\n");
145 continue;
146 }
147
148 i = 0;
149 uclass_foreach_dev(udev, uc) {
150 if (udev->driver != entry)
151 continue;
152 if (i)
153 printf("%-51.51s", "");
154
155 printf("%-25.25s\n", udev->name);
156 i++;
157 }
158 if (!i)
159 puts("<none>\n");
160 }
161}
162
163void dm_dump_static_driver_info(void)
164{
165 struct driver_info *drv = ll_entry_start(struct driver_info,
166 driver_info);
167 const int n_ents = ll_entry_count(struct driver_info, driver_info);
168 struct driver_info *entry;
169
170 puts("Driver Address\n");
171 puts("---------------------------------\n");
Simon Glass3b64ecd2022-05-08 04:39:21 -0600172 for (entry = drv; entry != drv + n_ents; entry++)
173 printf("%-25.25s %p\n", entry->name, entry->plat);
Niel Fourie39832fb2020-03-24 16:17:05 +0100174}
Simon Glassc8b5e222022-05-08 04:39:26 -0600175
176void dm_dump_mem(struct dm_stats *stats)
177{
178 int total, total_delta;
179 int i;
180
181 /* Support SPL printf() */
182 printf("Struct sizes: udevice %x, driver %x, uclass %x, uc_driver %x\n",
183 (int)sizeof(struct udevice), (int)sizeof(struct driver),
184 (int)sizeof(struct uclass), (int)sizeof(struct uclass_driver));
185 printf("Memory: device %x:%x, device names %x, uclass %x:%x\n",
186 stats->dev_count, stats->dev_size, stats->dev_name_size,
187 stats->uc_count, stats->uc_size);
188 printf("\n");
189 printf("%-15s %5s %5s %5s %5s %5s\n", "Attached type", "Count",
190 "Size", "Cur", "Tags", "Save");
191 printf("%-15s %5s %5s %5s %5s %5s\n", "---------------", "-----",
192 "-----", "-----", "-----", "-----");
193 total_delta = 0;
194 for (i = 0; i < DM_TAG_ATTACH_COUNT; i++) {
195 int cur_size, new_size, delta;
196
197 cur_size = stats->dev_count * sizeof(struct udevice);
198 new_size = stats->dev_count * (sizeof(struct udevice) -
199 sizeof(void *));
200 /*
201 * Let's assume we can fit each dmtag_node into 32 bits. We can
202 * limit the 'tiny tags' feature to SPL with
203 * CONFIG_SPL_SYS_MALLOC_F_LEN <= 64KB, so needing 14 bits to
204 * point to anything in that region (with 4-byte alignment).
205 * So:
206 * 4 bits for tag
207 * 14 bits for offset of dev
208 * 14 bits for offset of data
209 */
210 new_size += stats->attach_count[i] * sizeof(u32);
211 delta = cur_size - new_size;
212 total_delta += delta;
213 printf("%-16s %5x %6x %6x %6x %6x (%d)\n", tag_get_name(i),
214 stats->attach_count[i], stats->attach_size[i],
215 cur_size, new_size, delta > 0 ? delta : 0, delta);
216 }
217 printf("%-16s %5x %6x\n", "uclass", stats->uc_attach_count,
218 stats->uc_attach_size);
219 printf("%-16s %5x %6x %5s %5s %6x (%d)\n", "Attached total",
220 stats->attach_count_total + stats->uc_attach_count,
221 stats->attach_size_total + stats->uc_attach_size, "", "",
222 total_delta > 0 ? total_delta : 0, total_delta);
223 printf("%-16s %5x %6x\n", "tags", stats->tag_count, stats->tag_size);
224 printf("\n");
225 printf("Total size: %x (%d)\n", stats->total_size, stats->total_size);
226 printf("\n");
227
228 total = stats->total_size;
229 total -= total_delta;
230 printf("With tags: %x (%d)\n", total, total);
231
232 /* Use singly linked lists in struct udevice (3 nodes in each) */
233 total -= sizeof(void *) * 3 * stats->dev_count;
234 printf("- singly-linked: %x (%d)\n", total, total);
235
236 /* Use an index into the struct_driver list instead of a pointer */
237 total = total + stats->dev_count * (1 - sizeof(void *));
238 printf("- driver index: %x (%d)\n", total, total);
239
240 /* Same with the uclass */
241 total = total + stats->dev_count * (1 - sizeof(void *));
242 printf("- uclass index: %x (%d)\n", total, total);
243
244 /* Drop the device name */
245 printf("Drop device name (not SRAM): %x (%d)\n", stats->dev_name_size,
246 stats->dev_name_size);
247}