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.
14 Module Name: PeiPcdLib.c
21 The constructor function retrieve the PCD_PPI pointer.
25 @retval PCD_PPI * The pointer to the PCD_PPI.
35 EFI_PEI_SERVICES
**PeiServices
;
38 PeiServices
= GetPeiServicesTablePointer ();
40 Status
= (**PeiServices
).LocatePpi (
48 ASSERT_EFI_ERROR (Status
);
56 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
58 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
59 set values associated with a PCD token.
61 @retval SKU_ID Return the SKU ID that just be set.
71 ASSERT (SkuId
< 0x100);
73 GetPcdPpiPtr()->SetSku (SkuId
);;
81 Returns the 8-bit value for the token specified by TokenNumber.
83 @param[in] The PCD token number to retrieve a current value for.
85 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
96 PcdPpi
= GetPcdPpiPtr ();
98 return PcdPpi
->Get8 (TokenNumber
);
104 Returns the 16-bit value for the token specified by TokenNumber.
106 @param[in] The PCD token number to retrieve a current value for.
108 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
119 PcdPpi
= GetPcdPpiPtr ();
121 return PcdPpi
->Get16 (TokenNumber
);
127 Returns the 32-bit value for the token specified by TokenNumber.
129 @param[in] TokenNumber The PCD token number to retrieve a current value for.
131 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
142 PcdPpi
= GetPcdPpiPtr ();
144 return PcdPpi
->Get32 (TokenNumber
);
150 Returns the 64-bit value for the token specified by TokenNumber.
152 @param[in] TokenNumber The PCD token number to retrieve a current value for.
154 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
165 PcdPpi
= GetPcdPpiPtr ();
167 return PcdPpi
->Get64 (TokenNumber
);
173 Returns the pointer to the buffer of the token specified by TokenNumber.
175 @param[in] TokenNumber The PCD token number to retrieve a current value for.
177 @retval VOID* Returns the pointer to the token specified by TokenNumber.
188 PcdPpi
= GetPcdPpiPtr ();
190 return PcdPpi
->GetPtr (TokenNumber
);
196 Returns the Boolean value of the token specified by TokenNumber.
198 @param[in] TokenNumber The PCD token number to retrieve a current value for.
200 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
211 PcdPpi
= GetPcdPpiPtr ();
213 return PcdPpi
->GetBool (TokenNumber
);
219 Returns the size of the token specified by TokenNumber.
221 @param[in] TokenNumber The PCD token number to retrieve a current value for.
223 @retval UINTN Returns the size of the token specified by TokenNumber.
234 PcdPpi
= GetPcdPpiPtr ();
236 return PcdPpi
->GetSize (TokenNumber
);
242 Returns the 8-bit value for the token specified by TokenNumber and Guid.
243 If Guid is NULL, then ASSERT().
245 @param[in] Guid Pointer to a 128-bit unique value that designates
246 which namespace to retrieve a value from.
247 @param[in] TokenNumber The PCD token number to retrieve a current value for.
249 @retval UINT8 Return the UINT8.
261 PcdPpi
= GetPcdPpiPtr ();
263 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
269 Returns the 16-bit value for the token specified by TokenNumber and Guid.
270 If Guid is NULL, then ASSERT().
272 @param[in] Guid Pointer to a 128-bit unique value that designates
273 which namespace to retrieve a value from.
274 @param[in] TokenNumber The PCD token number to retrieve a current value for.
276 @retval UINT16 Return the UINT16.
288 PcdPpi
= GetPcdPpiPtr ();
290 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
296 Returns the 32-bit value for the token specified by TokenNumber and Guid.
297 If Guid is NULL, then ASSERT().
299 @param[in] Guid Pointer to a 128-bit unique value that designates
300 which namespace to retrieve a value from.
301 @param[in] TokenNumber The PCD token number to retrieve a current value for.
303 @retval UINT32 Return the UINT32.
315 PcdPpi
= GetPcdPpiPtr ();
317 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
324 Returns the 64-bit value for the token specified by TokenNumber and Guid.
325 If Guid is NULL, then ASSERT().
327 @param[in] Guid Pointer to a 128-bit unique value that designates
328 which namespace to retrieve a value from.
329 @param[in] TokenNumber The PCD token number to retrieve a current value for.
331 @retval UINT64 Return the UINT64.
343 PcdPpi
= GetPcdPpiPtr ();
345 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
351 Returns the pointer to the token specified by TokenNumber and Guid.
352 If Guid is NULL, then ASSERT().
354 @param[in] Guid Pointer to a 128-bit unique value that designates
355 which namespace to retrieve a value from.
356 @param[in] TokenNumber The PCD token number to retrieve a current value for.
358 @retval VOID* Return the VOID* pointer.
370 PcdPpi
= GetPcdPpiPtr ();
372 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
378 Returns the Boolean value of the token specified by TokenNumber and Guid.
379 If Guid is NULL, then ASSERT().
381 @param[in] Guid Pointer to a 128-bit unique value that designates
382 which namespace to retrieve a value from.
383 @param[in] TokenNumber The PCD token number to retrieve a current value for.
385 @retval BOOLEAN Return the BOOLEAN.
397 PcdPpi
= GetPcdPpiPtr ();
399 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
405 Returns the size of the token specified by TokenNumber and Guid.
406 If Guid is NULL, then ASSERT().
408 @param[in] Guid Pointer to a 128-bit unique value that designates
409 which namespace to retrieve a value from.
410 @param[in] TokenNumber The PCD token number to retrieve a current value for.
412 @retval UINTN Return the size.
424 PcdPpi
= GetPcdPpiPtr ();
426 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
432 Sets the 8-bit value for the token specified by TokenNumber
433 to the value specified by Value. Value is returned.
435 @param[in] TokenNumber The PCD token number to set a current value for.
436 @param[in] Value The 8-bit value to set.
438 @retval UINT8 Return the value been set.
444 IN UINTN TokenNumber
,
451 PcdPpi
= GetPcdPpiPtr ();
454 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
456 ASSERT_EFI_ERROR (Status
);
464 Sets the 16-bit value for the token specified by TokenNumber
465 to the value specified by Value. Value is returned.
467 @param[in] TokenNumber The PCD token number to set a current value for.
468 @param[in] Value The 16-bit value to set.
470 @retval UINT16 Return the value been set.
476 IN UINTN TokenNumber
,
483 PcdPpi
= GetPcdPpiPtr ();
486 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
488 ASSERT_EFI_ERROR (Status
);
496 Sets the 32-bit value for the token specified by TokenNumber
497 to the value specified by Value. Value is returned.
499 @param[in] TokenNumber The PCD token number to set a current value for.
500 @param[in] Value The 32-bit value to set.
502 @retval UINT32 Return the value been set.
508 IN UINTN TokenNumber
,
515 PcdPpi
= GetPcdPpiPtr ();
517 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
519 ASSERT_EFI_ERROR (Status
);
527 Sets the 64-bit value for the token specified by TokenNumber
528 to the value specified by Value. Value is returned.
530 @param[in] TokenNumber The PCD token number to set a current value for.
531 @param[in] Value The 64-bit value to set.
533 @retval UINT64 Return the value been set.
539 IN UINTN TokenNumber
,
546 PcdPpi
= GetPcdPpiPtr ();
549 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
551 ASSERT_EFI_ERROR (Status
);
559 Sets a buffer for the token specified by TokenNumber to
560 the value specified by Buffer and SizeOfValue. Buffer to
561 be set is returned. The content of the buffer could be
562 overwritten if a Callback on SET is registered with this
565 If SizeOfValue is greater than the maximum
566 size support by TokenNumber, then set SizeOfValue to the
567 maximum size supported by TokenNumber and return NULL to
568 indicate that the set operation was not actually performed.
570 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
572 @param[in] TokenNumber The PCD token number to set a current value for.
573 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
574 @param[in] Value A pointer to the buffer to set.
576 @retval VOID* Return the pointer for the buffer been set.
582 IN UINTN TokenNumber
,
583 IN OUT UINTN
*SizeOfBuffer
,
590 ASSERT (SizeOfBuffer
!= NULL
);
592 if (*SizeOfBuffer
> 0) {
593 ASSERT (Buffer
!= NULL
);
596 PcdPpi
= GetPcdPpiPtr ();
598 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
600 if (EFI_ERROR (Status
)) {
610 Sets the Boolean value for the token specified by TokenNumber
611 to the value specified by Value. Value is returned.
613 @param[in] TokenNumber The PCD token number to set a current value for.
614 @param[in] Value The boolean value to set.
616 @retval BOOLEAN Return the value been set.
622 IN UINTN TokenNumber
,
629 PcdPpi
= GetPcdPpiPtr ();
632 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
634 ASSERT_EFI_ERROR (Status
);
642 Sets the 8-bit value for the token specified by TokenNumber and
643 Guid to the value specified by Value. Value is returned.
644 If Guid is NULL, then ASSERT().
646 @param[in] Guid Pointer to a 128-bit unique value that
647 designates which namespace to set a value from.
648 @param[in] TokenNumber The PCD token number to set a current value for.
649 @param[in] Value The 8-bit value to set.
651 @retval UINT8 Return the value been set.
658 IN UINTN TokenNumber
,
665 PcdPpi
= GetPcdPpiPtr ();
668 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
670 ASSERT_EFI_ERROR (Status
);
678 Sets the 16-bit value for the token specified by TokenNumber and
679 Guid to the value specified by Value. Value is returned.
680 If Guid is NULL, then ASSERT().
682 @param[in] Guid Pointer to a 128-bit unique value that
683 designates which namespace to set a value from.
684 @param[in] TokenNumber The PCD token number to set a current value for.
685 @param[in] Value The 16-bit value to set.
687 @retval UINT8 Return the value been set.
694 IN UINTN TokenNumber
,
701 PcdPpi
= GetPcdPpiPtr ();
704 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
706 ASSERT_EFI_ERROR (Status
);
714 Sets the 32-bit value for the token specified by TokenNumber and
715 Guid to the value specified by Value. Value is returned.
716 If Guid is NULL, then ASSERT().
718 @param[in] Guid Pointer to a 128-bit unique value that
719 designates which namespace to set a value from.
720 @param[in] TokenNumber The PCD token number to set a current value for.
721 @param[in] Value The 32-bit value to set.
723 @retval UINT32 Return the value been set.
730 IN UINTN TokenNumber
,
737 PcdPpi
= GetPcdPpiPtr ();
740 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
742 ASSERT_EFI_ERROR (Status
);
750 Sets the 64-bit value for the token specified by TokenNumber and
751 Guid to the value specified by Value. Value is returned.
752 If Guid is NULL, then ASSERT().
754 @param[in] Guid Pointer to a 128-bit unique value that
755 designates which namespace to set a value from.
756 @param[in] TokenNumber The PCD token number to set a current value for.
757 @param[in] Value The 64-bit value to set.
759 @retval UINT64 Return the value been set.
766 IN UINTN TokenNumber
,
773 PcdPpi
= GetPcdPpiPtr ();
776 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
778 ASSERT_EFI_ERROR (Status
);
786 Sets a buffer for the token specified by TokenNumber to the value specified by
787 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
788 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
789 supported by TokenNumber and return NULL to indicate that the set operation
790 was not actually performed.
792 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
794 @param[in] Guid Pointer to a 128-bit unique value that
795 designates which namespace to set a value from.
796 @param[in] TokenNumber The PCD token number to set a current value for.
797 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
798 @param[in] Buffer A pointer to the buffer to set.
800 @retval VOID * Return the pinter to the buffer been set.
807 IN UINTN TokenNumber
,
808 IN OUT UINTN
*SizeOfBuffer
,
815 if (*SizeOfBuffer
> 0) {
816 ASSERT (Buffer
!= NULL
);
819 PcdPpi
= GetPcdPpiPtr ();
821 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
823 if (EFI_ERROR (Status
)) {
833 Sets the Boolean value for the token specified by TokenNumber and
834 Guid to the value specified by Value. Value is returned.
835 If Guid is NULL, then ASSERT().
837 @param[in] Guid Pointer to a 128-bit unique value that
838 designates which namespace to set a value from.
839 @param[in] TokenNumber The PCD token number to set a current value for.
840 @param[in] Value The Boolean value to set.
842 @retval Boolean Return the value been set.
849 IN UINTN TokenNumber
,
856 PcdPpi
= GetPcdPpiPtr ();
859 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
861 ASSERT_EFI_ERROR (Status
);
869 When the token specified by TokenNumber and Guid is set,
870 then notification function specified by NotificationFunction is called.
871 If Guid is NULL, then the default token space is used.
872 If NotificationFunction is NULL, then ASSERT().
874 @param[in] Guid Pointer to a 128-bit unique value that designates which
875 namespace to set a value from. If NULL, then the default
877 @param[in] TokenNumber The PCD token number to monitor.
878 @param[in] NotificationFunction The function to call when the token
879 specified by Guid and TokenNumber is set.
886 LibPcdCallbackOnSet (
887 IN CONST GUID
*Guid
, OPTIONAL
888 IN UINTN TokenNumber
,
889 IN PCD_CALLBACK NotificationFunction
895 PcdPpi
= GetPcdPpiPtr ();
898 Status
= PcdPpi
->CallbackOnSet (TokenNumber
, Guid
, NotificationFunction
);
900 ASSERT_EFI_ERROR (Status
);
908 Disable a notification function that was established with LibPcdCallbackonSet().
909 If NotificationFunction is NULL, then ASSERT().
911 @param[in] Guid Specify the GUID token space.
912 @param[in] TokenNumber Specify the token number.
913 @param[in] NotificationFunction The callback function to be unregistered.
920 LibPcdCancelCallback (
921 IN CONST GUID
*Guid
, OPTIONAL
922 IN UINTN TokenNumber
,
923 IN PCD_CALLBACK NotificationFunction
929 PcdPpi
= GetPcdPpiPtr ();
932 Status
= PcdPpi
->CancelCallback (TokenNumber
, Guid
, NotificationFunction
);
934 ASSERT_EFI_ERROR (Status
);
942 Retrieves the next PCD token number from the token space specified by Guid.
943 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
944 then the first token number is returned. Otherwise, the token number that
945 follows TokenNumber in the token space is returned. If TokenNumber is the last
946 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
947 is not in the token space specified by Guid, then ASSERT().
949 @param[in] Pointer to a 128-bit unique value that designates which namespace
950 to set a value from. If NULL, then the default token space is used.
951 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
954 @retval UINTN The next valid token number.
960 IN CONST GUID
*Guid
, OPTIONAL
967 PcdPpi
= GetPcdPpiPtr ();
970 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
972 ASSERT_EFI_ERROR (Status
);
979 Retrieves the next PCD token space from a token space specified by Guid.
980 Guid of NULL is reserved to mark the default local token namespace on the current
981 platform. If Guid is NULL, then the GUID of the first non-local token space of the
982 current platform is returned. If Guid is the last non-local token space,
983 then NULL is returned.
985 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
989 @param[in] Pointer to a 128-bit unique value that designates from which namespace
992 @retval CONST GUID * The next valid token namespace.
997 LibPcdGetNextTokenSpace (
1004 PcdPpi
= GetPcdPpiPtr ();
1007 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1009 ASSERT_EFI_ERROR (Status
);
1011 return (GUID
*)Guid
;
1017 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1018 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1019 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1020 NULL to indicate that the set operation was not actually performed.
1021 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1022 MaximumDatumSize and NULL must be returned.
1024 If PatchVariable is NULL, then ASSERT().
1025 If SizeOfValue is NULL, then ASSERT().
1026 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1028 @param[in] PatchVariable A pointer to the global variable in a module that is
1029 the target of the set operation.
1030 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1031 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1032 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1038 IN VOID
*PatchVariable
,
1039 IN UINTN MaximumDatumSize
,
1040 IN OUT UINTN
*SizeOfBuffer
,
1041 IN CONST VOID
*Buffer
1044 ASSERT (PatchVariable
!= NULL
);
1045 ASSERT (SizeOfBuffer
!= NULL
);
1047 if (*SizeOfBuffer
> 0) {
1048 ASSERT (Buffer
!= NULL
);
1051 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1052 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1053 *SizeOfBuffer
= MaximumDatumSize
;
1057 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1059 return (VOID
*) Buffer
;