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/PeiServicesTablePointerLib.h>
27 #include <Library/BaseMemoryLib.h>
30 The constructor function retrieve the PCD_PPI pointer.
34 @retval PCD_PPI * The pointer to the PCD_PPI.
46 Status
= PeiServicesLocatePpi (&gPcdPpiGuid
, 0, NULL
, (VOID
**)&PcdPpi
);
47 ASSERT_EFI_ERROR (Status
);
55 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
57 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
58 set values associated with a PCD token.
60 @retval SKU_ID Return the SKU ID that just be set.
70 ASSERT (SkuId
< 0x100);
72 GetPcdPpiPtr()->SetSku (SkuId
);;
80 Returns the 8-bit value for the token specified by TokenNumber.
82 @param[in] The PCD token number to retrieve a current value for.
84 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
95 PcdPpi
= GetPcdPpiPtr ();
97 return PcdPpi
->Get8 (TokenNumber
);
103 Returns the 16-bit value for the token specified by TokenNumber.
105 @param[in] The PCD token number to retrieve a current value for.
107 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
118 PcdPpi
= GetPcdPpiPtr ();
120 return PcdPpi
->Get16 (TokenNumber
);
126 Returns the 32-bit value for the token specified by TokenNumber.
128 @param[in] TokenNumber The PCD token number to retrieve a current value for.
130 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
141 PcdPpi
= GetPcdPpiPtr ();
143 return PcdPpi
->Get32 (TokenNumber
);
149 Returns the 64-bit value for the token specified by TokenNumber.
151 @param[in] TokenNumber The PCD token number to retrieve a current value for.
153 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
164 PcdPpi
= GetPcdPpiPtr ();
166 return PcdPpi
->Get64 (TokenNumber
);
172 Returns the pointer to the buffer of the token specified by TokenNumber.
174 @param[in] TokenNumber The PCD token number to retrieve a current value for.
176 @retval VOID* Returns the pointer to the token specified by TokenNumber.
187 PcdPpi
= GetPcdPpiPtr ();
189 return PcdPpi
->GetPtr (TokenNumber
);
195 Returns the Boolean value of the token specified by TokenNumber.
197 @param[in] TokenNumber The PCD token number to retrieve a current value for.
199 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
210 PcdPpi
= GetPcdPpiPtr ();
212 return PcdPpi
->GetBool (TokenNumber
);
218 Returns the size of the token specified by TokenNumber.
220 @param[in] TokenNumber The PCD token number to retrieve a current value for.
222 @retval UINTN Returns the size of the token specified by TokenNumber.
233 PcdPpi
= GetPcdPpiPtr ();
235 return PcdPpi
->GetSize (TokenNumber
);
241 Returns the 8-bit value for the token specified by TokenNumber and Guid.
242 If Guid is NULL, then ASSERT().
244 @param[in] Guid Pointer to a 128-bit unique value that designates
245 which namespace to retrieve a value from.
246 @param[in] TokenNumber The PCD token number to retrieve a current value for.
248 @retval UINT8 Return the UINT8.
260 ASSERT (Guid
!= NULL
);
262 PcdPpi
= GetPcdPpiPtr ();
264 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
270 Returns the 16-bit value for the token specified by TokenNumber and Guid.
271 If Guid is NULL, then ASSERT().
273 @param[in] Guid Pointer to a 128-bit unique value that designates
274 which namespace to retrieve a value from.
275 @param[in] TokenNumber The PCD token number to retrieve a current value for.
277 @retval UINT16 Return the UINT16.
289 ASSERT (Guid
!= NULL
);
291 PcdPpi
= GetPcdPpiPtr ();
293 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
299 Returns the 32-bit value for the token specified by TokenNumber and Guid.
300 If Guid is NULL, then ASSERT().
302 @param[in] Guid Pointer to a 128-bit unique value that designates
303 which namespace to retrieve a value from.
304 @param[in] TokenNumber The PCD token number to retrieve a current value for.
306 @retval UINT32 Return the UINT32.
318 ASSERT (Guid
!= NULL
);
320 PcdPpi
= GetPcdPpiPtr ();
322 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
329 Returns the 64-bit value for the token specified by TokenNumber and Guid.
330 If Guid is NULL, then ASSERT().
332 @param[in] Guid Pointer to a 128-bit unique value that designates
333 which namespace to retrieve a value from.
334 @param[in] TokenNumber The PCD token number to retrieve a current value for.
336 @retval UINT64 Return the UINT64.
348 ASSERT (Guid
!= NULL
);
350 PcdPpi
= GetPcdPpiPtr ();
352 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
358 Returns the pointer to the token specified by TokenNumber and Guid.
359 If Guid is NULL, then ASSERT().
361 @param[in] Guid Pointer to a 128-bit unique value that designates
362 which namespace to retrieve a value from.
363 @param[in] TokenNumber The PCD token number to retrieve a current value for.
365 @retval VOID* Return the VOID* pointer.
377 ASSERT (Guid
!= NULL
);
379 PcdPpi
= GetPcdPpiPtr ();
381 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
387 Returns the Boolean value of the token specified by TokenNumber and Guid.
388 If Guid is NULL, then ASSERT().
390 @param[in] Guid Pointer to a 128-bit unique value that designates
391 which namespace to retrieve a value from.
392 @param[in] TokenNumber The PCD token number to retrieve a current value for.
394 @retval BOOLEAN Return the BOOLEAN.
406 ASSERT (Guid
!= NULL
);
408 PcdPpi
= GetPcdPpiPtr ();
410 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
416 Returns the size of the token specified by TokenNumber and Guid.
417 If Guid is NULL, then ASSERT().
419 @param[in] Guid Pointer to a 128-bit unique value that designates
420 which namespace to retrieve a value from.
421 @param[in] TokenNumber The PCD token number to retrieve a current value for.
423 @retval UINTN Return the size.
435 ASSERT (Guid
!= NULL
);
437 PcdPpi
= GetPcdPpiPtr ();
439 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
445 Sets the 8-bit value for the token specified by TokenNumber
446 to the value specified by Value. Value is returned.
448 @param[in] TokenNumber The PCD token number to set a current value for.
449 @param[in] Value The 8-bit value to set.
451 @retval UINT8 Return the value been set.
457 IN UINTN TokenNumber
,
464 PcdPpi
= GetPcdPpiPtr ();
466 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
468 ASSERT_EFI_ERROR (Status
);
476 Sets the 16-bit value for the token specified by TokenNumber
477 to the value specified by Value. Value is returned.
479 @param[in] TokenNumber The PCD token number to set a current value for.
480 @param[in] Value The 16-bit value to set.
482 @retval UINT16 Return the value been set.
488 IN UINTN TokenNumber
,
495 PcdPpi
= GetPcdPpiPtr ();
497 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
499 ASSERT_EFI_ERROR (Status
);
507 Sets the 32-bit value for the token specified by TokenNumber
508 to the value specified by Value. Value is returned.
510 @param[in] TokenNumber The PCD token number to set a current value for.
511 @param[in] Value The 32-bit value to set.
513 @retval UINT32 Return the value been set.
519 IN UINTN TokenNumber
,
526 PcdPpi
= GetPcdPpiPtr ();
528 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
530 ASSERT_EFI_ERROR (Status
);
538 Sets the 64-bit value for the token specified by TokenNumber
539 to the value specified by Value. Value is returned.
541 @param[in] TokenNumber The PCD token number to set a current value for.
542 @param[in] Value The 64-bit value to set.
544 @retval UINT64 Return the value been set.
550 IN UINTN TokenNumber
,
557 PcdPpi
= GetPcdPpiPtr ();
559 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
561 ASSERT_EFI_ERROR (Status
);
569 Sets a buffer for the token specified by TokenNumber to
570 the value specified by Buffer and SizeOfValue. Buffer to
571 be set is returned. The content of the buffer could be
572 overwritten if a Callback on SET is registered with this
575 If SizeOfValue is greater than the maximum
576 size support by TokenNumber, then set SizeOfValue to the
577 maximum size supported by TokenNumber and return NULL to
578 indicate that the set operation was not actually performed.
580 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
582 @param[in] TokenNumber The PCD token number to set a current value for.
583 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
584 @param[in] Value A pointer to the buffer to set.
586 @retval VOID* Return the pointer for the buffer been set.
592 IN UINTN TokenNumber
,
593 IN OUT UINTN
*SizeOfBuffer
,
600 ASSERT (SizeOfBuffer
!= NULL
);
602 if (*SizeOfBuffer
> 0) {
603 ASSERT (Buffer
!= NULL
);
606 PcdPpi
= GetPcdPpiPtr ();
608 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
610 if (EFI_ERROR (Status
)) {
620 Sets the Boolean value for the token specified by TokenNumber
621 to the value specified by Value. Value is returned.
623 @param[in] TokenNumber The PCD token number to set a current value for.
624 @param[in] Value The boolean value to set.
626 @retval BOOLEAN Return the value been set.
632 IN UINTN TokenNumber
,
639 PcdPpi
= GetPcdPpiPtr ();
641 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
643 ASSERT_EFI_ERROR (Status
);
651 Sets the 8-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 8-bit value to set.
660 @retval UINT8 Return the value been set.
667 IN UINTN TokenNumber
,
674 PcdPpi
= GetPcdPpiPtr ();
676 ASSERT (Guid
!= NULL
);
678 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
680 ASSERT_EFI_ERROR (Status
);
688 Sets the 16-bit value for the token specified by TokenNumber and
689 Guid to the value specified by Value. Value is returned.
690 If Guid is NULL, then ASSERT().
692 @param[in] Guid Pointer to a 128-bit unique value that
693 designates which namespace to set a value from.
694 @param[in] TokenNumber The PCD token number to set a current value for.
695 @param[in] Value The 16-bit value to set.
697 @retval UINT8 Return the value been set.
704 IN UINTN TokenNumber
,
711 PcdPpi
= GetPcdPpiPtr ();
713 ASSERT (Guid
!= NULL
);
714 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
716 ASSERT_EFI_ERROR (Status
);
724 Sets the 32-bit value for the token specified by TokenNumber and
725 Guid to the value specified by Value. Value is returned.
726 If Guid is NULL, then ASSERT().
728 @param[in] Guid Pointer to a 128-bit unique value that
729 designates which namespace to set a value from.
730 @param[in] TokenNumber The PCD token number to set a current value for.
731 @param[in] Value The 32-bit value to set.
733 @retval UINT32 Return the value been set.
740 IN UINTN TokenNumber
,
746 ASSERT (Guid
!= NULL
);
747 PcdPpi
= GetPcdPpiPtr ();
750 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
752 ASSERT_EFI_ERROR (Status
);
760 Sets the 64-bit value for the token specified by TokenNumber and
761 Guid to the value specified by Value. Value is returned.
762 If Guid is NULL, then ASSERT().
764 @param[in] Guid Pointer to a 128-bit unique value that
765 designates which namespace to set a value from.
766 @param[in] TokenNumber The PCD token number to set a current value for.
767 @param[in] Value The 64-bit value to set.
769 @retval UINT64 Return the value been set.
776 IN UINTN TokenNumber
,
782 ASSERT (Guid
!= NULL
);
783 PcdPpi
= GetPcdPpiPtr ();
786 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
788 ASSERT_EFI_ERROR (Status
);
796 Sets a buffer for the token specified by TokenNumber to the value specified by
797 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
798 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
799 supported by TokenNumber and return NULL to indicate that the set operation
800 was not actually performed.
802 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
804 @param[in] Guid Pointer to a 128-bit unique value that
805 designates which namespace to set a value from.
806 @param[in] TokenNumber The PCD token number to set a current value for.
807 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
808 @param[in] Buffer A pointer to the buffer to set.
810 @retval VOID * Return the pinter to the buffer been set.
817 IN UINTN TokenNumber
,
818 IN OUT UINTN
*SizeOfBuffer
,
824 ASSERT (SizeOfBuffer
!= NULL
);
825 if (*SizeOfBuffer
> 0) {
826 ASSERT (Buffer
!= NULL
);
828 ASSERT (Guid
!= NULL
);
829 PcdPpi
= GetPcdPpiPtr ();
831 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
833 if (EFI_ERROR (Status
)) {
843 Sets the Boolean value for the token specified by TokenNumber and
844 Guid to the value specified by Value. Value is returned.
845 If Guid is NULL, then ASSERT().
847 @param[in] Guid Pointer to a 128-bit unique value that
848 designates which namespace to set a value from.
849 @param[in] TokenNumber The PCD token number to set a current value for.
850 @param[in] Value The Boolean value to set.
852 @retval Boolean Return the value been set.
859 IN UINTN TokenNumber
,
866 PcdPpi
= GetPcdPpiPtr ();
868 ASSERT (Guid
!= NULL
);
869 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
871 ASSERT_EFI_ERROR (Status
);
879 When the token specified by TokenNumber and Guid is set,
880 then notification function specified by NotificationFunction is called.
881 If Guid is NULL, then the default token space is used.
882 If NotificationFunction is NULL, then ASSERT().
884 @param[in] Guid Pointer to a 128-bit unique value that designates which
885 namespace to set a value from. If NULL, then the default
887 @param[in] TokenNumber The PCD token number to monitor.
888 @param[in] NotificationFunction The function to call when the token
889 specified by Guid and TokenNumber is set.
896 LibPcdCallbackOnSet (
897 IN CONST GUID
*Guid
, OPTIONAL
898 IN UINTN TokenNumber
,
899 IN PCD_CALLBACK NotificationFunction
905 PcdPpi
= GetPcdPpiPtr ();
908 Status
= PcdPpi
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
910 ASSERT_EFI_ERROR (Status
);
918 Disable a notification function that was established with LibPcdCallbackonSet().
919 If NotificationFunction is NULL, then ASSERT().
921 @param[in] Guid Specify the GUID token space.
922 @param[in] TokenNumber Specify the token number.
923 @param[in] NotificationFunction The callback function to be unregistered.
930 LibPcdCancelCallback (
931 IN CONST GUID
*Guid
, OPTIONAL
932 IN UINTN TokenNumber
,
933 IN PCD_CALLBACK NotificationFunction
939 PcdPpi
= GetPcdPpiPtr ();
942 Status
= PcdPpi
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
944 ASSERT_EFI_ERROR (Status
);
952 Retrieves the next PCD token number from the token space specified by Guid.
953 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
954 then the first token number is returned. Otherwise, the token number that
955 follows TokenNumber in the token space is returned. If TokenNumber is the last
956 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
957 is not in the token space specified by Guid, then ASSERT().
959 @param[in] Pointer to a 128-bit unique value that designates which namespace
960 to set a value from. If NULL, then the default token space is used.
961 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
964 @retval UINTN The next valid token number.
970 IN CONST GUID
*Guid
, OPTIONAL
977 PcdPpi
= GetPcdPpiPtr ();
980 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
982 ASSERT_EFI_ERROR (Status
);
989 Retrieves the next PCD token space from a token space specified by Guid.
990 Guid of NULL is reserved to mark the default local token namespace on the current
991 platform. If Guid is NULL, then the GUID of the first non-local token space of the
992 current platform is returned. If Guid is the last non-local token space,
993 then NULL is returned.
995 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
999 @param[in] Pointer to a 128-bit unique value that designates from which namespace
1000 to start the search.
1002 @retval CONST GUID * The next valid token namespace.
1007 LibPcdGetNextTokenSpace (
1014 PcdPpi
= GetPcdPpiPtr ();
1017 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1019 ASSERT_EFI_ERROR (Status
);
1021 return (GUID
*)Guid
;
1027 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1028 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1029 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1030 NULL to indicate that the set operation was not actually performed.
1031 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1032 MaximumDatumSize and NULL must be returned.
1034 If PatchVariable is NULL, then ASSERT().
1035 If SizeOfValue is NULL, then ASSERT().
1036 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1038 @param[in] PatchVariable A pointer to the global variable in a module that is
1039 the target of the set operation.
1040 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1041 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1042 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1048 IN VOID
*PatchVariable
,
1049 IN UINTN MaximumDatumSize
,
1050 IN OUT UINTN
*SizeOfBuffer
,
1051 IN CONST VOID
*Buffer
1054 ASSERT (PatchVariable
!= NULL
);
1055 ASSERT (SizeOfBuffer
!= NULL
);
1057 if (*SizeOfBuffer
> 0) {
1058 ASSERT (Buffer
!= NULL
);
1061 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1062 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1063 *SizeOfBuffer
= MaximumDatumSize
;
1067 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1069 return (VOID
*) Buffer
;