Changeset 791f58c in mainline for uspace/srv/devman/devman.c


Ignore:
Timestamp:
2010-10-23T16:42:08Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
713a4b9
Parents:
c6c389ed
Message:

Convert inline functions to regular.

File:
1 edited

Legend:

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

    rc6c389ed r791f58c  
    7676        .remove_callback = devices_remove_callback
    7777};
     78
     79/**
     80 * Initialize the list of device driver's.
     81 *
     82 * @param drv_list the list of device driver's.
     83 *
     84 */
     85void init_driver_list(driver_list_t *drv_list)
     86{
     87        assert(drv_list != NULL);
     88       
     89        list_initialize(&drv_list->drivers);
     90        fibril_mutex_initialize(&drv_list->drivers_mutex);
     91}
    7892
    7993/** Allocate and initialize a new driver structure.
     
    548562}
    549563
     564/** Initialize device driver structure.
     565 *
     566 * @param drv           The device driver structure.
     567 */
     568void init_driver(driver_t *drv)
     569{
     570        assert(drv != NULL);
     571
     572        memset(drv, 0, sizeof(driver_t));
     573        list_initialize(&drv->match_ids.ids);
     574        list_initialize(&drv->devices);
     575        fibril_mutex_initialize(&drv->driver_mutex);
     576}
     577
     578/** Device driver structure clean-up.
     579 *
     580 * @param drv           The device driver structure.
     581 */
     582void clean_driver(driver_t *drv)
     583{
     584        assert(drv != NULL);
     585
     586        free_not_null(drv->name);
     587        free_not_null(drv->binary_path);
     588
     589        clean_match_ids(&drv->match_ids);
     590
     591        init_driver(drv);
     592}
     593
     594/** Delete device driver structure.
     595 *
     596 * @param drv           The device driver structure.
     597 */
     598void delete_driver(driver_t *drv)
     599{
     600        assert(drv != NULL);
     601       
     602        clean_driver(drv);
     603        free(drv);
     604}
    550605
    551606/** Create devmap path and name for the device. */
     
    685740}
    686741
     742/* Device nodes */
     743
     744/** Create a new device node.
     745 *
     746 * @return              A device node structure.
     747 */
     748node_t *create_dev_node(void)
     749{
     750        node_t *res = malloc(sizeof(node_t));
     751       
     752        if (res != NULL) {
     753                memset(res, 0, sizeof(node_t));
     754                list_initialize(&res->children);
     755                list_initialize(&res->match_ids.ids);
     756                list_initialize(&res->classes);
     757        }
     758       
     759        return res;
     760}
     761
     762/** Delete a device node.
     763 *
     764 * @param node          The device node structure.
     765 */
     766void delete_dev_node(node_t *node)
     767{
     768        assert(list_empty(&node->children));
     769        assert(node->parent == NULL);
     770        assert(node->drv == NULL);
     771       
     772        clean_match_ids(&node->match_ids);
     773        free_not_null(node->name);
     774        free_not_null(node->pathname);
     775        free(node);
     776}
     777
     778/** Find the device node structure of the device witch has the specified handle.
     779 *
     780 * Device tree's rwlock should be held at least for reading.
     781 *
     782 * @param tree          The device tree where we look for the device node.
     783 * @param handle        The handle of the device.
     784 * @return              The device node.
     785 */
     786node_t *find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
     787{
     788        unsigned long key = handle;
     789        link_t *link = hash_table_find(&tree->devman_devices, &key);
     790        return hash_table_get_instance(link, node_t, devman_link);
     791}
     792
     793/** Find the device node structure of the device witch has the specified handle.
     794 *
     795 * @param tree          The device tree where we look for the device node.
     796 * @param handle        The handle of the device.
     797 * @return              The device node.
     798 */
     799node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
     800{
     801        node_t *node = NULL;
     802       
     803        fibril_rwlock_read_lock(&tree->rwlock);
     804        node = find_dev_node_no_lock(tree, handle);
     805        fibril_rwlock_read_unlock(&tree->rwlock);
     806       
     807        return node;
     808}
     809
     810
    687811/** Create and set device's full path in device tree.
    688812 *
     
    825949        return NULL;
    826950}
     951
     952/* Device classes */
     953
     954/** Create device class.
     955 *
     956 * @return      Device class.
     957 */
     958dev_class_t *create_dev_class(void)
     959{
     960        dev_class_t *cl;
     961       
     962        cl = (dev_class_t *) malloc(sizeof(dev_class_t));
     963        if (cl != NULL) {
     964                memset(cl, 0, sizeof(dev_class_t));
     965                list_initialize(&cl->devices);
     966                fibril_mutex_initialize(&cl->mutex);
     967        }
     968       
     969        return cl;
     970}
     971
     972/** Create device class info.
     973 *
     974 * @return              Device class info.
     975 */
     976dev_class_info_t *create_dev_class_info(void)
     977{
     978        dev_class_info_t *info;
     979       
     980        info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
     981        if (info != NULL)
     982                memset(info, 0, sizeof(dev_class_info_t));
     983       
     984        return info;
     985}
     986
     987size_t get_new_class_dev_idx(dev_class_t *cl)
     988{
     989        size_t dev_idx;
     990       
     991        fibril_mutex_lock(&cl->mutex);
     992        dev_idx = ++cl->curr_dev_idx;
     993        fibril_mutex_unlock(&cl->mutex);
     994       
     995        return dev_idx;
     996}
     997
    827998
    828999/** Create unique device name within the class.
     
    9211092}
    9221093
     1094void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
     1095{
     1096        list_append(&cl->link, &class_list->classes);
     1097}
     1098
    9231099void init_class_list(class_list_t *class_list)
    9241100{
     
    9301106
    9311107
    932 /* devmap devices */
     1108/* Devmap devices */
    9331109
    9341110node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle)
     
    9671143}
    9681144
     1145void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     1146{
     1147        unsigned long key = (unsigned long) cli->devmap_handle;
     1148       
     1149        fibril_rwlock_write_lock(&class_list->rwlock);
     1150        hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     1151        fibril_rwlock_write_unlock(&class_list->rwlock);
     1152}
     1153
     1154void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
     1155{
     1156        unsigned long key = (unsigned long) node->devmap_handle;
     1157        fibril_rwlock_write_lock(&tree->rwlock);
     1158        hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     1159        fibril_rwlock_write_unlock(&tree->rwlock);
     1160}
     1161
    9691162/** @}
    9701163 */
Note: See TracChangeset for help on using the changeset viewer.