Changeset 15f3c3f in mainline for uspace/srv/devman
- Timestamp:
- 2011-06-22T22:00:52Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 86ffa27f
- Parents:
- ef09a7a
- Location:
- uspace/srv/devman
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
ref09a7a r15f3c3f 37 37 #include <ipc/driver.h> 38 38 #include <ipc/devman.h> 39 #include < devmap.h>39 #include <loc.h> 40 40 #include <str_error.h> 41 41 #include <stdio.h> … … 66 66 } 67 67 68 static int devmap_functions_compare(unsigned long key[], hash_count_t keys,68 static int loc_functions_compare(unsigned long key[], hash_count_t keys, 69 69 link_t *item) 70 70 { 71 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devmap_fun);72 return (fun-> devmap_handle == (devmap_handle_t) key[0]);73 } 74 75 static int devmap_devices_class_compare(unsigned long key[], hash_count_t keys,71 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun); 72 return (fun->service_id == (service_id_t) key[0]); 73 } 74 75 static int loc_devices_class_compare(unsigned long key[], hash_count_t keys, 76 76 link_t *item) 77 77 { 78 78 dev_class_info_t *class_info 79 = hash_table_get_instance(item, dev_class_info_t, devmap_link);79 = hash_table_get_instance(item, dev_class_info_t, loc_link); 80 80 assert(class_info != NULL); 81 81 82 return (class_info-> devmap_handle == (devmap_handle_t) key[0]);82 return (class_info->service_id == (service_id_t) key[0]); 83 83 } 84 84 … … 99 99 }; 100 100 101 static hash_table_operations_t devmap_devices_ops = {101 static hash_table_operations_t loc_devices_ops = { 102 102 .hash = devices_hash, 103 .compare = devmap_functions_compare,103 .compare = loc_functions_compare, 104 104 .remove_callback = devices_remove_callback 105 105 }; 106 106 107 static hash_table_operations_t devmap_devices_class_ops = {107 static hash_table_operations_t loc_devices_class_ops = { 108 108 .hash = devices_hash, 109 .compare = devmap_devices_class_compare,109 .compare = loc_devices_class_compare, 110 110 .remove_callback = devices_remove_callback 111 111 }; … … 700 700 } 701 701 702 /** Create devmappath and name for the function. */703 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)704 { 705 char * devmap_pathname = NULL;706 char * devmap_name = NULL;707 708 asprintf(& devmap_name, "%s", fun->pathname);709 if ( devmap_name == NULL)702 /** Create loc path and name for the function. */ 703 void loc_register_tree_function(fun_node_t *fun, dev_tree_t *tree) 704 { 705 char *loc_pathname = NULL; 706 char *loc_name = NULL; 707 708 asprintf(&loc_name, "%s", fun->pathname); 709 if (loc_name == NULL) 710 710 return; 711 711 712 replace_char( devmap_name, '/', DEVMAP_SEPARATOR);713 714 asprintf(& devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE,715 devmap_name);716 if ( devmap_pathname == NULL) {717 free( devmap_name);712 replace_char(loc_name, '/', LOC_SEPARATOR); 713 714 asprintf(&loc_pathname, "%s/%s", LOC_DEVICE_NAMESPACE, 715 loc_name); 716 if (loc_pathname == NULL) { 717 free(loc_name); 718 718 return; 719 719 } 720 720 721 devmap_device_register_with_iface(devmap_pathname,722 &fun-> devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);723 724 tree_add_ devmap_function(tree, fun);725 726 free( devmap_name);727 free( devmap_pathname);721 loc_service_register_with_iface(loc_pathname, 722 &fun->service_id, DEVMAN_CONNECT_FROM_LOC); 723 724 tree_add_loc_function(tree, fun); 725 726 free(loc_name); 727 free(loc_pathname); 728 728 } 729 729 … … 855 855 hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1, 856 856 &devman_functions_ops); 857 hash_table_create(&tree-> devmap_functions, DEVICE_BUCKETS, 1,858 & devmap_devices_ops);857 hash_table_create(&tree->loc_functions, DEVICE_BUCKETS, 1, 858 &loc_devices_ops); 859 859 860 860 fibril_rwlock_initialize(&tree->rwlock); … … 951 951 list_initialize(&res->classes); 952 952 link_initialize(&res->devman_fun); 953 link_initialize(&res-> devmap_fun);953 link_initialize(&res->loc_fun); 954 954 } 955 955 … … 1267 1267 memset(info, 0, sizeof(dev_class_info_t)); 1268 1268 link_initialize(&info->dev_classes); 1269 link_initialize(&info-> devmap_link);1269 link_initialize(&info->loc_link); 1270 1270 link_initialize(&info->link); 1271 1271 } … … 1413 1413 list_initialize(&class_list->classes); 1414 1414 fibril_rwlock_initialize(&class_list->rwlock); 1415 hash_table_create(&class_list-> devmap_functions, DEVICE_BUCKETS, 1,1416 & devmap_devices_class_ops);1417 } 1418 1419 1420 /* Devmapdevices */1421 1422 fun_node_t *find_ devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)1415 hash_table_create(&class_list->loc_functions, DEVICE_BUCKETS, 1, 1416 &loc_devices_class_ops); 1417 } 1418 1419 1420 /* loc devices */ 1421 1422 fun_node_t *find_loc_tree_function(dev_tree_t *tree, service_id_t service_id) 1423 1423 { 1424 1424 fun_node_t *fun = NULL; 1425 1425 link_t *link; 1426 unsigned long key = (unsigned long) devmap_handle;1426 unsigned long key = (unsigned long) service_id; 1427 1427 1428 1428 fibril_rwlock_read_lock(&tree->rwlock); 1429 link = hash_table_find(&tree-> devmap_functions, &key);1429 link = hash_table_find(&tree->loc_functions, &key); 1430 1430 if (link != NULL) 1431 fun = hash_table_get_instance(link, fun_node_t, devmap_fun);1431 fun = hash_table_get_instance(link, fun_node_t, loc_fun); 1432 1432 fibril_rwlock_read_unlock(&tree->rwlock); 1433 1433 … … 1435 1435 } 1436 1436 1437 fun_node_t *find_ devmap_class_function(class_list_t *classes,1438 devmap_handle_t devmap_handle)1437 fun_node_t *find_loc_class_function(class_list_t *classes, 1438 service_id_t service_id) 1439 1439 { 1440 1440 fun_node_t *fun = NULL; 1441 1441 dev_class_info_t *cli; 1442 1442 link_t *link; 1443 unsigned long key = (unsigned long) devmap_handle;1443 unsigned long key = (unsigned long)service_id; 1444 1444 1445 1445 fibril_rwlock_read_lock(&classes->rwlock); 1446 link = hash_table_find(&classes-> devmap_functions, &key);1446 link = hash_table_find(&classes->loc_functions, &key); 1447 1447 if (link != NULL) { 1448 1448 cli = hash_table_get_instance(link, dev_class_info_t, 1449 devmap_link);1449 loc_link); 1450 1450 fun = cli->fun; 1451 1451 } … … 1455 1455 } 1456 1456 1457 void class_add_ devmap_function(class_list_t *class_list, dev_class_info_t *cli)1458 { 1459 unsigned long key = (unsigned long) cli-> devmap_handle;1457 void class_add_loc_function(class_list_t *class_list, dev_class_info_t *cli) 1458 { 1459 unsigned long key = (unsigned long) cli->service_id; 1460 1460 1461 1461 fibril_rwlock_write_lock(&class_list->rwlock); 1462 hash_table_insert(&class_list-> devmap_functions, &key, &cli->devmap_link);1462 hash_table_insert(&class_list->loc_functions, &key, &cli->loc_link); 1463 1463 fibril_rwlock_write_unlock(&class_list->rwlock); 1464 1464 1465 assert(find_ devmap_class_function(class_list, cli->devmap_handle) != NULL);1466 } 1467 1468 void tree_add_ devmap_function(dev_tree_t *tree, fun_node_t *fun)1469 { 1470 unsigned long key = (unsigned long) fun-> devmap_handle;1465 assert(find_loc_class_function(class_list, cli->service_id) != NULL); 1466 } 1467 1468 void tree_add_loc_function(dev_tree_t *tree, fun_node_t *fun) 1469 { 1470 unsigned long key = (unsigned long) fun->service_id; 1471 1471 fibril_rwlock_write_lock(&tree->rwlock); 1472 hash_table_insert(&tree-> devmap_functions, &key, &fun->devmap_fun);1472 hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun); 1473 1473 fibril_rwlock_write_unlock(&tree->rwlock); 1474 1474 } -
uspace/srv/devman/devman.h
ref09a7a r15f3c3f 41 41 #include <adt/hash_table.h> 42 42 #include <ipc/devman.h> 43 #include <ipc/ devmap.h>43 #include <ipc/loc.h> 44 44 #include <fibril_synch.h> 45 45 #include <atomic.h> … … 53 53 #define DEVICE_BUCKETS 256 54 54 55 #define DEVMAP_CLASS_NAMESPACE "class"56 #define DEVMAP_DEVICE_NAMESPACE "devices"57 #define DEVMAP_SEPARATOR '\\'55 #define LOC_CLASS_NAMESPACE "class" 56 #define LOC_DEVICE_NAMESPACE "devices" 57 #define LOC_SEPARATOR '\\' 58 58 59 59 struct dev_node; … … 172 172 /** List of device classes to which this device function belongs. */ 173 173 list_t classes; 174 /** Devmap handle if the device function is registered by devmap. */175 devmap_handle_t devmap_handle;174 /** Service ID if the device function is registered with loc. */ 175 service_id_t service_id; 176 176 177 177 /** … … 181 181 182 182 /** 183 * Used by the hash table of functions indexed by devmap device handles.184 */ 185 link_t devmap_fun;183 * Used by the hash table of functions indexed by service IDs. 184 */ 185 link_t loc_fun; 186 186 }; 187 187 … … 208 208 209 209 /** 210 * Hash table of devices registered by devmapper, indexed by devmap211 * handles.212 */ 213 hash_table_t devmap_functions;210 * Hash table of services registered with location service, indexed by 211 * service IDs. 212 */ 213 hash_table_t loc_functions; 214 214 } dev_tree_t; 215 215 … … 267 267 /** The name of the device function within the class. */ 268 268 char *dev_name; 269 /** The handle of the device by device mapperin the class namespace. */270 devmap_handle_t devmap_handle;271 272 /** 273 * Link in the hash table of devices registered by the devmapperusing269 /** Service ID in the class namespace. */ 270 service_id_t service_id; 271 272 /** 273 * Link to hash table of services registered with location service using 274 274 * their class names. 275 275 */ 276 link_t devmap_link;276 link_t loc_link; 277 277 } dev_class_info_t; 278 278 … … 283 283 284 284 /** 285 * Hash table of devices registered by devmapper using their class name,286 * indexed by devmap handles.287 */ 288 hash_table_t devmap_functions;285 * Hash table of services registered with location service using their 286 * class name, indexed by service IDs. 287 */ 288 hash_table_t loc_functions; 289 289 290 290 /** Fibril mutex for list of classes. */ … … 364 364 extern void add_dev_class_no_lock(class_list_t *, dev_class_t *); 365 365 366 /* Devmap devices */367 368 extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *);369 370 extern fun_node_t *find_ devmap_tree_function(dev_tree_t *, devmap_handle_t);371 extern fun_node_t *find_ devmap_class_function(class_list_t *, devmap_handle_t);372 373 extern void class_add_ devmap_function(class_list_t *, dev_class_info_t *);374 extern void tree_add_ devmap_function(dev_tree_t *, fun_node_t *);366 /* Loc services */ 367 368 extern void loc_register_tree_function(fun_node_t *, dev_tree_t *); 369 370 extern fun_node_t *find_loc_tree_function(dev_tree_t *, service_id_t); 371 extern fun_node_t *find_loc_class_function(class_list_t *, service_id_t); 372 373 extern void class_add_loc_function(class_list_t *, dev_class_info_t *); 374 extern void tree_add_loc_function(dev_tree_t *, fun_node_t *); 375 375 376 376 #endif -
uspace/srv/devman/main.c
ref09a7a r15f3c3f 56 56 #include <ipc/driver.h> 57 57 #include <thread.h> 58 #include < devmap.h>58 #include <loc.h> 59 59 60 60 #include "devman.h" … … 326 326 } 327 327 } else { 328 devmap_register_tree_function(fun, tree);328 loc_register_tree_function(fun, tree); 329 329 } 330 330 … … 333 333 } 334 334 335 static void devmap_register_class_dev(dev_class_info_t *cli)336 { 337 /* Create devmap path and name for the device. */338 char * devmap_pathname = NULL;339 340 asprintf(& devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,341 cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);342 if ( devmap_pathname == NULL)335 static void loc_register_class_dev(dev_class_info_t *cli) 336 { 337 /* Create loc path and name for the service. */ 338 char *loc_pathname = NULL; 339 340 asprintf(&loc_pathname, "%s/%s%c%s", LOC_CLASS_NAMESPACE, 341 cli->dev_class->name, LOC_SEPARATOR, cli->dev_name); 342 if (loc_pathname == NULL) 343 343 return; 344 344 345 345 /* 346 * Register the device by the device mapper and remember its devmap347 * handle.346 * Register the device with location service and remember its 347 * service ID. 348 348 */ 349 devmap_device_register_with_iface(devmap_pathname,350 &cli-> devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);349 loc_service_register_with_iface(loc_pathname, 350 &cli->service_id, DEVMAN_CONNECT_FROM_LOC); 351 351 352 352 /* 353 * Add device to the hash map of class devices registered by device354 * mapper.353 * Add device to the hash map of class devices registered with 354 * location service. 355 355 */ 356 class_add_ devmap_function(&class_list, cli);357 358 free( devmap_pathname);356 class_add_loc_function(&class_list, cli); 357 358 free(loc_pathname); 359 359 } 360 360 … … 381 381 dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL); 382 382 383 /* Register the device's class alias by devmapper. */384 devmap_register_class_dev(class_info);383 /* Register the device's class alias with location service. */ 384 loc_register_class_dev(class_info); 385 385 386 386 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.", … … 659 659 } 660 660 661 /** Function for handling connections from a client forwarded by the device662 * mapperto the device manager. */663 static void devman_connection_ devmapper(ipc_callid_t iid, ipc_call_t *icall)664 { 665 devmap_handle_t devmap_handle= IPC_GET_ARG2(*icall);661 /** Function for handling connections from a client forwarded by the location 662 * service to the device manager. */ 663 static void devman_connection_loc(ipc_callid_t iid, ipc_call_t *icall) 664 { 665 service_id_t service_id = IPC_GET_ARG2(*icall); 666 666 fun_node_t *fun; 667 667 dev_node_t *dev; 668 668 669 fun = find_ devmap_tree_function(&device_tree, devmap_handle);669 fun = find_loc_tree_function(&device_tree, service_id); 670 670 if (fun == NULL) 671 fun = find_ devmap_class_function(&class_list, devmap_handle);671 fun = find_loc_class_function(&class_list, service_id); 672 672 673 673 if (fun == NULL || fun->dev->drv == NULL) { … … 689 689 690 690 log_msg(LVL_DEBUG, 691 "Forwarding devmapperrequest for `%s' function to driver `%s'.",691 "Forwarding loc service request for `%s' function to driver `%s'.", 692 692 fun->pathname, dev->drv->name); 693 693 } … … 708 708 devman_forward(iid, icall, false); 709 709 break; 710 case DEVMAN_CONNECT_FROM_ DEVMAP:711 /* Someone connected through devmapnode. */712 devman_connection_ devmapper(iid, icall);710 case DEVMAN_CONNECT_FROM_LOC: 711 /* Someone connected through loc node. */ 712 devman_connection_loc(iid, icall); 713 713 break; 714 714 case DEVMAN_CONNECT_TO_PARENTS_DEVICE: … … 746 746 747 747 /* 748 * !!! devman_connection ... as the device manager is not a real devmap748 * !!! devman_connection ... as the device manager is not a real loc 749 749 * driver (it uses a completely different ipc protocol than an ordinary 750 * devmapdriver) forwarding a connection from client to the devman by751 * devmapperwould not work.750 * loc driver) forwarding a connection from client to the devman by 751 * location service would not work. 752 752 */ 753 devmap_driver_register(NAME, devman_connection);753 loc_server_register(NAME, devman_connection); 754 754 755 755 return true;
Note:
See TracChangeset
for help on using the changeset viewer.