Changeset 903bac0a in mainline for uspace/srv/devman/main.c
- Timestamp:
- 2011-08-19T09:00:38Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e2ab36f1
- Parents:
- d894fbd (diff), 42a619b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
rd894fbd r903bac0a 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" … … 64 64 static driver_list_t drivers_list; 65 65 static dev_tree_t device_tree; 66 static class_list_t class_list;67 66 68 67 /** Register running driver. */ … … 279 278 return; 280 279 } 281 280 282 281 fun_node_t *fun = create_fun_node(); 282 fun->ftype = ftype; 283 283 284 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { 284 285 fibril_rwlock_write_unlock(&tree->rwlock); … … 326 327 } 327 328 } else { 328 devmap_register_tree_function(fun, tree);329 loc_register_tree_function(fun, tree); 329 330 } 330 331 … … 333 334 } 334 335 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) 343 return; 344 345 /* 346 * Register the device by the device mapper and remember its devmap 347 * handle. 348 */ 349 devmap_device_register_with_iface(devmap_pathname, 350 &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 351 352 /* 353 * Add device to the hash map of class devices registered by device 354 * mapper. 355 */ 356 class_add_devmap_function(&class_list, cli); 357 358 free(devmap_pathname); 359 } 360 361 static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call) 336 static void devman_add_function_to_cat(ipc_callid_t callid, ipc_call_t *call) 362 337 { 363 338 devman_handle_t handle = IPC_GET_ARG1(*call); 364 365 /* Get class name. */ 366 char *class_name; 367 int rc = async_data_write_accept((void **) &class_name, true, 339 category_id_t cat_id; 340 int rc; 341 342 /* Get category name. */ 343 char *cat_name; 344 rc = async_data_write_accept((void **) &cat_name, true, 368 345 0, 0, 0, 0); 369 346 if (rc != EOK) { … … 378 355 } 379 356 380 dev_class_t *cl = get_dev_class(&class_list, class_name); 381 dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL); 382 383 /* Register the device's class alias by devmapper. */ 384 devmap_register_class_dev(class_info); 385 386 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.", 387 fun->pathname, class_name, class_info->dev_name); 388 357 rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING); 358 if (rc == EOK) { 359 loc_service_add_to_cat(fun->service_id, cat_id); 360 } else { 361 log_msg(LVL_ERROR, "Failed adding function `%s' to category " 362 "`%s'.", fun->pathname, cat_name); 363 } 364 365 log_msg(LVL_NOTE, "Function `%s' added to category `%s'.", 366 fun->pathname, cat_name); 367 368 async_answer_0(callid, EOK); 369 } 370 371 /** Remove function. */ 372 static void devman_remove_function(ipc_callid_t callid, ipc_call_t *call) 373 { 374 devman_handle_t fun_handle = IPC_GET_ARG1(*call); 375 dev_tree_t *tree = &device_tree; 376 int rc; 377 378 fibril_rwlock_write_lock(&tree->rwlock); 379 380 fun_node_t *fun = find_fun_node_no_lock(&device_tree, fun_handle); 381 if (fun == NULL) { 382 fibril_rwlock_write_unlock(&tree->rwlock); 383 async_answer_0(callid, ENOENT); 384 return; 385 } 386 387 log_msg(LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname); 388 389 if (fun->ftype == fun_inner) { 390 /* Handle possible descendants */ 391 /* TODO */ 392 log_msg(LVL_WARN, "devman_remove_function(): not handling " 393 "descendants\n"); 394 } else { 395 /* Unregister from location service */ 396 rc = loc_service_unregister(fun->service_id); 397 if (rc != EOK) { 398 log_msg(LVL_ERROR, "Failed unregistering tree service."); 399 fibril_rwlock_write_unlock(&tree->rwlock); 400 async_answer_0(callid, EIO); 401 return; 402 } 403 } 404 405 remove_fun_node(&device_tree, fun); 406 fibril_rwlock_write_unlock(&tree->rwlock); 407 delete_fun_node(fun); 408 409 log_msg(LVL_DEBUG, "devman_remove_function() succeeded."); 389 410 async_answer_0(callid, EOK); 390 411 } … … 439 460 devman_add_function(callid, &call); 440 461 break; 441 case DEVMAN_ADD_DEVICE_TO_CLASS: 442 devman_add_function_to_class(callid, &call); 462 case DEVMAN_ADD_DEVICE_TO_CATEGORY: 463 devman_add_function_to_cat(callid, &call); 464 break; 465 case DEVMAN_REMOVE_FUNCTION: 466 devman_remove_function(callid, &call); 443 467 break; 444 468 default: … … 464 488 465 489 free(pathname); 466 467 if (fun == NULL) {468 async_answer_0(iid, ENOENT);469 return;470 }471 472 async_answer_1(iid, EOK, fun->handle);473 }474 475 /** Find handle for the device instance identified by device class name. */476 static void devman_function_get_handle_by_class(ipc_callid_t iid,477 ipc_call_t *icall)478 {479 char *classname;480 char *devname;481 482 int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);483 if (rc != EOK) {484 async_answer_0(iid, rc);485 return;486 }487 rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);488 if (rc != EOK) {489 free(classname);490 async_answer_0(iid, rc);491 return;492 }493 494 495 fun_node_t *fun = find_fun_node_by_class(&class_list,496 classname, devname);497 498 free(classname);499 free(devname);500 490 501 491 if (fun == NULL) { … … 544 534 } 545 535 536 /** Find handle for the function instance identified by its service ID. */ 537 static void devman_fun_sid_to_handle(ipc_callid_t iid, ipc_call_t *icall) 538 { 539 fun_node_t *fun; 540 541 fun = find_loc_tree_function(&device_tree, IPC_GET_ARG1(*icall)); 542 543 if (fun == NULL) { 544 async_answer_0(iid, ENOENT); 545 return; 546 } 547 548 async_answer_1(iid, EOK, fun->handle); 549 } 546 550 547 551 /** Function for handling connections from a client to the device manager. */ … … 562 566 devman_function_get_handle(callid, &call); 563 567 break; 564 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:565 devman_function_get_handle_by_class(callid, &call);566 break;567 568 case DEVMAN_DEVICE_GET_DEVICE_PATH: 568 569 devman_get_device_path_by_handle(callid, &call); 570 break; 571 case DEVMAN_FUN_SID_TO_HANDLE: 572 devman_fun_sid_to_handle(callid, &call); 569 573 break; 570 574 default: … … 659 663 } 660 664 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);665 /** Function for handling connections from a client forwarded by the location 666 * service to the device manager. */ 667 static void devman_connection_loc(ipc_callid_t iid, ipc_call_t *icall) 668 { 669 service_id_t service_id = IPC_GET_ARG2(*icall); 666 670 fun_node_t *fun; 667 671 dev_node_t *dev; 668 672 669 fun = find_devmap_tree_function(&device_tree, devmap_handle); 670 if (fun == NULL) 671 fun = find_devmap_class_function(&class_list, devmap_handle); 673 fun = find_loc_tree_function(&device_tree, service_id); 672 674 673 675 if (fun == NULL || fun->dev->drv == NULL) { 676 log_msg(LVL_WARN, "devman_connection_loc(): function " 677 "not found.\n"); 674 678 async_answer_0(iid, ENOENT); 675 679 return; … … 677 681 678 682 dev = fun->dev; 679 680 if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) {681 async_answer_0(iid, EINVAL);682 return;683 }684 683 685 684 async_exch_t *exch = async_exchange_begin(dev->drv->sess); … … 689 688 690 689 log_msg(LVL_DEBUG, 691 "Forwarding devmapperrequest for `%s' function to driver `%s'.",690 "Forwarding loc service request for `%s' function to driver `%s'.", 692 691 fun->pathname, dev->drv->name); 693 692 } … … 708 707 devman_forward(iid, icall, false); 709 708 break; 710 case DEVMAN_CONNECT_FROM_ DEVMAP:711 /* Someone connected through devmapnode. */712 devman_connection_ devmapper(iid, icall);709 case DEVMAN_CONNECT_FROM_LOC: 710 /* Someone connected through loc node. */ 711 devman_connection_loc(iid, icall); 713 712 break; 714 713 case DEVMAN_CONNECT_TO_PARENTS_DEVICE: … … 743 742 } 744 743 745 init_class_list(&class_list);746 747 744 /* 748 * !!! devman_connection ... as the device manager is not a real devmap745 * !!! devman_connection ... as the device manager is not a real loc 749 746 * 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.747 * loc driver) forwarding a connection from client to the devman by 748 * location service would not work. 752 749 */ 753 devmap_driver_register(NAME, devman_connection);750 loc_server_register(NAME, devman_connection); 754 751 755 752 return true; … … 760 757 printf(NAME ": HelenOS Device Manager\n"); 761 758 762 if (log_init(NAME, LVL_ ERROR) != EOK) {759 if (log_init(NAME, LVL_WARN) != EOK) { 763 760 printf(NAME ": Error initializing logging subsystem.\n"); 764 761 return -1;
Note:
See TracChangeset
for help on using the changeset viewer.