2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-06-23 21:38:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2023-01-17 17:47:12 +00:00
|
|
|
#include <malloc.h>
|
2015-06-23 21:38:35 +00:00
|
|
|
#include <mapmem.h>
|
2023-01-17 17:47:12 +00:00
|
|
|
#include <sort.h>
|
2015-06-23 21:38:35 +00:00
|
|
|
#include <dm/root.h>
|
2017-06-22 08:10:11 +00:00
|
|
|
#include <dm/util.h>
|
2018-08-09 14:17:43 +00:00
|
|
|
#include <dm/uclass-internal.h>
|
2015-06-23 21:38:35 +00:00
|
|
|
|
2023-01-17 17:47:12 +00:00
|
|
|
/**
|
|
|
|
* struct sort_info - information used for sorting
|
|
|
|
*
|
|
|
|
* @dev: List of devices
|
|
|
|
* @alloced: Maximum number of devices in @dev
|
|
|
|
*/
|
|
|
|
struct sort_info {
|
|
|
|
struct udevice **dev;
|
|
|
|
int size;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int h_cmp_uclass_id(const void *d1, const void *d2)
|
|
|
|
{
|
|
|
|
const struct udevice *const *dev1 = d1;
|
|
|
|
const struct udevice *const *dev2 = d2;
|
|
|
|
|
|
|
|
return device_get_uclass_id(*dev1) - device_get_uclass_id(*dev2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_devices(struct udevice *dev, int depth, int last_flag,
|
|
|
|
struct udevice **devs)
|
2015-06-23 21:38:35 +00:00
|
|
|
{
|
|
|
|
int i, is_last;
|
|
|
|
struct udevice *child;
|
2020-12-19 17:40:10 +00:00
|
|
|
u32 flags = dev_get_flags(dev);
|
2015-06-23 21:38:35 +00:00
|
|
|
|
2018-10-15 09:03:06 +00:00
|
|
|
/* print the first 20 characters to not break the tree-format. */
|
2023-01-21 23:30:12 +00:00
|
|
|
printf(CONFIG_IS_ENABLED(USE_TINY_PRINTF) ? " %s %d [ %c ] %s " :
|
2020-12-23 02:30:22 +00:00
|
|
|
" %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name,
|
2018-08-09 14:17:43 +00:00
|
|
|
dev_get_uclass_index(dev, NULL),
|
2020-12-23 02:30:22 +00:00
|
|
|
flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
|
2015-06-23 21:38:35 +00:00
|
|
|
|
|
|
|
for (i = depth; i >= 0; i--) {
|
|
|
|
is_last = (last_flag >> i) & 1;
|
|
|
|
if (i) {
|
|
|
|
if (is_last)
|
|
|
|
printf(" ");
|
|
|
|
else
|
|
|
|
printf("| ");
|
|
|
|
} else {
|
|
|
|
if (is_last)
|
|
|
|
printf("`-- ");
|
|
|
|
else
|
|
|
|
printf("|-- ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s\n", dev->name);
|
|
|
|
|
2023-01-17 17:47:12 +00:00
|
|
|
if (devs) {
|
|
|
|
int count;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
device_foreach_child(child, dev)
|
|
|
|
devs[count++] = child;
|
|
|
|
qsort(devs, count, sizeof(struct udevice *), h_cmp_uclass_id);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
show_devices(devs[i], depth + 1,
|
|
|
|
(last_flag << 1) | (i == count - 1),
|
|
|
|
devs + count);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
device_foreach_child(child, dev) {
|
|
|
|
is_last = list_is_last(&child->sibling_node,
|
|
|
|
&dev->child_head);
|
|
|
|
show_devices(child, depth + 1,
|
|
|
|
(last_flag << 1) | is_last, NULL);
|
|
|
|
}
|
2015-06-23 21:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
static void dm_dump_tree_single(struct udevice *dev, bool sort)
|
2015-06-23 21:38:35 +00:00
|
|
|
{
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
int dev_count, uclasses;
|
|
|
|
struct udevice **devs = NULL;
|
2015-06-23 21:38:35 +00:00
|
|
|
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
dm_get_stats(&dev_count, &uclasses);
|
|
|
|
|
|
|
|
if (sort) {
|
|
|
|
devs = calloc(dev_count, sizeof(struct udevice *));
|
|
|
|
if (!devs) {
|
|
|
|
printf("(out of memory)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
show_devices(dev, -1, 0, devs);
|
|
|
|
free(devs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dm_dump_tree_recursive(struct udevice *dev, char *dev_name,
|
|
|
|
bool extended, bool sort)
|
|
|
|
{
|
|
|
|
struct udevice *child;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(dev_name);
|
|
|
|
|
|
|
|
device_foreach_child(child, dev) {
|
|
|
|
if (extended) {
|
|
|
|
if (!strncmp(child->name, dev_name, len)) {
|
|
|
|
dm_dump_tree_single(child, sort);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!strcmp(child->name, dev_name)) {
|
|
|
|
dm_dump_tree_single(child, sort);
|
|
|
|
continue;
|
2023-01-17 17:47:12 +00:00
|
|
|
}
|
|
|
|
}
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
dm_dump_tree_recursive(child, dev_name, extended, sort);
|
2015-06-23 21:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
void dm_dump_tree(char *dev_name, bool extended, bool sort)
|
|
|
|
{
|
|
|
|
struct udevice *root;
|
|
|
|
|
|
|
|
printf(" Class Index Probed Driver Name\n");
|
|
|
|
printf("-----------------------------------------------------------\n");
|
|
|
|
|
|
|
|
root = dm_root();
|
|
|
|
if (!root)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!dev_name || !strcmp(dev_name, "root")) {
|
|
|
|
dm_dump_tree_single(root, sort);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_dump_tree_recursive(root, dev_name, extended, sort);
|
|
|
|
}
|
|
|
|
|
2015-06-23 21:38:35 +00:00
|
|
|
/**
|
|
|
|
* dm_display_line() - Display information about a single device
|
|
|
|
*
|
|
|
|
* Displays a single line of information with an option prefix
|
|
|
|
*
|
|
|
|
* @dev: Device to display
|
|
|
|
*/
|
2018-08-09 14:17:43 +00:00
|
|
|
static void dm_display_line(struct udevice *dev, int index)
|
2015-06-23 21:38:35 +00:00
|
|
|
{
|
2019-09-30 08:19:13 +00:00
|
|
|
printf("%-3i %c %s @ %08lx", index,
|
2020-12-19 17:40:10 +00:00
|
|
|
dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ',
|
2015-06-23 21:38:35 +00:00
|
|
|
dev->name, (ulong)map_to_sysmem(dev));
|
2020-12-19 17:40:09 +00:00
|
|
|
if (dev->seq_ != -1)
|
2020-12-17 04:20:31 +00:00
|
|
|
printf(", seq %d", dev_seq(dev));
|
2015-06-23 21:38:35 +00:00
|
|
|
puts("\n");
|
|
|
|
}
|
|
|
|
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
static void dm_dump_uclass_single(enum uclass_id id)
|
2015-06-23 21:38:35 +00:00
|
|
|
{
|
|
|
|
struct uclass *uc;
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
int i = 0, ret;
|
|
|
|
|
|
|
|
ret = uclass_get(id, &uc);
|
|
|
|
if (ret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
printf("uclass %d: %s\n", id, uc->uc_drv->name);
|
|
|
|
uclass_foreach_dev(dev, uc) {
|
|
|
|
dm_display_line(dev, i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
puts("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void dm_dump_uclass(char *uclass, bool extended)
|
|
|
|
{
|
|
|
|
struct uclass *uc;
|
|
|
|
enum uclass_id id;
|
|
|
|
bool matching;
|
2015-06-23 21:38:35 +00:00
|
|
|
int ret;
|
|
|
|
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
matching = !!(uclass && strcmp(uclass, "root"));
|
2015-06-23 21:38:35 +00:00
|
|
|
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
for (id = 0; id < UCLASS_COUNT; id++) {
|
2015-06-23 21:38:35 +00:00
|
|
|
ret = uclass_get(id, &uc);
|
|
|
|
if (ret)
|
|
|
|
continue;
|
|
|
|
|
cmd: dm: allow for selecting uclass and device
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass name or the device
name that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 124: usb
=> dm tree usb:usb@1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
If you want forward-matching against a uclass or udevice name,
you can specify "-e" option.
=> dm uclass -e usb
uclass 15: usb_emul
0 hub-emul @ 0bcffb00, seq 0
1 flash-stick@0 @ 0bcffc30, seq 1
2 flash-stick@1 @ 0bcffdc0, seq 2
3 flash-stick@2 @ 0bcfff50, seq 3
4 keyb@3 @ 0bd000e0, seq 4
uclass 64: usb_mass_storage
uclass 121: usb
0 usb@1 @ 0bcff8b0, seq 1
uclass 122: usb_dev_generic
uclass 123: usb_hub
0 hub @ 0bcff9b0, seq 0
uclass 124: usb
=> dm tree -e usb
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb@1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick@0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick@1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick@2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb@3
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-23 01:49:47 +00:00
|
|
|
if (matching) {
|
|
|
|
if (extended) {
|
|
|
|
if (!strncmp(uc->uc_drv->name, uclass,
|
|
|
|
strlen(uclass)))
|
|
|
|
dm_dump_uclass_single(id);
|
|
|
|
} else {
|
|
|
|
if (!strcmp(uc->uc_drv->name, uclass))
|
|
|
|
dm_dump_uclass_single(id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dm_dump_uclass_single(id);
|
2015-06-23 21:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-17 19:48:09 +00:00
|
|
|
|
2020-03-24 15:17:05 +00:00
|
|
|
void dm_dump_driver_compat(void)
|
2020-01-17 19:48:09 +00:00
|
|
|
{
|
|
|
|
struct driver *d = ll_entry_start(struct driver, driver);
|
|
|
|
const int n_ents = ll_entry_count(struct driver, driver);
|
|
|
|
struct driver *entry;
|
|
|
|
const struct udevice_id *match;
|
|
|
|
|
|
|
|
puts("Driver Compatible\n");
|
|
|
|
puts("--------------------------------\n");
|
|
|
|
for (entry = d; entry < d + n_ents; entry++) {
|
2020-04-05 16:47:41 +00:00
|
|
|
match = entry->of_match;
|
|
|
|
|
|
|
|
printf("%-20.20s", entry->name);
|
|
|
|
if (match) {
|
|
|
|
printf(" %s", match->compatible);
|
|
|
|
match++;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
for (; match && match->compatible; match++)
|
|
|
|
printf("%-20.20s %s\n", "", match->compatible);
|
2020-01-17 19:48:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 15:17:05 +00:00
|
|
|
|
|
|
|
void dm_dump_drivers(void)
|
|
|
|
{
|
|
|
|
struct driver *d = ll_entry_start(struct driver, driver);
|
|
|
|
const int n_ents = ll_entry_count(struct driver, driver);
|
|
|
|
struct driver *entry;
|
|
|
|
struct udevice *udev;
|
|
|
|
struct uclass *uc;
|
2021-05-14 01:39:24 +00:00
|
|
|
int ret;
|
2020-03-24 15:17:05 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
puts("Driver uid uclass Devices\n");
|
|
|
|
puts("----------------------------------------------------------\n");
|
|
|
|
|
|
|
|
for (entry = d; entry < d + n_ents; entry++) {
|
2021-05-14 01:39:24 +00:00
|
|
|
ret = uclass_get(entry->id, &uc);
|
2020-03-24 15:17:05 +00:00
|
|
|
|
|
|
|
printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
|
2021-05-14 01:39:24 +00:00
|
|
|
!ret ? uc->uc_drv->name : "<no uclass>");
|
2020-03-24 15:17:05 +00:00
|
|
|
|
2021-05-14 01:39:24 +00:00
|
|
|
if (ret) {
|
2020-03-24 15:17:05 +00:00
|
|
|
puts("\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
uclass_foreach_dev(udev, uc) {
|
|
|
|
if (udev->driver != entry)
|
|
|
|
continue;
|
|
|
|
if (i)
|
|
|
|
printf("%-51.51s", "");
|
|
|
|
|
|
|
|
printf("%-25.25s\n", udev->name);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (!i)
|
|
|
|
puts("<none>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dm_dump_static_driver_info(void)
|
|
|
|
{
|
|
|
|
struct driver_info *drv = ll_entry_start(struct driver_info,
|
|
|
|
driver_info);
|
|
|
|
const int n_ents = ll_entry_count(struct driver_info, driver_info);
|
|
|
|
struct driver_info *entry;
|
|
|
|
|
|
|
|
puts("Driver Address\n");
|
|
|
|
puts("---------------------------------\n");
|
2022-05-08 10:39:21 +00:00
|
|
|
for (entry = drv; entry != drv + n_ents; entry++)
|
|
|
|
printf("%-25.25s %p\n", entry->name, entry->plat);
|
2020-03-24 15:17:05 +00:00
|
|
|
}
|
2022-05-08 10:39:26 +00:00
|
|
|
|
|
|
|
void dm_dump_mem(struct dm_stats *stats)
|
|
|
|
{
|
|
|
|
int total, total_delta;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Support SPL printf() */
|
|
|
|
printf("Struct sizes: udevice %x, driver %x, uclass %x, uc_driver %x\n",
|
|
|
|
(int)sizeof(struct udevice), (int)sizeof(struct driver),
|
|
|
|
(int)sizeof(struct uclass), (int)sizeof(struct uclass_driver));
|
|
|
|
printf("Memory: device %x:%x, device names %x, uclass %x:%x\n",
|
|
|
|
stats->dev_count, stats->dev_size, stats->dev_name_size,
|
|
|
|
stats->uc_count, stats->uc_size);
|
|
|
|
printf("\n");
|
|
|
|
printf("%-15s %5s %5s %5s %5s %5s\n", "Attached type", "Count",
|
|
|
|
"Size", "Cur", "Tags", "Save");
|
|
|
|
printf("%-15s %5s %5s %5s %5s %5s\n", "---------------", "-----",
|
|
|
|
"-----", "-----", "-----", "-----");
|
|
|
|
total_delta = 0;
|
|
|
|
for (i = 0; i < DM_TAG_ATTACH_COUNT; i++) {
|
|
|
|
int cur_size, new_size, delta;
|
|
|
|
|
|
|
|
cur_size = stats->dev_count * sizeof(struct udevice);
|
|
|
|
new_size = stats->dev_count * (sizeof(struct udevice) -
|
|
|
|
sizeof(void *));
|
|
|
|
/*
|
|
|
|
* Let's assume we can fit each dmtag_node into 32 bits. We can
|
|
|
|
* limit the 'tiny tags' feature to SPL with
|
|
|
|
* CONFIG_SPL_SYS_MALLOC_F_LEN <= 64KB, so needing 14 bits to
|
|
|
|
* point to anything in that region (with 4-byte alignment).
|
|
|
|
* So:
|
|
|
|
* 4 bits for tag
|
|
|
|
* 14 bits for offset of dev
|
|
|
|
* 14 bits for offset of data
|
|
|
|
*/
|
|
|
|
new_size += stats->attach_count[i] * sizeof(u32);
|
|
|
|
delta = cur_size - new_size;
|
|
|
|
total_delta += delta;
|
|
|
|
printf("%-16s %5x %6x %6x %6x %6x (%d)\n", tag_get_name(i),
|
|
|
|
stats->attach_count[i], stats->attach_size[i],
|
|
|
|
cur_size, new_size, delta > 0 ? delta : 0, delta);
|
|
|
|
}
|
|
|
|
printf("%-16s %5x %6x\n", "uclass", stats->uc_attach_count,
|
|
|
|
stats->uc_attach_size);
|
|
|
|
printf("%-16s %5x %6x %5s %5s %6x (%d)\n", "Attached total",
|
|
|
|
stats->attach_count_total + stats->uc_attach_count,
|
|
|
|
stats->attach_size_total + stats->uc_attach_size, "", "",
|
|
|
|
total_delta > 0 ? total_delta : 0, total_delta);
|
|
|
|
printf("%-16s %5x %6x\n", "tags", stats->tag_count, stats->tag_size);
|
|
|
|
printf("\n");
|
|
|
|
printf("Total size: %x (%d)\n", stats->total_size, stats->total_size);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
total = stats->total_size;
|
|
|
|
total -= total_delta;
|
|
|
|
printf("With tags: %x (%d)\n", total, total);
|
|
|
|
|
|
|
|
/* Use singly linked lists in struct udevice (3 nodes in each) */
|
|
|
|
total -= sizeof(void *) * 3 * stats->dev_count;
|
|
|
|
printf("- singly-linked: %x (%d)\n", total, total);
|
|
|
|
|
|
|
|
/* Use an index into the struct_driver list instead of a pointer */
|
|
|
|
total = total + stats->dev_count * (1 - sizeof(void *));
|
|
|
|
printf("- driver index: %x (%d)\n", total, total);
|
|
|
|
|
|
|
|
/* Same with the uclass */
|
|
|
|
total = total + stats->dev_count * (1 - sizeof(void *));
|
|
|
|
printf("- uclass index: %x (%d)\n", total, total);
|
|
|
|
|
|
|
|
/* Drop the device name */
|
|
|
|
printf("Drop device name (not SRAM): %x (%d)\n", stats->dev_name_size,
|
|
|
|
stats->dev_name_size);
|
|
|
|
}
|