Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d51ee2b in mainline


Ignore:
Timestamp:
2010-05-21T13:59:09Z (11 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master
Children:
957cfa58
Parents:
c47e1a8
Message:

parts of supporting code for the dynamic device classes

Location:
uspace/srv/devman
Files:
2 edited

Legend:

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

    rc47e1a8 rd51ee2b  
    736736}
    737737
     738/** Create unique device name within the class.
     739 *
     740 * @param cl the class.
     741 * @param base_dev_name contains base name for the device
     742 * if it was specified by the driver when it registered the device by the class;
     743 * NULL if driver specified no base name.
     744 * @return the unique name for the device within the class.
     745 */
     746char * create_dev_name_for_class(dev_class_t *cl, const char *base_dev_name)
     747{
     748        char *dev_name;
     749        const char *base_name;
     750        if (NULL != base_dev_name) {
     751                base_name = base_dev_name;
     752        } else {
     753                base_name = cl->base_dev_name;
     754        }
     755       
     756        size_t idx = get_new_class_dev_idx(cl);
     757        asprintf(&dev_name, "%s%d", base_name, idx);
     758        return dev_name;       
     759}
     760
     761/** Add the device to the class.
     762 *
     763 * The device may be added to multiple classes and a class may contain multiple devices.
     764 * The class and the device are associated with each other by the dev_class_info_t structure.
     765 *
     766 * @param dev the device.
     767 * @param class the class.
     768 * @param base_dev_name the base name of the device within the class if specified by the driver,
     769 * NULL otherwise.
     770 * @return dev_class_info_t structure which associates the device with the class.
     771 */
     772dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name)
     773{
     774        dev_class_info_t *info = create_dev_class_info();
     775        info->dev_class = cl;
     776        info->dev = dev;
     777       
     778        // add the device to the class
     779        fibril_mutex_lock(&cl->mutex);
     780        list_append(&info->link, &cl->devices);
     781        fibril_mutex_unlock(&cl->mutex);
     782       
     783        // add the class to the device
     784        list_append(&info->dev_classes, &dev->classes);
     785       
     786        // create unique name for the device within the class
     787        info->dev_name = create_dev_name_for_class(cl, base_dev_name); 
     788       
     789        return info;
     790}
     791
    738792/** @}
    739793 */
  • 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.