Changes in uspace/drv/bus/pci/pciintel/pci.c [46eb2c4:3e6a98c5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/pci/pciintel/pci.c
r46eb2c4 r3e6a98c5 57 57 #include <ops/hw_res.h> 58 58 #include <device/hw_res.h> 59 #include <ops/pio_window.h>60 #include <device/pio_window.h>61 59 #include <ddi.h> 62 60 #include <pci_dev_iface.h> … … 143 141 } 144 142 145 static pio_window_t *pciintel_get_pio_window(ddf_fun_t *fnode)146 {147 pci_fun_t *fun = pci_fun(fnode);148 149 if (fun == NULL)150 return NULL;151 return &fun->pio_window;152 }153 154 155 143 static int pci_config_space_write_32(ddf_fun_t *fun, uint32_t address, 156 144 uint32_t data) … … 210 198 .get_resource_list = &pciintel_get_resources, 211 199 .enable_interrupt = &pciintel_enable_interrupt, 212 };213 214 static pio_window_ops_t pciintel_pio_window_ops = {215 .get_pio_window = &pciintel_get_pio_window216 200 }; 217 201 … … 227 211 static ddf_dev_ops_t pci_fun_ops = { 228 212 .interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops, 229 .interfaces[PIO_WINDOW_DEV_IFACE] = &pciintel_pio_window_ops,230 213 .interfaces[PCI_DEV_IFACE] = &pci_dev_ops 231 214 }; … … 250 233 static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 251 234 { 235 pci_bus_t *bus = pci_bus_from_fun(fun); 236 237 fibril_mutex_lock(&bus->conf_mutex); 238 252 239 const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 253 pci_bus_t *bus = pci_bus_from_fun(fun); 254 uint32_t val; 255 256 fibril_mutex_lock(&bus->conf_mutex); 257 258 pio_write_32(bus->conf_addr_reg, host2uint32_t_le(conf_addr)); 259 260 /* 261 * Always read full 32-bits from the PCI conf_data_port register and 262 * get the desired portion of it afterwards. Some architectures do not 263 * support shorter PIO reads offset from this register. 264 */ 265 val = uint32_t_le2host(pio_read_32(bus->conf_data_reg)); 266 240 void *addr = bus->conf_data_port + (reg & 3); 241 242 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr)); 243 267 244 switch (len) { 268 245 case 1: 269 *buf = (uint8_t) (val >> ((reg & 3) * 8)); 246 /* No endianness change for 1 byte */ 247 buf[0] = pio_read_8(addr); 270 248 break; 271 249 case 2: 272 *((uint16_t *) buf) = (uint16_t) (val >> ((reg & 3)) * 8);250 ((uint16_t *) buf)[0] = uint16_t_le2host(pio_read_16(addr)); 273 251 break; 274 252 case 4: 275 *((uint32_t *) buf) = (uint32_t) val;253 ((uint32_t *) buf)[0] = uint32_t_le2host(pio_read_32(addr)); 276 254 break; 277 255 } … … 282 260 static void pci_conf_write(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 283 261 { 262 pci_bus_t *bus = pci_bus_from_fun(fun); 263 264 fibril_mutex_lock(&bus->conf_mutex); 265 284 266 const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 285 pci_bus_t *bus = pci_bus_from_fun(fun); 286 uint32_t val; 287 288 fibril_mutex_lock(&bus->conf_mutex); 289 290 /* 291 * Prepare to write full 32-bits to the PCI conf_data_port register. 292 * Some architectures do not support shorter PIO writes offset from this 293 * register. 294 */ 295 296 if (len < 4) { 297 /* 298 * We have fewer than full 32-bits, so we need to read the 299 * missing bits first. 300 */ 301 pio_write_32(bus->conf_addr_reg, host2uint32_t_le(conf_addr)); 302 val = uint32_t_le2host(pio_read_32(bus->conf_data_reg)); 303 } 267 void *addr = bus->conf_data_port + (reg & 3); 268 269 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr)); 304 270 305 271 switch (len) { 306 272 case 1: 307 val &= ~(0xffU << ((reg & 3) * 8));308 val |= *buf << ((reg & 3) * 8);273 /* No endianness change for 1 byte */ 274 pio_write_8(addr, buf[0]); 309 275 break; 310 276 case 2: 311 val &= ~(0xffffU << ((reg & 3) * 8)); 312 val |= *((uint16_t *) buf) << ((reg & 3) * 8); 277 pio_write_16(addr, host2uint16_t_le(((uint16_t *) buf)[0])); 313 278 break; 314 279 case 4: 315 val = *((uint32_t *) buf);280 pio_write_32(addr, host2uint32_t_le(((uint32_t *) buf)[0])); 316 281 break; 317 282 } 318 319 pio_write_32(bus->conf_addr_reg, host2uint32_t_le(conf_addr));320 pio_write_32(bus->conf_data_reg, host2uint32_t_le(val));321 283 322 284 fibril_mutex_unlock(&bus->conf_mutex); … … 365 327 366 328 /* Vendor ID & Device ID, length(incl \0) 22 */ 367 rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/ven=%04 "368 PRIx16 "&dev=%04" PRIx16,fun->vendor_id, fun->device_id);329 rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/ven=%04x&dev=%04x", 330 fun->vendor_id, fun->device_id); 369 331 if (rc < 0) { 370 332 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s", … … 449 411 hw_resources[count].res.io_range.address = range_addr; 450 412 hw_resources[count].res.io_range.size = range_size; 451 hw_resources[count].res.io_range.relative = true;452 413 hw_resources[count].res.io_range.endianness = LITTLE_ENDIAN; 453 414 } else { … … 455 416 hw_resources[count].res.mem_range.address = range_addr; 456 417 hw_resources[count].res.mem_range.size = range_size; 457 hw_resources[count].res.mem_range.relative = false;458 418 hw_resources[count].res.mem_range.endianness = LITTLE_ENDIAN; 459 419 } … … 473 433 { 474 434 /* Value of the BAR */ 475 uint32_t val; 476 uint32_t bar; 477 uint32_t mask; 478 435 uint32_t val, mask; 479 436 /* IO space address */ 480 437 bool io; … … 514 471 /* Get the address mask. */ 515 472 pci_conf_write_32(fun, addr, 0xffffffff); 516 bar = pci_conf_read_32(fun, addr); 517 518 /* 519 * Unimplemented BARs read back as all 0's. 520 */ 521 if (!bar) 522 return addr + (addrw64 ? 8 : 4); 523 524 mask &= bar; 525 473 mask &= pci_conf_read_32(fun, addr); 474 526 475 /* Restore the original value. */ 527 476 pci_conf_write_32(fun, addr, val); … … 571 520 { 572 521 uint8_t irq = pci_conf_read_8(fun, PCI_BRIDGE_INT_LINE); 573 uint8_t pin = pci_conf_read_8(fun, PCI_BRIDGE_INT_PIN); 574 575 if (pin != 0 && irq != 0xff) 522 if (irq != 0xff) 576 523 pci_add_interrupt(fun, irq); 577 524 } … … 636 583 pci_read_bars(fun); 637 584 pci_read_interrupt(fun); 638 639 /* Propagate the PIO window to the function. */640 fun->pio_window = bus->pio_win;641 585 642 586 ddf_fun_set_ops(fun->fnode, &pci_fun_ops); … … 669 613 static int pci_dev_add(ddf_dev_t *dnode) 670 614 { 671 hw_resource_list_t hw_resources;672 615 pci_bus_t *bus = NULL; 673 616 ddf_fun_t *ctl = NULL; … … 695 638 goto fail; 696 639 } 697 698 rc = pio_window_get(sess, &bus->pio_win); 699 if (rc != EOK) { 700 ddf_msg(LVL_ERROR, "pci_dev_add failed to get PIO window " 701 "for the device."); 702 goto fail; 703 } 640 641 hw_resource_list_t hw_resources; 704 642 705 643 rc = hw_res_get_resource_list(sess, &hw_resources); … … 724 662 hw_resources.resources[1].res.io_range.address); 725 663 726 if (pio_enable_resource(&bus->pio_win, &hw_resources.resources[0], 727 (void **) &bus->conf_addr_reg)) { 664 bus->conf_io_addr = 665 (uint32_t) hw_resources.resources[0].res.io_range.address; 666 bus->conf_io_data = 667 (uint32_t) hw_resources.resources[1].res.io_range.address; 668 669 if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 4, 670 &bus->conf_addr_port)) { 728 671 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); 729 672 rc = EADDRNOTAVAIL; 730 673 goto fail; 731 674 } 732 if (pio_enable _resource(&bus->pio_win, &hw_resources.resources[1],733 (void **) &bus->conf_data_reg)) {675 if (pio_enable((void *)(uintptr_t)bus->conf_io_data, 4, 676 &bus->conf_data_port)) { 734 677 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); 735 678 rc = EADDRNOTAVAIL; … … 786 729 { 787 730 ddf_log_init(NAME); 731 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 732 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops; 788 733 } 789 734 … … 813 758 fun->vendor_id = pci_conf_read_16(fun, PCI_VENDOR_ID); 814 759 fun->device_id = pci_conf_read_16(fun, PCI_DEVICE_ID); 815 816 /* Explicitly enable PCI bus mastering */817 fun->command = pci_conf_read_16(fun, PCI_COMMAND) |818 PCI_COMMAND_MASTER;819 pci_conf_write_16(fun, PCI_COMMAND, fun->command);820 821 760 fun->class_code = pci_conf_read_8(fun, PCI_BASE_CLASS); 822 761 fun->subclass_code = pci_conf_read_8(fun, PCI_SUB_CLASS);
Note:
See TracChangeset
for help on using the changeset viewer.