Changeset d51ee2b in mainline for uspace/srv/devman/devman.h


Ignore:
Timestamp:
2010-05-21T13:59:09Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
957cfa58
Parents:
c47e1a8
Message:

parts of supporting code for the dynamic device classes

File:
1 edited

Legend:

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

    rc47e1a8 rd51ee2b  
    4141#include <ipc/ipc.h>
    4242#include <ipc/devman.h>
     43#include <ipc/devmap.h>
    4344#include <fibril_synch.h>
    4445#include <atomic.h>
     
    5253
    5354struct node;
    54 
    5555typedef struct node node_t;
    5656
     
    126126            owned by one driver */
    127127        link_t driver_devices;
     128        /** The list of device classes to which this device belongs.*/
     129        link_t classes;
    128130};
    129131
     
    139141} dev_tree_t;
    140142
    141 
     143typedef struct dev_class {     
     144        /** The name of the class.*/
     145        const char *name;
     146        /** Pointer to the previous and next class in the list of registered classes.*/
     147        link_t link;   
     148        /** List of dev_class_info structures - one for each device registered by this class.*/
     149        link_t devices;
     150        /** Default base name for the device within the class, might be overrided by the driver.*/
     151        const char *base_dev_name;
     152        /** Unique numerical identifier appened to the base name of the newly added device.*/
     153        size_t curr_dev_idx;
     154        /** Synchronize access to the list of devices in this class. */
     155        fibril_mutex_t mutex;
     156} dev_class_t;
     157
     158/** Provides n-to-m mapping between device nodes and classes
     159 * - each device may be register to the arbitrary number of classes
     160 * and each class may contain the arbitrary number of devices. */
     161typedef struct dev_class_info {
     162        /** The class.*/
     163        dev_class_t *dev_class;
     164        /** The device.*/
     165        node_t *dev;
     166        /** Pointer to the previous and next class info in the list of devices registered by the class.*/
     167        link_t link;
     168        /** Pointer to the previous and next class info in the list of classes by which the device is registered.*/
     169        link_t dev_classes;
     170        /** The name of the device within the class.*/
     171        char *dev_name;
     172        /** The handle of the device by device mapper in the class namespace.*/
     173        dev_handle_t devmap_handle;
     174} dev_class_info_t;
    142175
    143176// Match ids and scores
     
    289322bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent);
    290323
     324// Device classes
     325
     326/** Create device class.
     327 *   
     328 * @return device class.
     329 */
     330static inline dev_class_t * create_dev_class()
     331{
     332        dev_class_t *cl = (dev_class_t *)malloc(sizeof(dev_class_t));
     333        if (NULL != cl) {
     334                memset(cl, 0, sizeof(dev_class_t));
     335                fibril_mutex_initialize(&cl->mutex);
     336        }
     337        return cl;     
     338}
     339
     340/** Create device class info.
     341 *
     342 * @return device class info.
     343 */
     344static inline dev_class_info_t * create_dev_class_info()
     345{
     346        dev_class_info_t *info = (dev_class_info_t *)malloc(sizeof(dev_class_info_t));
     347        if (NULL != info) {
     348                memset(info, 0, sizeof(dev_class_info_t));
     349        }
     350        return info;   
     351}
     352
     353static inline size_t get_new_class_dev_idx(dev_class_t *cl)
     354{
     355        size_t dev_idx;
     356        fibril_mutex_lock(&cl->mutex);
     357        dev_idx = ++cl->curr_dev_idx;
     358        fibril_mutex_unlock(&cl->mutex);
     359        return dev_idx;
     360}
     361
     362char * create_dev_name_for_class(dev_class_t *cl, const char *base_dev_name);
     363dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name);
     364
    291365#endif
    292366
Note: See TracChangeset for help on using the changeset viewer.