Changeset 8b1e15ac in mainline for uspace/srv
- Timestamp:
- 2011-02-11T22:26:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68414f4a
- Parents:
- 1b367b4
- Location:
- uspace/srv/devman
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r1b367b4 r8b1e15ac 709 709 710 710 /** Create devmap path and name for the function. */ 711 staticvoid devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)711 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree) 712 712 { 713 713 char *devmap_pathname = NULL; … … 777 777 case EOK: 778 778 dev->state = DEVICE_USABLE; 779 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!780 if (0) devmap_register_tree_function(NULL, tree);781 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!782 779 break; 783 780 case ENOENT: -
uspace/srv/devman/devman.h
r1b367b4 r8b1e15ac 363 363 /* Devmap devices */ 364 364 365 extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *); 366 365 367 extern fun_node_t *find_devmap_tree_function(dev_tree_t *, devmap_handle_t); 366 368 extern fun_node_t *find_devmap_class_function(class_list_t *, devmap_handle_t); -
uspace/srv/devman/main.c
r1b367b4 r8b1e15ac 204 204 } 205 205 206 /** Handle child deviceregistration.206 /** Handle function registration. 207 207 * 208 208 * Child devices are registered by their parent's device driver. 209 209 */ 210 static void devman_add_child(ipc_callid_t callid, ipc_call_t *call) 211 { 212 devman_handle_t parent_handle = IPC_GET_ARG1(*call); 213 sysarg_t match_count = IPC_GET_ARG2(*call); 210 static void devman_add_function(ipc_callid_t callid, ipc_call_t *call) 211 { 212 fun_type_t ftype = (fun_type_t) IPC_GET_ARG1(*call); 213 devman_handle_t dev_handle = IPC_GET_ARG2(*call); 214 sysarg_t match_count = IPC_GET_ARG3(*call); 214 215 dev_tree_t *tree = &device_tree; 215 216 216 217 fibril_rwlock_write_lock(&tree->rwlock); 217 dev_node_t *pdev = find_dev_node_no_lock(&device_tree, parent_handle); 218 219 dev_node_t *dev = NULL; 220 dev_node_t *pdev = find_dev_node_no_lock(&device_tree, dev_handle); 218 221 219 222 if (pdev == NULL) { 220 223 fibril_rwlock_write_unlock(&tree->rwlock); 221 224 async_answer_0(callid, ENOENT); 225 return; 226 } 227 228 if (ftype != fun_inner && ftype != fun_exposed) { 229 /* Unknown function type */ 230 printf(NAME ": Error, unknown function type provided by driver!\n"); 231 232 fibril_rwlock_write_unlock(&tree->rwlock); 233 async_answer_0(callid, EINVAL); 222 234 return; 223 235 } … … 239 251 } 240 252 241 dev_node_t *dev;242 243 dev = create_dev_node();244 if (dev == NULL) {245 fibril_rwlock_write_unlock(&tree->rwlock);246 delete_fun_node(fun);247 async_answer_0(callid, ENOMEM);248 return;249 } 250 251 insert_dev_node(tree, dev, fun);253 if (ftype == fun_inner) { 254 dev = create_dev_node(); 255 if (dev == NULL) { 256 fibril_rwlock_write_unlock(&tree->rwlock); 257 delete_fun_node(fun); 258 async_answer_0(callid, ENOMEM); 259 return; 260 } 261 262 insert_dev_node(tree, dev, fun); 263 } 252 264 253 265 fibril_rwlock_write_unlock(&tree->rwlock); 254 266 255 printf(NAME ": devman_add_ child%s\n", fun->pathname);267 printf(NAME ": devman_add_function %s\n", fun->pathname); 256 268 257 269 devman_receive_match_ids(match_count, &fun->match_ids); 258 270 259 /* 260 * Try to find a suitable driver and assign it to the device. We do 261 * not want to block the current fibril that is used for processing 262 * incoming calls: we will launch a separate fibril to handle the 263 * driver assigning. That is because assign_driver can actually include 264 * task spawning which could take some time. 265 */ 266 fid_t assign_fibril = fibril_create(assign_driver_fibril, dev); 267 if (assign_fibril == 0) { 271 if (ftype == fun_inner) { 272 assert(dev != NULL); 268 273 /* 269 * Fallback in case we are out of memory. 270 * Probably not needed as we will die soon anyway ;-). 274 * Try to find a suitable driver and assign it to the device. We do 275 * not want to block the current fibril that is used for processing 276 * incoming calls: we will launch a separate fibril to handle the 277 * driver assigning. That is because assign_driver can actually include 278 * task spawning which could take some time. 271 279 */ 272 (void) assign_driver_fibril(fun); 280 fid_t assign_fibril = fibril_create(assign_driver_fibril, dev); 281 if (assign_fibril == 0) { 282 /* 283 * Fallback in case we are out of memory. 284 * Probably not needed as we will die soon anyway ;-). 285 */ 286 (void) assign_driver_fibril(fun); 287 } else { 288 fibril_add_ready(assign_fibril); 289 } 273 290 } else { 274 fibril_add_ready(assign_fibril);275 } 276 291 devmap_register_tree_function(fun, tree); 292 } 293 277 294 /* Return device handle to parent's driver. */ 278 295 async_answer_1(callid, EOK, fun->handle); … … 384 401 cont = false; 385 402 continue; 386 case DEVMAN_ADD_ CHILD_DEVICE:387 devman_add_ child(callid, &call);403 case DEVMAN_ADD_FUNCTION: 404 devman_add_function(callid, &call); 388 405 break; 389 406 case DEVMAN_ADD_DEVICE_TO_CLASS: … … 409 426 } 410 427 411 fun_node_t * 428 fun_node_t *fun = find_fun_node_by_path(&device_tree, pathname); 412 429 413 430 free(pathname); … … 417 434 return; 418 435 } 419 436 420 437 async_answer_1(iid, EOK, fun->handle); 421 438 } … … 450 467 { 451 468 devman_handle_t handle = IPC_GET_ARG2(*icall); 452 453 fun_node_t *fun = find_fun_node(&device_tree, handle); 454 if (fun == NULL) { 455 printf(NAME ": devman_forward error - no device function with " 469 devman_handle_t fwd_h; 470 fun_node_t *fun = NULL; 471 dev_node_t *dev = NULL; 472 473 fun = find_fun_node(&device_tree, handle); 474 if (fun == NULL) 475 dev = find_dev_node(&device_tree, handle); 476 else 477 dev = fun->dev; 478 479 if (fun == NULL && dev == NULL) { 480 printf(NAME ": devman_forward error - no device or function with " 456 481 "handle %" PRIun " was found.\n", handle); 457 482 async_answer_0(iid, ENOENT); 458 483 return; 459 484 } 485 486 if (fun == NULL && !drv_to_parent) { 487 printf(NAME ": devman_forward error - cannot connect to " 488 "handle %d, refers to a device.\n", handle); 489 async_answer_0(iid, ENOENT); 490 return; 491 } 460 492 461 493 driver_t *driver = NULL; 462 494 463 495 if (drv_to_parent) { 464 if (fun->dev->pfun != NULL) 465 driver = fun->dev->pfun->dev->drv; 466 } else if (fun->dev->state == DEVICE_USABLE) { 467 driver = fun->dev->drv; 496 /* Connect to parent function of a device (or device function). */ 497 if (dev->pfun->dev != NULL) 498 driver = dev->pfun->dev->drv; 499 fwd_h = dev->pfun->handle; 500 } else if (dev->state == DEVICE_USABLE) { 501 /* Connect to the specified function */ 502 driver = dev->drv; 468 503 assert(driver != NULL); 504 505 fwd_h = handle; 469 506 } 470 507 … … 490 527 } 491 528 492 printf(NAME ": devman_forward: forward connection to function %s to " 493 "driver %s.\n", fun->pathname, driver->name); 494 async_forward_fast(iid, driver->phone, method, fun->handle, 0, IPC_FF_NONE); 529 if (fun != NULL) { 530 printf(NAME ": devman_forward: forward connection to function %s to " 531 "driver %s.\n", fun->pathname, driver->name); 532 } else { 533 printf(NAME ": devman_forward: forward connection to device %s to " 534 "driver %s.\n", dev->pfun->pathname, driver->name); 535 } 536 537 async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE); 495 538 } 496 539
Note:
See TracChangeset
for help on using the changeset viewer.