Changeset 97a62fe in mainline for uspace/drv
- Timestamp:
- 2011-02-14T21:41:50Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cd0684d
- Parents:
- 7df0477e
- Location:
- uspace/drv
- Files:
-
- 7 edited
-
isa/isa.c (modified) (5 diffs)
-
ns8250/ns8250.c (modified) (2 diffs)
-
pciintel/pci.c (modified) (16 diffs)
-
pciintel/pci.h (modified) (3 diffs)
-
rootpc/rootpc.c (modified) (3 diffs)
-
test1/test1.c (modified) (1 diff)
-
test2/test2.c (modified) (2 diffs)
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;
Note:
See TracChangeset
for help on using the changeset viewer.
