get_resources/lib.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resource definitions for the GET family of devices.
5
6#![forbid(unsafe_code)]
7
8/// Guest Emulation Log device resources.
9pub mod gel {
10 use mesh::MeshPayload;
11 use vm_resource::ResourceId;
12 use vm_resource::kind::VmbusDeviceHandleKind;
13
14 /// Handle to a guest emulation log device.
15 #[derive(MeshPayload)]
16 pub struct GuestEmulationLogHandle;
17
18 impl ResourceId<VmbusDeviceHandleKind> for GuestEmulationLogHandle {
19 const ID: &'static str = "gel";
20 }
21}
22
23/// Guest crash device resources.
24pub mod crash {
25 use mesh::MeshPayload;
26 use mesh::rpc::FailableRpc;
27 use std::fs::File;
28 use vm_resource::ResourceId;
29 use vm_resource::kind::VmbusDeviceHandleKind;
30
31 /// Handle to a guest crash dump device.
32 #[derive(MeshPayload)]
33 pub struct GuestCrashDeviceHandle {
34 /// A channel the device can use to get a file to write a dump to.
35 pub request_dump: mesh::Sender<FailableRpc<mesh::OneshotReceiver<()>, File>>,
36 /// The maximum size of the dump that the device will write.
37 pub max_dump_size: u64,
38 }
39
40 impl ResourceId<VmbusDeviceHandleKind> for GuestCrashDeviceHandle {
41 const ID: &'static str = "guest_crash_device";
42 }
43}
44
45/// Guest Emulation Device resources.
46pub mod ged {
47 use inspect::Inspect;
48 use mesh::MeshPayload;
49 use mesh::error::RemoteError;
50 use mesh::payload::Protobuf;
51 use mesh::rpc::Rpc;
52 use thiserror::Error;
53 use vm_resource::Resource;
54 use vm_resource::ResourceId;
55 use vm_resource::kind::FramebufferHandleKind;
56 use vm_resource::kind::VmbusDeviceHandleKind;
57 use vmgs_resources::VmgsResource;
58
59 /// A resource handle for a guest emulation device.
60 #[derive(MeshPayload)]
61 pub struct GuestEmulationDeviceHandle {
62 /// The firmware configuration for the guest.
63 pub firmware: GuestFirmwareConfig,
64 /// Enable COM1 for VTL0 and the VMBUS redirector in VTL2.
65 pub com1: bool,
66 /// Enable COM2 for VTL0 and the VMBUS redirector in VTL2.
67 pub com2: bool,
68 /// Enable vmbus redirection.
69 pub vmbus_redirection: bool,
70 /// Enable the TPM.
71 pub enable_tpm: bool,
72 /// Encoded VTL2 settings.
73 pub vtl2_settings: Option<Vec<u8>>,
74 /// The disk to back the GET's VMGS interface.
75 pub vmgs: VmgsResource,
76 /// Framebuffer device control.
77 pub framebuffer: Option<Resource<FramebufferHandleKind>>,
78 /// Access to VTL2 functionality.
79 pub guest_request_recv: mesh::Receiver<GuestEmulationRequest>,
80 /// Notification of firmware events.
81 pub firmware_event_send: Option<mesh::Sender<FirmwareEvent>>,
82 /// Enable secure boot.
83 pub secure_boot_enabled: bool,
84 /// The secure boot template type.
85 pub secure_boot_template: GuestSecureBootTemplateType,
86 /// Enable battery.
87 pub enable_battery: bool,
88 /// Suppress attestation and disable TPM state persistence.
89 pub no_persistent_secrets: bool,
90 /// Test configuration for IGVM Attest message.
91 pub igvm_attest_test_config: Option<IgvmAttestTestConfig>,
92 /// Send the test seed for GspById requests
93 pub test_gsp_by_id: bool,
94 /// EFI diagnostics log level
95 pub efi_diagnostics_log_level: EfiDiagnosticsLogLevelType,
96 }
97
98 /// The firmware and chipset configuration for the guest.
99 #[derive(MeshPayload)]
100 pub enum GuestFirmwareConfig {
101 /// Boot from UEFI with Hyper-V generation 2 devices.
102 Uefi {
103 /// Tell UEFI to consider booting from VPCI.
104 enable_vpci_boot: bool,
105 /// Enable UEFI firmware debugging for VTL0.
106 firmware_debug: bool,
107 /// Disable the UEFI frontpage which will cause the VM to shutdown instead when unable to boot.
108 disable_frontpage: bool,
109 /// Where to send UEFI console output
110 console_mode: UefiConsoleMode,
111 /// Perform a default boot even if boot entries exist and fail
112 default_boot_always_attempt: bool,
113 },
114 /// Boot from PC/AT BIOS with Hyper-V generation 1 devices.
115 Pcat {
116 /// The boot order for the PC/AT firmware.
117 boot_order: [PcatBootDevice; 4],
118 },
119 }
120
121 /// UEFI Console Mode
122 #[derive(MeshPayload, Clone, Debug, Copy)]
123 pub enum UefiConsoleMode {
124 /// video+kbd (having a head)
125 Default = 0,
126 /// headless with COM1 serial console
127 COM1 = 1,
128 /// headless with COM2 serial console
129 COM2 = 2,
130 /// headless
131 None = 3,
132 }
133
134 /// The guest's secure boot template type to use.
135 #[derive(MeshPayload, Clone, Debug, Copy)]
136 pub enum GuestSecureBootTemplateType {
137 /// No template specified.
138 None,
139 /// The microsoft windows template.
140 MicrosoftWindows,
141 /// The Microsoft UEFI certificate authority template.
142 MicrosoftUefiCertificateAuthority,
143 }
144
145 /// The guest's EFI diagnostics log level type to use.
146 #[derive(MeshPayload, Clone, Debug, Copy, Default)]
147 pub enum EfiDiagnosticsLogLevelType {
148 /// Default log level
149 #[default]
150 Default,
151 /// Include INFO logs
152 Info,
153 /// All logs
154 Full,
155 }
156
157 /// The boot devices for a PC/AT BIOS.
158 #[derive(MeshPayload, Debug, Clone, Copy, PartialEq)]
159 pub enum PcatBootDevice {
160 /// Boot from a floppy disk.
161 Floppy,
162 /// Boot from a hard drive.
163 HardDrive,
164 /// Boot from an optical drive.
165 Optical,
166 /// Boot from the network.
167 Network,
168 }
169
170 impl ResourceId<VmbusDeviceHandleKind> for GuestEmulationDeviceHandle {
171 const ID: &'static str = "ged";
172 }
173
174 /// Define servicing behavior.
175 #[derive(MeshPayload, Default)]
176 pub struct GuestServicingFlags {
177 /// Retain memory for DMA-attached devices.
178 pub nvme_keepalive: bool,
179 }
180
181 /// Actions a client can request that the Guest Emulation
182 /// Device perform.
183 #[derive(MeshPayload)]
184 pub enum GuestEmulationRequest {
185 /// Wait for VTL2 to connect to the GET.
186 WaitForConnect(Rpc<(), ()>),
187 /// Wait for VTL2 to start VTL0.
188 WaitForVtl0Start(Rpc<(), Result<(), Vtl0StartError>>),
189 /// Save VTL2 state.
190 SaveGuestVtl2State(Rpc<GuestServicingFlags, Result<(), SaveRestoreError>>),
191 /// Update the VTL2 settings.
192 ModifyVtl2Settings(Rpc<Vec<u8>, Result<(), ModifyVtl2SettingsError>>),
193 }
194
195 /// An error waiting to start VTL0.
196 #[derive(Debug, Error, Clone, MeshPayload)]
197 #[error("guest reported VTL0 start error: {0}")]
198 pub struct Vtl0StartError(pub String);
199
200 /// The various errors that can occur during a save or restore
201 /// operation for guest VTL2 state.
202 #[derive(Debug, Error, MeshPayload)]
203 #[expect(missing_docs)]
204 pub enum SaveRestoreError {
205 #[error("an operation is in progress")]
206 OperationInProgress,
207 #[error("vmbus io error")]
208 Io(#[source] RemoteError),
209 #[error("guest error")]
210 GuestError,
211 }
212
213 /// An error that can occur during a VTL2 settings update.
214 #[derive(Debug, Error, MeshPayload)]
215 #[expect(missing_docs)]
216 pub enum ModifyVtl2SettingsError {
217 #[error("large settings not supported")]
218 LargeSettingsNotSupported,
219 #[error("an operation is already in progress")]
220 OperationInProgress,
221 #[error("guest error: {0}")]
222 Guest(String),
223 }
224
225 /// Firmware events generated by the guest.
226 ///
227 /// TODO: For now, these mainly represent UEFI events without the corresponding extra information. This should be
228 /// rethought when HvLite supports Linux Direct, IGVM, and other types.
229 #[derive(Debug, Protobuf, PartialEq, Eq, Copy, Clone)]
230 pub enum FirmwareEvent {
231 /// Boot was successful.
232 BootSuccess,
233 /// Boot failed.
234 BootFailed,
235 /// No boot device could be found.
236 NoBootDevice,
237 /// A boot attempt was made.
238 BootAttempt,
239 }
240
241 /// Configuration to the GED's IGVM Attest request handler
242 /// for test scenarios.
243 #[derive(Debug, MeshPayload, Copy, Clone, Inspect)]
244 pub enum IgvmAttestTestConfig {
245 /// Config for testing AK cert retry after failure.
246 AkCertRequestFailureAndRetry,
247 /// Config for testing AK cert persistency across boots.
248 AkCertPersistentAcrossBoot,
249 }
250}