Implement all four UEFI Runtime Variable services for the nonvolatile\r
and volatile storage space and install variable architecture protocol.\r
\r
-Copyright (c) 2006 - 2008, Intel Corporation \r
+Copyright (c) 2006 - 2009, Intel Corporation \r
All rights reserved. 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
\r
**/\r
\r
-\r
#include "Variable.h"\r
\r
VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;\r
EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
EFI_HANDLE mHandle = NULL;\r
\r
-//\r
-// The current Hii implementation accesses this variable a larg # of times on every boot.\r
-// Other common variables are only accessed a single time. This is why this cache algorithm\r
-// only targets a single variable. Probably to get an performance improvement out of\r
-// a Cache you would need a cache that improves the search performance for a variable.\r
-//\r
+///\r
+/// The current Hii implementation accesses this variable many times on every boot.\r
+/// Other common variables are only accessed once. This is why this cache algorithm\r
+/// only targets a single variable. Probably to get an performance improvement out of\r
+/// a Cache you would need a cache that improves the search performance for a variable.\r
+///\r
VARIABLE_CACHE_ENTRY mVariableCache[] = {\r
{\r
&gEfiGlobalVariableGuid,\r
}\r
};\r
\r
-GLOBAL_REMOVE_IF_UNREFERENCED VARIABLE_INFO_ENTRY *gVariableInfo = NULL;\r
+VARIABLE_INFO_ENTRY *gVariableInfo = NULL;\r
+\r
+/**\r
+ Acquires lock only at boot time. Simply returns at runtime.\r
\r
+ This is a temperary function which will be removed when\r
+ EfiAcquireLock() in UefiLib can handle the call in UEFI\r
+ Runtimer driver in RT phase.\r
+ It calls EfiAcquireLock() at boot time, and simply returns\r
+ at runtime.\r
\r
+ @param Lock A pointer to the lock to acquire\r
\r
-//\r
-// This is a temperary function which will be removed\r
-// when EfiAcquireLock in UefiLib can handle the\r
-// the call in UEFI Runtimer driver in RT phase.\r
-//\r
+**/\r
VOID\r
AcquireLockOnlyAtBootTime (\r
IN EFI_LOCK *Lock\r
}\r
}\r
\r
-//\r
-// This is a temperary function which will be removed\r
-// when EfiAcquireLock in UefiLib can handle the\r
-// the call in UEFI Runtimer driver in RT phase.\r
-//\r
+/**\r
+ Releases lock only at boot time. Simply returns at runtime.\r
+\r
+ This is a temperary function which will be removed when\r
+ EfiReleaseLock() in UefiLib can handle the call in UEFI\r
+ Runtimer driver in RT phase.\r
+ It calls EfiReleaseLock() at boot time, and simply returns\r
+ at runtime.\r
+\r
+ @param Lock A pointer to the lock to release\r
+\r
+**/\r
VOID\r
ReleaseLockOnlyAtBootTime (\r
IN EFI_LOCK *Lock\r
\r
CopyGuid (&gVariableInfo->VendorGuid, VendorGuid);\r
gVariableInfo->Name = AllocatePool (StrLen (VariableName));\r
+ ASSERT (gVariableInfo->Name != NULL);\r
StrCpy (gVariableInfo->Name, VariableName);\r
gVariableInfo->Volatile = Volatile;\r
\r
- gBS->InstallConfigurationTable (&gEfiVariableInfoGuid, gVariableInfo);\r
+ gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r
}\r
\r
\r
\r
CopyGuid (&Entry->Next->VendorGuid, VendorGuid);\r
Entry->Next->Name = AllocatePool (StrLen (VariableName));\r
+ ASSERT (Entry->Next->Name != NULL);\r
StrCpy (Entry->Next->Name, VariableName);\r
Entry->Next->Volatile = Volatile;\r
}\r
}\r
\r
\r
-BOOLEAN\r
-IsValidVariableHeader (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
This code checks if variable header is valid or not.\r
\r
-Arguments:\r
- Variable Pointer to the Variable Header.\r
+ @param Variable Pointer to the Variable Header.\r
\r
-Returns:\r
- TRUE Variable header is valid.\r
- FALSE Variable header is not valid.\r
+ @retval TRUE Variable header is valid.\r
+ @retval FALSE Variable header is not valid.\r
\r
---*/\r
+**/\r
+BOOLEAN\r
+IsValidVariableHeader (\r
+ IN VARIABLE_HEADER *Variable\r
+ )\r
{\r
if (Variable == NULL || Variable->StartId != VARIABLE_DATA) {\r
return FALSE;\r
}\r
\r
\r
+/**\r
+\r
+ This function writes data to the FWH at the correct LBA even if the LBAs\r
+ are fragmented.\r
+\r
+ @param Global Pointer to VARAIBLE_GLOBAL structure\r
+ @param Volatile Point out the Variable is Volatile or Non-Volatile\r
+ @param SetByIndex TRUE if target pointer is given as index\r
+ FALSE if target pointer is absolute\r
+ @param Instance Instance of FV Block services\r
+ @param DataPtrIndex Pointer to the Data from the end of VARIABLE_STORE_HEADER\r
+ structure\r
+ @param DataSize Size of data to be written\r
+ @param Buffer Pointer to the buffer from which data is written\r
+\r
+ @retval EFI_INVALID_PARAMETER Parameters not valid\r
+ @retval EFI_SUCCESS Variable store successfully updated\r
+\r
+**/\r
EFI_STATUS\r
UpdateVariableStore (\r
IN VARIABLE_GLOBAL *Global,\r
IN UINT32 DataSize,\r
IN UINT8 *Buffer\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This function writes data to the FWH at the correct LBA even if the LBAs\r
- are fragmented.\r
-\r
-Arguments:\r
-\r
- Global - Pointer to VARAIBLE_GLOBAL structure\r
- Volatile - If the Variable is Volatile or Non-Volatile\r
- SetByIndex - TRUE: Target pointer is given as index\r
- FALSE: Target pointer is absolute\r
- Instance - Instance of FV Block services\r
- DataPtrIndex - Pointer to the Data from the end of VARIABLE_STORE_HEADER\r
- structure\r
- DataSize - Size of data to be written.\r
- Buffer - Pointer to the buffer from which data is written\r
-\r
-Returns:\r
-\r
- EFI_INVALID_PARAMETER - Parameters not valid\r
- EFI_SUCCESS - Variable store successfully updated\r
-\r
---*/\r
{\r
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r
UINTN BlockIndex2;\r
}\r
\r
\r
-VARIABLE_STORE_STATUS\r
-GetVariableStoreStatus (\r
- IN VARIABLE_STORE_HEADER *VarStoreHeader\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
This code gets the current status of Variable Store.\r
\r
-Arguments:\r
-\r
- VarStoreHeader Pointer to the Variable Store Header.\r
+ @param VarStoreHeader Pointer to the Variable Store Header.\r
\r
-Returns:\r
+ @retval EfiRaw Variable store status is raw\r
+ @retval EfiValid Variable store status is valid\r
+ @retval EfiInvalid Variable store status is invalid\r
\r
- EfiRaw Variable store status is raw\r
- EfiValid Variable store status is valid\r
- EfiInvalid Variable store status is invalid\r
-\r
---*/\r
+**/\r
+VARIABLE_STORE_STATUS\r
+GetVariableStoreStatus (\r
+ IN VARIABLE_STORE_HEADER *VarStoreHeader\r
+ )\r
{\r
- if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE &&\r
+ if (CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid) &&\r
VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
) {\r
\r
return EfiValid;\r
- } else if (VarStoreHeader->Signature == 0xffffffff &&\r
- VarStoreHeader->Size == 0xffffffff &&\r
- VarStoreHeader->Format == 0xff &&\r
- VarStoreHeader->State == 0xff\r
+ } else if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&\r
+ ((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&\r
+ ((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&\r
+ ((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&\r
+ VarStoreHeader->Size == 0xffffffff &&\r
+ VarStoreHeader->Format == 0xff &&\r
+ VarStoreHeader->State == 0xff\r
) {\r
\r
return EfiRaw;\r
}\r
\r
\r
-UINTN\r
-NameSizeOfVariable (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
This code gets the size of name of variable.\r
\r
-Arguments:\r
-\r
- Variable Pointer to the Variable Header.\r
+ @param Variable Pointer to the Variable Header\r
\r
-Returns:\r
+ @return UINTN Size of variable in bytes\r
\r
- UINTN Size of variable in bytes\r
-\r
---*/\r
+**/\r
+UINTN\r
+NameSizeOfVariable (\r
+ IN VARIABLE_HEADER *Variable\r
+ )\r
{\r
if (Variable->State == (UINT8) (-1) ||\r
- Variable->DataSize == (UINT32) -1 ||\r
- Variable->NameSize == (UINT32) -1 ||\r
- Variable->Attributes == (UINT32) -1) {\r
+ Variable->DataSize == (UINT32) (-1) ||\r
+ Variable->NameSize == (UINT32) (-1) ||\r
+ Variable->Attributes == (UINT32) (-1)) {\r
return 0;\r
}\r
return (UINTN) Variable->NameSize;\r
}\r
\r
-UINTN\r
-DataSizeOfVariable (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the size of name of variable.\r
-\r
-Arguments:\r
+/**\r
\r
- Variable Pointer to the Variable Header.\r
+ This code gets the size of variable data.\r
\r
-Returns:\r
+ @param Variable Pointer to the Variable Header\r
\r
- UINTN Size of variable in bytes\r
+ @return Size of variable in bytes\r
\r
---*/\r
+**/\r
+UINTN\r
+DataSizeOfVariable (\r
+ IN VARIABLE_HEADER *Variable\r
+ )\r
{\r
- if (Variable->State == (UINT8) -1 ||\r
- Variable->DataSize == (UINT32) -1 ||\r
- Variable->NameSize == (UINT32) -1 ||\r
- Variable->Attributes == (UINT32) -1) {\r
+ if (Variable->State == (UINT8) (-1) ||\r
+ Variable->DataSize == (UINT32) (-1) ||\r
+ Variable->NameSize == (UINT32) (-1) ||\r
+ Variable->Attributes == (UINT32) (-1)) {\r
return 0;\r
}\r
return (UINTN) Variable->DataSize;\r
}\r
\r
-CHAR16 *\r
-GetVariableNamePtr (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
This code gets the pointer to the variable name.\r
\r
-Arguments:\r
+ @param Variable Pointer to the Variable Header\r
\r
- Variable Pointer to the Variable Header.\r
+ @return Pointer to Variable Name which is Unicode encoding\r
\r
-Returns:\r
-\r
- CHAR16* Pointer to Variable Name\r
-\r
---*/\r
+**/\r
+CHAR16 *\r
+GetVariableNamePtr (\r
+ IN VARIABLE_HEADER *Variable\r
+ )\r
{\r
\r
return (CHAR16 *) (Variable + 1);\r
}\r
\r
-UINT8 *\r
-GetVariableDataPtr (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
This code gets the pointer to the variable data.\r
\r
-Arguments:\r
-\r
- Variable Pointer to the Variable Header.\r
+ @param Variable Pointer to the Variable Header\r
\r
-Returns:\r
+ @return Pointer to Variable Data\r
\r
- UINT8* Pointer to Variable Data\r
-\r
---*/\r
+**/\r
+UINT8 *\r
+GetVariableDataPtr (\r
+ IN VARIABLE_HEADER *Variable\r
+ )\r
{\r
UINTN Value;\r
\r
}\r
\r
\r
-VARIABLE_HEADER *\r
-GetNextVariablePtr (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
This code gets the pointer to the next variable header.\r
\r
-Arguments:\r
-\r
- Variable Pointer to the Variable Header.\r
+ @param Variable Pointer to the Variable Header\r
\r
-Returns:\r
+ @return Pointer to next variable header\r
\r
- VARIABLE_HEADER* Pointer to next variable header.\r
-\r
---*/\r
+**/\r
+VARIABLE_HEADER *\r
+GetNextVariablePtr (\r
+ IN VARIABLE_HEADER *Variable\r
+ )\r
{\r
UINTN Value;\r
\r
return (VARIABLE_HEADER *) HEADER_ALIGN (Value);\r
}\r
\r
-VARIABLE_HEADER *\r
-GetStartPointer (\r
- IN VARIABLE_STORE_HEADER *VarStoreHeader\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the pointer to the first variable memory pointer byte\r
-\r
-Arguments:\r
+/**\r
\r
- VarStoreHeader Pointer to the Variable Store Header.\r
+ Gets the pointer to the first variable header in given variable store area.\r
\r
-Returns:\r
+ @param VarStoreHeader Pointer to the Variable Store Header.\r
\r
- VARIABLE_HEADER* Pointer to last unavailable Variable Header\r
+ @return Pointer to the first variable header\r
\r
---*/\r
+**/\r
+VARIABLE_HEADER *\r
+GetStartPointer (\r
+ IN VARIABLE_STORE_HEADER *VarStoreHeader\r
+ )\r
{\r
//\r
// The end of variable store\r
return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);\r
}\r
\r
-VARIABLE_HEADER *\r
-GetEndPointer (\r
- IN VARIABLE_STORE_HEADER *VarStoreHeader\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the pointer to the last variable memory pointer byte\r
+/**\r
\r
-Arguments:\r
+ Gets the pointer to the end of the variable storage area.\r
\r
- VarStoreHeader Pointer to the Variable Store Header.\r
+ This function gets pointer to the end of the variable storage\r
+ area, according to the input variable store header.\r
\r
-Returns:\r
+ @param VarStoreHeader Pointer to the Variable Store Header\r
\r
- VARIABLE_HEADER* Pointer to last unavailable Variable Header\r
+ @return Pointer to the end of the variable storage area \r
\r
---*/\r
+**/\r
+VARIABLE_HEADER *\r
+GetEndPointer (\r
+ IN VARIABLE_STORE_HEADER *VarStoreHeader\r
+ )\r
{\r
//\r
// The end of variable store\r
}\r
\r
\r
+/**\r
+\r
+ Variable store garbage collection and reclaim operation.\r
+\r
+ @param VariableBase Base address of variable store\r
+ @param LastVariableOffset Offset of last variable\r
+ @param IsVolatile The variable store is volatile or not,\r
+ if it is non-volatile, need FTW\r
+ @param UpdatingVariable Pointer to updateing variable.\r
+\r
+ @return EFI_OUT_OF_RESOURCES\r
+ @return EFI_SUCCESS\r
+ @return Others\r
+\r
+**/\r
EFI_STATUS\r
Reclaim (\r
IN EFI_PHYSICAL_ADDRESS VariableBase,\r
IN BOOLEAN IsVolatile,\r
IN VARIABLE_HEADER *UpdatingVariable\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Variable store garbage collection and reclaim operation\r
-\r
-Arguments:\r
-\r
- VariableBase Base address of variable store\r
- LastVariableOffset Offset of last variable\r
- IsVolatile The variable store is volatile or not,\r
- if it is non-volatile, need FTW\r
-\r
-Returns:\r
-\r
- EFI STATUS\r
-\r
---*/\r
{\r
VARIABLE_HEADER *Variable;\r
VARIABLE_HEADER *AddedVariable;\r
CopyMem (ValidBuffer, VariableStoreHeader, sizeof (VARIABLE_STORE_HEADER));\r
CurrPtr = (UINT8 *) GetStartPointer ((VARIABLE_STORE_HEADER *) ValidBuffer);\r
\r
- //\r
- // Start Pointers for the variable.\r
- //\r
-\r
//\r
// Reinstall all ADDED variables as long as they are not identical to Updating Variable\r
// \r
\r
@param[in] VariableName Name of variable\r
@param[in] VendorGuid Guid of variable\r
- @param[in] Attribute Attribue of the variable\r
+ @param[in] Attributes Attribues of the variable\r
@param[in] DataSize Size of data. 0 means delete\r
@param[in] Data Variable data\r
\r
UINTN Index;\r
\r
if (EfiAtRuntime ()) {\r
+ //\r
// Don't use the cache at runtime\r
+ // \r
return;\r
}\r
\r
if (StrCmp (VariableName, Entry->Name) == 0) { \r
Entry->Attributes = Attributes;\r
if (DataSize == 0) {\r
+ //\r
// Delete Case\r
+ //\r
if (Entry->DataSize != 0) {\r
FreePool (Entry->Data);\r
}\r
CopyMem (Entry->Data, Data, DataSize);\r
} else {\r
Entry->Data = AllocatePool (DataSize);\r
+ ASSERT (Entry->Data != NULL);\r
+\r
Entry->DataSize = DataSize;\r
CopyMem (Entry->Data, Data, DataSize);\r
}\r
\r
\r
/**\r
- Search the cache to see if the variable is in the cache.\r
+ Search the cache to check if the variable is in it.\r
\r
- @param[in] VariableName Name of variable\r
- @param[in] VendorGuid Guid of variable\r
- @param[in] Attribute Attribue returned \r
- @param[in] DataSize Size of data returned\r
- @param[in] Data Variable data returned\r
+ This function searches the variable cache. If the variable to find exists, return its data\r
+ and attributes.\r
\r
- @retval EFI_SUCCESS VariableGuid & VariableName data was returned.\r
- @retval other Not found.\r
+ @param VariableName A Null-terminated Unicode string that is the name of the vendor's\r
+ variable. Each VariableName is unique for each \r
+ VendorGuid.\r
+ @param VendorGuid A unique identifier for the vendor\r
+ @param Attributes Pointer to the attributes bitmask of the variable for output.\r
+ @param DataSize On input, size of the buffer of Data.\r
+ On output, size of the variable's data.\r
+ @param Data Pointer to the data buffer for output.\r
+\r
+ @retval EFI_SUCCESS VariableGuid & VariableName data was returned.\r
+ @retval EFI_NOT_FOUND No matching variable found in cache.\r
+ @retval EFI_BUFFER_TOO_SMALL *DataSize is smaller than size of the variable's data to return.\r
\r
**/\r
EFI_STATUS\r
return EFI_NOT_FOUND;\r
}\r
\r
+/**\r
+ Finds variable in storage blocks of volatile and non-volatile storage areas.\r
+\r
+ This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
+ If VariableName is an empty string, then we just return the first\r
+ qualified variable without comparing VariableName and VendorGuid.\r
+ Otherwise, VariableName and VendorGuid are compared.\r
+\r
+ @param VariableName Name of the variable to be found\r
+ @param VendorGuid Vendor GUID to be found.\r
+ @param PtrTrack VARIABLE_POINTER_TRACK structure for output,\r
+ including the range searched and the target position.\r
+ @param Global Pointer to VARIABLE_GLOBAL structure, including\r
+ base of volatile variable storage area, base of\r
+ NV variable storage area, and a lock.\r
+\r
+ @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while\r
+ VendorGuid is NULL\r
+ @retval EFI_SUCCESS Variable successfully found\r
+ @retval EFI_INVALID_PARAMETER Variable not found\r
\r
+**/\r
EFI_STATUS\r
FindVariable (\r
IN CHAR16 *VariableName,\r
OUT VARIABLE_POINTER_TRACK *PtrTrack,\r
IN VARIABLE_GLOBAL *Global\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code finds variable in storage blocks (Volatile or Non-Volatile)\r
-\r
-Arguments:\r
-\r
- VariableName Name of the variable to be found\r
- VendorGuid Vendor GUID to be found.\r
- PtrTrack Variable Track Pointer structure that contains\r
- Variable Information.\r
- Contains the pointer of Variable header.\r
- Global VARIABLE_GLOBAL pointer\r
-\r
-Returns:\r
-\r
- EFI STATUS\r
-\r
---*/\r
{\r
VARIABLE_HEADER *Variable[2];\r
VARIABLE_HEADER *InDeletedVariable;\r
if (Variable[Index]->State == VAR_ADDED || \r
Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)\r
) {\r
- if (!EfiAtRuntime () || (Variable[Index]->Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
+ if (!EfiAtRuntime () || ((Variable[Index]->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {\r
if (VariableName[0] == 0) {\r
if (Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
InDeletedVariable = Variable[Index];\r
Point = (VOID *) GetVariableNamePtr (Variable[Index]);\r
\r
ASSERT (NameSizeOfVariable (Variable[Index]) != 0);\r
- if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable[Index]))) {\r
+ if (CompareMem (VariableName, Point, NameSizeOfVariable (Variable[Index])) == 0) {\r
if (Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
InDeletedVariable = Variable[Index];\r
InDeletedStorageIndex = Index;\r
}\r
\r
\r
+/**\r
\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code finds variable in storage blocks (Volatile or Non-Volatile)\r
-\r
-Arguments:\r
-\r
- VariableName Name of Variable to be found\r
- VendorGuid Variable vendor GUID\r
- Attributes OPTIONAL Attribute value of the variable found\r
- DataSize Size of Data found. If size is less than the\r
- data, this value contains the required size.\r
- Data Data pointer\r
- Global Pointer to VARIABLE_GLOBAL structure\r
- Instance Instance of the Firmware Volume.\r
-\r
-Returns:\r
-\r
- EFI_INVALID_PARAMETER - Invalid parameter\r
- EFI_SUCCESS - Find the specified variable\r
- EFI_NOT_FOUND - Not found\r
- EFI_BUFFER_TO_SMALL - DataSize is too small for the result\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 Data pointer.\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
+**/\r
EFI_STATUS\r
EFIAPI\r
RuntimeServiceGetVariable (\r
\r
\r
\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code Finds the Next available variable\r
-\r
-Arguments:\r
+/**\r
\r
- VariableNameSize Size of the variable\r
- VariableName Pointer to variable name\r
- VendorGuid Variable Vendor Guid\r
- Global VARIABLE_GLOBAL structure pointer.\r
- Instance FV instance\r
+ This code Finds the Next available variable.\r
\r
-Returns:\r
+ @param VariableNameSize Size of the variable name\r
+ @param VariableName Pointer to variable name\r
+ @param VendorGuid Variable Vendor Guid\r
\r
- EFI STATUS\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
+**/\r
EFI_STATUS\r
EFIAPI\r
RuntimeServiceGetNextVariableName (\r
// Variable is found\r
//\r
if (IsValidVariableHeader (Variable.CurrPtr) && Variable.CurrPtr->State == VAR_ADDED) {\r
- if (!(EfiAtRuntime () && !(Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {\r
+ if ((EfiAtRuntime () && ((Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) == 0) {\r
VarNameSize = NameSizeOfVariable (Variable.CurrPtr);\r
ASSERT (VarNameSize != 0);\r
\r
return Status;\r
}\r
\r
+/**\r
\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code sets variable in storage blocks (Volatile or Non-Volatile)\r
-\r
-Arguments:\r
-\r
- VariableName Name of Variable to be found\r
- VendorGuid Variable vendor GUID\r
- Attributes Attribute value of the variable found\r
- DataSize Size of Data found. If size is less than the\r
- data, this value contains the required size.\r
- Data Data pointer\r
- Global Pointer to VARIABLE_GLOBAL structure\r
- VolatileOffset The offset of last volatile variable\r
- NonVolatileOffset The offset of last non-volatile variable\r
- Instance Instance of the Firmware Volume.\r
+ This code sets variable in storage blocks (Volatile or Non-Volatile).\r
\r
-Returns:\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
- EFI_INVALID_PARAMETER - Invalid parameter\r
- EFI_SUCCESS - Set successfully\r
- EFI_OUT_OF_RESOURCES - Resource not enough to set variable\r
- EFI_NOT_FOUND - Not found\r
- EFI_DEVICE_ERROR - Variable can not be saved due to hardware failure\r
- EFI_WRITE_PROTECTED - Variable is read-only\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
+**/\r
EFI_STATUS\r
EFIAPI\r
RuntimeServiceSetVariable (\r
\r
//\r
// The size of the VariableName, including the Unicode Null in bytes plus\r
- // the DataSize is limited to maximum size of MAX_HARDWARE_ERROR_VARIABLE_SIZE (32K)\r
- // bytes for HwErrRec, and MAX_VARIABLE_SIZE (1024) bytes for the others.\r
+ // the DataSize is limited to maximum size of FixedPcdGet32(PcdMaxHardwareErrorVariableSize)\r
+ // bytes for HwErrRec, and FixedPcdGet32(PcdMaxVariableSize) bytes for the others.\r
//\r
if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
- if ((DataSize > MAX_HARDWARE_ERROR_VARIABLE_SIZE) || \r
- (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > MAX_HARDWARE_ERROR_VARIABLE_SIZE)) {\r
+ if ((DataSize > FixedPcdGet32(PcdMaxHardwareErrorVariableSize)) || \r
+ (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > FixedPcdGet32(PcdMaxHardwareErrorVariableSize))) {\r
return EFI_INVALID_PARAMETER;\r
} \r
} else {\r
//\r
// The size of the VariableName, including the Unicode Null in bytes plus\r
- // the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes.\r
+ // the DataSize is limited to maximum size of FixedPcdGet32(PcdMaxVariableSize) bytes.\r
//\r
- if ((DataSize > MAX_VARIABLE_SIZE) ||\r
- (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > MAX_VARIABLE_SIZE)) {\r
+ if ((DataSize > FixedPcdGet32(PcdMaxVariableSize)) ||\r
+ (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > FixedPcdGet32(PcdMaxVariableSize))) {\r
return EFI_INVALID_PARAMETER;\r
} \r
} \r
//\r
// Only variable have NV attribute can be updated/deleted in Runtime\r
//\r
- if (!(Variable.CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
+ if ((Variable.CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
Status = EFI_INVALID_PARAMETER;\r
goto Done; \r
}\r
// Only variable have NV|RT attribute can be created in Runtime\r
//\r
if (EfiAtRuntime () &&\r
- (!(Attributes & EFI_VARIABLE_RUNTIME_ACCESS) || !(Attributes & EFI_VARIABLE_NON_VOLATILE))) {\r
+ (((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) || ((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0))) {\r
Status = EFI_INVALID_PARAMETER;\r
goto Done;\r
} \r
//\r
NextVariable = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));\r
\r
- SetMem (NextVariable, SCRATCH_SIZE, 0xff);\r
+ SetMem (NextVariable, FixedPcdGet32(PcdMaxVariableSize), 0xff);\r
\r
NextVariable->StartId = VARIABLE_DATA;\r
NextVariable->Attributes = Attributes;\r
// include pad size.\r
//\r
VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);\r
- if (Attributes & EFI_VARIABLE_NON_VOLATILE) {\r
+ if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {\r
//\r
// Create a nonvolatile variable\r
//\r
return Status;\r
}\r
\r
-\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
This code returns information about the EFI variables.\r
\r
-Arguments:\r
-\r
- Attributes Attributes bitmask to specify the type of variables\r
- on which to return information.\r
- MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
- for the EFI variables associated with the attributes specified.\r
- RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r
- for EFI variables associated with the attributes specified.\r
- MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r
- associated with the attributes specified.\r
- Global Pointer to VARIABLE_GLOBAL structure.\r
- Instance Instance of the Firmware Volume.\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
-Returns:\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
- EFI STATUS\r
- EFI_INVALID_PARAMETER - An invalid combination of attribute bits was supplied.\r
- EFI_SUCCESS - Query successfully.\r
- EFI_UNSUPPORTED - The attribute is not supported on this platform.\r
-\r
---*/\r
+**/\r
EFI_STATUS\r
EFIAPI\r
RuntimeServiceQueryVariableInfo (\r
// Make sure if runtime bit is set, boot service bit is set also.\r
//\r
return EFI_INVALID_PARAMETER;\r
- } else if (EfiAtRuntime () && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
+ } else if (EfiAtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {\r
//\r
// Make sure RT Attribute is set if we are in Runtime phase.\r
//\r
*RemainingVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
\r
//\r
- // Let *MaximumVariableSize be MAX_VARIABLE_SIZE with the exception of the variable header size.\r
+ // Let *MaximumVariableSize be FixedPcdGet32(PcdMaxVariableSize) with the exception of the variable header size.\r
//\r
- *MaximumVariableSize = MAX_VARIABLE_SIZE - sizeof (VARIABLE_HEADER);\r
+ *MaximumVariableSize = FixedPcdGet32(PcdMaxVariableSize) - sizeof (VARIABLE_HEADER);\r
\r
//\r
// Harware error record variable needs larger size.\r
//\r
if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
- *MaximumVariableSize = MAX_HARDWARE_ERROR_VARIABLE_SIZE - sizeof (VARIABLE_HEADER);\r
+ *MaximumVariableSize = FixedPcdGet32(PcdMaxHardwareErrorVariableSize) - sizeof (VARIABLE_HEADER);\r
}\r
\r
//\r
return EFI_SUCCESS;\r
}\r
\r
+\r
+/**\r
+ Notification function of EVT_GROUP_READY_TO_BOOT event group.\r
+\r
+ This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.\r
+ When the Boot Manager is about to load and execute a boot option, it reclaims variable\r
+ storage if free size is below the threshold.\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
ReclaimForOS(\r
}\r
}\r
\r
+/**\r
+ Initializes variable store area for non-volatile and volatile variable.\r
+\r
+ @param ImageHandle The Image handle of this driver.\r
+ @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r
+\r
+ @retval EFI_SUCCESS Function successfully executed.\r
+ @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r
+\r
+**/\r
EFI_STATUS\r
VariableCommonInitialize (\r
IN EFI_HANDLE ImageHandle,\r
IN EFI_SYSTEM_TABLE *SystemTable\r
)\r
-/*++\r
-\r
-Routine Description:\r
- This function does common initialization for variable services\r
-\r
-Arguments:\r
-\r
- ImageHandle - The firmware allocated handle for the EFI image.\r
- SystemTable - A pointer to the EFI System Table.\r
-\r
-Returns:\r
-\r
- Status code.\r
-\r
- EFI_NOT_FOUND - Variable store area not found.\r
- EFI_UNSUPPORTED - Currently only one non-volatile variable store is supported.\r
- EFI_SUCCESS - Variable services successfully initialized.\r
-\r
---*/\r
{\r
EFI_STATUS Status;\r
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
//\r
// Allocate memory for volatile variable store\r
//\r
- VolatileVariableStore = AllocateRuntimePool (VARIABLE_STORE_SIZE + SCRATCH_SIZE);\r
+ VolatileVariableStore = AllocateRuntimePool (FixedPcdGet32(PcdVariableStoreSize) + FixedPcdGet32(PcdMaxVariableSize));\r
if (VolatileVariableStore == NULL) {\r
FreePool (mVariableModuleGlobal);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- SetMem (VolatileVariableStore, VARIABLE_STORE_SIZE + SCRATCH_SIZE, 0xff);\r
+ SetMem (VolatileVariableStore, FixedPcdGet32(PcdVariableStoreSize) + FixedPcdGet32(PcdMaxVariableSize), 0xff);\r
\r
//\r
// Variable Specific Data\r
mVariableModuleGlobal->VariableGlobal.VolatileVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VolatileVariableStore;\r
mVariableModuleGlobal->VolatileLastVariableOffset = (UINTN) GetStartPointer (VolatileVariableStore) - (UINTN) VolatileVariableStore;\r
\r
- VolatileVariableStore->Signature = VARIABLE_STORE_SIGNATURE;\r
- VolatileVariableStore->Size = VARIABLE_STORE_SIZE;\r
+ CopyGuid (&VolatileVariableStore->Signature, &gEfiVariableGuid);\r
+ VolatileVariableStore->Size = FixedPcdGet32(PcdVariableStoreSize);\r
VolatileVariableStore->Format = VARIABLE_STORE_FORMATTED;\r
VolatileVariableStore->State = VARIABLE_STORE_HEALTHY;\r
VolatileVariableStore->Reserved = 0;\r
return Status;\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
/**\r
Variable 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 availible. \r
+ for variable read and write services being availible. 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 The entry point is executed successfully.\r
- @retval other Some error occurs when executing this entry point.\r
+ @retval EFI_SUCCESS Variable service successfully initialized.\r
\r
**/\r
EFI_STATUS\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- Status = gBS->CreateEvent (\r
- EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\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