-/** @file PCD PEIM\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
+/** @file \r
+ All Pcd Ppi services are implemented here.\r
+ \r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+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
-Module Name: Pcd.c\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
-// Include common header file for this module.\r
-//\r
-#include "CommonHeader.h"\r
-\r
#include "Service.h"\r
\r
-\r
+///\r
+/// Instance of PCD_PPI protocol is EDKII native implementation.\r
+/// This protocol instance support dynamic and dynamicEx type PCDs.\r
+///\r
PCD_PPI mPcdPpiInstance = {\r
PeiPcdSetSku,\r
\r
PeiPcdGetNextTokenSpace\r
};\r
\r
+///\r
+/// Instance of EFI_PEI_PCD_PPI which is defined in PI 1.2 Vol 3.\r
+/// This PPI instance only support dyanmicEx type PCD.\r
+///\r
+EFI_PEI_PCD_PPI mEfiPcdPpiInstance = {\r
+ PeiPcdSetSku,\r
+ \r
+ PeiPcdGet8Ex,\r
+ PeiPcdGet16Ex,\r
+ PeiPcdGet32Ex,\r
+ PeiPcdGet64Ex,\r
+ PeiPcdGetPtrEx,\r
+ PeiPcdGetBoolEx,\r
+ PeiPcdGetSizeEx,\r
+ PeiPcdSet8Ex,\r
+ PeiPcdSet16Ex,\r
+ PeiPcdSet32Ex,\r
+ PeiPcdSet64Ex,\r
+ PeiPcdSetPtrEx,\r
+ PeiPcdSetBoolEx,\r
+ (EFI_PEI_PCD_PPI_CALLBACK_ON_SET) PeiRegisterCallBackOnSet,\r
+ (EFI_PEI_PCD_PPI_CANCEL_CALLBACK) PcdUnRegisterCallBackOnSet,\r
+ PeiPcdGetNextToken,\r
+ PeiPcdGetNextTokenSpace\r
+};\r
+\r
+///\r
+/// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.\r
+/// This protocol instance support dynamic and dynamicEx type PCDs.\r
+///\r
+GET_PCD_INFO_PPI mGetPcdInfoInstance = {\r
+ PeiGetPcdInfoGetInfo,\r
+ PeiGetPcdInfoGetInfoEx,\r
+ PeiGetPcdInfoGetSku\r
+};\r
+\r
+///\r
+/// Instance of EFI_GET_PCD_INFO_PPI which is defined in PI 1.2.1 Vol 3.\r
+/// This PPI instance only support dyanmicEx type PCD.\r
+///\r
+EFI_GET_PCD_INFO_PPI mEfiGetPcdInfoInstance = {\r
+ PeiGetPcdInfoGetInfoEx,\r
+ PeiGetPcdInfoGetSku\r
+};\r
\r
+EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {\r
+ {\r
+ EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+ &gPcdPpiGuid,\r
+ &mPcdPpiInstance\r
+ },\r
+ {\r
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+ &gEfiPeiPcdPpiGuid,\r
+ &mEfiPcdPpiInstance\r
+ }\r
+};\r
\r
-STATIC EFI_PEI_PPI_DESCRIPTOR mPpiPCD = {\r
- (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
- &gPcdPpiGuid,\r
- &mPcdPpiInstance\r
+EFI_PEI_PPI_DESCRIPTOR mPpiList2[] = {\r
+ {\r
+ EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+ &gGetPcdInfoPpiGuid,\r
+ &mGetPcdInfoInstance\r
+ },\r
+ {\r
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+ &gEfiGetPcdInfoPpiGuid,\r
+ &mEfiGetPcdInfoInstance\r
+ }\r
};\r
\r
+/**\r
+ Callback on SET PcdSetNvStoreDefaultId\r
+\r
+ Once PcdSetNvStoreDefaultId is set, the default NV storage will be found from\r
+ PcdNvStoreDefaultValueBuffer, and built into VariableHob.\r
\r
+ @param[in] CallBackGuid The PCD token GUID being set.\r
+ @param[in] CallBackToken The PCD token number being set.\r
+ @param[in, out] TokenData A pointer to the token data being set.\r
+ @param[in] TokenDataSize The size, in bytes, of the data being set.\r
\r
+**/\r
+VOID\r
+EFIAPI\r
+PcdSetNvStoreDefaultIdCallBack (\r
+ IN CONST EFI_GUID *CallBackGuid, OPTIONAL\r
+ IN UINTN CallBackToken,\r
+ IN OUT VOID *TokenData,\r
+ IN UINTN TokenDataSize\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINT16 DefaultId;\r
+ SKU_ID SkuId;\r
+ UINTN FullSize;\r
+ UINTN Index;\r
+ UINT8 *DataBuffer;\r
+ UINT8 *VarStoreHobData;\r
+ UINT8 *BufferEnd;\r
+ BOOLEAN IsFound;\r
+ VARIABLE_STORE_HEADER *NvStoreBuffer;\r
+ PCD_DEFAULT_DATA *DataHeader;\r
+ PCD_DEFAULT_INFO *DefaultInfo;\r
+ PCD_DATA_DELTA *DeltaData;\r
+\r
+ DefaultId = *(UINT16 *) TokenData;\r
+ SkuId = GetPcdDatabase()->SystemSkuId;\r
+ IsFound = FALSE;\r
+\r
+ if (PeiPcdGetSizeEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer)) > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {\r
+ DataBuffer = (UINT8 *) PeiPcdGetPtrEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer));\r
+ FullSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *) DataBuffer)->Length;\r
+ DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER));\r
+ //\r
+ // The first section data includes NV storage default setting.\r
+ //\r
+ NvStoreBuffer = (VARIABLE_STORE_HEADER *) ((UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize);\r
+ VarStoreHobData = (UINT8 *) BuildGuidHob (&NvStoreBuffer->Signature, NvStoreBuffer->Size);\r
+ ASSERT (VarStoreHobData != NULL);\r
+ CopyMem (VarStoreHobData, NvStoreBuffer, NvStoreBuffer->Size);\r
+ //\r
+ // Find the matched SkuId and DefaultId in the first section\r
+ //\r
+ DefaultInfo = &(DataHeader->DefaultInfo[0]);\r
+ BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r
+ while ((UINT8 *) DefaultInfo < BufferEnd) {\r
+ if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {\r
+ IsFound = TRUE;\r
+ break;\r
+ }\r
+ DefaultInfo ++;\r
+ }\r
+ //\r
+ // Find the matched SkuId and DefaultId in the remaining section\r
+ //\r
+ Index = sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER) + ((DataHeader->DataSize + 7) & (~7));\r
+ DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);\r
+ while (!IsFound && Index < FullSize && DataHeader->DataSize != 0xFFFFFFFF) {\r
+ DefaultInfo = &(DataHeader->DefaultInfo[0]);\r
+ BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r
+ while ((UINT8 *) DefaultInfo < BufferEnd) {\r
+ if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {\r
+ IsFound = TRUE;\r
+ break;\r
+ }\r
+ DefaultInfo ++;\r
+ }\r
+ if (IsFound) {\r
+ DeltaData = (PCD_DATA_DELTA *) BufferEnd;\r
+ BufferEnd = (UINT8 *) DataHeader + DataHeader->DataSize;\r
+ while ((UINT8 *) DeltaData < BufferEnd) {\r
+ *(VarStoreHobData + DeltaData->Offset) = (UINT8) DeltaData->Value;\r
+ DeltaData ++;\r
+ }\r
+ break;\r
+ }\r
+ Index = (Index + DataHeader->DataSize + 7) & (~7) ;\r
+ DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);\r
+ }\r
+ }\r
+\r
+ Status = PcdUnRegisterCallBackOnSet (\r
+ &gEfiMdeModulePkgTokenSpaceGuid,\r
+ PcdToken(PcdSetNvStoreDefaultId),\r
+ PcdSetNvStoreDefaultIdCallBack\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+ Main entry for PCD PEIM driver.\r
+ \r
+ This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.\r
+\r
+ @param FileHandle Handle of the file being invoked.\r
+ @param PeiServices Describes the list of possible PEI Services.\r
+\r
+ @return Status of install PCD_PPI\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PcdPeimInit (\r
- IN EFI_FFS_FILE_HEADER *FfsHeader,\r
- IN EFI_PEI_SERVICES **PeiServices\r
+ IN EFI_PEI_FILE_HANDLE FileHandle,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices\r
)\r
{\r
EFI_STATUS Status;\r
\r
- BuildPcdDatabase ();\r
- \r
- Status = PeiServicesInstallPpi (&mPpiPCD);\r
+ BuildPcdDatabase (FileHandle);\r
\r
+ //\r
+ // Install PCD_PPI and EFI_PEI_PCD_PPI.\r
+ //\r
+ Status = PeiServicesInstallPpi (&mPpiList[0]);\r
ASSERT_EFI_ERROR (Status);\r
- \r
- return EFI_SUCCESS;\r
+\r
+ //\r
+ // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.\r
+ //\r
+ Status = PeiServicesInstallPpi (&mPpiList2[0]);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Status = PeiRegisterCallBackOnSet (\r
+ &gEfiMdeModulePkgTokenSpaceGuid,\r
+ PcdToken(PcdSetNvStoreDefaultId),\r
+ PcdSetNvStoreDefaultIdCallBack\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return Status;\r
}\r
\r
+/**\r
+ Retrieve additional information associated with a PCD token in the default token space.\r
+\r
+ This includes information such as the type of value the TokenNumber is associated with as well as possible\r
+ human readable name that is associated with the token.\r
+\r
+ @param[in] TokenNumber The PCD token number.\r
+ @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
+ The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
+\r
+ @retval EFI_SUCCESS The PCD information was returned successfully.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiGetPcdInfoGetInfo (\r
+ IN UINTN TokenNumber,\r
+ OUT EFI_PCD_INFO *PcdInfo\r
+ )\r
+{\r
+ return PeiGetPcdInfo (NULL, TokenNumber, PcdInfo);\r
+}\r
+\r
+/**\r
+ Retrieve additional information associated with a PCD token.\r
+\r
+ This includes information such as the type of value the TokenNumber is associated with as well as possible\r
+ human readable name that is associated with the token.\r
+\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param[in] TokenNumber The PCD token number.\r
+ @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
+ The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
+\r
+ @retval EFI_SUCCESS The PCD information was returned successfully.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiGetPcdInfoGetInfoEx (\r
+ IN CONST EFI_GUID *Guid,\r
+ IN UINTN TokenNumber,\r
+ OUT EFI_PCD_INFO *PcdInfo\r
+ )\r
+{\r
+ return PeiGetPcdInfo (Guid, TokenNumber, PcdInfo);\r
+}\r
+\r
+/**\r
+ Retrieve the currently set SKU Id.\r
+\r
+ @return The currently set SKU Id. If the platform has not set at a SKU Id, then the\r
+ default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r
+ Id is returned.\r
+**/\r
+UINTN\r
+EFIAPI\r
+PeiGetPcdInfoGetSku (\r
+ VOID\r
+ )\r
+{\r
+ return (UINTN) GetPcdDatabase()->SystemSkuId;\r
+}\r
+\r
+/**\r
+ Sets the SKU value for subsequent calls to set or get PCD token values.\r
+\r
+ SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values. \r
+ SetSku() is normally called only once by the system.\r
+\r
+ For each item (token), the database can hold a single value that applies to all SKUs, \r
+ or multiple values, where each value is associated with a specific SKU Id. Items with multiple, \r
+ SKU-specific values are called SKU enabled. \r
+ \r
+ The SKU Id of zero is reserved as a default.\r
+ For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the \r
+ single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the \r
+ last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token, \r
+ the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been \r
+ set for that Id, the results are unpredictable.\r
+\r
+ @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and \r
+ set values associated with a PCD token.\r
+\r
+**/\r
VOID\r
EFIAPI\r
PeiPcdSetSku (\r
IN UINTN SkuId\r
)\r
{\r
+ PEI_PCD_DATABASE *PeiPcdDb;\r
+ SKU_ID *SkuIdTable;\r
+ UINTN Index;\r
+\r
+ PeiPcdDb = GetPcdDatabase();\r
+\r
+ if (SkuId == PeiPcdDb->SystemSkuId) {\r
+ //\r
+ // The input SKU Id is equal to current SKU Id, return directly.\r
+ //\r
+ return;\r
+ }\r
\r
- GetPcdDatabase()->Init.SystemSkuId = (SKU_ID) SkuId;\r
+ if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r
+ DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r
+ PeiPcdDb->SystemSkuId,\r
+ (SKU_ID) SkuId\r
+ ));\r
+ ASSERT (FALSE);\r
+ return;\r
+ }\r
\r
+ SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r
+ for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
+ if (SkuId == SkuIdTable[Index + 1]) {\r
+ DEBUG ((EFI_D_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));\r
+ PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r
+ return;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Invalid input SkuId, the default SKU Id will be still used for the system.\r
+ //\r
+ DEBUG ((EFI_D_INFO, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));\r
return;\r
}\r
\r
+/**\r
+ Retrieves an 8-bit value for a given PCD token.\r
\r
+ Retrieves the current byte-sized value for a PCD token number. \r
+ If the TokenNumber is invalid, the results are unpredictable.\r
+ \r
+ @param[in] TokenNumber The PCD token number. \r
\r
+ @return The UINT8 value.\r
+ \r
+**/\r
UINT8\r
EFIAPI\r
PeiPcdGet8 (\r
return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
}\r
\r
+/**\r
+ Retrieves an 16-bit value for a given PCD token.\r
\r
+ Retrieves the current 16-bits value for a PCD token number. \r
+ If the TokenNumber is invalid, the results are unpredictable.\r
+ \r
+ @param[in] TokenNumber The PCD token number. \r
\r
+ @return The UINT16 value.\r
+ \r
+**/\r
UINT16\r
EFIAPI\r
PeiPcdGet16 (\r
return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
}\r
\r
+/**\r
+ Retrieves an 32-bit value for a given PCD token.\r
\r
+ Retrieves the current 32-bits value for a PCD token number. \r
+ If the TokenNumber is invalid, the results are unpredictable.\r
+ \r
+ @param[in] TokenNumber The PCD token number. \r
\r
+ @return The UINT32 value.\r
+ \r
+**/\r
UINT32\r
EFIAPI\r
PeiPcdGet32 (\r
return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
}\r
\r
+/**\r
+ Retrieves an 64-bit value for a given PCD token.\r
\r
+ Retrieves the current 64-bits value for a PCD token number. \r
+ If the TokenNumber is invalid, the results are unpredictable.\r
+ \r
+ @param[in] TokenNumber The PCD token number. \r
\r
+ @return The UINT64 value.\r
+ \r
+**/\r
UINT64\r
EFIAPI\r
PeiPcdGet64 (\r
return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r
}\r
\r
+/**\r
+ Retrieves a pointer to a value for a given PCD token.\r
\r
+ Retrieves the current pointer to the buffer for a PCD token number. \r
+ Do not make any assumptions about the alignment of the pointer that \r
+ is returned by this function call. If the TokenNumber is invalid, \r
+ the results are unpredictable.\r
\r
+ @param[in] TokenNumber The PCD token number. \r
+\r
+ @return The pointer to the buffer to be retrieved.\r
+ \r
+**/\r
VOID *\r
EFIAPI\r
PeiPcdGetPtr (\r
return GetWorker (TokenNumber, 0);\r
}\r
\r
+/**\r
+ Retrieves a Boolean value for a given PCD token.\r
+\r
+ Retrieves the current boolean value for a PCD token number. \r
+ Do not make any assumptions about the alignment of the pointer that \r
+ is returned by this function call. If the TokenNumber is invalid, \r
+ the results are unpredictable.\r
\r
+ @param[in] TokenNumber The PCD token number. \r
\r
+ @return The Boolean value.\r
+ \r
+**/\r
BOOLEAN\r
EFIAPI\r
PeiPcdGetBool (\r
return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
}\r
\r
+/**\r
+ Retrieves the size of the value for a given PCD token.\r
\r
+ Retrieves the current size of a particular PCD token. \r
+ If the TokenNumber is invalid, the results are unpredictable.\r
\r
+ @param[in] TokenNumber The PCD token number. \r
+\r
+ @return The size of the value for the PCD token.\r
+ \r
+**/\r
UINTN\r
EFIAPI\r
PeiPcdGetSize (\r
PEI_PCD_DATABASE *PeiPcdDb;\r
UINTN Size;\r
UINTN MaxSize;\r
+ UINT32 LocalTokenCount;\r
\r
- //\r
- // If DebugAssertEnabled is TRUE, we still need to provide the GET size\r
- // function as GetWorker and SetWoker need this function to do ASSERT.\r
- //\r
- if ((!FeaturePcdGet(PcdPeiPcdDatabaseGetSizeEnabled)) &&\r
- (!DebugAssertEnabled ())) {\r
- return 0;\r
- }\r
-\r
- PeiPcdDb = GetPcdDatabase ();\r
+ PeiPcdDb = GetPcdDatabase ();\r
+ LocalTokenCount = PeiPcdDb->LocalTokenCount;\r
//\r
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
// We have to decrement TokenNumber by 1 to make it usable\r
// EBC compiler is very choosy. It may report warning about comparison\r
// between UINTN and 0 . So we add 1 in each size of the \r
// comparison.\r
- ASSERT (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);\r
+ ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));\r
\r
- Size = (PeiPcdDb->Init.LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
+ Size = (*((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber) & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
\r
if (Size == 0) {\r
//\r
\r
}\r
\r
+/**\r
+ Retrieves an 8-bit value for a given PCD token.\r
+\r
+ Retrieves the 8-bit value of a particular PCD token. \r
+ If the TokenNumber is invalid or the token space\r
+ specified by Guid does not exist, the results are \r
+ unpredictable.\r
\r
+ @param[in] Guid The token space for the token number.\r
+ @param[in] ExTokenNumber The PCD token number. \r
\r
+ @return The size 8-bit value for the PCD token.\r
+ \r
+**/\r
UINT8\r
EFIAPI\r
PeiPcdGet8Ex (\r
return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
}\r
\r
+/**\r
+ Retrieves an 16-bit value for a given PCD token.\r
\r
+ Retrieves the 16-bit value of a particular PCD token. \r
+ If the TokenNumber is invalid or the token space\r
+ specified by Guid does not exist, the results are \r
+ unpredictable.\r
\r
+ @param[in] Guid The token space for the token number.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+\r
+ @return The size 16-bit value for the PCD token.\r
+ \r
+**/\r
UINT16\r
EFIAPI\r
PeiPcdGet16Ex (\r
return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r
}\r
\r
+/**\r
+ Retrieves an 32-bit value for a given PCD token.\r
+\r
+ Retrieves the 32-bit value of a particular PCD token. \r
+ If the TokenNumber is invalid or the token space\r
+ specified by Guid does not exist, the results are \r
+ unpredictable.\r
\r
+ @param[in] Guid The token space for the token number.\r
+ @param[in] ExTokenNumber The PCD token number. \r
\r
+ @return The size 32-bit value for the PCD token.\r
+ \r
+**/\r
UINT32\r
EFIAPI\r
PeiPcdGet32Ex (\r
return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r
}\r
\r
+/**\r
+ Retrieves an 64-bit value for a given PCD token.\r
\r
+ Retrieves the 64-bit value of a particular PCD token. \r
+ If the TokenNumber is invalid or the token space\r
+ specified by Guid does not exist, the results are \r
+ unpredictable.\r
\r
+ @param[in] Guid The token space for the token number.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+\r
+ @return The size 64-bit value for the PCD token.\r
+ \r
+**/\r
UINT64\r
EFIAPI\r
PeiPcdGet64Ex (\r
return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r
}\r
\r
+/**\r
+ Retrieves a pointer to a value for a given PCD token.\r
+\r
+ Retrieves the current pointer to the buffer for a PCD token number. \r
+ Do not make any assumptions about the alignment of the pointer that \r
+ is returned by this function call. If the TokenNumber is invalid, \r
+ the results are unpredictable.\r
\r
+ @param[in] Guid The token space for the token number.\r
+ @param[in] ExTokenNumber The PCD token number. \r
\r
+ @return The pointer to the buffer to be retrieved.\r
+ \r
+**/\r
VOID *\r
EFIAPI\r
PeiPcdGetPtrEx (\r
return ExGetWorker (Guid, ExTokenNumber, 0);\r
}\r
\r
+/**\r
+ Retrieves an Boolean value for a given PCD token.\r
\r
+ Retrieves the Boolean value of a particular PCD token. \r
+ If the TokenNumber is invalid or the token space\r
+ specified by Guid does not exist, the results are \r
+ unpredictable.\r
\r
+ @param[in] Guid The token space for the token number.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+\r
+ @return The size Boolean value for the PCD token.\r
+ \r
+**/\r
BOOLEAN\r
EFIAPI\r
PeiPcdGetBoolEx (\r
return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
}\r
\r
+/**\r
+ Retrieves the size of the value for a given PCD token.\r
+\r
+ Retrieves the current size of a particular PCD token. \r
+ If the TokenNumber is invalid, the results are unpredictable.\r
\r
+ @param[in] Guid The token space for the token number.\r
+ @param[in] ExTokenNumber The PCD token number. \r
\r
+ @return The size of the value for the PCD token.\r
+ \r
+**/\r
UINTN\r
EFIAPI\r
PeiPcdGetSizeEx (\r
IN UINTN ExTokenNumber\r
)\r
{\r
- if ((!FeaturePcdGet (PcdPeiPcdDatabaseGetSizeEnabled)) || !FeaturePcdGet (PcdPeiPcdDatabaseExEnabled)) {\r
- return 0;\r
- }\r
-\r
return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));\r
}\r
\r
+/**\r
+ Sets an 8-bit value for a given PCD token.\r
\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] TokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
+\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSet8 (\r
return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
}\r
\r
+/**\r
+ Sets an 16-bit value for a given PCD token.\r
+\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] TokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSet16 (\r
return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
}\r
\r
+/**\r
+ Sets an 32-bit value for a given PCD token.\r
\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] TokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
+\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSet32 (\r
return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
}\r
\r
+/**\r
+ Sets an 64-bit value for a given PCD token.\r
+\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] TokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSet64 (\r
return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
}\r
\r
-\r
+/**\r
+ Sets a value of a specified size for a given PCD token.\r
+\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
+\r
+ @param[in] TokenNumber The PCD token number. \r
+ @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
+ On input, if the SizeOfValue is greater than the maximum size supported \r
+ for this TokenNumber then the output value of SizeOfValue will reflect \r
+ the maximum size supported for this TokenNumber.\r
+ @param[in] Buffer The buffer to set for the PCD token.\r
+\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSetPtr (\r
return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
}\r
\r
+/**\r
+ Sets an Boolean value for a given PCD token.\r
\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] TokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
+\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSetBool (\r
return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
}\r
\r
+/**\r
+ Sets an 8-bit value for a given PCD token.\r
+\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSet8Ex (\r
return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
}\r
\r
+/**\r
+ Sets an 16-bit value for a given PCD token.\r
\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
+\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSet16Ex (\r
return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
}\r
\r
+/**\r
+ Sets an 32-bit value for a given PCD token.\r
+\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSet32Ex (\r
return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
}\r
\r
+/**\r
+ Sets an 64-bit value for a given PCD token.\r
\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+ @param[in] Value The value to set for the PCD token.\r
+\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSet64Ex (\r
return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
}\r
\r
-\r
-\r
+/**\r
+ Sets a value of a specified size for a given PCD token.\r
+\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
+\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+ @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
+ On input, if the SizeOfValue is greater than the maximum size supported \r
+ for this TokenNumber then the output value of SizeOfValue will reflect \r
+ the maximum size supported for this TokenNumber.\r
+ @param[in] Value The buffer to set for the PCD token.\r
+\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSetPtrEx (\r
- IN CONST EFI_GUID *Guid,\r
- IN UINTN ExTokenNumber,\r
- IN UINTN *SizeOfBuffer,\r
- IN VOID *Value\r
+ IN CONST EFI_GUID *Guid,\r
+ IN UINTN ExTokenNumber,\r
+ IN OUT UINTN *SizeOfBuffer,\r
+ IN VOID *Value\r
)\r
{\r
return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);\r
}\r
\r
+/**\r
+ Sets an Boolean value for a given PCD token.\r
+\r
+ When the PCD service sets a value, it will check to ensure that the \r
+ size of the value being set is compatible with the Token's existing definition. \r
+ If it is not, an error will be returned.\r
\r
+ @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param [in] ExTokenNumber The PCD token number. \r
+ @param [in] Value The value to set for the PCD token.\r
\r
+ @retval EFI_SUCCESS Procedure returned successfully.\r
+ @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
+ being set was incompatible with a call to this function. \r
+ Use GetSize() to retrieve the size of the target data.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
+ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdSetBoolEx (\r
return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
}\r
\r
+/**\r
+ Specifies a function to be called anytime the value of a designated token is changed.\r
\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+ @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
\r
+ @retval EFI_SUCCESS The PCD service has successfully established a call event \r
+ for the CallBackToken requested.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiRegisterCallBackOnSet (\r
IN PCD_PPI_CALLBACK CallBackFunction\r
)\r
{\r
- if (!FeaturePcdGet(PcdPeiPcdDatabaseCallbackOnSetEnabled)) {\r
+ if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
- ASSERT (CallBackFunction != NULL);\r
- \r
+ if (CallBackFunction == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);\r
}\r
\r
+/**\r
+ Cancels a previously set callback function for a particular PCD token number.\r
+\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
+ @param[in] ExTokenNumber The PCD token number. \r
+ @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
\r
+ @retval EFI_SUCCESS The PCD service has successfully established a call event \r
+ for the CallBackToken requested.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PcdUnRegisterCallBackOnSet (\r
IN PCD_PPI_CALLBACK CallBackFunction\r
)\r
{\r
- if (!FeaturePcdGet(PcdPeiPcdDatabaseCallbackOnSetEnabled)) {\r
+ if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
- ASSERT (CallBackFunction != NULL);\r
- \r
+ if (CallBackFunction == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);\r
}\r
\r
+/**\r
+ Retrieves the next valid token number in a given namespace. \r
+ \r
+ This is useful since the PCD infrastructure contains a sparse list of token numbers, \r
+ and one cannot a priori know what token numbers are valid in the database. \r
+ \r
+ If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned. \r
+ If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned. \r
+ If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned. \r
+ If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned. \r
+ The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid. \r
+ If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned. \r
+ If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned. \r
+ If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
+\r
+\r
+ @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value. \r
+ This is an optional parameter that may be NULL. If this parameter is NULL, then a request \r
+ is being made to retrieve tokens from the default token space.\r
+ @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.\r
+ \r
+ @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.\r
+ @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.\r
\r
-\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdGetNextToken (\r
UINTN GuidTableIdx;\r
PEI_PCD_DATABASE *PeiPcdDb;\r
EFI_GUID *MatchGuid;\r
+ EFI_GUID *GuidTable;\r
DYNAMICEX_MAPPING *ExMapTable;\r
- UINTN i;\r
+ UINTN Index;\r
BOOLEAN Found;\r
BOOLEAN PeiExMapTableEmpty;\r
+ UINTN PeiNexTokenNumber; \r
\r
- if (!FeaturePcdGet (PcdPeiPcdDatabaseTraverseEnabled)) {\r
+ if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
- PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;\r
+ PeiPcdDb = GetPcdDatabase ();\r
+ PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;\r
+ GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
\r
+ if (PeiPcdDb->ExTokenCount == 0) {\r
+ PeiExMapTableEmpty = TRUE;\r
+ } else {\r
+ PeiExMapTableEmpty = FALSE;\r
+ }\r
if (Guid == NULL) {\r
- if (*TokenNumber > PEI_NEX_TOKEN_NUMBER) {\r
+ if (*TokenNumber > PeiNexTokenNumber) {\r
return EFI_NOT_FOUND;\r
}\r
(*TokenNumber)++;\r
- if (*TokenNumber > PEI_NEX_TOKEN_NUMBER) {\r
+ if (*TokenNumber > PeiNexTokenNumber) {\r
*TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
+ return EFI_NOT_FOUND;\r
}\r
return EFI_SUCCESS;\r
} else {\r
if (PeiExMapTableEmpty) {\r
- *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
- return EFI_SUCCESS;\r
+ return EFI_NOT_FOUND;\r
}\r
- \r
- //\r
- // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order\r
- // 1) ExGuid\r
- // 2) ExTokenNumber\r
- //\r
- PeiPcdDb = GetPcdDatabase ();\r
- \r
- MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), Guid);\r
+\r
+ MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);\r
\r
if (MatchGuid == NULL) {\r
- *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
return EFI_NOT_FOUND;\r
}\r
\r
- GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;\r
+ GuidTableIdx = MatchGuid - GuidTable;\r
\r
- ExMapTable = PeiPcdDb->Init.ExMapTable;\r
+ ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
\r
Found = FALSE;\r
//\r
// Locate the GUID in ExMapTable first.\r
//\r
- for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {\r
- if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {\r
+ for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r
+ if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
Found = TRUE;\r
break;\r
}\r
}\r
\r
if (Found) {\r
+ //\r
+ // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first\r
+ // token number in found token space.\r
+ //\r
if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
- *TokenNumber = ExMapTable[i].ExTokenNumber;\r
+ *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
return EFI_SUCCESS;\r
}\r
\r
- for ( ; i < PEI_EXMAPPING_TABLE_SIZE; i++) {\r
- if (ExMapTable[i].ExTokenNumber == *TokenNumber) {\r
- i++;\r
- if (i == PEI_EXMAPPING_TABLE_SIZE) {\r
- //\r
- // Exceed the length of ExMap Table\r
- //\r
- *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
- return EFI_SUCCESS;\r
- }\r
- if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {\r
- *TokenNumber = ExMapTable[i].ExTokenNumber;\r
- return EFI_SUCCESS;\r
- } else {\r
- *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
- return EFI_SUCCESS;\r
- }\r
+ for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {\r
+ if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {\r
+ break;\r
+ }\r
+ }\r
+\r
+ while (Index < PeiPcdDb->ExTokenCount) {\r
+ Index++;\r
+ if (Index == PeiPcdDb->ExTokenCount) {\r
+ //\r
+ // Exceed the length of ExMap Table\r
+ //\r
+ *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
+ return EFI_NOT_FOUND;\r
+ } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
+ //\r
+ // Found the next match\r
+ //\r
+ *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
+ return EFI_SUCCESS;\r
}\r
}\r
- return EFI_NOT_FOUND;\r
}\r
}\r
\r
return EFI_NOT_FOUND;\r
}\r
\r
+/**\r
+ Retrieves the next valid PCD token namespace for a given namespace.\r
+\r
+ Gets the next valid token namespace for a given namespace. This is useful to traverse the valid\r
+ token namespaces on a platform.\r
\r
+ @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token\r
+ namespace from which the search will start. On output, it designates the next valid\r
+ token namespace on the platform. If *Guid is NULL, then the GUID of the first token\r
+ space of the current platform is returned. If the search cannot locate the next valid\r
+ token namespace, an error is returned and the value of *Guid is undefined.\r
+ \r
+ @retval EFI_SUCCESS The PCD service retrieved the value requested.\r
+ @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.\r
\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiPcdGetNextTokenSpace (\r
EFI_GUID *MatchGuid;\r
PEI_PCD_DATABASE *PeiPcdDb;\r
DYNAMICEX_MAPPING *ExMapTable;\r
- UINTN i;\r
+ UINTN Index;\r
+ UINTN Index2;\r
BOOLEAN Found;\r
BOOLEAN PeiExMapTableEmpty;\r
+ EFI_GUID *GuidTable;\r
\r
- if (!FeaturePcdGet (PcdPeiPcdDatabaseTraverseEnabled)) {\r
+ if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
ASSERT (Guid != NULL);\r
\r
- PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;\r
+ PeiPcdDb = GetPcdDatabase ();\r
\r
+ if (PeiPcdDb->ExTokenCount == 0) {\r
+ PeiExMapTableEmpty = TRUE;\r
+ } else {\r
+ PeiExMapTableEmpty = FALSE;\r
+ }\r
+ \r
if (PeiExMapTableEmpty) {\r
- if (*Guid != NULL) {\r
- return EFI_NOT_FOUND;\r
- } else {\r
- return EFI_SUCCESS;\r
- }\r
+ return EFI_NOT_FOUND;\r
}\r
\r
- //\r
- // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order\r
- // 1) ExGuid\r
- // 2) ExTokenNumber\r
- //\r
- PeiPcdDb = GetPcdDatabase ();\r
-\r
- ExMapTable = PeiPcdDb->Init.ExMapTable;\r
-\r
+ ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
+ GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
+ \r
if (*Guid == NULL) {\r
//\r
// return the first Token Space Guid.\r
//\r
- *Guid = &PeiPcdDb->Init.GuidTable[ExMapTable[0].ExGuidIndex];\r
+ *Guid = GuidTable + ExMapTable[0].ExGuidIndex;\r
return EFI_SUCCESS;\r
}\r
\r
- MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), *Guid);\r
+ MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid);\r
\r
if (MatchGuid == NULL) {\r
return EFI_NOT_FOUND;\r
}\r
\r
- GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;\r
+ GuidTableIdx = MatchGuid - GuidTable;\r
\r
Found = FALSE;\r
- for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {\r
- if (ExMapTable[i].ExGuidIndex == GuidTableIdx) {\r
+ for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r
+ if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
Found = TRUE;\r
break;\r
}\r
}\r
\r
if (Found) {\r
- i++;\r
- for ( ; i < PEI_EXMAPPING_TABLE_SIZE; i++ ) {\r
- if (ExMapTable[i].ExGuidIndex != GuidTableIdx ) {\r
- *Guid = &PeiPcdDb->Init.GuidTable[ExMapTable[i].ExGuidIndex];\r
- return EFI_SUCCESS;\r
+ Index++;\r
+ for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) {\r
+ if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) {\r
+ Found = FALSE;\r
+ for (Index2 = 0 ; Index2 < Index; Index2++) {\r
+ if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) {\r
+ //\r
+ // This token namespace should have been found and output at preceding getting.\r
+ //\r
+ Found = TRUE;\r
+ break;\r
+ }\r
+ }\r
+ if (!Found) {\r
+ *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex;\r
+ return EFI_SUCCESS;\r
+ }\r
}\r
}\r
*Guid = NULL;\r
- return EFI_SUCCESS;\r
}\r
\r
return EFI_NOT_FOUND;\r
\r
}\r
\r
+/**\r
+ Get PCD value's size for POINTER type PCD.\r
+ \r
+ The POINTER type PCD's value will be stored into a buffer in specified size.\r
+ The max size of this PCD's value is described in PCD's definition in DEC file.\r
+\r
+ @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r
+ @param MaxSize Maximum size of PCD's value\r
+ @param Database Pcd database in PEI phase.\r
+\r
+ @return PCD value's size for POINTER type PCD.\r
+\r
+**/\r
UINTN\r
GetPtrTypeSize (\r
IN UINTN LocalTokenNumberTableIdx,\r
UINTN LocalTokenNumber;\r
SKU_ID *SkuIdTable;\r
SIZE_INFO *SizeTable;\r
- UINTN i;\r
+ UINTN Index;\r
\r
SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
\r
- LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];\r
+ LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
\r
ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
\r
- SizeTable = Database->Init.SizeTable;\r
+ SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
\r
*MaxSize = SizeTable[SizeTableIdx];\r
//\r
// SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
// PCD entry.\r
//\r
- if (LocalTokenNumber & PCD_TYPE_VPD) {\r
+ if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
//\r
- // We have only one entry for VPD enabled PCD entry:\r
+ // We have only two entry for VPD enabled PCD entry:\r
// 1) MAX Size.\r
+ // 2) Current Size\r
// We consider current size is equal to MAX size.\r
//\r
return *MaxSize;\r
// 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
//\r
SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
- for (i = 0; i < SkuIdTable[0]; i++) {\r
- if (SkuIdTable[1 + i] == Database->Init.SystemSkuId) {\r
- return SizeTable[SizeTableIdx + 1 + i];\r
+ for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
+ if (SkuIdTable[1 + Index] == Database->SystemSkuId) {\r
+ return SizeTable[SizeTableIdx + 1 + Index];\r
}\r
}\r
return SizeTable[SizeTableIdx + 1];\r
}\r
}\r
\r
+/**\r
+ Set PCD value's size for POINTER type PCD.\r
+ \r
+ The POINTER type PCD's value will be stored into a buffer in specified size.\r
+ The max size of this PCD's value is described in PCD's definition in DEC file.\r
+\r
+ @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r
+ @param CurrentSize Maximum size of PCD's value\r
+ @param Database Pcd database in PEI phase.\r
\r
+ @retval TRUE Success to set PCD's value size, which is not exceed maximum size\r
+ @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size\r
\r
+**/\r
BOOLEAN\r
SetPtrTypeSize (\r
IN UINTN LocalTokenNumberTableIdx,\r
UINTN LocalTokenNumber;\r
SKU_ID *SkuIdTable;\r
SIZE_INFO *SizeTable;\r
- UINTN i;\r
+ UINTN Index;\r
UINTN MaxSize;\r
\r
SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
\r
- LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];\r
+ LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
\r
ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
- \r
- SizeTable = Database->Init.SizeTable;\r
+\r
+ SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
\r
MaxSize = SizeTable[SizeTableIdx];\r
//\r
// SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
// PCD entry.\r
//\r
- if (LocalTokenNumber & PCD_TYPE_VPD) {\r
+ if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
//\r
// We shouldn't come here as we don't support SET for VPD\r
//\r
(*CurrentSize == MAX_ADDRESS)) {\r
*CurrentSize = MaxSize;\r
return FALSE;\r
- } \r
+ }\r
\r
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
//\r
// 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
//\r
SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
- for (i = 0; i < SkuIdTable[0]; i++) {\r
- if (SkuIdTable[1 + i] == Database->Init.SystemSkuId) {\r
- SizeTable[SizeTableIdx + 1 + i] = (SIZE_INFO) *CurrentSize;\r
+ for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
+ if (SkuIdTable[1 + Index] == Database->SystemSkuId) {\r
+ SizeTable[SizeTableIdx + 1 + Index] = (SIZE_INFO) *CurrentSize;\r
return TRUE;\r
}\r
}\r