Changeset 791f58c in mainline
- Timestamp:
- 2010-10-23T16:42:08Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 713a4b9
- Parents:
- c6c389ed
- Location:
- uspace/srv/devman
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
rc6c389ed r791f58c 76 76 .remove_callback = devices_remove_callback 77 77 }; 78 79 /** 80 * Initialize the list of device driver's. 81 * 82 * @param drv_list the list of device driver's. 83 * 84 */ 85 void init_driver_list(driver_list_t *drv_list) 86 { 87 assert(drv_list != NULL); 88 89 list_initialize(&drv_list->drivers); 90 fibril_mutex_initialize(&drv_list->drivers_mutex); 91 } 78 92 79 93 /** Allocate and initialize a new driver structure. … … 548 562 } 549 563 564 /** Initialize device driver structure. 565 * 566 * @param drv The device driver structure. 567 */ 568 void init_driver(driver_t *drv) 569 { 570 assert(drv != NULL); 571 572 memset(drv, 0, sizeof(driver_t)); 573 list_initialize(&drv->match_ids.ids); 574 list_initialize(&drv->devices); 575 fibril_mutex_initialize(&drv->driver_mutex); 576 } 577 578 /** Device driver structure clean-up. 579 * 580 * @param drv The device driver structure. 581 */ 582 void clean_driver(driver_t *drv) 583 { 584 assert(drv != NULL); 585 586 free_not_null(drv->name); 587 free_not_null(drv->binary_path); 588 589 clean_match_ids(&drv->match_ids); 590 591 init_driver(drv); 592 } 593 594 /** Delete device driver structure. 595 * 596 * @param drv The device driver structure. 597 */ 598 void delete_driver(driver_t *drv) 599 { 600 assert(drv != NULL); 601 602 clean_driver(drv); 603 free(drv); 604 } 550 605 551 606 /** Create devmap path and name for the device. */ … … 685 740 } 686 741 742 /* Device nodes */ 743 744 /** Create a new device node. 745 * 746 * @return A device node structure. 747 */ 748 node_t *create_dev_node(void) 749 { 750 node_t *res = malloc(sizeof(node_t)); 751 752 if (res != NULL) { 753 memset(res, 0, sizeof(node_t)); 754 list_initialize(&res->children); 755 list_initialize(&res->match_ids.ids); 756 list_initialize(&res->classes); 757 } 758 759 return res; 760 } 761 762 /** Delete a device node. 763 * 764 * @param node The device node structure. 765 */ 766 void delete_dev_node(node_t *node) 767 { 768 assert(list_empty(&node->children)); 769 assert(node->parent == NULL); 770 assert(node->drv == NULL); 771 772 clean_match_ids(&node->match_ids); 773 free_not_null(node->name); 774 free_not_null(node->pathname); 775 free(node); 776 } 777 778 /** Find the device node structure of the device witch has the specified handle. 779 * 780 * Device tree's rwlock should be held at least for reading. 781 * 782 * @param tree The device tree where we look for the device node. 783 * @param handle The handle of the device. 784 * @return The device node. 785 */ 786 node_t *find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle) 787 { 788 unsigned long key = handle; 789 link_t *link = hash_table_find(&tree->devman_devices, &key); 790 return hash_table_get_instance(link, node_t, devman_link); 791 } 792 793 /** Find the device node structure of the device witch has the specified handle. 794 * 795 * @param tree The device tree where we look for the device node. 796 * @param handle The handle of the device. 797 * @return The device node. 798 */ 799 node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle) 800 { 801 node_t *node = NULL; 802 803 fibril_rwlock_read_lock(&tree->rwlock); 804 node = find_dev_node_no_lock(tree, handle); 805 fibril_rwlock_read_unlock(&tree->rwlock); 806 807 return node; 808 } 809 810 687 811 /** Create and set device's full path in device tree. 688 812 * … … 825 949 return NULL; 826 950 } 951 952 /* Device classes */ 953 954 /** Create device class. 955 * 956 * @return Device class. 957 */ 958 dev_class_t *create_dev_class(void) 959 { 960 dev_class_t *cl; 961 962 cl = (dev_class_t *) malloc(sizeof(dev_class_t)); 963 if (cl != NULL) { 964 memset(cl, 0, sizeof(dev_class_t)); 965 list_initialize(&cl->devices); 966 fibril_mutex_initialize(&cl->mutex); 967 } 968 969 return cl; 970 } 971 972 /** Create device class info. 973 * 974 * @return Device class info. 975 */ 976 dev_class_info_t *create_dev_class_info(void) 977 { 978 dev_class_info_t *info; 979 980 info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t)); 981 if (info != NULL) 982 memset(info, 0, sizeof(dev_class_info_t)); 983 984 return info; 985 } 986 987 size_t get_new_class_dev_idx(dev_class_t *cl) 988 { 989 size_t dev_idx; 990 991 fibril_mutex_lock(&cl->mutex); 992 dev_idx = ++cl->curr_dev_idx; 993 fibril_mutex_unlock(&cl->mutex); 994 995 return dev_idx; 996 } 997 827 998 828 999 /** Create unique device name within the class. … … 921 1092 } 922 1093 1094 void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl) 1095 { 1096 list_append(&cl->link, &class_list->classes); 1097 } 1098 923 1099 void init_class_list(class_list_t *class_list) 924 1100 { … … 930 1106 931 1107 932 /* devmap devices */1108 /* Devmap devices */ 933 1109 934 1110 node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle) … … 967 1143 } 968 1144 1145 void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli) 1146 { 1147 unsigned long key = (unsigned long) cli->devmap_handle; 1148 1149 fibril_rwlock_write_lock(&class_list->rwlock); 1150 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 1151 fibril_rwlock_write_unlock(&class_list->rwlock); 1152 } 1153 1154 void tree_add_devmap_device(dev_tree_t *tree, node_t *node) 1155 { 1156 unsigned long key = (unsigned long) node->devmap_handle; 1157 fibril_rwlock_write_lock(&tree->rwlock); 1158 hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link); 1159 fibril_rwlock_write_unlock(&tree->rwlock); 1160 } 1161 969 1162 /** @} 970 1163 */ -
uspace/srv/devman/devman.h
rc6c389ed r791f58c 283 283 /* Drivers */ 284 284 285 /** 286 * Initialize the list of device driver's. 287 * 288 * @param drv_list the list of device driver's. 289 * 290 */ 291 static inline void init_driver_list(driver_list_t *drv_list) 292 { 293 assert(drv_list != NULL); 294 295 list_initialize(&drv_list->drivers); 296 fibril_mutex_initialize(&drv_list->drivers_mutex); 297 } 298 285 extern void init_driver_list(driver_list_t *); 299 286 extern driver_t *create_driver(void); 300 287 extern bool get_driver_info(const char *, const char *, driver_t *); … … 311 298 extern driver_t *find_driver(driver_list_t *, const char *); 312 299 extern void set_driver_phone(driver_t *, ipcarg_t); 313 void initialize_running_driver(driver_t *, dev_tree_t *); 314 315 /** Initialize device driver structure. 316 * 317 * @param drv The device driver structure. 318 */ 319 static inline void init_driver(driver_t *drv) 320 { 321 assert(drv != NULL); 322 323 memset(drv, 0, sizeof(driver_t)); 324 list_initialize(&drv->match_ids.ids); 325 list_initialize(&drv->devices); 326 fibril_mutex_initialize(&drv->driver_mutex); 327 } 328 329 /** Device driver structure clean-up. 330 * 331 * @param drv The device driver structure. 332 */ 333 static inline void clean_driver(driver_t *drv) 334 { 335 assert(drv != NULL); 336 337 free_not_null(drv->name); 338 free_not_null(drv->binary_path); 339 340 clean_match_ids(&drv->match_ids); 341 342 init_driver(drv); 343 } 344 345 /** Delete device driver structure. 346 * 347 * @param drv The device driver structure. 348 */ 349 static inline void delete_driver(driver_t *drv) 350 { 351 assert(drv != NULL); 352 353 clean_driver(drv); 354 free(drv); 355 } 356 300 extern void initialize_running_driver(driver_t *, dev_tree_t *); 301 302 extern void init_driver(driver_t *); 303 extern void clean_driver(driver_t *); 304 extern void delete_driver(driver_t *); 357 305 358 306 /* Device nodes */ 359 307 360 /** Create a new device node. 361 * 362 * @return A device node structure. 363 */ 364 static inline node_t *create_dev_node(void) 365 { 366 node_t *res = malloc(sizeof(node_t)); 367 368 if (res != NULL) { 369 memset(res, 0, sizeof(node_t)); 370 list_initialize(&res->children); 371 list_initialize(&res->match_ids.ids); 372 list_initialize(&res->classes); 373 } 374 375 return res; 376 } 377 378 /** Delete a device node. 379 * 380 * @param node The device node structure. 381 */ 382 static inline void delete_dev_node(node_t *node) 383 { 384 assert(list_empty(&node->children)); 385 assert(node->parent == NULL); 386 assert(node->drv == NULL); 387 388 clean_match_ids(&node->match_ids); 389 free_not_null(node->name); 390 free_not_null(node->pathname); 391 free(node); 392 } 393 394 /** Find the device node structure of the device witch has the specified handle. 395 * 396 * Device tree's rwlock should be held at least for reading. 397 * 398 * @param tree The device tree where we look for the device node. 399 * @param handle The handle of the device. 400 * @return The device node. 401 */ 402 static inline node_t *find_dev_node_no_lock(dev_tree_t *tree, 403 device_handle_t handle) 404 { 405 unsigned long key = handle; 406 link_t *link = hash_table_find(&tree->devman_devices, &key); 407 return hash_table_get_instance(link, node_t, devman_link); 408 } 409 410 /** Find the device node structure of the device witch has the specified handle. 411 * 412 * @param tree The device tree where we look for the device node. 413 * @param handle The handle of the device. 414 * @return The device node. 415 */ 416 static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle) 417 { 418 node_t *node = NULL; 419 420 fibril_rwlock_read_lock(&tree->rwlock); 421 node = find_dev_node_no_lock(tree, handle); 422 fibril_rwlock_read_unlock(&tree->rwlock); 423 424 return node; 425 } 426 308 extern node_t *create_dev_node(void); 309 extern void delete_dev_node(node_t *node); 310 extern node_t *find_dev_node_no_lock(dev_tree_t *tree, 311 device_handle_t handle); 312 extern node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle); 427 313 extern node_t *find_dev_node_by_path(dev_tree_t *, char *); 428 314 extern node_t *find_node_child(node_t *, const char *); 429 430 315 431 316 /* Device tree */ … … 435 320 extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *); 436 321 437 438 322 /* Device classes */ 439 323 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)); 449 if (cl != NULL) { 450 memset(cl, 0, sizeof(dev_class_t)); 451 list_initialize(&cl->devices); 452 fibril_mutex_initialize(&cl->mutex); 453 } 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 (info != NULL) 468 memset(info, 0, sizeof(dev_class_info_t)); 469 470 return info; 471 } 472 473 static inline size_t get_new_class_dev_idx(dev_class_t *cl) 474 { 475 size_t dev_idx; 476 477 fibril_mutex_lock(&cl->mutex); 478 dev_idx = ++cl->curr_dev_idx; 479 fibril_mutex_unlock(&cl->mutex); 480 481 return dev_idx; 482 } 483 324 extern dev_class_t *create_dev_class(void); 325 extern dev_class_info_t *create_dev_class_info(void); 326 extern size_t get_new_class_dev_idx(dev_class_t *); 484 327 extern char *create_dev_name_for_class(dev_class_t *, const char *); 485 328 extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *, … … 490 333 extern dev_class_t *get_dev_class(class_list_t *, char *); 491 334 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *); 492 493 static inline void add_dev_class_no_lock(class_list_t *class_list, 494 dev_class_t *cl) 495 { 496 list_append(&cl->link, &class_list->classes); 497 } 498 335 extern void add_dev_class_no_lock(class_list_t *, dev_class_t *); 499 336 500 337 /* Devmap devices */ … … 503 340 extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t); 504 341 505 static inline void class_add_devmap_device(class_list_t *class_list, 506 dev_class_info_t *cli) 507 { 508 unsigned long key = (unsigned long) cli->devmap_handle; 509 510 fibril_rwlock_write_lock(&class_list->rwlock); 511 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 512 fibril_rwlock_write_unlock(&class_list->rwlock); 513 } 514 515 static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node) 516 { 517 unsigned long key = (unsigned long) node->devmap_handle; 518 fibril_rwlock_write_lock(&tree->rwlock); 519 hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link); 520 fibril_rwlock_write_unlock(&tree->rwlock); 521 } 342 extern void class_add_devmap_device(class_list_t *, dev_class_info_t *); 343 extern void tree_add_devmap_device(dev_tree_t *, node_t *); 522 344 523 345 #endif -
uspace/srv/devman/util.c
rc6c389ed r791f58c 66 66 } 67 67 68 bool skip_spaces(char **buf) 69 { 70 while (isspace(**buf)) 71 (*buf)++; 72 return *buf != 0; 73 } 74 75 size_t get_nonspace_len(const char *str) 76 { 77 size_t len = 0; 78 79 while(*str != '\0' && !isspace(*str)) { 80 len++; 81 str++; 82 } 83 84 return len; 85 } 86 87 void free_not_null(const void *ptr) 88 { 89 if (ptr != NULL) 90 free(ptr); 91 } 92 93 char *clone_string(const char *s) 94 { 95 size_t size = str_size(s) + 1; 96 char *str; 97 98 str = (char *) malloc(size); 99 if (str != NULL) 100 str_cpy(str, size, s); 101 return str; 102 } 103 104 void replace_char(char *str, char orig, char repl) 105 { 106 while (*str) { 107 if (*str == orig) 108 *str = repl; 109 str++; 110 } 111 } 112 68 113 /** @} 69 114 */ -
uspace/srv/devman/util.h
rc6c389ed r791f58c 41 41 extern char *get_path_elem_end(char *); 42 42 43 static inline bool skip_spaces(char **buf) 44 { 45 while (isspace(**buf)) 46 (*buf)++; 47 return *buf != 0; 48 } 49 50 static inline size_t get_nonspace_len(const char *str) 51 { 52 size_t len = 0; 53 54 while(*str != '\0' && !isspace(*str)) { 55 len++; 56 str++; 57 } 58 59 return len; 60 } 61 62 static inline void free_not_null(const void *ptr) 63 { 64 if (ptr != NULL) 65 free(ptr); 66 } 67 68 static inline char *clone_string(const char *s) 69 { 70 size_t size = str_size(s) + 1; 71 char *str; 72 73 str = (char *) malloc(size); 74 if (str != NULL) 75 str_cpy(str, size, s); 76 return str; 77 } 78 79 static inline void replace_char(char *str, char orig, char repl) 80 { 81 while (*str) { 82 if (*str == orig) 83 *str = repl; 84 str++; 85 } 86 } 43 extern bool skip_spaces(char **); 44 extern size_t get_nonspace_len(const char *); 45 extern void free_not_null(const void *); 46 extern char *clone_string(const char *); 47 extern void replace_char(char *, char, char); 87 48 88 49 #endif
Note:
See TracChangeset
for help on using the changeset viewer.