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] TokenNumber 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] TokenNumber 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] Buffer A pointer to the buffer to set.
524 @retval VOID* Return the pointer for the buffer been set.
530 IN UINTN TokenNumber
,
531 IN OUT UINTN
*SizeOfBuffer
,
537 ASSERT (SizeOfBuffer
!= NULL
);
539 if (*SizeOfBuffer
> 0) {
540 ASSERT (Buffer
!= NULL
);
543 Status
= (GetPcdProtocol ())->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
545 if (EFI_ERROR (Status
)) {
555 Sets the Boolean value for the token specified by TokenNumber
556 to the value specified by Value. Value is returned.
558 @param[in] TokenNumber The PCD token number to set a current value for.
559 @param[in] Value The boolean value to set.
561 @retval BOOLEAN Return the value been set.
567 IN UINTN TokenNumber
,
573 Status
= (GetPcdProtocol ())->SetBool (TokenNumber
, Value
);
575 ASSERT_EFI_ERROR (Status
);
583 Sets the 8-bit value for the token specified by TokenNumber and
584 Guid to the value specified by Value. Value is returned.
585 If Guid is NULL, then ASSERT().
587 @param[in] Guid Pointer to a 128-bit unique value that
588 designates which namespace to set a value from.
589 @param[in] TokenNumber The PCD token number to set a current value for.
590 @param[in] Value The 8-bit value to set.
592 @retval UINT8 Return the value been set.
599 IN UINTN TokenNumber
,
605 ASSERT (Guid
!= NULL
);
607 Status
= (GetPcdProtocol ())->Set8Ex (Guid
, TokenNumber
, Value
);
609 ASSERT_EFI_ERROR (Status
);
617 Sets the 16-bit value for the token specified by TokenNumber and
618 Guid to the value specified by Value. Value is returned.
619 If Guid is NULL, then ASSERT().
621 @param[in] Guid Pointer to a 128-bit unique value that
622 designates which namespace to set a value from.
623 @param[in] TokenNumber The PCD token number to set a current value for.
624 @param[in] Value The 16-bit value to set.
626 @retval UINT8 Return the value been set.
633 IN UINTN TokenNumber
,
639 ASSERT (Guid
!= NULL
);
641 Status
= (GetPcdProtocol ())->Set16Ex (Guid
, TokenNumber
, Value
);
643 ASSERT_EFI_ERROR (Status
);
651 Sets the 32-bit value for the token specified by TokenNumber and
652 Guid to the value specified by Value. Value is returned.
653 If Guid is NULL, then ASSERT().
655 @param[in] Guid Pointer to a 128-bit unique value that
656 designates which namespace to set a value from.
657 @param[in] TokenNumber The PCD token number to set a current value for.
658 @param[in] Value The 32-bit value to set.
660 @retval UINT32 Return the value been set.
667 IN UINTN TokenNumber
,
673 ASSERT (Guid
!= NULL
);
675 Status
= (GetPcdProtocol ())->Set32Ex (Guid
, TokenNumber
, Value
);
677 ASSERT_EFI_ERROR (Status
);
685 Sets the 64-bit value for the token specified by TokenNumber and
686 Guid to the value specified by Value. Value is returned.
687 If Guid is NULL, then ASSERT().
689 @param[in] Guid Pointer to a 128-bit unique value that
690 designates which namespace to set a value from.
691 @param[in] TokenNumber The PCD token number to set a current value for.
692 @param[in] Value The 64-bit value to set.
694 @retval UINT64 Return the value been set.
701 IN UINTN TokenNumber
,
707 ASSERT (Guid
!= NULL
);
709 Status
= (GetPcdProtocol ())->Set64Ex (Guid
, TokenNumber
, Value
);
711 ASSERT_EFI_ERROR (Status
);
719 Sets a buffer for the token specified by TokenNumber to the value specified by
720 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
721 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
722 supported by TokenNumber and return NULL to indicate that the set operation
723 was not actually performed.
725 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
727 @param[in] Guid Pointer to a 128-bit unique value that
728 designates which namespace to set a value from.
729 @param[in] TokenNumber The PCD token number to set a current value for.
730 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
731 @param[in] Buffer A pointer to the buffer to set.
733 @retval VOID * Return the pinter to the buffer been set.
740 IN UINTN TokenNumber
,
741 IN OUT UINTN
*SizeOfBuffer
,
747 ASSERT (Guid
!= NULL
);
749 ASSERT (SizeOfBuffer
!= NULL
);
751 if (*SizeOfBuffer
> 0) {
752 ASSERT (Buffer
!= NULL
);
755 Status
= (GetPcdProtocol ())->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
757 if (EFI_ERROR (Status
)) {
767 Sets the Boolean value for the token specified by TokenNumber and
768 Guid to the value specified by Value. Value is returned.
769 If Guid is NULL, then ASSERT().
771 @param[in] Guid Pointer to a 128-bit unique value that
772 designates which namespace to set a value from.
773 @param[in] TokenNumber The PCD token number to set a current value for.
774 @param[in] Value The Boolean value to set.
776 @retval Boolean Return the value been set.
783 IN UINTN TokenNumber
,
789 ASSERT (Guid
!= NULL
);
791 Status
= (GetPcdProtocol ())->SetBoolEx (Guid
, TokenNumber
, Value
);
793 ASSERT_EFI_ERROR (Status
);
801 When the token specified by TokenNumber and Guid is set,
802 then notification function specified by NotificationFunction is called.
803 If Guid is NULL, then the default token space is used.
804 If NotificationFunction is NULL, then ASSERT().
806 @param[in] Guid Pointer to a 128-bit unique value that designates which
807 namespace to set a value from. If NULL, then the default
809 @param[in] TokenNumber The PCD token number to monitor.
810 @param[in] NotificationFunction The function to call when the token
811 specified by Guid and TokenNumber is set.
818 LibPcdCallbackOnSet (
819 IN CONST GUID
*Guid
, OPTIONAL
820 IN UINTN TokenNumber
,
821 IN PCD_CALLBACK NotificationFunction
826 ASSERT (NotificationFunction
!= NULL
);
828 Status
= (GetPcdProtocol ())->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
830 ASSERT_EFI_ERROR (Status
);
838 Disable a notification function that was established with LibPcdCallbackonSet().
839 If NotificationFunction is NULL, then ASSERT().
841 @param[in] Guid Specify the GUID token space.
842 @param[in] TokenNumber Specify the token number.
843 @param[in] NotificationFunction The callback function to be unregistered.
850 LibPcdCancelCallback (
851 IN CONST GUID
*Guid
, OPTIONAL
852 IN UINTN TokenNumber
,
853 IN PCD_CALLBACK NotificationFunction
858 ASSERT (NotificationFunction
!= NULL
);
860 Status
= (GetPcdProtocol ())->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
862 ASSERT_EFI_ERROR (Status
);
870 Retrieves the next PCD token number from the token space specified by Guid.
871 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
872 then the first token number is returned. Otherwise, the token number that
873 follows TokenNumber in the token space is returned. If TokenNumber is the last
874 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
875 is not in the token space specified by Guid, then ASSERT().
877 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
878 to set a value from. If NULL, then the default token space is used.
879 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
882 @retval UINTN The next valid token number.
888 IN CONST GUID
*Guid
, OPTIONAL
894 Status
= (GetPcdProtocol ())->GetNextToken (Guid
, &TokenNumber
);
896 ASSERT_EFI_ERROR (Status
);
904 Retrieves the next PCD token space from a token space specified by Guid.
905 Guid of NULL is reserved to mark the default local token namespace on the current
906 platform. If Guid is NULL, then the GUID of the first non-local token space of the
907 current platform is returned. If Guid is the last non-local token space,
908 then NULL is returned.
910 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
914 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
917 @retval CONST GUID * The next valid token namespace.
922 LibPcdGetNextTokenSpace (
928 Status
= (GetPcdProtocol ())->GetNextTokenSpace (&Guid
);
930 ASSERT_EFI_ERROR (Status
);
932 return (GUID
*) Guid
;
937 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
938 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
939 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
940 NULL to indicate that the set operation was not actually performed.
941 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
942 MaximumDatumSize and NULL must be returned.
944 If PatchVariable is NULL, then ASSERT().
945 If SizeOfValue is NULL, then ASSERT().
946 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
948 @param[in] PatchVariable A pointer to the global variable in a module that is
949 the target of the set operation.
950 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
951 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
952 @param[in] Buffer A pointer to the buffer to used to set the target variable.
958 IN VOID
*PatchVariable
,
959 IN UINTN MaximumDatumSize
,
960 IN OUT UINTN
*SizeOfBuffer
,
961 IN CONST VOID
*Buffer
964 ASSERT (PatchVariable
!= NULL
);
965 ASSERT (SizeOfBuffer
!= NULL
);
967 if (*SizeOfBuffer
> 0) {
968 ASSERT (Buffer
!= NULL
);
971 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
972 (*SizeOfBuffer
== MAX_ADDRESS
)) {
973 *SizeOfBuffer
= MaximumDatumSize
;
977 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
979 return (VOID
*) Buffer
;