Changeset 97a62fe in mainline for uspace/drv/pciintel/pci.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/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
Note:
See TracChangeset
for help on using the changeset viewer.