Changeset 692c40cb in mainline
- Timestamp:
- 2010-05-28T09:04:37Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5159ae9
- Parents:
- c9f3b45c
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/devman.c
rc9f3b45c r692c40cb 180 180 } 181 181 182 int devman_add_device_to_class(device_handle_t dev_handle, const char *class_name) 183 { 184 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING); 185 186 if (phone < 0) 187 return phone; 188 189 async_serialize_start(); 190 ipc_call_t answer; 191 aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, dev_handle, &answer); 192 193 ipcarg_t retval = async_data_write_start(phone, class_name, str_size(class_name)); 194 if (retval != EOK) { 195 async_wait_for(req, NULL); 196 async_serialize_end(); 197 return retval; 198 } 199 200 async_wait_for(req, &retval); 201 async_serialize_end(); 202 203 return retval; 204 } 205 182 206 void devman_hangup_phone(devman_interface_t iface) 183 207 { -
uspace/lib/c/include/devman.h
rc9f3b45c r692c40cb 53 53 int devman_device_get_handle(const char *pathname, device_handle_t *handle, unsigned int flags); 54 54 55 int devman_add_device_to_class(device_handle_t dev_handle, const char *class_name); 55 56 56 57 #endif -
uspace/lib/c/include/ipc/devman.h
rc9f3b45c r692c40cb 129 129 DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD, 130 130 DEVMAN_ADD_CHILD_DEVICE, 131 DEVMAN_ADD_MATCH_ID 131 DEVMAN_ADD_MATCH_ID, 132 DEVMAN_ADD_DEVICE_TO_CLASS 132 133 133 134 } driver_to_devman_t; -
uspace/lib/drv/generic/driver.c
rc9f3b45c r692c40cb 49 49 #include <errno.h> 50 50 51 #include <devman.h>52 #include <ipc/devman.h>53 51 #include <ipc/driver.h> 54 52 -
uspace/lib/drv/include/driver.h
rc9f3b45c r692c40cb 38 38 #include <adt/list.h> 39 39 #include <ipc/ipc.h> 40 #include <devman.h> 40 41 #include <ipc/devman.h> 41 42 #include <ipc/dev_iface.h> … … 286 287 } 287 288 289 static inline int add_device_to_class(device_t *dev, const char *class_name) 290 { 291 return devman_add_device_to_class(dev->handle, class_name); 292 } 293 288 294 #endif 289 295 -
uspace/srv/devman/devman.c
rc9f3b45c r692c40cb 807 807 */ 808 808 dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name) 809 { 809 { 810 810 dev_class_info_t *info = create_dev_class_info(); 811 info->dev_class = cl; 812 info->dev = dev; 813 814 // add the device to the class 815 fibril_mutex_lock(&cl->mutex); 816 list_append(&info->link, &cl->devices); 817 fibril_mutex_unlock(&cl->mutex); 818 819 // add the class to the device 820 list_append(&info->dev_classes, &dev->classes); 821 822 // create unique name for the device within the class 823 info->dev_name = create_dev_name_for_class(cl, base_dev_name); 811 if (NULL != info) { 812 info->dev_class = cl; 813 info->dev = dev; 814 815 // add the device to the class 816 fibril_mutex_lock(&cl->mutex); 817 list_append(&info->link, &cl->devices); 818 fibril_mutex_unlock(&cl->mutex); 819 820 // add the class to the device 821 list_append(&info->dev_classes, &dev->classes); 822 823 // create unique name for the device within the class 824 info->dev_name = create_dev_name_for_class(cl, base_dev_name); 825 } 824 826 825 827 return info; 826 828 } 827 829 830 dev_class_t * get_dev_class(class_list_t *class_list, char *class_name) 831 { 832 dev_class_t *cl; 833 fibril_mutex_lock(&class_list->classes_mutex); 834 cl = find_dev_class_no_lock(class_list, class_name); 835 if (NULL == cl) { 836 cl = create_dev_class(); 837 if (NULL != cl) { 838 cl->name = class_name; 839 cl->base_dev_name = ""; 840 add_dev_class_no_lock(class_list, cl); 841 } 842 } 843 fibril_mutex_unlock(&class_list->classes_mutex); 844 return cl; 845 } 846 847 dev_class_t * find_dev_class_no_lock(class_list_t *class_list, const char *class_name) 848 { 849 dev_class_t *cl; 850 link_t *link = class_list->classes.next; 851 while (link != &class_list->classes) { 852 cl = list_get_instance(link, dev_class_t, link); 853 if (0 == str_cmp(cl->name, class_name)) { 854 return cl; 855 } 856 } 857 858 return NULL; 859 } 860 828 861 /** @} 829 862 */ -
uspace/srv/devman/devman.h
rc9f3b45c r692c40cb 158 158 link_t link; 159 159 /** List of dev_class_info structures - one for each device registered by this class.*/ 160 link_t devices; 161 /** Default base name for the device within the class, might be overrided by the driver.*/ 160 link_t devices; 161 /** Default base name for the device within the class, might be overrided by the driver.*/ 162 162 const char *base_dev_name; 163 /** Unique numerical identifier appened to the base nameof the newly added device.*/163 /** Unique numerical identifier of the newly added device.*/ 164 164 size_t curr_dev_idx; 165 165 /** Synchronize access to the list of devices in this class. */ … … 185 185 } dev_class_info_t; 186 186 187 /** The list of device classes. */ 188 typedef struct class_list { 189 /** List of classes */ 190 link_t classes; 191 /** Fibril mutex for list of classes. */ 192 fibril_mutex_t classes_mutex; 193 } class_list_t; 194 187 195 // Match ids and scores 188 196 … … 282 290 { 283 291 node_t *res = malloc(sizeof(node_t)); 292 284 293 if (res != NULL) { 285 294 memset(res, 0, sizeof(node_t)); 295 list_initialize(&res->children); 296 list_initialize(&res->match_ids.ids); 297 list_initialize(&res->classes); 286 298 } 287 288 list_initialize(&res->children);289 list_initialize(&res->match_ids.ids);290 299 291 300 return res; … … 364 373 if (NULL != cl) { 365 374 memset(cl, 0, sizeof(dev_class_t)); 375 list_initialize(&cl->devices); 366 376 fibril_mutex_initialize(&cl->mutex); 367 377 } … … 394 404 dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name); 395 405 406 static inline void init_class_list(class_list_t *class_list) 407 { 408 list_initialize(&class_list->classes); 409 fibril_mutex_initialize(&class_list->classes_mutex); 410 } 411 412 dev_class_t * get_dev_class(class_list_t *class_list, char *class_name); 413 dev_class_t * find_dev_class_no_lock(class_list_t *class_list, const char *class_name); 414 415 static inline void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl) 416 { 417 list_append(&cl->link, &class_list->classes); 418 } 419 396 420 #endif 397 421 -
uspace/srv/devman/main.c
rc9f3b45c r692c40cb 60 60 static driver_list_t drivers_list; 61 61 static dev_tree_t device_tree; 62 static class_list_t class_list; 62 63 63 64 … … 240 241 // try to find suitable driver and assign it to the device 241 242 assign_driver(node, &drivers_list); 243 } 244 245 static void devman_add_device_to_class(ipc_callid_t callid, ipc_call_t *call) 246 { 247 device_handle_t handle = IPC_GET_ARG1(*call); 248 249 // Get class name 250 char *class_name; 251 int rc = async_data_write_accept((void **)&class_name, true, 0, 0, 0, 0); 252 if (rc != EOK) { 253 ipc_answer_0(callid, rc); 254 return; 255 } 256 257 node_t *dev = find_dev_node(&device_tree, handle); 258 if (NULL == dev) { 259 ipc_answer_0(callid, ENOENT); 260 return; 261 } 262 263 dev_class_t *cl = get_dev_class(&class_list, class_name); 264 265 dev_class_info_t *class_info = add_device_to_class(dev, cl, NULL); 266 267 // TODO register the device's class alias by devmapper 268 269 printf(NAME ": device '%s' added to class '%s', class name '%s' was asigned to it\n", dev->pathname, class_name, class_info->dev_name); 270 271 ipc_answer_0(callid, EOK); 242 272 } 243 273 … … 294 324 case DEVMAN_ADD_CHILD_DEVICE: 295 325 devman_add_child(callid, &call); 326 break; 327 case DEVMAN_ADD_DEVICE_TO_CLASS: 328 devman_add_device_to_class(callid, &call); 296 329 break; 297 330 default: … … 444 477 } 445 478 479 init_class_list(&class_list); 480 446 481 return true; 447 482 } -
uspace/srv/drivers/ns8250/ns8250.c
rc9f3b45c r692c40cb 760 760 dev->class = &ns8250_dev_class; 761 761 762 add_device_to_class(dev, "serial"); 763 762 764 printf(NAME ": the %s device has been successfully initialized.\n", dev->name); 763 765
Note:
See TracChangeset
for help on using the changeset viewer.