Changes in uspace/srv/devman/main.c [7e752b2:ffa2c8ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r7e752b2 rffa2c8ef 74 74 75 75 iid = async_get_call(&icall); 76 if (IPC_GET_ METHOD(icall) != DEVMAN_DRIVER_REGISTER) {77 ipc_answer_0(iid, EREFUSED);76 if (IPC_GET_IMETHOD(icall) != DEVMAN_DRIVER_REGISTER) { 77 async_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 ipc_answer_0(iid, rc);86 async_answer_0(iid, rc); 87 87 return NULL; 88 88 } … … 98 98 free(drv_name); 99 99 drv_name = NULL; 100 ipc_answer_0(iid, ENOENT);100 async_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_ METHOD(call) != IPC_M_CONNECT_TO_ME) {112 ipc_answer_0(callid, ENOTSUP);113 ipc_answer_0(iid, ENOTSUP);111 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 112 async_answer_0(callid, ENOTSUP); 113 async_answer_0(iid, ENOTSUP); 114 114 return NULL; 115 115 } … … 121 121 driver->name); 122 122 123 ipc_answer_0(callid, EOK);124 ipc_answer_0(iid, EOK);123 async_answer_0(callid, EOK); 124 async_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_ METHOD(call)) {143 if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) { 144 144 printf(NAME ": ERROR: devman_receive_match_id - invalid " 145 145 "protocol.\n"); 146 ipc_answer_0(callid, EINVAL);146 async_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 ipc_answer_0(callid, ENOMEM);154 async_answer_0(callid, ENOMEM); 155 155 return ENOMEM; 156 156 } 157 157 158 ipc_answer_0(callid, EOK);158 async_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( ipcarg_t match_count,186 static int devman_receive_match_ids(sysarg_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 199 206 /** Handle child device registration. 200 207 * … … 204 211 { 205 212 devman_handle_t parent_handle = IPC_GET_ARG1(*call); 206 ipcarg_t match_count = IPC_GET_ARG2(*call);213 sysarg_t match_count = IPC_GET_ARG2(*call); 207 214 dev_tree_t *tree = &device_tree; 208 215 … … 212 219 if (parent == NULL) { 213 220 fibril_rwlock_write_unlock(&tree->rwlock); 214 ipc_answer_0(callid, ENOENT);221 async_answer_0(callid, ENOENT); 215 222 return; 216 223 } … … 220 227 if (rc != EOK) { 221 228 fibril_rwlock_write_unlock(&tree->rwlock); 222 ipc_answer_0(callid, rc);229 async_answer_0(callid, rc); 223 230 return; 224 231 } … … 228 235 fibril_rwlock_write_unlock(&tree->rwlock); 229 236 delete_dev_node(node); 230 ipc_answer_0(callid, ENOMEM);237 async_answer_0(callid, ENOMEM); 231 238 return; 232 239 } … … 237 244 238 245 devman_receive_match_ids(match_count, &node->match_ids); 239 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 240 265 /* Return device handle to parent's driver. */ 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); 266 async_answer_1(callid, EOK, node->handle); 245 267 } 246 268 … … 259 281 * handle. 260 282 */ 261 devmap_device_register(devmap_pathname, &cli->devmap_handle); 283 devmap_device_register_with_iface(devmap_pathname, 284 &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 262 285 263 286 /* … … 279 302 0, 0, 0, 0); 280 303 if (rc != EOK) { 281 ipc_answer_0(callid, rc);304 async_answer_0(callid, rc); 282 305 return; 283 306 } … … 285 308 node_t *dev = find_dev_node(&device_tree, handle); 286 309 if (dev == NULL) { 287 ipc_answer_0(callid, ENOENT);310 async_answer_0(callid, ENOENT); 288 311 return; 289 312 } … … 297 320 printf(NAME ": device '%s' added to class '%s', class name '%s' was " 298 321 "asigned to it\n", dev->pathname, class_name, class_info->dev_name); 299 300 ipc_answer_0(callid, EOK);322 323 async_answer_0(callid, EOK); 301 324 } 302 325 … … 320 343 { 321 344 /* Accept the connection. */ 322 ipc_answer_0(iid, EOK);345 async_answer_0(iid, EOK); 323 346 324 347 driver_t *driver = devman_driver_register(); … … 345 368 callid = async_get_call(&call); 346 369 347 switch (IPC_GET_ METHOD(call)) {370 switch (IPC_GET_IMETHOD(call)) { 348 371 case IPC_M_PHONE_HUNGUP: 349 372 cont = false; … … 356 379 break; 357 380 default: 358 ipc_answer_0(callid, EINVAL);381 async_answer_0(callid, EINVAL); 359 382 break; 360 383 } … … 370 393 int rc = async_data_write_accept((void **) &pathname, true, 0, 0, 0, 0); 371 394 if (rc != EOK) { 372 ipc_answer_0(iid, rc);395 async_answer_0(iid, rc); 373 396 return; 374 397 } … … 379 402 380 403 if (dev == NULL) { 381 ipc_answer_0(iid, ENOENT);382 return; 383 } 384 385 ipc_answer_1(iid, EOK, dev->handle);404 async_answer_0(iid, ENOENT); 405 return; 406 } 407 408 async_answer_1(iid, EOK, dev->handle); 386 409 } 387 410 … … 391 414 { 392 415 /* Accept connection. */ 393 ipc_answer_0(iid, EOK);416 async_answer_0(iid, EOK); 394 417 395 418 bool cont = true; … … 398 421 ipc_callid_t callid = async_get_call(&call); 399 422 400 switch (IPC_GET_ METHOD(call)) {423 switch (IPC_GET_IMETHOD(call)) { 401 424 case IPC_M_PHONE_HUNGUP: 402 425 cont = false; … … 406 429 break; 407 430 default: 408 ipc_answer_0(callid, ENOENT);431 async_answer_0(callid, ENOENT); 409 432 } 410 433 } … … 420 443 printf(NAME ": devman_forward error - no device with handle %" PRIun 421 444 " was found.\n", handle); 422 ipc_answer_0(iid, ENOENT);445 async_answer_0(iid, ENOENT); 423 446 return; 424 447 } … … 437 460 printf(NAME ": devman_forward error - the device is not in %" PRIun 438 461 " usable state.\n", handle); 439 ipc_answer_0(iid, ENOENT);462 async_answer_0(iid, ENOENT); 440 463 return; 441 464 } … … 451 474 driver->name); 452 475 printf("the driver's phone is %" PRIun ").\n", driver->phone); 453 ipc_answer_0(iid, EINVAL);476 async_answer_0(iid, EINVAL); 454 477 return; 455 478 } … … 457 480 printf(NAME ": devman_forward: forward connection to device %s to " 458 481 "driver %s.\n", dev->pathname, driver->name); 459 ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);482 async_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE); 460 483 } 461 484 … … 464 487 static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall) 465 488 { 466 devmap_handle_t devmap_handle = IPC_GET_ METHOD(*icall);489 devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall); 467 490 node_t *dev; 468 491 … … 472 495 473 496 if (dev == NULL || dev->drv == NULL) { 474 ipc_answer_0(iid, ENOENT);497 async_answer_0(iid, ENOENT); 475 498 return; 476 499 } 477 500 478 501 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 " 502 async_answer_0(iid, EINVAL); 503 return; 504 } 505 506 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0, 507 IPC_FF_NONE); 508 printf(NAME ": devman_connection_devmapper: forwarded connection to " 484 509 "device %s to driver %s.\n", dev->pathname, dev->drv->name); 485 ipc_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0,486 IPC_FF_NONE);487 510 } 488 511 … … 490 513 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall) 491 514 { 492 /*493 * Silly hack to enable the device manager to register as a driver by494 * the device mapper. If the ipc method is not IPC_M_CONNECT_ME_TO, this495 * is not the forwarded connection from naming service, so it must be a496 * connection from the devmapper which thinks this is a devmapper-style497 * driver. So pretend this is a devmapper-style driver. (This does not498 * work for device with handle == IPC_M_CONNECT_ME_TO, because devmapper499 * 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 connection506 * from naming service by which we registered as device manager, so be507 * device manager.508 */509 510 515 /* Select interface. */ 511 switch (( ipcarg_t) (IPC_GET_ARG1(*icall))) {516 switch ((sysarg_t) (IPC_GET_ARG1(*icall))) { 512 517 case DEVMAN_DRIVER: 513 518 devman_connection_driver(iid, icall); … … 520 525 devman_forward(iid, icall, false); 521 526 break; 527 case DEVMAN_CONNECT_FROM_DEVMAP: 528 /* Someone connected through devmap node. */ 529 devman_connection_devmapper(iid, icall); 530 break; 522 531 case DEVMAN_CONNECT_TO_PARENTS_DEVICE: 523 532 /* Connect client to selected device. */ … … 526 535 default: 527 536 /* No such interface */ 528 ipc_answer_0(iid, ENOENT);537 async_answer_0(iid, ENOENT); 529 538 } 530 539 } … … 577 586 578 587 /* Register device manager at naming service. */ 579 ipcarg_t phonead; 580 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0) 588 if (service_register(SERVICE_DEVMAN) != EOK) 581 589 return -1; 582 590
Note:
See TracChangeset
for help on using the changeset viewer.