2 Implementation of PcdLib class library for DXE phase.
4 Copyright (c) 2006 - 2009, 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.
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 The constructor function caches the PCD_PROTOCOL pointer.
33 @param[in] ImageHandle The firmware allocated handle for the EFI image.
34 @param[in] SystemTable A pointer to the EFI System Table.
36 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
42 IN EFI_HANDLE ImageHandle
,
43 IN EFI_SYSTEM_TABLE
*SystemTable
49 // PCD protocol need to be installed before the module access Dynamic type PCD.
50 // But dynamic type PCD is not required in PI 1.2 specification.
52 gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
55 // PI Pcd protocol defined in PI 1.2 vol3 should be installed before the module
56 // access DynamicEx type PCD.
58 Status
= gBS
->LocateProtocol (&gEfiPcdProtocolGuid
, NULL
, (VOID
**) &mPiPcd
);
60 ASSERT_EFI_ERROR (Status
);
61 ASSERT (mPiPcd
!= NULL
);
68 This function provides a means by which SKU support can be established in the PCD infrastructure.
70 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
71 If SkuId >= PCD_MAX_SKU_ID, then ASSERT().
73 @param SkuId The SKU value that will be used when the PCD service retrieves and sets values
74 associated with a PCD token.
76 @return Return the SKU ID that just be set.
85 ASSERT (mPcd
!= NULL
);
86 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
96 This function provides a means by which to retrieve a value for a given PCD token.
98 Returns the 8-bit value for the token specified by TokenNumber.
100 @param[in] TokenNumber The PCD token number to retrieve a current value for.
102 @return Returns the 8-bit value for the token specified by TokenNumber.
111 ASSERT (mPcd
!= NULL
);
112 return mPcd
->Get8 (TokenNumber
);
118 This function provides a means by which to retrieve a value for a given PCD token.
120 Returns the 16-bit value for the token specified by TokenNumber.
122 @param[in] TokenNumber The PCD token number to retrieve a current value for.
124 @return Returns the 16-bit value for the token specified by TokenNumber.
133 ASSERT (mPcd
!= NULL
);
134 return mPcd
->Get16 (TokenNumber
);
140 This function provides a means by which to retrieve a value for a given PCD token.
142 Returns the 32-bit value for the token specified by TokenNumber.
144 @param[in] TokenNumber The PCD token number to retrieve a current value for.
146 @return Returns the 32-bit value for the token specified by TokenNumber.
155 ASSERT (mPcd
!= NULL
);
156 return mPcd
->Get32 (TokenNumber
);
162 This function provides a means by which to retrieve a value for a given PCD token.
164 Returns the 64-bit value for the token specified by TokenNumber.
166 @param[in] TokenNumber The PCD token number to retrieve a current value for.
168 @return Returns the 64-bit value for the token specified by TokenNumber.
177 ASSERT (mPcd
!= NULL
);
178 return mPcd
->Get64 (TokenNumber
);
184 This function provides a means by which to retrieve a value for a given PCD token.
186 Returns the pointer to the buffer of the token specified by TokenNumber.
188 @param[in] TokenNumber The PCD token number to retrieve a current value for.
190 @return Returns the pointer to the token specified by TokenNumber.
199 ASSERT (mPcd
!= NULL
);
200 return mPcd
->GetPtr (TokenNumber
);
206 This function provides a means by which to retrieve a value for a given PCD token.
208 Returns the Boolean value of the token specified by TokenNumber.
210 @param[in] TokenNumber The PCD token number to retrieve a current value for.
212 @return Returns the Boolean value of the token specified by TokenNumber.
221 ASSERT (mPcd
!= NULL
);
222 return mPcd
->GetBool (TokenNumber
);
228 This function provides a means by which to retrieve the size of a given PCD token.
230 @param[in] TokenNumber The PCD token number to retrieve a current value for.
232 @return Returns the size of the token specified by TokenNumber.
241 ASSERT (mPcd
!= NULL
);
242 return mPcd
->GetSize (TokenNumber
);
248 This function provides a means by which to retrieve a value for a given PCD token.
250 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 @return Return the UINT8.
268 ASSERT (Guid
!= NULL
);
270 return mPiPcd
->Get8Ex (Guid
, TokenNumber
);
275 This function provides a means by which to retrieve a value for a given PCD token.
277 Returns the 16-bit value for the token specified by TokenNumber and Guid.
279 If Guid is NULL, then ASSERT().
281 @param[in] Guid Pointer to a 128-bit unique value that designates
282 which namespace to retrieve a value from.
283 @param[in] TokenNumber The PCD token number to retrieve a current value for.
285 @return Return the UINT16.
295 ASSERT (Guid
!= NULL
);
297 return mPiPcd
->Get16Ex (Guid
, TokenNumber
);
302 Returns the 32-bit value for the token specified by TokenNumber and Guid.
303 If Guid is NULL, then ASSERT().
305 @param[in] Guid Pointer to a 128-bit unique value that designates
306 which namespace to retrieve a value from.
307 @param[in] TokenNumber The PCD token number to retrieve a current value for.
309 @return Return the UINT32.
319 ASSERT (Guid
!= NULL
);
321 return mPiPcd
->Get32Ex (Guid
, TokenNumber
);
327 This function provides a means by which to retrieve a value for a given PCD token.
329 Returns the 64-bit value for the token specified by TokenNumber and Guid.
331 If Guid is NULL, then ASSERT().
333 @param[in] Guid Pointer to a 128-bit unique value that designates
334 which namespace to retrieve a value from.
335 @param[in] TokenNumber The PCD token number to retrieve a current value for.
337 @return Return the UINT64.
347 ASSERT (Guid
!= NULL
);
349 return mPiPcd
->Get64Ex (Guid
, TokenNumber
);
355 This function provides a means by which to retrieve a value for a given PCD token.
357 Returns the pointer to the buffer of token specified by TokenNumber and Guid.
359 If Guid is NULL, then ASSERT().
361 @param[in] Guid Pointer to a 128-bit unique value that designates
362 which namespace to retrieve a value from.
363 @param[in] TokenNumber The PCD token number to retrieve a current value for.
365 @return Return the VOID* pointer.
375 ASSERT (Guid
!= NULL
);
377 return mPiPcd
->GetPtrEx (Guid
, TokenNumber
);
383 This function provides a means by which to retrieve a value for a given PCD token.
385 Returns the Boolean value of the token specified by TokenNumber and Guid.
387 If Guid is NULL, then ASSERT().
389 @param[in] Guid Pointer to a 128-bit unique value that designates
390 which namespace to retrieve a value from.
391 @param[in] TokenNumber The PCD token number to retrieve a current value for.
393 @return Return the BOOLEAN.
403 ASSERT (Guid
!= NULL
);
405 return mPiPcd
->GetBoolEx (Guid
, TokenNumber
);
411 This function provides a means by which to retrieve the size of a given PCD token.
413 Returns the size of the token specified by TokenNumber and Guid.
415 If Guid is NULL, then ASSERT().
417 @param[in] Guid Pointer to a 128-bit unique value that designates
418 which namespace to retrieve a value from.
419 @param[in] TokenNumber The PCD token number to retrieve a current value for.
421 @return Return the size.
431 ASSERT (Guid
!= NULL
);
433 return mPiPcd
->GetSizeEx (Guid
, TokenNumber
);
439 This function provides a means by which to set a value for a given PCD token.
441 Sets the 8-bit value for the token specified by TokenNumber
442 to the value specified by Value. Value is returned.
444 @param[in] TokenNumber The PCD token number to set a current value for.
445 @param[in] Value The 8-bit value to set.
447 @return Return the value been set.
453 IN UINTN TokenNumber
,
459 ASSERT (mPcd
!= NULL
);
460 Status
= mPcd
->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 been set.
484 IN UINTN TokenNumber
,
490 ASSERT (mPcd
!= NULL
);
491 Status
= mPcd
->Set16 (TokenNumber
, Value
);
493 ASSERT_EFI_ERROR (Status
);
501 This function provides a means by which to set a value for a given PCD token.
503 Sets the 32-bit value for the token specified by TokenNumber
504 to the value specified by Value. Value is returned.
506 @param[in] TokenNumber The PCD token number to set a current value for.
507 @param[in] Value The 32-bit value to set.
509 @return Return the value been set.
515 IN UINTN TokenNumber
,
521 ASSERT (mPcd
!= NULL
);
522 Status
= mPcd
->Set32 (TokenNumber
, Value
);
524 ASSERT_EFI_ERROR (Status
);
532 This function provides a means by which to set a value for a given PCD token.
534 Sets the 64-bit value for the token specified by TokenNumber
535 to the value specified by Value. Value is returned.
537 @param[in] TokenNumber The PCD token number to set a current value for.
538 @param[in] Value The 64-bit value to set.
540 @return Return the value been set.
546 IN UINTN TokenNumber
,
552 ASSERT (mPcd
!= NULL
);
553 Status
= mPcd
->Set64 (TokenNumber
, Value
);
555 ASSERT_EFI_ERROR (Status
);
563 This function provides a means by which to set a value for a given PCD token.
565 Sets a buffer for the token specified by TokenNumber to the value
566 specified by Buffer and SizeOfBuffer. Buffer is returned.
567 If SizeOfBuffer is greater than the maximum size support by TokenNumber,
568 then set SizeOfBuffer to the maximum size supported by TokenNumber and
569 return NULL to indicate that the set operation was not actually performed.
571 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
572 maximum size supported by TokenName and NULL must be returned.
574 If SizeOfBuffer is NULL, then ASSERT().
575 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
577 @param[in] TokenNumber The PCD token number to set a current value for.
578 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
579 @param[in] Buffer A pointer to the buffer to set.
581 @return Return the pointer for the buffer been set.
587 IN UINTN TokenNumber
,
588 IN OUT UINTN
*SizeOfBuffer
,
589 IN CONST VOID
*Buffer
594 ASSERT (mPcd
!= NULL
);
595 ASSERT (SizeOfBuffer
!= NULL
);
597 if (*SizeOfBuffer
> 0) {
598 ASSERT (Buffer
!= NULL
);
601 Status
= mPcd
->SetPtr (TokenNumber
, SizeOfBuffer
, (VOID
*) Buffer
);
603 if (EFI_ERROR (Status
)) {
607 return (VOID
*) Buffer
;
613 This function provides a means by which to set a value for a given PCD token.
615 Sets the Boolean value for the token specified by TokenNumber
616 to the value specified by Value. Value is returned.
618 @param[in] TokenNumber The PCD token number to set a current value for.
619 @param[in] Value The boolean value to set.
621 @return Return the value been set.
627 IN UINTN TokenNumber
,
633 ASSERT (mPcd
!= NULL
);
634 Status
= mPcd
->SetBool (TokenNumber
, Value
);
636 ASSERT_EFI_ERROR (Status
);
644 This function provides a means by which to set a value for a given PCD token.
646 Sets the 8-bit value for the token specified by TokenNumber and
647 Guid to the value specified by Value. Value is returned.
649 If Guid is NULL, then ASSERT().
651 @param[in] Guid Pointer to a 128-bit unique value that
652 designates which namespace to set a value from.
653 @param[in] TokenNumber The PCD token number to set a current value for.
654 @param[in] Value The 8-bit value to set.
656 @return Return the value been set.
663 IN UINTN TokenNumber
,
669 ASSERT (Guid
!= NULL
);
671 Status
= mPiPcd
->Set8Ex (Guid
, TokenNumber
, Value
);
673 ASSERT_EFI_ERROR (Status
);
681 This function provides a means by which to set a value for a given PCD token.
683 Sets the 16-bit value for the token specified by TokenNumber and
684 Guid to the value specified by Value. Value is returned.
686 If Guid is NULL, then ASSERT().
688 @param[in] Guid Pointer to a 128-bit unique value that
689 designates which namespace to set a value from.
690 @param[in] TokenNumber The PCD token number to set a current value for.
691 @param[in] Value The 16-bit value to set.
693 @return Return the value been set.
700 IN UINTN TokenNumber
,
706 ASSERT (Guid
!= NULL
);
708 Status
= mPiPcd
->Set16Ex (Guid
, TokenNumber
, Value
);
710 ASSERT_EFI_ERROR (Status
);
718 This function provides a means by which to set a value for a given PCD token.
720 Sets the 32-bit value for the token specified by TokenNumber and
721 Guid to the value specified by Value. Value is returned.
723 If Guid is NULL, then ASSERT().
725 @param[in] Guid Pointer to a 128-bit unique value that
726 designates which namespace to set a value from.
727 @param[in] TokenNumber The PCD token number to set a current value for.
728 @param[in] Value The 32-bit value to set.
730 @return Return the value been set.
737 IN UINTN TokenNumber
,
743 ASSERT (Guid
!= NULL
);
745 Status
= mPiPcd
->Set32Ex (Guid
, TokenNumber
, Value
);
747 ASSERT_EFI_ERROR (Status
);
755 This function provides a means by which to set a value for a given PCD token.
757 Sets the 64-bit value for the token specified by TokenNumber and
758 Guid to the value specified by Value. Value is returned.
759 If Guid is NULL, then ASSERT().
761 @param[in] Guid Pointer to a 128-bit unique value that
762 designates which namespace to set a value from.
763 @param[in] TokenNumber The PCD token number to set a current value for.
764 @param[in] Value The 64-bit value to set.
766 @return Return the value been set.
773 IN UINTN TokenNumber
,
779 ASSERT (Guid
!= NULL
);
781 Status
= mPiPcd
->Set64Ex (Guid
, TokenNumber
, Value
);
783 ASSERT_EFI_ERROR (Status
);
791 This function provides a means by which to set a value for a given PCD token.
793 Sets a buffer for the token specified by TokenNumber to the value specified by
794 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
795 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
796 supported by TokenNumber and return NULL to indicate that the set operation
797 was not actually performed.
799 If Guid is NULL, then ASSERT().
800 If SizeOfBuffer is NULL, then ASSERT().
801 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
803 @param[in] Guid Pointer to a 128-bit unique value that
804 designates which namespace to set a value from.
805 @param[in] TokenNumber The PCD token number to set a current value for.
806 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
807 @param[in] Buffer A pointer to the buffer to set.
809 @return Return the pinter to the buffer been set.
816 IN UINTN TokenNumber
,
817 IN OUT UINTN
*SizeOfBuffer
,
823 ASSERT (Guid
!= NULL
);
825 ASSERT (SizeOfBuffer
!= NULL
);
827 if (*SizeOfBuffer
> 0) {
828 ASSERT (Buffer
!= NULL
);
831 Status
= mPiPcd
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
833 if (EFI_ERROR (Status
)) {
843 This function provides a means by which to set a value for a given PCD token.
845 Sets the Boolean value for the token specified by TokenNumber and
846 Guid to the value specified by Value. Value is returned.
848 If Guid is NULL, then ASSERT().
850 @param[in] Guid Pointer to a 128-bit unique value that
851 designates which namespace to set a value from.
852 @param[in] TokenNumber The PCD token number to set a current value for.
853 @param[in] Value The Boolean value to set.
855 @return Return the value been set.
862 IN UINTN TokenNumber
,
868 ASSERT (Guid
!= NULL
);
870 Status
= mPiPcd
->SetBoolEx (Guid
, TokenNumber
, Value
);
872 ASSERT_EFI_ERROR (Status
);
880 Set up a notification function that is called when a specified token is set.
882 When the token specified by TokenNumber and Guid is set,
883 then notification function specified by NotificationFunction is called.
884 If Guid is NULL, then the default token space is used.
885 If NotificationFunction is NULL, then ASSERT().
887 @param[in] Guid Pointer to a 128-bit unique value that designates which
888 namespace to set a value from. If NULL, then the default
890 @param[in] TokenNumber The PCD token number to monitor.
891 @param[in] NotificationFunction The function to call when the token
892 specified by Guid and TokenNumber is set.
897 LibPcdCallbackOnSet (
898 IN CONST GUID
*Guid
, OPTIONAL
899 IN UINTN TokenNumber
,
900 IN PCD_CALLBACK NotificationFunction
905 ASSERT (NotificationFunction
!= NULL
);
907 Status
= mPiPcd
->CallbackOnSet (Guid
, TokenNumber
, (EFI_PCD_PROTOCOL_CALLBACK
) NotificationFunction
);
909 ASSERT_EFI_ERROR (Status
);
917 Disable a notification function that was established with LibPcdCallbackonSet().
919 Disable a notification function that was previously established with LibPcdCallbackOnSet().
920 If NotificationFunction is NULL, then ASSERT().
921 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
922 and NotificationFunction, then ASSERT().
924 @param[in] Guid Specify the GUID token space.
925 @param[in] TokenNumber Specify the token number.
926 @param[in] NotificationFunction The callback function to be unregistered.
931 LibPcdCancelCallback (
932 IN CONST GUID
*Guid
, OPTIONAL
933 IN UINTN TokenNumber
,
934 IN PCD_CALLBACK NotificationFunction
939 ASSERT (NotificationFunction
!= NULL
);
941 Status
= mPiPcd
->CancelCallback (Guid
, TokenNumber
, (EFI_PCD_PROTOCOL_CALLBACK
) NotificationFunction
);
943 ASSERT_EFI_ERROR (Status
);
951 Retrieves the next token in a token space.
953 Retrieves the next PCD token number from the token space specified by Guid.
954 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
955 then the first token number is returned. Otherwise, the token number that
956 follows TokenNumber in the token space is returned. If TokenNumber is the last
957 token number in the token space, then 0 is returned.
959 If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
961 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
962 to set a value from. If NULL, then the default token space is used.
963 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
966 @return The next valid token number.
972 IN CONST GUID
*Guid
, OPTIONAL
978 Status
= mPiPcd
->GetNextToken (Guid
, &TokenNumber
);
980 ASSERT_EFI_ERROR (Status
);
988 Used to retrieve the list of available PCD token space GUIDs.
990 Returns the PCD token space GUID that follows TokenSpaceGuid in the list of token spaces
992 If TokenSpaceGuid is NULL, then a pointer to the first PCD token spaces returned.
993 If TokenSpaceGuid is the last PCD token space GUID in the list, then NULL is returned.
995 @param TokenSpaceGuid Pointer to the a PCD token space GUID
997 @return The next valid token namespace.
1002 LibPcdGetNextTokenSpace (
1003 IN CONST GUID
*TokenSpaceGuid
1008 Status
= mPiPcd
->GetNextTokenSpace (&TokenSpaceGuid
);
1010 ASSERT_EFI_ERROR (Status
);
1012 return (GUID
*) TokenSpaceGuid
;
1017 Sets a value of a patchable PCD entry that is type pointer.
1019 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1020 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
1021 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
1022 NULL to indicate that the set operation was not actually performed.
1023 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1024 MaximumDatumSize and NULL must be returned.
1026 If PatchVariable is NULL, then ASSERT().
1027 If SizeOfBuffer is NULL, then ASSERT().
1028 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1030 @param[in] PatchVariable A pointer to the global variable in a module that is
1031 the target of the set operation.
1032 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1033 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1034 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1036 @return Return the pointer to the buffer been set.
1042 IN VOID
*PatchVariable
,
1043 IN UINTN MaximumDatumSize
,
1044 IN OUT UINTN
*SizeOfBuffer
,
1045 IN CONST VOID
*Buffer
1048 ASSERT (PatchVariable
!= NULL
);
1049 ASSERT (SizeOfBuffer
!= NULL
);
1051 if (*SizeOfBuffer
> 0) {
1052 ASSERT (Buffer
!= NULL
);
1055 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1056 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1057 *SizeOfBuffer
= MaximumDatumSize
;
1061 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1063 return (VOID
*) Buffer
;