2 All Pcd Ppi services are implemented here.
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 /// Instance of PCD_PPI protocol is EDKII native implementation.
20 /// This protocol instance support dynamic and dynamicEx type PCDs.
22 PCD_PPI mPcdPpiInstance
= {
55 PeiRegisterCallBackOnSet
,
56 PcdUnRegisterCallBackOnSet
,
58 PeiPcdGetNextTokenSpace
62 /// Instance of EFI_PEI_PCD_PPI which is defined in PI 1.2 Vol 3.
63 /// This PPI instance only support dyanmicEx type PCD.
65 EFI_PEI_PCD_PPI mEfiPcdPpiInstance
= {
81 (EFI_PEI_PCD_PPI_CALLBACK_ON_SET
) PeiRegisterCallBackOnSet
,
82 (EFI_PEI_PCD_PPI_CANCEL_CALLBACK
) PcdUnRegisterCallBackOnSet
,
84 PeiPcdGetNextTokenSpace
88 /// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.
89 /// This protocol instance support dynamic and dynamicEx type PCDs.
91 GET_PCD_INFO_PPI mGetPcdInfoInstance
= {
93 PeiGetPcdInfoGetInfoEx
,
98 /// Instance of EFI_GET_PCD_INFO_PPI which is defined in PI 1.2.1 Vol 3.
99 /// This PPI instance only support dyanmicEx type PCD.
101 EFI_GET_PCD_INFO_PPI mEfiGetPcdInfoInstance
= {
102 PeiGetPcdInfoGetInfoEx
,
106 EFI_PEI_PPI_DESCRIPTOR mPpiList
[] = {
108 EFI_PEI_PPI_DESCRIPTOR_PPI
,
113 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
119 EFI_PEI_PPI_DESCRIPTOR mPpiList2
[] = {
121 EFI_PEI_PPI_DESCRIPTOR_PPI
,
126 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
127 &gEfiGetPcdInfoPpiGuid
,
128 &mEfiGetPcdInfoInstance
133 Callback on SET PcdSetNvStoreDefaultId
135 Once PcdSetNvStoreDefaultId is set, the default NV storage will be found from
136 PcdNvStoreDefaultValueBuffer, and built into VariableHob.
138 @param[in] CallBackGuid The PCD token GUID being set.
139 @param[in] CallBackToken The PCD token number being set.
140 @param[in, out] TokenData A pointer to the token data being set.
141 @param[in] TokenDataSize The size, in bytes, of the data being set.
146 PcdSetNvStoreDefaultIdCallBack (
147 IN CONST EFI_GUID
*CallBackGuid
, OPTIONAL
148 IN UINTN CallBackToken
,
149 IN OUT VOID
*TokenData
,
150 IN UINTN TokenDataSize
159 UINT8
*VarStoreHobData
;
162 VARIABLE_STORE_HEADER
*NvStoreBuffer
;
163 PCD_DEFAULT_DATA
*DataHeader
;
164 PCD_DEFAULT_INFO
*DefaultInfo
;
165 PCD_DATA_DELTA
*DeltaData
;
167 DefaultId
= *(UINT16
*) TokenData
;
168 SkuId
= GetPcdDatabase()->SystemSkuId
;
171 if (PeiPcdGetSizeEx (&gEfiMdeModulePkgTokenSpaceGuid
, PcdToken (PcdNvStoreDefaultValueBuffer
)) > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER
)) {
172 DataBuffer
= (UINT8
*) PeiPcdGetPtrEx (&gEfiMdeModulePkgTokenSpaceGuid
, PcdToken (PcdNvStoreDefaultValueBuffer
));
173 FullSize
= ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER
*) DataBuffer
)->Length
;
174 DataHeader
= (PCD_DEFAULT_DATA
*) (DataBuffer
+ sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER
));
176 // The first section data includes NV storage default setting.
178 NvStoreBuffer
= (VARIABLE_STORE_HEADER
*) ((UINT8
*) DataHeader
+ sizeof (DataHeader
->DataSize
) + DataHeader
->HeaderSize
);
179 VarStoreHobData
= (UINT8
*) BuildGuidHob (&NvStoreBuffer
->Signature
, NvStoreBuffer
->Size
);
180 ASSERT (VarStoreHobData
!= NULL
);
181 CopyMem (VarStoreHobData
, NvStoreBuffer
, NvStoreBuffer
->Size
);
183 // Find the matched SkuId and DefaultId in the first section
185 DefaultInfo
= &(DataHeader
->DefaultInfo
[0]);
186 BufferEnd
= (UINT8
*) DataHeader
+ sizeof (DataHeader
->DataSize
) + DataHeader
->HeaderSize
;
187 while ((UINT8
*) DefaultInfo
< BufferEnd
) {
188 if (DefaultInfo
->DefaultId
== DefaultId
&& DefaultInfo
->SkuId
== SkuId
) {
195 // Find the matched SkuId and DefaultId in the remaining section
197 Index
= sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER
) + ((DataHeader
->DataSize
+ 7) & (~7));
198 DataHeader
= (PCD_DEFAULT_DATA
*) (DataBuffer
+ Index
);
199 while (!IsFound
&& Index
< FullSize
&& DataHeader
->DataSize
!= 0xFFFFFFFF) {
200 DefaultInfo
= &(DataHeader
->DefaultInfo
[0]);
201 BufferEnd
= (UINT8
*) DataHeader
+ sizeof (DataHeader
->DataSize
) + DataHeader
->HeaderSize
;
202 while ((UINT8
*) DefaultInfo
< BufferEnd
) {
203 if (DefaultInfo
->DefaultId
== DefaultId
&& DefaultInfo
->SkuId
== SkuId
) {
210 DeltaData
= (PCD_DATA_DELTA
*) BufferEnd
;
211 BufferEnd
= (UINT8
*) DataHeader
+ DataHeader
->DataSize
;
212 while ((UINT8
*) DeltaData
< BufferEnd
) {
213 *(VarStoreHobData
+ DeltaData
->Offset
) = (UINT8
) DeltaData
->Value
;
218 Index
= (Index
+ DataHeader
->DataSize
+ 7) & (~7) ;
219 DataHeader
= (PCD_DEFAULT_DATA
*) (DataBuffer
+ Index
);
223 Status
= PcdUnRegisterCallBackOnSet (
224 &gEfiMdeModulePkgTokenSpaceGuid
,
225 PcdToken(PcdSetNvStoreDefaultId
),
226 PcdSetNvStoreDefaultIdCallBack
228 ASSERT_EFI_ERROR (Status
);
232 Main entry for PCD PEIM driver.
234 This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.
236 @param FileHandle Handle of the file being invoked.
237 @param PeiServices Describes the list of possible PEI Services.
239 @return Status of install PCD_PPI
245 IN EFI_PEI_FILE_HANDLE FileHandle
,
246 IN CONST EFI_PEI_SERVICES
**PeiServices
251 BuildPcdDatabase (FileHandle
);
254 // Install PCD_PPI and EFI_PEI_PCD_PPI.
256 Status
= PeiServicesInstallPpi (&mPpiList
[0]);
257 ASSERT_EFI_ERROR (Status
);
260 // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.
262 Status
= PeiServicesInstallPpi (&mPpiList2
[0]);
263 ASSERT_EFI_ERROR (Status
);
265 Status
= PeiRegisterCallBackOnSet (
266 &gEfiMdeModulePkgTokenSpaceGuid
,
267 PcdToken(PcdSetNvStoreDefaultId
),
268 PcdSetNvStoreDefaultIdCallBack
270 ASSERT_EFI_ERROR (Status
);
276 Retrieve additional information associated with a PCD token in the default token space.
278 This includes information such as the type of value the TokenNumber is associated with as well as possible
279 human readable name that is associated with the token.
281 @param[in] TokenNumber The PCD token number.
282 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
283 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
285 @retval EFI_SUCCESS The PCD information was returned successfully.
286 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
290 PeiGetPcdInfoGetInfo (
291 IN UINTN TokenNumber
,
292 OUT EFI_PCD_INFO
*PcdInfo
295 return PeiGetPcdInfo (NULL
, TokenNumber
, PcdInfo
);
299 Retrieve additional information associated with a PCD token.
301 This includes information such as the type of value the TokenNumber is associated with as well as possible
302 human readable name that is associated with the token.
304 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
305 @param[in] TokenNumber The PCD token number.
306 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
307 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
309 @retval EFI_SUCCESS The PCD information was returned successfully.
310 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
314 PeiGetPcdInfoGetInfoEx (
315 IN CONST EFI_GUID
*Guid
,
316 IN UINTN TokenNumber
,
317 OUT EFI_PCD_INFO
*PcdInfo
320 return PeiGetPcdInfo (Guid
, TokenNumber
, PcdInfo
);
324 Retrieve the currently set SKU Id.
326 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the
327 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
332 PeiGetPcdInfoGetSku (
336 return (UINTN
) GetPcdDatabase()->SystemSkuId
;
340 Sets the SKU value for subsequent calls to set or get PCD token values.
342 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
343 SetSku() is normally called only once by the system.
345 For each item (token), the database can hold a single value that applies to all SKUs,
346 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
347 SKU-specific values are called SKU enabled.
349 The SKU Id of zero is reserved as a default.
350 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
351 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
352 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
353 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
354 set for that Id, the results are unpredictable.
356 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
357 set values associated with a PCD token.
366 PEI_PCD_DATABASE
*PeiPcdDb
;
370 PeiPcdDb
= GetPcdDatabase();
372 if (SkuId
== PeiPcdDb
->SystemSkuId
) {
374 // The input SKU Id is equal to current SKU Id, return directly.
379 if (PeiPcdDb
->SystemSkuId
!= (SKU_ID
) 0) {
380 DEBUG ((DEBUG_ERROR
, "PcdPei - The SKU Id could be changed only once."));
383 "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",
384 PeiPcdDb
->SystemSkuId
,
391 SkuIdTable
= (SKU_ID
*) ((UINT8
*) PeiPcdDb
+ PeiPcdDb
->SkuIdTableOffset
);
392 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
393 if (SkuId
== SkuIdTable
[Index
+ 1]) {
394 DEBUG ((EFI_D_INFO
, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID
) SkuId
));
395 PeiPcdDb
->SystemSkuId
= (SKU_ID
) SkuId
;
401 // Invalid input SkuId, the default SKU Id will be still used for the system.
403 DEBUG ((EFI_D_INFO
, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));
408 Retrieves an 8-bit value for a given PCD token.
410 Retrieves the current byte-sized value for a PCD token number.
411 If the TokenNumber is invalid, the results are unpredictable.
413 @param[in] TokenNumber The PCD token number.
415 @return The UINT8 value.
424 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
428 Retrieves an 16-bit value for a given PCD token.
430 Retrieves the current 16-bits value for a PCD token number.
431 If the TokenNumber is invalid, the results are unpredictable.
433 @param[in] TokenNumber The PCD token number.
435 @return The UINT16 value.
444 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
448 Retrieves an 32-bit value for a given PCD token.
450 Retrieves the current 32-bits value for a PCD token number.
451 If the TokenNumber is invalid, the results are unpredictable.
453 @param[in] TokenNumber The PCD token number.
455 @return The UINT32 value.
464 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
468 Retrieves an 64-bit value for a given PCD token.
470 Retrieves the current 64-bits value for a PCD token number.
471 If the TokenNumber is invalid, the results are unpredictable.
473 @param[in] TokenNumber The PCD token number.
475 @return The UINT64 value.
484 return ReadUnaligned64 (GetWorker (TokenNumber
, sizeof (UINT64
)));
488 Retrieves a pointer to a value for a given PCD token.
490 Retrieves the current pointer to the buffer for a PCD token number.
491 Do not make any assumptions about the alignment of the pointer that
492 is returned by this function call. If the TokenNumber is invalid,
493 the results are unpredictable.
495 @param[in] TokenNumber The PCD token number.
497 @return The pointer to the buffer to be retrieved.
506 return GetWorker (TokenNumber
, 0);
510 Retrieves a Boolean value for a given PCD token.
512 Retrieves the current boolean value for a PCD token number.
513 Do not make any assumptions about the alignment of the pointer that
514 is returned by this function call. If the TokenNumber is invalid,
515 the results are unpredictable.
517 @param[in] TokenNumber The PCD token number.
519 @return The Boolean value.
528 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
532 Retrieves the size of the value for a given PCD token.
534 Retrieves the current size of a particular PCD token.
535 If the TokenNumber is invalid, the results are unpredictable.
537 @param[in] TokenNumber The PCD token number.
539 @return The size of the value for the PCD token.
548 PEI_PCD_DATABASE
*PeiPcdDb
;
551 UINT32 LocalTokenCount
;
553 PeiPcdDb
= GetPcdDatabase ();
554 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
556 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
557 // We have to decrement TokenNumber by 1 to make it usable
558 // as the array index.
562 // EBC compiler is very choosy. It may report warning about comparison
563 // between UINTN and 0 . So we add 1 in each size of the
565 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
567 Size
= (*((UINT32
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->LocalTokenNumberTableOffset
) + TokenNumber
) & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
571 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
573 return GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
581 Retrieves an 8-bit value for a given PCD token.
583 Retrieves the 8-bit value of a particular PCD token.
584 If the TokenNumber is invalid or the token space
585 specified by Guid does not exist, the results are
588 @param[in] Guid The token space for the token number.
589 @param[in] ExTokenNumber The PCD token number.
591 @return The size 8-bit value for the PCD token.
597 IN CONST EFI_GUID
*Guid
,
598 IN UINTN ExTokenNumber
601 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT8
)));
605 Retrieves an 16-bit value for a given PCD token.
607 Retrieves the 16-bit value of a particular PCD token.
608 If the TokenNumber is invalid or the token space
609 specified by Guid does not exist, the results are
612 @param[in] Guid The token space for the token number.
613 @param[in] ExTokenNumber The PCD token number.
615 @return The size 16-bit value for the PCD token.
621 IN CONST EFI_GUID
*Guid
,
622 IN UINTN ExTokenNumber
625 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT16
)));
629 Retrieves an 32-bit value for a given PCD token.
631 Retrieves the 32-bit value of a particular PCD token.
632 If the TokenNumber is invalid or the token space
633 specified by Guid does not exist, the results are
636 @param[in] Guid The token space for the token number.
637 @param[in] ExTokenNumber The PCD token number.
639 @return The size 32-bit value for the PCD token.
645 IN CONST EFI_GUID
*Guid
,
646 IN UINTN ExTokenNumber
649 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT32
)));
653 Retrieves an 64-bit value for a given PCD token.
655 Retrieves the 64-bit value of a particular PCD token.
656 If the TokenNumber is invalid or the token space
657 specified by Guid does not exist, the results are
660 @param[in] Guid The token space for the token number.
661 @param[in] ExTokenNumber The PCD token number.
663 @return The size 64-bit value for the PCD token.
669 IN CONST EFI_GUID
*Guid
,
670 IN UINTN ExTokenNumber
673 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT64
)));
677 Retrieves a pointer to a value for a given PCD token.
679 Retrieves the current pointer to the buffer for a PCD token number.
680 Do not make any assumptions about the alignment of the pointer that
681 is returned by this function call. If the TokenNumber is invalid,
682 the results are unpredictable.
684 @param[in] Guid The token space for the token number.
685 @param[in] ExTokenNumber The PCD token number.
687 @return The pointer to the buffer to be retrieved.
693 IN CONST EFI_GUID
*Guid
,
694 IN UINTN ExTokenNumber
697 return ExGetWorker (Guid
, ExTokenNumber
, 0);
701 Retrieves an Boolean value for a given PCD token.
703 Retrieves the Boolean value of a particular PCD token.
704 If the TokenNumber is invalid or the token space
705 specified by Guid does not exist, the results are
708 @param[in] Guid The token space for the token number.
709 @param[in] ExTokenNumber The PCD token number.
711 @return The size Boolean value for the PCD token.
717 IN CONST EFI_GUID
*Guid
,
718 IN UINTN ExTokenNumber
721 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (BOOLEAN
)));
725 Retrieves the size of the value for a given PCD token.
727 Retrieves the current size of a particular PCD token.
728 If the TokenNumber is invalid, the results are unpredictable.
730 @param[in] Guid The token space for the token number.
731 @param[in] ExTokenNumber The PCD token number.
733 @return The size of the value for the PCD token.
739 IN CONST EFI_GUID
*Guid
,
740 IN UINTN ExTokenNumber
743 return PeiPcdGetSize (GetExPcdTokenNumber (Guid
, ExTokenNumber
));
747 Sets an 8-bit value for a given PCD token.
749 When the PCD service sets a value, it will check to ensure that the
750 size of the value being set is compatible with the Token's existing definition.
751 If it is not, an error will be returned.
753 @param[in] TokenNumber The PCD token number.
754 @param[in] Value The value to set for the PCD token.
756 @retval EFI_SUCCESS Procedure returned successfully.
757 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
758 being set was incompatible with a call to this function.
759 Use GetSize() to retrieve the size of the target data.
760 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
766 IN UINTN TokenNumber
,
770 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
774 Sets an 16-bit value for a given PCD token.
776 When the PCD service sets a value, it will check to ensure that the
777 size of the value being set is compatible with the Token's existing definition.
778 If it is not, an error will be returned.
780 @param[in] TokenNumber The PCD token number.
781 @param[in] Value The value to set for the PCD token.
783 @retval EFI_SUCCESS Procedure returned successfully.
784 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
785 being set was incompatible with a call to this function.
786 Use GetSize() to retrieve the size of the target data.
787 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
793 IN UINTN TokenNumber
,
797 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
801 Sets an 32-bit value for a given PCD token.
803 When the PCD service sets a value, it will check to ensure that the
804 size of the value being set is compatible with the Token's existing definition.
805 If it is not, an error will be returned.
807 @param[in] TokenNumber The PCD token number.
808 @param[in] Value The value to set for the PCD token.
810 @retval EFI_SUCCESS Procedure returned successfully.
811 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
812 being set was incompatible with a call to this function.
813 Use GetSize() to retrieve the size of the target data.
814 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
820 IN UINTN TokenNumber
,
824 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
828 Sets an 64-bit value for a given PCD token.
830 When the PCD service sets a value, it will check to ensure that the
831 size of the value being set is compatible with the Token's existing definition.
832 If it is not, an error will be returned.
834 @param[in] TokenNumber The PCD token number.
835 @param[in] Value The value to set for the PCD token.
837 @retval EFI_SUCCESS Procedure returned successfully.
838 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
839 being set was incompatible with a call to this function.
840 Use GetSize() to retrieve the size of the target data.
841 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
847 IN UINTN TokenNumber
,
851 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
855 Sets a value of a specified size for a given PCD token.
857 When the PCD service sets a value, it will check to ensure that the
858 size of the value being set is compatible with the Token's existing definition.
859 If it is not, an error will be returned.
861 @param[in] TokenNumber The PCD token number.
862 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
863 On input, if the SizeOfValue is greater than the maximum size supported
864 for this TokenNumber then the output value of SizeOfValue will reflect
865 the maximum size supported for this TokenNumber.
866 @param[in] Buffer The buffer to set for the PCD token.
868 @retval EFI_SUCCESS Procedure returned successfully.
869 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
870 being set was incompatible with a call to this function.
871 Use GetSize() to retrieve the size of the target data.
872 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
878 IN UINTN TokenNumber
,
879 IN OUT UINTN
*SizeOfBuffer
,
883 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
887 Sets an Boolean value for a given PCD token.
889 When the PCD service sets a value, it will check to ensure that the
890 size of the value being set is compatible with the Token's existing definition.
891 If it is not, an error will be returned.
893 @param[in] TokenNumber The PCD token number.
894 @param[in] Value The value to set for the PCD token.
896 @retval EFI_SUCCESS Procedure returned successfully.
897 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
898 being set was incompatible with a call to this function.
899 Use GetSize() to retrieve the size of the target data.
900 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
906 IN UINTN TokenNumber
,
910 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
914 Sets an 8-bit value for a given PCD token.
916 When the PCD service sets a value, it will check to ensure that the
917 size of the value being set is compatible with the Token's existing definition.
918 If it is not, an error will be returned.
920 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
921 @param[in] ExTokenNumber The PCD token number.
922 @param[in] Value The value to set for the PCD token.
924 @retval EFI_SUCCESS Procedure returned successfully.
925 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
926 being set was incompatible with a call to this function.
927 Use GetSize() to retrieve the size of the target data.
928 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
934 IN CONST EFI_GUID
*Guid
,
935 IN UINTN ExTokenNumber
,
939 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
943 Sets an 16-bit value for a given PCD token.
945 When the PCD service sets a value, it will check to ensure that the
946 size of the value being set is compatible with the Token's existing definition.
947 If it is not, an error will be returned.
949 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
950 @param[in] ExTokenNumber The PCD token number.
951 @param[in] Value The value to set for the PCD token.
953 @retval EFI_SUCCESS Procedure returned successfully.
954 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
955 being set was incompatible with a call to this function.
956 Use GetSize() to retrieve the size of the target data.
957 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
963 IN CONST EFI_GUID
*Guid
,
964 IN UINTN ExTokenNumber
,
968 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
972 Sets an 32-bit value for a given PCD token.
974 When the PCD service sets a value, it will check to ensure that the
975 size of the value being set is compatible with the Token's existing definition.
976 If it is not, an error will be returned.
978 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
979 @param[in] ExTokenNumber The PCD token number.
980 @param[in] Value The value to set for the PCD token.
982 @retval EFI_SUCCESS Procedure returned successfully.
983 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
984 being set was incompatible with a call to this function.
985 Use GetSize() to retrieve the size of the target data.
986 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
992 IN CONST EFI_GUID
*Guid
,
993 IN UINTN ExTokenNumber
,
997 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
1001 Sets an 64-bit value for a given PCD token.
1003 When the PCD service sets a value, it will check to ensure that the
1004 size of the value being set is compatible with the Token's existing definition.
1005 If it is not, an error will be returned.
1007 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1008 @param[in] ExTokenNumber The PCD token number.
1009 @param[in] Value The value to set for the PCD token.
1011 @retval EFI_SUCCESS Procedure returned successfully.
1012 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1013 being set was incompatible with a call to this function.
1014 Use GetSize() to retrieve the size of the target data.
1015 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1021 IN CONST EFI_GUID
*Guid
,
1022 IN UINTN ExTokenNumber
,
1026 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
1030 Sets a value of a specified size for a given PCD token.
1032 When the PCD service sets a value, it will check to ensure that the
1033 size of the value being set is compatible with the Token's existing definition.
1034 If it is not, an error will be returned.
1036 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1037 @param[in] ExTokenNumber The PCD token number.
1038 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
1039 On input, if the SizeOfValue is greater than the maximum size supported
1040 for this TokenNumber then the output value of SizeOfValue will reflect
1041 the maximum size supported for this TokenNumber.
1042 @param[in] Value The buffer to set for the PCD token.
1044 @retval EFI_SUCCESS Procedure returned successfully.
1045 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1046 being set was incompatible with a call to this function.
1047 Use GetSize() to retrieve the size of the target data.
1048 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1054 IN CONST EFI_GUID
*Guid
,
1055 IN UINTN ExTokenNumber
,
1056 IN OUT UINTN
*SizeOfBuffer
,
1060 return ExSetWorker (ExTokenNumber
, Guid
, Value
, SizeOfBuffer
, TRUE
);
1064 Sets an Boolean value for a given PCD token.
1066 When the PCD service sets a value, it will check to ensure that the
1067 size of the value being set is compatible with the Token's existing definition.
1068 If it is not, an error will be returned.
1070 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1071 @param [in] ExTokenNumber The PCD token number.
1072 @param [in] Value The value to set for the PCD token.
1074 @retval EFI_SUCCESS Procedure returned successfully.
1075 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1076 being set was incompatible with a call to this function.
1077 Use GetSize() to retrieve the size of the target data.
1078 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1084 IN CONST EFI_GUID
*Guid
,
1085 IN UINTN ExTokenNumber
,
1089 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
1093 Specifies a function to be called anytime the value of a designated token is changed.
1095 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1096 @param[in] ExTokenNumber The PCD token number.
1097 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1099 @retval EFI_SUCCESS The PCD service has successfully established a call event
1100 for the CallBackToken requested.
1101 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1106 PeiRegisterCallBackOnSet (
1107 IN CONST EFI_GUID
*Guid
, OPTIONAL
1108 IN UINTN ExTokenNumber
,
1109 IN PCD_PPI_CALLBACK CallBackFunction
1112 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
1113 return EFI_UNSUPPORTED
;
1116 if (CallBackFunction
== NULL
) {
1117 return EFI_INVALID_PARAMETER
;
1120 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, TRUE
);
1124 Cancels a previously set callback function for a particular PCD token number.
1126 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1127 @param[in] ExTokenNumber The PCD token number.
1128 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1130 @retval EFI_SUCCESS The PCD service has successfully established a call event
1131 for the CallBackToken requested.
1132 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1137 PcdUnRegisterCallBackOnSet (
1138 IN CONST EFI_GUID
*Guid
, OPTIONAL
1139 IN UINTN ExTokenNumber
,
1140 IN PCD_PPI_CALLBACK CallBackFunction
1143 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
1144 return EFI_UNSUPPORTED
;
1147 if (CallBackFunction
== NULL
) {
1148 return EFI_INVALID_PARAMETER
;
1151 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, FALSE
);
1155 Retrieves the next valid token number in a given namespace.
1157 This is useful since the PCD infrastructure contains a sparse list of token numbers,
1158 and one cannot a priori know what token numbers are valid in the database.
1160 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
1161 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
1162 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
1163 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
1164 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
1165 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
1166 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1167 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1170 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1171 This is an optional parameter that may be NULL. If this parameter is NULL, then a request
1172 is being made to retrieve tokens from the default token space.
1173 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
1175 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
1176 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.
1181 PeiPcdGetNextToken (
1182 IN CONST EFI_GUID
*Guid
, OPTIONAL
1183 IN OUT UINTN
*TokenNumber
1187 PEI_PCD_DATABASE
*PeiPcdDb
;
1188 EFI_GUID
*MatchGuid
;
1189 EFI_GUID
*GuidTable
;
1190 DYNAMICEX_MAPPING
*ExMapTable
;
1193 BOOLEAN PeiExMapTableEmpty
;
1194 UINTN PeiNexTokenNumber
;
1196 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
1197 return EFI_UNSUPPORTED
;
1200 PeiPcdDb
= GetPcdDatabase ();
1201 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
1202 GuidTable
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
);
1204 if (PeiPcdDb
->ExTokenCount
== 0) {
1205 PeiExMapTableEmpty
= TRUE
;
1207 PeiExMapTableEmpty
= FALSE
;
1210 if (*TokenNumber
> PeiNexTokenNumber
) {
1211 return EFI_NOT_FOUND
;
1214 if (*TokenNumber
> PeiNexTokenNumber
) {
1215 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1216 return EFI_NOT_FOUND
;
1220 if (PeiExMapTableEmpty
) {
1221 return EFI_NOT_FOUND
;
1224 MatchGuid
= ScanGuid (GuidTable
, PeiPcdDb
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
1226 if (MatchGuid
== NULL
) {
1227 return EFI_NOT_FOUND
;
1230 GuidTableIdx
= MatchGuid
- GuidTable
;
1232 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->ExMapTableOffset
);
1236 // Locate the GUID in ExMapTable first.
1238 for (Index
= 0; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
1239 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1247 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
1248 // token number in found token space.
1250 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
1251 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
1255 for ( ; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
1256 if ((ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) && (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
)) {
1261 while (Index
< PeiPcdDb
->ExTokenCount
) {
1263 if (Index
== PeiPcdDb
->ExTokenCount
) {
1265 // Exceed the length of ExMap Table
1267 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1268 return EFI_NOT_FOUND
;
1269 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1271 // Found the next match
1273 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
1280 return EFI_NOT_FOUND
;
1284 Retrieves the next valid PCD token namespace for a given namespace.
1286 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid
1287 token namespaces on a platform.
1289 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token
1290 namespace from which the search will start. On output, it designates the next valid
1291 token namespace on the platform. If *Guid is NULL, then the GUID of the first token
1292 space of the current platform is returned. If the search cannot locate the next valid
1293 token namespace, an error is returned and the value of *Guid is undefined.
1295 @retval EFI_SUCCESS The PCD service retrieved the value requested.
1296 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.
1301 PeiPcdGetNextTokenSpace (
1302 IN OUT CONST EFI_GUID
**Guid
1306 EFI_GUID
*MatchGuid
;
1307 PEI_PCD_DATABASE
*PeiPcdDb
;
1308 DYNAMICEX_MAPPING
*ExMapTable
;
1312 BOOLEAN PeiExMapTableEmpty
;
1313 EFI_GUID
*GuidTable
;
1315 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
1316 return EFI_UNSUPPORTED
;
1319 ASSERT (Guid
!= NULL
);
1321 PeiPcdDb
= GetPcdDatabase ();
1323 if (PeiPcdDb
->ExTokenCount
== 0) {
1324 PeiExMapTableEmpty
= TRUE
;
1326 PeiExMapTableEmpty
= FALSE
;
1329 if (PeiExMapTableEmpty
) {
1330 return EFI_NOT_FOUND
;
1333 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->ExMapTableOffset
);
1334 GuidTable
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
);
1336 if (*Guid
== NULL
) {
1338 // return the first Token Space Guid.
1340 *Guid
= GuidTable
+ ExMapTable
[0].ExGuidIndex
;
1344 MatchGuid
= ScanGuid (GuidTable
, PeiPcdDb
->GuidTableCount
* sizeof(GuidTable
[0]), *Guid
);
1346 if (MatchGuid
== NULL
) {
1347 return EFI_NOT_FOUND
;
1350 GuidTableIdx
= MatchGuid
- GuidTable
;
1353 for (Index
= 0; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
1354 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1362 for ( ; Index
< PeiPcdDb
->ExTokenCount
; Index
++ ) {
1363 if (ExMapTable
[Index
].ExGuidIndex
!= GuidTableIdx
) {
1365 for (Index2
= 0 ; Index2
< Index
; Index2
++) {
1366 if (ExMapTable
[Index2
].ExGuidIndex
== ExMapTable
[Index
].ExGuidIndex
) {
1368 // This token namespace should have been found and output at preceding getting.
1375 *Guid
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
) + ExMapTable
[Index
].ExGuidIndex
;
1383 return EFI_NOT_FOUND
;
1388 Get PCD value's size for POINTER type PCD.
1390 The POINTER type PCD's value will be stored into a buffer in specified size.
1391 The max size of this PCD's value is described in PCD's definition in DEC file.
1393 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1394 @param MaxSize Maximum size of PCD's value
1395 @param Database Pcd database in PEI phase.
1397 @return PCD value's size for POINTER type PCD.
1402 IN UINTN LocalTokenNumberTableIdx
,
1404 IN PEI_PCD_DATABASE
*Database
1408 UINTN LocalTokenNumber
;
1410 SIZE_INFO
*SizeTable
;
1413 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1415 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1417 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1419 SizeTable
= (SIZE_INFO
*)((UINT8
*)Database
+ Database
->SizeTableOffset
);
1421 *MaxSize
= SizeTable
[SizeTableIdx
];
1423 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1426 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1428 // We have only two entry for VPD enabled PCD entry:
1431 // We consider current size is equal to MAX size.
1435 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1437 // We have only two entry for Non-Sku enabled PCD entry:
1441 return SizeTable
[SizeTableIdx
+ 1];
1444 // We have these entry for SKU enabled PCD entry
1446 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1448 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1449 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1450 if (SkuIdTable
[1 + Index
] == Database
->SystemSkuId
) {
1451 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1454 return SizeTable
[SizeTableIdx
+ 1];
1460 Set PCD value's size for POINTER type PCD.
1462 The POINTER type PCD's value will be stored into a buffer in specified size.
1463 The max size of this PCD's value is described in PCD's definition in DEC file.
1465 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1466 @param CurrentSize Maximum size of PCD's value
1467 @param Database Pcd database in PEI phase.
1469 @retval TRUE Success to set PCD's value size, which is not exceed maximum size
1470 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size
1475 IN UINTN LocalTokenNumberTableIdx
,
1476 IN OUT UINTN
*CurrentSize
,
1477 IN PEI_PCD_DATABASE
*Database
1481 UINTN LocalTokenNumber
;
1483 SIZE_INFO
*SizeTable
;
1487 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1489 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1491 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1493 SizeTable
= (SIZE_INFO
*)((UINT8
*)Database
+ Database
->SizeTableOffset
);
1495 MaxSize
= SizeTable
[SizeTableIdx
];
1497 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1500 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1502 // We shouldn't come here as we don't support SET for VPD
1507 if ((*CurrentSize
> MaxSize
) ||
1508 (*CurrentSize
== MAX_ADDRESS
)) {
1509 *CurrentSize
= MaxSize
;
1513 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1515 // We have only two entry for Non-Sku enabled PCD entry:
1519 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1523 // We have these entry for SKU enabled PCD entry
1525 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1527 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1528 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1529 if (SkuIdTable
[1 + Index
] == Database
->SystemSkuId
) {
1530 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1534 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;