[bus][pci] Disable IO and mem decoding around BAR enumeration

Disable IO and mem decoding around BAR enumation as described in the PCI
Local Bus specification. This behavior should be safer when messing
around BARs for BAR lengths.
This commit is contained in:
Pedro Falcato
2022-12-31 03:12:16 +00:00
committed by Travis Geiselbrecht
parent 91d0a5f7d1
commit 3b4dade91f

View File

@@ -338,6 +338,14 @@ status_t device::load_bars() {
return ERR_NOT_SUPPORTED;
}
// Disable IO and MEM decoding around BAR detection, as we fiddle with
// BAR addresses themselves for length detection.
// This behavior is recommended by the PCI Local Bus Specification.
uint16_t command;
pci_read_config_half(loc(), PCI_CONFIG_COMMAND, &command);
pci_write_config_half(loc(), PCI_CONFIG_COMMAND, command & ~(PCI_COMMAND_IO_EN | PCI_COMMAND_MEM_EN));
for (size_t i=0; i < num_bars; i++) {
bars_[i] = {};
uint64_t bar_addr = config_.type0.base_addresses[i];
@@ -411,6 +419,9 @@ status_t device::load_bars() {
}
}
// Restore any IO and MEM decoding that was enabled before
pci_write_config_half(loc(), PCI_CONFIG_COMMAND, command);
return NO_ERROR;
}