| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Lenka Trochtova
|
|---|
| 3 | * Copyright (c) 2011 Jiri Svoboda
|
|---|
| 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 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef DDF_DRIVER_H_
|
|---|
| 37 | #define DDF_DRIVER_H_
|
|---|
| 38 |
|
|---|
| 39 | #include <async.h>
|
|---|
| 40 | #include <ipc/devman.h>
|
|---|
| 41 | #include <ipc/dev_iface.h>
|
|---|
| 42 | #include "../dev_iface.h"
|
|---|
| 43 |
|
|---|
| 44 | typedef struct ddf_dev ddf_dev_t;
|
|---|
| 45 | typedef struct ddf_fun ddf_fun_t;
|
|---|
| 46 |
|
|---|
| 47 | /*
|
|---|
| 48 | * Device
|
|---|
| 49 | */
|
|---|
| 50 |
|
|---|
| 51 | /** Devices operations */
|
|---|
| 52 | typedef struct ddf_dev_ops {
|
|---|
| 53 | /**
|
|---|
| 54 | * Optional callback function called when a client is connecting to the
|
|---|
| 55 | * device.
|
|---|
| 56 | */
|
|---|
| 57 | int (*open)(ddf_fun_t *);
|
|---|
| 58 |
|
|---|
| 59 | /**
|
|---|
| 60 | * Optional callback function called when a client is disconnecting from
|
|---|
| 61 | * the device.
|
|---|
| 62 | */
|
|---|
| 63 | void (*close)(ddf_fun_t *);
|
|---|
| 64 |
|
|---|
| 65 | /** The table of standard interfaces implemented by the device. */
|
|---|
| 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 | */
|
|---|
| 73 | remote_handler_t *default_handler;
|
|---|
| 74 | } ddf_dev_ops_t;
|
|---|
| 75 |
|
|---|
| 76 | /** Device structure */
|
|---|
| 77 | struct ddf_dev {
|
|---|
| 78 | /**
|
|---|
| 79 | * Globally unique device identifier (assigned to the device by the
|
|---|
| 80 | * device manager).
|
|---|
| 81 | */
|
|---|
| 82 | devman_handle_t handle;
|
|---|
| 83 | /** Reference count */
|
|---|
| 84 | atomic_t refcnt;
|
|---|
| 85 |
|
|---|
| 86 | /**
|
|---|
| 87 | * Session to the parent device driver (if it is different from this
|
|---|
| 88 | * driver)
|
|---|
| 89 | */
|
|---|
| 90 | async_sess_t *parent_sess;
|
|---|
| 91 |
|
|---|
| 92 | /** Device name */
|
|---|
| 93 | const char *name;
|
|---|
| 94 |
|
|---|
| 95 | /** Driver-specific data associated with this device */
|
|---|
| 96 | void *driver_data;
|
|---|
| 97 |
|
|---|
| 98 | /** Link in the list of devices handled by the driver */
|
|---|
| 99 | link_t link;
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | /** Function structure */
|
|---|
| 103 | struct ddf_fun {
|
|---|
| 104 | /** True if bound to the device manager */
|
|---|
| 105 | bool bound;
|
|---|
| 106 | /** Function indentifier (asigned by device manager) */
|
|---|
| 107 | devman_handle_t handle;
|
|---|
| 108 | /** Reference count */
|
|---|
| 109 | atomic_t refcnt;
|
|---|
| 110 |
|
|---|
| 111 | /** Device which this function belogs to */
|
|---|
| 112 | ddf_dev_t *dev;
|
|---|
| 113 |
|
|---|
| 114 | /** Function type */
|
|---|
| 115 | fun_type_t ftype;
|
|---|
| 116 | /** Function name */
|
|---|
| 117 | const char *name;
|
|---|
| 118 | /** List of device ids for driver matching */
|
|---|
| 119 | match_id_list_t match_ids;
|
|---|
| 120 | /** Driver-specific data associated with this function */
|
|---|
| 121 | void *driver_data;
|
|---|
| 122 | /** Implementation of operations provided by this function */
|
|---|
| 123 | ddf_dev_ops_t *ops;
|
|---|
| 124 | /** Connection handler or @c NULL to use the DDF default handler. */
|
|---|
| 125 | async_client_conn_t conn_handler;
|
|---|
| 126 |
|
|---|
| 127 | /** Link in the list of functions handled by the driver */
|
|---|
| 128 | link_t link;
|
|---|
| 129 | };
|
|---|
| 130 |
|
|---|
| 131 | /*
|
|---|
| 132 | * Driver
|
|---|
| 133 | */
|
|---|
| 134 |
|
|---|
| 135 | /** Generic device driver operations */
|
|---|
| 136 | typedef struct driver_ops {
|
|---|
| 137 | /** Callback method for passing a new device to the device driver */
|
|---|
| 138 | int (*dev_add)(ddf_dev_t *);
|
|---|
| 139 | /** Ask driver to remove a device */
|
|---|
| 140 | int (*dev_remove)(ddf_dev_t *);
|
|---|
| 141 | /** Inform driver a device disappeared */
|
|---|
| 142 | int (*dev_gone)(ddf_dev_t *);
|
|---|
| 143 | /** Ask driver to online a specific function */
|
|---|
| 144 | int (*fun_online)(ddf_fun_t *);
|
|---|
| 145 | /** Ask driver to offline a specific function */
|
|---|
| 146 | int (*fun_offline)(ddf_fun_t *);
|
|---|
| 147 | } driver_ops_t;
|
|---|
| 148 |
|
|---|
| 149 | /** Driver structure */
|
|---|
| 150 | typedef struct driver {
|
|---|
| 151 | /** Name of the device driver */
|
|---|
| 152 | const char *name;
|
|---|
| 153 | /** Generic device driver operations */
|
|---|
| 154 | driver_ops_t *driver_ops;
|
|---|
| 155 | } driver_t;
|
|---|
| 156 |
|
|---|
| 157 | extern int ddf_driver_main(driver_t *);
|
|---|
| 158 |
|
|---|
| 159 | extern void *ddf_dev_data_alloc(ddf_dev_t *, size_t);
|
|---|
| 160 | extern ddf_fun_t *ddf_fun_create(ddf_dev_t *, fun_type_t, const char *);
|
|---|
| 161 | extern void ddf_fun_destroy(ddf_fun_t *);
|
|---|
| 162 | extern void *ddf_fun_data_alloc(ddf_fun_t *, size_t);
|
|---|
| 163 | extern int ddf_fun_bind(ddf_fun_t *);
|
|---|
| 164 | extern int ddf_fun_unbind(ddf_fun_t *);
|
|---|
| 165 | extern int ddf_fun_online(ddf_fun_t *);
|
|---|
| 166 | extern int ddf_fun_offline(ddf_fun_t *);
|
|---|
| 167 | extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int);
|
|---|
| 168 |
|
|---|
| 169 | extern int ddf_fun_add_to_category(ddf_fun_t *, const char *);
|
|---|
| 170 |
|
|---|
| 171 | #endif
|
|---|
| 172 |
|
|---|
| 173 | /**
|
|---|
| 174 | * @}
|
|---|
| 175 | */
|
|---|