00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00033 #ifndef DEVMAN_H_
00034 #define DEVMAN_H_
00035
00036 #include <assert.h>
00037 #include <bool.h>
00038 #include <dirent.h>
00039 #include <str.h>
00040 #include <adt/list.h>
00041 #include <adt/hash_table.h>
00042 #include <ipc/devman.h>
00043 #include <ipc/devmap.h>
00044 #include <fibril_synch.h>
00045 #include <atomic.h>
00046
00047 #include "util.h"
00048
00049 #define NAME "devman"
00050
00051 #define MATCH_EXT ".ma"
00052 #define DEVICE_BUCKETS 256
00053
00054 #define DEVMAP_CLASS_NAMESPACE "class"
00055 #define DEVMAP_DEVICE_NAMESPACE "devices"
00056 #define DEVMAP_SEPARATOR '\\'
00057
00058 struct dev_node;
00059 typedef struct dev_node dev_node_t;
00060
00061 struct fun_node;
00062 typedef struct fun_node fun_node_t;
00063
00064 typedef enum {
00066 DRIVER_NOT_STARTED = 0,
00067
00072 DRIVER_STARTING,
00073
00075 DRIVER_RUNNING
00076 } driver_state_t;
00077
00079 typedef struct driver {
00081 link_t drivers;
00082
00087 int state;
00088
00090 int phone;
00092 char *name;
00094 const char *binary_path;
00096 match_id_list_t match_ids;
00098 link_t devices;
00099
00103 fibril_mutex_t driver_mutex;
00104 } driver_t;
00105
00107 typedef struct driver_list {
00109 link_t drivers;
00111 fibril_mutex_t drivers_mutex;
00112 } driver_list_t;
00113
00115 typedef enum {
00116 DEVICE_NOT_INITIALIZED = 0,
00117 DEVICE_USABLE,
00118 DEVICE_NOT_PRESENT,
00119 DEVICE_INVALID
00120 } device_state_t;
00121
00123 struct dev_node {
00125 devman_handle_t handle;
00126
00128 fun_node_t *pfun;
00129
00131 link_t functions;
00133 driver_t *drv;
00135 device_state_t state;
00137 link_t driver_devices;
00138
00142 link_t devman_dev;
00143
00147 bool passed_to_driver;
00148 };
00149
00151 struct fun_node {
00153 devman_handle_t handle;
00155 char *name;
00156
00158 char *pathname;
00159
00161 dev_node_t *dev;
00162
00164 link_t dev_functions;
00165
00167 dev_node_t *child;
00169 match_id_list_t match_ids;
00170
00172 link_t classes;
00174 devmap_handle_t devmap_handle;
00175
00179 link_t devman_fun;
00180
00184 link_t devmap_fun;
00185 };
00186
00187
00189 typedef struct dev_tree {
00191 fun_node_t *root_node;
00192
00197 devman_handle_t current_handle;
00198
00200 fibril_rwlock_t rwlock;
00201
00203 hash_table_t devman_devices;
00204
00206 hash_table_t devman_functions;
00207
00212 hash_table_t devmap_functions;
00213 } dev_tree_t;
00214
00215 typedef struct dev_class {
00217 const char *name;
00218
00223 link_t link;
00224
00229 link_t devices;
00230
00235 const char *base_dev_name;
00236
00238 size_t curr_dev_idx;
00240 fibril_mutex_t mutex;
00241 } dev_class_t;
00242
00248 typedef struct dev_class_info {
00250 dev_class_t *dev_class;
00252 fun_node_t *fun;
00253
00258 link_t link;
00259
00264 link_t dev_classes;
00265
00267 char *dev_name;
00269 devmap_handle_t devmap_handle;
00270
00275 link_t devmap_link;
00276 } dev_class_info_t;
00277
00279 typedef struct class_list {
00281 link_t classes;
00282
00287 hash_table_t devmap_functions;
00288
00290 fibril_rwlock_t rwlock;
00291 } class_list_t;
00292
00293
00294
00295 extern int get_match_score(driver_t *, dev_node_t *);
00296
00297 extern bool parse_match_ids(char *, match_id_list_t *);
00298 extern bool read_match_ids(const char *, match_id_list_t *);
00299 extern char *read_match_id(char **);
00300 extern char *read_id(const char **);
00301
00302
00303
00304 extern void init_driver_list(driver_list_t *);
00305 extern driver_t *create_driver(void);
00306 extern bool get_driver_info(const char *, const char *, driver_t *);
00307 extern int lookup_available_drivers(driver_list_t *, const char *);
00308
00309 extern driver_t *find_best_match_driver(driver_list_t *, dev_node_t *);
00310 extern bool assign_driver(dev_node_t *, driver_list_t *, dev_tree_t *);
00311
00312 extern void add_driver(driver_list_t *, driver_t *);
00313 extern void attach_driver(dev_node_t *, driver_t *);
00314 extern void add_device(int, driver_t *, dev_node_t *, dev_tree_t *);
00315 extern bool start_driver(driver_t *);
00316
00317 extern driver_t *find_driver(driver_list_t *, const char *);
00318 extern void initialize_running_driver(driver_t *, dev_tree_t *);
00319
00320 extern void init_driver(driver_t *);
00321 extern void clean_driver(driver_t *);
00322 extern void delete_driver(driver_t *);
00323
00324
00325
00326 extern dev_node_t *create_dev_node(void);
00327 extern void delete_dev_node(dev_node_t *node);
00328 extern dev_node_t *find_dev_node_no_lock(dev_tree_t *tree,
00329 devman_handle_t handle);
00330 extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle);
00331 extern dev_node_t *find_dev_function(dev_node_t *, const char *);
00332
00333 extern fun_node_t *create_fun_node(void);
00334 extern void delete_fun_node(fun_node_t *);
00335 extern fun_node_t *find_fun_node_no_lock(dev_tree_t *tree,
00336 devman_handle_t handle);
00337 extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
00338 extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
00339 extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);
00340 extern fun_node_t *find_fun_node_by_class(class_list_t *, const char *, const char *);
00341
00342
00343
00344 extern bool init_device_tree(dev_tree_t *, driver_list_t *);
00345 extern bool create_root_nodes(dev_tree_t *);
00346 extern bool insert_dev_node(dev_tree_t *, dev_node_t *, fun_node_t *);
00347 extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *);
00348
00349
00350
00351 extern dev_class_t *create_dev_class(void);
00352 extern dev_class_info_t *create_dev_class_info(void);
00353 extern size_t get_new_class_dev_idx(dev_class_t *);
00354 extern char *create_dev_name_for_class(dev_class_t *, const char *);
00355 extern dev_class_info_t *add_function_to_class(fun_node_t *, dev_class_t *,
00356 const char *);
00357
00358 extern void init_class_list(class_list_t *);
00359
00360 extern dev_class_t *get_dev_class(class_list_t *, char *);
00361 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
00362 extern dev_class_info_t *find_dev_in_class(dev_class_t *, const char *);
00363 extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
00364
00365
00366
00367 extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *);
00368
00369 extern fun_node_t *find_devmap_tree_function(dev_tree_t *, devmap_handle_t);
00370 extern fun_node_t *find_devmap_class_function(class_list_t *, devmap_handle_t);
00371
00372 extern void class_add_devmap_function(class_list_t *, dev_class_info_t *);
00373 extern void tree_add_devmap_function(dev_tree_t *, fun_node_t *);
00374
00375 #endif
00376