source: rtems/cpukit/libdrvmgr/drvmgr_print.c @ 2fb0912

4.115
Last change on this file since 2fb0912 was 65d1f35, checked in by Daniel Hellstrom <daniel@…>, on 02/27/15 at 15:42:36

DRVMGR: updated copyright into one line only

  • Property mode set to 100644
File size: 11.0 KB
Line 
1/* Driver Manager Information printing Interface Implementation
2 *
3 * COPYRIGHT (c) 2009 Cobham Gaisler AB.
4 *
5 * The license and distribution terms for this file may be
6 * found in the file LICENSE in this distribution or at
7 * http://www.rtems.com/license/LICENSE.
8 */
9
10/*
11 *  These functions print stuff about the driver manager, what devices were
12 *  found and were united with a driver, the Bus topology, memory taken, etc.
13 *
14 */
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include <drvmgr/drvmgr.h>
21#include "drvmgr_internal.h"
22
23typedef void (*fun_ptr)(void);
24
25static int print_dev_found(struct drvmgr_dev *dev, void *arg)
26{
27        char **pparg = arg;
28
29        if (pparg && *pparg) {
30                printf(*pparg);
31                *pparg = NULL;
32        }
33
34        printf(" DEV %p  %s on bus %p\n", dev,
35                dev->name ? dev->name : "NO_NAME", dev->parent);
36
37        return 0; /* Continue to next device */
38}
39
40void drvmgr_print_devs(unsigned int options)
41{
42        struct rtems_driver_manager *mgr = &drv_mgr;
43        char *parg;
44
45        /* Print Drivers */
46        if (options & PRINT_DEVS_ASSIGNED) {
47                parg = " --- DEVICES ASSIGNED TO DRIVER ---\n";
48                drvmgr_for_each_listdev(&mgr->devices[DRVMGR_LEVEL_MAX],
49                                DEV_STATE_UNITED, 0, print_dev_found, &parg);
50                if (parg != NULL)
51                        printf("\n NO DEVICES WERE ASSIGNED A DRIVER\n");
52        }
53
54        if (options & PRINT_DEVS_UNASSIGNED) {
55                parg = "\n --- DEVICES WITHOUT DRIVER ---\n";
56                drvmgr_for_each_listdev(&mgr->devices_inactive, 0,
57                        DEV_STATE_UNITED, print_dev_found, &parg);
58                if (parg != NULL)
59                        printf("\n NO DEVICES WERE WITHOUT DRIVER\n");
60        }
61
62        if (options & PRINT_DEVS_FAILED) {
63                parg = "\n --- DEVICES FAILED TO INITIALIZE ---\n";
64                drvmgr_for_each_listdev(&mgr->devices_inactive,
65                        DEV_STATE_INIT_FAILED, 0, print_dev_found, &parg);
66                if (parg != NULL)
67                        printf("\n NO DEVICES FAILED TO INITIALIZE\n");
68        }
69
70        if (options & PRINT_DEVS_IGNORED) {
71                parg = "\n --- DEVICES IGNORED ---\n";
72                drvmgr_for_each_listdev(&mgr->devices_inactive,
73                        DEV_STATE_IGNORED, 0, print_dev_found, &parg);
74                if (parg != NULL)
75                        printf("\n NO DEVICES WERE IGNORED\n");
76        }
77
78        printf("\n\n");
79}
80
81static int drvmgr_topo_func(struct drvmgr_dev *dev, void *arg)
82{
83        char prefix[32];
84        int depth = dev->parent->depth;
85
86        if (depth > 30)
87                return 0; /* depth more than 30 not supported */
88        memset(prefix, ' ', depth + 1);
89        prefix[depth + 1] = '\0';
90
91        printf(" %s|-> DEV  %p  %s\n", prefix, dev,
92                dev->name ? dev->name :  "NO_NAME");
93        return 0;
94}
95
96void drvmgr_print_topo(void)
97{
98        /* Print Bus topology */
99        printf(" --- BUS TOPOLOGY ---\n");
100        drvmgr_for_each_dev(drvmgr_topo_func, NULL, DRVMGR_FED_DF);
101        printf("\n\n");
102}
103
104/* Print the memory usage */
105void drvmgr_print_mem(void)
106{
107        struct rtems_driver_manager *mgr = &drv_mgr;
108        struct drvmgr_bus *bus;
109        struct drvmgr_dev *dev;
110        struct drvmgr_drv *drv;
111
112        struct drvmgr_bus_res *node;
113        struct drvmgr_drv_res *res;
114        struct drvmgr_key *key;
115
116        unsigned int busmem = 0;
117        unsigned int devmem = 0;
118        unsigned int drvmem = 0;
119        unsigned int resmem = 0;
120        unsigned int devprivmem = 0;
121
122        DRVMGR_LOCK_READ();
123
124        bus = BUS_LIST_HEAD(&mgr->buses[DRVMGR_LEVEL_MAX]);
125        while (bus) {
126                busmem += sizeof(struct drvmgr_bus);
127
128                /* Get size of resources on this bus */
129                node = bus->reslist;
130                while (node) {
131                        resmem += sizeof(struct drvmgr_bus_res);
132
133                        res = node->resource;
134                        while (res->keys) {
135                                resmem += sizeof(struct drvmgr_drv_res);
136
137                                key = res->keys;
138                                while (key->key_type != KEY_TYPE_NONE) {
139                                        resmem += sizeof
140                                                (struct drvmgr_key);
141                                        key++;
142                                }
143                                resmem += sizeof(struct drvmgr_key);
144                                res++;
145                        }
146
147                        node = node->next;
148                }
149
150                bus = bus->next;
151        }
152
153        drv = DRV_LIST_HEAD(&mgr->drivers);
154        while (drv) {
155                drvmem += sizeof(struct drvmgr_drv);
156                drv = drv->next;
157        }
158
159        dev = DEV_LIST_HEAD(&mgr->devices[DRVMGR_LEVEL_MAX]);
160        while (dev) {
161                devmem += sizeof(struct drvmgr_dev);
162                if (dev->drv && dev->drv->dev_priv_size > 0)
163                        devprivmem += dev->drv->dev_priv_size;
164                dev = dev->next;
165        }
166
167        DRVMGR_UNLOCK();
168
169        printf(" --- MEMORY USAGE ---\n");
170        printf(" BUS:          %d bytes\n", busmem);
171        printf(" DRV:          %d bytes\n", drvmem);
172        printf(" DEV:          %d bytes\n", devmem);
173        printf(" DEV private:  %d bytes\n", devprivmem);
174        printf(" RES:          %d bytes\n", resmem);
175        printf(" TOTAL:        %d bytes\n",
176                        busmem + drvmem + devmem + devprivmem + resmem);
177        printf("\n\n");
178}
179
180/* Print the memory usage */
181void drvmgr_summary(void)
182{
183        struct rtems_driver_manager *mgr = &drv_mgr;
184        struct drvmgr_bus *bus;
185        struct drvmgr_dev *dev;
186        struct drvmgr_drv *drv;
187        int i, buscnt = 0, devcnt = 0, drvcnt = 0;
188
189        printf(" --- SUMMARY ---\n");
190
191        drv = DRV_LIST_HEAD(&mgr->drivers);
192        while (drv) {
193                drvcnt++;
194                drv = drv->next;
195        }
196        printf(" NUMBER OF DRIVERS:               %d\n", drvcnt);
197
198        DRVMGR_LOCK_READ();
199
200        for (i = 0; i <= DRVMGR_LEVEL_MAX; i++) {
201                buscnt = 0;
202                bus = BUS_LIST_HEAD(&mgr->buses[i]);
203                while (bus) {
204                        buscnt++;
205                        bus = bus->next;
206                }
207                if (buscnt > 0) {
208                        printf(" NUMBER OF BUSES IN LEVEL[%d]:     %d\n",
209                                i, buscnt);
210                }
211        }
212
213        for (i = 0; i <= DRVMGR_LEVEL_MAX; i++) {
214                devcnt = 0;
215                dev = DEV_LIST_HEAD(&mgr->devices[i]);
216                while (dev) {
217                        devcnt++;
218                        dev = dev->next;
219                }
220                if (devcnt > 0) {
221                        printf(" NUMBER OF DEVS IN LEVEL[%d]:      %d\n",
222                                i, devcnt);
223                }
224        }
225
226        DRVMGR_UNLOCK();
227
228        printf("\n\n");
229}
230
231static void print_info(void *p, char *str)
232{
233        printf("  ");
234        puts(str);
235}
236
237void drvmgr_info_dev(struct drvmgr_dev *dev, unsigned int options)
238{
239        if (!dev)
240                return;
241
242        printf(" -- DEVICE %p --\n", dev);
243        if (options & OPTION_DEV_GENINFO) {
244                printf("  PARENT BUS:  %p\n", dev->parent);
245                printf("  NAME:        %s\n", dev->name ? dev->name : "NO_NAME");
246                printf("  STATE:       0x%08x\n", dev->state);
247                if (dev->bus)
248                        printf("  BRIDGE TO:   %p\n", dev->bus);
249                printf("  INIT LEVEL:  %d\n", dev->level);
250                printf("  ERROR:       %d\n", dev->error);
251                printf("  MINOR BUS:   %d\n", dev->minor_bus);
252                if (dev->drv) {
253                        printf("  MINOR DRV:   %d\n", dev->minor_drv);
254                        printf("  DRIVER:      %p (%s)\n", dev->drv,
255                                dev->drv->name ? dev->drv->name : "NO_NAME");
256                        printf("  PRIVATE:     %p\n", dev->priv);
257                }
258        }
259
260        if (options & OPTION_DEV_BUSINFO) {
261                printf("  --- DEVICE INFO FROM BUS DRIVER ---\n");
262                if (!dev->parent)
263                        printf("  !! device has no parent bus !!\n");
264                else if (dev->parent->ops->info_dev)
265                        dev->parent->ops->info_dev(dev, print_info, NULL);
266                else
267                        printf("  Bus doesn't implement info_dev func\n");
268        }
269
270        if (options & OPTION_DEV_DRVINFO) {
271                if (dev->drv) {
272                        printf("  --- DEVICE INFO FROM DEVICE DRIVER ---\n");
273                        if (dev->drv->ops->info)
274                                dev->drv->ops->info(dev, print_info, NULL, 0, 0);
275                        else
276                                printf("  Driver doesn't implement info func\n");
277                }
278        }
279}
280
281static void drvmgr_info_bus_map(struct drvmgr_map_entry *map)
282{
283        if (map == NULL)
284                printf("    Addresses mapped 1:1\n");
285        else if (map == DRVMGR_TRANSLATE_NO_BRIDGE)
286                printf("    No bridge in this direction\n");
287        else {
288                while (map->size != 0) {
289                        printf("    0x%08lx-0x%08lx => 0x%08lx-0x%08lx  %s\n",
290                                (unsigned long)map->from_adr,
291                                (unsigned long)(map->from_adr + map->size - 1),
292                                (unsigned long)map->to_adr,
293                                (unsigned long)(map->to_adr + map->size - 1),
294                                map->name ? map->name : "no label");
295                        map++;
296                }
297        }
298}
299
300void drvmgr_info_bus(struct drvmgr_bus *bus, unsigned int options)
301{
302        struct drvmgr_dev *dev;
303
304        /* Print Driver */
305        printf("-- BUS %p --\n", bus);
306        printf("  BUS TYPE:    %d\n", bus->bus_type);
307        printf("  DEVICE:      %p (%s)\n", bus->dev,
308                bus->dev->name ? bus->dev->name : "NO_NAME");
309        printf("  OPS:         %p\n", bus->ops);
310        printf("  CHILDREN:    %d devices\n", bus->dev_cnt);
311        printf("  LEVEL:       %d\n", bus->level);
312        printf("  STATE:       0x%08x\n", bus->state);
313        printf("  ERROR:       %d\n", bus->error);
314
315        /* Print address mappings up- (to parent) and down- (from parent to
316         * this bus) stream the bridge of this bus
317         */
318        printf("  DOWN STREAMS BRIDGE MAPPINGS  (from parent to this bus)\n");
319        drvmgr_info_bus_map(bus->maps_down);
320        printf("  UP STREAMS BRIDGE MAPPINGS    (from this bus to parent)\n");
321        drvmgr_info_bus_map(bus->maps_up);
322
323        /* Print Devices on this bus? */
324        if (options & OPTION_BUS_DEVS) {
325                printf("  CHILDREN:\n");
326                DRVMGR_LOCK_READ();
327                dev = bus->children;
328                while (dev) {
329                        printf("   |- DEV[%02d]: %p  %s\n", dev->minor_bus,
330                                dev, dev->name ? dev->name : "NO_NAME");
331                        dev = dev->next_in_bus;
332                }
333                DRVMGR_UNLOCK();
334        }
335}
336
337char *drv_ops_names[DRV_OPS_NUM] = {
338        "init[1]:",
339        "init[2]:",
340        "init[3]:",
341        "init[4]:",
342        "remove: ",
343        "info:   "
344};
345
346void drvmgr_info_drv(struct drvmgr_drv *drv, unsigned int options)
347{
348        struct drvmgr_dev *dev;
349        fun_ptr *ppfunc;
350        int i;
351
352        /* Print Driver */
353        printf(" -- DRIVER %p --\n", drv);
354        printf("  DRIVER ID:   0x%llx\n", drv->drv_id);
355        printf("  NAME:        %s\n", drv->name ? drv->name : "NO_NAME");
356        printf("  BUS TYPE:    %d\n", drv->bus_type);
357        printf("  OPERATIONS:\n");
358        for (i = 0, ppfunc = (fun_ptr *)&drv->ops->init[0]; i<DRV_OPS_NUM; i++)
359                printf("   %s    %p\n", drv_ops_names[i], ppfunc[i]);
360        printf("  NO. DEVICES: %d\n", drv->dev_cnt);
361
362        /* Print devices united with this driver? */
363        if (options & OPTION_DRV_DEVS) {
364                DRVMGR_LOCK_READ();
365                dev = drv->dev;
366                while (dev) {
367                        printf("  DEV[%02d]:     %p  %s\n", dev->minor_drv,
368                                dev, dev->name ? dev->name : "NO_NAME");
369                        dev = dev->next_in_drv;
370                }
371                DRVMGR_UNLOCK();
372        }
373}
374
375void (*info_obj[3])(void *obj, unsigned int) = {
376        /* DRVMGR_OBJ_DRV */ (void (*)(void *, unsigned int))drvmgr_info_drv,
377        /* DRVMGR_OBJ_BUS */ (void (*)(void *, unsigned int))drvmgr_info_bus,
378        /* DRVMGR_OBJ_DEV */ (void (*)(void *, unsigned int))drvmgr_info_dev,
379};
380
381/* Get information about a device/bus/driver */
382void drvmgr_info(void *id, unsigned int options)
383{
384        int obj_type;
385        void (*func)(void *, unsigned int);
386
387        if (!id)
388                return;
389        obj_type = *(int *)id;
390        if ((obj_type < DRVMGR_OBJ_DRV) || (obj_type > DRVMGR_OBJ_DEV))
391                return;
392        func = info_obj[obj_type - 1];
393        func(id, options);
394}
395
396void drvmgr_info_devs_on_bus(struct drvmgr_bus *bus, unsigned int options)
397{
398        struct drvmgr_dev *dev;
399
400        /* Print All Devices on Bus */
401        printf("\n\n  -= All Devices on BUS %p =-\n\n", bus);
402        dev = bus->children;
403        while (dev) {
404                drvmgr_info_dev(dev, options);
405                puts("");
406                dev = dev->next_in_bus;
407        }
408
409        if ((options & OPTION_RECURSIVE) == 0)
410                return;
411
412        /* This device provides a bus, print the bus */
413        dev = bus->children;
414        while (dev) {
415                if (dev->bus)
416                        drvmgr_info_devs_on_bus(dev->bus, options);
417                dev = dev->next_in_bus;
418        }
419}
420
421void drvmgr_info_devs(unsigned int options)
422{
423        struct rtems_driver_manager *mgr = &drv_mgr;
424        struct drvmgr_dev *dev;
425
426        /* Print device information of all devices and their child devices */
427        dev = &mgr->root_dev;
428        drvmgr_info_devs_on_bus(dev->bus, options);
429        printf("\n\n");
430}
431
432void drvmgr_info_drvs(unsigned int options)
433{
434        struct rtems_driver_manager *mgr = &drv_mgr;
435        struct drvmgr_drv *drv;
436
437        drv = DRV_LIST_HEAD(&mgr->drivers);
438        while (drv) {
439                drvmgr_info_drv(drv, options);
440                puts("\n");
441                drv = drv->next;
442        }
443}
444
445void drvmgr_info_buses(unsigned int options)
446{
447        struct rtems_driver_manager *mgr = &drv_mgr;
448        struct drvmgr_bus *bus;
449
450        bus = BUS_LIST_HEAD(&mgr->buses[DRVMGR_LEVEL_MAX]);
451        while (bus) {
452                drvmgr_info_bus(bus, options);
453                puts("\n");
454                bus = bus->next;
455        }
456}
Note: See TracBrowser for help on using the repository browser.