3 Implment all four UEFI runtime variable services and
4 install variable architeture protocol.
6 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 EFI_EVENT mVirtualAddressChangeEvent
= NULL
;
23 This code finds variable in storage blocks (Volatile or Non-Volatile).
25 @param VariableName Name of Variable to be found.
26 @param VendorGuid Variable vendor GUID.
27 @param Attributes Attribute value of the variable found.
28 @param DataSize Size of Data found. If size is less than the
29 data, this value contains the required size.
30 @param Data The buffer to return the contents of the variable. May be NULL
31 with a zero DataSize in order to determine the size buffer needed.
33 @return EFI_INVALID_PARAMETER Invalid parameter
34 @return EFI_SUCCESS Find the specified variable
35 @return EFI_NOT_FOUND Not found
36 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result
41 RuntimeServiceGetVariable (
42 IN CHAR16
*VariableName
,
43 IN EFI_GUID
*VendorGuid
,
44 OUT UINT32
*Attributes OPTIONAL
,
45 IN OUT UINTN
*DataSize
,
46 OUT VOID
*Data OPTIONAL
49 return EmuGetVariable (
55 &mVariableModuleGlobal
->VariableGlobal
[Physical
]
61 This code Finds the Next available variable.
63 @param VariableNameSize The size of the VariableName buffer. The size must be large enough to fit input
64 string supplied in VariableName buffer.
65 @param VariableName On input, supplies the last VariableName that was returned by GetNextVariableName().
66 On output, returns the Null-terminated Unicode string of the current variable.
67 @param VendorGuid On input, supplies the last VendorGuid that was returned by GetNextVariableName().
68 On output, returns the VendorGuid of the current variable.
70 @retval EFI_SUCCESS The function completed successfully.
71 @retval EFI_NOT_FOUND The next variable was not found.
72 @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result.
73 VariableNameSize has been updated with the size needed to complete the request.
74 @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL.
75 @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and
76 GUID of an existing variable.
77 @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of
78 the input VariableName buffer.
83 RuntimeServiceGetNextVariableName (
84 IN OUT UINTN
*VariableNameSize
,
85 IN OUT CHAR16
*VariableName
,
86 IN OUT EFI_GUID
*VendorGuid
89 return EmuGetNextVariableName (
93 &mVariableModuleGlobal
->VariableGlobal
[Physical
]
99 This code sets variable in storage blocks (Volatile or Non-Volatile).
101 @param VariableName Name of Variable to be found
102 @param VendorGuid Variable vendor GUID
103 @param Attributes Attribute value of the variable found
104 @param DataSize Size of Data found. If size is less than the
105 data, this value contains the required size.
106 @param Data Data pointer
108 @return EFI_INVALID_PARAMETER Invalid parameter
109 @return EFI_SUCCESS Set successfully
110 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable
111 @return EFI_NOT_FOUND Not found
112 @return EFI_WRITE_PROTECTED Variable is read-only
117 RuntimeServiceSetVariable (
118 IN CHAR16
*VariableName
,
119 IN EFI_GUID
*VendorGuid
,
120 IN UINT32 Attributes
,
125 return EmuSetVariable (
131 &mVariableModuleGlobal
->VariableGlobal
[Physical
],
132 &mVariableModuleGlobal
->VolatileLastVariableOffset
,
133 &mVariableModuleGlobal
->NonVolatileLastVariableOffset
139 This code returns information about the EFI variables.
141 @param Attributes Attributes bitmask to specify the type of variables
142 on which to return information.
143 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
144 for the EFI variables associated with the attributes specified.
145 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
146 for EFI variables associated with the attributes specified.
147 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
148 associated with the attributes specified.
150 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
151 @return EFI_SUCCESS Query successfully.
152 @return EFI_UNSUPPORTED The attribute is not supported on this platform.
157 RuntimeServiceQueryVariableInfo (
158 IN UINT32 Attributes
,
159 OUT UINT64
*MaximumVariableStorageSize
,
160 OUT UINT64
*RemainingVariableStorageSize
,
161 OUT UINT64
*MaximumVariableSize
164 return EmuQueryVariableInfo (
166 MaximumVariableStorageSize
,
167 RemainingVariableStorageSize
,
169 &mVariableModuleGlobal
->VariableGlobal
[Physical
]
174 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
176 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
177 It convers pointer to new virtual address.
179 @param Event Event whose notification function is being invoked.
180 @param Context Pointer to the notification function's context.
185 VariableClassAddressChangeEvent (
190 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->PlatformLangCodes
);
191 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->LangCodes
);
192 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->PlatformLang
);
195 (VOID
**) &mVariableModuleGlobal
->VariableGlobal
[Physical
].NonVolatileVariableBase
199 (VOID
**) &mVariableModuleGlobal
->VariableGlobal
[Physical
].VolatileVariableBase
201 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
);
205 EmuVariable Driver main entry point. The Variable driver places the 4 EFI
206 runtime services in the EFI System Table and installs arch protocols
207 for variable read and write services being available. It also registers
208 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
210 @param[in] ImageHandle The firmware allocated handle for the EFI image.
211 @param[in] SystemTable A pointer to the EFI System Table.
213 @retval EFI_SUCCESS Variable service successfully initialized.
218 VariableServiceInitialize (
219 IN EFI_HANDLE ImageHandle
,
220 IN EFI_SYSTEM_TABLE
*SystemTable
223 EFI_HANDLE NewHandle
;
226 Status
= VariableCommonInitialize (ImageHandle
, SystemTable
);
227 ASSERT_EFI_ERROR (Status
);
229 SystemTable
->RuntimeServices
->GetVariable
= RuntimeServiceGetVariable
;
230 SystemTable
->RuntimeServices
->GetNextVariableName
= RuntimeServiceGetNextVariableName
;
231 SystemTable
->RuntimeServices
->SetVariable
= RuntimeServiceSetVariable
;
232 SystemTable
->RuntimeServices
->QueryVariableInfo
= RuntimeServiceQueryVariableInfo
;
235 // Now install the Variable Runtime Architectural Protocol on a new handle
238 Status
= gBS
->InstallMultipleProtocolInterfaces (
240 &gEfiVariableArchProtocolGuid
,
242 &gEfiVariableWriteArchProtocolGuid
,
246 ASSERT_EFI_ERROR (Status
);
248 Status
= gBS
->CreateEventEx (
251 VariableClassAddressChangeEvent
,
253 &gEfiEventVirtualAddressChangeGuid
,
254 &mVirtualAddressChangeEvent
256 ASSERT_EFI_ERROR (Status
);