Changes in uspace/drv/pciintel/pci.c [91579d5:ebcb05a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/pciintel/pci.c
r91579d5 rebcb05a 48 48 49 49 #include <ddf/driver.h> 50 #include <ddf/log.h> 50 51 #include <devman.h> 51 52 #include <ipc/devman.h> 52 53 #include <ipc/dev_iface.h> 53 #include <ipc/irc.h>54 #include <ipc/ns.h>55 #include <ipc/services.h>56 #include <sysinfo.h>57 54 #include <ops/hw_res.h> 58 55 #include <device/hw_res.h> 59 56 #include <ddi.h> 60 57 #include <libarch/ddi.h> 61 #include <pci_dev_iface.h>62 58 63 59 #include "pci.h" … … 88 84 static bool pciintel_enable_interrupt(ddf_fun_t *fnode) 89 85 { 90 /* This is an old ugly way, copied from ne2000 driver */ 91 assert(fnode); 92 pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data; 93 94 sysarg_t apic; 95 sysarg_t i8259; 96 97 int irc_phone = -1; 98 int irc_service = -1; 99 100 if ((sysinfo_get_value("apic", &apic) == EOK) && (apic)) { 101 irc_service = SERVICE_APIC; 102 } else if ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259)) { 103 irc_service = SERVICE_I8259; 104 } 105 106 if (irc_service == -1) { 107 return false; 108 } 109 110 irc_phone = service_connect_blocking(irc_service, 0, 0); 111 if (irc_phone < 0) { 112 return false; 113 } 114 115 size_t i; 116 for (i = 0; i < dev_data->hw_resources.count; i++) { 117 if (dev_data->hw_resources.resources[i].type == INTERRUPT) { 118 int irq = dev_data->hw_resources.resources[i].res.interrupt.irq; 119 int rc = async_req_1_0(irc_phone, IRC_ENABLE_INTERRUPT, irq); 120 if (rc != EOK) { 121 async_hangup(irc_phone); 122 return false; 123 } 124 } 125 } 126 127 async_hangup(irc_phone); 128 return true; 129 } 130 131 static int pci_config_space_write_32( 132 ddf_fun_t *fun, uint32_t address, uint32_t data) 133 { 134 if (address > 252) 135 return EINVAL; 136 pci_conf_write_32(PCI_FUN(fun), address, data); 137 return EOK; 138 } 139 140 static int pci_config_space_write_16( 141 ddf_fun_t *fun, uint32_t address, uint16_t data) 142 { 143 if (address > 254) 144 return EINVAL; 145 pci_conf_write_16(PCI_FUN(fun), address, data); 146 return EOK; 147 } 148 149 static int pci_config_space_write_8( 150 ddf_fun_t *fun, uint32_t address, uint8_t data) 151 { 152 if (address > 255) 153 return EINVAL; 154 pci_conf_write_8(PCI_FUN(fun), address, data); 155 return EOK; 156 } 157 158 static int pci_config_space_read_32( 159 ddf_fun_t *fun, uint32_t address, uint32_t *data) 160 { 161 if (address > 252) 162 return EINVAL; 163 *data = pci_conf_read_32(PCI_FUN(fun), address); 164 return EOK; 165 } 166 167 static int pci_config_space_read_16( 168 ddf_fun_t *fun, uint32_t address, uint16_t *data) 169 { 170 if (address > 254) 171 return EINVAL; 172 *data = pci_conf_read_16(PCI_FUN(fun), address); 173 return EOK; 174 } 175 176 static int pci_config_space_read_8( 177 ddf_fun_t *fun, uint32_t address, uint8_t *data) 178 { 179 if (address > 255) 180 return EINVAL; 181 *data = pci_conf_read_8(PCI_FUN(fun), address); 182 return EOK; 86 /* TODO */ 87 88 return false; 183 89 } 184 90 … … 188 94 }; 189 95 190 static pci_dev_iface_t pci_dev_ops = { 191 .config_space_read_8 = &pci_config_space_read_8, 192 .config_space_read_16 = &pci_config_space_read_16, 193 .config_space_read_32 = &pci_config_space_read_32, 194 .config_space_write_8 = &pci_config_space_write_8, 195 .config_space_write_16 = &pci_config_space_write_16, 196 .config_space_write_32 = &pci_config_space_write_32 197 }; 198 199 static ddf_dev_ops_t pci_fun_ops = { 200 .interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops, 201 .interfaces[PCI_DEV_IFACE] = &pci_dev_ops 202 }; 96 static ddf_dev_ops_t pci_fun_ops; 203 97 204 98 static int pci_add_device(ddf_dev_t *); … … 332 226 333 227 if (match_id_str == NULL) { 334 printf(NAME ": out of memory creating match ID.\n");228 ddf_msg(LVL_ERROR, "Out of memory creating match ID."); 335 229 return; 336 230 } … … 338 232 rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90); 339 233 if (rc != EOK) { 340 printf(NAME ": error adding match ID: %s\n",234 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", 341 235 str_error(rc)); 342 236 } … … 394 288 /* Get the value of the BAR. */ 395 289 val = pci_conf_read_32(fun, addr); 396 397 #define IO_MASK (~0x3)398 #define MEM_MASK (~0xf)399 290 400 291 io = (bool) (val & 1); 401 292 if (io) { 402 293 addrw64 = false; 403 mask = IO_MASK;404 294 } else { 405 mask = MEM_MASK;406 295 switch ((val >> 1) & 3) { 407 296 case 0: … … 419 308 /* Get the address mask. */ 420 309 pci_conf_write_32(fun, addr, 0xffffffff); 421 mask &= pci_conf_read_32(fun, addr);310 mask = pci_conf_read_32(fun, addr); 422 311 423 312 /* Restore the original value. */ … … 435 324 436 325 if (range_addr != 0) { 437 printf(NAME ": function %s : ", fun->fnode->name);438 printf("address = %" PRIx64, range_addr);439 printf(", size = %x\n",(unsigned int) range_size);326 ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64 327 ", size = %x", fun->fnode->name, range_addr, 328 (unsigned int) range_size); 440 329 } 441 330 … … 462 351 hw_res_list->count++; 463 352 464 printf(NAME ": function %s uses irq %x.\n", fun->fnode->name, irq);353 ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq); 465 354 } 466 355 … … 518 407 char *fun_name = pci_fun_create_name(fun); 519 408 if (fun_name == NULL) { 520 printf(NAME ": out of memory.\n");409 ddf_msg(LVL_ERROR, "Out of memory."); 521 410 return; 522 411 } … … 524 413 fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name); 525 414 if (fnode == NULL) { 526 printf(NAME ": error creating function.\n");415 ddf_msg(LVL_ERROR, "Failed creating function."); 527 416 return; 528 417 } … … 538 427 fnode->driver_data = fun; 539 428 540 printf(NAME ": adding new function %s.\n",429 ddf_msg(LVL_DEBUG, "Adding new function %s.", 541 430 fnode->name); 542 431 … … 555 444 child_bus = pci_conf_read_8(fun, 556 445 PCI_BRIDGE_SEC_BUS_NUM); 557 printf(NAME ": device is pci-to-pci bridge, " 558 "secondary bus number = %d.\n", bus_num); 446 ddf_msg(LVL_DEBUG, "Device is pci-to-pci " 447 "bridge, secondary bus number = %d.", 448 bus_num); 559 449 if (child_bus > bus_num) 560 450 pci_bus_scan(bus, child_bus); … … 578 468 int rc; 579 469 580 printf(NAME ": pci_add_device\n");470 ddf_msg(LVL_DEBUG, "pci_add_device"); 581 471 dnode->parent_phone = -1; 582 472 583 473 bus = pci_bus_new(); 584 474 if (bus == NULL) { 585 printf(NAME ": pci_add_device allocation failed.\n");475 ddf_msg(LVL_ERROR, "pci_add_device allocation failed."); 586 476 rc = ENOMEM; 587 477 goto fail; … … 593 483 IPC_FLAG_BLOCKING); 594 484 if (dnode->parent_phone < 0) { 595 printf(NAME ":pci_add_device failed to connect to the "596 "parent's driver. \n");485 ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the " 486 "parent's driver."); 597 487 rc = dnode->parent_phone; 598 488 goto fail; … … 603 493 rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources); 604 494 if (rc != EOK) { 605 printf(NAME ": pci_add_device failed to get hw resources for"606 " the device.\n");495 ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources " 496 "for the device."); 607 497 goto fail; 608 498 } 609 499 got_res = true; 610 500 611 printf(NAME ": conf_addr = %" PRIx64 ".\n",501 ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".", 612 502 hw_resources.resources[0].res.io_range.address); 613 503 … … 621 511 if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8, 622 512 &bus->conf_addr_port)) { 623 printf(NAME ": failed to enable configuration ports.\n");513 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); 624 514 rc = EADDRNOTAVAIL; 625 515 goto fail; … … 628 518 629 519 /* Make the bus device more visible. It has no use yet. */ 630 printf(NAME ": adding a 'ctl' function\n");520 ddf_msg(LVL_DEBUG, "Adding a 'ctl' function"); 631 521 632 522 ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl"); 633 523 if (ctl == NULL) { 634 printf(NAME ": error creating control function.\n");524 ddf_msg(LVL_ERROR, "Failed creating control function."); 635 525 rc = ENOMEM; 636 526 goto fail; … … 639 529 rc = ddf_fun_bind(ctl); 640 530 if (rc != EOK) { 641 printf(NAME ": error binding control function.\n");531 ddf_msg(LVL_ERROR, "Failed binding control function."); 642 532 goto fail; 643 533 } 644 534 645 535 /* Enumerate functions. */ 646 printf(NAME ": scanning the bus\n");536 ddf_msg(LVL_DEBUG, "Scanning the bus"); 647 537 pci_bus_scan(bus, 0); 648 538 … … 666 556 static void pciintel_init(void) 667 557 { 558 ddf_log_init(NAME, LVL_ERROR); 668 559 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 669 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops;670 560 } 671 561 … … 739 629 size_t pci_bar_mask_to_size(uint32_t mask) 740 630 { 741 size_t size = mask & ~(mask - 1); 742 return size; 631 return ((mask & 0xfffffff0) ^ 0xffffffff) + 1; 743 632 } 744 633 745 634 int main(int argc, char *argv[]) 746 635 { 747 printf(NAME ": HelenOS pci bus driver (intel method 1).\n");636 printf(NAME ": HelenOS PCI bus driver (Intel method 1).\n"); 748 637 pciintel_init(); 749 638 return ddf_driver_main(&pci_driver);
Note:
See TracChangeset
for help on using the changeset viewer.