Example #1
0
File: Pcd.c Project: b-man/edk2
/**
  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 retrieve the next token.
                          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
DxePcdGetNextToken (
  IN CONST EFI_GUID         *Guid, OPTIONAL
  IN OUT   UINTN            *TokenNumber
  )
{
  EFI_STATUS          Status;
  BOOLEAN             PeiExMapTableEmpty;
  BOOLEAN             DxeExMapTableEmpty;

  Status = EFI_NOT_FOUND;
  PeiExMapTableEmpty = mPeiExMapTableEmpty;
  DxeExMapTableEmpty = mDxeExMapTableEmpty;

  //
  // Scan the local token space
  //
  if (Guid == NULL) {
    // EBC compiler is very choosy. It may report warning about comparison
    // between UINTN and 0 . So we add 1 in each size of the
    // comparison.
    if (((*TokenNumber + 1 > mPeiNexTokenCount + 1) && (*TokenNumber + 1 <= mPeiLocalTokenCount + 1)) ||
        ((*TokenNumber + 1 > (mPeiLocalTokenCount + mDxeNexTokenCount + 1)))) {
      return EFI_NOT_FOUND;
    }

    (*TokenNumber)++;
    if ((*TokenNumber + 1 > mPeiNexTokenCount + 1) &&
        (*TokenNumber + 1 <= mPeiLocalTokenCount + 1)) {
      //
      // The first Non-Ex type Token Number for DXE PCD
      // database is mPeiLocalTokenCount + 1
      //
      if (mDxeNexTokenCount > 0) {
        *TokenNumber = mPeiLocalTokenCount + 1;
      } else {
        *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
        return EFI_NOT_FOUND;
      }
    } else if (*TokenNumber + 1 > mDxeNexTokenCount + mPeiLocalTokenCount + 1) {
      *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
      return EFI_NOT_FOUND;
    }
    return EFI_SUCCESS;
  }

  if (PeiExMapTableEmpty && DxeExMapTableEmpty) {
    return EFI_NOT_FOUND;
  }

  if (!PeiExMapTableEmpty) {
    Status = ExGetNextTokeNumber (
                        Guid,
                        TokenNumber,
                        (EFI_GUID *)((UINT8 *)mPcdDatabase.PeiDb + mPcdDatabase.PeiDb->GuidTableOffset),
                        mPeiGuidTableSize,
                        (DYNAMICEX_MAPPING *)((UINT8 *) mPcdDatabase.PeiDb + mPcdDatabase.PeiDb->ExMapTableOffset),
                        mPeiExMapppingTableSize
                        );
  }

  if (Status == EFI_SUCCESS) {
    return Status;
  }

  if (!DxeExMapTableEmpty) {
    Status = ExGetNextTokeNumber (
                        Guid,
                        TokenNumber,
                        (EFI_GUID *)((UINT8 *)mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->GuidTableOffset),
                        mDxeGuidTableSize,
                        (DYNAMICEX_MAPPING *)((UINT8 *) mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->ExMapTableOffset),
                        mDxeExMapppingTableSize
                        );
  }

  return Status;
}
Example #2
0
/**
  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 retrieve the next token.
                          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 retrieved the next valid token number. Or the input token number
                        is already the last valid token number in the PCD database.
                        In the later case, *TokenNumber is updated with the value of 0.
  @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.

**/
EFI_STATUS
EFIAPI
DxePcdGetNextToken (
    IN CONST EFI_GUID         *Guid, OPTIONAL
    IN OUT   UINTN            *TokenNumber
)
{
    EFI_STATUS          Status;
    BOOLEAN             PeiExMapTableEmpty;
    BOOLEAN             DxeExMapTableEmpty;

    Status = EFI_NOT_FOUND;
    PeiExMapTableEmpty = PEI_EXMAP_TABLE_EMPTY;
    DxeExMapTableEmpty = DXE_EXMAP_TABLE_EMPTY;

    //
    // Scan the local token space
    //
    if (Guid == NULL) {
        // EBC compiler is very choosy. It may report warning about comparison
        // between UINTN and 0 . So we add 1 in each size of the
        // comparison.
        if (((*TokenNumber + 1 > PEI_NEX_TOKEN_NUMBER + 1) && (*TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1)) ||
                ((*TokenNumber + 1 > (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER + 1)))) {
            return EFI_NOT_FOUND;
        }

        (*TokenNumber)++;
        if ((*TokenNumber + 1 > PEI_NEX_TOKEN_NUMBER + 1) &&
                (*TokenNumber <= PEI_LOCAL_TOKEN_NUMBER)) {
            //
            // The first Non-Ex type Token Number for DXE PCD
            // database is PEI_LOCAL_TOKEN_NUMBER
            //
            *TokenNumber = PEI_LOCAL_TOKEN_NUMBER;
        } else if (*TokenNumber + 1 > DXE_NEX_TOKEN_NUMBER + PEI_LOCAL_TOKEN_NUMBER + 1) {
            *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
        }
        return EFI_SUCCESS;
    }

    if (PeiExMapTableEmpty && DxeExMapTableEmpty) {
        *TokenNumber = PCD_INVALID_TOKEN_NUMBER;
        return EFI_NOT_FOUND;
    }

    if (!PeiExMapTableEmpty) {
        Status = ExGetNextTokeNumber (
                     Guid,
                     TokenNumber,
                     mPcdDatabase->PeiDb.Init.GuidTable,
                     sizeof(mPcdDatabase->PeiDb.Init.GuidTable),
                     mPcdDatabase->PeiDb.Init.ExMapTable,
                     sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)
                 );
    }

    if (Status == EFI_SUCCESS) {
        return Status;
    }

    if (!DxeExMapTableEmpty) {
        Status = ExGetNextTokeNumber (
                     Guid,
                     TokenNumber,
                     mPcdDatabase->DxeDb.Init.GuidTable,
                     sizeof(mPcdDatabase->DxeDb.Init.GuidTable),
                     mPcdDatabase->DxeDb.Init.ExMapTable,
                     sizeof(mPcdDatabase->DxeDb.Init.ExMapTable)
                 );
    }

    return Status;
}