summaryrefslogtreecommitdiff
path: root/drivers/core/dump.c
blob: 3e77832a3a004133f60a7a68ddd6a6066bc67f91 (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (c) 2015 Google, Inc
 */

#include <common.h>
#include <dm.h>
#include <malloc.h>
#include <mapmem.h>
#include <sort.h>
#include <dm/root.h>
#include <dm/util.h>
#include <dm/uclass-internal.h>

/**
 * struct sort_info - information used for sorting
 *
 * @dev: List of devices
 * @alloced: Maximum number of devices in @dev
 */
struct sort_info {
	struct udevice **dev;
	int size;
};

static int h_cmp_uclass_id(const void *d1, const void *d2)
{
	const struct udevice *const *dev1 = d1;
	const struct udevice *const *dev2 = d2;

	return device_get_uclass_id(*dev1) - device_get_uclass_id(*dev2);
}

static void show_devices(struct udevice *dev, int depth, int last_flag,
			 struct udevice **devs)
{
	int i, is_last;
	struct udevice *child;
	u32 flags = dev_get_flags(dev);

	/* print the first 20 characters to not break the tree-format. */
	printf(CONFIG_IS_ENABLED(USE_TINY_PRINTF) ? " %s  %d  [ %c ]   %s  " :
	       " %-10.10s  %3d  [ %c ]   %-20.20s  ", dev->uclass->uc_drv->name,
	       dev_get_uclass_index(dev, NULL),
	       flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);

	for (i = depth; i >= 0; i--) {
		is_last = (last_flag >> i) & 1;
		if (i) {
			if (is_last)
				printf("    ");
			else
				printf("|   ");
		} else {
			if (is_last)
				printf("`-- ");
			else
				printf("|-- ");
		}
	}

	printf("%s\n", dev->name);

	if (devs) {
		int count;
		int i;

		count = 0;
		device_foreach_child(child, dev)
			devs[count++] = child;
		qsort(devs, count, sizeof(struct udevice *), h_cmp_uclass_id);

		for (i = 0; i < count; i++) {
			show_devices(devs[i], depth + 1,
				     (last_flag << 1) | (i == count - 1),
				     devs + count);
		}
	} else {
		device_foreach_child(child, dev) {
			is_last = list_is_last(&child->sibling_node,
					       &dev->child_head);
			show_devices(child, depth + 1,
				     (last_flag << 1) | is_last, NULL);
		}
	}
}

void dm_dump_tree(bool sort)
{
	struct udevice *root;

	root = dm_root();
	if (root) {
		int dev_count, uclasses;
		struct udevice **devs = NULL;

		dm_get_stats(&dev_count, &uclasses);

		printf(" Class     Index  Probed  Driver                Name\n");
		printf("-----------------------------------------------------------\n");
		if (sort) {
			devs = calloc(dev_count, sizeof(struct udevice *));
			if (!devs) {
				printf("(out of memory)\n");
				return;
			}
		}
		show_devices(root, -1, 0, devs);
		free(devs);
	}
}

/**
 * dm_display_line() - Display information about a single device
 *
 * Displays a single line of information with an option prefix
 *
 * @dev:	Device to display
 */
static void dm_display_line(struct udevice *dev, int index)
{
	printf("%-3i %c %s @ %08lx", index,
	       dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ',
	       dev->name, (ulong)map_to_sysmem(dev));
	if (dev->seq_ != -1)
		printf(", seq %d", dev_seq(dev));
	puts("\n");
}

void dm_dump_uclass(void)
{
	struct uclass *uc;
	int ret;
	int id;

	for (id = 0; id < UCLASS_COUNT; id++) {
		struct udevice *dev;
		int i = 0;

		ret = uclass_get(id, &uc);
		if (ret)
			continue;

		printf("uclass %d: %s\n", id, uc->uc_drv->name);
		uclass_foreach_dev(dev, uc) {
			dm_display_line(dev, i);
			i++;
		}
		puts("\n");
	}
}

void dm_dump_driver_compat(void)
{
	struct driver *d = ll_entry_start(struct driver, driver);
	const int n_ents = ll_entry_count(struct driver, driver);
	struct driver *entry;
	const struct udevice_id *match;

	puts("Driver                Compatible\n");
	puts("--------------------------------\n");
	for (entry = d; entry < d + n_ents; entry++) {
		match = entry->of_match;

		printf("%-20.20s", entry->name);
		if (match) {
			printf("  %s", match->compatible);
			match++;
		}
		printf("\n");

		for (; match && match->compatible; match++)
			printf("%-20.20s  %s\n", "", match->compatible);
	}
}

void dm_dump_drivers(void)
{
	struct driver *d = ll_entry_start(struct driver, driver);
	const int n_ents = ll_entry_count(struct driver, driver);
	struct driver *entry;
	struct udevice *udev;
	struct uclass *uc;
	int ret;
	int i;

	puts("Driver                    uid uclass               Devices\n");
	puts("----------------------------------------------------------\n");

	for (entry = d; entry < d + n_ents; entry++) {
		ret = uclass_get(entry->id, &uc);

		printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
		       !ret ? uc->uc_drv->name : "<no uclass>");

		if (ret) {
			puts("\n");
			continue;
		}

		i = 0;
		uclass_foreach_dev(udev, uc) {
			if (udev->driver != entry)
				continue;
			if (i)
				printf("%-51.51s", "");

			printf("%-25.25s\n", udev->name);
			i++;
		}
		if (!i)
			puts("<none>\n");
	}
}

void dm_dump_static_driver_info(void)
{
	struct driver_info *drv = ll_entry_start(struct driver_info,
						 driver_info);
	const int n_ents = ll_entry_count(struct driver_info, driver_info);
	struct driver_info *entry;

	puts("Driver                    Address\n");
	puts("---------------------------------\n");
	for (entry = drv; entry != drv + n_ents; entry++)
		printf("%-25.25s %p\n", entry->name, entry->plat);
}

void dm_dump_mem(struct dm_stats *stats)
{
	int total, total_delta;
	int i;

	/* Support SPL printf() */
	printf("Struct sizes: udevice %x, driver %x, uclass %x, uc_driver %x\n",
	       (int)sizeof(struct udevice), (int)sizeof(struct driver),
	       (int)sizeof(struct uclass), (int)sizeof(struct uclass_driver));
	printf("Memory: device %x:%x, device names %x, uclass %x:%x\n",
	       stats->dev_count, stats->dev_size, stats->dev_name_size,
	       stats->uc_count, stats->uc_size);
	printf("\n");
	printf("%-15s  %5s  %5s  %5s  %5s  %5s\n", "Attached type", "Count",
	       "Size", "Cur", "Tags", "Save");
	printf("%-15s  %5s  %5s  %5s  %5s  %5s\n", "---------------", "-----",
	       "-----", "-----", "-----", "-----");
	total_delta = 0;
	for (i = 0; i < DM_TAG_ATTACH_COUNT; i++) {
		int cur_size, new_size, delta;

		cur_size = stats->dev_count * sizeof(struct udevice);
		new_size = stats->dev_count * (sizeof(struct udevice) -
			sizeof(void *));
		/*
		 * Let's assume we can fit each dmtag_node into 32 bits. We can
		 * limit the 'tiny tags' feature to SPL with
		 * CONFIG_SPL_SYS_MALLOC_F_LEN <= 64KB, so needing 14 bits to
		 * point to anything in that region (with 4-byte alignment).
		 * So:
		 *    4 bits for tag
		 *    14 bits for offset of dev
		 *    14 bits for offset of data
		 */
		new_size += stats->attach_count[i] * sizeof(u32);
		delta = cur_size - new_size;
		total_delta += delta;
		printf("%-16s %5x %6x %6x %6x %6x (%d)\n", tag_get_name(i),
		       stats->attach_count[i], stats->attach_size[i],
		       cur_size, new_size, delta > 0 ? delta : 0, delta);
	}
	printf("%-16s %5x %6x\n", "uclass", stats->uc_attach_count,
	       stats->uc_attach_size);
	printf("%-16s %5x %6x  %5s  %5s  %6x (%d)\n", "Attached total",
	       stats->attach_count_total + stats->uc_attach_count,
	       stats->attach_size_total + stats->uc_attach_size, "", "",
	       total_delta > 0 ? total_delta : 0, total_delta);
	printf("%-16s %5x %6x\n", "tags", stats->tag_count, stats->tag_size);
	printf("\n");
	printf("Total size: %x (%d)\n", stats->total_size, stats->total_size);
	printf("\n");

	total = stats->total_size;
	total -= total_delta;
	printf("With tags:       %x (%d)\n", total, total);

	/* Use singly linked lists in struct udevice (3 nodes in each) */
	total -= sizeof(void *) * 3 * stats->dev_count;
	printf("- singly-linked: %x (%d)\n", total, total);

	/* Use an index into the struct_driver list instead of a pointer */
	total = total + stats->dev_count * (1 - sizeof(void *));
	printf("- driver index:  %x (%d)\n", total, total);

	/* Same with the uclass */
	total = total + stats->dev_count * (1 - sizeof(void *));
	printf("- uclass index:  %x (%d)\n", total, total);

	/* Drop the device name */
	printf("Drop device name (not SRAM): %x (%d)\n", stats->dev_name_size,
	       stats->dev_name_size);
}