summary refs log tree commit diff
path: root/resources
diff options
context:
space:
mode:
authorDaniel Prilik <prilik@google.com>2019-03-25 16:17:09 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-17 17:23:02 -0700
commit7303d2c491f9c679bcbc506100adef81baefe30c (patch)
tree924d8b8f06e3c5c556e69b8a63c8454fa63b47d9 /resources
parentfd8cad3fd2ddcc07163586a0aff13b81dc9f4999 (diff)
downloadcrosvm-7303d2c491f9c679bcbc506100adef81baefe30c.tar
crosvm-7303d2c491f9c679bcbc506100adef81baefe30c.tar.gz
crosvm-7303d2c491f9c679bcbc506100adef81baefe30c.tar.bz2
crosvm-7303d2c491f9c679bcbc506100adef81baefe30c.tar.lz
crosvm-7303d2c491f9c679bcbc506100adef81baefe30c.tar.xz
crosvm-7303d2c491f9c679bcbc506100adef81baefe30c.tar.zst
crosvm-7303d2c491f9c679bcbc506100adef81baefe30c.zip
resources: add build method to SystemAllocator
AddressRanges' name doesn't suggest that it's a SystemAllocator builder.
This CL renames it to SystemAllocatorBuilder, and adds a
SystemAllocator::builder() that removes the need to have a separate
import for the Builder.

A minor change, but it cleans up the interface a bit.

BUG=chromium:936567
TEST=cargo test -p resources && cargo build

Change-Id: I6d14368490c0d3c4018858f541e4ae5390995878
Reviewed-on: https://chromium-review.googlesource.com/1540398
Commit-Ready: Daniel Prilik <prilik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'resources')
-rw-r--r--resources/src/lib.rs2
-rw-r--r--resources/src/system_allocator.rs15
2 files changed, 11 insertions, 6 deletions
diff --git a/resources/src/lib.rs b/resources/src/lib.rs
index 602c390..b16b2da 100644
--- a/resources/src/lib.rs
+++ b/resources/src/lib.rs
@@ -10,4 +10,4 @@ mod system_allocator;
 
 pub use crate::address_allocator::AddressAllocator;
 pub use crate::gpu_allocator::{GpuMemoryAllocator, GpuMemoryDesc, GpuMemoryPlaneDesc};
-pub use crate::system_allocator::{AddressRanges, SystemAllocator};
+pub use crate::system_allocator::SystemAllocator;
diff --git a/resources/src/system_allocator.rs b/resources/src/system_allocator.rs
index 8cde454..3cc564d 100644
--- a/resources/src/system_allocator.rs
+++ b/resources/src/system_allocator.rs
@@ -12,8 +12,8 @@ use crate::gpu_allocator::{self, GpuMemoryAllocator};
 /// # Example - Use the `SystemAddress` builder.
 ///
 /// ```
-/// # use resources::AddressRanges;
-///   if let Some(mut a) = AddressRanges::new()
+/// # use resources::SystemAllocator;
+///   if let Some(mut a) = SystemAllocator::builder()
 ///           .add_io_addresses(0x1000, 0x10000)
 ///           .add_device_addresses(0x10000000, 0x10000000)
 ///           .add_mmio_addresses(0x30000000, 0x10000)
@@ -72,6 +72,11 @@ impl SystemAllocator {
         })
     }
 
+    /// Returns a `SystemAllocatorBuilder` that can create a new `SystemAllocator`.
+    pub fn builder() -> SystemAllocatorBuilder {
+        SystemAllocatorBuilder::new()
+    }
+
     /// Reserves the next available system irq number.
     pub fn allocate_irq(&mut self) -> Option<u32> {
         if let Some(irq_num) = self.next_irq.checked_add(1) {
@@ -104,7 +109,7 @@ impl SystemAllocator {
 }
 
 /// Used to build a system address map for use in creating a `SystemAllocator`.
-pub struct AddressRanges {
+pub struct SystemAllocatorBuilder {
     io_base: Option<u64>,
     io_size: Option<u64>,
     mmio_base: Option<u64>,
@@ -113,9 +118,9 @@ pub struct AddressRanges {
     device_size: Option<u64>,
 }
 
-impl AddressRanges {
+impl SystemAllocatorBuilder {
     pub fn new() -> Self {
-        AddressRanges {
+        SystemAllocatorBuilder {
             io_base: None,
             io_size: None,
             mmio_base: None,