vmm: Use new Resource type PciBar

Instead of defining some very generic resources as PioAddressRange or
MmioAddressRange for each PCI BAR, let's move to the new Resource type
PciBar in order to make things clearer. This allows the code for being
more readable, but also removes the need for hard assumptions about the
MMIO and PIO ranges. PioAddressRange and MmioAddressRange types can be
used to describe everything except PCI BARs. BARs are very special as
they can be relocated and have special information we want to carry
along with them.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-04-15 11:27:53 +02:00
committed by Bo Chen
parent 89218b6d1e
commit 11e9f43305
6 changed files with 89 additions and 63 deletions
+10 -11
View File
@@ -376,18 +376,17 @@ impl VfioCommon {
let region_size: u64;
let bar_addr: GuestAddress;
let restored_bar_addr = if let Some(resources) = &resources {
match resources
.get(bars.len())
.ok_or(PciDeviceError::MissingResource)?
{
Resource::MmioAddressRange { base, .. } => Some(GuestAddress(*base)),
Resource::PioAddressRange { base, .. } => Some(GuestAddress(*base as u64)),
_ => return Err(PciDeviceError::InvalidResourceType),
let mut restored_bar_addr = None;
if let Some(resources) = &resources {
for resource in resources {
if let Resource::PciBar { index, base, .. } = resource {
if *index == bar_id as usize {
restored_bar_addr = Some(GuestAddress(*base));
break;
}
}
}
} else {
None
};
}
let bar_offset = if bar_id == VFIO_PCI_ROM_REGION_INDEX {
(PCI_ROM_EXP_BAR_INDEX * 4) as u32