Changeset 1d5a540 in mainline for uspace/drv/bus/pci/pciintel/pci.c
- Timestamp:
- 2012-08-17T11:52:20Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 034c4202
- Parents:
- 8312577 (diff), 56fd7cf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/pci/pciintel/pci.c
r8312577 r1d5a540 50 50 #include <ddf/driver.h> 51 51 #include <ddf/log.h> 52 #include <devman.h>53 #include <ipc/devman.h>54 52 #include <ipc/dev_iface.h> 55 53 #include <ipc/irc.h> … … 71 69 72 70 /** Obtain PCI function soft-state from DDF function node */ 73 #define PCI_FUN(fnode) ((pci_fun_t *) (fnode)->driver_data) 71 static pci_fun_t *pci_fun(ddf_fun_t *fnode) 72 { 73 return ddf_fun_data_get(fnode); 74 } 74 75 75 76 /** Obtain PCI bus soft-state from DDF device node */ 76 #define PCI_BUS(dnode) ((pci_bus_t *) (dnode)->driver_data) 77 #if 0 78 static pci_bus_t *pci_bus(ddf_dev_t *dnode) 79 { 80 return ddf_dev_data_get(dnode); 81 } 82 #endif 77 83 78 84 /** Obtain PCI bus soft-state from function soft-state */ 79 #define PCI_BUS_FROM_FUN(fun) ((fun)->busptr) 85 static pci_bus_t *pci_bus_from_fun(pci_fun_t *fun) 86 { 87 return fun->busptr; 88 } 80 89 81 90 /** Max is 47, align to something nice. */ … … 84 93 static hw_resource_list_t *pciintel_get_resources(ddf_fun_t *fnode) 85 94 { 86 pci_fun_t *fun = PCI_FUN(fnode);95 pci_fun_t *fun = pci_fun(fnode); 87 96 88 97 if (fun == NULL) … … 95 104 /* This is an old ugly way */ 96 105 assert(fnode); 97 pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data;106 pci_fun_t *dev_data = pci_fun(fnode); 98 107 99 108 sysarg_t apic; … … 138 147 if (address > 252) 139 148 return EINVAL; 140 pci_conf_write_32( PCI_FUN(fun), address, data);149 pci_conf_write_32(pci_fun(fun), address, data); 141 150 return EOK; 142 151 } … … 147 156 if (address > 254) 148 157 return EINVAL; 149 pci_conf_write_16( PCI_FUN(fun), address, data);158 pci_conf_write_16(pci_fun(fun), address, data); 150 159 return EOK; 151 160 } … … 156 165 if (address > 255) 157 166 return EINVAL; 158 pci_conf_write_8( PCI_FUN(fun), address, data);167 pci_conf_write_8(pci_fun(fun), address, data); 159 168 return EOK; 160 169 } … … 165 174 if (address > 252) 166 175 return EINVAL; 167 *data = pci_conf_read_32( PCI_FUN(fun), address);176 *data = pci_conf_read_32(pci_fun(fun), address); 168 177 return EOK; 169 178 } … … 174 183 if (address > 254) 175 184 return EINVAL; 176 *data = pci_conf_read_16( PCI_FUN(fun), address);185 *data = pci_conf_read_16(pci_fun(fun), address); 177 186 return EOK; 178 187 } … … 183 192 if (address > 255) 184 193 return EINVAL; 185 *data = pci_conf_read_8( PCI_FUN(fun), address);194 *data = pci_conf_read_8(pci_fun(fun), address); 186 195 return EOK; 187 196 } … … 225 234 static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 226 235 { 227 pci_bus_t *bus = PCI_BUS_FROM_FUN(fun);236 pci_bus_t *bus = pci_bus_from_fun(fun); 228 237 229 238 fibril_mutex_lock(&bus->conf_mutex); … … 252 261 static void pci_conf_write(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 253 262 { 254 pci_bus_t *bus = PCI_BUS_FROM_FUN(fun);263 pci_bus_t *bus = pci_bus_from_fun(fun); 255 264 256 265 fibril_mutex_lock(&bus->conf_mutex); … … 480 489 if (range_addr != 0) { 481 490 ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64 482 ", size = %x", fun->fnode->name, range_addr,491 ", size = %x", ddf_fun_get_name(fun->fnode), range_addr, 483 492 (unsigned int) range_size); 484 493 } … … 506 515 hw_res_list->count++; 507 516 508 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq);517 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", ddf_fun_get_name(fun->fnode), irq); 509 518 } 510 519 … … 523 532 void pci_bus_scan(pci_bus_t *bus, int bus_num) 524 533 { 525 ddf_fun_t *fnode;526 534 pci_fun_t *fun; 535 int rc; 527 536 528 537 int child_bus = 0; … … 531 540 uint8_t header_type; 532 541 533 fun = pci_fun_new(bus);534 535 542 for (dnum = 0; dnum < 32; dnum++) { 536 543 multi = true; 537 544 for (fnum = 0; multi && fnum < 8; fnum++) { 545 fun = pci_fun_new(bus); 546 538 547 pci_fun_init(fun, bus_num, dnum, fnum); 539 548 if (fun->vendor_id == 0xffff) { 549 pci_fun_delete(fun); 540 550 /* 541 551 * The device is not present, go on scanning the … … 559 569 if (fun_name == NULL) { 560 570 ddf_msg(LVL_ERROR, "Out of memory."); 571 pci_fun_delete(fun); 561 572 return; 562 573 } 563 574 564 fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);575 rc = ddf_fun_set_name(fun->fnode, fun_name); 565 576 free(fun_name); 566 if (fnode == NULL) { 567 ddf_msg(LVL_ERROR, "Failed creating function."); 577 if (rc != EOK) { 578 ddf_msg(LVL_ERROR, "Failed setting function name."); 579 pci_fun_delete(fun); 568 580 return; 569 581 } 570 571 fun->fnode = fnode;572 582 573 583 pci_alloc_resource_list(fun); … … 575 585 pci_read_interrupt(fun); 576 586 577 fnode->ops = &pci_fun_ops; 578 fnode->driver_data = fun; 587 ddf_fun_set_ops(fun->fnode, &pci_fun_ops); 579 588 580 589 ddf_msg(LVL_DEBUG, "Adding new function %s.", 581 fnode->name);590 ddf_fun_get_name(fun->fnode)); 582 591 583 592 pci_fun_create_match_ids(fun); 584 593 585 if (ddf_fun_bind(f node) != EOK) {594 if (ddf_fun_bind(fun->fnode) != EOK) { 586 595 pci_clean_resource_list(fun); 587 clean_match_ids(&fnode->match_ids); 588 free((char *) fnode->name); 589 fnode->name = NULL; 596 pci_fun_delete(fun); 590 597 continue; 591 598 } … … 601 608 pci_bus_scan(bus, child_bus); 602 609 } 603 604 fun = pci_fun_new(bus);605 610 } 606 }607 608 if (fun->vendor_id == 0xffff) {609 /* Free the auxiliary function structure. */610 pci_fun_delete(fun);611 611 } 612 612 } … … 617 617 ddf_fun_t *ctl = NULL; 618 618 bool got_res = false; 619 async_sess_t *sess; 619 620 int rc; 620 621 621 622 ddf_msg(LVL_DEBUG, "pci_dev_add"); 622 dnode->parent_sess = NULL;623 623 624 624 bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t)); … … 631 631 632 632 bus->dnode = dnode; 633 dnode->driver_data = bus; 634 635 dnode->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE, 636 dnode->handle, IPC_FLAG_BLOCKING); 637 if (!dnode->parent_sess) { 633 634 sess = ddf_dev_parent_sess_create(dnode, EXCHANGE_SERIALIZE); 635 if (sess == NULL) { 638 636 ddf_msg(LVL_ERROR, "pci_dev_add failed to connect to the " 639 637 "parent driver."); … … 644 642 hw_resource_list_t hw_resources; 645 643 646 rc = hw_res_get_resource_list( dnode->parent_sess, &hw_resources);644 rc = hw_res_get_resource_list(sess, &hw_resources); 647 645 if (rc != EOK) { 648 646 ddf_msg(LVL_ERROR, "pci_dev_add failed to get hw resources " … … 708 706 709 707 fail: 710 if (dnode->parent_sess)711 async_hangup(dnode->parent_sess);712 713 708 if (got_res) 714 709 hw_res_clean_resource_list(&hw_resources); … … 742 737 { 743 738 pci_fun_t *fun; 744 745 fun = (pci_fun_t *) calloc(1, sizeof(pci_fun_t)); 739 ddf_fun_t *fnode; 740 741 fnode = ddf_fun_create(bus->dnode, fun_inner, NULL); 742 if (fnode == NULL) 743 return NULL; 744 745 fun = ddf_fun_data_alloc(fnode, sizeof(pci_fun_t)); 746 746 if (fun == NULL) 747 747 return NULL; 748 748 749 749 fun->busptr = bus; 750 fun->fnode = fnode; 750 751 return fun; 751 752 } … … 766 767 void pci_fun_delete(pci_fun_t *fun) 767 768 { 768 assert(fun != NULL);769 769 hw_res_clean_resource_list(&fun->hw_resources); 770 free(fun); 770 if (fun->fnode != NULL) 771 ddf_fun_destroy(fun->fnode); 771 772 } 772 773
Note:
See TracChangeset
for help on using the changeset viewer.