1use bitfield_struct::bitfield;
8use guid::Guid;
9use open_enum::open_enum;
10use serde::Deserialize;
11use serde::Serialize;
12
13pub type DevLoopCompatOption<T> = Option<T>;
23
24#[derive(Debug, Default, Deserialize, Serialize)]
25#[serde(rename_all = "PascalCase")]
26pub struct DevicePlatformSettingsV2Json {
27 pub v1: HclDevicePlatformSettings,
28 pub v2: HclDevicePlatformSettingsV2,
29}
30
31#[derive(Debug, Default, Deserialize, Serialize)]
37#[serde(default, rename_all = "PascalCase")]
38pub struct HclDevicePlatformSettings {
39 pub secure_boot_enabled: bool,
40 pub secure_boot_template_id: HclSecureBootTemplateId,
41 pub enable_battery: bool,
42 pub enable_processor_idle: bool,
43 pub enable_tpm: bool,
44 pub com1: HclUartSettings,
45 pub com2: HclUartSettings,
46 #[serde(with = "serde_helpers::as_string")]
47 pub bios_guid: Guid,
48 pub console_mode: u8,
49 pub enable_firmware_debugging: bool,
50 pub enable_hibernation: bool,
51 pub serial_number: String,
52 pub base_board_serial_number: String,
53 pub chassis_serial_number: String,
54 pub chassis_asset_tag: String,
55}
56
57#[derive(Debug, Default, Deserialize, Serialize)]
59#[serde(rename_all = "PascalCase")]
60pub enum HclSecureBootTemplateId {
61 #[serde(rename = "None")]
62 #[default]
63 None,
64 #[serde(rename = "MicrosoftWindows")]
65 MicrosoftWindows,
66 #[serde(rename = "MicrosoftUEFICertificateAuthority")]
67 MicrosoftUEFICertificateAuthority,
68}
69
70#[derive(Debug, Default, Deserialize, Serialize)]
72#[serde(default, rename_all = "PascalCase")]
73pub struct HclUartSettings {
74 pub enable_port: bool,
75 pub debugger_mode: bool,
76 pub enable_vmbus_redirector: bool,
77}
78
79#[derive(Debug, Default, Deserialize, Serialize)]
80#[serde(rename_all = "PascalCase")]
81pub struct HclDevicePlatformSettingsV2 {
82 pub r#static: HclDevicePlatformSettingsV2Static,
83 pub dynamic: HclDevicePlatformSettingsV2Dynamic,
84}
85
86#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
88pub enum PcatBootDevice {
89 Floppy,
90 Optical,
91 HardDrive,
92 Network,
93}
94
95#[derive(Debug, Copy, Clone, Deserialize, Serialize, Default)]
97pub enum GuestStateLifetime {
98 #[default]
99 Default,
100 ReprovisionOnFailure,
101 Reprovision,
102 Ephemeral,
103}
104
105#[derive(Debug, Copy, Clone, Deserialize, Serialize, Default)]
107pub enum GuestStateEncryptionPolicy {
108 #[default]
115 Auto,
116 None,
121 GspById,
128 GspKey,
134 HardwareSealing,
138}
139
140open_enum! {
141 #[derive(Default, Deserialize, Serialize)]
143 pub enum EfiDiagnosticsLogLevelType: u32 {
144 DEFAULT = 0,
146 INFO = 1,
148 FULL = 2,
150 }
151}
152
153#[derive(Debug, Copy, Clone, Deserialize, Serialize, Default)]
164pub enum HardwareSealingPolicy {
165 #[default]
167 None,
168 Hash,
170 Signer,
172}
173
174#[bitfield(u64)]
176#[derive(Deserialize, Serialize)]
177#[serde(transparent)]
178pub struct ManagementVtlFeatures {
179 pub strict_encryption_policy: bool,
180 pub _reserved1: bool,
181 pub control_ak_cert_provisioning: bool,
182 pub attempt_ak_cert_callback: bool,
183 pub tx_only_serial_port: bool,
184 #[bits(59)]
185 pub _reserved2: u64,
186}
187
188#[derive(Debug, Default, Deserialize, Serialize)]
189#[serde(rename_all = "PascalCase")]
190pub struct HclDevicePlatformSettingsV2Static {
191 pub legacy_memory_map: bool,
193 pub pause_after_boot_failure: bool,
194 pub pxe_ip_v6: bool,
195 pub measure_additional_pcrs: bool,
196 pub disable_frontpage: bool,
197 pub disable_sha384_pcr: bool,
198 pub media_present_enabled_by_default: bool,
199 pub memory_protection_mode: u8,
200 #[serde(default)]
201 pub default_boot_always_attempt: bool,
202
203 pub vpci_boot_enabled: bool,
205 #[serde(default)]
206 #[serde(with = "serde_helpers::opt_guid_str")]
207 pub vpci_instance_filter: Option<Guid>,
208
209 pub num_lock_enabled: bool,
211 pub pcat_boot_device_order: Option<[PcatBootDevice; 4]>,
212
213 pub smbios: HclDevicePlatformSettingsV2StaticSmbios,
214
215 #[serde(default)]
220 #[serde(with = "serde_helpers::opt_base64_vec")]
221 pub vtl2_settings: Option<Vec<u8>>,
222
223 pub vmbus_redirection_enabled: bool,
224 pub no_persistent_secrets: bool,
225 pub watchdog_enabled: bool,
226 #[serde(default)]
229 pub firmware_mode_is_pcat: bool,
230 #[serde(default)]
231 pub always_relay_host_mmio: bool,
232 #[serde(default)]
233 pub imc_enabled: bool,
234 #[serde(default)]
235 pub cxl_memory_enabled: bool,
236 #[serde(default)]
237 pub guest_state_lifetime: GuestStateLifetime,
238 #[serde(default)]
239 pub guest_state_encryption_policy: GuestStateEncryptionPolicy,
240 #[serde(default)]
241 pub efi_diagnostics_log_level: EfiDiagnosticsLogLevelType,
242 #[serde(default)]
243 pub management_vtl_features: ManagementVtlFeatures,
244 #[serde(default)]
245 pub force_dma_bounce_enabled: bool,
246 #[serde(default)]
247 pub hardware_sealing_policy_id: HardwareSealingPolicy,
248}
249
250#[derive(Debug, Default, Deserialize, Serialize)]
251#[serde(rename_all = "PascalCase")]
252pub struct HclDevicePlatformSettingsV2StaticSmbios {
253 pub system_manufacturer: String,
254 pub system_product_name: String,
255 pub system_version: String,
256 #[serde(rename = "SystemSKUNumber")]
257 pub system_sku_number: String,
258 pub system_family: String,
259 pub bios_lock_string: String,
260 pub memory_device_serial_number: String,
261}
262
263#[derive(Debug, Default, Deserialize, Serialize)]
264#[serde(rename_all = "PascalCase")]
265pub struct HclDevicePlatformSettingsV2Dynamic {
266 pub nvdimm_count: u16,
267 pub enable_psp: bool,
268 pub generation_id_low: u64,
269 pub generation_id_high: u64,
270 pub smbios: HclDevicePlatformSettingsV2DynamicSmbios,
271 pub is_servicing_scenario: bool,
272
273 #[serde(default)]
274 #[serde(with = "serde_helpers::vec_base64_vec")]
275 pub acpi_tables: Vec<Vec<u8>>,
276}
277
278#[derive(Debug, Default, Deserialize, Serialize)]
279#[serde(rename_all = "PascalCase")]
280pub struct HclDevicePlatformSettingsV2DynamicSmbios {
281 #[serde(with = "serde_helpers::base64_vec")]
282 pub processor_manufacturer: Vec<u8>,
283 #[serde(with = "serde_helpers::base64_vec")]
284 pub processor_version: Vec<u8>,
285
286 #[serde(rename = "ProcessorID")]
287 pub processor_id: u64,
288 pub external_clock: u16,
289 pub max_speed: u16,
290 pub current_speed: u16,
291 pub processor_characteristics: u16,
292 pub processor_family2: u16,
293 pub processor_type: u8,
294 pub voltage: u8,
295 pub status: u8,
296 pub processor_upgrade: u8,
297}
298
299#[cfg(test)]
300mod test {
301 use super::*;
302
303 #[test]
304 fn smoke_test_sample() {
305 serde_json::from_slice::<DevicePlatformSettingsV2Json>(include_bytes!(
306 "dps_test_json.json"
307 ))
308 .unwrap();
309 }
310
311 #[test]
312 fn smoke_test_sample_with_vtl2settings() {
313 serde_json::from_slice::<DevicePlatformSettingsV2Json>(include_bytes!(
314 "dps_test_json_with_vtl2settings.json"
315 ))
316 .unwrap();
317 }
318}