+++ /dev/null
-/** @file\r
-\r
- Implment all four UEFI runtime variable services and\r
- install variable architeture protocol.\r
-\r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "Variable.h"\r
-\r
-EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
-\r
-/**\r
-\r
- This code finds variable in storage blocks (Volatile or Non-Volatile).\r
-\r
- @param VariableName Name of Variable to be found.\r
- @param VendorGuid Variable vendor GUID.\r
- @param Attributes Attribute value of the variable found.\r
- @param DataSize Size of Data found. If size is less than the\r
- data, this value contains the required size.\r
- @param Data The buffer to return the contents of the variable. May be NULL\r
- with a zero DataSize in order to determine the size buffer needed.\r
-\r
- @return EFI_INVALID_PARAMETER Invalid parameter\r
- @return EFI_SUCCESS Find the specified variable\r
- @return EFI_NOT_FOUND Not found\r
- @return EFI_BUFFER_TO_SMALL DataSize is too small for the result\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeServiceGetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data OPTIONAL\r
- )\r
-{\r
- return EmuGetVariable (\r
- VariableName,\r
- VendorGuid,\r
- Attributes OPTIONAL,\r
- DataSize,\r
- Data,\r
- &mVariableModuleGlobal->VariableGlobal[Physical]\r
- );\r
-}\r
-\r
-/**\r
-\r
- This code Finds the Next available variable.\r
-\r
- @param VariableNameSize The size of the VariableName buffer. The size must be large enough to fit input\r
- string supplied in VariableName buffer.\r
- @param VariableName On input, supplies the last VariableName that was returned by GetNextVariableName().\r
- On output, returns the Null-terminated Unicode string of the current variable.\r
- @param VendorGuid On input, supplies the last VendorGuid that was returned by GetNextVariableName().\r
- On output, returns the VendorGuid of the current variable.\r
-\r
- @retval EFI_SUCCESS The function completed successfully.\r
- @retval EFI_NOT_FOUND The next variable was not found.\r
- @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result.\r
- VariableNameSize has been updated with the size needed to complete the request.\r
- @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL.\r
- @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and\r
- GUID of an existing variable.\r
- @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of\r
- the input VariableName buffer.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeServiceGetNextVariableName (\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VendorGuid\r
- )\r
-{\r
- return EmuGetNextVariableName (\r
- VariableNameSize,\r
- VariableName,\r
- VendorGuid,\r
- &mVariableModuleGlobal->VariableGlobal[Physical]\r
- );\r
-}\r
-\r
-/**\r
-\r
- This code sets variable in storage blocks (Volatile or Non-Volatile).\r
-\r
- @param VariableName Name of Variable to be found\r
- @param VendorGuid Variable vendor GUID\r
- @param Attributes Attribute value of the variable found\r
- @param DataSize Size of Data found. If size is less than the\r
- data, this value contains the required size.\r
- @param Data Data pointer\r
-\r
- @return EFI_INVALID_PARAMETER Invalid parameter\r
- @return EFI_SUCCESS Set successfully\r
- @return EFI_OUT_OF_RESOURCES Resource not enough to set variable\r
- @return EFI_NOT_FOUND Not found\r
- @return EFI_WRITE_PROTECTED Variable is read-only\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeServiceSetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data\r
- )\r
-{\r
- return EmuSetVariable (\r
- VariableName,\r
- VendorGuid,\r
- Attributes,\r
- DataSize,\r
- Data,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- &mVariableModuleGlobal->VolatileLastVariableOffset,\r
- &mVariableModuleGlobal->NonVolatileLastVariableOffset\r
- );\r
-}\r
-\r
-/**\r
-\r
- This code returns information about the EFI variables.\r
-\r
- @param Attributes Attributes bitmask to specify the type of variables\r
- on which to return information.\r
- @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
- for the EFI variables associated with the attributes specified.\r
- @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r
- for EFI variables associated with the attributes specified.\r
- @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r
- associated with the attributes specified.\r
-\r
- @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r
- @return EFI_SUCCESS Query successfully.\r
- @return EFI_UNSUPPORTED The attribute is not supported on this platform.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RuntimeServiceQueryVariableInfo (\r
- IN UINT32 Attributes,\r
- OUT UINT64 *MaximumVariableStorageSize,\r
- OUT UINT64 *RemainingVariableStorageSize,\r
- OUT UINT64 *MaximumVariableSize\r
- )\r
-{\r
- return EmuQueryVariableInfo (\r
- Attributes,\r
- MaximumVariableStorageSize,\r
- RemainingVariableStorageSize,\r
- MaximumVariableSize,\r
- &mVariableModuleGlobal->VariableGlobal[Physical]\r
- );\r
-}\r
-\r
-/**\r
- Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
-\r
- This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
- It convers pointer to new virtual address.\r
-\r
- @param Event Event whose notification function is being invoked.\r
- @param Context Pointer to the notification function's context.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-VariableClassAddressChangeEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);\r
- EfiConvertPointer (\r
- 0x0,\r
- (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase\r
- );\r
- EfiConvertPointer (\r
- 0x0,\r
- (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase\r
- );\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
-}\r
-\r
-/**\r
- EmuVariable Driver main entry point. The Variable driver places the 4 EFI\r
- runtime services in the EFI System Table and installs arch protocols\r
- for variable read and write services being available. It also registers\r
- notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
-\r
- @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
- @param[in] SystemTable A pointer to the EFI System Table.\r
-\r
- @retval EFI_SUCCESS Variable service successfully initialized.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VariableServiceInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-{\r
- EFI_HANDLE NewHandle;\r
- EFI_STATUS Status;\r
-\r
- Status = VariableCommonInitialize (ImageHandle, SystemTable);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;\r
- SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;\r
- SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;\r
- SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;\r
-\r
- //\r
- // Now install the Variable Runtime Architectural Protocol on a new handle\r
- //\r
- NewHandle = NULL;\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &NewHandle,\r
- &gEfiVariableArchProtocolGuid,\r
- NULL,\r
- &gEfiVariableWriteArchProtocolGuid,\r
- NULL,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = gBS->CreateEventEx (\r
- EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- VariableClassAddressChangeEvent,\r
- NULL,\r
- &gEfiEventVirtualAddressChangeGuid,\r
- &mVirtualAddressChangeEvent\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return EFI_SUCCESS;\r
-}\r