Changeset bda60d9 in mainline for uspace/srv/devman/devman.c


Ignore:
Timestamp:
2010-03-19T14:40:14Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d347b53
Parents:
7707954
Message:

adding child device - parts of code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    r7707954 rbda60d9  
    320320        node_t *node = create_dev_node();
    321321        if (node) {
    322                 insert_dev_node(tree, node, NULL);
     322                insert_dev_node(tree, node, "", NULL);
    323323                match_id_t *id = create_match_id();
    324324                id->id = "root";
     
    410410}
    411411
     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 */
    412418driver_t * find_driver(driver_list_t *drv_list, const char *drv_name)
    413419{       
     
    432438}
    433439
     440/** Remember the driver's phone.
     441 * @param driver the driver.
     442 * @param phone the phone to the driver.
     443 */
    434444void set_driver_phone(driver_t *driver, ipcarg_t phone)
    435445{               
     
    467477}
    468478
    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.
    470481 *
    471482 * Pass devices formerly matched to the driver to the driver and remember the driver is running and fully functional now.
     
    559570        printf(NAME ": init_device_tree.\n");
    560571       
     572        memset(tree->node_map, 0, MAX_DEV * sizeof(node_t *));
     573       
    561574        atomic_set(&tree->current_handle, 0);
    562575       
     
    570583}
    571584
     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 */
     591static 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 */
     624bool 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
    572656/** @}
    573657 */
Note: See TracChangeset for help on using the changeset viewer.