xref: /OK3568_Linux_fs/u-boot/drivers/core/dump.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
show_devices(struct udevice * dev,int depth,int last_flag)13 static void show_devices(struct udevice *dev, int depth, int last_flag)
14 {
15 	int i, is_last;
16 	struct udevice *child;
17 
18 	/* print the first 11 characters to not break the tree-format. */
19 	printf(" %08lx    %-10.10s [ %c ]   %-25.25s  ",
20 	       (ulong)dev, dev->uclass->uc_drv->name,
21 	       dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
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 #ifdef CONFIG_USING_KERNEL_DTB_V2
39 	printf("%s %s\n", dev->name, dev->flags & DM_FLAG_KNRL_DTB ? "" : "*");
40 #else
41 	int pre_reloc, remained;
42 
43 	pre_reloc = dev->flags & DM_FLAG_KNRL_DTB ? 0 : 1;
44 	remained = pre_reloc ? !list_empty(&dev->uclass_node) : 0;
45 	printf("%s %s%s\n", dev->name, pre_reloc ? "*" : "", remained ? "*" : "");
46 #endif
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 
dm_dump_all(void)53 void dm_dump_all(void)
54 {
55 	struct udevice *root;
56 
57 	root = dm_root();
58 	if (root) {
59 		printf(" Addr        Class      Probed    Driver                   Name\n");
60 		printf("-------------------------------------------------------------------------\n");
61 		show_devices(root, -1, 0);
62 	}
63 }
64 
65 /**
66  * dm_display_line() - Display information about a single device
67  *
68  * Displays a single line of information with an option prefix
69  *
70  * @dev:	Device to display
71  */
dm_display_line(struct udevice * dev)72 static void dm_display_line(struct udevice *dev)
73 {
74 	printf("  [ %c ] %s @ %08lx",
75 	       dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ',
76 	       dev->name, (ulong)map_to_sysmem(dev));
77 	if (dev->seq != -1 || dev->req_seq != -1)
78 		printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
79 	if (dev->driver->id == UCLASS_BLK) {
80 		struct blk_desc *desc = dev_get_uclass_platdata(dev);
81 		printf(" | %s%d", blk_get_if_type_name(desc->if_type), desc->devnum);
82 	}
83 	printf(" %c", dev->flags & DM_FLAG_KNRL_DTB ? ' ' : '*');
84 	puts("\n");
85 }
86 
dm_dump_uclass(void)87 void dm_dump_uclass(void)
88 {
89 	struct uclass *uc;
90 	int ret;
91 	int id;
92 
93 	for (id = 0; id < UCLASS_COUNT; id++) {
94 		struct udevice *dev;
95 
96 		ret = uclass_get(id, &uc);
97 		if (ret)
98 			continue;
99 
100 		printf("uclass %d: %s\n", id, uc->uc_drv->name);
101 		if (list_empty(&uc->dev_head))
102 			continue;
103 		list_for_each_entry(dev, &uc->dev_head, uclass_node) {
104 			dm_display_line(dev);
105 		}
106 		puts("\n");
107 	}
108 }
109