/*++\r
\r
-Copyright (c) 2006, 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
-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
+Copyright (c) 2006, 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
+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
Module Name:\r
- \r
+\r
EmuVariable.c\r
\r
Abstract:\r
//\r
ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
\r
+STATIC\r
UINT32\r
EFIAPI\r
ArrayLength (\r
return (Count * 2) + 2;\r
}\r
\r
-UINTN\r
-EFIAPI\r
-GetPadSize (\r
- IN UINTN Value\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This function return the pad size for alignment\r
-\r
-Arguments:\r
-\r
- Value The value need to align\r
-\r
-Returns:\r
-\r
- Pad size for value\r
-\r
---*/\r
-{\r
- //\r
- // If alignment is 0 or 1, means no alignment required\r
- //\r
- if (ALIGNMENT == 0 || ALIGNMENT == 1) {\r
- return 0;\r
- }\r
-\r
- return ALIGNMENT - (Value % ALIGNMENT);\r
-}\r
-\r
-VARIABLE_STORE_STATUS\r
-EFIAPI\r
-GetVariableStoreStatus (\r
- IN VARIABLE_STORE_HEADER *VarStoreHeader\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the pointer to the variable name.\r
-\r
-Arguments:\r
-\r
- VarStoreHeader Pointer to the Variable Store Header.\r
-\r
-Returns:\r
-\r
- EfiHealthy Variable store is healthy\r
- EfiRaw Variable store is raw\r
- EfiInvalid Variable store is invalid\r
-\r
---*/\r
-{\r
- if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE &&\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
- ) {\r
-\r
- return EfiRaw;\r
- } else {\r
- return EfiInvalid;\r
- }\r
-}\r
-\r
+STATIC\r
UINT8 *\r
EFIAPI\r
GetVariableDataPtr (\r
//\r
// Be careful about pad size for alignment\r
//\r
- return (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (Variable) + Variable->NameSize + GetPadSize (Variable->NameSize));\r
+ return (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (Variable) + Variable->NameSize + GET_PAD_SIZE (Variable->NameSize));\r
}\r
\r
+STATIC\r
VARIABLE_HEADER *\r
EFIAPI\r
GetNextVariablePtr (\r
return VarHeader;\r
}\r
\r
+STATIC\r
VARIABLE_HEADER *\r
EFIAPI\r
GetEndPointer (\r
return (VARIABLE_HEADER *) ((UINTN) VolHeader + VolHeader->Size);\r
}\r
\r
+STATIC\r
EFI_STATUS\r
EFIAPI\r
FindVariable (\r
//\r
VarDataSize = Variable.CurrPtr->DataSize;\r
if (*DataSize >= VarDataSize) {\r
+ if (Data == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
- if (Attributes) {\r
+ if (Attributes != NULL) {\r
*Attributes = Variable.CurrPtr->Attributes;\r
}\r
\r
UINTN VarNameSize;\r
EFI_STATUS Status;\r
\r
- if (VariableNameSize == NULL || VendorGuid == NULL) {\r
+ if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
Variable.StartPtr = (VARIABLE_HEADER *) ((UINTN) (Global->VolatileVariableBase + sizeof (VARIABLE_STORE_HEADER)));\r
Variable.EndPtr = (VARIABLE_HEADER *) GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase));\r
} else {\r
- return EFI_NOT_FOUND;\r
+ goto Error;\r
}\r
\r
Variable.CurrPtr = Variable.StartPtr;\r
}\r
}\r
\r
+Error:\r
return EFI_NOT_FOUND;\r
}\r
\r
\r
if (Status == EFI_INVALID_PARAMETER) {\r
return Status;\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_VARIABLE_SIZE (1024) bytes.\r
- //\r
- else if (sizeof (VARIABLE_HEADER) + (ArrayLength (VariableName) + DataSize) > MAX_VARIABLE_SIZE) {\r
+ } else if (!EFI_ERROR (Status) && Variable.Volatile && EfiAtRuntime()) {\r
+ //\r
+ // If EfiAtRuntime and the variable is Volatile and Runtime Access, \r
+ // the volatile is ReadOnly, and SetVariable should be aborted and \r
+ // return EFI_WRITE_PROTECTED.\r
+ //\r
+ return EFI_WRITE_PROTECTED;\r
+ } else if (sizeof (VARIABLE_HEADER) + (ArrayLength (VariableName) + DataSize) > MAX_VARIABLE_SIZE) {\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
+ //\r
return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Make sure if runtime bit is set, boot service bit is set also\r
- //\r
- else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS\r
+ } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS\r
) {\r
+ //\r
+ // Make sure if runtime bit is set, boot service bit is set also\r
+ //\r
return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Runtime but Attribute is not Runtime\r
- //\r
- else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
+ } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
+ //\r
+ // Runtime but Attribute is not Runtime\r
+ //\r
return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Cannot set volatile variable in Runtime\r
- //\r
- else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
+ } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
+ //\r
+ // Cannot set volatile variable in Runtime\r
+ //\r
return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Setting a data variable with no access, or zero DataSize attributes\r
- // specified causes it to be deleted.\r
- //\r
- else if (DataSize == 0 || Attributes == 0) {\r
+ } else if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {\r
+ //\r
+ // Setting a data variable with no access, or zero DataSize attributes\r
+ // specified causes it to be deleted.\r
+ //\r
if (!EFI_ERROR (Status)) {\r
Variable.CurrPtr->State &= VAR_DELETED;\r
return EFI_SUCCESS;\r
//\r
VarNameOffset = sizeof (VARIABLE_HEADER);\r
VarNameSize = ArrayLength (VariableName);\r
- VarDataOffset = VarNameOffset + VarNameSize + GetPadSize (VarNameSize);\r
- VarSize = VarDataOffset + DataSize + GetPadSize (DataSize);\r
+ VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);\r
+ VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);\r
\r
if (Attributes & EFI_VARIABLE_NON_VOLATILE) {\r
if ((UINT32) (VarSize +*NonVolatileOffset) >\r
return EFI_SUCCESS;\r
}\r
\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+EFI_STATUS\r
+EFIAPI\r
+QueryVariableInfo (\r
+ IN UINT32 Attributes,\r
+ OUT UINT64 *MaximumVariableStorageSize,\r
+ OUT UINT64 *RemainingVariableStorageSize,\r
+ OUT UINT64 *MaximumVariableSize,\r
+ IN VARIABLE_GLOBAL *Global,\r
+ IN UINT32 Instance\r
+ )\r
+/*++\r
+\r
+Routine Description:\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 the EFI variables associated with the attributes specified.\r
+ MaximumVariableSize Pointer to the maximum size of the individual EFI variables\r
+ associated with the attributes specified.\r
+ Global Pointer to VARIABLE_GLOBAL structure.\r
+ Instance Instance of the Firmware Volume.\r
+\r
+Returns:\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
+ VARIABLE_HEADER *Variable;\r
+ VARIABLE_HEADER *NextVariable;\r
+ UINT64 VariableSize;\r
+ VARIABLE_STORE_HEADER *VariableStoreHeader;\r
+\r
+ if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)) == 0) {\r
+ //\r
+ // Make sure the Attributes combination is supported by the platform.\r
+ //\r
+ return EFI_UNSUPPORTED;\r
+ } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
+ //\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
+ //\r
+ // Make sure RT Attribute is set if we are in Runtime phase.\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
+ //\r
+ // Cannot Query volatile variable in Runtime\r
+ //\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
+ //\r
+ // Query is Volatile related.\r
+ //\r
+ VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase);\r
+ } else {\r
+ //\r
+ // Query is Non-Volatile related.\r
+ //\r
+ VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) Global->NonVolatileVariableBase);\r
+ }\r
+\r
+ //\r
+ // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize\r
+ // with the storage size (excluding the storage header size)\r
+ //\r
+ *MaximumVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
+ *RemainingVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
+\r
+ //\r
+ // Let *MaximumVariableSize be MAX_VARIABLE_SIZE\r
+ //\r
+ *MaximumVariableSize = MAX_VARIABLE_SIZE;\r
+\r
+ //\r
+ // Point to the starting address of the variables.\r
+ //\r
+ Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
+\r
+ //\r
+ // Now walk through the related variable store.\r
+ //\r
+ while (Variable < GetEndPointer (VariableStoreHeader)) {\r
+ if (Variable->StartId != VARIABLE_DATA) {\r
+ break;\r
+ }\r
+\r
+ NextVariable = (VARIABLE_HEADER *) (GetVariableDataPtr (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));\r
+ VariableSize = (UINT64) (UINTN) NextVariable - (UINT64) (UINTN) Variable;\r
+\r
+ if (Variable->State == VAR_ADDED) {\r
+ *RemainingVariableStorageSize -= VariableSize;\r
+ }\r
+\r
+ //\r
+ // Go to the next one.\r
+ //\r
+ Variable = NextVariable;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+#endif\r
+\r
+STATIC\r
EFI_STATUS\r
EFIAPI\r
InitializeVariableStore (\r
//\r
mVariableModuleGlobal = (ESAL_VARIABLE_GLOBAL *) AllocateRuntimePool (\r
sizeof (ESAL_VARIABLE_GLOBAL)\r
- );\r
+ );\r
if (NULL == mVariableModuleGlobal) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r