Skip to content

Commit 7147c9f

Browse files
committed
pci: fix: config_io_read16/write16: use off instead of addr
1 parent eb5f65c commit 7147c9f

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/pci.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,44 +227,44 @@ static void pci_io_config_write32(uint32_t bus, uint32_t dev, uint32_t func,
227227
static uint16_t pci_io_config_read16(uint32_t bus, uint32_t dev, uint32_t func,
228228
uint32_t off)
229229
{
230-
uint32_t address = PCI_IO_CONFIG_ADDR(bus, dev, func, off);
231-
uint32_t data = 0xffff;
230+
uint32_t data;
232231
int aligned32;
232+
uint32_t off_aligned;
233233

234234
/* off must be 16 bit aligned */
235-
if ((address & PCI_ADDR_16BIT_ALIGNED_MASK) != 0)
236-
return data;
235+
if ((off & PCI_ADDR_16BIT_ALIGNED_MASK) != 0)
236+
return 0xffff;
237237

238-
address = pci_align32_address(address, &aligned32);
239-
data = pci_io_config_read32(bus, dev, func, address);
240-
if (!aligned32)
241-
data >>= PCI_DATA_HI16_SHIFT;
242-
else
238+
off_aligned = pci_align32_address(off, &aligned32);
239+
data = pci_io_config_read32(bus, dev, func, off_aligned);
240+
if (aligned32)
243241
data &= PCI_DATA_LO16_MASK;
242+
else
243+
data >>= PCI_DATA_HI16_SHIFT;
244244
return (uint16_t)data;
245245
}
246246

247247
static void pci_io_config_write16(uint32_t bus, uint32_t dev, uint32_t func,
248248
uint32_t off, uint16_t val)
249249
{
250-
uint32_t dst_addr = PCI_IO_CONFIG_ADDR(bus, dev, func, off);
250+
uint32_t off_aligned;
251251
uint32_t reg;
252252
int aligned32;
253253

254254
/* off must be 16 bit aligned */
255-
if ((dst_addr & PCI_ADDR_16BIT_ALIGNED_MASK) != 0)
255+
if ((off & PCI_ADDR_16BIT_ALIGNED_MASK) != 0)
256256
return;
257257

258-
dst_addr = pci_align32_address(dst_addr, &aligned32);
259-
reg = pci_io_config_read32(bus, dev, func, dst_addr);
258+
off_aligned = pci_align32_address(off, &aligned32);
259+
reg = pci_io_config_read32(bus, dev, func, off_aligned);
260260
if (aligned32) {
261261
reg &= PCI_DATA_HI16_MASK;
262262
reg |= val;
263263
} else {
264264
reg &= PCI_DATA_LO16_MASK;
265265
reg |= (val << PCI_DATA_HI16_SHIFT);
266266
}
267-
pci_io_config_write32(bus, dev, func, dst_addr, reg);
267+
pci_io_config_write32(bus, dev, func, off_aligned, reg);
268268
}
269269
#endif /* PCI_USE_ECAM */
270270

0 commit comments

Comments
 (0)