source: rtems/cpukit/libdrvmgr/drvmgr_res.c @ 4d3e70f4

4.115
Last change on this file since 4d3e70f4 was 4d3e70f4, checked in by Daniel Hellstrom <daniel@…>, on 04/13/15 at 09:26:52

DRVMGR: KEY_TYPE now a enum drvmgr_kt

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/* Driver Manager Driver Resource 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.org/license/LICENSE.
8 */
9
10#include <string.h>
11#include <drvmgr/drvmgr.h>
12
13/* Find all the resource keys for a device among all bus resources */
14int drvmgr_keys_get(struct drvmgr_dev *dev, struct drvmgr_key **keys)
15{
16        struct drvmgr_bus *bus;
17        struct drvmgr_bus_res *node;
18        struct drvmgr_drv_res *res;
19        uint64_t drv_id;
20
21        bus = dev->parent;
22        if (!bus || !dev->drv)
23                return -1;
24
25        drv_id = dev->drv->drv_id;
26
27        /* Loop all resource arrays */
28        node = bus->reslist;
29        while (node) {
30                /* Find driver ID in resource array */
31                res = &node->resource[0];
32                while (res->drv_id) {
33                        if (res->drv_id == drv_id) {
34                                /* Found resource matching driver, now check
35                                 * that this resource is for this device.
36                                 */
37                                if (dev->minor_bus == res->minor_bus) {
38                                        /* Matching driver and core number */
39                                        if (keys)
40                                                *keys = res->keys;
41                                        return 0;
42                                }
43                        }
44                        res++;
45                }
46                node = node->next;
47        }
48        if (keys)
49                *keys = NULL;
50        return 1;
51}
52
53/* Return key that matches key name */
54struct drvmgr_key *drvmgr_key_get(
55        struct drvmgr_key *keys,
56        char *key_name)
57{
58        struct drvmgr_key *key;
59
60        if (!keys)
61                return NULL;
62
63        key = keys;
64        while (key->key_type != DRVMGR_KT_NONE) {
65                if (strcmp(key_name, key->key_name) == 0)
66                        return key;
67                key++;
68        }
69        return NULL;
70}
71
72union drvmgr_key_value *drvmgr_key_val_get(
73        struct drvmgr_key *keys,
74        char *key_name,
75        enum drvmgr_kt key_type)
76{
77        struct drvmgr_key *key_match;
78
79        key_match = drvmgr_key_get(keys, key_name);
80        if (key_match) {
81                /* Found key, put pointer to value into */
82                if ((key_type == DRVMGR_KT_ANY) ||
83                    (key_match->key_type == key_type))
84                        return &key_match->key_value;
85        }
86        return NULL;
87}
88
89union drvmgr_key_value *drvmgr_dev_key_get(
90        struct drvmgr_dev *dev,
91        char *key_name,
92        enum drvmgr_kt key_type)
93{
94        struct drvmgr_key *keys = NULL;
95
96        /* Find first entry in key array for the device */
97        if (drvmgr_keys_get(dev, &keys))
98                return NULL;
99
100        /* Find a specific key among the device keys */
101        return drvmgr_key_val_get(keys, key_name, key_type);
102}
Note: See TracBrowser for help on using the repository browser.