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 PCD_PROTOCOL
*mPcd
= NULL
;
30 The constructor function caches the PCD_PROTOCOL pointer.
32 @param[in] ImageHandle The firmware allocated handle for the EFI image.
33 @param[in] SystemTable A pointer to the EFI System Table.
35 @retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
41 IN EFI_HANDLE ImageHandle
,
42 IN EFI_SYSTEM_TABLE
*SystemTable
48 // PCD protocol has not been installed, but a module needs to access a
51 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
52 ASSERT_EFI_ERROR (Status
);
60 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
61 If SkuId is not less than PCD_MAX_SKU_ID, then ASSERT().
63 @param[in] SkuId System SKU ID. The SKU value that will be used when the PCD service will retrieve and
66 @return Return the SKU ID that just be set.
75 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
85 Returns the 8-bit value for the token specified by TokenNumber.
87 @param[in] TokenNumber The PCD token number to retrieve a current value for.
89 @return Returns the 8-bit value for the token specified by TokenNumber.
98 return mPcd
->Get8 (TokenNumber
);
104 Returns the 16-bit value for the token specified by TokenNumber.
106 @param[in] TokenNumber The PCD token number to retrieve a current value for.
108 @return Returns the 16-bit value for the token specified by TokenNumber.
117 return mPcd
->Get16 (TokenNumber
);
123 Returns the 32-bit value for the token specified by TokenNumber.
125 @param[in] TokenNumber The PCD token number to retrieve a current value for.
127 @return Returns the 32-bit value for the token specified by TokenNumber.
136 return mPcd
->Get32 (TokenNumber
);
142 Returns the 64-bit value for the token specified by TokenNumber.
144 @param[in] TokenNumber The PCD token number to retrieve a current value for.
146 @return Returns the 64-bit value for the token specified by TokenNumber.
155 return mPcd
->Get64 (TokenNumber
);
161 Returns the pointer to the buffer of the token specified by TokenNumber.
163 @param[in] TokenNumber The PCD token number to retrieve a current value for.
165 @return Returns the pointer to the token specified by TokenNumber.
174 return mPcd
->GetPtr (TokenNumber
);
180 Returns the Boolean value of the token specified by TokenNumber.
182 @param[in] TokenNumber The PCD token number to retrieve a current value for.
184 @return Returns the Boolean value of the token specified by TokenNumber.
193 return mPcd
->GetBool (TokenNumber
);
199 Returns the size of the token specified by TokenNumber.
201 @param[in] TokenNumber The PCD token number to retrieve a current value for.
203 @return Returns the size of the token specified by TokenNumber.
212 return mPcd
->GetSize (TokenNumber
);
218 Returns the 8-bit value for the token specified by TokenNumber and Guid.
219 If Guid is NULL, then ASSERT().
221 @param[in] Guid Pointer to a 128-bit unique value that designates
222 which namespace to retrieve a value from.
223 @param[in] TokenNumber The PCD token number to retrieve a current value for.
225 @return Return the UINT8.
235 ASSERT (Guid
!= NULL
);
237 return mPcd
->Get8Ex (Guid
, TokenNumber
);
242 Returns the 16-bit value for the token specified by TokenNumber and Guid.
243 If Guid is NULL, then ASSERT().
245 @param[in] Guid Pointer to a 128-bit unique value that designates
246 which namespace to retrieve a value from.
247 @param[in] TokenNumber The PCD token number to retrieve a current value for.
249 @return Return the UINT16.
259 ASSERT (Guid
!= NULL
);
261 return mPcd
->Get16Ex (Guid
, TokenNumber
);
266 Returns the 32-bit value for the token specified by TokenNumber and Guid.
267 If Guid is NULL, then ASSERT().
269 @param[in] Guid Pointer to a 128-bit unique value that designates
270 which namespace to retrieve a value from.
271 @param[in] TokenNumber The PCD token number to retrieve a current value for.
273 @return Return the UINT32.
283 ASSERT (Guid
!= NULL
);
285 return mPcd
->Get32Ex (Guid
, TokenNumber
);
291 Returns the 64-bit value for the token specified by TokenNumber and Guid.
292 If Guid is NULL, then ASSERT().
294 @param[in] Guid Pointer to a 128-bit unique value that designates
295 which namespace to retrieve a value from.
296 @param[in] TokenNumber The PCD token number to retrieve a current value for.
298 @return Return the UINT64.
308 ASSERT (Guid
!= NULL
);
310 return mPcd
->Get64Ex (Guid
, TokenNumber
);
316 Returns the pointer to the token specified by TokenNumber and Guid.
317 If Guid is NULL, then ASSERT().
319 @param[in] Guid Pointer to a 128-bit unique value that designates
320 which namespace to retrieve a value from.
321 @param[in] TokenNumber The PCD token number to retrieve a current value for.
323 @return Return the VOID* pointer.
333 ASSERT (Guid
!= NULL
);
335 return mPcd
->GetPtrEx (Guid
, TokenNumber
);
341 Returns the Boolean value of the token specified by TokenNumber and Guid.
342 If Guid is NULL, then ASSERT().
344 @param[in] Guid Pointer to a 128-bit unique value that designates
345 which namespace to retrieve a value from.
346 @param[in] TokenNumber The PCD token number to retrieve a current value for.
348 @return Return the BOOLEAN.
358 ASSERT (Guid
!= NULL
);
360 return mPcd
->GetBoolEx (Guid
, TokenNumber
);
366 Returns the size of the token specified by TokenNumber and Guid.
367 If Guid is NULL, then ASSERT().
369 @param[in] Guid Pointer to a 128-bit unique value that designates
370 which namespace to retrieve a value from.
371 @param[in] TokenNumber The PCD token number to retrieve a current value for.
373 @return Return the size.
383 ASSERT (Guid
!= NULL
);
385 return mPcd
->GetSizeEx (Guid
, TokenNumber
);
391 Sets the 8-bit value for the token specified by TokenNumber
392 to the value specified by Value. Value is returned.
393 If fail to set pcd value, then ASSERT_EFI_ERROR().
395 @param[in] TokenNumber The PCD token number to set a current value for.
396 @param[in] Value The 8-bit value to set.
398 @return Return the value been set.
404 IN UINTN TokenNumber
,
410 Status
= mPcd
->Set8 (TokenNumber
, Value
);
412 ASSERT_EFI_ERROR (Status
);
420 Sets the 16-bit value for the token specified by TokenNumber
421 to the value specified by Value. Value is returned.
422 If fail to set pcd value, then ASSERT_EFI_ERROR().
424 @param[in] TokenNumber The PCD token number to set a current value for.
425 @param[in] Value The 16-bit value to set.
427 @return Return the value been set.
433 IN UINTN TokenNumber
,
439 Status
= mPcd
->Set16 (TokenNumber
, Value
);
441 ASSERT_EFI_ERROR (Status
);
449 Sets the 32-bit value for the token specified by TokenNumber
450 to the value specified by Value. Value is returned.
451 If fail to set pcd value, then ASSERT_EFI_ERROR().
453 @param[in] TokenNumber The PCD token number to set a current value for.
454 @param[in] Value The 32-bit value to set.
456 @return Return the value been set.
462 IN UINTN TokenNumber
,
467 Status
= mPcd
->Set32 (TokenNumber
, Value
);
469 ASSERT_EFI_ERROR (Status
);
477 Sets the 64-bit value for the token specified by TokenNumber
478 to the value specified by Value. Value is returned.
479 If fail to set pcd value, then ASSERT_EFI_ERROR().
481 @param[in] TokenNumber The PCD token number to set a current value for.
482 @param[in] Value The 64-bit value to set.
484 @return Return the value been set.
490 IN UINTN TokenNumber
,
496 Status
= mPcd
->Set64 (TokenNumber
, Value
);
498 ASSERT_EFI_ERROR (Status
);
506 Sets a buffer for the token specified by TokenNumber to
507 the value specified by Buffer and SizeOfBuffer. Buffer to
508 be set is returned. The content of the buffer could be
509 overwritten if a Callback on SET is registered with this
512 If SizeOfBuffer is greater than the maximum
513 size support by TokenNumber, then set SizeOfBuffer to the
514 maximum size supported by TokenNumber and return NULL to
515 indicate that the set operation was not actually performed.
517 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
519 @param[in] TokenNumber The PCD token number to set a current value for.
520 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
521 In out, returns actual size of buff is set.
522 @param[in] Buffer A pointer to the buffer to set.
524 @return 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
= mPcd
->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.
557 If fail to set pcd value, then ASSERT_EFI_ERROR().
559 @param[in] TokenNumber The PCD token number to set a current value for.
560 @param[in] Value The boolean value to set.
562 @return Return the value been set.
568 IN UINTN TokenNumber
,
574 Status
= mPcd
->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().
587 If fail to set pcd value, then ASSERT_EFI_ERROR().
589 @param[in] Guid Pointer to a 128-bit unique value that
590 designates which namespace to set a value from.
591 @param[in] TokenNumber The PCD token number to set a current value for.
592 @param[in] Value The 8-bit value to set.
594 @return Return the value been set.
601 IN UINTN TokenNumber
,
607 ASSERT (Guid
!= NULL
);
609 Status
= mPcd
->Set8Ex (Guid
, TokenNumber
, Value
);
611 ASSERT_EFI_ERROR (Status
);
619 Sets the 16-bit value for the token specified by TokenNumber and
620 Guid to the value specified by Value. Value is returned.
621 If Guid is NULL, then ASSERT().
622 If fail to set pcd value, then ASSERT_EFI_ERROR().
624 @param[in] Guid Pointer to a 128-bit unique value that
625 designates which namespace to set a value from.
626 @param[in] TokenNumber The PCD token number to set a current value for.
627 @param[in] Value The 16-bit value to set.
629 @return Return the value been set.
636 IN UINTN TokenNumber
,
642 ASSERT (Guid
!= NULL
);
644 Status
= mPcd
->Set16Ex (Guid
, TokenNumber
, Value
);
646 ASSERT_EFI_ERROR (Status
);
654 Sets the 32-bit value for the token specified by TokenNumber and
655 Guid to the value specified by Value. Value is returned.
656 If Guid is NULL, then ASSERT().
657 If fail to set pcd value, then ASSERT_EFI_ERROR().
659 @param[in] Guid Pointer to a 128-bit unique value that
660 designates which namespace to set a value from.
661 @param[in] TokenNumber The PCD token number to set a current value for.
662 @param[in] Value The 32-bit value to set.
664 @return Return the value been set.
671 IN UINTN TokenNumber
,
677 ASSERT (Guid
!= NULL
);
679 Status
= mPcd
->Set32Ex (Guid
, TokenNumber
, Value
);
681 ASSERT_EFI_ERROR (Status
);
689 Sets the 64-bit value for the token specified by TokenNumber and
690 Guid to the value specified by Value. Value is returned.
691 If Guid is NULL, then ASSERT().
693 @param[in] Guid Pointer to a 128-bit unique value that
694 designates which namespace to set a value from.
695 @param[in] TokenNumber The PCD token number to set a current value for.
696 @param[in] Value The 64-bit value to set.
698 @return Return the value been set.
705 IN UINTN TokenNumber
,
711 ASSERT (Guid
!= NULL
);
713 Status
= mPcd
->Set64Ex (Guid
, TokenNumber
, Value
);
715 ASSERT_EFI_ERROR (Status
);
723 Sets a buffer for the token specified by TokenNumber to the value specified by
724 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
725 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
726 supported by TokenNumber and return NULL to indicate that the set operation
727 was not actually performed.
729 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
731 @param[in] Guid Pointer to a 128-bit unique value that
732 designates which namespace to set a value from.
733 @param[in] TokenNumber The PCD token number to set a current value for.
734 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
735 In out, returns actual size of buffer is set.
736 @param[in] Buffer A pointer to the buffer to set.
738 @return Return the pinter to the buffer been set.
745 IN UINTN TokenNumber
,
746 IN OUT UINTN
*SizeOfBuffer
,
752 ASSERT (Guid
!= NULL
);
754 ASSERT (SizeOfBuffer
!= NULL
);
756 if (*SizeOfBuffer
> 0) {
757 ASSERT (Buffer
!= NULL
);
760 Status
= mPcd
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
762 if (EFI_ERROR (Status
)) {
772 Sets the Boolean value for the token specified by TokenNumber and
773 Guid to the value specified by Value. Value is returned.
774 If Guid is NULL, then ASSERT().
775 If fail to set pcd value, then ASSERT_EFI_ERROR().
777 @param[in] Guid Pointer to a 128-bit unique value that
778 designates which namespace to set a value from.
779 @param[in] TokenNumber The PCD token number to set a current value for.
780 @param[in] Value The Boolean value to set.
782 @return Return the value been set.
789 IN UINTN TokenNumber
,
795 ASSERT (Guid
!= NULL
);
797 Status
= mPcd
->SetBoolEx (Guid
, TokenNumber
, Value
);
799 ASSERT_EFI_ERROR (Status
);
807 When the token specified by TokenNumber and Guid is set,
808 then notification function specified by NotificationFunction is called.
809 If Guid is NULL, then the default token space is used.
810 If NotificationFunction is NULL, then ASSERT().
811 If fail to set callback function, then ASSERT_EFI_ERROR().
813 @param[in] Guid Pointer to a 128-bit unique value that designates which
814 namespace to set a value from. If NULL, then the default
816 @param[in] TokenNumber The PCD token number to monitor.
817 @param[in] NotificationFunction The function to call when the token
818 specified by Guid and TokenNumber is set.
822 LibPcdCallbackOnSet (
823 IN CONST GUID
*Guid
, OPTIONAL
824 IN UINTN TokenNumber
,
825 IN PCD_CALLBACK NotificationFunction
830 ASSERT (NotificationFunction
!= NULL
);
832 Status
= mPcd
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
834 ASSERT_EFI_ERROR (Status
);
842 Disable a notification function that was established with LibPcdCallbackonSet().
843 If NotificationFunction is NULL, then ASSERT().
844 If fail to cancel callback function, then ASSERT_EFI_ERROR().
846 @param[in] Guid Specify the GUID token space.
847 @param[in] TokenNumber Specify the token number.
848 @param[in] NotificationFunction The callback function to be unregistered.
853 LibPcdCancelCallback (
854 IN CONST GUID
*Guid
, OPTIONAL
855 IN UINTN TokenNumber
,
856 IN PCD_CALLBACK NotificationFunction
861 ASSERT (NotificationFunction
!= NULL
);
863 Status
= mPcd
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
865 ASSERT_EFI_ERROR (Status
);
873 Retrieves the next PCD token number from the token space specified by Guid.
874 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
875 then the first token number is returned. Otherwise, the token number that
876 follows TokenNumber in the token space is returned. If TokenNumber is the last
877 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
878 is not in the token space specified by Guid, then ASSERT().
879 If Fail to get next token, then ASSERT_EFI_ERROR().
881 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
882 to set a value from. If NULL, then the default token space is used.
883 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
886 @return The next valid token number.
892 IN CONST GUID
*Guid
, OPTIONAL
898 Status
= mPcd
->GetNextToken (Guid
, &TokenNumber
);
900 ASSERT_EFI_ERROR (Status
);
908 Retrieves the next PCD token space from a token space specified by Guid.
909 Guid of NULL is reserved to mark the default local token namespace on the current
910 platform. If Guid is NULL, then the GUID of the first non-local token space of the
911 current platform is returned. If Guid is the last non-local token space,
912 then NULL is returned.
914 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
915 If fail to get next token space, then ASSERT_EFI_ERROR().
917 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
920 @return The next valid token namespace.
925 LibPcdGetNextTokenSpace (
931 Status
= mPcd
->GetNextTokenSpace (&Guid
);
933 ASSERT_EFI_ERROR (Status
);
935 return (GUID
*) Guid
;
940 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
941 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
942 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
943 NULL to indicate that the set operation was not actually performed.
944 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
945 MaximumDatumSize and NULL must be returned.
947 If PatchVariable is NULL, then ASSERT().
948 If SizeOfBuffer is NULL, then ASSERT().
949 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
951 @param[in] PatchVariable A pointer to the global variable in a module that is
952 the target of the set operation.
953 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
954 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
955 In out, returns actual size of buffer is set.
956 @param[in] Buffer A pointer to the buffer to used to set the target variable.
958 @return Return the pinter to the buffer been set.
959 @retval NULL If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set
960 to MaximumDatumSize and NULL must be returned.
965 IN VOID
*PatchVariable
,
966 IN UINTN MaximumDatumSize
,
967 IN OUT UINTN
*SizeOfBuffer
,
968 IN CONST VOID
*Buffer
971 ASSERT (PatchVariable
!= NULL
);
972 ASSERT (SizeOfBuffer
!= NULL
);
974 if (*SizeOfBuffer
> 0) {
975 ASSERT (Buffer
!= NULL
);
978 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
979 (*SizeOfBuffer
== MAX_ADDRESS
)) {
980 *SizeOfBuffer
= MaximumDatumSize
;
984 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
986 return (VOID
*) Buffer
;