Changeset 38b3baf in mainline for uspace/srv/devman/devman.h


Ignore:
Timestamp:
2010-10-23T07:16:14Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7e66a5ec
Parents:
032e0bb
Message:

Cstyle fixes of devman.

File:
1 edited

Legend:

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

    r032e0bb r38b3baf  
    6161
    6262typedef enum {
    63         /** driver has not been started */
     63        /** Driver has not been started. */
    6464        DRIVER_NOT_STARTED = 0,
    65         /** driver has been started, but has not registered as running and ready to receive requests */
     65       
     66        /**
     67         * Driver has been started, but has not registered as running and ready
     68         * to receive requests.
     69         */
    6670        DRIVER_STARTING,
    67         /** driver is running and prepared to serve incomming requests */
     71       
     72        /** Driver is running and prepared to serve incomming requests. */
    6873        DRIVER_RUNNING
    6974} driver_state_t;
    7075
    71 /** Representation of device driver.
    72  */
     76/** Representation of device driver. */
    7377typedef struct driver {
    74         /** Pointers to previous and next drivers in a linked list */
     78        /** Pointers to previous and next drivers in a linked list. */
    7579        link_t drivers;
    76         /** Specifies whether the driver has been started and wheter is running and prepared to receive requests.*/
     80       
     81        /**
     82         * Specifies whether the driver has been started and wheter is running
     83         * and prepared to receive requests.
     84         */
    7785        int state;
    78         /** Phone asociated with this driver */
     86       
     87        /** Phone asociated with this driver. */
    7988        ipcarg_t phone;
    80         /** Name of the device driver */
     89        /** Name of the device driver. */
    8190        char *name;
    82         /** Path to the driver's binary */
     91        /** Path to the driver's binary. */
    8392        const char *binary_path;
    84         /** List of device ids for device-to-driver matching.*/
     93        /** List of device ids for device-to-driver matching. */
    8594        match_id_list_t match_ids;
    86         /** Pointer to the linked list of devices controlled by this driver */
     95        /** Pointer to the linked list of devices controlled by this driver. */
    8796        link_t devices;
    88         /** Fibril mutex for this driver - driver state, list of devices, phone.*/
     97       
     98        /**
     99         * Fibril mutex for this driver - driver state, list of devices, phone.
     100         */
    89101        fibril_mutex_t driver_mutex;
    90102} driver_t;
     
    95107        link_t drivers;
    96108        /** Fibril mutex for list of drivers. */
    97         fibril_mutex_t drivers_mutex;   
     109        fibril_mutex_t drivers_mutex;
    98110} driver_list_t;
    99111
     
    106118} device_state_t;
    107119
    108 /** Representation of a node in the device tree.*/
     120/** Representation of a node in the device tree. */
    109121struct node {
    110         /** The global unique identifier of the device.*/
     122        /** The global unique identifier of the device. */
    111123        device_handle_t handle;
    112124        /** The name of the device specified by its parent. */
    113125        char *name;
    114         /** Full path and name of the device in device hierarchi (i. e. in full path in device tree).*/
    115         char *pathname;
     126       
     127        /**
     128         * Full path and name of the device in device hierarchi (i. e. in full
     129         * path in device tree).
     130         */
     131        char *pathname;
     132       
    116133        /** The node of the parent device. */
    117134        node_t *parent;
    118         /** Pointers to previous and next child devices in the linked list of parent device's node.*/
     135       
     136        /**
     137         * Pointers to previous and next child devices in the linked list of
     138         * parent device's node.
     139         */
    119140        link_t sibling;
     141       
    120142        /** List of child device nodes. */
    121143        link_t children;
    122         /** List of device ids for device-to-driver matching.*/
     144        /** List of device ids for device-to-driver matching. */
    123145        match_id_list_t match_ids;
    124         /** Driver of this device.*/
     146        /** Driver of this device. */
    125147        driver_t *drv;
    126148        /** The state of the device. */
    127149        device_state_t state;
    128         /** Pointer to the previous and next device in the list of devices
    129             owned by one driver */
     150        /**
     151         * Pointer to the previous and next device in the list of devices
     152         * owned by one driver.
     153         */
    130154        link_t driver_devices;
    131         /** The list of device classes to which this device belongs.*/
     155       
     156        /** The list of device classes to which this device belongs. */
    132157        link_t classes;
    133158        /** Devmap handle if the device is registered by devmapper. */
    134159        dev_handle_t devmap_handle;
    135         /** Used by the hash table of devices indexed by devman device handles.*/
     160       
     161        /**
     162         * Used by the hash table of devices indexed by devman device handles.
     163         */
    136164        link_t devman_link;
    137         /** Used by the hash table of devices indexed by devmap device handles.*/
     165       
     166        /**
     167         * Used by the hash table of devices indexed by devmap device handles.
     168         */
    138169        link_t devmap_link;
    139170};
    140171
    141 
    142 /** Represents device tree.
    143  */
     172/** Represents device tree. */
    144173typedef struct dev_tree {
    145174        /** Root device node. */
    146175        node_t *root_node;
    147         /** The next available handle - handles are assigned in a sequential manner.*/
     176       
     177        /**
     178         * The next available handle - handles are assigned in a sequential
     179         * manner.
     180         */
    148181        device_handle_t current_handle;
    149         /** Synchronize access to the device tree.*/
     182       
     183        /** Synchronize access to the device tree. */
    150184        fibril_rwlock_t rwlock;
    151         /** Hash table of all devices indexed by devman handles.*/
     185       
     186        /** Hash table of all devices indexed by devman handles. */
    152187        hash_table_t devman_devices;
    153         /** Hash table of devices registered by devmapper, indexed by devmap handles.*/
     188       
     189        /**
     190         * Hash table of devices registered by devmapper, indexed by devmap
     191         * handles.
     192         */
    154193        hash_table_t devmap_devices;
    155194} dev_tree_t;
    156195
    157 typedef struct dev_class {     
    158         /** The name of the class.*/
     196typedef struct dev_class {
     197        /** The name of the class. */
    159198        const char *name;
    160         /** Pointer to the previous and next class in the list of registered classes.*/
    161         link_t link;   
    162         /** List of dev_class_info structures - one for each device registered by this class.*/
     199       
     200        /**
     201         * Pointer to the previous and next class in the list of registered
     202         * classes.
     203         */
     204        link_t link;
     205       
     206        /**
     207         * List of dev_class_info structures - one for each device registered by
     208         * this class.
     209         */
    163210        link_t devices;
    164         /** Default base name for the device within the class, might be overrided by the driver.*/     
     211       
     212        /**
     213         * Default base name for the device within the class, might be overrided
     214         * by the driver.
     215         */
    165216        const char *base_dev_name;
    166         /** Unique numerical identifier of the newly added device.*/
     217       
     218        /** Unique numerical identifier of the newly added device. */
    167219        size_t curr_dev_idx;
    168220        /** Synchronize access to the list of devices in this class. */
     
    170222} dev_class_t;
    171223
    172 /** Provides n-to-m mapping between device nodes and classes
    173  * - each device may be register to the arbitrary number of classes
    174  * and each class may contain the arbitrary number of devices. */
     224/** Provides n-to-m mapping between device nodes and classes - each device may
     225 * be register to the arbitrary number of classes and each class may contain
     226 * the arbitrary number of devices.
     227 */
    175228typedef struct dev_class_info {
    176         /** The class.*/
     229        /** The class. */
    177230        dev_class_t *dev_class;
    178         /** The device.*/
     231        /** The device. */
    179232        node_t *dev;
    180         /** Pointer to the previous and next class info in the list of devices registered by the class.*/
     233       
     234        /**
     235         * Pointer to the previous and next class info in the list of devices
     236         * registered by the class.
     237         */
    181238        link_t link;
    182         /** Pointer to the previous and next class info in the list of classes by which the device is registered.*/
     239       
     240        /**
     241         * Pointer to the previous and next class info in the list of classes
     242         * by which the device is registered.
     243         */
    183244        link_t dev_classes;
    184         /** The name of the device within the class.*/
    185         char *dev_name;
    186         /** The handle of the device by device mapper in the class namespace.*/
     245       
     246        /** The name of the device within the class. */
     247        char *dev_name;
     248        /** The handle of the device by device mapper in the class namespace. */
    187249        dev_handle_t devmap_handle;
    188         /** Link in the hash table of devices registered by the devmapper using their class names.*/
     250       
     251        /**
     252         * Link in the hash table of devices registered by the devmapper using
     253         * their class names.
     254         */
    189255        link_t devmap_link;
    190256} dev_class_info_t;
     
    192258/** The list of device classes. */
    193259typedef struct class_list {
    194         /** List of classes */
     260        /** List of classes. */
    195261        link_t classes;
    196         /** Hash table of devices registered by devmapper using their class name, indexed by devmap handles.*/
     262       
     263        /**
     264         * Hash table of devices registered by devmapper using their class name,
     265         * indexed by devmap handles.
     266         */
    197267        hash_table_t devmap_devices;
     268       
    198269        /** Fibril mutex for list of classes. */
    199         fibril_rwlock_t rwlock; 
     270        fibril_rwlock_t rwlock;
    200271} class_list_t;
    201272
    202 // Match ids and scores
    203 
    204 int get_match_score(driver_t *drv, node_t *dev);
    205 
    206 bool parse_match_ids(char *buf, match_id_list_t *ids);
    207 bool read_match_ids(const char *conf_path, match_id_list_t *ids);
    208 char * read_match_id(char **buf);
    209 char * read_id(const char **buf);
    210 
    211 // Drivers
    212 
    213 /** 
     273/* Match ids and scores */
     274
     275extern int get_match_score(driver_t *, node_t *);
     276
     277extern bool parse_match_ids(char *, match_id_list_t *);
     278extern bool read_match_ids(const char *, match_id_list_t *);
     279extern char *read_match_id(char **);
     280extern char *read_id(const char **);
     281
     282/* Drivers */
     283
     284/**
    214285 * Initialize the list of device driver's.
    215  * 
     286 *
    216287 * @param drv_list the list of device driver's.
    217  * 
    218  */
    219 static inline void init_driver_list(driver_list_t *drv_list) 
     288 *
     289 */
     290static inline void init_driver_list(driver_list_t *drv_list)
    220291{
    221292        assert(NULL != drv_list);
    222293       
    223294        list_initialize(&drv_list->drivers);
    224         fibril_mutex_initialize(&drv_list->drivers_mutex);     
    225 }
    226 
    227 driver_t * create_driver(void);
    228 bool get_driver_info(const char *base_path, const char *name, driver_t *drv);
    229 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path);
    230 
    231 driver_t * find_best_match_driver(driver_list_t *drivers_list, node_t *node);
    232 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree);
    233 
    234 void add_driver(driver_list_t *drivers_list, driver_t *drv);
    235 void attach_driver(node_t *node, driver_t *drv);
    236 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree);
    237 bool start_driver(driver_t *drv);
    238 
    239 driver_t * find_driver(driver_list_t *drv_list, const char *drv_name);
    240 void set_driver_phone(driver_t *driver, ipcarg_t phone);
    241 void initialize_running_driver(driver_t *driver, dev_tree_t *tree);
    242 
    243 /**
    244  * Initialize device driver structure.
    245  *
    246  * @param drv the device driver structure.
    247  *
     295        fibril_mutex_initialize(&drv_list->drivers_mutex);
     296}
     297
     298extern driver_t *create_driver(void);
     299extern bool get_driver_info(const char *, const char *, driver_t *);
     300extern int lookup_available_drivers(driver_list_t *, const char *);
     301
     302extern driver_t *find_best_match_driver(driver_list_t *, node_t *);
     303extern bool assign_driver(node_t *, driver_list_t *, dev_tree_t *);
     304
     305extern void add_driver(driver_list_t *, driver_t *);
     306extern void attach_driver(node_t *, driver_t *);
     307extern void add_device(int, driver_t *, node_t *, dev_tree_t *);
     308extern bool start_driver(driver_t *);
     309
     310extern driver_t *find_driver(driver_list_t *, const char *);
     311extern void set_driver_phone(driver_t *, ipcarg_t);
     312void initialize_running_driver(driver_t *, dev_tree_t *);
     313
     314/** Initialize device driver structure.
     315 *
     316 * @param drv           The device driver structure.
    248317 */
    249318static inline void init_driver(driver_t *drv)
     
    254323        list_initialize(&drv->match_ids.ids);
    255324        list_initialize(&drv->devices);
    256         fibril_mutex_initialize(&drv->driver_mutex);   
    257 }
    258 
    259 /**
    260  * Device driver structure clean-up.
    261  *
    262  * @param drv the device driver structure.
     325        fibril_mutex_initialize(&drv->driver_mutex);
     326}
     327
     328/** Device driver structure clean-up.
     329 *
     330 * @param drv           The device driver structure.
    263331 */
    264332static inline void clean_driver(driver_t *drv)
     
    267335
    268336        free_not_null(drv->name);
    269         free_not_null(drv->binary_path); 
     337        free_not_null(drv->binary_path);
    270338
    271339        clean_match_ids(&drv->match_ids);
     
    274342}
    275343
    276 /**
    277  * Delete device driver structure.
    278  *
    279  *  @param drv the device driver structure.*
     344/** Delete device driver structure.
     345 *
     346 * @param drv           The device driver structure.
    280347 */
    281348static inline void delete_driver(driver_t *drv)
     
    287354}
    288355
    289 // Device nodes
    290 /**
    291  * Create a new device node.
    292  *
    293  * @return a device node structure.
    294  *
    295  */
    296 static inline node_t * create_dev_node()
     356
     357/* Device nodes */
     358
     359/** Create a new device node.
     360 *
     361 * @return              A device node structure.
     362 */
     363static inline node_t *create_dev_node(void)
    297364{
    298365        node_t *res = malloc(sizeof(node_t));
     
    308375}
    309376
    310 /**
    311  * Delete a device node.
    312  *
    313  * @param node a device node structure.
    314  *
     377/** Delete a device node.
     378 *
     379 * @param node          The device node structure.
    315380 */
    316381static inline void delete_dev_node(node_t *node)
    317382{
    318         assert(list_empty(&node->children) && NULL == node->parent && NULL == node->drv);
     383        assert(list_empty(&node->children));
     384        assert(NULL == node->parent);
     385        assert(NULL == node->drv);
    319386       
    320387        clean_match_ids(&node->match_ids);
    321388        free_not_null(node->name);
    322389        free_not_null(node->pathname);
    323         free(node);     
    324 }
    325 
    326 /**
    327  * Find the device node structure of the device witch has the specified handle.
    328  *
     390        free(node);
     391}
     392
     393/** Find the device node structure of the device witch has the specified handle.
     394 *
    329395 * Device tree's rwlock should be held at least for reading.
    330  *
    331  * @param tree the device tree where we look for the device node.
    332  * @param handle the handle of the device.
    333  * @return the device node.
    334  */
    335 static inline node_t * find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
     396 *
     397 * @param tree          The device tree where we look for the device node.
     398 * @param handle        The handle of the device.
     399 * @return              The device node.
     400 */
     401static inline node_t *
     402find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
    336403{
    337404        unsigned long key = handle;
     
    340407}
    341408
    342 /**
    343  * Find the device node structure of the device witch has the specified handle.
    344  *
    345  * @param tree the device tree where we look for the device node.
    346  * @param handle the handle of the device.
    347  * @return the device node.
    348  */
    349 static inline node_t * find_dev_node(dev_tree_t *tree, device_handle_t handle)
     409/** Find the device node structure of the device witch has the specified handle.
     410 *
     411 * @param tree          The device tree where we look for the device node.
     412 * @param handle        The handle of the device.
     413 * @return              The device node.
     414 */
     415static inline node_t *
     416find_dev_node(dev_tree_t *tree, device_handle_t handle)
    350417{
    351418        node_t *node = NULL;
    352419       
    353420        fibril_rwlock_read_lock(&tree->rwlock);
    354        
    355421        node = find_dev_node_no_lock(tree, handle);
    356        
    357422        fibril_rwlock_read_unlock(&tree->rwlock);
    358423       
     
    360425}
    361426
    362 node_t * find_dev_node_by_path(dev_tree_t *tree, char *path);
    363 node_t *find_node_child(node_t *parent, const char *name);
    364 
    365 // Device tree
    366 
    367 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list);
    368 bool create_root_node(dev_tree_t *tree);
    369 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent);
    370 
    371 // Device classes
    372 
    373 /** Create device class.
    374  *   
    375  * @return device class.
    376  */
    377 static inline dev_class_t * create_dev_class()
    378 {
    379         dev_class_t *cl = (dev_class_t *)malloc(sizeof(dev_class_t));
     427extern node_t *find_dev_node_by_path(dev_tree_t *, char *);
     428extern node_t *find_node_child(node_t *, const char *);
     429
     430
     431/* Device tree */
     432
     433extern bool init_device_tree(dev_tree_t *, driver_list_t *);
     434extern bool create_root_node(dev_tree_t *);
     435extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *);
     436
     437
     438/* Device classes */
     439
     440/** Create device class.
     441 *
     442 * @return              Device class.
     443 */
     444static inline dev_class_t *create_dev_class(void)
     445{
     446        dev_class_t *cl;
     447       
     448        cl = (dev_class_t *) malloc(sizeof(dev_class_t));
    380449        if (NULL != cl) {
    381450                memset(cl, 0, sizeof(dev_class_t));
     
    383452                fibril_mutex_initialize(&cl->mutex);
    384453        }
    385         return cl;     
    386 }
    387 
    388 /** Create device class info.
    389  *
    390  * @return device class info.
    391  */
    392 static inline dev_class_info_t * create_dev_class_info()
    393 {
    394         dev_class_info_t *info = (dev_class_info_t *)malloc(sizeof(dev_class_info_t));
    395         if (NULL != info) {
     454       
     455        return cl;
     456}
     457
     458/** Create device class info.
     459 *
     460 * @return              Device class info.
     461 */
     462static inline dev_class_info_t *create_dev_class_info(void)
     463{
     464        dev_class_info_t *info;
     465       
     466        info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
     467        if (NULL != info)
    396468                memset(info, 0, sizeof(dev_class_info_t));
    397         }
    398         return info;   
     469       
     470        return info;
    399471}
    400472
     
    402474{
    403475        size_t dev_idx;
     476       
    404477        fibril_mutex_lock(&cl->mutex);
    405478        dev_idx = ++cl->curr_dev_idx;
    406479        fibril_mutex_unlock(&cl->mutex);
     480       
    407481        return dev_idx;
    408482}
    409483
    410 char * create_dev_name_for_class(dev_class_t *cl, const char *base_dev_name);
    411 dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name);
    412 
    413 void init_class_list(class_list_t *class_list);
    414 
    415 dev_class_t * get_dev_class(class_list_t *class_list, char *class_name);
    416 dev_class_t * find_dev_class_no_lock(class_list_t *class_list, const char *class_name);
    417 
    418 static inline void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
     484extern char *create_dev_name_for_class(dev_class_t *, const char *);
     485extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *,
     486    const char *);
     487
     488extern void init_class_list(class_list_t *);
     489
     490extern dev_class_t *get_dev_class(class_list_t *, char *);
     491extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
     492
     493static inline void
     494add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
    419495{
    420496        list_append(&cl->link, &class_list->classes);
     
    422498
    423499
    424 // devmap devices
    425 
    426 node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle);
    427 node_t *find_devmap_class_device(class_list_t *classes, dev_handle_t devmap_handle);
    428 
    429 
    430 static inline void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
    431 {
    432         unsigned long key = (unsigned long)cli->devmap_handle;
     500/* Devmap devices */
     501
     502extern node_t *find_devmap_tree_device(dev_tree_t *, dev_handle_t);
     503extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t);
     504
     505static inline void
     506class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     507{
     508        unsigned long key = (unsigned long) cli->devmap_handle;
     509       
    433510        fibril_rwlock_write_lock(&class_list->rwlock);
    434511        hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     
    438515static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
    439516{
    440         unsigned long key = (unsigned long)node->devmap_handle;
     517        unsigned long key = (unsigned long) node->devmap_handle;
    441518        fibril_rwlock_write_lock(&tree->rwlock);
    442519        hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
    443         fibril_rwlock_write_unlock(&tree->rwlock);     
     520        fibril_rwlock_write_unlock(&tree->rwlock);
    444521}
    445522
Note: See TracChangeset for help on using the changeset viewer.