diff options
author | Simon Glass <sjg@chromium.org> | 2021-12-16 20:59:32 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-12-23 10:24:40 -0500 |
commit | 6476c4d9818beac88610f18ff3c3cb05c7a1f33b (patch) | |
tree | 90bbf1c2bbaa910806e695a472bc52000056721d /drivers/core | |
parent | 985503439762c3168aeb80f529bb9bbcd773dd2c (diff) | |
download | u-boot-6476c4d9818beac88610f18ff3c3cb05c7a1f33b.tar.gz u-boot-6476c4d9818beac88610f18ff3c3cb05c7a1f33b.tar.bz2 u-boot-6476c4d9818beac88610f18ff3c3cb05c7a1f33b.zip |
dm: core: Allow getting some basic stats
Add a function that returns some basic stats about driver model. For now
we only have two.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/device.c | 11 | ||||
-rw-r--r-- | drivers/core/root.c | 7 | ||||
-rw-r--r-- | drivers/core/uclass.c | 13 |
3 files changed, 31 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c index 74374ff881..4873c47d10 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -739,6 +739,17 @@ int device_get_child_count(const struct udevice *parent) return count; } +int device_get_decendent_count(const struct udevice *parent) +{ + const struct udevice *dev; + int count = 1; + + list_for_each_entry(dev, &parent->child_head, sibling_node) + count += device_get_decendent_count(dev); + + return count; +} + int device_find_child_by_seq(const struct udevice *parent, int seq, struct udevice **devp) { diff --git a/drivers/core/root.c b/drivers/core/root.c index 26b8195faa..815173f86e 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -26,6 +26,7 @@ #include <dm/read.h> #include <dm/root.h> #include <dm/uclass.h> +#include <dm/uclass-internal.h> #include <dm/util.h> #include <linux/list.h> @@ -407,6 +408,12 @@ int dm_init_and_scan(bool pre_reloc_only) return 0; } +void dm_get_stats(int *device_countp, int *uclass_countp) +{ + *device_countp = device_get_decendent_count(gd->dm_root); + *uclass_countp = uclass_get_count(); +} + #ifdef CONFIG_ACPIGEN static int root_acpi_get_name(const struct udevice *dev, char *out_name) { diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 2aa2143077..336ea8d243 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -643,6 +643,19 @@ int uclass_next_device_check(struct udevice **devp) return device_probe(*devp); } +int uclass_get_count(void) +{ + const struct uclass *uc; + int count = 0; + + if (gd->dm_root) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) + count++; + } + + return count; +} + int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data, struct udevice **devp) { |