Skip to content

Commit 4739af9

Browse files
committed
pci: fix: write both masks at once in 64bit BAR sizing
1 parent ea81953 commit 4739af9

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/pci.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,23 @@ static int pci_program_bar(uint8_t bus, uint8_t dev, uint8_t fun,
442442
bar_align = bar_value & PCI_ENUM_MM_BAR_MASK;
443443
is_prefetch = pci_enum_is_prefetch(bar_value);
444444
if (pci_enum_is_64bit(bar_value)) {
445+
*is_64bit = 1;
445446
orig_bar2 = pci_config_read32(bus, dev, fun, bar_off + 4);
447+
448+
/* rewrite 0xff..ff mask and re-read the first BAR value, specs
449+
* requires to wirte the mask on both registers before reading
450+
* the sizes back */
451+
pci_config_write32(bus, dev, fun, bar_off, 0xffffffff);
446452
pci_config_write32(bus, dev, fun, bar_off + 4, 0xffffffff);
453+
bar_value = pci_config_read32(bus, dev,fun, bar_off);
454+
bar_align = bar_value & PCI_ENUM_MM_BAR_MASK;
447455
reg = pci_config_read32(bus, dev, fun, bar_off + 4);
448456
PCI_DEBUG_PRINTF("bar high 32bit: %d\r\n", reg);
449457
if (reg != 0xffffffff) {
450458
PCI_DEBUG_PRINTF("Device wants too much memory, skipping\r\n");
451459
pci_config_write32(bus, dev, fun, bar_off + 4, orig_bar2);
452460
goto restore_bar;
453461
}
454-
*is_64bit = 1;
455462
}
456463
if (is_prefetch) {
457464
base = &info->mem_pf;

0 commit comments

Comments
 (0)