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 // Include common header file for this module.
23 #include "CommonHeader.h"
26 The constructor function retrieve the PCD_PPI pointer.
30 @retval PCD_PPI * The pointer to the PCD_PPI.
41 EFI_PEI_SERVICES
**PeiServices
;
44 PeiServices
= GetPeiServicesTablePointer ();
46 Status
= (**PeiServices
).LocatePpi (
54 ASSERT_EFI_ERROR (Status
);
62 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
64 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
65 set values associated with a PCD token.
67 @retval SKU_ID Return the SKU ID that just be set.
77 ASSERT (SkuId
< 0x100);
79 GetPcdPpiPtr()->SetSku (SkuId
);;
87 Returns the 8-bit value for the token specified by TokenNumber.
89 @param[in] The PCD token number to retrieve a current value for.
91 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
102 PcdPpi
= GetPcdPpiPtr ();
104 return PcdPpi
->Get8 (TokenNumber
);
110 Returns the 16-bit value for the token specified by TokenNumber.
112 @param[in] The PCD token number to retrieve a current value for.
114 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
125 PcdPpi
= GetPcdPpiPtr ();
127 return PcdPpi
->Get16 (TokenNumber
);
133 Returns the 32-bit value for the token specified by TokenNumber.
135 @param[in] TokenNumber The PCD token number to retrieve a current value for.
137 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
148 PcdPpi
= GetPcdPpiPtr ();
150 return PcdPpi
->Get32 (TokenNumber
);
156 Returns the 64-bit value for the token specified by TokenNumber.
158 @param[in] TokenNumber The PCD token number to retrieve a current value for.
160 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
171 PcdPpi
= GetPcdPpiPtr ();
173 return PcdPpi
->Get64 (TokenNumber
);
179 Returns the pointer to the buffer of the token specified by TokenNumber.
181 @param[in] TokenNumber The PCD token number to retrieve a current value for.
183 @retval VOID* Returns the pointer to the token specified by TokenNumber.
194 PcdPpi
= GetPcdPpiPtr ();
196 return PcdPpi
->GetPtr (TokenNumber
);
202 Returns the Boolean value of the token specified by TokenNumber.
204 @param[in] TokenNumber The PCD token number to retrieve a current value for.
206 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
217 PcdPpi
= GetPcdPpiPtr ();
219 return PcdPpi
->GetBool (TokenNumber
);
225 Returns the size of the token specified by TokenNumber.
227 @param[in] TokenNumber The PCD token number to retrieve a current value for.
229 @retval UINTN Returns the size of the token specified by TokenNumber.
240 PcdPpi
= GetPcdPpiPtr ();
242 return PcdPpi
->GetSize (TokenNumber
);
248 Returns the 8-bit value for the token specified by TokenNumber and Guid.
249 If Guid is NULL, then ASSERT().
251 @param[in] Guid Pointer to a 128-bit unique value that designates
252 which namespace to retrieve a value from.
253 @param[in] TokenNumber The PCD token number to retrieve a current value for.
255 @retval UINT8 Return the UINT8.
267 ASSERT (Guid
!= NULL
);
269 PcdPpi
= GetPcdPpiPtr ();
271 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
277 Returns the 16-bit value for the token specified by TokenNumber and Guid.
278 If Guid is NULL, then ASSERT().
280 @param[in] Guid Pointer to a 128-bit unique value that designates
281 which namespace to retrieve a value from.
282 @param[in] TokenNumber The PCD token number to retrieve a current value for.
284 @retval UINT16 Return the UINT16.
296 ASSERT (Guid
!= NULL
);
298 PcdPpi
= GetPcdPpiPtr ();
300 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
306 Returns the 32-bit value for the token specified by TokenNumber and Guid.
307 If Guid is NULL, then ASSERT().
309 @param[in] Guid Pointer to a 128-bit unique value that designates
310 which namespace to retrieve a value from.
311 @param[in] TokenNumber The PCD token number to retrieve a current value for.
313 @retval UINT32 Return the UINT32.
325 ASSERT (Guid
!= NULL
);
327 PcdPpi
= GetPcdPpiPtr ();
329 return PcdPpi
->Get32Ex (Guid
, TokenNumber
);
336 Returns the 64-bit value for the token specified by TokenNumber and Guid.
337 If Guid is NULL, then ASSERT().
339 @param[in] Guid Pointer to a 128-bit unique value that designates
340 which namespace to retrieve a value from.
341 @param[in] TokenNumber The PCD token number to retrieve a current value for.
343 @retval UINT64 Return the UINT64.
355 ASSERT (Guid
!= NULL
);
357 PcdPpi
= GetPcdPpiPtr ();
359 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
365 Returns the pointer to the token specified by TokenNumber and Guid.
366 If Guid is NULL, then ASSERT().
368 @param[in] Guid Pointer to a 128-bit unique value that designates
369 which namespace to retrieve a value from.
370 @param[in] TokenNumber The PCD token number to retrieve a current value for.
372 @retval VOID* Return the VOID* pointer.
384 ASSERT (Guid
!= NULL
);
386 PcdPpi
= GetPcdPpiPtr ();
388 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
394 Returns the Boolean value of the token specified by TokenNumber and Guid.
395 If Guid is NULL, then ASSERT().
397 @param[in] Guid Pointer to a 128-bit unique value that designates
398 which namespace to retrieve a value from.
399 @param[in] TokenNumber The PCD token number to retrieve a current value for.
401 @retval BOOLEAN Return the BOOLEAN.
413 ASSERT (Guid
!= NULL
);
415 PcdPpi
= GetPcdPpiPtr ();
417 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
423 Returns the size of the token specified by TokenNumber and Guid.
424 If Guid is NULL, then ASSERT().
426 @param[in] Guid Pointer to a 128-bit unique value that designates
427 which namespace to retrieve a value from.
428 @param[in] TokenNumber The PCD token number to retrieve a current value for.
430 @retval UINTN Return the size.
442 ASSERT (Guid
!= NULL
);
444 PcdPpi
= GetPcdPpiPtr ();
446 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
452 Sets the 8-bit value for the token specified by TokenNumber
453 to the value specified by Value. Value is returned.
455 @param[in] TokenNumber The PCD token number to set a current value for.
456 @param[in] Value The 8-bit value to set.
458 @retval UINT8 Return the value been set.
464 IN UINTN TokenNumber
,
471 PcdPpi
= GetPcdPpiPtr ();
473 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
475 ASSERT_EFI_ERROR (Status
);
483 Sets the 16-bit value for the token specified by TokenNumber
484 to the value specified by Value. Value is returned.
486 @param[in] TokenNumber The PCD token number to set a current value for.
487 @param[in] Value The 16-bit value to set.
489 @retval UINT16 Return the value been set.
495 IN UINTN TokenNumber
,
502 PcdPpi
= GetPcdPpiPtr ();
504 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
506 ASSERT_EFI_ERROR (Status
);
514 Sets the 32-bit value for the token specified by TokenNumber
515 to the value specified by Value. Value is returned.
517 @param[in] TokenNumber The PCD token number to set a current value for.
518 @param[in] Value The 32-bit value to set.
520 @retval UINT32 Return the value been set.
526 IN UINTN TokenNumber
,
533 PcdPpi
= GetPcdPpiPtr ();
535 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
537 ASSERT_EFI_ERROR (Status
);
545 Sets the 64-bit value for the token specified by TokenNumber
546 to the value specified by Value. Value is returned.
548 @param[in] TokenNumber The PCD token number to set a current value for.
549 @param[in] Value The 64-bit value to set.
551 @retval UINT64 Return the value been set.
557 IN UINTN TokenNumber
,
564 PcdPpi
= GetPcdPpiPtr ();
566 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
568 ASSERT_EFI_ERROR (Status
);
576 Sets a buffer for the token specified by TokenNumber to
577 the value specified by Buffer and SizeOfValue. Buffer to
578 be set is returned. The content of the buffer could be
579 overwritten if a Callback on SET is registered with this
582 If SizeOfValue is greater than the maximum
583 size support by TokenNumber, then set SizeOfValue to the
584 maximum size supported by TokenNumber and return NULL to
585 indicate that the set operation was not actually performed.
587 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
589 @param[in] TokenNumber The PCD token number to set a current value for.
590 @param[in,out] SizeOfBuffer The size, in bytes, of Buffer.
591 @param[in] Value A pointer to the buffer to set.
593 @retval VOID* Return the pointer for the buffer been set.
599 IN UINTN TokenNumber
,
600 IN OUT UINTN
*SizeOfBuffer
,
607 ASSERT (SizeOfBuffer
!= NULL
);
609 if (*SizeOfBuffer
> 0) {
610 ASSERT (Buffer
!= NULL
);
613 PcdPpi
= GetPcdPpiPtr ();
615 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
617 if (EFI_ERROR (Status
)) {
627 Sets the Boolean value for the token specified by TokenNumber
628 to the value specified by Value. Value is returned.
630 @param[in] TokenNumber The PCD token number to set a current value for.
631 @param[in] Value The boolean value to set.
633 @retval BOOLEAN Return the value been set.
639 IN UINTN TokenNumber
,
646 PcdPpi
= GetPcdPpiPtr ();
648 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
650 ASSERT_EFI_ERROR (Status
);
658 Sets the 8-bit value for the token specified by TokenNumber and
659 Guid to the value specified by Value. Value is returned.
660 If Guid is NULL, then ASSERT().
662 @param[in] Guid Pointer to a 128-bit unique value that
663 designates which namespace to set a value from.
664 @param[in] TokenNumber The PCD token number to set a current value for.
665 @param[in] Value The 8-bit value to set.
667 @retval UINT8 Return the value been set.
674 IN UINTN TokenNumber
,
681 PcdPpi
= GetPcdPpiPtr ();
683 ASSERT (Guid
!= NULL
);
685 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
687 ASSERT_EFI_ERROR (Status
);
695 Sets the 16-bit value for the token specified by TokenNumber and
696 Guid to the value specified by Value. Value is returned.
697 If Guid is NULL, then ASSERT().
699 @param[in] Guid Pointer to a 128-bit unique value that
700 designates which namespace to set a value from.
701 @param[in] TokenNumber The PCD token number to set a current value for.
702 @param[in] Value The 16-bit value to set.
704 @retval UINT8 Return the value been set.
711 IN UINTN TokenNumber
,
718 PcdPpi
= GetPcdPpiPtr ();
720 ASSERT (Guid
!= NULL
);
721 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
723 ASSERT_EFI_ERROR (Status
);
731 Sets the 32-bit value for the token specified by TokenNumber and
732 Guid to the value specified by Value. Value is returned.
733 If Guid is NULL, then ASSERT().
735 @param[in] Guid Pointer to a 128-bit unique value that
736 designates which namespace to set a value from.
737 @param[in] TokenNumber The PCD token number to set a current value for.
738 @param[in] Value The 32-bit value to set.
740 @retval UINT32 Return the value been set.
747 IN UINTN TokenNumber
,
753 ASSERT (Guid
!= NULL
);
754 PcdPpi
= GetPcdPpiPtr ();
757 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
759 ASSERT_EFI_ERROR (Status
);
767 Sets the 64-bit value for the token specified by TokenNumber and
768 Guid to the value specified by Value. Value is returned.
769 If Guid is NULL, then ASSERT().
771 @param[in] Guid Pointer to a 128-bit unique value that
772 designates which namespace to set a value from.
773 @param[in] TokenNumber The PCD token number to set a current value for.
774 @param[in] Value The 64-bit value to set.
776 @retval UINT64 Return the value been set.
783 IN UINTN TokenNumber
,
789 ASSERT (Guid
!= NULL
);
790 PcdPpi
= GetPcdPpiPtr ();
793 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
795 ASSERT_EFI_ERROR (Status
);
803 Sets a buffer for the token specified by TokenNumber to the value specified by
804 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
805 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
806 supported by TokenNumber and return NULL to indicate that the set operation
807 was not actually performed.
809 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
811 @param[in] Guid Pointer to a 128-bit unique value that
812 designates which namespace to set a value from.
813 @param[in] TokenNumber The PCD token number to set a current value for.
814 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
815 @param[in] Buffer A pointer to the buffer to set.
817 @retval VOID * Return the pinter to the buffer been set.
824 IN UINTN TokenNumber
,
825 IN OUT UINTN
*SizeOfBuffer
,
831 ASSERT (SizeOfBuffer
!= NULL
);
832 if (*SizeOfBuffer
> 0) {
833 ASSERT (Buffer
!= NULL
);
835 ASSERT (Guid
!= NULL
);
836 PcdPpi
= GetPcdPpiPtr ();
838 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
840 if (EFI_ERROR (Status
)) {
850 Sets the Boolean value for the token specified by TokenNumber and
851 Guid to the value specified by Value. Value is returned.
852 If Guid is NULL, then ASSERT().
854 @param[in] Guid Pointer to a 128-bit unique value that
855 designates which namespace to set a value from.
856 @param[in] TokenNumber The PCD token number to set a current value for.
857 @param[in] Value The Boolean value to set.
859 @retval Boolean Return the value been set.
866 IN UINTN TokenNumber
,
873 PcdPpi
= GetPcdPpiPtr ();
875 ASSERT (Guid
!= NULL
);
876 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
878 ASSERT_EFI_ERROR (Status
);
886 When the token specified by TokenNumber and Guid is set,
887 then notification function specified by NotificationFunction is called.
888 If Guid is NULL, then the default token space is used.
889 If NotificationFunction is NULL, then ASSERT().
891 @param[in] Guid Pointer to a 128-bit unique value that designates which
892 namespace to set a value from. If NULL, then the default
894 @param[in] TokenNumber The PCD token number to monitor.
895 @param[in] NotificationFunction The function to call when the token
896 specified by Guid and TokenNumber is set.
903 LibPcdCallbackOnSet (
904 IN CONST GUID
*Guid
, OPTIONAL
905 IN UINTN TokenNumber
,
906 IN PCD_CALLBACK NotificationFunction
912 PcdPpi
= GetPcdPpiPtr ();
915 Status
= PcdPpi
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
917 ASSERT_EFI_ERROR (Status
);
925 Disable a notification function that was established with LibPcdCallbackonSet().
926 If NotificationFunction is NULL, then ASSERT().
928 @param[in] Guid Specify the GUID token space.
929 @param[in] TokenNumber Specify the token number.
930 @param[in] NotificationFunction The callback function to be unregistered.
937 LibPcdCancelCallback (
938 IN CONST GUID
*Guid
, OPTIONAL
939 IN UINTN TokenNumber
,
940 IN PCD_CALLBACK NotificationFunction
946 PcdPpi
= GetPcdPpiPtr ();
949 Status
= PcdPpi
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
951 ASSERT_EFI_ERROR (Status
);
959 Retrieves the next PCD token number from the token space specified by Guid.
960 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
961 then the first token number is returned. Otherwise, the token number that
962 follows TokenNumber in the token space is returned. If TokenNumber is the last
963 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
964 is not in the token space specified by Guid, then ASSERT().
966 @param[in] Pointer to a 128-bit unique value that designates which namespace
967 to set a value from. If NULL, then the default token space is used.
968 @param[in] The previous PCD token number. If 0, then retrieves the first PCD
971 @retval UINTN The next valid token number.
977 IN CONST GUID
*Guid
, OPTIONAL
984 PcdPpi
= GetPcdPpiPtr ();
987 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
989 ASSERT_EFI_ERROR (Status
);
996 Retrieves the next PCD token space from a token space specified by Guid.
997 Guid of NULL is reserved to mark the default local token namespace on the current
998 platform. If Guid is NULL, then the GUID of the first non-local token space of the
999 current platform is returned. If Guid is the last non-local token space,
1000 then NULL is returned.
1002 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
1006 @param[in] Pointer to a 128-bit unique value that designates from which namespace
1007 to start the search.
1009 @retval CONST GUID * The next valid token namespace.
1014 LibPcdGetNextTokenSpace (
1021 PcdPpi
= GetPcdPpiPtr ();
1024 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1026 ASSERT_EFI_ERROR (Status
);
1028 return (GUID
*)Guid
;
1034 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1035 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1036 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1037 NULL to indicate that the set operation was not actually performed.
1038 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1039 MaximumDatumSize and NULL must be returned.
1041 If PatchVariable is NULL, then ASSERT().
1042 If SizeOfValue is NULL, then ASSERT().
1043 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1045 @param[in] PatchVariable A pointer to the global variable in a module that is
1046 the target of the set operation.
1047 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1048 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1049 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1055 IN VOID
*PatchVariable
,
1056 IN UINTN MaximumDatumSize
,
1057 IN OUT UINTN
*SizeOfBuffer
,
1058 IN CONST VOID
*Buffer
1061 ASSERT (PatchVariable
!= NULL
);
1062 ASSERT (SizeOfBuffer
!= NULL
);
1064 if (*SizeOfBuffer
> 0) {
1065 ASSERT (Buffer
!= NULL
);
1068 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1069 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1070 *SizeOfBuffer
= MaximumDatumSize
;
1074 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1076 return (VOID
*) Buffer
;