Changeset 75732da in mainline for uspace/srv/devman/devman.c
- Timestamp:
- 2010-12-13T07:20:20Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 309dea52
- Parents:
- 84439d7 (diff), 37f7cfe (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
r84439d7 r75732da 516 516 /** Notify driver about the devices to which it was assigned. 517 517 * 518 * The driver's mutex must be locked.519 *520 518 * @param driver The driver to which the devices are passed. 521 519 */ … … 526 524 int phone; 527 525 528 printf(NAME ": pass_devices_to_driver\n"); 529 530 phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 531 if (phone > 0) { 532 526 printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name); 527 528 fibril_mutex_lock(&driver->driver_mutex); 529 530 phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 531 532 if (phone < 0) { 533 fibril_mutex_unlock(&driver->driver_mutex); 534 return; 535 } 536 537 /* 538 * Go through devices list as long as there is some device 539 * that has not been passed to the driver. 540 */ 541 link = driver->devices.next; 542 while (link != &driver->devices) { 543 dev = list_get_instance(link, node_t, driver_devices); 544 if (dev->passed_to_driver) { 545 link = link->next; 546 continue; 547 } 548 549 /* 550 * We remove the device from the list to allow safe adding 551 * of new devices (no one will touch our item this way). 552 */ 553 list_remove(link); 554 555 /* 556 * Unlock to avoid deadlock when adding device 557 * handled by itself. 558 */ 559 fibril_mutex_unlock(&driver->driver_mutex); 560 561 add_device(phone, driver, dev, tree); 562 563 /* 564 * Lock again as we will work with driver's 565 * structure. 566 */ 567 fibril_mutex_lock(&driver->driver_mutex); 568 569 /* 570 * Insert the device back. 571 * The order is not relevant here so no harm is done 572 * (actually, the order would be preserved in most cases). 573 */ 574 list_append(link, &driver->devices); 575 576 /* 577 * Restart the cycle to go through all devices again. 578 */ 533 579 link = driver->devices.next; 534 while (link != &driver->devices) { 535 dev = list_get_instance(link, node_t, driver_devices); 536 add_device(phone, driver, dev, tree); 537 link = link->next; 538 } 539 540 ipc_hangup(phone); 541 } 580 } 581 582 ipc_hangup(phone); 583 584 /* 585 * Once we passed all devices to the driver, we need to mark the 586 * driver as running. 587 * It is vital to do it here and inside critical section. 588 * 589 * If we would change the state earlier, other devices added to 590 * the driver would be added to the device list and started 591 * immediately and possibly started here as well. 592 */ 593 printf(NAME ": driver %s goes into running state.\n", driver->name); 594 driver->state = DRIVER_RUNNING; 595 596 fibril_mutex_unlock(&driver->driver_mutex); 542 597 } 543 598 … … 553 608 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 554 609 { 555 printf(NAME ": initialize_running_driver\n"); 556 fibril_mutex_lock(&driver->driver_mutex); 610 printf(NAME ": initialize_running_driver (`%s')\n", driver->name); 557 611 558 612 /* … … 561 615 */ 562 616 pass_devices_to_driver(driver, tree); 563 564 /* Change driver's state to running. */565 driver->state = DRIVER_RUNNING;566 567 fibril_mutex_unlock(&driver->driver_mutex);568 617 } 569 618 … … 637 686 } 638 687 639 640 688 /** Pass a device to running driver. 641 689 * … … 645 693 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree) 646 694 { 647 printf(NAME ": add_device\n"); 695 /* 696 * We do not expect to have driver's mutex locked as we do not 697 * access any structures that would affect driver_t. 698 */ 699 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 700 node->name); 648 701 649 702 ipcarg_t rc; … … 657 710 parent_handle = 0; 658 711 } 712 659 713 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle, 660 714 parent_handle, &answer); … … 666 720 /* TODO handle error */ 667 721 } 668 722 669 723 /* Wait for answer from the driver. */ 670 724 async_wait_for(req, &rc); 725 671 726 switch(rc) { 672 727 case EOK: … … 681 736 } 682 737 738 node->passed_to_driver = true; 739 683 740 return; 684 741 } … … 706 763 attach_driver(node, drv); 707 764 765 fibril_mutex_lock(&drv->driver_mutex); 708 766 if (drv->state == DRIVER_NOT_STARTED) { 709 767 /* Start the driver. */ 710 768 start_driver(drv); 711 769 } 712 713 if (drv->state == DRIVER_RUNNING) { 770 bool is_running = drv->state == DRIVER_RUNNING; 771 fibril_mutex_unlock(&drv->driver_mutex); 772 773 if (is_running) { 714 774 /* Notify the driver about the new device. */ 715 int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);775 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 716 776 if (phone > 0) { 717 777 add_device(phone, drv, node, tree); … … 875 935 node->name = dev_name; 876 936 if (!set_dev_path(node, parent)) { 877 fibril_rwlock_write_unlock(&tree->rwlock);878 937 return false; 879 938 } … … 1097 1156 while (link != &class_list->classes) { 1098 1157 cl = list_get_instance(link, dev_class_t, link); 1099 if (str_cmp(cl->name, class_name) == 0) 1158 if (str_cmp(cl->name, class_name) == 0) { 1100 1159 return cl; 1160 } 1161 link = link->next; 1101 1162 } 1102 1163
Note:
See TracChangeset
for help on using the changeset viewer.