1 | /*
|
---|
2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup devman
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | #ifndef LIBC_IPC_DEVMAN_H_
|
---|
34 | #define LIBC_IPC_DEVMAN_H_
|
---|
35 |
|
---|
36 | #include <ipc/common.h>
|
---|
37 | #include <adt/list.h>
|
---|
38 | #include <malloc.h>
|
---|
39 | #include <mem.h>
|
---|
40 |
|
---|
41 | #define DEVMAN_NAME_MAXLEN 256
|
---|
42 |
|
---|
43 | typedef sysarg_t devman_handle_t;
|
---|
44 |
|
---|
45 | typedef enum {
|
---|
46 | /** Invalid value for debugging purposes */
|
---|
47 | fun_invalid = 0,
|
---|
48 | /** Function to which child devices attach */
|
---|
49 | fun_inner,
|
---|
50 | /** Fuction exported to external clients (leaf function) */
|
---|
51 | fun_exposed
|
---|
52 | } fun_type_t;
|
---|
53 |
|
---|
54 | /** Ids of device models used for device-to-driver matching.
|
---|
55 | */
|
---|
56 | typedef struct match_id {
|
---|
57 | /** Pointers to next and previous ids.
|
---|
58 | */
|
---|
59 | link_t link;
|
---|
60 | /** Id of device model.
|
---|
61 | */
|
---|
62 | const char *id;
|
---|
63 | /** Relevancy of device-to-driver match.
|
---|
64 | * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
|
---|
65 | * the more suitable is the leaf driver for handling the device.
|
---|
66 | */
|
---|
67 | unsigned int score;
|
---|
68 | } match_id_t;
|
---|
69 |
|
---|
70 | /** List of ids for matching devices to drivers sorted
|
---|
71 | * according to match scores in descending order.
|
---|
72 | */
|
---|
73 | typedef struct match_id_list {
|
---|
74 | list_t ids;
|
---|
75 | } match_id_list_t;
|
---|
76 |
|
---|
77 | static inline match_id_t *create_match_id(void)
|
---|
78 | {
|
---|
79 | match_id_t *id = malloc(sizeof(match_id_t));
|
---|
80 | memset(id, 0, sizeof(match_id_t));
|
---|
81 | return id;
|
---|
82 | }
|
---|
83 |
|
---|
84 | static inline void delete_match_id(match_id_t *id)
|
---|
85 | {
|
---|
86 | if (id) {
|
---|
87 | if (NULL != id->id) {
|
---|
88 | free(id->id);
|
---|
89 | }
|
---|
90 | free(id);
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
|
---|
95 | {
|
---|
96 | match_id_t *mid = NULL;
|
---|
97 | link_t *link = ids->ids.head.next;
|
---|
98 |
|
---|
99 | while (link != &ids->ids.head) {
|
---|
100 | mid = list_get_instance(link, match_id_t,link);
|
---|
101 | if (mid->score < id->score) {
|
---|
102 | break;
|
---|
103 | }
|
---|
104 | link = link->next;
|
---|
105 | }
|
---|
106 |
|
---|
107 | list_insert_before(&id->link, link);
|
---|
108 | }
|
---|
109 |
|
---|
110 | static inline void init_match_ids(match_id_list_t *id_list)
|
---|
111 | {
|
---|
112 | list_initialize(&id_list->ids);
|
---|
113 | }
|
---|
114 |
|
---|
115 | static inline void clean_match_ids(match_id_list_t *ids)
|
---|
116 | {
|
---|
117 | link_t *link = NULL;
|
---|
118 | match_id_t *id;
|
---|
119 |
|
---|
120 | while (!list_empty(&ids->ids)) {
|
---|
121 | link = list_first(&ids->ids);
|
---|
122 | list_remove(link);
|
---|
123 | id = list_get_instance(link, match_id_t, link);
|
---|
124 | delete_match_id(id);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | typedef enum {
|
---|
129 | DEVMAN_DRIVER = 1,
|
---|
130 | DEVMAN_CLIENT,
|
---|
131 | DEVMAN_CONNECT_TO_DEVICE,
|
---|
132 | DEVMAN_CONNECT_FROM_LOC,
|
---|
133 | DEVMAN_CONNECT_TO_PARENTS_DEVICE
|
---|
134 | } devman_interface_t;
|
---|
135 |
|
---|
136 | typedef enum {
|
---|
137 | DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
|
---|
138 | DEVMAN_ADD_FUNCTION,
|
---|
139 | DEVMAN_ADD_MATCH_ID,
|
---|
140 | DEVMAN_ADD_DEVICE_TO_CATEGORY,
|
---|
141 | DEVMAN_REMOVE_FUNCTION
|
---|
142 | } driver_to_devman_t;
|
---|
143 |
|
---|
144 | typedef enum {
|
---|
145 | DRIVER_ADD_DEVICE = IPC_FIRST_USER_METHOD
|
---|
146 |
|
---|
147 | } devman_to_driver_t;
|
---|
148 |
|
---|
149 | typedef enum {
|
---|
150 | DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
|
---|
151 | DEVMAN_DEVICE_GET_DEVICE_PATH,
|
---|
152 | DEVMAN_FUN_SID_TO_HANDLE
|
---|
153 | } client_to_devman_t;
|
---|
154 |
|
---|
155 | #endif
|
---|
156 |
|
---|
157 | /** @}
|
---|
158 | */
|
---|