Merge git://git.denx.de/u-boot-dm
[platform/kernel/u-boot.git] / drivers / core / dump.c
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 #include <dm/util.h>
12
13 static void show_devices(struct udevice *dev, int depth, int last_flag)
14 {
15         int i, is_last;
16         struct udevice *child;
17         char class_name[12];
18
19         /* print the first 11 characters to not break the tree-format. */
20         strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
21         printf(" %-11s [ %c ]    ", class_name,
22                dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
23
24         for (i = depth; i >= 0; i--) {
25                 is_last = (last_flag >> i) & 1;
26                 if (i) {
27                         if (is_last)
28                                 printf("    ");
29                         else
30                                 printf("|   ");
31                 } else {
32                         if (is_last)
33                                 printf("`-- ");
34                         else
35                                 printf("|-- ");
36                 }
37         }
38
39         printf("%s\n", dev->name);
40
41         list_for_each_entry(child, &dev->child_head, sibling_node) {
42                 is_last = list_is_last(&child->sibling_node, &dev->child_head);
43                 show_devices(child, depth + 1, (last_flag << 1) | is_last);
44         }
45 }
46
47 void dm_dump_all(void)
48 {
49         struct udevice *root;
50
51         root = dm_root();
52         if (root) {
53                 printf(" Class       Probed   Name\n");
54                 printf("----------------------------------------\n");
55                 show_devices(root, -1, 0);
56         }
57 }
58
59 /**
60  * dm_display_line() - Display information about a single device
61  *
62  * Displays a single line of information with an option prefix
63  *
64  * @dev:        Device to display
65  */
66 static void dm_display_line(struct udevice *dev)
67 {
68         printf("- %c %s @ %08lx",
69                dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
70                dev->name, (ulong)map_to_sysmem(dev));
71         if (dev->seq != -1 || dev->req_seq != -1)
72                 printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
73         puts("\n");
74 }
75
76 void dm_dump_uclass(void)
77 {
78         struct uclass *uc;
79         int ret;
80         int id;
81
82         for (id = 0; id < UCLASS_COUNT; id++) {
83                 struct udevice *dev;
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;
92                 list_for_each_entry(dev, &uc->dev_head, uclass_node) {
93                         dm_display_line(dev);
94                 }
95                 puts("\n");
96         }
97 }