3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 Platform Configuration Database (PCD) Service PEIM
20 #include <PcdEmulator.h>
23 // BugBug: PEI early phase does not support global variable!!!
24 // This is only a temperary solution.
30 STATIC EMULATED_PCD_DATABASE_EX
*
34 EFI_HOB_GUID_TYPE
*GuidHob
;
35 EMULATED_PCD_DATABASE_EX
*EmulatedPcdDatabaseEx
;
37 GuidHob
= GetFirstGuidHob (&gPcdHobGuid
);
38 EmulatedPcdDatabaseEx
= (EMULATED_PCD_DATABASE_EX
*) GET_GUID_HOB_DATA(GuidHob
);
40 return EmulatedPcdDatabaseEx
;
44 GetPcdDataBaseExEntryCount (
45 EMULATED_PCD_DATABASE_EX
* Database
47 return Database
->Count
;
51 GetPcdDataBaseExSize (
52 EMULATED_PCD_DATABASE_EX
* Database
56 Size
= sizeof (Database
->Count
)
57 + (sizeof (Database
->Entry
[0]) * Database
->Count
);
78 EMULATED_PCD_ENTRY_EX
*Pcd
;
80 Pcd
= GetPcdEntry (TokenNumber
);
82 ASSERT (Pcd
->DatumSize
== 1);
84 return (UINT8
)Pcd
->Datum
;
93 EMULATED_PCD_ENTRY_EX
*Pcd
;
95 Pcd
= GetPcdEntry (TokenNumber
);
97 ASSERT (Pcd
->DatumSize
== 2);
99 return (UINT16
)Pcd
->Datum
;
108 EMULATED_PCD_ENTRY_EX
*Pcd
;
110 Pcd
= GetPcdEntry (TokenNumber
);
111 ASSERT (Pcd
!= NULL
);
112 ASSERT (Pcd
->DatumSize
== 4);
114 return (UINT32
)Pcd
->Datum
;
123 EMULATED_PCD_ENTRY_EX
*Pcd
;
125 Pcd
= GetPcdEntry (TokenNumber
);
126 ASSERT (Pcd
!= NULL
);
127 ASSERT (Pcd
->DatumSize
== sizeof (UINT64
));
129 return (UINT64
)Pcd
->Datum
;
138 EMULATED_PCD_ENTRY_EX
*Pcd
;
140 Pcd
= GetPcdEntry (TokenNumber
);
141 ASSERT (Pcd
!= NULL
);
143 return (VOID
*)(UINTN
)Pcd
->ExtendedData
;
148 PcdEmulatorGetBoolean (
152 EMULATED_PCD_ENTRY_EX
*Pcd
;
154 Pcd
= GetPcdEntry (TokenNumber
);
155 ASSERT (Pcd
!= NULL
);
156 ASSERT (Pcd
->DatumSize
== 1);
158 return (BOOLEAN
)Pcd
->Datum
;
167 EMULATED_PCD_ENTRY_EX
*Pcd
;
169 Pcd
= GetPcdEntry (TokenNumber
);
170 ASSERT (Pcd
!= NULL
);
171 return Pcd
->DatumSize
;
177 IN CONST EFI_GUID
*PcdDataBaseName
,
188 IN CONST EFI_GUID
*PcdDataBaseName
,
199 IN CONST EFI_GUID
*PcdDataBaseName
,
210 IN CONST EFI_GUID
*PcdDataBaseName
,
220 PcdEmulatorGetPtrEx (
221 IN CONST EFI_GUID
*PcdDataBaseName
,
231 PcdEmulatorGetBooleanEx (
232 IN CONST EFI_GUID
*PcdDataBaseName
,
242 PcdEmulatorGetSizeEx (
243 IN CONST EFI_GUID
*PcdDataBaseName
,
247 EMULATED_PCD_ENTRY_EX
*Pcd
;
249 Pcd
= GetPcdEntry (TokenNumber
);
250 ASSERT (Pcd
!= NULL
);
251 return Pcd
->DatumSize
;
258 IN UINTN TokenNumber
,
263 EMULATED_PCD_ENTRY_EX
*Pcd
;
265 Pcd
= GetPcdEntry (TokenNumber
);
266 ASSERT (Pcd
!= NULL
);
268 ASSERT (Pcd
->DatumSize
== sizeof (UINT8
));
278 IN UINTN TokenNumber
,
291 IN UINTN TokenNumber
,
296 EMULATED_PCD_ENTRY_EX
*Pcd
;
298 Pcd
= GetPcdEntry (TokenNumber
);
299 ASSERT (Pcd
!= NULL
);
301 ASSERT (Pcd
->DatumSize
== sizeof (UINT32
));
311 IN UINTN TokenNumber
,
324 IN UINTN TokenNumber
,
336 PcdEmulatorSetBoolean (
337 IN UINTN TokenNumber
,
350 IN CONST EFI_GUID
*Guid
,
351 IN UINTN TokenNumber
,
364 IN CONST EFI_GUID
*Guid
,
365 IN UINTN TokenNumber
,
378 IN CONST EFI_GUID
*Guid
,
379 IN UINTN TokenNumber
,
392 IN CONST EFI_GUID
*Guid
,
393 IN UINTN TokenNumber
,
405 PcdEmulatorSetPtrEx (
406 IN CONST EFI_GUID
*Guid
,
407 IN UINTN TokenNumber
,
419 PcdEmulatorSetBooleanEx (
420 IN CONST EFI_GUID
*Guid
,
421 IN UINTN TokenNumber
,
433 PcdEmulatorCallBackOnSet (
434 IN UINTN TokenNumber
,
435 IN CONST EFI_GUID
*Guid
, OPTIONAL
436 IN PCD_PPI_CALLBACK CallBackFunction
439 EMULATED_PCD_ENTRY_EX
*Pcd
;
441 Pcd
= GetPcdEntry (TokenNumber
);
442 ASSERT (Pcd
!= NULL
);
444 if (Pcd
->CallBackListSize
== Pcd
->CallBackEntries
) {
445 return EFI_OUT_OF_RESOURCES
;
448 Pcd
->CallBackList
[Pcd
->CallBackEntries
++] = CallBackFunction
;
455 PcdEmulatorUnregisterCallBackOnSet (
456 IN UINTN TokenNumber
,
457 IN CONST EFI_GUID
*Guid
, OPTIONAL
458 IN PCD_PPI_CALLBACK CallBackfunction
461 EMULATED_PCD_ENTRY_EX
*Pcd
;
464 Pcd
= GetPcdEntry (TokenNumber
);
465 ASSERT (Pcd
!= NULL
);
467 for (Index
= 0; Index
< Pcd
->CallBackListSize
; Index
++) {
468 if (Pcd
->CallBackList
[Index
] == CallBackfunction
) {
469 Pcd
->CallBackList
[Index
] = NULL
;
474 return EFI_NOT_FOUND
;
479 PcdEmulatorGetNextToken (
480 IN CONST EFI_GUID
*Guid
, OPTIONAL
484 EMULATED_PCD_ENTRY_EX
*Pcd
;
485 EMULATED_PCD_ENTRY_EX
*LastPcdEntry
;
486 EMULATED_PCD_DATABASE_EX
*PcdDatabase
;
487 EMULATED_PCD_ENTRY_EX
*PcdEntry
;
489 PcdDatabase
= GetPcdDataBaseEx ();
490 PcdEntry
= PcdDatabase
->Entry
;
492 if (*Token
== PCD_INVALID_TOKEN
) {
494 // BugBug: Due to variable size array, ensure we convert this to a reasonable database
495 // that can accomodate array references for simplicity's sake
496 *Token
= PcdEntry
[0].Token
;
500 Pcd
= GetPcdEntry (*Token
);
502 return EFI_NOT_FOUND
;
505 LastPcdEntry
= PcdEntry
+ GetPcdDataBaseExEntryCount (PcdDatabase
);
506 if (++Pcd
>= LastPcdEntry
) {
507 return EFI_NOT_FOUND
;
514 PCD_PPI mPcdPpiInstance
= {
522 PcdEmulatorGetBoolean
,
530 PcdEmulatorGetBooleanEx
,
531 PcdEmulatorGetSizeEx
,
538 PcdEmulatorSetBoolean
,
545 PcdEmulatorSetBooleanEx
,
547 PcdEmulatorCallBackOnSet
,
548 PcdEmulatorUnregisterCallBackOnSet
,
549 PcdEmulatorGetNextToken
552 STATIC EFI_PEI_PPI_DESCRIPTOR mPpiPCD
= {
553 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
560 PeimPcdEmulatorEntry (
561 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
562 IN EFI_PEI_SERVICES
**PeiServices
569 UINT8
*AllocatedBuffer
;
570 EMULATED_PCD_DATABASE_EX
*EmulatedPcdDatabaseEx
;
571 EMULATED_PCD_ENTRY_EX
*EmulatedPcdEntryEx
;
574 // BugBug: Normally, we would read an FFS file for this data
575 // We need to remember, that when we read the FFS file, items such as the VariableName will not be encoded as a pointer
576 // but as an array of content. In this emulation, our init is encoding this data as a pointer.
577 // In the FFS version, we will depend on the proper Entry Count in the FFS data since the structures will
578 // now be variable length.
583 // We should now read from the FFS file into the cache - for now, we fake this.
585 Count
= GetPcdDataBaseSize () / sizeof (EMULATED_PCD_ENTRY
);
588 // Let's now determine how big of a buffer we need for our database
589 // For the FFS version, we need to calculate/consider the VariableName/ExtendedData size!!!
591 Calculation
= sizeof (UINTN
) + (Count
* sizeof (EMULATED_PCD_ENTRY_EX
));
593 EmulatedPcdDatabaseEx
= (EMULATED_PCD_DATABASE_EX
*) BuildGuidHob (&gPcdHobGuid
, Calculation
);
595 EmulatedPcdDatabaseEx
->Count
= Count
;
596 EmulatedPcdEntryEx
= EmulatedPcdDatabaseEx
->Entry
;
598 AllocatedBuffer
= AllocatePool (Count
* sizeof (PCD_PPI_CALLBACK
) * MAX_PCD_CALLBACK
);
599 ASSERT (AllocatedBuffer
!= NULL
);
601 for (Index
= 0; Index
< Count
; Index
++) {
603 // Copy from source to our own allocated buffer - normally an FFS read
605 (*PeiServices
)->CopyMem (
606 (VOID
*) (EmulatedPcdEntryEx
+ Index
),
607 (VOID
*) (gEmulatedPcdEntry
+ Index
),
608 sizeof (EMULATED_PCD_ENTRY
)
612 // All the CallBackList worker functions refer to this CallBackList as CallBackList[CallbackEntry]
613 // so we seed the same buffer address here.
615 EmulatedPcdEntryEx
[Index
].CallBackList
= (PCD_PPI_CALLBACK
*)AllocatedBuffer
;
616 AllocatedBuffer
+= (sizeof (PCD_PPI_CALLBACK
) * MAX_PCD_CALLBACK
);
617 EmulatedPcdEntryEx
[Index
].CallBackEntries
= 0;
618 EmulatedPcdEntryEx
[Index
].CallBackListSize
= MAX_PCD_CALLBACK
;
622 // Install PCD service PPI
624 Status
= PeiCoreInstallPpi (&mPpiPCD
);
626 ASSERT_EFI_ERROR (Status
);
631 EMULATED_PCD_ENTRY_EX
*
638 EMULATED_PCD_DATABASE_EX
*EmulatedPcdDatabaseEx
;
639 EMULATED_PCD_ENTRY_EX
*EmulatedPcdEntryEx
;
643 EmulatedPcdDatabaseEx
= GetPcdDataBaseEx ();
645 // BugBug: This Count will change when we flip over to FFS version
647 Count
= EmulatedPcdDatabaseEx
->Count
;
648 EmulatedPcdEntryEx
= EmulatedPcdDatabaseEx
->Entry
;
649 for (Index
= 0; Index
< Count
; Index
++) {
650 if (EmulatedPcdEntryEx
[Index
].Token
== TokenNumber
) {
651 return &EmulatedPcdEntryEx
[Index
];