mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-18 10:35:23 +00:00
pci: vfio: Move find_region() to VfioCommon
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
ecc8382ff0
commit
2ff193456d
@ -794,6 +794,17 @@ impl VfioCommon {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn find_region(&self, addr: u64) -> Option<MmioRegion> {
|
||||||
|
for region in self.mmio_regions.iter() {
|
||||||
|
if addr >= region.start.raw_value()
|
||||||
|
&& addr < region.start.unchecked_add(region.length).raw_value()
|
||||||
|
{
|
||||||
|
return Some(*region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// VfioPciDevice represents a VFIO PCI device.
|
/// VfioPciDevice represents a VFIO PCI device.
|
||||||
@ -868,17 +879,6 @@ impl VfioPciDevice {
|
|||||||
self.iommu_attached
|
self.iommu_attached
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_region(&self, addr: u64) -> Option<MmioRegion> {
|
|
||||||
for region in self.common.mmio_regions.iter() {
|
|
||||||
if addr >= region.start.raw_value()
|
|
||||||
&& addr < region.start.unchecked_add(region.length).raw_value()
|
|
||||||
{
|
|
||||||
return Some(*region);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Map MMIO regions into the guest, and avoid VM exits when the guest tries
|
/// Map MMIO regions into the guest, and avoid VM exits when the guest tries
|
||||||
/// to reach those regions.
|
/// to reach those regions.
|
||||||
///
|
///
|
||||||
@ -1182,7 +1182,7 @@ impl PciDevice for VfioPciDevice {
|
|||||||
|
|
||||||
fn read_bar(&mut self, base: u64, offset: u64, data: &mut [u8]) {
|
fn read_bar(&mut self, base: u64, offset: u64, data: &mut [u8]) {
|
||||||
let addr = base + offset;
|
let addr = base + offset;
|
||||||
if let Some(region) = self.find_region(addr) {
|
if let Some(region) = self.common.find_region(addr) {
|
||||||
let offset = addr - region.start.raw_value();
|
let offset = addr - region.start.raw_value();
|
||||||
|
|
||||||
if self
|
if self
|
||||||
@ -1208,7 +1208,7 @@ impl PciDevice for VfioPciDevice {
|
|||||||
|
|
||||||
fn write_bar(&mut self, base: u64, offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
|
fn write_bar(&mut self, base: u64, offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
|
||||||
let addr = base + offset;
|
let addr = base + offset;
|
||||||
if let Some(region) = self.find_region(addr) {
|
if let Some(region) = self.common.find_region(addr) {
|
||||||
let offset = addr - region.start.raw_value();
|
let offset = addr - region.start.raw_value();
|
||||||
|
|
||||||
// If the MSI-X table is written to, we need to update our cache.
|
// If the MSI-X table is written to, we need to update our cache.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user