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.
14 Module Name: PeiPcdLib.c
21 The constructor function retrieve the PCD_PPI pointer.
25 @retval PCD_PPI * The pointer to the PCD_PPI.
35 EFI_PEI_SERVICES
**PeiServices
;
38 PeiServices
= GetPeiServicesTablePointer ();
40 Status
= (**PeiServices
).LocatePpi (
48 ASSERT_EFI_ERROR (Status
);
56 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
58 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
59 set values associated with a PCD token.
61 @retval SKU_ID Return the SKU ID that just be set.
71 ASSERT (SkuId
< 0x100);
73 GetPcdPpiPtr()->SetSku (SkuId
);;
81 Returns the 8-bit value for the token specified by TokenNumber.
83 @param[in] The PCD token number to retrieve a current value for.
85 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
96 PcdPpi
= GetPcdPpiPtr ();
98 return PcdPpi
->Get8 (TokenNumber
);
104 Returns the 16-bit value for the token specified by TokenNumber.
106 @param[in] The PCD token number to retrieve a current value for.
108 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
119 PcdPpi
= GetPcdPpiPtr ();
121 return PcdPpi
->Get16 (TokenNumber
);
127 Returns the 32-bit value for the token specified by TokenNumber.
129 @param[in] TokenNumber The PCD token number to retrieve a current value for.
131 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
142 PcdPpi
= GetPcdPpiPtr ();
144 return PcdPpi
->Get32 (TokenNumber
);
150 Returns the 64-bit value for the token specified by TokenNumber.
152 @param[in] TokenNumber The PCD token number to retrieve a current value for.
154 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
165 PcdPpi
= GetPcdPpiPtr ();
167 return PcdPpi
->Get64 (TokenNumber
);
173 Returns the pointer to the buffer of the token specified by TokenNumber.
175 @param[in] TokenNumber The PCD token number to retrieve a current value for.
177 @retval VOID* Returns the pointer to the token specified by TokenNumber.
188 PcdPpi
= GetPcdPpiPtr ();
190 return PcdPpi
->GetPtr (TokenNumber
);
196 Returns the Boolean value of the token specified by TokenNumber.
198 @param[in] TokenNumber The PCD token number to retrieve a current value for.
200 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
211 PcdPpi
= GetPcdPpiPtr ();
213 return PcdPpi
->GetBool (TokenNumber
);
219 Returns the size of the token specified by TokenNumber.
221 @param[in] TokenNumber The PCD token number to retrieve a current value for.
223 @retval UINTN Returns the size of the token specified by TokenNumber.
234 PcdPpi
= GetPcdPpiPtr ();
236 return PcdPpi
->GetSize (TokenNumber
);
242 Returns the 8-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 @retval UINT8 Return the UINT8.
261 ASSERT (Guid
!= NULL
);
263 PcdPpi
= GetPcdPpiPtr ();
265 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
271 Returns the 16-bit value for the token specified by TokenNumber and Guid.
272 If Guid is NULL, then ASSERT().
274 @param[in] Guid Pointer to a 128-bit unique value that designates
275 which namespace to retrieve a value from.
276 @param[in] TokenNumber The PCD token number to retrieve a current value for.
278 @retval UINT16 Return the UINT16.
290 ASSERT (Guid
!= NULL
);
292 PcdPpi
= GetPcdPpiPtr ();
294 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
300 Returns the 32-bit value for the token specified by TokenNumber and Guid.
301 If Guid is NULL, then ASSERT().
303 @param[in] Guid Pointer to a 128-bit unique value that designates
304 which namespace to retrieve a value from.
305 @param[in] TokenNumber The PCD token number to retrieve a current value for.
307 @retval UINT32 Return the UINT32.
319 ASSERT (Guid
!= NULL
);
321 PcdPpi
= GetPcdPpiPtr ();
323 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
330 Returns the 64-bit value for the token specified by TokenNumber and Guid.
331 If Guid is NULL, then ASSERT().
333 @param[in] Guid Pointer to a 128-bit unique value that designates
334 which namespace to retrieve a value from.
335 @param[in] TokenNumber The PCD token number to retrieve a current value for.
337 @retval UINT64 Return the UINT64.
349 ASSERT (Guid
!= NULL
);
351 PcdPpi
= GetPcdPpiPtr ();
353 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
359 Returns the pointer to the token specified by TokenNumber and Guid.
360 If Guid is NULL, then ASSERT().
362 @param[in] Guid Pointer to a 128-bit unique value that designates
363 which namespace to retrieve a value from.
364 @param[in] TokenNumber The PCD token number to retrieve a current value for.
366 @retval VOID* Return the VOID* pointer.
378 ASSERT (Guid
!= NULL
);
380 PcdPpi
= GetPcdPpiPtr ();
382 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
388 Returns the Boolean value of the token specified by TokenNumber and Guid.
389 If Guid is NULL, then ASSERT().
391 @param[in] Guid Pointer to a 128-bit unique value that designates
392 which namespace to retrieve a value from.
393 @param[in] TokenNumber The PCD token number to retrieve a current value for.
395 @retval BOOLEAN Return the BOOLEAN.
407 ASSERT (Guid
!= NULL
);
409 PcdPpi
= GetPcdPpiPtr ();
411 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
417 Returns the size of the token specified by TokenNumber and Guid.
418 If Guid is NULL, then ASSERT().
420 @param[in] Guid Pointer to a 128-bit unique value that designates
421 which namespace to retrieve a value from.
422 @param[in] TokenNumber The PCD token number to retrieve a current value for.
424 @retval UINTN Return the size.
436 ASSERT (Guid
!= NULL
);
438 PcdPpi
= GetPcdPpiPtr ();
440 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
446 Sets the 8-bit value for the token specified by TokenNumber
447 to the value specified by Value. Value is returned.
449 @param[in] TokenNumber The PCD token number to set a current value for.
450 @param[in] Value The 8-bit value to set.
452 @retval UINT8 Return the value been set.
458 IN UINTN TokenNumber
,
465 PcdPpi
= GetPcdPpiPtr ();
467 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
469 ASSERT_EFI_ERROR (Status
);
477 Sets the 16-bit value for the token specified by TokenNumber
478 to the value specified by Value. Value is returned.
480 @param[in] TokenNumber The PCD token number to set a current value for.
481 @param[in] Value The 16-bit value to set.
483 @retval UINT16 Return the value been set.
489 IN UINTN TokenNumber
,
496 PcdPpi
= GetPcdPpiPtr ();
498 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
500 ASSERT_EFI_ERROR (Status
);
508 Sets the 32-bit value for the token specified by TokenNumber
509 to the value specified by Value. Value is returned.
511 @param[in] TokenNumber The PCD token number to set a current value for.
512 @param[in] Value The 32-bit value to set.
514 @retval UINT32 Return the value been set.
520 IN UINTN TokenNumber
,
527 PcdPpi
= GetPcdPpiPtr ();
529 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
531 ASSERT_EFI_ERROR (Status
);
539 Sets the 64-bit value for the token specified by TokenNumber
540 to the value specified by Value. Value is returned.
542 @param[in] TokenNumber The PCD token number to set a current value for.
543 @param[in] Value The 64-bit value to set.
545 @retval UINT64 Return the value been set.
551 IN UINTN TokenNumber
,
558 PcdPpi
= GetPcdPpiPtr ();
560 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
562 ASSERT_EFI_ERROR (Status
);
570 Sets a buffer for the token specified by TokenNumber to
571 the value specified by Buffer and SizeOfValue. Buffer to
572 be set is returned. The content of the buffer could be
573 overwritten if a Callback on SET is registered with this
576 If SizeOfValue is greater than the maximum
577 size support by TokenNumber, then set SizeOfValue to the
578 maximum size supported by TokenNumber and return NULL to
579 indicate that the set operation was not actually performed.
581 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
583 @param[in] TokenNumber The PCD token number to set a current value for.
584 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
585 @param[in] Value A pointer to the buffer to set.
587 @retval VOID* Return the pointer for the buffer been set.
593 IN UINTN TokenNumber
,
594 IN OUT UINTN
*SizeOfBuffer
,
601 ASSERT (SizeOfBuffer
!= NULL
);
603 if (*SizeOfBuffer
> 0) {
604 ASSERT (Buffer
!= NULL
);
607 PcdPpi
= GetPcdPpiPtr ();
609 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
611 if (EFI_ERROR (Status
)) {
621 Sets the Boolean value for the token specified by TokenNumber
622 to the value specified by Value. Value is returned.
624 @param[in] TokenNumber The PCD token number to set a current value for.
625 @param[in] Value The boolean value to set.
627 @retval BOOLEAN Return the value been set.
633 IN UINTN TokenNumber
,
640 PcdPpi
= GetPcdPpiPtr ();
642 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
644 ASSERT_EFI_ERROR (Status
);
652 Sets the 8-bit value for the token specified by TokenNumber and
653 Guid to the value specified by Value. Value is returned.
654 If Guid is NULL, then ASSERT().
656 @param[in] Guid Pointer to a 128-bit unique value that
657 designates which namespace to set a value from.
658 @param[in] TokenNumber The PCD token number to set a current value for.
659 @param[in] Value The 8-bit value to set.
661 @retval UINT8 Return the value been set.
668 IN UINTN TokenNumber
,
675 PcdPpi
= GetPcdPpiPtr ();
677 ASSERT (Guid
!= NULL
);
679 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
681 ASSERT_EFI_ERROR (Status
);
689 Sets the 16-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 16-bit value to set.
698 @retval UINT8 Return the value been set.
705 IN UINTN TokenNumber
,
712 PcdPpi
= GetPcdPpiPtr ();
714 ASSERT (Guid
!= NULL
);
715 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
717 ASSERT_EFI_ERROR (Status
);
725 Sets the 32-bit value for the token specified by TokenNumber and
726 Guid to the value specified by Value. Value is returned.
727 If Guid is NULL, then ASSERT().
729 @param[in] Guid Pointer to a 128-bit unique value that
730 designates which namespace to set a value from.
731 @param[in] TokenNumber The PCD token number to set a current value for.
732 @param[in] Value The 32-bit value to set.
734 @retval UINT32 Return the value been set.
741 IN UINTN TokenNumber
,
747 ASSERT (Guid
!= NULL
);
748 PcdPpi
= GetPcdPpiPtr ();
751 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
753 ASSERT_EFI_ERROR (Status
);
761 Sets the 64-bit value for the token specified by TokenNumber and
762 Guid to the value specified by Value. Value is returned.
763 If Guid is NULL, then ASSERT().
765 @param[in] Guid Pointer to a 128-bit unique value that
766 designates which namespace to set a value from.
767 @param[in] TokenNumber The PCD token number to set a current value for.
768 @param[in] Value The 64-bit value to set.
770 @retval UINT64 Return the value been set.
777 IN UINTN TokenNumber
,
783 ASSERT (Guid
!= NULL
);
784 PcdPpi
= GetPcdPpiPtr ();
787 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
789 ASSERT_EFI_ERROR (Status
);
797 Sets a buffer for the token specified by TokenNumber to the value specified by
798 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
799 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
800 supported by TokenNumber and return NULL to indicate that the set operation
801 was not actually performed.
803 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
805 @param[in] Guid Pointer to a 128-bit unique value that
806 designates which namespace to set a value from.
807 @param[in] TokenNumber The PCD token number to set a current value for.
808 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
809 @param[in] Buffer A pointer to the buffer to set.
811 @retval VOID * Return the pinter to the buffer been set.
818 IN UINTN TokenNumber
,
819 IN OUT UINTN
*SizeOfBuffer
,
825 ASSERT (SizeOfBuffer
!= NULL
);
826 if (*SizeOfBuffer
> 0) {
827 ASSERT (Buffer
!= NULL
);
829 ASSERT (Guid
!= NULL
);
830 PcdPpi
= GetPcdPpiPtr ();
832 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
834 if (EFI_ERROR (Status
)) {
844 Sets the Boolean value for the token specified by TokenNumber and
845 Guid to the value specified by Value. Value is returned.
846 If Guid is NULL, then ASSERT().
848 @param[in] Guid Pointer to a 128-bit unique value that
849 designates which namespace to set a value from.
850 @param[in] TokenNumber The PCD token number to set a current value for.
851 @param[in] Value The Boolean value to set.
853 @retval Boolean Return the value been set.
860 IN UINTN TokenNumber
,
867 PcdPpi
= GetPcdPpiPtr ();
869 ASSERT (Guid
!= NULL
);
870 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
872 ASSERT_EFI_ERROR (Status
);
880 When the token specified by TokenNumber and Guid is set,
881 then notification function specified by NotificationFunction is called.
882 If Guid is NULL, then the default token space is used.
883 If NotificationFunction is NULL, then ASSERT().
885 @param[in] Guid Pointer to a 128-bit unique value that designates which
886 namespace to set a value from. If NULL, then the default
888 @param[in] TokenNumber The PCD token number to monitor.
889 @param[in] NotificationFunction The function to call when the token
890 specified by Guid and TokenNumber is set.
897 LibPcdCallbackOnSet (
898 IN CONST GUID
*Guid
, OPTIONAL
899 IN UINTN TokenNumber
,
900 IN PCD_CALLBACK NotificationFunction
906 PcdPpi
= GetPcdPpiPtr ();
909 Status
= PcdPpi
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
911 ASSERT_EFI_ERROR (Status
);
919 Disable a notification function that was established with LibPcdCallbackonSet().
920 If NotificationFunction is NULL, then ASSERT().
922 @param[in] Guid Specify the GUID token space.
923 @param[in] TokenNumber Specify the token number.
924 @param[in] NotificationFunction The callback function to be unregistered.
931 LibPcdCancelCallback (
932 IN CONST GUID
*Guid
, OPTIONAL
933 IN UINTN TokenNumber
,
934 IN PCD_CALLBACK NotificationFunction
940 PcdPpi
= GetPcdPpiPtr ();
943 Status
= PcdPpi
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
945 ASSERT_EFI_ERROR (Status
);
953 Retrieves the next PCD token number from the token space specified by Guid.
954 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
955 then the first token number is returned. Otherwise, the token number that
956 follows TokenNumber in the token space is returned. If TokenNumber is the last
957 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
958 is not in the token space specified by Guid, then ASSERT().
960 @param[in] Pointer to a 128-bit unique value that designates which namespace
961 to set a value from. If NULL, then the default token space is used.
962 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
965 @retval UINTN The next valid token number.
971 IN CONST GUID
*Guid
, OPTIONAL
978 PcdPpi
= GetPcdPpiPtr ();
981 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
983 ASSERT_EFI_ERROR (Status
);
990 Retrieves the next PCD token space from a token space specified by Guid.
991 Guid of NULL is reserved to mark the default local token namespace on the current
992 platform. If Guid is NULL, then the GUID of the first non-local token space of the
993 current platform is returned. If Guid is the last non-local token space,
994 then NULL is returned.
996 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
1000 @param[in] Pointer to a 128-bit unique value that designates from which namespace
1001 to start the search.
1003 @retval CONST GUID * The next valid token namespace.
1008 LibPcdGetNextTokenSpace (
1015 PcdPpi
= GetPcdPpiPtr ();
1018 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1020 ASSERT_EFI_ERROR (Status
);
1022 return (GUID
*)Guid
;
1028 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1029 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1030 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1031 NULL to indicate that the set operation was not actually performed.
1032 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1033 MaximumDatumSize and NULL must be returned.
1035 If PatchVariable is NULL, then ASSERT().
1036 If SizeOfValue is NULL, then ASSERT().
1037 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1039 @param[in] PatchVariable A pointer to the global variable in a module that is
1040 the target of the set operation.
1041 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1042 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1043 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1049 IN VOID
*PatchVariable
,
1050 IN UINTN MaximumDatumSize
,
1051 IN OUT UINTN
*SizeOfBuffer
,
1052 IN CONST VOID
*Buffer
1055 ASSERT (PatchVariable
!= NULL
);
1056 ASSERT (SizeOfBuffer
!= NULL
);
1058 if (*SizeOfBuffer
> 0) {
1059 ASSERT (Buffer
!= NULL
);
1062 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1063 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1064 *SizeOfBuffer
= MaximumDatumSize
;
1068 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1070 return (VOID
*) Buffer
;