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.
55 If SkuId >= PCD_MAX_SKU_ID, then ASSERT().
57 @param SkuId The SKU value that will be used when the PCD service retrieves and sets values
58 associated with a PCD token.
60 @return Return the SKU ID that just be set.
70 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
72 GetPcdPpiPointer()->SetSku (SkuId
);
80 This function provides a means by which to retrieve a value for a given PCD token.
82 Returns the 8-bit value for the token specified by TokenNumber.
84 @param[in] TokenNumber The PCD token number to retrieve a current value for.
86 @return Returns the 8-bit value for the token specified by TokenNumber.
95 return (GetPcdPpiPointer ())->Get8 (TokenNumber
);
101 This function provides a means by which to retrieve a value for a given PCD token.
103 Returns the 16-bit value for the token specified by TokenNumber.
105 @param[in] TokenNumber The PCD token number to retrieve a current value for.
107 @return Returns the 16-bit value for the token specified by TokenNumber.
116 return (GetPcdPpiPointer ())->Get16 (TokenNumber
);
122 This function provides a means by which to retrieve a value for a given PCD token.
124 Returns the 32-bit value for the token specified by TokenNumber.
126 @param[in] TokenNumber The PCD token number to retrieve a current value for.
128 @return Returns the 32-bit value for the token specified by TokenNumber.
137 return (GetPcdPpiPointer ())->Get32 (TokenNumber
);
143 This function provides a means by which to retrieve a value for a given PCD token.
145 Returns the 64-bit value for the token specified by TokenNumber.
147 @param[in] TokenNumber The PCD token number to retrieve a current value for.
149 @return Returns the 64-bit value for the token specified by TokenNumber.
158 return (GetPcdPpiPointer ())->Get64 (TokenNumber
);
164 This function provides a means by which to retrieve a value for a given PCD token.
166 Returns the pointer to the buffer of the token specified by TokenNumber.
168 @param[in] TokenNumber The PCD token number to retrieve a current value for.
170 @return Returns the pointer to the token specified by TokenNumber.
179 return (GetPcdPpiPointer ())->GetPtr (TokenNumber
);
185 This function provides a means by which to retrieve a value for a given PCD token.
187 Returns the Boolean value of the token specified by TokenNumber.
189 @param[in] TokenNumber The PCD token number to retrieve a current value for.
191 @return Returns the Boolean value of the token specified by TokenNumber.
200 return (GetPcdPpiPointer ())->GetBool (TokenNumber
);
206 This function provides a means by which to retrieve the size of a given PCD token.
208 @param[in] TokenNumber The PCD token number to retrieve a current value for.
210 @return Returns the size of the token specified by TokenNumber.
219 return (GetPcdPpiPointer ())->GetSize (TokenNumber
);
225 This function provides a means by which to retrieve a value for a given PCD token.
227 Returns the 8-bit value for the token specified by TokenNumber and Guid.
229 If Guid is NULL, then ASSERT().
231 @param[in] Guid Pointer to a 128-bit unique value that designates
232 which namespace to retrieve a value from.
233 @param[in] TokenNumber The PCD token number to retrieve a current value for.
235 @return Return the UINT8.
245 ASSERT (Guid
!= NULL
);
247 return (GetPcdPpiPointer ())->Get8Ex (Guid
, TokenNumber
);
253 This function provides a means by which to retrieve a value for a given PCD token.
255 Returns the 16-bit value for the token specified by TokenNumber and Guid.
257 If Guid is NULL, then ASSERT().
259 @param[in] Guid Pointer to a 128-bit unique value that designates
260 which namespace to retrieve a value from.
261 @param[in] TokenNumber The PCD token number to retrieve a current value for.
263 @return Return the UINT16.
274 ASSERT (Guid
!= NULL
);
276 return (GetPcdPpiPointer ())->Get16Ex (Guid
, TokenNumber
);
282 Returns the 32-bit value for the token specified by TokenNumber and Guid.
283 If Guid is NULL, then ASSERT().
285 @param[in] Guid Pointer to a 128-bit unique value that designates
286 which namespace to retrieve a value from.
287 @param[in] TokenNumber The PCD token number to retrieve a current value for.
289 @return Return the UINT32.
299 ASSERT (Guid
!= NULL
);
301 return (GetPcdPpiPointer ())->Get32Ex (Guid
, TokenNumber
);
308 This function provides a means by which to retrieve a value for a given PCD token.
310 Returns the 64-bit value for the token specified by TokenNumber and Guid.
312 If Guid is NULL, then ASSERT().
314 @param[in] Guid Pointer to a 128-bit unique value that designates
315 which namespace to retrieve a value from.
316 @param[in] TokenNumber The PCD token number to retrieve a current value for.
318 @return Return the UINT64.
328 ASSERT (Guid
!= NULL
);
329 return (GetPcdPpiPointer ())->Get64Ex (Guid
, TokenNumber
);
335 This function provides a means by which to retrieve a value for a given PCD token.
337 Returns the pointer to the buffer of token specified by TokenNumber and Guid.
339 If Guid is NULL, then ASSERT().
341 @param[in] Guid Pointer to a 128-bit unique value that designates
342 which namespace to retrieve a value from.
343 @param[in] TokenNumber The PCD token number to retrieve a current value for.
345 @return Return the VOID* pointer.
355 ASSERT (Guid
!= NULL
);
357 return (GetPcdPpiPointer ())->GetPtrEx (Guid
, TokenNumber
);
363 This function provides a means by which to retrieve a value for a given PCD token.
365 Returns the Boolean value of the token specified by TokenNumber and Guid.
367 If Guid is NULL, then ASSERT().
369 @param[in] Guid Pointer to a 128-bit unique value that designates
370 which namespace to retrieve a value from.
371 @param[in] TokenNumber The PCD token number to retrieve a current value for.
373 @return Return the BOOLEAN.
383 ASSERT (Guid
!= NULL
);
384 return (GetPcdPpiPointer ())->GetBoolEx (Guid
, TokenNumber
);
390 This function provides a means by which to retrieve the size of a given PCD token.
392 Returns the size of the token specified by TokenNumber and Guid.
394 If Guid is NULL, then ASSERT().
396 @param[in] Guid Pointer to a 128-bit unique value that designates
397 which namespace to retrieve a value from.
398 @param[in] TokenNumber The PCD token number to retrieve a current value for.
400 @return Return the size.
410 ASSERT (Guid
!= NULL
);
411 return (GetPcdPpiPointer ())->GetSizeEx (Guid
, TokenNumber
);
417 This function provides a means by which to set a value for a given PCD token.
419 Sets the 8-bit value for the token specified by TokenNumber
420 to the value specified by Value. Value is returned.
422 @param[in] TokenNumber The PCD token number to set a current value for.
423 @param[in] Value The 8-bit value to set.
425 @return Return the value been set.
431 IN UINTN TokenNumber
,
437 Status
= (GetPcdPpiPointer ())->Set8 (TokenNumber
, Value
);
439 ASSERT_EFI_ERROR (Status
);
447 This function provides a means by which to set a value for a given PCD token.
449 Sets the 16-bit value for the token specified by TokenNumber
450 to the value specified by Value. Value is returned.
452 @param[in] TokenNumber The PCD token number to set a current value for.
453 @param[in] Value The 16-bit value to set.
455 @return Return the value been set.
461 IN UINTN TokenNumber
,
467 Status
= (GetPcdPpiPointer ())->Set16 (TokenNumber
, Value
);
469 ASSERT_EFI_ERROR (Status
);
477 This function provides a means by which to set a value for a given PCD token.
479 Sets the 32-bit value for the token specified by TokenNumber
480 to the value specified by Value. Value is returned.
482 @param[in] TokenNumber The PCD token number to set a current value for.
483 @param[in] Value The 32-bit value to set.
485 @return Return the value been set.
491 IN UINTN TokenNumber
,
497 Status
= (GetPcdPpiPointer ())->Set32 (TokenNumber
, Value
);
499 ASSERT_EFI_ERROR (Status
);
507 This function provides a means by which to set a value for a given PCD token.
509 Sets the 64-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 64-bit value to set.
515 @return Return the value been set.
521 IN UINTN TokenNumber
,
527 Status
= (GetPcdPpiPointer ())->Set64 (TokenNumber
, Value
);
529 ASSERT_EFI_ERROR (Status
);
537 This function provides a means by which to set a value for a given PCD token.
539 Sets a buffer for the token specified by TokenNumber to the value
540 specified by Buffer and SizeOfBuffer. Buffer is returned.
541 If SizeOfBuffer is greater than the maximum size support by TokenNumber,
542 then set SizeOfBuffer to the maximum size supported by TokenNumber and
543 return NULL to indicate that the set operation was not actually performed.
545 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
546 maximum size supported by TokenName and NULL must be returned.
548 If SizeOfBuffer is NULL, then ASSERT().
549 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
551 @param[in] TokenNumber The PCD token number to set a current value for.
552 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
553 @param[in] Buffer A pointer to the buffer to set.
555 @return Return the pointer for the buffer been set.
561 IN UINTN TokenNumber
,
562 IN OUT UINTN
*SizeOfBuffer
,
563 IN CONST VOID
*Buffer
568 ASSERT (SizeOfBuffer
!= NULL
);
570 if (*SizeOfBuffer
> 0) {
571 ASSERT (Buffer
!= NULL
);
574 Status
= (GetPcdPpiPointer ())->SetPtr (TokenNumber
, SizeOfBuffer
, (VOID
*) Buffer
);
576 if (EFI_ERROR (Status
)) {
580 return (VOID
*) Buffer
;
586 This function provides a means by which to set a value for a given PCD token.
588 Sets the Boolean value for the token specified by TokenNumber
589 to the value specified by Value. Value is returned.
591 @param[in] TokenNumber The PCD token number to set a current value for.
592 @param[in] Value The boolean value to set.
594 @return Return the value been set.
600 IN UINTN TokenNumber
,
606 Status
= (GetPcdPpiPointer ())->SetBool (TokenNumber
, Value
);
608 ASSERT_EFI_ERROR (Status
);
616 This function provides a means by which to set a value for a given PCD token.
618 Sets the 8-bit value for the token specified by TokenNumber and
619 Guid to the value specified by Value. Value is returned.
621 If Guid is NULL, then ASSERT().
623 @param[in] Guid Pointer to a 128-bit unique value that
624 designates which namespace to set a value from.
625 @param[in] TokenNumber The PCD token number to set a current value for.
626 @param[in] Value The 8-bit value to set.
628 @return Return the value been set.
635 IN UINTN TokenNumber
,
641 ASSERT (Guid
!= NULL
);
643 Status
= (GetPcdPpiPointer ())->Set8Ex (Guid
, TokenNumber
, Value
);
645 ASSERT_EFI_ERROR (Status
);
653 This function provides a means by which to set a value for a given PCD token.
655 Sets the 16-bit value for the token specified by TokenNumber and
656 Guid to the value specified by Value. Value is returned.
658 If Guid is NULL, then ASSERT().
660 @param[in] Guid Pointer to a 128-bit unique value that
661 designates which namespace to set a value from.
662 @param[in] TokenNumber The PCD token number to set a current value for.
663 @param[in] Value The 16-bit value to set.
665 @return Return the value been set.
672 IN UINTN TokenNumber
,
677 ASSERT (Guid
!= NULL
);
678 Status
= (GetPcdPpiPointer ())->Set16Ex (Guid
, TokenNumber
, Value
);
680 ASSERT_EFI_ERROR (Status
);
688 This function provides a means by which to set a value for a given PCD token.
690 Sets the 32-bit value for the token specified by TokenNumber and
691 Guid to the value specified by Value. Value is returned.
693 If Guid is NULL, then ASSERT().
695 @param[in] Guid Pointer to a 128-bit unique value that
696 designates which namespace to set a value from.
697 @param[in] TokenNumber The PCD token number to set a current value for.
698 @param[in] Value The 32-bit value to set.
700 @return Return the value been set.
707 IN UINTN TokenNumber
,
713 ASSERT (Guid
!= NULL
);
715 Status
= (GetPcdPpiPointer ())->Set32Ex (Guid
, TokenNumber
, Value
);
717 ASSERT_EFI_ERROR (Status
);
725 This function provides a means by which to set a value for a given PCD token.
727 Sets the 64-bit value for the token specified by TokenNumber and
728 Guid to the value specified by Value. Value is returned.
729 If Guid is NULL, then ASSERT().
731 @param[in] Guid Pointer to a 128-bit unique value that
732 designates which namespace to set a value from.
733 @param[in] TokenNumber The PCD token number to set a current value for.
734 @param[in] Value The 64-bit value to set.
736 @return Return the value been set.
743 IN UINTN TokenNumber
,
748 ASSERT (Guid
!= NULL
);
750 Status
= (GetPcdPpiPointer ())->Set64Ex (Guid
, TokenNumber
, Value
);
752 ASSERT_EFI_ERROR (Status
);
760 This function provides a means by which to set a value for a given PCD token.
762 Sets a buffer for the token specified by TokenNumber to the value specified by
763 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
764 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
765 supported by TokenNumber and return NULL to indicate that the set operation
766 was not actually performed.
768 If Guid is NULL, then ASSERT().
769 If SizeOfBuffer is NULL, then ASSERT().
770 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
772 @param[in] Guid Pointer to a 128-bit unique value that
773 designates which namespace to set a value from.
774 @param[in] TokenNumber The PCD token number to set a current value for.
775 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
776 @param[in] Buffer A pointer to the buffer to set.
778 @return Return the pinter to the buffer been set.
785 IN UINTN TokenNumber
,
786 IN OUT UINTN
*SizeOfBuffer
,
791 ASSERT (SizeOfBuffer
!= NULL
);
792 if (*SizeOfBuffer
> 0) {
793 ASSERT (Buffer
!= NULL
);
795 ASSERT (Guid
!= NULL
);
797 Status
= (GetPcdPpiPointer ())->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
799 if (EFI_ERROR (Status
)) {
809 This function provides a means by which to set a value for a given PCD token.
811 Sets the Boolean value for the token specified by TokenNumber and
812 Guid to the value specified by Value. Value is returned.
814 If Guid is NULL, then ASSERT().
816 @param[in] Guid Pointer to a 128-bit unique value that
817 designates which namespace to set a value from.
818 @param[in] TokenNumber The PCD token number to set a current value for.
819 @param[in] Value The Boolean value to set.
821 @return Return the value been set.
828 IN UINTN TokenNumber
,
834 ASSERT (Guid
!= NULL
);
835 Status
= (GetPcdPpiPointer ())->SetBoolEx (Guid
, TokenNumber
, Value
);
837 ASSERT_EFI_ERROR (Status
);
845 Set up a notification function that is called when a specified token is set.
847 When the token specified by TokenNumber and Guid is set,
848 then notification function specified by NotificationFunction is called.
849 If Guid is NULL, then the default token space is used.
850 If NotificationFunction is NULL, then ASSERT().
852 @param[in] Guid Pointer to a 128-bit unique value that designates which
853 namespace to set a value from. If NULL, then the default
855 @param[in] TokenNumber The PCD token number to monitor.
856 @param[in] NotificationFunction The function to call when the token
857 specified by Guid and TokenNumber is set.
862 LibPcdCallbackOnSet (
863 IN CONST GUID
*Guid
, OPTIONAL
864 IN UINTN TokenNumber
,
865 IN PCD_CALLBACK NotificationFunction
870 ASSERT (NotificationFunction
!= NULL
);
872 Status
= (GetPcdPpiPointer ())->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
874 ASSERT_EFI_ERROR (Status
);
882 Disable a notification function that was established with LibPcdCallbackonSet().
884 Disable a notification function that was previously established with LibPcdCallbackOnSet().
885 If NotificationFunction is NULL, then ASSERT().
886 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
887 and NotificationFunction, then ASSERT().
889 @param[in] Guid Specify the GUID token space.
890 @param[in] TokenNumber Specify the token number.
891 @param[in] NotificationFunction The callback function to be unregistered.
896 LibPcdCancelCallback (
897 IN CONST GUID
*Guid
, OPTIONAL
898 IN UINTN TokenNumber
,
899 IN PCD_CALLBACK NotificationFunction
904 ASSERT (NotificationFunction
!= NULL
);
906 Status
= (GetPcdPpiPointer ())->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
908 ASSERT_EFI_ERROR (Status
);
916 Retrieves the next token in a token space.
918 Retrieves the next PCD token number from the token space specified by Guid.
919 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
920 then the first token number is returned. Otherwise, the token number that
921 follows TokenNumber in the token space is returned. If TokenNumber is the last
922 token number in the token space, then 0 is returned.
924 If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
926 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
927 to set a value from. If NULL, then the default token space is used.
928 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
931 @return The next valid token number.
937 IN CONST GUID
*Guid
, OPTIONAL
943 Status
= (GetPcdPpiPointer ())->GetNextToken (Guid
, &TokenNumber
);
945 ASSERT_EFI_ERROR (Status
);
952 Used to retrieve the list of available PCD token space GUIDs.
954 Returns the PCD token space GUID that follows TokenSpaceGuid in the list of token spaces
956 If TokenSpaceGuid is NULL, then a pointer to the first PCD token spaces returned.
957 If TokenSpaceGuid is the last PCD token space GUID in the list, then NULL is returned.
959 @param TokenSpaceGuid Pointer to the a PCD token space GUID
961 @return The next valid token namespace.
966 LibPcdGetNextTokenSpace (
967 IN CONST GUID
*TokenSpaceGuid
972 Status
= (GetPcdPpiPointer ())->GetNextTokenSpace (&TokenSpaceGuid
);
974 ASSERT_EFI_ERROR (Status
);
976 return (GUID
*) TokenSpaceGuid
;
982 Sets a value of a patchable PCD entry that is type pointer.
984 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
985 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
986 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
987 NULL to indicate that the set operation was not actually performed.
988 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
989 MaximumDatumSize and NULL must be returned.
991 If PatchVariable is NULL, then ASSERT().
992 If SizeOfBuffer is NULL, then ASSERT().
993 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
995 @param[in] PatchVariable A pointer to the global variable in a module that is
996 the target of the set operation.
997 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
998 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
999 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1001 @return Return the pointer to the buffer been set.
1007 IN VOID
*PatchVariable
,
1008 IN UINTN MaximumDatumSize
,
1009 IN OUT UINTN
*SizeOfBuffer
,
1010 IN CONST VOID
*Buffer
1013 ASSERT (PatchVariable
!= NULL
);
1014 ASSERT (SizeOfBuffer
!= NULL
);
1016 if (*SizeOfBuffer
> 0) {
1017 ASSERT (Buffer
!= NULL
);
1020 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1021 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1022 *SizeOfBuffer
= MaximumDatumSize
;
1026 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1028 return (VOID
*) Buffer
;