Changeset 38b3baf in mainline for uspace/srv/devman/devman.h
- Timestamp:
- 2010-10-23T07:16:14Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e66a5ec
- Parents:
- 032e0bb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.h
r032e0bb r38b3baf 61 61 62 62 typedef enum { 63 /** driver has not been started*/63 /** Driver has not been started. */ 64 64 DRIVER_NOT_STARTED = 0, 65 /** driver has been started, but has not registered as running and ready to receive requests */ 65 66 /** 67 * Driver has been started, but has not registered as running and ready 68 * to receive requests. 69 */ 66 70 DRIVER_STARTING, 67 /** driver is running and prepared to serve incomming requests */ 71 72 /** Driver is running and prepared to serve incomming requests. */ 68 73 DRIVER_RUNNING 69 74 } driver_state_t; 70 75 71 /** Representation of device driver. 72 */ 76 /** Representation of device driver. */ 73 77 typedef struct driver { 74 /** Pointers to previous and next drivers in a linked list */78 /** Pointers to previous and next drivers in a linked list. */ 75 79 link_t drivers; 76 /** Specifies whether the driver has been started and wheter is running and prepared to receive requests.*/ 80 81 /** 82 * Specifies whether the driver has been started and wheter is running 83 * and prepared to receive requests. 84 */ 77 85 int state; 78 /** Phone asociated with this driver */ 86 87 /** Phone asociated with this driver. */ 79 88 ipcarg_t phone; 80 /** Name of the device driver */89 /** Name of the device driver. */ 81 90 char *name; 82 /** Path to the driver's binary */91 /** Path to the driver's binary. */ 83 92 const char *binary_path; 84 /** List of device ids for device-to-driver matching. */93 /** List of device ids for device-to-driver matching. */ 85 94 match_id_list_t match_ids; 86 /** Pointer to the linked list of devices controlled by this driver */95 /** Pointer to the linked list of devices controlled by this driver. */ 87 96 link_t devices; 88 /** Fibril mutex for this driver - driver state, list of devices, phone.*/ 97 98 /** 99 * Fibril mutex for this driver - driver state, list of devices, phone. 100 */ 89 101 fibril_mutex_t driver_mutex; 90 102 } driver_t; … … 95 107 link_t drivers; 96 108 /** Fibril mutex for list of drivers. */ 97 fibril_mutex_t drivers_mutex; 109 fibril_mutex_t drivers_mutex; 98 110 } driver_list_t; 99 111 … … 106 118 } device_state_t; 107 119 108 /** Representation of a node in the device tree. */120 /** Representation of a node in the device tree. */ 109 121 struct node { 110 /** The global unique identifier of the device. */122 /** The global unique identifier of the device. */ 111 123 device_handle_t handle; 112 124 /** The name of the device specified by its parent. */ 113 125 char *name; 114 /** Full path and name of the device in device hierarchi (i. e. in full path in device tree).*/ 115 char *pathname; 126 127 /** 128 * Full path and name of the device in device hierarchi (i. e. in full 129 * path in device tree). 130 */ 131 char *pathname; 132 116 133 /** The node of the parent device. */ 117 134 node_t *parent; 118 /** Pointers to previous and next child devices in the linked list of parent device's node.*/ 135 136 /** 137 * Pointers to previous and next child devices in the linked list of 138 * parent device's node. 139 */ 119 140 link_t sibling; 141 120 142 /** List of child device nodes. */ 121 143 link_t children; 122 /** List of device ids for device-to-driver matching. */144 /** List of device ids for device-to-driver matching. */ 123 145 match_id_list_t match_ids; 124 /** Driver of this device. */146 /** Driver of this device. */ 125 147 driver_t *drv; 126 148 /** The state of the device. */ 127 149 device_state_t state; 128 /** Pointer to the previous and next device in the list of devices 129 owned by one driver */ 150 /** 151 * Pointer to the previous and next device in the list of devices 152 * owned by one driver. 153 */ 130 154 link_t driver_devices; 131 /** The list of device classes to which this device belongs.*/ 155 156 /** The list of device classes to which this device belongs. */ 132 157 link_t classes; 133 158 /** Devmap handle if the device is registered by devmapper. */ 134 159 dev_handle_t devmap_handle; 135 /** Used by the hash table of devices indexed by devman device handles.*/ 160 161 /** 162 * Used by the hash table of devices indexed by devman device handles. 163 */ 136 164 link_t devman_link; 137 /** Used by the hash table of devices indexed by devmap device handles.*/ 165 166 /** 167 * Used by the hash table of devices indexed by devmap device handles. 168 */ 138 169 link_t devmap_link; 139 170 }; 140 171 141 142 /** Represents device tree. 143 */ 172 /** Represents device tree. */ 144 173 typedef struct dev_tree { 145 174 /** Root device node. */ 146 175 node_t *root_node; 147 /** The next available handle - handles are assigned in a sequential manner.*/ 176 177 /** 178 * The next available handle - handles are assigned in a sequential 179 * manner. 180 */ 148 181 device_handle_t current_handle; 149 /** Synchronize access to the device tree.*/ 182 183 /** Synchronize access to the device tree. */ 150 184 fibril_rwlock_t rwlock; 151 /** Hash table of all devices indexed by devman handles.*/ 185 186 /** Hash table of all devices indexed by devman handles. */ 152 187 hash_table_t devman_devices; 153 /** Hash table of devices registered by devmapper, indexed by devmap handles.*/ 188 189 /** 190 * Hash table of devices registered by devmapper, indexed by devmap 191 * handles. 192 */ 154 193 hash_table_t devmap_devices; 155 194 } dev_tree_t; 156 195 157 typedef struct dev_class { 158 /** The name of the class. */196 typedef struct dev_class { 197 /** The name of the class. */ 159 198 const char *name; 160 /** Pointer to the previous and next class in the list of registered classes.*/ 161 link_t link; 162 /** List of dev_class_info structures - one for each device registered by this class.*/ 199 200 /** 201 * Pointer to the previous and next class in the list of registered 202 * classes. 203 */ 204 link_t link; 205 206 /** 207 * List of dev_class_info structures - one for each device registered by 208 * this class. 209 */ 163 210 link_t devices; 164 /** Default base name for the device within the class, might be overrided by the driver.*/ 211 212 /** 213 * Default base name for the device within the class, might be overrided 214 * by the driver. 215 */ 165 216 const char *base_dev_name; 166 /** Unique numerical identifier of the newly added device.*/ 217 218 /** Unique numerical identifier of the newly added device. */ 167 219 size_t curr_dev_idx; 168 220 /** Synchronize access to the list of devices in this class. */ … … 170 222 } dev_class_t; 171 223 172 /** Provides n-to-m mapping between device nodes and classes 173 * - each device may be register to the arbitrary number of classes 174 * and each class may contain the arbitrary number of devices. */ 224 /** Provides n-to-m mapping between device nodes and classes - each device may 225 * be register to the arbitrary number of classes and each class may contain 226 * the arbitrary number of devices. 227 */ 175 228 typedef struct dev_class_info { 176 /** The class. */229 /** The class. */ 177 230 dev_class_t *dev_class; 178 /** The device. */231 /** The device. */ 179 232 node_t *dev; 180 /** Pointer to the previous and next class info in the list of devices registered by the class.*/ 233 234 /** 235 * Pointer to the previous and next class info in the list of devices 236 * registered by the class. 237 */ 181 238 link_t link; 182 /** Pointer to the previous and next class info in the list of classes by which the device is registered.*/ 239 240 /** 241 * Pointer to the previous and next class info in the list of classes 242 * by which the device is registered. 243 */ 183 244 link_t dev_classes; 184 /** The name of the device within the class.*/ 185 char *dev_name; 186 /** The handle of the device by device mapper in the class namespace.*/ 245 246 /** The name of the device within the class. */ 247 char *dev_name; 248 /** The handle of the device by device mapper in the class namespace. */ 187 249 dev_handle_t devmap_handle; 188 /** Link in the hash table of devices registered by the devmapper using their class names.*/ 250 251 /** 252 * Link in the hash table of devices registered by the devmapper using 253 * their class names. 254 */ 189 255 link_t devmap_link; 190 256 } dev_class_info_t; … … 192 258 /** The list of device classes. */ 193 259 typedef struct class_list { 194 /** List of classes */260 /** List of classes. */ 195 261 link_t classes; 196 /** Hash table of devices registered by devmapper using their class name, indexed by devmap handles.*/ 262 263 /** 264 * Hash table of devices registered by devmapper using their class name, 265 * indexed by devmap handles. 266 */ 197 267 hash_table_t devmap_devices; 268 198 269 /** Fibril mutex for list of classes. */ 199 fibril_rwlock_t rwlock; 270 fibril_rwlock_t rwlock; 200 271 } class_list_t; 201 272 202 / / Match ids and scores203 204 int get_match_score(driver_t *drv, node_t *dev);205 206 bool parse_match_ids(char *buf, match_id_list_t *ids);207 bool read_match_ids(const char *conf_path, match_id_list_t *ids);208 char * read_match_id(char **buf);209 char * read_id(const char **buf);210 211 / / Drivers212 213 /** 273 /* Match ids and scores */ 274 275 extern int get_match_score(driver_t *, node_t *); 276 277 extern bool parse_match_ids(char *, match_id_list_t *); 278 extern bool read_match_ids(const char *, match_id_list_t *); 279 extern char *read_match_id(char **); 280 extern char *read_id(const char **); 281 282 /* Drivers */ 283 284 /** 214 285 * Initialize the list of device driver's. 215 * 286 * 216 287 * @param drv_list the list of device driver's. 217 * 218 */ 219 static inline void init_driver_list(driver_list_t *drv_list) 288 * 289 */ 290 static inline void init_driver_list(driver_list_t *drv_list) 220 291 { 221 292 assert(NULL != drv_list); 222 293 223 294 list_initialize(&drv_list->drivers); 224 fibril_mutex_initialize(&drv_list->drivers_mutex); 225 } 226 227 driver_t * create_driver(void); 228 bool get_driver_info(const char *base_path, const char *name, driver_t *drv); 229 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path); 230 231 driver_t * find_best_match_driver(driver_list_t *drivers_list, node_t *node); 232 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree); 233 234 void add_driver(driver_list_t *drivers_list, driver_t *drv); 235 void attach_driver(node_t *node, driver_t *drv); 236 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree); 237 bool start_driver(driver_t *drv); 238 239 driver_t * find_driver(driver_list_t *drv_list, const char *drv_name); 240 void set_driver_phone(driver_t *driver, ipcarg_t phone); 241 void initialize_running_driver(driver_t *driver, dev_tree_t *tree); 242 243 /** 244 * Initialize device driver structure. 245 * 246 * @param drv the device driver structure. 247 * 295 fibril_mutex_initialize(&drv_list->drivers_mutex); 296 } 297 298 extern driver_t *create_driver(void); 299 extern bool get_driver_info(const char *, const char *, driver_t *); 300 extern int lookup_available_drivers(driver_list_t *, const char *); 301 302 extern driver_t *find_best_match_driver(driver_list_t *, node_t *); 303 extern bool assign_driver(node_t *, driver_list_t *, dev_tree_t *); 304 305 extern void add_driver(driver_list_t *, driver_t *); 306 extern void attach_driver(node_t *, driver_t *); 307 extern void add_device(int, driver_t *, node_t *, dev_tree_t *); 308 extern bool start_driver(driver_t *); 309 310 extern driver_t *find_driver(driver_list_t *, const char *); 311 extern void set_driver_phone(driver_t *, ipcarg_t); 312 void initialize_running_driver(driver_t *, dev_tree_t *); 313 314 /** Initialize device driver structure. 315 * 316 * @param drv The device driver structure. 248 317 */ 249 318 static inline void init_driver(driver_t *drv) … … 254 323 list_initialize(&drv->match_ids.ids); 255 324 list_initialize(&drv->devices); 256 fibril_mutex_initialize(&drv->driver_mutex); 257 } 258 259 /** 260 * Device driver structure clean-up. 261 * 262 * @param drv the device driver structure. 325 fibril_mutex_initialize(&drv->driver_mutex); 326 } 327 328 /** Device driver structure clean-up. 329 * 330 * @param drv The device driver structure. 263 331 */ 264 332 static inline void clean_driver(driver_t *drv) … … 267 335 268 336 free_not_null(drv->name); 269 free_not_null(drv->binary_path); 337 free_not_null(drv->binary_path); 270 338 271 339 clean_match_ids(&drv->match_ids); … … 274 342 } 275 343 276 /** 277 * Delete device driver structure. 278 * 279 * @param drv the device driver structure.* 344 /** Delete device driver structure. 345 * 346 * @param drv The device driver structure. 280 347 */ 281 348 static inline void delete_driver(driver_t *drv) … … 287 354 } 288 355 289 // Device nodes 290 /* *291 * Create a new device node. 292 * 293 * @return a device node structure.294 * 295 */ 296 static inline node_t * create_dev_node()356 357 /* Device nodes */ 358 359 /** Create a new device node. 360 * 361 * @return A device node structure. 362 */ 363 static inline node_t *create_dev_node(void) 297 364 { 298 365 node_t *res = malloc(sizeof(node_t)); … … 308 375 } 309 376 310 /** 311 * Delete a device node. 312 * 313 * @param node a device node structure. 314 * 377 /** Delete a device node. 378 * 379 * @param node The device node structure. 315 380 */ 316 381 static inline void delete_dev_node(node_t *node) 317 382 { 318 assert(list_empty(&node->children) && NULL == node->parent && NULL == node->drv); 383 assert(list_empty(&node->children)); 384 assert(NULL == node->parent); 385 assert(NULL == node->drv); 319 386 320 387 clean_match_ids(&node->match_ids); 321 388 free_not_null(node->name); 322 389 free_not_null(node->pathname); 323 free(node); 324 } 325 326 /** 327 * Find the device node structure of the device witch has the specified handle. 328 * 390 free(node); 391 } 392 393 /** Find the device node structure of the device witch has the specified handle. 394 * 329 395 * Device tree's rwlock should be held at least for reading. 330 * 331 * @param tree the device tree where we look for the device node. 332 * @param handle the handle of the device. 333 * @return the device node. 334 */ 335 static inline node_t * find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle) 396 * 397 * @param tree The device tree where we look for the device node. 398 * @param handle The handle of the device. 399 * @return The device node. 400 */ 401 static inline node_t * 402 find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle) 336 403 { 337 404 unsigned long key = handle; … … 340 407 } 341 408 342 /** 343 * Find the device node structure of the device witch has the specified handle.344 * 345 * @param tree the device tree where we look for the device node.346 * @ param handle the handle of the device.347 * @return the device node.348 */ 349 static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)409 /** Find the device node structure of the device witch has the specified handle. 410 * 411 * @param tree The device tree where we look for the device node. 412 * @param handle The handle of the device. 413 * @return The device node. 414 */ 415 static inline node_t * 416 find_dev_node(dev_tree_t *tree, device_handle_t handle) 350 417 { 351 418 node_t *node = NULL; 352 419 353 420 fibril_rwlock_read_lock(&tree->rwlock); 354 355 421 node = find_dev_node_no_lock(tree, handle); 356 357 422 fibril_rwlock_read_unlock(&tree->rwlock); 358 423 … … 360 425 } 361 426 362 node_t * find_dev_node_by_path(dev_tree_t *tree, char *path); 363 node_t *find_node_child(node_t *parent, const char *name); 364 365 // Device tree 366 367 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list); 368 bool create_root_node(dev_tree_t *tree); 369 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent); 370 371 // Device classes 372 373 /** Create device class. 374 * 375 * @return device class. 376 */ 377 static inline dev_class_t * create_dev_class() 378 { 379 dev_class_t *cl = (dev_class_t *)malloc(sizeof(dev_class_t)); 427 extern node_t *find_dev_node_by_path(dev_tree_t *, char *); 428 extern node_t *find_node_child(node_t *, const char *); 429 430 431 /* Device tree */ 432 433 extern bool init_device_tree(dev_tree_t *, driver_list_t *); 434 extern bool create_root_node(dev_tree_t *); 435 extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *); 436 437 438 /* Device classes */ 439 440 /** Create device class. 441 * 442 * @return Device class. 443 */ 444 static inline dev_class_t *create_dev_class(void) 445 { 446 dev_class_t *cl; 447 448 cl = (dev_class_t *) malloc(sizeof(dev_class_t)); 380 449 if (NULL != cl) { 381 450 memset(cl, 0, sizeof(dev_class_t)); … … 383 452 fibril_mutex_initialize(&cl->mutex); 384 453 } 385 return cl; 386 } 387 388 /** Create device class info. 389 * 390 * @return device class info. 391 */ 392 static inline dev_class_info_t * create_dev_class_info() 393 { 394 dev_class_info_t *info = (dev_class_info_t *)malloc(sizeof(dev_class_info_t)); 395 if (NULL != info) { 454 455 return cl; 456 } 457 458 /** Create device class info. 459 * 460 * @return Device class info. 461 */ 462 static inline dev_class_info_t *create_dev_class_info(void) 463 { 464 dev_class_info_t *info; 465 466 info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t)); 467 if (NULL != info) 396 468 memset(info, 0, sizeof(dev_class_info_t)); 397 }398 return info; 469 470 return info; 399 471 } 400 472 … … 402 474 { 403 475 size_t dev_idx; 476 404 477 fibril_mutex_lock(&cl->mutex); 405 478 dev_idx = ++cl->curr_dev_idx; 406 479 fibril_mutex_unlock(&cl->mutex); 480 407 481 return dev_idx; 408 482 } 409 483 410 char * create_dev_name_for_class(dev_class_t *cl, const char *base_dev_name); 411 dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name); 412 413 void init_class_list(class_list_t *class_list); 414 415 dev_class_t * get_dev_class(class_list_t *class_list, char *class_name); 416 dev_class_t * find_dev_class_no_lock(class_list_t *class_list, const char *class_name); 417 418 static inline void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl) 484 extern char *create_dev_name_for_class(dev_class_t *, const char *); 485 extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *, 486 const char *); 487 488 extern void init_class_list(class_list_t *); 489 490 extern dev_class_t *get_dev_class(class_list_t *, char *); 491 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *); 492 493 static inline void 494 add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl) 419 495 { 420 496 list_append(&cl->link, &class_list->classes); … … 422 498 423 499 424 // devmap devices 425 426 node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle); 427 node_t *find_devmap_class_device(class_list_t *classes, dev_handle_t devmap_handle); 428 429 430 static inline void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli) 431 { 432 unsigned long key = (unsigned long)cli->devmap_handle; 500 /* Devmap devices */ 501 502 extern node_t *find_devmap_tree_device(dev_tree_t *, dev_handle_t); 503 extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t); 504 505 static inline void 506 class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli) 507 { 508 unsigned long key = (unsigned long) cli->devmap_handle; 509 433 510 fibril_rwlock_write_lock(&class_list->rwlock); 434 511 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); … … 438 515 static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node) 439 516 { 440 unsigned long key = (unsigned long) node->devmap_handle;517 unsigned long key = (unsigned long) node->devmap_handle; 441 518 fibril_rwlock_write_lock(&tree->rwlock); 442 519 hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link); 443 fibril_rwlock_write_unlock(&tree->rwlock); 520 fibril_rwlock_write_unlock(&tree->rwlock); 444 521 } 445 522
Note:
See TracChangeset
for help on using the changeset viewer.