Changes in uspace/drv/bus/pci/pciintel/pci.c [267f235:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/pci/pciintel/pci.c
r267f235 r9d58539 38 38 39 39 #include <assert.h> 40 #include <byteorder.h>41 40 #include <stdio.h> 42 41 #include <errno.h> … … 50 49 #include <ddf/driver.h> 51 50 #include <ddf/log.h> 51 #include <devman.h> 52 #include <ipc/devman.h> 52 53 #include <ipc/dev_iface.h> 53 54 #include <ipc/irc.h> … … 69 70 70 71 /** Obtain PCI function soft-state from DDF function node */ 71 static pci_fun_t *pci_fun(ddf_fun_t *fnode) 72 { 73 return ddf_fun_data_get(fnode); 74 } 72 #define PCI_FUN(fnode) ((pci_fun_t *) (fnode)->driver_data) 75 73 76 74 /** Obtain PCI bus soft-state from DDF device node */ 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 75 #define PCI_BUS(dnode) ((pci_bus_t *) (dnode)->driver_data) 83 76 84 77 /** Obtain PCI bus soft-state from function soft-state */ 85 static pci_bus_t *pci_bus_from_fun(pci_fun_t *fun) 86 { 87 return fun->busptr; 88 } 78 #define PCI_BUS_FROM_FUN(fun) ((fun)->busptr) 89 79 90 80 /** Max is 47, align to something nice. */ … … 93 83 static hw_resource_list_t *pciintel_get_resources(ddf_fun_t *fnode) 94 84 { 95 pci_fun_t *fun = pci_fun(fnode);85 pci_fun_t *fun = PCI_FUN(fnode); 96 86 97 87 if (fun == NULL) … … 104 94 /* This is an old ugly way */ 105 95 assert(fnode); 106 pci_fun_t *dev_data = pci_fun(fnode);96 pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data; 107 97 108 98 sysarg_t apic; … … 147 137 if (address > 252) 148 138 return EINVAL; 149 pci_conf_write_32( pci_fun(fun), address, data);139 pci_conf_write_32(PCI_FUN(fun), address, data); 150 140 return EOK; 151 141 } … … 156 146 if (address > 254) 157 147 return EINVAL; 158 pci_conf_write_16( pci_fun(fun), address, data);148 pci_conf_write_16(PCI_FUN(fun), address, data); 159 149 return EOK; 160 150 } … … 165 155 if (address > 255) 166 156 return EINVAL; 167 pci_conf_write_8( pci_fun(fun), address, data);157 pci_conf_write_8(PCI_FUN(fun), address, data); 168 158 return EOK; 169 159 } … … 174 164 if (address > 252) 175 165 return EINVAL; 176 *data = pci_conf_read_32( pci_fun(fun), address);166 *data = pci_conf_read_32(PCI_FUN(fun), address); 177 167 return EOK; 178 168 } … … 183 173 if (address > 254) 184 174 return EINVAL; 185 *data = pci_conf_read_16( pci_fun(fun), address);175 *data = pci_conf_read_16(PCI_FUN(fun), address); 186 176 return EOK; 187 177 } … … 192 182 if (address > 255) 193 183 return EINVAL; 194 *data = pci_conf_read_8( pci_fun(fun), address);184 *data = pci_conf_read_8(PCI_FUN(fun), address); 195 185 return EOK; 196 186 } … … 234 224 static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 235 225 { 236 pci_bus_t *bus = pci_bus_from_fun(fun);226 pci_bus_t *bus = PCI_BUS_FROM_FUN(fun); 237 227 238 228 fibril_mutex_lock(&bus->conf_mutex); … … 241 231 void *addr = bus->conf_data_port + (reg & 3); 242 232 243 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));233 pio_write_32(bus->conf_addr_port, conf_addr); 244 234 245 235 switch (len) { 246 236 case 1: 247 /* No endianness change for 1 byte */248 237 buf[0] = pio_read_8(addr); 249 238 break; 250 239 case 2: 251 ((uint16_t *) buf)[0] = uint16_t_le2host(pio_read_16(addr));240 ((uint16_t *) buf)[0] = pio_read_16(addr); 252 241 break; 253 242 case 4: 254 ((uint32_t *) buf)[0] = uint32_t_le2host(pio_read_32(addr));243 ((uint32_t *) buf)[0] = pio_read_32(addr); 255 244 break; 256 245 } … … 261 250 static void pci_conf_write(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 262 251 { 263 pci_bus_t *bus = pci_bus_from_fun(fun);252 pci_bus_t *bus = PCI_BUS_FROM_FUN(fun); 264 253 265 254 fibril_mutex_lock(&bus->conf_mutex); 266 255 267 const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 256 uint32_t conf_addr; 257 conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 268 258 void *addr = bus->conf_data_port + (reg & 3); 269 259 270 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));260 pio_write_32(bus->conf_addr_port, conf_addr); 271 261 272 262 switch (len) { 273 263 case 1: 274 /* No endianness change for 1 byte */275 264 pio_write_8(addr, buf[0]); 276 265 break; 277 266 case 2: 278 pio_write_16(addr, host2uint16_t_le(((uint16_t *) buf)[0]));267 pio_write_16(addr, ((uint16_t *) buf)[0]); 279 268 break; 280 269 case 4: 281 pio_write_32(addr, host2uint32_t_le(((uint32_t *) buf)[0]));270 pio_write_32(addr, ((uint32_t *) buf)[0]); 282 271 break; 283 272 } … … 489 478 if (range_addr != 0) { 490 479 ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64 491 ", size = %x", ddf_fun_get_name(fun->fnode), range_addr,480 ", size = %x", fun->fnode->name, range_addr, 492 481 (unsigned int) range_size); 493 482 } … … 515 504 hw_res_list->count++; 516 505 517 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", ddf_fun_get_name(fun->fnode), irq);506 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq); 518 507 } 519 508 … … 532 521 void pci_bus_scan(pci_bus_t *bus, int bus_num) 533 522 { 523 ddf_fun_t *fnode; 534 524 pci_fun_t *fun; 535 int rc;536 525 537 526 int child_bus = 0; … … 540 529 uint8_t header_type; 541 530 531 fun = pci_fun_new(bus); 532 542 533 for (dnum = 0; dnum < 32; dnum++) { 543 534 multi = true; 544 535 for (fnum = 0; multi && fnum < 8; fnum++) { 545 fun = pci_fun_new(bus);546 547 536 pci_fun_init(fun, bus_num, dnum, fnum); 548 537 if (fun->vendor_id == 0xffff) { 549 pci_fun_delete(fun);550 538 /* 551 539 * The device is not present, go on scanning the … … 569 557 if (fun_name == NULL) { 570 558 ddf_msg(LVL_ERROR, "Out of memory."); 571 pci_fun_delete(fun);572 559 return; 573 560 } 574 561 575 rc = ddf_fun_set_name(fun->fnode, fun_name);562 fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name); 576 563 free(fun_name); 577 if (rc != EOK) { 578 ddf_msg(LVL_ERROR, "Failed setting function name."); 579 pci_fun_delete(fun); 564 if (fnode == NULL) { 565 ddf_msg(LVL_ERROR, "Failed creating function."); 580 566 return; 581 567 } 568 569 fun->fnode = fnode; 582 570 583 571 pci_alloc_resource_list(fun); … … 585 573 pci_read_interrupt(fun); 586 574 587 ddf_fun_set_ops(fun->fnode, &pci_fun_ops); 575 fnode->ops = &pci_fun_ops; 576 fnode->driver_data = fun; 588 577 589 578 ddf_msg(LVL_DEBUG, "Adding new function %s.", 590 ddf_fun_get_name(fun->fnode));579 fnode->name); 591 580 592 581 pci_fun_create_match_ids(fun); 593 582 594 if (ddf_fun_bind(f un->fnode) != EOK) {583 if (ddf_fun_bind(fnode) != EOK) { 595 584 pci_clean_resource_list(fun); 596 pci_fun_delete(fun); 585 clean_match_ids(&fnode->match_ids); 586 free((char *) fnode->name); 587 fnode->name = NULL; 597 588 continue; 598 589 } … … 608 599 pci_bus_scan(bus, child_bus); 609 600 } 601 602 fun = pci_fun_new(bus); 610 603 } 604 } 605 606 if (fun->vendor_id == 0xffff) { 607 /* Free the auxiliary function structure. */ 608 pci_fun_delete(fun); 611 609 } 612 610 } … … 617 615 ddf_fun_t *ctl = NULL; 618 616 bool got_res = false; 619 async_sess_t *sess;620 617 int rc; 621 618 622 619 ddf_msg(LVL_DEBUG, "pci_dev_add"); 620 dnode->parent_sess = NULL; 623 621 624 622 bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t)); … … 631 629 632 630 bus->dnode = dnode; 633 634 sess = ddf_dev_parent_sess_create(dnode, EXCHANGE_SERIALIZE); 635 if (sess == NULL) { 631 dnode->driver_data = bus; 632 633 dnode->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE, 634 dnode->handle, IPC_FLAG_BLOCKING); 635 if (!dnode->parent_sess) { 636 636 ddf_msg(LVL_ERROR, "pci_dev_add failed to connect to the " 637 637 "parent driver."); … … 642 642 hw_resource_list_t hw_resources; 643 643 644 rc = hw_res_get_resource_list( sess, &hw_resources);644 rc = hw_res_get_resource_list(dnode->parent_sess, &hw_resources); 645 645 if (rc != EOK) { 646 646 ddf_msg(LVL_ERROR, "pci_dev_add failed to get hw resources " … … 650 650 got_res = true; 651 651 652 653 assert(hw_resources.count > 1);654 assert(hw_resources.resources[0].type == IO_RANGE);655 assert(hw_resources.resources[0].res.io_range.size >= 4);656 657 assert(hw_resources.resources[1].type == IO_RANGE);658 assert(hw_resources.resources[1].res.io_range.size >= 4);659 660 652 ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".", 661 653 hw_resources.resources[0].res.io_range.address); 662 ddf_msg(LVL_DEBUG, "data_addr = %" PRIx64 ".", 663 hw_resources.resources[1].res.io_range.address); 654 655 assert(hw_resources.count > 0); 656 assert(hw_resources.resources[0].type == IO_RANGE); 657 assert(hw_resources.resources[0].res.io_range.size == 8); 664 658 665 659 bus->conf_io_addr = 666 660 (uint32_t) hw_resources.resources[0].res.io_range.address; 667 bus->conf_io_data = 668 (uint32_t) hw_resources.resources[1].res.io_range.address; 669 670 if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 4, 661 662 if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8, 671 663 &bus->conf_addr_port)) { 672 664 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); … … 674 666 goto fail; 675 667 } 676 if (pio_enable((void *)(uintptr_t)bus->conf_io_data, 4, 677 &bus->conf_data_port)) { 678 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); 679 rc = EADDRNOTAVAIL; 680 goto fail; 681 } 668 bus->conf_data_port = (char *) bus->conf_addr_port + 4; 682 669 683 670 /* Make the bus device more visible. It has no use yet. */ … … 706 693 707 694 fail: 695 if (dnode->parent_sess) 696 async_hangup(dnode->parent_sess); 697 708 698 if (got_res) 709 699 hw_res_clean_resource_list(&hw_resources); … … 729 719 static void pciintel_init(void) 730 720 { 731 ddf_log_init(NAME );721 ddf_log_init(NAME, LVL_ERROR); 732 722 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 733 723 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops; … … 737 727 { 738 728 pci_fun_t *fun; 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)); 729 730 fun = (pci_fun_t *) calloc(1, sizeof(pci_fun_t)); 746 731 if (fun == NULL) 747 732 return NULL; 748 733 749 734 fun->busptr = bus; 750 fun->fnode = fnode;751 735 return fun; 752 736 } … … 767 751 void pci_fun_delete(pci_fun_t *fun) 768 752 { 753 assert(fun != NULL); 769 754 hw_res_clean_resource_list(&fun->hw_resources); 770 if (fun->fnode != NULL) 771 ddf_fun_destroy(fun->fnode); 755 free(fun); 772 756 } 773 757
Note:
See TracChangeset
for help on using the changeset viewer.