Changeset 7a252ec8 in mainline for uspace/lib/drv/include/driver.h
- Timestamp:
- 2010-10-21T20:13:40Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 848e3d15
- Parents:
- a79d88d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/include/driver.h
ra79d88d r7a252ec8 32 32 /** @file 33 33 */ 34 34 35 #ifndef LIBDRV_DRIVER_H_ 35 36 #define LIBDRV_DRIVER_H_ 36 37 37 38 38 #include <adt/list.h> … … 52 52 typedef struct device device_t; 53 53 54 // device interface 55 56 // first two parameters: device and interface structure registered by the devices driver 57 typedef void remote_iface_func_t(device_t*, void *, ipc_callid_t, ipc_call_t *); 54 /* device interface */ 55 56 /* 57 * First two parameters: device and interface structure registered by the 58 * devices driver. 59 */ 60 typedef void remote_iface_func_t(device_t *, void *, ipc_callid_t, 61 ipc_call_t *); 58 62 typedef remote_iface_func_t *remote_iface_func_ptr_t; 59 typedef void remote_handler_t(device_t *, ipc_callid_t, ipc_call_t *);63 typedef void remote_handler_t(device_t *, ipc_callid_t, ipc_call_t *); 60 64 61 65 typedef struct { … … 65 69 66 70 typedef struct { 67 remote_iface_t * 71 remote_iface_t *ifaces[DEV_IFACE_COUNT]; 68 72 } iface_dipatch_table_t; 69 73 … … 74 78 } 75 79 76 remote_iface_t * get_remote_iface(int idx);77 remote_iface_func_ptr_t get_remote_method(remote_iface_t * rem_iface, ipcarg_t iface_method_idx);78 79 80 / / device class80 remote_iface_t *get_remote_iface(int); 81 remote_iface_func_ptr_t get_remote_method(remote_iface_t *, ipcarg_t); 82 83 84 /* device class */ 81 85 82 86 /** Devices operations. */ 83 87 typedef struct device_ops { 84 /** Optional callback function called when a client is connecting to the device. */ 85 int (*open)(device_t *dev); 86 /** Optional callback function called when a client is disconnecting from the device. */ 87 void (*close)(device_t *dev); 88 /** 89 * Optional callback function called when a client is connecting to the 90 * device. 91 */ 92 int (*open)(device_t *); 93 94 /** 95 * Optional callback function called when a client is disconnecting from 96 * the device. 97 */ 98 void (*close)(device_t *); 99 88 100 /** The table of standard interfaces implemented by the device. */ 89 void *interfaces[DEV_IFACE_COUNT]; 90 /** The default handler of remote client requests. If the client's remote request cannot be handled 91 * by any of the standard interfaces, the default handler is used.*/ 101 void *interfaces[DEV_IFACE_COUNT]; 102 103 /** 104 * The default handler of remote client requests. If the client's remote 105 * request cannot be handled by any of the standard interfaces, the 106 * default handler is used. 107 */ 92 108 remote_handler_t *default_handler; 93 109 } device_ops_t; 94 110 95 111 96 / / device112 /* device */ 97 113 98 114 /** The device. */ 99 115 struct device { 100 /** Globally unique device identifier (assigned to the device by the device manager). */ 116 /** 117 * Globally unique device identifier (assigned to the device by the 118 * device manager). 119 */ 101 120 device_handle_t handle; 102 /** The phone to the parent device driver (if it is different from this driver).*/ 121 122 /** 123 * The phone to the parent device driver (if it is different from this 124 * driver). 125 */ 103 126 int parent_phone; 127 104 128 /** Parent device if handled by this driver, NULL otherwise. */ 105 129 device_t *parent; 106 /** The device's name. */130 /** The device's name. */ 107 131 const char *name; 108 /** The list of device ids for device-to-driver matching. */132 /** The list of device ids for device-to-driver matching. */ 109 133 match_id_list_t match_ids; 110 /** The device driver's data associated with this device. */134 /** The device driver's data associated with this device. */ 111 135 void *driver_data; 112 /** The implementation of operations provided by this device. */136 /** The implementation of operations provided by this device. */ 113 137 device_ops_t *ops; 114 /** Pointer to the previous and next device in the list of devices handled by the driver */ 138 139 /** 140 * Pointer to the previous and next device in the list of devices 141 * handled by the driver. 142 */ 115 143 link_t link; 116 144 }; 117 145 118 146 119 / / driver147 /* driver */ 120 148 121 149 /** Generic device driver operations. */ … … 123 151 /** Callback method for passing a new device to the device driver.*/ 124 152 int (*add_device)(device_t *dev); 125 / / TODO add other generic driver operations153 /* TODO add other generic driver operations */ 126 154 } driver_ops_t; 127 155 … … 134 162 } driver_t; 135 163 136 int driver_main(driver_t * drv);137 138 /** Create new device structure. 139 * 140 * @return the device structure.141 */ 142 static inline device_t * create_device()164 int driver_main(driver_t *); 165 166 /** Create new device structure. 167 * 168 * @return The device structure. 169 */ 170 static inline device_t *create_device(void) 143 171 { 144 172 device_t *dev = malloc(sizeof(device_t)); … … 150 178 } 151 179 152 /** Delete device structure. 153 * 154 * @param dev the device structure.180 /** Delete device structure. 181 * 182 * @param dev The device structure. 155 183 */ 156 184 static inline void delete_device(device_t *dev) 157 185 { 158 186 clean_match_ids(&dev->match_ids); 159 if (NULL != dev->name) {187 if (NULL != dev->name) 160 188 free(dev->name); 161 }162 189 free(dev); 163 190 } 164 191 165 static inline void * 166 { 167 assert(is_valid_iface_idx(idx)); 168 if (NULL == dev->ops) {192 static inline void *device_get_iface(device_t *dev, dev_inferface_idx_t idx) 193 { 194 assert(is_valid_iface_idx(idx)); 195 if (NULL == dev->ops) 169 196 return NULL; 170 }171 return dev->ops->interfaces[idx]; 172 } 173 174 int child_device_register(device_t *child, device_t *parent); 175 176 / / interrupts177 178 typedef void interrupt_handler_t(device_t * dev, ipc_callid_t iid, ipc_call_t *icall);197 return dev->ops->interfaces[idx]; 198 } 199 200 int child_device_register(device_t *, device_t *); 201 202 203 /* interrupts */ 204 205 typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *); 179 206 180 207 typedef struct interrupt_context { … … 192 219 } interrupt_context_list_t; 193 220 194 static inline interrupt_context_t * create_interrupt_context() 195 { 196 interrupt_context_t *ctx = (interrupt_context_t *)malloc(sizeof(interrupt_context_t)); 197 if (NULL != ctx) { 221 static inline interrupt_context_t *create_interrupt_context(void) 222 { 223 interrupt_context_t *ctx; 224 225 ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t)); 226 if (NULL != ctx) 198 227 memset(ctx, 0, sizeof(interrupt_context_t)); 199 }228 200 229 return ctx; 201 230 } … … 203 232 static inline void delete_interrupt_context(interrupt_context_t *ctx) 204 233 { 205 if (NULL != ctx) {234 if (NULL != ctx) 206 235 free(ctx); 207 }208 236 } 209 237 … … 212 240 memset(list, 0, sizeof(interrupt_context_list_t)); 213 241 fibril_mutex_initialize(&list->mutex); 214 list_initialize(&list->contexts); 215 } 216 217 static inline void add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 242 list_initialize(&list->contexts); 243 } 244 245 static inline void 246 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 218 247 { 219 248 fibril_mutex_lock(&list->mutex); 220 221 249 ctx->id = list->curr_id++; 222 250 list_append(&ctx->link, &list->contexts); 223 224 251 fibril_mutex_unlock(&list->mutex); 225 252 } 226 253 227 static inline void remove_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 254 static inline void 255 remove_interrupt_context(interrupt_context_list_t *list, 256 interrupt_context_t *ctx) 228 257 { 229 258 fibril_mutex_lock(&list->mutex); 230 231 259 list_remove(&ctx->link); 232 233 260 fibril_mutex_unlock(&list->mutex); 234 261 } 235 262 236 static inline interrupt_context_t *find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 237 { 238 fibril_mutex_lock(&list->mutex); 263 static inline interrupt_context_t * 264 find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 265 { 266 fibril_mutex_lock(&list->mutex); 267 239 268 link_t *link = list->contexts.next; 240 269 interrupt_context_t *ctx; … … 247 276 } 248 277 link = link->next; 249 } 250 fibril_mutex_unlock(&list->mutex); 278 } 279 280 fibril_mutex_unlock(&list->mutex); 251 281 return NULL; 252 282 } 253 283 254 static inline interrupt_context_t *find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq) 255 { 256 fibril_mutex_lock(&list->mutex); 284 static inline interrupt_context_t * 285 find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq) 286 { 287 fibril_mutex_lock(&list->mutex); 288 257 289 link_t *link = list->contexts.next; 258 290 interrupt_context_t *ctx; … … 265 297 } 266 298 link = link->next; 267 } 268 fibril_mutex_unlock(&list->mutex); 299 } 300 301 fibril_mutex_unlock(&list->mutex); 269 302 return NULL; 270 303 } 271 304 272 int register_interrupt_handler(device_t *dev, int irq, interrupt_handler_t *handler, irq_code_t *pseudocode); 273 int unregister_interrupt_handler(device_t *dev, int irq); 274 275 276 // default handler for client requests 277 278 static inline remote_handler_t * device_get_default_handler(device_t *dev) 279 { 280 if (NULL == dev->ops) { 305 int register_interrupt_handler(device_t *, int, interrupt_handler_t *, 306 irq_code_t *); 307 int unregister_interrupt_handler(device_t *, int); 308 309 310 /* default handler for client requests */ 311 312 static inline remote_handler_t *device_get_default_handler(device_t *dev) 313 { 314 if (NULL == dev->ops) 281 315 return NULL; 282 } 283 284 return dev->ops->default_handler; 316 return dev->ops->default_handler; 285 317 } 286 318
Note:
See TracChangeset
for help on using the changeset viewer.