summary refs log tree commit diff
path: root/resources
diff options
context:
space:
mode:
authorXiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>2019-10-29 17:32:44 +0800
committerCommit Bot <commit-bot@chromium.org>2019-11-10 06:39:31 +0000
commit87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1 (patch)
tree29bc942019a2cdb32d292c4650eccb5cf0deaddf /resources
parent279248255f9f65c6baf044f1fbff0011bcd9938a (diff)
downloadcrosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.gz
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.bz2
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.lz
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.xz
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.tar.zst
crosvm-87a3b44d9e6caa82ab521a5dd9bafdb56e8b6ed1.zip
Resource: Unify mmio allocator
Current mmio and device two allocators exist, the purpose to define
two allocator is:
Accessing to gpa from mmio allocator cause vm exit, while gpa from
device allocator doesn't cause vm exit.

Whether vm exits exist or not, dependency on whether
vm->add_device_memory() is called with gpa from allocator or not.Even
if gpa is from mmio alloator, and vm->add_device_memory() is called
with this gpa, accessing this gpa won't cause vm exit. So mmio allocator
and device allocator couldn't guarantee the original purpose.

This patch unify mmio allocator and device allocator into one mmio
allocator.

BUG=chromium:992270
TEST=this patch doesn't change function, so just run build_test

Change-Id: If87d5c2838eb122ef627fa45c394b1b3ccfafeb0
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895233
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'resources')
-rw-r--r--resources/src/lib.rs2
-rw-r--r--resources/src/system_allocator.rs29
2 files changed, 19 insertions, 12 deletions
diff --git a/resources/src/lib.rs b/resources/src/lib.rs
index ce4855a..27f6abc 100644
--- a/resources/src/lib.rs
+++ b/resources/src/lib.rs
@@ -17,7 +17,7 @@ pub use crate::address_allocator::AddressAllocator;
 pub use crate::gpu_allocator::{
     GpuAllocatorError, GpuMemoryAllocator, GpuMemoryDesc, GpuMemoryPlaneDesc,
 };
-pub use crate::system_allocator::SystemAllocator;
+pub use crate::system_allocator::{MmioType, SystemAllocator};
 
 mod address_allocator;
 mod gpu_allocator;
diff --git a/resources/src/system_allocator.rs b/resources/src/system_allocator.rs
index 6cdb70e..b3a3062 100644
--- a/resources/src/system_allocator.rs
+++ b/resources/src/system_allocator.rs
@@ -13,7 +13,7 @@ use crate::{Alloc, Error, Result};
 /// # Example - Use the `SystemAddress` builder.
 ///
 /// ```
-/// # use resources::{Alloc, SystemAllocator};
+/// # use resources::{Alloc, MmioType, SystemAllocator};
 ///   if let Ok(mut a) = SystemAllocator::builder()
 ///           .add_io_addresses(0x1000, 0x10000)
 ///           .add_device_addresses(0x10000000, 0x10000000)
@@ -22,7 +22,7 @@ use crate::{Alloc, Error, Result};
 ///       assert_eq!(a.allocate_irq(), Some(5));
 ///       assert_eq!(a.allocate_irq(), Some(6));
 ///       assert_eq!(
-///           a.device_allocator()
+///           a.mmio_allocator(MmioType::Device)
 ///              .allocate(
 ///                  0x100,
 ///                  Alloc::PciBar { bus: 0, dev: 0, bar: 0 },
@@ -31,11 +31,20 @@ use crate::{Alloc, Error, Result};
 ///           Ok(0x10000000)
 ///       );
 ///       assert_eq!(
-///           a.device_allocator().get(&Alloc::PciBar { bus: 0, dev: 0, bar: 0 }),
+///           a.mmio_allocator(MmioType::Device).get(&Alloc::PciBar { bus: 0, dev: 0, bar: 0 }),
 ///           Some(&(0x10000000, 0x100, "bar0".to_string()))
 ///       );
 ///   }
 /// ```
+
+/// MMIO address Type
+///    Mmio: address allocated from mmio_address_space
+///    Device: address allocated from device_address_space
+pub enum MmioType {
+    Mmio,
+    Device,
+}
+
 #[derive(Debug)]
 pub struct SystemAllocator {
     io_address_space: Option<AddressAllocator>,
@@ -108,14 +117,12 @@ impl SystemAllocator {
         self.io_address_space.as_mut()
     }
 
-    /// Gets an allocator to be used for device memory.
-    pub fn device_allocator(&mut self) -> &mut AddressAllocator {
-        &mut self.device_address_space
-    }
-
-    /// Gets an allocator to be used for MMIO memory.
-    pub fn mmio_allocator(&mut self) -> &mut AddressAllocator {
-        &mut self.mmio_address_space
+    /// Gets an allocator to be used for MMIO allocation.
+    pub fn mmio_allocator(&mut self, mmio_type: MmioType) -> &mut AddressAllocator {
+        match mmio_type {
+            MmioType::Device => &mut self.device_address_space,
+            MmioType::Mmio => &mut self.mmio_address_space,
+        }
     }
 
     /// Gets an allocator to be used for GPU memory.