Changes in uspace/srv/devman/devman.c [791f58c:58b833c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r791f58c r58b833c 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 }92 78 93 79 /** Allocate and initialize a new driver structure. … … 562 548 } 563 549 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 }605 550 606 551 /** Create devmap path and name for the device. */ … … 740 685 } 741 686 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 811 687 /** Create and set device's full path in device tree. 812 688 * … … 949 825 return NULL; 950 826 } 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 998 827 999 828 /** Create unique device name within the class. … … 1092 921 } 1093 922 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 1099 923 void init_class_list(class_list_t *class_list) 1100 924 { … … 1106 930 1107 931 1108 /* Devmap devices */932 /* devmap devices */ 1109 933 1110 934 node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle) … … 1143 967 } 1144 968 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 1162 969 /** @} 1163 970 */
Note:
See TracChangeset
for help on using the changeset viewer.