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) Protocol
20 #include <PcdEmulator.h>
25 GetPcdDataEntryCount (
28 return gEmulatedPcdDatabaseEx
->Count
;
47 EMULATED_PCD_ENTRY_EX
*Pcd
;
49 Pcd
= GetPcdEntry (TokenNumber
);
51 ASSERT (Pcd
->DatumSize
== 1);
53 return (UINT8
)Pcd
->Datum
;
62 EMULATED_PCD_ENTRY_EX
*Pcd
;
64 Pcd
= GetPcdEntry (TokenNumber
);
66 ASSERT (Pcd
->DatumSize
== 2);
68 return (UINT16
)Pcd
->Datum
;
77 EMULATED_PCD_ENTRY_EX
*Pcd
;
79 Pcd
= GetPcdEntry (TokenNumber
);
81 ASSERT (Pcd
->DatumSize
== 4);
83 return (UINT32
)Pcd
->Datum
;
92 EMULATED_PCD_ENTRY_EX
*Pcd
;
94 Pcd
= GetPcdEntry (TokenNumber
);
96 ASSERT (Pcd
->DatumSize
== sizeof (UINT64
));
98 return (UINT64
)Pcd
->Datum
;
107 EMULATED_PCD_ENTRY_EX
*Pcd
;
109 Pcd
= GetPcdEntry (TokenNumber
);
110 ASSERT (Pcd
!= NULL
);
112 return (VOID
*)(UINTN
)Pcd
->ExtendedData
;
117 PcdEmulatorGetBoolean (
121 EMULATED_PCD_ENTRY_EX
*Pcd
;
123 Pcd
= GetPcdEntry (TokenNumber
);
124 ASSERT (Pcd
!= NULL
);
125 ASSERT (Pcd
->DatumSize
== 1);
127 return (BOOLEAN
)Pcd
->Datum
;
136 EMULATED_PCD_ENTRY_EX
*Pcd
;
138 Pcd
= GetPcdEntry (TokenNumber
);
139 ASSERT (Pcd
!= NULL
);
140 return Pcd
->DatumSize
;
146 IN CONST EFI_GUID
*PcdDataBaseName
,
157 IN CONST EFI_GUID
*PcdDataBaseName
,
168 IN CONST EFI_GUID
*PcdDataBaseName
,
179 IN CONST EFI_GUID
*PcdDataBaseName
,
189 PcdEmulatorGetPtrEx (
190 IN CONST EFI_GUID
*PcdDataBaseName
,
200 PcdEmulatorGetBooleanEx (
201 IN CONST EFI_GUID
*PcdDataBaseName
,
211 PcdEmulatorGetSizeEx (
212 IN CONST EFI_GUID
*PcdDataBaseName
,
216 EMULATED_PCD_ENTRY_EX
*Pcd
;
218 Pcd
= GetPcdEntry (TokenNumber
);
219 ASSERT (Pcd
!= NULL
);
220 return Pcd
->DatumSize
;
227 IN UINTN TokenNumber
,
232 EMULATED_PCD_ENTRY_EX
*Pcd
;
234 Pcd
= GetPcdEntry (TokenNumber
);
235 ASSERT (Pcd
!= NULL
);
237 ASSERT (Pcd
->DatumSize
== sizeof (UINT8
));
247 IN UINTN TokenNumber
,
260 IN UINTN TokenNumber
,
265 EMULATED_PCD_ENTRY_EX
*Pcd
;
267 Pcd
= GetPcdEntry (TokenNumber
);
268 ASSERT (Pcd
!= NULL
);
270 ASSERT (Pcd
->DatumSize
== sizeof (UINT32
));
280 IN UINTN TokenNumber
,
293 IN UINTN TokenNumber
,
305 PcdEmulatorSetBoolean (
306 IN UINTN TokenNumber
,
319 IN CONST EFI_GUID
*Guid
,
320 IN UINTN TokenNumber
,
333 IN CONST EFI_GUID
*Guid
,
334 IN UINTN TokenNumber
,
347 IN CONST EFI_GUID
*Guid
,
348 IN UINTN TokenNumber
,
361 IN CONST EFI_GUID
*Guid
,
362 IN UINTN TokenNumber
,
374 PcdEmulatorSetPtrEx (
375 IN CONST EFI_GUID
*Guid
,
376 IN UINTN TokenNumber
,
388 PcdEmulatorSetBooleanEx (
389 IN CONST EFI_GUID
*Guid
,
390 IN UINTN TokenNumber
,
402 PcdEmulatorCallBackOnSet (
403 IN UINTN TokenNumber
,
404 IN CONST EFI_GUID
*Guid
, OPTIONAL
405 IN PCD_PROTOCOL_CALLBACK CallBackFunction
408 EMULATED_PCD_ENTRY_EX
*Pcd
;
410 Pcd
= GetPcdEntry (TokenNumber
);
411 ASSERT (Pcd
!= NULL
);
413 if (Pcd
->CallBackListSize
== Pcd
->CallBackEntries
) {
414 return EFI_OUT_OF_RESOURCES
;
417 Pcd
->CallBackList
[Pcd
->CallBackEntries
++] = CallBackFunction
;
424 PcdEmulatorUnregisterCallBackOnSet (
425 IN UINTN TokenNumber
,
426 IN CONST EFI_GUID
*Guid
, OPTIONAL
427 IN PCD_PROTOCOL_CALLBACK CallBackfunction
430 EMULATED_PCD_ENTRY_EX
*Pcd
;
433 Pcd
= GetPcdEntry (TokenNumber
);
434 ASSERT (Pcd
!= NULL
);
436 for (Index
= 0; Index
< Pcd
->CallBackListSize
; Index
++) {
437 if (Pcd
->CallBackList
[Index
] == CallBackfunction
) {
438 Pcd
->CallBackList
[Index
] = NULL
;
443 return EFI_NOT_FOUND
;
448 PcdEmulatorGetNextToken (
449 IN CONST EFI_GUID
*Guid
, OPTIONAL
453 EMULATED_PCD_ENTRY_EX
*Pcd
;
454 EMULATED_PCD_ENTRY_EX
*LastPcdEntry
;
456 if (*Token
== PCD_INVALID_TOKEN
) {
458 // BugBug: Due to variable size array, ensure we convert this to a reasonable database
459 // that can accomodate array references for simplicity's sake
460 *Token
= gEmulatedPcdEntryEx
[0].Token
;
464 Pcd
= GetPcdEntry (*Token
);
466 return EFI_NOT_FOUND
;
469 LastPcdEntry
= gEmulatedPcdEntryEx
+ GetPcdDataEntryCount ();
470 if (++Pcd
>= LastPcdEntry
) {
471 return EFI_NOT_FOUND
;
478 PCD_PROTOCOL mPcdProtocolInstance
= {
486 PcdEmulatorGetBoolean
,
494 PcdEmulatorGetBooleanEx
,
495 PcdEmulatorGetSizeEx
,
502 PcdEmulatorSetBoolean
,
509 PcdEmulatorSetBooleanEx
,
511 PcdEmulatorCallBackOnSet
,
512 PcdEmulatorUnregisterCallBackOnSet
,
513 PcdEmulatorGetNextToken
520 IN EFI_HANDLE ImageHandle
,
521 IN EFI_SYSTEM_TABLE
*SystemTable
525 EFI_HOB_GUID_TYPE
*GuidHob
;
527 GuidHob
= GetFirstGuidHob (&gPcdHobGuid
);
528 gEmulatedPcdDatabaseEx
= (EMULATED_PCD_DATABASE_EX
*) GET_GUID_HOB_DATA(GuidHob
);
529 ASSERT (gEmulatedPcdDatabaseEx
!= NULL
);
530 gEmulatedPcdEntryEx
= gEmulatedPcdDatabaseEx
->Entry
;
532 Status
= gBS
->InstallMultipleProtocolInterfaces (
534 &gPcdProtocolGuid
, &mPcdProtocolInstance
,
537 ASSERT_EFI_ERROR (Status
);
542 EMULATED_PCD_ENTRY_EX
*
550 Count
= GetPcdDataEntryCount ();
551 for (Index
= 0; Index
< Count
; Index
++) {
552 if (gEmulatedPcdEntryEx
[Index
].Token
== TokenNumber
) {
553 return &gEmulatedPcdEntryEx
[Index
];