Skip to main content

Module layout

Module layout 

Source
Expand description

VM address-space layout allocator.

This module provides a pure-math layout allocator that places reserved and fixed ranges, 32-bit MMIO, ordinary RAM, 64-bit MMIO, and post-MMIO ranges in a flat guest physical address map. It has no knowledge of specific architectures, firmware types, or chipset conventions; callers express those policies as reserved/fixed ranges and dynamic requests.

§Usage

use memory_range::MemoryRange;
use vm_topology::layout::{LayoutBuilder, Placement};

let mut ram = Vec::new();
let mut vmbus = MemoryRange::EMPTY;

let mut builder = LayoutBuilder::new();
builder.fixed(
    "reserved",
    MemoryRange::new(0xFE00_0000..0x1_0000_0000),
);
builder.request(
    "vmbus",
    &mut vmbus,
    128 * 1024 * 1024,
    1024 * 1024,
    Placement::Mmio32,
);
builder.ram("ram", &mut ram, 2 * 1024 * 1024 * 1024, 4096);

let sorted = builder.allocate().unwrap();
assert_eq!(ram, [MemoryRange::new(0..0x8000_0000)]);
assert_eq!(vmbus.end(), 0xFE00_0000);
assert_eq!(sorted.len(), 3);

Structs§

LayoutBuilder
A builder for computing a deterministic VM address-space layout.
PlacedRange
A placed range returned by LayoutBuilder::allocate.

Enums§

AllocateError
Error returned by LayoutBuilder::allocate.
AllocationPhase
Allocation phase reported in AllocateError::Exhausted.
PlacedRangeKind
The kind of a produced allocation.
Placement
The placement class for a dynamic single-range layout request.