2 Implementation of PcdLib class library for DXE phase.
4 Copyright (c) 2006, 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.
17 // The package level header files this module uses
21 // The protocols, PPI and GUID defintions for this module
23 #include <Protocol/Pcd.h>
25 // The Library classes this module consumes
27 #include <Library/PcdLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/BaseMemoryLib.h>
32 #include "DxePcdLibInternal.h"
34 static PCD_PROTOCOL
*mPcd
;
37 The constructor function caches the PCD_PROTOCOL pointer.
39 @param[in] ImageHandle The firmware allocated handle for the EFI image.
40 @param[in] SystemTable A pointer to the EFI System Table.
42 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
48 IN EFI_HANDLE ImageHandle
,
49 IN EFI_SYSTEM_TABLE
*SystemTable
54 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
55 ASSERT_EFI_ERROR (Status
);
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 @retval SKU_ID Return the SKU ID that just be set.
76 ASSERT (SkuId
< 0x100);
86 Returns the 8-bit value for the token specified by TokenNumber.
88 @param[in] The PCD token number to retrieve a current value for.
90 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
99 return mPcd
->Get8 (TokenNumber
);
105 Returns the 16-bit value for the token specified by TokenNumber.
107 @param[in] The PCD token number to retrieve a current value for.
109 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
118 return mPcd
->Get16 (TokenNumber
);
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 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
137 return mPcd
->Get32 (TokenNumber
);
143 Returns the 64-bit value for the token specified by TokenNumber.
145 @param[in] TokenNumber The PCD token number to retrieve a current value for.
147 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
156 return mPcd
->Get64 (TokenNumber
);
162 Returns the pointer to the buffer of the token specified by TokenNumber.
164 @param[in] TokenNumber The PCD token number to retrieve a current value for.
166 @retval VOID* Returns the pointer to the token specified by TokenNumber.
175 return mPcd
->GetPtr (TokenNumber
);
181 Returns the Boolean value of the token specified by TokenNumber.
183 @param[in] TokenNumber The PCD token number to retrieve a current value for.
185 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
194 return mPcd
->GetBool (TokenNumber
);
200 Returns the size of the token specified by TokenNumber.
202 @param[in] TokenNumber The PCD token number to retrieve a current value for.
204 @retval UINTN Returns the size of the token specified by TokenNumber.
213 return mPcd
->GetSize (TokenNumber
);
219 Returns the 8-bit value for the token specified by TokenNumber and Guid.
220 If Guid is NULL, then ASSERT().
222 @param[in] Guid Pointer to a 128-bit unique value that designates
223 which namespace to retrieve a value from.
224 @param[in] TokenNumber The PCD token number to retrieve a current value for.
226 @retval UINT8 Return the UINT8.
236 ASSERT (Guid
!= NULL
);
238 return mPcd
->Get8Ex (Guid
, TokenNumber
);
243 Returns the 16-bit value for the token specified by TokenNumber and Guid.
244 If Guid is NULL, then ASSERT().
246 @param[in] Guid Pointer to a 128-bit unique value that designates
247 which namespace to retrieve a value from.
248 @param[in] TokenNumber The PCD token number to retrieve a current value for.
250 @retval UINT16 Return the UINT16.
260 ASSERT (Guid
!= NULL
);
262 return mPcd
->Get16Ex (Guid
, TokenNumber
);
267 Returns the 32-bit value for the token specified by TokenNumber and Guid.
268 If Guid is NULL, then ASSERT().
270 @param[in] Guid Pointer to a 128-bit unique value that designates
271 which namespace to retrieve a value from.
272 @param[in] TokenNumber The PCD token number to retrieve a current value for.
274 @retval UINT32 Return the UINT32.
284 ASSERT (Guid
!= NULL
);
286 return mPcd
->Get32Ex (Guid
, TokenNumber
);
292 Returns the 64-bit value for the token specified by TokenNumber and Guid.
293 If Guid is NULL, then ASSERT().
295 @param[in] Guid Pointer to a 128-bit unique value that designates
296 which namespace to retrieve a value from.
297 @param[in] TokenNumber The PCD token number to retrieve a current value for.
299 @retval UINT64 Return the UINT64.
309 ASSERT (Guid
!= NULL
);
311 return mPcd
->Get64Ex (Guid
, TokenNumber
);
317 Returns the pointer to the token specified by TokenNumber and Guid.
318 If Guid is NULL, then ASSERT().
320 @param[in] Guid Pointer to a 128-bit unique value that designates
321 which namespace to retrieve a value from.
322 @param[in] TokenNumber The PCD token number to retrieve a current value for.
324 @retval VOID* Return the VOID* pointer.
334 ASSERT (Guid
!= NULL
);
336 return mPcd
->GetPtrEx (Guid
, TokenNumber
);
342 Returns the Boolean value of the token specified by TokenNumber and Guid.
343 If Guid is NULL, then ASSERT().
345 @param[in] Guid Pointer to a 128-bit unique value that designates
346 which namespace to retrieve a value from.
347 @param[in] TokenNumber The PCD token number to retrieve a current value for.
349 @retval BOOLEAN Return the BOOLEAN.
359 ASSERT (Guid
!= NULL
);
361 return mPcd
->GetBoolEx (Guid
, TokenNumber
);
367 Returns the size 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 @retval UINTN Return the size.
384 ASSERT (Guid
!= NULL
);
386 return mPcd
->GetSizeEx (Guid
, TokenNumber
);
392 Sets the 8-bit value for the token specified by TokenNumber
393 to the value specified by Value. Value is returned.
395 @param[in] TokenNumber The PCD token number to set a current value for.
396 @param[in] Value The 8-bit value to set.
398 @retval UINT8 Return the value been set.
404 IN UINTN TokenNumber
,
410 Status
= mPcd
->Set8 (TokenNumber
, Value
);
412 ASSERT_EFI_ERROR (Status
);
420 Sets the 16-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 16-bit value to set.
426 @retval UINT16 Return the value been set.
432 IN UINTN TokenNumber
,
438 Status
= mPcd
->Set16 (TokenNumber
, Value
);
440 ASSERT_EFI_ERROR (Status
);
448 Sets the 32-bit value for the token specified by TokenNumber
449 to the value specified by Value. Value is returned.
451 @param[in] TokenNumber The PCD token number to set a current value for.
452 @param[in] Value The 32-bit value to set.
454 @retval UINT32 Return the value been set.
460 IN UINTN TokenNumber
,
465 Status
= mPcd
->Set32 (TokenNumber
, Value
);
467 ASSERT_EFI_ERROR (Status
);
475 Sets the 64-bit value for the token specified by TokenNumber
476 to the value specified by Value. Value is returned.
478 @param[in] TokenNumber The PCD token number to set a current value for.
479 @param[in] Value The 64-bit value to set.
481 @retval UINT64 Return the value been set.
487 IN UINTN TokenNumber
,
493 Status
= mPcd
->Set64 (TokenNumber
, Value
);
495 ASSERT_EFI_ERROR (Status
);
503 Sets a buffer for the token specified by TokenNumber to
504 the value specified by Buffer and SizeOfValue. Buffer to
505 be set is returned. The content of the buffer could be
506 overwritten if a Callback on SET is registered with this
509 If SizeOfValue is greater than the maximum
510 size support by TokenNumber, then set SizeOfValue to the
511 maximum size supported by TokenNumber and return NULL to
512 indicate that the set operation was not actually performed.
514 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
516 @param[in] TokenNumber The PCD token number to set a current value for.
517 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
518 @param[in] Value A pointer to the buffer to set.
520 @retval VOID* Return the pointer for the buffer been set.
527 IN UINTN TokenNumber
,
528 IN OUT UINTN
*SizeOfBuffer
,
534 ASSERT (SizeOfBuffer
!= NULL
);
536 if (*SizeOfBuffer
> 0) {
537 ASSERT (Buffer
!= NULL
);
540 Status
= mPcd
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
542 if (EFI_ERROR (Status
)) {
552 Sets the Boolean value for the token specified by TokenNumber
553 to the value specified by Value. Value is returned.
555 @param[in] TokenNumber The PCD token number to set a current value for.
556 @param[in] Value The boolean value to set.
558 @retval BOOLEAN Return the value been set.
564 IN UINTN TokenNumber
,
570 Status
= mPcd
->SetBool (TokenNumber
, Value
);
572 ASSERT_EFI_ERROR (Status
);
580 Sets the 8-bit value for the token specified by TokenNumber and
581 Guid to the value specified by Value. Value is returned.
582 If Guid is NULL, then ASSERT().
584 @param[in] Guid Pointer to a 128-bit unique value that
585 designates which namespace to set a value from.
586 @param[in] TokenNumber The PCD token number to set a current value for.
587 @param[in] Value The 8-bit value to set.
589 @retval UINT8 Return the value been set.
596 IN UINTN TokenNumber
,
602 ASSERT (Guid
!= NULL
);
604 Status
= mPcd
->Set8Ex (Guid
, TokenNumber
, Value
);
606 ASSERT_EFI_ERROR (Status
);
614 Sets the 16-bit value for the token specified by TokenNumber and
615 Guid to the value specified by Value. Value is returned.
616 If Guid is NULL, then ASSERT().
618 @param[in] Guid Pointer to a 128-bit unique value that
619 designates which namespace to set a value from.
620 @param[in] TokenNumber The PCD token number to set a current value for.
621 @param[in] Value The 16-bit value to set.
623 @retval UINT8 Return the value been set.
630 IN UINTN TokenNumber
,
636 ASSERT (Guid
!= NULL
);
638 Status
= mPcd
->Set16Ex (Guid
, TokenNumber
, Value
);
640 ASSERT_EFI_ERROR (Status
);
648 Sets the 32-bit value for the token specified by TokenNumber and
649 Guid to the value specified by Value. Value is returned.
650 If Guid is NULL, then ASSERT().
652 @param[in] Guid Pointer to a 128-bit unique value that
653 designates which namespace to set a value from.
654 @param[in] TokenNumber The PCD token number to set a current value for.
655 @param[in] Value The 32-bit value to set.
657 @retval UINT32 Return the value been set.
664 IN UINTN TokenNumber
,
670 ASSERT (Guid
!= NULL
);
672 Status
= mPcd
->Set32Ex (Guid
, TokenNumber
, Value
);
674 ASSERT_EFI_ERROR (Status
);
682 Sets the 64-bit value for the token specified by TokenNumber and
683 Guid to the value specified by Value. Value is returned.
684 If Guid is NULL, then ASSERT().
686 @param[in] Guid Pointer to a 128-bit unique value that
687 designates which namespace to set a value from.
688 @param[in] TokenNumber The PCD token number to set a current value for.
689 @param[in] Value The 64-bit value to set.
691 @retval UINT64 Return the value been set.
698 IN UINTN TokenNumber
,
704 ASSERT (Guid
!= NULL
);
706 Status
= mPcd
->Set64Ex (Guid
, TokenNumber
, Value
);
708 ASSERT_EFI_ERROR (Status
);
716 Sets a buffer for the token specified by TokenNumber to the value specified by
717 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
718 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
719 supported by TokenNumber and return NULL to indicate that the set operation
720 was not actually performed.
722 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
724 @param[in] Guid Pointer to a 128-bit unique value that
725 designates which namespace to set a value from.
726 @param[in] TokenNumber The PCD token number to set a current value for.
727 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
728 @param[in] Buffer A pointer to the buffer to set.
730 @retval VOID * Return the pinter to the buffer been set.
737 IN UINTN TokenNumber
,
738 IN OUT UINTN
*SizeOfBuffer
,
744 ASSERT (Guid
!= NULL
);
746 ASSERT (SizeOfBuffer
!= NULL
);
748 if (*SizeOfBuffer
> 0) {
749 ASSERT (Buffer
!= NULL
);
752 Status
= mPcd
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
754 if (EFI_ERROR (Status
)) {
764 Sets the Boolean value for the token specified by TokenNumber and
765 Guid to the value specified by Value. Value is returned.
766 If Guid is NULL, then ASSERT().
768 @param[in] Guid Pointer to a 128-bit unique value that
769 designates which namespace to set a value from.
770 @param[in] TokenNumber The PCD token number to set a current value for.
771 @param[in] Value The Boolean value to set.
773 @retval Boolean Return the value been set.
780 IN UINTN TokenNumber
,
786 ASSERT (Guid
!= NULL
);
788 Status
= mPcd
->SetBoolEx (Guid
, TokenNumber
, Value
);
790 ASSERT_EFI_ERROR (Status
);
798 When the token specified by TokenNumber and Guid is set,
799 then notification function specified by NotificationFunction is called.
800 If Guid is NULL, then the default token space is used.
801 If NotificationFunction is NULL, then ASSERT().
803 @param[in] Guid Pointer to a 128-bit unique value that designates which
804 namespace to set a value from. If NULL, then the default
806 @param[in] TokenNumber The PCD token number to monitor.
807 @param[in] NotificationFunction The function to call when the token
808 specified by Guid and TokenNumber is set.
815 LibPcdCallbackOnSet (
816 IN CONST GUID
*Guid
, OPTIONAL
817 IN UINTN TokenNumber
,
818 IN PCD_CALLBACK NotificationFunction
823 ASSERT (NotificationFunction
!= NULL
);
825 Status
= mPcd
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
827 ASSERT_EFI_ERROR (Status
);
835 Disable a notification function that was established with LibPcdCallbackonSet().
836 If NotificationFunction is NULL, then ASSERT().
838 @param[in] Guid Specify the GUID token space.
839 @param[in] TokenNumber Specify the token number.
840 @param[in] NotificationFunction The callback function to be unregistered.
847 LibPcdCancelCallback (
848 IN CONST GUID
*Guid
, OPTIONAL
849 IN UINTN TokenNumber
,
850 IN PCD_CALLBACK NotificationFunction
855 ASSERT (NotificationFunction
!= NULL
);
857 Status
= mPcd
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
859 ASSERT_EFI_ERROR (Status
);
867 Retrieves the next PCD token number from the token space specified by Guid.
868 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
869 then the first token number is returned. Otherwise, the token number that
870 follows TokenNumber in the token space is returned. If TokenNumber is the last
871 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
872 is not in the token space specified by Guid, then ASSERT().
874 @param[in] Pointer to a 128-bit unique value that designates which namespace
875 to set a value from. If NULL, then the default token space is used.
876 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
879 @retval UINTN The next valid token number.
885 IN CONST GUID
*Guid
, OPTIONAL
891 Status
= mPcd
->GetNextToken (Guid
, &TokenNumber
);
893 ASSERT_EFI_ERROR (Status
);
901 Retrieves the next PCD token space from a token space specified by Guid.
902 Guid of NULL is reserved to mark the default local token namespace on the current
903 platform. If Guid is NULL, then the GUID of the first non-local token space of the
904 current platform is returned. If Guid is the last non-local token space,
905 then NULL is returned.
907 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
911 @param[in] Pointer to a 128-bit unique value that designates from which namespace
914 @retval CONST GUID * The next valid token namespace.
919 LibPcdGetNextTokenSpace (
925 Status
= mPcd
->GetNextTokenSpace (&Guid
);
927 ASSERT_EFI_ERROR (Status
);
929 return (GUID
*) Guid
;
934 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
935 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
936 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
937 NULL to indicate that the set operation was not actually performed.
938 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
939 MaximumDatumSize and NULL must be returned.
941 If PatchVariable is NULL, then ASSERT().
942 If SizeOfValue is NULL, then ASSERT().
943 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
945 @param[in] PatchVariable A pointer to the global variable in a module that is
946 the target of the set operation.
947 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
948 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
949 @param[in] Buffer A pointer to the buffer to used to set the target variable.
955 IN VOID
*PatchVariable
,
956 IN UINTN MaximumDatumSize
,
957 IN OUT UINTN
*SizeOfBuffer
,
958 IN CONST VOID
*Buffer
961 ASSERT (PatchVariable
!= NULL
);
962 ASSERT (SizeOfBuffer
!= NULL
);
964 if (*SizeOfBuffer
> 0) {
965 ASSERT (Buffer
!= NULL
);
968 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
969 (*SizeOfBuffer
== MAX_ADDRESS
)) {
970 *SizeOfBuffer
= MaximumDatumSize
;
974 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
976 return (VOID
*) Buffer
;