Service.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Help functions used by PCD DXE driver.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Service.h"
/**
Get the PCD entry pointer in PCD database.
This routine will visit PCD database to find the PCD entry according to given
token number. The given token number is autogened by build tools and it will be
translated to local token number. Local token number contains PCD's type and
offset of PCD entry in PCD database.
@param TokenNumber Token's number, it is autogened by build tools
@param GetSize The size of token's value
@return PCD entry pointer in PCD database
**/
VOID *
)
{
//
// Aquire lock to prevent reentrance from TPL_CALLBACK level
//
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
//
// PCD_TOTAL_TOKEN_NUMBER is a auto-generated constant.
// It could be zero. EBC compiler is very choosy. It may
// report warning. So we add 1 in each size of the
// comparison.
//
// 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 (GetSize == 0) {
} else {
}
LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize, IsPeiDb);
}
if (IsPeiDb) {
} else {
}
switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
break;
case PCD_TYPE_HII|PCD_TYPE_STRING:
case PCD_TYPE_HII:
if (IsPeiDb) {
} else {
}
//
// If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of
// string array in string table.
//
if (Status == EFI_SUCCESS) {
if (GetSize == 0) {
//
// It is a pointer type. So get the MaxSize reserved for
// this PCD entry.
//
}
}
} else {
if (Status == EFI_SUCCESS) {
if (GetSize == 0) {
//
// It is a pointer type. So get the MaxSize reserved for
// this PCD entry.
//
}
}
//
// If the operation is successful, we copy the data
// to the default value buffer in the PCD Database.
// So that we can free the Data allocated in GetHiiVariable.
//
//
// If the operation is not successful,
// Return 1) either the default value specified by Platform Integrator
// 2) Or the value Set by a PCD set operation.
//
}
break;
case PCD_TYPE_STRING:
break;
case PCD_TYPE_DATA:
break;
default:
break;
}
return RetPtr;
}
/**
Register the callback function for a PCD entry.
This routine will register a callback function to a PCD entry by given token number
and token space guid.
@param TokenNumber PCD token's number, it is autogened by build tools.
@param Guid PCD token space's guid,
if not NULL, this PCD is dynamicEx type PCD.
@param CallBackFunction Callback function pointer
@return EFI_SUCCESS Always success for registering callback function.
**/
)
{
}
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index of mCallbackFnTable[].
//
//
// We only allow a Callback function to be register once
// for a TokenNumber. So just return EFI_SUCCESS
//
return EFI_SUCCESS;
}
}
return EFI_SUCCESS;
}
/**
UnRegister the callback function for a PCD entry.
This routine will unregister a callback function to a PCD entry by given token number
and token space guid.
@param TokenNumber PCD token's number, it is autogened by build tools.
@param Guid PCD token space's guid.
if not NULL, this PCD is dynamicEx type PCD.
@param CallBackFunction Callback function pointer
@retval EFI_SUCCESS Callback function is success to be unregister.
@retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
**/
)
{
}
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index of mCallbackFnTable[].
//
//
// We only allow a Callback function to be register once
// for a TokenNumber. So we can safely remove the Node from
// the Link List and return EFI_SUCCESS.
//
return EFI_SUCCESS;
}
}
return EFI_INVALID_PARAMETER;
}
/**
Get next token number in given token space.
This routine is used for dynamicEx type PCD. It will firstly scan token space
table to get token space according to given token space guid. Then scan given
token number in found token space, if found, then return next token number in
this token space.
@param Guid Token space guid. Next token number will be scaned in
this token space.
@param TokenNumber Token number.
If PCD_INVALID_TOKEN_NUMBER, return first token number in
token space table.
If not PCD_INVALID_TOKEN_NUMBER, return next token number
in token space table.
@param GuidTable Token space guid table. It will be used for scan token space
by given token space guid.
@param SizeOfGuidTable The size of guid table.
@param ExMapTable DynamicEx token number mapping table.
@param SizeOfExMapTable The size of dynamicEx token number mapping table.
@retval EFI_NOT_FOUND Can not given token space or token number.
@retval EFI_SUCCESS Success to get next token number.
**/
)
{
//
// Scan token space guid
//
return EFI_NOT_FOUND;
}
//
// Find the token space table in dynamicEx mapping table.
//
break;
}
}
if (Found) {
//
// If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
// token number in found token space.
//
if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {
return EFI_SUCCESS;
}
Index ++;
if (Index == SizeOfExMapTable) {
//
// Exceed the length of ExMap Table
//
return EFI_SUCCESS;
//
// Found the next match
//
return EFI_SUCCESS;
} else {
//
// Guid has been changed. It is the next Token Space Guid.
// We should flag no more TokenNumber.
//
return EFI_SUCCESS;
}
}
}
}
return EFI_NOT_FOUND;
}
/**
Initialize the PCD database in DXE phase.
PCD database in DXE phase also contains PCD database in PEI phase which is copied
from GUID Hob.
**/
)
{
//
// We will copy over the PEI phase's PCD Database.
//
// If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
// should not be included at all. So the GuidHob could
// be NULL. If it is NULL, we just copy over the DXE Default
// Value to PCD Database.
//
//
// Copy PCD Entries refereneced in PEI phase to PCD DATABASE
//
}
//
// Copy PCD Entries with default value to PCD DATABASE
//
//
// Initialized the Callback Function Table
//
// 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.
}
}
/**
Get Variable which contains HII type PCD entry.
@param VariableGuid Variable's guid
@param VariableName Variable's unicode name string
@param VariableData Variable's data pointer,
@param VariableSize Variable's size.
@return the status of gRT->GetVariable
**/
)
{
Size = 0;
//
// Firstly get the real size of HII variable
//
(UINT16 *)VariableName,
NULL,
&Size,
);
//
// Allocate buffer to hold whole variable data according to variable size.
//
if (Status == EFI_BUFFER_TOO_SMALL) {
NULL,
&Size,
);
*VariableData = Buffer;
*VariableSize = Size;
}
return Status;
}
/**
Find the local token number according to system SKU ID.
@param LocalTokenNumber PCD token number
@param Size The size of PCD entry.
@param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
If False, the PCD entry is initialized in DXE phase.
@return Token number according to system SKU ID.
**/
)
{
//
// Find the current system's SKU ID entry in SKU ID table.
//
break;
}
}
switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
case PCD_TYPE_HII:
case PCD_TYPE_STRING:
case PCD_TYPE_DATA:
default:
}
return 0;
}
/**
Invoke the callback function when dynamic PCD entry was set, if this PCD entry
has registered callback function.
@param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
type PCD.
@param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
PCD.
@param TokenNumber PCD token number generated by build tools.
@param Data Value want to be set for this PCD entry
@param Size The size of value
**/
)
{
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index of mCallbackFnTable[].
//
Data,
Size);
}
return;
}
/**
Wrapper function for setting non-pointer type value for a PCD entry.
@param TokenNumber Pcd token number autogenerated by build tools.
@param Data Value want to be set for PCD entry
@param Size Size of value.
@return status of SetWorker.
**/
)
{
}
/**
Set value for an PCD entry
@param TokenNumber Pcd token number autogenerated by build tools.
@param Data Value want to be set for PCD entry
@param Size Size of value.
@param PtrType If TRUE, the type of PCD entry's value is Pointer.
If False, the type of PCD entry's value is not Pointer.
@retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
@retval EFI_INVALID_PARAMETER If Size can not be set to size table.
@retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
@retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
range of UINT8, UINT16, UINT32, UINT64
@retval EFI_NOT_FOUND Can not find the PCD type according to token number.
**/
)
{
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
//
// 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 (PtrType) {
//
// Get MaxSize first, then check new size with max buffer size.
//
return EFI_INVALID_PARAMETER;
}
} else {
return EFI_INVALID_PARAMETER;
}
}
//
// 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.
//
(TokenNumber + 1 >= PEI_LOCAL_TOKEN_NUMBER + 1 || TokenNumber + 1 < (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER + 1))) {
}
//
// Aquire lock to prevent reentrance from TPL_CALLBACK level
//
//
// 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 (PtrType) {
} else {
}
LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize, IsPeiDb);
}
if (IsPeiDb) {
} else {
}
switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
break;
case PCD_TYPE_STRING:
} else {
}
break;
case PCD_TYPE_HII|PCD_TYPE_STRING:
case PCD_TYPE_HII:
if (PtrType) {
break;
}
}
if (IsPeiDb) {
} else {
}
if (EFI_NOT_FOUND == Status) {
CopyMem (
Data,
*Size
);
} else {
}
}
break;
case PCD_TYPE_DATA:
if (PtrType) {
} else {
}
break;
}
switch (*Size) {
case sizeof(UINT8):
break;
case sizeof(UINT16):
break;
case sizeof(UINT32):
break;
case sizeof(UINT64):
break;
default:
break;
}
break;
default:
break;
}
return Status;
}
/**
Wrapper function for get PCD value for dynamic-ex PCD.
@param Guid Token space guid for dynamic-ex PCD.
@param ExTokenNumber Token number for dynamic-ex PCD.
@param GetSize The size of dynamic-ex PCD value.
@return PCD entry in PCD database.
**/
VOID *
)
{
}
/**
Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
@param ExTokenNumber Token number for dynamic-ex PCD.
@param Guid Token space guid for dynamic-ex PCD.
@param Data Value want to be set.
@param SetSize The size of value.
@return status of ExSetWorker().
**/
)
{
}
/**
Set value for a dynamic PCD entry.
This routine find the local token number according to dynamic-ex PCD's token
space guid and token number firstly, and invoke callback function if this PCD
entry registered callback function. Finally, invoken general SetWorker to set
PCD value.
@param ExTokenNumber Dynamic-ex PCD token number.
@param Guid Token space guid for dynamic-ex PCD.
@param Data PCD value want to be set
@param SetSize Size of value.
@param PtrType If TRUE, this PCD entry is pointer type.
If FALSE, this PCD entry is not pointer type.
@return status of SetWorker().
**/
)
{
}
/**
Set value for HII-type PCD.
HII-type PCD is to visit this variable.
@param VariableGuid Guid of variable which stored value of a HII-type PCD.
@param VariableName Unicode name of variable which stored value of a HII-type PCD.
@param Data Value want to be set.
@param DataSize Size of value
@param Offset Value offset of HII-type PCD in variable.
@return status of GetVariable()/SetVariable().
**/
)
{
Size = 0;
SetSize = 0;
//
// Try to get original variable size information.
//
(UINT16 *)VariableName,
NULL,
&Size,
);
if (Status == EFI_BUFFER_TOO_SMALL) {
//
// Patch new PCD's value to offset in given HII variable.
//
} else {
}
&Size,
);
);
return Status;
} else if (Status == EFI_NOT_FOUND) {
//
// If variable does not exist, a new variable need to be created.
//
Size,
);
return Status;
}
//
// If we drop to here, the value is failed to be written in to variable area
// So, we will save the data in the PCD Database's volatile area.
//
return Status;
}
/**
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 Dynamic-ex PCD token number.
@return local token number for dynamic-ex PCD.
**/
)
{
if (!PEI_DATABASE_EMPTY) {
}
}
}
}
//
// We need to ASSERT here. If GUID can't be found in GuidTable, this is a
// error in the BUILD system.
//
}
}
return 0;
}
/**
Get SKU ID table from PCD database.
@param LocalTokenNumberTableIdx Index of local token number in token number table.
@param IsPeiPcd If TRUE,
@return Pointer to SKU ID array table
**/
SKU_ID *
)
{
if (IsPeiPcd) {
} else {
LocalTokenNumber = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable[LocalTokenNumberTableIdx - PEI_LOCAL_TOKEN_NUMBER];
}
}
/**
Wrapper function of getting index of PCD entry in size table.
@param LocalTokenNumberTableIdx Index of this PCD in local token number table.
@param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
If FALSE, the pcd entry is initialized in DXE phase.
@return index of PCD entry in size table.
**/
)
{
if (IsPeiDb) {
} else {
}
SizeTableIdx = 0;
//
// SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
// PCD entry.
//
if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
//
// We have only one entry for VPD enabled PCD entry:
// 1) MAX Size.
// We consider current size is equal to MAX size.
//
SizeTableIdx++;
} else {
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
//
// We have only two entry for Non-Sku enabled PCD entry:
// 1) MAX SIZE
// 2) Current Size
//
SizeTableIdx += 2;
} else {
//
// We have these entry for SKU enabled PCD entry
// 1) MAX SIZE
// 2) Current Size for each SKU_ID (It is equal to MaxSku).
//
}
}
}
}
return SizeTableIdx;
}
/**
Get size of POINTER type PCD value.
@param LocalTokenNumberTableIdx Index of local token number in local token number table.
@param MaxSize Maxmium size of POINTER type PCD value.
@return size of POINTER type PCD value.
**/
)
{
// 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 (IsPeiDb) {
} else {
}
//
// SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
// PCD entry.
//
if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
//
// We have only one entry for VPD enabled PCD entry:
// 1) MAX Size.
// We consider current size is equal to MAX size.
//
return *MaxSize;
} else {
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
//
// We have only two entry for Non-Sku enabled PCD entry:
// 1) MAX SIZE
// 2) Current Size
//
} else {
//
// We have these entry for SKU enabled PCD entry
// 1) MAX SIZE
// 2) Current Size for each SKU_ID (It is equal to MaxSku).
//
}
}
}
}
}
/**
Set size of POINTER type PCD value. The size should not exceed the maximum size
of this PCD value.
@param LocalTokenNumberTableIdx Index of local token number in local token number table.
@param CurrentSize Size of POINTER type PCD value.
@retval TRUE Success to set size of PCD value.
@retval FALSE Fail to set size of PCD value.
**/
)
{
//
// 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 (IsPeiDb) {
} else {
}
//
// SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
// PCD entry.
//
if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
//
// We shouldn't come here as we don't support SET for VPD
//
return FALSE;
} else {
if ((*CurrentSize > MaxSize) ||
(*CurrentSize == MAX_ADDRESS)) {
*CurrentSize = MaxSize;
return FALSE;
}
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
//
// We have only two entry for Non-Sku enabled PCD entry:
// 1) MAX SIZE
// 2) Current Size
//
return TRUE;
} else {
//
// We have these entry for SKU enabled PCD entry
// 1) MAX SIZE
// 2) Current Size for each SKU_ID (It is equal to MaxSku).
//
return TRUE;
}
}
return TRUE;
}
}
}