Skip to main content

openhcl_boot/host_params/
mod.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Module used to parse the host parameters used to setup Underhill. These are
5//! provided via a device tree IGVM parameter.
6
7use crate::cmdline::BootCommandLineOptions;
8use crate::host_params::shim_params::IsolationType;
9use arrayvec::ArrayString;
10use arrayvec::ArrayVec;
11use host_fdt_parser::CpuEntry;
12use host_fdt_parser::GicInfo;
13use host_fdt_parser::MemoryAllocationMode;
14use host_fdt_parser::MemoryEntry;
15use host_fdt_parser::VmbusInfo;
16
17mod dt;
18mod mmio;
19pub mod shim_params;
20
21/// Maximum supported cpu count by underhill.
22pub const MAX_CPU_COUNT: usize = 2048;
23
24/// The maximum number of supported virtual NUMA nodes. This must be at least as
25/// large as whatever the host supports.
26pub const MAX_NUMA_NODES: usize = 64;
27
28pub const COMMAND_LINE_SIZE: usize = 0x2000;
29
30/// Each ram range reported by the host for VTL2 is split per NUMA node.
31///
32/// Today, Hyper-V has a max limit of 64 NUMA nodes, so we should only ever see
33/// 64 ram ranges.
34pub const MAX_VTL2_RAM_RANGES: usize = 64;
35
36/// The maximum number of ram ranges that can be read from the host.
37const MAX_PARTITION_RAM_RANGES: usize = 1024;
38
39/// Maximum size of the host-provided entropy
40pub const MAX_ENTROPY_SIZE: usize = 256;
41
42/// Information about the guest partition.
43#[derive(Debug)]
44pub struct PartitionInfo {
45    /// Ram assigned to VTL2. This is either parsed from the host via IGVM
46    /// parameters, allocated dynamically, or the fixed at build value.
47    ///
48    /// This vec is guaranteed to be sorted, and non-overlapping.
49    pub vtl2_ram: ArrayVec<MemoryEntry, MAX_VTL2_RAM_RANGES>,
50    /// The full memory map provided by the host.
51    pub partition_ram: ArrayVec<MemoryEntry, MAX_PARTITION_RAM_RANGES>,
52    /// The partiton's isolation type.
53    pub isolation: IsolationType,
54    /// The reg field in device tree for the BSP. This is either the apic_id on
55    /// x64, or mpidr on aarch64.
56    pub bsp_reg: u32,
57    /// Cpu info for enabled cpus.
58    pub cpus: ArrayVec<CpuEntry, MAX_CPU_COUNT>,
59    /// Per-CPU state to apply when starting the sidecar kernel.
60    pub sidecar_cpu_overrides: sidecar_defs::PerCpuState,
61    /// VMBUS info for VTL2.
62    pub vmbus_vtl2: VmbusInfo,
63    /// VMBUS info for VTL0.
64    pub vmbus_vtl0: VmbusInfo,
65    /// Command line to be used for the underhill kernel.
66    pub cmdline: ArrayString<COMMAND_LINE_SIZE>,
67    /// Com3 serial device is available
68    pub com3_serial_available: bool,
69    /// Memory allocation mode that was performed.
70    pub memory_allocation_mode: MemoryAllocationMode,
71    /// Entropy from the host to be used by the OpenHCL kernel
72    pub entropy: Option<ArrayVec<u8, MAX_ENTROPY_SIZE>>,
73    /// The VTL0 alias map physical address.
74    pub vtl0_alias_map: Option<u64>,
75    /// Host is compatible with DMA preservation / NVMe keep-alive.
76    pub nvme_keepalive: bool,
77    /// Parsed boot command line options.
78    pub boot_options: BootCommandLineOptions,
79
80    /// GIC information on AArch64.
81    pub gic: Option<GicInfo>,
82    /// PMU GSIV on AArch64.
83    pub pmu_gsiv: Option<u32>,
84}
85
86impl PartitionInfo {
87    /// Create an empty [`PartitionInfo`].
88    pub const fn new() -> Self {
89        PartitionInfo {
90            vtl2_ram: ArrayVec::new_const(),
91            partition_ram: ArrayVec::new_const(),
92            isolation: IsolationType::None,
93            bsp_reg: 0,
94            cpus: ArrayVec::new_const(),
95            sidecar_cpu_overrides: sidecar_defs::PerCpuState {
96                per_cpu_state_specified: false,
97                sidecar_starts_cpu: [true; sidecar_defs::NUM_CPUS_SUPPORTED_FOR_PER_CPU_STATE],
98            },
99            vmbus_vtl2: VmbusInfo {
100                mmio: ArrayVec::new_const(),
101                connection_id: 0,
102            },
103            vmbus_vtl0: VmbusInfo {
104                mmio: ArrayVec::new_const(),
105                connection_id: 0,
106            },
107            cmdline: ArrayString::new_const(),
108            com3_serial_available: false,
109            memory_allocation_mode: MemoryAllocationMode::Host,
110            entropy: None,
111            vtl0_alias_map: None,
112            nvme_keepalive: false,
113            boot_options: BootCommandLineOptions::new(),
114            gic: None,
115            pmu_gsiv: None,
116        }
117    }
118}