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 /// VMBUS info for VTL2.
60 pub vmbus_vtl2: VmbusInfo,
61 /// VMBUS info for VTL0.
62 pub vmbus_vtl0: VmbusInfo,
63 /// Command line to be used for the underhill kernel.
64 pub cmdline: ArrayString<COMMAND_LINE_SIZE>,
65 /// Com3 serial device is available
66 pub com3_serial_available: bool,
67 /// Memory allocation mode that was performed.
68 pub memory_allocation_mode: MemoryAllocationMode,
69 /// Entropy from the host to be used by the OpenHCL kernel
70 pub entropy: Option<ArrayVec<u8, MAX_ENTROPY_SIZE>>,
71 /// The VTL0 alias map physical address.
72 pub vtl0_alias_map: Option<u64>,
73 /// Host is compatible with DMA preservation / NVMe keep-alive.
74 pub nvme_keepalive: bool,
75 /// Parsed boot command line options.
76 pub boot_options: BootCommandLineOptions,
77
78 /// GIC information on AArch64.
79 pub gic: Option<GicInfo>,
80 /// PMU GSIV on AArch64.
81 pub pmu_gsiv: Option<u32>,
82}
83
84impl PartitionInfo {
85 /// Create an empty [`PartitionInfo`].
86 pub const fn new() -> Self {
87 PartitionInfo {
88 vtl2_ram: ArrayVec::new_const(),
89 partition_ram: ArrayVec::new_const(),
90 isolation: IsolationType::None,
91 bsp_reg: 0,
92 cpus: ArrayVec::new_const(),
93 vmbus_vtl2: VmbusInfo {
94 mmio: ArrayVec::new_const(),
95 connection_id: 0,
96 },
97 vmbus_vtl0: VmbusInfo {
98 mmio: ArrayVec::new_const(),
99 connection_id: 0,
100 },
101 cmdline: ArrayString::new_const(),
102 com3_serial_available: false,
103 memory_allocation_mode: MemoryAllocationMode::Host,
104 entropy: None,
105 vtl0_alias_map: None,
106 nvme_keepalive: false,
107 boot_options: BootCommandLineOptions::new(),
108 gic: None,
109 pmu_gsiv: None,
110 }
111 }
112}