2 Implementation of PcdLib class library for DXE 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.
19 #include <Protocol/Pcd.h>
21 #include <Library/PcdLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/BaseMemoryLib.h>
26 PCD_PROTOCOL
*mPcd
= NULL
;
29 Retrieves PCD protocol interface.
31 This function retrieves PCD protocol interface. On the first invocation, it
32 retrieves protocol interface via UEFI boot services and cache it to accelarte
33 further access. A module invokes this function only when it needs to access a
35 If UefiBootServicesTableLib has not been initialized, then ASSERT ().
36 If PCD protocol has not been installed, then ASSERT ().
38 @return mPcd The PCD protocol protocol interface.
51 // PCD protocol has not been installed, but a module needs to access a
54 Status
= gBS
->LocateProtocol (&gPcdProtocolGuid
, NULL
, (VOID
**)&mPcd
);
55 ASSERT_EFI_ERROR (Status
);
64 Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned.
65 If SkuId is not less than PCD_MAX_SKU_ID, then ASSERT().
67 @param[in] SkuId System SKU ID. The SKU value that will be used when the PCD service will retrieve and
70 @retval SKU_ID Return the SKU ID that just be set.
79 ASSERT (SkuId
< PCD_MAX_SKU_ID
);
81 (GetPcdProtocol ())->SetSku (SkuId
);
89 Returns the 8-bit value for the token specified by TokenNumber.
91 @param[in] TokenNumber The PCD token number to retrieve a current value for.
93 @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber.
102 return (GetPcdProtocol ())->Get8 (TokenNumber
);
108 Returns the 16-bit value for the token specified by TokenNumber.
110 @param[in] TokenNumber The PCD token number to retrieve a current value for.
112 @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber.
121 return (GetPcdProtocol ())->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.
140 return (GetPcdProtocol ())->Get32 (TokenNumber
);
146 Returns the 64-bit value for the token specified by TokenNumber.
148 @param[in] TokenNumber The PCD token number to retrieve a current value for.
150 @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber.
159 return (GetPcdProtocol ())->Get64 (TokenNumber
);
165 Returns the pointer to the buffer of the token specified by TokenNumber.
167 @param[in] TokenNumber The PCD token number to retrieve a current value for.
169 @retval VOID* Returns the pointer to the token specified by TokenNumber.
178 return (GetPcdProtocol ())->GetPtr (TokenNumber
);
184 Returns the Boolean value of the token specified by TokenNumber.
186 @param[in] TokenNumber The PCD token number to retrieve a current value for.
188 @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber.
197 return (GetPcdProtocol ())->GetBool (TokenNumber
);
203 Returns the size of the token specified by TokenNumber.
205 @param[in] TokenNumber The PCD token number to retrieve a current value for.
207 @retval UINTN Returns the size of the token specified by TokenNumber.
216 return (GetPcdProtocol ())->GetSize (TokenNumber
);
222 Returns the 8-bit value for the token specified by TokenNumber and Guid.
223 If Guid is NULL, then ASSERT().
225 @param[in] Guid Pointer to a 128-bit unique value that designates
226 which namespace to retrieve a value from.
227 @param[in] TokenNumber The PCD token number to retrieve a current value for.
229 @retval UINT8 Return the UINT8.
239 ASSERT (Guid
!= NULL
);
241 return (GetPcdProtocol ())->Get8Ex (Guid
, TokenNumber
);
246 Returns the 16-bit value for the token specified by TokenNumber and Guid.
247 If Guid is NULL, then ASSERT().
249 @param[in] Guid Pointer to a 128-bit unique value that designates
250 which namespace to retrieve a value from.
251 @param[in] TokenNumber The PCD token number to retrieve a current value for.
253 @retval UINT16 Return the UINT16.
263 ASSERT (Guid
!= NULL
);
265 return (GetPcdProtocol ())->Get16Ex (Guid
, TokenNumber
);
270 Returns the 32-bit value for the token specified by TokenNumber and Guid.
271 If Guid is NULL, then ASSERT().
273 @param[in] Guid Pointer to a 128-bit unique value that designates
274 which namespace to retrieve a value from.
275 @param[in] TokenNumber The PCD token number to retrieve a current value for.
277 @retval UINT32 Return the UINT32.
287 ASSERT (Guid
!= NULL
);
289 return (GetPcdProtocol ())->Get32Ex (Guid
, TokenNumber
);
295 Returns the 64-bit value for the token specified by TokenNumber and Guid.
296 If Guid is NULL, then ASSERT().
298 @param[in] Guid Pointer to a 128-bit unique value that designates
299 which namespace to retrieve a value from.
300 @param[in] TokenNumber The PCD token number to retrieve a current value for.
302 @retval UINT64 Return the UINT64.
312 ASSERT (Guid
!= NULL
);
314 return (GetPcdProtocol ())->Get64Ex (Guid
, TokenNumber
);
320 Returns the pointer to the token specified by TokenNumber and Guid.
321 If Guid is NULL, then ASSERT().
323 @param[in] Guid Pointer to a 128-bit unique value that designates
324 which namespace to retrieve a value from.
325 @param[in] TokenNumber The PCD token number to retrieve a current value for.
327 @retval VOID* Return the VOID* pointer.
337 ASSERT (Guid
!= NULL
);
339 return (GetPcdProtocol ())->GetPtrEx (Guid
, TokenNumber
);
345 Returns the Boolean value of the token specified by TokenNumber and Guid.
346 If Guid is NULL, then ASSERT().
348 @param[in] Guid Pointer to a 128-bit unique value that designates
349 which namespace to retrieve a value from.
350 @param[in] TokenNumber The PCD token number to retrieve a current value for.
352 @retval BOOLEAN Return the BOOLEAN.
362 ASSERT (Guid
!= NULL
);
364 return (GetPcdProtocol ())->GetBoolEx (Guid
, TokenNumber
);
370 Returns the size of the token specified by TokenNumber and Guid.
371 If Guid is NULL, then ASSERT().
373 @param[in] Guid Pointer to a 128-bit unique value that designates
374 which namespace to retrieve a value from.
375 @param[in] TokenNumber The PCD token number to retrieve a current value for.
377 @retval UINTN Return the size.
387 ASSERT (Guid
!= NULL
);
389 return (GetPcdProtocol ())->GetSizeEx (Guid
, TokenNumber
);
395 Sets the 8-bit value for the token specified by TokenNumber
396 to the value specified by Value. Value is returned.
397 If fail to set pcd value, then ASSERT_EFI_ERROR().
399 @param[in] TokenNumber The PCD token number to set a current value for.
400 @param[in] Value The 8-bit value to set.
402 @retval UINT8 Return the value been set.
408 IN UINTN TokenNumber
,
414 Status
= (GetPcdProtocol ())->Set8 (TokenNumber
, Value
);
416 ASSERT_EFI_ERROR (Status
);
424 Sets the 16-bit value for the token specified by TokenNumber
425 to the value specified by Value. Value is returned.
426 If fail to set pcd value, then ASSERT_EFI_ERROR().
428 @param[in] TokenNumber The PCD token number to set a current value for.
429 @param[in] Value The 16-bit value to set.
431 @retval UINT16 Return the value been set.
437 IN UINTN TokenNumber
,
443 Status
= (GetPcdProtocol ())->Set16 (TokenNumber
, Value
);
445 ASSERT_EFI_ERROR (Status
);
453 Sets the 32-bit value for the token specified by TokenNumber
454 to the value specified by Value. Value is returned.
455 If fail to set pcd value, then ASSERT_EFI_ERROR().
457 @param[in] TokenNumber The PCD token number to set a current value for.
458 @param[in] Value The 32-bit value to set.
460 @retval UINT32 Return the value been set.
466 IN UINTN TokenNumber
,
471 Status
= (GetPcdProtocol ())->Set32 (TokenNumber
, Value
);
473 ASSERT_EFI_ERROR (Status
);
481 Sets the 64-bit value for the token specified by TokenNumber
482 to the value specified by Value. Value is returned.
483 If fail to set pcd value, then ASSERT_EFI_ERROR().
485 @param[in] TokenNumber The PCD token number to set a current value for.
486 @param[in] Value The 64-bit value to set.
488 @retval UINT64 Return the value been set.
494 IN UINTN TokenNumber
,
500 Status
= (GetPcdProtocol ())->Set64 (TokenNumber
, Value
);
502 ASSERT_EFI_ERROR (Status
);
510 Sets a buffer for the token specified by TokenNumber to
511 the value specified by Buffer and SizeOfBuffer. Buffer to
512 be set is returned. The content of the buffer could be
513 overwritten if a Callback on SET is registered with this
516 If SizeOfBuffer is greater than the maximum
517 size support by TokenNumber, then set SizeOfBuffer to the
518 maximum size supported by TokenNumber and return NULL to
519 indicate that the set operation was not actually performed.
521 If SizeOfValue > 0 and Buffer is NULL, then ASSERT().
523 @param[in] TokenNumber The PCD token number to set a current value for.
524 @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
525 In out, returns actual size of buff is set.
526 @param[in] Buffer A pointer to the buffer to set.
528 @retval VOID* Return the pointer for the buffer been set.
534 IN UINTN TokenNumber
,
535 IN OUT UINTN
*SizeOfBuffer
,
541 ASSERT (SizeOfBuffer
!= NULL
);
543 if (*SizeOfBuffer
> 0) {
544 ASSERT (Buffer
!= NULL
);
547 Status
= (GetPcdProtocol ())->SetPtr (TokenNumber
, SizeOfBuffer
, Buffer
);
549 if (EFI_ERROR (Status
)) {
559 Sets the Boolean value for the token specified by TokenNumber
560 to the value specified by Value. Value is returned.
561 If fail to set pcd value, then ASSERT_EFI_ERROR().
563 @param[in] TokenNumber The PCD token number to set a current value for.
564 @param[in] Value The boolean value to set.
566 @retval BOOLEAN Return the value been set.
572 IN UINTN TokenNumber
,
578 Status
= (GetPcdProtocol ())->SetBool (TokenNumber
, Value
);
580 ASSERT_EFI_ERROR (Status
);
588 Sets the 8-bit value for the token specified by TokenNumber and
589 Guid to the value specified by Value. Value is returned.
590 If Guid is NULL, then ASSERT().
591 If fail to set pcd value, then ASSERT_EFI_ERROR().
593 @param[in] Guid Pointer to a 128-bit unique value that
594 designates which namespace to set a value from.
595 @param[in] TokenNumber The PCD token number to set a current value for.
596 @param[in] Value The 8-bit value to set.
598 @retval UINT8 Return the value been set.
605 IN UINTN TokenNumber
,
611 ASSERT (Guid
!= NULL
);
613 Status
= (GetPcdProtocol ())->Set8Ex (Guid
, TokenNumber
, Value
);
615 ASSERT_EFI_ERROR (Status
);
623 Sets the 16-bit value for the token specified by TokenNumber and
624 Guid to the value specified by Value. Value is returned.
625 If Guid is NULL, then ASSERT().
626 If fail to set pcd value, then ASSERT_EFI_ERROR().
628 @param[in] Guid Pointer to a 128-bit unique value that
629 designates which namespace to set a value from.
630 @param[in] TokenNumber The PCD token number to set a current value for.
631 @param[in] Value The 16-bit value to set.
633 @retval UINT16 Return the value been set.
640 IN UINTN TokenNumber
,
646 ASSERT (Guid
!= NULL
);
648 Status
= (GetPcdProtocol ())->Set16Ex (Guid
, TokenNumber
, Value
);
650 ASSERT_EFI_ERROR (Status
);
658 Sets the 32-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().
661 If fail to set pcd value, then ASSERT_EFI_ERROR().
663 @param[in] Guid Pointer to a 128-bit unique value that
664 designates which namespace to set a value from.
665 @param[in] TokenNumber The PCD token number to set a current value for.
666 @param[in] Value The 32-bit value to set.
668 @retval UINT32 Return the value been set.
675 IN UINTN TokenNumber
,
681 ASSERT (Guid
!= NULL
);
683 Status
= (GetPcdProtocol ())->Set32Ex (Guid
, TokenNumber
, Value
);
685 ASSERT_EFI_ERROR (Status
);
693 Sets the 64-bit value for the token specified by TokenNumber and
694 Guid to the value specified by Value. Value is returned.
695 If Guid is NULL, then ASSERT().
697 @param[in] Guid Pointer to a 128-bit unique value that
698 designates which namespace to set a value from.
699 @param[in] TokenNumber The PCD token number to set a current value for.
700 @param[in] Value The 64-bit value to set.
702 @retval UINT64 Return the value been set.
709 IN UINTN TokenNumber
,
715 ASSERT (Guid
!= NULL
);
717 Status
= (GetPcdProtocol ())->Set64Ex (Guid
, TokenNumber
, Value
);
719 ASSERT_EFI_ERROR (Status
);
727 Sets a buffer for the token specified by TokenNumber to the value specified by
728 Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
729 the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size
730 supported by TokenNumber and return NULL to indicate that the set operation
731 was not actually performed.
733 If SizeOfBuffer > 0 and Buffer 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, out] SizeOfBuffer The size, in bytes, of Buffer.
739 In out, returns actual size of buffer is set.
740 @param[in] Buffer A pointer to the buffer to set.
742 @retval VOID * Return the pinter to the buffer been set.
749 IN UINTN TokenNumber
,
750 IN OUT UINTN
*SizeOfBuffer
,
756 ASSERT (Guid
!= NULL
);
758 ASSERT (SizeOfBuffer
!= NULL
);
760 if (*SizeOfBuffer
> 0) {
761 ASSERT (Buffer
!= NULL
);
764 Status
= (GetPcdProtocol ())->SetPtrEx (Guid
, TokenNumber
, SizeOfBuffer
, Buffer
);
766 if (EFI_ERROR (Status
)) {
776 Sets the Boolean value for the token specified by TokenNumber and
777 Guid to the value specified by Value. Value is returned.
778 If Guid is NULL, then ASSERT().
779 If fail to set pcd value, then ASSERT_EFI_ERROR().
781 @param[in] Guid Pointer to a 128-bit unique value that
782 designates which namespace to set a value from.
783 @param[in] TokenNumber The PCD token number to set a current value for.
784 @param[in] Value The Boolean value to set.
786 @retval Boolean Return the value been set.
793 IN UINTN TokenNumber
,
799 ASSERT (Guid
!= NULL
);
801 Status
= (GetPcdProtocol ())->SetBoolEx (Guid
, TokenNumber
, Value
);
803 ASSERT_EFI_ERROR (Status
);
811 When the token specified by TokenNumber and Guid is set,
812 then notification function specified by NotificationFunction is called.
813 If Guid is NULL, then the default token space is used.
814 If NotificationFunction is NULL, then ASSERT().
815 If fail to set callback function, then ASSERT_EFI_ERROR().
817 @param[in] Guid Pointer to a 128-bit unique value that designates which
818 namespace to set a value from. If NULL, then the default
820 @param[in] TokenNumber The PCD token number to monitor.
821 @param[in] NotificationFunction The function to call when the token
822 specified by Guid and TokenNumber is set.
829 LibPcdCallbackOnSet (
830 IN CONST GUID
*Guid
, OPTIONAL
831 IN UINTN TokenNumber
,
832 IN PCD_CALLBACK NotificationFunction
837 ASSERT (NotificationFunction
!= NULL
);
839 Status
= (GetPcdProtocol ())->CallbackOnSet (Guid
, TokenNumber
, NotificationFunction
);
841 ASSERT_EFI_ERROR (Status
);
849 Disable a notification function that was established with LibPcdCallbackonSet().
850 If NotificationFunction is NULL, then ASSERT().
851 If fail to cancel callback function, then ASSERT_EFI_ERROR().
853 @param[in] Guid Specify the GUID token space.
854 @param[in] TokenNumber Specify the token number.
855 @param[in] NotificationFunction The callback function to be unregistered.
862 LibPcdCancelCallback (
863 IN CONST GUID
*Guid
, OPTIONAL
864 IN UINTN TokenNumber
,
865 IN PCD_CALLBACK NotificationFunction
870 ASSERT (NotificationFunction
!= NULL
);
872 Status
= (GetPcdProtocol ())->CancelCallback (Guid
, TokenNumber
, NotificationFunction
);
874 ASSERT_EFI_ERROR (Status
);
882 Retrieves the next PCD token number from the token space specified by Guid.
883 If Guid is NULL, then the default token space is used. If TokenNumber is 0,
884 then the first token number is returned. Otherwise, the token number that
885 follows TokenNumber in the token space is returned. If TokenNumber is the last
886 token number in the token space, then 0 is returned. If TokenNumber is not 0 and
887 is not in the token space specified by Guid, then ASSERT().
888 If Fail to get next token, then ASSERT_EFI_ERROR().
890 @param[in] Guid Pointer to a 128-bit unique value that designates which namespace
891 to set a value from. If NULL, then the default token space is used.
892 @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD
895 @retval UINTN The next valid token number.
901 IN CONST GUID
*Guid
, OPTIONAL
907 Status
= (GetPcdProtocol ())->GetNextToken (Guid
, &TokenNumber
);
909 ASSERT_EFI_ERROR (Status
);
917 Retrieves the next PCD token space from a token space specified by Guid.
918 Guid of NULL is reserved to mark the default local token namespace on the current
919 platform. If Guid is NULL, then the GUID of the first non-local token space of the
920 current platform is returned. If Guid is the last non-local token space,
921 then NULL is returned.
923 If Guid is not NULL and is not a valid token space in the current platform, then ASSERT().
924 If fail to get next token space, then ASSERT_EFI_ERROR().
926 @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace
929 @retval CONST GUID * The next valid token namespace.
934 LibPcdGetNextTokenSpace (
940 Status
= (GetPcdProtocol ())->GetNextTokenSpace (&Guid
);
942 ASSERT_EFI_ERROR (Status
);
944 return (GUID
*) Guid
;
949 Sets the PCD entry specified by PatchVariable to the value specified by Buffer
950 and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than
951 MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return
952 NULL to indicate that the set operation was not actually performed.
953 If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to
954 MaximumDatumSize and NULL must be returned.
956 If PatchVariable is NULL, then ASSERT().
957 If SizeOfBuffer is NULL, then ASSERT().
958 If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT().
960 @param[in] PatchVariable A pointer to the global variable in a module that is
961 the target of the set operation.
962 @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable.
963 @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer.
964 In out, returns actual size of buffer is set.
965 @param[in] Buffer A pointer to the buffer to used to set the target variable.
971 IN VOID
*PatchVariable
,
972 IN UINTN MaximumDatumSize
,
973 IN OUT UINTN
*SizeOfBuffer
,
974 IN CONST VOID
*Buffer
977 ASSERT (PatchVariable
!= NULL
);
978 ASSERT (SizeOfBuffer
!= NULL
);
980 if (*SizeOfBuffer
> 0) {
981 ASSERT (Buffer
!= NULL
);
984 if ((*SizeOfBuffer
> MaximumDatumSize
) ||
985 (*SizeOfBuffer
== MAX_ADDRESS
)) {
986 *SizeOfBuffer
= MaximumDatumSize
;
990 CopyMem (PatchVariable
, Buffer
, *SizeOfBuffer
);
992 return (VOID
*) Buffer
;