Changes in uspace/drv/pciintel/pci.c [af6b5157:40a5d40] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/pciintel/pci.c
raf6b5157 r40a5d40 51 51 #include <ipc/devman.h> 52 52 #include <ipc/dev_iface.h> 53 #include <ipc/irc.h> 54 #include <ipc/ns.h> 55 #include <ipc/services.h> 56 #include <sysinfo.h> 53 57 #include <ops/hw_res.h> 54 58 #include <device/hw_res.h> 55 59 #include <ddi.h> 56 60 #include <libarch/ddi.h> 61 #include <pci_dev_iface.h> 57 62 58 63 #include "pci.h" … … 83 88 static bool pciintel_enable_interrupt(ddf_fun_t *fnode) 84 89 { 85 /* TODO */ 86 87 return false; 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 = 0; 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 == 0) 107 return false; 108 109 irc_phone = service_connect_blocking(irc_service, 0, 0); 110 if (irc_phone < 0) 111 return false; 112 113 size_t i; 114 for (i = 0; i < dev_data->hw_resources.count; i++) { 115 if (dev_data->hw_resources.resources[i].type == INTERRUPT) { 116 int irq = dev_data->hw_resources.resources[i].res.interrupt.irq; 117 int rc = async_req_1_0(irc_phone, IRC_ENABLE_INTERRUPT, irq); 118 if (rc != EOK) { 119 async_hangup(irc_phone); 120 return false; 121 } 122 } 123 } 124 125 async_hangup(irc_phone); 126 return true; 127 } 128 129 static int pci_config_space_write_32( 130 ddf_fun_t *fun, uint32_t address, uint32_t data) 131 { 132 if (address > 252) 133 return EINVAL; 134 pci_conf_write_32(PCI_FUN(fun), address, data); 135 return EOK; 136 } 137 138 static int pci_config_space_write_16( 139 ddf_fun_t *fun, uint32_t address, uint16_t data) 140 { 141 if (address > 254) 142 return EINVAL; 143 pci_conf_write_16(PCI_FUN(fun), address, data); 144 return EOK; 145 } 146 147 static int pci_config_space_write_8( 148 ddf_fun_t *fun, uint32_t address, uint8_t data) 149 { 150 if (address > 255) 151 return EINVAL; 152 pci_conf_write_8(PCI_FUN(fun), address, data); 153 return EOK; 154 } 155 156 static int pci_config_space_read_32( 157 ddf_fun_t *fun, uint32_t address, uint32_t *data) 158 { 159 if (address > 252) 160 return EINVAL; 161 *data = pci_conf_read_32(PCI_FUN(fun), address); 162 return EOK; 163 } 164 165 static int pci_config_space_read_16( 166 ddf_fun_t *fun, uint32_t address, uint16_t *data) 167 { 168 if (address > 254) 169 return EINVAL; 170 *data = pci_conf_read_16(PCI_FUN(fun), address); 171 return EOK; 172 } 173 174 static int pci_config_space_read_8( 175 ddf_fun_t *fun, uint32_t address, uint8_t *data) 176 { 177 if (address > 255) 178 return EINVAL; 179 *data = pci_conf_read_8(PCI_FUN(fun), address); 180 return EOK; 88 181 } 89 182 … … 93 186 }; 94 187 95 static ddf_dev_ops_t pci_fun_ops; 188 static pci_dev_iface_t pci_dev_ops = { 189 .config_space_read_8 = &pci_config_space_read_8, 190 .config_space_read_16 = &pci_config_space_read_16, 191 .config_space_read_32 = &pci_config_space_read_32, 192 .config_space_write_8 = &pci_config_space_write_8, 193 .config_space_write_16 = &pci_config_space_write_16, 194 .config_space_write_32 = &pci_config_space_write_32 195 }; 196 197 static ddf_dev_ops_t pci_fun_ops = { 198 .interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops, 199 .interfaces[PCI_DEV_IFACE] = &pci_dev_ops 200 }; 96 201 97 202 static int pci_add_device(ddf_dev_t *); … … 287 392 /* Get the value of the BAR. */ 288 393 val = pci_conf_read_32(fun, addr); 394 395 #define IO_MASK (~0x3) 396 #define MEM_MASK (~0xf) 289 397 290 398 io = (bool) (val & 1); 291 399 if (io) { 292 400 addrw64 = false; 401 mask = IO_MASK; 293 402 } else { 403 mask = MEM_MASK; 294 404 switch ((val >> 1) & 3) { 295 405 case 0: … … 307 417 /* Get the address mask. */ 308 418 pci_conf_write_32(fun, addr, 0xffffffff); 309 mask = pci_conf_read_32(fun, addr);419 mask &= pci_conf_read_32(fun, addr); 310 420 311 421 /* Restore the original value. */ … … 555 665 { 556 666 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 667 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops; 557 668 } 558 669 … … 626 737 size_t pci_bar_mask_to_size(uint32_t mask) 627 738 { 628 return ((mask & 0xfffffff0) ^ 0xffffffff) + 1; 739 size_t size = mask & ~(mask - 1); 740 return size; 629 741 } 630 742
Note:
See TracChangeset
for help on using the changeset viewer.