1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
11 #include <dm/uclass-internal.h>
13 static void show_devices(struct udevice *dev, int depth, int last_flag)
16 struct udevice *child;
17 u32 flags = dev_get_flags(dev);
19 /* print the first 20 characters to not break the tree-format. */
20 printf(IS_ENABLED(CONFIG_SPL_BUILD) ? " %s %d [ %c ] %s " :
21 " %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name,
22 dev_get_uclass_index(dev, NULL),
23 flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
25 for (i = depth; i >= 0; i--) {
26 is_last = (last_flag >> i) & 1;
40 printf("%s\n", dev->name);
42 device_foreach_child(child, dev) {
43 is_last = list_is_last(&child->sibling_node, &dev->child_head);
44 show_devices(child, depth + 1, (last_flag << 1) | is_last);
48 void dm_dump_tree(void)
54 printf(" Class Index Probed Driver Name\n");
55 printf("-----------------------------------------------------------\n");
56 show_devices(root, -1, 0);
61 * dm_display_line() - Display information about a single device
63 * Displays a single line of information with an option prefix
65 * @dev: Device to display
67 static void dm_display_line(struct udevice *dev, int index)
69 printf("%-3i %c %s @ %08lx", index,
70 dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ',
71 dev->name, (ulong)map_to_sysmem(dev));
73 printf(", seq %d", dev_seq(dev));
77 void dm_dump_uclass(void)
83 for (id = 0; id < UCLASS_COUNT; id++) {
87 ret = uclass_get(id, &uc);
91 printf("uclass %d: %s\n", id, uc->uc_drv->name);
92 uclass_foreach_dev(dev, uc) {
93 dm_display_line(dev, i);
100 void dm_dump_driver_compat(void)
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;
107 puts("Driver Compatible\n");
108 puts("--------------------------------\n");
109 for (entry = d; entry < d + n_ents; entry++) {
110 match = entry->of_match;
112 printf("%-20.20s", entry->name);
114 printf(" %s", match->compatible);
119 for (; match && match->compatible; match++)
120 printf("%-20.20s %s\n", "", match->compatible);
124 void dm_dump_drivers(void)
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;
134 puts("Driver uid uclass Devices\n");
135 puts("----------------------------------------------------------\n");
137 for (entry = d; entry < d + n_ents; entry++) {
138 ret = uclass_get(entry->id, &uc);
140 printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
141 !ret ? uc->uc_drv->name : "<no uclass>");
149 uclass_foreach_dev(udev, uc) {
150 if (udev->driver != entry)
153 printf("%-51.51s", "");
155 printf("%-25.25s\n", udev->name);
163 void dm_dump_static_driver_info(void)
165 struct driver_info *drv = ll_entry_start(struct driver_info,
167 const int n_ents = ll_entry_count(struct driver_info, driver_info);
168 struct driver_info *entry;
170 puts("Driver Address\n");
171 puts("---------------------------------\n");
172 for (entry = drv; entry != drv + n_ents; entry++)
173 printf("%-25.25s %p\n", entry->name, entry->plat);
176 void dm_dump_mem(struct dm_stats *stats)
178 int total, total_delta;
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);
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 "-----", "-----", "-----", "-----");
194 for (i = 0; i < DM_TAG_ATTACH_COUNT; i++) {
195 int cur_size, new_size, delta;
197 cur_size = stats->dev_count * sizeof(struct udevice);
198 new_size = stats->dev_count * (sizeof(struct udevice) -
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).
207 * 14 bits for offset of dev
208 * 14 bits for offset of data
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);
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);
225 printf("Total size: %x (%d)\n", stats->total_size, stats->total_size);
228 total = stats->total_size;
229 total -= total_delta;
230 printf("With tags: %x (%d)\n", total, total);
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);
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);
240 /* Same with the uclass */
241 total = total + stats->dev_count * (1 - sizeof(void *));
242 printf("- uclass index: %x (%d)\n", total, total);
244 /* Drop the device name */
245 printf("Drop device name (not SRAM): %x (%d)\n", stats->dev_name_size,
246 stats->dev_name_size);