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 Retrieve the PCD_PPI pointer.
32 This function is to locate PCD_PPI PPI via PeiService.
33 If fail to locate PCD_PPI, then ASSERT_EFI_ERROR().
35 @retval PCD_PPI * The pointer to the PCD_PPI.
46 Status
= PeiServicesLocatePpi (&gPcdPpiGuid
, 0, NULL
, (VOID
**)&PcdPpi
);
47 ASSERT_EFI_ERROR (Status
);
53 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
54 If SkuId not less than PCD_MAX_SKU_ID, then ASSERT().
56 @param[in] System sku id. The SKU value that will be used when the PCD service will retrieve and
59 @retval SKU_ID Return the SKU ID that just be set.
69 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
71 GetPcdPpiPointer()->SetSku (SkuId
);
79 Returns the 8-bit value for the token specified by TokenNumber.
81 @param[in] TokenNumber The PCD token number to retrieve a current value for.
83 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
92 return (GetPcdPpiPointer ())->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.
111 return (GetPcdPpiPointer ())->Get16 (TokenNumber
);
117 Returns the 32-bit value for the token specified by TokenNumber.
119 @param[in] TokenNumber The PCD token number to retrieve a current value for.
121 @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber.
130 return (GetPcdPpiPointer ())->Get32 (TokenNumber
);
136 Returns the 64-bit value for the token specified by TokenNumber.
138 @param[in] TokenNumber The PCD token number to retrieve a current value for.
140 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
149 return (GetPcdPpiPointer ())->Get64 (TokenNumber
);
155 Returns the pointer to the buffer of the token specified by TokenNumber.
157 @param[in] TokenNumber The PCD token number to retrieve a current value for.
159 @retval VOID* Returns the pointer to the token specified by TokenNumber.
168 return (GetPcdPpiPointer ())->GetPtr (TokenNumber
);
174 Returns the Boolean value of the token specified by TokenNumber.
176 @param[in] TokenNumber The PCD token number to retrieve a current value for.
178 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
187 return (GetPcdPpiPointer ())->GetBool (TokenNumber
);
193 Returns the size of the token specified by TokenNumber.
195 @param[in] TokenNumber The PCD token number to retrieve a current value for.
197 @retval UINTN Returns the size of the token specified by TokenNumber.
206 return (GetPcdPpiPointer ())->GetSize (TokenNumber
);
212 Returns the 8-bit value for the token specified by TokenNumber and Guid.
213 If Guid is NULL, then ASSERT().
215 @param[in] Guid Pointer to a 128-bit unique value that designates
216 which namespace to retrieve a value from.
217 @param[in] TokenNumber The PCD token number to retrieve a current value for.
219 @retval UINT8 Return the UINT8.
229 ASSERT (Guid
!= NULL
);
231 return (GetPcdPpiPointer ())->Get8Ex (Guid
, TokenNumber
);
237 Returns the 16-bit value for the token specified by TokenNumber and Guid.
238 If Guid is NULL, then ASSERT().
240 @param[in] Guid Pointer to a 128-bit unique value that designates
241 which namespace to retrieve a value from.
242 @param[in] TokenNumber The PCD token number to retrieve a current value for.
244 @retval UINT16 Return the UINT16.
255 ASSERT (Guid
!= NULL
);
257 return (GetPcdPpiPointer ())->Get16Ex (Guid
, TokenNumber
);
263 Returns the 32-bit value for the token specified by TokenNumber and Guid.
264 If Guid is NULL, then ASSERT().
266 @param[in] Guid Pointer to a 128-bit unique value that designates
267 which namespace to retrieve a value from.
268 @param[in] TokenNumber The PCD token number to retrieve a current value for.
270 @retval UINT32 Return the UINT32.
280 ASSERT (Guid
!= NULL
);
282 return (GetPcdPpiPointer ())->Get32Ex (Guid
, TokenNumber
);
289 Returns the 64-bit value for the token specified by TokenNumber and Guid.
290 If Guid is NULL, then ASSERT().
292 @param[in] Guid Pointer to a 128-bit unique value that designates
293 which namespace to retrieve a value from.
294 @param[in] TokenNumber The PCD token number to retrieve a current value for.
296 @retval UINT64 Return the UINT64.
306 ASSERT (Guid
!= NULL
);
307 return (GetPcdPpiPointer ())->Get64Ex (Guid
, TokenNumber
);
313 Returns the pointer to the token specified by TokenNumber and Guid.
314 If Guid is NULL, then ASSERT().
316 @param[in] Guid Pointer to a 128-bit unique value that designates
317 which namespace to retrieve a value from.
318 @param[in] TokenNumber The PCD token number to retrieve a current value for.
320 @retval VOID* Return the VOID* pointer.
330 ASSERT (Guid
!= NULL
);
332 return (GetPcdPpiPointer ())->GetPtrEx (Guid
, TokenNumber
);
338 Returns the Boolean value of the token specified by TokenNumber and Guid.
339 If Guid is NULL, then ASSERT().
341 @param[in] Guid Pointer to a 128-bit unique value that designates
342 which namespace to retrieve a value from.
343 @param[in] TokenNumber The PCD token number to retrieve a current value for.
345 @retval BOOLEAN Return the BOOLEAN.
355 ASSERT (Guid
!= NULL
);
356 return (GetPcdPpiPointer ())->GetBoolEx (Guid
, TokenNumber
);
362 Returns the size of the token specified by TokenNumber and Guid.
363 If Guid is NULL, then ASSERT().
365 @param[in] Guid Pointer to a 128-bit unique value that designates
366 which namespace to retrieve a value from.
367 @param[in] TokenNumber The PCD token number to retrieve a current value for.
369 @retval UINTN Return the size.
379 ASSERT (Guid
!= NULL
);
380 return (GetPcdPpiPointer ())->GetSizeEx (Guid
, TokenNumber
);
386 Sets the 8-bit value for the token specified by TokenNumber
387 to the value specified by Value. Value is returned.
388 If fail to set pcd value, then ASSERT_EFI_ERROR().
390 @param[in] TokenNumber The PCD token number to set a current value for.
391 @param[in] Value The 8-bit value to set.
393 @retval UINT8 Return the value been set.
399 IN UINTN TokenNumber
,
405 Status
= (GetPcdPpiPointer ())->Set8 (TokenNumber
, Value
);
407 ASSERT_EFI_ERROR (Status
);
415 Sets the 16-bit value for the token specified by TokenNumber
416 to the value specified by Value. Value is returned.
417 If fail to set pcd value, then ASSERT_EFI_ERROR().
419 @param[in] TokenNumber The PCD token number to set a current value for.
420 @param[in] Value The 16-bit value to set.
422 @retval UINT16 Return the value been set.
428 IN UINTN TokenNumber
,
434 Status
= (GetPcdPpiPointer ())->Set16 (TokenNumber
, Value
);
436 ASSERT_EFI_ERROR (Status
);
444 Sets the 32-bit value for the token specified by TokenNumber
445 to the value specified by Value. Value is returned.
446 If fail to set pcd value, then ASSERT_EFI_ERROR().
448 @param[in] TokenNumber The PCD token number to set a current value for.
449 @param[in] Value The 32-bit value to set.
451 @retval UINT32 Return the value been set.
457 IN UINTN TokenNumber
,
463 Status
= (GetPcdPpiPointer ())->Set32 (TokenNumber
, Value
);
465 ASSERT_EFI_ERROR (Status
);
473 Sets the 64-bit value for the token specified by TokenNumber
474 to the value specified by Value. Value is returned.
475 If fail to set pcd value, then ASSERT_EFI_ERROR().
477 @param[in] TokenNumber The PCD token number to set a current value for.
478 @param[in] Value The 64-bit value to set.
480 @retval UINT64 Return the value been set.
486 IN UINTN TokenNumber
,
492 Status
= (GetPcdPpiPointer ())->Set64 (TokenNumber
, Value
);
494 ASSERT_EFI_ERROR (Status
);
502 Sets a buffer for the token specified by TokenNumber to
503 the value specified by Buffer and SizeOfBuffer. Buffer to
504 be set is returned. The content of the buffer could be
505 overwritten if a Callback on SET is registered with this
508 If SizeOfBuffer is greater than the maximum
509 size support by TokenNumber, then set SizeOfBuffer to the
510 maximum size supported by TokenNumber and return NULL to
511 indicate that the set operation was not actually performed.
513 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
515 @param[in] TokenNumber The PCD token number to set a current value for.
516 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
517 In out, returns actual size of buffer is set.
518 @param[in] Buffer A pointer to the buffer to set.
520 @retval VOID* Return the pointer for the buffer been set.
526 IN UINTN TokenNumber
,
527 IN OUT UINTN
*SizeOfBuffer
,
533 ASSERT (SizeOfBuffer
!= NULL
);
535 if (*SizeOfBuffer
> 0) {
536 ASSERT (Buffer
!= NULL
);
539 Status
= (GetPcdPpiPointer ())->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
541 if (EFI_ERROR (Status
)) {
551 Sets the Boolean value for the token specified by TokenNumber
552 to the value specified by Value. Value is returned.
553 If fail to set pcd value, then ASSERT_EFI_ERROR().
555 @param[in] TokenNumber The PCD token number to set a current value for.
556 @param[in] Value The boolean value to set.
558 @retval BOOLEAN Return the value been set.
564 IN UINTN TokenNumber
,
570 Status
= (GetPcdPpiPointer ())->SetBool (TokenNumber
, Value
);
572 ASSERT_EFI_ERROR (Status
);
580 Sets the 8-bit value for the token specified by TokenNumber and
581 Guid to the value specified by Value. Value is returned.
582 If Guid is NULL, then ASSERT().
583 If fail to set pcd value, then ASSERT_EFI_ERROR().
585 @param[in] Guid Pointer to a 128-bit unique value that
586 designates which namespace to set a value from.
587 @param[in] TokenNumber The PCD token number to set a current value for.
588 @param[in] Value The 8-bit value to set.
590 @retval UINT8 Return the value been set.
597 IN UINTN TokenNumber
,
603 ASSERT (Guid
!= NULL
);
605 Status
= (GetPcdPpiPointer ())->Set8Ex (Guid
, TokenNumber
, Value
);
607 ASSERT_EFI_ERROR (Status
);
615 Sets the 16-bit value for the token specified by TokenNumber and
616 Guid to the value specified by Value. Value is returned.
617 If Guid is NULL, then ASSERT().
618 If fail to set pcd value, then ASSERT_EFI_ERROR().
620 @param[in] Guid Pointer to a 128-bit unique value that
621 designates which namespace to set a value from.
622 @param[in] TokenNumber The PCD token number to set a current value for.
623 @param[in] Value The 16-bit value to set.
625 @retval UINT16 Return the value been set.
632 IN UINTN TokenNumber
,
637 ASSERT (Guid
!= NULL
);
638 Status
= (GetPcdPpiPointer ())->Set16Ex (Guid
, TokenNumber
, Value
);
640 ASSERT_EFI_ERROR (Status
);
648 Sets the 32-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().
651 If fail to set pcd value, then ASSERT_EFI_ERROR().
653 @param[in] Guid Pointer to a 128-bit unique value that
654 designates which namespace to set a value from.
655 @param[in] TokenNumber The PCD token number to set a current value for.
656 @param[in] Value The 32-bit value to set.
658 @retval UINT32 Return the value been set.
665 IN UINTN TokenNumber
,
671 ASSERT (Guid
!= NULL
);
673 Status
= (GetPcdPpiPointer ())->Set32Ex (Guid
, TokenNumber
, Value
);
675 ASSERT_EFI_ERROR (Status
);
683 Sets the 64-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().
686 If fail to set pcd value, then ASSERT_EFI_ERROR().
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 64-bit value to set.
693 @retval UINT64 Return the value been set.
700 IN UINTN TokenNumber
,
705 ASSERT (Guid
!= NULL
);
707 Status
= (GetPcdPpiPointer ())->Set64Ex (Guid
, TokenNumber
, Value
);
709 ASSERT_EFI_ERROR (Status
);
717 Sets a buffer for the token specified by TokenNumber to the value specified by
718 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
719 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
720 supported by TokenNumber and return NULL to indicate that the set operation
721 was not actually performed.
723 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
725 @param[in] Guid Pointer to a 128-bit unique value that
726 designates which namespace to set a value from.
727 @param[in] TokenNumber The PCD token number to set a current value for.
728 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
729 In out, returns actual size of buffer is set.
730 @param[in] Buffer A pointer to the buffer to set.
732 @retval VOID * Return the pinter to the buffer been set.
739 IN UINTN TokenNumber
,
740 IN OUT UINTN
*SizeOfBuffer
,
745 ASSERT (SizeOfBuffer
!= NULL
);
746 if (*SizeOfBuffer
> 0) {
747 ASSERT (Buffer
!= NULL
);
749 ASSERT (Guid
!= NULL
);
751 Status
= (GetPcdPpiPointer ())->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
753 if (EFI_ERROR (Status
)) {
763 Sets the Boolean value for the token specified by TokenNumber and
764 Guid to the value specified by Value. Value is returned.
765 If Guid is NULL, then ASSERT().
766 If fail to set pcd value, then ASSERT_EFI_ERROR().
768 @param[in] Guid Pointer to a 128-bit unique value that
769 designates which namespace to set a value from.
770 @param[in] TokenNumber The PCD token number to set a current value for.
771 @param[in] Value The Boolean value to set.
773 @retval Boolean Return the value been set.
780 IN UINTN TokenNumber
,
786 ASSERT (Guid
!= NULL
);
787 Status
= (GetPcdPpiPointer ())->SetBoolEx (Guid
, TokenNumber
, Value
);
789 ASSERT_EFI_ERROR (Status
);
797 When the token specified by TokenNumber and Guid is set,
798 then notification function specified by NotificationFunction is called.
799 If Guid is NULL, then the default token space is used.
800 If NotificationFunction is NULL, then ASSERT().
801 If fail to set callback, then ASSERT_EFI_ERROR().
802 @param[in] Guid Pointer to a 128-bit unique value that designates which
803 namespace to set a value from. If NULL, then the default
805 @param[in] TokenNumber The PCD token number to monitor.
806 @param[in] NotificationFunction The function to call when the token
807 specified by Guid and TokenNumber is set.
814 LibPcdCallbackOnSet (
815 IN CONST GUID
*Guid
, OPTIONAL
816 IN UINTN TokenNumber
,
817 IN PCD_CALLBACK NotificationFunction
822 Status
= (GetPcdPpiPointer ())->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
824 ASSERT_EFI_ERROR (Status
);
832 Disable a notification function that was established with LibPcdCallbackonSet().
833 If NotificationFunction is NULL, then ASSERT().
834 If fail to cancel callback, then ASSERT_EFI_ERROR().
836 @param[in] Guid Specify the GUID token space.
837 @param[in] TokenNumber Specify the token number.
838 @param[in] NotificationFunction The callback function to be unregistered.
845 LibPcdCancelCallback (
846 IN CONST GUID
*Guid
, OPTIONAL
847 IN UINTN TokenNumber
,
848 IN PCD_CALLBACK NotificationFunction
853 Status
= (GetPcdPpiPointer ())->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
855 ASSERT_EFI_ERROR (Status
);
863 Retrieves the next PCD token number from the token space specified by Guid.
864 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
865 then the first token number is returned. Otherwise, the token number that
866 follows TokenNumber in the token space is returned. If TokenNumber is the last
867 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
868 is not in the token space specified by Guid, then ASSERT().
869 If fail to get token in given token space, then ASSERT_EFI_ERROR().
871 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
872 to set a value from. If NULL, then the default token space is used.
873 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
876 @retval UINTN The next valid token number.
882 IN CONST GUID
*Guid
, OPTIONAL
888 Status
= (GetPcdPpiPointer ())->GetNextToken (Guid
, &TokenNumber
);
890 ASSERT_EFI_ERROR (Status
);
897 Retrieves the next PCD token space from a token space specified by Guid.
898 Guid of NULL is reserved to mark the default local token namespace on the current
899 platform. If Guid is NULL, then the GUID of the first non-local token space of the
900 current platform is returned. If Guid is the last non-local token space,
901 then NULL is returned.
902 If fail to get next token space, then ASSERT_EFI_ERROR().
904 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
908 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
911 @retval CONST GUID * The next valid token namespace.
916 LibPcdGetNextTokenSpace (
922 Status
= (GetPcdPpiPointer ())->GetNextTokenSpace (&Guid
);
924 ASSERT_EFI_ERROR (Status
);
932 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
933 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
934 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
935 NULL to indicate that the set operation was not actually performed.
936 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
937 MaximumDatumSize and NULL must be returned.
939 If PatchVariable is NULL, then ASSERT().
940 If SizeOfBuffer is NULL, then ASSERT().
941 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
943 @param[in] PatchVariable A pointer to the global variable in a module that is
944 the target of the set operation.
945 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
946 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
947 In out, returns actual size of buffer is set.
948 @param[in] Buffer A pointer to the buffer to used to set the target variable.
954 IN VOID
*PatchVariable
,
955 IN UINTN MaximumDatumSize
,
956 IN OUT UINTN
*SizeOfBuffer
,
957 IN CONST VOID
*Buffer
960 ASSERT (PatchVariable
!= NULL
);
961 ASSERT (SizeOfBuffer
!= NULL
);
963 if (*SizeOfBuffer
> 0) {
964 ASSERT (Buffer
!= NULL
);
967 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
968 (*SizeOfBuffer
== MAX_ADDRESS
)) {
969 *SizeOfBuffer
= MaximumDatumSize
;
973 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
975 return (VOID
*) Buffer
;