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]
114 Auto,
115 None,
120 GspById,
127 GspKey,
133 HardwareSealing,
136}
137
138open_enum! {
139 #[derive(Default, Deserialize, Serialize)]
141 pub enum EfiDiagnosticsLogLevelType: u32 {
142 DEFAULT = 0,
144 INFO = 1,
146 FULL = 2,
148 }
149}
150
151#[bitfield(u64)]
153#[derive(Deserialize, Serialize)]
154#[serde(transparent)]
155pub struct ManagementVtlFeatures {
156 pub strict_encryption_policy: bool,
157 pub _reserved1: bool,
158 pub attempt_ak_cert_callback: bool,
159 #[bits(61)]
160 pub _reserved2: u64,
161}
162
163#[derive(Debug, Default, Deserialize, Serialize)]
164#[serde(rename_all = "PascalCase")]
165pub struct HclDevicePlatformSettingsV2Static {
166 pub legacy_memory_map: bool,
168 pub pause_after_boot_failure: bool,
169 pub pxe_ip_v6: bool,
170 pub measure_additional_pcrs: bool,
171 pub disable_frontpage: bool,
172 pub disable_sha384_pcr: bool,
173 pub media_present_enabled_by_default: bool,
174 pub memory_protection_mode: u8,
175 #[serde(default)]
176 pub default_boot_always_attempt: bool,
177
178 pub vpci_boot_enabled: bool,
180 #[serde(default)]
181 #[serde(with = "serde_helpers::opt_guid_str")]
182 pub vpci_instance_filter: Option<Guid>,
183
184 pub num_lock_enabled: bool,
186 pub pcat_boot_device_order: Option<[PcatBootDevice; 4]>,
187
188 pub smbios: HclDevicePlatformSettingsV2StaticSmbios,
189
190 #[serde(default)]
195 #[serde(with = "serde_helpers::opt_base64_vec")]
196 pub vtl2_settings: Option<Vec<u8>>,
197
198 pub vmbus_redirection_enabled: bool,
199 pub no_persistent_secrets: bool,
200 pub watchdog_enabled: bool,
201 #[serde(default)]
204 pub firmware_mode_is_pcat: bool,
205 #[serde(default)]
206 pub always_relay_host_mmio: bool,
207 #[serde(default)]
208 pub imc_enabled: bool,
209 #[serde(default)]
210 pub cxl_memory_enabled: bool,
211 #[serde(default)]
212 pub guest_state_lifetime: GuestStateLifetime,
213 #[serde(default)]
214 pub guest_state_encryption_policy: GuestStateEncryptionPolicy,
215 #[serde(default)]
216 pub efi_diagnostics_log_level: EfiDiagnosticsLogLevelType,
217 #[serde(default)]
218 pub management_vtl_features: ManagementVtlFeatures,
219}
220
221#[derive(Debug, Default, Deserialize, Serialize)]
222#[serde(rename_all = "PascalCase")]
223pub struct HclDevicePlatformSettingsV2StaticSmbios {
224 pub system_manufacturer: String,
225 pub system_product_name: String,
226 pub system_version: String,
227 #[serde(rename = "SystemSKUNumber")]
228 pub system_sku_number: String,
229 pub system_family: String,
230 pub bios_lock_string: String,
231 pub memory_device_serial_number: String,
232}
233
234#[derive(Debug, Default, Deserialize, Serialize)]
235#[serde(rename_all = "PascalCase")]
236pub struct HclDevicePlatformSettingsV2Dynamic {
237 pub nvdimm_count: u16,
238 pub enable_psp: bool,
239 pub generation_id_low: u64,
240 pub generation_id_high: u64,
241 pub smbios: HclDevicePlatformSettingsV2DynamicSmbios,
242 pub is_servicing_scenario: bool,
243
244 #[serde(default)]
245 #[serde(with = "serde_helpers::vec_base64_vec")]
246 pub acpi_tables: Vec<Vec<u8>>,
247}
248
249#[derive(Debug, Default, Deserialize, Serialize)]
250#[serde(rename_all = "PascalCase")]
251pub struct HclDevicePlatformSettingsV2DynamicSmbios {
252 #[serde(with = "serde_helpers::base64_vec")]
253 pub processor_manufacturer: Vec<u8>,
254 #[serde(with = "serde_helpers::base64_vec")]
255 pub processor_version: Vec<u8>,
256
257 #[serde(rename = "ProcessorID")]
258 pub processor_id: u64,
259 pub external_clock: u16,
260 pub max_speed: u16,
261 pub current_speed: u16,
262 pub processor_characteristics: u16,
263 pub processor_family2: u16,
264 pub processor_type: u8,
265 pub voltage: u8,
266 pub status: u8,
267 pub processor_upgrade: u8,
268}
269
270#[cfg(test)]
271mod test {
272 use super::*;
273
274 #[test]
275 fn smoke_test_sample() {
276 serde_json::from_slice::<DevicePlatformSettingsV2Json>(include_bytes!(
277 "dps_test_json.json"
278 ))
279 .unwrap();
280 }
281
282 #[test]
283 fn smoke_test_sample_with_vtl2settings() {
284 serde_json::from_slice::<DevicePlatformSettingsV2Json>(include_bytes!(
285 "dps_test_json_with_vtl2settings.json"
286 ))
287 .unwrap();
288 }
289}