2 Implementation of PcdLib class library for PEI phase.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 // The package level header files this module uses
23 // The protocols, PPI and GUID defintions for this module
27 // The Library classes this module consumes
29 #include <Library/PcdLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/PeiServicesTablePointerLib.h>
32 #include <Library/BaseMemoryLib.h>
35 The constructor function retrieve the PCD_PPI pointer.
39 @retval PCD_PPI * The pointer to the PCD_PPI.
50 EFI_PEI_SERVICES
**PeiServices
;
53 PeiServices
= GetPeiServicesTablePointer ();
55 Status
= (**PeiServices
).LocatePpi (
63 ASSERT_EFI_ERROR (Status
);
71 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
73 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
74 set values associated with a PCD token.
76 @retval SKU_ID Return the SKU ID that just be set.
86 ASSERT (SkuId
< 0x100);
88 GetPcdPpiPtr()->SetSku (SkuId
);;
96 Returns the 8-bit value for the token specified by TokenNumber.
98 @param[in] The PCD token number to retrieve a current value for.
100 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
111 PcdPpi
= GetPcdPpiPtr ();
113 return PcdPpi
->Get8 (TokenNumber
);
119 Returns the 16-bit value for the token specified by TokenNumber.
121 @param[in] The PCD token number to retrieve a current value for.
123 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
134 PcdPpi
= GetPcdPpiPtr ();
136 return PcdPpi
->Get16 (TokenNumber
);
142 Returns the 32-bit value for the token specified by TokenNumber.
144 @param[in] TokenNumber The PCD token number to retrieve a current value for.
146 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
157 PcdPpi
= GetPcdPpiPtr ();
159 return PcdPpi
->Get32 (TokenNumber
);
165 Returns the 64-bit value for the token specified by TokenNumber.
167 @param[in] TokenNumber The PCD token number to retrieve a current value for.
169 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
180 PcdPpi
= GetPcdPpiPtr ();
182 return PcdPpi
->Get64 (TokenNumber
);
188 Returns the pointer to the buffer of the token specified by TokenNumber.
190 @param[in] TokenNumber The PCD token number to retrieve a current value for.
192 @retval VOID* Returns the pointer to the token specified by TokenNumber.
203 PcdPpi
= GetPcdPpiPtr ();
205 return PcdPpi
->GetPtr (TokenNumber
);
211 Returns the Boolean value of the token specified by TokenNumber.
213 @param[in] TokenNumber The PCD token number to retrieve a current value for.
215 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
226 PcdPpi
= GetPcdPpiPtr ();
228 return PcdPpi
->GetBool (TokenNumber
);
234 Returns the size of the token specified by TokenNumber.
236 @param[in] TokenNumber The PCD token number to retrieve a current value for.
238 @retval UINTN Returns the size of the token specified by TokenNumber.
249 PcdPpi
= GetPcdPpiPtr ();
251 return PcdPpi
->GetSize (TokenNumber
);
257 Returns the 8-bit value for the token specified by TokenNumber and Guid.
258 If Guid is NULL, then ASSERT().
260 @param[in] Guid Pointer to a 128-bit unique value that designates
261 which namespace to retrieve a value from.
262 @param[in] TokenNumber The PCD token number to retrieve a current value for.
264 @retval UINT8 Return the UINT8.
276 ASSERT (Guid
!= NULL
);
278 PcdPpi
= GetPcdPpiPtr ();
280 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
286 Returns the 16-bit value for the token specified by TokenNumber and Guid.
287 If Guid is NULL, then ASSERT().
289 @param[in] Guid Pointer to a 128-bit unique value that designates
290 which namespace to retrieve a value from.
291 @param[in] TokenNumber The PCD token number to retrieve a current value for.
293 @retval UINT16 Return the UINT16.
305 ASSERT (Guid
!= NULL
);
307 PcdPpi
= GetPcdPpiPtr ();
309 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
315 Returns the 32-bit value for the token specified by TokenNumber and Guid.
316 If Guid is NULL, then ASSERT().
318 @param[in] Guid Pointer to a 128-bit unique value that designates
319 which namespace to retrieve a value from.
320 @param[in] TokenNumber The PCD token number to retrieve a current value for.
322 @retval UINT32 Return the UINT32.
334 ASSERT (Guid
!= NULL
);
336 PcdPpi
= GetPcdPpiPtr ();
338 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
345 Returns the 64-bit value for the token specified by TokenNumber and Guid.
346 If Guid is NULL, then ASSERT().
348 @param[in] Guid Pointer to a 128-bit unique value that designates
349 which namespace to retrieve a value from.
350 @param[in] TokenNumber The PCD token number to retrieve a current value for.
352 @retval UINT64 Return the UINT64.
364 ASSERT (Guid
!= NULL
);
366 PcdPpi
= GetPcdPpiPtr ();
368 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
374 Returns the pointer to the token specified by TokenNumber and Guid.
375 If Guid is NULL, then ASSERT().
377 @param[in] Guid Pointer to a 128-bit unique value that designates
378 which namespace to retrieve a value from.
379 @param[in] TokenNumber The PCD token number to retrieve a current value for.
381 @retval VOID* Return the VOID* pointer.
393 ASSERT (Guid
!= NULL
);
395 PcdPpi
= GetPcdPpiPtr ();
397 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
403 Returns the Boolean value of the token specified by TokenNumber and Guid.
404 If Guid is NULL, then ASSERT().
406 @param[in] Guid Pointer to a 128-bit unique value that designates
407 which namespace to retrieve a value from.
408 @param[in] TokenNumber The PCD token number to retrieve a current value for.
410 @retval BOOLEAN Return the BOOLEAN.
422 ASSERT (Guid
!= NULL
);
424 PcdPpi
= GetPcdPpiPtr ();
426 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
432 Returns the size of the token specified by TokenNumber and Guid.
433 If Guid is NULL, then ASSERT().
435 @param[in] Guid Pointer to a 128-bit unique value that designates
436 which namespace to retrieve a value from.
437 @param[in] TokenNumber The PCD token number to retrieve a current value for.
439 @retval UINTN Return the size.
451 ASSERT (Guid
!= NULL
);
453 PcdPpi
= GetPcdPpiPtr ();
455 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
461 Sets the 8-bit value for the token specified by TokenNumber
462 to the value specified by Value. Value is returned.
464 @param[in] TokenNumber The PCD token number to set a current value for.
465 @param[in] Value The 8-bit value to set.
467 @retval UINT8 Return the value been set.
473 IN UINTN TokenNumber
,
480 PcdPpi
= GetPcdPpiPtr ();
482 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
484 ASSERT_EFI_ERROR (Status
);
492 Sets the 16-bit value for the token specified by TokenNumber
493 to the value specified by Value. Value is returned.
495 @param[in] TokenNumber The PCD token number to set a current value for.
496 @param[in] Value The 16-bit value to set.
498 @retval UINT16 Return the value been set.
504 IN UINTN TokenNumber
,
511 PcdPpi
= GetPcdPpiPtr ();
513 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
515 ASSERT_EFI_ERROR (Status
);
523 Sets the 32-bit value for the token specified by TokenNumber
524 to the value specified by Value. Value is returned.
526 @param[in] TokenNumber The PCD token number to set a current value for.
527 @param[in] Value The 32-bit value to set.
529 @retval UINT32 Return the value been set.
535 IN UINTN TokenNumber
,
542 PcdPpi
= GetPcdPpiPtr ();
544 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
546 ASSERT_EFI_ERROR (Status
);
554 Sets the 64-bit value for the token specified by TokenNumber
555 to the value specified by Value. Value is returned.
557 @param[in] TokenNumber The PCD token number to set a current value for.
558 @param[in] Value The 64-bit value to set.
560 @retval UINT64 Return the value been set.
566 IN UINTN TokenNumber
,
573 PcdPpi
= GetPcdPpiPtr ();
575 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
577 ASSERT_EFI_ERROR (Status
);
585 Sets a buffer for the token specified by TokenNumber to
586 the value specified by Buffer and SizeOfValue. Buffer to
587 be set is returned. The content of the buffer could be
588 overwritten if a Callback on SET is registered with this
591 If SizeOfValue is greater than the maximum
592 size support by TokenNumber, then set SizeOfValue to the
593 maximum size supported by TokenNumber and return NULL to
594 indicate that the set operation was not actually performed.
596 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
598 @param[in] TokenNumber The PCD token number to set a current value for.
599 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
600 @param[in] Value A pointer to the buffer to set.
602 @retval VOID* Return the pointer for the buffer been set.
608 IN UINTN TokenNumber
,
609 IN OUT UINTN
*SizeOfBuffer
,
616 ASSERT (SizeOfBuffer
!= NULL
);
618 if (*SizeOfBuffer
> 0) {
619 ASSERT (Buffer
!= NULL
);
622 PcdPpi
= GetPcdPpiPtr ();
624 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
626 if (EFI_ERROR (Status
)) {
636 Sets the Boolean value for the token specified by TokenNumber
637 to the value specified by Value. Value is returned.
639 @param[in] TokenNumber The PCD token number to set a current value for.
640 @param[in] Value The boolean value to set.
642 @retval BOOLEAN Return the value been set.
648 IN UINTN TokenNumber
,
655 PcdPpi
= GetPcdPpiPtr ();
657 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
659 ASSERT_EFI_ERROR (Status
);
667 Sets the 8-bit value for the token specified by TokenNumber and
668 Guid to the value specified by Value. Value is returned.
669 If Guid is NULL, then ASSERT().
671 @param[in] Guid Pointer to a 128-bit unique value that
672 designates which namespace to set a value from.
673 @param[in] TokenNumber The PCD token number to set a current value for.
674 @param[in] Value The 8-bit value to set.
676 @retval UINT8 Return the value been set.
683 IN UINTN TokenNumber
,
690 PcdPpi
= GetPcdPpiPtr ();
692 ASSERT (Guid
!= NULL
);
694 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
696 ASSERT_EFI_ERROR (Status
);
704 Sets the 16-bit value for the token specified by TokenNumber and
705 Guid to the value specified by Value. Value is returned.
706 If Guid is NULL, then ASSERT().
708 @param[in] Guid Pointer to a 128-bit unique value that
709 designates which namespace to set a value from.
710 @param[in] TokenNumber The PCD token number to set a current value for.
711 @param[in] Value The 16-bit value to set.
713 @retval UINT8 Return the value been set.
720 IN UINTN TokenNumber
,
727 PcdPpi
= GetPcdPpiPtr ();
729 ASSERT (Guid
!= NULL
);
730 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
732 ASSERT_EFI_ERROR (Status
);
740 Sets the 32-bit value for the token specified by TokenNumber and
741 Guid to the value specified by Value. Value is returned.
742 If Guid is NULL, then ASSERT().
744 @param[in] Guid Pointer to a 128-bit unique value that
745 designates which namespace to set a value from.
746 @param[in] TokenNumber The PCD token number to set a current value for.
747 @param[in] Value The 32-bit value to set.
749 @retval UINT32 Return the value been set.
756 IN UINTN TokenNumber
,
762 ASSERT (Guid
!= NULL
);
763 PcdPpi
= GetPcdPpiPtr ();
766 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
768 ASSERT_EFI_ERROR (Status
);
776 Sets the 64-bit value for the token specified by TokenNumber and
777 Guid to the value specified by Value. Value is returned.
778 If Guid is NULL, then ASSERT().
780 @param[in] Guid Pointer to a 128-bit unique value that
781 designates which namespace to set a value from.
782 @param[in] TokenNumber The PCD token number to set a current value for.
783 @param[in] Value The 64-bit value to set.
785 @retval UINT64 Return the value been set.
792 IN UINTN TokenNumber
,
798 ASSERT (Guid
!= NULL
);
799 PcdPpi
= GetPcdPpiPtr ();
802 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
804 ASSERT_EFI_ERROR (Status
);
812 Sets a buffer for the token specified by TokenNumber to the value specified by
813 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
814 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
815 supported by TokenNumber and return NULL to indicate that the set operation
816 was not actually performed.
818 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
820 @param[in] Guid Pointer to a 128-bit unique value that
821 designates which namespace to set a value from.
822 @param[in] TokenNumber The PCD token number to set a current value for.
823 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
824 @param[in] Buffer A pointer to the buffer to set.
826 @retval VOID * Return the pinter to the buffer been set.
833 IN UINTN TokenNumber
,
834 IN OUT UINTN
*SizeOfBuffer
,
840 ASSERT (SizeOfBuffer
!= NULL
);
841 if (*SizeOfBuffer
> 0) {
842 ASSERT (Buffer
!= NULL
);
844 ASSERT (Guid
!= NULL
);
845 PcdPpi
= GetPcdPpiPtr ();
847 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
849 if (EFI_ERROR (Status
)) {
859 Sets the Boolean value for the token specified by TokenNumber and
860 Guid to the value specified by Value. Value is returned.
861 If Guid is NULL, then ASSERT().
863 @param[in] Guid Pointer to a 128-bit unique value that
864 designates which namespace to set a value from.
865 @param[in] TokenNumber The PCD token number to set a current value for.
866 @param[in] Value The Boolean value to set.
868 @retval Boolean Return the value been set.
875 IN UINTN TokenNumber
,
882 PcdPpi
= GetPcdPpiPtr ();
884 ASSERT (Guid
!= NULL
);
885 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
887 ASSERT_EFI_ERROR (Status
);
895 When the token specified by TokenNumber and Guid is set,
896 then notification function specified by NotificationFunction is called.
897 If Guid is NULL, then the default token space is used.
898 If NotificationFunction is NULL, then ASSERT().
900 @param[in] Guid Pointer to a 128-bit unique value that designates which
901 namespace to set a value from. If NULL, then the default
903 @param[in] TokenNumber The PCD token number to monitor.
904 @param[in] NotificationFunction The function to call when the token
905 specified by Guid and TokenNumber is set.
912 LibPcdCallbackOnSet (
913 IN CONST GUID
*Guid
, OPTIONAL
914 IN UINTN TokenNumber
,
915 IN PCD_CALLBACK NotificationFunction
921 PcdPpi
= GetPcdPpiPtr ();
924 Status
= PcdPpi
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
926 ASSERT_EFI_ERROR (Status
);
934 Disable a notification function that was established with LibPcdCallbackonSet().
935 If NotificationFunction is NULL, then ASSERT().
937 @param[in] Guid Specify the GUID token space.
938 @param[in] TokenNumber Specify the token number.
939 @param[in] NotificationFunction The callback function to be unregistered.
946 LibPcdCancelCallback (
947 IN CONST GUID
*Guid
, OPTIONAL
948 IN UINTN TokenNumber
,
949 IN PCD_CALLBACK NotificationFunction
955 PcdPpi
= GetPcdPpiPtr ();
958 Status
= PcdPpi
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
960 ASSERT_EFI_ERROR (Status
);
968 Retrieves the next PCD token number from the token space specified by Guid.
969 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
970 then the first token number is returned. Otherwise, the token number that
971 follows TokenNumber in the token space is returned. If TokenNumber is the last
972 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
973 is not in the token space specified by Guid, then ASSERT().
975 @param[in] Pointer to a 128-bit unique value that designates which namespace
976 to set a value from. If NULL, then the default token space is used.
977 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
980 @retval UINTN The next valid token number.
986 IN CONST GUID
*Guid
, OPTIONAL
993 PcdPpi
= GetPcdPpiPtr ();
996 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
998 ASSERT_EFI_ERROR (Status
);
1005 Retrieves the next PCD token space from a token space specified by Guid.
1006 Guid of NULL is reserved to mark the default local token namespace on the current
1007 platform. If Guid is NULL, then the GUID of the first non-local token space of the
1008 current platform is returned. If Guid is the last non-local token space,
1009 then NULL is returned.
1011 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
1015 @param[in] Pointer to a 128-bit unique value that designates from which namespace
1016 to start the search.
1018 @retval CONST GUID * The next valid token namespace.
1023 LibPcdGetNextTokenSpace (
1030 PcdPpi
= GetPcdPpiPtr ();
1033 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1035 ASSERT_EFI_ERROR (Status
);
1037 return (GUID
*)Guid
;
1043 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1044 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1045 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1046 NULL to indicate that the set operation was not actually performed.
1047 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1048 MaximumDatumSize and NULL must be returned.
1050 If PatchVariable is NULL, then ASSERT().
1051 If SizeOfValue is NULL, then ASSERT().
1052 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1054 @param[in] PatchVariable A pointer to the global variable in a module that is
1055 the target of the set operation.
1056 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1057 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1058 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1064 IN VOID
*PatchVariable
,
1065 IN UINTN MaximumDatumSize
,
1066 IN OUT UINTN
*SizeOfBuffer
,
1067 IN CONST VOID
*Buffer
1070 ASSERT (PatchVariable
!= NULL
);
1071 ASSERT (SizeOfBuffer
!= NULL
);
1073 if (*SizeOfBuffer
> 0) {
1074 ASSERT (Buffer
!= NULL
);
1077 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1078 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1079 *SizeOfBuffer
= MaximumDatumSize
;
1083 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1085 return (VOID
*) Buffer
;