/** Retrieve additional information associated with a PCD token. This includes information such as the type of value the TokenNumber is associated with as well as possible human readable name that is associated with the token. @param[in] Database PCD database. @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value. @param[in] TokenNumber The PCD token number. @param[out] PcdInfo The returned information associated with the requested TokenNumber. The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName. @retval EFI_SUCCESS The PCD information was returned successfully @retval EFI_NOT_FOUND The PCD service could not find the requested token number. **/ EFI_STATUS ExGetPcdInfo ( IN PEI_PCD_DATABASE *Database, IN CONST EFI_GUID *Guid, IN UINTN TokenNumber, OUT EFI_PCD_INFO *PcdInfo ) { UINTN GuidTableIdx; EFI_GUID *MatchGuid; EFI_GUID *GuidTable; DYNAMICEX_MAPPING *ExMapTable; UINTN Index; UINT32 LocalTokenNumber; GuidTable = (EFI_GUID *)((UINT8 *)Database + Database->GuidTableOffset); MatchGuid = ScanGuid (GuidTable, Database->GuidTableCount * sizeof(EFI_GUID), Guid); if (MatchGuid == NULL) { return EFI_NOT_FOUND; } GuidTableIdx = MatchGuid - GuidTable; ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)Database + Database->ExMapTableOffset); // // Find the PCD by GuidTableIdx and ExTokenNumber in ExMapTable. // for (Index = 0; Index < Database->ExTokenCount; Index++) { if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) { if (TokenNumber == PCD_INVALID_TOKEN_NUMBER) { // // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8, // PcdSize to 0 and PcdName to the null-terminated ASCII string // associated with the token's namespace Guid. // PcdInfo->PcdType = EFI_PCD_TYPE_8; PcdInfo->PcdSize = 0; // // Here use one representative in the token space to get the TokenSpaceCName. // PcdInfo->PcdName = GetPcdName (TRUE, Database, ExMapTable[Index].TokenNumber); return EFI_SUCCESS; } else if (ExMapTable[Index].ExTokenNumber == TokenNumber) { PcdInfo->PcdSize = PeiPcdGetSize (ExMapTable[Index].TokenNumber); LocalTokenNumber = GetLocalTokenNumber (Database, ExMapTable[Index].TokenNumber); PcdInfo->PcdType = GetPcdType (LocalTokenNumber); PcdInfo->PcdName = GetPcdName (FALSE, Database, ExMapTable[Index].TokenNumber); return EFI_SUCCESS; } } } return EFI_NOT_FOUND; }
/** Get local token number according to dynamic-ex PCD's {token space guid:token number} A dynamic-ex type PCD, developer must provide pair of token space guid: token number in DEC file. PCD database maintain a mapping table that translate pair of {token space guid: token number} to local token number. @param Guid Token space guid for dynamic-ex PCD entry. @param ExTokenNumber EDES_TODO: Add parameter description @return local token number for dynamic-ex PCD. **/ UINTN GetExPcdTokenNumber ( IN CONST EFI_GUID *Guid, IN UINTN ExTokenNumber ) { UINT32 Index; DYNAMICEX_MAPPING *ExMap; EFI_GUID *GuidTable; EFI_GUID *MatchGuid; UINTN MatchGuidIdx; PEI_PCD_DATABASE *PeiPcdDb; PeiPcdDb = GetPcdDatabase(); ExMap = PeiPcdDb->Init.ExMapTable; GuidTable = PeiPcdDb->Init.GuidTable; MatchGuid = ScanGuid (GuidTable, sizeof(PeiPcdDb->Init.GuidTable), Guid); // // We need to ASSERT here. If GUID can't be found in GuidTable, this is a // error in the BUILD system. // ASSERT (MatchGuid != NULL); MatchGuidIdx = MatchGuid - GuidTable; for (Index = 0; Index < PEI_EXMAPPING_TABLE_SIZE; Index++) { if ((ExTokenNumber == ExMap[Index].ExTokenNumber) && (MatchGuidIdx == ExMap[Index].ExGuidIndex)) { return ExMap[Index].LocalTokenNumber; } } return PCD_INVALID_TOKEN_NUMBER; }
/** Get Token Number according to dynamic-ex PCD's {token space guid:token number} A dynamic-ex type PCD, developer must provide pair of token space guid: token number in DEC file. PCD database maintain a mapping table that translate pair of {token space guid: token number} to Token Number. @param Guid Token space guid for dynamic-ex PCD entry. @param ExTokenNumber Dynamic-ex PCD token number. @return Token Number for dynamic-ex PCD. **/ UINTN GetExPcdTokenNumber ( IN CONST EFI_GUID *Guid, IN UINTN ExTokenNumber ) { UINT32 Index; DYNAMICEX_MAPPING *ExMap; EFI_GUID *GuidTable; EFI_GUID *MatchGuid; UINTN MatchGuidIdx; PEI_PCD_DATABASE *PeiPcdDb; PeiPcdDb = GetPcdDatabase(); ExMap = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset); GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset); MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid); // // We need to ASSERT here. If GUID can't be found in GuidTable, this is a // error in the BUILD system. // ASSERT (MatchGuid != NULL); MatchGuidIdx = MatchGuid - GuidTable; for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) { if ((ExTokenNumber == ExMap[Index].ExTokenNumber) && (MatchGuidIdx == ExMap[Index].ExGuidIndex)) { return ExMap[Index].TokenNumber; } } return PCD_INVALID_TOKEN_NUMBER; }
/** Retrieves the next valid PCD token namespace for a given namespace. Gets the next valid token namespace for a given namespace. This is useful to traverse the valid token namespaces on a platform. @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token namespace from which the search will start. On output, it designates the next valid token namespace on the platform. If *Guid is NULL, then the GUID of the first token space of the current platform is returned. If the search cannot locate the next valid token namespace, an error is returned and the value of *Guid is undefined. @retval EFI_SUCCESS The PCD service retrieved the value requested. @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace. **/ EFI_STATUS EFIAPI PeiPcdGetNextTokenSpace ( IN OUT CONST EFI_GUID **Guid ) { UINTN GuidTableIdx; EFI_GUID *MatchGuid; PEI_PCD_DATABASE *PeiPcdDb; DYNAMICEX_MAPPING *ExMapTable; UINTN Index; UINTN Index2; BOOLEAN Found; BOOLEAN PeiExMapTableEmpty; EFI_GUID *GuidTable; if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) { return EFI_UNSUPPORTED; } ASSERT (Guid != NULL); PeiPcdDb = GetPcdDatabase (); if (PeiPcdDb->ExTokenCount == 0) { PeiExMapTableEmpty = TRUE; } else { PeiExMapTableEmpty = FALSE; } if (PeiExMapTableEmpty) { return EFI_NOT_FOUND; } ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset); GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset); if (*Guid == NULL) { // // return the first Token Space Guid. // *Guid = GuidTable + ExMapTable[0].ExGuidIndex; return EFI_SUCCESS; } MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid); if (MatchGuid == NULL) { return EFI_NOT_FOUND; } GuidTableIdx = MatchGuid - GuidTable; Found = FALSE; for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) { if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) { Found = TRUE; break; } } if (Found) { Index++; for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) { if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) { Found = FALSE; for (Index2 = 0 ; Index2 < Index; Index2++) { if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) { // // This token namespace should have been found and output at preceding getting. // Found = TRUE; break; } } if (!Found) { *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex; return EFI_SUCCESS; } } } *Guid = NULL; } return EFI_NOT_FOUND; }
/** Retrieves the next valid token number in a given namespace. This is useful since the PCD infrastructure contains a sparse list of token numbers, and one cannot a priori know what token numbers are valid in the database. If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned. If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned. If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned. If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned. The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid. If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned. If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned. If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned. @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value. This is an optional parameter that may be NULL. If this parameter is NULL, then a request is being made to retrieve tokens from the default token space. @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number. @retval EFI_SUCCESS The PCD service has retrieved the next valid token number. @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number. **/ EFI_STATUS EFIAPI PeiPcdGetNextToken ( IN CONST EFI_GUID *Guid, OPTIONAL IN OUT UINTN *TokenNumber ) { UINTN GuidTableIdx; PEI_PCD_DATABASE *PeiPcdDb; EFI_GUID *MatchGuid; EFI_GUID *GuidTable; DYNAMICEX_MAPPING *ExMapTable; UINTN Index; BOOLEAN Found; BOOLEAN PeiExMapTableEmpty; UINTN PeiNexTokenNumber; if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) { return EFI_UNSUPPORTED; } PeiPcdDb = GetPcdDatabase (); PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount; GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset); if (PeiPcdDb->ExTokenCount == 0) { PeiExMapTableEmpty = TRUE; } else { PeiExMapTableEmpty = FALSE; } if (Guid == NULL) { if (*TokenNumber > PeiNexTokenNumber) { return EFI_NOT_FOUND; } (*TokenNumber)++; if (*TokenNumber > PeiNexTokenNumber) { *TokenNumber = PCD_INVALID_TOKEN_NUMBER; return EFI_NOT_FOUND; } return EFI_SUCCESS; } else { if (PeiExMapTableEmpty) { return EFI_NOT_FOUND; } MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid); if (MatchGuid == NULL) { return EFI_NOT_FOUND; } GuidTableIdx = MatchGuid - GuidTable; ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset); Found = FALSE; // // Locate the GUID in ExMapTable first. // for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) { if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) { Found = TRUE; break; } } if (Found) { if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) { *TokenNumber = ExMapTable[Index].ExTokenNumber; return EFI_SUCCESS; } for ( ; Index < PeiPcdDb->ExTokenCount; Index++) { if (ExMapTable[Index].ExTokenNumber == *TokenNumber) { break; } } while (Index < PeiPcdDb->ExTokenCount) { Index++; if (Index == PeiPcdDb->ExTokenCount) { // // Exceed the length of ExMap Table // *TokenNumber = PCD_INVALID_TOKEN_NUMBER; return EFI_NOT_FOUND; } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) { // // Found the next match // *TokenNumber = ExMapTable[Index].ExTokenNumber; return EFI_SUCCESS; } } } } return EFI_NOT_FOUND; }