Changeset 957cfa58 in mainline for uspace/srv/devman/devman.h


Ignore:
Timestamp:
2010-05-26T20:25:43Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c9f3b45c
Parents:
d51ee2b
Message:

devman - use hash table to lookup device according to its handle.

File:
1 edited

Legend:

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

    rd51ee2b r957cfa58  
    3939#include <str.h>
    4040#include <adt/list.h>
     41#include <adt/hash_table.h>
    4142#include <ipc/ipc.h>
    4243#include <ipc/devman.h>
     
    5051
    5152#define MATCH_EXT ".ma"
    52 #define MAX_DEV 256
     53#define DEVICE_BUCKETS 256
    5354
    5455struct node;
     
    115116        /** List of child device nodes. */
    116117        link_t children;
    117         /** Fibril mutex for the list of child device nodes of this node. */
    118         fibril_mutex_t children_mutex;
    119118        /** List of device ids for device-to-driver matching.*/
    120119        match_id_list_t match_ids;
     
    128127        /** The list of device classes to which this device belongs.*/
    129128        link_t classes;
     129        /** Devmap handle if the device is registered by devmapper. */
     130        dev_handle_t devmap_handle;
     131        /** Used by the hash table of devices indexed by devman device handles.*/
     132        link_t devman_link;
     133        /** Used by the hash table of devices indexed by devmap device handles.*/
     134        link_t devmap_link;
    130135};
     136
    131137
    132138/** Represents device tree.
     
    136142        node_t *root_node;
    137143        /** The next available handle - handles are assigned in a sequential manner.*/
    138         atomic_t current_handle;
    139         /** Handle-to-node mapping. */
    140         node_t * node_map[MAX_DEV];
     144        device_handle_t current_handle;
     145        /** Synchronize access to the device tree.*/
     146        fibril_rwlock_t rwlock;
     147        /** Hash table of all devices indexed by devman handles.*/
     148        hash_table_t devman_devices;
     149        /** Hash table of devices registered by devmapper, indexed by devmap handles.*/
     150        hash_table_t devmap_devices;
     151       
    141152} dev_tree_t;
    142153
     
    277288        list_initialize(&res->children);
    278289        list_initialize(&res->match_ids.ids);
    279         fibril_mutex_initialize(&res->children_mutex);
    280290       
    281291        return res;
     
    301311 * Find the device node structure of the device witch has the specified handle.
    302312 *
     313 * Device tree's rwlock should be held at least for reading.
     314 *
    303315 * @param tree the device tree where we look for the device node.
    304316 * @param handle the handle of the device.
    305317 * @return the device node.
    306318 */
    307 static inline node_t * find_dev_node(dev_tree_t *tree, long handle)
    308 {
    309         if (handle < MAX_DEV) {
    310                 return tree->node_map[handle];
    311         }
    312         return NULL;
     319static inline node_t * find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
     320{
     321        unsigned long key = handle;
     322        link_t *link = hash_table_find(&tree->devman_devices, &key);
     323        return hash_table_get_instance(link, node_t, devman_link);
     324}
     325
     326/**
     327 * Find the device node structure of the device witch has the specified handle.
     328 *
     329 * @param tree the device tree where we look for the device node.
     330 * @param handle the handle of the device.
     331 * @return the device node.
     332 */
     333static inline node_t * find_dev_node(dev_tree_t *tree, device_handle_t handle)
     334{
     335        node_t *node = NULL;
     336       
     337        fibril_rwlock_read_lock(&tree->rwlock);
     338       
     339        node = find_dev_node_no_lock(tree, handle);
     340       
     341        fibril_rwlock_read_unlock(&tree->rwlock);
     342       
     343        return node;
    313344}
    314345
Note: See TracChangeset for help on using the changeset viewer.