2 Implementation of PcdLib class library for DXE 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.
19 #include <Protocol/Pcd.h>
21 #include <Library/PcdLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/BaseMemoryLib.h>
26 PCD_PROTOCOL
*mPcd
= NULL
;
30 The constructor function caches the PCD_PROTOCOL pointer.
32 @param[in] ImageHandle The firmware allocated handle for the EFI image.
33 @param[in] SystemTable A pointer to the EFI System Table.
35 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
41 IN EFI_HANDLE ImageHandle
,
42 IN EFI_SYSTEM_TABLE
*SystemTable
48 // PCD protocol has not been installed, but a module needs to access a
51 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
52 ASSERT_EFI_ERROR (Status
);
60 This function provides a means by which SKU support can be established in the PCD infrastructure.
62 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
64 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
65 set values associated with a PCD token.
67 If SkuId >= 0x100, then ASSERT().
69 @return Return the SKU ID that just be set.
78 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
88 This function provides a means by which to retrieve a value for a given PCD token.
90 Returns the 8-bit value for the token specified by TokenNumber.
92 @param[in] TokenNumber The PCD token number to retrieve a current value for.
94 @return Returns the 8-bit value for the token specified by TokenNumber.
103 return mPcd
->Get8 (TokenNumber
);
109 This function provides a means by which to retrieve a value for a given PCD token.
111 Returns the 16-bit value for the token specified by TokenNumber.
113 @param[in] TokenNumber The PCD token number to retrieve a current value for.
115 @return Returns the 16-bit value for the token specified by TokenNumber.
124 return mPcd
->Get16 (TokenNumber
);
130 This function provides a means by which to retrieve a value for a given PCD token.
132 Returns the 32-bit value for the token specified by TokenNumber.
134 @param[in] TokenNumber The PCD token number to retrieve a current value for.
136 @return Returns the 32-bit value for the token specified by TokenNumber.
145 return mPcd
->Get32 (TokenNumber
);
151 This function provides a means by which to retrieve a value for a given PCD token.
153 Returns the 64-bit value for the token specified by TokenNumber.
155 @param[in] TokenNumber The PCD token number to retrieve a current value for.
157 @return Returns the 64-bit value for the token specified by TokenNumber.
166 return mPcd
->Get64 (TokenNumber
);
172 This function provides a means by which to retrieve a value for a given PCD token.
174 Returns the pointer to the buffer of the token specified by TokenNumber.
176 @param[in] TokenNumber The PCD token number to retrieve a current value for.
178 @return Returns the pointer to the token specified by TokenNumber.
187 return mPcd
->GetPtr (TokenNumber
);
193 This function provides a means by which to retrieve a value for a given PCD token.
195 Returns the Boolean value of the token specified by TokenNumber.
197 @param[in] TokenNumber The PCD token number to retrieve a current value for.
199 @return Returns the Boolean value of the token specified by TokenNumber.
208 return mPcd
->GetBool (TokenNumber
);
214 This function provides a means by which to retrieve the size of a given PCD token.
216 @param[in] TokenNumber The PCD token number to retrieve a current value for.
218 @return Returns the size of the token specified by TokenNumber.
227 return mPcd
->GetSize (TokenNumber
);
233 This function provides a means by which to retrieve a value for a given PCD token.
235 Returns the 8-bit value for the token specified by TokenNumber and Guid.
237 If Guid is NULL, then ASSERT().
239 @param[in] Guid Pointer to a 128-bit unique value that designates
240 which namespace to retrieve a value from.
241 @param[in] TokenNumber The PCD token number to retrieve a current value for.
243 @return Return the UINT8.
253 ASSERT (Guid
!= NULL
);
255 return mPcd
->Get8Ex (Guid
, TokenNumber
);
260 This function provides a means by which to retrieve a value for a given PCD token.
262 Returns the 16-bit value for the token specified by TokenNumber and Guid.
264 If Guid is NULL, then ASSERT().
266 @param[in] Guid Pointer to a 128-bit unique value that designates
267 which namespace to retrieve a value from.
268 @param[in] TokenNumber The PCD token number to retrieve a current value for.
270 @return Return the UINT16.
280 ASSERT (Guid
!= NULL
);
282 return mPcd
->Get16Ex (Guid
, TokenNumber
);
287 Returns the 32-bit value for the token specified by TokenNumber and Guid.
288 If Guid is NULL, then ASSERT().
290 @param[in] Guid Pointer to a 128-bit unique value that designates
291 which namespace to retrieve a value from.
292 @param[in] TokenNumber The PCD token number to retrieve a current value for.
294 @return Return the UINT32.
304 ASSERT (Guid
!= NULL
);
306 return mPcd
->Get32Ex (Guid
, TokenNumber
);
312 This function provides a means by which to retrieve a value for a given PCD token.
314 Returns the 64-bit value for the token specified by TokenNumber and Guid.
316 If Guid is NULL, then ASSERT().
318 @param[in] Guid Pointer to a 128-bit unique value that designates
319 which namespace to retrieve a value from.
320 @param[in] TokenNumber The PCD token number to retrieve a current value for.
322 @return Return the UINT64.
332 ASSERT (Guid
!= NULL
);
334 return mPcd
->Get64Ex (Guid
, TokenNumber
);
340 This function provides a means by which to retrieve a value for a given PCD token.
342 Returns the pointer to the buffer of token specified by TokenNumber and Guid.
344 If Guid is NULL, then ASSERT().
346 @param[in] Guid Pointer to a 128-bit unique value that designates
347 which namespace to retrieve a value from.
348 @param[in] TokenNumber The PCD token number to retrieve a current value for.
350 @return Return the VOID* pointer.
360 ASSERT (Guid
!= NULL
);
362 return mPcd
->GetPtrEx (Guid
, TokenNumber
);
368 This function provides a means by which to retrieve a value for a given PCD token.
370 Returns the Boolean value of the token specified by TokenNumber and Guid.
372 If Guid is NULL, then ASSERT().
374 @param[in] Guid Pointer to a 128-bit unique value that designates
375 which namespace to retrieve a value from.
376 @param[in] TokenNumber The PCD token number to retrieve a current value for.
378 @return Return the BOOLEAN.
388 ASSERT (Guid
!= NULL
);
390 return mPcd
->GetBoolEx (Guid
, TokenNumber
);
396 This function provides a means by which to retrieve the size of a given PCD token.
398 Returns the size of the token specified by TokenNumber and Guid.
400 If Guid is NULL, then ASSERT().
402 @param[in] Guid Pointer to a 128-bit unique value that designates
403 which namespace to retrieve a value from.
404 @param[in] TokenNumber The PCD token number to retrieve a current value for.
406 @return Return the size.
416 ASSERT (Guid
!= NULL
);
418 return mPcd
->GetSizeEx (Guid
, TokenNumber
);
424 This function provides a means by which to set a value for a given PCD token.
426 Sets the 8-bit value for the token specified by TokenNumber
427 to the value specified by Value. Value is returned.
429 @param[in] TokenNumber The PCD token number to set a current value for.
430 @param[in] Value The 8-bit value to set.
432 @return Return the value been set.
438 IN UINTN TokenNumber
,
444 Status
= mPcd
->Set8 (TokenNumber
, Value
);
446 ASSERT_EFI_ERROR (Status
);
454 This function provides a means by which to set a value for a given PCD token.
456 Sets the 16-bit value for the token specified by TokenNumber
457 to the value specified by Value. Value is returned.
459 @param[in] TokenNumber The PCD token number to set a current value for.
460 @param[in] Value The 16-bit value to set.
462 @return Return the value been set.
468 IN UINTN TokenNumber
,
474 Status
= mPcd
->Set16 (TokenNumber
, Value
);
476 ASSERT_EFI_ERROR (Status
);
484 This function provides a means by which to set a value for a given PCD token.
486 Sets the 32-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 32-bit value to set.
492 @return Return the value been set.
498 IN UINTN TokenNumber
,
503 Status
= mPcd
->Set32 (TokenNumber
, Value
);
505 ASSERT_EFI_ERROR (Status
);
513 This function provides a means by which to set a value for a given PCD token.
515 Sets the 64-bit value for the token specified by TokenNumber
516 to the value specified by Value. Value is returned.
518 @param[in] TokenNumber The PCD token number to set a current value for.
519 @param[in] Value The 64-bit value to set.
521 @return Return the value been set.
527 IN UINTN TokenNumber
,
533 Status
= mPcd
->Set64 (TokenNumber
, Value
);
535 ASSERT_EFI_ERROR (Status
);
543 This function provides a means by which to set a value for a given PCD token.
545 Sets a buffer for the token specified by TokenNumber to the value
546 specified by Buffer and SizeOfBuffer. Buffer is returned.
547 If SizeOfBuffer is greater than the maximum size support by TokenNumber,
548 then set SizeOfBuffer to the maximum size supported by TokenNumber and
549 return NULL to indicate that the set operation was not actually performed.
551 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the
552 maximum size supported by TokenName and NULL must be returned.
554 If SizeOfBuffer is NULL, then ASSERT().
555 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
557 @param[in] TokenNumber The PCD token number to set a current value for.
558 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
559 @param[in] Buffer A pointer to the buffer to set.
561 @return Return the pointer for the buffer been set.
567 IN UINTN TokenNumber
,
568 IN OUT UINTN
*SizeOfBuffer
,
569 IN CONST VOID
*Buffer
574 ASSERT (SizeOfBuffer
!= NULL
);
576 if (*SizeOfBuffer
> 0) {
577 ASSERT (Buffer
!= NULL
);
580 Status
= mPcd
->SetPtr (TokenNumber
, SizeOfBuffer
, (VOID
*) Buffer
);
582 if (EFI_ERROR (Status
)) {
586 return (VOID
*) Buffer
;
592 This function provides a means by which to set a value for a given PCD token.
594 Sets the Boolean value for the token specified by TokenNumber
595 to the value specified by Value. Value is returned.
597 @param[in] TokenNumber The PCD token number to set a current value for.
598 @param[in] Value The boolean value to set.
600 @return Return the value been set.
606 IN UINTN TokenNumber
,
612 Status
= mPcd
->SetBool (TokenNumber
, Value
);
614 ASSERT_EFI_ERROR (Status
);
622 This function provides a means by which to set a value for a given PCD token.
624 Sets the 8-bit value for the token specified by TokenNumber and
625 Guid to the value specified by Value. Value is returned.
627 If Guid is NULL, then ASSERT().
629 @param[in] Guid Pointer to a 128-bit unique value that
630 designates which namespace to set a value from.
631 @param[in] TokenNumber The PCD token number to set a current value for.
632 @param[in] Value The 8-bit value to set.
634 @return Return the value been set.
641 IN UINTN TokenNumber
,
647 ASSERT (Guid
!= NULL
);
649 Status
= mPcd
->Set8Ex (Guid
, TokenNumber
, Value
);
651 ASSERT_EFI_ERROR (Status
);
659 This function provides a means by which to set a value for a given PCD token.
661 Sets the 16-bit value for the token specified by TokenNumber and
662 Guid to the value specified by Value. Value is returned.
664 If Guid is NULL, then ASSERT().
666 @param[in] Guid Pointer to a 128-bit unique value that
667 designates which namespace to set a value from.
668 @param[in] TokenNumber The PCD token number to set a current value for.
669 @param[in] Value The 16-bit value to set.
671 @return Return the value been set.
678 IN UINTN TokenNumber
,
684 ASSERT (Guid
!= NULL
);
686 Status
= mPcd
->Set16Ex (Guid
, TokenNumber
, Value
);
688 ASSERT_EFI_ERROR (Status
);
696 This function provides a means by which to set a value for a given PCD token.
698 Sets the 32-bit value for the token specified by TokenNumber and
699 Guid to the value specified by Value. Value is returned.
701 If Guid is NULL, then ASSERT().
703 @param[in] Guid Pointer to a 128-bit unique value that
704 designates which namespace to set a value from.
705 @param[in] TokenNumber The PCD token number to set a current value for.
706 @param[in] Value The 32-bit value to set.
708 @return Return the value been set.
715 IN UINTN TokenNumber
,
721 ASSERT (Guid
!= NULL
);
723 Status
= mPcd
->Set32Ex (Guid
, TokenNumber
, Value
);
725 ASSERT_EFI_ERROR (Status
);
733 This function provides a means by which to set a value for a given PCD token.
735 Sets the 64-bit value for the token specified by TokenNumber and
736 Guid to the value specified by Value. Value is returned.
737 If Guid is NULL, then ASSERT().
739 @param[in] Guid Pointer to a 128-bit unique value that
740 designates which namespace to set a value from.
741 @param[in] TokenNumber The PCD token number to set a current value for.
742 @param[in] Value The 64-bit value to set.
744 @return Return the value been set.
751 IN UINTN TokenNumber
,
757 ASSERT (Guid
!= NULL
);
759 Status
= mPcd
->Set64Ex (Guid
, TokenNumber
, Value
);
761 ASSERT_EFI_ERROR (Status
);
769 This function provides a means by which to set a value for a given PCD token.
771 Sets a buffer for the token specified by TokenNumber to the value specified by
772 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
773 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
774 supported by TokenNumber and return NULL to indicate that the set operation
775 was not actually performed.
777 If Guid is NULL, then ASSERT().
778 If SizeOfBuffer is NULL, then ASSERT().
779 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
781 @param[in] Guid Pointer to a 128-bit unique value that
782 designates which namespace to set a value from.
783 @param[in] TokenNumber The PCD token number to set a current value for.
784 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
785 @param[in] Buffer A pointer to the buffer to set.
787 @return Return the pinter to the buffer been set.
794 IN UINTN TokenNumber
,
795 IN OUT UINTN
*SizeOfBuffer
,
801 ASSERT (Guid
!= NULL
);
803 ASSERT (SizeOfBuffer
!= NULL
);
805 if (*SizeOfBuffer
> 0) {
806 ASSERT (Buffer
!= NULL
);
809 Status
= mPcd
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
811 if (EFI_ERROR (Status
)) {
821 This function provides a means by which to set a value for a given PCD token.
823 Sets the Boolean value for the token specified by TokenNumber and
824 Guid to the value specified by Value. Value is returned.
826 If Guid is NULL, then ASSERT().
828 @param[in] Guid Pointer to a 128-bit unique value that
829 designates which namespace to set a value from.
830 @param[in] TokenNumber The PCD token number to set a current value for.
831 @param[in] Value The Boolean value to set.
833 @return Return the value been set.
840 IN UINTN TokenNumber
,
846 ASSERT (Guid
!= NULL
);
848 Status
= mPcd
->SetBoolEx (Guid
, TokenNumber
, Value
);
850 ASSERT_EFI_ERROR (Status
);
858 Set up a notification function that is called when a specified token is set.
860 When the token specified by TokenNumber and Guid is set,
861 then notification function specified by NotificationFunction is called.
862 If Guid is NULL, then the default token space is used.
864 If NotificationFunction is NULL, then ASSERT().
866 @param[in] Guid Pointer to a 128-bit unique value that designates which
867 namespace to set a value from. If NULL, then the default
869 @param[in] TokenNumber The PCD token number to monitor.
870 @param[in] NotificationFunction The function to call when the token
871 specified by Guid and TokenNumber is set.
876 LibPcdCallbackOnSet (
877 IN CONST GUID
*Guid
, OPTIONAL
878 IN UINTN TokenNumber
,
879 IN PCD_CALLBACK NotificationFunction
884 ASSERT (NotificationFunction
!= NULL
);
886 Status
= mPcd
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
888 ASSERT_EFI_ERROR (Status
);
896 Disable a notification function that was established with LibPcdCallbackonSet().
898 Disable a notification function that was previously established with LibPcdCallbackOnSet().
900 If NotificationFunction is NULL, then ASSERT().
901 If LibPcdCallbackOnSet() was not previously called with Guid, TokenNumber,
902 and NotificationFunction, then ASSERT().
904 @param[in] Guid Specify the GUID token space.
905 @param[in] TokenNumber Specify the token number.
906 @param[in] NotificationFunction The callback function to be unregistered.
911 LibPcdCancelCallback (
912 IN CONST GUID
*Guid
, OPTIONAL
913 IN UINTN TokenNumber
,
914 IN PCD_CALLBACK NotificationFunction
919 ASSERT (NotificationFunction
!= NULL
);
921 Status
= mPcd
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
923 ASSERT_EFI_ERROR (Status
);
931 Retrieves the next token in a token space.
933 Retrieves the next PCD token number from the token space specified by Guid.
934 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
935 then the first token number is returned. Otherwise, the token number that
936 follows TokenNumber in the token space is returned. If TokenNumber is the last
937 token number in the token space, then 0 is returned.
939 If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT().
941 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
942 to set a value from. If NULL, then the default token space is used.
943 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
946 @return The next valid token number.
952 IN CONST GUID
*Guid
, OPTIONAL
958 Status
= mPcd
->GetNextToken (Guid
, &TokenNumber
);
960 ASSERT_EFI_ERROR (Status
);
968 Used to retrieve the list of available PCD token space GUIDs.
970 Retrieves the next PCD token space from a token space specified by Guid.
971 Guid of NULL is reserved to mark the default local token namespace on the current
972 platform. If Guid is NULL, then the GUID of the first non-local token space of the
973 current platform is returned. If Guid is the last non-local token space,
974 then NULL is returned.
976 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
980 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
983 @return The next valid token namespace.
988 LibPcdGetNextTokenSpace (
989 IN CONST GUID
*TokenSpaceGuid
994 Status
= mPcd
->GetNextTokenSpace (&TokenSpaceGuid
);
996 ASSERT_EFI_ERROR (Status
);
998 return (GUID
*) TokenSpaceGuid
;
1003 Sets a value of a patchable PCD entry that is type pointer.
1005 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1006 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
1007 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
1008 NULL to indicate that the set operation was not actually performed.
1009 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
1010 MaximumDatumSize and NULL must be returned.
1012 If PatchVariable is NULL, then ASSERT().
1013 If SizeOfBuffer is NULL, then ASSERT().
1014 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
1016 @param[in] PatchVariable A pointer to the global variable in a module that is
1017 the target of the set operation.
1018 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1019 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1020 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1022 @return Return the pointer to the buffer been set.
1028 IN VOID
*PatchVariable
,
1029 IN UINTN MaximumDatumSize
,
1030 IN OUT UINTN
*SizeOfBuffer
,
1031 IN CONST VOID
*Buffer
1034 ASSERT (PatchVariable
!= NULL
);
1035 ASSERT (SizeOfBuffer
!= NULL
);
1037 if (*SizeOfBuffer
> 0) {
1038 ASSERT (Buffer
!= NULL
);
1041 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1042 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1043 *SizeOfBuffer
= MaximumDatumSize
;
1047 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1049 return (VOID
*) Buffer
;