Changeset 040068c in mainline for uspace/srv/devman/devman.c
- Timestamp:
- 2010-12-09T00:28:58Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cdc1aa1
- Parents:
- 818dc00 (diff), 0a5a950 (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
r818dc00 r040068c 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 688 static FIBRIL_MUTEX_INITIALIZE(add_device_guard); 639 689 640 690 /** Pass a device to running driver. … … 645 695 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree) 646 696 { 647 printf(NAME ": add_device\n"); 697 fibril_mutex_lock(&add_device_guard); 698 699 /* 700 * We do not expect to have driver's mutex locked as we do not 701 * access any structures that would affect driver_t. 702 */ 703 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 704 node->name); 648 705 649 706 ipcarg_t rc; … … 657 714 parent_handle = 0; 658 715 } 716 659 717 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle, 660 718 parent_handle, &answer); … … 666 724 /* TODO handle error */ 667 725 } 668 726 669 727 /* Wait for answer from the driver. */ 670 728 async_wait_for(req, &rc); 729 730 fibril_mutex_unlock(&add_device_guard); 731 671 732 switch(rc) { 672 733 case EOK: … … 681 742 } 682 743 744 node->passed_to_driver = true; 745 683 746 return; 684 747 } … … 706 769 attach_driver(node, drv); 707 770 771 fibril_mutex_lock(&drv->driver_mutex); 708 772 if (drv->state == DRIVER_NOT_STARTED) { 709 773 /* Start the driver. */ 710 774 start_driver(drv); 711 775 } 712 713 if (drv->state == DRIVER_RUNNING) { 776 bool is_running = drv->state == DRIVER_RUNNING; 777 fibril_mutex_unlock(&drv->driver_mutex); 778 779 if (is_running) { 714 780 /* Notify the driver about the new device. */ 715 int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);781 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 716 782 if (phone > 0) { 717 783 add_device(phone, drv, node, tree); … … 875 941 node->name = dev_name; 876 942 if (!set_dev_path(node, parent)) { 877 fibril_rwlock_write_unlock(&tree->rwlock);878 943 return false; 879 944 } … … 1097 1162 while (link != &class_list->classes) { 1098 1163 cl = list_get_instance(link, dev_class_t, link); 1099 if (str_cmp(cl->name, class_name) == 0) 1164 if (str_cmp(cl->name, class_name) == 0) { 1100 1165 return cl; 1166 } 1167 link = link->next; 1101 1168 } 1102 1169
Note:
See TracChangeset
for help on using the changeset viewer.