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.
14 Module Name: DxePcdLib.c
19 // The package level header files this module uses
23 // The protocols, PPI and GUID defintions for this module
25 #include <Protocol/Pcd.h>
27 // The Library classes this module consumes
29 #include <Library/PcdLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/BaseMemoryLib.h>
34 #include "DxePcdLibInternal.h"
36 static PCD_PROTOCOL
*mPcd
;
39 The constructor function caches the PCD_PROTOCOL pointer.
41 @param[in] ImageHandle The firmware allocated handle for the EFI image.
42 @param[in] SystemTable A pointer to the EFI System Table.
44 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
50 IN EFI_HANDLE ImageHandle
,
51 IN EFI_SYSTEM_TABLE
*SystemTable
56 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
57 ASSERT_EFI_ERROR (Status
);
64 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
66 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
67 set values associated with a PCD token.
69 @retval SKU_ID Return the SKU ID that just be set.
78 ASSERT (SkuId
< 0x100);
88 Returns the 8-bit value for the token specified by TokenNumber.
90 @param[in] The PCD token number to retrieve a current value for.
92 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
101 return mPcd
->Get8 (TokenNumber
);
107 Returns the 16-bit value for the token specified by TokenNumber.
109 @param[in] The PCD token number to retrieve a current value for.
111 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
120 return mPcd
->Get16 (TokenNumber
);
126 Returns the 32-bit value for the token specified by TokenNumber.
128 @param[in] TokenNumber The PCD token number to retrieve a current value for.
130 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
139 return mPcd
->Get32 (TokenNumber
);
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 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
158 return mPcd
->Get64 (TokenNumber
);
164 Returns the pointer to the buffer of the token specified by TokenNumber.
166 @param[in] TokenNumber The PCD token number to retrieve a current value for.
168 @retval VOID* Returns the pointer to the token specified by TokenNumber.
177 return mPcd
->GetPtr (TokenNumber
);
183 Returns the Boolean value of the token specified by TokenNumber.
185 @param[in] TokenNumber The PCD token number to retrieve a current value for.
187 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
196 return mPcd
->GetBool (TokenNumber
);
202 Returns the size of the token specified by TokenNumber.
204 @param[in] TokenNumber The PCD token number to retrieve a current value for.
206 @retval UINTN Returns the size of the token specified by TokenNumber.
215 return mPcd
->GetSize (TokenNumber
);
221 Returns the 8-bit value for the token specified by TokenNumber and Guid.
222 If Guid is NULL, then ASSERT().
224 @param[in] Guid Pointer to a 128-bit unique value that designates
225 which namespace to retrieve a value from.
226 @param[in] TokenNumber The PCD token number to retrieve a current value for.
228 @retval UINT8 Return the UINT8.
238 ASSERT (Guid
!= NULL
);
240 return mPcd
->Get8Ex (Guid
, TokenNumber
);
245 Returns the 16-bit value for the token specified by TokenNumber and Guid.
246 If Guid is NULL, then ASSERT().
248 @param[in] Guid Pointer to a 128-bit unique value that designates
249 which namespace to retrieve a value from.
250 @param[in] TokenNumber The PCD token number to retrieve a current value for.
252 @retval UINT16 Return the UINT16.
262 ASSERT (Guid
!= NULL
);
264 return mPcd
->Get16Ex (Guid
, TokenNumber
);
269 Returns the 32-bit value for the token specified by TokenNumber and Guid.
270 If Guid is NULL, then ASSERT().
272 @param[in] Guid Pointer to a 128-bit unique value that designates
273 which namespace to retrieve a value from.
274 @param[in] TokenNumber The PCD token number to retrieve a current value for.
276 @retval UINT32 Return the UINT32.
286 ASSERT (Guid
!= NULL
);
288 return mPcd
->Get32Ex (Guid
, TokenNumber
);
294 Returns the 64-bit value for the token specified by TokenNumber and Guid.
295 If Guid is NULL, then ASSERT().
297 @param[in] Guid Pointer to a 128-bit unique value that designates
298 which namespace to retrieve a value from.
299 @param[in] TokenNumber The PCD token number to retrieve a current value for.
301 @retval UINT64 Return the UINT64.
311 ASSERT (Guid
!= NULL
);
313 return mPcd
->Get64Ex (Guid
, TokenNumber
);
319 Returns the pointer to the token specified by TokenNumber and Guid.
320 If Guid is NULL, then ASSERT().
322 @param[in] Guid Pointer to a 128-bit unique value that designates
323 which namespace to retrieve a value from.
324 @param[in] TokenNumber The PCD token number to retrieve a current value for.
326 @retval VOID* Return the VOID* pointer.
336 ASSERT (Guid
!= NULL
);
338 return mPcd
->GetPtrEx (Guid
, TokenNumber
);
344 Returns the Boolean value of the token specified by TokenNumber and Guid.
345 If Guid is NULL, then ASSERT().
347 @param[in] Guid Pointer to a 128-bit unique value that designates
348 which namespace to retrieve a value from.
349 @param[in] TokenNumber The PCD token number to retrieve a current value for.
351 @retval BOOLEAN Return the BOOLEAN.
361 ASSERT (Guid
!= NULL
);
363 return mPcd
->GetBoolEx (Guid
, TokenNumber
);
369 Returns the size of the token specified by TokenNumber and Guid.
370 If Guid is NULL, then ASSERT().
372 @param[in] Guid Pointer to a 128-bit unique value that designates
373 which namespace to retrieve a value from.
374 @param[in] TokenNumber The PCD token number to retrieve a current value for.
376 @retval UINTN Return the size.
386 ASSERT (Guid
!= NULL
);
388 return mPcd
->GetSizeEx (Guid
, TokenNumber
);
394 Sets the 8-bit value for the token specified by TokenNumber
395 to the value specified by Value. Value is returned.
397 @param[in] TokenNumber The PCD token number to set a current value for.
398 @param[in] Value The 8-bit value to set.
400 @retval UINT8 Return the value been set.
406 IN UINTN TokenNumber
,
412 Status
= mPcd
->Set8 (TokenNumber
, Value
);
414 ASSERT_EFI_ERROR (Status
);
422 Sets the 16-bit value for the token specified by TokenNumber
423 to the value specified by Value. Value is returned.
425 @param[in] TokenNumber The PCD token number to set a current value for.
426 @param[in] Value The 16-bit value to set.
428 @retval UINT16 Return the value been set.
434 IN UINTN TokenNumber
,
440 Status
= mPcd
->Set16 (TokenNumber
, Value
);
442 ASSERT_EFI_ERROR (Status
);
450 Sets the 32-bit value for the token specified by TokenNumber
451 to the value specified by Value. Value is returned.
453 @param[in] TokenNumber The PCD token number to set a current value for.
454 @param[in] Value The 32-bit value to set.
456 @retval UINT32 Return the value been set.
462 IN UINTN TokenNumber
,
467 Status
= mPcd
->Set32 (TokenNumber
, Value
);
469 ASSERT_EFI_ERROR (Status
);
477 Sets the 64-bit value for the token specified by TokenNumber
478 to the value specified by Value. Value is returned.
480 @param[in] TokenNumber The PCD token number to set a current value for.
481 @param[in] Value The 64-bit value to set.
483 @retval UINT64 Return the value been set.
489 IN UINTN TokenNumber
,
495 Status
= mPcd
->Set64 (TokenNumber
, Value
);
497 ASSERT_EFI_ERROR (Status
);
505 Sets a buffer for the token specified by TokenNumber to
506 the value specified by Buffer and SizeOfValue. Buffer to
507 be set is returned. The content of the buffer could be
508 overwritten if a Callback on SET is registered with this
511 If SizeOfValue is greater than the maximum
512 size support by TokenNumber, then set SizeOfValue to the
513 maximum size supported by TokenNumber and return NULL to
514 indicate that the set operation was not actually performed.
516 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
518 @param[in] TokenNumber The PCD token number to set a current value for.
519 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
520 @param[in] Value A pointer to the buffer to set.
522 @retval VOID* Return the pointer for the buffer been set.
529 IN UINTN TokenNumber
,
530 IN OUT UINTN
*SizeOfBuffer
,
536 ASSERT (SizeOfBuffer
!= NULL
);
538 if (*SizeOfBuffer
> 0) {
539 ASSERT (Buffer
!= NULL
);
542 Status
= mPcd
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
544 if (EFI_ERROR (Status
)) {
554 Sets the Boolean value for the token specified by TokenNumber
555 to the value specified by Value. Value is returned.
557 @param[in] TokenNumber The PCD token number to set a current value for.
558 @param[in] Value The boolean value to set.
560 @retval BOOLEAN Return the value been set.
566 IN UINTN TokenNumber
,
572 Status
= mPcd
->SetBool (TokenNumber
, Value
);
574 ASSERT_EFI_ERROR (Status
);
582 Sets the 8-bit value for the token specified by TokenNumber and
583 Guid to the value specified by Value. Value is returned.
584 If Guid is NULL, then ASSERT().
586 @param[in] Guid Pointer to a 128-bit unique value that
587 designates which namespace to set a value from.
588 @param[in] TokenNumber The PCD token number to set a current value for.
589 @param[in] Value The 8-bit value to set.
591 @retval UINT8 Return the value been set.
598 IN UINTN TokenNumber
,
604 ASSERT (Guid
!= NULL
);
606 Status
= mPcd
->Set8Ex (Guid
, TokenNumber
, Value
);
608 ASSERT_EFI_ERROR (Status
);
616 Sets the 16-bit value for the token specified by TokenNumber and
617 Guid to the value specified by Value. Value is returned.
618 If Guid is NULL, then ASSERT().
620 @param[in] Guid Pointer to a 128-bit unique value that
621 designates which namespace to set a value from.
622 @param[in] TokenNumber The PCD token number to set a current value for.
623 @param[in] Value The 16-bit value to set.
625 @retval UINT8 Return the value been set.
632 IN UINTN TokenNumber
,
638 ASSERT (Guid
!= NULL
);
640 Status
= mPcd
->Set16Ex (Guid
, TokenNumber
, Value
);
642 ASSERT_EFI_ERROR (Status
);
650 Sets the 32-bit value for the token specified by TokenNumber and
651 Guid to the value specified by Value. Value is returned.
652 If Guid is NULL, then ASSERT().
654 @param[in] Guid Pointer to a 128-bit unique value that
655 designates which namespace to set a value from.
656 @param[in] TokenNumber The PCD token number to set a current value for.
657 @param[in] Value The 32-bit value to set.
659 @retval UINT32 Return the value been set.
666 IN UINTN TokenNumber
,
672 ASSERT (Guid
!= NULL
);
674 Status
= mPcd
->Set32Ex (Guid
, TokenNumber
, Value
);
676 ASSERT_EFI_ERROR (Status
);
684 Sets the 64-bit value for the token specified by TokenNumber and
685 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 64-bit value to set.
693 @retval UINT64 Return the value been set.
700 IN UINTN TokenNumber
,
706 ASSERT (Guid
!= NULL
);
708 Status
= mPcd
->Set64Ex (Guid
, TokenNumber
, Value
);
710 ASSERT_EFI_ERROR (Status
);
718 Sets a buffer for the token specified by TokenNumber to the value specified by
719 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
720 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
721 supported by TokenNumber and return NULL to indicate that the set operation
722 was not actually performed.
724 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
726 @param[in] Guid Pointer to a 128-bit unique value that
727 designates which namespace to set a value from.
728 @param[in] TokenNumber The PCD token number to set a current value for.
729 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
730 @param[in] Buffer A pointer to the buffer to set.
732 @retval VOID * Return the pinter to the buffer been set.
739 IN UINTN TokenNumber
,
740 IN OUT UINTN
*SizeOfBuffer
,
746 ASSERT (Guid
!= NULL
);
748 ASSERT (SizeOfBuffer
!= NULL
);
750 if (*SizeOfBuffer
> 0) {
751 ASSERT (Buffer
!= NULL
);
754 Status
= mPcd
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
756 if (EFI_ERROR (Status
)) {
766 Sets the Boolean value for the token specified by TokenNumber and
767 Guid to the value specified by Value. Value is returned.
768 If Guid is NULL, then ASSERT().
770 @param[in] Guid Pointer to a 128-bit unique value that
771 designates which namespace to set a value from.
772 @param[in] TokenNumber The PCD token number to set a current value for.
773 @param[in] Value The Boolean value to set.
775 @retval Boolean Return the value been set.
782 IN UINTN TokenNumber
,
788 ASSERT (Guid
!= NULL
);
790 Status
= mPcd
->SetBoolEx (Guid
, TokenNumber
, Value
);
792 ASSERT_EFI_ERROR (Status
);
800 When the token specified by TokenNumber and Guid is set,
801 then notification function specified by NotificationFunction is called.
802 If Guid is NULL, then the default token space is used.
803 If NotificationFunction is NULL, then ASSERT().
805 @param[in] Guid Pointer to a 128-bit unique value that designates which
806 namespace to set a value from. If NULL, then the default
808 @param[in] TokenNumber The PCD token number to monitor.
809 @param[in] NotificationFunction The function to call when the token
810 specified by Guid and TokenNumber is set.
817 LibPcdCallbackOnSet (
818 IN CONST GUID
*Guid
, OPTIONAL
819 IN UINTN TokenNumber
,
820 IN PCD_CALLBACK NotificationFunction
825 ASSERT (NotificationFunction
!= NULL
);
827 Status
= mPcd
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
829 ASSERT_EFI_ERROR (Status
);
837 Disable a notification function that was established with LibPcdCallbackonSet().
838 If NotificationFunction is NULL, then ASSERT().
840 @param[in] Guid Specify the GUID token space.
841 @param[in] TokenNumber Specify the token number.
842 @param[in] NotificationFunction The callback function to be unregistered.
849 LibPcdCancelCallback (
850 IN CONST GUID
*Guid
, OPTIONAL
851 IN UINTN TokenNumber
,
852 IN PCD_CALLBACK NotificationFunction
857 ASSERT (NotificationFunction
!= NULL
);
859 Status
= mPcd
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
861 ASSERT_EFI_ERROR (Status
);
869 Retrieves the next PCD token number from the token space specified by Guid.
870 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
871 then the first token number is returned. Otherwise, the token number that
872 follows TokenNumber in the token space is returned. If TokenNumber is the last
873 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
874 is not in the token space specified by Guid, then ASSERT().
876 @param[in] Pointer to a 128-bit unique value that designates which namespace
877 to set a value from. If NULL, then the default token space is used.
878 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
881 @retval UINTN The next valid token number.
887 IN CONST GUID
*Guid
, OPTIONAL
893 Status
= mPcd
->GetNextToken (Guid
, &TokenNumber
);
895 ASSERT_EFI_ERROR (Status
);
903 Retrieves the next PCD token space from a token space specified by Guid.
904 Guid of NULL is reserved to mark the default local token namespace on the current
905 platform. If Guid is NULL, then the GUID of the first non-local token space of the
906 current platform is returned. If Guid is the last non-local token space,
907 then NULL is returned.
909 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
913 @param[in] Pointer to a 128-bit unique value that designates from which namespace
916 @retval CONST GUID * The next valid token namespace.
921 LibPcdGetNextTokenSpace (
927 Status
= mPcd
->GetNextTokenSpace (&Guid
);
929 ASSERT_EFI_ERROR (Status
);
931 return (GUID
*) Guid
;
936 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
937 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
938 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
939 NULL to indicate that the set operation was not actually performed.
940 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
941 MaximumDatumSize and NULL must be returned.
943 If PatchVariable is NULL, then ASSERT().
944 If SizeOfValue is NULL, then ASSERT().
945 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
947 @param[in] PatchVariable A pointer to the global variable in a module that is
948 the target of the set operation.
949 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
950 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
951 @param[in] Buffer A pointer to the buffer to used to set the target variable.
957 IN VOID
*PatchVariable
,
958 IN UINTN MaximumDatumSize
,
959 IN OUT UINTN
*SizeOfBuffer
,
960 IN CONST VOID
*Buffer
963 ASSERT (PatchVariable
!= NULL
);
964 ASSERT (SizeOfBuffer
!= NULL
);
966 if (*SizeOfBuffer
> 0) {
967 ASSERT (Buffer
!= NULL
);
970 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
971 (*SizeOfBuffer
== MAX_ADDRESS
)) {
972 *SizeOfBuffer
= MaximumDatumSize
;
976 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
978 return (VOID
*) Buffer
;