2 Implementation of PcdLib class library for DXE phase.
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 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.
19 #include <Protocol/Pcd.h>
20 #include <Protocol/PiPcd.h>
22 #include <Library/PcdLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/BaseMemoryLib.h>
27 PCD_PROTOCOL
*mPcd
= NULL
;
28 EFI_PCD_PROTOCOL
*mPiPcd
= NULL
;
31 Retrieves the PI PCD protocol from the handle database.
43 // PI Pcd protocol defined in PI 1.2 vol3 should be installed before the module
44 // access DynamicEx type PCD.
46 Status
= gBS
->LocateProtocol (&gEfiPcdProtocolGuid
, NULL
, (VOID
**) &mPiPcd
);
47 ASSERT_EFI_ERROR (Status
);
48 ASSERT (mPiPcd
!= NULL
);
54 Retrieves the PCD protocol from the handle database.
66 // PCD protocol need to be installed before the module access Dynamic type PCD.
67 // But dynamic type PCD is not required in PI 1.2 specification.
69 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
70 ASSERT_EFI_ERROR (Status
);
71 ASSERT (mPcd
!= NULL
);
78 This function provides a means by which SKU support can be established in the PCD infrastructure.
80 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
81 If SkuId >= PCD_MAX_SKU_ID, then ASSERT().
83 @param SkuId The SKU value that will be used when the PCD service retrieves and sets values
84 associated with a PCD token.
86 @return Return the SKU ID that just be set.
95 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
97 GetPcdProtocol()->SetSku (SkuId
);
105 This function provides a means by which to retrieve a value for a given PCD token.
107 Returns the 8-bit value for the token specified by TokenNumber.
109 @param[in] TokenNumber The PCD token number to retrieve a current value for.
111 @return Returns the 8-bit value for the token specified by TokenNumber.
120 return GetPcdProtocol()->Get8 (TokenNumber
);
126 This function provides a means by which to retrieve a value for a given PCD token.
128 Returns the 16-bit value for the token specified by TokenNumber.
130 @param[in] TokenNumber The PCD token number to retrieve a current value for.
132 @return Returns the 16-bit value for the token specified by TokenNumber.
141 return GetPcdProtocol()->Get16 (TokenNumber
);
147 This function provides a means by which to retrieve a value for a given PCD token.
149 Returns the 32-bit value for the token specified by TokenNumber.
151 @param[in] TokenNumber The PCD token number to retrieve a current value for.
153 @return Returns the 32-bit value for the token specified by TokenNumber.
162 return GetPcdProtocol()->Get32 (TokenNumber
);
168 This function provides a means by which to retrieve a value for a given PCD token.
170 Returns the 64-bit value for the token specified by TokenNumber.
172 @param[in] TokenNumber The PCD token number to retrieve a current value for.
174 @return Returns the 64-bit value for the token specified by TokenNumber.
183 return GetPcdProtocol()->Get64 (TokenNumber
);
189 This function provides a means by which to retrieve a value for a given PCD token.
191 Returns the pointer to the buffer of the token specified by TokenNumber.
193 @param[in] TokenNumber The PCD token number to retrieve a current value for.
195 @return Returns the pointer to the token specified by TokenNumber.
204 return GetPcdProtocol()->GetPtr (TokenNumber
);
210 This function provides a means by which to retrieve a value for a given PCD token.
212 Returns the Boolean value of the token specified by TokenNumber.
214 @param[in] TokenNumber The PCD token number to retrieve a current value for.
216 @return Returns the Boolean value of the token specified by TokenNumber.
225 return GetPcdProtocol()->GetBool (TokenNumber
);
231 This function provides a means by which to retrieve the size of a given PCD token.
233 @param[in] TokenNumber The PCD token number to retrieve a current value for.
235 @return Returns the size of the token specified by TokenNumber.
244 return GetPcdProtocol()->GetSize (TokenNumber
);
250 This function provides a means by which to retrieve a value for a given PCD token.
252 Returns the 8-bit value for the token specified by TokenNumber and Guid.
254 If Guid is NULL, then ASSERT().
256 @param[in] Guid The pointer to a 128-bit unique value that designates
257 which namespace to retrieve a value from.
258 @param[in] TokenNumber The PCD token number to retrieve a current value for.
260 @return Return the UINT8.
270 ASSERT (Guid
!= NULL
);
272 return GetPiPcdProtocol()->Get8 (Guid
, TokenNumber
);
277 This function provides a means by which to retrieve a value for a given PCD token.
279 Returns the 16-bit value for the token specified by TokenNumber and Guid.
281 If Guid is NULL, then ASSERT().
283 @param[in] Guid The 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 @return Return the UINT16.
297 ASSERT (Guid
!= NULL
);
299 return GetPiPcdProtocol()->Get16 (Guid
, TokenNumber
);
304 Returns the 32-bit value for the token specified by TokenNumber and Guid.
305 If Guid is NULL, then ASSERT().
307 @param[in] Guid The pointer to a 128-bit unique value that designates
308 which namespace to retrieve a value from.
309 @param[in] TokenNumber The PCD token number to retrieve a current value for.
311 @return Return the UINT32.
321 ASSERT (Guid
!= NULL
);
323 return GetPiPcdProtocol()->Get32 (Guid
, TokenNumber
);
329 This function provides a means by which to retrieve a value for a given PCD token.
331 Returns the 64-bit value for the token specified by TokenNumber and Guid.
333 If Guid is NULL, then ASSERT().
335 @param[in] Guid The pointer to a 128-bit unique value that designates
336 which namespace to retrieve a value from.
337 @param[in] TokenNumber The PCD token number to retrieve a current value for.
339 @return Return the UINT64.
349 ASSERT (Guid
!= NULL
);
351 return GetPiPcdProtocol()->Get64 (Guid
, TokenNumber
);
357 This function provides a means by which to retrieve a value for a given PCD token.
359 Returns the pointer to the buffer of token specified by TokenNumber and Guid.
361 If Guid is NULL, then ASSERT().
363 @param[in] Guid The 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 @return Return the VOID* pointer.
377 ASSERT (Guid
!= NULL
);
379 return GetPiPcdProtocol()->GetPtr (Guid
, TokenNumber
);
385 This function provides a means by which to retrieve a value for a given PCD token.
387 Returns the Boolean value of the token specified by TokenNumber and Guid.
389 If Guid is NULL, then ASSERT().
391 @param[in] Guid The pointer to a 128-bit unique value that designates
392 which namespace to retrieve a value from.
393 @param[in] TokenNumber The PCD token number to retrieve a current value for.
395 @return Return the BOOLEAN.
405 ASSERT (Guid
!= NULL
);
407 return GetPiPcdProtocol()->GetBool (Guid
, TokenNumber
);
413 This function provides a means by which to retrieve the size of a given PCD token.
415 Returns the size of the token specified by TokenNumber and Guid.
417 If Guid is NULL, then ASSERT().
419 @param[in] Guid The pointer to a 128-bit unique value that designates
420 which namespace to retrieve a value from.
421 @param[in] TokenNumber The PCD token number to retrieve a current value for.
423 @return Return the size.
433 ASSERT (Guid
!= NULL
);
435 return GetPiPcdProtocol()->GetSize (Guid
, TokenNumber
);
441 This function provides a means by which to set a value for a given PCD token.
443 Sets the 8-bit value for the token specified by TokenNumber
444 to the value specified by Value. Value is returned.
446 @param[in] TokenNumber The PCD token number to set a current value for.
447 @param[in] Value The 8-bit value to set.
449 @return Return the value that was set.
455 IN UINTN TokenNumber
,
461 Status
= GetPcdProtocol()->Set8 (TokenNumber
, Value
);
462 ASSERT_EFI_ERROR (Status
);
470 This function provides a means by which to set a value for a given PCD token.
472 Sets the 16-bit value for the token specified by TokenNumber
473 to the value specified by Value. Value is returned.
475 @param[in] TokenNumber The PCD token number to set a current value for.
476 @param[in] Value The 16-bit value to set.
478 @return Return the value that was set.
484 IN UINTN TokenNumber
,
490 Status
= GetPcdProtocol()->Set16 (TokenNumber
, Value
);
491 ASSERT_EFI_ERROR (Status
);
499 This function provides a means by which to set a value for a given PCD token.
501 Sets the 32-bit value for the token specified by TokenNumber
502 to the value specified by Value. Value is returned.
504 @param[in] TokenNumber The PCD token number to set a current value for.
505 @param[in] Value The 32-bit value to set.
507 @return Return the value that was set.
513 IN UINTN TokenNumber
,
519 Status
= GetPcdProtocol()->Set32 (TokenNumber
, Value
);
520 ASSERT_EFI_ERROR (Status
);
528 This function provides a means by which to set a value for a given PCD token.
530 Sets the 64-bit value for the token specified by TokenNumber
531 to the value specified by Value. Value is returned.
533 @param[in] TokenNumber The PCD token number to set a current value for.
534 @param[in] Value The 64-bit value to set.
536 @return Return the value that was set.
542 IN UINTN TokenNumber
,
548 Status
= GetPcdProtocol()->Set64 (TokenNumber
, Value
);
549 ASSERT_EFI_ERROR (Status
);
557 This function provides a means by which to set a value for a given PCD token.
559 Sets a buffer for the token specified by TokenNumber to the value
560 specified by Buffer and SizeOfBuffer. Buffer is returned.
561 If SizeOfBuffer is greater than the maximum size support by TokenNumber,
562 then set SizeOfBuffer to the maximum size supported by TokenNumber and
563 return NULL to indicate that the set operation was not actually performed.
565 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
566 maximum size supported by TokenName and NULL must be returned.
568 If SizeOfBuffer is NULL, then ASSERT().
569 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
571 @param[in] TokenNumber The PCD token number to set a current value for.
572 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
573 @param[in] Buffer A pointer to the buffer to set.
575 @return Return the pointer for the buffer been set.
581 IN UINTN TokenNumber
,
582 IN OUT UINTN
*SizeOfBuffer
,
583 IN CONST VOID
*Buffer
588 ASSERT (SizeOfBuffer
!= NULL
);
590 if (*SizeOfBuffer
> 0) {
591 ASSERT (Buffer
!= NULL
);
594 Status
= GetPcdProtocol()->SetPtr (TokenNumber
, SizeOfBuffer
, (VOID
*) Buffer
);
595 if (EFI_ERROR (Status
)) {
599 return (VOID
*)Buffer
;
605 This function provides a means by which to set a value for a given PCD token.
607 Sets the Boolean value for the token specified by TokenNumber
608 to the value specified by Value. Value is returned.
610 @param[in] TokenNumber The PCD token number to set a current value for.
611 @param[in] Value The boolean value to set.
613 @return Return the value that was set.
619 IN UINTN TokenNumber
,
625 Status
= GetPcdProtocol()->SetBool (TokenNumber
, Value
);
626 ASSERT_EFI_ERROR (Status
);
634 This function provides a means by which to set a value for a given PCD token.
636 Sets the 8-bit value for the token specified by TokenNumber and
637 Guid to the value specified by Value. Value is returned.
639 If Guid is NULL, then ASSERT().
641 @param[in] Guid The pointer to a 128-bit unique value that
642 designates which namespace to set a value from.
643 @param[in] TokenNumber The PCD token number to set a current value for.
644 @param[in] Value The 8-bit value to set.
646 @return Return the value that was set.
653 IN UINTN TokenNumber
,
659 ASSERT (Guid
!= NULL
);
661 Status
= GetPiPcdProtocol()->Set8 (Guid
, TokenNumber
, Value
);
662 ASSERT_EFI_ERROR (Status
);
670 This function provides a means by which to set a value for a given PCD token.
672 Sets the 16-bit value for the token specified by TokenNumber and
673 Guid to the value specified by Value. Value is returned.
675 If Guid is NULL, then ASSERT().
677 @param[in] Guid The pointer to a 128-bit unique value that
678 designates which namespace to set a value from.
679 @param[in] TokenNumber The PCD token number to set a current value for.
680 @param[in] Value The 16-bit value to set.
682 @return Return the value that was set.
689 IN UINTN TokenNumber
,
695 ASSERT (Guid
!= NULL
);
697 Status
= GetPiPcdProtocol()->Set16 (Guid
, TokenNumber
, Value
);
698 ASSERT_EFI_ERROR (Status
);
706 This function provides a means by which to set a value for a given PCD token.
708 Sets the 32-bit value for the token specified by TokenNumber and
709 Guid to the value specified by Value. Value is returned.
711 If Guid is NULL, then ASSERT().
713 @param[in] Guid The pointer to a 128-bit unique value that
714 designates which namespace to set a value from.
715 @param[in] TokenNumber The PCD token number to set a current value for.
716 @param[in] Value The 32-bit value to set.
718 @return Return the value that was set.
725 IN UINTN TokenNumber
,
731 ASSERT (Guid
!= NULL
);
733 Status
= GetPiPcdProtocol()->Set32 (Guid
, TokenNumber
, Value
);
734 ASSERT_EFI_ERROR (Status
);
742 This function provides a means by which to set a value for a given PCD token.
744 Sets the 64-bit value for the token specified by TokenNumber and
745 Guid to the value specified by Value. Value is returned.
746 If Guid is NULL, then ASSERT().
748 @param[in] Guid The pointer to a 128-bit unique value that
749 designates which namespace to set a value from.
750 @param[in] TokenNumber The PCD token number to set a current value for.
751 @param[in] Value The 64-bit value to set.
753 @return Return the value that was set.
760 IN UINTN TokenNumber
,
766 ASSERT (Guid
!= NULL
);
768 Status
= GetPiPcdProtocol()->Set64 (Guid
, TokenNumber
, Value
);
769 ASSERT_EFI_ERROR (Status
);
777 This function provides a means by which to set a value for a given PCD token.
779 Sets a buffer for the token specified by TokenNumber to the value specified by
780 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
781 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
782 supported by TokenNumber and return NULL to indicate that the set operation
783 was not actually performed.
785 If Guid is NULL, then ASSERT().
786 If SizeOfBuffer is NULL, then ASSERT().
787 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
789 @param[in] Guid The pointer to a 128-bit unique value that
790 designates which namespace to set a value from.
791 @param[in] TokenNumber The PCD token number to set a current value for.
792 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
793 @param[in] Buffer A pointer to the buffer to set.
795 @return Return the pointer to the buffer been set.
802 IN UINTN TokenNumber
,
803 IN OUT UINTN
*SizeOfBuffer
,
809 ASSERT (Guid
!= NULL
);
811 ASSERT (SizeOfBuffer
!= NULL
);
813 if (*SizeOfBuffer
> 0) {
814 ASSERT (Buffer
!= NULL
);
817 Status
= GetPiPcdProtocol()->SetPtr (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
818 if (EFI_ERROR (Status
)) {
828 This function provides a means by which to set a value for a given PCD token.
830 Sets the Boolean value for the token specified by TokenNumber and
831 Guid to the value specified by Value. Value is returned.
833 If Guid is NULL, then ASSERT().
835 @param[in] Guid The pointer to a 128-bit unique value that
836 designates which namespace to set a value from.
837 @param[in] TokenNumber The PCD token number to set a current value for.
838 @param[in] Value The Boolean value to set.
840 @return Return the value that was set.
847 IN UINTN TokenNumber
,
853 ASSERT (Guid
!= NULL
);
855 Status
= GetPiPcdProtocol()->SetBool (Guid
, TokenNumber
, Value
);
856 ASSERT_EFI_ERROR (Status
);
864 Set up a notification function that is called when a specified token is set.
866 When the token specified by TokenNumber and Guid is set,
867 then notification function specified by NotificationFunction is called.
868 If Guid is NULL, then the default token space is used.
869 If NotificationFunction is NULL, then ASSERT().
871 @param[in] Guid The pointer to a 128-bit unique value that designates which
872 namespace to set a value from. If NULL, then the default
874 @param[in] TokenNumber The PCD token number to monitor.
875 @param[in] NotificationFunction The function to call when the token
876 specified by Guid and TokenNumber is set.
881 LibPcdCallbackOnSet (
882 IN CONST GUID
*Guid
, OPTIONAL
883 IN UINTN TokenNumber
,
884 IN PCD_CALLBACK NotificationFunction
889 ASSERT (NotificationFunction
!= NULL
);
891 Status
= GetPiPcdProtocol()->CallbackOnSet (Guid
, TokenNumber
, (EFI_PCD_PROTOCOL_CALLBACK
) NotificationFunction
);
892 ASSERT_EFI_ERROR (Status
);
900 Disable a notification function that was established with LibPcdCallbackonSet().
902 Disable a notification function that was previously established with LibPcdCallbackOnSet().
903 If NotificationFunction is NULL, then ASSERT().
904 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
905 and NotificationFunction, then ASSERT().
907 @param[in] Guid Specify the GUID token space.
908 @param[in] TokenNumber Specify the token number.
909 @param[in] NotificationFunction The callback function to be unregistered.
914 LibPcdCancelCallback (
915 IN CONST GUID
*Guid
, OPTIONAL
916 IN UINTN TokenNumber
,
917 IN PCD_CALLBACK NotificationFunction
922 ASSERT (NotificationFunction
!= NULL
);
924 Status
= GetPiPcdProtocol()->CancelCallback (Guid
, TokenNumber
, (EFI_PCD_PROTOCOL_CALLBACK
) NotificationFunction
);
925 ASSERT_EFI_ERROR (Status
);
933 Retrieves the next token in a token space.
935 Retrieves the next PCD token number from the token space specified by Guid.
936 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
937 then the first token number is returned. Otherwise, the token number that
938 follows TokenNumber in the token space is returned. If TokenNumber is the last
939 token number in the token space, then 0 is returned.
941 If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
943 @param[in] Guid The pointer to a 128-bit unique value that designates which namespace
944 to set a value from. If NULL, then the default token space is used.
945 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
948 @return The next valid token number.
954 IN CONST GUID
*Guid
, OPTIONAL
958 GetPiPcdProtocol()->GetNextToken (Guid
, &TokenNumber
);
966 Used to retrieve the list of available PCD token space GUIDs.
968 Returns the PCD token space GUID that follows TokenSpaceGuid in the list of token spaces
970 If TokenSpaceGuid is NULL, then a pointer to the first PCD token spaces returned.
971 If TokenSpaceGuid is the last PCD token space GUID in the list, then NULL is returned.
973 @param TokenSpaceGuid The pointer to the a PCD token space GUID.
975 @return The next valid token namespace.
980 LibPcdGetNextTokenSpace (
981 IN CONST GUID
*TokenSpaceGuid
984 GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid
);
986 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
;