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 PcdPpi
= GetPcdPpiPtr ();
263 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
269 Returns the 16-bit value for the token specified by TokenNumber and Guid.
270 If Guid is NULL, then ASSERT().
272 @param[in] Guid Pointer to a 128-bit unique value that designates
273 which namespace to retrieve a value from.
274 @param[in] TokenNumber The PCD token number to retrieve a current value for.
276 @retval UINT16 Return the UINT16.
288 PcdPpi
= GetPcdPpiPtr ();
290 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
296 Returns the 32-bit value for the token specified by TokenNumber and Guid.
297 If Guid is NULL, then ASSERT().
299 @param[in] Guid Pointer to a 128-bit unique value that designates
300 which namespace to retrieve a value from.
301 @param[in] TokenNumber The PCD token number to retrieve a current value for.
303 @retval UINT32 Return the UINT32.
315 PcdPpi
= GetPcdPpiPtr ();
317 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
324 Returns the 64-bit value for the token specified by TokenNumber and Guid.
325 If Guid is NULL, then ASSERT().
327 @param[in] Guid Pointer to a 128-bit unique value that designates
328 which namespace to retrieve a value from.
329 @param[in] TokenNumber The PCD token number to retrieve a current value for.
331 @retval UINT64 Return the UINT64.
343 PcdPpi
= GetPcdPpiPtr ();
345 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
351 Returns the pointer to 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 VOID* Return the VOID* pointer.
370 PcdPpi
= GetPcdPpiPtr ();
372 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
378 Returns the Boolean value of the token specified by TokenNumber and Guid.
379 If Guid is NULL, then ASSERT().
381 @param[in] Guid Pointer to a 128-bit unique value that designates
382 which namespace to retrieve a value from.
383 @param[in] TokenNumber The PCD token number to retrieve a current value for.
385 @retval BOOLEAN Return the BOOLEAN.
397 PcdPpi
= GetPcdPpiPtr ();
399 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
405 Returns the size of the token specified by TokenNumber and Guid.
406 If Guid is NULL, then ASSERT().
408 @param[in] Guid Pointer to a 128-bit unique value that designates
409 which namespace to retrieve a value from.
410 @param[in] TokenNumber The PCD token number to retrieve a current value for.
412 @retval UINTN Return the size.
424 PcdPpi
= GetPcdPpiPtr ();
426 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
432 Sets the 8-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 8-bit value to set.
438 @retval UINT8 Return the value been set.
444 IN UINTN TokenNumber
,
451 PcdPpi
= GetPcdPpiPtr ();
454 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
456 ASSERT_EFI_ERROR (Status
);
464 Sets the 16-bit value for the token specified by TokenNumber
465 to the value specified by Value. Value is returned.
467 @param[in] TokenNumber The PCD token number to set a current value for.
468 @param[in] Value The 16-bit value to set.
470 @retval UINT16 Return the value been set.
476 IN UINTN TokenNumber
,
483 PcdPpi
= GetPcdPpiPtr ();
486 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
488 ASSERT_EFI_ERROR (Status
);
496 Sets the 32-bit value for the token specified by TokenNumber
497 to the value specified by Value. Value is returned.
499 @param[in] TokenNumber The PCD token number to set a current value for.
500 @param[in] Value The 32-bit value to set.
502 @retval UINT32 Return the value been set.
508 IN UINTN TokenNumber
,
515 PcdPpi
= GetPcdPpiPtr ();
517 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
519 ASSERT_EFI_ERROR (Status
);
527 Sets the 64-bit value for the token specified by TokenNumber
528 to the value specified by Value. Value is returned.
530 @param[in] TokenNumber The PCD token number to set a current value for.
531 @param[in] Value The 64-bit value to set.
533 @retval UINT64 Return the value been set.
539 IN UINTN TokenNumber
,
546 PcdPpi
= GetPcdPpiPtr ();
549 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
551 ASSERT_EFI_ERROR (Status
);
559 Sets a buffer for the token specified by TokenNumber to
560 the value specified by Buffer and SizeOfValue. Buffer to
561 be set is returned. The content of the buffer could be
562 overwritten if a Callback on SET is registered with this
565 If SizeOfValue is greater than the maximum
566 size support by TokenNumber, then set SizeOfValue to the
567 maximum size supported by TokenNumber and return NULL to
568 indicate that the set operation was not actually performed.
570 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
572 @param[in] TokenNumber The PCD token number to set a current value for.
573 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
574 @param[in] Value A pointer to the buffer to set.
576 @retval VOID* Return the pointer for the buffer been set.
582 IN UINTN TokenNumber
,
583 IN OUT UINTN
*SizeOfBuffer
,
591 ASSERT (SizeOfBuffer
!= NULL
);
593 if (*SizeOfBuffer
> 0) {
594 ASSERT (Buffer
!= NULL
);
597 PcdPpi
= GetPcdPpiPtr ();
599 Size
= LibPcdGetSize (TokenNumber
);
601 if (*SizeOfBuffer
> Size
) {
602 *SizeOfBuffer
= Size
;
606 Status
= PcdPpi
->SetPtr (TokenNumber
, *SizeOfBuffer
, Buffer
);
608 ASSERT_EFI_ERROR (Status
);
616 Sets the Boolean value for the token specified by TokenNumber
617 to the value specified by Value. Value is returned.
619 @param[in] TokenNumber The PCD token number to set a current value for.
620 @param[in] Value The boolean value to set.
622 @retval BOOLEAN Return the value been set.
628 IN UINTN TokenNumber
,
635 PcdPpi
= GetPcdPpiPtr ();
638 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
640 ASSERT_EFI_ERROR (Status
);
648 Sets the 8-bit value for the token specified by TokenNumber and
649 Guid to the value specified by Value. Value is returned.
650 If Guid is NULL, then ASSERT().
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 8-bit value to set.
657 @retval UINT8 Return the value been set.
664 IN UINTN TokenNumber
,
671 PcdPpi
= GetPcdPpiPtr ();
674 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
676 ASSERT_EFI_ERROR (Status
);
684 Sets the 16-bit value for the token specified by TokenNumber and
685 Guid to the value specified by Value. Value is returned.
686 If Guid is NULL, then ASSERT().
688 @param[in] Guid Pointer to a 128-bit unique value that
689 designates which namespace to set a value from.
690 @param[in] TokenNumber The PCD token number to set a current value for.
691 @param[in] Value The 16-bit value to set.
693 @retval UINT8 Return the value been set.
700 IN UINTN TokenNumber
,
707 PcdPpi
= GetPcdPpiPtr ();
710 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
712 ASSERT_EFI_ERROR (Status
);
720 Sets the 32-bit value for the token specified by TokenNumber and
721 Guid to the value specified by Value. Value is returned.
722 If Guid 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] Value The 32-bit value to set.
729 @retval UINT32 Return the value been set.
736 IN UINTN TokenNumber
,
743 PcdPpi
= GetPcdPpiPtr ();
746 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
748 ASSERT_EFI_ERROR (Status
);
756 Sets the 64-bit value for the token specified by TokenNumber and
757 Guid to the value specified by Value. Value is returned.
758 If Guid is NULL, then ASSERT().
760 @param[in] Guid Pointer to a 128-bit unique value that
761 designates which namespace to set a value from.
762 @param[in] TokenNumber The PCD token number to set a current value for.
763 @param[in] Value The 64-bit value to set.
765 @retval UINT64 Return the value been set.
772 IN UINTN TokenNumber
,
779 PcdPpi
= GetPcdPpiPtr ();
782 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
784 ASSERT_EFI_ERROR (Status
);
792 Sets a buffer for the token specified by TokenNumber to the value specified by
793 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
794 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
795 supported by TokenNumber and return NULL to indicate that the set operation
796 was not actually performed.
798 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
800 @param[in] Guid Pointer to a 128-bit unique value that
801 designates which namespace to set a value from.
802 @param[in] TokenNumber The PCD token number to set a current value for.
803 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
804 @param[in] Buffer A pointer to the buffer to set.
806 @retval VOID * Return the pinter to the buffer been set.
813 IN UINTN TokenNumber
,
814 IN OUT UINTN
*SizeOfBuffer
,
822 if (*SizeOfBuffer
> 0) {
823 ASSERT (Buffer
!= NULL
);
826 PcdPpi
= GetPcdPpiPtr ();
828 Size
= LibPcdGetExSize (Guid
, TokenNumber
);
829 if (*SizeOfBuffer
> Size
) {
830 *SizeOfBuffer
= Size
;
834 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, *SizeOfBuffer
, Buffer
);
836 ASSERT_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 ();
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 (TokenNumber
, Guid
, 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 (TokenNumber
, Guid
, 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
;