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