Changeset a33f0a6 in mainline for uspace/drv/bus/pci/pciintel/pci.c
- Timestamp:
- 2011-08-03T17:34:57Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1940326
- Parents:
- 52a79081 (diff), 3fab770 (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/pci/pciintel/pci.c
r52a79081 ra33f0a6 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> 54 58 #include <ops/hw_res.h> 55 59 #include <device/hw_res.h> 56 60 #include <ddi.h> 57 61 #include <libarch/ddi.h> 62 #include <pci_dev_iface.h> 58 63 59 64 #include "pci.h" … … 84 89 static bool pciintel_enable_interrupt(ddf_fun_t *fnode) 85 90 { 86 /* TODO */ 87 88 return false; 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; 89 183 } 90 184 … … 94 188 }; 95 189 96 static ddf_dev_ops_t pci_fun_ops; 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 }; 97 203 98 204 static int pci_add_device(ddf_dev_t *); … … 236 342 } 237 343 344 free(match_id_str); 345 238 346 /* TODO add more ids (with subsys ids, using class id etc.) */ 239 347 } … … 288 396 /* Get the value of the BAR. */ 289 397 val = pci_conf_read_32(fun, addr); 398 399 #define IO_MASK (~0x3) 400 #define MEM_MASK (~0xf) 290 401 291 402 io = (bool) (val & 1); 292 403 if (io) { 293 404 addrw64 = false; 405 mask = IO_MASK; 294 406 } else { 407 mask = MEM_MASK; 295 408 switch ((val >> 1) & 3) { 296 409 case 0: … … 308 421 /* Get the address mask. */ 309 422 pci_conf_write_32(fun, addr, 0xffffffff); 310 mask = pci_conf_read_32(fun, addr);423 mask &= pci_conf_read_32(fun, addr); 311 424 312 425 /* Restore the original value. */ … … 469 582 470 583 ddf_msg(LVL_DEBUG, "pci_add_device"); 471 dnode->parent_ phone = -1;584 dnode->parent_sess = NULL; 472 585 473 586 bus = pci_bus_new(); … … 480 593 dnode->driver_data = bus; 481 594 482 dnode->parent_ phone = devman_parent_device_connect(dnode->handle,483 IPC_FLAG_BLOCKING);484 if ( dnode->parent_phone < 0) {595 dnode->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE, 596 dnode->handle, IPC_FLAG_BLOCKING); 597 if (!dnode->parent_sess) { 485 598 ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the " 486 "parent 'sdriver.");487 rc = dnode->parent_phone;599 "parent driver."); 600 rc = ENOENT; 488 601 goto fail; 489 602 } … … 491 604 hw_resource_list_t hw_resources; 492 605 493 rc = hw_res_get_resource_list(dnode->parent_ phone, &hw_resources);606 rc = hw_res_get_resource_list(dnode->parent_sess, &hw_resources); 494 607 if (rc != EOK) { 495 608 ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources " … … 544 657 if (bus != NULL) 545 658 pci_bus_delete(bus); 546 if (dnode->parent_phone >= 0) 547 async_hangup(dnode->parent_phone); 659 660 if (dnode->parent_sess) 661 async_hangup(dnode->parent_sess); 662 548 663 if (got_res) 549 664 hw_res_clean_resource_list(&hw_resources); 665 550 666 if (ctl != NULL) 551 667 ddf_fun_destroy(ctl); 552 668 553 669 return rc; 554 670 } … … 558 674 ddf_log_init(NAME, LVL_ERROR); 559 675 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 676 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops; 560 677 } 561 678 … … 629 746 size_t pci_bar_mask_to_size(uint32_t mask) 630 747 { 631 return ((mask & 0xfffffff0) ^ 0xffffffff) + 1; 748 size_t size = mask & ~(mask - 1); 749 return size; 632 750 } 633 751
Note:
See TracChangeset
for help on using the changeset viewer.