[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 |
|
---|
[8b1e15ac] | 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 |
|
---|
[bda60d9] | 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 | */
|
---|
[c47e1a8] | 62 | const char *id;
|
---|
[bda60d9] | 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 {
|
---|
[b72efe8] | 74 | list_t ids;
|
---|
[bda60d9] | 75 | } match_id_list_t;
|
---|
| 76 |
|
---|
[64d2b10] | 77 | static inline match_id_t *create_match_id(void)
|
---|
[bda60d9] | 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 |
|
---|
[64d2b10] | 94 | static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
|
---|
[bda60d9] | 95 | {
|
---|
| 96 | match_id_t *mid = NULL;
|
---|
[b72efe8] | 97 | link_t *link = ids->ids.head.next;
|
---|
[bda60d9] | 98 |
|
---|
[b72efe8] | 99 | while (link != &ids->ids.head) {
|
---|
[bda60d9] | 100 | mid = list_get_instance(link, match_id_t,link);
|
---|
| 101 | if (mid->score < id->score) {
|
---|
| 102 | break;
|
---|
[b72efe8] | 103 | }
|
---|
[bda60d9] | 104 | link = link->next;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[64d2b10] | 107 | list_insert_before(&id->link, link);
|
---|
[bda60d9] | 108 | }
|
---|
| 109 |
|
---|
[5af21c5] | 110 | static inline void init_match_ids(match_id_list_t *id_list)
|
---|
| 111 | {
|
---|
| 112 | list_initialize(&id_list->ids);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[bda60d9] | 115 | static inline void clean_match_ids(match_id_list_t *ids)
|
---|
| 116 | {
|
---|
| 117 | link_t *link = NULL;
|
---|
| 118 | match_id_t *id;
|
---|
| 119 |
|
---|
[b72efe8] | 120 | while (!list_empty(&ids->ids)) {
|
---|
| 121 | link = list_first(&ids->ids);
|
---|
| 122 | list_remove(link);
|
---|
[bda60d9] | 123 | id = list_get_instance(link, match_id_t, link);
|
---|
[b72efe8] | 124 | delete_match_id(id);
|
---|
| 125 | }
|
---|
[bda60d9] | 126 | }
|
---|
| 127 |
|
---|
[924c75e1] | 128 | typedef enum {
|
---|
| 129 | DEVMAN_DRIVER = 1,
|
---|
| 130 | DEVMAN_CLIENT,
|
---|
[5cd136ab] | 131 | DEVMAN_CONNECT_TO_DEVICE,
|
---|
[15f3c3f] | 132 | DEVMAN_CONNECT_FROM_LOC,
|
---|
[5cd136ab] | 133 | DEVMAN_CONNECT_TO_PARENTS_DEVICE
|
---|
[924c75e1] | 134 | } devman_interface_t;
|
---|
[e2b9a993] | 135 |
|
---|
| 136 | typedef enum {
|
---|
| 137 | DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
|
---|
[8b1e15ac] | 138 | DEVMAN_ADD_FUNCTION,
|
---|
[692c40cb] | 139 | DEVMAN_ADD_MATCH_ID,
|
---|
[d0dd7b5] | 140 | DEVMAN_ADD_DEVICE_TO_CATEGORY,
|
---|
| 141 | DEVMAN_REMOVE_FUNCTION
|
---|
[924c75e1] | 142 | } driver_to_devman_t;
|
---|
| 143 |
|
---|
| 144 | typedef enum {
|
---|
| 145 | DRIVER_ADD_DEVICE = IPC_FIRST_USER_METHOD
|
---|
| 146 |
|
---|
| 147 | } devman_to_driver_t;
|
---|
[e2b9a993] | 148 |
|
---|
[f658458] | 149 | typedef enum {
|
---|
[fc8c2b6] | 150 | DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
|
---|
[e280857] | 151 | DEVMAN_DEVICE_GET_DEVICE_PATH,
|
---|
| 152 | DEVMAN_FUN_SID_TO_HANDLE
|
---|
[f658458] | 153 | } client_to_devman_t;
|
---|
| 154 |
|
---|
[c16cf62] | 155 | #endif
|
---|
[e2b9a993] | 156 |
|
---|
[c16cf62] | 157 | /** @}
|
---|
[47a7174f] | 158 | */
|
---|