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 | |
| 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 | |
| 48 | void dm_dump_all(void) |
| 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); |
| 92 | if (list_empty(&uc->dev_head)) |
| 93 | continue; |
Liviu Dudau | 6f38622 | 2018-09-28 14:12:55 +0100 | [diff] [blame] | 94 | uclass_foreach_dev(dev, uc) { |
Jean-Jacques Hiblot | 9bb6c7f | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 95 | dm_display_line(dev, i); |
| 96 | i++; |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 97 | } |
| 98 | puts("\n"); |
| 99 | } |
| 100 | } |
Sean Anderson | 0282757 | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 101 | |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 102 | void dm_dump_driver_compat(void) |
Sean Anderson | 0282757 | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 103 | { |
| 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 Panait | 8dada7f | 2020-04-05 19:47:41 +0300 | [diff] [blame] | 112 | 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 Anderson | 0282757 | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 123 | } |
| 124 | } |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 125 | |
| 126 | void 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; |
Simon Glass | 4e456c4 | 2021-05-13 19:39:24 -0600 | [diff] [blame] | 133 | int ret; |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 134 | int i; |
| 135 | |
| 136 | puts("Driver uid uclass Devices\n"); |
| 137 | puts("----------------------------------------------------------\n"); |
| 138 | |
| 139 | for (entry = d; entry < d + n_ents; entry++) { |
Simon Glass | 4e456c4 | 2021-05-13 19:39:24 -0600 | [diff] [blame] | 140 | ret = uclass_get(entry->id, &uc); |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 141 | |
| 142 | printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id, |
Simon Glass | 4e456c4 | 2021-05-13 19:39:24 -0600 | [diff] [blame] | 143 | !ret ? uc->uc_drv->name : "<no uclass>"); |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 144 | |
Simon Glass | 4e456c4 | 2021-05-13 19:39:24 -0600 | [diff] [blame] | 145 | if (ret) { |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 146 | puts("\n"); |
| 147 | continue; |
| 148 | } |
| 149 | |
| 150 | i = 0; |
| 151 | uclass_foreach_dev(udev, uc) { |
| 152 | if (udev->driver != entry) |
| 153 | continue; |
| 154 | if (i) |
| 155 | printf("%-51.51s", ""); |
| 156 | |
| 157 | printf("%-25.25s\n", udev->name); |
| 158 | i++; |
| 159 | } |
| 160 | if (!i) |
| 161 | puts("<none>\n"); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void dm_dump_static_driver_info(void) |
| 166 | { |
| 167 | struct driver_info *drv = ll_entry_start(struct driver_info, |
| 168 | driver_info); |
| 169 | const int n_ents = ll_entry_count(struct driver_info, driver_info); |
| 170 | struct driver_info *entry; |
| 171 | |
| 172 | puts("Driver Address\n"); |
| 173 | puts("---------------------------------\n"); |
| 174 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 175 | printf("%-25.25s @%08lx\n", entry->name, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 176 | (ulong)map_to_sysmem(entry->plat)); |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 177 | } |
| 178 | } |