[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.
@@ -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;
}
