guest_emulation_transport/
api.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Friendly Rust representations of the data sent over the GET.
5
6// These types are re-exported as-is, in order to avoid requiring consumers of
7// the GET and GED to also import get_protocol.
8pub use get_protocol::CreateRamGpaRangeFlags;
9pub use get_protocol::EventLogId;
10pub use get_protocol::GSP_CIPHERTEXT_MAX;
11pub use get_protocol::GspCiphertextContent;
12pub use get_protocol::GspCleartextContent;
13pub use get_protocol::GspExtendedStatusFlags;
14pub use get_protocol::IGVM_ATTEST_MSG_REQ_AGENT_DATA_MAX_SIZE;
15pub use get_protocol::MAX_TRANSFER_SIZE;
16pub use get_protocol::NUMBER_GSP;
17pub use get_protocol::ProtocolVersion;
18pub use get_protocol::SaveGuestVtl2StateFlags;
19pub use get_protocol::VmgsIoStatus;
20use zerocopy::FromZeros;
21
22use guid::Guid;
23
24/// Device platform settings.
25#[expect(missing_docs)]
26pub mod platform_settings {
27    pub use get_protocol::dps_json::PcatBootDevice;
28
29    use get_protocol::dps_json::GuestStateLifetime;
30    use guid::Guid;
31    use inspect::Inspect;
32
33    /// All available device platform settings.
34    #[derive(Debug, Inspect)]
35    pub struct DevicePlatformSettings {
36        pub smbios: Smbios,
37        pub general: General,
38        #[inspect(with = "inspect::iter_by_index")]
39        pub acpi_tables: Vec<Vec<u8>>,
40    }
41
42    /// All available SMBIOS related config.
43    #[derive(Debug, Inspect)]
44    pub struct Smbios {
45        pub serial_number: Vec<u8>,
46        pub base_board_serial_number: Vec<u8>,
47        pub chassis_serial_number: Vec<u8>,
48        pub chassis_asset_tag: Vec<u8>,
49
50        pub system_manufacturer: Vec<u8>,
51        pub system_product_name: Vec<u8>,
52        pub system_version: Vec<u8>,
53        pub system_sku_number: Vec<u8>,
54        pub system_family: Vec<u8>,
55        pub bios_lock_string: Vec<u8>,
56        pub memory_device_serial_number: Vec<u8>,
57
58        pub processor_manufacturer: Vec<u8>,
59        pub processor_version: Vec<u8>,
60        pub processor_id: u64,
61        pub external_clock: u16,
62        pub max_speed: u16,
63        pub current_speed: u16,
64        pub processor_characteristics: u16,
65        pub processor_family2: u16,
66        pub processor_type: u8,
67        pub voltage: u8,
68        pub status: u8,
69        pub processor_upgrade: u8,
70    }
71
72    /// All available general device platform configuration.
73    // DEVNOTE: "general" is code for "not well organized", so if you've got a
74    // better way to organize these settings, do consider cleaning this up a bit!
75    #[derive(Debug, Inspect)]
76    pub struct General {
77        pub secure_boot_enabled: bool,
78        pub secure_boot_template: SecureBootTemplateType,
79        pub bios_guid: Guid,
80        pub console_mode: UefiConsoleMode,
81        pub battery_enabled: bool,
82        pub processor_idle_enabled: bool,
83        pub tpm_enabled: bool,
84        pub com1_enabled: bool,
85        pub com1_debugger_mode: bool,
86        pub com1_vmbus_redirector: bool,
87        pub com2_enabled: bool,
88        pub com2_debugger_mode: bool,
89        pub com2_vmbus_redirector: bool,
90        pub firmware_debugging_enabled: bool,
91        pub hibernation_enabled: bool,
92
93        pub suppress_attestation: Option<bool>,
94        pub generation_id: Option<[u8; 16]>,
95
96        pub legacy_memory_map: bool,
97        pub pause_after_boot_failure: bool,
98        pub pxe_ip_v6: bool,
99        pub measure_additional_pcrs: bool,
100        pub disable_frontpage: bool,
101        pub disable_sha384_pcr: bool,
102        pub media_present_enabled_by_default: bool,
103        pub vpci_boot_enabled: bool,
104        pub memory_protection_mode: MemoryProtectionMode,
105        pub default_boot_always_attempt: bool,
106        pub num_lock_enabled: bool,
107        #[inspect(with = "|x| inspect::iter_by_index(x).map_value(inspect::AsDebug)")]
108        pub pcat_boot_device_order: [PcatBootDevice; 4],
109
110        pub vpci_instance_filter: Option<Guid>,
111        pub nvdimm_count: u16,
112        pub psp_enabled: bool,
113
114        pub vmbus_redirection_enabled: bool,
115        pub always_relay_host_mmio: bool,
116        pub vtl2_settings: Option<underhill_config::Vtl2Settings>,
117
118        pub is_servicing_scenario: bool,
119        pub watchdog_enabled: bool,
120        pub firmware_mode_is_pcat: bool,
121        pub imc_enabled: bool,
122        pub cxl_memory_enabled: bool,
123
124        #[inspect(debug)]
125        pub guest_state_lifetime: GuestStateLifetime,
126    }
127
128    #[derive(Copy, Clone, Debug, Inspect)]
129    pub enum MemoryProtectionMode {
130        Disabled = 0,
131        Default = 1,
132        Strict = 2,
133        Relaxed = 3,
134    }
135
136    #[derive(Debug, Inspect)]
137    pub enum UefiConsoleMode {
138        /// video+kbd (having a head)
139        Default = 0,
140        /// headless with COM1 serial console
141        COM1 = 1,
142        /// headless with COM2 serial console
143        COM2 = 2,
144        /// headless
145        None = 3,
146    }
147
148    #[derive(Debug, Inspect)]
149    pub enum SecureBootTemplateType {
150        /// No template to apply.
151        None,
152        /// Apply the Windows only CA.
153        MicrosoftWindows,
154        /// Apply the Microsoft UEFI CA.
155        MicrosoftUefiCertificateAuthority,
156    }
157}
158
159/// Response fields for Guest State Protection sent from the host
160pub struct GuestStateProtection {
161    /// Guest State Protection ciphertext content
162    pub encrypted_gsp: GspCiphertextContent,
163    /// Guest State Protection cleartext content
164    pub decrypted_gsp: [GspCleartextContent; NUMBER_GSP as usize],
165    /// Extended status flags
166    pub extended_status_flags: GspExtendedStatusFlags,
167    /// Randomized new_gsp sent in the GuestStateProtectionRequest message to
168    /// the host
169    pub new_gsp: GspCleartextContent,
170}
171
172/// Response fields for Guest State Protection by ID from the host
173#[derive(Copy, Clone)]
174pub struct GuestStateProtectionById {
175    /// Guest State Protection cleartext content
176    pub seed: GspCleartextContent,
177    /// Extended status flags
178    pub extended_status_flags: GspExtendedStatusFlags,
179}
180
181impl GuestStateProtectionById {
182    /// Construct a blank instance of `GuestStateProtectionById`
183    pub fn new_zeroed() -> GuestStateProtectionById {
184        GuestStateProtectionById {
185            seed: GspCleartextContent::new_zeroed(),
186            extended_status_flags: GspExtendedStatusFlags::new_zeroed(),
187        }
188    }
189}
190
191/// Response for IGVM Attest from the host
192#[derive(Clone)]
193pub struct IgvmAttest {
194    /// Response data
195    pub response: Vec<u8>,
196}
197
198/// Response fields for VMGS Get Device Info from the host
199pub struct VmgsGetDeviceInfo {
200    /// Status of the request
201    pub status: VmgsIoStatus,
202    /// Logical sectors
203    pub capacity: u64,
204    /// Bytes per logical sector
205    pub bytes_per_logical_sector: u16,
206    /// Bytes per physical sector
207    pub bytes_per_physical_sector: u16,
208    /// Maximum transfer size bytes
209    pub maximum_transfer_size_bytes: u32,
210}
211
212/// Response fields from Time from the host
213#[derive(Debug, Copy, Clone)]
214pub struct Time {
215    /// UTC, in 100ns units since Jan 1 1601.
216    ///
217    /// (corresponds to `RtlGetSystemTime()` on the Host)
218    pub utc: i64,
219    /// Time zone (as minutes from UTC)
220    pub time_zone: i16,
221}
222
223/// A handle returned by `CreateRamGpaRange`, which can be passed to
224/// `ResetRamGpaRange` in order to reset the associated range.
225#[derive(Debug)]
226pub struct RemoteRamGpaRangeHandle(u32);
227
228impl RemoteRamGpaRangeHandle {
229    /// Return a raw u32 that represents this handle
230    pub fn as_raw(&self) -> u32 {
231        self.0
232    }
233
234    /// Create a new [`RemoteRamGpaRangeHandle`] from a raw u32 previously
235    /// returned from `into_raw`.
236    pub fn from_raw(handle: u32) -> Self {
237        RemoteRamGpaRangeHandle(handle)
238    }
239}
240
241/// Request to save Guest state during servicing.
242pub struct GuestSaveRequest {
243    /// GUID associated with the request.
244    pub correlation_id: Guid,
245    /// When to complete the request.
246    pub deadline: std::time::Instant,
247    /// Flags bitfield.
248    pub capabilities_flags: SaveGuestVtl2StateFlags,
249}