Ignore:
File:
1 edited

Legend:

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

    r80a96d2 r3ad7b1c  
    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>
    47 #include <async.h>
    4846
    4947#include "util.h"
     
    5452#define DEVICE_BUCKETS 256
    5553
    56 #define LOC_DEVICE_NAMESPACE "devices"
    57 #define LOC_SEPARATOR '\\'
     54#define DEVMAP_CLASS_NAMESPACE "class"
     55#define DEVMAP_DEVICE_NAMESPACE "devices"
     56#define DEVMAP_SEPARATOR '\\'
    5857
    5958struct dev_node;
     
    6261struct fun_node;
    6362typedef struct fun_node fun_node_t;
    64 
    65 typedef struct {
    66         fibril_mutex_t mutex;
    67         struct driver *driver;
    68 } client_t;
    6963
    7064typedef enum {
     
    9387        int state;
    9488       
    95         /** Session asociated with this driver. */
    96         async_sess_t *sess;
     89        /** Phone asociated with this driver. */
     90        int phone;
    9791        /** Name of the device driver. */
    9892        char *name;
     
    10195        /** List of device ids for device-to-driver matching. */
    10296        match_id_list_t match_ids;
    103         /** List of devices controlled by this driver. */
    104         list_t devices;
    105        
    106         /**
    107          * Fibril mutex for this driver - driver state, list of devices, session.
     97        /** Pointer to the linked list of devices controlled by this driver. */
     98        link_t devices;
     99       
     100        /**
     101         * Fibril mutex for this driver - driver state, list of devices, phone.
    108102         */
    109103        fibril_mutex_t driver_mutex;
     
    113107typedef struct driver_list {
    114108        /** List of drivers */
    115         list_t drivers;
     109        link_t drivers;
    116110        /** Fibril mutex for list of drivers. */
    117111        fibril_mutex_t drivers_mutex;
    118112} driver_list_t;
    119113
    120 /** Device state */
     114/** The state of the device. */
    121115typedef enum {
    122116        DEVICE_NOT_INITIALIZED = 0,
    123117        DEVICE_USABLE,
    124118        DEVICE_NOT_PRESENT,
    125         DEVICE_INVALID,
    126         /** Device node has been removed from the tree */
    127         DEVICE_REMOVED
     119        DEVICE_INVALID
    128120} device_state_t;
    129121
    130122/** Device node in the device tree. */
    131123struct dev_node {
    132         /** Reference count */
    133         atomic_t refcnt;
    134        
    135124        /** The global unique identifier of the device. */
    136125        devman_handle_t handle;
     
    140129       
    141130        /** List of device functions. */
    142         list_t functions;
     131        link_t functions;
    143132        /** Driver of this device. */
    144133        driver_t *drv;
     
    159148};
    160149
    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 
    170150/** Function node in the device tree. */
    171151struct fun_node {
    172         /** Reference count */
    173         atomic_t refcnt;
    174         /** State */
    175         fun_state_t state;
    176        
    177152        /** The global unique identifier of the function */
    178153        devman_handle_t handle;
    179154        /** Name of the function, assigned by the device driver */
    180155        char *name;
    181         /** Function type */
    182         fun_type_t ftype;
    183156       
    184157        /** Full path and name of the device in device hierarchy */
     
    196169        match_id_list_t match_ids;
    197170       
    198         /** Service ID if the device function is registered with loc. */
    199         service_id_t service_id;
     171        /** The list of device classes to which this device function belongs. */
     172        link_t classes;
     173        /** Devmap handle if the device function is registered by devmap. */
     174        devmap_handle_t devmap_handle;
    200175       
    201176        /**
     
    205180       
    206181        /**
    207          * Used by the hash table of functions indexed by service IDs.
    208          */
    209         link_t loc_fun;
     182         * Used by the hash table of functions indexed by devmap device handles.
     183         */
     184        link_t devmap_fun;
    210185};
    211186
     
    232207       
    233208        /**
    234          * Hash table of services registered with location service, indexed by
    235          * service IDs.
    236          */
    237         hash_table_t loc_functions;
     209         * Hash table of devices registered by devmapper, indexed by devmap
     210         * handles.
     211         */
     212        hash_table_t devmap_functions;
    238213} dev_tree_t;
     214
     215typedef struct dev_class {
     216        /** The name of the class. */
     217        const char *name;
     218       
     219        /**
     220         * Pointer to the previous and next class in the list of registered
     221         * classes.
     222         */
     223        link_t link;
     224       
     225        /**
     226         * List of dev_class_info structures - one for each device registered by
     227         * this class.
     228         */
     229        link_t devices;
     230       
     231        /**
     232         * Default base name for the device within the class, might be overrided
     233         * by the driver.
     234         */
     235        const char *base_dev_name;
     236       
     237        /** Unique numerical identifier of the newly added device. */
     238        size_t curr_dev_idx;
     239        /** Synchronize access to the list of devices in this class. */
     240        fibril_mutex_t mutex;
     241} dev_class_t;
     242
     243/**
     244 * Provides n-to-m mapping between function nodes and classes - each function
     245 * can register in an arbitrary number of classes and each class can contain
     246 * an arbitrary number of device functions.
     247 */
     248typedef struct dev_class_info {
     249        /** The class. */
     250        dev_class_t *dev_class;
     251        /** The device. */
     252        fun_node_t *fun;
     253       
     254        /**
     255         * Pointer to the previous and next class info in the list of devices
     256         * registered by the class.
     257         */
     258        link_t link;
     259       
     260        /**
     261         * Pointer to the previous and next class info in the list of classes
     262         * by which the device is registered.
     263         */
     264        link_t dev_classes;
     265       
     266        /** The name of the device function within the class. */
     267        char *dev_name;
     268        /** The handle of the device by device mapper in the class namespace. */
     269        devmap_handle_t devmap_handle;
     270       
     271        /**
     272         * Link in the hash table of devices registered by the devmapper using
     273         * their class names.
     274         */
     275        link_t devmap_link;
     276} dev_class_info_t;
     277
     278/** The list of device classes. */
     279typedef struct class_list {
     280        /** List of classes. */
     281        link_t classes;
     282       
     283        /**
     284         * Hash table of devices registered by devmapper using their class name,
     285         * indexed by devmap handles.
     286         */
     287        hash_table_t devmap_functions;
     288       
     289        /** Fibril mutex for list of classes. */
     290        fibril_rwlock_t rwlock;
     291} class_list_t;
    239292
    240293/* Match ids and scores */
     
    258311
    259312extern 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 *);
     313extern void attach_driver(dev_node_t *, driver_t *);
     314extern void add_device(int, driver_t *, dev_node_t *, dev_tree_t *);
    263315extern bool start_driver(driver_t *);
    264 extern int driver_dev_remove(dev_tree_t *, dev_node_t *);
    265 extern int driver_dev_gone(dev_tree_t *, dev_node_t *);
    266 extern int driver_fun_online(dev_tree_t *, fun_node_t *);
    267 extern int driver_fun_offline(dev_tree_t *, fun_node_t *);
    268316
    269317extern driver_t *find_driver(driver_list_t *, const char *);
     
    278326extern dev_node_t *create_dev_node(void);
    279327extern void delete_dev_node(dev_node_t *node);
    280 extern void dev_add_ref(dev_node_t *);
    281 extern void dev_del_ref(dev_node_t *);
    282328extern dev_node_t *find_dev_node_no_lock(dev_tree_t *tree,
    283329    devman_handle_t handle);
    284330extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle);
    285331extern dev_node_t *find_dev_function(dev_node_t *, const char *);
    286 extern int dev_get_functions(dev_tree_t *tree, dev_node_t *, devman_handle_t *,
    287     size_t, size_t *);
    288332
    289333extern fun_node_t *create_fun_node(void);
    290334extern void delete_fun_node(fun_node_t *);
    291 extern void fun_add_ref(fun_node_t *);
    292 extern void fun_del_ref(fun_node_t *);
    293335extern fun_node_t *find_fun_node_no_lock(dev_tree_t *tree,
    294336    devman_handle_t handle);
    295337extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
    296338extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
    297 extern fun_node_t *find_fun_node_in_device(dev_tree_t *tree, dev_node_t *,
    298     const char *);
     339extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);
     340extern fun_node_t *find_fun_node_by_class(class_list_t *, const char *, const char *);
    299341
    300342/* Device tree */
     
    303345extern bool create_root_nodes(dev_tree_t *);
    304346extern bool insert_dev_node(dev_tree_t *, dev_node_t *, fun_node_t *);
    305 extern void remove_dev_node(dev_tree_t *, dev_node_t *);
    306347extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *);
    307 extern void remove_fun_node(dev_tree_t *, fun_node_t *);
    308 
    309 /* Loc services */
    310 
    311 extern void loc_register_tree_function(fun_node_t *, dev_tree_t *);
    312 
    313 extern fun_node_t *find_loc_tree_function(dev_tree_t *, service_id_t);
    314 
    315 extern void tree_add_loc_function(dev_tree_t *, fun_node_t *);
     348
     349/* Device classes */
     350
     351extern dev_class_t *create_dev_class(void);
     352extern dev_class_info_t *create_dev_class_info(void);
     353extern size_t get_new_class_dev_idx(dev_class_t *);
     354extern char *create_dev_name_for_class(dev_class_t *, const char *);
     355extern dev_class_info_t *add_function_to_class(fun_node_t *, dev_class_t *,
     356    const char *);
     357
     358extern void init_class_list(class_list_t *);
     359
     360extern dev_class_t *get_dev_class(class_list_t *, char *);
     361extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
     362extern dev_class_info_t *find_dev_in_class(dev_class_t *, const char *);
     363extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
     364
     365/* Devmap devices */
     366
     367extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *);
     368
     369extern fun_node_t *find_devmap_tree_function(dev_tree_t *, devmap_handle_t);
     370extern fun_node_t *find_devmap_class_function(class_list_t *, devmap_handle_t);
     371
     372extern void class_add_devmap_function(class_list_t *, dev_class_info_t *);
     373extern void tree_add_devmap_function(dev_tree_t *, fun_node_t *);
    316374
    317375#endif
Note: See TracChangeset for help on using the changeset viewer.