Changeset 4006447 in mainline for uspace/srv/devman/devman.c
- Timestamp:
- 2010-12-06T20:03:54Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c0bd08d
- Parents:
- b38dfd8 (diff), 463e734 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
rb38dfd8 r4006447 508 508 /** Notify driver about the devices to which it was assigned. 509 509 * 510 * The driver's mutex must be locked.511 *512 510 * @param driver The driver to which the devices are passed. 513 511 */ … … 518 516 int phone; 519 517 520 printf(NAME ": pass_devices_to_driver\n"); 521 522 phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 523 if (phone > 0) { 524 518 printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name); 519 520 fibril_mutex_lock(&driver->driver_mutex); 521 522 phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 523 524 if (phone < 0) { 525 fibril_mutex_unlock(&driver->driver_mutex); 526 return; 527 } 528 529 /* 530 * Go through devices list as long as there is some device 531 * that has not been passed to the driver. 532 */ 533 link = driver->devices.next; 534 while (link != &driver->devices) { 535 dev = list_get_instance(link, node_t, driver_devices); 536 if (dev->passed_to_driver) { 537 link = link->next; 538 continue; 539 } 540 541 /* 542 * We remove the device from the list to allow safe adding 543 * of new devices (no one will touch our item this way). 544 */ 545 list_remove(link); 546 547 /* 548 * Unlock to avoid deadlock when adding device 549 * handled by itself. 550 */ 551 fibril_mutex_unlock(&driver->driver_mutex); 552 553 add_device(phone, driver, dev, tree); 554 555 /* 556 * Lock again as we will work with driver's 557 * structure. 558 */ 559 fibril_mutex_lock(&driver->driver_mutex); 560 561 /* 562 * Insert the device back. 563 * The order is not relevant here so no harm is done 564 * (actually, the order would be preserved in most cases). 565 */ 566 list_append(link, &driver->devices); 567 568 /* 569 * Restart the cycle to go through all devices again. 570 */ 525 571 link = driver->devices.next; 526 while (link != &driver->devices) { 527 dev = list_get_instance(link, node_t, driver_devices); 528 add_device(phone, driver, dev, tree); 529 link = link->next; 530 } 531 532 ipc_hangup(phone); 533 } 572 } 573 574 ipc_hangup(phone); 575 576 /* 577 * Once we passed all devices to the driver, we need to mark the 578 * driver as running. 579 * It is vital to do it here and inside critical section. 580 * 581 * If we would change the state earlier, other devices added to 582 * the driver would be added to the device list and started 583 * immediately and possibly started here as well. 584 */ 585 printf(NAME ": driver %s goes into running state.\n", driver->name); 586 driver->state = DRIVER_RUNNING; 587 588 fibril_mutex_unlock(&driver->driver_mutex); 534 589 } 535 590 … … 545 600 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 546 601 { 547 printf(NAME ": initialize_running_driver\n"); 548 fibril_mutex_lock(&driver->driver_mutex); 602 printf(NAME ": initialize_running_driver (`%s')\n", driver->name); 549 603 550 604 /* … … 553 607 */ 554 608 pass_devices_to_driver(driver, tree); 555 556 /* Change driver's state to running. */557 driver->state = DRIVER_RUNNING;558 559 fibril_mutex_unlock(&driver->driver_mutex);560 609 } 561 610 … … 629 678 } 630 679 680 static FIBRIL_MUTEX_INITIALIZE(add_device_guard); 631 681 632 682 /** Pass a device to running driver. … … 637 687 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree) 638 688 { 639 printf(NAME ": add_device\n"); 689 fibril_mutex_lock(&add_device_guard); 690 691 /* 692 * We do not expect to have driver's mutex locked as we do not 693 * access any structures that would affect driver_t. 694 */ 695 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 696 node->name); 640 697 641 698 ipcarg_t rc; … … 643 700 644 701 /* Send the device to the driver. */ 645 aid_t req = async_send_1(phone, DRIVER_ADD_DEVICE, node->handle, 646 &answer); 702 devman_handle_t parent_handle; 703 if (node->parent) { 704 parent_handle = node->parent->handle; 705 } else { 706 parent_handle = 0; 707 } 708 709 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle, 710 parent_handle, &answer); 647 711 648 712 /* Send the device's name to the driver. */ … … 652 716 /* TODO handle error */ 653 717 } 654 718 655 719 /* Wait for answer from the driver. */ 656 720 async_wait_for(req, &rc); 721 722 fibril_mutex_unlock(&add_device_guard); 723 657 724 switch(rc) { 658 725 case EOK: … … 667 734 } 668 735 736 node->passed_to_driver = true; 737 669 738 return; 670 739 } … … 692 761 attach_driver(node, drv); 693 762 763 fibril_mutex_lock(&drv->driver_mutex); 694 764 if (drv->state == DRIVER_NOT_STARTED) { 695 765 /* Start the driver. */ 696 766 start_driver(drv); 697 767 } 698 699 if (drv->state == DRIVER_RUNNING) { 768 bool is_running = drv->state == DRIVER_RUNNING; 769 fibril_mutex_unlock(&drv->driver_mutex); 770 771 if (is_running) { 700 772 /* Notify the driver about the new device. */ 701 int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);773 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 702 774 if (phone > 0) { 703 775 add_device(phone, drv, node, tree); … … 861 933 node->name = dev_name; 862 934 if (!set_dev_path(node, parent)) { 863 fibril_rwlock_write_unlock(&tree->rwlock);864 935 return false; 865 936 } … … 1083 1154 while (link != &class_list->classes) { 1084 1155 cl = list_get_instance(link, dev_class_t, link); 1085 if (str_cmp(cl->name, class_name) == 0) 1156 if (str_cmp(cl->name, class_name) == 0) { 1086 1157 return cl; 1158 } 1159 link = link->next; 1087 1160 } 1088 1161
Note:
See TracChangeset
for help on using the changeset viewer.