Changeset 97a62fe in mainline for uspace/lib/drv/generic/driver.c
- Timestamp:
- 2011-02-14T21:41:50Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cd0684d
- Parents:
- 7df0477e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/driver.c
r7df0477e r97a62fe 477 477 * @return The device structure. 478 478 */ 479 function_t *create_function(void)479 static function_t *create_function(void) 480 480 { 481 481 function_t *fun; 482 482 483 fun = malloc(sizeof(function_t));483 fun = calloc(1, sizeof(function_t)); 484 484 if (fun == NULL) 485 485 return NULL; 486 486 487 memset(fun, 0, sizeof(device_t));488 489 487 init_match_ids(&fun->match_ids); 490 488 link_initialize(&fun->link); … … 506 504 * @param dev The device structure. 507 505 */ 508 void delete_function(function_t *fun)506 static void delete_function(function_t *fun) 509 507 { 510 508 clean_match_ids(&fun->match_ids); … … 514 512 } 515 513 514 /** Create a DDF function node. 515 * 516 * Create a DDF function (in memory). Both child devices and external clients 517 * communicate with a device via its functions. 518 * 519 * The created function node is fully formed, but only exists in the memory 520 * of the client task. In order to be visible to the system, the function 521 * must be bound using ddf_fun_bind(). 522 * 523 * This function should only fail if there is not enough free memory. 524 * Specifically, this function succeeds even if @a dev already has 525 * a (bound) function with the same name. 526 * 527 * Type: A function of type fun_inner indicates that DDF should attempt 528 * to attach child devices to the function. fun_exposed means that 529 * the function should be exported to external clients (applications). 530 * 531 * @param dev Device to which we are adding function 532 * @param ftype Type of function (fun_inner or fun_exposed) 533 * @param name Name of function 534 * 535 * @return New function or @c NULL if memory is not available 536 */ 537 function_t *ddf_fun_create(device_t *dev, fun_type_t ftype, const char *name) 538 { 539 function_t *fun; 540 541 fun = create_function(); 542 if (fun == NULL) 543 return NULL; 544 545 fun->bound = false; 546 fun->dev = dev; 547 fun->ftype = ftype; 548 549 fun->name = str_dup(name); 550 if (fun->name == NULL) { 551 delete_function(fun); 552 return NULL; 553 } 554 555 return fun; 556 } 557 558 /** Destroy DDF function node. 559 * 560 * Destroy a function previously created with ddf_fun_create(). The function 561 * must not be bound. 562 * 563 * @param fun Function to destroy 564 */ 565 void ddf_fun_destroy(function_t *fun) 566 { 567 assert(fun->bound == false); 568 delete_function(fun); 569 } 570 516 571 void *function_get_ops(function_t *fun, dev_inferface_idx_t idx) 517 572 { … … 522 577 } 523 578 524 int register_function(function_t *fun, device_t *dev) 579 /** Bind a function node. 580 * 581 * Bind the specified function to the system. This effectively makes 582 * the function visible to the system (uploads it to the server). 583 * 584 * This function can fail for several reasons. Specifically, 585 * it will fail if the device already has a bound function of 586 * the same name. 587 * 588 * @param fun Function to bind 589 * @return EOK on success or negative error code 590 */ 591 int ddf_fun_bind(function_t *fun) 525 592 { 526 593 assert(fun->name != NULL); 527 594 528 595 int res; 529 530 fun->dev = dev;531 596 532 597 add_to_functions_list(fun); 533 598 res = devman_add_function(fun->name, fun->ftype, &fun->match_ids, 534 dev->handle, &fun->handle);599 fun->dev->handle, &fun->handle); 535 600 if (res != EOK) { 536 601 remove_from_functions_list(fun); … … 538 603 } 539 604 605 fun->bound = true; 540 606 return res; 541 607 } … … 556 622 int rc; 557 623 558 fun = create_function();624 fun = ddf_fun_create(dev, fun_inner, fun_name); 559 625 if (fun == NULL) { 560 626 rc = ENOMEM; 561 627 goto failure; 562 628 } 563 564 fun->dev = dev;565 fun->name = fun_name;566 fun->ftype = fun_inner;567 629 568 630 m_id = create_match_id(); … … 576 638 add_match_id(&fun->match_ids, m_id); 577 639 578 rc = register_function(fun, dev);640 rc = ddf_fun_bind(fun); 579 641 if (rc != EOK) 580 642 goto failure;
Note:
See TracChangeset
for help on using the changeset viewer.