[c16cf62] | 1 | /*
|
---|
[a1769ee] | 2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
[af6b5157] | 3 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[c16cf62] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libdrv
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
[7a252ec8] | 35 |
|
---|
[af6b5157] | 36 | #ifndef DDF_DRIVER_H_
|
---|
| 37 | #define DDF_DRIVER_H_
|
---|
[c16cf62] | 38 |
|
---|
[79ae36dd] | 39 | #include <async.h>
|
---|
[bda60d9] | 40 | #include <ipc/devman.h>
|
---|
[a1769ee] | 41 | #include <ipc/dev_iface.h>
|
---|
[af6b5157] | 42 | #include "../dev_iface.h"
|
---|
[22027b6e] | 43 |
|
---|
[83a2f43] | 44 | typedef struct ddf_dev ddf_dev_t;
|
---|
| 45 | typedef struct ddf_fun ddf_fun_t;
|
---|
[8b1e15ac] | 46 |
|
---|
[97adec8] | 47 | /*
|
---|
[af6b5157] | 48 | * Device
|
---|
[97adec8] | 49 | */
|
---|
[3843ecb] | 50 |
|
---|
[97adec8] | 51 | /** Devices operations */
|
---|
[83a2f43] | 52 | typedef struct ddf_dev_ops {
|
---|
[7a252ec8] | 53 | /**
|
---|
| 54 | * Optional callback function called when a client is connecting to the
|
---|
| 55 | * device.
|
---|
| 56 | */
|
---|
[83a2f43] | 57 | int (*open)(ddf_fun_t *);
|
---|
[7a252ec8] | 58 |
|
---|
| 59 | /**
|
---|
| 60 | * Optional callback function called when a client is disconnecting from
|
---|
| 61 | * the device.
|
---|
| 62 | */
|
---|
[83a2f43] | 63 | void (*close)(ddf_fun_t *);
|
---|
[7a252ec8] | 64 |
|
---|
[08d9525a] | 65 | /** The table of standard interfaces implemented by the device. */
|
---|
[7a252ec8] | 66 | void *interfaces[DEV_IFACE_COUNT];
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
| 69 | * The default handler of remote client requests. If the client's remote
|
---|
| 70 | * request cannot be handled by any of the standard interfaces, the
|
---|
| 71 | * default handler is used.
|
---|
| 72 | */
|
---|
[08d9525a] | 73 | remote_handler_t *default_handler;
|
---|
[83a2f43] | 74 | } ddf_dev_ops_t;
|
---|
[3843ecb] | 75 |
|
---|
[97adec8] | 76 | /** Device structure */
|
---|
[83a2f43] | 77 | struct ddf_dev {
|
---|
[7a252ec8] | 78 | /**
|
---|
| 79 | * Globally unique device identifier (assigned to the device by the
|
---|
| 80 | * device manager).
|
---|
| 81 | */
|
---|
[0b5a4131] | 82 | devman_handle_t handle;
|
---|
[77ad86c] | 83 |
|
---|
[0f0f8bc] | 84 | /** Reference count */
|
---|
| 85 | atomic_t refcnt;
|
---|
[7a252ec8] | 86 |
|
---|
| 87 | /**
|
---|
[79ae36dd] | 88 | * Session to the parent device driver (if it is different from this
|
---|
[97adec8] | 89 | * driver)
|
---|
[7a252ec8] | 90 | */
|
---|
[79ae36dd] | 91 | async_sess_t *parent_sess;
|
---|
[7a252ec8] | 92 |
|
---|
[97adec8] | 93 | /** Device name */
|
---|
[bda60d9] | 94 | const char *name;
|
---|
[8b1e15ac] | 95 |
|
---|
[97adec8] | 96 | /** Driver-specific data associated with this device */
|
---|
[eff1a590] | 97 | void *driver_data;
|
---|
[7a252ec8] | 98 |
|
---|
[97adec8] | 99 | /** Link in the list of devices handled by the driver */
|
---|
[084ff99] | 100 | link_t link;
|
---|
[a1769ee] | 101 | };
|
---|
[c16cf62] | 102 |
|
---|
[8b1e15ac] | 103 | /** Function structure */
|
---|
[83a2f43] | 104 | struct ddf_fun {
|
---|
[97a62fe] | 105 | /** True if bound to the device manager */
|
---|
| 106 | bool bound;
|
---|
[77ad86c] | 107 |
|
---|
[8b1e15ac] | 108 | /** Function indentifier (asigned by device manager) */
|
---|
| 109 | devman_handle_t handle;
|
---|
[77ad86c] | 110 |
|
---|
[0f0f8bc] | 111 | /** Reference count */
|
---|
| 112 | atomic_t refcnt;
|
---|
[8b1e15ac] | 113 |
|
---|
| 114 | /** Device which this function belogs to */
|
---|
[83a2f43] | 115 | ddf_dev_t *dev;
|
---|
[8b1e15ac] | 116 |
|
---|
| 117 | /** Function type */
|
---|
| 118 | fun_type_t ftype;
|
---|
[77ad86c] | 119 |
|
---|
[8b1e15ac] | 120 | /** Function name */
|
---|
| 121 | const char *name;
|
---|
[77ad86c] | 122 |
|
---|
[8b1e15ac] | 123 | /** List of device ids for driver matching */
|
---|
| 124 | match_id_list_t match_ids;
|
---|
[77ad86c] | 125 |
|
---|
[8b1e15ac] | 126 | /** Driver-specific data associated with this function */
|
---|
| 127 | void *driver_data;
|
---|
[77ad86c] | 128 |
|
---|
[8b1e15ac] | 129 | /** Implementation of operations provided by this function */
|
---|
[83a2f43] | 130 | ddf_dev_ops_t *ops;
|
---|
[77ad86c] | 131 |
|
---|
[ff65e91] | 132 | /** Connection handler or @c NULL to use the DDF default handler. */
|
---|
| 133 | async_client_conn_t conn_handler;
|
---|
[8b1e15ac] | 134 |
|
---|
| 135 | /** Link in the list of functions handled by the driver */
|
---|
| 136 | link_t link;
|
---|
| 137 | };
|
---|
| 138 |
|
---|
[97adec8] | 139 | /*
|
---|
| 140 | * Driver
|
---|
| 141 | */
|
---|
[a1769ee] | 142 |
|
---|
[97adec8] | 143 | /** Generic device driver operations */
|
---|
[a1769ee] | 144 | typedef struct driver_ops {
|
---|
[97adec8] | 145 | /** Callback method for passing a new device to the device driver */
|
---|
[0c0f823b] | 146 | int (*dev_add)(ddf_dev_t *);
|
---|
[77ad86c] | 147 |
|
---|
[1a5b252] | 148 | /** Ask driver to remove a device */
|
---|
| 149 | int (*dev_remove)(ddf_dev_t *);
|
---|
[77ad86c] | 150 |
|
---|
[80a96d2] | 151 | /** Inform driver a device disappeared */
|
---|
| 152 | int (*dev_gone)(ddf_dev_t *);
|
---|
[77ad86c] | 153 |
|
---|
[1a5b252] | 154 | /** Ask driver to online a specific function */
|
---|
| 155 | int (*fun_online)(ddf_fun_t *);
|
---|
[77ad86c] | 156 |
|
---|
[1a5b252] | 157 | /** Ask driver to offline a specific function */
|
---|
| 158 | int (*fun_offline)(ddf_fun_t *);
|
---|
[c16cf62] | 159 | } driver_ops_t;
|
---|
| 160 |
|
---|
[97adec8] | 161 | /** Driver structure */
|
---|
[c16cf62] | 162 | typedef struct driver {
|
---|
[97adec8] | 163 | /** Name of the device driver */
|
---|
[c16cf62] | 164 | const char *name;
|
---|
[97adec8] | 165 | /** Generic device driver operations */
|
---|
[c16cf62] | 166 | driver_ops_t *driver_ops;
|
---|
| 167 | } driver_t;
|
---|
| 168 |
|
---|
[2a770a35] | 169 | extern int ddf_driver_main(driver_t *);
|
---|
[c16cf62] | 170 |
|
---|
[c5be39b] | 171 | extern void *ddf_dev_data_alloc(ddf_dev_t *, size_t);
|
---|
[83a2f43] | 172 | extern ddf_fun_t *ddf_fun_create(ddf_dev_t *, fun_type_t, const char *);
|
---|
| 173 | extern void ddf_fun_destroy(ddf_fun_t *);
|
---|
[c5be39b] | 174 | extern void *ddf_fun_data_alloc(ddf_fun_t *, size_t);
|
---|
[83a2f43] | 175 | extern int ddf_fun_bind(ddf_fun_t *);
|
---|
[d0dd7b5] | 176 | extern int ddf_fun_unbind(ddf_fun_t *);
|
---|
[1a5b252] | 177 | extern int ddf_fun_online(ddf_fun_t *);
|
---|
| 178 | extern int ddf_fun_offline(ddf_fun_t *);
|
---|
[83a2f43] | 179 | extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int);
|
---|
[97a62fe] | 180 |
|
---|
[1dc4a5e] | 181 | extern int ddf_fun_add_to_category(ddf_fun_t *, const char *);
|
---|
[692c40cb] | 182 |
|
---|
[c16cf62] | 183 | #endif
|
---|
| 184 |
|
---|
| 185 | /**
|
---|
| 186 | * @}
|
---|
[a1769ee] | 187 | */
|
---|