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