uefi_specs/hyperv/
nvram.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Nvram types defined in `BiosInterface.h`
5
6use self::packed_nums::*;
7use crate::hyperv::common::EfiStatus64NoErrorBit;
8use bitfield_struct::bitfield;
9use guid::Guid;
10use open_enum::open_enum;
11use zerocopy::FromBytes;
12use zerocopy::Immutable;
13use zerocopy::IntoBytes;
14use zerocopy::KnownLayout;
15
16#[allow(non_camel_case_types)]
17mod packed_nums {
18    pub type u64_ne = zerocopy::U64<zerocopy::NativeEndian>;
19}
20
21open_enum! {
22    /// Command types for NVRAM_COMMAND_DESCRIPTOR.
23    ///
24    /// These correlate with the semantics of the UEFI runtime variable services.
25    ///
26    /// MsvmPkg: `NVRAM_COMMAND`
27    #[derive(IntoBytes, FromBytes, Immutable, KnownLayout)]
28    pub enum NvramCommand: u32 {
29        GET_VARIABLE = 0,
30        SET_VARIABLE = 1,
31        GET_FIRST_VARIABLE_NAME = 2,
32        GET_NEXT_VARIABLE_NAME = 3,
33        QUERY_INFO = 4,
34        SIGNAL_RUNTIME = 5,
35        DEBUG_STRING = 6,
36    }
37}
38
39/// MsvmPkg: `NVRAM_COMMAND_DESCRIPTOR`
40#[repr(C)]
41#[derive(Debug, Clone, Copy, IntoBytes, FromBytes, Immutable, KnownLayout)]
42pub struct NvramCommandDescriptor {
43    pub command: NvramCommand,
44    pub status: EfiStatus64NoErrorBit,
45}
46
47/// MsvmPkg: `NVRAM_COMMAND_DESCRIPTOR`
48#[repr(C)]
49#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]
50pub struct NvramDebugStringCommand {
51    pub padding: u32,
52    pub address: u64_ne,
53    pub len: u32,
54}
55
56/// MsvmPkg: `NVRAM_COMMAND_DESCRIPTOR`
57#[repr(C)]
58#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]
59pub struct NvramVariableCommand {
60    /// UEFI variable attributes associated with the variable: access rights
61    /// (RT/BS).
62    ///
63    /// Used as input for the SetVariable command. Used as output for the
64    /// GetVariable command.
65    pub attributes: u32,
66
67    /// GPA of the buffer containing a 16-bit unicode variable name.
68    ///
69    /// Memory at this location is read for the GetVariable, SetVariable,
70    /// GetNextVariable command. Memory at this location is written to for the
71    /// GetNextVariable command.
72    pub name_address: u64_ne,
73
74    /// Size in bytes of the buffer at VariableNameAddress.
75    ///
76    /// Used as input for GetVariable, SetVariable, and GetNextVariable
77    /// commands. Used as output for the GetNextVariable command.
78    pub name_bytes: u32,
79
80    /// A GUID comprising the other half of the variable name.
81    ///
82    /// Used as input for GetVariable, SetVariable, and GetNextVariable
83    /// commands. Used as output for the GetNextVariable command.
84    pub vendor_guid: Guid,
85
86    /// GPA of the buffer containing variable data. Memory at this location is
87    /// written to for the GetVariable command.
88    ///
89    /// Memory at this location is read for the SetVariable command.
90    pub data_address: u64_ne,
91
92    /// Size of the buffer at VariableDataAddress.
93    ///
94    /// Used as input for the GetVariable command. Used as output for the
95    /// GetVariable and SetVariable commands.
96    pub data_bytes: u32,
97}
98
99/// MsvmPkg: `NVRAM_COMMAND_DESCRIPTOR`
100#[repr(C)]
101#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]
102pub struct NvramQueryInfo {
103    /// Attribute mask, controls variable type for which the information is
104    /// returned.
105    ///
106    /// Used as an input for the QueryInfo command.
107    pub attributes: u32,
108
109    // These are outputs for the QueryInfo command.
110    pub maximum_variable_storage: u64_ne,
111    pub remaining_variable_storage: u64_ne,
112    pub maximum_variable_size: u64_ne,
113}
114
115/// MsvmPkg: `NVRAM_COMMAND_DESCRIPTOR`
116#[bitfield(u64)]
117#[derive(IntoBytes, FromBytes, Immutable, KnownLayout)]
118pub struct SignalRuntimeCommandFlags {
119    pub vsm_aware: bool,
120    #[bits(63)]
121    _reserved: u64,
122}
123
124/// MsvmPkg: `NVRAM_COMMAND_DESCRIPTOR`
125///
126/// ```text
127/// union
128/// {
129///     struct
130///     {
131///         UINT64 VsmAware : 1;
132///         UINT64 Unused   : 63;
133///     } S;
134///     UINT64 AsUINT64;
135/// } SignalRuntimeCommand;
136/// ```
137#[repr(C)]
138#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]
139pub struct NvramSignalRuntimeCommand {
140    pub flags: SignalRuntimeCommandFlags,
141}
142
143pub mod vars {
144    use guid::Guid;
145
146    const SECURE_BOOT_ENABLE_GUID: Guid = guid::guid!("f0a30bc7-af08-4556-99c4-001009c93a44");
147
148    pub const MSFT_SECURE_BOOT_PRODUCTION_GUID: Guid =
149        guid::guid!("77fa9abd-0359-4d32-bd60-28f4e78f784b");
150
151    const EFI_HYPERV_PRIVATE_GUID: Guid = guid::guid!("610b9e98-c6f6-47f8-8b47-2d2da0d52a91");
152
153    defn_nvram_var!(SECURE_BOOT_ENABLE = (SECURE_BOOT_ENABLE_GUID, "SecureBootEnable"));
154    defn_nvram_var!(CURRENT_POLICY = (MSFT_SECURE_BOOT_PRODUCTION_GUID, "CurrentPolicy"));
155    defn_nvram_var!(OS_LOADER_INDICATIONS = (EFI_HYPERV_PRIVATE_GUID, "OsLoaderIndications"));
156    defn_nvram_var!(
157        OS_LOADER_INDICATIONS_SUPPORTED = (EFI_HYPERV_PRIVATE_GUID, "OsLoaderIndicationsSupported")
158    );
159}