[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 | */
|
---|
| 32 |
|
---|
| 33 | #ifndef LIBC_IPC_DEVMAN_H_
|
---|
| 34 | #define LIBC_IPC_DEVMAN_H_
|
---|
| 35 |
|
---|
[bda60d9] | 36 | #include <adt/list.h>
|
---|
[e2b9a993] | 37 | #include <ipc/ipc.h>
|
---|
[bda60d9] | 38 | #include <stdlib.h>
|
---|
[5af21c5] | 39 | #include <stdio.h>
|
---|
[c47e1a8] | 40 | #include <str.h>
|
---|
[e2b9a993] | 41 |
|
---|
[729fa2d6] | 42 | #define DEVMAN_NAME_MAXLEN 256
|
---|
| 43 |
|
---|
[bda60d9] | 44 | typedef ipcarg_t device_handle_t;
|
---|
| 45 |
|
---|
| 46 | /** Ids of device models used for device-to-driver matching.
|
---|
| 47 | */
|
---|
| 48 | typedef struct match_id {
|
---|
| 49 | /** Pointers to next and previous ids.
|
---|
| 50 | */
|
---|
| 51 | link_t link;
|
---|
| 52 | /** Id of device model.
|
---|
| 53 | */
|
---|
[c47e1a8] | 54 | const char *id;
|
---|
[bda60d9] | 55 | /** Relevancy of device-to-driver match.
|
---|
| 56 | * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
|
---|
| 57 | * the more suitable is the leaf driver for handling the device.
|
---|
| 58 | */
|
---|
| 59 | unsigned int score;
|
---|
| 60 | } match_id_t;
|
---|
| 61 |
|
---|
| 62 | /** List of ids for matching devices to drivers sorted
|
---|
| 63 | * according to match scores in descending order.
|
---|
| 64 | */
|
---|
| 65 | typedef struct match_id_list {
|
---|
| 66 | link_t ids;
|
---|
| 67 | } match_id_list_t;
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | static inline match_id_t * create_match_id()
|
---|
| 71 | {
|
---|
| 72 | match_id_t *id = malloc(sizeof(match_id_t));
|
---|
| 73 | memset(id, 0, sizeof(match_id_t));
|
---|
| 74 | return id;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | static inline void delete_match_id(match_id_t *id)
|
---|
| 78 | {
|
---|
| 79 | if (id) {
|
---|
| 80 | if (NULL != id->id) {
|
---|
| 81 | free(id->id);
|
---|
| 82 | }
|
---|
| 83 | free(id);
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
|
---|
| 88 | {
|
---|
| 89 | match_id_t *mid = NULL;
|
---|
| 90 | link_t *link = ids->ids.next;
|
---|
| 91 |
|
---|
| 92 | while (link != &ids->ids) {
|
---|
| 93 | mid = list_get_instance(link, match_id_t,link);
|
---|
| 94 | if (mid->score < id->score) {
|
---|
| 95 | break;
|
---|
| 96 | }
|
---|
| 97 | link = link->next;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | list_insert_before(&id->link, link);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[5af21c5] | 103 | static inline void init_match_ids(match_id_list_t *id_list)
|
---|
| 104 | {
|
---|
| 105 | list_initialize(&id_list->ids);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[bda60d9] | 108 | static inline void clean_match_ids(match_id_list_t *ids)
|
---|
| 109 | {
|
---|
| 110 | link_t *link = NULL;
|
---|
| 111 | match_id_t *id;
|
---|
| 112 |
|
---|
| 113 | while(!list_empty(&ids->ids)) {
|
---|
| 114 | link = ids->ids.next;
|
---|
| 115 | list_remove(link);
|
---|
| 116 | id = list_get_instance(link, match_id_t, link);
|
---|
| 117 | delete_match_id(id);
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[924c75e1] | 121 | typedef enum {
|
---|
| 122 | DEVMAN_DRIVER = 1,
|
---|
| 123 | DEVMAN_CLIENT,
|
---|
[5cd136ab] | 124 | DEVMAN_CONNECT_TO_DEVICE,
|
---|
| 125 | DEVMAN_CONNECT_TO_PARENTS_DEVICE
|
---|
[924c75e1] | 126 | } devman_interface_t;
|
---|
[e2b9a993] | 127 |
|
---|
| 128 | typedef enum {
|
---|
| 129 | DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
|
---|
[66babbd] | 130 | DEVMAN_ADD_CHILD_DEVICE,
|
---|
| 131 | DEVMAN_ADD_MATCH_ID
|
---|
[e2b9a993] | 132 |
|
---|
[924c75e1] | 133 | } driver_to_devman_t;
|
---|
| 134 |
|
---|
| 135 | typedef enum {
|
---|
| 136 | DRIVER_ADD_DEVICE = IPC_FIRST_USER_METHOD
|
---|
| 137 |
|
---|
| 138 | } devman_to_driver_t;
|
---|
[e2b9a993] | 139 |
|
---|
[f658458] | 140 | typedef enum {
|
---|
| 141 | DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD
|
---|
| 142 | } client_to_devman_t;
|
---|
| 143 |
|
---|
[c16cf62] | 144 | #endif
|
---|
[e2b9a993] | 145 |
|
---|
[c16cf62] | 146 | /** @}
|
---|
| 147 | */ |
---|