Changes in uspace/srv/devman/main.c [ffa2c8ef:7e752b2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
rffa2c8ef r7e752b2 74 74 75 75 iid = async_get_call(&icall); 76 if (IPC_GET_ IMETHOD(icall) != DEVMAN_DRIVER_REGISTER) {77 async_answer_0(iid, EREFUSED);76 if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) { 77 ipc_answer_0(iid, EREFUSED); 78 78 return NULL; 79 79 } … … 84 84 int rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0); 85 85 if (rc != EOK) { 86 async_answer_0(iid, rc);86 ipc_answer_0(iid, rc); 87 87 return NULL; 88 88 } … … 98 98 free(drv_name); 99 99 drv_name = NULL; 100 async_answer_0(iid, ENOENT);100 ipc_answer_0(iid, ENOENT); 101 101 return NULL; 102 102 } … … 109 109 ipc_call_t call; 110 110 ipc_callid_t callid = async_get_call(&call); 111 if (IPC_GET_ IMETHOD(call) != IPC_M_CONNECT_TO_ME) {112 async_answer_0(callid, ENOTSUP);113 async_answer_0(iid, ENOTSUP);111 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { 112 ipc_answer_0(callid, ENOTSUP); 113 ipc_answer_0(iid, ENOTSUP); 114 114 return NULL; 115 115 } … … 121 121 driver->name); 122 122 123 async_answer_0(callid, EOK);124 async_answer_0(iid, EOK);123 ipc_answer_0(callid, EOK); 124 ipc_answer_0(iid, EOK); 125 125 126 126 return driver; … … 141 141 142 142 callid = async_get_call(&call); 143 if (DEVMAN_ADD_MATCH_ID != IPC_GET_ IMETHOD(call)) {143 if (DEVMAN_ADD_MATCH_ID != IPC_GET_METHOD(call)) { 144 144 printf(NAME ": ERROR: devman_receive_match_id - invalid " 145 145 "protocol.\n"); 146 async_answer_0(callid, EINVAL);146 ipc_answer_0(callid, EINVAL); 147 147 delete_match_id(match_id); 148 148 return EINVAL; … … 152 152 printf(NAME ": ERROR: devman_receive_match_id - failed to " 153 153 "allocate match id.\n"); 154 async_answer_0(callid, ENOMEM);154 ipc_answer_0(callid, ENOMEM); 155 155 return ENOMEM; 156 156 } 157 157 158 async_answer_0(callid, EOK);158 ipc_answer_0(callid, EOK); 159 159 160 160 match_id->score = IPC_GET_ARG1(call); … … 184 184 * @return Zero on success, negative error code otherwise. 185 185 */ 186 static int devman_receive_match_ids( sysarg_t match_count,186 static int devman_receive_match_ids(ipcarg_t match_count, 187 187 match_id_list_t *match_ids) 188 188 { … … 197 197 } 198 198 199 static int assign_driver_fibril(void *arg)200 {201 node_t *node = (node_t *) arg;202 assign_driver(node, &drivers_list, &device_tree);203 return EOK;204 }205 206 199 /** Handle child device registration. 207 200 * … … 211 204 { 212 205 devman_handle_t parent_handle = IPC_GET_ARG1(*call); 213 sysarg_t match_count = IPC_GET_ARG2(*call);206 ipcarg_t match_count = IPC_GET_ARG2(*call); 214 207 dev_tree_t *tree = &device_tree; 215 208 … … 219 212 if (parent == NULL) { 220 213 fibril_rwlock_write_unlock(&tree->rwlock); 221 async_answer_0(callid, ENOENT);214 ipc_answer_0(callid, ENOENT); 222 215 return; 223 216 } … … 227 220 if (rc != EOK) { 228 221 fibril_rwlock_write_unlock(&tree->rwlock); 229 async_answer_0(callid, rc);222 ipc_answer_0(callid, rc); 230 223 return; 231 224 } … … 235 228 fibril_rwlock_write_unlock(&tree->rwlock); 236 229 delete_dev_node(node); 237 async_answer_0(callid, ENOMEM);230 ipc_answer_0(callid, ENOMEM); 238 231 return; 239 232 } … … 244 237 245 238 devman_receive_match_ids(match_count, &node->match_ids); 246 247 /* 248 * Try to find a suitable driver and assign it to the device. We do 249 * not want to block the current fibril that is used for processing 250 * incoming calls: we will launch a separate fibril to handle the 251 * driver assigning. That is because assign_driver can actually include 252 * task spawning which could take some time. 253 */ 254 fid_t assign_fibril = fibril_create(assign_driver_fibril, node); 255 if (assign_fibril == 0) { 256 /* 257 * Fallback in case we are out of memory. 258 * Probably not needed as we will die soon anyway ;-). 259 */ 260 (void) assign_driver_fibril(node); 261 } else { 262 fibril_add_ready(assign_fibril); 263 } 264 239 265 240 /* Return device handle to parent's driver. */ 266 async_answer_1(callid, EOK, node->handle); 241 ipc_answer_1(callid, EOK, node->handle); 242 243 /* Try to find suitable driver and assign it to the device. */ 244 assign_driver(node, &drivers_list, &device_tree); 267 245 } 268 246 … … 281 259 * handle. 282 260 */ 283 devmap_device_register_with_iface(devmap_pathname, 284 &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 261 devmap_device_register(devmap_pathname, &cli->devmap_handle); 285 262 286 263 /* … … 302 279 0, 0, 0, 0); 303 280 if (rc != EOK) { 304 async_answer_0(callid, rc);281 ipc_answer_0(callid, rc); 305 282 return; 306 283 } … … 308 285 node_t *dev = find_dev_node(&device_tree, handle); 309 286 if (dev == NULL) { 310 async_answer_0(callid, ENOENT);287 ipc_answer_0(callid, ENOENT); 311 288 return; 312 289 } … … 320 297 printf(NAME ": device '%s' added to class '%s', class name '%s' was " 321 298 "asigned to it\n", dev->pathname, class_name, class_info->dev_name); 322 323 async_answer_0(callid, EOK);299 300 ipc_answer_0(callid, EOK); 324 301 } 325 302 … … 343 320 { 344 321 /* Accept the connection. */ 345 async_answer_0(iid, EOK);322 ipc_answer_0(iid, EOK); 346 323 347 324 driver_t *driver = devman_driver_register(); … … 368 345 callid = async_get_call(&call); 369 346 370 switch (IPC_GET_ IMETHOD(call)) {347 switch (IPC_GET_METHOD(call)) { 371 348 case IPC_M_PHONE_HUNGUP: 372 349 cont = false; … … 379 356 break; 380 357 default: 381 async_answer_0(callid, EINVAL);358 ipc_answer_0(callid, EINVAL); 382 359 break; 383 360 } … … 393 370 int rc = async_data_write_accept((void **) &pathname, true, 0, 0, 0, 0); 394 371 if (rc != EOK) { 395 async_answer_0(iid, rc);372 ipc_answer_0(iid, rc); 396 373 return; 397 374 } … … 402 379 403 380 if (dev == NULL) { 404 async_answer_0(iid, ENOENT);405 return; 406 } 407 408 async_answer_1(iid, EOK, dev->handle);381 ipc_answer_0(iid, ENOENT); 382 return; 383 } 384 385 ipc_answer_1(iid, EOK, dev->handle); 409 386 } 410 387 … … 414 391 { 415 392 /* Accept connection. */ 416 async_answer_0(iid, EOK);393 ipc_answer_0(iid, EOK); 417 394 418 395 bool cont = true; … … 421 398 ipc_callid_t callid = async_get_call(&call); 422 399 423 switch (IPC_GET_ IMETHOD(call)) {400 switch (IPC_GET_METHOD(call)) { 424 401 case IPC_M_PHONE_HUNGUP: 425 402 cont = false; … … 429 406 break; 430 407 default: 431 async_answer_0(callid, ENOENT);408 ipc_answer_0(callid, ENOENT); 432 409 } 433 410 } … … 443 420 printf(NAME ": devman_forward error - no device with handle %" PRIun 444 421 " was found.\n", handle); 445 async_answer_0(iid, ENOENT);422 ipc_answer_0(iid, ENOENT); 446 423 return; 447 424 } … … 460 437 printf(NAME ": devman_forward error - the device is not in %" PRIun 461 438 " usable state.\n", handle); 462 async_answer_0(iid, ENOENT);439 ipc_answer_0(iid, ENOENT); 463 440 return; 464 441 } … … 474 451 driver->name); 475 452 printf("the driver's phone is %" PRIun ").\n", driver->phone); 476 async_answer_0(iid, EINVAL);453 ipc_answer_0(iid, EINVAL); 477 454 return; 478 455 } … … 480 457 printf(NAME ": devman_forward: forward connection to device %s to " 481 458 "driver %s.\n", dev->pathname, driver->name); 482 async_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);459 ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE); 483 460 } 484 461 … … 487 464 static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall) 488 465 { 489 devmap_handle_t devmap_handle = IPC_GET_ ARG2(*icall);466 devmap_handle_t devmap_handle = IPC_GET_METHOD(*icall); 490 467 node_t *dev; 491 468 … … 495 472 496 473 if (dev == NULL || dev->drv == NULL) { 497 async_answer_0(iid, ENOENT);474 ipc_answer_0(iid, ENOENT); 498 475 return; 499 476 } 500 477 501 478 if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) { 502 async_answer_0(iid, EINVAL); 503 return; 504 } 505 506 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 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, 507 486 IPC_FF_NONE); 508 printf(NAME ": devman_connection_devmapper: forwarded connection to "509 "device %s to driver %s.\n", dev->pathname, dev->drv->name);510 487 } 511 488 … … 513 490 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall) 514 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 515 510 /* Select interface. */ 516 switch (( sysarg_t) (IPC_GET_ARG1(*icall))) {511 switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) { 517 512 case DEVMAN_DRIVER: 518 513 devman_connection_driver(iid, icall); … … 525 520 devman_forward(iid, icall, false); 526 521 break; 527 case DEVMAN_CONNECT_FROM_DEVMAP:528 /* Someone connected through devmap node. */529 devman_connection_devmapper(iid, icall);530 break;531 522 case DEVMAN_CONNECT_TO_PARENTS_DEVICE: 532 523 /* Connect client to selected device. */ … … 535 526 default: 536 527 /* No such interface */ 537 async_answer_0(iid, ENOENT);528 ipc_answer_0(iid, ENOENT); 538 529 } 539 530 } … … 586 577 587 578 /* Register device manager at naming service. */ 588 if (service_register(SERVICE_DEVMAN) != EOK) 579 ipcarg_t phonead; 580 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0) 589 581 return -1; 590 582
Note:
See TracChangeset
for help on using the changeset viewer.