Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | 304fbef | 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 | fce136a | 2017-06-22 17:10:11 +0900 | [diff] [blame] | 10 | #include <dm/util.h> |
Jean-Jacques Hiblot | 999b204 | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 11 | #include <dm/uclass-internal.h> |
Simon Glass | 304fbef | 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 | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 17 | |
Liviu Dudau | 5197daf | 2018-10-15 10:03:06 +0100 | [diff] [blame] | 18 | /* print the first 20 characters to not break the tree-format. */ |
Patrick Delaunay | 2a43dbd | 2019-09-30 10:19:13 +0200 | [diff] [blame] | 19 | printf(" %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name, |
Jean-Jacques Hiblot | 999b204 | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 20 | dev_get_uclass_index(dev, NULL), |
Simon Glass | ee3e520 | 2017-08-02 12:12:02 -0600 | [diff] [blame] | 21 | dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name); |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 22 | |
| 23 | for (i = depth; i >= 0; i--) { |
| 24 | is_last = (last_flag >> i) & 1; |
| 25 | if (i) { |
| 26 | if (is_last) |
| 27 | printf(" "); |
| 28 | else |
| 29 | printf("| "); |
| 30 | } else { |
| 31 | if (is_last) |
| 32 | printf("`-- "); |
| 33 | else |
| 34 | printf("|-- "); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | printf("%s\n", dev->name); |
| 39 | |
| 40 | list_for_each_entry(child, &dev->child_head, sibling_node) { |
| 41 | is_last = list_is_last(&child->sibling_node, &dev->child_head); |
| 42 | show_devices(child, depth + 1, (last_flag << 1) | is_last); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void dm_dump_all(void) |
| 47 | { |
| 48 | struct udevice *root; |
| 49 | |
| 50 | root = dm_root(); |
| 51 | if (root) { |
Simon Glass | 54d2cfe | 2018-12-05 18:42:52 -0700 | [diff] [blame] | 52 | printf(" Class Index Probed Driver Name\n"); |
Liviu Dudau | 5197daf | 2018-10-15 10:03:06 +0100 | [diff] [blame] | 53 | printf("-----------------------------------------------------------\n"); |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 54 | show_devices(root, -1, 0); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * dm_display_line() - Display information about a single device |
| 60 | * |
| 61 | * Displays a single line of information with an option prefix |
| 62 | * |
| 63 | * @dev: Device to display |
| 64 | */ |
Jean-Jacques Hiblot | 999b204 | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 65 | static void dm_display_line(struct udevice *dev, int index) |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 66 | { |
Patrick Delaunay | 2a43dbd | 2019-09-30 10:19:13 +0200 | [diff] [blame] | 67 | printf("%-3i %c %s @ %08lx", index, |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 68 | dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', |
| 69 | dev->name, (ulong)map_to_sysmem(dev)); |
| 70 | if (dev->seq != -1 || dev->req_seq != -1) |
| 71 | printf(", seq %d, (req %d)", dev->seq, dev->req_seq); |
| 72 | puts("\n"); |
| 73 | } |
| 74 | |
| 75 | void dm_dump_uclass(void) |
| 76 | { |
| 77 | struct uclass *uc; |
| 78 | int ret; |
| 79 | int id; |
| 80 | |
| 81 | for (id = 0; id < UCLASS_COUNT; id++) { |
| 82 | struct udevice *dev; |
Jean-Jacques Hiblot | 999b204 | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 83 | int i = 0; |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 84 | |
| 85 | ret = uclass_get(id, &uc); |
| 86 | if (ret) |
| 87 | continue; |
| 88 | |
| 89 | printf("uclass %d: %s\n", id, uc->uc_drv->name); |
| 90 | if (list_empty(&uc->dev_head)) |
| 91 | continue; |
Liviu Dudau | 81f351d | 2018-09-28 14:12:55 +0100 | [diff] [blame] | 92 | uclass_foreach_dev(dev, uc) { |
Jean-Jacques Hiblot | 999b204 | 2018-08-09 16:17:43 +0200 | [diff] [blame] | 93 | dm_display_line(dev, i); |
| 94 | i++; |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 95 | } |
| 96 | puts("\n"); |
| 97 | } |
| 98 | } |
Sean Anderson | 7b9d60f | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 99 | |
Niel Fourie | 2e48836 | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 100 | void dm_dump_driver_compat(void) |
Sean Anderson | 7b9d60f | 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 | 28888ca | 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 | 7b9d60f | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 121 | } |
| 122 | } |
Niel Fourie | 2e48836 | 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; |
| 131 | int i; |
| 132 | |
| 133 | puts("Driver uid uclass Devices\n"); |
| 134 | puts("----------------------------------------------------------\n"); |
| 135 | |
| 136 | for (entry = d; entry < d + n_ents; entry++) { |
| 137 | uclass_get(entry->id, &uc); |
| 138 | |
| 139 | printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id, |
| 140 | uc ? uc->uc_drv->name : "<no uclass>"); |
| 141 | |
| 142 | if (!uc) { |
| 143 | puts("\n"); |
| 144 | continue; |
| 145 | } |
| 146 | |
| 147 | i = 0; |
| 148 | uclass_foreach_dev(udev, uc) { |
| 149 | if (udev->driver != entry) |
| 150 | continue; |
| 151 | if (i) |
| 152 | printf("%-51.51s", ""); |
| 153 | |
| 154 | printf("%-25.25s\n", udev->name); |
| 155 | i++; |
| 156 | } |
| 157 | if (!i) |
| 158 | puts("<none>\n"); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void dm_dump_static_driver_info(void) |
| 163 | { |
| 164 | struct driver_info *drv = ll_entry_start(struct driver_info, |
| 165 | driver_info); |
| 166 | const int n_ents = ll_entry_count(struct driver_info, driver_info); |
| 167 | struct driver_info *entry; |
| 168 | |
| 169 | puts("Driver Address\n"); |
| 170 | puts("---------------------------------\n"); |
| 171 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 172 | printf("%-25.25s @%08lx\n", entry->name, |
| 173 | (ulong)map_to_sysmem(entry->platdata)); |
| 174 | } |
| 175 | } |