+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- EmuVariable.c\r
-\r
-Abstract:\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#include "Variable.h"\r
-\r
-//\r
-// Don't use module globals after the SetVirtualAddress map is signaled\r
-//\r
-ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\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
-STATIC\r
-VOID\r
-AcquireLockOnlyAtBootTime (\r
- IN EFI_LOCK *Lock\r
- )\r
-{\r
- if (!EfiAtRuntime ()) {\r
- EfiAcquireLock (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
-STATIC\r
-VOID\r
-ReleaseLockOnlyAtBootTime (\r
- IN EFI_LOCK *Lock\r
- )\r
-{\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (Lock);\r
- }\r
-}\r
-\r
-STATIC\r
-UINT8 *\r
-EFIAPI\r
-GetVariableDataPtr (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the pointer to the variable data.\r
-\r
-Arguments:\r
-\r
- Variable Pointer to the Variable Header.\r
-\r
-Returns:\r
-\r
- UINT8* Pointer to Variable Data\r
-\r
---*/\r
-{\r
- if (Variable->StartId != VARIABLE_DATA) {\r
- return NULL;\r
- }\r
- //\r
- // Be careful about pad size for alignment\r
- //\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
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the pointer to the next variable header.\r
-\r
-Arguments:\r
-\r
- Variable Pointer to the Variable Header.\r
-\r
-Returns:\r
-\r
- VARIABLE_HEADER* Pointer to next variable header.\r
-\r
---*/\r
-{\r
- VARIABLE_HEADER *VarHeader;\r
-\r
- if (Variable->StartId != VARIABLE_DATA) {\r
- return NULL;\r
- }\r
- //\r
- // Be careful about pad size for alignment\r
- //\r
- VarHeader = (VARIABLE_HEADER *) (GetVariableDataPtr (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));\r
-\r
- if (VarHeader->StartId != VARIABLE_DATA ||\r
- (sizeof (VARIABLE_HEADER) + VarHeader->DataSize + VarHeader->NameSize) > MAX_VARIABLE_SIZE\r
- ) {\r
- return NULL;\r
- }\r
-\r
- return VarHeader;\r
-}\r
-\r
-STATIC\r
-VARIABLE_HEADER *\r
-EFIAPI\r
-GetEndPointer (\r
- IN VARIABLE_STORE_HEADER *VolHeader\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the pointer to the last variable memory pointer byte\r
-\r
-Arguments:\r
-\r
- Variable Pointer to the Variable Header.\r
-\r
-Returns:\r
-\r
- VARIABLE_HEADER* Pointer to last unavailable Variable Header\r
-\r
---*/\r
-{\r
- //\r
- // The end of variable store\r
- //\r
- return (VARIABLE_HEADER *) ((UINTN) VolHeader + VolHeader->Size);\r
-}\r
-\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-FindVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\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_STORE_HEADER *VariableStoreHeader[2];\r
- UINTN Index;\r
-\r
- //\r
- // We aquire the lock at the entry of FindVariable as GetVariable, GetNextVariableName\r
- // SetVariable all call FindVariable at entry point. Please move "Aquire Lock" to\r
- // the correct places if this assumption does not hold TRUE anymore.\r
- //\r
- AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);\r
-\r
- //\r
- // 0: Non-Volatile, 1: Volatile\r
- //\r
- VariableStoreHeader[0] = (VARIABLE_STORE_HEADER *) ((UINTN) Global->NonVolatileVariableBase);\r
- VariableStoreHeader[1] = (VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase);\r
-\r
- //\r
- // Start Pointers for the variable.\r
- // Actual Data Pointer where data can be written.\r
- //\r
- Variable[0] = (VARIABLE_HEADER *) (VariableStoreHeader[0] + 1);\r
- Variable[1] = (VARIABLE_HEADER *) (VariableStoreHeader[1] + 1);\r
-\r
- if (VariableName[0] != 0 && VendorGuid == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Find the variable by walk through non-volatile and volatile variable store\r
- //\r
- for (Index = 0; Index < 2; Index++) {\r
- PtrTrack->StartPtr = (VARIABLE_HEADER *) (VariableStoreHeader[Index] + 1);\r
- PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader[Index]);\r
-\r
- while ((Variable[Index] != NULL) && (Variable[Index] <= GetEndPointer (VariableStoreHeader[Index]))) {\r
- if (Variable[Index]->StartId == VARIABLE_DATA && Variable[Index]->State == VAR_ADDED) {\r
- if (!(EfiAtRuntime () && !(Variable[Index]->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {\r
- if (VariableName[0] == 0) {\r
- PtrTrack->CurrPtr = Variable[Index];\r
- PtrTrack->Volatile = (BOOLEAN) Index;\r
- return EFI_SUCCESS;\r
- } else {\r
- if (CompareGuid (VendorGuid, &Variable[Index]->VendorGuid)) {\r
- if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable[Index]), Variable[Index]->NameSize)) {\r
- PtrTrack->CurrPtr = Variable[Index];\r
- PtrTrack->Volatile = (BOOLEAN) Index;\r
- return EFI_SUCCESS;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- Variable[Index] = GetNextVariablePtr (Variable[Index]);\r
- }\r
- }\r
- PtrTrack->CurrPtr = NULL;\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-GetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID * VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data,\r
- IN VARIABLE_GLOBAL * Global,\r
- IN UINT32 Instance\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 STATUS\r
-\r
---*/\r
-{\r
- VARIABLE_POINTER_TRACK Variable;\r
- UINTN VarDataSize;\r
- EFI_STATUS Status;\r
-\r
- if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Find existing variable\r
- //\r
- Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
-\r
- if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
- //\r
- // Get data size\r
- //\r
- VarDataSize = Variable.CurrPtr->DataSize;\r
- if (*DataSize >= VarDataSize) {\r
- if (Data == NULL) {\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- }\r
-\r
- CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
- if (Attributes != NULL) {\r
- *Attributes = Variable.CurrPtr->Attributes;\r
- }\r
-\r
- *DataSize = VarDataSize;\r
- Status = EFI_SUCCESS;\r
- goto Done;\r
- } else {\r
- *DataSize = VarDataSize;\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- goto Done;\r
- }\r
-\r
-Done:\r
- ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-GetNextVariableName (\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VendorGuid,\r
- IN VARIABLE_GLOBAL *Global,\r
- IN UINT32 Instance\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code Finds the Next available variable\r
-\r
-Arguments:\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
-\r
-Returns:\r
-\r
- EFI STATUS\r
-\r
---*/\r
-{\r
- VARIABLE_POINTER_TRACK Variable;\r
- UINTN VarNameSize;\r
- EFI_STATUS Status;\r
-\r
- if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
-\r
- if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
-\r
- while (TRUE) {\r
- if (VariableName[0] != 0) {\r
- //\r
- // If variable name is not NULL, get next variable\r
- //\r
- Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
- }\r
- //\r
- // If both volatile and non-volatile variable store are parsed,\r
- // return not found\r
- //\r
- if (Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL) {\r
- Variable.Volatile = (BOOLEAN) (Variable.Volatile ^ ((BOOLEAN) 0x1));\r
- if (Variable.Volatile) {\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
- Status = EFI_NOT_FOUND;\r
- goto Done;\r
- }\r
-\r
- Variable.CurrPtr = Variable.StartPtr;\r
- if (Variable.CurrPtr->StartId != VARIABLE_DATA) {\r
- continue;\r
- }\r
- }\r
- //\r
- // Variable is found\r
- //\r
- if (Variable.CurrPtr->StartId == VARIABLE_DATA && Variable.CurrPtr->State == VAR_ADDED) {\r
- if (!(EfiAtRuntime () && !(Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {\r
- VarNameSize = Variable.CurrPtr->NameSize;\r
- if (VarNameSize <= *VariableNameSize) {\r
- CopyMem (\r
- VariableName,\r
- GET_VARIABLE_NAME_PTR (Variable.CurrPtr),\r
- VarNameSize\r
- );\r
- CopyMem (\r
- VendorGuid,\r
- &Variable.CurrPtr->VendorGuid,\r
- sizeof (EFI_GUID)\r
- );\r
- Status = EFI_SUCCESS;\r
- } else {\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- }\r
-\r
- *VariableNameSize = VarNameSize;\r
- goto Done;\r
- }\r
- }\r
- }\r
-\r
-Done:\r
- ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
- return Status;\r
-\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data,\r
- IN VARIABLE_GLOBAL *Global,\r
- IN UINTN *VolatileOffset,\r
- IN UINTN *NonVolatileOffset,\r
- IN UINT32 Instance\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
-\r
-Returns:\r
-\r
- EFI STATUS\r
-\r
---*/\r
-{\r
- VARIABLE_POINTER_TRACK Variable;\r
- EFI_STATUS Status;\r
- VARIABLE_HEADER *NextVariable;\r
- UINTN VarNameSize;\r
- UINTN VarNameOffset;\r
- UINTN VarDataOffset;\r
- UINTN VarSize;\r
-\r
- if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
-\r
- if (Status == EFI_INVALID_PARAMETER) {\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
- // return EFI_WRITE_PROTECTED.\r
- //\r
- Status = EFI_WRITE_PROTECTED;\r
- goto Done;\r
- } else if (sizeof (VARIABLE_HEADER) + (StrSize (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
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\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
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
- //\r
- // Runtime but Attribute is not Runtime\r
- //\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
- //\r
- // Cannot set volatile variable in Runtime\r
- //\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\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
- Status = EFI_SUCCESS;\r
- goto Done;\r
- }\r
-\r
- Status = EFI_NOT_FOUND;\r
- goto Done;\r
- } else {\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // If the variable is marked valid and the same data has been passed in\r
- // then return to the caller immediately.\r
- //\r
- if (Variable.CurrPtr->DataSize == DataSize &&\r
- !CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize)\r
- ) {\r
- Status = EFI_SUCCESS;\r
- goto Done;\r
- } else if (Variable.CurrPtr->State == VAR_ADDED) {\r
- //\r
- // Mark the old variable as in delete transition\r
- //\r
- Variable.CurrPtr->State &= VAR_IN_DELETED_TRANSITION;\r
- }\r
- }\r
- //\r
- // Create a new variable and copy the data.\r
- //\r
- VarNameOffset = sizeof (VARIABLE_HEADER);\r
- VarNameSize = StrSize (VariableName);\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
- ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size\r
- ) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Done;\r
- }\r
-\r
- NextVariable = (VARIABLE_HEADER *) (UINT8 *) (*NonVolatileOffset + (UINTN) Global->NonVolatileVariableBase);\r
- *NonVolatileOffset = *NonVolatileOffset + VarSize;\r
- } else {\r
- if (EfiAtRuntime ()) {\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- }\r
-\r
- if ((UINT32) (VarSize +*VolatileOffset) >\r
- ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size\r
- ) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Done;\r
- }\r
-\r
- NextVariable = (VARIABLE_HEADER *) (UINT8 *) (*VolatileOffset + (UINTN) Global->VolatileVariableBase);\r
- *VolatileOffset = *VolatileOffset + VarSize;\r
- }\r
-\r
- NextVariable->StartId = VARIABLE_DATA;\r
- NextVariable->Attributes = Attributes;\r
- NextVariable->State = VAR_ADDED;\r
- NextVariable->Reserved = 0;\r
-\r
- //\r
- // There will be pad bytes after Data, the NextVariable->NameSize and\r
- // NextVariable->NameSize should not include pad size so that variable\r
- // service can get actual size in GetVariable\r
- //\r
- NextVariable->NameSize = (UINT32)VarNameSize;\r
- NextVariable->DataSize = (UINT32)DataSize;\r
-\r
- CopyMem (&NextVariable->VendorGuid, VendorGuid, sizeof (EFI_GUID));\r
- CopyMem (\r
- (UINT8 *) ((UINTN) NextVariable + VarNameOffset),\r
- VariableName,\r
- VarNameSize\r
- );\r
- CopyMem (\r
- (UINT8 *) ((UINTN) NextVariable + VarDataOffset),\r
- Data,\r
- DataSize\r
- );\r
-\r
- //\r
- // Mark the old variable as deleted\r
- //\r
- if (!EFI_ERROR (Status)) {\r
- Variable.CurrPtr->State &= VAR_DELETED;\r
- }\r
- }\r
-\r
- Status = EFI_SUCCESS;\r
-Done:\r
- ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
- return Status;\r
-}\r
-\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
- AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);\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
- ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
- return EFI_SUCCESS;\r
-}\r
-\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeVariableStore (\r
- OUT EFI_PHYSICAL_ADDRESS *VariableBase,\r
- OUT UINTN *LastVariableOffset\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This function initializes variable store\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- VARIABLE_STORE_HEADER *VariableStore;\r
-\r
- //\r
- // Allocate memory for volatile variable store\r
- //\r
- VariableStore = (VARIABLE_STORE_HEADER *) AllocateRuntimePool (\r
- VARIABLE_STORE_SIZE\r
- );\r
- if (NULL == VariableStore) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- SetMem (VariableStore, VARIABLE_STORE_SIZE, 0xff);\r
-\r
- //\r
- // Variable Specific Data\r
- //\r
- *VariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStore;\r
- *LastVariableOffset = sizeof (VARIABLE_STORE_HEADER);\r
-\r
- VariableStore->Signature = VARIABLE_STORE_SIGNATURE;\r
- VariableStore->Size = VARIABLE_STORE_SIZE;\r
- VariableStore->Format = VARIABLE_STORE_FORMATTED;\r
- VariableStore->State = VARIABLE_STORE_HEALTHY;\r
- VariableStore->Reserved = 0;\r
- VariableStore->Reserved1 = 0;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\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
-Returns:\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Allocate memory for mVariableModuleGlobal\r
- //\r
- mVariableModuleGlobal = (ESAL_VARIABLE_GLOBAL *) AllocateRuntimePool (\r
- sizeof (ESAL_VARIABLE_GLOBAL)\r
- );\r
- if (NULL == mVariableModuleGlobal) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal[Physical].VariableServicesLock, TPL_NOTIFY);\r
-\r
- //\r
- // Intialize volatile variable store\r
- //\r
- Status = InitializeVariableStore (\r
- &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase,\r
- &mVariableModuleGlobal->VolatileLastVariableOffset\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- //\r
- // Intialize non volatile variable store\r
- //\r
- Status = InitializeVariableStore (\r
- &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,\r
- &mVariableModuleGlobal->NonVolatileLastVariableOffset\r
- );\r
-\r
- return Status;\r
-}\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
- <MsaHeader>\r
- <ModuleName>EmuVariable</ModuleName>\r
- <ModuleType>DXE_RUNTIME_DRIVER</ModuleType>\r
- <GuidValue>CBD2E4D5-7068-4FF5-B866-9822B4AD8D61</GuidValue>\r
- <Version>1.0</Version>\r
- <Abstract>Emulation Variable for EFI_RUNTIME_SERVICES.</Abstract>\r
- <Description>This module provides three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName</Description>\r
- <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
- <License>All rights reserved. This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
- <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
- </MsaHeader>\r
- <ModuleDefinitions>\r
- <SupportedArchitectures>IA32 X64 EBC</SupportedArchitectures>\r
- <BinaryModule>false</BinaryModule>\r
- <OutputFileBasename>EmuVariable</OutputFileBasename>\r
- </ModuleDefinitions>\r
- <LibraryClassDefinitions>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>BaseMemoryLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>MemoryAllocationLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>DebugLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiRuntimeLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiDriverEntryPoint</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiBootServicesTableLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>BaseLib</Keyword>\r
- </LibraryClass>\r
- </LibraryClassDefinitions>\r
- <SourceFiles>\r
- <Filename>Variable.h</Filename>\r
- <Filename>EmuVariable.c</Filename>\r
- <Filename>EmuVariable.dxs</Filename>\r
- <Filename>InitVariable.c</Filename>\r
- </SourceFiles>\r
- <PackageDependencies>\r
- <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
- <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
- </PackageDependencies>\r
- <Protocols>\r
- <Protocol Usage="ALWAYS_PRODUCED" SupArchList="IA32 X64">\r
- <ProtocolCName>gEfiVariableWriteArchProtocolGuid</ProtocolCName>\r
- </Protocol>\r
- <Protocol Usage="ALWAYS_PRODUCED" SupArchList="IA32 X64">\r
- <ProtocolCName>gEfiVariableArchProtocolGuid</ProtocolCName>\r
- </Protocol>\r
- </Protocols>\r
- <Externs>\r
- <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
- <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
- <Extern>\r
- <ModuleEntryPoint>VariableServiceInitialize</ModuleEntryPoint>\r
- </Extern>\r
- </Externs>\r
-</ModuleSurfaceArea>
\ No newline at end of file
+++ /dev/null
-#/** @file\r
-# Emulation Variable for EFI_RUNTIME_SERVICES.\r
-#\r
-# This module provides three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName\r
-# Copyright (c) 2006 - 2007, Intel Corporation\r
-#\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
-# 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
-\r
-################################################################################\r
-#\r
-# Defines Section - statements that will be processed to create a Makefile.\r
-#\r
-################################################################################\r
-[Defines]\r
- INF_VERSION = 0x00010005\r
- BASE_NAME = EmuVariableRuntimeDxe\r
- FILE_GUID = CBD2E4D5-7068-4FF5-B866-9822B4AD8D61\r
- MODULE_TYPE = DXE_RUNTIME_DRIVER\r
- VERSION_STRING = 1.0\r
- EDK_RELEASE_VERSION = 0x00020000\r
- EFI_SPECIFICATION_VERSION = 0x00020000\r
-\r
- ENTRY_POINT = VariableServiceInitialize\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-# VALID_ARCHITECTURES = IA32 X64 EBC\r
-#\r
-\r
-################################################################################\r
-#\r
-# Sources Section - list of files that are required for the build to succeed.\r
-#\r
-################################################################################\r
-\r
-[Sources.common]\r
- InitVariable.c\r
- EmuVariable.c\r
- Variable.h\r
-\r
-\r
-################################################################################\r
-#\r
-# Package Dependency Section - list of Package files that are required for\r
-# this module.\r
-#\r
-################################################################################\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- MdeModulePkg/MdeModulePkg.dec\r
-\r
-\r
-################################################################################\r
-#\r
-# Library Class Section - list of Library Classes that are required for\r
-# this module.\r
-#\r
-################################################################################\r
-\r
-[LibraryClasses]\r
- BaseLib\r
- UefiLib\r
- UefiBootServicesTableLib\r
- UefiDriverEntryPoint\r
- UefiRuntimeLib\r
- DebugLib\r
- MemoryAllocationLib\r
- BaseMemoryLib\r
-\r
-\r
-################################################################################\r
-#\r
-# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
-# that this module uses or produces.\r
-#\r
-################################################################################\r
-\r
-[Protocols.IA32]\r
- gEfiVariableArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
- gEfiVariableWriteArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
-\r
-[Protocols.X64]\r
- gEfiVariableArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
- gEfiVariableWriteArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
-\r
-\r
-################################################################################\r
-#\r
-# Dependency Expression Section - list of Dependency expressions that are required for\r
-# this module.\r
-#\r
-################################################################################\r
-\r
-[Depex]\r
- TRUE\r
-\r
+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- InitVariable.c\r
-\r
-Abstract:\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#include "Variable.h"\r
-\r
-//\r
-// Don't use module globals after the SetVirtualAddress map is signaled\r
-//\r
-extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\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\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- return GetVariable (\r
- VariableName,\r
- VendorGuid,\r
- Attributes OPTIONAL,\r
- DataSize,\r
- Data,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- mVariableModuleGlobal->FvbInstance\r
- );\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
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- return GetNextVariableName (\r
- VariableNameSize,\r
- VariableName,\r
- VendorGuid,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- mVariableModuleGlobal->FvbInstance\r
- );\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
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- return SetVariable (\r
- VariableName,\r
- VendorGuid,\r
- Attributes,\r
- DataSize,\r
- Data,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- &mVariableModuleGlobal->VolatileLastVariableOffset,\r
- &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
- mVariableModuleGlobal->FvbInstance\r
- );\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
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- return QueryVariableInfo (\r
- Attributes,\r
- MaximumVariableStorageSize,\r
- RemainingVariableStorageSize,\r
- MaximumVariableSize,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- mVariableModuleGlobal->FvbInstance\r
- );\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-VariableClassAddressChangeEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\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
-EFI_STATUS\r
-EFIAPI\r
-VariableServiceInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\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
- return EFI_SUCCESS;\r
-}\r
+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- Variable.h\r
-\r
-Abstract:\r
-\r
---*/\r
-\r
-#ifndef _VARIABLE_H\r
-#define _VARIABLE_H\r
-\r
-//\r
-// Statements that include other header files\r
-//\r
-//\r
-// The package level header files this module uses\r
-//\r
-#include <PiDxe.h>\r
-//\r
-// The protocols, PPI and GUID defintions for this module\r
-//\r
-#include <Protocol/VariableWrite.h>\r
-#include <Protocol/Variable.h>\r
-//\r
-// The Library classes this module consumes\r
-//\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/BaseLib.h>\r
-\r
-//\r
-// BugBug: We need relcate the head file.\r
-//\r
-#include <Common/Variable.h>\r
-\r
-#define VARIABLE_STORE_SIZE (64 * 1024)\r
-#define SCRATCH_SIZE (4 * 1024)\r
-\r
-//\r
-// Define GET_PAD_SIZE to optimize compiler\r
-//\r
-#if ((ALIGNMENT == 0) || (ALIGNMENT == 1))\r
-#define GET_PAD_SIZE(a) (0)\r
-#else\r
-#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))\r
-#endif\r
-\r
-#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))\r
-\r
-typedef enum {\r
- Physical,\r
- Virtual\r
-} VARIABLE_POINTER_TYPE;\r
-\r
-typedef struct {\r
- VARIABLE_HEADER *CurrPtr;\r
- VARIABLE_HEADER *EndPtr;\r
- VARIABLE_HEADER *StartPtr;\r
- BOOLEAN Volatile;\r
-} VARIABLE_POINTER_TRACK;\r
-\r
-typedef struct {\r
- EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r
- EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r
- EFI_LOCK VariableServicesLock;\r
-} VARIABLE_GLOBAL;\r
-\r
-typedef struct {\r
- VARIABLE_GLOBAL VariableGlobal[2];\r
- UINTN VolatileLastVariableOffset;\r
- UINTN NonVolatileLastVariableOffset;\r
- UINT32 FvbInstance;\r
-} ESAL_VARIABLE_GLOBAL;\r
-\r
-extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
-\r
-//\r
-// Functions\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-VariableCommonInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-VariableServiceInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-;\r
-\r
-VOID\r
-EFIAPI\r
-VariableClassAddressChangeEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-GetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID * VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data,\r
- IN VARIABLE_GLOBAL * Global,\r
- IN UINT32 Instance\r
- )\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-GetNextVariableName (\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VendorGuid,\r
- IN VARIABLE_GLOBAL *Global,\r
- IN UINT32 Instance\r
- )\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data,\r
- IN VARIABLE_GLOBAL *Global,\r
- IN UINTN *VolatileOffset,\r
- IN UINTN *NonVolatileOffset,\r
- IN UINT32 Instance\r
- )\r
-;\r
-\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
-#endif\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation. All rights reserved. <BR> \r
-This software and associated documentation (if any) is furnished\r
-under a license and may only be used or copied in accordance\r
-with the terms of the license. Except as permitted by such\r
-license, no part of this software or documentation may be\r
-reproduced, stored in a retrieval system, or transmitted in any\r
-form or by any means without the express written consent of\r
-Intel Corporation.\r
-\r
-\r
-\r
-Module Name:\r
-\r
- Ia32PcRtc.c\r
-\r
-Abstract:\r
-\r
---*/\r
-\r
-#include "PcRtc.h"\r
-\r
-static PC_RTC_MODULE_GLOBALS mModuleGlobal;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PcRtcEfiGetTime (\r
- OUT EFI_TIME *Time,\r
- OUT EFI_TIME_CAPABILITIES *Capabilities\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
- Capabilities - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- return PcRtcGetTime (Time, Capabilities, &mModuleGlobal);\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PcRtcEfiSetTime (\r
- IN EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- return PcRtcSetTime (Time, &mModuleGlobal);\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PcRtcEfiGetWakeupTime (\r
- OUT BOOLEAN *Enabled,\r
- OUT BOOLEAN *Pending,\r
- OUT EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Enabled - GC_TODO: add argument description\r
- Pending - GC_TODO: add argument description\r
- Time - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- return PcRtcGetWakeupTime (Enabled, Pending, Time, &mModuleGlobal);\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PcRtcEfiSetWakeupTime (\r
- IN BOOLEAN Enabled,\r
- OUT EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Enabled - GC_TODO: add argument description\r
- Time - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- return PcRtcSetWakeupTime (Enabled, Time, &mModuleGlobal);\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-InitializePcRtc (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
- \r
-\r
-Returns: \r
---*/\r
-// GC_TODO: ImageHandle - add argument and description to function comment\r
-// GC_TODO: SystemTable - add argument and description to function comment\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE NewHandle;\r
-\r
- EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_HIGH_LEVEL);\r
-\r
- Status = PcRtcInit (&mModuleGlobal);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- gRT->GetTime = PcRtcEfiGetTime;\r
- gRT->SetTime = PcRtcEfiSetTime;\r
- gRT->GetWakeupTime = PcRtcEfiGetWakeupTime;\r
- gRT->SetWakeupTime = PcRtcEfiSetWakeupTime;\r
-\r
- NewHandle = NULL;\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &NewHandle,\r
- &gEfiRealTimeClockArchProtocolGuid,\r
- NULL,\r
- NULL\r
- );\r
-\r
- return Status;\r
-}\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR>\r
-This software and associated documentation (if any) is furnished\r
-under a license and may only be used or copied in accordance\r
-with the terms of the license. Except as permitted by such\r
-license, no part of this software or documentation may be\r
-reproduced, stored in a retrieval system, or transmitted in any\r
-form or by any means without the express written consent of\r
-Intel Corporation.\r
-\r
-\r
-\r
-Module Name:\r
-\r
- PcRtc.c\r
-\r
-Abstract:\r
-\r
- RTC Architectural Protocol GUID as defined in DxeCis 0.96\r
-\r
---*/\r
-\r
-#include "PcRtc.h"\r
-\r
-STATIC\r
-INTN\r
-CompareHMS (\r
- IN EFI_TIME *From,\r
- IN EFI_TIME *To\r
- );\r
-\r
-STATIC\r
-BOOLEAN\r
-IsWithinOneDay (\r
- IN EFI_TIME *From,\r
- IN EFI_TIME *To\r
- );\r
-\r
-STATIC\r
-UINT8\r
-RtcRead (\r
- IN UINT8 Address\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Address - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));\r
- return IoRead8 (PCAT_RTC_DATA_REGISTER);\r
-}\r
-\r
-STATIC\r
-VOID\r
-RtcWrite (\r
- IN UINT8 Address,\r
- IN UINT8 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Address - GC_TODO: add argument description\r
- Data - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));\r
- IoWrite8 (PCAT_RTC_DATA_REGISTER, Data);\r
-}\r
-\r
-EFI_STATUS\r
-PcRtcInit (\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Global - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
- EFI_SUCCESS - GC_TODO: Add description for return value\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- RTC_REGISTER_A RegisterA;\r
- RTC_REGISTER_B RegisterB;\r
- RTC_REGISTER_D RegisterD;\r
- UINT8 Century;\r
- EFI_TIME Time;\r
-\r
- //\r
- // Acquire RTC Lock to make access to RTC atomic\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
- if (!EfiAtRuntime ()) {\r
- EfiAcquireLock (&Global->RtcLock);\r
- }\r
- //\r
- // Initialize RTC Register\r
- //\r
- // Make sure Division Chain is properly configured,\r
- // or RTC clock won't "tick" -- time won't increment\r
- //\r
- RegisterA.Data = RTC_INIT_REGISTER_A;\r
- RtcWrite (RTC_ADDRESS_REGISTER_A, RegisterA.Data);\r
-\r
- //\r
- // Read Register B\r
- //\r
- RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
-\r
- //\r
- // Clear RTC flag register\r
- //\r
- RtcRead (RTC_ADDRESS_REGISTER_C);\r
-\r
- //\r
- // Clear RTC register D\r
- //\r
- RegisterD.Data = RTC_INIT_REGISTER_D;\r
- RtcWrite (RTC_ADDRESS_REGISTER_D, RegisterD.Data);\r
-\r
- //\r
- // Wait for up to 0.1 seconds for the RTC to be updated\r
- //\r
- Status = RtcWaitToUpdate (100000);\r
- if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- return EFI_DEVICE_ERROR;\r
- }\r
- //\r
- // Get the Time/Date/Daylight Savings values.\r
- //\r
- Time.Second = RtcRead (RTC_ADDRESS_SECONDS);\r
- Time.Minute = RtcRead (RTC_ADDRESS_MINUTES);\r
- Time.Hour = RtcRead (RTC_ADDRESS_HOURS);\r
- Time.Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
- Time.Month = RtcRead (RTC_ADDRESS_MONTH);\r
- Time.Year = RtcRead (RTC_ADDRESS_YEAR);\r
-\r
- ConvertRtcTimeToEfiTime (&Time, RegisterB);\r
-\r
- if (RtcTestCenturyRegister () == EFI_SUCCESS) {\r
- Century = BcdToDecimal8 ((UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f));\r
- } else {\r
- Century = BcdToDecimal8 (RtcRead (RTC_ADDRESS_CENTURY));\r
- }\r
-\r
- Time.Year = (UINT16) (Century * 100 + Time.Year);\r
-\r
- //\r
- // Set RTC configuration after get original time\r
- //\r
- RtcWrite (RTC_ADDRESS_REGISTER_B, RTC_INIT_REGISTER_B);\r
-\r
- //\r
- // Release RTC Lock.\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- //\r
- // Validate time fields\r
- //\r
- Status = RtcTimeFieldsValid (&Time);\r
- if (EFI_ERROR (Status)) {\r
- Time.Second = RTC_INIT_SECOND;\r
- Time.Minute = RTC_INIT_MINUTE;\r
- Time.Hour = RTC_INIT_HOUR;\r
- Time.Day = RTC_INIT_DAY;\r
- Time.Month = RTC_INIT_MONTH;\r
- Time.Year = RTC_INIT_YEAR;\r
- }\r
- //\r
- // Reset time value according to new RTC configuration\r
- //\r
- PcRtcSetTime (&Time, Global);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-PcRtcGetTime (\r
- OUT EFI_TIME *Time,\r
- IN EFI_TIME_CAPABILITIES *Capabilities,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
- Returns:\r
---*/\r
-// GC_TODO: Time - add argument and description to function comment\r
-// GC_TODO: Capabilities - add argument and description to function comment\r
-// GC_TODO: Global - add argument and description to function comment\r
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-// GC_TODO: EFI_SUCCESS - add return value to function comment\r
-{\r
- EFI_STATUS Status;\r
- RTC_REGISTER_B RegisterB;\r
- UINT8 Century;\r
-\r
- //\r
- // Check parameters for null pointer\r
- //\r
- if (Time == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
-\r
- }\r
- //\r
- // Acquire RTC Lock to make access to RTC atomic\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
- if (!EfiAtRuntime ()) {\r
- EfiAcquireLock (&Global->RtcLock);\r
- }\r
- //\r
- // Wait for up to 0.1 seconds for the RTC to be updated\r
- //\r
- Status = RtcWaitToUpdate (100000);\r
- if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- return Status;\r
- }\r
- //\r
- // Read Register B\r
- //\r
- RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
-\r
- //\r
- // Get the Time/Date/Daylight Savings values.\r
- //\r
- Time->Second = RtcRead (RTC_ADDRESS_SECONDS);\r
- Time->Minute = RtcRead (RTC_ADDRESS_MINUTES);\r
- Time->Hour = RtcRead (RTC_ADDRESS_HOURS);\r
- Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
- Time->Month = RtcRead (RTC_ADDRESS_MONTH);\r
- Time->Year = RtcRead (RTC_ADDRESS_YEAR);\r
-\r
- ConvertRtcTimeToEfiTime (Time, RegisterB);\r
-\r
- if (RtcTestCenturyRegister () == EFI_SUCCESS) {\r
- Century = BcdToDecimal8 ((UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f));\r
- } else {\r
- Century = BcdToDecimal8 (RtcRead (RTC_ADDRESS_CENTURY));\r
- }\r
-\r
- Time->Year = (UINT16) (Century * 100 + Time->Year);\r
-\r
- //\r
- // Release RTC Lock.\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- //\r
- // Get the variable that containts the TimeZone and Daylight fields\r
- //\r
- Time->TimeZone = Global->SavedTimeZone;\r
- Time->Daylight = Global->Daylight;\r
-\r
- //\r
- // Make sure all field values are in correct range\r
- //\r
- Status = RtcTimeFieldsValid (Time);\r
- if (EFI_ERROR (Status)) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- //\r
- // Fill in Capabilities if it was passed in\r
- //\r
- if (Capabilities) {\r
- Capabilities->Resolution = 1;\r
- //\r
- // 1 hertz\r
- //\r
- Capabilities->Accuracy = 50000000;\r
- //\r
- // 50 ppm\r
- //\r
- Capabilities->SetsToZero = FALSE;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-PcRtcSetTime (\r
- IN EFI_TIME *Time,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
- Returns:\r
---*/\r
-// GC_TODO: Time - add argument and description to function comment\r
-// GC_TODO: Global - add argument and description to function comment\r
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-{\r
- EFI_STATUS Status;\r
- EFI_TIME RtcTime;\r
- RTC_REGISTER_B RegisterB;\r
- UINT8 Century;\r
-\r
- if (Time == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Make sure that the time fields are valid\r
- //\r
- Status = RtcTimeFieldsValid (Time);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- CopyMem (&RtcTime, Time, sizeof (EFI_TIME));\r
-\r
- //\r
- // Acquire RTC Lock to make access to RTC atomic\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
- if (!EfiAtRuntime ()) {\r
- EfiAcquireLock (&Global->RtcLock);\r
- }\r
- //\r
- // Wait for up to 0.1 seconds for the RTC to be updated\r
- //\r
- Status = RtcWaitToUpdate (100000);\r
- if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- return Status;\r
- }\r
- //\r
- // Read Register B, and inhibit updates of the RTC\r
- //\r
- RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
- RegisterB.Bits.SET = 1;\r
- RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
-\r
- ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century);\r
-\r
- RtcWrite (RTC_ADDRESS_SECONDS, RtcTime.Second);\r
- RtcWrite (RTC_ADDRESS_MINUTES, RtcTime.Minute);\r
- RtcWrite (RTC_ADDRESS_HOURS, RtcTime.Hour);\r
- RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH, RtcTime.Day);\r
- RtcWrite (RTC_ADDRESS_MONTH, RtcTime.Month);\r
- RtcWrite (RTC_ADDRESS_YEAR, (UINT8) RtcTime.Year);\r
- if (RtcTestCenturyRegister () == EFI_SUCCESS) {\r
- Century = (UINT8) ((Century & 0x7f) | (RtcRead (RTC_ADDRESS_CENTURY) & 0x80));\r
- }\r
-\r
- RtcWrite (RTC_ADDRESS_CENTURY, Century);\r
-\r
- //\r
- // Allow updates of the RTC registers\r
- //\r
- RegisterB.Bits.SET = 0;\r
- RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
-\r
- //\r
- // Release RTC Lock.\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- //\r
- // Set the variable that containts the TimeZone and Daylight fields\r
- //\r
- Global->SavedTimeZone = Time->TimeZone;\r
- Global->Daylight = Time->Daylight;\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-PcRtcGetWakeupTime (\r
- OUT BOOLEAN *Enabled,\r
- OUT BOOLEAN *Pending,\r
- OUT EFI_TIME *Time,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
-\r
-\r
-Returns:\r
---*/\r
-// GC_TODO: Enabled - add argument and description to function comment\r
-// GC_TODO: Pending - add argument and description to function comment\r
-// GC_TODO: Time - add argument and description to function comment\r
-// GC_TODO: Global - add argument and description to function comment\r
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-// GC_TODO: EFI_SUCCESS - add return value to function comment\r
-{\r
- EFI_STATUS Status;\r
- RTC_REGISTER_B RegisterB;\r
- RTC_REGISTER_C RegisterC;\r
- UINT8 Century;\r
-\r
- //\r
- // Check paramters for null pointers\r
- //\r
- if ((Enabled == NULL) || (Pending == NULL) || (Time == NULL)) {\r
- return EFI_INVALID_PARAMETER;\r
-\r
- }\r
- //\r
- // Acquire RTC Lock to make access to RTC atomic\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
- if (!EfiAtRuntime ()) {\r
- EfiAcquireLock (&Global->RtcLock);\r
- }\r
- //\r
- // Wait for up to 0.1 seconds for the RTC to be updated\r
- //\r
- Status = RtcWaitToUpdate (100000);\r
- if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- return EFI_DEVICE_ERROR;\r
- }\r
- //\r
- // Read Register B and Register C\r
- //\r
- RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
- RegisterC.Data = RtcRead (RTC_ADDRESS_REGISTER_C);\r
-\r
- //\r
- // Get the Time/Date/Daylight Savings values.\r
- //\r
- *Enabled = RegisterB.Bits.AIE;\r
- if (*Enabled) {\r
- Time->Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM);\r
- Time->Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM);\r
- Time->Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM);\r
- Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
- Time->Month = RtcRead (RTC_ADDRESS_MONTH);\r
- Time->Year = RtcRead (RTC_ADDRESS_YEAR);\r
- } else {\r
- Time->Second = 0;\r
- Time->Minute = 0;\r
- Time->Hour = 0;\r
- Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
- Time->Month = RtcRead (RTC_ADDRESS_MONTH);\r
- Time->Year = RtcRead (RTC_ADDRESS_YEAR);\r
- }\r
-\r
- ConvertRtcTimeToEfiTime (Time, RegisterB);\r
-\r
- if (RtcTestCenturyRegister () == EFI_SUCCESS) {\r
- Century = BcdToDecimal8 ((UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f));\r
- } else {\r
- Century = BcdToDecimal8 (RtcRead (RTC_ADDRESS_CENTURY));\r
- }\r
-\r
- Time->Year = (UINT16) (Century * 100 + Time->Year);\r
-\r
- //\r
- // Release RTC Lock.\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- //\r
- // Make sure all field values are in correct range\r
- //\r
- Status = RtcTimeFieldsValid (Time);\r
- if (EFI_ERROR (Status)) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- *Pending = RegisterC.Bits.AF;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-PcRtcSetWakeupTime (\r
- IN BOOLEAN Enable,\r
- OUT EFI_TIME *Time,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
-\r
-\r
-Returns:\r
---*/\r
-// GC_TODO: Enable - add argument and description to function comment\r
-// GC_TODO: Time - add argument and description to function comment\r
-// GC_TODO: Global - add argument and description to function comment\r
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-// GC_TODO: EFI_UNSUPPORTED - add return value to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-// GC_TODO: EFI_SUCCESS - add return value to function comment\r
-{\r
- EFI_STATUS Status;\r
- EFI_TIME RtcTime;\r
- RTC_REGISTER_B RegisterB;\r
- UINT8 Century;\r
- EFI_TIME_CAPABILITIES Capabilities;\r
-\r
- if (Enable) {\r
-\r
- if (Time == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Make sure that the time fields are valid\r
- //\r
- Status = RtcTimeFieldsValid (Time);\r
- if (EFI_ERROR (Status)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Just support set alarm time within 24 hours\r
- //\r
- PcRtcGetTime (&RtcTime, &Capabilities, Global);\r
- if (!IsWithinOneDay (&RtcTime, Time)) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- //\r
- // Make a local copy of the time and date\r
- //\r
- CopyMem (&RtcTime, Time, sizeof (EFI_TIME));\r
-\r
- }\r
- //\r
- // Acquire RTC Lock to make access to RTC atomic\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or\r
- // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock\r
- if (!EfiAtRuntime ()) {\r
- EfiAcquireLock (&Global->RtcLock);\r
- }\r
- //\r
- // Wait for up to 0.1 seconds for the RTC to be updated\r
- //\r
- Status = RtcWaitToUpdate (100000);\r
- if (EFI_ERROR (Status)) {\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- return EFI_DEVICE_ERROR;\r
- }\r
- //\r
- // Read Register B, and inhibit updates of the RTC\r
- //\r
- RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
-\r
- RegisterB.Bits.SET = 1;\r
- RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
-\r
- if (Enable) {\r
- ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century);\r
-\r
- //\r
- // Set RTC alarm time\r
- //\r
- RtcWrite (RTC_ADDRESS_SECONDS_ALARM, RtcTime.Second);\r
- RtcWrite (RTC_ADDRESS_MINUTES_ALARM, RtcTime.Minute);\r
- RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour);\r
-\r
- RegisterB.Bits.AIE = 1;\r
-\r
- } else {\r
- RegisterB.Bits.AIE = 0;\r
- }\r
- //\r
- // Allow updates of the RTC registers\r
- //\r
- RegisterB.Bits.SET = 0;\r
- RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
-\r
- //\r
- // Release RTC Lock.\r
- //\r
- //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or\r
- // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (&Global->RtcLock);\r
- }\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-RtcTestCenturyRegister (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
-\r
-\r
-Returns:\r
---*/\r
-// GC_TODO: EFI_SUCCESS - add return value to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-{\r
- UINT8 Century;\r
- UINT8 Temp;\r
-\r
- Century = RtcRead (RTC_ADDRESS_CENTURY);\r
- //\r
- // RtcWrite (RTC_ADDRESS_CENTURY, 0x00);\r
- //\r
- Temp = (UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f);\r
- RtcWrite (RTC_ADDRESS_CENTURY, Century);\r
- if (Temp == 0x19 || Temp == 0x20) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- return EFI_DEVICE_ERROR;\r
-}\r
-\r
-VOID\r
-ConvertRtcTimeToEfiTime (\r
- IN EFI_TIME *Time,\r
- IN RTC_REGISTER_B RegisterB\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
-\r
-\r
-Returns:\r
---*/\r
-// GC_TODO: Time - add argument and description to function comment\r
-// GC_TODO: RegisterB - add argument and description to function comment\r
-{\r
- BOOLEAN PM;\r
-\r
- if ((Time->Hour) & 0x80) {\r
- PM = TRUE;\r
- } else {\r
- PM = FALSE;\r
- }\r
-\r
- Time->Hour = (UINT8) (Time->Hour & 0x7f);\r
-\r
- if (RegisterB.Bits.DM == 0) {\r
- Time->Year = BcdToDecimal8 ((UINT8) Time->Year);\r
- Time->Month = BcdToDecimal8 (Time->Month);\r
- Time->Day = BcdToDecimal8 (Time->Day);\r
- Time->Hour = BcdToDecimal8 (Time->Hour);\r
- Time->Minute = BcdToDecimal8 (Time->Minute);\r
- Time->Second = BcdToDecimal8 (Time->Second);\r
- }\r
- //\r
- // If time is in 12 hour format, convert it to 24 hour format\r
- //\r
- if (RegisterB.Bits.MIL == 0) {\r
- if (PM && Time->Hour < 12) {\r
- Time->Hour = (UINT8) (Time->Hour + 12);\r
- }\r
-\r
- if (!PM && Time->Hour == 12) {\r
- Time->Hour = 0;\r
- }\r
- }\r
-\r
- Time->Nanosecond = 0;\r
- Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
- Time->Daylight = 0;\r
-}\r
-\r
-EFI_STATUS\r
-RtcWaitToUpdate (\r
- UINTN Timeout\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
-\r
-Returns:\r
---*/\r
-// GC_TODO: Timeout - add argument and description to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment\r
-// GC_TODO: EFI_SUCCESS - add return value to function comment\r
-{\r
- RTC_REGISTER_A RegisterA;\r
- RTC_REGISTER_D RegisterD;\r
-\r
- //\r
- // See if the RTC is functioning correctly\r
- //\r
- RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D);\r
-\r
- if (RegisterD.Bits.VRT == 0) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- //\r
- // Wait for up to 0.1 seconds for the RTC to be ready.\r
- //\r
- Timeout = (Timeout / 10) + 1;\r
- RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A);\r
- while (RegisterA.Bits.UIP == 1 && Timeout > 0) {\r
- MicroSecondDelay (10);\r
- RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A);\r
- Timeout--;\r
- }\r
-\r
- RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D);\r
- if (Timeout == 0 || RegisterD.Bits.VRT == 0) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-RtcTimeFieldsValid (\r
- IN EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
- Returns:\r
---*/\r
-// GC_TODO: Time - add argument and description to function comment\r
-// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-// GC_TODO: EFI_SUCCESS - add return value to function comment\r
-{\r
- if (Time->Year < 1998 ||\r
- Time->Year > 2099 ||\r
- Time->Month < 1 ||\r
- Time->Month > 12 ||\r
- (!DayValid (Time)) ||\r
- Time->Hour > 23 ||\r
- Time->Minute > 59 ||\r
- Time->Second > 59 ||\r
- Time->Nanosecond > 999999999 ||\r
- (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
- (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r
- ) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-BOOLEAN\r
-DayValid (\r
- IN EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- INTN DayOfMonth[12];\r
-\r
- DayOfMonth[0] = 31;\r
- DayOfMonth[1] = 29;\r
- DayOfMonth[2] = 31;\r
- DayOfMonth[3] = 30;\r
- DayOfMonth[4] = 31;\r
- DayOfMonth[5] = 30;\r
- DayOfMonth[6] = 31;\r
- DayOfMonth[7] = 31;\r
- DayOfMonth[8] = 30;\r
- DayOfMonth[9] = 31;\r
- DayOfMonth[10] = 30;\r
- DayOfMonth[11] = 31;\r
-\r
- if (Time->Day < 1 ||\r
- Time->Day > DayOfMonth[Time->Month - 1] ||\r
- (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
- ) {\r
- return FALSE;\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
-BOOLEAN\r
-IsLeapYear (\r
- IN EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- if (Time->Year % 4 == 0) {\r
- if (Time->Year % 100 == 0) {\r
- if (Time->Year % 400 == 0) {\r
- return TRUE;\r
- } else {\r
- return FALSE;\r
- }\r
- } else {\r
- return TRUE;\r
- }\r
- } else {\r
- return FALSE;\r
- }\r
-}\r
-\r
-VOID\r
-ConvertEfiTimeToRtcTime (\r
- IN EFI_TIME *Time,\r
- IN RTC_REGISTER_B RegisterB,\r
- IN UINT8 *Century\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Arguments:\r
-\r
-\r
-Returns:\r
---*/\r
-// GC_TODO: Time - add argument and description to function comment\r
-// GC_TODO: RegisterB - add argument and description to function comment\r
-// GC_TODO: Century - add argument and description to function comment\r
-{\r
- BOOLEAN PM;\r
-\r
- PM = TRUE;\r
- //\r
- // Adjust hour field if RTC in in 12 hour mode\r
- //\r
- if (RegisterB.Bits.MIL == 0) {\r
- if (Time->Hour < 12) {\r
- PM = FALSE;\r
- }\r
-\r
- if (Time->Hour >= 13) {\r
- Time->Hour = (UINT8) (Time->Hour - 12);\r
- } else if (Time->Hour == 0) {\r
- Time->Hour = 12;\r
- }\r
- }\r
- //\r
- // Set the Time/Date/Daylight Savings values.\r
- //\r
- *Century = DecimalToBcd8 ((UINT8) (Time->Year / 100));\r
-\r
- Time->Year = (UINT16) (Time->Year % 100);\r
-\r
- if (RegisterB.Bits.DM == 0) {\r
- Time->Year = DecimalToBcd8 ((UINT8) Time->Year);\r
- Time->Month = DecimalToBcd8 (Time->Month);\r
- Time->Day = DecimalToBcd8 (Time->Day);\r
- Time->Hour = DecimalToBcd8 (Time->Hour);\r
- Time->Minute = DecimalToBcd8 (Time->Minute);\r
- Time->Second = DecimalToBcd8 (Time->Second);\r
- }\r
- //\r
- // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.\r
- //\r
- if (RegisterB.Bits.MIL == 0 && PM) {\r
- Time->Hour = (UINT8) (Time->Hour | 0x80);\r
- }\r
-}\r
-\r
-STATIC\r
-INTN\r
-CompareHMS (\r
- IN EFI_TIME *From,\r
- IN EFI_TIME *To\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Compare the Hour, Minute and Second of the 'From' time and the 'To' time.\r
- Only compare H/M/S in EFI_TIME and ignore other fields here.\r
-\r
-Arguments:\r
-\r
- From - the first time\r
- To - the second time\r
-\r
-Returns:\r
-\r
- >0 : The H/M/S of the 'From' time is later than those of 'To' time\r
- ==0 : The H/M/S of the 'From' time is same as those of 'To' time\r
- <0 : The H/M/S of the 'From' time is earlier than those of 'To' time\r
-\r
---*/\r
-{\r
- if ((From->Hour > To->Hour) ||\r
- ((From->Hour == To->Hour) && (From->Minute > To->Minute)) ||\r
- ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second > To->Second))) {\r
- return 1;\r
- } else if ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second == To->Second)) {\r
- return 0;\r
- } else {\r
- return -1;\r
- }\r
-}\r
-\r
-STATIC\r
-BOOLEAN\r
-IsWithinOneDay (\r
- IN EFI_TIME *From,\r
- IN EFI_TIME *To\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Judge whether two days are adjacent.\r
-\r
-Arguments:\r
-\r
- From - the first day\r
- To - the second day\r
-\r
-Returns:\r
-\r
- TRUE - The interval of two days are within one day.\r
- FALSE - The interval of two days exceed ony day or parameter error.\r
-\r
---*/\r
-{\r
- UINT8 DayOfMonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\r
- BOOLEAN Adjacent = FALSE;\r
-\r
- if (From->Year == To->Year) {\r
- if (From->Month == To->Month) {\r
- if ((From->Day + 1) == To->Day) {\r
- if ((CompareHMS(From, To) >= 0)) {\r
- Adjacent = TRUE;\r
- }\r
- } else if (From->Day == To->Day) {\r
- if ((CompareHMS(From, To) <= 0)) {\r
- Adjacent = TRUE;\r
- }\r
- }\r
- } else if (((From->Month + 1) == To->Month) && (To->Day == 1)) {\r
- if ((From->Month == 2) && !IsLeapYear(From)) {\r
- if (From->Day == 28) {\r
- if ((CompareHMS(From, To) >= 0)) {\r
- Adjacent = TRUE;\r
- }\r
- }\r
- } else if (From->Day == DayOfMonth[From->Month - 1]) {\r
- if ((CompareHMS(From, To) >= 0)) {\r
- Adjacent = TRUE;\r
- }\r
- }\r
- }\r
- } else if (((From->Year + 1) == To->Year) &&\r
- (From->Month == 12) &&\r
- (From->Day == 31) &&\r
- (To->Month == 1) &&\r
- (To->Day == 1)) {\r
- if ((CompareHMS(From, To) >= 0)) {\r
- Adjacent = TRUE;\r
- }\r
- }\r
-\r
- return Adjacent;\r
-}\r
-\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation. All rights reserved. \r
-This software and associated documentation (if any) is furnished\r
-under a license and may only be used or copied in accordance\r
-with the terms of the license. Except as permitted by such\r
-license, no part of this software or documentation may be\r
-reproduced, stored in a retrieval system, or transmitted in any\r
-form or by any means without the express written consent of\r
-Intel Corporation.\r
-\r
-\r
-Module Name:\r
- \r
- PcRtc.h\r
-\r
-Abstract:\r
-\r
- Include for real time clock driver\r
-\r
-Revision History\r
-\r
-\r
---*/\r
-\r
-#ifndef _RTC_H_\r
-#define _RTC_H_\r
-\r
-//\r
-// The package level header files this module uses\r
-//\r
-#include <PiDxe.h>\r
-//\r
-// The protocols, PPI and GUID defintions for this module\r
-//\r
-#include <Protocol/RealTimeClock.h>\r
-//\r
-// The Library classes this module consumes\r
-//\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/IoLib.h>\r
-#include <Library/TimerLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-\r
-\r
-typedef struct {\r
- EFI_LOCK RtcLock;\r
- UINT16 SavedTimeZone;\r
- UINT8 Daylight;\r
-} PC_RTC_MODULE_GLOBALS;\r
-\r
-#define PCAT_RTC_ADDRESS_REGISTER 0x70\r
-#define PCAT_RTC_DATA_REGISTER 0x71\r
-\r
-//\r
-// Dallas DS12C887 Real Time Clock\r
-//\r
-#define RTC_ADDRESS_SECONDS 0 // R/W Range 0..59\r
-#define RTC_ADDRESS_SECONDS_ALARM 1 // R/W Range 0..59\r
-#define RTC_ADDRESS_MINUTES 2 // R/W Range 0..59\r
-#define RTC_ADDRESS_MINUTES_ALARM 3 // R/W Range 0..59\r
-#define RTC_ADDRESS_HOURS 4 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r
-#define RTC_ADDRESS_HOURS_ALARM 5 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r
-#define RTC_ADDRESS_DAY_OF_THE_WEEK 6 // R/W Range 1..7\r
-#define RTC_ADDRESS_DAY_OF_THE_MONTH 7 // R/W Range 1..31\r
-#define RTC_ADDRESS_MONTH 8 // R/W Range 1..12\r
-#define RTC_ADDRESS_YEAR 9 // R/W Range 0..99\r
-#define RTC_ADDRESS_REGISTER_A 10 // R/W[0..6] R0[7]\r
-#define RTC_ADDRESS_REGISTER_B 11 // R/W\r
-#define RTC_ADDRESS_REGISTER_C 12 // RO\r
-#define RTC_ADDRESS_REGISTER_D 13 // RO\r
-#define RTC_ADDRESS_CENTURY 50 // R/W Range 19..20 Bit 8 is R/W\r
-//\r
-// Date and time initial values.\r
-// They are used if the RTC values are invalid during driver initialization\r
-//\r
-#define RTC_INIT_SECOND 0\r
-#define RTC_INIT_MINUTE 0\r
-#define RTC_INIT_HOUR 0\r
-#define RTC_INIT_DAY 1\r
-#define RTC_INIT_MONTH 1\r
-#define RTC_INIT_YEAR 2001\r
-\r
-//\r
-// Register initial values\r
-//\r
-#define RTC_INIT_REGISTER_A 0x26\r
-#define RTC_INIT_REGISTER_B 0x02\r
-#define RTC_INIT_REGISTER_D 0x0\r
-\r
-#pragma pack(1)\r
-//\r
-// Register A\r
-//\r
-typedef struct {\r
- UINT8 RS : 4; // Rate Selection Bits\r
- UINT8 DV : 3; // Divisor\r
- UINT8 UIP : 1; // Update in progress\r
-} RTC_REGISTER_A_BITS;\r
-\r
-typedef union {\r
- RTC_REGISTER_A_BITS Bits;\r
- UINT8 Data;\r
-} RTC_REGISTER_A;\r
-\r
-//\r
-// Register B\r
-//\r
-typedef struct {\r
- UINT8 DSE : 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled\r
- UINT8 MIL : 1; // 0 - 12 hour mode 1 - 24 hour mode\r
- UINT8 DM : 1; // 0 - BCD Format 1 - Binary Format\r
- UINT8 SQWE : 1; // 0 - Disable SQWE output 1 - Enable SQWE output\r
- UINT8 UIE : 1; // 0 - Update INT disabled 1 - Update INT enabled\r
- UINT8 AIE : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled\r
- UINT8 PIE : 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled\r
- UINT8 SET : 1; // 0 - Normal operation. 1 - Updates inhibited\r
-} RTC_REGISTER_B_BITS;\r
-\r
-typedef union {\r
- RTC_REGISTER_B_BITS Bits;\r
- UINT8 Data;\r
-} RTC_REGISTER_B;\r
-\r
-//\r
-// Register C\r
-//\r
-typedef struct {\r
- UINT8 Reserved : 4; // Read as zero. Can not be written.\r
- UINT8 UF : 1; // Update End Interrupt Flag\r
- UINT8 AF : 1; // Alarm Interrupt Flag\r
- UINT8 PF : 1; // Periodic Interrupt Flag\r
- UINT8 IRQF : 1; // Iterrupt Request Flag = PF & PIE | AF & AIE | UF & UIE\r
-} RTC_REGISTER_C_BITS;\r
-\r
-typedef union {\r
- RTC_REGISTER_C_BITS Bits;\r
- UINT8 Data;\r
-} RTC_REGISTER_C;\r
-\r
-//\r
-// Register D\r
-//\r
-typedef struct {\r
- UINT8 Reserved : 7; // Read as zero. Can not be written.\r
- UINT8 VRT : 1; // Valid RAM and Time\r
-} RTC_REGISTER_D_BITS;\r
-\r
-typedef union {\r
- RTC_REGISTER_D_BITS Bits;\r
- UINT8 Data;\r
-} RTC_REGISTER_D;\r
-\r
-#pragma pack()\r
-\r
-EFI_STATUS\r
-PcRtcInit (\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Global - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-PcRtcSetTime (\r
- IN EFI_TIME *Time,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
- Global - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-PcRtcGetTime (\r
- OUT EFI_TIME *Time,\r
- IN EFI_TIME_CAPABILITIES *Capabilities,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
- Capabilities - GC_TODO: add argument description\r
- Global - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-PcRtcSetWakeupTime (\r
- IN BOOLEAN Enable,\r
- OUT EFI_TIME *Time,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Enable - GC_TODO: add argument description\r
- Time - GC_TODO: add argument description\r
- Global - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-PcRtcGetWakeupTime (\r
- OUT BOOLEAN *Enabled,\r
- OUT BOOLEAN *Pending,\r
- OUT EFI_TIME *Time,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Enabled - GC_TODO: add argument description\r
- Pending - GC_TODO: add argument description\r
- Time - GC_TODO: add argument description\r
- Global - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-InitializePcRtc (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- ImageHandle - GC_TODO: add argument description\r
- SystemTable - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-UINT8\r
-BcdToDecimal (\r
- IN UINT8 BcdValue\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- BcdValue - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-RtcTimeFieldsValid (\r
- IN EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-UINT8\r
-DecimaltoBcd (\r
- IN UINT8 DecValue\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- DecValue - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-VOID\r
-ConvertEfiTimeToRtcTime (\r
- IN EFI_TIME *Time,\r
- IN RTC_REGISTER_B RegisterB,\r
- IN UINT8 *Century\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
- RegisterB - GC_TODO: add argument description\r
- Century - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-RtcTestCenturyRegister (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-VOID\r
-ConvertRtcTimeToEfiTime (\r
- IN EFI_TIME *Time,\r
- IN RTC_REGISTER_B RegisterB\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Time - GC_TODO: add argument description\r
- RegisterB - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-RtcWaitToUpdate (\r
- UINTN Timeout\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Timeout - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-UINT8\r
-RtcSaveContext (\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- Global - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-VOID\r
-RtcRestoreContext (\r
- IN UINT8 SavedAddressRegister,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- SavedAddressRegister - GC_TODO: add argument description\r
- Global - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-BOOLEAN\r
-DayValid (\r
- IN EFI_TIME *Time\r
- );\r
-\r
-BOOLEAN\r
-IsLeapYear (\r
- IN EFI_TIME *Time\r
- );\r
-\r
-#endif\r
+++ /dev/null
-#/** @file\r
-# PcRtc driver to install EFI_REAL_TIME_CLOCK_ARCH_PROTOCOL.\r
-#\r
-# This driver provides GetTime, SetTime, GetWakeupTime, SetWakeupTime services to Runtime Service Table.\r
-# Copyright (c) 2006 - 2007, Intel Corporation.\r
-#\r
-# All rights reserved.\r
-# This software and associated documentation (if any) is furnished\r
-# under a license and may only be used or copied in accordance\r
-# with the terms of the license. Except as permitted by such\r
-# license, no part of this software or documentation may be\r
-# reproduced, stored in a retrieval system, or transmitted in any\r
-# form or by any means without the express written consent of\r
-# Intel Corporation.\r
-#\r
-#\r
-#**/\r
-\r
-################################################################################\r
-#\r
-# Defines Section - statements that will be processed to create a Makefile.\r
-#\r
-################################################################################\r
-[Defines]\r
- INF_VERSION = 0x00010005\r
- BASE_NAME = PcRtc\r
- FILE_GUID = 378D7B65-8DA9-4773-B6E4-A47826A833E1\r
- MODULE_TYPE = DXE_RUNTIME_DRIVER\r
- VERSION_STRING = 1.0\r
- EDK_RELEASE_VERSION = 0x00020000\r
- EFI_SPECIFICATION_VERSION = 0x00020000\r
-\r
- ENTRY_POINT = InitializePcRtc\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-# VALID_ARCHITECTURES = IA32 X64 EBC\r
-#\r
-\r
-################################################################################\r
-#\r
-# Sources Section - list of files that are required for the build to succeed.\r
-#\r
-################################################################################\r
-\r
-[Sources.common]\r
- Ia32/Ia32PcRtc.c\r
- PcRtc.c\r
- PcRtc.h\r
-\r
-\r
-################################################################################\r
-#\r
-# Package Dependency Section - list of Package files that are required for\r
-# this module.\r
-#\r
-################################################################################\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- IntelFrameworkPkg/IntelFrameworkPkg.dec\r
-\r
-\r
-################################################################################\r
-#\r
-# Library Class Section - list of Library Classes that are required for\r
-# this module.\r
-#\r
-################################################################################\r
-\r
-[LibraryClasses]\r
- UefiRuntimeServicesTableLib\r
- UefiRuntimeLib\r
- UefiBootServicesTableLib\r
- UefiDriverEntryPoint\r
- TimerLib\r
- IoLib\r
- BaseMemoryLib\r
- UefiLib\r
- DebugLib\r
- BaseLib\r
-\r
-\r
-################################################################################\r
-#\r
-# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
-# that this module uses or produces.\r
-#\r
-################################################################################\r
-\r
-[Protocols]\r
- gEfiRealTimeClockArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
-\r
-\r
-################################################################################\r
-#\r
-# Dependency Expression Section - list of Dependency expressions that are required for\r
-# this module.\r
-#\r
-################################################################################\r
-\r
-[Depex]\r
- gEfiCpuArchProtocolGuid AND gEfiMetronomeArchProtocolGuid\r
-\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<ModuleSurfaceArea xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd" xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
- <MsaHeader>\r
- <ModuleName>PcRtc</ModuleName>\r
- <ModuleType>DXE_RUNTIME_DRIVER</ModuleType>\r
- <GuidValue>378D7B65-8DA9-4773-B6E4-A47826A833E1</GuidValue>\r
- <Version>1.0</Version>\r
- <Abstract>PcRtc driver to install EFI_REAL_TIME_CLOCK_ARCH_PROTOCOL.</Abstract>\r
- <Description>This driver provides GetTime, SetTime, GetWakeupTime, SetWakeupTime services to Runtime Service Table.</Description>\r
- <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
- <License>All rights reserved.\r
- This software and associated documentation (if any) is furnished\r
- under a license and may only be used or copied in accordance\r
- with the terms of the license. Except as permitted by such\r
- license, no part of this software or documentation may be\r
- reproduced, stored in a retrieval system, or transmitted in any\r
- form or by any means without the express written consent of\r
- Intel Corporation.</License>\r
- <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
- </MsaHeader>\r
- <ModuleDefinitions>\r
- <SupportedArchitectures>IA32 X64 EBC</SupportedArchitectures>\r
- <BinaryModule>false</BinaryModule>\r
- <OutputFileBasename>PcRtc</OutputFileBasename>\r
- </ModuleDefinitions>\r
- <LibraryClassDefinitions>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>BaseLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>DebugLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>BaseMemoryLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>IoLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>TimerLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiDriverEntryPoint</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiBootServicesTableLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiRuntimeLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiRuntimeServicesTableLib</Keyword>\r
- </LibraryClass>\r
- </LibraryClassDefinitions>\r
- <SourceFiles>\r
- <Filename>PcRtc.h</Filename>\r
- <Filename>PcRtc.c</Filename>\r
- <Filename>Ia32PcRtc.dxs</Filename>\r
- <Filename>Ia32/Ia32PcRtc.c</Filename>\r
- </SourceFiles>\r
- <PackageDependencies>\r
- <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
- </PackageDependencies>\r
- <Protocols>\r
- <Protocol Usage="ALWAYS_PRODUCED">\r
- <ProtocolCName>gEfiRealTimeClockArchProtocolGuid</ProtocolCName>\r
- </Protocol>\r
- </Protocols>\r
- <Externs>\r
- <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
- <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
- <Extern>\r
- <ModuleEntryPoint>InitializePcRtc</ModuleEntryPoint>\r
- </Extern>\r
- </Externs>\r
-</ModuleSurfaceArea>\r
+++ /dev/null
-/** @file\r
- Variable worker functions.\r
-\r
- Copyright (c) 2006, Intel Corporation<BR>\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
-**/\r
-\r
-#include <Variable.h>\r
-\r
-\r
-/**\r
- Get one variable by the index count.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Count The index count of variable in index table.\r
-\r
- @return The pointer to variable header indexed by count.\r
-\r
-**/\r
-VARIABLE_HEADER *\r
-GetVariableByIndex (\r
- IN VARIABLE_INDEX_TABLE *IndexTable,\r
- IN UINT32 Count\r
- )\r
-{\r
- return (VARIABLE_HEADER *) (UINTN) ((((UINT32)IndexTable->Index[Count]) << 2) + ((UINT32)(UINTN)IndexTable->StartPtr & 0xFFFC0000) );\r
-}\r
-\r
-/**\r
- Record Variable in VariableIndex HOB.\r
-\r
- Record Variable in VariableIndex HOB and update the length of variable index table.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Variable The pointer to the variable that will be recorded.\r
-\r
- @retval VOID\r
-\r
-**/\r
-VOID\r
-VariableIndexTableUpdate (\r
- IN OUT VARIABLE_INDEX_TABLE *IndexTable,\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-{\r
- IndexTable->Index[IndexTable->Length++] = (UINT16) (((UINT32)(UINTN) Variable) >> 2);\r
-\r
- return;\r
-}\r
-\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006 - 2007 Intel Corporation. <BR>\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
-Module Name:\r
-\r
- Variable.c\r
-\r
-Abstract:\r
-\r
- Framework PEIM to provide the Variable functionality\r
-\r
---*/\r
-\r
-\r
-#include "Variable.h"\r
-\r
-//\r
-// Module globals\r
-//\r
-static EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = {\r
- PeiGetVariable,\r
- PeiGetNextVariableName\r
-};\r
-\r
-static EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {\r
- (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
- &gEfiPeiReadOnlyVariable2PpiGuid,\r
- &mVariablePpi\r
-};\r
-\r
-EFI_GUID mEfiVariableIndexTableGuid = EFI_VARIABLE_INDEX_TABLE_GUID;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PeimInitializeVariableServices (\r
- IN EFI_FFS_FILE_HEADER *FfsHeader,\r
- IN EFI_PEI_SERVICES **PeiServices\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Provide the functionality of the variable services.\r
-\r
-Arguments:\r
-\r
- FfsHeadher - The FFS file header\r
- PeiServices - General purpose services available to every PEIM.\r
-\r
-Returns:\r
-\r
- Status - EFI_SUCCESS if the interface could be successfully\r
- installed\r
-\r
---*/\r
-{\r
- //\r
- // Publish the variable capability to other modules\r
- //\r
- return (**PeiServices).InstallPpi (PeiServices, &mPpiListVariable);\r
-\r
-}\r
-\r
-STATIC\r
-VARIABLE_HEADER *\r
-GetNextVariablePtr (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code checks if variable header is valid or not.\r
-\r
-Arguments:\r
- Variable Pointer to the Variable Header.\r
-\r
-Returns:\r
- TRUE Variable header is valid.\r
- FALSE Variable header is not valid.\r
-\r
---*/\r
-{\r
- return (VARIABLE_HEADER *) ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));\r
-}\r
-\r
-STATIC\r
-BOOLEAN\r
-EFIAPI\r
-IsValidVariableHeader (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code checks if variable header is valid or not.\r
-\r
-Arguments:\r
- Variable Pointer to the Variable Header.\r
-\r
-Returns:\r
- TRUE Variable header is valid.\r
- FALSE Variable header is not valid.\r
-\r
---*/\r
-{\r
- if (Variable == NULL ||\r
- Variable->StartId != VARIABLE_DATA ||\r
- (sizeof (VARIABLE_HEADER) + Variable->DataSize + Variable->NameSize) > MAX_VARIABLE_SIZE\r
- ) {\r
- return FALSE;\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
-STATIC\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
- EfiRaw Variable store is raw\r
- EfiValid Variable store is valid\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
- }\r
-\r
- 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
-EFI_STATUS\r
-CompareWithValidVariable (\r
- IN VARIABLE_HEADER *Variable,\r
- IN CONST CHAR16 *VariableName,\r
- IN CONST EFI_GUID *VendorGuid,\r
- OUT VARIABLE_POINTER_TRACK *PtrTrack\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This function compares a variable with variable entries in database\r
-\r
-Arguments:\r
-\r
- Variable - Pointer to the variable in our database\r
- VariableName - Name of the variable to compare to 'Variable'\r
- VendorGuid - GUID of the variable to compare to 'Variable'\r
- PtrTrack - Variable Track Pointer structure that contains\r
- Variable Information.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Found match variable\r
- EFI_NOT_FOUND - Variable not found\r
-\r
---*/\r
-{\r
- if (VariableName[0] == 0) {\r
- PtrTrack->CurrPtr = Variable;\r
- return EFI_SUCCESS;\r
- } else {\r
- //\r
- // Don't use CompareGuid function here for performance reasons.\r
- // Instead we compare the GUID a UINT32 at a time and branch\r
- // on the first failed comparison.\r
- //\r
- if ((((INT32 *) VendorGuid)[0] == ((INT32 *) &Variable->VendorGuid)[0]) &&\r
- (((INT32 *) VendorGuid)[1] == ((INT32 *) &Variable->VendorGuid)[1]) &&\r
- (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) &&\r
- (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])\r
- ) {\r
- if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), Variable->NameSize)) {\r
- PtrTrack->CurrPtr = Variable;\r
- return EFI_SUCCESS;\r
- }\r
- }\r
- }\r
-\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-FindVariable (\r
- IN EFI_PEI_SERVICES **PeiServices,\r
- IN CONST CHAR16 *VariableName,\r
- IN CONST EFI_GUID *VendorGuid,\r
- OUT VARIABLE_POINTER_TRACK *PtrTrack\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code finds variable in storage blocks (Non-Volatile)\r
-\r
-Arguments:\r
-\r
- PeiServices - General purpose services available to every PEIM.\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
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Variable found successfully\r
- EFI_NOT_FOUND - Variable not found\r
- EFI_INVALID_PARAMETER - Invalid variable name\r
-\r
---*/\r
-{\r
- EFI_HOB_GUID_TYPE *GuidHob;\r
- VARIABLE_STORE_HEADER *VariableStoreHeader;\r
- VARIABLE_HEADER *Variable;\r
- VARIABLE_HEADER *MaxIndex;\r
- VARIABLE_INDEX_TABLE *IndexTable;\r
- UINT32 Count;\r
- UINT8 *VariableBase;\r
-\r
- if (VariableName != 0 && VendorGuid == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // No Variable Address equals zero, so 0 as initial value is safe.\r
- //\r
- MaxIndex = 0;\r
-\r
- GuidHob = GetFirstGuidHob (&mEfiVariableIndexTableGuid);\r
- if (GuidHob == NULL) {\r
- IndexTable = BuildGuidHob (&mEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));\r
- IndexTable->Length = 0;\r
- IndexTable->StartPtr = NULL;\r
- IndexTable->EndPtr = NULL;\r
- IndexTable->GoneThrough = 0;\r
- } else {\r
- IndexTable = GET_GUID_HOB_DATA (GuidHob);\r
- for (Count = 0; Count < IndexTable->Length; Count++)\r
- {\r
- MaxIndex = GetVariableByIndex (IndexTable, Count);\r
-\r
- if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
- PtrTrack->StartPtr = IndexTable->StartPtr;\r
- PtrTrack->EndPtr = IndexTable->EndPtr;\r
-\r
- return EFI_SUCCESS;\r
- }\r
- }\r
-\r
- if (IndexTable->GoneThrough) {\r
- return EFI_NOT_FOUND;\r
- }\r
- }\r
- //\r
- // If not found in HOB, then let's start from the MaxIndex we've found.\r
- //\r
- if (MaxIndex != NULL) {\r
- Variable = GetNextVariablePtr (MaxIndex);\r
- } else {\r
- if (IndexTable->StartPtr || IndexTable->EndPtr) {\r
- Variable = IndexTable->StartPtr;\r
- } else {\r
- VariableBase = (UINT8 *) (UINTN) PcdGet32 (PcdFlashNvStorageVariableBase);\r
- VariableStoreHeader = (VARIABLE_STORE_HEADER *) (VariableBase + \\r
- ((EFI_FIRMWARE_VOLUME_HEADER *) (VariableBase)) -> HeaderLength);\r
-\r
- if (GetVariableStoreStatus (VariableStoreHeader) != EfiValid) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- if (~VariableStoreHeader->Size == 0) {\r
- return EFI_NOT_FOUND;\r
- }\r
- //\r
- // Find the variable by walk through non-volatile variable store\r
- //\r
- IndexTable->StartPtr = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
- IndexTable->EndPtr = (VARIABLE_HEADER *) ((UINTN) VariableStoreHeader + VariableStoreHeader->Size);\r
-\r
- //\r
- // Start Pointers for the variable.\r
- // Actual Data Pointer where data can be written.\r
- //\r
- Variable = IndexTable->StartPtr;\r
- }\r
- }\r
- //\r
- // Find the variable by walk through non-volatile variable store\r
- //\r
- PtrTrack->StartPtr = IndexTable->StartPtr;\r
- PtrTrack->EndPtr = IndexTable->EndPtr;\r
-\r
- while (IsValidVariableHeader (Variable) && (Variable <= IndexTable->EndPtr)) {\r
- if (Variable->State == VAR_ADDED) {\r
- //\r
- // Record Variable in VariableIndex HOB\r
- //\r
- if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME)\r
- {\r
- VariableIndexTableUpdate (IndexTable, Variable);\r
- }\r
-\r
- if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
- return EFI_SUCCESS;\r
- }\r
- }\r
-\r
- Variable = GetNextVariablePtr (Variable);\r
- }\r
- //\r
- // If gone through the VariableStore, that means we never find in Firmware any more.\r
- //\r
- if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) {\r
- IndexTable->GoneThrough = 1;\r
- }\r
-\r
- PtrTrack->CurrPtr = NULL;\r
-\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PeiGetVariable (\r
- IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
- IN CONST CHAR16 *VariableName,\r
- IN CONST EFI_GUID *VariableGuid,\r
- OUT UINT32 *Attributes,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Provide the read variable functionality of the variable services.\r
-\r
-Arguments:\r
-\r
- PeiServices - General purpose services available to every PEIM.\r
-\r
- VariableName - The variable name\r
-\r
- VendorGuid - The vendor's GUID\r
-\r
- Attributes - Pointer to the attribute\r
-\r
- DataSize - Size of data\r
-\r
- Data - Pointer to data\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The interface could be successfully installed\r
-\r
- EFI_NOT_FOUND - The variable could not be discovered\r
-\r
- EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough\r
-\r
---*/\r
-{\r
- VARIABLE_POINTER_TRACK Variable;\r
- UINTN VarDataSize;\r
- EFI_STATUS Status;\r
- EFI_PEI_SERVICES **PeiServices;\r
-\r
- PeiServices = GetPeiServicesTablePointer ();\r
- if (VariableName == NULL || VariableGuid == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Find existing variable\r
- //\r
- Status = FindVariable (PeiServices, VariableName, VariableGuid, &Variable);\r
- if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
- return Status;\r
- }\r
- //\r
- // Get data size\r
- //\r
- VarDataSize = Variable.CurrPtr->DataSize;\r
- if (*DataSize >= VarDataSize) {\r
- (*PeiServices)->CopyMem (Data, GET_VARIABLE_DATA_PTR (Variable.CurrPtr), VarDataSize);\r
-\r
- if (Attributes != NULL) {\r
- *Attributes = Variable.CurrPtr->Attributes;\r
- }\r
-\r
- *DataSize = VarDataSize;\r
- return EFI_SUCCESS;\r
- } else {\r
- *DataSize = VarDataSize;\r
- return EFI_BUFFER_TOO_SMALL;\r
- }\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PeiGetNextVariableName (\r
- IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VariableGuid\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Provide the get next variable functionality of the variable services.\r
-\r
-Arguments:\r
-\r
- PeiServices - General purpose services available to every PEIM.\r
- VariabvleNameSize - The variable name's size.\r
- VariableName - A pointer to the variable's name.\r
- VariableGuid - A pointer to the EFI_GUID structure.\r
-\r
- VariableNameSize - Size of the variable name\r
-\r
- VariableName - The variable name\r
-\r
- VendorGuid - The vendor's GUID\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The interface could be successfully installed\r
-\r
- EFI_NOT_FOUND - The variable could not be discovered\r
-\r
---*/\r
-{\r
- VARIABLE_POINTER_TRACK Variable;\r
- UINTN VarNameSize;\r
- EFI_STATUS Status;\r
- EFI_PEI_SERVICES **PeiServices;\r
-\r
- PeiServices = GetPeiServicesTablePointer ();\r
- if (VariableName == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = FindVariable (PeiServices, VariableName, VariableGuid, &Variable);\r
- if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
- return Status;\r
- }\r
-\r
- if (VariableName[0] != 0) {\r
- //\r
- // If variable name is not NULL, get next variable\r
- //\r
- Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
- }\r
-\r
- while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {\r
- if (IsValidVariableHeader (Variable.CurrPtr)) {\r
- if (Variable.CurrPtr->State == VAR_ADDED) {\r
- VarNameSize = (UINTN) Variable.CurrPtr->NameSize;\r
- if (VarNameSize <= *VariableNameSize) {\r
- (*PeiServices)->CopyMem (VariableName, GET_VARIABLE_NAME_PTR (Variable.CurrPtr), VarNameSize);\r
-\r
- (*PeiServices)->CopyMem (VariableGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));\r
-\r
- Status = EFI_SUCCESS;\r
- } else {\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- }\r
-\r
- *VariableNameSize = VarNameSize;\r
- return Status;\r
- //\r
- // Variable is found\r
- //\r
- } else {\r
- Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
- }\r
- } else {\r
- break;\r
- }\r
- }\r
-\r
- return EFI_NOT_FOUND;\r
-}\r
+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- Variable.dxs\r
-\r
-Abstract:\r
-\r
- Dependency expression file for Variable PEIM.\r
-\r
---*/ \r
-//\r
-// Include common header file for this module.\r
-//\r
-#include "CommonHeader.h"\r
-\r
-#include <PeimDepex.h>\r
-\r
-DEPENDENCY_START\r
- TRUE\r
-DEPENDENCY_END\r
-\r
-\r
+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- Variable.h\r
-\r
-Abstract:\r
-\r
- Tiano PEIM to provide the variable functionality\r
-\r
---*/\r
-\r
-#ifndef _PEI_VARIABLE_H\r
-#define _PEI_VARIABLE_H\r
-\r
-#include <PiPei.h>\r
-#include <Ppi/ReadOnlyVariable2.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/PeimEntryPoint.h>\r
-#include <Library/HobLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/PeiServicesTablePointerLib.h>\r
-\r
-\r
-//\r
-// BugBug: We need relcate the head file.\r
-//\r
-#include <Common/Variable.h>\r
-\r
-//\r
-// Define GET_PAD_SIZE to optimize compiler\r
-//\r
-#if ((ALIGNMENT == 0) || (ALIGNMENT == 1))\r
-#define GET_PAD_SIZE(a) (0)\r
-#else\r
-#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))\r
-#endif\r
-\r
-#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))\r
-\r
-#define GET_VARIABLE_DATA_PTR(a) \\r
- (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (a) + (a)->NameSize + GET_PAD_SIZE ((a)->NameSize))\r
-\r
-typedef struct {\r
- VARIABLE_HEADER *CurrPtr;\r
- VARIABLE_HEADER *EndPtr;\r
- VARIABLE_HEADER *StartPtr;\r
-} VARIABLE_POINTER_TRACK;\r
-\r
-#define VARIABLE_INDEX_TABLE_VOLUME 122\r
-\r
-#define EFI_VARIABLE_INDEX_TABLE_GUID \\r
- { 0x8cfdb8c8, 0xd6b2, 0x40f3, { 0x8e, 0x97, 0x02, 0x30, 0x7c, 0xc9, 0x8b, 0x7c } }\r
-\r
-typedef struct {\r
- UINT16 Length;\r
- UINT16 GoneThrough;\r
- VARIABLE_HEADER *EndPtr;\r
- VARIABLE_HEADER *StartPtr;\r
- UINT16 Index[VARIABLE_INDEX_TABLE_VOLUME];\r
-} VARIABLE_INDEX_TABLE;\r
-\r
-\r
-//\r
-// Functions\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-PeimInitializeVariableServices (\r
- IN EFI_FFS_FILE_HEADER *FfsHeader,\r
- IN EFI_PEI_SERVICES **PeiServices\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- FfsHeader - TODO: add argument description\r
- PeiServices - TODO: add argument description\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PeiGetVariable (\r
- IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
- IN CONST CHAR16 *VariableName,\r
- IN CONST EFI_GUID *VariableGuid,\r
- OUT UINT32 *Attributes,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- PeiServices - TODO: add argument description\r
- VariableName - TODO: add argument description\r
- VendorGuid - TODO: add argument description\r
- Attributes - TODO: add argument description\r
- DataSize - TODO: add argument description\r
- Data - TODO: add argument description\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-PeiGetNextVariableName (\r
- IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VariableGuid\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- PeiServices - TODO: add argument description\r
- VariableNameSize - TODO: add argument description\r
- VariableName - TODO: add argument description\r
- VendorGuid - TODO: add argument description\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-/**\r
- Get one variable by the index count.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Count The index count of variable in index table.\r
-\r
- @return The pointer to variable header indexed by count.\r
-\r
-**/\r
-VARIABLE_HEADER *\r
-GetVariableByIndex (\r
- IN VARIABLE_INDEX_TABLE *IndexTable,\r
- IN UINT32 Count\r
- );\r
-\r
-/**\r
- Record Variable in VariableIndex HOB.\r
-\r
- Record Variable in VariableIndex HOB and update the length of variable index table.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Variable The pointer to the variable that will be recorded.\r
-\r
- @retval VOID\r
-\r
-**/\r
-VOID\r
-VariableIndexTableUpdate (\r
- IN OUT VARIABLE_INDEX_TABLE *IndexTable,\r
- IN VARIABLE_HEADER *Variable\r
- );\r
-\r
-#endif // _PEI_VARIABLE_H\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
- <MsaHeader>\r
- <ModuleName>PeiVariable</ModuleName>\r
- <ModuleType>PEIM</ModuleType>\r
- <GuidValue>34C8C28F-B61C-45a2-8F2E-89E46BECC63B</GuidValue>\r
- <Version>1.0</Version>\r
- <Abstract>Component description file for PeiVariable module.</Abstract>\r
- <Description>Framework PEIM to provide the Variable functionality.</Description>\r
- <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
- <License>All rights reserved. This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
- <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
- </MsaHeader>\r
- <ModuleDefinitions>\r
- <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
- <BinaryModule>false</BinaryModule>\r
- <OutputFileBasename>PeiVariable</OutputFileBasename>\r
- </ModuleDefinitions>\r
- <LibraryClassDefinitions>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>DebugLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>PeimEntryPoint</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>HobLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>PcdLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>BaseMemoryLib</Keyword>\r
- </LibraryClass>\r
- </LibraryClassDefinitions>\r
- <SourceFiles>\r
- <Filename>Variable.h</Filename>\r
- <Filename>Variable.c</Filename>\r
- <Filename>Variable.dxs</Filename>\r
- <Filename SupArchList="IA32 X64 EBC">VariableWorker.c</Filename>\r
- <Filename SupArchList="IPF">Ipf/VariableWorker.c</Filename>\r
- <Filename SupArchList="IA32">Ia32/VarMachine.h</Filename>\r
- <Filename SupArchList="EBC">Ebc/VarMachine.h</Filename>\r
- <Filename SupArchList="X64">x64/VarMachine.h</Filename>\r
- <Filename SupArchList="IPF">Ipf/VarMachine.h</Filename>\r
- </SourceFiles>\r
- <PackageDependencies>\r
- <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
- <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
- </PackageDependencies>\r
- <PPIs>\r
- <Ppi Usage="ALWAYS_CONSUMED">\r
- <PpiCName>gEfiPeiReadOnlyVariablePpiGuid</PpiCName>\r
- </Ppi>\r
- </PPIs>\r
- <Externs>\r
- <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
- <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
- <Extern>\r
- <ModuleEntryPoint>PeimInitializeVariableServices</ModuleEntryPoint>\r
- </Extern>\r
- </Externs>\r
- <PcdCoded>\r
- <PcdEntry PcdItemType="DYNAMIC">\r
- <C_Name>PcdFlashNvStorageVariableBase</C_Name>\r
- <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
- <HelpText>The driver gets the Variable store base address from this PCD. This base address point to
- an EFI_FIRMWARE_VOLUMN_HEADER struct.</HelpText>\r
- </PcdEntry>\r
- </PcdCoded>\r
-</ModuleSurfaceArea>
\ No newline at end of file
+++ /dev/null
-#/** @file\r
-# Component description file for PeiVariable module.\r
-#\r
-# Framework PEIM to provide the Variable functionality.\r
-# Copyright (c) 2006 - 2007, Intel Corporation\r
-#\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
-# 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
-\r
-[Defines]\r
- INF_VERSION = 0x00010005\r
- BASE_NAME = PeiVariable\r
- FILE_GUID = 34C8C28F-B61C-45a2-8F2E-89E46BECC63B\r
- MODULE_TYPE = PEIM\r
- VERSION_STRING = 1.0\r
- EDK_RELEASE_VERSION = 0x00020000\r
- EFI_SPECIFICATION_VERSION = 0x00020000\r
-\r
- ENTRY_POINT = PeimInitializeVariableServices\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-# VALID_ARCHITECTURES = IA32 X64 IPF EBC\r
-#\r
-\r
-[Sources.common]\r
- Variable.c\r
- Variable.h\r
-\r
-[Sources.Ia32]\r
- VariableWorker.c\r
-\r
-[Sources.X64]\r
- VariableWorker.c\r
-\r
-[Sources.IPF]\r
- Ipf/VariableWorker.c\r
-\r
-[Sources.EBC]\r
- VariableWorker.c\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- MdeModulePkg/MdeModulePkg.dec\r
-\r
-[LibraryClasses]\r
- BaseMemoryLib\r
- PcdLib\r
- HobLib\r
- PeimEntryPoint\r
- DebugLib\r
- PeiServiceTablePointerLib\r
-\r
-[Ppis]\r
- gEfiPeiReadOnlyVariable2PpiGuid # PPI ALWAYS_CONSUMED\r
-\r
-[PcdsDynamic.common]\r
- PcdFlashNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid\r
-\r
-[Depex]\r
- TRUE\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 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
- VariableWorker.c\r
-\r
-Abstract:\r
-\r
- Framework PEIM to provide the Variable functionality\r
-\r
---*/\r
-\r
-#include <Variable.h>\r
-\r
-/**\r
- Get one variable by the index count.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Count The index count of variable in index table.\r
-\r
- @return The pointer to variable header indexed by count.\r
-\r
-**/\r
-VARIABLE_HEADER *\r
-GetVariableByIndex (\r
- IN VARIABLE_INDEX_TABLE *IndexTable,\r
- IN UINT32 Count\r
- )\r
-{\r
- return (VARIABLE_HEADER *) (UINTN) (IndexTable->Index[Count] + ((UINTN) IndexTable->StartPtr & 0xFFFF0000));\r
-}\r
-\r
-/**\r
- Record Variable in VariableIndex HOB.\r
-\r
- Record Variable in VariableIndex HOB and update the length of variable index table.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Variable The pointer to the variable that will be recorded.\r
-\r
- @retval VOID\r
-\r
-**/\r
-VOID\r
-VariableIndexTableUpdate (\r
- IN OUT VARIABLE_INDEX_TABLE *IndexTable,\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-{\r
- IndexTable->Index[IndexTable->Length++] = (UINT16) (UINTN) Variable;\r
-\r
- return;\r
-}\r
-\r
+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- InitVariable.c\r
-\r
-Abstract:\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#include "Variable.h"\r
-\r
-//\r
-// Event for Exit Boot Services Callback\r
-//\r
-STATIC EFI_EVENT mExitBootServicesEvent = NULL;\r
-\r
-\r
-//\r
-// Don't use module globals after the SetVirtualAddress map is signaled\r
-//\r
-extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\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\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- return GetVariable (\r
- VariableName,\r
- VendorGuid,\r
- Attributes OPTIONAL,\r
- DataSize,\r
- Data,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- mVariableModuleGlobal->FvbInstance\r
- );\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
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- return GetNextVariableName (\r
- VariableNameSize,\r
- VariableName,\r
- VendorGuid,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- mVariableModuleGlobal->FvbInstance\r
- );\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
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- return SetVariable (\r
- VariableName,\r
- VendorGuid,\r
- Attributes,\r
- DataSize,\r
- Data,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- &mVariableModuleGlobal->VolatileLastVariableOffset,\r
- &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
- mVariableModuleGlobal->FvbInstance\r
- );\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
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\r
- return QueryVariableInfo (\r
- Attributes,\r
- MaximumVariableStorageSize,\r
- RemainingVariableStorageSize,\r
- MaximumVariableSize,\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- mVariableModuleGlobal->FvbInstance\r
- );\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-VariableClassAddressChangeEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
-{\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
-EFI_STATUS\r
-EFIAPI\r
-VariableServiceInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\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->CreateEvent (\r
- EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
- TPL_NOTIFY,\r
- VariableClassAddressChangeEvent,\r
- NULL,\r
- &mExitBootServicesEvent\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return EFI_SUCCESS;\r
-}\r
+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- Variable.c\r
-\r
-Abstract:\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-\r
-#include "Variable.h"\r
-#include <Common/FlashMap.h>\r
-\r
-//\r
-// Don't use module globals after the SetVirtualAddress map is signaled\r
-//\r
-ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\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
-STATIC\r
-VOID\r
-AcquireLockOnlyAtBootTime (\r
- IN EFI_LOCK *Lock\r
- )\r
-{\r
- if (!EfiAtRuntime ()) {\r
- EfiAcquireLock (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
-STATIC\r
-VOID\r
-ReleaseLockOnlyAtBootTime (\r
- IN EFI_LOCK *Lock\r
- )\r
-{\r
- if (!EfiAtRuntime ()) {\r
- EfiReleaseLock (Lock);\r
- }\r
-}\r
-\r
-STATIC\r
-BOOLEAN\r
-EFIAPI\r
-IsValidVariableHeader (\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code checks if variable header is valid or not.\r
-\r
-Arguments:\r
- Variable Pointer to the Variable Header.\r
-\r
-Returns:\r
- TRUE Variable header is valid.\r
- FALSE Variable header is not valid.\r
-\r
---*/\r
-{\r
- if (Variable == NULL ||\r
- Variable->StartId != VARIABLE_DATA ||\r
- (sizeof (VARIABLE_HEADER) + Variable->NameSize + Variable->DataSize) > MAX_VARIABLE_SIZE\r
- ) {\r
- return FALSE;\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-UpdateVariableStore (\r
- IN VARIABLE_GLOBAL *Global,\r
- IN BOOLEAN Volatile,\r
- IN BOOLEAN SetByIndex,\r
- IN UINTN Instance,\r
- IN UINTN DataPtrIndex,\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 STATUS\r
-\r
---*/\r
-{\r
- EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r
- UINTN BlockIndex2;\r
- UINTN LinearOffset;\r
- UINTN CurrWriteSize;\r
- UINTN CurrWritePtr;\r
- UINT8 *CurrBuffer;\r
- EFI_LBA LbaNumber;\r
- UINTN Size;\r
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
- VARIABLE_STORE_HEADER *VolatileBase;\r
- EFI_PHYSICAL_ADDRESS FvVolHdr;\r
- EFI_PHYSICAL_ADDRESS DataPtr;\r
- EFI_STATUS Status;\r
-\r
- FwVolHeader = NULL;\r
- DataPtr = DataPtrIndex;\r
-\r
- //\r
- // Check if the Data is Volatile\r
- //\r
- if (!Volatile) {\r
- EfiFvbGetPhysicalAddress (Instance, &FvVolHdr);\r
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);\r
- //\r
- // Data Pointer should point to the actual Address where data is to be\r
- // written\r
- //\r
- if (SetByIndex) {\r
- DataPtr += Global->NonVolatileVariableBase;\r
- }\r
-\r
- if ((DataPtr + DataSize) >= ((EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) FwVolHeader + FwVolHeader->FvLength))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- } else {\r
- //\r
- // Data Pointer should point to the actual Address where data is to be\r
- // written\r
- //\r
- VolatileBase = (VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase);\r
- if (SetByIndex) {\r
- DataPtr += Global->VolatileVariableBase;\r
- }\r
-\r
- if ((DataPtr + DataSize) >= ((UINTN) ((UINT8 *) VolatileBase + VolatileBase->Size))) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- }\r
- //\r
- // If Volatile Variable just do a simple mem copy.\r
- //\r
- if (Volatile) {\r
- CopyMem ((UINT8 *) ((UINTN) DataPtr), Buffer, DataSize);\r
- return EFI_SUCCESS;\r
- }\r
- //\r
- // If we are here we are dealing with Non-Volatile Variables\r
- //\r
- LinearOffset = (UINTN) FwVolHeader;\r
- CurrWritePtr = (UINTN) DataPtr;\r
- CurrWriteSize = DataSize;\r
- CurrBuffer = Buffer;\r
- LbaNumber = 0;\r
-\r
- if (CurrWritePtr < LinearOffset) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- for (PtrBlockMapEntry = FwVolHeader->BlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r
- for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->NumBlocks; BlockIndex2++) {\r
- //\r
- // Check to see if the Variable Writes are spanning through multiple\r
- // blocks.\r
- //\r
- if ((CurrWritePtr >= LinearOffset) && (CurrWritePtr < LinearOffset + PtrBlockMapEntry->Length)) {\r
- if ((CurrWritePtr + CurrWriteSize) <= (LinearOffset + PtrBlockMapEntry->Length)) {\r
- Status = EfiFvbWriteBlock (\r
- Instance,\r
- LbaNumber,\r
- (UINTN) (CurrWritePtr - LinearOffset),\r
- &CurrWriteSize,\r
- CurrBuffer\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- } else {\r
- Size = (UINT32) (LinearOffset + PtrBlockMapEntry->Length - CurrWritePtr);\r
- Status = EfiFvbWriteBlock (\r
- Instance,\r
- LbaNumber,\r
- (UINTN) (CurrWritePtr - LinearOffset),\r
- &Size,\r
- CurrBuffer\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- CurrWritePtr = LinearOffset + PtrBlockMapEntry->Length;\r
- CurrBuffer = CurrBuffer + Size;\r
- CurrWriteSize = CurrWriteSize - Size;\r
- }\r
- }\r
-\r
- LinearOffset += PtrBlockMapEntry->Length;\r
- LbaNumber++;\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-STATIC\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 current status of Variable Store.\r
-\r
-Arguments:\r
-\r
- VarStoreHeader Pointer to the Variable Store Header.\r
-\r
-Returns:\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
- 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
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the pointer to the variable data.\r
-\r
-Arguments:\r
-\r
- Variable Pointer to the Variable Header.\r
-\r
-Returns:\r
-\r
- UINT8* Pointer to Variable Data\r
-\r
---*/\r
-{\r
- //\r
- // Be careful about pad size for alignment\r
- //\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
- IN VARIABLE_HEADER *Variable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code gets the pointer to the next variable header.\r
-\r
-Arguments:\r
-\r
- Variable Pointer to the Variable Header.\r
-\r
-Returns:\r
-\r
- VARIABLE_HEADER* Pointer to next variable header.\r
-\r
---*/\r
-{\r
- if (!IsValidVariableHeader (Variable)) {\r
- return NULL;\r
- }\r
- //\r
- // Be careful about pad size for alignment\r
- //\r
- return (VARIABLE_HEADER *) ((UINTN) GetVariableDataPtr (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));\r
-}\r
-\r
-STATIC\r
-VARIABLE_HEADER *\r
-EFIAPI\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
-Arguments:\r
-\r
- VarStoreHeader Pointer to the Variable Store Header.\r
-\r
-Returns:\r
-\r
- VARIABLE_HEADER* Pointer to last unavailable Variable Header\r
-\r
---*/\r
-{\r
- //\r
- // The end of variable store\r
- //\r
- return (VARIABLE_HEADER *) ((UINTN) VarStoreHeader + VarStoreHeader->Size);\r
-}\r
-\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-Reclaim (\r
- IN EFI_PHYSICAL_ADDRESS VariableBase,\r
- OUT UINTN *LastVariableOffset,\r
- IN BOOLEAN IsVolatile\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 *NextVariable;\r
- VARIABLE_STORE_HEADER *VariableStoreHeader;\r
- UINT8 *ValidBuffer;\r
- UINTN ValidBufferSize;\r
- UINTN VariableSize;\r
- UINT8 *CurrPtr;\r
- EFI_STATUS Status;\r
-\r
- VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) VariableBase);\r
-\r
- //\r
- // Start Pointers for the variable.\r
- //\r
- Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
-\r
- ValidBufferSize = sizeof (VARIABLE_STORE_HEADER);\r
-\r
- while (IsValidVariableHeader (Variable)) {\r
- NextVariable = GetNextVariablePtr (Variable);\r
- if (Variable->State == VAR_ADDED) {\r
- VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
- ValidBufferSize += VariableSize;\r
- }\r
-\r
- Variable = NextVariable;\r
- }\r
-\r
- ValidBuffer = AllocatePool (ValidBufferSize);\r
- if (ValidBuffer == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- SetMem (ValidBuffer, ValidBufferSize, 0xff);\r
-\r
- CurrPtr = ValidBuffer;\r
-\r
- //\r
- // Copy variable store header\r
- //\r
- CopyMem (CurrPtr, VariableStoreHeader, sizeof (VARIABLE_STORE_HEADER));\r
- CurrPtr += sizeof (VARIABLE_STORE_HEADER);\r
-\r
- //\r
- // Start Pointers for the variable.\r
- //\r
- Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
-\r
- while (IsValidVariableHeader (Variable)) {\r
- NextVariable = GetNextVariablePtr (Variable);\r
- if (Variable->State == VAR_ADDED) {\r
- VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
- CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);\r
- CurrPtr += VariableSize;\r
- }\r
-\r
- Variable = NextVariable;\r
- }\r
-\r
- if (IsVolatile) {\r
- //\r
- // If volatile variable store, just copy valid buffer\r
- //\r
- SetMem ((UINT8 *) (UINTN) VariableBase, VariableStoreHeader->Size, 0xff);\r
- CopyMem ((UINT8 *) (UINTN) VariableBase, ValidBuffer, ValidBufferSize);\r
- *LastVariableOffset = ValidBufferSize;\r
- Status = EFI_SUCCESS;\r
- } else {\r
- //\r
- // If non-volatile variable store, perform FTW here.\r
- //\r
- Status = FtwVariableSpace (\r
- VariableBase,\r
- ValidBuffer,\r
- ValidBufferSize\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- *LastVariableOffset = ValidBufferSize;\r
- }\r
- }\r
-\r
- FreePool (ValidBuffer);\r
-\r
- if (EFI_ERROR (Status)) {\r
- *LastVariableOffset = 0;\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-FindVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\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_STORE_HEADER *VariableStoreHeader[2];\r
- UINTN Index;\r
-\r
- //\r
- // We aquire the lock at the entry of FindVariable as GetVariable, GetNextVariableName\r
- // SetVariable all call FindVariable at entry point. Please move "Aquire Lock" to\r
- // the correct places if this assumption does not hold TRUE anymore.\r
- //\r
- AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);\r
-\r
- //\r
- // 0: Non-Volatile, 1: Volatile\r
- //\r
- VariableStoreHeader[0] = (VARIABLE_STORE_HEADER *) ((UINTN) Global->NonVolatileVariableBase);\r
- VariableStoreHeader[1] = (VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase);\r
-\r
- //\r
- // Start Pointers for the variable.\r
- // Actual Data Pointer where data can be written.\r
- //\r
- Variable[0] = (VARIABLE_HEADER *) (VariableStoreHeader[0] + 1);\r
- Variable[1] = (VARIABLE_HEADER *) (VariableStoreHeader[1] + 1);\r
-\r
- if (VariableName[0] != 0 && VendorGuid == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Find the variable by walk through non-volatile and volatile variable store\r
- //\r
- for (Index = 0; Index < 2; Index++) {\r
- PtrTrack->StartPtr = (VARIABLE_HEADER *) (VariableStoreHeader[Index] + 1);\r
- PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader[Index]);\r
-\r
- while (IsValidVariableHeader (Variable[Index]) && (Variable[Index] <= GetEndPointer (VariableStoreHeader[Index]))) {\r
- if (Variable[Index]->State == VAR_ADDED) {\r
- if (!(EfiAtRuntime () && !(Variable[Index]->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {\r
- if (VariableName[0] == 0) {\r
- PtrTrack->CurrPtr = Variable[Index];\r
- PtrTrack->Volatile = (BOOLEAN) Index;\r
- return EFI_SUCCESS;\r
- } else {\r
- if (CompareGuid (VendorGuid, &Variable[Index]->VendorGuid)) {\r
- if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable[Index]), Variable[Index]->NameSize)) {\r
- PtrTrack->CurrPtr = Variable[Index];\r
- PtrTrack->Volatile = (BOOLEAN) Index;\r
- return EFI_SUCCESS;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- Variable[Index] = GetNextVariablePtr (Variable[Index]);\r
- }\r
- //\r
- // While (...)\r
- //\r
- }\r
- //\r
- // for (...)\r
- //\r
- PtrTrack->CurrPtr = NULL;\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-GetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID * VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data,\r
- IN VARIABLE_GLOBAL * Global,\r
- IN UINT32 Instance\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 STATUS\r
-\r
---*/\r
-{\r
- VARIABLE_POINTER_TRACK Variable;\r
- UINTN VarDataSize;\r
- EFI_STATUS Status;\r
-\r
- if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- //\r
- // Find existing variable\r
- //\r
- Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
-\r
- if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
- //\r
- // Get data size\r
- //\r
- VarDataSize = Variable.CurrPtr->DataSize;\r
- if (*DataSize >= VarDataSize) {\r
- if (Data == NULL) {\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- }\r
-\r
- CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
- if (Attributes != NULL) {\r
- *Attributes = Variable.CurrPtr->Attributes;\r
- }\r
-\r
- *DataSize = VarDataSize;\r
- Status = EFI_SUCCESS;\r
- goto Done;\r
- } else {\r
- *DataSize = VarDataSize;\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- goto Done;\r
- }\r
-\r
-Done:\r
- ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-GetNextVariableName (\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VendorGuid,\r
- IN VARIABLE_GLOBAL *Global,\r
- IN UINT32 Instance\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code Finds the Next available variable\r
-\r
-Arguments:\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
-\r
-Returns:\r
-\r
- EFI STATUS\r
-\r
---*/\r
-{\r
- VARIABLE_POINTER_TRACK Variable;\r
- UINTN VarNameSize;\r
- EFI_STATUS Status;\r
-\r
- if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
-\r
- if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
-\r
- if (VariableName[0] != 0) {\r
- //\r
- // If variable name is not NULL, get next variable\r
- //\r
- Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
- }\r
-\r
- while (TRUE) {\r
- //\r
- // If both volatile and non-volatile variable store are parsed,\r
- // return not found\r
- //\r
- if (Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL) {\r
- Variable.Volatile = (BOOLEAN) (Variable.Volatile ^ ((BOOLEAN) 0x1));\r
- if (Variable.Volatile) {\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
- Status = EFI_NOT_FOUND;\r
- goto Done;\r
- }\r
-\r
- Variable.CurrPtr = Variable.StartPtr;\r
- if (!IsValidVariableHeader (Variable.CurrPtr)) {\r
- continue;\r
- }\r
- }\r
- //\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
- VarNameSize = Variable.CurrPtr->NameSize;\r
- if (VarNameSize <= *VariableNameSize) {\r
- CopyMem (\r
- VariableName,\r
- GET_VARIABLE_NAME_PTR (Variable.CurrPtr),\r
- VarNameSize\r
- );\r
- CopyMem (\r
- VendorGuid,\r
- &Variable.CurrPtr->VendorGuid,\r
- sizeof (EFI_GUID)\r
- );\r
- Status = EFI_SUCCESS;\r
- } else {\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- }\r
-\r
- *VariableNameSize = VarNameSize;\r
- goto Done;\r
- }\r
- }\r
-\r
- Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
- }\r
-\r
-Done:\r
- ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data,\r
- IN VARIABLE_GLOBAL *Global,\r
- IN UINTN *VolatileOffset,\r
- IN UINTN *NonVolatileOffset,\r
- IN UINT32 Instance\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
-\r
-Returns:\r
-\r
- EFI STATUS\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
-\r
---*/\r
-{\r
- VARIABLE_POINTER_TRACK Variable;\r
- EFI_STATUS Status;\r
- VARIABLE_HEADER *NextVariable;\r
- UINTN VarNameSize;\r
- UINTN VarNameOffset;\r
- UINTN VarDataOffset;\r
- UINTN VarSize;\r
- UINT8 State;\r
- BOOLEAN Reclaimed;\r
-\r
- Reclaimed = FALSE;\r
-\r
- if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
-\r
- if (Status == EFI_INVALID_PARAMETER) {\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
- // return EFI_WRITE_PROTECTED.\r
- //\r
- Status = EFI_WRITE_PROTECTED;\r
- goto Done;\r
- } else if (sizeof (VARIABLE_HEADER) + StrSize (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
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- } else if (Attributes == EFI_VARIABLE_NON_VOLATILE) {\r
- //\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
- EFI_VARIABLE_RUNTIME_ACCESS) {\r
- //\r
- // Make sure if runtime bit is set, boot service bit is set also\r
- //\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
- //\r
- // Runtime but Attribute is not Runtime\r
- //\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
- //\r
- // Cannot set volatile variable in Runtime\r
- //\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\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
- State = Variable.CurrPtr->State;\r
- State &= VAR_DELETED;\r
-\r
- Status = UpdateVariableStore (\r
- Global,\r
- Variable.Volatile,\r
- FALSE,\r
- Instance,\r
- (UINTN) &Variable.CurrPtr->State,\r
- sizeof (UINT8),\r
- &State\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
-\r
- Status = EFI_SUCCESS;\r
- goto Done;\r
- }\r
-\r
- Status = EFI_NOT_FOUND;\r
- goto Done;\r
- } else {\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // If the variable is marked valid and the same data has been passed in\r
- // then return to the caller immediately.\r
- //\r
- if (Variable.CurrPtr->DataSize == DataSize &&\r
- !CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize)\r
- ) {\r
- Status = EFI_SUCCESS;\r
- goto Done;\r
- } else if (Variable.CurrPtr->State == VAR_ADDED) {\r
- //\r
- // Mark the old variable as in delete transition\r
- //\r
- State = Variable.CurrPtr->State;\r
- State &= VAR_IN_DELETED_TRANSITION;\r
-\r
- Status = UpdateVariableStore (\r
- Global,\r
- Variable.Volatile,\r
- FALSE,\r
- Instance,\r
- (UINTN) &Variable.CurrPtr->State,\r
- sizeof (UINT8),\r
- &State\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
- }\r
- }\r
- //\r
- // Create a new variable and copy the data.\r
- //\r
- // Tricky part: Use scratch data area at the end of volatile variable store\r
- // as a temporary storage.\r
- //\r
- NextVariable = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase));\r
-\r
- SetMem (NextVariable, SCRATCH_SIZE, 0xff);\r
-\r
- NextVariable->StartId = VARIABLE_DATA;\r
- NextVariable->Attributes = Attributes;\r
- //\r
- // NextVariable->State = VAR_ADDED;\r
- //\r
- NextVariable->Reserved = 0;\r
- VarNameOffset = sizeof (VARIABLE_HEADER);\r
- VarNameSize = StrSize (VariableName);\r
- CopyMem (\r
- (UINT8 *) ((UINTN) NextVariable + VarNameOffset),\r
- VariableName,\r
- VarNameSize\r
- );\r
- VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);\r
- CopyMem (\r
- (UINT8 *) ((UINTN) NextVariable + VarDataOffset),\r
- Data,\r
- DataSize\r
- );\r
- CopyMem (&NextVariable->VendorGuid, VendorGuid, sizeof (EFI_GUID));\r
- //\r
- // There will be pad bytes after Data, the NextVariable->NameSize and\r
- // NextVariable->DataSize should not include pad size so that variable\r
- // service can get actual size in GetVariable\r
- //\r
- NextVariable->NameSize = (UINT32)VarNameSize;\r
- NextVariable->DataSize = (UINT32)DataSize;\r
-\r
- //\r
- // The actual size of the variable that stores in storage should\r
- // include pad size.\r
- //\r
- VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);\r
- if (Attributes & EFI_VARIABLE_NON_VOLATILE) {\r
- if ((UINT32) (VarSize +*NonVolatileOffset) >\r
- ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size\r
- ) {\r
- if (EfiAtRuntime ()) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Done;\r
- }\r
- //\r
- // Perform garbage collection & reclaim operation\r
- //\r
- Status = Reclaim (Global->NonVolatileVariableBase, NonVolatileOffset, FALSE);\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
- //\r
- // If still no enough space, return out of resources\r
- //\r
- if ((UINT32) (VarSize +*NonVolatileOffset) >\r
- ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size\r
- ) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Done;\r
- }\r
-\r
- Reclaimed = TRUE;\r
- }\r
- //\r
- // Three steps\r
- // 1. Write variable header\r
- // 2. Write variable data\r
- // 3. Set variable state to valid\r
- //\r
- //\r
- // Step 1:\r
- //\r
- Status = UpdateVariableStore (\r
- Global,\r
- FALSE,\r
- TRUE,\r
- Instance,\r
- *NonVolatileOffset,\r
- sizeof (VARIABLE_HEADER),\r
- (UINT8 *) NextVariable\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
- //\r
- // Step 2:\r
- //\r
- Status = UpdateVariableStore (\r
- Global,\r
- FALSE,\r
- TRUE,\r
- Instance,\r
- *NonVolatileOffset + sizeof (VARIABLE_HEADER),\r
- (UINT32) VarSize - sizeof (VARIABLE_HEADER),\r
- (UINT8 *) NextVariable + sizeof (VARIABLE_HEADER)\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
- //\r
- // Step 3:\r
- //\r
- NextVariable->State = VAR_ADDED;\r
- Status = UpdateVariableStore (\r
- Global,\r
- FALSE,\r
- TRUE,\r
- Instance,\r
- *NonVolatileOffset,\r
- sizeof (VARIABLE_HEADER),\r
- (UINT8 *) NextVariable\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
-\r
- *NonVolatileOffset = *NonVolatileOffset + VarSize;\r
-\r
- } else {\r
- if (EfiAtRuntime ()) {\r
- Status = EFI_INVALID_PARAMETER;\r
- goto Done;\r
- }\r
-\r
- if ((UINT32) (VarSize +*VolatileOffset) >\r
- ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size\r
- ) {\r
- //\r
- // Perform garbage collection & reclaim operation\r
- //\r
- Status = Reclaim (Global->VolatileVariableBase, VolatileOffset, TRUE);\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
- //\r
- // If still no enough space, return out of resources\r
- //\r
- if ((UINT32) (VarSize +*VolatileOffset) >\r
- ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size\r
- ) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Done;\r
- }\r
-\r
- Reclaimed = TRUE;\r
- }\r
-\r
- NextVariable->State = VAR_ADDED;\r
- Status = UpdateVariableStore (\r
- Global,\r
- TRUE,\r
- TRUE,\r
- Instance,\r
- *VolatileOffset,\r
- (UINT32) VarSize,\r
- (UINT8 *) NextVariable\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
-\r
- *VolatileOffset = *VolatileOffset + VarSize;\r
- }\r
- //\r
- // Mark the old variable as deleted\r
- //\r
- if (!Reclaimed && !EFI_ERROR (Status) && Variable.CurrPtr != NULL) {\r
- State = Variable.CurrPtr->State;\r
- State &= VAR_DELETED;\r
-\r
- Status = UpdateVariableStore (\r
- Global,\r
- Variable.Volatile,\r
- FALSE,\r
- Instance,\r
- (UINTN) &Variable.CurrPtr->State,\r
- sizeof (UINT8),\r
- &State\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Done;\r
- }\r
- }\r
- }\r
-\r
- Status = EFI_SUCCESS;\r
-Done:\r
- ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
- return Status;\r
-}\r
-\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
- }\r
-\r
- AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);\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 (IsValidVariableHeader (Variable) && (Variable < GetEndPointer (VariableStoreHeader))) {\r
- NextVariable = GetNextVariablePtr (Variable);\r
- VariableSize = (UINT64) (UINTN) NextVariable - (UINT64) (UINTN) Variable;\r
-\r
- if (EfiAtRuntime ()) {\r
- //\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
- // 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
- // 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
- // Go to the next one\r
- //\r
- Variable = NextVariable;\r
- }\r
-\r
- ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\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
- CHAR8 *CurrPtr;\r
- VARIABLE_STORE_HEADER *VolatileVariableStore;\r
- VARIABLE_STORE_HEADER *VariableStoreHeader;\r
- VARIABLE_HEADER *NextVariable;\r
- UINT32 Instance;\r
- EFI_PHYSICAL_ADDRESS FvVolHdr;\r
-\r
- UINT64 TempVariableStoreHeader;\r
-\r
- EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;\r
- EFI_FLASH_SUBAREA_ENTRY VariableStoreEntry;\r
- UINT64 BaseAddress;\r
- UINT64 Length;\r
- UINTN Index;\r
- UINT8 Data;\r
-\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, TPL_NOTIFY);\r
-\r
- //\r
- // Allocate memory for volatile variable store\r
- //\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
- //\r
- // Variable Specific Data\r
- //\r
- mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VolatileVariableStore;\r
- mVariableModuleGlobal->VolatileLastVariableOffset = sizeof (VARIABLE_STORE_HEADER);\r
-\r
- VolatileVariableStore->Signature = VARIABLE_STORE_SIGNATURE;\r
- VolatileVariableStore->Size = VARIABLE_STORE_SIZE;\r
- VolatileVariableStore->Format = VARIABLE_STORE_FORMATTED;\r
- VolatileVariableStore->State = VARIABLE_STORE_HEALTHY;\r
- VolatileVariableStore->Reserved = 0;\r
- VolatileVariableStore->Reserved1 = 0;\r
-\r
- //\r
- // Get non volatile varaible store\r
- //\r
-\r
- TempVariableStoreHeader = (UINT64) PcdGet32 (PcdFlashNvStorageVariableBase);\r
- VariableStoreEntry.Base = TempVariableStoreHeader + \\r
- (((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (TempVariableStoreHeader)) -> HeaderLength);\r
- VariableStoreEntry.Length = (UINT64) PcdGet32 (PcdFlashNvStorageVariableSize) - \\r
- (((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (TempVariableStoreHeader)) -> HeaderLength);\r
- //\r
- // Mark the variable storage region of the FLASH as RUNTIME\r
- //\r
- BaseAddress = VariableStoreEntry.Base & (~EFI_PAGE_MASK);\r
- Length = VariableStoreEntry.Length + (VariableStoreEntry.Base - BaseAddress);\r
- Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);\r
-\r
- Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
- if (EFI_ERROR (Status)) {\r
- FreePool (mVariableModuleGlobal);\r
- FreePool (VolatileVariableStore);\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- Status = gDS->SetMemorySpaceAttributes (\r
- BaseAddress,\r
- Length,\r
- GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
- );\r
- if (EFI_ERROR (Status)) {\r
- FreePool (mVariableModuleGlobal);\r
- FreePool (VolatileVariableStore);\r
- return EFI_UNSUPPORTED;\r
- }\r
- //\r
- // Get address of non volatile variable store base\r
- //\r
- mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase = VariableStoreEntry.Base;\r
-\r
- //\r
- // Check Integrity\r
- //\r
- //\r
- // Find the Correct Instance of the FV Block Service.\r
- //\r
- Instance = 0;\r
- CurrPtr = (CHAR8 *) ((UINTN) mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase);\r
- while (EfiFvbGetPhysicalAddress (Instance, &FvVolHdr) == EFI_SUCCESS) {\r
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);\r
- if (CurrPtr >= (CHAR8 *) FwVolHeader && CurrPtr < (((CHAR8 *) FwVolHeader) + FwVolHeader->FvLength)) {\r
- mVariableModuleGlobal->FvbInstance = Instance;\r
- break;\r
- }\r
-\r
- Instance++;\r
- }\r
-\r
- VariableStoreHeader = (VARIABLE_STORE_HEADER *) CurrPtr;\r
- if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {\r
- if (~VariableStoreHeader->Size == 0) {\r
- Status = UpdateVariableStore (\r
- &mVariableModuleGlobal->VariableGlobal[Physical],\r
- FALSE,\r
- FALSE,\r
- mVariableModuleGlobal->FvbInstance,\r
- (UINTN) &VariableStoreHeader->Size,\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
-\r
- mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase = (EFI_PHYSICAL_ADDRESS) ((UINTN) CurrPtr);\r
- //\r
- // Parse non-volatile variable data and get last variable offset\r
- //\r
- NextVariable = (VARIABLE_HEADER *) (CurrPtr + sizeof (VARIABLE_STORE_HEADER));\r
- Status = EFI_SUCCESS;\r
-\r
- while (IsValidVariableHeader (NextVariable)) {\r
- NextVariable = GetNextVariablePtr (NextVariable);\r
- }\r
-\r
- mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) CurrPtr;\r
-\r
- //\r
- // Check if the free area is blow a threshold\r
- //\r
- if ((((VARIABLE_STORE_HEADER *)((UINTN) CurrPtr))->Size - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {\r
- Status = Reclaim (\r
- mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,\r
- &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
- FALSE\r
- );\r
- }\r
-\r
- if (EFI_ERROR (Status)) {\r
- FreePool (mVariableModuleGlobal);\r
- FreePool (VolatileVariableStore);\r
- return Status;\r
- }\r
-\r
- //\r
- // Check if the free area is really free.\r
- //\r
- for (Index = mVariableModuleGlobal->NonVolatileLastVariableOffset; Index < VariableStoreHeader->Size; Index++) {\r
- Data = ((UINT8 *) (UINTN) mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase)[Index];\r
- if (Data != 0xff) {\r
- //\r
- // There must be something wrong in variable store, do reclaim operation.\r
- //\r
- Status = Reclaim (\r
- mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,\r
- &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
- FALSE\r
- );\r
- break;\r
- }\r
- }\r
- }\r
-\r
- if (EFI_ERROR (Status)) {\r
- FreePool (mVariableModuleGlobal);\r
- FreePool (VolatileVariableStore);\r
- }\r
-\r
- return Status;\r
-}\r
+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- Variable.h\r
-\r
-Abstract:\r
-\r
---*/\r
-\r
-#ifndef _VARIABLE_H\r
-#define _VARIABLE_H\r
-\r
-#include <PiDxe.h>\r
-#include <Protocol/VariableWrite.h>\r
-#include <Protocol/FaultTolerantWriteLite.h>\r
-#include <Protocol/FirmwareVolumeBlock.h>\r
-#include <Protocol/Variable.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/DxeServicesTableLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/FvbServiceLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/HobLib.h>\r
-#include <Common/FlashMap.h>\r
-#include <Guid/FlashMapHob.h>\r
-\r
-//\r
-// BugBug: We need relcate the head file.\r
-//\r
-#include <Common/Variable.h>\r
-\r
-#define VARIABLE_RECLAIM_THRESHOLD (1024)\r
-\r
-#define VARIABLE_STORE_SIZE (64 * 1024)\r
-#define SCRATCH_SIZE (4 * 1024)\r
-\r
-//\r
-// Define GET_PAD_SIZE to optimize compiler\r
-//\r
-#if ((ALIGNMENT == 0) || (ALIGNMENT == 1))\r
-#define GET_PAD_SIZE(a) (0)\r
-#else\r
-#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))\r
-#endif\r
-\r
-#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))\r
-\r
-typedef enum {\r
- Physical,\r
- Virtual\r
-} VARIABLE_POINTER_TYPE;\r
-\r
-typedef struct {\r
- VARIABLE_HEADER *CurrPtr;\r
- VARIABLE_HEADER *EndPtr;\r
- VARIABLE_HEADER *StartPtr;\r
- BOOLEAN Volatile;\r
-} VARIABLE_POINTER_TRACK;\r
-\r
-typedef struct {\r
- EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r
- EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r
- EFI_LOCK VariableServicesLock;\r
-} VARIABLE_GLOBAL;\r
-\r
-typedef struct {\r
- VARIABLE_GLOBAL VariableGlobal[2];\r
- UINTN VolatileLastVariableOffset;\r
- UINTN NonVolatileLastVariableOffset;\r
- UINT32 FvbInstance;\r
-} ESAL_VARIABLE_GLOBAL;\r
-\r
-extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
-\r
-//\r
-// Functions\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-VariableCommonInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-VariableServiceInitialize (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- );\r
-\r
-VOID\r
-EFIAPI\r
-VariableClassAddressChangeEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-GetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID * VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data,\r
- IN VARIABLE_GLOBAL * Global,\r
- IN UINT32 Instance\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-GetNextVariableName (\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VendorGuid,\r
- IN VARIABLE_GLOBAL *Global,\r
- IN UINT32 Instance\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data,\r
- IN VARIABLE_GLOBAL *Global,\r
- IN UINTN *VolatileOffset,\r
- IN UINTN *NonVolatileOffset,\r
- IN UINT32 Instance\r
- );\r
-\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
-EFI_STATUS\r
-GetFvbHandleByAddress (\r
- IN EFI_PHYSICAL_ADDRESS VariableStoreBase,\r
- OUT EFI_HANDLE *FvbHandle\r
- );\r
-\r
-EFI_STATUS\r
-FtwVariableSpace (\r
- IN EFI_PHYSICAL_ADDRESS VariableBaseAddress,\r
- IN UINT8 *Buffer,\r
- IN UINTN BufferSize\r
- );\r
-\r
-#endif\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
- <MsaHeader>\r
- <ModuleName>Variable</ModuleName>\r
- <ModuleType>DXE_RUNTIME_DRIVER</ModuleType>\r
- <GuidValue>CBD2E4D5-7068-4FF5-B462-9822B4AD8D60</GuidValue>\r
- <Version>1.0</Version>\r
- <Abstract>Component description file for Variable module.</Abstract>\r
- <Description>This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.</Description>\r
- <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
- <License>All rights reserved. This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
- <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
- </MsaHeader>\r
- <ModuleDefinitions>\r
- <SupportedArchitectures>IA32 X64</SupportedArchitectures>\r
- <BinaryModule>false</BinaryModule>\r
- <OutputFileBasename>Variable</OutputFileBasename>\r
- </ModuleDefinitions>\r
- <LibraryClassDefinitions>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>PcdLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiDriverEntryPoint</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>DxeServicesTableLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiRuntimeLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>DebugLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>BaseMemoryLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>EdkFvbServiceLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiBootServicesTableLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>UefiLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>BaseLib</Keyword>\r
- </LibraryClass>\r
- <LibraryClass Usage="ALWAYS_CONSUMED">\r
- <Keyword>MemoryAllocationLib</Keyword>\r
- </LibraryClass>\r
- </LibraryClassDefinitions>\r
- <SourceFiles>\r
- <Filename>Variable.h</Filename>\r
- <Filename>Variable.c</Filename>\r
- <Filename>reclaim.h</Filename>\r
- <Filename>reclaim.c</Filename>\r
- <Filename>InitVariable.c</Filename>\r
- <Filename>Variable.dxs</Filename>\r
- </SourceFiles>\r
- <PackageDependencies>\r
- <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
- <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
- </PackageDependencies>\r
- <Protocols>\r
- <Protocol Usage="ALWAYS_PRODUCED">\r
- <ProtocolCName>gEfiVariableArchProtocolGuid</ProtocolCName>\r
- </Protocol>\r
- <Protocol Usage="ALWAYS_PRODUCED">\r
- <ProtocolCName>gEfiVariableWriteArchProtocolGuid</ProtocolCName>\r
- </Protocol>\r
- <Protocol Usage="SOMETIMES_CONSUMED">\r
- <ProtocolCName>gEfiFaultTolerantWriteLiteProtocolGuid</ProtocolCName>\r
- </Protocol>\r
- <Protocol Usage="SOMETIMES_CONSUMED">\r
- <ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>\r
- </Protocol>\r
- </Protocols>\r
- <Externs>\r
- <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
- <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
- <Extern>\r
- <ModuleEntryPoint>VariableServiceInitialize</ModuleEntryPoint>\r
- </Extern>\r
- <Extern>\r
- <SetVirtualAddressMapCallBack>VariableClassAddressChangeEvent</SetVirtualAddressMapCallBack>\r
- </Extern>\r
- </Externs>\r
- <PcdCoded>\r
- <PcdEntry PcdItemType="DYNAMIC">\r
- <C_Name>PcdFlashNvStorageVariableBase</C_Name>\r
- <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
- <HelpText>The driver gets the Variable store base address from this PCD. This base address point to
- an EFI_FIRMWARE_VOLUMN_HEADER struct.</HelpText>\r
- </PcdEntry>\r
- <PcdEntry PcdItemType="DYNAMIC">\r
- <C_Name>PcdFlashNvStorageVariableSize</C_Name>\r
- <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
- <HelpText>The driver gets the NvStorage Variable Size from this PCD.</HelpText>\r
- </PcdEntry>\r
- </PcdCoded>\r
-</ModuleSurfaceArea>
\ No newline at end of file
+++ /dev/null
-#/** @file\r
-# Component description file for Variable module.\r
-#\r
-# This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.\r
-# Copyright (c) 2006 - 2007, Intel Corporation\r
-#\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
-# 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
-\r
-[Defines]\r
- INF_VERSION = 0x00010005\r
- BASE_NAME = VariableRuntimeDxe\r
- FILE_GUID = CBD2E4D5-7068-4FF5-B462-9822B4AD8D60\r
- MODULE_TYPE = DXE_RUNTIME_DRIVER\r
- VERSION_STRING = 1.0\r
- EDK_RELEASE_VERSION = 0x00020000\r
- EFI_SPECIFICATION_VERSION = 0x00020000\r
-\r
- ENTRY_POINT = VariableServiceInitialize\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-# VALID_ARCHITECTURES = IA32 X64\r
-#\r
-# VIRTUAL_ADDRESS_MAP_CALLBACK = VariableClassAddressChangeEvent\r
-#\r
-\r
-[Sources.common]\r
- InitVariable.c\r
- reclaim.c\r
- Variable.c\r
- Variable.h\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
-\r
-[LibraryClasses]\r
- MemoryAllocationLib\r
- BaseLib\r
- UefiLib\r
- UefiBootServicesTableLib\r
- FvbServiceLib\r
- BaseMemoryLib\r
- DebugLib\r
- UefiRuntimeLib\r
- DxeServicesTableLib\r
- UefiDriverEntryPoint\r
- PcdLib\r
- HobLib\r
-\r
-[Guids]\r
- gEfiFlashMapHobGuid\r
-\r
-[Protocols]\r
- gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL SOMETIMES_CONSUMED\r
- gEfiFaultTolerantWriteLiteProtocolGuid # PROTOCOL SOMETIMES_CONSUMED\r
- gEfiVariableWriteArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
- gEfiVariableArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
-\r
-[PcdsDynamic.common]\r
- PcdFlashNvStorageVariableSize|gEfiMdeModulePkgTokenSpaceGuid\r
- PcdFlashNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid\r
-\r
-[Depex]\r
- gEfiFirmwareVolumeBlockProtocolGuid AND gEfiAlternateFvBlockGuid AND gEfiFaultTolerantWriteLiteProtocolGuid\r
-\r
+++ /dev/null
-/*++\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
-\r
-Module Name:\r
-\r
- reclaim.c\r
-\r
-Abstract:\r
-\r
- Handles non-volatile variable store garbage collection, using FTW\r
- (Fault Tolerant Write) protocol.\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-\r
-#include <Variable.h>\r
-#include "Common/Variable.h"\r
-\r
-EFI_STATUS\r
-GetFvbHandleByAddress (\r
- IN EFI_PHYSICAL_ADDRESS Address,\r
- OUT EFI_HANDLE *FvbHandle\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE *HandleBuffer;\r
- UINTN HandleCount;\r
- UINTN Index;\r
- EFI_PHYSICAL_ADDRESS FvbBaseAddress;\r
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;\r
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
-\r
- *FvbHandle = NULL;\r
- //\r
- // Locate all handles of Fvb protocol\r
- //\r
- Status = gBS->LocateHandleBuffer (\r
- ByProtocol,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- NULL,\r
- &HandleCount,\r
- &HandleBuffer\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return EFI_NOT_FOUND;\r
- }\r
- //\r
- // Get the FVB to access variable store\r
- //\r
- for (Index = 0; Index < HandleCount; Index += 1) {\r
- Status = gBS->HandleProtocol (\r
- HandleBuffer[Index],\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- (VOID **) &Fvb\r
- );\r
- if (EFI_ERROR (Status)) {\r
- Status = EFI_NOT_FOUND;\r
- break;\r
- }\r
- //\r
- // Compare the address and select the right one\r
- //\r
- Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);\r
- if (EFI_ERROR (Status)) {\r
- continue;\r
- }\r
-\r
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvbBaseAddress);\r
- if ((Address >= FvbBaseAddress) && (Address <= (FvbBaseAddress + FwVolHeader->FvLength))) {\r
- *FvbHandle = HandleBuffer[Index];\r
- Status = EFI_SUCCESS;\r
- break;\r
- }\r
- }\r
-\r
- FreePool (HandleBuffer);\r
- return Status;\r
-}\r
-\r
-STATIC\r
-EFI_STATUS\r
-GetLbaAndOffsetByAddress (\r
- IN EFI_PHYSICAL_ADDRESS Address,\r
- OUT EFI_LBA *Lba,\r
- OUT UINTN *Offset\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE FvbHandle;\r
- EFI_PHYSICAL_ADDRESS FvbBaseAddress;\r
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;\r
- EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
- EFI_FV_BLOCK_MAP_ENTRY *FvbMapEntry;\r
- UINT32 LbaIndex;\r
-\r
- *Lba = (EFI_LBA) (-1);\r
- *Offset = 0;\r
-\r
- //\r
- // Get the proper FVB\r
- //\r
- Status = GetFvbHandleByAddress (Address, &FvbHandle);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Status = gBS->HandleProtocol (\r
- FvbHandle,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- (VOID **) &Fvb\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- //\r
- // Get the Base Address of FV\r
- //\r
- Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvbBaseAddress);\r
-\r
- //\r
- // Get the (LBA, Offset) of Address\r
- //\r
- if ((Address >= FvbBaseAddress) && (Address <= (FvbBaseAddress + FwVolHeader->FvLength))) {\r
- if ((FwVolHeader->FvLength) > (FwVolHeader->HeaderLength)) {\r
- //\r
- // BUGBUG: Assume one FV has one type of BlockLength\r
- //\r
- FvbMapEntry = &FwVolHeader->BlockMap[0];\r
- for (LbaIndex = 1; LbaIndex <= FvbMapEntry->NumBlocks; LbaIndex += 1) {\r
- if (Address < (FvbBaseAddress + FvbMapEntry->Length * LbaIndex)) {\r
- //\r
- // Found the (Lba, Offset)\r
- //\r
- *Lba = LbaIndex - 1;\r
- *Offset = (UINTN) (Address - (FvbBaseAddress + FvbMapEntry->Length * (LbaIndex - 1)));\r
- return EFI_SUCCESS;\r
- }\r
- }\r
- }\r
- }\r
-\r
- return EFI_ABORTED;\r
-}\r
-\r
-EFI_STATUS\r
-FtwVariableSpace (\r
- IN EFI_PHYSICAL_ADDRESS VariableBase,\r
- IN UINT8 *Buffer,\r
- IN UINTN BufferSize\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Write a buffer to Variable space, in the working block.\r
-\r
-Arguments:\r
- FvbHandle - Indicates a handle to FVB to access variable store\r
- Buffer - Point to the input buffer\r
- BufferSize - The number of bytes of the input Buffer\r
-\r
-Returns:\r
- EFI_SUCCESS - The function completed successfully\r
- EFI_ABORTED - The function could not complete successfully\r
- EFI_NOT_FOUND - Locate FVB protocol by handle fails\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE FvbHandle;\r
- EFI_FTW_LITE_PROTOCOL *FtwLiteProtocol;\r
- EFI_LBA VarLba;\r
- UINTN VarOffset;\r
- UINT8 *FtwBuffer;\r
- UINTN FtwBufferSize;\r
-\r
- //\r
- // Locate fault tolerant write protocol\r
- //\r
- Status = gBS->LocateProtocol (\r
- &gEfiFaultTolerantWriteLiteProtocolGuid,\r
- NULL,\r
- (VOID **) &FtwLiteProtocol\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return EFI_NOT_FOUND;\r
- }\r
- //\r
- // Locate Fvb handle by address\r
- //\r
- Status = GetFvbHandleByAddress (VariableBase, &FvbHandle);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- //\r
- // Get LBA and Offset by address\r
- //\r
- Status = GetLbaAndOffsetByAddress (VariableBase, &VarLba, &VarOffset);\r
- if (EFI_ERROR (Status)) {\r
- return EFI_ABORTED;\r
- }\r
- //\r
- // Prepare for the variable data\r
- //\r
- FtwBufferSize = ((VARIABLE_STORE_HEADER *) ((UINTN) VariableBase))->Size;\r
- FtwBuffer = AllocateRuntimePool (FtwBufferSize);\r
- if (FtwBuffer == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- SetMem (FtwBuffer, FtwBufferSize, (UINT8) 0xff);\r
- CopyMem (FtwBuffer, Buffer, BufferSize);\r
-\r
- //\r
- // FTW write record\r
- //\r
- Status = FtwLiteProtocol->Write (\r
- FtwLiteProtocol,\r
- FvbHandle,\r
- VarLba, // LBA\r
- VarOffset, // Offset\r
- &FtwBufferSize, // NumBytes,\r
- FtwBuffer\r
- );\r
-\r
- FreePool (FtwBuffer);\r
- return Status;\r
-}\r