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 package level header files this module uses
25 // The protocols, PPI and GUID defintions for this module
29 // The Library classes this module consumes
31 #include <Library/PcdLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/PeiServicesTablePointerLib.h>
34 #include <Library/BaseMemoryLib.h>
37 The constructor function retrieve the PCD_PPI pointer.
41 @retval PCD_PPI * The pointer to the PCD_PPI.
52 EFI_PEI_SERVICES
**PeiServices
;
55 PeiServices
= GetPeiServicesTablePointer ();
57 Status
= (**PeiServices
).LocatePpi (
65 ASSERT_EFI_ERROR (Status
);
73 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
75 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
76 set values associated with a PCD token.
78 @retval SKU_ID Return the SKU ID that just be set.
88 ASSERT (SkuId
< 0x100);
90 GetPcdPpiPtr()->SetSku (SkuId
);;
98 Returns the 8-bit value for the token specified by TokenNumber.
100 @param[in] The PCD token number to retrieve a current value for.
102 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
113 PcdPpi
= GetPcdPpiPtr ();
115 return PcdPpi
->Get8 (TokenNumber
);
121 Returns the 16-bit value for the token specified by TokenNumber.
123 @param[in] The PCD token number to retrieve a current value for.
125 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
136 PcdPpi
= GetPcdPpiPtr ();
138 return PcdPpi
->Get16 (TokenNumber
);
144 Returns the 32-bit value for the token specified by TokenNumber.
146 @param[in] TokenNumber The PCD token number to retrieve a current value for.
148 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
159 PcdPpi
= GetPcdPpiPtr ();
161 return PcdPpi
->Get32 (TokenNumber
);
167 Returns the 64-bit value for the token specified by TokenNumber.
169 @param[in] TokenNumber The PCD token number to retrieve a current value for.
171 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
182 PcdPpi
= GetPcdPpiPtr ();
184 return PcdPpi
->Get64 (TokenNumber
);
190 Returns the pointer to the buffer of the token specified by TokenNumber.
192 @param[in] TokenNumber The PCD token number to retrieve a current value for.
194 @retval VOID* Returns the pointer to the token specified by TokenNumber.
205 PcdPpi
= GetPcdPpiPtr ();
207 return PcdPpi
->GetPtr (TokenNumber
);
213 Returns the Boolean value of the token specified by TokenNumber.
215 @param[in] TokenNumber The PCD token number to retrieve a current value for.
217 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
228 PcdPpi
= GetPcdPpiPtr ();
230 return PcdPpi
->GetBool (TokenNumber
);
236 Returns the size of the token specified by TokenNumber.
238 @param[in] TokenNumber The PCD token number to retrieve a current value for.
240 @retval UINTN Returns the size of the token specified by TokenNumber.
251 PcdPpi
= GetPcdPpiPtr ();
253 return PcdPpi
->GetSize (TokenNumber
);
259 Returns the 8-bit value for the token specified by TokenNumber and Guid.
260 If Guid is NULL, then ASSERT().
262 @param[in] Guid Pointer to a 128-bit unique value that designates
263 which namespace to retrieve a value from.
264 @param[in] TokenNumber The PCD token number to retrieve a current value for.
266 @retval UINT8 Return the UINT8.
278 ASSERT (Guid
!= NULL
);
280 PcdPpi
= GetPcdPpiPtr ();
282 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
288 Returns the 16-bit value for the token specified by TokenNumber and Guid.
289 If Guid is NULL, then ASSERT().
291 @param[in] Guid Pointer to a 128-bit unique value that designates
292 which namespace to retrieve a value from.
293 @param[in] TokenNumber The PCD token number to retrieve a current value for.
295 @retval UINT16 Return the UINT16.
307 ASSERT (Guid
!= NULL
);
309 PcdPpi
= GetPcdPpiPtr ();
311 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
317 Returns the 32-bit value for the token specified by TokenNumber and Guid.
318 If Guid is NULL, then ASSERT().
320 @param[in] Guid Pointer to a 128-bit unique value that designates
321 which namespace to retrieve a value from.
322 @param[in] TokenNumber The PCD token number to retrieve a current value for.
324 @retval UINT32 Return the UINT32.
336 ASSERT (Guid
!= NULL
);
338 PcdPpi
= GetPcdPpiPtr ();
340 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
347 Returns the 64-bit value for the token specified by TokenNumber and Guid.
348 If Guid is NULL, then ASSERT().
350 @param[in] Guid Pointer to a 128-bit unique value that designates
351 which namespace to retrieve a value from.
352 @param[in] TokenNumber The PCD token number to retrieve a current value for.
354 @retval UINT64 Return the UINT64.
366 ASSERT (Guid
!= NULL
);
368 PcdPpi
= GetPcdPpiPtr ();
370 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
376 Returns the pointer to the token specified by TokenNumber and Guid.
377 If Guid is NULL, then ASSERT().
379 @param[in] Guid Pointer to a 128-bit unique value that designates
380 which namespace to retrieve a value from.
381 @param[in] TokenNumber The PCD token number to retrieve a current value for.
383 @retval VOID* Return the VOID* pointer.
395 ASSERT (Guid
!= NULL
);
397 PcdPpi
= GetPcdPpiPtr ();
399 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
405 Returns the Boolean value 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 BOOLEAN Return the BOOLEAN.
424 ASSERT (Guid
!= NULL
);
426 PcdPpi
= GetPcdPpiPtr ();
428 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
434 Returns the size of the token specified by TokenNumber and Guid.
435 If Guid is NULL, then ASSERT().
437 @param[in] Guid Pointer to a 128-bit unique value that designates
438 which namespace to retrieve a value from.
439 @param[in] TokenNumber The PCD token number to retrieve a current value for.
441 @retval UINTN Return the size.
453 ASSERT (Guid
!= NULL
);
455 PcdPpi
= GetPcdPpiPtr ();
457 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
463 Sets the 8-bit value for the token specified by TokenNumber
464 to the value specified by Value. Value is returned.
466 @param[in] TokenNumber The PCD token number to set a current value for.
467 @param[in] Value The 8-bit value to set.
469 @retval UINT8 Return the value been set.
475 IN UINTN TokenNumber
,
482 PcdPpi
= GetPcdPpiPtr ();
484 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
486 ASSERT_EFI_ERROR (Status
);
494 Sets the 16-bit value for the token specified by TokenNumber
495 to the value specified by Value. Value is returned.
497 @param[in] TokenNumber The PCD token number to set a current value for.
498 @param[in] Value The 16-bit value to set.
500 @retval UINT16 Return the value been set.
506 IN UINTN TokenNumber
,
513 PcdPpi
= GetPcdPpiPtr ();
515 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
517 ASSERT_EFI_ERROR (Status
);
525 Sets the 32-bit value for the token specified by TokenNumber
526 to the value specified by Value. Value is returned.
528 @param[in] TokenNumber The PCD token number to set a current value for.
529 @param[in] Value The 32-bit value to set.
531 @retval UINT32 Return the value been set.
537 IN UINTN TokenNumber
,
544 PcdPpi
= GetPcdPpiPtr ();
546 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
548 ASSERT_EFI_ERROR (Status
);
556 Sets the 64-bit value for the token specified by TokenNumber
557 to the value specified by Value. Value is returned.
559 @param[in] TokenNumber The PCD token number to set a current value for.
560 @param[in] Value The 64-bit value to set.
562 @retval UINT64 Return the value been set.
568 IN UINTN TokenNumber
,
575 PcdPpi
= GetPcdPpiPtr ();
577 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
579 ASSERT_EFI_ERROR (Status
);
587 Sets a buffer for the token specified by TokenNumber to
588 the value specified by Buffer and SizeOfValue. Buffer to
589 be set is returned. The content of the buffer could be
590 overwritten if a Callback on SET is registered with this
593 If SizeOfValue is greater than the maximum
594 size support by TokenNumber, then set SizeOfValue to the
595 maximum size supported by TokenNumber and return NULL to
596 indicate that the set operation was not actually performed.
598 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
600 @param[in] TokenNumber The PCD token number to set a current value for.
601 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
602 @param[in] Value A pointer to the buffer to set.
604 @retval VOID* Return the pointer for the buffer been set.
610 IN UINTN TokenNumber
,
611 IN OUT UINTN
*SizeOfBuffer
,
618 ASSERT (SizeOfBuffer
!= NULL
);
620 if (*SizeOfBuffer
> 0) {
621 ASSERT (Buffer
!= NULL
);
624 PcdPpi
= GetPcdPpiPtr ();
626 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
628 if (EFI_ERROR (Status
)) {
638 Sets the Boolean value for the token specified by TokenNumber
639 to the value specified by Value. Value is returned.
641 @param[in] TokenNumber The PCD token number to set a current value for.
642 @param[in] Value The boolean value to set.
644 @retval BOOLEAN Return the value been set.
650 IN UINTN TokenNumber
,
657 PcdPpi
= GetPcdPpiPtr ();
659 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
661 ASSERT_EFI_ERROR (Status
);
669 Sets the 8-bit value for the token specified by TokenNumber and
670 Guid to the value specified by Value. Value is returned.
671 If Guid is NULL, then ASSERT().
673 @param[in] Guid Pointer to a 128-bit unique value that
674 designates which namespace to set a value from.
675 @param[in] TokenNumber The PCD token number to set a current value for.
676 @param[in] Value The 8-bit value to set.
678 @retval UINT8 Return the value been set.
685 IN UINTN TokenNumber
,
692 PcdPpi
= GetPcdPpiPtr ();
694 ASSERT (Guid
!= NULL
);
696 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
698 ASSERT_EFI_ERROR (Status
);
706 Sets the 16-bit value for the token specified by TokenNumber and
707 Guid to the value specified by Value. Value is returned.
708 If Guid is NULL, then ASSERT().
710 @param[in] Guid Pointer to a 128-bit unique value that
711 designates which namespace to set a value from.
712 @param[in] TokenNumber The PCD token number to set a current value for.
713 @param[in] Value The 16-bit value to set.
715 @retval UINT8 Return the value been set.
722 IN UINTN TokenNumber
,
729 PcdPpi
= GetPcdPpiPtr ();
731 ASSERT (Guid
!= NULL
);
732 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
734 ASSERT_EFI_ERROR (Status
);
742 Sets the 32-bit value for the token specified by TokenNumber and
743 Guid to the value specified by Value. Value is returned.
744 If Guid is NULL, then ASSERT().
746 @param[in] Guid Pointer to a 128-bit unique value that
747 designates which namespace to set a value from.
748 @param[in] TokenNumber The PCD token number to set a current value for.
749 @param[in] Value The 32-bit value to set.
751 @retval UINT32 Return the value been set.
758 IN UINTN TokenNumber
,
764 ASSERT (Guid
!= NULL
);
765 PcdPpi
= GetPcdPpiPtr ();
768 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
770 ASSERT_EFI_ERROR (Status
);
778 Sets the 64-bit value for the token specified by TokenNumber and
779 Guid to the value specified by Value. Value is returned.
780 If Guid is NULL, then ASSERT().
782 @param[in] Guid Pointer to a 128-bit unique value that
783 designates which namespace to set a value from.
784 @param[in] TokenNumber The PCD token number to set a current value for.
785 @param[in] Value The 64-bit value to set.
787 @retval UINT64 Return the value been set.
794 IN UINTN TokenNumber
,
800 ASSERT (Guid
!= NULL
);
801 PcdPpi
= GetPcdPpiPtr ();
804 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
806 ASSERT_EFI_ERROR (Status
);
814 Sets a buffer for the token specified by TokenNumber to the value specified by
815 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
816 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
817 supported by TokenNumber and return NULL to indicate that the set operation
818 was not actually performed.
820 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
822 @param[in] Guid Pointer to a 128-bit unique value that
823 designates which namespace to set a value from.
824 @param[in] TokenNumber The PCD token number to set a current value for.
825 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
826 @param[in] Buffer A pointer to the buffer to set.
828 @retval VOID * Return the pinter to the buffer been set.
835 IN UINTN TokenNumber
,
836 IN OUT UINTN
*SizeOfBuffer
,
842 ASSERT (SizeOfBuffer
!= NULL
);
843 if (*SizeOfBuffer
> 0) {
844 ASSERT (Buffer
!= NULL
);
846 ASSERT (Guid
!= NULL
);
847 PcdPpi
= GetPcdPpiPtr ();
849 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
851 if (EFI_ERROR (Status
)) {
861 Sets the Boolean value for the token specified by TokenNumber and
862 Guid to the value specified by Value. Value is returned.
863 If Guid is NULL, then ASSERT().
865 @param[in] Guid Pointer to a 128-bit unique value that
866 designates which namespace to set a value from.
867 @param[in] TokenNumber The PCD token number to set a current value for.
868 @param[in] Value The Boolean value to set.
870 @retval Boolean Return the value been set.
877 IN UINTN TokenNumber
,
884 PcdPpi
= GetPcdPpiPtr ();
886 ASSERT (Guid
!= NULL
);
887 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
889 ASSERT_EFI_ERROR (Status
);
897 When the token specified by TokenNumber and Guid is set,
898 then notification function specified by NotificationFunction is called.
899 If Guid is NULL, then the default token space is used.
900 If NotificationFunction is NULL, then ASSERT().
902 @param[in] Guid Pointer to a 128-bit unique value that designates which
903 namespace to set a value from. If NULL, then the default
905 @param[in] TokenNumber The PCD token number to monitor.
906 @param[in] NotificationFunction The function to call when the token
907 specified by Guid and TokenNumber is set.
914 LibPcdCallbackOnSet (
915 IN CONST GUID
*Guid
, OPTIONAL
916 IN UINTN TokenNumber
,
917 IN PCD_CALLBACK NotificationFunction
923 PcdPpi
= GetPcdPpiPtr ();
926 Status
= PcdPpi
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
928 ASSERT_EFI_ERROR (Status
);
936 Disable a notification function that was established with LibPcdCallbackonSet().
937 If NotificationFunction is NULL, then ASSERT().
939 @param[in] Guid Specify the GUID token space.
940 @param[in] TokenNumber Specify the token number.
941 @param[in] NotificationFunction The callback function to be unregistered.
948 LibPcdCancelCallback (
949 IN CONST GUID
*Guid
, OPTIONAL
950 IN UINTN TokenNumber
,
951 IN PCD_CALLBACK NotificationFunction
957 PcdPpi
= GetPcdPpiPtr ();
960 Status
= PcdPpi
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
962 ASSERT_EFI_ERROR (Status
);
970 Retrieves the next PCD token number from the token space specified by Guid.
971 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
972 then the first token number is returned. Otherwise, the token number that
973 follows TokenNumber in the token space is returned. If TokenNumber is the last
974 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
975 is not in the token space specified by Guid, then ASSERT().
977 @param[in] Pointer to a 128-bit unique value that designates which namespace
978 to set a value from. If NULL, then the default token space is used.
979 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
982 @retval UINTN The next valid token number.
988 IN CONST GUID
*Guid
, OPTIONAL
995 PcdPpi
= GetPcdPpiPtr ();
998 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
1000 ASSERT_EFI_ERROR (Status
);
1007 Retrieves the next PCD token space from a token space specified by Guid.
1008 Guid of NULL is reserved to mark the default local token namespace on the current
1009 platform. If Guid is NULL, then the GUID of the first non-local token space of the
1010 current platform is returned. If Guid is the last non-local token space,
1011 then NULL is returned.
1013 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
1017 @param[in] Pointer to a 128-bit unique value that designates from which namespace
1018 to start the search.
1020 @retval CONST GUID * The next valid token namespace.
1025 LibPcdGetNextTokenSpace (
1032 PcdPpi
= GetPcdPpiPtr ();
1035 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1037 ASSERT_EFI_ERROR (Status
);
1039 return (GUID
*)Guid
;
1045 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1046 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1047 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1048 NULL to indicate that the set operation was not actually performed.
1049 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1050 MaximumDatumSize and NULL must be returned.
1052 If PatchVariable is NULL, then ASSERT().
1053 If SizeOfValue is NULL, then ASSERT().
1054 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1056 @param[in] PatchVariable A pointer to the global variable in a module that is
1057 the target of the set operation.
1058 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1059 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1060 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1066 IN VOID
*PatchVariable
,
1067 IN UINTN MaximumDatumSize
,
1068 IN OUT UINTN
*SizeOfBuffer
,
1069 IN CONST VOID
*Buffer
1072 ASSERT (PatchVariable
!= NULL
);
1073 ASSERT (SizeOfBuffer
!= NULL
);
1075 if (*SizeOfBuffer
> 0) {
1076 ASSERT (Buffer
!= NULL
);
1079 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1080 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1081 *SizeOfBuffer
= MaximumDatumSize
;
1085 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1087 return (VOID
*) Buffer
;