[e2b9a993] | 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 | */
|
---|
[64d2b10] | 32 |
|
---|
[e2b9a993] | 33 | #ifndef LIBC_IPC_DEVMAN_H_
|
---|
| 34 | #define LIBC_IPC_DEVMAN_H_
|
---|
| 35 |
|
---|
[64d2b10] | 36 | #include <ipc/common.h>
|
---|
[bda60d9] | 37 | #include <adt/list.h>
|
---|
[64d2b10] | 38 | #include <malloc.h>
|
---|
| 39 | #include <mem.h>
|
---|
[e2b9a993] | 40 |
|
---|
[64d2b10] | 41 | #define DEVMAN_NAME_MAXLEN 256
|
---|
[729fa2d6] | 42 |
|
---|
[96b02eb9] | 43 | typedef sysarg_t devman_handle_t;
|
---|
[bda60d9] | 44 |
|
---|
[e5556e4a] | 45 | typedef enum {
|
---|
| 46 | /** Driver has not been started. */
|
---|
| 47 | DRIVER_NOT_STARTED = 0,
|
---|
| 48 |
|
---|
| 49 | /**
|
---|
| 50 | * Driver has been started, but has not registered as running and ready
|
---|
| 51 | * to receive requests.
|
---|
| 52 | */
|
---|
| 53 | DRIVER_STARTING,
|
---|
| 54 |
|
---|
| 55 | /** Driver is running and prepared to serve incomming requests. */
|
---|
| 56 | DRIVER_RUNNING
|
---|
| 57 | } driver_state_t;
|
---|
| 58 |
|
---|
[8b1e15ac] | 59 | typedef enum {
|
---|
| 60 | /** Invalid value for debugging purposes */
|
---|
| 61 | fun_invalid = 0,
|
---|
| 62 | /** Function to which child devices attach */
|
---|
| 63 | fun_inner,
|
---|
| 64 | /** Fuction exported to external clients (leaf function) */
|
---|
| 65 | fun_exposed
|
---|
| 66 | } fun_type_t;
|
---|
| 67 |
|
---|
[bda60d9] | 68 | /** Ids of device models used for device-to-driver matching.
|
---|
| 69 | */
|
---|
| 70 | typedef struct match_id {
|
---|
| 71 | /** Pointers to next and previous ids.
|
---|
| 72 | */
|
---|
| 73 | link_t link;
|
---|
| 74 | /** Id of device model.
|
---|
| 75 | */
|
---|
[c47e1a8] | 76 | const char *id;
|
---|
[bda60d9] | 77 | /** Relevancy of device-to-driver match.
|
---|
| 78 | * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
|
---|
| 79 | * the more suitable is the leaf driver for handling the device.
|
---|
| 80 | */
|
---|
| 81 | unsigned int score;
|
---|
| 82 | } match_id_t;
|
---|
| 83 |
|
---|
| 84 | /** List of ids for matching devices to drivers sorted
|
---|
| 85 | * according to match scores in descending order.
|
---|
| 86 | */
|
---|
| 87 | typedef struct match_id_list {
|
---|
[b72efe8] | 88 | list_t ids;
|
---|
[bda60d9] | 89 | } match_id_list_t;
|
---|
| 90 |
|
---|
[64d2b10] | 91 | static inline match_id_t *create_match_id(void)
|
---|
[bda60d9] | 92 | {
|
---|
| 93 | match_id_t *id = malloc(sizeof(match_id_t));
|
---|
| 94 | memset(id, 0, sizeof(match_id_t));
|
---|
| 95 | return id;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | static inline void delete_match_id(match_id_t *id)
|
---|
| 99 | {
|
---|
| 100 | if (id) {
|
---|
| 101 | if (NULL != id->id) {
|
---|
| 102 | free(id->id);
|
---|
| 103 | }
|
---|
| 104 | free(id);
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[64d2b10] | 108 | static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
|
---|
[bda60d9] | 109 | {
|
---|
| 110 | match_id_t *mid = NULL;
|
---|
[b72efe8] | 111 | link_t *link = ids->ids.head.next;
|
---|
[bda60d9] | 112 |
|
---|
[b72efe8] | 113 | while (link != &ids->ids.head) {
|
---|
[bda60d9] | 114 | mid = list_get_instance(link, match_id_t,link);
|
---|
| 115 | if (mid->score < id->score) {
|
---|
| 116 | break;
|
---|
[b72efe8] | 117 | }
|
---|
[bda60d9] | 118 | link = link->next;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[64d2b10] | 121 | list_insert_before(&id->link, link);
|
---|
[bda60d9] | 122 | }
|
---|
| 123 |
|
---|
[5af21c5] | 124 | static inline void init_match_ids(match_id_list_t *id_list)
|
---|
| 125 | {
|
---|
| 126 | list_initialize(&id_list->ids);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[bda60d9] | 129 | static inline void clean_match_ids(match_id_list_t *ids)
|
---|
| 130 | {
|
---|
| 131 | link_t *link = NULL;
|
---|
| 132 | match_id_t *id;
|
---|
| 133 |
|
---|
[b72efe8] | 134 | while (!list_empty(&ids->ids)) {
|
---|
| 135 | link = list_first(&ids->ids);
|
---|
| 136 | list_remove(link);
|
---|
[bda60d9] | 137 | id = list_get_instance(link, match_id_t, link);
|
---|
[b72efe8] | 138 | delete_match_id(id);
|
---|
| 139 | }
|
---|
[bda60d9] | 140 | }
|
---|
| 141 |
|
---|
[924c75e1] | 142 | typedef enum {
|
---|
| 143 | DEVMAN_DRIVER = 1,
|
---|
| 144 | DEVMAN_CLIENT,
|
---|
[5cd136ab] | 145 | DEVMAN_CONNECT_TO_DEVICE,
|
---|
[15f3c3f] | 146 | DEVMAN_CONNECT_FROM_LOC,
|
---|
[5cd136ab] | 147 | DEVMAN_CONNECT_TO_PARENTS_DEVICE
|
---|
[924c75e1] | 148 | } devman_interface_t;
|
---|
[e2b9a993] | 149 |
|
---|
| 150 | typedef enum {
|
---|
| 151 | DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
|
---|
[8b1e15ac] | 152 | DEVMAN_ADD_FUNCTION,
|
---|
[692c40cb] | 153 | DEVMAN_ADD_MATCH_ID,
|
---|
[d0dd7b5] | 154 | DEVMAN_ADD_DEVICE_TO_CATEGORY,
|
---|
[1a5b252] | 155 | DEVMAN_DRV_FUN_ONLINE,
|
---|
| 156 | DEVMAN_DRV_FUN_OFFLINE,
|
---|
[d0dd7b5] | 157 | DEVMAN_REMOVE_FUNCTION
|
---|
[924c75e1] | 158 | } driver_to_devman_t;
|
---|
| 159 |
|
---|
| 160 | typedef enum {
|
---|
[1a5b252] | 161 | DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD,
|
---|
| 162 | DRIVER_DEV_REMOVE,
|
---|
[80a96d2] | 163 | DRIVER_DEV_GONE,
|
---|
[1a5b252] | 164 | DRIVER_FUN_ONLINE,
|
---|
| 165 | DRIVER_FUN_OFFLINE,
|
---|
[924c75e1] | 166 | } devman_to_driver_t;
|
---|
[e2b9a993] | 167 |
|
---|
[f658458] | 168 | typedef enum {
|
---|
[fc8c2b6] | 169 | DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
|
---|
[7beb220] | 170 | DEVMAN_DEV_GET_FUNCTIONS,
|
---|
| 171 | DEVMAN_FUN_GET_CHILD,
|
---|
| 172 | DEVMAN_FUN_GET_NAME,
|
---|
[3f57fb7] | 173 | DEVMAN_FUN_GET_DRIVER_NAME,
|
---|
[1a5b252] | 174 | DEVMAN_FUN_ONLINE,
|
---|
| 175 | DEVMAN_FUN_OFFLINE,
|
---|
[7beb220] | 176 | DEVMAN_FUN_GET_PATH,
|
---|
[0511549] | 177 | DEVMAN_FUN_SID_TO_HANDLE,
|
---|
| 178 | DEVMAN_GET_DRIVERS,
|
---|
[7969087] | 179 | DEVMAN_DRIVER_GET_HANDLE,
|
---|
[e5556e4a] | 180 | DEVMAN_DRIVER_GET_NAME,
|
---|
[7969087] | 181 | DEVMAN_DRIVER_GET_STATE,
|
---|
| 182 | DEVMAN_DRIVER_LOAD
|
---|
[f658458] | 183 | } client_to_devman_t;
|
---|
| 184 |
|
---|
[c16cf62] | 185 | #endif
|
---|
[e2b9a993] | 186 |
|
---|
[c16cf62] | 187 | /** @}
|
---|
[47a7174f] | 188 | */
|
---|