Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <mapmem.h> |
| 9 | #include <dm/root.h> |
Masahiro Yamada | 77018de | 2017-06-22 17:10:11 +0900 | [diff] [blame] | 10 | #include <dm/util.h> |
Jean-Jacques Hiblot | 9bb6c7f | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 11 | #include <dm/uclass-internal.h> |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 12 | |
| 13 | static void show_devices(struct udevice *dev, int depth, int last_flag) |
| 14 | { |
| 15 | int i, is_last; |
| 16 | struct udevice *child; |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 17 | u32 flags = dev_get_flags(dev); |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 18 | |
Liviu Dudau | 764cae5 | 2018-10-15 10:03:06 +0100 | [diff] [blame] | 19 | /* print the first 20 characters to not break the tree-format. */ |
Simon Glass | f03341f | 2020-12-22 19:30:22 -0700 | [diff] [blame] | 20 | printf(IS_ENABLED(CONFIG_SPL_BUILD) ? " %s %d [ %c ] %s " : |
| 21 | " %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name, |
Jean-Jacques Hiblot | 9bb6c7f | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 22 | dev_get_uclass_index(dev, NULL), |
Simon Glass | f03341f | 2020-12-22 19:30:22 -0700 | [diff] [blame] | 23 | flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name); |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 24 | |
| 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 Anderson | f69a330 | 2022-03-30 12:26:40 -0400 | [diff] [blame] | 42 | device_foreach_child(child, dev) { |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 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 | |
Simon Glass | d94d743 | 2022-05-08 04:39:19 -0600 | [diff] [blame] | 48 | void dm_dump_tree(void) |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 49 | { |
| 50 | struct udevice *root; |
| 51 | |
| 52 | root = dm_root(); |
| 53 | if (root) { |
Simon Glass | df60424 | 2018-12-05 18:42:52 -0700 | [diff] [blame] | 54 | printf(" Class Index Probed Driver Name\n"); |
Liviu Dudau | 764cae5 | 2018-10-15 10:03:06 +0100 | [diff] [blame] | 55 | printf("-----------------------------------------------------------\n"); |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 56 | 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 Hiblot | 9bb6c7f | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 67 | static void dm_display_line(struct udevice *dev, int index) |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 68 | { |
Patrick Delaunay | 6814897 | 2019-09-30 10:19:13 +0200 | [diff] [blame] | 69 | printf("%-3i %c %s @ %08lx", index, |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 70 | dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ', |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 71 | dev->name, (ulong)map_to_sysmem(dev)); |
Simon Glass | 5e34992 | 2020-12-19 10:40:09 -0700 | [diff] [blame] | 72 | if (dev->seq_ != -1) |
Simon Glass | f7eca61 | 2020-12-16 21:20:31 -0700 | [diff] [blame] | 73 | printf(", seq %d", dev_seq(dev)); |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 74 | puts("\n"); |
| 75 | } |
| 76 | |
| 77 | void 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 Hiblot | 9bb6c7f | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 85 | int i = 0; |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 86 | |
| 87 | ret = uclass_get(id, &uc); |
| 88 | if (ret) |
| 89 | continue; |
| 90 | |
| 91 | printf("uclass %d: %s\n", id, uc->uc_drv->name); |
Liviu Dudau | 6f38622 | 2018-09-28 14:12:55 +0100 | [diff] [blame] | 92 | uclass_foreach_dev(dev, uc) { |
Jean-Jacques Hiblot | 9bb6c7f | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 93 | dm_display_line(dev, i); |
| 94 | i++; |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 95 | } |
| 96 | puts("\n"); |
| 97 | } |
| 98 | } |
Sean Anderson | 0282757 | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 99 | |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 100 | void dm_dump_driver_compat(void) |
Sean Anderson | 0282757 | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 101 | { |
| 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 Panait | 8dada7f | 2020-04-05 19:47:41 +0300 | [diff] [blame] | 110 | 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 Anderson | 0282757 | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 121 | } |
| 122 | } |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 123 | |
| 124 | void 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 Glass | 4e456c4 | 2021-05-13 19:39:24 -0600 | [diff] [blame] | 131 | int ret; |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 132 | int i; |
| 133 | |
| 134 | puts("Driver uid uclass Devices\n"); |
| 135 | puts("----------------------------------------------------------\n"); |
| 136 | |
| 137 | for (entry = d; entry < d + n_ents; entry++) { |
Simon Glass | 4e456c4 | 2021-05-13 19:39:24 -0600 | [diff] [blame] | 138 | ret = uclass_get(entry->id, &uc); |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 139 | |
| 140 | printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id, |
Simon Glass | 4e456c4 | 2021-05-13 19:39:24 -0600 | [diff] [blame] | 141 | !ret ? uc->uc_drv->name : "<no uclass>"); |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 142 | |
Simon Glass | 4e456c4 | 2021-05-13 19:39:24 -0600 | [diff] [blame] | 143 | if (ret) { |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 144 | 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 | |
| 163 | void 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 Glass | 3b64ecd | 2022-05-08 04:39:21 -0600 | [diff] [blame] | 172 | for (entry = drv; entry != drv + n_ents; entry++) |
| 173 | printf("%-25.25s %p\n", entry->name, entry->plat); |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 174 | } |
Simon Glass | c8b5e22 | 2022-05-08 04:39:26 -0600 | [diff] [blame] | 175 | |
| 176 | void 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 | } |