Ignore:
File:
1 edited

Legend:

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

    rc1a0488 r79ae36dd  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
    3  * Copyright (c) 2011 Jiri Svoboda
    43 * All rights reserved.
    54 *
     
    4241#include <adt/hash_table.h>
    4342#include <ipc/devman.h>
    44 #include <ipc/loc.h>
     43#include <ipc/devmap.h>
    4544#include <fibril_synch.h>
    4645#include <atomic.h>
     
    5453#define DEVICE_BUCKETS 256
    5554
    56 #define LOC_DEVICE_NAMESPACE "devices"
    57 #define LOC_SEPARATOR '\\'
     55#define DEVMAP_CLASS_NAMESPACE "class"
     56#define DEVMAP_DEVICE_NAMESPACE "devices"
     57#define DEVMAP_SEPARATOR '\\'
    5858
    5959struct dev_node;
     
    6262struct fun_node;
    6363typedef struct fun_node fun_node_t;
    64 
    65 typedef struct {
    66         fibril_mutex_t mutex;
    67         struct driver *driver;
    68 } client_t;
    6964
    7065typedef enum {
     
    10196        /** List of device ids for device-to-driver matching. */
    10297        match_id_list_t match_ids;
    103         /** List of devices controlled by this driver. */
    104         list_t devices;
     98        /** Pointer to the linked list of devices controlled by this driver. */
     99        link_t devices;
    105100       
    106101        /**
     
    113108typedef struct driver_list {
    114109        /** List of drivers */
    115         list_t drivers;
     110        link_t drivers;
    116111        /** Fibril mutex for list of drivers. */
    117112        fibril_mutex_t drivers_mutex;
    118113} driver_list_t;
    119114
    120 /** Device state */
     115/** The state of the device. */
    121116typedef enum {
    122117        DEVICE_NOT_INITIALIZED = 0,
    123118        DEVICE_USABLE,
    124119        DEVICE_NOT_PRESENT,
    125         DEVICE_INVALID,
    126         /** Device node has been removed from the tree */
    127         DEVICE_REMOVED
     120        DEVICE_INVALID
    128121} device_state_t;
    129122
    130123/** Device node in the device tree. */
    131124struct dev_node {
    132         /** Reference count */
    133         atomic_t refcnt;
    134        
    135125        /** The global unique identifier of the device. */
    136126        devman_handle_t handle;
     
    140130       
    141131        /** List of device functions. */
    142         list_t functions;
     132        link_t functions;
    143133        /** Driver of this device. */
    144134        driver_t *drv;
     
    159149};
    160150
    161 /** Function state */
    162 typedef enum {
    163         FUN_INIT = 0,
    164         FUN_OFF_LINE,
    165         FUN_ON_LINE,
    166         /** Function node has been removed from the tree */
    167         FUN_REMOVED
    168 } fun_state_t;
    169 
    170151/** Function node in the device tree. */
    171152struct fun_node {
    172         /** Reference count */
    173         atomic_t refcnt;
    174         /** State */
    175         fun_state_t state;
    176        
    177153        /** The global unique identifier of the function */
    178154        devman_handle_t handle;
    179155        /** Name of the function, assigned by the device driver */
    180156        char *name;
    181         /** Function type */
    182         fun_type_t ftype;
    183157       
    184158        /** Full path and name of the device in device hierarchy */
     
    196170        match_id_list_t match_ids;
    197171       
    198         /** Service ID if the device function is registered with loc. */
    199         service_id_t service_id;
     172        /** The list of device classes to which this device function belongs. */
     173        link_t classes;
     174        /** Devmap handle if the device function is registered by devmap. */
     175        devmap_handle_t devmap_handle;
    200176       
    201177        /**
     
    205181       
    206182        /**
    207          * Used by the hash table of functions indexed by service IDs.
    208          */
    209         link_t loc_fun;
     183         * Used by the hash table of functions indexed by devmap device handles.
     184         */
     185        link_t devmap_fun;
    210186};
    211187
     
    232208       
    233209        /**
    234          * Hash table of services registered with location service, indexed by
    235          * service IDs.
    236          */
    237         hash_table_t loc_functions;
     210         * Hash table of devices registered by devmapper, indexed by devmap
     211         * handles.
     212         */
     213        hash_table_t devmap_functions;
    238214} dev_tree_t;
     215
     216typedef struct dev_class {
     217        /** The name of the class. */
     218        const char *name;
     219       
     220        /**
     221         * Pointer to the previous and next class in the list of registered
     222         * classes.
     223         */
     224        link_t link;
     225       
     226        /**
     227         * List of dev_class_info structures - one for each device registered by
     228         * this class.
     229         */
     230        link_t devices;
     231       
     232        /**
     233         * Default base name for the device within the class, might be overrided
     234         * by the driver.
     235         */
     236        const char *base_dev_name;
     237       
     238        /** Unique numerical identifier of the newly added device. */
     239        size_t curr_dev_idx;
     240        /** Synchronize access to the list of devices in this class. */
     241        fibril_mutex_t mutex;
     242} dev_class_t;
     243
     244/**
     245 * Provides n-to-m mapping between function nodes and classes - each function
     246 * can register in an arbitrary number of classes and each class can contain
     247 * an arbitrary number of device functions.
     248 */
     249typedef struct dev_class_info {
     250        /** The class. */
     251        dev_class_t *dev_class;
     252        /** The device. */
     253        fun_node_t *fun;
     254       
     255        /**
     256         * Pointer to the previous and next class info in the list of devices
     257         * registered by the class.
     258         */
     259        link_t link;
     260       
     261        /**
     262         * Pointer to the previous and next class info in the list of classes
     263         * by which the device is registered.
     264         */
     265        link_t dev_classes;
     266       
     267        /** The name of the device function within the class. */
     268        char *dev_name;
     269        /** The handle of the device by device mapper in the class namespace. */
     270        devmap_handle_t devmap_handle;
     271       
     272        /**
     273         * Link in the hash table of devices registered by the devmapper using
     274         * their class names.
     275         */
     276        link_t devmap_link;
     277} dev_class_info_t;
     278
     279/** The list of device classes. */
     280typedef struct class_list {
     281        /** List of classes. */
     282        link_t classes;
     283       
     284        /**
     285         * Hash table of devices registered by devmapper using their class name,
     286         * indexed by devmap handles.
     287         */
     288        hash_table_t devmap_functions;
     289       
     290        /** Fibril mutex for list of classes. */
     291        fibril_rwlock_t rwlock;
     292} class_list_t;
    239293
    240294/* Match ids and scores */
     
    258312
    259313extern void add_driver(driver_list_t *, driver_t *);
    260 extern void attach_driver(dev_tree_t *, dev_node_t *, driver_t *);
    261 extern void detach_driver(dev_tree_t *, dev_node_t *);
    262 extern void add_device(driver_t *, dev_node_t *, dev_tree_t *);
     314extern void attach_driver(dev_node_t *, driver_t *);
     315extern void add_device(async_sess_t *, driver_t *, dev_node_t *, dev_tree_t *);
    263316extern bool start_driver(driver_t *);
    264 extern int driver_dev_remove(dev_tree_t *, dev_node_t *);
    265 extern int driver_fun_online(dev_tree_t *, fun_node_t *);
    266 extern int driver_fun_offline(dev_tree_t *, fun_node_t *);
    267317
    268318extern driver_t *find_driver(driver_list_t *, const char *);
     
    277327extern dev_node_t *create_dev_node(void);
    278328extern void delete_dev_node(dev_node_t *node);
    279 extern void dev_add_ref(dev_node_t *);
    280 extern void dev_del_ref(dev_node_t *);
    281329extern dev_node_t *find_dev_node_no_lock(dev_tree_t *tree,
    282330    devman_handle_t handle);
    283331extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle);
    284332extern dev_node_t *find_dev_function(dev_node_t *, const char *);
    285 extern int dev_get_functions(dev_tree_t *tree, dev_node_t *, devman_handle_t *,
    286     size_t, size_t *);
    287333
    288334extern fun_node_t *create_fun_node(void);
    289335extern void delete_fun_node(fun_node_t *);
    290 extern void fun_add_ref(fun_node_t *);
    291 extern void fun_del_ref(fun_node_t *);
    292336extern fun_node_t *find_fun_node_no_lock(dev_tree_t *tree,
    293337    devman_handle_t handle);
    294338extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
    295339extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
    296 extern fun_node_t *find_fun_node_in_device(dev_tree_t *tree, dev_node_t *,
    297     const char *);
     340extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);
     341extern fun_node_t *find_fun_node_by_class(class_list_t *, const char *, const char *);
    298342
    299343/* Device tree */
     
    302346extern bool create_root_nodes(dev_tree_t *);
    303347extern bool insert_dev_node(dev_tree_t *, dev_node_t *, fun_node_t *);
    304 extern void remove_dev_node(dev_tree_t *, dev_node_t *);
    305348extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *);
    306 extern void remove_fun_node(dev_tree_t *, fun_node_t *);
    307 
    308 /* Loc services */
    309 
    310 extern void loc_register_tree_function(fun_node_t *, dev_tree_t *);
    311 
    312 extern fun_node_t *find_loc_tree_function(dev_tree_t *, service_id_t);
    313 
    314 extern void tree_add_loc_function(dev_tree_t *, fun_node_t *);
     349
     350/* Device classes */
     351
     352extern dev_class_t *create_dev_class(void);
     353extern dev_class_info_t *create_dev_class_info(void);
     354extern size_t get_new_class_dev_idx(dev_class_t *);
     355extern char *create_dev_name_for_class(dev_class_t *, const char *);
     356extern dev_class_info_t *add_function_to_class(fun_node_t *, dev_class_t *,
     357    const char *);
     358
     359extern void init_class_list(class_list_t *);
     360
     361extern dev_class_t *get_dev_class(class_list_t *, char *);
     362extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
     363extern dev_class_info_t *find_dev_in_class(dev_class_t *, const char *);
     364extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
     365
     366/* Devmap devices */
     367
     368extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *);
     369
     370extern fun_node_t *find_devmap_tree_function(dev_tree_t *, devmap_handle_t);
     371extern fun_node_t *find_devmap_class_function(class_list_t *, devmap_handle_t);
     372
     373extern void class_add_devmap_function(class_list_t *, dev_class_info_t *);
     374extern void tree_add_devmap_function(dev_tree_t *, fun_node_t *);
    315375
    316376#endif
Note: See TracChangeset for help on using the changeset viewer.