pub struct AddressAllocator {
    pools: Vec<AddressRange>,
    min_align: u64,
    preferred_align: u64,
    allocs: HashMap<Alloc, (AddressRange, String)>,
    regions: BTreeSet<AddressRange>,
}
Expand description

Manages allocating address ranges. Use AddressAllocator whenever an address range needs to be allocated to different users. Allocations must be uniquely tagged with an Alloc enum, which can be used for lookup. An human-readable tag String must also be provided for debugging / reference.

Fields§

§pools: Vec<AddressRange>

The list of pools from which address are allocated. The union of all regions from |allocs| and |regions| equals the pools.

§min_align: u64§preferred_align: u64§allocs: HashMap<Alloc, (AddressRange, String)>

The region that is allocated.

§regions: BTreeSet<AddressRange>

The region that is not allocated yet.

Implementations§

source§

impl AddressAllocator

source

pub fn new( pool: AddressRange, min_align: Option<u64>, preferred_align: Option<u64> ) -> Result<Self>

Creates a new AddressAllocator for managing a range of addresses. Can return an error if pool is empty or if alignment isn’t a power of two.

  • pool - The address range to allocate from.
  • min_align - The minimum size of an address region to align to, defaults to four.
  • preferred_align - The preferred alignment of an address region, used if possible.

If an allocation cannot be satisfied with the preferred alignment, the minimum alignment will be used instead.

source

pub fn new_from_list<T>( pools: T, min_align: Option<u64>, preferred_align: Option<u64> ) -> Result<Self>
where T: IntoIterator<Item = AddressRange>,

Creates a new AddressAllocator for managing a range of addresses. Can return None if all pools are empty alignment isn’t a power of two.

  • pools - The list of pools to initialize the allocator with.
  • min_align - The minimum size of an address region to align to, defaults to four.
  • preferred_align - The preferred alignment of an address region, used if possible.

If an allocation cannot be satisfied with the preferred alignment, the minimum alignment will be used instead.

source

pub fn pools(&self) -> &[AddressRange]

Gets the regions managed by the allocator.

This returns the original pools value provided to AddressAllocator::new().

source

fn internal_allocate_from_slot( &mut self, slot: AddressRange, range: AddressRange, alloc: Alloc, tag: String ) -> Result<u64>

source

fn internal_allocate_with_align( &mut self, size: u64, alloc: Alloc, tag: String, alignment: u64, reverse: bool ) -> Result<u64>

source

pub fn reverse_allocate_with_align( &mut self, size: u64, alloc: Alloc, tag: String, alignment: u64 ) -> Result<u64>

Allocates a range of addresses from the reverse managed region with an optional tag and minimal alignment. Returns allocated_address. (allocated_address, size, tag) can be retrieved through the get method.

source

pub fn reverse_allocate( &mut self, size: u64, alloc: Alloc, tag: String ) -> Result<u64>

Allocates a range of addresses, preferring to allocate from high rather than low addresses.

source

pub fn allocate_with_align( &mut self, size: u64, alloc: Alloc, tag: String, alignment: u64 ) -> Result<u64>

Allocates a range of addresses from the managed region with an optional tag and minimal alignment. Returns allocated_address. (allocated_address, size, tag) can be retrieved through the get method.

source

pub fn allocate(&mut self, size: u64, alloc: Alloc, tag: String) -> Result<u64>

source

pub fn allocate_at( &mut self, range: AddressRange, alloc: Alloc, tag: String ) -> Result<()>

Allocates a range of addresses from the managed region with an optional tag and required location. Allocation alignment is not enforced. Returns OutOfSpace if requested range is not available or ExistingAlloc if the requested range overlaps an existing allocation.

source

pub fn release(&mut self, alloc: Alloc) -> Result<AddressRange>

Releases exising allocation back to free pool and returns the range that was released.

source

pub fn release_containing(&mut self, value: u64) -> Result<AddressRange>

Release a allocation contains the value.

source

fn find_overlapping(&self, range: AddressRange) -> Option<Alloc>

source

pub fn get_max_addr(&self) -> u64

source

pub fn get(&self, alloc: &Alloc) -> Option<&(AddressRange, String)>

Returns allocation associated with alloc, or None if no such allocation exists.

source

fn insert_at(&mut self, slot: AddressRange) -> Result<()>

Insert range of addresses into the pool, coalescing neighboring regions.

source

pub fn address_from_pci_offset( &self, alloc: Alloc, offset: u64, size: u64 ) -> Result<u64>

Returns an address from associated PCI alloc given an allocation offset and size.

Trait Implementations§

source§

impl Debug for AddressAllocator

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for AddressAllocator

source§

fn eq(&self, other: &AddressAllocator) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for AddressAllocator

source§

impl StructuralPartialEq for AddressAllocator

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.