3 Implment all four UEFI runtime variable services and
4 install variable architeture protocol.
6 Copyright (c) 2006 - 2008, Intel Corporation
7 All rights reserved. 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 Data pointer.
32 @return EFI_INVALID_PARAMETER Invalid parameter
33 @return EFI_SUCCESS Find the specified variable
34 @return EFI_NOT_FOUND Not found
35 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result
40 RuntimeServiceGetVariable (
41 IN CHAR16
*VariableName
,
42 IN EFI_GUID
*VendorGuid
,
43 OUT UINT32
*Attributes OPTIONAL
,
44 IN OUT UINTN
*DataSize
,
54 &mVariableModuleGlobal
->VariableGlobal
[Physical
],
55 mVariableModuleGlobal
->FvbInstance
61 This code Finds the Next available variable.
63 @param VariableNameSize Size of the variable name
64 @param VariableName Pointer to variable name
65 @param VendorGuid Variable Vendor Guid
67 @return EFI_INVALID_PARAMETER Invalid parameter
68 @return EFI_SUCCESS Find the specified variable
69 @return EFI_NOT_FOUND Not found
70 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result
75 RuntimeServiceGetNextVariableName (
76 IN OUT UINTN
*VariableNameSize
,
77 IN OUT CHAR16
*VariableName
,
78 IN OUT EFI_GUID
*VendorGuid
81 return GetNextVariableName (
85 &mVariableModuleGlobal
->VariableGlobal
[Physical
],
86 mVariableModuleGlobal
->FvbInstance
92 This code sets variable in storage blocks (Volatile or Non-Volatile).
94 @param VariableName Name of Variable to be found
95 @param VendorGuid Variable vendor GUID
96 @param Attributes Attribute value of the variable found
97 @param DataSize Size of Data found. If size is less than the
98 data, this value contains the required size.
99 @param Data Data pointer
101 @return EFI_INVALID_PARAMETER Invalid parameter
102 @return EFI_SUCCESS Set successfully
103 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable
104 @return EFI_NOT_FOUND Not found
105 @return EFI_WRITE_PROTECTED Variable is read-only
110 RuntimeServiceSetVariable (
111 IN CHAR16
*VariableName
,
112 IN EFI_GUID
*VendorGuid
,
113 IN UINT32 Attributes
,
124 &mVariableModuleGlobal
->VariableGlobal
[Physical
],
125 &mVariableModuleGlobal
->VolatileLastVariableOffset
,
126 &mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
127 mVariableModuleGlobal
->FvbInstance
133 This code returns information about the EFI variables.
135 @param Attributes Attributes bitmask to specify the type of variables
136 on which to return information.
137 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
138 for the EFI variables associated with the attributes specified.
139 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
140 for EFI variables associated with the attributes specified.
141 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
142 associated with the attributes specified.
144 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
145 @return EFI_SUCCESS Query successfully.
146 @return EFI_UNSUPPORTED The attribute is not supported on this platform.
151 RuntimeServiceQueryVariableInfo (
152 IN UINT32 Attributes
,
153 OUT UINT64
*MaximumVariableStorageSize
,
154 OUT UINT64
*RemainingVariableStorageSize
,
155 OUT UINT64
*MaximumVariableSize
158 return QueryVariableInfo (
160 MaximumVariableStorageSize
,
161 RemainingVariableStorageSize
,
163 &mVariableModuleGlobal
->VariableGlobal
[Physical
],
164 mVariableModuleGlobal
->FvbInstance
169 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
171 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
172 It convers pointer to new virtual address.
174 @param Event Event whose notification function is being invoked.
175 @param Context Pointer to the notification function's context.
180 VariableClassAddressChangeEvent (
187 (VOID
**) &mVariableModuleGlobal
->VariableGlobal
[Physical
].NonVolatileVariableBase
191 (VOID
**) &mVariableModuleGlobal
->VariableGlobal
[Physical
].VolatileVariableBase
193 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
);
197 EmuVariable Driver main entry point. The Variable driver places the 4 EFI
198 runtime services in the EFI System Table and installs arch protocols
199 for variable read and write services being availible. It also registers
200 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
202 @param[in] ImageHandle The firmware allocated handle for the EFI image.
203 @param[in] SystemTable A pointer to the EFI System Table.
205 @retval EFI_SUCCESS Variable service successfully initialized.
210 VariableServiceInitialize (
211 IN EFI_HANDLE ImageHandle
,
212 IN EFI_SYSTEM_TABLE
*SystemTable
215 EFI_HANDLE NewHandle
;
218 Status
= VariableCommonInitialize (ImageHandle
, SystemTable
);
219 ASSERT_EFI_ERROR (Status
);
221 SystemTable
->RuntimeServices
->GetVariable
= RuntimeServiceGetVariable
;
222 SystemTable
->RuntimeServices
->GetNextVariableName
= RuntimeServiceGetNextVariableName
;
223 SystemTable
->RuntimeServices
->SetVariable
= RuntimeServiceSetVariable
;
224 SystemTable
->RuntimeServices
->QueryVariableInfo
= RuntimeServiceQueryVariableInfo
;
227 // Now install the Variable Runtime Architectural Protocol on a new handle
230 Status
= gBS
->InstallMultipleProtocolInterfaces (
232 &gEfiVariableArchProtocolGuid
,
234 &gEfiVariableWriteArchProtocolGuid
,
238 ASSERT_EFI_ERROR (Status
);
240 Status
= gBS
->CreateEventEx (
243 VariableClassAddressChangeEvent
,
245 &gEfiEventVirtualAddressChangeGuid
,
246 &mVirtualAddressChangeEvent
248 ASSERT_EFI_ERROR (Status
);