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.
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 #include "DxePcdLibInternal.h"
28 static PCD_PROTOCOL
*mPcd
;
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
48 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
49 ASSERT_EFI_ERROR (Status
);
56 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
58 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
59 set values associated with a PCD token.
61 @retval SKU_ID Return the SKU ID that just be set.
70 ASSERT (SkuId
< 0x100);
80 Returns the 8-bit value for the token specified by TokenNumber.
82 @param[in] The PCD token number to retrieve a current value for.
84 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
93 return mPcd
->Get8 (TokenNumber
);
99 Returns the 16-bit value for the token specified by TokenNumber.
101 @param[in] The PCD token number to retrieve a current value for.
103 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
112 return mPcd
->Get16 (TokenNumber
);
118 Returns the 32-bit value for the token specified by TokenNumber.
120 @param[in] TokenNumber The PCD token number to retrieve a current value for.
122 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
131 return mPcd
->Get32 (TokenNumber
);
137 Returns the 64-bit value for the token specified by TokenNumber.
139 @param[in] TokenNumber The PCD token number to retrieve a current value for.
141 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
150 return mPcd
->Get64 (TokenNumber
);
156 Returns the pointer to the buffer of the token specified by TokenNumber.
158 @param[in] TokenNumber The PCD token number to retrieve a current value for.
160 @retval VOID* Returns the pointer to the token specified by TokenNumber.
169 return mPcd
->GetPtr (TokenNumber
);
175 Returns the Boolean value of the token specified by TokenNumber.
177 @param[in] TokenNumber The PCD token number to retrieve a current value for.
179 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
188 return mPcd
->GetBool (TokenNumber
);
194 Returns the size of the token specified by TokenNumber.
196 @param[in] TokenNumber The PCD token number to retrieve a current value for.
198 @retval UINTN Returns the size of the token specified by TokenNumber.
207 return mPcd
->GetSize (TokenNumber
);
213 Returns the 8-bit value for the token specified by TokenNumber and Guid.
214 If Guid is NULL, then ASSERT().
216 @param[in] Guid Pointer to a 128-bit unique value that designates
217 which namespace to retrieve a value from.
218 @param[in] TokenNumber The PCD token number to retrieve a current value for.
220 @retval UINT8 Return the UINT8.
230 ASSERT (Guid
!= NULL
);
232 return mPcd
->Get8Ex (Guid
, TokenNumber
);
237 Returns the 16-bit value for the token specified by TokenNumber and Guid.
238 If Guid is NULL, then ASSERT().
240 @param[in] Guid Pointer to a 128-bit unique value that designates
241 which namespace to retrieve a value from.
242 @param[in] TokenNumber The PCD token number to retrieve a current value for.
244 @retval UINT16 Return the UINT16.
254 ASSERT (Guid
!= NULL
);
256 return mPcd
->Get16Ex (Guid
, TokenNumber
);
261 Returns the 32-bit value for the token specified by TokenNumber and Guid.
262 If Guid is NULL, then ASSERT().
264 @param[in] Guid Pointer to a 128-bit unique value that designates
265 which namespace to retrieve a value from.
266 @param[in] TokenNumber The PCD token number to retrieve a current value for.
268 @retval UINT32 Return the UINT32.
278 ASSERT (Guid
!= NULL
);
280 return mPcd
->Get32Ex (Guid
, TokenNumber
);
286 Returns the 64-bit value for the token specified by TokenNumber and Guid.
287 If Guid is NULL, then ASSERT().
289 @param[in] Guid Pointer to a 128-bit unique value that designates
290 which namespace to retrieve a value from.
291 @param[in] TokenNumber The PCD token number to retrieve a current value for.
293 @retval UINT64 Return the UINT64.
303 ASSERT (Guid
!= NULL
);
305 return mPcd
->Get64Ex (Guid
, TokenNumber
);
311 Returns the pointer to the token specified by TokenNumber and Guid.
312 If Guid is NULL, then ASSERT().
314 @param[in] Guid Pointer to a 128-bit unique value that designates
315 which namespace to retrieve a value from.
316 @param[in] TokenNumber The PCD token number to retrieve a current value for.
318 @retval VOID* Return the VOID* pointer.
328 ASSERT (Guid
!= NULL
);
330 return mPcd
->GetPtrEx (Guid
, TokenNumber
);
336 Returns the Boolean value of the token specified by TokenNumber and Guid.
337 If Guid is NULL, then ASSERT().
339 @param[in] Guid Pointer to a 128-bit unique value that designates
340 which namespace to retrieve a value from.
341 @param[in] TokenNumber The PCD token number to retrieve a current value for.
343 @retval BOOLEAN Return the BOOLEAN.
353 ASSERT (Guid
!= NULL
);
355 return mPcd
->GetBoolEx (Guid
, TokenNumber
);
361 Returns the size of the token specified by TokenNumber and Guid.
362 If Guid is NULL, then ASSERT().
364 @param[in] Guid Pointer to a 128-bit unique value that designates
365 which namespace to retrieve a value from.
366 @param[in] TokenNumber The PCD token number to retrieve a current value for.
368 @retval UINTN Return the size.
378 ASSERT (Guid
!= NULL
);
380 return mPcd
->GetSizeEx (Guid
, TokenNumber
);
386 Sets the 8-bit value for the token specified by TokenNumber
387 to the value specified by Value. Value is returned.
389 @param[in] TokenNumber The PCD token number to set a current value for.
390 @param[in] Value The 8-bit value to set.
392 @retval UINT8 Return the value been set.
398 IN UINTN TokenNumber
,
404 Status
= mPcd
->Set8 (TokenNumber
, Value
);
406 ASSERT_EFI_ERROR (Status
);
414 Sets the 16-bit value for the token specified by TokenNumber
415 to the value specified by Value. Value is returned.
417 @param[in] TokenNumber The PCD token number to set a current value for.
418 @param[in] Value The 16-bit value to set.
420 @retval UINT16 Return the value been set.
426 IN UINTN TokenNumber
,
432 Status
= mPcd
->Set16 (TokenNumber
, Value
);
434 ASSERT_EFI_ERROR (Status
);
442 Sets the 32-bit value for the token specified by TokenNumber
443 to the value specified by Value. Value is returned.
445 @param[in] TokenNumber The PCD token number to set a current value for.
446 @param[in] Value The 32-bit value to set.
448 @retval UINT32 Return the value been set.
454 IN UINTN TokenNumber
,
459 Status
= mPcd
->Set32 (TokenNumber
, Value
);
461 ASSERT_EFI_ERROR (Status
);
469 Sets the 64-bit value for the token specified by TokenNumber
470 to the value specified by Value. Value is returned.
472 @param[in] TokenNumber The PCD token number to set a current value for.
473 @param[in] Value The 64-bit value to set.
475 @retval UINT64 Return the value been set.
481 IN UINTN TokenNumber
,
487 Status
= mPcd
->Set64 (TokenNumber
, Value
);
489 ASSERT_EFI_ERROR (Status
);
497 Sets a buffer for the token specified by TokenNumber to
498 the value specified by Buffer and SizeOfValue. Buffer to
499 be set is returned. The content of the buffer could be
500 overwritten if a Callback on SET is registered with this
503 If SizeOfValue is greater than the maximum
504 size support by TokenNumber, then set SizeOfValue to the
505 maximum size supported by TokenNumber and return NULL to
506 indicate that the set operation was not actually performed.
508 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
510 @param[in] TokenNumber The PCD token number to set a current value for.
511 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
512 @param[in] Value A pointer to the buffer to set.
514 @retval VOID* Return the pointer for the buffer been set.
521 IN UINTN TokenNumber
,
522 IN OUT UINTN
*SizeOfBuffer
,
528 ASSERT (SizeOfBuffer
!= NULL
);
530 if (*SizeOfBuffer
> 0) {
531 ASSERT (Buffer
!= NULL
);
534 Status
= mPcd
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
536 if (EFI_ERROR (Status
)) {
546 Sets the Boolean value for the token specified by TokenNumber
547 to the value specified by Value. Value is returned.
549 @param[in] TokenNumber The PCD token number to set a current value for.
550 @param[in] Value The boolean value to set.
552 @retval BOOLEAN Return the value been set.
558 IN UINTN TokenNumber
,
564 Status
= mPcd
->SetBool (TokenNumber
, Value
);
566 ASSERT_EFI_ERROR (Status
);
574 Sets the 8-bit value for the token specified by TokenNumber and
575 Guid to the value specified by Value. Value is returned.
576 If Guid is NULL, then ASSERT().
578 @param[in] Guid Pointer to a 128-bit unique value that
579 designates which namespace to set a value from.
580 @param[in] TokenNumber The PCD token number to set a current value for.
581 @param[in] Value The 8-bit value to set.
583 @retval UINT8 Return the value been set.
590 IN UINTN TokenNumber
,
596 ASSERT (Guid
!= NULL
);
598 Status
= mPcd
->Set8Ex (Guid
, TokenNumber
, Value
);
600 ASSERT_EFI_ERROR (Status
);
608 Sets the 16-bit value for the token specified by TokenNumber and
609 Guid to the value specified by Value. Value is returned.
610 If Guid is NULL, then ASSERT().
612 @param[in] Guid Pointer to a 128-bit unique value that
613 designates which namespace to set a value from.
614 @param[in] TokenNumber The PCD token number to set a current value for.
615 @param[in] Value The 16-bit value to set.
617 @retval UINT8 Return the value been set.
624 IN UINTN TokenNumber
,
630 ASSERT (Guid
!= NULL
);
632 Status
= mPcd
->Set16Ex (Guid
, TokenNumber
, Value
);
634 ASSERT_EFI_ERROR (Status
);
642 Sets the 32-bit value for the token specified by TokenNumber and
643 Guid to the value specified by Value. Value is returned.
644 If Guid is NULL, then ASSERT().
646 @param[in] Guid Pointer to a 128-bit unique value that
647 designates which namespace to set a value from.
648 @param[in] TokenNumber The PCD token number to set a current value for.
649 @param[in] Value The 32-bit value to set.
651 @retval UINT32 Return the value been set.
658 IN UINTN TokenNumber
,
664 ASSERT (Guid
!= NULL
);
666 Status
= mPcd
->Set32Ex (Guid
, TokenNumber
, Value
);
668 ASSERT_EFI_ERROR (Status
);
676 Sets the 64-bit value for the token specified by TokenNumber and
677 Guid to the value specified by Value. Value is returned.
678 If Guid is NULL, then ASSERT().
680 @param[in] Guid Pointer to a 128-bit unique value that
681 designates which namespace to set a value from.
682 @param[in] TokenNumber The PCD token number to set a current value for.
683 @param[in] Value The 64-bit value to set.
685 @retval UINT64 Return the value been set.
692 IN UINTN TokenNumber
,
698 ASSERT (Guid
!= NULL
);
700 Status
= mPcd
->Set64Ex (Guid
, TokenNumber
, Value
);
702 ASSERT_EFI_ERROR (Status
);
710 Sets a buffer for the token specified by TokenNumber to the value specified by
711 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
712 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
713 supported by TokenNumber and return NULL to indicate that the set operation
714 was not actually performed.
716 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
718 @param[in] Guid Pointer to a 128-bit unique value that
719 designates which namespace to set a value from.
720 @param[in] TokenNumber The PCD token number to set a current value for.
721 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
722 @param[in] Buffer A pointer to the buffer to set.
724 @retval VOID * Return the pinter to the buffer been set.
731 IN UINTN TokenNumber
,
732 IN OUT UINTN
*SizeOfBuffer
,
738 ASSERT (Guid
!= NULL
);
740 ASSERT (SizeOfBuffer
!= NULL
);
742 if (*SizeOfBuffer
> 0) {
743 ASSERT (Buffer
!= NULL
);
746 Status
= mPcd
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
748 if (EFI_ERROR (Status
)) {
758 Sets the Boolean value for the token specified by TokenNumber and
759 Guid to the value specified by Value. Value is returned.
760 If Guid is NULL, then ASSERT().
762 @param[in] Guid Pointer to a 128-bit unique value that
763 designates which namespace to set a value from.
764 @param[in] TokenNumber The PCD token number to set a current value for.
765 @param[in] Value The Boolean value to set.
767 @retval Boolean Return the value been set.
774 IN UINTN TokenNumber
,
780 ASSERT (Guid
!= NULL
);
782 Status
= mPcd
->SetBoolEx (Guid
, TokenNumber
, Value
);
784 ASSERT_EFI_ERROR (Status
);
792 When the token specified by TokenNumber and Guid is set,
793 then notification function specified by NotificationFunction is called.
794 If Guid is NULL, then the default token space is used.
795 If NotificationFunction is NULL, then ASSERT().
797 @param[in] Guid Pointer to a 128-bit unique value that designates which
798 namespace to set a value from. If NULL, then the default
800 @param[in] TokenNumber The PCD token number to monitor.
801 @param[in] NotificationFunction The function to call when the token
802 specified by Guid and TokenNumber is set.
809 LibPcdCallbackOnSet (
810 IN CONST GUID
*Guid
, OPTIONAL
811 IN UINTN TokenNumber
,
812 IN PCD_CALLBACK NotificationFunction
817 ASSERT (NotificationFunction
!= NULL
);
819 Status
= mPcd
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
821 ASSERT_EFI_ERROR (Status
);
829 Disable a notification function that was established with LibPcdCallbackonSet().
830 If NotificationFunction is NULL, then ASSERT().
832 @param[in] Guid Specify the GUID token space.
833 @param[in] TokenNumber Specify the token number.
834 @param[in] NotificationFunction The callback function to be unregistered.
841 LibPcdCancelCallback (
842 IN CONST GUID
*Guid
, OPTIONAL
843 IN UINTN TokenNumber
,
844 IN PCD_CALLBACK NotificationFunction
849 ASSERT (NotificationFunction
!= NULL
);
851 Status
= mPcd
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
853 ASSERT_EFI_ERROR (Status
);
861 Retrieves the next PCD token number from the token space specified by Guid.
862 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
863 then the first token number is returned. Otherwise, the token number that
864 follows TokenNumber in the token space is returned. If TokenNumber is the last
865 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
866 is not in the token space specified by Guid, then ASSERT().
868 @param[in] Pointer to a 128-bit unique value that designates which namespace
869 to set a value from. If NULL, then the default token space is used.
870 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
873 @retval UINTN The next valid token number.
879 IN CONST GUID
*Guid
, OPTIONAL
885 Status
= mPcd
->GetNextToken (Guid
, &TokenNumber
);
887 ASSERT_EFI_ERROR (Status
);
895 Retrieves the next PCD token space from a token space specified by Guid.
896 Guid of NULL is reserved to mark the default local token namespace on the current
897 platform. If Guid is NULL, then the GUID of the first non-local token space of the
898 current platform is returned. If Guid is the last non-local token space,
899 then NULL is returned.
901 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
905 @param[in] Pointer to a 128-bit unique value that designates from which namespace
908 @retval CONST GUID * The next valid token namespace.
913 LibPcdGetNextTokenSpace (
919 Status
= mPcd
->GetNextTokenSpace (&Guid
);
921 ASSERT_EFI_ERROR (Status
);
923 return (GUID
*) Guid
;
928 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
929 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
930 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
931 NULL to indicate that the set operation was not actually performed.
932 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
933 MaximumDatumSize and NULL must be returned.
935 If PatchVariable is NULL, then ASSERT().
936 If SizeOfValue is NULL, then ASSERT().
937 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
939 @param[in] PatchVariable A pointer to the global variable in a module that is
940 the target of the set operation.
941 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
942 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
943 @param[in] Buffer A pointer to the buffer to used to set the target variable.
949 IN VOID
*PatchVariable
,
950 IN UINTN MaximumDatumSize
,
951 IN OUT UINTN
*SizeOfBuffer
,
952 IN CONST VOID
*Buffer
955 ASSERT (PatchVariable
!= NULL
);
956 ASSERT (SizeOfBuffer
!= NULL
);
958 if (*SizeOfBuffer
> 0) {
959 ASSERT (Buffer
!= NULL
);
962 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
963 (*SizeOfBuffer
== MAX_ADDRESS
)) {
964 *SizeOfBuffer
= MaximumDatumSize
;
968 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
970 return (VOID
*) Buffer
;