1use bitfield_struct::bitfield;
7use core::mem::size_of;
8use hvdef::HV_PAGE_SIZE;
9#[cfg(feature = "inspect")]
10use inspect::Inspect;
11use open_enum::open_enum;
12use static_assertions::const_assert_eq;
13use zerocopy::FromBytes;
14use zerocopy::Immutable;
15use zerocopy::IntoBytes;
16use zerocopy::KnownLayout;
17
18pub const PARAVISOR_CONFIG_SLIT_SIZE_PAGES: u64 = 20;
22pub const PARAVISOR_CONFIG_PPTT_SIZE_PAGES: u64 = 20;
24pub const PARAVISOR_CONFIG_DEVICE_TREE_SIZE_PAGES: u64 = 64;
26
27pub const PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_PAGE_COUNT_MAX: u64 =
29 PARAVISOR_CONFIG_SLIT_SIZE_PAGES
30 + PARAVISOR_CONFIG_PPTT_SIZE_PAGES
31 + PARAVISOR_CONFIG_DEVICE_TREE_SIZE_PAGES;
32
33pub const PARAVISOR_CONFIG_SLIT_PAGE_INDEX: u64 = 0;
36pub const PARAVISOR_CONFIG_PPTT_PAGE_INDEX: u64 =
38 PARAVISOR_CONFIG_SLIT_PAGE_INDEX + PARAVISOR_CONFIG_SLIT_SIZE_PAGES;
39pub const PARAVISOR_CONFIG_DEVICE_TREE_PAGE_INDEX: u64 =
41 PARAVISOR_CONFIG_PPTT_PAGE_INDEX + PARAVISOR_CONFIG_PPTT_SIZE_PAGES;
42pub const PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_BASE_INDEX: u64 =
44 PARAVISOR_CONFIG_SLIT_PAGE_INDEX;
45
46pub const PARAVISOR_RESERVED_VTL2_SNP_CPUID_SIZE_PAGES: u64 = 2;
48pub const PARAVISOR_RESERVED_VTL2_SNP_VMSA_SIZE_PAGES: u64 = 1;
50pub const PARAVISOR_RESERVED_VTL2_SNP_SECRETS_SIZE_PAGES: u64 = 1;
52
53pub const PARAVISOR_RESERVED_VTL2_PAGE_COUNT_MAX: u64 = PARAVISOR_RESERVED_VTL2_SNP_CPUID_SIZE_PAGES
55 + PARAVISOR_RESERVED_VTL2_SNP_VMSA_SIZE_PAGES
56 + PARAVISOR_RESERVED_VTL2_SNP_SECRETS_SIZE_PAGES;
57
58pub const PARAVISOR_RESERVED_VTL2_SNP_VMSA_PAGE_INDEX: u64 = 0;
67pub const PARAVISOR_RESERVED_VTL2_SNP_CPUID_PAGE_INDEX: u64 =
69 PARAVISOR_RESERVED_VTL2_SNP_VMSA_PAGE_INDEX + PARAVISOR_RESERVED_VTL2_SNP_VMSA_SIZE_PAGES;
70pub const PARAVISOR_RESERVED_VTL2_SNP_SECRETS_PAGE_INDEX: u64 =
72 PARAVISOR_RESERVED_VTL2_SNP_CPUID_PAGE_INDEX + PARAVISOR_RESERVED_VTL2_SNP_CPUID_SIZE_PAGES;
73
74pub const PARAVISOR_MEASURED_VTL2_CONFIG_ACCEPTED_MEMORY_SIZE_PAGES: u64 = 1;
78pub const PARAVISOR_MEASURED_VTL2_CONFIG_SIZE_PAGES: u64 = 1;
80
81pub const PARAVISOR_MEASURED_VTL2_CONFIG_REGION_PAGE_COUNT: u64 =
83 PARAVISOR_MEASURED_VTL2_CONFIG_ACCEPTED_MEMORY_SIZE_PAGES
84 + PARAVISOR_MEASURED_VTL2_CONFIG_SIZE_PAGES;
85
86pub const PARAVISOR_MEASURED_VTL2_CONFIG_ACCEPTED_MEMORY_PAGE_INDEX: u64 =
89 PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_BASE_INDEX
90 + PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_PAGE_COUNT_MAX;
91
92pub const PARAVISOR_MEASURED_VTL2_CONFIG_PAGE_INDEX: u64 =
94 PARAVISOR_MEASURED_VTL2_CONFIG_ACCEPTED_MEMORY_PAGE_INDEX
95 + PARAVISOR_MEASURED_VTL2_CONFIG_ACCEPTED_MEMORY_SIZE_PAGES;
96
97pub const PARAVISOR_VTL2_CONFIG_REGION_PAGE_COUNT_MAX: u64 =
99 PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_PAGE_COUNT_MAX
100 + PARAVISOR_MEASURED_VTL2_CONFIG_REGION_PAGE_COUNT; pub const PARAVISOR_DEFAULT_MEMORY_BASE_ADDRESS: u64 = 128 * 1024 * 1024;
105pub const PARAVISOR_DEFAULT_MEMORY_PAGE_COUNT: u64 = 64 * 1024 * 1024 / HV_PAGE_SIZE;
107pub const PARAVISOR_LOCAL_MAP_VA: u64 = 0x200000;
109pub const PARAVISOR_LOCAL_MAP_SIZE: u64 = 0x200000;
111
112open_enum! {
113 #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
115 pub enum CommandLinePolicy : u16 {
116 STATIC = 0,
118 APPEND_CHOSEN = 1,
121 }
122}
123
124pub const COMMAND_LINE_SIZE: usize = 4092;
126
127#[repr(C)]
129#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
130pub struct ParavisorCommandLine {
131 pub policy: CommandLinePolicy,
133 pub static_command_line_len: u16,
135 pub static_command_line: [u8; COMMAND_LINE_SIZE],
140}
141
142impl ParavisorCommandLine {
143 pub fn command_line(&self) -> Option<&str> {
146 core::str::from_utf8(&self.static_command_line[..self.static_command_line_len as usize])
147 .ok()
148 }
149}
150
151const_assert_eq!(size_of::<ParavisorCommandLine>(), HV_PAGE_SIZE as usize);
152
153#[repr(C)]
155#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, PartialEq)]
156pub struct PageRegionDescriptor {
157 pub base_page_number: u64,
159 pub page_count: u64,
161}
162
163#[cfg(feature = "inspect")]
164impl Inspect for PageRegionDescriptor {
165 fn inspect(&self, req: inspect::Request<'_>) {
166 let pages = self.pages();
167
168 match pages {
169 None => {
170 req.ignore();
171 }
172 Some((base, count)) => {
173 req.respond()
174 .field("base_page_number", base)
175 .field("page_count", count);
176 }
177 }
178 }
179}
180
181impl PageRegionDescriptor {
182 pub const EMPTY: Self = PageRegionDescriptor {
184 base_page_number: 0,
185 page_count: 0,
186 };
187
188 pub fn new(base_page_number: u64, page_count: u64) -> Self {
190 PageRegionDescriptor {
191 base_page_number,
192 page_count,
193 }
194 }
195
196 pub fn pages(&self) -> Option<(u64, u64)> {
198 if self.page_count != 0 {
199 Some((self.base_page_number, self.page_count))
200 } else {
201 None
202 }
203 }
204}
205
206#[repr(C)]
208#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, PartialEq)]
209pub struct ImportedRegionsPageHeader {
210 pub sha384_hash: [u8; 48],
212}
213
214#[repr(C)]
216#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, PartialEq)]
217pub struct ImportedRegionDescriptor {
218 pub base_page_number: u64,
220 pub page_count: u64,
222 pub accepted: u8,
224 padding: [u8; 7],
226}
227
228#[cfg(feature = "inspect")]
229impl Inspect for ImportedRegionDescriptor {
230 fn inspect(&self, req: inspect::Request<'_>) {
231 let pages = self.pages();
232
233 match pages {
234 None => {
235 req.ignore();
236 }
237 Some((base, count, accepted)) => {
238 req.respond()
239 .field("base_page_number", base)
240 .field("page_count", count)
241 .field("accepted", accepted);
242 }
243 }
244 }
245}
246
247impl ImportedRegionDescriptor {
248 pub const EMPTY: Self = ImportedRegionDescriptor {
250 base_page_number: 0,
251 page_count: 0,
252 accepted: false as u8,
253 padding: [0; 7],
254 };
255
256 pub fn new(base_page_number: u64, page_count: u64, accepted: bool) -> Self {
258 ImportedRegionDescriptor {
259 base_page_number,
260 page_count,
261 accepted: accepted as u8,
262 padding: [0; 7],
263 }
264 }
265
266 pub fn pages(&self) -> Option<(u64, u64, bool)> {
268 if self.page_count != 0 {
269 Some((self.base_page_number, self.page_count, self.accepted != 0))
270 } else {
271 None
272 }
273 }
274}
275
276#[repr(C)]
278#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
279#[cfg_attr(feature = "inspect", derive(Inspect))]
280pub struct LinuxInfo {
281 pub kernel_region: PageRegionDescriptor,
283 pub kernel_entrypoint: u64,
285 pub initrd_region: PageRegionDescriptor,
287 pub initrd_size: u64,
289 pub command_line: PageRegionDescriptor,
291}
292
293#[repr(C)]
295#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
296#[cfg_attr(feature = "inspect", derive(Inspect))]
297pub struct UefiInfo {
298 pub firmware: PageRegionDescriptor,
300 pub vtl0_vp_context: PageRegionDescriptor,
302}
303
304#[cfg_attr(feature = "inspect", derive(Inspect))]
306#[bitfield(u64)]
307#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
308pub struct SupportedVtl0LoadInfo {
309 #[bits(1)]
311 pub uefi_supported: bool,
312 #[bits(1)]
314 pub pcat_supported: bool,
315 #[bits(1)]
317 pub linux_direct_supported: bool,
318 #[bits(61)]
320 pub reserved: u64,
321}
322
323#[repr(C)]
328#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
329#[cfg_attr(feature = "inspect", derive(Inspect))]
330pub struct ParavisorMeasuredVtl0Config {
331 pub magic: u64,
333 pub supported_vtl0: SupportedVtl0LoadInfo,
335 pub uefi_info: UefiInfo,
337 pub linux_info: LinuxInfo,
339}
340
341impl ParavisorMeasuredVtl0Config {
342 pub const MAGIC: u64 = 0x4F48434C56544C30;
344}
345
346pub const PARAVISOR_VTL0_MEASURED_CONFIG_BASE_PAGE_X64: u64 = 0;
350
351pub const PARAVISOR_VTL0_MEASURED_CONFIG_BASE_PAGE_AARCH64: u64 = 16 << (20 - 12);
358
359#[repr(C)]
361#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
362#[cfg_attr(feature = "inspect", derive(Inspect))]
363pub struct ParavisorMeasuredVtl2Config {
364 pub magic: u64,
366 pub vtom_offset_bit: u8,
368 pub padding: [u8; 7],
370}
371
372impl ParavisorMeasuredVtl2Config {
373 pub const MAGIC: u64 = 0x4F48434C56544C32;
375}