2006-04-22 00:54:32 +02:00
|
|
|
/** @file
|
|
|
|
Private functions used by PCD DXE driver.s
|
|
|
|
|
|
|
|
Copyright (c) 2006, 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
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
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: Service.c
|
|
|
|
|
|
|
|
**/
|
|
|
|
#include "Service.h"
|
|
|
|
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
//
|
|
|
|
// Build Tool will generate DXE_PCD_DB_INIT_VALUE in Autogen.h
|
|
|
|
// Compression Algorithm will take care of the size optimization.
|
|
|
|
//
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
PCD_DATABASE * mPcdDatabase;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-02 09:03:06 +02:00
|
|
|
LIST_ENTRY *mCallbackFnTable;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
VOID *
|
2006-05-29 14:56:03 +02:00
|
|
|
GetWorker (
|
2006-06-07 14:31:33 +02:00
|
|
|
UINTN TokenNumber,
|
2006-05-29 14:56:03 +02:00
|
|
|
UINTN GetSize
|
|
|
|
)
|
2006-04-22 00:54:32 +02:00
|
|
|
{
|
2006-05-29 14:56:03 +02:00
|
|
|
UINT32 *LocalTokenNumberTable;
|
|
|
|
UINT16 *SizeTable;
|
|
|
|
BOOLEAN IsPeiDb;
|
|
|
|
UINTN Size;
|
2006-05-24 10:16:20 +02:00
|
|
|
UINT32 Offset;
|
|
|
|
EFI_GUID *GuidTable;
|
|
|
|
UINT16 *StringTable;
|
|
|
|
EFI_GUID *Guid;
|
|
|
|
UINT16 *Name;
|
|
|
|
VARIABLE_HEAD *VariableHead;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN DataSize;
|
|
|
|
VOID *Data;
|
|
|
|
VPD_HEAD *VpdHead;
|
|
|
|
UINT8 *PcdDb;
|
|
|
|
UINT16 StringTableIdx;
|
2006-05-29 14:56:03 +02:00
|
|
|
UINT32 LocalTokenNumber;
|
|
|
|
|
2006-06-23 06:30:23 +02:00
|
|
|
//
|
|
|
|
// 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--;
|
|
|
|
|
2006-05-29 14:56:03 +02:00
|
|
|
ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);
|
|
|
|
|
2006-06-23 06:30:23 +02:00
|
|
|
Size = DxePcdGetSize (TokenNumber + 1);
|
2006-05-29 14:56:03 +02:00
|
|
|
ASSERT (GetSize == Size || GetSize == 0);
|
2006-05-24 10:16:20 +02:00
|
|
|
|
2006-05-29 14:56:03 +02:00
|
|
|
|
2006-06-10 14:03:36 +02:00
|
|
|
IsPeiDb = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;
|
2006-05-29 14:56:03 +02:00
|
|
|
|
|
|
|
LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable :
|
|
|
|
mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
|
|
|
|
|
|
|
|
SizeTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.SizeTable:
|
|
|
|
mPcdDatabase->DxeDb.Init.SizeTable;
|
|
|
|
|
|
|
|
TokenNumber = IsPeiDb ? TokenNumber :
|
|
|
|
TokenNumber - PEI_LOCAL_TOKEN_NUMBER;
|
|
|
|
|
|
|
|
LocalTokenNumber = LocalTokenNumberTable[TokenNumber];
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
|
|
|
|
LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size, IsPeiDb);
|
|
|
|
}
|
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
PcdDb = IsPeiDb ? ((UINT8 *) &mPcdDatabase->PeiDb) : ((UINT8 *) &mPcdDatabase->DxeDb);
|
|
|
|
StringTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.StringTable :
|
|
|
|
mPcdDatabase->DxeDb.Init.StringTable;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
|
|
|
|
|
|
|
|
switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
|
|
|
|
case PCD_TYPE_VPD:
|
|
|
|
VpdHead = (VPD_HEAD *) ((UINT8 *) PcdDb + Offset);
|
2006-06-07 17:56:29 +02:00
|
|
|
return (VOID *) (UINTN) (FixedPcdGet32(PcdVpdBaseAddress) + VpdHead->Offset);
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
case PCD_TYPE_HII:
|
2006-05-29 03:48:32 +02:00
|
|
|
GuidTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.GuidTable :
|
|
|
|
mPcdDatabase->DxeDb.Init.GuidTable;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
VariableHead = (VARIABLE_HEAD *) (PcdDb + Offset);
|
|
|
|
|
|
|
|
Guid = &(GuidTable[VariableHead->GuidTableIndex]);
|
|
|
|
Name = &(StringTable[VariableHead->StringIndex]);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
|
2006-06-13 12:34:56 +02:00
|
|
|
if (Status == EFI_SUCCESS) {
|
|
|
|
ASSERT (DataSize >= (UINTN) (VariableHead->Offset + Size));
|
|
|
|
return (UINT8 *) Data + VariableHead->Offset;
|
|
|
|
} else {
|
|
|
|
//
|
2006-06-23 06:30:23 +02:00
|
|
|
// Return the default value specified by Platform Integrator
|
|
|
|
//
|
|
|
|
return (VOID *) ((UINT8 *) PcdDb + VariableHead->DefaultValueOffset);
|
|
|
|
}
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
case PCD_TYPE_STRING:
|
|
|
|
StringTableIdx = (UINT16) *((UINT8 *) PcdDb + Offset);
|
|
|
|
return (VOID *) &StringTable[StringTableIdx];
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
case PCD_TYPE_DATA:
|
|
|
|
return (VOID *) ((UINT8 *) PcdDb + Offset);
|
|
|
|
break;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
default:
|
|
|
|
ASSERT (FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
ASSERT (FALSE);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
2006-04-22 00:54:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
EFI_STATUS
|
|
|
|
DxeRegisterCallBackWorker (
|
2006-06-07 14:31:33 +02:00
|
|
|
IN UINTN TokenNumber,
|
2006-05-24 10:16:20 +02:00
|
|
|
IN CONST GUID *Guid, OPTIONAL
|
2006-05-29 03:48:32 +02:00
|
|
|
IN PCD_PROTOCOL_CALLBACK CallBackFunction
|
2006-05-24 10:16:20 +02:00
|
|
|
)
|
|
|
|
{
|
2006-05-29 03:48:32 +02:00
|
|
|
CALLBACK_FN_ENTRY *FnTableEntry;
|
|
|
|
LIST_ENTRY *ListHead;
|
|
|
|
LIST_ENTRY *ListNode;
|
|
|
|
|
|
|
|
if (Guid != NULL) {
|
2006-06-07 17:56:29 +02:00
|
|
|
TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) TokenNumber);
|
2006-05-29 03:48:32 +02:00
|
|
|
}
|
|
|
|
|
2006-06-23 06:30:23 +02:00
|
|
|
//
|
|
|
|
// 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--;
|
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
ListHead = &mCallbackFnTable[TokenNumber];
|
|
|
|
ListNode = GetFirstNode (ListHead);
|
|
|
|
|
|
|
|
while (ListNode != ListHead) {
|
|
|
|
FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);
|
|
|
|
|
|
|
|
if (FnTableEntry->CallbackFn == CallBackFunction) {
|
|
|
|
//
|
|
|
|
// We only allow a Callback function to be register once
|
|
|
|
// for a TokenNumber. So just return EFI_SUCCESS
|
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
ListNode = GetNextNode (ListHead, ListNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
FnTableEntry = AllocatePool (sizeof(CALLBACK_FN_ENTRY));
|
|
|
|
ASSERT (FnTableEntry != NULL);
|
|
|
|
|
|
|
|
FnTableEntry->CallbackFn = CallBackFunction;
|
|
|
|
InsertTailList (ListHead, &FnTableEntry->Node);
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
2006-04-22 00:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
EFI_STATUS
|
2006-05-29 03:48:32 +02:00
|
|
|
DxeUnRegisterCallBackWorker (
|
2006-06-07 14:31:33 +02:00
|
|
|
IN UINTN TokenNumber,
|
2006-05-29 03:48:32 +02:00
|
|
|
IN CONST GUID *Guid, OPTIONAL
|
|
|
|
IN PCD_PROTOCOL_CALLBACK CallBackFunction
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CALLBACK_FN_ENTRY *FnTableEntry;
|
|
|
|
LIST_ENTRY *ListHead;
|
|
|
|
LIST_ENTRY *ListNode;
|
|
|
|
|
|
|
|
if (Guid != NULL) {
|
2006-06-07 17:56:29 +02:00
|
|
|
TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) TokenNumber);
|
2006-05-29 03:48:32 +02:00
|
|
|
}
|
|
|
|
|
2006-06-23 06:30:23 +02:00
|
|
|
//
|
|
|
|
// 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--;
|
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
ListHead = &mCallbackFnTable[TokenNumber];
|
|
|
|
ListNode = GetFirstNode (ListHead);
|
|
|
|
|
|
|
|
while (ListNode != ListHead) {
|
|
|
|
FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);
|
|
|
|
|
|
|
|
if (FnTableEntry->CallbackFn == CallBackFunction) {
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
RemoveEntryList (ListNode);
|
|
|
|
FreePool (FnTableEntry);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
ListNode = GetNextNode (ListHead, ListNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-06-07 14:31:33 +02:00
|
|
|
UINTN
|
2006-05-29 03:48:32 +02:00
|
|
|
ExGetNextTokeNumber (
|
|
|
|
IN CONST EFI_GUID *Guid,
|
2006-06-07 14:31:33 +02:00
|
|
|
IN UINTN TokenNumber,
|
2006-05-29 03:48:32 +02:00
|
|
|
IN EFI_GUID *GuidTable,
|
|
|
|
IN UINTN SizeOfGuidTable,
|
|
|
|
IN DYNAMICEX_MAPPING *ExMapTable,
|
|
|
|
IN UINTN SizeOfExMapTable
|
2006-04-22 00:54:32 +02:00
|
|
|
)
|
|
|
|
{
|
2006-05-29 03:48:32 +02:00
|
|
|
EFI_GUID *MatchGuid;
|
|
|
|
UINTN Idx;
|
|
|
|
UINTN GuidTableIdx;
|
|
|
|
BOOLEAN Found;
|
|
|
|
|
|
|
|
MatchGuid = ScanGuid (GuidTable, SizeOfGuidTable, Guid);
|
|
|
|
if (MatchGuid == NULL) {
|
|
|
|
return PCD_INVALID_TOKEN_NUMBER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Found = FALSE;
|
|
|
|
GuidTableIdx = MatchGuid - GuidTable;
|
|
|
|
for (Idx = 0; Idx < SizeOfExMapTable; Idx++) {
|
|
|
|
if (ExMapTable[Idx].ExGuidIndex == GuidTableIdx) {
|
|
|
|
Found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Found) {
|
|
|
|
if (TokenNumber == PCD_INVALID_TOKEN_NUMBER) {
|
|
|
|
return ExMapTable[Idx].ExTokenNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( ; Idx < SizeOfExMapTable; Idx++) {
|
|
|
|
if (ExMapTable[Idx].ExTokenNumber == TokenNumber) {
|
|
|
|
Idx++;
|
|
|
|
if (Idx == SizeOfExMapTable) {
|
|
|
|
//
|
|
|
|
// Exceed the length of ExMap Table
|
|
|
|
//
|
|
|
|
return PCD_INVALID_TOKEN_NUMBER;
|
|
|
|
} else if (ExMapTable[Idx].ExGuidIndex == GuidTableIdx) {
|
|
|
|
//
|
|
|
|
// Found the next match
|
|
|
|
//
|
|
|
|
return ExMapTable[Idx].ExTokenNumber;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Guid has been changed. It is the next Token Space Guid.
|
|
|
|
// We should flag no more TokenNumber.
|
|
|
|
//
|
|
|
|
return PCD_INVALID_TOKEN_NUMBER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PCD_INVALID_TOKEN_NUMBER;
|
2006-04-22 00:54:32 +02:00
|
|
|
}
|
2006-05-29 03:48:32 +02:00
|
|
|
|
2006-04-22 00:54:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
VOID
|
|
|
|
BuildPcdDxeDataBase (
|
|
|
|
VOID
|
2006-06-07 14:31:33 +02:00
|
|
|
)
|
2006-04-22 00:54:32 +02:00
|
|
|
{
|
2006-05-24 10:16:20 +02:00
|
|
|
PEI_PCD_DATABASE *PeiDatabase;
|
|
|
|
EFI_HOB_GUID_TYPE *GuidHob;
|
2006-05-29 03:48:32 +02:00
|
|
|
UINTN Idx;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
mPcdDatabase = AllocateZeroPool (sizeof(PCD_DATABASE));
|
|
|
|
ASSERT (mPcdDatabase != NULL);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
GuidHob = GetFirstGuidHob (&gPcdDataBaseHobGuid);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-02 07:28:18 +02:00
|
|
|
if (GuidHob != NULL) {
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
|
|
|
|
PeiDatabase = (PEI_PCD_DATABASE *) GET_GUID_HOB_DATA (GuidHob);
|
|
|
|
//
|
|
|
|
// Copy PCD Entries refereneced in PEI phase to PCD DATABASE
|
|
|
|
//
|
|
|
|
CopyMem (&mPcdDatabase->PeiDb, PeiDatabase, sizeof (PEI_PCD_DATABASE));
|
|
|
|
}
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Copy PCD Entries with default value to PCD DATABASE
|
|
|
|
//
|
2006-05-29 03:48:32 +02:00
|
|
|
CopyMem (&mPcdDatabase->DxeDb.Init, &gDXEPcdDbInit, sizeof(DXE_PCD_DATABASE_INIT));
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialized the Callback Function Table
|
|
|
|
//
|
2006-06-02 09:03:06 +02:00
|
|
|
|
|
|
|
if (PCD_TOTAL_TOKEN_NUMBER != 0) {
|
2006-06-07 14:31:33 +02:00
|
|
|
mCallbackFnTable = AllocateZeroPool (PCD_TOTAL_TOKEN_NUMBER * sizeof (LIST_ENTRY));
|
2006-06-02 09:03:06 +02:00
|
|
|
}
|
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
for (Idx = 0; Idx < PCD_TOTAL_TOKEN_NUMBER; Idx++) {
|
|
|
|
InitializeListHead (&mCallbackFnTable[Idx]);
|
|
|
|
}
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
return;
|
2006-04-22 00:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
EFI_STATUS
|
|
|
|
GetHiiVariable (
|
|
|
|
IN EFI_GUID *VariableGuid,
|
|
|
|
IN UINT16 *VariableName,
|
|
|
|
OUT VOID ** VariableData,
|
|
|
|
OUT UINTN *VariableSize
|
2006-04-22 00:54:32 +02:00
|
|
|
)
|
|
|
|
{
|
2006-05-24 10:16:20 +02:00
|
|
|
UINTN Size;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
VOID *Buffer;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-23 06:30:23 +02:00
|
|
|
Size = 0;
|
|
|
|
Buffer = NULL;
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
Status = EfiGetVariable (
|
|
|
|
(UINT16 *)VariableName,
|
|
|
|
VariableGuid,
|
|
|
|
NULL,
|
|
|
|
&Size,
|
2006-06-23 06:30:23 +02:00
|
|
|
Buffer
|
2006-05-24 10:16:20 +02:00
|
|
|
);
|
2006-06-23 06:30:23 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
Buffer = AllocatePool (Size);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
ASSERT (Buffer != NULL);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
Status = EfiGetVariable (
|
|
|
|
VariableName,
|
|
|
|
VariableGuid,
|
|
|
|
NULL,
|
|
|
|
&Size,
|
|
|
|
Buffer
|
|
|
|
);
|
|
|
|
|
|
|
|
ASSERT (Status == EFI_SUCCESS);
|
|
|
|
}
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-23 06:30:23 +02:00
|
|
|
*VariableData = Buffer;
|
|
|
|
*VariableSize = Size;
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
return Status;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
UINT32
|
|
|
|
GetSkuEnabledTokenNumber (
|
|
|
|
UINT32 LocalTokenNumber,
|
|
|
|
UINTN Size,
|
|
|
|
BOOLEAN IsPeiDb
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SKU_HEAD *SkuHead;
|
|
|
|
SKU_ID *SkuIdTable;
|
|
|
|
INTN i;
|
|
|
|
UINT8 *Value;
|
|
|
|
SKU_ID *PhaseSkuIdTable;
|
|
|
|
UINT8 *PcdDb;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
PcdDb = IsPeiDb ? (UINT8 *) &mPcdDatabase->PeiDb : (UINT8 *) &mPcdDatabase->DxeDb;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
SkuHead = (SKU_HEAD *) (PcdDb + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));
|
|
|
|
Value = (UINT8 *) (PcdDb + SkuHead->SkuDataStartOffset);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
PhaseSkuIdTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.SkuIdTable :
|
|
|
|
mPcdDatabase->DxeDb.Init.SkuIdTable;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
SkuIdTable = &PhaseSkuIdTable[SkuHead->SkuIdTableOffset];
|
|
|
|
|
|
|
|
for (i = 0; i < SkuIdTable[0]; i++) {
|
2006-05-29 03:48:32 +02:00
|
|
|
if (mPcdDatabase->PeiDb.Init.SystemSkuId == SkuIdTable[i + 1]) {
|
2006-05-24 10:16:20 +02:00
|
|
|
break;
|
2006-04-22 00:54:32 +02:00
|
|
|
}
|
|
|
|
}
|
2006-05-24 10:16:20 +02:00
|
|
|
ASSERT (i < SkuIdTable[0]);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
|
|
|
|
case PCD_TYPE_VPD:
|
|
|
|
Value = (UINT8 *) &(((VPD_HEAD *) Value)[i]);
|
2006-06-07 17:56:29 +02:00
|
|
|
return (UINT32) ((Value - PcdDb) | PCD_TYPE_VPD);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
case PCD_TYPE_HII:
|
|
|
|
Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[i]);
|
2006-06-07 17:56:29 +02:00
|
|
|
return (UINT32) ((Value - PcdDb) | PCD_TYPE_HII);
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
case PCD_TYPE_DATA:
|
|
|
|
Value += Size * i;
|
2006-06-07 17:56:29 +02:00
|
|
|
return (UINT32) (Value - PcdDb);
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT (FALSE);
|
|
|
|
|
|
|
|
return 0;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
VOID
|
|
|
|
InvokeCallbackOnSet (
|
|
|
|
UINT32 ExTokenNumber,
|
|
|
|
CONST EFI_GUID *Guid, OPTIONAL
|
|
|
|
UINTN TokenNumber,
|
|
|
|
VOID *Data,
|
|
|
|
UINTN Size
|
|
|
|
)
|
|
|
|
{
|
2006-05-29 03:48:32 +02:00
|
|
|
CALLBACK_FN_ENTRY *FnTableEntry;
|
|
|
|
LIST_ENTRY *ListHead;
|
|
|
|
LIST_ENTRY *ListNode;
|
|
|
|
|
2006-06-23 06:30:23 +02:00
|
|
|
//
|
|
|
|
// 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--;
|
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
ListHead = &mCallbackFnTable[TokenNumber];
|
|
|
|
ListNode = GetFirstNode (ListHead);
|
|
|
|
|
|
|
|
while (ListNode != ListHead) {
|
|
|
|
FnTableEntry = CR_FNENTRY_FROM_LISTNODE(ListNode, CALLBACK_FN_ENTRY, Node);
|
|
|
|
|
|
|
|
FnTableEntry->CallbackFn(Guid,
|
|
|
|
(Guid == NULL) ? TokenNumber : ExTokenNumber,
|
|
|
|
Data,
|
|
|
|
Size);
|
|
|
|
|
|
|
|
ListNode = GetNextNode (ListHead, ListNode);
|
|
|
|
}
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
return;
|
2006-04-22 00:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
|
2006-04-22 00:54:32 +02:00
|
|
|
EFI_STATUS
|
2006-05-24 10:16:20 +02:00
|
|
|
SetWorker (
|
2006-06-07 14:31:33 +02:00
|
|
|
UINTN TokenNumber,
|
2006-05-29 12:42:13 +02:00
|
|
|
VOID *Data,
|
|
|
|
UINTN Size,
|
|
|
|
BOOLEAN PtrType
|
2006-04-22 00:54:32 +02:00
|
|
|
)
|
|
|
|
{
|
2006-05-24 10:16:20 +02:00
|
|
|
UINT32 *LocalTokenNumberTable;
|
|
|
|
BOOLEAN IsPeiDb;
|
2006-05-29 14:56:03 +02:00
|
|
|
UINT32 LocalTokenNumber;
|
|
|
|
EFI_GUID *GuidTable;
|
|
|
|
UINT16 *StringTable;
|
|
|
|
EFI_GUID *Guid;
|
|
|
|
UINT16 *Name;
|
2006-06-13 12:34:56 +02:00
|
|
|
UINTN VariableOffset;
|
2006-05-29 14:56:03 +02:00
|
|
|
VOID *InternalData;
|
|
|
|
VARIABLE_HEAD *VariableHead;
|
|
|
|
UINTN Offset;
|
|
|
|
UINT8 *PcdDb;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-23 06:30:23 +02:00
|
|
|
//
|
|
|
|
// 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--;
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
if (PtrType) {
|
2006-06-23 06:30:23 +02:00
|
|
|
ASSERT (Size <= DxePcdGetSize (TokenNumber + 1));
|
2006-05-24 10:16:20 +02:00
|
|
|
} else {
|
2006-06-23 06:30:23 +02:00
|
|
|
ASSERT (Size == DxePcdGetSize (TokenNumber + 1));
|
2006-04-22 00:54:32 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 14:03:36 +02:00
|
|
|
IsPeiDb = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable :
|
|
|
|
mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 14:56:03 +02:00
|
|
|
if ((TokenNumber < PEI_NEX_TOKEN_NUMBER) ||
|
|
|
|
(TokenNumber >= PEI_LOCAL_TOKEN_NUMBER || TokenNumber < (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER))) {
|
2006-06-23 06:30:23 +02:00
|
|
|
InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, Size);
|
2006-05-29 14:56:03 +02:00
|
|
|
}
|
2006-05-29 12:42:13 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
TokenNumber = IsPeiDb ? TokenNumber
|
|
|
|
: TokenNumber - PEI_LOCAL_TOKEN_NUMBER;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 14:56:03 +02:00
|
|
|
LocalTokenNumber = LocalTokenNumberTable[TokenNumber];
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
|
|
|
|
LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size, IsPeiDb);
|
|
|
|
}
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
PcdDb = IsPeiDb ? ((UINT8 *) &mPcdDatabase->PeiDb) : ((UINT8 *) &mPcdDatabase->DxeDb);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
StringTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.StringTable :
|
|
|
|
mPcdDatabase->DxeDb.Init.StringTable;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
InternalData = PcdDb + Offset;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
|
|
|
|
case PCD_TYPE_VPD:
|
|
|
|
ASSERT (FALSE);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
case PCD_TYPE_STRING:
|
|
|
|
CopyMem (&StringTable[*((UINT16 *)InternalData)], Data, Size);
|
2006-06-13 12:34:56 +02:00
|
|
|
return EFI_SUCCESS;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
case PCD_TYPE_HII:
|
|
|
|
//
|
|
|
|
// Bug Bug: Please implement this
|
|
|
|
//
|
2006-05-29 03:48:32 +02:00
|
|
|
GuidTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.GuidTable :
|
|
|
|
mPcdDatabase->DxeDb.Init.GuidTable;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
VariableHead = (VARIABLE_HEAD *) (PcdDb + Offset);
|
|
|
|
|
|
|
|
Guid = &(GuidTable[VariableHead->GuidTableIndex]);
|
|
|
|
Name = &(StringTable[VariableHead->StringIndex]);
|
2006-06-13 12:34:56 +02:00
|
|
|
VariableOffset = VariableHead->Offset;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
return SetHiiVariable (Guid, Name, Data, Size, VariableOffset);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
case PCD_TYPE_DATA:
|
|
|
|
if (PtrType) {
|
|
|
|
CopyMem (InternalData, Data, Size);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
switch (Size) {
|
|
|
|
case sizeof(UINT8):
|
|
|
|
*((UINT8 *) InternalData) = *((UINT8 *) Data);
|
|
|
|
return EFI_SUCCESS;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
case sizeof(UINT16):
|
|
|
|
*((UINT16 *) InternalData) = *((UINT16 *) Data);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
case sizeof(UINT32):
|
|
|
|
*((UINT32 *) InternalData) = *((UINT32 *) Data);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
case sizeof(UINT64):
|
|
|
|
*((UINT64 *) InternalData) = *((UINT64 *) Data);
|
|
|
|
return EFI_SUCCESS;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
default:
|
|
|
|
ASSERT (FALSE);
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT (FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT (FALSE);
|
|
|
|
return EFI_NOT_FOUND;
|
2006-04-22 00:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-29 14:56:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
VOID *
|
|
|
|
ExGetWorker (
|
|
|
|
IN CONST EFI_GUID *Guid,
|
|
|
|
IN UINTN ExTokenNumber,
|
|
|
|
IN UINTN GetSize
|
|
|
|
)
|
|
|
|
{
|
2006-06-07 17:56:29 +02:00
|
|
|
return GetWorker(GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber), GetSize);
|
2006-05-29 14:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
ExSetWorker (
|
2006-06-07 14:31:33 +02:00
|
|
|
IN UINTN ExTokenNumber,
|
2006-05-29 14:56:03 +02:00
|
|
|
IN CONST EFI_GUID *Guid,
|
|
|
|
VOID *Data,
|
|
|
|
UINTN SetSize,
|
|
|
|
BOOLEAN PtrType
|
|
|
|
)
|
|
|
|
{
|
2006-06-07 14:31:33 +02:00
|
|
|
UINTN TokenNumber;
|
2006-05-29 14:56:03 +02:00
|
|
|
|
2006-06-07 17:56:29 +02:00
|
|
|
TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber);
|
2006-05-29 14:56:03 +02:00
|
|
|
|
2006-06-07 17:56:29 +02:00
|
|
|
InvokeCallbackOnSet ((UINT32) ExTokenNumber, Guid, TokenNumber, Data, SetSize);
|
2006-05-29 14:56:03 +02:00
|
|
|
|
|
|
|
SetWorker (TokenNumber, Data, SetSize, PtrType);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-22 00:54:32 +02:00
|
|
|
EFI_STATUS
|
|
|
|
SetHiiVariable (
|
|
|
|
IN EFI_GUID *VariableGuid,
|
|
|
|
IN UINT16 *VariableName,
|
|
|
|
IN CONST VOID *Data,
|
|
|
|
IN UINTN DataSize,
|
|
|
|
IN UINTN Offset
|
|
|
|
)
|
|
|
|
{
|
2006-05-24 10:16:20 +02:00
|
|
|
UINTN Size;
|
|
|
|
VOID *Buffer;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 Attribute;
|
2006-04-22 00:54:32 +02:00
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
|
|
|
|
Status = EfiGetVariable (
|
|
|
|
(UINT16 *)VariableName,
|
|
|
|
VariableGuid,
|
2006-05-24 10:16:20 +02:00
|
|
|
&Attribute,
|
2006-04-22 00:54:32 +02:00
|
|
|
&Size,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
Buffer = AllocatePool (Size);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
ASSERT (Buffer != NULL);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
Status = EfiGetVariable (
|
|
|
|
VariableName,
|
|
|
|
VariableGuid,
|
|
|
|
&Attribute,
|
|
|
|
&Size,
|
|
|
|
Buffer
|
|
|
|
);
|
|
|
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-06-13 12:34:56 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
Attribute = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
|
|
|
|
Size = DataSize + Offset;
|
|
|
|
Buffer = AllocateZeroPool (Size);
|
|
|
|
ASSERT (Buffer != NULL);
|
|
|
|
CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);
|
|
|
|
|
|
|
|
}
|
2006-04-22 00:54:32 +02:00
|
|
|
|
|
|
|
return EfiSetVariable (
|
2006-06-13 12:34:56 +02:00
|
|
|
VariableName,
|
|
|
|
VariableGuid,
|
|
|
|
Attribute,
|
|
|
|
Size,
|
|
|
|
Buffer
|
|
|
|
);
|
2006-04-22 00:54:32 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-06-07 14:31:33 +02:00
|
|
|
UINTN
|
2006-05-29 14:56:03 +02:00
|
|
|
GetExPcdTokenNumber (
|
2006-05-24 10:16:20 +02:00
|
|
|
IN CONST EFI_GUID *Guid,
|
2006-06-07 17:56:29 +02:00
|
|
|
IN UINT32 ExTokenNumber
|
2006-05-24 10:16:20 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 i;
|
|
|
|
DYNAMICEX_MAPPING *ExMap;
|
|
|
|
EFI_GUID *GuidTable;
|
2006-05-29 14:56:03 +02:00
|
|
|
EFI_GUID *MatchGuid;
|
|
|
|
UINTN MatchGuidIdx;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
ExMap = mPcdDatabase->PeiDb.Init.ExMapTable;
|
|
|
|
GuidTable = mPcdDatabase->PeiDb.Init.GuidTable;
|
2006-05-29 14:56:03 +02:00
|
|
|
|
|
|
|
MatchGuid = ScanGuid (GuidTable, sizeof(mPcdDatabase->PeiDb.Init.GuidTable), Guid);
|
|
|
|
ASSERT (MatchGuid != NULL);
|
|
|
|
|
|
|
|
MatchGuidIdx = MatchGuid - GuidTable;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {
|
|
|
|
if ((ExTokenNumber == ExMap[i].ExTokenNumber) &&
|
2006-05-29 14:56:03 +02:00
|
|
|
(MatchGuidIdx == ExMap[i].ExGuidIndex)) {
|
|
|
|
return ExMap[i].LocalTokenNumber;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-29 03:48:32 +02:00
|
|
|
ExMap = mPcdDatabase->DxeDb.Init.ExMapTable;
|
|
|
|
GuidTable = mPcdDatabase->DxeDb.Init.GuidTable;
|
2006-05-29 14:56:03 +02:00
|
|
|
|
|
|
|
MatchGuid = ScanGuid (GuidTable, sizeof(mPcdDatabase->DxeDb.Init.GuidTable), Guid);
|
|
|
|
ASSERT (MatchGuid != NULL);
|
|
|
|
|
|
|
|
MatchGuidIdx = MatchGuid - GuidTable;
|
2006-05-24 10:16:20 +02:00
|
|
|
|
|
|
|
for (i = 0; i < DXE_EXMAPPING_TABLE_SIZE; i++) {
|
|
|
|
if ((ExTokenNumber == ExMap[i].ExTokenNumber) &&
|
2006-05-29 14:56:03 +02:00
|
|
|
(MatchGuidIdx == ExMap[i].ExGuidIndex)) {
|
|
|
|
return ExMap[i].LocalTokenNumber + PEI_LOCAL_TOKEN_NUMBER;
|
2006-05-24 10:16:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT (FALSE);
|
|
|
|
|
2006-05-29 14:56:03 +02:00
|
|
|
return 0;
|
2006-05-24 10:16:20 +02:00
|
|
|
}
|
|
|
|
|