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 }
95
96 /// The firmware and chipset configuration for the guest.
97 #[derive(MeshPayload)]
98 pub enum GuestFirmwareConfig {
99 /// Boot from UEFI with Hyper-V generation 2 devices.
100 Uefi {
101 /// Tell UEFI to consider booting from VPCI.
102 enable_vpci_boot: bool,
103 /// Enable UEFI firmware debugging for VTL0.
104 firmware_debug: bool,
105 /// Disable the UEFI frontpage which will cause the VM to shutdown instead when unable to boot.
106 disable_frontpage: bool,
107 /// Where to send UEFI console output
108 console_mode: UefiConsoleMode,
109 /// Perform a default boot even if boot entries exist and fail
110 default_boot_always_attempt: bool,
111 },
112 /// Boot from PC/AT BIOS with Hyper-V generation 1 devices.
113 Pcat {
114 /// The boot order for the PC/AT firmware.
115 boot_order: [PcatBootDevice; 4],
116 },
117 }
118
119 /// UEFI Console Mode
120 #[derive(MeshPayload, Clone, Debug, Copy)]
121 pub enum UefiConsoleMode {
122 /// video+kbd (having a head)
123 Default = 0,
124 /// headless with COM1 serial console
125 COM1 = 1,
126 /// headless with COM2 serial console
127 COM2 = 2,
128 /// headless
129 None = 3,
130 }
131
132 /// The guest's secure boot template type to use.
133 #[derive(MeshPayload, Clone, Debug, Copy)]
134 pub enum GuestSecureBootTemplateType {
135 /// No template specified.
136 None,
137 /// The microsoft windows template.
138 MicrosoftWindows,
139 /// The Microsoft UEFI certificate authority template.
140 MicrosoftUefiCertificateAuthority,
141 }
142
143 /// The boot devices for a PC/AT BIOS.
144 #[derive(MeshPayload, Debug, Clone, Copy, PartialEq)]
145 pub enum PcatBootDevice {
146 /// Boot from a floppy disk.
147 Floppy,
148 /// Boot from a hard drive.
149 HardDrive,
150 /// Boot from an optical drive.
151 Optical,
152 /// Boot from the network.
153 Network,
154 }
155
156 impl ResourceId<VmbusDeviceHandleKind> for GuestEmulationDeviceHandle {
157 const ID: &'static str = "ged";
158 }
159
160 /// Define servicing behavior.
161 #[derive(MeshPayload, Default)]
162 pub struct GuestServicingFlags {
163 /// Retain memory for DMA-attached devices.
164 pub nvme_keepalive: bool,
165 }
166
167 /// Actions a client can request that the Guest Emulation
168 /// Device perform.
169 #[derive(MeshPayload)]
170 pub enum GuestEmulationRequest {
171 /// Wait for VTL2 to connect to the GET.
172 WaitForConnect(Rpc<(), ()>),
173 /// Wait for VTL2 to start VTL0.
174 WaitForVtl0Start(Rpc<(), Result<(), Vtl0StartError>>),
175 /// Save VTL2 state.
176 SaveGuestVtl2State(Rpc<GuestServicingFlags, Result<(), SaveRestoreError>>),
177 /// Update the VTL2 settings.
178 ModifyVtl2Settings(Rpc<Vec<u8>, Result<(), ModifyVtl2SettingsError>>),
179 }
180
181 /// An error waiting to start VTL0.
182 #[derive(Debug, Error, Clone, MeshPayload)]
183 #[error("guest reported VTL0 start error: {0}")]
184 pub struct Vtl0StartError(pub String);
185
186 /// The various errors that can occur during a save or restore
187 /// operation for guest VTL2 state.
188 #[derive(Debug, Error, MeshPayload)]
189 #[expect(missing_docs)]
190 pub enum SaveRestoreError {
191 #[error("an operation is in progress")]
192 OperationInProgress,
193 #[error("vmbus io error")]
194 Io(#[source] RemoteError),
195 #[error("guest error")]
196 GuestError,
197 }
198
199 /// An error that can occur during a VTL2 settings update.
200 #[derive(Debug, Error, MeshPayload)]
201 #[expect(missing_docs)]
202 pub enum ModifyVtl2SettingsError {
203 #[error("large settings not supported")]
204 LargeSettingsNotSupported,
205 #[error("an operation is already in progress")]
206 OperationInProgress,
207 #[error("guest error: {0}")]
208 Guest(String),
209 }
210
211 /// Firmware events generated by the guest.
212 ///
213 /// TODO: For now, these mainly represent UEFI events without the corresponding extra information. This should be
214 /// rethought when HvLite supports Linux Direct, IGVM, and other types.
215 #[derive(Debug, Protobuf, PartialEq, Eq, Copy, Clone)]
216 pub enum FirmwareEvent {
217 /// Boot was successful.
218 BootSuccess,
219 /// Boot failed.
220 BootFailed,
221 /// No boot device could be found.
222 NoBootDevice,
223 /// A boot attempt was made.
224 BootAttempt,
225 }
226
227 /// Configuration to the GED's IGVM Attest request handler
228 /// for test scenarios.
229 #[derive(Debug, MeshPayload, Copy, Clone, Inspect)]
230 pub enum IgvmAttestTestConfig {
231 /// Config for testing AK cert retry after failure.
232 AkCertRequestFailureAndRetry,
233 /// Config for testing AK cert persistency across boots.
234 AkCertPersistentAcrossBoot,
235 }
236}