1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
* Copyright (c) 2013 Google, Inc
*
* (C) Copyright 2012
* Marek Vasut <marex@denx.de>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <dm.h>
#include <malloc.h>
#include <errno.h>
#include <asm/io.h>
#include <dm/root.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
/**
* dm_display_line() - Display information about a single device
*
* Displays a single line of information with an option prefix
*
* @dev: Device to display
* @buf: Prefix to display at the start of the line
*/
static void dm_display_line(struct udevice *dev, char *buf)
{
printf("%s- %c %s @ %08lx", buf,
dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
dev->name, (ulong)map_to_sysmem(dev));
puts("\n");
}
static int display_succ(struct udevice *in, char *buf)
{
int len;
int ip = 0;
char local[16];
struct udevice *pos, *n, *prev = NULL;
dm_display_line(in, buf);
if (list_empty(&in->child_head))
return 0;
len = strlen(buf);
strncpy(local, buf, sizeof(local));
snprintf(local + len, 2, "|");
if (len && local[len - 1] == '`')
local[len - 1] = ' ';
list_for_each_entry_safe(pos, n, &in->child_head, sibling_node) {
if (ip++)
display_succ(prev, local);
prev = pos;
}
snprintf(local + len, 2, "`");
display_succ(prev, local);
return 0;
}
static int dm_dump(struct udevice *dev)
{
if (!dev)
return -EINVAL;
return display_succ(dev, "");
}
static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
struct udevice *root;
root = dm_root();
printf("ROOT %08lx\n", (ulong)map_to_sysmem(root));
return dm_dump(root);
}
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");
}
return 0;
}
#ifdef CONFIG_DM_TEST
static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
return dm_test_main();
}
#define TEST_HELP "\ndm test Run tests"
#else
#define TEST_HELP
#endif
static cmd_tbl_t test_commands[] = {
U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
#ifdef CONFIG_DM_TEST
U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
#endif
};
static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
cmd_tbl_t *test_cmd;
int ret;
if (argc != 2)
return CMD_RET_USAGE;
test_cmd = find_cmd_tbl(argv[1], test_commands,
ARRAY_SIZE(test_commands));
argc -= 2;
argv += 2;
if (!test_cmd || argc > test_cmd->maxargs)
return CMD_RET_USAGE;
ret = test_cmd->cmd(test_cmd, flag, argc, argv);
return cmd_process_error(test_cmd, ret);
}
U_BOOT_CMD(
dm, 2, 1, do_dm,
"Driver model low level access",
"tree Dump driver model tree ('*' = activated)\n"
"dm uclass Dump list of instances for each uclass"
TEST_HELP
);
|