Changes in uspace/srv/devman/main.c [3ad7b1c:c6c389ed] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r3ad7b1c rc6c389ed 36 36 */ 37 37 38 #include <inttypes.h>39 38 #include <assert.h> 40 39 #include <ipc/services.h> … … 43 42 #include <stdio.h> 44 43 #include <errno.h> 45 #include <str_error.h>46 44 #include <bool.h> 47 45 #include <fibril_synch.h> … … 52 50 #include <sys/stat.h> 53 51 #include <ctype.h> 54 #include <io/log.h>55 52 #include <ipc/devman.h> 56 53 #include <ipc/driver.h> … … 73 70 driver_t *driver = NULL; 74 71 75 log_msg(LVL_DEBUG, "devman_driver_register");72 printf(NAME ": devman_driver_register \n"); 76 73 77 74 iid = async_get_call(&icall); 78 if (IPC_GET_ IMETHOD(icall) != DEVMAN_DRIVER_REGISTER) {79 async_answer_0(iid, EREFUSED);75 if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) { 76 ipc_answer_0(iid, EREFUSED); 80 77 return NULL; 81 78 } … … 86 83 int rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0); 87 84 if (rc != EOK) { 88 async_answer_0(iid, rc);85 ipc_answer_0(iid, rc); 89 86 return NULL; 90 87 } 91 88 92 log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",89 printf(NAME ": the %s driver is trying to register by the service.\n", 93 90 drv_name); 94 91 95 92 /* Find driver structure. */ 96 93 driver = find_driver(&drivers_list, drv_name); 94 97 95 if (driver == NULL) { 98 log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);96 printf(NAME ": no driver named %s was found.\n", drv_name); 99 97 free(drv_name); 100 98 drv_name = NULL; 101 async_answer_0(iid, ENOENT);99 ipc_answer_0(iid, ENOENT); 102 100 return NULL; 103 101 } … … 106 104 drv_name = NULL; 107 105 108 fibril_mutex_lock(&driver->driver_mutex);109 110 if (driver->phone >= 0) {111 /* We already have a connection to the driver. */112 log_msg(LVL_ERROR, "Driver '%s' already started.\n",113 driver->name);114 fibril_mutex_unlock(&driver->driver_mutex);115 async_answer_0(iid, EEXISTS);116 return NULL;117 }118 119 switch (driver->state) {120 case DRIVER_NOT_STARTED:121 /* Somebody started the driver manually. */122 log_msg(LVL_NOTE, "Driver '%s' started manually.\n",123 driver->name);124 driver->state = DRIVER_STARTING;125 break;126 case DRIVER_STARTING:127 /* The expected case */128 break;129 case DRIVER_RUNNING:130 /* Should not happen since we do not have a connected phone */131 assert(false);132 }133 134 106 /* Create connection to the driver. */ 135 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 136 driver->name); 107 printf(NAME ": creating connection to the %s driver.\n", driver->name); 137 108 ipc_call_t call; 138 109 ipc_callid_t callid = async_get_call(&call); 139 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 140 fibril_mutex_unlock(&driver->driver_mutex); 141 async_answer_0(callid, ENOTSUP); 142 async_answer_0(iid, ENOTSUP); 110 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { 111 ipc_answer_0(callid, ENOTSUP); 112 ipc_answer_0(iid, ENOTSUP); 143 113 return NULL; 144 114 } 145 115 146 116 /* Remember driver's phone. */ 147 driver->phone = IPC_GET_ARG5(call); 148 149 fibril_mutex_unlock(&driver->driver_mutex); 150 151 log_msg(LVL_NOTE, 152 "The `%s' driver was successfully registered as running.", 117 set_driver_phone(driver, IPC_GET_ARG5(call)); 118 119 printf(NAME ": the %s driver was successfully registered as running.\n", 153 120 driver->name); 154 121 155 async_answer_0(callid, EOK);156 async_answer_0(iid, EOK);122 ipc_answer_0(callid, EOK); 123 ipc_answer_0(iid, EOK); 157 124 158 125 return driver; … … 173 140 174 141 callid = async_get_call(&call); 175 if (DEVMAN_ADD_MATCH_ID != IPC_GET_ IMETHOD(call)) {176 log_msg(LVL_ERROR,177 " Invalid protocol when trying to receive match id.");178 async_answer_0(callid, EINVAL);142 if (DEVMAN_ADD_MATCH_ID != IPC_GET_METHOD(call)) { 143 printf(NAME ": ERROR: devman_receive_match_id - invalid " 144 "protocol.\n"); 145 ipc_answer_0(callid, EINVAL); 179 146 delete_match_id(match_id); 180 147 return EINVAL; … … 182 149 183 150 if (match_id == NULL) { 184 log_msg(LVL_ERROR, "Failed to allocate match id."); 185 async_answer_0(callid, ENOMEM); 151 printf(NAME ": ERROR: devman_receive_match_id - failed to " 152 "allocate match id.\n"); 153 ipc_answer_0(callid, ENOMEM); 186 154 return ENOMEM; 187 155 } 188 156 189 async_answer_0(callid, EOK);157 ipc_answer_0(callid, EOK); 190 158 191 159 match_id->score = IPC_GET_ARG1(call); … … 196 164 if (rc != EOK) { 197 165 delete_match_id(match_id); 198 log_msg(LVL_ERROR, "Failed to receive match id string: %s.",199 str_error(rc));166 printf(NAME ": devman_receive_match_id - failed to receive " 167 "match id string.\n"); 200 168 return rc; 201 169 } … … 203 171 list_append(&match_id->link, &match_ids->ids); 204 172 205 log_msg(LVL_DEBUG, "Received match id `%s', score %d.",173 printf(NAME ": received match id '%s', score = %d \n", 206 174 match_id->id, match_id->score); 207 175 return rc; … … 215 183 * @return Zero on success, negative error code otherwise. 216 184 */ 217 static int devman_receive_match_ids( sysarg_t match_count,185 static int devman_receive_match_ids(ipcarg_t match_count, 218 186 match_id_list_t *match_ids) 219 187 { … … 228 196 } 229 197 230 static int assign_driver_fibril(void *arg) 231 { 232 dev_node_t *dev_node = (dev_node_t *) arg; 233 assign_driver(dev_node, &drivers_list, &device_tree); 234 return EOK; 235 } 236 237 /** Handle function registration. 198 /** Handle child device registration. 238 199 * 239 200 * Child devices are registered by their parent's device driver. 240 201 */ 241 static void devman_add_function(ipc_callid_t callid, ipc_call_t *call) 242 { 243 fun_type_t ftype = (fun_type_t) IPC_GET_ARG1(*call); 244 devman_handle_t dev_handle = IPC_GET_ARG2(*call); 245 sysarg_t match_count = IPC_GET_ARG3(*call); 202 static void devman_add_child(ipc_callid_t callid, ipc_call_t *call) 203 { 204 device_handle_t parent_handle = IPC_GET_ARG1(*call); 205 ipcarg_t match_count = IPC_GET_ARG2(*call); 246 206 dev_tree_t *tree = &device_tree; 247 207 248 208 fibril_rwlock_write_lock(&tree->rwlock); 249 250 dev_node_t *dev = NULL; 251 dev_node_t *pdev = find_dev_node_no_lock(&device_tree, dev_handle); 252 253 if (pdev == NULL) { 209 node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle); 210 211 if (parent == NULL) { 254 212 fibril_rwlock_write_unlock(&tree->rwlock); 255 async_answer_0(callid, ENOENT); 256 return; 257 } 258 259 if (ftype != fun_inner && ftype != fun_exposed) { 260 /* Unknown function type */ 261 log_msg(LVL_ERROR, 262 "Unknown function type %d provided by driver.", 263 (int) ftype); 264 265 fibril_rwlock_write_unlock(&tree->rwlock); 266 async_answer_0(callid, EINVAL); 267 return; 268 } 269 270 char *fun_name = NULL; 271 int rc = async_data_write_accept((void **)&fun_name, true, 0, 0, 0, 0); 213 ipc_answer_0(callid, ENOENT); 214 return; 215 } 216 217 char *dev_name = NULL; 218 int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0); 272 219 if (rc != EOK) { 273 220 fibril_rwlock_write_unlock(&tree->rwlock); 274 async_answer_0(callid, rc);275 return; 276 } 277 278 /* Check that function with same name is not there already. */279 if ( find_fun_node_in_device(pdev, fun_name) != NULL) {221 ipc_answer_0(callid, rc); 222 return; 223 } 224 225 node_t *node = create_dev_node(); 226 if (!insert_dev_node(&device_tree, node, dev_name, parent)) { 280 227 fibril_rwlock_write_unlock(&tree->rwlock); 281 async_answer_0(callid, EEXISTS); 282 printf(NAME ": Warning, driver tried to register `%s' twice.\n", 283 fun_name); 284 free(fun_name); 285 return; 286 } 287 288 fun_node_t *fun = create_fun_node(); 289 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { 290 fibril_rwlock_write_unlock(&tree->rwlock); 291 delete_fun_node(fun); 292 async_answer_0(callid, ENOMEM); 293 return; 294 } 295 296 if (ftype == fun_inner) { 297 dev = create_dev_node(); 298 if (dev == NULL) { 299 fibril_rwlock_write_unlock(&tree->rwlock); 300 delete_fun_node(fun); 301 async_answer_0(callid, ENOMEM); 302 return; 303 } 304 305 insert_dev_node(tree, dev, fun); 228 delete_dev_node(node); 229 ipc_answer_0(callid, ENOMEM); 230 return; 306 231 } 307 232 308 233 fibril_rwlock_write_unlock(&tree->rwlock); 309 234 310 log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname); 311 312 devman_receive_match_ids(match_count, &fun->match_ids); 313 314 if (ftype == fun_inner) { 315 assert(dev != NULL); 316 /* 317 * Try to find a suitable driver and assign it to the device. We do 318 * not want to block the current fibril that is used for processing 319 * incoming calls: we will launch a separate fibril to handle the 320 * driver assigning. That is because assign_driver can actually include 321 * task spawning which could take some time. 322 */ 323 fid_t assign_fibril = fibril_create(assign_driver_fibril, dev); 324 if (assign_fibril == 0) { 325 /* 326 * Fallback in case we are out of memory. 327 * Probably not needed as we will die soon anyway ;-). 328 */ 329 (void) assign_driver_fibril(fun); 330 } else { 331 fibril_add_ready(assign_fibril); 332 } 333 } else { 334 devmap_register_tree_function(fun, tree); 335 } 235 printf(NAME ": devman_add_child %s\n", node->pathname); 236 237 devman_receive_match_ids(match_count, &node->match_ids); 336 238 337 239 /* Return device handle to parent's driver. */ 338 async_answer_1(callid, EOK, fun->handle); 240 ipc_answer_1(callid, EOK, node->handle); 241 242 /* Try to find suitable driver and assign it to the device. */ 243 assign_driver(node, &drivers_list, &device_tree); 339 244 } 340 245 … … 353 258 * handle. 354 259 */ 355 devmap_device_register_with_iface(devmap_pathname, 356 &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 260 devmap_device_register(devmap_pathname, &cli->devmap_handle); 357 261 358 262 /* … … 360 264 * mapper. 361 265 */ 362 class_add_devmap_ function(&class_list, cli);266 class_add_devmap_device(&class_list, cli); 363 267 364 268 free(devmap_pathname); 365 269 } 366 270 367 static void devman_add_ function_to_class(ipc_callid_t callid, ipc_call_t *call)368 { 369 dev man_handle_t handle = IPC_GET_ARG1(*call);271 static void devman_add_device_to_class(ipc_callid_t callid, ipc_call_t *call) 272 { 273 device_handle_t handle = IPC_GET_ARG1(*call); 370 274 371 275 /* Get class name. */ … … 374 278 0, 0, 0, 0); 375 279 if (rc != EOK) { 376 async_answer_0(callid, rc);280 ipc_answer_0(callid, rc); 377 281 return; 378 282 } 379 283 380 fun_node_t *fun = find_fun_node(&device_tree, handle);381 if ( fun== NULL) {382 async_answer_0(callid, ENOENT);284 node_t *dev = find_dev_node(&device_tree, handle); 285 if (dev == NULL) { 286 ipc_answer_0(callid, ENOENT); 383 287 return; 384 288 } 385 289 386 290 dev_class_t *cl = get_dev_class(&class_list, class_name); 387 dev_class_info_t *class_info = add_ function_to_class(fun, cl, NULL);291 dev_class_info_t *class_info = add_device_to_class(dev, cl, NULL); 388 292 389 293 /* Register the device's class alias by devmapper. */ 390 294 devmap_register_class_dev(class_info); 391 295 392 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",393 fun->pathname, class_name, class_info->dev_name);394 395 async_answer_0(callid, EOK);296 printf(NAME ": device '%s' added to class '%s', class name '%s' was " 297 "asigned to it\n", dev->pathname, class_name, class_info->dev_name); 298 299 ipc_answer_0(callid, EOK); 396 300 } 397 301 … … 406 310 407 311 initialize_running_driver(driver, &device_tree); 408 log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",312 printf(NAME ": the %s driver was successfully initialized. \n", 409 313 driver->name); 410 314 return 0; … … 415 319 { 416 320 /* Accept the connection. */ 417 async_answer_0(iid, EOK);321 ipc_answer_0(iid, EOK); 418 322 419 323 driver_t *driver = devman_driver_register(); … … 428 332 fid_t fid = fibril_create(init_running_drv, driver); 429 333 if (fid == 0) { 430 log_msg(LVL_ERROR, "Failed to create initialization fibril " \431 " for driver `%s'.", driver->name);334 printf(NAME ": Error creating fibril for the initialization of " 335 "the newly registered running driver.\n"); 432 336 return; 433 337 } … … 440 344 callid = async_get_call(&call); 441 345 442 switch (IPC_GET_ IMETHOD(call)) {346 switch (IPC_GET_METHOD(call)) { 443 347 case IPC_M_PHONE_HUNGUP: 444 348 cont = false; 445 349 continue; 446 case DEVMAN_ADD_ FUNCTION:447 devman_add_ function(callid, &call);350 case DEVMAN_ADD_CHILD_DEVICE: 351 devman_add_child(callid, &call); 448 352 break; 449 353 case DEVMAN_ADD_DEVICE_TO_CLASS: 450 devman_add_ function_to_class(callid, &call);354 devman_add_device_to_class(callid, &call); 451 355 break; 452 356 default: 453 async_answer_0(callid, EINVAL);357 ipc_answer_0(callid, EINVAL); 454 358 break; 455 359 } … … 459 363 /** Find handle for the device instance identified by the device's path in the 460 364 * device tree. */ 461 static void devman_ function_get_handle(ipc_callid_t iid, ipc_call_t *icall)365 static void devman_device_get_handle(ipc_callid_t iid, ipc_call_t *icall) 462 366 { 463 367 char *pathname; … … 465 369 int rc = async_data_write_accept((void **) &pathname, true, 0, 0, 0, 0); 466 370 if (rc != EOK) { 467 async_answer_0(iid, rc);468 return; 469 } 470 471 fun_node_t *fun = find_fun_node_by_path(&device_tree, pathname);371 ipc_answer_0(iid, rc); 372 return; 373 } 374 375 node_t * dev = find_dev_node_by_path(&device_tree, pathname); 472 376 473 377 free(pathname); 474 378 475 if (fun == NULL) { 476 async_answer_0(iid, ENOENT); 477 return; 478 } 479 480 async_answer_1(iid, EOK, fun->handle); 481 } 482 483 /** Find handle for the device instance identified by device class name. */ 484 static void devman_function_get_handle_by_class(ipc_callid_t iid, 485 ipc_call_t *icall) 486 { 487 char *classname; 488 char *devname; 489 490 int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0); 491 if (rc != EOK) { 492 async_answer_0(iid, rc); 493 return; 494 } 495 rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0); 496 if (rc != EOK) { 497 free(classname); 498 async_answer_0(iid, rc); 499 return; 500 } 501 502 503 fun_node_t *fun = find_fun_node_by_class(&class_list, 504 classname, devname); 505 506 free(classname); 507 free(devname); 508 509 if (fun == NULL) { 510 async_answer_0(iid, ENOENT); 511 return; 512 } 513 514 async_answer_1(iid, EOK, fun->handle); 379 if (dev == NULL) { 380 ipc_answer_0(iid, ENOENT); 381 return; 382 } 383 384 ipc_answer_1(iid, EOK, dev->handle); 515 385 } 516 386 … … 520 390 { 521 391 /* Accept connection. */ 522 async_answer_0(iid, EOK);392 ipc_answer_0(iid, EOK); 523 393 524 394 bool cont = true; … … 527 397 ipc_callid_t callid = async_get_call(&call); 528 398 529 switch (IPC_GET_ IMETHOD(call)) {399 switch (IPC_GET_METHOD(call)) { 530 400 case IPC_M_PHONE_HUNGUP: 531 401 cont = false; 532 402 continue; 533 403 case DEVMAN_DEVICE_GET_HANDLE: 534 devman_function_get_handle(callid, &call); 535 break; 536 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS: 537 devman_function_get_handle_by_class(callid, &call); 404 devman_device_get_handle(callid, &call); 538 405 break; 539 406 default: 540 async_answer_0(callid, ENOENT); 407 if (!(callid & IPC_CALLID_NOTIFICATION)) 408 ipc_answer_0(callid, ENOENT); 541 409 } 542 410 } … … 546 414 bool drv_to_parent) 547 415 { 548 devman_handle_t handle = IPC_GET_ARG2(*icall); 549 devman_handle_t fwd_h; 550 fun_node_t *fun = NULL; 551 dev_node_t *dev = NULL; 552 553 fun = find_fun_node(&device_tree, handle); 554 if (fun == NULL) 555 dev = find_dev_node(&device_tree, handle); 556 else 557 dev = fun->dev; 558 559 /* 560 * For a valid function to connect to we need a device. The root 561 * function, for example, has no device and cannot be connected to. 562 * This means @c dev needs to be valid regardless whether we are 563 * connecting to a device or to a function. 564 */ 416 device_handle_t handle = IPC_GET_ARG2(*icall); 417 418 node_t *dev = find_dev_node(&device_tree, handle); 565 419 if (dev == NULL) { 566 log_msg(LVL_ERROR, "IPC forwarding failed - no device or " 567 "function with handle %" PRIun " was found.", handle); 568 async_answer_0(iid, ENOENT); 569 return; 570 } 571 572 if (fun == NULL && !drv_to_parent) { 573 log_msg(LVL_ERROR, NAME ": devman_forward error - cannot " 574 "connect to handle %" PRIun ", refers to a device.", 575 handle); 576 async_answer_0(iid, ENOENT); 420 printf(NAME ": devman_forward error - no device with handle %x " 421 "was found.\n", handle); 422 ipc_answer_0(iid, ENOENT); 577 423 return; 578 424 } … … 581 427 582 428 if (drv_to_parent) { 583 /* Connect to parent function of a device (or device function). */ 584 if (dev->pfun->dev != NULL) 585 driver = dev->pfun->dev->drv; 586 fwd_h = dev->pfun->handle; 429 if (dev->parent != NULL) 430 driver = dev->parent->drv; 587 431 } else if (dev->state == DEVICE_USABLE) { 588 /* Connect to the specified function */589 432 driver = dev->drv; 590 433 assert(driver != NULL); 591 592 fwd_h = handle;593 434 } 594 435 595 436 if (driver == NULL) { 596 log_msg(LVL_ERROR, "IPC forwarding refused - " \597 " the device %" PRIun " is not in usable state.", handle);598 async_answer_0(iid, ENOENT);437 printf(NAME ": devman_forward error - the device is not in " 438 "usable state.\n", handle); 439 ipc_answer_0(iid, ENOENT); 599 440 return; 600 441 } … … 606 447 method = DRIVER_CLIENT; 607 448 608 if (driver->phone < 0) { 609 log_msg(LVL_ERROR, 610 "Could not forward to driver `%s' (phone is %d).", 611 driver->name, (int) driver->phone); 612 async_answer_0(iid, EINVAL); 613 return; 614 } 615 616 if (fun != NULL) { 617 log_msg(LVL_DEBUG, 618 "Forwarding request for `%s' function to driver `%s'.", 619 fun->pathname, driver->name); 620 } else { 621 log_msg(LVL_DEBUG, 622 "Forwarding request for `%s' device to driver `%s'.", 623 dev->pfun->pathname, driver->name); 624 } 625 626 async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE); 449 if (driver->phone <= 0) { 450 printf(NAME ": devman_forward: cound not forward to driver %s ", 451 driver->name); 452 printf("the driver's phone is %x).\n", driver->phone); 453 ipc_answer_0(iid, EINVAL); 454 return; 455 } 456 457 printf(NAME ": devman_forward: forward connection to device %s to " 458 "driver %s.\n", dev->pathname, driver->name); 459 ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE); 627 460 } 628 461 … … 631 464 static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall) 632 465 { 633 devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall); 634 fun_node_t *fun; 635 dev_node_t *dev; 636 637 fun = find_devmap_tree_function(&device_tree, devmap_handle); 638 if (fun == NULL) 639 fun = find_devmap_class_function(&class_list, devmap_handle); 640 641 if (fun == NULL || fun->dev->drv == NULL) { 642 async_answer_0(iid, ENOENT); 643 return; 644 } 645 646 dev = fun->dev; 647 648 if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) { 649 async_answer_0(iid, EINVAL); 650 return; 651 } 652 653 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0, 466 dev_handle_t devmap_handle = IPC_GET_METHOD(*icall); 467 node_t *dev; 468 469 dev = find_devmap_tree_device(&device_tree, devmap_handle); 470 if (dev == NULL) 471 dev = find_devmap_class_device(&class_list, devmap_handle); 472 473 if (dev == NULL || dev->drv == NULL) { 474 ipc_answer_0(iid, ENOENT); 475 return; 476 } 477 478 if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) { 479 ipc_answer_0(iid, EINVAL); 480 return; 481 } 482 483 printf(NAME ": devman_connection_devmapper: forward connection to " 484 "device %s to driver %s.\n", dev->pathname, dev->drv->name); 485 ipc_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0, 654 486 IPC_FF_NONE); 655 log_msg(LVL_DEBUG,656 "Forwarding devmapper request for `%s' function to driver `%s'.",657 fun->pathname, dev->drv->name);658 487 } 659 488 … … 661 490 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall) 662 491 { 492 /* 493 * Silly hack to enable the device manager to register as a driver by 494 * the device mapper. If the ipc method is not IPC_M_CONNECT_ME_TO, this 495 * is not the forwarded connection from naming service, so it must be a 496 * connection from the devmapper which thinks this is a devmapper-style 497 * driver. So pretend this is a devmapper-style driver. (This does not 498 * work for device with handle == IPC_M_CONNECT_ME_TO, because devmapper 499 * passes device handle to the driver as an ipc method.) 500 */ 501 if (IPC_GET_METHOD(*icall) != IPC_M_CONNECT_ME_TO) 502 devman_connection_devmapper(iid, icall); 503 504 /* 505 * ipc method is IPC_M_CONNECT_ME_TO, so this is forwarded connection 506 * from naming service by which we registered as device manager, so be 507 * device manager. 508 */ 509 663 510 /* Select interface. */ 664 switch (( sysarg_t) (IPC_GET_ARG1(*icall))) {511 switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) { 665 512 case DEVMAN_DRIVER: 666 513 devman_connection_driver(iid, icall); … … 673 520 devman_forward(iid, icall, false); 674 521 break; 675 case DEVMAN_CONNECT_FROM_DEVMAP:676 /* Someone connected through devmap node. */677 devman_connection_devmapper(iid, icall);678 break;679 522 case DEVMAN_CONNECT_TO_PARENTS_DEVICE: 680 523 /* Connect client to selected device. */ … … 683 526 default: 684 527 /* No such interface */ 685 async_answer_0(iid, ENOENT);528 ipc_answer_0(iid, ENOENT); 686 529 } 687 530 } … … 690 533 static bool devman_init(void) 691 534 { 692 log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");535 printf(NAME ": devman_init - looking for available drivers.\n"); 693 536 694 537 /* Initialize list of available drivers. */ … … 696 539 if (lookup_available_drivers(&drivers_list, 697 540 DRIVER_DEFAULT_STORE) == 0) { 698 log_msg(LVL_FATAL, "No drivers found.");541 printf(NAME " no drivers found."); 699 542 return false; 700 543 } 701 544 702 log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");545 printf(NAME ": devman_init - list of drivers has been initialized.\n"); 703 546 704 547 /* Create root device node. */ 705 548 if (!init_device_tree(&device_tree, &drivers_list)) { 706 log_msg(LVL_FATAL, "Failed to initialize device tree.");549 printf(NAME " failed to initialize device tree."); 707 550 return false; 708 551 } … … 725 568 printf(NAME ": HelenOS Device Manager\n"); 726 569 727 if (log_init(NAME, LVL_ERROR) != EOK) {728 printf(NAME ": Error initializing logging subsystem.\n");729 return -1;730 }731 732 570 if (!devman_init()) { 733 log_msg(LVL_ERROR, "Error while initializing service.");571 printf(NAME ": Error while initializing service\n"); 734 572 return -1; 735 573 } … … 739 577 740 578 /* Register device manager at naming service. */ 741 i f (service_register(SERVICE_DEVMAN) != EOK) {742 log_msg(LVL_ERROR, "Failed registering as a service.");579 ipcarg_t phonead; 580 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0) 743 581 return -1; 744 } 745 746 printf(NAME ": Accepting connections.\n"); 582 583 printf(NAME ": Accepting connections\n"); 747 584 async_manager(); 748 585
Note:
See TracChangeset
for help on using the changeset viewer.