Changeset bda60d9 in mainline for uspace/srv/devman/devman.c
- Timestamp:
- 2010-03-19T14:40:14Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d347b53
- Parents:
- 7707954
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r7707954 rbda60d9 320 320 node_t *node = create_dev_node(); 321 321 if (node) { 322 insert_dev_node(tree, node, NULL);322 insert_dev_node(tree, node, "", NULL); 323 323 match_id_t *id = create_match_id(); 324 324 id->id = "root"; … … 410 410 } 411 411 412 /** Find device driver in the list of device drivers. 413 * 414 * @param drv_list the list of device drivers. 415 * @param drv_name the name of the device driver which is searched. 416 * @return the device driver of the specified name, if it is in the list, NULL otherwise. 417 */ 412 418 driver_t * find_driver(driver_list_t *drv_list, const char *drv_name) 413 419 { … … 432 438 } 433 439 440 /** Remember the driver's phone. 441 * @param driver the driver. 442 * @param phone the phone to the driver. 443 */ 434 444 void set_driver_phone(driver_t *driver, ipcarg_t phone) 435 445 { … … 467 477 } 468 478 469 /** Finish the initialization of a driver after it has succesfully started and registered itself by the device manager. 479 /** Finish the initialization of a driver after it has succesfully started 480 * and after it has registered itself by the device manager. 470 481 * 471 482 * Pass devices formerly matched to the driver to the driver and remember the driver is running and fully functional now. … … 559 570 printf(NAME ": init_device_tree.\n"); 560 571 572 memset(tree->node_map, 0, MAX_DEV * sizeof(node_t *)); 573 561 574 atomic_set(&tree->current_handle, 0); 562 575 … … 570 583 } 571 584 585 /** Create and set device's full path in device tree. 586 * 587 * @param node the device's device node. 588 * @param parent the parent device node. 589 * @return true on success, false otherwise (insufficient resources etc.). 590 */ 591 static bool set_dev_path(node_t *node, node_t *parent) 592 { 593 assert(NULL != node->name); 594 595 size_t pathsize = (str_size(node->name) + 1); 596 if (NULL != parent) { 597 pathsize += str_size(parent->name) + 1; 598 } 599 600 if (NULL == (node->pathname = (char *)malloc(pathsize))) { 601 printf(NAME ": failed to allocate device path.\n"); 602 return false; 603 } 604 605 if (NULL != parent) { 606 str_cpy(node->pathname, pathsize, parent->pathname); 607 str_append(node->pathname, pathsize, "/"); 608 str_append(node->pathname, pathsize, node->name); 609 } else { 610 str_cpy(node->pathname, pathsize, node->name); 611 } 612 613 return true; 614 } 615 616 /** Insert new device into device tree. 617 * 618 * @param tree the device tree. 619 * @param node the newly added device node. 620 * @param dev_name the name of the newly added device. 621 * @param parent the parent device node. 622 * @return true on success, false otherwise (insufficient resources etc.). 623 */ 624 bool insert_dev_node(dev_tree_t *tree, node_t *node, const char *dev_name, node_t *parent) 625 { 626 printf(NAME ": insert_dev_node\n"); 627 628 assert(NULL != node && NULL != tree && dev_name != NULL); 629 630 node->name = dev_name; 631 if (!set_dev_path(node, parent)) { 632 return false; 633 } 634 635 // add the node to the handle-to-node map 636 node->handle = atomic_postinc(&tree->current_handle); 637 if (node->handle >= MAX_DEV) { 638 printf(NAME ": failed to add device to device tree, because maximum number of devices was reached.\n"); 639 free(node->pathname); 640 node->pathname = NULL; 641 atomic_postdec(&tree->current_handle); 642 return false; 643 } 644 tree->node_map[node->handle] = node; 645 646 // add the node to the list of its parent's children 647 node->parent = parent; 648 if (NULL != parent) { 649 fibril_mutex_lock(&parent->children_mutex); 650 list_append(&node->sibling, &parent->children); 651 fibril_mutex_unlock(&parent->children_mutex); 652 } 653 return true; 654 } 655 572 656 /** @} 573 657 */
Note:
See TracChangeset
for help on using the changeset viewer.