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.
36 EFI_PEI_SERVICES
**PeiServices
;
39 PeiServices
= GetPeiServicesTablePointer ();
41 Status
= (**PeiServices
).LocatePpi (
49 ASSERT_EFI_ERROR (Status
);
57 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
59 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
60 set values associated with a PCD token.
62 @retval SKU_ID Return the SKU ID that just be set.
72 ASSERT (SkuId
< 0x100);
74 GetPcdPpiPtr()->SetSku (SkuId
);;
82 Returns the 8-bit value for the token specified by TokenNumber.
84 @param[in] The PCD token number to retrieve a current value for.
86 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
97 PcdPpi
= GetPcdPpiPtr ();
99 return PcdPpi
->Get8 (TokenNumber
);
105 Returns the 16-bit value for the token specified by TokenNumber.
107 @param[in] The PCD token number to retrieve a current value for.
109 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
120 PcdPpi
= GetPcdPpiPtr ();
122 return PcdPpi
->Get16 (TokenNumber
);
128 Returns the 32-bit value for the token specified by TokenNumber.
130 @param[in] TokenNumber The PCD token number to retrieve a current value for.
132 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
143 PcdPpi
= GetPcdPpiPtr ();
145 return PcdPpi
->Get32 (TokenNumber
);
151 Returns the 64-bit value for the token specified by TokenNumber.
153 @param[in] TokenNumber The PCD token number to retrieve a current value for.
155 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
166 PcdPpi
= GetPcdPpiPtr ();
168 return PcdPpi
->Get64 (TokenNumber
);
174 Returns the pointer to the buffer of the token specified by TokenNumber.
176 @param[in] TokenNumber The PCD token number to retrieve a current value for.
178 @retval VOID* Returns the pointer to the token specified by TokenNumber.
189 PcdPpi
= GetPcdPpiPtr ();
191 return PcdPpi
->GetPtr (TokenNumber
);
197 Returns the Boolean value of the token specified by TokenNumber.
199 @param[in] TokenNumber The PCD token number to retrieve a current value for.
201 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
212 PcdPpi
= GetPcdPpiPtr ();
214 return PcdPpi
->GetBool (TokenNumber
);
220 Returns the size of the token specified by TokenNumber.
222 @param[in] TokenNumber The PCD token number to retrieve a current value for.
224 @retval UINTN Returns the size of the token specified by TokenNumber.
235 PcdPpi
= GetPcdPpiPtr ();
237 return PcdPpi
->GetSize (TokenNumber
);
243 Returns the 8-bit value for the token specified by TokenNumber and Guid.
244 If Guid is NULL, then ASSERT().
246 @param[in] Guid Pointer to a 128-bit unique value that designates
247 which namespace to retrieve a value from.
248 @param[in] TokenNumber The PCD token number to retrieve a current value for.
250 @retval UINT8 Return the UINT8.
262 ASSERT (Guid
!= NULL
);
264 PcdPpi
= GetPcdPpiPtr ();
266 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
272 Returns the 16-bit value for the token specified by TokenNumber and Guid.
273 If Guid is NULL, then ASSERT().
275 @param[in] Guid Pointer to a 128-bit unique value that designates
276 which namespace to retrieve a value from.
277 @param[in] TokenNumber The PCD token number to retrieve a current value for.
279 @retval UINT16 Return the UINT16.
291 ASSERT (Guid
!= NULL
);
293 PcdPpi
= GetPcdPpiPtr ();
295 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
301 Returns the 32-bit value for the token specified by TokenNumber and Guid.
302 If Guid is NULL, then ASSERT().
304 @param[in] Guid Pointer to a 128-bit unique value that designates
305 which namespace to retrieve a value from.
306 @param[in] TokenNumber The PCD token number to retrieve a current value for.
308 @retval UINT32 Return the UINT32.
320 ASSERT (Guid
!= NULL
);
322 PcdPpi
= GetPcdPpiPtr ();
324 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
331 Returns the 64-bit value for the token specified by TokenNumber and Guid.
332 If Guid is NULL, then ASSERT().
334 @param[in] Guid Pointer to a 128-bit unique value that designates
335 which namespace to retrieve a value from.
336 @param[in] TokenNumber The PCD token number to retrieve a current value for.
338 @retval UINT64 Return the UINT64.
350 ASSERT (Guid
!= NULL
);
352 PcdPpi
= GetPcdPpiPtr ();
354 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
360 Returns the pointer to the token specified by TokenNumber and Guid.
361 If Guid is NULL, then ASSERT().
363 @param[in] Guid Pointer to a 128-bit unique value that designates
364 which namespace to retrieve a value from.
365 @param[in] TokenNumber The PCD token number to retrieve a current value for.
367 @retval VOID* Return the VOID* pointer.
379 ASSERT (Guid
!= NULL
);
381 PcdPpi
= GetPcdPpiPtr ();
383 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
389 Returns the Boolean value of the token specified by TokenNumber and Guid.
390 If Guid is NULL, then ASSERT().
392 @param[in] Guid Pointer to a 128-bit unique value that designates
393 which namespace to retrieve a value from.
394 @param[in] TokenNumber The PCD token number to retrieve a current value for.
396 @retval BOOLEAN Return the BOOLEAN.
408 ASSERT (Guid
!= NULL
);
410 PcdPpi
= GetPcdPpiPtr ();
412 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
418 Returns the size of the token specified by TokenNumber and Guid.
419 If Guid is NULL, then ASSERT().
421 @param[in] Guid Pointer to a 128-bit unique value that designates
422 which namespace to retrieve a value from.
423 @param[in] TokenNumber The PCD token number to retrieve a current value for.
425 @retval UINTN Return the size.
437 ASSERT (Guid
!= NULL
);
439 PcdPpi
= GetPcdPpiPtr ();
441 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
447 Sets the 8-bit value for the token specified by TokenNumber
448 to the value specified by Value. Value is returned.
450 @param[in] TokenNumber The PCD token number to set a current value for.
451 @param[in] Value The 8-bit value to set.
453 @retval UINT8 Return the value been set.
459 IN UINTN TokenNumber
,
466 PcdPpi
= GetPcdPpiPtr ();
468 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
470 ASSERT_EFI_ERROR (Status
);
478 Sets the 16-bit value for the token specified by TokenNumber
479 to the value specified by Value. Value is returned.
481 @param[in] TokenNumber The PCD token number to set a current value for.
482 @param[in] Value The 16-bit value to set.
484 @retval UINT16 Return the value been set.
490 IN UINTN TokenNumber
,
497 PcdPpi
= GetPcdPpiPtr ();
499 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
501 ASSERT_EFI_ERROR (Status
);
509 Sets the 32-bit value for the token specified by TokenNumber
510 to the value specified by Value. Value is returned.
512 @param[in] TokenNumber The PCD token number to set a current value for.
513 @param[in] Value The 32-bit value to set.
515 @retval UINT32 Return the value been set.
521 IN UINTN TokenNumber
,
528 PcdPpi
= GetPcdPpiPtr ();
530 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
532 ASSERT_EFI_ERROR (Status
);
540 Sets the 64-bit value for the token specified by TokenNumber
541 to the value specified by Value. Value is returned.
543 @param[in] TokenNumber The PCD token number to set a current value for.
544 @param[in] Value The 64-bit value to set.
546 @retval UINT64 Return the value been set.
552 IN UINTN TokenNumber
,
559 PcdPpi
= GetPcdPpiPtr ();
561 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
563 ASSERT_EFI_ERROR (Status
);
571 Sets a buffer for the token specified by TokenNumber to
572 the value specified by Buffer and SizeOfValue. Buffer to
573 be set is returned. The content of the buffer could be
574 overwritten if a Callback on SET is registered with this
577 If SizeOfValue is greater than the maximum
578 size support by TokenNumber, then set SizeOfValue to the
579 maximum size supported by TokenNumber and return NULL to
580 indicate that the set operation was not actually performed.
582 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
584 @param[in] TokenNumber The PCD token number to set a current value for.
585 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
586 @param[in] Value A pointer to the buffer to set.
588 @retval VOID* Return the pointer for the buffer been set.
594 IN UINTN TokenNumber
,
595 IN OUT UINTN
*SizeOfBuffer
,
602 ASSERT (SizeOfBuffer
!= NULL
);
604 if (*SizeOfBuffer
> 0) {
605 ASSERT (Buffer
!= NULL
);
608 PcdPpi
= GetPcdPpiPtr ();
610 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
612 if (EFI_ERROR (Status
)) {
622 Sets the Boolean value for the token specified by TokenNumber
623 to the value specified by Value. Value is returned.
625 @param[in] TokenNumber The PCD token number to set a current value for.
626 @param[in] Value The boolean value to set.
628 @retval BOOLEAN Return the value been set.
634 IN UINTN TokenNumber
,
641 PcdPpi
= GetPcdPpiPtr ();
643 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
645 ASSERT_EFI_ERROR (Status
);
653 Sets the 8-bit value for the token specified by TokenNumber and
654 Guid to the value specified by Value. Value is returned.
655 If Guid is NULL, then ASSERT().
657 @param[in] Guid Pointer to a 128-bit unique value that
658 designates which namespace to set a value from.
659 @param[in] TokenNumber The PCD token number to set a current value for.
660 @param[in] Value The 8-bit value to set.
662 @retval UINT8 Return the value been set.
669 IN UINTN TokenNumber
,
676 PcdPpi
= GetPcdPpiPtr ();
678 ASSERT (Guid
!= NULL
);
680 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
682 ASSERT_EFI_ERROR (Status
);
690 Sets the 16-bit value for the token specified by TokenNumber and
691 Guid to the value specified by Value. Value is returned.
692 If Guid is NULL, then ASSERT().
694 @param[in] Guid Pointer to a 128-bit unique value that
695 designates which namespace to set a value from.
696 @param[in] TokenNumber The PCD token number to set a current value for.
697 @param[in] Value The 16-bit value to set.
699 @retval UINT8 Return the value been set.
706 IN UINTN TokenNumber
,
713 PcdPpi
= GetPcdPpiPtr ();
715 ASSERT (Guid
!= NULL
);
716 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
718 ASSERT_EFI_ERROR (Status
);
726 Sets the 32-bit value for the token specified by TokenNumber and
727 Guid to the value specified by Value. Value is returned.
728 If Guid is NULL, then ASSERT().
730 @param[in] Guid Pointer to a 128-bit unique value that
731 designates which namespace to set a value from.
732 @param[in] TokenNumber The PCD token number to set a current value for.
733 @param[in] Value The 32-bit value to set.
735 @retval UINT32 Return the value been set.
742 IN UINTN TokenNumber
,
748 ASSERT (Guid
!= NULL
);
749 PcdPpi
= GetPcdPpiPtr ();
752 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
754 ASSERT_EFI_ERROR (Status
);
762 Sets the 64-bit value for the token specified by TokenNumber and
763 Guid to the value specified by Value. Value is returned.
764 If Guid is NULL, then ASSERT().
766 @param[in] Guid Pointer to a 128-bit unique value that
767 designates which namespace to set a value from.
768 @param[in] TokenNumber The PCD token number to set a current value for.
769 @param[in] Value The 64-bit value to set.
771 @retval UINT64 Return the value been set.
778 IN UINTN TokenNumber
,
784 ASSERT (Guid
!= NULL
);
785 PcdPpi
= GetPcdPpiPtr ();
788 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
790 ASSERT_EFI_ERROR (Status
);
798 Sets a buffer for the token specified by TokenNumber to the value specified by
799 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
800 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
801 supported by TokenNumber and return NULL to indicate that the set operation
802 was not actually performed.
804 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
806 @param[in] Guid Pointer to a 128-bit unique value that
807 designates which namespace to set a value from.
808 @param[in] TokenNumber The PCD token number to set a current value for.
809 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
810 @param[in] Buffer A pointer to the buffer to set.
812 @retval VOID * Return the pinter to the buffer been set.
819 IN UINTN TokenNumber
,
820 IN OUT UINTN
*SizeOfBuffer
,
826 ASSERT (SizeOfBuffer
!= NULL
);
827 if (*SizeOfBuffer
> 0) {
828 ASSERT (Buffer
!= NULL
);
830 ASSERT (Guid
!= NULL
);
831 PcdPpi
= GetPcdPpiPtr ();
833 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
835 if (EFI_ERROR (Status
)) {
845 Sets the Boolean value for the token specified by TokenNumber and
846 Guid to the value specified by Value. Value is returned.
847 If Guid is NULL, then ASSERT().
849 @param[in] Guid Pointer to a 128-bit unique value that
850 designates which namespace to set a value from.
851 @param[in] TokenNumber The PCD token number to set a current value for.
852 @param[in] Value The Boolean value to set.
854 @retval Boolean Return the value been set.
861 IN UINTN TokenNumber
,
868 PcdPpi
= GetPcdPpiPtr ();
870 ASSERT (Guid
!= NULL
);
871 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
873 ASSERT_EFI_ERROR (Status
);
881 When the token specified by TokenNumber and Guid is set,
882 then notification function specified by NotificationFunction is called.
883 If Guid is NULL, then the default token space is used.
884 If NotificationFunction is NULL, then ASSERT().
886 @param[in] Guid Pointer to a 128-bit unique value that designates which
887 namespace to set a value from. If NULL, then the default
889 @param[in] TokenNumber The PCD token number to monitor.
890 @param[in] NotificationFunction The function to call when the token
891 specified by Guid and TokenNumber is set.
898 LibPcdCallbackOnSet (
899 IN CONST GUID
*Guid
, OPTIONAL
900 IN UINTN TokenNumber
,
901 IN PCD_CALLBACK NotificationFunction
907 PcdPpi
= GetPcdPpiPtr ();
910 Status
= PcdPpi
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
912 ASSERT_EFI_ERROR (Status
);
920 Disable a notification function that was established with LibPcdCallbackonSet().
921 If NotificationFunction is NULL, then ASSERT().
923 @param[in] Guid Specify the GUID token space.
924 @param[in] TokenNumber Specify the token number.
925 @param[in] NotificationFunction The callback function to be unregistered.
932 LibPcdCancelCallback (
933 IN CONST GUID
*Guid
, OPTIONAL
934 IN UINTN TokenNumber
,
935 IN PCD_CALLBACK NotificationFunction
941 PcdPpi
= GetPcdPpiPtr ();
944 Status
= PcdPpi
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
946 ASSERT_EFI_ERROR (Status
);
954 Retrieves the next PCD token number from the token space specified by Guid.
955 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
956 then the first token number is returned. Otherwise, the token number that
957 follows TokenNumber in the token space is returned. If TokenNumber is the last
958 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
959 is not in the token space specified by Guid, then ASSERT().
961 @param[in] Pointer to a 128-bit unique value that designates which namespace
962 to set a value from. If NULL, then the default token space is used.
963 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
966 @retval UINTN The next valid token number.
972 IN CONST GUID
*Guid
, OPTIONAL
979 PcdPpi
= GetPcdPpiPtr ();
982 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
984 ASSERT_EFI_ERROR (Status
);
991 Retrieves the next PCD token space from a token space specified by Guid.
992 Guid of NULL is reserved to mark the default local token namespace on the current
993 platform. If Guid is NULL, then the GUID of the first non-local token space of the
994 current platform is returned. If Guid is the last non-local token space,
995 then NULL is returned.
997 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
1001 @param[in] Pointer to a 128-bit unique value that designates from which namespace
1002 to start the search.
1004 @retval CONST GUID * The next valid token namespace.
1009 LibPcdGetNextTokenSpace (
1016 PcdPpi
= GetPcdPpiPtr ();
1019 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1021 ASSERT_EFI_ERROR (Status
);
1023 return (GUID
*)Guid
;
1029 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1030 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1031 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1032 NULL to indicate that the set operation was not actually performed.
1033 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1034 MaximumDatumSize and NULL must be returned.
1036 If PatchVariable is NULL, then ASSERT().
1037 If SizeOfValue is NULL, then ASSERT().
1038 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1040 @param[in] PatchVariable A pointer to the global variable in a module that is
1041 the target of the set operation.
1042 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1043 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1044 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1050 IN VOID
*PatchVariable
,
1051 IN UINTN MaximumDatumSize
,
1052 IN OUT UINTN
*SizeOfBuffer
,
1053 IN CONST VOID
*Buffer
1056 ASSERT (PatchVariable
!= NULL
);
1057 ASSERT (SizeOfBuffer
!= NULL
);
1059 if (*SizeOfBuffer
> 0) {
1060 ASSERT (Buffer
!= NULL
);
1063 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1064 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1065 *SizeOfBuffer
= MaximumDatumSize
;
1069 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1071 return (VOID
*) Buffer
;