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
18 static PCD_PROTOCOL
*mPcd
;
21 The constructor function caches the PCD_PROTOCOL pointer.
23 @param[in] ImageHandle The firmware allocated handle for the EFI image.
24 @param[in] SystemTable A pointer to the EFI System Table.
26 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
32 IN EFI_HANDLE ImageHandle
,
33 IN EFI_SYSTEM_TABLE
*SystemTable
38 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
39 ASSERT_EFI_ERROR (Status
);
46 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
48 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
49 set values associated with a PCD token.
51 @retval SKU_ID Return the SKU ID that just be set.
60 ASSERT (SkuId
< 0x100);
70 Returns the 8-bit value for the token specified by TokenNumber.
72 @param[in] The PCD token number to retrieve a current value for.
74 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
83 return mPcd
->Get8 (TokenNumber
);
89 Returns the 16-bit value for the token specified by TokenNumber.
91 @param[in] The PCD token number to retrieve a current value for.
93 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
102 return mPcd
->Get16 (TokenNumber
);
108 Returns the 32-bit value for the token specified by TokenNumber.
110 @param[in] TokenNumber The PCD token number to retrieve a current value for.
112 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
121 return mPcd
->Get32 (TokenNumber
);
127 Returns the 64-bit value for the token specified by TokenNumber.
129 @param[in] TokenNumber The PCD token number to retrieve a current value for.
131 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
140 return mPcd
->Get64 (TokenNumber
);
146 Returns the pointer to the buffer of the token specified by TokenNumber.
148 @param[in] TokenNumber The PCD token number to retrieve a current value for.
150 @retval VOID* Returns the pointer to the token specified by TokenNumber.
159 return mPcd
->GetPtr (TokenNumber
);
165 Returns the Boolean value of the token specified by TokenNumber.
167 @param[in] TokenNumber The PCD token number to retrieve a current value for.
169 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
178 return mPcd
->GetBool (TokenNumber
);
184 Returns the size of the token specified by TokenNumber.
186 @param[in] TokenNumber The PCD token number to retrieve a current value for.
188 @retval UINTN Returns the size of the token specified by TokenNumber.
197 return mPcd
->GetSize (TokenNumber
);
203 Returns the 8-bit value for the token specified by TokenNumber and Guid.
204 If Guid is NULL, then ASSERT().
206 @param[in] Guid Pointer to a 128-bit unique value that designates
207 which namespace to retrieve a value from.
208 @param[in] TokenNumber The PCD token number to retrieve a current value for.
210 @retval UINT8 Return the UINT8.
220 ASSERT (Guid
!= NULL
);
222 return mPcd
->Get8Ex (Guid
, TokenNumber
);
227 Returns the 16-bit value for the token specified by TokenNumber and Guid.
228 If Guid is NULL, then ASSERT().
230 @param[in] Guid Pointer to a 128-bit unique value that designates
231 which namespace to retrieve a value from.
232 @param[in] TokenNumber The PCD token number to retrieve a current value for.
234 @retval UINT16 Return the UINT16.
244 ASSERT (Guid
!= NULL
);
246 return mPcd
->Get16Ex (Guid
, TokenNumber
);
251 Returns the 32-bit value for the token specified by TokenNumber and Guid.
252 If Guid is NULL, then ASSERT().
254 @param[in] Guid Pointer to a 128-bit unique value that designates
255 which namespace to retrieve a value from.
256 @param[in] TokenNumber The PCD token number to retrieve a current value for.
258 @retval UINT32 Return the UINT32.
268 ASSERT (Guid
!= NULL
);
270 return mPcd
->Get32Ex (Guid
, TokenNumber
);
276 Returns the 64-bit value for the token specified by TokenNumber and Guid.
277 If Guid is NULL, then ASSERT().
279 @param[in] Guid Pointer to a 128-bit unique value that designates
280 which namespace to retrieve a value from.
281 @param[in] TokenNumber The PCD token number to retrieve a current value for.
283 @retval UINT64 Return the UINT64.
293 ASSERT (Guid
!= NULL
);
295 return mPcd
->Get64Ex (Guid
, TokenNumber
);
301 Returns the pointer to the token specified by TokenNumber and Guid.
302 If Guid is NULL, then ASSERT().
304 @param[in] Guid Pointer to a 128-bit unique value that designates
305 which namespace to retrieve a value from.
306 @param[in] TokenNumber The PCD token number to retrieve a current value for.
308 @retval VOID* Return the VOID* pointer.
318 ASSERT (Guid
!= NULL
);
320 return mPcd
->GetPtrEx (Guid
, TokenNumber
);
326 Returns the Boolean value of the token specified by TokenNumber and Guid.
327 If Guid is NULL, then ASSERT().
329 @param[in] Guid Pointer to a 128-bit unique value that designates
330 which namespace to retrieve a value from.
331 @param[in] TokenNumber The PCD token number to retrieve a current value for.
333 @retval BOOLEAN Return the BOOLEAN.
343 ASSERT (Guid
!= NULL
);
345 return mPcd
->GetBoolEx (Guid
, TokenNumber
);
351 Returns the size of the token specified by TokenNumber and Guid.
352 If Guid is NULL, then ASSERT().
354 @param[in] Guid Pointer to a 128-bit unique value that designates
355 which namespace to retrieve a value from.
356 @param[in] TokenNumber The PCD token number to retrieve a current value for.
358 @retval UINTN Return the size.
368 ASSERT (Guid
!= NULL
);
370 return mPcd
->GetSizeEx (Guid
, TokenNumber
);
376 Sets the 8-bit value for the token specified by TokenNumber
377 to the value specified by Value. Value is returned.
379 @param[in] TokenNumber The PCD token number to set a current value for.
380 @param[in] Value The 8-bit value to set.
382 @retval UINT8 Return the value been set.
388 IN UINTN TokenNumber
,
394 Status
= mPcd
->Set8 (TokenNumber
, Value
);
396 ASSERT_EFI_ERROR (Status
);
404 Sets the 16-bit value for the token specified by TokenNumber
405 to the value specified by Value. Value is returned.
407 @param[in] TokenNumber The PCD token number to set a current value for.
408 @param[in] Value The 16-bit value to set.
410 @retval UINT16 Return the value been set.
416 IN UINTN TokenNumber
,
422 Status
= mPcd
->Set16 (TokenNumber
, Value
);
424 ASSERT_EFI_ERROR (Status
);
432 Sets the 32-bit value for the token specified by TokenNumber
433 to the value specified by Value. Value is returned.
435 @param[in] TokenNumber The PCD token number to set a current value for.
436 @param[in] Value The 32-bit value to set.
438 @retval UINT32 Return the value been set.
444 IN UINTN TokenNumber
,
449 Status
= mPcd
->Set32 (TokenNumber
, Value
);
451 ASSERT_EFI_ERROR (Status
);
459 Sets the 64-bit value for the token specified by TokenNumber
460 to the value specified by Value. Value is returned.
462 @param[in] TokenNumber The PCD token number to set a current value for.
463 @param[in] Value The 64-bit value to set.
465 @retval UINT64 Return the value been set.
471 IN UINTN TokenNumber
,
477 Status
= mPcd
->Set64 (TokenNumber
, Value
);
479 ASSERT_EFI_ERROR (Status
);
487 Sets a buffer for the token specified by TokenNumber to
488 the value specified by Buffer and SizeOfValue. Buffer to
489 be set is returned. The content of the buffer could be
490 overwritten if a Callback on SET is registered with this
493 If SizeOfValue is greater than the maximum
494 size support by TokenNumber, then set SizeOfValue to the
495 maximum size supported by TokenNumber and return NULL to
496 indicate that the set operation was not actually performed.
498 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
500 @param[in] TokenNumber The PCD token number to set a current value for.
501 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
502 @param[in] Value A pointer to the buffer to set.
504 @retval VOID* Return the pointer for the buffer been set.
511 IN UINTN TokenNumber
,
512 IN OUT UINTN
*SizeOfBuffer
,
518 ASSERT (SizeOfBuffer
!= NULL
);
520 if (*SizeOfBuffer
> 0) {
521 ASSERT (Buffer
!= NULL
);
524 Status
= mPcd
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
526 if (EFI_ERROR (Status
)) {
536 Sets the Boolean value for the token specified by TokenNumber
537 to the value specified by Value. Value is returned.
539 @param[in] TokenNumber The PCD token number to set a current value for.
540 @param[in] Value The boolean value to set.
542 @retval BOOLEAN Return the value been set.
548 IN UINTN TokenNumber
,
554 Status
= mPcd
->SetBool (TokenNumber
, Value
);
556 ASSERT_EFI_ERROR (Status
);
564 Sets the 8-bit value for the token specified by TokenNumber and
565 Guid to the value specified by Value. Value is returned.
566 If Guid is NULL, then ASSERT().
568 @param[in] Guid Pointer to a 128-bit unique value that
569 designates which namespace to set a value from.
570 @param[in] TokenNumber The PCD token number to set a current value for.
571 @param[in] Value The 8-bit value to set.
573 @retval UINT8 Return the value been set.
580 IN UINTN TokenNumber
,
586 ASSERT (Guid
!= NULL
);
588 Status
= mPcd
->Set8Ex (Guid
, TokenNumber
, Value
);
590 ASSERT_EFI_ERROR (Status
);
598 Sets the 16-bit value for the token specified by TokenNumber and
599 Guid to the value specified by Value. Value is returned.
600 If Guid is NULL, then ASSERT().
602 @param[in] Guid Pointer to a 128-bit unique value that
603 designates which namespace to set a value from.
604 @param[in] TokenNumber The PCD token number to set a current value for.
605 @param[in] Value The 16-bit value to set.
607 @retval UINT8 Return the value been set.
614 IN UINTN TokenNumber
,
620 ASSERT (Guid
!= NULL
);
622 Status
= mPcd
->Set16Ex (Guid
, TokenNumber
, Value
);
624 ASSERT_EFI_ERROR (Status
);
632 Sets the 32-bit value for the token specified by TokenNumber and
633 Guid to the value specified by Value. Value is returned.
634 If Guid is NULL, then ASSERT().
636 @param[in] Guid Pointer to a 128-bit unique value that
637 designates which namespace to set a value from.
638 @param[in] TokenNumber The PCD token number to set a current value for.
639 @param[in] Value The 32-bit value to set.
641 @retval UINT32 Return the value been set.
648 IN UINTN TokenNumber
,
654 ASSERT (Guid
!= NULL
);
656 Status
= mPcd
->Set32Ex (Guid
, TokenNumber
, Value
);
658 ASSERT_EFI_ERROR (Status
);
666 Sets the 64-bit value for the token specified by TokenNumber and
667 Guid to the value specified by Value. Value is returned.
668 If Guid is NULL, then ASSERT().
670 @param[in] Guid Pointer to a 128-bit unique value that
671 designates which namespace to set a value from.
672 @param[in] TokenNumber The PCD token number to set a current value for.
673 @param[in] Value The 64-bit value to set.
675 @retval UINT64 Return the value been set.
682 IN UINTN TokenNumber
,
688 ASSERT (Guid
!= NULL
);
690 Status
= mPcd
->Set64Ex (Guid
, TokenNumber
, Value
);
692 ASSERT_EFI_ERROR (Status
);
700 Sets a buffer for the token specified by TokenNumber to the value specified by
701 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
702 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
703 supported by TokenNumber and return NULL to indicate that the set operation
704 was not actually performed.
706 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
708 @param[in] Guid Pointer to a 128-bit unique value that
709 designates which namespace to set a value from.
710 @param[in] TokenNumber The PCD token number to set a current value for.
711 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
712 @param[in] Buffer A pointer to the buffer to set.
714 @retval VOID * Return the pinter to the buffer been set.
721 IN UINTN TokenNumber
,
722 IN OUT UINTN
*SizeOfBuffer
,
728 ASSERT (Guid
!= NULL
);
730 ASSERT (SizeOfBuffer
!= NULL
);
732 if (*SizeOfBuffer
> 0) {
733 ASSERT (Buffer
!= NULL
);
736 Status
= mPcd
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
738 if (EFI_ERROR (Status
)) {
748 Sets the Boolean value for the token specified by TokenNumber and
749 Guid to the value specified by Value. Value is returned.
750 If Guid is NULL, then ASSERT().
752 @param[in] Guid Pointer to a 128-bit unique value that
753 designates which namespace to set a value from.
754 @param[in] TokenNumber The PCD token number to set a current value for.
755 @param[in] Value The Boolean value to set.
757 @retval Boolean Return the value been set.
764 IN UINTN TokenNumber
,
770 ASSERT (Guid
!= NULL
);
772 Status
= mPcd
->SetBoolEx (Guid
, TokenNumber
, Value
);
774 ASSERT_EFI_ERROR (Status
);
782 When the token specified by TokenNumber and Guid is set,
783 then notification function specified by NotificationFunction is called.
784 If Guid is NULL, then the default token space is used.
785 If NotificationFunction is NULL, then ASSERT().
787 @param[in] Guid Pointer to a 128-bit unique value that designates which
788 namespace to set a value from. If NULL, then the default
790 @param[in] TokenNumber The PCD token number to monitor.
791 @param[in] NotificationFunction The function to call when the token
792 specified by Guid and TokenNumber is set.
799 LibPcdCallbackOnSet (
800 IN CONST GUID
*Guid
, OPTIONAL
801 IN UINTN TokenNumber
,
802 IN PCD_CALLBACK NotificationFunction
807 ASSERT (NotificationFunction
!= NULL
);
809 Status
= mPcd
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
811 ASSERT_EFI_ERROR (Status
);
819 Disable a notification function that was established with LibPcdCallbackonSet().
820 If NotificationFunction is NULL, then ASSERT().
822 @param[in] Guid Specify the GUID token space.
823 @param[in] TokenNumber Specify the token number.
824 @param[in] NotificationFunction The callback function to be unregistered.
831 LibPcdCancelCallback (
832 IN CONST GUID
*Guid
, OPTIONAL
833 IN UINTN TokenNumber
,
834 IN PCD_CALLBACK NotificationFunction
839 ASSERT (NotificationFunction
!= NULL
);
841 Status
= mPcd
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
843 ASSERT_EFI_ERROR (Status
);
851 Retrieves the next PCD token number from the token space specified by Guid.
852 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
853 then the first token number is returned. Otherwise, the token number that
854 follows TokenNumber in the token space is returned. If TokenNumber is the last
855 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
856 is not in the token space specified by Guid, then ASSERT().
858 @param[in] Pointer to a 128-bit unique value that designates which namespace
859 to set a value from. If NULL, then the default token space is used.
860 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
863 @retval UINTN The next valid token number.
869 IN CONST GUID
*Guid
, OPTIONAL
875 Status
= mPcd
->GetNextToken (Guid
, &TokenNumber
);
877 ASSERT_EFI_ERROR (Status
);
885 Retrieves the next PCD token space from a token space specified by Guid.
886 Guid of NULL is reserved to mark the default local token namespace on the current
887 platform. If Guid is NULL, then the GUID of the first non-local token space of the
888 current platform is returned. If Guid is the last non-local token space,
889 then NULL is returned.
891 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
895 @param[in] Pointer to a 128-bit unique value that designates from which namespace
898 @retval CONST GUID * The next valid token namespace.
903 LibPcdGetNextTokenSpace (
909 Status
= mPcd
->GetNextTokenSpace (&Guid
);
911 ASSERT_EFI_ERROR (Status
);
913 return (GUID
*) Guid
;
918 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
919 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
920 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
921 NULL to indicate that the set operation was not actually performed.
922 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
923 MaximumDatumSize and NULL must be returned.
925 If PatchVariable is NULL, then ASSERT().
926 If SizeOfValue is NULL, then ASSERT().
927 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
929 @param[in] PatchVariable A pointer to the global variable in a module that is
930 the target of the set operation.
931 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
932 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
933 @param[in] Buffer A pointer to the buffer to used to set the target variable.
939 IN VOID
*PatchVariable
,
940 IN UINTN MaximumDatumSize
,
941 IN OUT UINTN
*SizeOfBuffer
,
942 IN CONST VOID
*Buffer
945 ASSERT (PatchVariable
!= NULL
);
946 ASSERT (SizeOfBuffer
!= NULL
);
948 if (*SizeOfBuffer
> 0) {
949 ASSERT (Buffer
!= NULL
);
952 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
953 (*SizeOfBuffer
== MAX_ADDRESS
)) {
954 *SizeOfBuffer
= MaximumDatumSize
;
958 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
960 return (VOID
*) Buffer
;