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.com/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 */ |
---|
14 | int 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 */ |
---|
54 | struct 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 != KEY_TYPE_NONE) { |
---|
65 | if (strcmp(key_name, key->key_name) == 0) |
---|
66 | return key; |
---|
67 | key++; |
---|
68 | } |
---|
69 | return NULL; |
---|
70 | } |
---|
71 | |
---|
72 | union drvmgr_key_value *drvmgr_key_val_get( |
---|
73 | struct drvmgr_key *keys, |
---|
74 | char *key_name, |
---|
75 | int 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 == -1) || (key_match->key_type == key_type)) |
---|
83 | return &key_match->key_value; |
---|
84 | } |
---|
85 | return NULL; |
---|
86 | } |
---|
87 | |
---|
88 | union drvmgr_key_value *drvmgr_dev_key_get( |
---|
89 | struct drvmgr_dev *dev, |
---|
90 | char *key_name, |
---|
91 | int key_type) |
---|
92 | { |
---|
93 | struct drvmgr_key *keys = NULL; |
---|
94 | |
---|
95 | /* Find first entry in key array for the device */ |
---|
96 | if (drvmgr_keys_get(dev, &keys)) |
---|
97 | return NULL; |
---|
98 | |
---|
99 | /* Find a specific key among the device keys */ |
---|
100 | return drvmgr_key_val_get(keys, key_name, key_type); |
---|
101 | } |
---|