Changes in uspace/drv/pciintel/pci.c [79ae36dd:ebcb05a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/pciintel/pci.c
r79ae36dd rebcb05a 52 52 #include <ipc/devman.h> 53 53 #include <ipc/dev_iface.h> 54 #include <ipc/irc.h>55 #include <ns.h>56 #include <ipc/services.h>57 #include <sysinfo.h>58 54 #include <ops/hw_res.h> 59 55 #include <device/hw_res.h> 60 56 #include <ddi.h> 61 57 #include <libarch/ddi.h> 62 #include <pci_dev_iface.h>63 58 64 59 #include "pci.h" … … 89 84 static bool pciintel_enable_interrupt(ddf_fun_t *fnode) 90 85 { 91 /* This is an old ugly way, copied from ne2000 driver */ 92 assert(fnode); 93 pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data; 94 95 sysarg_t apic; 96 sysarg_t i8259; 97 98 async_sess_t *irc_sess = NULL; 99 100 if (((sysinfo_get_value("apic", &apic) == EOK) && (apic)) 101 || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) { 102 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE, 103 SERVICE_IRC, 0, 0); 104 } 105 106 if (!irc_sess) 107 return false; 108 109 size_t i = 0; 110 hw_resource_list_t *res = &dev_data->hw_resources; 111 for (; i < res->count; i++) { 112 if (res->resources[i].type == INTERRUPT) { 113 const int irq = res->resources[i].res.interrupt.irq; 114 115 async_exch_t *exch = async_exchange_begin(irc_sess); 116 const int rc = 117 async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq); 118 async_exchange_end(exch); 119 120 if (rc != EOK) { 121 async_hangup(irc_sess); 122 return false; 123 } 124 } 125 } 126 127 async_hangup(irc_sess); 128 return true; 129 } 130 131 static int pci_config_space_write_32(ddf_fun_t *fun, uint32_t address, 132 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 *); … … 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. */ … … 580 469 581 470 ddf_msg(LVL_DEBUG, "pci_add_device"); 582 dnode->parent_ sess = NULL;471 dnode->parent_phone = -1; 583 472 584 473 bus = pci_bus_new(); … … 591 480 dnode->driver_data = bus; 592 481 593 dnode->parent_ sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,594 dnode->handle,IPC_FLAG_BLOCKING);595 if ( !dnode->parent_sess) {482 dnode->parent_phone = devman_parent_device_connect(dnode->handle, 483 IPC_FLAG_BLOCKING); 484 if (dnode->parent_phone < 0) { 596 485 ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the " 597 "parent driver.");598 rc = ENOENT;486 "parent's driver."); 487 rc = dnode->parent_phone; 599 488 goto fail; 600 489 } … … 602 491 hw_resource_list_t hw_resources; 603 492 604 rc = hw_res_get_resource_list(dnode->parent_ sess, &hw_resources);493 rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources); 605 494 if (rc != EOK) { 606 495 ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources " … … 655 544 if (bus != NULL) 656 545 pci_bus_delete(bus); 657 658 if (dnode->parent_sess) 659 async_hangup(dnode->parent_sess); 660 546 if (dnode->parent_phone >= 0) 547 async_hangup(dnode->parent_phone); 661 548 if (got_res) 662 549 hw_res_clean_resource_list(&hw_resources); 663 664 550 if (ctl != NULL) 665 551 ddf_fun_destroy(ctl); 666 552 667 553 return rc; 668 554 } … … 672 558 ddf_log_init(NAME, LVL_ERROR); 673 559 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 674 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops;675 560 } 676 561 … … 744 629 size_t pci_bar_mask_to_size(uint32_t mask) 745 630 { 746 size_t size = mask & ~(mask - 1); 747 return size; 631 return ((mask & 0xfffffff0) ^ 0xffffffff) + 1; 748 632 } 749 633
Note:
See TracChangeset
for help on using the changeset viewer.