pinctrl: qcom: Add pinctrl driver for QCS404 SoC
[platform/kernel/u-boot.git] / drivers / core / dump.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2015 Google, Inc
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <mapmem.h>
9 #include <dm/root.h>
10 #include <dm/util.h>
11 #include <dm/uclass-internal.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         u32 flags = dev_get_flags(dev);
18
19         /* print the first 20 characters to not break the tree-format. */
20         printf(IS_ENABLED(CONFIG_SPL_BUILD) ? " %s  %d  [ %c ]   %s  " :
21                " %-10.10s  %3d  [ %c ]   %-20.20s  ", dev->uclass->uc_drv->name,
22                dev_get_uclass_index(dev, NULL),
23                flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
24
25         for (i = depth; i >= 0; i--) {
26                 is_last = (last_flag >> i) & 1;
27                 if (i) {
28                         if (is_last)
29                                 printf("    ");
30                         else
31                                 printf("|   ");
32                 } else {
33                         if (is_last)
34                                 printf("`-- ");
35                         else
36                                 printf("|-- ");
37                 }
38         }
39
40         printf("%s\n", dev->name);
41
42         device_foreach_child(child, dev) {
43                 is_last = list_is_last(&child->sibling_node, &dev->child_head);
44                 show_devices(child, depth + 1, (last_flag << 1) | is_last);
45         }
46 }
47
48 void dm_dump_tree(void)
49 {
50         struct udevice *root;
51
52         root = dm_root();
53         if (root) {
54                 printf(" Class     Index  Probed  Driver                Name\n");
55                 printf("-----------------------------------------------------------\n");
56                 show_devices(root, -1, 0);
57         }
58 }
59
60 /**
61  * dm_display_line() - Display information about a single device
62  *
63  * Displays a single line of information with an option prefix
64  *
65  * @dev:        Device to display
66  */
67 static void dm_display_line(struct udevice *dev, int index)
68 {
69         printf("%-3i %c %s @ %08lx", index,
70                dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ',
71                dev->name, (ulong)map_to_sysmem(dev));
72         if (dev->seq_ != -1)
73                 printf(", seq %d", dev_seq(dev));
74         puts("\n");
75 }
76
77 void dm_dump_uclass(void)
78 {
79         struct uclass *uc;
80         int ret;
81         int id;
82
83         for (id = 0; id < UCLASS_COUNT; id++) {
84                 struct udevice *dev;
85                 int i = 0;
86
87                 ret = uclass_get(id, &uc);
88                 if (ret)
89                         continue;
90
91                 printf("uclass %d: %s\n", id, uc->uc_drv->name);
92                 uclass_foreach_dev(dev, uc) {
93                         dm_display_line(dev, i);
94                         i++;
95                 }
96                 puts("\n");
97         }
98 }
99
100 void dm_dump_driver_compat(void)
101 {
102         struct driver *d = ll_entry_start(struct driver, driver);
103         const int n_ents = ll_entry_count(struct driver, driver);
104         struct driver *entry;
105         const struct udevice_id *match;
106
107         puts("Driver                Compatible\n");
108         puts("--------------------------------\n");
109         for (entry = d; entry < d + n_ents; entry++) {
110                 match = entry->of_match;
111
112                 printf("%-20.20s", entry->name);
113                 if (match) {
114                         printf("  %s", match->compatible);
115                         match++;
116                 }
117                 printf("\n");
118
119                 for (; match && match->compatible; match++)
120                         printf("%-20.20s  %s\n", "", match->compatible);
121         }
122 }
123
124 void dm_dump_drivers(void)
125 {
126         struct driver *d = ll_entry_start(struct driver, driver);
127         const int n_ents = ll_entry_count(struct driver, driver);
128         struct driver *entry;
129         struct udevice *udev;
130         struct uclass *uc;
131         int ret;
132         int i;
133
134         puts("Driver                    uid uclass               Devices\n");
135         puts("----------------------------------------------------------\n");
136
137         for (entry = d; entry < d + n_ents; entry++) {
138                 ret = uclass_get(entry->id, &uc);
139
140                 printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
141                        !ret ? uc->uc_drv->name : "<no uclass>");
142
143                 if (ret) {
144                         puts("\n");
145                         continue;
146                 }
147
148                 i = 0;
149                 uclass_foreach_dev(udev, uc) {
150                         if (udev->driver != entry)
151                                 continue;
152                         if (i)
153                                 printf("%-51.51s", "");
154
155                         printf("%-25.25s\n", udev->name);
156                         i++;
157                 }
158                 if (!i)
159                         puts("<none>\n");
160         }
161 }
162
163 void dm_dump_static_driver_info(void)
164 {
165         struct driver_info *drv = ll_entry_start(struct driver_info,
166                                                  driver_info);
167         const int n_ents = ll_entry_count(struct driver_info, driver_info);
168         struct driver_info *entry;
169
170         puts("Driver                    Address\n");
171         puts("---------------------------------\n");
172         for (entry = drv; entry != drv + n_ents; entry++)
173                 printf("%-25.25s %p\n", entry->name, entry->plat);
174 }
175
176 void dm_dump_mem(struct dm_stats *stats)
177 {
178         int total, total_delta;
179         int i;
180
181         /* Support SPL printf() */
182         printf("Struct sizes: udevice %x, driver %x, uclass %x, uc_driver %x\n",
183                (int)sizeof(struct udevice), (int)sizeof(struct driver),
184                (int)sizeof(struct uclass), (int)sizeof(struct uclass_driver));
185         printf("Memory: device %x:%x, device names %x, uclass %x:%x\n",
186                stats->dev_count, stats->dev_size, stats->dev_name_size,
187                stats->uc_count, stats->uc_size);
188         printf("\n");
189         printf("%-15s  %5s  %5s  %5s  %5s  %5s\n", "Attached type", "Count",
190                "Size", "Cur", "Tags", "Save");
191         printf("%-15s  %5s  %5s  %5s  %5s  %5s\n", "---------------", "-----",
192                "-----", "-----", "-----", "-----");
193         total_delta = 0;
194         for (i = 0; i < DM_TAG_ATTACH_COUNT; i++) {
195                 int cur_size, new_size, delta;
196
197                 cur_size = stats->dev_count * sizeof(struct udevice);
198                 new_size = stats->dev_count * (sizeof(struct udevice) -
199                         sizeof(void *));
200                 /*
201                  * Let's assume we can fit each dmtag_node into 32 bits. We can
202                  * limit the 'tiny tags' feature to SPL with
203                  * CONFIG_SPL_SYS_MALLOC_F_LEN <= 64KB, so needing 14 bits to
204                  * point to anything in that region (with 4-byte alignment).
205                  * So:
206                  *    4 bits for tag
207                  *    14 bits for offset of dev
208                  *    14 bits for offset of data
209                  */
210                 new_size += stats->attach_count[i] * sizeof(u32);
211                 delta = cur_size - new_size;
212                 total_delta += delta;
213                 printf("%-16s %5x %6x %6x %6x %6x (%d)\n", tag_get_name(i),
214                        stats->attach_count[i], stats->attach_size[i],
215                        cur_size, new_size, delta > 0 ? delta : 0, delta);
216         }
217         printf("%-16s %5x %6x\n", "uclass", stats->uc_attach_count,
218                stats->uc_attach_size);
219         printf("%-16s %5x %6x  %5s  %5s  %6x (%d)\n", "Attached total",
220                stats->attach_count_total + stats->uc_attach_count,
221                stats->attach_size_total + stats->uc_attach_size, "", "",
222                total_delta > 0 ? total_delta : 0, total_delta);
223         printf("%-16s %5x %6x\n", "tags", stats->tag_count, stats->tag_size);
224         printf("\n");
225         printf("Total size: %x (%d)\n", stats->total_size, stats->total_size);
226         printf("\n");
227
228         total = stats->total_size;
229         total -= total_delta;
230         printf("With tags:       %x (%d)\n", total, total);
231
232         /* Use singly linked lists in struct udevice (3 nodes in each) */
233         total -= sizeof(void *) * 3 * stats->dev_count;
234         printf("- singly-linked: %x (%d)\n", total, total);
235
236         /* Use an index into the struct_driver list instead of a pointer */
237         total = total + stats->dev_count * (1 - sizeof(void *));
238         printf("- driver index:  %x (%d)\n", total, total);
239
240         /* Same with the uclass */
241         total = total + stats->dev_count * (1 - sizeof(void *));
242         printf("- uclass index:  %x (%d)\n", total, total);
243
244         /* Drop the device name */
245         printf("Drop device name (not SRAM): %x (%d)\n", stats->dev_name_size,
246                stats->dev_name_size);
247 }