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.
23 #include <Library/PcdLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/PeiServicesTablePointerLib.h>
26 #include <Library/BaseMemoryLib.h>
29 The constructor function retrieve the PCD_PPI pointer.
33 @retval PCD_PPI * The pointer to the PCD_PPI.
44 EFI_PEI_SERVICES
**PeiServices
;
47 PeiServices
= GetPeiServicesTablePointer ();
49 Status
= (**PeiServices
).LocatePpi (
57 ASSERT_EFI_ERROR (Status
);
65 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
67 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
68 set values associated with a PCD token.
70 @retval SKU_ID Return the SKU ID that just be set.
80 ASSERT (SkuId
< 0x100);
82 GetPcdPpiPtr()->SetSku (SkuId
);;
90 Returns the 8-bit value for the token specified by TokenNumber.
92 @param[in] The PCD token number to retrieve a current value for.
94 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
105 PcdPpi
= GetPcdPpiPtr ();
107 return PcdPpi
->Get8 (TokenNumber
);
113 Returns the 16-bit value for the token specified by TokenNumber.
115 @param[in] The PCD token number to retrieve a current value for.
117 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
128 PcdPpi
= GetPcdPpiPtr ();
130 return PcdPpi
->Get16 (TokenNumber
);
136 Returns the 32-bit value for the token specified by TokenNumber.
138 @param[in] TokenNumber The PCD token number to retrieve a current value for.
140 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
151 PcdPpi
= GetPcdPpiPtr ();
153 return PcdPpi
->Get32 (TokenNumber
);
159 Returns the 64-bit value for the token specified by TokenNumber.
161 @param[in] TokenNumber The PCD token number to retrieve a current value for.
163 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
174 PcdPpi
= GetPcdPpiPtr ();
176 return PcdPpi
->Get64 (TokenNumber
);
182 Returns the pointer to the buffer of the token specified by TokenNumber.
184 @param[in] TokenNumber The PCD token number to retrieve a current value for.
186 @retval VOID* Returns the pointer to the token specified by TokenNumber.
197 PcdPpi
= GetPcdPpiPtr ();
199 return PcdPpi
->GetPtr (TokenNumber
);
205 Returns the Boolean value of the token specified by TokenNumber.
207 @param[in] TokenNumber The PCD token number to retrieve a current value for.
209 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
220 PcdPpi
= GetPcdPpiPtr ();
222 return PcdPpi
->GetBool (TokenNumber
);
228 Returns the size of the token specified by TokenNumber.
230 @param[in] TokenNumber The PCD token number to retrieve a current value for.
232 @retval UINTN Returns the size of the token specified by TokenNumber.
243 PcdPpi
= GetPcdPpiPtr ();
245 return PcdPpi
->GetSize (TokenNumber
);
251 Returns the 8-bit value for the token specified by TokenNumber and Guid.
252 If Guid is NULL, then ASSERT().
254 @param[in] Guid Pointer to a 128-bit unique value that designates
255 which namespace to retrieve a value from.
256 @param[in] TokenNumber The PCD token number to retrieve a current value for.
258 @retval UINT8 Return the UINT8.
270 ASSERT (Guid
!= NULL
);
272 PcdPpi
= GetPcdPpiPtr ();
274 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
280 Returns the 16-bit value for the token specified by TokenNumber and Guid.
281 If Guid is NULL, then ASSERT().
283 @param[in] Guid Pointer to a 128-bit unique value that designates
284 which namespace to retrieve a value from.
285 @param[in] TokenNumber The PCD token number to retrieve a current value for.
287 @retval UINT16 Return the UINT16.
299 ASSERT (Guid
!= NULL
);
301 PcdPpi
= GetPcdPpiPtr ();
303 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
309 Returns the 32-bit value for the token specified by TokenNumber and Guid.
310 If Guid is NULL, then ASSERT().
312 @param[in] Guid Pointer to a 128-bit unique value that designates
313 which namespace to retrieve a value from.
314 @param[in] TokenNumber The PCD token number to retrieve a current value for.
316 @retval UINT32 Return the UINT32.
328 ASSERT (Guid
!= NULL
);
330 PcdPpi
= GetPcdPpiPtr ();
332 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
339 Returns the 64-bit value for the token specified by TokenNumber and Guid.
340 If Guid is NULL, then ASSERT().
342 @param[in] Guid Pointer to a 128-bit unique value that designates
343 which namespace to retrieve a value from.
344 @param[in] TokenNumber The PCD token number to retrieve a current value for.
346 @retval UINT64 Return the UINT64.
358 ASSERT (Guid
!= NULL
);
360 PcdPpi
= GetPcdPpiPtr ();
362 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
368 Returns the pointer to the token specified by TokenNumber and Guid.
369 If Guid is NULL, then ASSERT().
371 @param[in] Guid Pointer to a 128-bit unique value that designates
372 which namespace to retrieve a value from.
373 @param[in] TokenNumber The PCD token number to retrieve a current value for.
375 @retval VOID* Return the VOID* pointer.
387 ASSERT (Guid
!= NULL
);
389 PcdPpi
= GetPcdPpiPtr ();
391 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
397 Returns the Boolean value of the token specified by TokenNumber and Guid.
398 If Guid is NULL, then ASSERT().
400 @param[in] Guid Pointer to a 128-bit unique value that designates
401 which namespace to retrieve a value from.
402 @param[in] TokenNumber The PCD token number to retrieve a current value for.
404 @retval BOOLEAN Return the BOOLEAN.
416 ASSERT (Guid
!= NULL
);
418 PcdPpi
= GetPcdPpiPtr ();
420 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
426 Returns the size of the token specified by TokenNumber and Guid.
427 If Guid is NULL, then ASSERT().
429 @param[in] Guid Pointer to a 128-bit unique value that designates
430 which namespace to retrieve a value from.
431 @param[in] TokenNumber The PCD token number to retrieve a current value for.
433 @retval UINTN Return the size.
445 ASSERT (Guid
!= NULL
);
447 PcdPpi
= GetPcdPpiPtr ();
449 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
455 Sets the 8-bit value for the token specified by TokenNumber
456 to the value specified by Value. Value is returned.
458 @param[in] TokenNumber The PCD token number to set a current value for.
459 @param[in] Value The 8-bit value to set.
461 @retval UINT8 Return the value been set.
467 IN UINTN TokenNumber
,
474 PcdPpi
= GetPcdPpiPtr ();
476 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
478 ASSERT_EFI_ERROR (Status
);
486 Sets the 16-bit value for the token specified by TokenNumber
487 to the value specified by Value. Value is returned.
489 @param[in] TokenNumber The PCD token number to set a current value for.
490 @param[in] Value The 16-bit value to set.
492 @retval UINT16 Return the value been set.
498 IN UINTN TokenNumber
,
505 PcdPpi
= GetPcdPpiPtr ();
507 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
509 ASSERT_EFI_ERROR (Status
);
517 Sets the 32-bit value for the token specified by TokenNumber
518 to the value specified by Value. Value is returned.
520 @param[in] TokenNumber The PCD token number to set a current value for.
521 @param[in] Value The 32-bit value to set.
523 @retval UINT32 Return the value been set.
529 IN UINTN TokenNumber
,
536 PcdPpi
= GetPcdPpiPtr ();
538 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
540 ASSERT_EFI_ERROR (Status
);
548 Sets the 64-bit value for the token specified by TokenNumber
549 to the value specified by Value. Value is returned.
551 @param[in] TokenNumber The PCD token number to set a current value for.
552 @param[in] Value The 64-bit value to set.
554 @retval UINT64 Return the value been set.
560 IN UINTN TokenNumber
,
567 PcdPpi
= GetPcdPpiPtr ();
569 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
571 ASSERT_EFI_ERROR (Status
);
579 Sets a buffer for the token specified by TokenNumber to
580 the value specified by Buffer and SizeOfValue. Buffer to
581 be set is returned. The content of the buffer could be
582 overwritten if a Callback on SET is registered with this
585 If SizeOfValue is greater than the maximum
586 size support by TokenNumber, then set SizeOfValue to the
587 maximum size supported by TokenNumber and return NULL to
588 indicate that the set operation was not actually performed.
590 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
592 @param[in] TokenNumber The PCD token number to set a current value for.
593 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
594 @param[in] Value A pointer to the buffer to set.
596 @retval VOID* Return the pointer for the buffer been set.
602 IN UINTN TokenNumber
,
603 IN OUT UINTN
*SizeOfBuffer
,
610 ASSERT (SizeOfBuffer
!= NULL
);
612 if (*SizeOfBuffer
> 0) {
613 ASSERT (Buffer
!= NULL
);
616 PcdPpi
= GetPcdPpiPtr ();
618 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
620 if (EFI_ERROR (Status
)) {
630 Sets the Boolean value for the token specified by TokenNumber
631 to the value specified by Value. Value is returned.
633 @param[in] TokenNumber The PCD token number to set a current value for.
634 @param[in] Value The boolean value to set.
636 @retval BOOLEAN Return the value been set.
642 IN UINTN TokenNumber
,
649 PcdPpi
= GetPcdPpiPtr ();
651 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
653 ASSERT_EFI_ERROR (Status
);
661 Sets the 8-bit value for the token specified by TokenNumber and
662 Guid to the value specified by Value. Value is returned.
663 If Guid is NULL, then ASSERT().
665 @param[in] Guid Pointer to a 128-bit unique value that
666 designates which namespace to set a value from.
667 @param[in] TokenNumber The PCD token number to set a current value for.
668 @param[in] Value The 8-bit value to set.
670 @retval UINT8 Return the value been set.
677 IN UINTN TokenNumber
,
684 PcdPpi
= GetPcdPpiPtr ();
686 ASSERT (Guid
!= NULL
);
688 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
690 ASSERT_EFI_ERROR (Status
);
698 Sets the 16-bit value for the token specified by TokenNumber and
699 Guid to the value specified by Value. Value is returned.
700 If Guid is NULL, then ASSERT().
702 @param[in] Guid Pointer to a 128-bit unique value that
703 designates which namespace to set a value from.
704 @param[in] TokenNumber The PCD token number to set a current value for.
705 @param[in] Value The 16-bit value to set.
707 @retval UINT8 Return the value been set.
714 IN UINTN TokenNumber
,
721 PcdPpi
= GetPcdPpiPtr ();
723 ASSERT (Guid
!= NULL
);
724 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
726 ASSERT_EFI_ERROR (Status
);
734 Sets the 32-bit value for the token specified by TokenNumber and
735 Guid to the value specified by Value. Value is returned.
736 If Guid is NULL, then ASSERT().
738 @param[in] Guid Pointer to a 128-bit unique value that
739 designates which namespace to set a value from.
740 @param[in] TokenNumber The PCD token number to set a current value for.
741 @param[in] Value The 32-bit value to set.
743 @retval UINT32 Return the value been set.
750 IN UINTN TokenNumber
,
756 ASSERT (Guid
!= NULL
);
757 PcdPpi
= GetPcdPpiPtr ();
760 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
762 ASSERT_EFI_ERROR (Status
);
770 Sets the 64-bit value for the token specified by TokenNumber and
771 Guid to the value specified by Value. Value is returned.
772 If Guid is NULL, then ASSERT().
774 @param[in] Guid Pointer to a 128-bit unique value that
775 designates which namespace to set a value from.
776 @param[in] TokenNumber The PCD token number to set a current value for.
777 @param[in] Value The 64-bit value to set.
779 @retval UINT64 Return the value been set.
786 IN UINTN TokenNumber
,
792 ASSERT (Guid
!= NULL
);
793 PcdPpi
= GetPcdPpiPtr ();
796 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
798 ASSERT_EFI_ERROR (Status
);
806 Sets a buffer for the token specified by TokenNumber to the value specified by
807 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
808 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
809 supported by TokenNumber and return NULL to indicate that the set operation
810 was not actually performed.
812 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
814 @param[in] Guid Pointer to a 128-bit unique value that
815 designates which namespace to set a value from.
816 @param[in] TokenNumber The PCD token number to set a current value for.
817 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
818 @param[in] Buffer A pointer to the buffer to set.
820 @retval VOID * Return the pinter to the buffer been set.
827 IN UINTN TokenNumber
,
828 IN OUT UINTN
*SizeOfBuffer
,
834 ASSERT (SizeOfBuffer
!= NULL
);
835 if (*SizeOfBuffer
> 0) {
836 ASSERT (Buffer
!= NULL
);
838 ASSERT (Guid
!= NULL
);
839 PcdPpi
= GetPcdPpiPtr ();
841 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
843 if (EFI_ERROR (Status
)) {
853 Sets the Boolean value for the token specified by TokenNumber and
854 Guid to the value specified by Value. Value is returned.
855 If Guid is NULL, then ASSERT().
857 @param[in] Guid Pointer to a 128-bit unique value that
858 designates which namespace to set a value from.
859 @param[in] TokenNumber The PCD token number to set a current value for.
860 @param[in] Value The Boolean value to set.
862 @retval Boolean Return the value been set.
869 IN UINTN TokenNumber
,
876 PcdPpi
= GetPcdPpiPtr ();
878 ASSERT (Guid
!= NULL
);
879 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
881 ASSERT_EFI_ERROR (Status
);
889 When the token specified by TokenNumber and Guid is set,
890 then notification function specified by NotificationFunction is called.
891 If Guid is NULL, then the default token space is used.
892 If NotificationFunction is NULL, then ASSERT().
894 @param[in] Guid Pointer to a 128-bit unique value that designates which
895 namespace to set a value from. If NULL, then the default
897 @param[in] TokenNumber The PCD token number to monitor.
898 @param[in] NotificationFunction The function to call when the token
899 specified by Guid and TokenNumber is set.
906 LibPcdCallbackOnSet (
907 IN CONST GUID
*Guid
, OPTIONAL
908 IN UINTN TokenNumber
,
909 IN PCD_CALLBACK NotificationFunction
915 PcdPpi
= GetPcdPpiPtr ();
918 Status
= PcdPpi
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
920 ASSERT_EFI_ERROR (Status
);
928 Disable a notification function that was established with LibPcdCallbackonSet().
929 If NotificationFunction is NULL, then ASSERT().
931 @param[in] Guid Specify the GUID token space.
932 @param[in] TokenNumber Specify the token number.
933 @param[in] NotificationFunction The callback function to be unregistered.
940 LibPcdCancelCallback (
941 IN CONST GUID
*Guid
, OPTIONAL
942 IN UINTN TokenNumber
,
943 IN PCD_CALLBACK NotificationFunction
949 PcdPpi
= GetPcdPpiPtr ();
952 Status
= PcdPpi
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
954 ASSERT_EFI_ERROR (Status
);
962 Retrieves the next PCD token number from the token space specified by Guid.
963 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
964 then the first token number is returned. Otherwise, the token number that
965 follows TokenNumber in the token space is returned. If TokenNumber is the last
966 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
967 is not in the token space specified by Guid, then ASSERT().
969 @param[in] Pointer to a 128-bit unique value that designates which namespace
970 to set a value from. If NULL, then the default token space is used.
971 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
974 @retval UINTN The next valid token number.
980 IN CONST GUID
*Guid
, OPTIONAL
987 PcdPpi
= GetPcdPpiPtr ();
990 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
992 ASSERT_EFI_ERROR (Status
);
999 Retrieves the next PCD token space from a token space specified by Guid.
1000 Guid of NULL is reserved to mark the default local token namespace on the current
1001 platform. If Guid is NULL, then the GUID of the first non-local token space of the
1002 current platform is returned. If Guid is the last non-local token space,
1003 then NULL is returned.
1005 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
1009 @param[in] Pointer to a 128-bit unique value that designates from which namespace
1010 to start the search.
1012 @retval CONST GUID * The next valid token namespace.
1017 LibPcdGetNextTokenSpace (
1024 PcdPpi
= GetPcdPpiPtr ();
1027 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1029 ASSERT_EFI_ERROR (Status
);
1031 return (GUID
*)Guid
;
1037 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1038 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1039 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1040 NULL to indicate that the set operation was not actually performed.
1041 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1042 MaximumDatumSize and NULL must be returned.
1044 If PatchVariable is NULL, then ASSERT().
1045 If SizeOfValue is NULL, then ASSERT().
1046 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1048 @param[in] PatchVariable A pointer to the global variable in a module that is
1049 the target of the set operation.
1050 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1051 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1052 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1058 IN VOID
*PatchVariable
,
1059 IN UINTN MaximumDatumSize
,
1060 IN OUT UINTN
*SizeOfBuffer
,
1061 IN CONST VOID
*Buffer
1064 ASSERT (PatchVariable
!= NULL
);
1065 ASSERT (SizeOfBuffer
!= NULL
);
1067 if (*SizeOfBuffer
> 0) {
1068 ASSERT (Buffer
!= NULL
);
1071 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1072 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1073 *SizeOfBuffer
= MaximumDatumSize
;
1077 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1079 return (VOID
*) Buffer
;