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.
32 @retval PCD_PPI * The pointer to the PCD_PPI.
43 Status
= PeiServicesLocatePpi (&gPcdPpiGuid
, 0, NULL
, (VOID
**)&PcdPpi
);
44 ASSERT_EFI_ERROR (Status
);
50 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
52 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
53 set values associated with a PCD token.
55 @retval SKU_ID Return the SKU ID that just be set.
65 ASSERT (SkuId
< 0x100);
67 GetPcdPpiPtr()->SetSku (SkuId
);;
75 Returns the 8-bit value for the token specified by TokenNumber.
77 @param[in] TokenNumber The PCD token number to retrieve a current value for.
79 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
90 PcdPpi
= GetPcdPpiPtr ();
92 return PcdPpi
->Get8 (TokenNumber
);
98 Returns the 16-bit value for the token specified by TokenNumber.
100 @param[in] TokenNumber The PCD token number to retrieve a current value for.
102 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
113 PcdPpi
= GetPcdPpiPtr ();
115 return PcdPpi
->Get16 (TokenNumber
);
121 Returns the 32-bit value for the token specified by TokenNumber.
123 @param[in] TokenNumber The PCD token number to retrieve a current value for.
125 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
136 PcdPpi
= GetPcdPpiPtr ();
138 return PcdPpi
->Get32 (TokenNumber
);
144 Returns the 64-bit value for the token specified by TokenNumber.
146 @param[in] TokenNumber The PCD token number to retrieve a current value for.
148 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
159 PcdPpi
= GetPcdPpiPtr ();
161 return PcdPpi
->Get64 (TokenNumber
);
167 Returns the pointer to the buffer of the token specified by TokenNumber.
169 @param[in] TokenNumber The PCD token number to retrieve a current value for.
171 @retval VOID* Returns the pointer to the token specified by TokenNumber.
182 PcdPpi
= GetPcdPpiPtr ();
184 return PcdPpi
->GetPtr (TokenNumber
);
190 Returns the Boolean value of the token specified by TokenNumber.
192 @param[in] TokenNumber The PCD token number to retrieve a current value for.
194 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
205 PcdPpi
= GetPcdPpiPtr ();
207 return PcdPpi
->GetBool (TokenNumber
);
213 Returns the size of the token specified by TokenNumber.
215 @param[in] TokenNumber The PCD token number to retrieve a current value for.
217 @retval UINTN Returns the size of the token specified by TokenNumber.
228 PcdPpi
= GetPcdPpiPtr ();
230 return PcdPpi
->GetSize (TokenNumber
);
236 Returns the 8-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 @retval UINT8 Return the UINT8.
255 ASSERT (Guid
!= NULL
);
257 PcdPpi
= GetPcdPpiPtr ();
259 return PcdPpi
->Get8Ex (Guid
, TokenNumber
);
265 Returns the 16-bit value for the token specified by TokenNumber and Guid.
266 If Guid is NULL, then ASSERT().
268 @param[in] Guid Pointer to a 128-bit unique value that designates
269 which namespace to retrieve a value from.
270 @param[in] TokenNumber The PCD token number to retrieve a current value for.
272 @retval UINT16 Return the UINT16.
284 ASSERT (Guid
!= NULL
);
286 PcdPpi
= GetPcdPpiPtr ();
288 return PcdPpi
->Get16Ex (Guid
, TokenNumber
);
294 Returns the 32-bit value for the token specified by TokenNumber and Guid.
295 If Guid is NULL, then ASSERT().
297 @param[in] Guid Pointer to a 128-bit unique value that designates
298 which namespace to retrieve a value from.
299 @param[in] TokenNumber The PCD token number to retrieve a current value for.
301 @retval UINT32 Return the UINT32.
313 ASSERT (Guid
!= NULL
);
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 ASSERT (Guid
!= NULL
);
345 PcdPpi
= GetPcdPpiPtr ();
347 return PcdPpi
->Get64Ex (Guid
, TokenNumber
);
353 Returns the pointer to the token specified by TokenNumber and Guid.
354 If Guid is NULL, then ASSERT().
356 @param[in] Guid Pointer to a 128-bit unique value that designates
357 which namespace to retrieve a value from.
358 @param[in] TokenNumber The PCD token number to retrieve a current value for.
360 @retval VOID* Return the VOID* pointer.
372 ASSERT (Guid
!= NULL
);
374 PcdPpi
= GetPcdPpiPtr ();
376 return PcdPpi
->GetPtrEx (Guid
, TokenNumber
);
382 Returns the Boolean value of the token specified by TokenNumber and Guid.
383 If Guid is NULL, then ASSERT().
385 @param[in] Guid Pointer to a 128-bit unique value that designates
386 which namespace to retrieve a value from.
387 @param[in] TokenNumber The PCD token number to retrieve a current value for.
389 @retval BOOLEAN Return the BOOLEAN.
401 ASSERT (Guid
!= NULL
);
403 PcdPpi
= GetPcdPpiPtr ();
405 return PcdPpi
->GetBoolEx (Guid
, TokenNumber
);
411 Returns the size of the token specified by TokenNumber and Guid.
412 If Guid is NULL, then ASSERT().
414 @param[in] Guid Pointer to a 128-bit unique value that designates
415 which namespace to retrieve a value from.
416 @param[in] TokenNumber The PCD token number to retrieve a current value for.
418 @retval UINTN Return the size.
430 ASSERT (Guid
!= NULL
);
432 PcdPpi
= GetPcdPpiPtr ();
434 return PcdPpi
->GetSizeEx (Guid
, TokenNumber
);
440 Sets the 8-bit value for the token specified by TokenNumber
441 to the value specified by Value. Value is returned.
443 @param[in] TokenNumber The PCD token number to set a current value for.
444 @param[in] Value The 8-bit value to set.
446 @retval UINT8 Return the value been set.
452 IN UINTN TokenNumber
,
459 PcdPpi
= GetPcdPpiPtr ();
461 Status
= PcdPpi
->Set8 (TokenNumber
, Value
);
463 ASSERT_EFI_ERROR (Status
);
471 Sets the 16-bit value for the token specified by TokenNumber
472 to the value specified by Value. Value is returned.
474 @param[in] TokenNumber The PCD token number to set a current value for.
475 @param[in] Value The 16-bit value to set.
477 @retval UINT16 Return the value been set.
483 IN UINTN TokenNumber
,
490 PcdPpi
= GetPcdPpiPtr ();
492 Status
= PcdPpi
->Set16 (TokenNumber
, Value
);
494 ASSERT_EFI_ERROR (Status
);
502 Sets the 32-bit value for the token specified by TokenNumber
503 to the value specified by Value. Value is returned.
505 @param[in] TokenNumber The PCD token number to set a current value for.
506 @param[in] Value The 32-bit value to set.
508 @retval UINT32 Return the value been set.
514 IN UINTN TokenNumber
,
521 PcdPpi
= GetPcdPpiPtr ();
523 Status
= PcdPpi
->Set32 (TokenNumber
, Value
);
525 ASSERT_EFI_ERROR (Status
);
533 Sets the 64-bit value for the token specified by TokenNumber
534 to the value specified by Value. Value is returned.
536 @param[in] TokenNumber The PCD token number to set a current value for.
537 @param[in] Value The 64-bit value to set.
539 @retval UINT64 Return the value been set.
545 IN UINTN TokenNumber
,
552 PcdPpi
= GetPcdPpiPtr ();
554 Status
= PcdPpi
->Set64 (TokenNumber
, Value
);
556 ASSERT_EFI_ERROR (Status
);
564 Sets a buffer for the token specified by TokenNumber to
565 the value specified by Buffer and SizeOfValue. Buffer to
566 be set is returned. The content of the buffer could be
567 overwritten if a Callback on SET is registered with this
570 If SizeOfValue is greater than the maximum
571 size support by TokenNumber, then set SizeOfValue to the
572 maximum size supported by TokenNumber and return NULL to
573 indicate that the set operation was not actually performed.
575 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
577 @param[in] TokenNumber The PCD token number to set a current value for.
578 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
579 @param[in] Buffer A pointer to the buffer to set.
581 @retval VOID* Return the pointer for the buffer been set.
587 IN UINTN TokenNumber
,
588 IN OUT UINTN
*SizeOfBuffer
,
595 ASSERT (SizeOfBuffer
!= NULL
);
597 if (*SizeOfBuffer
> 0) {
598 ASSERT (Buffer
!= NULL
);
601 PcdPpi
= GetPcdPpiPtr ();
603 Status
= PcdPpi
->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
605 if (EFI_ERROR (Status
)) {
615 Sets the Boolean value for the token specified by TokenNumber
616 to the value specified by Value. Value is returned.
618 @param[in] TokenNumber The PCD token number to set a current value for.
619 @param[in] Value The boolean value to set.
621 @retval BOOLEAN Return the value been set.
627 IN UINTN TokenNumber
,
634 PcdPpi
= GetPcdPpiPtr ();
636 Status
= PcdPpi
->SetBool (TokenNumber
, Value
);
638 ASSERT_EFI_ERROR (Status
);
646 Sets the 8-bit value for the token specified by TokenNumber and
647 Guid to the value specified by Value. Value is returned.
648 If Guid is NULL, then ASSERT().
650 @param[in] Guid Pointer to a 128-bit unique value that
651 designates which namespace to set a value from.
652 @param[in] TokenNumber The PCD token number to set a current value for.
653 @param[in] Value The 8-bit value to set.
655 @retval UINT8 Return the value been set.
662 IN UINTN TokenNumber
,
669 PcdPpi
= GetPcdPpiPtr ();
671 ASSERT (Guid
!= NULL
);
673 Status
= PcdPpi
->Set8Ex (Guid
, TokenNumber
, Value
);
675 ASSERT_EFI_ERROR (Status
);
683 Sets the 16-bit value for the token specified by TokenNumber and
684 Guid to the value specified by Value. Value is returned.
685 If Guid is NULL, then ASSERT().
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 16-bit value to set.
692 @retval UINT8 Return the value been set.
699 IN UINTN TokenNumber
,
706 PcdPpi
= GetPcdPpiPtr ();
708 ASSERT (Guid
!= NULL
);
709 Status
= PcdPpi
->Set16Ex (Guid
, TokenNumber
, Value
);
711 ASSERT_EFI_ERROR (Status
);
719 Sets the 32-bit value for the token specified by TokenNumber and
720 Guid to the value specified by Value. Value is returned.
721 If Guid is NULL, then ASSERT().
723 @param[in] Guid Pointer to a 128-bit unique value that
724 designates which namespace to set a value from.
725 @param[in] TokenNumber The PCD token number to set a current value for.
726 @param[in] Value The 32-bit value to set.
728 @retval UINT32 Return the value been set.
735 IN UINTN TokenNumber
,
741 ASSERT (Guid
!= NULL
);
742 PcdPpi
= GetPcdPpiPtr ();
745 Status
= PcdPpi
->Set32Ex (Guid
, TokenNumber
, Value
);
747 ASSERT_EFI_ERROR (Status
);
755 Sets the 64-bit value for the token specified by TokenNumber and
756 Guid to the value specified by Value. Value is returned.
757 If Guid is NULL, then ASSERT().
759 @param[in] Guid Pointer to a 128-bit unique value that
760 designates which namespace to set a value from.
761 @param[in] TokenNumber The PCD token number to set a current value for.
762 @param[in] Value The 64-bit value to set.
764 @retval UINT64 Return the value been set.
771 IN UINTN TokenNumber
,
777 ASSERT (Guid
!= NULL
);
778 PcdPpi
= GetPcdPpiPtr ();
781 Status
= PcdPpi
->Set64Ex (Guid
, TokenNumber
, Value
);
783 ASSERT_EFI_ERROR (Status
);
791 Sets a buffer for the token specified by TokenNumber to the value specified by
792 Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
793 the maximum size support by TokenNumber, then set SizeOfValue to the maximum size
794 supported by TokenNumber and return NULL to indicate that the set operation
795 was not actually performed.
797 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
799 @param[in] Guid Pointer to a 128-bit unique value that
800 designates which namespace to set a value from.
801 @param[in] TokenNumber The PCD token number to set a current value for.
802 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
803 @param[in] Buffer A pointer to the buffer to set.
805 @retval VOID * Return the pinter to the buffer been set.
812 IN UINTN TokenNumber
,
813 IN OUT UINTN
*SizeOfBuffer
,
819 ASSERT (SizeOfBuffer
!= NULL
);
820 if (*SizeOfBuffer
> 0) {
821 ASSERT (Buffer
!= NULL
);
823 ASSERT (Guid
!= NULL
);
824 PcdPpi
= GetPcdPpiPtr ();
826 Status
= PcdPpi
->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
828 if (EFI_ERROR (Status
)) {
838 Sets the Boolean value for the token specified by TokenNumber and
839 Guid to the value specified by Value. Value is returned.
840 If Guid is NULL, then ASSERT().
842 @param[in] Guid Pointer to a 128-bit unique value that
843 designates which namespace to set a value from.
844 @param[in] TokenNumber The PCD token number to set a current value for.
845 @param[in] Value The Boolean value to set.
847 @retval Boolean Return the value been set.
854 IN UINTN TokenNumber
,
861 PcdPpi
= GetPcdPpiPtr ();
863 ASSERT (Guid
!= NULL
);
864 Status
= PcdPpi
->SetBoolEx (Guid
, TokenNumber
, Value
);
866 ASSERT_EFI_ERROR (Status
);
874 When the token specified by TokenNumber and Guid is set,
875 then notification function specified by NotificationFunction is called.
876 If Guid is NULL, then the default token space is used.
877 If NotificationFunction is NULL, then ASSERT().
879 @param[in] Guid Pointer to a 128-bit unique value that designates which
880 namespace to set a value from. If NULL, then the default
882 @param[in] TokenNumber The PCD token number to monitor.
883 @param[in] NotificationFunction The function to call when the token
884 specified by Guid and TokenNumber is set.
891 LibPcdCallbackOnSet (
892 IN CONST GUID
*Guid
, OPTIONAL
893 IN UINTN TokenNumber
,
894 IN PCD_CALLBACK NotificationFunction
900 PcdPpi
= GetPcdPpiPtr ();
903 Status
= PcdPpi
->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
905 ASSERT_EFI_ERROR (Status
);
913 Disable a notification function that was established with LibPcdCallbackonSet().
914 If NotificationFunction is NULL, then ASSERT().
916 @param[in] Guid Specify the GUID token space.
917 @param[in] TokenNumber Specify the token number.
918 @param[in] NotificationFunction The callback function to be unregistered.
925 LibPcdCancelCallback (
926 IN CONST GUID
*Guid
, OPTIONAL
927 IN UINTN TokenNumber
,
928 IN PCD_CALLBACK NotificationFunction
934 PcdPpi
= GetPcdPpiPtr ();
937 Status
= PcdPpi
->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
939 ASSERT_EFI_ERROR (Status
);
947 Retrieves the next PCD token number from the token space specified by Guid.
948 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
949 then the first token number is returned. Otherwise, the token number that
950 follows TokenNumber in the token space is returned. If TokenNumber is the last
951 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
952 is not in the token space specified by Guid, then ASSERT().
954 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
955 to set a value from. If NULL, then the default token space is used.
956 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
959 @retval UINTN The next valid token number.
965 IN CONST GUID
*Guid
, OPTIONAL
972 PcdPpi
= GetPcdPpiPtr ();
975 Status
= PcdPpi
->GetNextToken (Guid
, &TokenNumber
);
977 ASSERT_EFI_ERROR (Status
);
984 Retrieves the next PCD token space from a token space specified by Guid.
985 Guid of NULL is reserved to mark the default local token namespace on the current
986 platform. If Guid is NULL, then the GUID of the first non-local token space of the
987 current platform is returned. If Guid is the last non-local token space,
988 then NULL is returned.
990 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
994 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
997 @retval CONST GUID * The next valid token namespace.
1002 LibPcdGetNextTokenSpace (
1009 PcdPpi
= GetPcdPpiPtr ();
1012 Status
= PcdPpi
->GetNextTokenSpace (&Guid
);
1014 ASSERT_EFI_ERROR (Status
);
1016 return (GUID
*)Guid
;
1022 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
1023 and SizeOfValue. Buffer is returned. If SizeOfValue is greater than
1024 MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return
1025 NULL to indicate that the set operation was not actually performed.
1026 If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to
1027 MaximumDatumSize and NULL must be returned.
1029 If PatchVariable is NULL, then ASSERT().
1030 If SizeOfValue is NULL, then ASSERT().
1031 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
1033 @param[in] PatchVariable A pointer to the global variable in a module that is
1034 the target of the set operation.
1035 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
1036 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
1037 @param[in] Buffer A pointer to the buffer to used to set the target variable.
1043 IN VOID
*PatchVariable
,
1044 IN UINTN MaximumDatumSize
,
1045 IN OUT UINTN
*SizeOfBuffer
,
1046 IN CONST VOID
*Buffer
1049 ASSERT (PatchVariable
!= NULL
);
1050 ASSERT (SizeOfBuffer
!= NULL
);
1052 if (*SizeOfBuffer
> 0) {
1053 ASSERT (Buffer
!= NULL
);
1056 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
1057 (*SizeOfBuffer
== MAX_ADDRESS
)) {
1058 *SizeOfBuffer
= MaximumDatumSize
;
1062 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
1064 return (VOID
*) Buffer
;