/*++\r
\r
-Copyright (c) 2006 - 2007, 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 - 2007, 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
ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
\r
//\r
-// This is a temperary function which will be removed \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
\r
//\r
-// This is a temperary function which will be removed \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
EfiRaw Variable store status is raw\r
EfiValid Variable store status is valid\r
- EfiInvalid Variable store status is invalid \r
+ EfiInvalid Variable store status is invalid\r
\r
--*/\r
{\r
Variable = NextVariable;\r
}\r
\r
- Status = gBS->AllocatePool (\r
- EfiBootServicesData,\r
- ValidBufferSize,\r
- (VOID **) &ValidBuffer\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
+ ValidBuffer = AllocatePool (ValidBufferSize);\r
+ if (ValidBuffer == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
}\r
\r
SetMem (ValidBuffer, ValidBufferSize, 0xff);\r
}\r
}\r
\r
- gBS->FreePool (ValidBuffer);\r
+ FreePool (ValidBuffer);\r
\r
if (EFI_ERROR (Status)) {\r
*LastVariableOffset = 0;\r
goto Done;\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
+ // 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
Status = EFI_WRITE_PROTECTED;\r
goto Done;\r
} else if (Attributes == EFI_VARIABLE_NON_VOLATILE) {\r
//\r
- // Make sure not only EFI_VARIABLE_NON_VOLATILE is set \r
+ // Make sure not only EFI_VARIABLE_NON_VOLATILE is set\r
//\r
Status = EFI_INVALID_PARAMETER;\r
goto Done;\r
- } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == \r
+ } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) ==\r
EFI_VARIABLE_RUNTIME_ACCESS) {\r
//\r
// Make sure if runtime bit is set, boot service bit is set also\r
Status = EFI_OUT_OF_RESOURCES;\r
goto Done;\r
}\r
- \r
+\r
Reclaimed = TRUE;\r
}\r
//\r
Status = EFI_OUT_OF_RESOURCES;\r
goto Done;\r
}\r
- \r
+\r
Reclaimed = TRUE;\r
}\r
\r
return Status;\r
}\r
\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
EFI_STATUS\r
EFIAPI\r
QueryVariableInfo (\r
\r
Arguments:\r
\r
- Attributes Attributes bitmask to specify the type of variables \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
+ 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
}\r
\r
AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);\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
+ VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase);\r
} else {\r
//\r
// Query is Non-Volatile related.\r
}\r
\r
//\r
- // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize \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
\r
if (EfiAtRuntime ()) {\r
//\r
- // we don't take the state of the variables in mind \r
+ // we don't take the state of the variables in mind\r
// when calculating RemainingVariableStorageSize,\r
- // since the space occupied by variables not marked with \r
+ // since the space occupied by variables not marked with\r
// VAR_ADDED is not allowed to be reclaimed in Runtime.\r
//\r
*RemainingVariableStorageSize -= VariableSize;\r
} else {\r
//\r
- // Only care about Variables with State VAR_ADDED,because \r
+ // Only care about Variables with State VAR_ADDED,because\r
// the space not marked as VAR_ADDED is reclaimable now.\r
//\r
if (Variable->State == VAR_ADDED) {\r
*RemainingVariableStorageSize -= VariableSize;\r
}\r
}\r
- \r
+\r
//\r
// Go to the next one\r
//\r
Variable = NextVariable;\r
}\r
- \r
+\r
ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
return EFI_SUCCESS;\r
}\r
-#endif\r
\r
EFI_STATUS\r
EFIAPI\r
SystemTable - A pointer to the EFI System Table.\r
\r
Returns:\r
- \r
+\r
Status code.\r
- \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
UINTN Index;\r
UINT8 Data;\r
\r
- Status = gBS->AllocatePool (\r
- EfiRuntimeServicesData,\r
- sizeof (ESAL_VARIABLE_GLOBAL),\r
- (VOID **) &mVariableModuleGlobal\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
+ mVariableModuleGlobal = AllocateRuntimePool (sizeof (ESAL_VARIABLE_GLOBAL));\r
+ if (mVariableModuleGlobal == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal[Physical].VariableServicesLock, EFI_TPL_CALLBACK);\r
- \r
+ EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal[Physical].VariableServicesLock, TPL_NOTIFY);\r
+\r
//\r
// Allocate memory for volatile variable store\r
//\r
- Status = gBS->AllocatePool (\r
- EfiRuntimeServicesData,\r
- VARIABLE_STORE_SIZE + SCRATCH_SIZE,\r
- (VOID **) &VolatileVariableStore\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- gBS->FreePool (mVariableModuleGlobal);\r
- return Status;\r
+ VolatileVariableStore = AllocateRuntimePool (VARIABLE_STORE_SIZE + SCRATCH_SIZE);\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
\r
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
if (EFI_ERROR (Status)) {\r
- gBS->FreePool (mVariableModuleGlobal);\r
- gBS->FreePool (VolatileVariableStore);\r
+ FreePool (mVariableModuleGlobal);\r
+ FreePool (VolatileVariableStore);\r
return EFI_UNSUPPORTED;\r
}\r
\r
GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
);\r
if (EFI_ERROR (Status)) {\r
- gBS->FreePool (mVariableModuleGlobal);\r
- gBS->FreePool (VolatileVariableStore);\r
+ FreePool (mVariableModuleGlobal);\r
+ FreePool (VolatileVariableStore);\r
return EFI_UNSUPPORTED;\r
}\r
//\r
sizeof (UINT32),\r
(UINT8 *) &VariableStoreEntry.Length\r
);\r
+ // \r
+ // As Variables are stored in NV storage, which are slow devices,such as flash.\r
+ // Variable operation may skip checking variable program result to improve performance,\r
+ // We can assume Variable program is OK through some check point.\r
+ // Variable Store Size Setting should be the first Variable write operation,\r
+ // We can assume all Read/Write is OK if we can set Variable store size successfully.\r
+ // If write fail, we will assert here\r
+ //\r
+ ASSERT(VariableStoreHeader->Size == VariableStoreEntry.Length);\r
\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
if (EFI_ERROR (Status)) {\r
- gBS->FreePool (mVariableModuleGlobal);\r
- gBS->FreePool (VolatileVariableStore);\r
+ FreePool (mVariableModuleGlobal);\r
+ FreePool (VolatileVariableStore);\r
return Status;\r
}\r
\r
}\r
\r
if (EFI_ERROR (Status)) {\r
- gBS->FreePool (mVariableModuleGlobal);\r
- gBS->FreePool (VolatileVariableStore);\r
+ FreePool (mVariableModuleGlobal);\r
+ FreePool (VolatileVariableStore);\r
}\r
\r
return Status;\r