Changeset 82721f5 in mainline for uspace/drv/bus/pci/pciintel/pci.c
- Timestamp:
- 2013-09-09T19:45:31Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c501bc4
- Parents:
- a1ecb88
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/pci/pciintel/pci.c
ra1ecb88 r82721f5 233 233 static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 234 234 { 235 const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 235 236 pci_bus_t *bus = pci_bus_from_fun(fun); 237 uint32_t val; 236 238 237 239 fibril_mutex_lock(&bus->conf_mutex); 238 239 const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 240 void *addr = bus->conf_data_port + (reg & 3); 241 240 242 241 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr)); 243 242 243 /* 244 * Always read full 32-bits from the PCI conf_data_port register and 245 * get the desired portion of it afterwards. Some architectures do not 246 * support shorter PIO reads offset from this register. 247 */ 248 val = uint32_t_le2host(pio_read_32(bus->conf_data_port)); 249 244 250 switch (len) { 245 251 case 1: 246 /* No endianness change for 1 byte */ 247 buf[0] = pio_read_8(addr); 252 *buf = (uint8_t) (val >> ((reg & 3) * 8)); 248 253 break; 249 254 case 2: 250 ((uint16_t *) buf)[0] = uint16_t_le2host(pio_read_16(addr));255 *((uint16_t *) buf) = (uint16_t) (val >> ((reg & 3)) * 8); 251 256 break; 252 257 case 4: 253 ((uint32_t *) buf)[0] = uint32_t_le2host(pio_read_32(addr));258 *((uint32_t *) buf) = (uint32_t) val; 254 259 break; 255 260 } … … 260 265 static void pci_conf_write(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 261 266 { 267 const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 262 268 pci_bus_t *bus = pci_bus_from_fun(fun); 269 uint32_t val; 263 270 264 271 fibril_mutex_lock(&bus->conf_mutex); 265 266 const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg); 267 void *addr = bus->conf_data_port + (reg & 3); 268 269 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr)); 272 273 /* 274 * Prepare to write full 32-bits to the PCI conf_data_port register. 275 * Some architectures do not support shorter PIO writes offset from this 276 * register. 277 */ 278 279 if (len < 4) { 280 /* 281 * We have fewer than full 32-bits, so we need to read the 282 * missing bits first. 283 */ 284 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr)); 285 val = uint32_t_le2host(pio_read_32(bus->conf_data_port)); 286 } 270 287 271 288 switch (len) { 272 289 case 1: 273 /* No endianness change for 1 byte */274 pio_write_8(addr, buf[0]);290 val &= ~(0xffU << ((reg & 3) * 8)); 291 val |= *buf << ((reg & 3) * 8); 275 292 break; 276 293 case 2: 277 pio_write_16(addr, host2uint16_t_le(((uint16_t *) buf)[0])); 294 val &= ~(0xffffU << ((reg & 3) * 8)); 295 val |= *((uint16_t *) buf) << ((reg & 3) * 8); 278 296 break; 279 297 case 4: 280 pio_write_32(addr, host2uint32_t_le(((uint32_t *) buf)[0]));298 val = *((uint32_t *) buf); 281 299 break; 282 300 } 301 302 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr)); 303 pio_write_32(bus->conf_data_port, host2uint32_t_le(val)); 283 304 284 305 fibril_mutex_unlock(&bus->conf_mutex);
Note:
See TracChangeset
for help on using the changeset viewer.