]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: Move the tree/uclass dump code into its own file
authorSimon Glass <sjg@chromium.org>
Tue, 23 Jun 2015 21:38:35 +0000 (15:38 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 21 Jul 2015 23:39:22 +0000 (17:39 -0600)
In SPL it is sometimes useful to be able to obtain a dump of the current
driver model state. Since commands are not available, provide a way to
directly call the functions to output this information.

Adjust the existing commands to use these functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/core/Makefile
drivers/core/dump.c [new file with mode: 0644]
include/dm/util.h
test/dm/cmd_dm.c

index a3fec3850395512d3fdb177feb49ebb1381ca224..ed21fedbc08fed64d78462c47d395393083061a2 100644 (file)
@@ -9,3 +9,4 @@ ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_OF_CONTROL) += simple-bus.o
 endif
 obj-$(CONFIG_DM_DEVICE_REMOVE) += device-remove.o
+obj-$(CONFIG_DM)       += dump.o
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
new file mode 100644 (file)
index 0000000..fd4596e
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <mapmem.h>
+#include <dm/root.h>
+
+static void show_devices(struct udevice *dev, int depth, int last_flag)
+{
+       int i, is_last;
+       struct udevice *child;
+       char class_name[12];
+
+       /* print the first 11 characters to not break the tree-format. */
+       strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
+       printf(" %-11s [ %c ]    ", class_name,
+              dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
+
+       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);
+
+       list_for_each_entry(child, &dev->child_head, sibling_node) {
+               is_last = list_is_last(&child->sibling_node, &dev->child_head);
+               show_devices(child, depth + 1, (last_flag << 1) | is_last);
+       }
+}
+
+void dm_dump_all(void)
+{
+       struct udevice *root;
+
+       root = dm_root();
+       if (root) {
+               printf(" Class       Probed   Name\n");
+               printf("----------------------------------------\n");
+               show_devices(root, -1, 0);
+       }
+}
+
+/**
+ * dm_display_line() - Display information about a single device
+ *
+ * Displays a single line of information with an option prefix
+ *
+ * @dev:       Device to display
+ */
+static void dm_display_line(struct udevice *dev)
+{
+       printf("- %c %s @ %08lx",
+              dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
+              dev->name, (ulong)map_to_sysmem(dev));
+       if (dev->seq != -1 || dev->req_seq != -1)
+               printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
+       puts("\n");
+}
+
+void dm_dump_uclass(void)
+{
+       struct uclass *uc;
+       int ret;
+       int id;
+
+       for (id = 0; id < UCLASS_COUNT; id++) {
+               struct udevice *dev;
+
+               ret = uclass_get(id, &uc);
+               if (ret)
+                       continue;
+
+               printf("uclass %d: %s\n", id, uc->uc_drv->name);
+               if (list_empty(&uc->dev_head))
+                       continue;
+               list_for_each_entry(dev, &uc->dev_head, uclass_node) {
+                       dm_display_line(dev);
+               }
+               puts("\n");
+       }
+}
index 0cec17b52a413e8631bd0cc54c08d226e049515b..7dbed6793f887dd38b50a8ef92f23b677e00ae3c 100644 (file)
@@ -33,4 +33,10 @@ struct list_head;
  */
 int list_count_items(struct list_head *head);
 
+/* Dump out a tree of all devices */
+void dm_dump_all(void);
+
+/* Dump out a list of uclasses and their devices */
+void dm_dump_uclass(void);
+
 #endif
index 5bb2a99c8f0b5f207e61aea6ae990b2902eff524..5c501ec2541b85756b59f8038dd0f89c5c2add0c 100644 (file)
 #include <errno.h>
 #include <asm/io.h>
 #include <dm/root.h>
-#include <dm/uclass-internal.h>
-
-static void show_devices(struct udevice *dev, int depth, int last_flag)
-{
-       int i, is_last;
-       struct udevice *child;
-       char class_name[12];
-
-       /* print the first 11 characters to not break the tree-format. */
-       strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
-       printf(" %-11s [ %c ]    ", class_name,
-              dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
-
-       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);
-
-       list_for_each_entry(child, &dev->child_head, sibling_node) {
-               is_last = list_is_last(&child->sibling_node, &dev->child_head);
-               show_devices(child, depth + 1, (last_flag << 1) | is_last);
-       }
-}
+#include <dm/util.h>
 
 static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
                          char * const argv[])
 {
-       struct udevice *root;
-
-       root = dm_root();
-       if (root) {
-               printf(" Class       Probed   Name\n");
-               printf("----------------------------------------\n");
-               show_devices(root, -1, 0);
-       }
+       dm_dump_all();
 
        return 0;
 }
 
-/**
- * dm_display_line() - Display information about a single device
- *
- * Displays a single line of information with an option prefix
- *
- * @dev:       Device to display
- */
-static void dm_display_line(struct udevice *dev)
-{
-       printf("- %c %s @ %08lx",
-              dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
-              dev->name, (ulong)map_to_sysmem(dev));
-       if (dev->seq != -1 || dev->req_seq != -1)
-               printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
-       puts("\n");
-}
-
 static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
                             char * const argv[])
 {
-       struct uclass *uc;
-       int ret;
-       int id;
-
-       for (id = 0; id < UCLASS_COUNT; id++) {
-               struct udevice *dev;
-
-               ret = uclass_get(id, &uc);
-               if (ret)
-                       continue;
-
-               printf("uclass %d: %s\n", id, uc->uc_drv->name);
-               if (list_empty(&uc->dev_head))
-                       continue;
-               list_for_each_entry(dev, &uc->dev_head, uclass_node) {
-                       dm_display_line(dev);
-               }
-               puts("\n");
-       }
+       dm_dump_uclass();
 
        return 0;
 }