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 // Include common header file for this module.
21 #include "CommonHeader.h"
23 static PCD_PROTOCOL
*mPcd
;
26 The constructor function caches the PCD_PROTOCOL pointer.
28 @param[in] ImageHandle The firmware allocated handle for the EFI image.
29 @param[in] SystemTable A pointer to the EFI System Table.
31 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
37 IN EFI_HANDLE ImageHandle
,
38 IN EFI_SYSTEM_TABLE
*SystemTable
43 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
44 ASSERT_EFI_ERROR (Status
);
51 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
53 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
54 set values associated with a PCD token.
56 @retval SKU_ID Return the SKU ID that just be set.
65 ASSERT (SkuId
< 0x100);
75 Returns the 8-bit value for the token specified by TokenNumber.
77 @param[in] The PCD token number to retrieve a current value for.
79 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
88 return mPcd
->Get8 (TokenNumber
);
94 Returns the 16-bit value for the token specified by TokenNumber.
96 @param[in] The PCD token number to retrieve a current value for.
98 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
107 return mPcd
->Get16 (TokenNumber
);
113 Returns the 32-bit value for the token specified by TokenNumber.
115 @param[in] TokenNumber The PCD token number to retrieve a current value for.
117 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
126 return mPcd
->Get32 (TokenNumber
);
132 Returns the 64-bit value for the token specified by TokenNumber.
134 @param[in] TokenNumber The PCD token number to retrieve a current value for.
136 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
145 return mPcd
->Get64 (TokenNumber
);
151 Returns the pointer to the buffer of the token specified by TokenNumber.
153 @param[in] TokenNumber The PCD token number to retrieve a current value for.
155 @retval VOID* Returns the pointer to the token specified by TokenNumber.
164 return mPcd
->GetPtr (TokenNumber
);
170 Returns the Boolean value of the token specified by TokenNumber.
172 @param[in] TokenNumber The PCD token number to retrieve a current value for.
174 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
183 return mPcd
->GetBool (TokenNumber
);
189 Returns the size of the token specified by TokenNumber.
191 @param[in] TokenNumber The PCD token number to retrieve a current value for.
193 @retval UINTN Returns the size of the token specified by TokenNumber.
202 return mPcd
->GetSize (TokenNumber
);
208 Returns the 8-bit value for the token specified by TokenNumber and Guid.
209 If Guid is NULL, then ASSERT().
211 @param[in] Guid Pointer to a 128-bit unique value that designates
212 which namespace to retrieve a value from.
213 @param[in] TokenNumber The PCD token number to retrieve a current value for.
215 @retval UINT8 Return the UINT8.
225 ASSERT (Guid
!= NULL
);
227 return mPcd
->Get8Ex (Guid
, TokenNumber
);
232 Returns the 16-bit value for the token specified by TokenNumber and Guid.
233 If Guid is NULL, then ASSERT().
235 @param[in] Guid Pointer to a 128-bit unique value that designates
236 which namespace to retrieve a value from.
237 @param[in] TokenNumber The PCD token number to retrieve a current value for.
239 @retval UINT16 Return the UINT16.
249 ASSERT (Guid
!= NULL
);
251 return mPcd
->Get16Ex (Guid
, TokenNumber
);
256 Returns the 32-bit value for the token specified by TokenNumber and Guid.
257 If Guid is NULL, then ASSERT().
259 @param[in] Guid Pointer to a 128-bit unique value that designates
260 which namespace to retrieve a value from.
261 @param[in] TokenNumber The PCD token number to retrieve a current value for.
263 @retval UINT32 Return the UINT32.
273 ASSERT (Guid
!= NULL
);
275 return mPcd
->Get32Ex (Guid
, TokenNumber
);
281 Returns the 64-bit value for the token specified by TokenNumber and Guid.
282 If Guid is NULL, then ASSERT().
284 @param[in] Guid Pointer to a 128-bit unique value that designates
285 which namespace to retrieve a value from.
286 @param[in] TokenNumber The PCD token number to retrieve a current value for.
288 @retval UINT64 Return the UINT64.
298 ASSERT (Guid
!= NULL
);
300 return mPcd
->Get64Ex (Guid
, TokenNumber
);
306 Returns the pointer to the token specified by TokenNumber and Guid.
307 If Guid is NULL, then ASSERT().
309 @param[in] Guid Pointer to a 128-bit unique value that designates
310 which namespace to retrieve a value from.
311 @param[in] TokenNumber The PCD token number to retrieve a current value for.
313 @retval VOID* Return the VOID* pointer.
323 ASSERT (Guid
!= NULL
);
325 return mPcd
->GetPtrEx (Guid
, TokenNumber
);
331 Returns the Boolean value of the token specified by TokenNumber and Guid.
332 If Guid is NULL, then ASSERT().
334 @param[in] Guid Pointer to a 128-bit unique value that designates
335 which namespace to retrieve a value from.
336 @param[in] TokenNumber The PCD token number to retrieve a current value for.
338 @retval BOOLEAN Return the BOOLEAN.
348 ASSERT (Guid
!= NULL
);
350 return mPcd
->GetBoolEx (Guid
, TokenNumber
);
356 Returns the size of the token specified by TokenNumber and Guid.
357 If Guid is NULL, then ASSERT().
359 @param[in] Guid Pointer to a 128-bit unique value that designates
360 which namespace to retrieve a value from.
361 @param[in] TokenNumber The PCD token number to retrieve a current value for.
363 @retval UINTN Return the size.
373 ASSERT (Guid
!= NULL
);
375 return mPcd
->GetSizeEx (Guid
, TokenNumber
);
381 Sets the 8-bit value for the token specified by TokenNumber
382 to the value specified by Value. Value is returned.
384 @param[in] TokenNumber The PCD token number to set a current value for.
385 @param[in] Value The 8-bit value to set.
387 @retval UINT8 Return the value been set.
393 IN UINTN TokenNumber
,
399 Status
= mPcd
->Set8 (TokenNumber
, Value
);
401 ASSERT_EFI_ERROR (Status
);
409 Sets the 16-bit value for the token specified by TokenNumber
410 to the value specified by Value. Value is returned.
412 @param[in] TokenNumber The PCD token number to set a current value for.
413 @param[in] Value The 16-bit value to set.
415 @retval UINT16 Return the value been set.
421 IN UINTN TokenNumber
,
427 Status
= mPcd
->Set16 (TokenNumber
, Value
);
429 ASSERT_EFI_ERROR (Status
);
437 Sets the 32-bit value for the token specified by TokenNumber
438 to the value specified by Value. Value is returned.
440 @param[in] TokenNumber The PCD token number to set a current value for.
441 @param[in] Value The 32-bit value to set.
443 @retval UINT32 Return the value been set.
449 IN UINTN TokenNumber
,
454 Status
= mPcd
->Set32 (TokenNumber
, Value
);
456 ASSERT_EFI_ERROR (Status
);
464 Sets the 64-bit value for the token specified by TokenNumber
465 to the value specified by Value. Value is returned.
467 @param[in] TokenNumber The PCD token number to set a current value for.
468 @param[in] Value The 64-bit value to set.
470 @retval UINT64 Return the value been set.
476 IN UINTN TokenNumber
,
482 Status
= mPcd
->Set64 (TokenNumber
, Value
);
484 ASSERT_EFI_ERROR (Status
);
492 Sets a buffer for the token specified by TokenNumber to
493 the value specified by Buffer and SizeOfValue. Buffer to
494 be set is returned. The content of the buffer could be
495 overwritten if a Callback on SET is registered with this
498 If SizeOfValue is greater than the maximum
499 size support by TokenNumber, then set SizeOfValue to the
500 maximum size supported by TokenNumber and return NULL to
501 indicate that the set operation was not actually performed.
503 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
505 @param[in] TokenNumber The PCD token number to set a current value for.
506 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
507 @param[in] Value A pointer to the buffer to set.
509 @retval VOID* Return the pointer for the buffer been set.
516 IN UINTN TokenNumber
,
517 IN OUT UINTN
*SizeOfBuffer
,
523 ASSERT (SizeOfBuffer
!= NULL
);
525 if (*SizeOfBuffer
> 0) {
526 ASSERT (Buffer
!= NULL
);
529 Status
= mPcd
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
531 if (EFI_ERROR (Status
)) {
541 Sets the Boolean value for the token specified by TokenNumber
542 to the value specified by Value. Value is returned.
544 @param[in] TokenNumber The PCD token number to set a current value for.
545 @param[in] Value The boolean value to set.
547 @retval BOOLEAN Return the value been set.
553 IN UINTN TokenNumber
,
559 Status
= mPcd
->SetBool (TokenNumber
, Value
);
561 ASSERT_EFI_ERROR (Status
);
569 Sets the 8-bit value for the token specified by TokenNumber and
570 Guid to the value specified by Value. Value is returned.
571 If Guid is NULL, then ASSERT().
573 @param[in] Guid Pointer to a 128-bit unique value that
574 designates which namespace to set a value from.
575 @param[in] TokenNumber The PCD token number to set a current value for.
576 @param[in] Value The 8-bit value to set.
578 @retval UINT8 Return the value been set.
585 IN UINTN TokenNumber
,
591 ASSERT (Guid
!= NULL
);
593 Status
= mPcd
->Set8Ex (Guid
, TokenNumber
, Value
);
595 ASSERT_EFI_ERROR (Status
);
603 Sets the 16-bit value for the token specified by TokenNumber and
604 Guid to the value specified by Value. Value is returned.
605 If Guid is NULL, then ASSERT().
607 @param[in] Guid Pointer to a 128-bit unique value that
608 designates which namespace to set a value from.
609 @param[in] TokenNumber The PCD token number to set a current value for.
610 @param[in] Value The 16-bit value to set.
612 @retval UINT8 Return the value been set.
619 IN UINTN TokenNumber
,
625 ASSERT (Guid
!= NULL
);
627 Status
= mPcd
->Set16Ex (Guid
, TokenNumber
, Value
);
629 ASSERT_EFI_ERROR (Status
);
637 Sets the 32-bit value for the token specified by TokenNumber and
638 Guid to the value specified by Value. Value is returned.
639 If Guid is NULL, then ASSERT().
641 @param[in] Guid Pointer to a 128-bit unique value that
642 designates which namespace to set a value from.
643 @param[in] TokenNumber The PCD token number to set a current value for.
644 @param[in] Value The 32-bit value to set.
646 @retval UINT32 Return the value been set.
653 IN UINTN TokenNumber
,
659 ASSERT (Guid
!= NULL
);
661 Status
= mPcd
->Set32Ex (Guid
, TokenNumber
, Value
);
663 ASSERT_EFI_ERROR (Status
);
671 Sets the 64-bit value for the token specified by TokenNumber and
672 Guid to the value specified by Value. Value is returned.
673 If Guid is NULL, then ASSERT().
675 @param[in] Guid Pointer to a 128-bit unique value that
676 designates which namespace to set a value from.
677 @param[in] TokenNumber The PCD token number to set a current value for.
678 @param[in] Value The 64-bit value to set.
680 @retval UINT64 Return the value been set.
687 IN UINTN TokenNumber
,
693 ASSERT (Guid
!= NULL
);
695 Status
= mPcd
->Set64Ex (Guid
, TokenNumber
, Value
);
697 ASSERT_EFI_ERROR (Status
);
705 Sets a buffer for the token specified by TokenNumber to the value specified by
706 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
707 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
708 supported by TokenNumber and return NULL to indicate that the set operation
709 was not actually performed.
711 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
713 @param[in] Guid Pointer to a 128-bit unique value that
714 designates which namespace to set a value from.
715 @param[in] TokenNumber The PCD token number to set a current value for.
716 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
717 @param[in] Buffer A pointer to the buffer to set.
719 @retval VOID * Return the pinter to the buffer been set.
726 IN UINTN TokenNumber
,
727 IN OUT UINTN
*SizeOfBuffer
,
733 ASSERT (Guid
!= NULL
);
735 ASSERT (SizeOfBuffer
!= NULL
);
737 if (*SizeOfBuffer
> 0) {
738 ASSERT (Buffer
!= NULL
);
741 Status
= mPcd
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
743 if (EFI_ERROR (Status
)) {
753 Sets the Boolean value for the token specified by TokenNumber and
754 Guid to the value specified by Value. Value is returned.
755 If Guid is NULL, then ASSERT().
757 @param[in] Guid Pointer to a 128-bit unique value that
758 designates which namespace to set a value from.
759 @param[in] TokenNumber The PCD token number to set a current value for.
760 @param[in] Value The Boolean value to set.
762 @retval Boolean Return the value been set.
769 IN UINTN TokenNumber
,
775 ASSERT (Guid
!= NULL
);
777 Status
= mPcd
->SetBoolEx (Guid
, TokenNumber
, Value
);
779 ASSERT_EFI_ERROR (Status
);
787 When the token specified by TokenNumber and Guid is set,
788 then notification function specified by NotificationFunction is called.
789 If Guid is NULL, then the default token space is used.
790 If NotificationFunction is NULL, then ASSERT().
792 @param[in] Guid Pointer to a 128-bit unique value that designates which
793 namespace to set a value from. If NULL, then the default
795 @param[in] TokenNumber The PCD token number to monitor.
796 @param[in] NotificationFunction The function to call when the token
797 specified by Guid and TokenNumber is set.
804 LibPcdCallbackOnSet (
805 IN CONST GUID
*Guid
, OPTIONAL
806 IN UINTN TokenNumber
,
807 IN PCD_CALLBACK NotificationFunction
812 ASSERT (NotificationFunction
!= NULL
);
814 Status
= mPcd
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
816 ASSERT_EFI_ERROR (Status
);
824 Disable a notification function that was established with LibPcdCallbackonSet().
825 If NotificationFunction is NULL, then ASSERT().
827 @param[in] Guid Specify the GUID token space.
828 @param[in] TokenNumber Specify the token number.
829 @param[in] NotificationFunction The callback function to be unregistered.
836 LibPcdCancelCallback (
837 IN CONST GUID
*Guid
, OPTIONAL
838 IN UINTN TokenNumber
,
839 IN PCD_CALLBACK NotificationFunction
844 ASSERT (NotificationFunction
!= NULL
);
846 Status
= mPcd
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
848 ASSERT_EFI_ERROR (Status
);
856 Retrieves the next PCD token number from the token space specified by Guid.
857 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
858 then the first token number is returned. Otherwise, the token number that
859 follows TokenNumber in the token space is returned. If TokenNumber is the last
860 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
861 is not in the token space specified by Guid, then ASSERT().
863 @param[in] Pointer to a 128-bit unique value that designates which namespace
864 to set a value from. If NULL, then the default token space is used.
865 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
868 @retval UINTN The next valid token number.
874 IN CONST GUID
*Guid
, OPTIONAL
880 Status
= mPcd
->GetNextToken (Guid
, &TokenNumber
);
882 ASSERT_EFI_ERROR (Status
);
890 Retrieves the next PCD token space from a token space specified by Guid.
891 Guid of NULL is reserved to mark the default local token namespace on the current
892 platform. If Guid is NULL, then the GUID of the first non-local token space of the
893 current platform is returned. If Guid is the last non-local token space,
894 then NULL is returned.
896 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
900 @param[in] Pointer to a 128-bit unique value that designates from which namespace
903 @retval CONST GUID * The next valid token namespace.
908 LibPcdGetNextTokenSpace (
914 Status
= mPcd
->GetNextTokenSpace (&Guid
);
916 ASSERT_EFI_ERROR (Status
);
918 return (GUID
*) Guid
;
923 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
924 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
925 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
926 NULL to indicate that the set operation was not actually performed.
927 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
928 MaximumDatumSize and NULL must be returned.
930 If PatchVariable is NULL, then ASSERT().
931 If SizeOfValue is NULL, then ASSERT().
932 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
934 @param[in] PatchVariable A pointer to the global variable in a module that is
935 the target of the set operation.
936 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
937 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
938 @param[in] Buffer A pointer to the buffer to used to set the target variable.
944 IN VOID
*PatchVariable
,
945 IN UINTN MaximumDatumSize
,
946 IN OUT UINTN
*SizeOfBuffer
,
947 IN CONST VOID
*Buffer
950 ASSERT (PatchVariable
!= NULL
);
951 ASSERT (SizeOfBuffer
!= NULL
);
953 if (*SizeOfBuffer
> 0) {
954 ASSERT (Buffer
!= NULL
);
957 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
958 (*SizeOfBuffer
== MAX_ADDRESS
)) {
959 *SizeOfBuffer
= MaximumDatumSize
;
963 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
965 return (VOID
*) Buffer
;