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 NVMe devices.
178        pub nvme_keepalive: bool,
179        /// Retain memory for MANA devices.
180        pub mana_keepalive: bool,
181    }
182
183    /// Actions a client can request that the Guest Emulation
184    /// Device perform.
185    #[derive(MeshPayload)]
186    pub enum GuestEmulationRequest {
187        /// Wait for VTL2 to connect to the GET.
188        WaitForConnect(Rpc<(), ()>),
189        /// Wait for VTL2 to start VTL0.
190        WaitForVtl0Start(Rpc<(), Result<(), Vtl0StartError>>),
191        /// Save VTL2 state.
192        SaveGuestVtl2State(Rpc<GuestServicingFlags, Result<(), SaveRestoreError>>),
193        /// Update the VTL2 settings.
194        ModifyVtl2Settings(Rpc<Vec<u8>, Result<(), ModifyVtl2SettingsError>>),
195    }
196
197    /// An error waiting to start VTL0.
198    #[derive(Debug, Error, Clone, MeshPayload)]
199    #[error("guest reported VTL0 start error: {0}")]
200    pub struct Vtl0StartError(pub String);
201
202    /// The various errors that can occur during a save or restore
203    /// operation for guest VTL2 state.
204    #[derive(Debug, Error, MeshPayload)]
205    #[expect(missing_docs)]
206    pub enum SaveRestoreError {
207        #[error("an operation is in progress")]
208        OperationInProgress,
209        #[error("vmbus io error")]
210        Io(#[source] RemoteError),
211        #[error("guest error")]
212        GuestError,
213    }
214
215    /// An error that can occur during a VTL2 settings update.
216    #[derive(Debug, Error, MeshPayload)]
217    #[expect(missing_docs)]
218    pub enum ModifyVtl2SettingsError {
219        #[error("large settings not supported")]
220        LargeSettingsNotSupported,
221        #[error("an operation is already in progress")]
222        OperationInProgress,
223        #[error("guest error: {0}")]
224        Guest(String),
225    }
226
227    /// Firmware events generated by the guest.
228    ///
229    /// TODO: For now, these mainly represent UEFI events without the corresponding extra information. This should be
230    ///       rethought when HvLite supports Linux Direct, IGVM, and other types.
231    #[derive(Debug, Protobuf, PartialEq, Eq, Copy, Clone)]
232    pub enum FirmwareEvent {
233        /// Boot was successful.
234        BootSuccess,
235        /// Boot failed.
236        BootFailed,
237        /// No boot device could be found.
238        NoBootDevice,
239        /// A boot attempt was made.
240        BootAttempt,
241    }
242
243    /// Configuration to the GED's IGVM Attest request handler
244    /// for test scenarios.
245    #[derive(Debug, MeshPayload, Copy, Clone, Inspect)]
246    pub enum IgvmAttestTestConfig {
247        /// Config for testing AK cert retry after failure.
248        AkCertRequestFailureAndRetry,
249        /// Config for testing AK cert persistency across boots.
250        AkCertPersistentAcrossBoot,
251    }
252}