Changeset fc02cc41 in mainline
- Timestamp:
- 2009-06-10T19:15:00Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba2a055
- Parents:
- 95ba2b8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r95ba2b8 rfc02cc41 42 42 #include <errno.h> 43 43 #include <bool.h> 44 #include <fibril_sync.h> 44 45 #include <stdlib.h> 45 46 #include <string.h> … … 62 63 /** Device driver name */ 63 64 char *name; 65 /** Fibril mutex for list of devices owned by this driver */ 66 fibril_mutex_t devices_mutex; 64 67 } devmap_driver_t; 65 68 … … 92 95 LIST_INITIALIZE(pending_req); 93 96 97 /* Locking order: 98 * drivers_list_mutex 99 * devices_list_mutex 100 * (devmap_driver_t *)->devices_mutex 101 * create_handle_mutex 102 **/ 103 104 static FIBRIL_MUTEX_INITIALIZE(devices_list_mutex); 105 static FIBRIL_MUTEX_INITIALIZE(drivers_list_mutex); 106 static FIBRIL_MUTEX_INITIALIZE(create_handle_mutex); 107 94 108 static dev_handle_t last_handle = 0; 95 109 … … 100 114 */ 101 115 116 fibril_mutex_lock(&create_handle_mutex); 102 117 last_handle++; 118 fibril_mutex_unlock(&create_handle_mutex); 103 119 104 120 return last_handle; … … 134 150 static devmap_device_t *devmap_device_find_handle(dev_handle_t handle) 135 151 { 152 fibril_mutex_lock(&devices_list_mutex); 153 136 154 link_t *item = (&devices_list)->next; 137 155 devmap_device_t *device = NULL; … … 144 162 } 145 163 146 if (item == &devices_list) 164 if (item == &devices_list) { 165 fibril_mutex_unlock(&devices_list_mutex); 147 166 return NULL; 167 } 148 168 149 169 device = list_get_instance(item, devmap_device_t, devices); 170 171 fibril_mutex_unlock(&devices_list_mutex); 150 172 151 173 return device; … … 236 258 driver->name[name_size] = 0; 237 259 260 /* Initialize mutex for list of devices owned by this driver */ 261 fibril_mutex_initialize(&driver->devices_mutex); 262 238 263 /* 239 264 * Initialize list of asociated devices 240 265 */ 241 list_initialize(& (driver->devices));266 list_initialize(&driver->devices); 242 267 243 268 /* … … 262 287 list_initialize(&(driver->drivers)); 263 288 289 fibril_mutex_lock(&drivers_list_mutex); 290 264 291 /* TODO: 265 292 * check that no driver with name equal to driver->name is registered … … 270 297 */ 271 298 list_append(&(driver->drivers), &drivers_list); 299 fibril_mutex_unlock(&drivers_list_mutex); 272 300 273 301 ipc_answer_0(iid, EOK); … … 286 314 return EEXISTS; 287 315 316 fibril_mutex_lock(&drivers_list_mutex); 317 288 318 if (driver->phone != 0) 289 319 ipc_hangup(driver->phone); … … 291 321 /* Remove it from list of drivers */ 292 322 list_remove(&(driver->drivers)); 323 324 /* Unregister all its devices */ 325 fibril_mutex_lock(&devices_list_mutex); 326 fibril_mutex_lock(&driver->devices_mutex); 293 327 294 328 while (!list_empty(&(driver->devices))) { … … 298 332 } 299 333 334 fibril_mutex_unlock(&driver->devices_mutex); 335 fibril_mutex_unlock(&devices_list_mutex); 336 fibril_mutex_unlock(&drivers_list_mutex); 337 300 338 /* free name and driver */ 301 339 if (driver->name != NULL) … … 311 349 static void process_pending_lookup(void) 312 350 { 313 async_serialize_start();314 315 351 link_t *cur; 316 352 … … 331 367 goto loop; 332 368 } 333 334 async_serialize_end();335 369 } 336 370 … … 386 420 list_initialize(&(device->driver_devices)); 387 421 422 fibril_mutex_lock(&devices_list_mutex); 423 388 424 /* Check that device with such name is not already registered */ 389 425 if (NULL != devmap_device_find_name(device->name)) { 390 426 printf(NAME ": Device '%s' already registered\n", device->name); 427 fibril_mutex_unlock(&devices_list_mutex); 391 428 free(device->name); 392 429 free(device); … … 403 440 list_append(&device->devices, &devices_list); 404 441 442 /* Insert device into list of devices that belog to one driver */ 443 fibril_mutex_lock(&device->driver->devices_mutex); 444 405 445 list_append(&device->driver_devices, &device->driver->devices); 446 447 fibril_mutex_unlock(&device->driver->devices_mutex); 448 fibril_mutex_unlock(&devices_list_mutex); 406 449 407 450 ipc_answer_1(iid, EOK, device->handle); … … 556 599 static void devmap_get_count(ipc_callid_t iid, ipc_call_t *icall) 557 600 { 601 fibril_mutex_lock(&devices_list_mutex); 558 602 ipc_answer_1(iid, EOK, list_count(&devices_list)); 603 fibril_mutex_unlock(&devices_list_mutex); 559 604 } 560 605 561 606 static void devmap_get_devices(ipc_callid_t iid, ipc_call_t *icall) 562 607 { 608 fibril_mutex_lock(&devices_list_mutex); 609 563 610 ipc_callid_t callid; 564 611 size_t size; … … 604 651 free(desc); 605 652 653 fibril_mutex_unlock(&devices_list_mutex); 654 606 655 ipc_answer_1(iid, EOK, pos); 607 656 } … … 627 676 list_initialize(&(device->driver_devices)); 628 677 678 fibril_mutex_lock(&devices_list_mutex); 679 629 680 /* Get unique device handle */ 630 681 device->handle = devmap_create_handle(); … … 633 684 /* Insert device into list of all devices */ 634 685 list_append(&device->devices, &devices_list); 686 687 fibril_mutex_unlock(&devices_list_mutex); 635 688 636 689 return true; … … 656 709 ipc_callid_t callid = async_get_call(&call); 657 710 658 async_serialize_start();659 660 711 switch (IPC_GET_METHOD(call)) { 661 712 case IPC_M_PHONE_HUNGUP: 662 713 cont = false; 663 async_serialize_end();664 714 continue; 665 715 case DEVMAP_DRIVER_UNREGISTER: … … 687 737 ipc_answer_0(callid, ENOENT); 688 738 } 689 690 async_serialize_end();691 739 } 692 740 … … 695 743 * Unregister the device driver and all its devices. 696 744 */ 697 698 async_serialize_start();699 700 745 devmap_driver_unregister(driver); 701 746 driver = NULL; 702 703 async_serialize_end();704 747 } 705 748 } … … 718 761 ipc_callid_t callid = async_get_call(&call); 719 762 720 async_serialize_start();721 722 763 switch (IPC_GET_METHOD(call)) { 723 764 case IPC_M_PHONE_HUNGUP: 724 765 cont = false; 725 async_serialize_end();726 766 continue; 727 767 case DEVMAP_DEVICE_GET_HANDLE: … … 741 781 ipc_answer_0(callid, ENOENT); 742 782 } 743 744 async_serialize_end();745 783 } 746 784 }
Note:
See TracChangeset
for help on using the changeset viewer.