2 Implementation of PcdLib class library for PEI 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.
23 #include <Library/PeiServicesLib.h>
24 #include <Library/PcdLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/BaseMemoryLib.h>
29 Retrieve the PCD_PPI pointer.
31 This function is to locate PCD_PPI PPI via PeiService.
32 If fail to locate PCD_PPI, then ASSERT_EFI_ERROR().
34 @retval PCD_PPI * The pointer to the PCD_PPI.
45 Status
= PeiServicesLocatePpi (&gPcdPpiGuid
, 0, NULL
, (VOID
**)&PcdPpi
);
46 ASSERT_EFI_ERROR (Status
);
52 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
53 If SkuId not less than PCD_MAX_SKU_ID, then ASSERT().
55 @param[in] SkuId System sku id. The SKU value that will be used when the PCD service will retrieve and
58 @return Return the SKU ID that just be set.
68 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
70 GetPcdPpiPointer()->SetSku (SkuId
);
78 Returns the 8-bit value for the token specified by TokenNumber.
80 @param[in] TokenNumber The PCD token number to retrieve a current value for.
82 @return Returns the 8-bit value for the token specified by TokenNumber.
91 return (GetPcdPpiPointer ())->Get8 (TokenNumber
);
97 Returns the 16-bit value for the token specified by TokenNumber.
99 @param[in] TokenNumber The PCD token number to retrieve a current value for.
101 @return Returns the 16-bit value for the token specified by TokenNumber.
110 return (GetPcdPpiPointer ())->Get16 (TokenNumber
);
116 Returns the 32-bit value for the token specified by TokenNumber.
118 @param[in] TokenNumber The PCD token number to retrieve a current value for.
120 @return Returns the 32-bit value for the token specified by TokenNumber.
129 return (GetPcdPpiPointer ())->Get32 (TokenNumber
);
135 Returns the 64-bit value for the token specified by TokenNumber.
137 @param[in] TokenNumber The PCD token number to retrieve a current value for.
139 @return Returns the 64-bit value for the token specified by TokenNumber.
148 return (GetPcdPpiPointer ())->Get64 (TokenNumber
);
154 Returns the pointer to the buffer of the token specified by TokenNumber.
156 @param[in] TokenNumber The PCD token number to retrieve a current value for.
158 @return Returns the pointer to the token specified by TokenNumber.
167 return (GetPcdPpiPointer ())->GetPtr (TokenNumber
);
173 Returns the Boolean value of the token specified by TokenNumber.
175 @param[in] TokenNumber The PCD token number to retrieve a current value for.
177 @return Returns the Boolean value of the token specified by TokenNumber.
186 return (GetPcdPpiPointer ())->GetBool (TokenNumber
);
192 Returns the size of the token specified by TokenNumber.
194 @param[in] TokenNumber The PCD token number to retrieve a current value for.
196 @return Returns the size of the token specified by TokenNumber.
205 return (GetPcdPpiPointer ())->GetSize (TokenNumber
);
211 Returns the 8-bit value for the token specified by TokenNumber and Guid.
212 If Guid is NULL, then ASSERT().
214 @param[in] Guid Pointer to a 128-bit unique value that designates
215 which namespace to retrieve a value from.
216 @param[in] TokenNumber The PCD token number to retrieve a current value for.
218 @return Return the UINT8.
228 ASSERT (Guid
!= NULL
);
230 return (GetPcdPpiPointer ())->Get8Ex (Guid
, TokenNumber
);
236 Returns the 16-bit value for the token specified by TokenNumber and Guid.
237 If Guid is NULL, then ASSERT().
239 @param[in] Guid Pointer to a 128-bit unique value that designates
240 which namespace to retrieve a value from.
241 @param[in] TokenNumber The PCD token number to retrieve a current value for.
243 @return Return the UINT16.
254 ASSERT (Guid
!= NULL
);
256 return (GetPcdPpiPointer ())->Get16Ex (Guid
, TokenNumber
);
262 Returns the 32-bit value for the token specified by TokenNumber and Guid.
263 If Guid is NULL, then ASSERT().
265 @param[in] Guid Pointer to a 128-bit unique value that designates
266 which namespace to retrieve a value from.
267 @param[in] TokenNumber The PCD token number to retrieve a current value for.
269 @return Return the UINT32.
279 ASSERT (Guid
!= NULL
);
281 return (GetPcdPpiPointer ())->Get32Ex (Guid
, TokenNumber
);
288 Returns the 64-bit value for the token specified by TokenNumber and Guid.
289 If Guid is NULL, then ASSERT().
291 @param[in] Guid Pointer to a 128-bit unique value that designates
292 which namespace to retrieve a value from.
293 @param[in] TokenNumber The PCD token number to retrieve a current value for.
295 @return Return the UINT64.
305 ASSERT (Guid
!= NULL
);
306 return (GetPcdPpiPointer ())->Get64Ex (Guid
, TokenNumber
);
312 Returns the pointer to the token specified by TokenNumber and Guid.
313 If Guid is NULL, then ASSERT().
315 @param[in] Guid Pointer to a 128-bit unique value that designates
316 which namespace to retrieve a value from.
317 @param[in] TokenNumber The PCD token number to retrieve a current value for.
319 @return Return the VOID* pointer.
329 ASSERT (Guid
!= NULL
);
331 return (GetPcdPpiPointer ())->GetPtrEx (Guid
, TokenNumber
);
337 Returns the Boolean value of the token specified by TokenNumber and Guid.
338 If Guid is NULL, then ASSERT().
340 @param[in] Guid Pointer to a 128-bit unique value that designates
341 which namespace to retrieve a value from.
342 @param[in] TokenNumber The PCD token number to retrieve a current value for.
344 @return Return the BOOLEAN.
354 ASSERT (Guid
!= NULL
);
355 return (GetPcdPpiPointer ())->GetBoolEx (Guid
, TokenNumber
);
361 Returns the size of the token specified by TokenNumber and Guid.
362 If Guid is NULL, then ASSERT().
364 @param[in] Guid Pointer to a 128-bit unique value that designates
365 which namespace to retrieve a value from.
366 @param[in] TokenNumber The PCD token number to retrieve a current value for.
368 @return Return the size.
378 ASSERT (Guid
!= NULL
);
379 return (GetPcdPpiPointer ())->GetSizeEx (Guid
, TokenNumber
);
385 Sets the 8-bit value for the token specified by TokenNumber
386 to the value specified by Value. Value is returned.
387 If fail to set pcd value, then ASSERT_EFI_ERROR().
389 @param[in] TokenNumber The PCD token number to set a current value for.
390 @param[in] Value The 8-bit value to set.
392 @return Return the value been set.
398 IN UINTN TokenNumber
,
404 Status
= (GetPcdPpiPointer ())->Set8 (TokenNumber
, Value
);
406 ASSERT_EFI_ERROR (Status
);
414 Sets the 16-bit value for the token specified by TokenNumber
415 to the value specified by Value. Value is returned.
416 If fail to set pcd value, then ASSERT_EFI_ERROR().
418 @param[in] TokenNumber The PCD token number to set a current value for.
419 @param[in] Value The 16-bit value to set.
421 @return Return the value been set.
427 IN UINTN TokenNumber
,
433 Status
= (GetPcdPpiPointer ())->Set16 (TokenNumber
, Value
);
435 ASSERT_EFI_ERROR (Status
);
443 Sets the 32-bit value for the token specified by TokenNumber
444 to the value specified by Value. Value is returned.
445 If fail to set pcd value, then ASSERT_EFI_ERROR().
447 @param[in] TokenNumber The PCD token number to set a current value for.
448 @param[in] Value The 32-bit value to set.
450 @return Return the value been set.
456 IN UINTN TokenNumber
,
462 Status
= (GetPcdPpiPointer ())->Set32 (TokenNumber
, Value
);
464 ASSERT_EFI_ERROR (Status
);
472 Sets the 64-bit value for the token specified by TokenNumber
473 to the value specified by Value. Value is returned.
474 If fail to set pcd value, then ASSERT_EFI_ERROR().
476 @param[in] TokenNumber The PCD token number to set a current value for.
477 @param[in] Value The 64-bit value to set.
479 @return Return the value been set.
485 IN UINTN TokenNumber
,
491 Status
= (GetPcdPpiPointer ())->Set64 (TokenNumber
, Value
);
493 ASSERT_EFI_ERROR (Status
);
501 Sets a buffer for the token specified by TokenNumber to
502 the value specified by Buffer and SizeOfBuffer. Buffer to
503 be set is returned. The content of the buffer could be
504 overwritten if a Callback on SET is registered with this
507 If SizeOfBuffer is greater than the maximum
508 size support by TokenNumber, then set SizeOfBuffer to the
509 maximum size supported by TokenNumber and return NULL to
510 indicate that the set operation was not actually performed.
512 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
514 @param[in] TokenNumber The PCD token number to set a current value for.
515 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
516 In out, returns actual size of buffer is set.
517 @param[in] Buffer A pointer to the buffer to set.
519 @return Return the pointer for the buffer been set.
525 IN UINTN TokenNumber
,
526 IN OUT UINTN
*SizeOfBuffer
,
532 ASSERT (SizeOfBuffer
!= NULL
);
534 if (*SizeOfBuffer
> 0) {
535 ASSERT (Buffer
!= NULL
);
538 Status
= (GetPcdPpiPointer ())->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
540 if (EFI_ERROR (Status
)) {
550 Sets the Boolean value for the token specified by TokenNumber
551 to the value specified by Value. Value is returned.
552 If fail to set pcd value, then ASSERT_EFI_ERROR().
554 @param[in] TokenNumber The PCD token number to set a current value for.
555 @param[in] Value The boolean value to set.
557 @return Return the value been set.
563 IN UINTN TokenNumber
,
569 Status
= (GetPcdPpiPointer ())->SetBool (TokenNumber
, Value
);
571 ASSERT_EFI_ERROR (Status
);
579 Sets the 8-bit value for the token specified by TokenNumber and
580 Guid to the value specified by Value. Value is returned.
581 If Guid is NULL, then ASSERT().
582 If fail to set pcd value, then ASSERT_EFI_ERROR().
584 @param[in] Guid Pointer to a 128-bit unique value that
585 designates which namespace to set a value from.
586 @param[in] TokenNumber The PCD token number to set a current value for.
587 @param[in] Value The 8-bit value to set.
589 @return Return the value been set.
596 IN UINTN TokenNumber
,
602 ASSERT (Guid
!= NULL
);
604 Status
= (GetPcdPpiPointer ())->Set8Ex (Guid
, TokenNumber
, Value
);
606 ASSERT_EFI_ERROR (Status
);
614 Sets the 16-bit value for the token specified by TokenNumber and
615 Guid to the value specified by Value. Value is returned.
616 If Guid is NULL, then ASSERT().
617 If fail to set pcd value, then ASSERT_EFI_ERROR().
619 @param[in] Guid Pointer to a 128-bit unique value that
620 designates which namespace to set a value from.
621 @param[in] TokenNumber The PCD token number to set a current value for.
622 @param[in] Value The 16-bit value to set.
624 @return Return the value been set.
631 IN UINTN TokenNumber
,
636 ASSERT (Guid
!= NULL
);
637 Status
= (GetPcdPpiPointer ())->Set16Ex (Guid
, TokenNumber
, Value
);
639 ASSERT_EFI_ERROR (Status
);
647 Sets the 32-bit value for the token specified by TokenNumber and
648 Guid to the value specified by Value. Value is returned.
649 If Guid is NULL, then ASSERT().
650 If fail to set pcd value, then ASSERT_EFI_ERROR().
652 @param[in] Guid Pointer to a 128-bit unique value that
653 designates which namespace to set a value from.
654 @param[in] TokenNumber The PCD token number to set a current value for.
655 @param[in] Value The 32-bit value to set.
657 @return Return the value been set.
664 IN UINTN TokenNumber
,
670 ASSERT (Guid
!= NULL
);
672 Status
= (GetPcdPpiPointer ())->Set32Ex (Guid
, TokenNumber
, Value
);
674 ASSERT_EFI_ERROR (Status
);
682 Sets the 64-bit value for the token specified by TokenNumber and
683 Guid to the value specified by Value. Value is returned.
684 If Guid is NULL, then ASSERT().
685 If fail to set pcd value, then ASSERT_EFI_ERROR().
687 @param[in] Guid Pointer to a 128-bit unique value that
688 designates which namespace to set a value from.
689 @param[in] TokenNumber The PCD token number to set a current value for.
690 @param[in] Value The 64-bit value to set.
692 @return Return the value been set.
699 IN UINTN TokenNumber
,
704 ASSERT (Guid
!= NULL
);
706 Status
= (GetPcdPpiPointer ())->Set64Ex (Guid
, TokenNumber
, Value
);
708 ASSERT_EFI_ERROR (Status
);
716 Sets a buffer for the token specified by TokenNumber to the value specified by
717 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
718 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
719 supported by TokenNumber and return NULL to indicate that the set operation
720 was not actually performed.
722 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
724 @param[in] Guid Pointer to a 128-bit unique value that
725 designates which namespace to set a value from.
726 @param[in] TokenNumber The PCD token number to set a current value for.
727 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
728 In out, returns actual size of buffer is set.
729 @param[in] Buffer A pointer to the buffer to set.
731 @return Return the pinter to the buffer been set.
738 IN UINTN TokenNumber
,
739 IN OUT UINTN
*SizeOfBuffer
,
744 ASSERT (SizeOfBuffer
!= NULL
);
745 if (*SizeOfBuffer
> 0) {
746 ASSERT (Buffer
!= NULL
);
748 ASSERT (Guid
!= NULL
);
750 Status
= (GetPcdPpiPointer ())->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
752 if (EFI_ERROR (Status
)) {
762 Sets the Boolean value for the token specified by TokenNumber and
763 Guid to the value specified by Value. Value is returned.
764 If Guid is NULL, then ASSERT().
765 If fail to set pcd value, then ASSERT_EFI_ERROR().
767 @param[in] Guid Pointer to a 128-bit unique value that
768 designates which namespace to set a value from.
769 @param[in] TokenNumber The PCD token number to set a current value for.
770 @param[in] Value The Boolean value to set.
772 @return Return the value been set.
779 IN UINTN TokenNumber
,
785 ASSERT (Guid
!= NULL
);
786 Status
= (GetPcdPpiPointer ())->SetBoolEx (Guid
, TokenNumber
, Value
);
788 ASSERT_EFI_ERROR (Status
);
796 When the token specified by TokenNumber and Guid is set,
797 then notification function specified by NotificationFunction is called.
798 If Guid is NULL, then the default token space is used.
799 If NotificationFunction is NULL, then ASSERT().
800 If fail to set callback, then ASSERT_EFI_ERROR().
801 @param[in] Guid Pointer to a 128-bit unique value that designates which
802 namespace to set a value from. If NULL, then the default
804 @param[in] TokenNumber The PCD token number to monitor.
805 @param[in] NotificationFunction The function to call when the token
806 specified by Guid and TokenNumber is set.
811 LibPcdCallbackOnSet (
812 IN CONST GUID
*Guid
, OPTIONAL
813 IN UINTN TokenNumber
,
814 IN PCD_CALLBACK NotificationFunction
819 Status
= (GetPcdPpiPointer ())->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
821 ASSERT_EFI_ERROR (Status
);
829 Disable a notification function that was established with LibPcdCallbackonSet().
830 If NotificationFunction is NULL, then ASSERT().
831 If fail to cancel callback, then ASSERT_EFI_ERROR().
833 @param[in] Guid Specify the GUID token space.
834 @param[in] TokenNumber Specify the token number.
835 @param[in] NotificationFunction The callback function to be unregistered.
840 LibPcdCancelCallback (
841 IN CONST GUID
*Guid
, OPTIONAL
842 IN UINTN TokenNumber
,
843 IN PCD_CALLBACK NotificationFunction
848 Status
= (GetPcdPpiPointer ())->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
850 ASSERT_EFI_ERROR (Status
);
858 Retrieves the next PCD token number from the token space specified by Guid.
859 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
860 then the first token number is returned. Otherwise, the token number that
861 follows TokenNumber in the token space is returned. If TokenNumber is the last
862 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
863 is not in the token space specified by Guid, then ASSERT().
864 If fail to get token in given token space, then ASSERT_EFI_ERROR().
866 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
867 to set a value from. If NULL, then the default token space is used.
868 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
871 @return The next valid token number.
877 IN CONST GUID
*Guid
, OPTIONAL
883 Status
= (GetPcdPpiPointer ())->GetNextToken (Guid
, &TokenNumber
);
885 ASSERT_EFI_ERROR (Status
);
892 Retrieves the next PCD token space from a token space specified by Guid.
893 Guid of NULL is reserved to mark the default local token namespace on the current
894 platform. If Guid is NULL, then the GUID of the first non-local token space of the
895 current platform is returned. If Guid is the last non-local token space,
896 then NULL is returned.
897 If fail to get next token space, then ASSERT_EFI_ERROR().
899 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
903 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
906 @return The next valid token namespace.
911 LibPcdGetNextTokenSpace (
917 Status
= (GetPcdPpiPointer ())->GetNextTokenSpace (&Guid
);
919 ASSERT_EFI_ERROR (Status
);
927 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
928 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
929 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
930 NULL to indicate that the set operation was not actually performed.
931 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
932 MaximumDatumSize and NULL must be returned.
934 If PatchVariable is NULL, then ASSERT().
935 If SizeOfBuffer is NULL, then ASSERT().
936 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
938 @param[in] PatchVariable A pointer to the global variable in a module that is
939 the target of the set operation.
940 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
941 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
942 In out, returns actual size of buffer is set.
943 @param[in] Buffer A pointer to the buffer to used to set the target variable.
945 @return Return the pinter to the buffer been set.
951 IN VOID
*PatchVariable
,
952 IN UINTN MaximumDatumSize
,
953 IN OUT UINTN
*SizeOfBuffer
,
954 IN CONST VOID
*Buffer
957 ASSERT (PatchVariable
!= NULL
);
958 ASSERT (SizeOfBuffer
!= NULL
);
960 if (*SizeOfBuffer
> 0) {
961 ASSERT (Buffer
!= NULL
);
964 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
965 (*SizeOfBuffer
== MAX_ADDRESS
)) {
966 *SizeOfBuffer
= MaximumDatumSize
;
970 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
972 return (VOID
*) Buffer
;