Changeset 97a62fe in mainline
- 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
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/isa/isa.c
r7df0477e r97a62fe 106 106 }; 107 107 108 static isa_fun_t *isa_fun_create( )108 static isa_fun_t *isa_fun_create(device_t *dev, const char *name) 109 109 { 110 110 isa_fun_t *fun = calloc(1, sizeof(isa_fun_t)); … … 112 112 return NULL; 113 113 114 function_t *fnode = create_function();114 function_t *fnode = ddf_fun_create(dev, fun_inner, name); 115 115 if (fnode == NULL) { 116 116 free(fun); … … 417 417 return NULL; 418 418 419 isa_fun_t *fun = isa_fun_create( );419 isa_fun_t *fun = isa_fun_create(dev, fun_name); 420 420 if (fun == NULL) { 421 421 free(fun_name); 422 422 return NULL; 423 423 } 424 425 function_t *fnode = fun->fnode;426 fnode->name = fun_name;427 fnode->ftype = fun_inner;428 424 429 425 /* Allocate buffer for the list of hardware resources of the device. */ … … 447 443 448 444 /* Set device operations to the device. */ 449 fnode->ops = &isa_fun_ops; 450 451 printf(NAME ": register_function(fun, dev); function is %s.\n", 452 fnode->name); 453 register_function(fnode, dev); 445 fun->fnode->ops = &isa_fun_ops; 446 447 printf(NAME ": Binding function %s.\n", fun->fnode->name); 448 449 /* XXX Handle error */ 450 (void) ddf_fun_bind(fun->fnode); 454 451 455 452 return fun_conf; … … 482 479 printf(NAME ": adding a 'ctl' function\n"); 483 480 484 function_t *ctl = create_function(); 485 ctl->ftype = fun_exposed; 486 ctl->name = "ctl"; 487 register_function(ctl, dev); 481 function_t *ctl = ddf_fun_create(dev, fun_exposed, "ctl"); 482 if (ctl == NULL) { 483 printf(NAME ": Error creating control function.\n"); 484 return EXDEV; 485 } 486 487 if (ddf_fun_bind(ctl) != EOK) { 488 printf(NAME ": Error binding control function.\n"); 489 return EXDEV; 490 } 488 491 489 492 /* Add functions as specified in the configuration file. */ -
uspace/drv/ns8250/ns8250.c
r7df0477e r97a62fe 761 761 } 762 762 763 fun = create_function(); 764 fun->ftype = fun_exposed; 765 fun->name = "a"; 763 fun = ddf_fun_create(dev, fun_exposed, "a"); 764 if (fun == NULL) { 765 printf(NAME ": error creating function.\n"); 766 goto fail; 767 } 766 768 767 769 /* Set device operations. */ 768 770 fun->ops = &ns8250_dev_ops; 769 register_function(fun, dev); 771 rc = ddf_fun_bind(fun); 772 if (rc != EOK) { 773 printf(NAME ": error binding function.\n"); 774 goto fail; 775 } 776 770 777 ns->fun = fun; 771 778 … … 777 784 return EOK; 778 785 fail: 786 if (fun != NULL) 787 ddf_fun_destroy(fun); 779 788 if (need_cleanup) 780 789 ns8250_dev_cleanup(ns); -
uspace/drv/pciintel/pci.c
r7df0477e r97a62fe 69 69 70 70 /** Obtain PCI bus soft-state from function soft-state */ 71 #define PCI_BUS_FROM_FUN(fun) ( PCI_BUS(fun->fnode->dev))71 #define PCI_BUS_FROM_FUN(fun) ((fun)->busptr) 72 72 73 73 static hw_resource_list_t *pciintel_get_resources(function_t *fnode) … … 361 361 void pci_bus_scan(pci_bus_t *bus, int bus_num) 362 362 { 363 function_t *fnode = create_function(); 364 pci_fun_t *fun = pci_fun_new(); 365 fnode->driver_data = fun; 363 function_t *fnode; 364 pci_fun_t *fun; 366 365 367 366 int child_bus = 0; … … 370 369 uint8_t header_type; 371 370 372 /* We need this early, before registering. */ 373 fun->fnode = fnode; 374 fnode->dev = bus->dnode; 375 fnode->driver_data = fun; 371 fun = pci_fun_new(bus); 376 372 377 373 for (dnum = 0; dnum < 32; dnum++) { … … 402 398 header_type = header_type & 0x7F; 403 399 404 pci_fun_create_name(fun); 400 char *fun_name = pci_fun_create_name(fun); 401 if (fun_name == NULL) { 402 printf(NAME ": out of memory.\n"); 403 return; 404 } 405 406 fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name); 407 if (fnode == NULL) { 408 printf(NAME ": error creating function.\n"); 409 return; 410 } 411 412 free(fun_name); 413 fun->fnode = fnode; 405 414 406 415 pci_alloc_resource_list(fun); … … 408 417 pci_read_interrupt(fun); 409 418 410 fnode->ftype = fun_inner;411 419 fnode->ops = &pci_fun_ops; 420 fnode->driver_data = fun; 412 421 413 422 printf(NAME ": adding new function %s.\n", … … 416 425 pci_fun_create_match_ids(fun); 417 426 418 if ( register_function(fnode, bus->dnode) != EOK) {427 if (ddf_fun_bind(fnode) != EOK) { 419 428 pci_clean_resource_list(fun); 420 429 clean_match_ids(&fnode->match_ids); … … 434 443 } 435 444 436 /* Alloc new aux. fun. structure. */ 437 fnode = create_function(); 438 439 /* We need this early, before registering. */ 440 fnode->dev = bus->dnode; 441 442 fun = pci_fun_new(); 443 fun->fnode = fnode; 444 fnode->driver_data = fun; 445 fun = pci_fun_new(bus); 445 446 } 446 447 } 447 448 448 449 if (fun->vendor_id == 0xffff) { 449 delete_function(fnode);450 450 /* Free the auxiliary function structure. */ 451 451 pci_fun_delete(fun); … … 455 455 static int pci_add_device(device_t *dnode) 456 456 { 457 pci_bus_t *bus = NULL; 458 function_t *ctl = NULL; 459 bool got_res = false; 457 460 int rc; 458 461 459 462 printf(NAME ": pci_add_device\n"); 460 461 pci_bus_t *bus = pci_bus_new(); 463 dnode->parent_phone = -1; 464 465 bus = pci_bus_new(); 462 466 if (bus == NULL) { 463 467 printf(NAME ": pci_add_device allocation failed.\n"); 464 return ENOMEM; 468 rc = ENOMEM; 469 goto fail; 465 470 } 466 471 bus->dnode = dnode; … … 472 477 printf(NAME ": pci_add_device failed to connect to the " 473 478 "parent's driver.\n"); 474 pci_bus_delete(bus);475 return dnode->parent_phone;479 rc = dnode->parent_phone; 480 goto fail; 476 481 } 477 482 … … 482 487 printf(NAME ": pci_add_device failed to get hw resources for " 483 488 "the device.\n"); 484 pci_bus_delete(bus); 485 async_hangup(dnode->parent_phone); 486 return rc; 487 } 489 goto fail; 490 } 491 got_res = true; 488 492 489 493 printf(NAME ": conf_addr = %" PRIx64 ".\n", … … 500 504 &bus->conf_addr_port)) { 501 505 printf(NAME ": failed to enable configuration ports.\n"); 502 pci_bus_delete(bus); 503 async_hangup(dnode->parent_phone); 504 hw_res_clean_resource_list(&hw_resources); 505 return EADDRNOTAVAIL; 506 rc = EADDRNOTAVAIL; 507 goto fail; 506 508 } 507 509 bus->conf_data_port = (char *) bus->conf_addr_port + 4; … … 510 512 printf(NAME ": adding a 'ctl' function\n"); 511 513 512 function_t *ctl = create_function(); 513 ctl->ftype = fun_exposed; 514 ctl->name = "ctl"; 515 register_function(ctl, dnode); 514 ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl"); 515 if (ctl == NULL) { 516 printf(NAME ": error creating control function.\n"); 517 rc = ENOMEM; 518 goto fail; 519 } 520 521 rc = ddf_fun_bind(ctl); 522 if (rc != EOK) { 523 printf(NAME ": error binding control function.\n"); 524 goto fail; 525 } 516 526 517 527 /* Enumerate functions. */ … … 522 532 523 533 return EOK; 534 535 fail: 536 if (bus != NULL) 537 pci_bus_delete(bus); 538 if (dnode->parent_phone >= 0) 539 async_hangup(dnode->parent_phone); 540 if (got_res) 541 hw_res_clean_resource_list(&hw_resources); 542 if (ctl != NULL) 543 ddf_fun_destroy(ctl); 544 545 return rc; 524 546 } 525 547 … … 529 551 } 530 552 531 pci_fun_t *pci_fun_new(void) 532 { 533 pci_fun_t *res; 534 535 res = (pci_fun_t *) calloc(1, sizeof(pci_fun_t)); 536 return res; 553 pci_fun_t *pci_fun_new(pci_bus_t *bus) 554 { 555 pci_fun_t *fun; 556 557 fun = (pci_fun_t *) calloc(1, sizeof(pci_fun_t)); 558 if (fun == NULL) 559 return NULL; 560 561 fun->busptr = bus; 562 return fun; 537 563 } 538 564 … … 551 577 } 552 578 553 voidpci_fun_create_name(pci_fun_t *fun)579 char *pci_fun_create_name(pci_fun_t *fun) 554 580 { 555 581 char *name = NULL; … … 557 583 asprintf(&name, "%02x:%02x.%01x", fun->bus, fun->dev, 558 584 fun->fn); 559 fun->fnode->name =name;585 return name; 560 586 } 561 587 -
uspace/drv/pciintel/pci.h
r7df0477e r97a62fe 45 45 #define PCI_MAX_HW_RES 8 46 46 47 typedef struct pciintel_bus { 48 /** DDF device node */ 49 device_t *dnode; 50 uint32_t conf_io_addr; 51 void *conf_data_port; 52 void *conf_addr_port; 53 fibril_mutex_t conf_mutex; 54 } pci_bus_t; 55 47 56 typedef struct pci_fun_data { 57 pci_bus_t *busptr; 48 58 function_t *fnode; 49 59 … … 55 65 hw_resource_list_t hw_resources; 56 66 } pci_fun_t; 57 58 typedef struct pciintel_bus {59 /** DDF device node */60 device_t *dnode;61 uint32_t conf_io_addr;62 void *conf_data_port;63 void *conf_addr_port;64 fibril_mutex_t conf_mutex;65 } pci_bus_t;66 67 67 68 extern void pci_fun_create_match_ids(pci_fun_t *); … … 79 80 extern void pci_add_interrupt(pci_fun_t *, int); 80 81 81 extern pci_fun_t *pci_fun_new( void);82 extern pci_fun_t *pci_fun_new(pci_bus_t *); 82 83 extern void pci_fun_init(pci_fun_t *, int, int, int); 83 84 extern void pci_fun_delete(pci_fun_t *); 84 extern voidpci_fun_create_name(pci_fun_t *);85 extern char *pci_fun_create_name(pci_fun_t *); 85 86 86 87 extern void pci_bus_scan(pci_bus_t *, int); -
uspace/drv/rootpc/rootpc.c
r7df0477e r97a62fe 125 125 126 126 /* Create new device. */ 127 fnode = create_function();127 fnode = ddf_fun_create(dev, fun_inner, name); 128 128 if (fnode == NULL) 129 129 goto failure; 130 130 131 fnode->name = name;132 131 fnode->driver_data = fun; 133 fnode->ftype = fun_inner;134 132 135 133 /* Initialize match id list */ … … 146 144 147 145 /* Register function. */ 148 if (register_function(fnode, dev) != EOK) 146 if (ddf_fun_bind(fnode) != EOK) { 147 printf(NAME ": error binding function %s.\n", name); 149 148 goto failure; 149 } 150 150 printf(NAME ": registered function handle = %u\n", fnode->handle); 151 151 … … 156 156 match_id->id = NULL; 157 157 158 if (fnode != NULL) { 159 fnode->name = NULL; 160 delete_function(fnode); 161 } 158 if (fnode != NULL) 159 ddf_fun_destroy(fnode); 162 160 163 161 printf(NAME ": failed to add function '%s'.\n", name); -
uspace/drv/test1/test1.c
r7df0477e r97a62fe 92 92 { 93 93 function_t *fun_a; 94 int rc; 94 95 95 96 printf(NAME ": add_device(name=\"%s\", handle=%d)\n", 96 97 dev->name, (int) dev->handle); 97 98 98 fun_a = create_function(); 99 fun_a->ftype = fun_exposed; 100 fun_a->name = "a"; 99 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 100 if (fun_a == NULL) { 101 printf(NAME ": error creating function 'a'.\n"); 102 return ENOMEM; 103 } 101 104 102 register_function(fun_a, dev); 105 rc = ddf_fun_bind(fun_a); 106 if (rc != EOK) { 107 printf(NAME ": error binding function 'a'.\n"); 108 return rc; 109 } 103 110 104 111 add_function_to_class(fun_a, "virtual"); -
uspace/drv/test2/test2.c
r7df0477e r97a62fe 82 82 { 83 83 device_t *dev = (device_t *) arg; 84 function_t *fun; 84 function_t *fun_a; 85 int rc; 85 86 86 87 async_usleep(1000); … … 91 92 "test1", "virtual&test1", 10); 92 93 93 fun = create_function(); 94 fun->ftype = fun_exposed; 95 fun->name = "a"; 94 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 95 if (fun_a == NULL) { 96 printf(NAME ": error creating function 'a'.\n"); 97 return ENOMEM; 98 } 96 99 97 register_function(fun, dev); 100 rc = ddf_fun_bind(fun_a); 101 if (rc != EOK) { 102 printf(NAME ": error binding function 'a'.\n"); 103 return rc; 104 } 98 105 99 add_function_to_class(fun , "virtual");106 add_function_to_class(fun_a, "virtual"); 100 107 101 108 return EOK; -
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; -
uspace/lib/drv/include/driver.h
r7df0477e r97a62fe 115 115 /** Function structure */ 116 116 struct function { 117 /** True if bound to the device manager */ 118 bool bound; 117 119 /** Function indentifier (asigned by device manager) */ 118 120 devman_handle_t handle; … … 157 159 int driver_main(driver_t *); 158 160 159 /** Create new device structure. 160 * 161 * @return The device structure. 162 */ 163 extern function_t *create_function(void); 164 extern void delete_function(function_t *); 161 extern function_t *ddf_fun_create(device_t *, fun_type_t, const char *); 162 extern void ddf_fun_destroy(function_t *); 163 extern int ddf_fun_bind(function_t *); 164 165 165 extern void *function_get_ops(function_t *, dev_inferface_idx_t); 166 166 167 extern int register_function(function_t *, device_t *);168 167 extern int register_function_wrapper(device_t *, const char *, const char *, 169 168 int);
Note:
See TracChangeset
for help on using the changeset viewer.