xref: /rk3399_rockchip-uboot/drivers/core/dump.c (revision 7ac3b0edb507765f43120c591d830e5f63fe3474)
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 	int pre_reloc, remained;
18 
19 	/* print the first 11 characters to not break the tree-format. */
20 	printf(" %08lx    %-10.10s [ %c ]   %-25.25s  ",
21 	       (ulong)dev, dev->uclass->uc_drv->name,
22 	       dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
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 	pre_reloc = dev_read_bool(dev, "u-boot,dm-pre-reloc") ||
40 		    dev_read_bool(dev, "u-boot,dm-spl");
41 	if (pre_reloc)
42 		remained = !list_empty(&dev->uclass_node);
43 	else
44 		remained = 0;
45 
46 	printf("%s %s%s\n", dev->name, pre_reloc ? "*" : "", remained ? "*" : "");
47 
48 	list_for_each_entry(child, &dev->child_head, sibling_node) {
49 		is_last = list_is_last(&child->sibling_node, &dev->child_head);
50 		show_devices(child, depth + 1, (last_flag << 1) | is_last);
51 	}
52 }
53 
54 void dm_dump_all(void)
55 {
56 	struct udevice *root;
57 
58 	root = dm_root();
59 	if (root) {
60 		printf(" Addr        Class      Probed    Driver                   Name\n");
61 		printf("-------------------------------------------------------------------------\n");
62 		show_devices(root, -1, 0);
63 	}
64 }
65 
66 /**
67  * dm_display_line() - Display information about a single device
68  *
69  * Displays a single line of information with an option prefix
70  *
71  * @dev:	Device to display
72  */
73 static void dm_display_line(struct udevice *dev)
74 {
75 	printf("  %c [ %c ] %s @ %08lx",
76 	       dev_read_bool(dev, "u-boot,dm-pre-pre_reloc") ||
77 	       dev_read_bool(dev, "u-boot,dm-spl") ? '*' : ' ',
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 void dm_dump_uclass(void)
86 {
87 	struct uclass *uc;
88 	int ret;
89 	int id;
90 
91 	for (id = 0; id < UCLASS_COUNT; id++) {
92 		struct udevice *dev;
93 
94 		ret = uclass_get(id, &uc);
95 		if (ret)
96 			continue;
97 
98 		printf("uclass %d: %s\n", id, uc->uc_drv->name);
99 		if (list_empty(&uc->dev_head))
100 			continue;
101 		list_for_each_entry(dev, &uc->dev_head, uclass_node) {
102 			dm_display_line(dev);
103 		}
104 		puts("\n");
105 	}
106 }
107