source: rtems/cpukit/libdrvmgr/drvmgr_res.c @ 5823bae8

4.115
Last change on this file since 5823bae8 was e7fade3, checked in by Daniel Hellstrom <daniel@…>, on 11/28/11 at 08:52:03

DRVMGR: added driver manager to cpukit/libdrvmgr

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/* Driver Manager Driver Resource Interface Implementation.
2 *
3 * COPYRIGHT (c) 2009.
4 * Cobham Gaisler AB.
5 *
6 * The license and distribution terms for this file may be
7 * found in the file LICENSE in this distribution or at
8 * http://www.rtems.com/license/LICENSE.
9 */
10
11#include <string.h>
12#include <drvmgr/drvmgr.h>
13
14/* Find all the resource keys for a device among all bus resources */
15int drvmgr_keys_get(struct drvmgr_dev *dev, struct drvmgr_key **keys)
16{
17        struct drvmgr_bus *bus;
18        struct drvmgr_bus_res *node;
19        struct drvmgr_drv_res *res;
20        uint64_t drv_id;
21
22        bus = dev->parent;
23        if (!bus || !dev->drv)
24                return -1;
25
26        drv_id = dev->drv->drv_id;
27
28        /* Loop all resource arrays */
29        node = bus->reslist;
30        while (node) {
31                /* Find driver ID in resource array */
32                res = &node->resource[0];
33                while (res->drv_id) {
34                        if (res->drv_id == drv_id) {
35                                /* Found resource matching driver, now check
36                                 * that this resource is for this device.
37                                 */
38                                if (dev->minor_bus == res->minor_bus) {
39                                        /* Matching driver and core number */
40                                        if (keys)
41                                                *keys = res->keys;
42                                        return 0;
43                                }
44                        }
45                        res++;
46                }
47                node = node->next;
48        }
49        if (keys)
50                *keys = NULL;
51        return 1;
52}
53
54/* Return key that matches key name */
55struct drvmgr_key *drvmgr_key_get(
56        struct drvmgr_key *keys,
57        char *key_name)
58{
59        struct drvmgr_key *key;
60
61        if (!keys)
62                return NULL;
63
64        key = keys;
65        while (key->key_type != KEY_TYPE_NONE) {
66                if (strcmp(key_name, key->key_name) == 0)
67                        return key;
68                key++;
69        }
70        return NULL;
71}
72
73union drvmgr_key_value *drvmgr_key_val_get(
74        struct drvmgr_key *keys,
75        char *key_name,
76        int key_type)
77{
78        struct drvmgr_key *key_match;
79
80        key_match = drvmgr_key_get(keys, key_name);
81        if (key_match) {
82                /* Found key, put pointer to value into */
83                if ((key_type == -1) || (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        int 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.