2 Implementation of PcdLib class library for PEI phase.
4 Copyright (c) 2006 - 2008, 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/PeiServicesLib.h>
24 #include <Library/PcdLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/BaseMemoryLib.h>
29 Retrieve the PCD_PPI pointer.
31 This function is to locate PCD_PPI PPI via PeiService.
32 If fail to locate PCD_PPI, then ASSERT_EFI_ERROR().
34 @retval PCD_PPI * The pointer to the PCD_PPI.
45 Status
= PeiServicesLocatePpi (&gPcdPpiGuid
, 0, NULL
, (VOID
**)&PcdPpi
);
46 ASSERT_EFI_ERROR (Status
);
52 This function provides a means by which SKU support can be established in the PCD infrastructure.
54 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
56 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
57 set values associated with a PCD token.
59 If SkuId >= 0x100, then ASSERT().
61 @return Return the SKU ID that just be set.
71 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
73 GetPcdPpiPointer()->SetSku (SkuId
);
81 This function provides a means by which to retrieve a value for a given PCD token.
83 Returns the 8-bit value for the token specified by TokenNumber.
85 @param[in] TokenNumber The PCD token number to retrieve a current value for.
87 @return Returns the 8-bit value for the token specified by TokenNumber.
96 return (GetPcdPpiPointer ())->Get8 (TokenNumber
);
102 This function provides a means by which to retrieve a value for a given PCD token.
104 Returns the 16-bit value for the token specified by TokenNumber.
106 @param[in] TokenNumber The PCD token number to retrieve a current value for.
108 @return Returns the 16-bit value for the token specified by TokenNumber.
117 return (GetPcdPpiPointer ())->Get16 (TokenNumber
);
123 This function provides a means by which to retrieve a value for a given PCD token.
125 Returns the 32-bit value for the token specified by TokenNumber.
127 @param[in] TokenNumber The PCD token number to retrieve a current value for.
129 @return Returns the 32-bit value for the token specified by TokenNumber.
138 return (GetPcdPpiPointer ())->Get32 (TokenNumber
);
144 This function provides a means by which to retrieve a value for a given PCD token.
146 Returns the 64-bit value for the token specified by TokenNumber.
148 @param[in] TokenNumber The PCD token number to retrieve a current value for.
150 @return Returns the 64-bit value for the token specified by TokenNumber.
159 return (GetPcdPpiPointer ())->Get64 (TokenNumber
);
165 This function provides a means by which to retrieve a value for a given PCD token.
167 Returns the pointer to the buffer of the token specified by TokenNumber.
169 @param[in] TokenNumber The PCD token number to retrieve a current value for.
171 @return Returns the pointer to the token specified by TokenNumber.
180 return (GetPcdPpiPointer ())->GetPtr (TokenNumber
);
186 This function provides a means by which to retrieve a value for a given PCD token.
188 Returns the Boolean value of the token specified by TokenNumber.
190 @param[in] TokenNumber The PCD token number to retrieve a current value for.
192 @return Returns the Boolean value of the token specified by TokenNumber.
201 return (GetPcdPpiPointer ())->GetBool (TokenNumber
);
207 This function provides a means by which to retrieve the size of a given PCD token.
209 @param[in] TokenNumber The PCD token number to retrieve a current value for.
211 @return Returns the size of the token specified by TokenNumber.
220 return (GetPcdPpiPointer ())->GetSize (TokenNumber
);
226 This function provides a means by which to retrieve a value for a given PCD token.
228 Returns the 8-bit value for the token specified by TokenNumber and Guid.
230 If Guid is NULL, then ASSERT().
232 @param[in] Guid Pointer to a 128-bit unique value that designates
233 which namespace to retrieve a value from.
234 @param[in] TokenNumber The PCD token number to retrieve a current value for.
236 @return Return the UINT8.
246 ASSERT (Guid
!= NULL
);
248 return (GetPcdPpiPointer ())->Get8Ex (Guid
, TokenNumber
);
254 This function provides a means by which to retrieve a value for a given PCD token.
256 Returns the 16-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 @return Return the UINT16.
275 ASSERT (Guid
!= NULL
);
277 return (GetPcdPpiPointer ())->Get16Ex (Guid
, TokenNumber
);
283 Returns the 32-bit value for the token specified by TokenNumber and Guid.
284 If Guid is NULL, then ASSERT().
286 @param[in] Guid Pointer to a 128-bit unique value that designates
287 which namespace to retrieve a value from.
288 @param[in] TokenNumber The PCD token number to retrieve a current value for.
290 @return Return the UINT32.
300 ASSERT (Guid
!= NULL
);
302 return (GetPcdPpiPointer ())->Get32Ex (Guid
, TokenNumber
);
309 This function provides a means by which to retrieve a value for a given PCD token.
311 Returns the 64-bit value for the token specified by TokenNumber and Guid.
313 If Guid is NULL, then ASSERT().
315 @param[in] Guid Pointer to a 128-bit unique value that designates
316 which namespace to retrieve a value from.
317 @param[in] TokenNumber The PCD token number to retrieve a current value for.
319 @return Return the UINT64.
329 ASSERT (Guid
!= NULL
);
330 return (GetPcdPpiPointer ())->Get64Ex (Guid
, TokenNumber
);
336 This function provides a means by which to retrieve a value for a given PCD token.
338 Returns the pointer to the buffer of 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 @return Return the VOID* pointer.
356 ASSERT (Guid
!= NULL
);
358 return (GetPcdPpiPointer ())->GetPtrEx (Guid
, TokenNumber
);
364 This function provides a means by which to retrieve a value for a given PCD token.
366 Returns the Boolean value of the token specified by TokenNumber and Guid.
368 If Guid is NULL, then ASSERT().
370 @param[in] Guid Pointer to a 128-bit unique value that designates
371 which namespace to retrieve a value from.
372 @param[in] TokenNumber The PCD token number to retrieve a current value for.
374 @return Return the BOOLEAN.
384 ASSERT (Guid
!= NULL
);
385 return (GetPcdPpiPointer ())->GetBoolEx (Guid
, TokenNumber
);
391 This function provides a means by which to retrieve the size of a given PCD token.
393 Returns the size of the token specified by TokenNumber and Guid.
395 If Guid is NULL, then ASSERT().
397 @param[in] Guid Pointer to a 128-bit unique value that designates
398 which namespace to retrieve a value from.
399 @param[in] TokenNumber The PCD token number to retrieve a current value for.
401 @return Return the size.
411 ASSERT (Guid
!= NULL
);
412 return (GetPcdPpiPointer ())->GetSizeEx (Guid
, TokenNumber
);
418 This function provides a means by which to set a value for a given PCD token.
420 Sets the 8-bit value for the token specified by TokenNumber
421 to the value specified by Value. Value is returned.
423 @param[in] TokenNumber The PCD token number to set a current value for.
424 @param[in] Value The 8-bit value to set.
426 @return Return the value been set.
432 IN UINTN TokenNumber
,
438 Status
= (GetPcdPpiPointer ())->Set8 (TokenNumber
, Value
);
440 ASSERT_EFI_ERROR (Status
);
448 This function provides a means by which to set a value for a given PCD token.
450 Sets the 16-bit value for the token specified by TokenNumber
451 to the value specified by Value. Value is returned.
453 @param[in] TokenNumber The PCD token number to set a current value for.
454 @param[in] Value The 16-bit value to set.
456 @return Return the value been set.
462 IN UINTN TokenNumber
,
468 Status
= (GetPcdPpiPointer ())->Set16 (TokenNumber
, Value
);
470 ASSERT_EFI_ERROR (Status
);
478 This function provides a means by which to set a value for a given PCD token.
480 Sets the 32-bit value for the token specified by TokenNumber
481 to the value specified by Value. Value is returned.
483 @param[in] TokenNumber The PCD token number to set a current value for.
484 @param[in] Value The 32-bit value to set.
486 @return Return the value been set.
492 IN UINTN TokenNumber
,
498 Status
= (GetPcdPpiPointer ())->Set32 (TokenNumber
, Value
);
500 ASSERT_EFI_ERROR (Status
);
508 This function provides a means by which to set a value for a given PCD token.
510 Sets the 64-bit value for the token specified by TokenNumber
511 to the value specified by Value. Value is returned.
513 @param[in] TokenNumber The PCD token number to set a current value for.
514 @param[in] Value The 64-bit value to set.
516 @return Return the value been set.
522 IN UINTN TokenNumber
,
528 Status
= (GetPcdPpiPointer ())->Set64 (TokenNumber
, Value
);
530 ASSERT_EFI_ERROR (Status
);
538 This function provides a means by which to set a value for a given PCD token.
540 Sets a buffer for the token specified by TokenNumber to the value
541 specified by Buffer and SizeOfBuffer. Buffer is returned.
542 If SizeOfBuffer is greater than the maximum size support by TokenNumber,
543 then set SizeOfBuffer to the maximum size supported by TokenNumber and
544 return NULL to indicate that the set operation was not actually performed.
546 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
547 maximum size supported by TokenName and NULL must be returned.
549 If SizeOfBuffer is NULL, then ASSERT().
550 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
552 @param[in] TokenNumber The PCD token number to set a current value for.
553 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
554 @param[in] Buffer A pointer to the buffer to set.
556 @return Return the pointer for the buffer been set.
562 IN UINTN TokenNumber
,
563 IN OUT UINTN
*SizeOfBuffer
,
564 IN CONST VOID
*Buffer
569 ASSERT (SizeOfBuffer
!= NULL
);
571 if (*SizeOfBuffer
> 0) {
572 ASSERT (Buffer
!= NULL
);
575 Status
= (GetPcdPpiPointer ())->SetPtr (TokenNumber
, SizeOfBuffer
, (VOID
*) Buffer
);
577 if (EFI_ERROR (Status
)) {
581 return (VOID
*) Buffer
;
587 This function provides a means by which to set a value for a given PCD token.
589 Sets the Boolean value for the token specified by TokenNumber
590 to the value specified by Value. Value is returned.
592 @param[in] TokenNumber The PCD token number to set a current value for.
593 @param[in] Value The boolean value to set.
595 @return Return the value been set.
601 IN UINTN TokenNumber
,
607 Status
= (GetPcdPpiPointer ())->SetBool (TokenNumber
, Value
);
609 ASSERT_EFI_ERROR (Status
);
617 This function provides a means by which to set a value for a given PCD token.
619 Sets the 8-bit value for the token specified by TokenNumber and
620 Guid to the value specified by Value. Value is returned.
622 If Guid is NULL, then ASSERT().
624 @param[in] Guid Pointer to a 128-bit unique value that
625 designates which namespace to set a value from.
626 @param[in] TokenNumber The PCD token number to set a current value for.
627 @param[in] Value The 8-bit value to set.
629 @return Return the value been set.
636 IN UINTN TokenNumber
,
642 ASSERT (Guid
!= NULL
);
644 Status
= (GetPcdPpiPointer ())->Set8Ex (Guid
, TokenNumber
, Value
);
646 ASSERT_EFI_ERROR (Status
);
654 This function provides a means by which to set a value for a given PCD token.
656 Sets the 16-bit value for the token specified by TokenNumber and
657 Guid to the value specified by Value. Value is returned.
659 If Guid is NULL, then ASSERT().
661 @param[in] Guid Pointer to a 128-bit unique value that
662 designates which namespace to set a value from.
663 @param[in] TokenNumber The PCD token number to set a current value for.
664 @param[in] Value The 16-bit value to set.
666 @return Return the value been set.
673 IN UINTN TokenNumber
,
678 ASSERT (Guid
!= NULL
);
679 Status
= (GetPcdPpiPointer ())->Set16Ex (Guid
, TokenNumber
, Value
);
681 ASSERT_EFI_ERROR (Status
);
689 This function provides a means by which to set a value for a given PCD token.
691 Sets the 32-bit value for the token specified by TokenNumber and
692 Guid to the value specified by Value. Value is returned.
694 If Guid is NULL, then ASSERT().
696 @param[in] Guid Pointer to a 128-bit unique value that
697 designates which namespace to set a value from.
698 @param[in] TokenNumber The PCD token number to set a current value for.
699 @param[in] Value The 32-bit value to set.
701 @return Return the value been set.
708 IN UINTN TokenNumber
,
714 ASSERT (Guid
!= NULL
);
716 Status
= (GetPcdPpiPointer ())->Set32Ex (Guid
, TokenNumber
, Value
);
718 ASSERT_EFI_ERROR (Status
);
726 This function provides a means by which to set a value for a given PCD token.
728 Sets the 64-bit value for the token specified by TokenNumber and
729 Guid to the value specified by Value. Value is returned.
730 If Guid is NULL, then ASSERT().
732 @param[in] Guid Pointer to a 128-bit unique value that
733 designates which namespace to set a value from.
734 @param[in] TokenNumber The PCD token number to set a current value for.
735 @param[in] Value The 64-bit value to set.
737 @return Return the value been set.
744 IN UINTN TokenNumber
,
749 ASSERT (Guid
!= NULL
);
751 Status
= (GetPcdPpiPointer ())->Set64Ex (Guid
, TokenNumber
, Value
);
753 ASSERT_EFI_ERROR (Status
);
761 This function provides a means by which to set a value for a given PCD token.
763 Sets a buffer for the token specified by TokenNumber to the value specified by
764 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
765 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
766 supported by TokenNumber and return NULL to indicate that the set operation
767 was not actually performed.
769 If Guid is NULL, then ASSERT().
770 If SizeOfBuffer is NULL, then ASSERT().
771 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
773 @param[in] Guid Pointer to a 128-bit unique value that
774 designates which namespace to set a value from.
775 @param[in] TokenNumber The PCD token number to set a current value for.
776 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
777 @param[in] Buffer A pointer to the buffer to set.
779 @return Return the pinter to the buffer been set.
786 IN UINTN TokenNumber
,
787 IN OUT UINTN
*SizeOfBuffer
,
792 ASSERT (SizeOfBuffer
!= NULL
);
793 if (*SizeOfBuffer
> 0) {
794 ASSERT (Buffer
!= NULL
);
796 ASSERT (Guid
!= NULL
);
798 Status
= (GetPcdPpiPointer ())->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
800 if (EFI_ERROR (Status
)) {
810 This function provides a means by which to set a value for a given PCD token.
812 Sets the Boolean value for the token specified by TokenNumber and
813 Guid to the value specified by Value. Value is returned.
815 If Guid is NULL, then ASSERT().
817 @param[in] Guid Pointer to a 128-bit unique value that
818 designates which namespace to set a value from.
819 @param[in] TokenNumber The PCD token number to set a current value for.
820 @param[in] Value The Boolean value to set.
822 @return Return the value been set.
829 IN UINTN TokenNumber
,
835 ASSERT (Guid
!= NULL
);
836 Status
= (GetPcdPpiPointer ())->SetBoolEx (Guid
, TokenNumber
, Value
);
838 ASSERT_EFI_ERROR (Status
);
846 Set up a notification function that is called when a specified token is set.
848 When the token specified by TokenNumber and Guid is set,
849 then notification function specified by NotificationFunction is called.
850 If Guid is NULL, then the default token space is used.
852 If NotificationFunction is NULL, then ASSERT().
854 @param[in] Guid Pointer to a 128-bit unique value that designates which
855 namespace to set a value from. If NULL, then the default
857 @param[in] TokenNumber The PCD token number to monitor.
858 @param[in] NotificationFunction The function to call when the token
859 specified by Guid and TokenNumber is set.
864 LibPcdCallbackOnSet (
865 IN CONST GUID
*Guid
, OPTIONAL
866 IN UINTN TokenNumber
,
867 IN PCD_CALLBACK NotificationFunction
872 ASSERT (NotificationFunction
!= NULL
);
874 Status
= (GetPcdPpiPointer ())->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
876 ASSERT_EFI_ERROR (Status
);
884 Disable a notification function that was established with LibPcdCallbackonSet().
886 Disable a notification function that was previously established with LibPcdCallbackOnSet().
888 If NotificationFunction is NULL, then ASSERT().
889 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
890 and NotificationFunction, then ASSERT().
892 @param[in] Guid Specify the GUID token space.
893 @param[in] TokenNumber Specify the token number.
894 @param[in] NotificationFunction The callback function to be unregistered.
899 LibPcdCancelCallback (
900 IN CONST GUID
*Guid
, OPTIONAL
901 IN UINTN TokenNumber
,
902 IN PCD_CALLBACK NotificationFunction
907 ASSERT (NotificationFunction
!= NULL
);
909 Status
= (GetPcdPpiPointer ())->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
911 ASSERT_EFI_ERROR (Status
);
919 Retrieves the next token in a token space.
921 Retrieves the next PCD token number from the token space specified by Guid.
922 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
923 then the first token number is returned. Otherwise, the token number that
924 follows TokenNumber in the token space is returned. If TokenNumber is the last
925 token number in the token space, then 0 is returned.
927 If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
929 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
930 to set a value from. If NULL, then the default token space is used.
931 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
934 @return The next valid token number.
940 IN CONST GUID
*Guid
, OPTIONAL
946 Status
= (GetPcdPpiPointer ())->GetNextToken (Guid
, &TokenNumber
);
948 ASSERT_EFI_ERROR (Status
);
955 Used to retrieve the list of available PCD token space GUIDs.
957 Retrieves the next PCD token space from a token space specified by Guid.
958 Guid of NULL is reserved to mark the default local token namespace on the current
959 platform. If Guid is NULL, then the GUID of the first non-local token space of the
960 current platform is returned. If Guid is the last non-local token space,
961 then NULL is returned.
963 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
967 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
970 @return The next valid token namespace.
975 LibPcdGetNextTokenSpace (
976 IN CONST GUID
*TokenSpaceGuid
981 Status
= (GetPcdPpiPointer ())->GetNextTokenSpace (&TokenSpaceGuid
);
983 ASSERT_EFI_ERROR (Status
);
985 return (GUID
*) TokenSpaceGuid
;
991 Sets a value of a patchable PCD entry that is type pointer.
993 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
994 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
995 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
996 NULL to indicate that the set operation was not actually performed.
997 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
998 MaximumDatumSize and NULL must be returned.
1000 If PatchVariable is NULL, then ASSERT().
1001 If SizeOfBuffer is NULL, then ASSERT().
1002 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1004 @param[in] PatchVariable A pointer to the global variable in a module that is
1005 the target of the set operation.
1006 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1007 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1008 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1010 @return Return the pointer to the buffer been set.
1016 IN VOID
*PatchVariable
,
1017 IN UINTN MaximumDatumSize
,
1018 IN OUT UINTN
*SizeOfBuffer
,
1019 IN CONST VOID
*Buffer
1022 ASSERT (PatchVariable
!= NULL
);
1023 ASSERT (SizeOfBuffer
!= NULL
);
1025 if (*SizeOfBuffer
> 0) {
1026 ASSERT (Buffer
!= NULL
);
1029 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1030 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1031 *SizeOfBuffer
= MaximumDatumSize
;
1035 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1037 return (VOID
*) Buffer
;