Commit 304fbef156b00d8d7005c8b156e64a6632d45008

Authored by Simon Glass
1 parent da229e4e57

dm: Move the tree/uclass dump code into its own file

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>

Showing 4 changed files with 106 additions and 79 deletions Side-by-side Diff

drivers/core/Makefile
... ... @@ -9,4 +9,5 @@
9 9 obj-$(CONFIG_OF_CONTROL) += simple-bus.o
10 10 endif
11 11 obj-$(CONFIG_DM_DEVICE_REMOVE) += device-remove.o
  12 +obj-$(CONFIG_DM) += dump.o
  1 +/*
  2 + * Copyright (c) 2015 Google, Inc
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <dm.h>
  9 +#include <mapmem.h>
  10 +#include <dm/root.h>
  11 +
  12 +static void show_devices(struct udevice *dev, int depth, int last_flag)
  13 +{
  14 + int i, is_last;
  15 + struct udevice *child;
  16 + char class_name[12];
  17 +
  18 + /* print the first 11 characters to not break the tree-format. */
  19 + strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
  20 + printf(" %-11s [ %c ] ", class_name,
  21 + dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
  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) {
  52 + printf(" Class Probed Name\n");
  53 + printf("----------------------------------------\n");
  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 + */
  65 +static void dm_display_line(struct udevice *dev)
  66 +{
  67 + printf("- %c %s @ %08lx",
  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;
  83 +
  84 + ret = uclass_get(id, &uc);
  85 + if (ret)
  86 + continue;
  87 +
  88 + printf("uclass %d: %s\n", id, uc->uc_drv->name);
  89 + if (list_empty(&uc->dev_head))
  90 + continue;
  91 + list_for_each_entry(dev, &uc->dev_head, uclass_node) {
  92 + dm_display_line(dev);
  93 + }
  94 + puts("\n");
  95 + }
  96 +}
... ... @@ -33,5 +33,11 @@
33 33 */
34 34 int list_count_items(struct list_head *head);
35 35  
  36 +/* Dump out a tree of all devices */
  37 +void dm_dump_all(void);
  38 +
  39 +/* Dump out a list of uclasses and their devices */
  40 +void dm_dump_uclass(void);
  41 +
36 42 #endif
... ... @@ -14,96 +14,20 @@
14 14 #include <errno.h>
15 15 #include <asm/io.h>
16 16 #include <dm/root.h>
17   -#include <dm/uclass-internal.h>
  17 +#include <dm/util.h>
18 18  
19   -static void show_devices(struct udevice *dev, int depth, int last_flag)
20   -{
21   - int i, is_last;
22   - struct udevice *child;
23   - char class_name[12];
24   -
25   - /* print the first 11 characters to not break the tree-format. */
26   - strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
27   - printf(" %-11s [ %c ] ", class_name,
28   - dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
29   -
30   - for (i = depth; i >= 0; i--) {
31   - is_last = (last_flag >> i) & 1;
32   - if (i) {
33   - if (is_last)
34   - printf(" ");
35   - else
36   - printf("| ");
37   - } else {
38   - if (is_last)
39   - printf("`-- ");
40   - else
41   - printf("|-- ");
42   - }
43   - }
44   -
45   - printf("%s\n", dev->name);
46   -
47   - list_for_each_entry(child, &dev->child_head, sibling_node) {
48   - is_last = list_is_last(&child->sibling_node, &dev->child_head);
49   - show_devices(child, depth + 1, (last_flag << 1) | is_last);
50   - }
51   -}
52   -
53 19 static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
54 20 char * const argv[])
55 21 {
56   - struct udevice *root;
  22 + dm_dump_all();
57 23  
58   - root = dm_root();
59   - if (root) {
60   - printf(" Class Probed Name\n");
61   - printf("----------------------------------------\n");
62   - show_devices(root, -1, 0);
63   - }
64   -
65 24 return 0;
66 25 }
67 26  
68   -/**
69   - * dm_display_line() - Display information about a single device
70   - *
71   - * Displays a single line of information with an option prefix
72   - *
73   - * @dev: Device to display
74   - */
75   -static void dm_display_line(struct udevice *dev)
76   -{
77   - printf("- %c %s @ %08lx",
78   - dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
79   - dev->name, (ulong)map_to_sysmem(dev));
80   - if (dev->seq != -1 || dev->req_seq != -1)
81   - printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
82   - puts("\n");
83   -}
84   -
85 27 static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
86 28 char * const argv[])
87 29 {
88   - struct uclass *uc;
89   - int ret;
90   - int id;
91   -
92   - for (id = 0; id < UCLASS_COUNT; id++) {
93   - struct udevice *dev;
94   -
95   - ret = uclass_get(id, &uc);
96   - if (ret)
97   - continue;
98   -
99   - printf("uclass %d: %s\n", id, uc->uc_drv->name);
100   - if (list_empty(&uc->dev_head))
101   - continue;
102   - list_for_each_entry(dev, &uc->dev_head, uclass_node) {
103   - dm_display_line(dev);
104   - }
105   - puts("\n");
106   - }
  30 + dm_dump_uclass();
107 31  
108 32 return 0;
109 33 }