Changeset 80bffdb0 in mainline
- Timestamp:
- 2011-01-09T21:02:35Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8b5c8ae
- Parents:
- d6b1359 (diff), 22027b6e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/drv
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/dev_iface.c
rd6b1359 r80bffdb0 36 36 */ 37 37 38 #include <assert.h> 39 38 40 #include "dev_iface.h" 39 41 #include "remote_hw_res.h" … … 47 49 }; 48 50 49 remote_iface_t *get_remote_iface(int idx)51 remote_iface_t *get_remote_iface(int idx) 50 52 { 51 53 assert(is_valid_iface_idx(idx)); … … 59 61 return NULL; 60 62 } 63 61 64 return rem_iface->methods[iface_method_idx]; 65 } 66 67 bool is_valid_iface_idx(int idx) 68 { 69 return (0 <= idx) && (idx < DEV_IFACE_MAX); 62 70 } 63 71 -
uspace/lib/drv/generic/driver.c
rd6b1359 r80bffdb0 52 52 #include <ipc/driver.h> 53 53 54 #include "dev_iface.h" 54 55 #include "driver.h" 55 56 56 /* driver structure */ 57 57 /** Driver structure */ 58 58 static driver_t *driver; 59 59 60 /* devices */ 61 60 /** Devices */ 62 61 LIST_INITIALIZE(devices); 63 62 FIBRIL_MUTEX_INITIALIZE(devices_mutex); 64 63 65 /* interrupts */ 66 64 /** Interrupts */ 67 65 static interrupt_context_list_t interrupt_contexts; 68 66 … … 85 83 86 84 ctx = find_interrupt_context_by_id(&interrupt_contexts, id); 87 if ( NULL != ctx && NULL != ctx->handler)85 if (ctx != NULL && ctx->handler != NULL) 88 86 (*ctx->handler)(ctx->dev, iid, icall); 89 87 } 88 89 interrupt_context_t *create_interrupt_context(void) 90 { 91 interrupt_context_t *ctx; 92 93 ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t)); 94 if (ctx != NULL) 95 memset(ctx, 0, sizeof(interrupt_context_t)); 96 97 return ctx; 98 } 99 100 void delete_interrupt_context(interrupt_context_t *ctx) 101 { 102 if (ctx != NULL) 103 free(ctx); 104 } 105 106 void init_interrupt_context_list(interrupt_context_list_t *list) 107 { 108 memset(list, 0, sizeof(interrupt_context_list_t)); 109 fibril_mutex_initialize(&list->mutex); 110 list_initialize(&list->contexts); 111 } 112 113 void 114 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 115 { 116 fibril_mutex_lock(&list->mutex); 117 ctx->id = list->curr_id++; 118 list_append(&ctx->link, &list->contexts); 119 fibril_mutex_unlock(&list->mutex); 120 } 121 122 void remove_interrupt_context(interrupt_context_list_t *list, 123 interrupt_context_t *ctx) 124 { 125 fibril_mutex_lock(&list->mutex); 126 list_remove(&ctx->link); 127 fibril_mutex_unlock(&list->mutex); 128 } 129 130 interrupt_context_t * 131 find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 132 { 133 fibril_mutex_lock(&list->mutex); 134 135 link_t *link = list->contexts.next; 136 interrupt_context_t *ctx; 137 138 while (link != &list->contexts) { 139 ctx = list_get_instance(link, interrupt_context_t, link); 140 if (ctx->id == id) { 141 fibril_mutex_unlock(&list->mutex); 142 return ctx; 143 } 144 link = link->next; 145 } 146 147 fibril_mutex_unlock(&list->mutex); 148 return NULL; 149 } 150 151 interrupt_context_t * 152 find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq) 153 { 154 fibril_mutex_lock(&list->mutex); 155 156 link_t *link = list->contexts.next; 157 interrupt_context_t *ctx; 158 159 while (link != &list->contexts) { 160 ctx = list_get_instance(link, interrupt_context_t, link); 161 if (ctx->irq == irq && ctx->dev == dev) { 162 fibril_mutex_unlock(&list->mutex); 163 return ctx; 164 } 165 link = link->next; 166 } 167 168 fibril_mutex_unlock(&list->mutex); 169 return NULL; 170 } 171 90 172 91 173 int … … 101 183 add_interrupt_context(&interrupt_contexts, ctx); 102 184 103 if ( NULL == pseudocode)185 if (pseudocode == NULL) 104 186 pseudocode = &default_pseudocode; 105 187 106 188 int res = ipc_register_irq(irq, dev->handle, ctx->id, pseudocode); 107 if ( 0 != res) {189 if (res != EOK) { 108 190 remove_interrupt_context(&interrupt_contexts, ctx); 109 191 delete_interrupt_context(ctx); … … 118 200 dev, irq); 119 201 int res = ipc_unregister_irq(irq, dev->handle); 120 121 if ( NULL != ctx) {202 203 if (ctx != NULL) { 122 204 remove_interrupt_context(&interrupt_contexts, ctx); 123 205 delete_interrupt_context(ctx); 124 206 } 207 125 208 return res; 126 209 } … … 140 223 } 141 224 142 static device_t * 225 static device_t *driver_get_device(link_t *devices, devman_handle_t handle) 143 226 { 144 227 device_t *dev = NULL; … … 146 229 fibril_mutex_lock(&devices_mutex); 147 230 link_t *link = devices->next; 231 148 232 while (link != devices) { 149 233 dev = list_get_instance(link, device_t, link); 150 if ( handle == dev->handle) {234 if (dev->handle == handle) { 151 235 fibril_mutex_unlock(&devices_mutex); 152 236 return dev; … … 154 238 link = link->next; 155 239 } 240 156 241 fibril_mutex_unlock(&devices_mutex); 157 242 158 243 return NULL; 159 244 } … … 162 247 { 163 248 char *dev_name = NULL; 164 int res = EOK;165 166 devman_handle_t dev_handle = 249 int res; 250 251 devman_handle_t dev_handle = IPC_GET_ARG1(*icall); 167 252 devman_handle_t parent_dev_handle = IPC_GET_ARG2(*icall); 168 253 169 254 device_t *dev = create_device(); 170 255 dev->handle = dev_handle; … … 177 262 178 263 res = driver->driver_ops->add_device(dev); 179 if ( 0 == res) {264 if (res == EOK) { 180 265 printf("%s: new device with handle=%" PRIun " was added.\n", 181 266 driver->name, dev_handle); … … 194 279 /* Accept connection */ 195 280 ipc_answer_0(iid, EOK); 196 281 197 282 bool cont = true; 198 283 while (cont) { 199 284 ipc_call_t call; 200 285 ipc_callid_t callid = async_get_call(&call); 201 286 202 287 switch (IPC_GET_IMETHOD(call)) { 203 288 case IPC_M_PHONE_HUNGUP: … … 240 325 * use the device. 241 326 */ 242 327 243 328 int ret = EOK; 244 329 /* open the device */ 245 if ( NULL != dev->ops && NULL != dev->ops->open)330 if (dev->ops != NULL && dev->ops->open != NULL) 246 331 ret = (*dev->ops->open)(dev); 247 332 248 ipc_answer_0(iid, ret); 249 if ( EOK != ret)333 ipc_answer_0(iid, ret); 334 if (ret != EOK) 250 335 return; 251 336 252 337 while (1) { 253 338 ipc_callid_t callid; … … 258 343 259 344 switch (method) { 260 case IPC_M_PHONE_HUNGUP: 345 case IPC_M_PHONE_HUNGUP: 261 346 /* close the device */ 262 if ( NULL != dev->ops && NULL != dev->ops->close)347 if (dev->ops != NULL && dev->ops->close != NULL) 263 348 (*dev->ops->close)(dev); 264 349 ipc_answer_0(callid, EOK); 265 350 return; 266 default: 351 default: 267 352 /* convert ipc interface id to interface index */ 268 353 … … 272 357 remote_handler_t *default_handler = 273 358 device_get_default_handler(dev); 274 if ( NULL != default_handler) {359 if (default_handler != NULL) { 275 360 (*default_handler)(dev, callid, &call); 276 361 break; … … 286 371 break; 287 372 } 288 373 289 374 /* calling one of the device's interfaces */ 290 375 291 /* get the device interface structure*/292 void * iface = device_get_iface(dev, iface_idx);293 if ( NULL == iface) {376 /* Get the interface ops structure. */ 377 void *ops = device_get_ops(dev, iface_idx); 378 if (ops == NULL) { 294 379 printf("%s: driver_connection_gen error - ", 295 380 driver->name); … … 299 384 break; 300 385 } 301 386 302 387 /* 303 388 * Get the corresponding interface for remote request 304 389 * handling ("remote interface"). 305 390 */ 306 remote_iface_t *rem_iface = get_remote_iface(iface_idx);307 assert( NULL != rem_iface);308 391 remote_iface_t *rem_iface = get_remote_iface(iface_idx); 392 assert(rem_iface != NULL); 393 309 394 /* get the method of the remote interface */ 310 395 sysarg_t iface_method_idx = IPC_GET_ARG1(call); 311 396 remote_iface_func_ptr_t iface_method_ptr = 312 397 get_remote_method(rem_iface, iface_method_idx); 313 if ( NULL == iface_method_ptr) {398 if (iface_method_ptr == NULL) { 314 399 // the interface has not such method 315 400 printf("%s: driver_connection_gen error - " … … 325 410 * associated with the device by its driver. 326 411 */ 327 (*iface_method_ptr)(dev, iface, callid, &call);412 (*iface_method_ptr)(dev, ops, callid, &call); 328 413 break; 329 414 } … … 348 433 switch ((sysarg_t) (IPC_GET_ARG1(*icall))) { 349 434 case DRIVER_DEVMAN: 350 /* handle PnP eventsfrom device manager */435 /* Handle request from device manager */ 351 436 driver_connection_devman(iid, icall); 352 437 break; 353 438 case DRIVER_DRIVER: 354 /* handle request from drivers of child devices */439 /* Handle request from drivers of child devices */ 355 440 driver_connection_driver(iid, icall); 356 441 break; 357 442 case DRIVER_CLIENT: 358 /* handle requestsfrom client applications */443 /* Handle request from client applications */ 359 444 driver_connection_client(iid, icall); 360 445 break; 361 362 446 default: 363 447 /* No such interface */ … … 366 450 } 367 451 452 /** Create new device structure. 453 * 454 * @return The device structure. 455 */ 456 device_t *create_device(void) 457 { 458 device_t *dev = malloc(sizeof(device_t)); 459 460 if (dev != NULL) { 461 memset(dev, 0, sizeof(device_t)); 462 init_match_ids(&dev->match_ids); 463 } 464 465 return dev; 466 } 467 468 /** Delete device structure. 469 * 470 * @param dev The device structure. 471 */ 472 void delete_device(device_t *dev) 473 { 474 clean_match_ids(&dev->match_ids); 475 if (dev->name != NULL) 476 free(dev->name); 477 free(dev); 478 } 479 480 void *device_get_ops(device_t *dev, dev_inferface_idx_t idx) 481 { 482 assert(is_valid_iface_idx(idx)); 483 if (dev->ops == NULL) 484 return NULL; 485 return dev->ops->interfaces[idx]; 486 } 487 368 488 int child_device_register(device_t *child, device_t *parent) 369 489 { 370 assert( NULL != child->name);371 490 assert(child->name != NULL); 491 372 492 int res; 373 493 … … 375 495 res = devman_child_device_register(child->name, &child->match_ids, 376 496 parent->handle, &child->handle); 377 if (EOK == res) 497 if (res != EOK) { 498 remove_from_devices_list(child); 378 499 return res; 379 remove_from_devices_list(child); 500 } 501 380 502 return res; 381 503 } … … 395 517 match_id_t *match_id = NULL; 396 518 int rc; 397 519 398 520 child = create_device(); 399 521 if (child == NULL) { … … 401 523 goto failure; 402 524 } 403 525 404 526 child->name = child_name; 405 527 406 528 match_id = create_match_id(); 407 529 if (match_id == NULL) { … … 409 531 goto failure; 410 532 } 411 533 412 534 match_id->id = child_match_id; 413 535 match_id->score = child_match_score; 414 536 add_match_id(&child->match_ids, match_id); 415 537 416 538 rc = child_device_register(child, parent); 417 if ( EOK != rc)539 if (rc != EOK) 418 540 goto failure; 419 541 420 542 return EOK; 421 543 422 544 failure: 423 545 if (match_id != NULL) { … … 425 547 delete_match_id(match_id); 426 548 } 427 549 428 550 if (child != NULL) { 429 551 child->name = NULL; 430 552 delete_device(child); 431 553 } 432 554 433 555 return rc; 556 } 557 558 /** Get default handler for client requests */ 559 remote_handler_t *device_get_default_handler(device_t *dev) 560 { 561 if (dev->ops == NULL) 562 return NULL; 563 return dev->ops->default_handler; 564 } 565 566 int add_device_to_class(device_t *dev, const char *class_name) 567 { 568 return devman_add_device_to_class(dev->handle, class_name); 434 569 } 435 570 … … 441 576 */ 442 577 driver = drv; 443 578 444 579 /* Initialize the list of interrupt contexts. */ 445 580 init_interrupt_context_list(&interrupt_contexts); … … 453 588 */ 454 589 devman_driver_register(driver->name, driver_connection); 455 590 456 591 async_manager(); 457 592 458 593 /* Never reached. */ 459 594 return 0; -
uspace/lib/drv/generic/remote_char_dev.c
rd6b1359 r80bffdb0 69 69 * 70 70 * @param dev The device from which the data are read. 71 * @param iface The local interfacestructure.71 * @param ops The local ops structure. 72 72 */ 73 73 static void 74 remote_char_read(device_t *dev, void * iface, ipc_callid_t callid,74 remote_char_read(device_t *dev, void *ops, ipc_callid_t callid, 75 75 ipc_call_t *call) 76 76 { 77 char_dev_ops_t *char_ iface = (char_dev_ops_t *) iface;77 char_dev_ops_t *char_dev_ops = (char_dev_ops_t *) ops; 78 78 ipc_callid_t cid; 79 79 … … 85 85 } 86 86 87 if (!char_ iface->read) {87 if (!char_dev_ops->read) { 88 88 async_data_read_finalize(cid, NULL, 0); 89 89 ipc_answer_0(callid, ENOTSUP); … … 95 95 96 96 char buf[MAX_CHAR_RW_COUNT]; 97 int ret = (*char_ iface->read)(dev, buf, len);97 int ret = (*char_dev_ops->read)(dev, buf, len); 98 98 99 99 if (ret < 0) { … … 116 116 * 117 117 * @param dev The device to which the data are written. 118 * @param iface The local interfacestructure.118 * @param ops The local ops structure. 119 119 */ 120 120 static void 121 remote_char_write(device_t *dev, void * iface, ipc_callid_t callid,121 remote_char_write(device_t *dev, void *ops, ipc_callid_t callid, 122 122 ipc_call_t *call) 123 123 { 124 char_dev_ops_t *char_ iface = (char_dev_ops_t *) iface;124 char_dev_ops_t *char_dev_ops = (char_dev_ops_t *) ops; 125 125 ipc_callid_t cid; 126 126 size_t len; … … 132 132 } 133 133 134 if (!char_ iface->write) {134 if (!char_dev_ops->write) { 135 135 async_data_write_finalize(cid, NULL, 0); 136 136 ipc_answer_0(callid, ENOTSUP); … … 145 145 async_data_write_finalize(cid, buf, len); 146 146 147 int ret = (*char_ iface->write)(dev, buf, len);147 int ret = (*char_dev_ops->write)(dev, buf, len); 148 148 if (ret < 0) { 149 149 /* Some error occured. */ -
uspace/lib/drv/generic/remote_hw_res.c
rd6b1359 r80bffdb0 40 40 #include "driver.h" 41 41 42 static void remote_ res_get_resource_list(device_t *, void *, ipc_callid_t,42 static void remote_hw_res_get_resource_list(device_t *, void *, ipc_callid_t, 43 43 ipc_call_t *); 44 static void remote_ res_enable_interrupt(device_t *, void *, ipc_callid_t,44 static void remote_hw_res_enable_interrupt(device_t *, void *, ipc_callid_t, 45 45 ipc_call_t *); 46 46 47 47 static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = { 48 &remote_ res_get_resource_list,49 &remote_ res_enable_interrupt48 &remote_hw_res_get_resource_list, 49 &remote_hw_res_enable_interrupt 50 50 }; 51 51 … … 56 56 }; 57 57 58 static void remote_ res_enable_interrupt(device_t *dev, void *iface,58 static void remote_hw_res_enable_interrupt(device_t *dev, void *ops, 59 59 ipc_callid_t callid, ipc_call_t *call) 60 60 { 61 hw_res_ops_t * ires = (hw_res_ops_t *) iface;61 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops; 62 62 63 if ( NULL == ires->enable_interrupt)63 if (hw_res_ops->enable_interrupt == NULL) 64 64 ipc_answer_0(callid, ENOTSUP); 65 else if ( ires->enable_interrupt(dev))65 else if (hw_res_ops->enable_interrupt(dev)) 66 66 ipc_answer_0(callid, EOK); 67 67 else … … 69 69 } 70 70 71 static void remote_ res_get_resource_list(device_t *dev, void *iface,71 static void remote_hw_res_get_resource_list(device_t *dev, void *ops, 72 72 ipc_callid_t callid, ipc_call_t *call) 73 73 { 74 hw_res_ops_t *ires = (hw_res_ops_t *) iface; 75 if (NULL == ires->get_resource_list) { 74 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops; 75 76 if (hw_res_ops->get_resource_list == NULL) { 76 77 ipc_answer_0(callid, ENOTSUP); 77 78 return; 78 79 } 79 80 80 hw_resource_list_t *hw_resources = ires->get_resource_list(dev);81 if ( NULL == hw_resources){81 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(dev); 82 if (hw_resources == NULL){ 82 83 ipc_answer_0(callid, ENOENT); 83 84 return; 84 } 85 } 85 86 86 ipc_answer_1(callid, EOK, hw_resources->count); 87 ipc_answer_1(callid, EOK, hw_resources->count); 87 88 88 89 size_t len; 89 90 if (!async_data_read_receive(&callid, &len)) { 90 /* protocol error - the recipient is not accepting data */91 /* Protocol error - the recipient is not accepting data */ 91 92 return; 92 93 } -
uspace/lib/drv/include/dev_iface.h
rd6b1359 r80bffdb0 36 36 #define LIBDRV_DEV_IFACE_H_ 37 37 38 #include "driver.h"38 #include <ipc/dev_iface.h> 39 39 40 /* TODO declare device interface structures here */ 40 /* 41 * Device interface 42 */ 43 44 struct device; 45 46 /* 47 * First two parameters: device and interface structure registered by the 48 * devices driver. 49 */ 50 typedef void remote_iface_func_t(struct device *, void *, ipc_callid_t, 51 ipc_call_t *); 52 typedef remote_iface_func_t *remote_iface_func_ptr_t; 53 typedef void remote_handler_t(struct device *, ipc_callid_t, ipc_call_t *); 54 55 typedef struct { 56 size_t method_count; 57 remote_iface_func_ptr_t *methods; 58 } remote_iface_t; 59 60 typedef struct { 61 remote_iface_t *ifaces[DEV_IFACE_COUNT]; 62 } iface_dipatch_table_t; 63 64 extern remote_iface_t *get_remote_iface(int); 65 extern remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t); 66 67 68 extern bool is_valid_iface_idx(int); 41 69 42 70 #endif -
uspace/lib/drv/include/driver.h
rd6b1359 r80bffdb0 47 47 #include <malloc.h> 48 48 49 #include "dev_iface.h" 50 49 51 struct device; 50 52 typedef struct device device_t; 51 53 52 /* device interface */ 54 /* 55 * Device class 56 */ 53 57 54 /* 55 * First two parameters: device and interface structure registered by the 56 * devices driver. 57 */ 58 typedef void remote_iface_func_t(device_t *, void *, ipc_callid_t, 59 ipc_call_t *); 60 typedef remote_iface_func_t *remote_iface_func_ptr_t; 61 typedef void remote_handler_t(device_t *, ipc_callid_t, ipc_call_t *); 62 63 typedef struct { 64 size_t method_count; 65 remote_iface_func_ptr_t *methods; 66 } remote_iface_t; 67 68 typedef struct { 69 remote_iface_t *ifaces[DEV_IFACE_COUNT]; 70 } iface_dipatch_table_t; 71 72 73 static inline bool is_valid_iface_idx(int idx) 74 { 75 return 0 <= idx && idx < DEV_IFACE_MAX; 76 } 77 78 remote_iface_t *get_remote_iface(int); 79 remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t); 80 81 82 /* device class */ 83 84 /** Devices operations. */ 58 /** Devices operations */ 85 59 typedef struct device_ops { 86 60 /** … … 108 82 109 83 110 /* device */ 84 /* 85 * Device 86 */ 111 87 112 /** The device.*/88 /** Device structure */ 113 89 struct device { 114 90 /** … … 119 95 120 96 /** 121 * The phone to the parent device driver (if it is different from this122 * driver) .97 * Phone to the parent device driver (if it is different from this 98 * driver) 123 99 */ 124 100 int parent_phone; 125 101 126 /** Parent device if handled by this driver, NULL otherwise .*/102 /** Parent device if handled by this driver, NULL otherwise */ 127 103 device_t *parent; 128 /** The device's name.*/104 /** Device name */ 129 105 const char *name; 130 /** The list of device ids for device-to-driver matching.*/106 /** List of device ids for device-to-driver matching */ 131 107 match_id_list_t match_ids; 132 /** The device driver's data associated with this device.*/108 /** Driver-specific data associated with this device */ 133 109 void *driver_data; 134 /** The implementation of operations provided by this device .*/110 /** The implementation of operations provided by this device */ 135 111 device_ops_t *ops; 136 112 137 /** 138 * Pointer to the previous and next device in the list of devices 139 * handled by the driver. 140 */ 113 /** Link in the list of devices handled by the driver */ 141 114 link_t link; 142 115 }; 143 116 117 /* 118 * Driver 119 */ 144 120 145 /* driver */ 146 147 /** Generic device driver operations. */ 121 /** Generic device driver operations */ 148 122 typedef struct driver_ops { 149 /** Callback method for passing a new device to the device driver .*/123 /** Callback method for passing a new device to the device driver */ 150 124 int (*add_device)(device_t *dev); 151 /* TODO add other generic driver operations */125 /* TODO: add other generic driver operations */ 152 126 } driver_ops_t; 153 127 154 /** The driver structure.*/128 /** Driver structure */ 155 129 typedef struct driver { 156 /** The name of the device driver.*/130 /** Name of the device driver */ 157 131 const char *name; 158 /** Generic device driver operations .*/132 /** Generic device driver operations */ 159 133 driver_ops_t *driver_ops; 160 134 } driver_t; … … 166 140 * @return The device structure. 167 141 */ 168 static inline device_t *create_device(void) 169 { 170 device_t *dev = malloc(sizeof(device_t)); 171 if (NULL != dev) { 172 memset(dev, 0, sizeof(device_t)); 173 init_match_ids(&dev->match_ids); 174 } 175 return dev; 176 } 142 extern device_t *create_device(void); 143 extern void delete_device(device_t *); 144 extern void *device_get_ops(device_t *, dev_inferface_idx_t); 177 145 178 /** Delete device structure. 179 * 180 * @param dev The device structure. 146 extern int child_device_register(device_t *, device_t *); 147 extern int child_device_register_wrapper(device_t *, const char *, const char *, 148 int); 149 150 /* 151 * Interrupts 181 152 */ 182 static inline void delete_device(device_t *dev)183 {184 clean_match_ids(&dev->match_ids);185 if (NULL != dev->name)186 free(dev->name);187 free(dev);188 }189 190 static inline void *device_get_iface(device_t *dev, dev_inferface_idx_t idx)191 {192 assert(is_valid_iface_idx(idx));193 if (NULL == dev->ops)194 return NULL;195 return dev->ops->interfaces[idx];196 }197 198 int child_device_register(device_t *, device_t *);199 int child_device_register_wrapper(device_t *, const char *, const char *, int);200 201 202 /* interrupts */203 153 204 154 typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *); … … 218 168 } interrupt_context_list_t; 219 169 220 static inline interrupt_context_t *create_interrupt_context(void) 221 { 222 interrupt_context_t *ctx; 223 224 ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t)); 225 if (NULL != ctx) 226 memset(ctx, 0, sizeof(interrupt_context_t)); 227 228 return ctx; 229 } 170 extern interrupt_context_t *create_interrupt_context(void); 171 extern void delete_interrupt_context(interrupt_context_t *); 172 extern void init_interrupt_context_list(interrupt_context_list_t *); 173 extern void add_interrupt_context(interrupt_context_list_t *, 174 interrupt_context_t *); 175 extern void remove_interrupt_context(interrupt_context_list_t *, 176 interrupt_context_t *); 177 extern interrupt_context_t *find_interrupt_context_by_id( 178 interrupt_context_list_t *, int); 179 extern interrupt_context_t *find_interrupt_context( 180 interrupt_context_list_t *, device_t *, int); 230 181 231 static inline void delete_interrupt_context(interrupt_context_t *ctx) 232 { 233 if (NULL != ctx) 234 free(ctx); 235 } 182 extern int register_interrupt_handler(device_t *, int, interrupt_handler_t *, 183 irq_code_t *); 184 extern int unregister_interrupt_handler(device_t *, int); 236 185 237 static inline void init_interrupt_context_list(interrupt_context_list_t *list) 238 { 239 memset(list, 0, sizeof(interrupt_context_list_t)); 240 fibril_mutex_initialize(&list->mutex); 241 list_initialize(&list->contexts); 242 } 243 244 static inline void 245 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 246 { 247 fibril_mutex_lock(&list->mutex); 248 ctx->id = list->curr_id++; 249 list_append(&ctx->link, &list->contexts); 250 fibril_mutex_unlock(&list->mutex); 251 } 252 253 static inline void 254 remove_interrupt_context(interrupt_context_list_t *list, 255 interrupt_context_t *ctx) 256 { 257 fibril_mutex_lock(&list->mutex); 258 list_remove(&ctx->link); 259 fibril_mutex_unlock(&list->mutex); 260 } 261 262 static inline interrupt_context_t * 263 find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 264 { 265 fibril_mutex_lock(&list->mutex); 266 267 link_t *link = list->contexts.next; 268 interrupt_context_t *ctx; 269 270 while (link != &list->contexts) { 271 ctx = list_get_instance(link, interrupt_context_t, link); 272 if (id == ctx->id) { 273 fibril_mutex_unlock(&list->mutex); 274 return ctx; 275 } 276 link = link->next; 277 } 278 279 fibril_mutex_unlock(&list->mutex); 280 return NULL; 281 } 282 283 static inline interrupt_context_t * 284 find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq) 285 { 286 fibril_mutex_lock(&list->mutex); 287 288 link_t *link = list->contexts.next; 289 interrupt_context_t *ctx; 290 291 while (link != &list->contexts) { 292 ctx = list_get_instance(link, interrupt_context_t, link); 293 if (irq == ctx->irq && dev == ctx->dev) { 294 fibril_mutex_unlock(&list->mutex); 295 return ctx; 296 } 297 link = link->next; 298 } 299 300 fibril_mutex_unlock(&list->mutex); 301 return NULL; 302 } 303 304 int register_interrupt_handler(device_t *, int, interrupt_handler_t *, 305 irq_code_t *); 306 int unregister_interrupt_handler(device_t *, int); 307 308 309 /* default handler for client requests */ 310 311 static inline remote_handler_t *device_get_default_handler(device_t *dev) 312 { 313 if (NULL == dev->ops) 314 return NULL; 315 return dev->ops->default_handler; 316 } 317 318 static inline int add_device_to_class(device_t *dev, const char *class_name) 319 { 320 return devman_add_device_to_class(dev->handle, class_name); 321 } 186 extern remote_handler_t *device_get_default_handler(device_t *); 187 extern int add_device_to_class(device_t *, const char *); 322 188 323 189 #endif
Note:
See TracChangeset
for help on using the changeset viewer.