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
= NULL
;
31 Retrieves PCD protocol interface.
33 This function retrieves PCD protocol interface. On the first invocation, it
34 retrieves protocol interface via UEFI boot services and cache it to accelarte
35 further access. A module invokes this function only when it needs to access a
37 If UefiBootServicesTableLib has not been initialized, then ASSERT ().
38 If PCD protocol has not been installed, then ASSERT ().
40 @return mPcd The PCD protocol protocol interface.
53 // PCD protocol has not been installed, but a module needs to access a
56 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
57 ASSERT_EFI_ERROR (Status
);
66 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
68 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
69 set values associated with a PCD token.
71 @retval SKU_ID Return the SKU ID that just be set.
80 ASSERT (SkuId
< 0x100);
82 (GetPcdProtocol ())->SetSku (SkuId
);
90 Returns the 8-bit value for the token specified by TokenNumber.
92 @param[in] The PCD token number to retrieve a current value for.
94 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
103 return (GetPcdProtocol ())->Get8 (TokenNumber
);
109 Returns the 16-bit value for the token specified by TokenNumber.
111 @param[in] The PCD token number to retrieve a current value for.
113 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
122 return (GetPcdProtocol ())->Get16 (TokenNumber
);
128 Returns the 32-bit value for the token specified by TokenNumber.
130 @param[in] TokenNumber The PCD token number to retrieve a current value for.
132 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
141 return (GetPcdProtocol ())->Get32 (TokenNumber
);
147 Returns the 64-bit value for the token specified by TokenNumber.
149 @param[in] TokenNumber The PCD token number to retrieve a current value for.
151 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
160 return (GetPcdProtocol ())->Get64 (TokenNumber
);
166 Returns the pointer to the buffer of the token specified by TokenNumber.
168 @param[in] TokenNumber The PCD token number to retrieve a current value for.
170 @retval VOID* Returns the pointer to the token specified by TokenNumber.
179 return (GetPcdProtocol ())->GetPtr (TokenNumber
);
185 Returns the Boolean value of the token specified by TokenNumber.
187 @param[in] TokenNumber The PCD token number to retrieve a current value for.
189 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
198 return (GetPcdProtocol ())->GetBool (TokenNumber
);
204 Returns the size of the token specified by TokenNumber.
206 @param[in] TokenNumber The PCD token number to retrieve a current value for.
208 @retval UINTN Returns the size of the token specified by TokenNumber.
217 return (GetPcdProtocol ())->GetSize (TokenNumber
);
223 Returns the 8-bit value for the token specified by TokenNumber and Guid.
224 If Guid is NULL, then ASSERT().
226 @param[in] Guid Pointer to a 128-bit unique value that designates
227 which namespace to retrieve a value from.
228 @param[in] TokenNumber The PCD token number to retrieve a current value for.
230 @retval UINT8 Return the UINT8.
240 ASSERT (Guid
!= NULL
);
242 return (GetPcdProtocol ())->Get8Ex (Guid
, TokenNumber
);
247 Returns the 16-bit value for the token specified by TokenNumber and Guid.
248 If Guid is NULL, then ASSERT().
250 @param[in] Guid Pointer to a 128-bit unique value that designates
251 which namespace to retrieve a value from.
252 @param[in] TokenNumber The PCD token number to retrieve a current value for.
254 @retval UINT16 Return the UINT16.
264 ASSERT (Guid
!= NULL
);
266 return (GetPcdProtocol ())->Get16Ex (Guid
, TokenNumber
);
271 Returns the 32-bit value for the token specified by TokenNumber and Guid.
272 If Guid is NULL, then ASSERT().
274 @param[in] Guid Pointer to a 128-bit unique value that designates
275 which namespace to retrieve a value from.
276 @param[in] TokenNumber The PCD token number to retrieve a current value for.
278 @retval UINT32 Return the UINT32.
288 ASSERT (Guid
!= NULL
);
290 return (GetPcdProtocol ())->Get32Ex (Guid
, TokenNumber
);
296 Returns the 64-bit value for the token specified by TokenNumber and Guid.
297 If Guid is NULL, then ASSERT().
299 @param[in] Guid Pointer to a 128-bit unique value that designates
300 which namespace to retrieve a value from.
301 @param[in] TokenNumber The PCD token number to retrieve a current value for.
303 @retval UINT64 Return the UINT64.
313 ASSERT (Guid
!= NULL
);
315 return (GetPcdProtocol ())->Get64Ex (Guid
, TokenNumber
);
321 Returns the pointer to the token specified by TokenNumber and Guid.
322 If Guid is NULL, then ASSERT().
324 @param[in] Guid Pointer to a 128-bit unique value that designates
325 which namespace to retrieve a value from.
326 @param[in] TokenNumber The PCD token number to retrieve a current value for.
328 @retval VOID* Return the VOID* pointer.
338 ASSERT (Guid
!= NULL
);
340 return (GetPcdProtocol ())->GetPtrEx (Guid
, TokenNumber
);
346 Returns the Boolean value of the token specified by TokenNumber and Guid.
347 If Guid is NULL, then ASSERT().
349 @param[in] Guid Pointer to a 128-bit unique value that designates
350 which namespace to retrieve a value from.
351 @param[in] TokenNumber The PCD token number to retrieve a current value for.
353 @retval BOOLEAN Return the BOOLEAN.
363 ASSERT (Guid
!= NULL
);
365 return (GetPcdProtocol ())->GetBoolEx (Guid
, TokenNumber
);
371 Returns the size 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 @retval UINTN Return the size.
388 ASSERT (Guid
!= NULL
);
390 return (GetPcdProtocol ())->GetSizeEx (Guid
, TokenNumber
);
396 Sets the 8-bit value for the token specified by TokenNumber
397 to the value specified by Value. Value is returned.
399 @param[in] TokenNumber The PCD token number to set a current value for.
400 @param[in] Value The 8-bit value to set.
402 @retval UINT8 Return the value been set.
408 IN UINTN TokenNumber
,
414 Status
= (GetPcdProtocol ())->Set8 (TokenNumber
, Value
);
416 ASSERT_EFI_ERROR (Status
);
424 Sets the 16-bit value for the token specified by TokenNumber
425 to the value specified by Value. Value is returned.
427 @param[in] TokenNumber The PCD token number to set a current value for.
428 @param[in] Value The 16-bit value to set.
430 @retval UINT16 Return the value been set.
436 IN UINTN TokenNumber
,
442 Status
= (GetPcdProtocol ())->Set16 (TokenNumber
, Value
);
444 ASSERT_EFI_ERROR (Status
);
452 Sets the 32-bit value for the token specified by TokenNumber
453 to the value specified by Value. Value is returned.
455 @param[in] TokenNumber The PCD token number to set a current value for.
456 @param[in] Value The 32-bit value to set.
458 @retval UINT32 Return the value been set.
464 IN UINTN TokenNumber
,
469 Status
= (GetPcdProtocol ())->Set32 (TokenNumber
, Value
);
471 ASSERT_EFI_ERROR (Status
);
479 Sets the 64-bit value for the token specified by TokenNumber
480 to the value specified by Value. Value is returned.
482 @param[in] TokenNumber The PCD token number to set a current value for.
483 @param[in] Value The 64-bit value to set.
485 @retval UINT64 Return the value been set.
491 IN UINTN TokenNumber
,
497 Status
= (GetPcdProtocol ())->Set64 (TokenNumber
, Value
);
499 ASSERT_EFI_ERROR (Status
);
507 Sets a buffer for the token specified by TokenNumber to
508 the value specified by Buffer and SizeOfValue. Buffer to
509 be set is returned. The content of the buffer could be
510 overwritten if a Callback on SET is registered with this
513 If SizeOfValue is greater than the maximum
514 size support by TokenNumber, then set SizeOfValue to the
515 maximum size supported by TokenNumber and return NULL to
516 indicate that the set operation was not actually performed.
518 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
520 @param[in] TokenNumber The PCD token number to set a current value for.
521 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
522 @param[in] Value A pointer to the buffer to set.
524 @retval VOID* Return the pointer for the buffer been set.
531 IN UINTN TokenNumber
,
532 IN OUT UINTN
*SizeOfBuffer
,
538 ASSERT (SizeOfBuffer
!= NULL
);
540 if (*SizeOfBuffer
> 0) {
541 ASSERT (Buffer
!= NULL
);
544 Status
= (GetPcdProtocol ())->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
546 if (EFI_ERROR (Status
)) {
556 Sets the Boolean value for the token specified by TokenNumber
557 to the value specified by Value. Value is returned.
559 @param[in] TokenNumber The PCD token number to set a current value for.
560 @param[in] Value The boolean value to set.
562 @retval BOOLEAN Return the value been set.
568 IN UINTN TokenNumber
,
574 Status
= (GetPcdProtocol ())->SetBool (TokenNumber
, Value
);
576 ASSERT_EFI_ERROR (Status
);
584 Sets the 8-bit value for the token specified by TokenNumber and
585 Guid to the value specified by Value. Value is returned.
586 If Guid is NULL, then ASSERT().
588 @param[in] Guid Pointer to a 128-bit unique value that
589 designates which namespace to set a value from.
590 @param[in] TokenNumber The PCD token number to set a current value for.
591 @param[in] Value The 8-bit value to set.
593 @retval UINT8 Return the value been set.
600 IN UINTN TokenNumber
,
606 ASSERT (Guid
!= NULL
);
608 Status
= (GetPcdProtocol ())->Set8Ex (Guid
, TokenNumber
, Value
);
610 ASSERT_EFI_ERROR (Status
);
618 Sets the 16-bit value for the token specified by TokenNumber and
619 Guid to the value specified by Value. Value is returned.
620 If Guid is NULL, then ASSERT().
622 @param[in] Guid Pointer to a 128-bit unique value that
623 designates which namespace to set a value from.
624 @param[in] TokenNumber The PCD token number to set a current value for.
625 @param[in] Value The 16-bit value to set.
627 @retval UINT8 Return the value been set.
634 IN UINTN TokenNumber
,
640 ASSERT (Guid
!= NULL
);
642 Status
= (GetPcdProtocol ())->Set16Ex (Guid
, TokenNumber
, Value
);
644 ASSERT_EFI_ERROR (Status
);
652 Sets the 32-bit value for the token specified by TokenNumber and
653 Guid to the value specified by Value. Value is returned.
654 If Guid is NULL, then ASSERT().
656 @param[in] Guid Pointer to a 128-bit unique value that
657 designates which namespace to set a value from.
658 @param[in] TokenNumber The PCD token number to set a current value for.
659 @param[in] Value The 32-bit value to set.
661 @retval UINT32 Return the value been set.
668 IN UINTN TokenNumber
,
674 ASSERT (Guid
!= NULL
);
676 Status
= (GetPcdProtocol ())->Set32Ex (Guid
, TokenNumber
, Value
);
678 ASSERT_EFI_ERROR (Status
);
686 Sets the 64-bit value for the token specified by TokenNumber and
687 Guid to the value specified by Value. Value is returned.
688 If Guid is NULL, then ASSERT().
690 @param[in] Guid Pointer to a 128-bit unique value that
691 designates which namespace to set a value from.
692 @param[in] TokenNumber The PCD token number to set a current value for.
693 @param[in] Value The 64-bit value to set.
695 @retval UINT64 Return the value been set.
702 IN UINTN TokenNumber
,
708 ASSERT (Guid
!= NULL
);
710 Status
= (GetPcdProtocol ())->Set64Ex (Guid
, TokenNumber
, Value
);
712 ASSERT_EFI_ERROR (Status
);
720 Sets a buffer for the token specified by TokenNumber to the value specified by
721 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
722 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
723 supported by TokenNumber and return NULL to indicate that the set operation
724 was not actually performed.
726 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
728 @param[in] Guid Pointer to a 128-bit unique value that
729 designates which namespace to set a value from.
730 @param[in] TokenNumber The PCD token number to set a current value for.
731 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
732 @param[in] Buffer A pointer to the buffer to set.
734 @retval VOID * Return the pinter to the buffer been set.
741 IN UINTN TokenNumber
,
742 IN OUT UINTN
*SizeOfBuffer
,
748 ASSERT (Guid
!= NULL
);
750 ASSERT (SizeOfBuffer
!= NULL
);
752 if (*SizeOfBuffer
> 0) {
753 ASSERT (Buffer
!= NULL
);
756 Status
= (GetPcdProtocol ())->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
758 if (EFI_ERROR (Status
)) {
768 Sets the Boolean value for the token specified by TokenNumber and
769 Guid to the value specified by Value. Value is returned.
770 If Guid is NULL, then ASSERT().
772 @param[in] Guid Pointer to a 128-bit unique value that
773 designates which namespace to set a value from.
774 @param[in] TokenNumber The PCD token number to set a current value for.
775 @param[in] Value The Boolean value to set.
777 @retval Boolean Return the value been set.
784 IN UINTN TokenNumber
,
790 ASSERT (Guid
!= NULL
);
792 Status
= (GetPcdProtocol ())->SetBoolEx (Guid
, TokenNumber
, Value
);
794 ASSERT_EFI_ERROR (Status
);
802 When the token specified by TokenNumber and Guid is set,
803 then notification function specified by NotificationFunction is called.
804 If Guid is NULL, then the default token space is used.
805 If NotificationFunction is NULL, then ASSERT().
807 @param[in] Guid Pointer to a 128-bit unique value that designates which
808 namespace to set a value from. If NULL, then the default
810 @param[in] TokenNumber The PCD token number to monitor.
811 @param[in] NotificationFunction The function to call when the token
812 specified by Guid and TokenNumber is set.
819 LibPcdCallbackOnSet (
820 IN CONST GUID
*Guid
, OPTIONAL
821 IN UINTN TokenNumber
,
822 IN PCD_CALLBACK NotificationFunction
827 ASSERT (NotificationFunction
!= NULL
);
829 Status
= (GetPcdProtocol ())->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
831 ASSERT_EFI_ERROR (Status
);
839 Disable a notification function that was established with LibPcdCallbackonSet().
840 If NotificationFunction is NULL, then ASSERT().
842 @param[in] Guid Specify the GUID token space.
843 @param[in] TokenNumber Specify the token number.
844 @param[in] NotificationFunction The callback function to be unregistered.
851 LibPcdCancelCallback (
852 IN CONST GUID
*Guid
, OPTIONAL
853 IN UINTN TokenNumber
,
854 IN PCD_CALLBACK NotificationFunction
859 ASSERT (NotificationFunction
!= NULL
);
861 Status
= (GetPcdProtocol ())->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
863 ASSERT_EFI_ERROR (Status
);
871 Retrieves the next PCD token number from the token space specified by Guid.
872 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
873 then the first token number is returned. Otherwise, the token number that
874 follows TokenNumber in the token space is returned. If TokenNumber is the last
875 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
876 is not in the token space specified by Guid, then ASSERT().
878 @param[in] Pointer to a 128-bit unique value that designates which namespace
879 to set a value from. If NULL, then the default token space is used.
880 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
883 @retval UINTN The next valid token number.
889 IN CONST GUID
*Guid
, OPTIONAL
895 Status
= (GetPcdProtocol ())->GetNextToken (Guid
, &TokenNumber
);
897 ASSERT_EFI_ERROR (Status
);
905 Retrieves the next PCD token space from a token space specified by Guid.
906 Guid of NULL is reserved to mark the default local token namespace on the current
907 platform. If Guid is NULL, then the GUID of the first non-local token space of the
908 current platform is returned. If Guid is the last non-local token space,
909 then NULL is returned.
911 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
915 @param[in] Pointer to a 128-bit unique value that designates from which namespace
918 @retval CONST GUID * The next valid token namespace.
923 LibPcdGetNextTokenSpace (
929 Status
= (GetPcdProtocol ())->GetNextTokenSpace (&Guid
);
931 ASSERT_EFI_ERROR (Status
);
933 return (GUID
*) Guid
;
938 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
939 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
940 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
941 NULL to indicate that the set operation was not actually performed.
942 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
943 MaximumDatumSize and NULL must be returned.
945 If PatchVariable is NULL, then ASSERT().
946 If SizeOfValue is NULL, then ASSERT().
947 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
949 @param[in] PatchVariable A pointer to the global variable in a module that is
950 the target of the set operation.
951 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
952 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
953 @param[in] Buffer A pointer to the buffer to used to set the target variable.
959 IN VOID
*PatchVariable
,
960 IN UINTN MaximumDatumSize
,
961 IN OUT UINTN
*SizeOfBuffer
,
962 IN CONST VOID
*Buffer
965 ASSERT (PatchVariable
!= NULL
);
966 ASSERT (SizeOfBuffer
!= NULL
);
968 if (*SizeOfBuffer
> 0) {
969 ASSERT (Buffer
!= NULL
);
972 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
973 (*SizeOfBuffer
== MAX_ADDRESS
)) {
974 *SizeOfBuffer
= MaximumDatumSize
;
978 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
980 return (VOID
*) Buffer
;