X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=IntelFrameworkModulePkg%2FUniversal%2FVariablePei%2FVariable.c;h=f57e2002e262af50ea6d43e8f4a107ff0205e67c;hp=e050fbcf9d3f3edea3a43744ee5a813e370f0082;hb=bcd70414877e56f3bffff0bf11b07a30ef51a68f;hpb=9cad030bc14e706d8986ed33f0fa8b28f0828c48 diff --git a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c index e050fbcf9d..f57e2002e2 100644 --- a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c +++ b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c @@ -1,6 +1,7 @@ -/*++ - -Copyright (c) 2006 - 2007 Intel Corporation.
+/** @file + Framework PEIM to provide the Variable functionality + +Copyright (c) 2006 - 2008 Intel Corporation.
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 @@ -10,13 +11,7 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: - Variable.c - -Abstract: - - Framework PEIM to provide the Variable functionality - ---*/ +**/ #include "Variable.h" @@ -49,164 +44,227 @@ static EFI_PEI_PPI_DESCRIPTOR mPpiListVariable[] = { EFI_GUID mEfiVariableIndexTableGuid = EFI_VARIABLE_INDEX_TABLE_GUID; +/** + Provide the functionality of the variable services. + + @param FfsHeadher - The FFS file header + @param PeiServices - General purpose services available to every PEIM. + + @return Status - EFI_SUCCESS if the interface could be successfully + installed + +**/ EFI_STATUS EFIAPI PeimInitializeVariableServices ( IN EFI_FFS_FILE_HEADER *FfsHeader, IN EFI_PEI_SERVICES **PeiServices ) -/*++ +{ + // + // Publish the variable capability to other modules + // + return (**PeiServices).InstallPpi ((CONST EFI_PEI_SERVICES **) PeiServices, &mPpiListVariable[0]); + +} -Routine Description: +/** + This code gets the pointer to the first variable memory pointer byte - Provide the functionality of the variable services. + @param VarStoreHeader Pointer to the Variable Store Header. + + @Return VARIABLE_HEADER* Pointer to last unavailable Variable Header + +**/ +VARIABLE_HEADER * +GetStartPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +{ + // + // The end of variable store + // + return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); +} -Arguments: +/** + This code gets the pointer to the last variable memory pointer byte - FfsHeadher - The FFS file header - PeiServices - General purpose services available to every PEIM. + @param VarStoreHeader Pointer to the Variable Store Header. -Returns: + @Return VARIABLE_HEADER* Pointer to last unavailable Variable Header - Status - EFI_SUCCESS if the interface could be successfully - installed +**/ +VARIABLE_HEADER * +GetEndPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) ---*/ { // - // Publish the variable capability to other modules + // The end of variable store // - return (**PeiServices).InstallPpi ((CONST EFI_PEI_SERVICES **) PeiServices, &mPpiListVariable[0]); - + return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size); } +/** -UINT32 -NameSizeOfVariable ( + This code checks if variable header is valid or not. + + @param Variable Pointer to the Variable Header. + + @retval TRUE Variable header is valid. + @retval FALSE Variable header is not valid. + +**/ +STATIC +BOOLEAN +EFIAPI +IsValidVariableHeader ( IN VARIABLE_HEADER *Variable ) { - // - // Check whether the header is valid fully; - // Tricky: The unprogramed data in FLASH equals 0xff. - // - if (Variable->DataSize == (UINT32) -1 || - Variable->Attributes == (UINT32) -1 || - Variable->NameSize == (UINT32) -1) { - return 0; + if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) { + return FALSE; } - return Variable->NameSize; + + return TRUE; } -UINT32 -DataSizeOfVariable ( +/** + This code gets the size of name of variable. + + @param Variable Pointer to the Variable Header. + + @Return UINTN Size of variable in bytes + +**/ +UINTN +NameSizeOfVariable ( IN VARIABLE_HEADER *Variable ) { - // - // Check whether the header is valid fully; - // Tricky: The unprogramed data in FLASH equals 0xff. - // - if (Variable->DataSize == (UINT32) -1 || - Variable->Attributes == (UINT32) -1 || - Variable->NameSize == (UINT32) -1) { + if (Variable->State == (UINT8) (-1) || + Variable->DataSize == (UINT32) -1 || + Variable->NameSize == (UINT32) -1 || + Variable->Attributes == (UINT32) -1) { return 0; } - return Variable->DataSize; + return (UINTN) Variable->NameSize; } -UINT32 -AttributesOfVariable ( +/** + This code gets the size of name of variable. + + @param Variable Pointer to the Variable Header. + + @Return UINTN Size of variable in bytes + +**/ +UINTN +DataSizeOfVariable ( IN VARIABLE_HEADER *Variable ) { - - // - // Check whether the header is valid fully; - // Tricky: The unprogramed data in FLASH equals 0xff. - // - if (Variable->DataSize == (UINT32) -1 || - Variable->Attributes == (UINT32) -1 || - Variable->NameSize == (UINT32) -1) { + if (Variable->State == (UINT8) -1 || + Variable->DataSize == (UINT32) -1 || + Variable->NameSize == (UINT32) -1 || + Variable->Attributes == (UINT32) -1) { return 0; } - return Variable->Attributes; + return (UINTN) Variable->DataSize; } -STATIC -VARIABLE_HEADER * -GetNextVariablePtr ( - IN VARIABLE_HEADER *Variable - ) -/*++ - -Routine Description: +/** + This code gets the pointer to the variable name. - This code checks if variable header is valid or not. + @param Variable Pointer to the Variable Header. -Arguments: - Variable Pointer to the Variable Header. + @Return CHAR16* Pointer to Variable Name -Returns: - TRUE Variable header is valid. - FALSE Variable header is not valid. +**/ +CHAR16 * +GetVariableNamePtr ( + IN VARIABLE_HEADER *Variable + ) ---*/ { - return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + DataSizeOfVariable (Variable) + GET_PAD_SIZE (DataSizeOfVariable (Variable))); + + return (CHAR16 *) (Variable + 1); } -STATIC -BOOLEAN -EFIAPI -IsValidVariableHeader ( +/** + This code gets the pointer to the variable data. + + @param Variable Pointer to the Variable Header. + + @Return UINT8* Pointer to Variable Data + +**/ +UINT8 * +GetVariableDataPtr ( IN VARIABLE_HEADER *Variable ) -/*++ +{ + UINTN Value; + + // + // Be careful about pad size for alignment + // + Value = (UINTN) GetVariableNamePtr (Variable); + Value += NameSizeOfVariable (Variable); + Value += GET_PAD_SIZE (NameSizeOfVariable (Variable)); -Routine Description: + return (UINT8 *) Value; +} - This code checks if variable header is valid or not. +/** + This code gets the pointer to the next variable header. -Arguments: - Variable Pointer to the Variable Header. + @param Variable Pointer to the Variable Header. -Returns: - TRUE Variable header is valid. - FALSE Variable header is not valid. + @Return VARIABLE_HEADER* Pointer to next variable header. + +**/ +VARIABLE_HEADER * +GetNextVariablePtr ( + IN VARIABLE_HEADER *Variable + ) ---*/ { - if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) { - return FALSE; + UINTN Value; + + if (!IsValidVariableHeader (Variable)) { + return NULL; } - return TRUE; + Value = (UINTN) GetVariableDataPtr (Variable); + Value += DataSizeOfVariable (Variable); + Value += GET_PAD_SIZE (DataSizeOfVariable (Variable)); + + // + // Be careful about pad size for alignment + // + return (VARIABLE_HEADER *) HEADER_ALIGN (Value); } +/** + This code gets the pointer to the variable name. + + @param VarStoreHeader Pointer to the Variable Store Header. + + @retval EfiRaw Variable store is raw + @retval EfiValid Variable store is valid + @retval EfiInvalid Variable store is invalid + +**/ STATIC VARIABLE_STORE_STATUS EFIAPI GetVariableStoreStatus ( IN VARIABLE_STORE_HEADER *VarStoreHeader ) -/*++ - -Routine Description: - This code gets the pointer to the variable name. - -Arguments: - - VarStoreHeader Pointer to the Variable Store Header. - -Returns: - - EfiRaw Variable store is raw - EfiValid Variable store is valid - EfiInvalid Variable store is invalid - ---*/ { if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE && VarStoreHeader->Format == VARIABLE_STORE_FORMATTED && @@ -228,6 +286,19 @@ Returns: } } +/** + This function compares a variable with variable entries in database + + @param Variable - Pointer to the variable in our database + @param VariableName - Name of the variable to compare to 'Variable' + @param VendorGuid - GUID of the variable to compare to 'Variable' + @param PtrTrack - Variable Track Pointer structure that contains + Variable Information. + + @Retval EFI_SUCCESS - Found match variable + @retval EFI_NOT_FOUND - Variable not found + +**/ STATIC EFI_STATUS CompareWithValidVariable ( @@ -236,27 +307,10 @@ CompareWithValidVariable ( IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack ) -/*++ - -Routine Description: - - This function compares a variable with variable entries in database - -Arguments: - - Variable - Pointer to the variable in our database - VariableName - Name of the variable to compare to 'Variable' - VendorGuid - GUID of the variable to compare to 'Variable' - PtrTrack - Variable Track Pointer structure that contains - Variable Information. -Returns: - - EFI_SUCCESS - Found match variable - EFI_NOT_FOUND - Variable not found - ---*/ { + VOID *Point; + if (VariableName[0] == 0) { PtrTrack->CurrPtr = Variable; return EFI_SUCCESS; @@ -272,7 +326,8 @@ Returns: (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3]) ) { ASSERT (NameSizeOfVariable (Variable) != 0); - if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), NameSizeOfVariable (Variable))) { + Point = (VOID *) GetVariableNamePtr (Variable); + if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable))) { PtrTrack->CurrPtr = Variable; return EFI_SUCCESS; } @@ -282,6 +337,20 @@ Returns: return EFI_NOT_FOUND; } +/** + This code finds variable in storage blocks (Non-Volatile) + + @param PeiServices - General purpose services available to every PEIM. + @param VariableName - Name of the variable to be found + @param VendorGuid - Vendor GUID to be found. + @param PtrTrack - Variable Track Pointer structure that contains + Variable Information. + + @retval EFI_SUCCESS - Variable found successfully + @retval EFI_NOT_FOUND - Variable not found + @retval EFI_INVALID_PARAMETER - Invalid variable name + +**/ STATIC EFI_STATUS EFIAPI @@ -291,27 +360,7 @@ FindVariable ( IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack ) -/*++ - -Routine Description: - - This code finds variable in storage blocks (Non-Volatile) - -Arguments: - - PeiServices - General purpose services available to every PEIM. - VariableName - Name of the variable to be found - VendorGuid - Vendor GUID to be found. - PtrTrack - Variable Track Pointer structure that contains - Variable Information. -Returns: - - EFI_SUCCESS - Variable found successfully - EFI_NOT_FOUND - Variable not found - EFI_INVALID_PARAMETER - Invalid variable name - ---*/ { EFI_HOB_GUID_TYPE *GuidHob; VARIABLE_STORE_HEADER *VariableStoreHeader; @@ -341,6 +390,7 @@ Returns: for (Count = 0; Count < IndexTable->Length; Count++) { MaxIndex = GetVariableByIndex (IndexTable, Count); + if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) { PtrTrack->StartPtr = IndexTable->StartPtr; PtrTrack->EndPtr = IndexTable->EndPtr; @@ -376,8 +426,8 @@ Returns: // // Find the variable by walk through non-volatile variable store // - IndexTable->StartPtr = (VARIABLE_HEADER *) (VariableStoreHeader + 1); - IndexTable->EndPtr = (VARIABLE_HEADER *) ((UINTN) VariableStoreHeader + VariableStoreHeader->Size); + IndexTable->StartPtr = GetStartPointer (VariableStoreHeader); + IndexTable->EndPtr = GetEndPointer (VariableStoreHeader); // // Start Pointers for the variable. @@ -421,51 +471,45 @@ Returns: return EFI_NOT_FOUND; } -EFI_STATUS -EFIAPI -PeiGetVariable ( - IN EFI_PEI_SERVICES **PeiServices, - IN CHAR16 *VariableName, - IN EFI_GUID * VendorGuid, - OUT UINT32 *Attributes OPTIONAL, - IN OUT UINTN *DataSize, - OUT VOID *Data - ) -/*++ - -Routine Description: - +/** Provide the read variable functionality of the variable services. -Arguments: - - PeiServices - General purpose services available to every PEIM. + @param PeiServices - General purpose services available to every PEIM. - VariableName - The variable name + @param VariableName - The variable name - VendorGuid - The vendor's GUID + @param VendorGuid - The vendor's GUID - Attributes - Pointer to the attribute + @param Attributes - Pointer to the attribute - DataSize - Size of data + @param DataSize - Size of data - Data - Pointer to data + @param Data - Pointer to data -Returns: + @retval EFI_SUCCESS - The interface could be successfully installed - EFI_SUCCESS - The interface could be successfully installed + @retval EFI_NOT_FOUND - The variable could not be discovered - EFI_NOT_FOUND - The variable could not be discovered + @retval EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough - EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough +**/ +EFI_STATUS +EFIAPI +PeiGetVariable ( + IN EFI_PEI_SERVICES **PeiServices, + IN CHAR16 *VariableName, + IN EFI_GUID * VendorGuid, + OUT UINT32 *Attributes OPTIONAL, + IN OUT UINTN *DataSize, + OUT VOID *Data + ) ---*/ { VARIABLE_POINTER_TRACK Variable; UINTN VarDataSize; EFI_STATUS Status; - if (VariableName == NULL || VendorGuid == NULL) { + if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) { return EFI_INVALID_PARAMETER; } // @@ -481,7 +525,14 @@ Returns: // VarDataSize = DataSizeOfVariable (Variable.CurrPtr); if (*DataSize >= VarDataSize) { - (*PeiServices)->CopyMem (Data, GET_VARIABLE_DATA_PTR (Variable.CurrPtr), VarDataSize); + // + // PO-TKW: Address one checking in this place + // + if (Data == NULL) { + return EFI_INVALID_PARAMETER; + } + + (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize); if (Attributes != NULL) { *Attributes = Variable.CurrPtr->Attributes; @@ -495,46 +546,39 @@ Returns: } } - -EFI_STATUS -EFIAPI -PeiGetVariable2 ( - IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, - IN CONST CHAR16 *VariableName, - IN CONST EFI_GUID *VariableGuid, - OUT UINT32 *Attributes, - IN OUT UINTN *DataSize, - OUT VOID *Data - ) -/*++ - -Routine Description: - +/** Provide the read variable functionality of the variable services. -Arguments: - - PeiServices - General purpose services available to every PEIM. + @param PeiServices - General purpose services available to every PEIM. - VariableName - The variable name + @param VariableName - The variable name - VendorGuid - The vendor's GUID + @param VendorGuid - The vendor's GUID - Attributes - Pointer to the attribute + @param Attributes - Pointer to the attribute - DataSize - Size of data + @param DataSize - Size of data - Data - Pointer to data + @param Data - Pointer to data -Returns: + @retval EFI_SUCCESS - The interface could be successfully installed - EFI_SUCCESS - The interface could be successfully installed + @retval EFI_NOT_FOUND - The variable could not be discovered - EFI_NOT_FOUND - The variable could not be discovered + @retval EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough - EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough +**/ +EFI_STATUS +EFIAPI +PeiGetVariable2 ( + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VariableGuid, + OUT UINT32 *Attributes, + IN OUT UINTN *DataSize, + OUT VOID *Data + ) ---*/ { return PeiGetVariable ( GetPeiServicesTablePointer (), @@ -546,46 +590,40 @@ Returns: ); } -EFI_STATUS -EFIAPI -PeiGetNextVariableName ( - IN EFI_PEI_SERVICES **PeiServices, - IN OUT UINTN *VariableNameSize, - IN OUT CHAR16 *VariableName, - IN OUT EFI_GUID *VendorGuid - ) -/*++ - -Routine Description: - +/** Provide the get next variable functionality of the variable services. -Arguments: - - PeiServices - General purpose services available to every PEIM. - VariabvleNameSize - The variable name's size. - VariableName - A pointer to the variable's name. - VendorGuid - A pointer to the EFI_GUID structure. + @param PeiServices - General purpose services available to every PEIM. + @param VariabvleNameSize - The variable name's size. + @param VariableName - A pointer to the variable's name. + @param VendorGuid - A pointer to the EFI_GUID structure. - VariableNameSize - Size of the variable name + @param VariableNameSize - Size of the variable name - VariableName - The variable name + @param VariableName - The variable name - VendorGuid - The vendor's GUID + @param VendorGuid - The vendor's GUID -Returns: + @retval EFI_SUCCESS - The interface could be successfully installed - EFI_SUCCESS - The interface could be successfully installed + @retval EFI_NOT_FOUND - The variable could not be discovered - EFI_NOT_FOUND - The variable could not be discovered +**/ +EFI_STATUS +EFIAPI +PeiGetNextVariableName ( + IN EFI_PEI_SERVICES **PeiServices, + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) ---*/ { VARIABLE_POINTER_TRACK Variable; UINTN VarNameSize; EFI_STATUS Status; - if (VariableName == NULL) { + if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) { return EFI_INVALID_PARAMETER; } @@ -609,7 +647,7 @@ Returns: VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr); if (VarNameSize <= *VariableNameSize) { - (*PeiServices)->CopyMem (VariableName, GET_VARIABLE_NAME_PTR (Variable.CurrPtr), VarNameSize); + (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize); (*PeiServices)->CopyMem (VendorGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID)); @@ -634,40 +672,35 @@ Returns: return EFI_NOT_FOUND; } -EFI_STATUS -EFIAPI -PeiGetNextVariableName2 ( - IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, - IN OUT UINTN *VariableNameSize, - IN OUT CHAR16 *VariableName, - IN OUT EFI_GUID *VariableGuid - ) -/*++ - -Routine Description: - +/** Provide the get next variable functionality of the variable services. -Arguments: + @param PeiServices - General purpose services available to every PEIM. + @param VariabvleNameSize - The variable name's size. + @param VariableName - A pointer to the variable's name. + @param VariableGuid - A pointer to the EFI_GUID structure. - PeiServices - General purpose services available to every PEIM. - VariabvleNameSize - The variable name's size. - VariableName - A pointer to the variable's name. - VariableGuid - A pointer to the EFI_GUID structure. + @param VariableNameSize - Size of the variable name - VariableNameSize - Size of the variable name + @param VariableName - The variable name - VariableName - The variable name + @param VendorGuid - The vendor's GUID - VendorGuid - The vendor's GUID -Returns: + @retval EFI_SUCCESS - The interface could be successfully installed - EFI_SUCCESS - The interface could be successfully installed + @retval EFI_NOT_FOUND - The variable could not be discovered - EFI_NOT_FOUND - The variable could not be discovered +**/ +EFI_STATUS +EFIAPI +PeiGetNextVariableName2 ( + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VariableGuid + ) ---*/ { return PeiGetNextVariableName ( GetPeiServicesTablePointer (), @@ -676,3 +709,4 @@ Returns: VariableGuid ); } +