]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/PCD/Dxe/Pcd.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Dxe / Pcd.c
CommitLineData
80408db0 1/** @file\r
2ab6330e 2 PCD DXE driver manage all PCD entry initialized in PEI phase and DXE phase, and\r
8a541f0a 3 produce the implementation of native PCD protocol and EFI_PCD_PROTOCOL defined in\r
120ca3ce 4 PI 1.4a Vol3.\r
80408db0 5\r
d1102dba 6Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
80408db0 8\r
80408db0 9**/\r
10\r
80408db0 11#include "Service.h"\r
12\r
2ab6330e 13///\r
14/// PCD database lock.\r
15///\r
1436aea4 16EFI_LOCK mPcdDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\r
80408db0 17\r
17e7fa8f 18///\r
d1102dba 19/// PCD_PROTOCOL the EDKII native implementation which support dynamic\r
17e7fa8f 20/// type and dynamicEx type PCDs.\r
21///\r
1436aea4 22PCD_PROTOCOL mPcdInstance = {\r
80408db0 23 DxePcdSetSku,\r
24\r
25 DxePcdGet8,\r
26 DxePcdGet16,\r
27 DxePcdGet32,\r
28 DxePcdGet64,\r
29 DxePcdGetPtr,\r
30 DxePcdGetBool,\r
31 DxePcdGetSize,\r
32\r
33 DxePcdGet8Ex,\r
34 DxePcdGet16Ex,\r
35 DxePcdGet32Ex,\r
36 DxePcdGet64Ex,\r
37 DxePcdGetPtrEx,\r
38 DxePcdGetBoolEx,\r
39 DxePcdGetSizeEx,\r
40\r
41 DxePcdSet8,\r
42 DxePcdSet16,\r
43 DxePcdSet32,\r
44 DxePcdSet64,\r
45 DxePcdSetPtr,\r
46 DxePcdSetBool,\r
47\r
48 DxePcdSet8Ex,\r
49 DxePcdSet16Ex,\r
50 DxePcdSet32Ex,\r
51 DxePcdSet64Ex,\r
52 DxePcdSetPtrEx,\r
53 DxePcdSetBoolEx,\r
54\r
55 DxeRegisterCallBackOnSet,\r
56 DxeUnRegisterCallBackOnSet,\r
57 DxePcdGetNextToken,\r
58 DxePcdGetNextTokenSpace\r
59};\r
60\r
17e7fa8f 61///\r
62/// EFI_PCD_PROTOCOL is defined in PI 1.2 Vol 3 which only support dynamicEx type\r
63/// PCD.\r
64///\r
1436aea4 65EFI_PCD_PROTOCOL mEfiPcdInstance = {\r
c896d682 66 DxePcdSetSku,\r
67 DxePcdGet8Ex,\r
68 DxePcdGet16Ex,\r
69 DxePcdGet32Ex,\r
70 DxePcdGet64Ex,\r
71 DxePcdGetPtrEx,\r
72 DxePcdGetBoolEx,\r
73 DxePcdGetSizeEx,\r
74 DxePcdSet8Ex,\r
75 DxePcdSet16Ex,\r
76 DxePcdSet32Ex,\r
77 DxePcdSet64Ex,\r
78 DxePcdSetPtrEx,\r
79 DxePcdSetBoolEx,\r
1436aea4
MK
80 (EFI_PCD_PROTOCOL_CALLBACK_ON_SET)DxeRegisterCallBackOnSet,\r
81 (EFI_PCD_PROTOCOL_CANCEL_CALLBACK)DxeUnRegisterCallBackOnSet,\r
c896d682 82 DxePcdGetNextToken,\r
83 DxePcdGetNextTokenSpace\r
84};\r
80408db0 85\r
96d6d004
SZ
86///\r
87/// Instance of GET_PCD_INFO_PROTOCOL protocol is EDKII native implementation.\r
88/// This protocol instance support dynamic and dynamicEx type PCDs.\r
89///\r
1436aea4 90GET_PCD_INFO_PROTOCOL mGetPcdInfoInstance = {\r
96d6d004
SZ
91 DxeGetPcdInfoGetInfo,\r
92 DxeGetPcdInfoGetInfoEx,\r
93 DxeGetPcdInfoGetSku\r
94};\r
95\r
96///\r
97/// Instance of EFI_GET_PCD_INFO_PROTOCOL which is defined in PI 1.2.1 Vol 3.\r
98/// This PPI instance only support dyanmicEx type PCD.\r
99///\r
100EFI_GET_PCD_INFO_PROTOCOL mEfiGetPcdInfoInstance = {\r
101 DxeGetPcdInfoGetInfoEx,\r
102 DxeGetPcdInfoGetSku\r
103};\r
104\r
1436aea4
MK
105EFI_HANDLE mPcdHandle = NULL;\r
106UINTN mVpdBaseAddress = 0;\r
80408db0 107\r
2ab6330e 108/**\r
109 Main entry for PCD DXE driver.\r
d1102dba 110\r
2ab6330e 111 This routine initialize the PCD database and install PCD_PROTOCOL.\r
d1102dba 112\r
2ab6330e 113 @param ImageHandle Image handle for PCD DXE driver.\r
114 @param SystemTable Pointer to SystemTable.\r
115\r
116 @return Status of gBS->InstallProtocolInterface()\r
117\r
118**/\r
80408db0 119EFI_STATUS\r
120EFIAPI\r
121PcdDxeInit (\r
1436aea4
MK
122 IN EFI_HANDLE ImageHandle,\r
123 IN EFI_SYSTEM_TABLE *SystemTable\r
80408db0 124 )\r
125{\r
1436aea4
MK
126 EFI_STATUS Status;\r
127 VOID *Registration;\r
23f3e119 128\r
80408db0 129 //\r
130 // Make sure the Pcd Protocol is not already installed in the system\r
131 //\r
132\r
133 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gPcdProtocolGuid);\r
134\r
135 BuildPcdDxeDataBase ();\r
136\r
c896d682 137 //\r
8a541f0a 138 // Install PCD_PROTOCOL to handle dynamic type PCD\r
139 // Install EFI_PCD_PROTOCOL to handle dynamicEx type PCD\r
c896d682 140 //\r
8a541f0a 141 Status = gBS->InstallMultipleProtocolInterfaces (\r
17e7fa8f 142 &mPcdHandle,\r
1436aea4
MK
143 &gPcdProtocolGuid,\r
144 &mPcdInstance,\r
145 &gEfiPcdProtocolGuid,\r
146 &mEfiPcdInstance,\r
17e7fa8f 147 NULL\r
c896d682 148 );\r
80408db0 149 ASSERT_EFI_ERROR (Status);\r
150\r
61d8989f 151 //\r
85d0b97d
SZ
152 // Install GET_PCD_INFO_PROTOCOL to handle dynamic type PCD\r
153 // Install EFI_GET_PCD_INFO_PROTOCOL to handle dynamicEx type PCD\r
61d8989f 154 //\r
85d0b97d
SZ
155 Status = gBS->InstallMultipleProtocolInterfaces (\r
156 &mPcdHandle,\r
1436aea4
MK
157 &gGetPcdInfoProtocolGuid,\r
158 &mGetPcdInfoInstance,\r
159 &gEfiGetPcdInfoProtocolGuid,\r
160 &mEfiGetPcdInfoInstance,\r
85d0b97d
SZ
161 NULL\r
162 );\r
163 ASSERT_EFI_ERROR (Status);\r
96d6d004 164\r
23f3e119
SZ
165 //\r
166 // Register callback function upon VariableLockProtocol\r
167 // to lock the variables referenced by DynamicHii PCDs with RO property set in *.dsc.\r
168 //\r
169 EfiCreateProtocolNotifyEvent (\r
170 &gEdkiiVariableLockProtocolGuid,\r
171 TPL_CALLBACK,\r
172 VariableLockCallBack,\r
173 NULL,\r
174 &Registration\r
175 );\r
176\r
534efca0
LG
177 //\r
178 // Cache VpdBaseAddress in entry point for the following usage.\r
179 //\r
180\r
181 //\r
182 // PcdVpdBaseAddress64 is DynamicEx PCD only. So, DxePcdGet64Ex() is used to get its value.\r
183 //\r
1436aea4 184 mVpdBaseAddress = (UINTN)DxePcdGet64Ex (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdVpdBaseAddress64));\r
534efca0
LG
185 if (mVpdBaseAddress == 0) {\r
186 //\r
187 // PcdVpdBaseAddress64 is not set, get value from PcdVpdBaseAddress.\r
188 //\r
1436aea4 189 mVpdBaseAddress = (UINTN)PcdGet32 (PcdVpdBaseAddress);\r
534efca0
LG
190 }\r
191\r
17e7fa8f 192 return Status;\r
96d6d004
SZ
193}\r
194\r
195/**\r
196 Retrieve additional information associated with a PCD token in the default token space.\r
197\r
198 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
199 human readable name that is associated with the token.\r
200\r
201 @param[in] TokenNumber The PCD token number.\r
202 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
203 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
204\r
205 @retval EFI_SUCCESS The PCD information was returned successfully.\r
206 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
207**/\r
208EFI_STATUS\r
209EFIAPI\r
210DxeGetPcdInfoGetInfo (\r
1436aea4
MK
211 IN UINTN TokenNumber,\r
212 OUT EFI_PCD_INFO *PcdInfo\r
96d6d004
SZ
213 )\r
214{\r
215 return DxeGetPcdInfo (NULL, TokenNumber, PcdInfo);\r
216}\r
217\r
218/**\r
219 Retrieve additional information associated with a PCD token.\r
220\r
221 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
222 human readable name that is associated with the token.\r
80408db0 223\r
96d6d004
SZ
224 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
225 @param[in] TokenNumber The PCD token number.\r
226 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
227 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
228\r
229 @retval EFI_SUCCESS The PCD information was returned successfully.\r
230 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
231**/\r
232EFI_STATUS\r
233EFIAPI\r
234DxeGetPcdInfoGetInfoEx (\r
1436aea4
MK
235 IN CONST EFI_GUID *Guid,\r
236 IN UINTN TokenNumber,\r
237 OUT EFI_PCD_INFO *PcdInfo\r
96d6d004
SZ
238 )\r
239{\r
240 return DxeGetPcdInfo (Guid, TokenNumber, PcdInfo);\r
241}\r
242\r
243/**\r
244 Retrieve the currently set SKU Id.\r
245\r
246 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the\r
247 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r
248 Id is returned.\r
249**/\r
250UINTN\r
251EFIAPI\r
252DxeGetPcdInfoGetSku (\r
253 VOID\r
254 )\r
255{\r
1436aea4 256 return (UINTN)mPcdDatabase.DxeDb->SystemSkuId;\r
80408db0 257}\r
258\r
2ab6330e 259/**\r
260 Sets the SKU value for subsequent calls to set or get PCD token values.\r
261\r
d1102dba 262 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.\r
2ab6330e 263 SetSku() is normally called only once by the system.\r
264\r
d1102dba
LG
265 For each item (token), the database can hold a single value that applies to all SKUs,\r
266 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,\r
267 SKU-specific values are called SKU enabled.\r
268\r
120ca3ce 269 The SKU Id of zero is reserved as a default.\r
d1102dba
LG
270 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the\r
271 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the\r
272 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,\r
273 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been\r
2ab6330e 274 set for that Id, the results are unpredictable.\r
275\r
d1102dba 276 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and\r
2ab6330e 277 set values associated with a PCD token.\r
278\r
2ab6330e 279**/\r
80408db0 280VOID\r
281EFIAPI\r
282DxePcdSetSku (\r
1436aea4 283 IN UINTN SkuId\r
80408db0 284 )\r
285{\r
1436aea4
MK
286 SKU_ID *SkuIdTable;\r
287 UINTN Index;\r
288 EFI_STATUS Status;\r
85d0b97d 289\r
1436aea4 290 DEBUG ((DEBUG_INFO, "PcdDxe - SkuId 0x%lx is to be set.\n", (SKU_ID)SkuId));\r
f71503c3 291\r
2db48a1f
SZ
292 if (SkuId == mPcdDatabase.DxeDb->SystemSkuId) {\r
293 //\r
294 // The input SKU Id is equal to current SKU Id, return directly.\r
295 //\r
f71503c3 296 DEBUG ((DEBUG_INFO, "PcdDxe - SkuId is same to current system Sku.\n"));\r
2db48a1f
SZ
297 return;\r
298 }\r
299\r
1436aea4 300 if (mPcdDatabase.DxeDb->SystemSkuId != (SKU_ID)0) {\r
2db48a1f
SZ
301 DEBUG ((DEBUG_ERROR, "PcdDxe - The SKU Id could be changed only once."));\r
302 DEBUG ((\r
303 DEBUG_ERROR,\r
304 "PcdDxe - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r
305 mPcdDatabase.DxeDb->SystemSkuId,\r
1436aea4 306 (SKU_ID)SkuId\r
2db48a1f
SZ
307 ));\r
308 ASSERT (FALSE);\r
309 return;\r
310 }\r
311\r
1436aea4 312 SkuIdTable = (SKU_ID *)((UINT8 *)mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->SkuIdTableOffset);\r
85d0b97d
SZ
313 for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
314 if (SkuId == SkuIdTable[Index + 1]) {\r
f71503c3 315 DEBUG ((DEBUG_INFO, "PcdDxe - SkuId is found in SkuId table.\n"));\r
7c736265
LG
316 Status = UpdatePcdDatabase (SkuId, TRUE);\r
317 if (!EFI_ERROR (Status)) {\r
1436aea4
MK
318 mPcdDatabase.DxeDb->SystemSkuId = (SKU_ID)SkuId;\r
319 DEBUG ((DEBUG_INFO, "PcdDxe - Set current SKU Id to 0x%lx.\n", (SKU_ID)SkuId));\r
7c736265
LG
320 return;\r
321 }\r
85d0b97d
SZ
322 }\r
323 }\r
324\r
325 //\r
2db48a1f 326 // Invalid input SkuId, the default SKU Id will be still used for the system.\r
85d0b97d 327 //\r
f71503c3 328 DEBUG ((DEBUG_ERROR, "PcdDxe - Invalid input SkuId, the default SKU Id will be still used.\n"));\r
80408db0 329 return;\r
330}\r
331\r
2ab6330e 332/**\r
333 Retrieves an 8-bit value for a given PCD token.\r
80408db0 334\r
d1102dba 335 Retrieves the current byte-sized value for a PCD token number.\r
2ab6330e 336 If the TokenNumber is invalid, the results are unpredictable.\r
d1102dba
LG
337\r
338 @param[in] TokenNumber The PCD token number.\r
80408db0 339\r
2ab6330e 340 @return The UINT8 value.\r
d1102dba 341\r
2ab6330e 342**/\r
80408db0 343UINT8\r
344EFIAPI\r
345DxePcdGet8 (\r
1436aea4 346 IN UINTN TokenNumber\r
80408db0 347 )\r
348{\r
1436aea4 349 return *((UINT8 *)GetWorker (TokenNumber, sizeof (UINT8)));\r
80408db0 350}\r
351\r
2ab6330e 352/**\r
353 Retrieves an 16-bit value for a given PCD token.\r
80408db0 354\r
d1102dba 355 Retrieves the current 16-bits value for a PCD token number.\r
2ab6330e 356 If the TokenNumber is invalid, the results are unpredictable.\r
d1102dba
LG
357\r
358 @param[in] TokenNumber The PCD token number.\r
80408db0 359\r
2ab6330e 360 @return The UINT16 value.\r
d1102dba 361\r
2ab6330e 362**/\r
80408db0 363UINT16\r
364EFIAPI\r
365DxePcdGet16 (\r
1436aea4 366 IN UINTN TokenNumber\r
80408db0 367 )\r
368{\r
369 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
370}\r
371\r
2ab6330e 372/**\r
373 Retrieves an 32-bit value for a given PCD token.\r
80408db0 374\r
d1102dba 375 Retrieves the current 32-bits value for a PCD token number.\r
2ab6330e 376 If the TokenNumber is invalid, the results are unpredictable.\r
d1102dba
LG
377\r
378 @param[in] TokenNumber The PCD token number.\r
80408db0 379\r
2ab6330e 380 @return The UINT32 value.\r
d1102dba 381\r
2ab6330e 382**/\r
80408db0 383UINT32\r
384EFIAPI\r
385DxePcdGet32 (\r
1436aea4 386 IN UINTN TokenNumber\r
80408db0 387 )\r
388{\r
389 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
390}\r
391\r
2ab6330e 392/**\r
393 Retrieves an 64-bit value for a given PCD token.\r
80408db0 394\r
d1102dba 395 Retrieves the current 64-bits value for a PCD token number.\r
2ab6330e 396 If the TokenNumber is invalid, the results are unpredictable.\r
d1102dba
LG
397\r
398 @param[in] TokenNumber The PCD token number.\r
80408db0 399\r
2ab6330e 400 @return The UINT64 value.\r
d1102dba 401\r
2ab6330e 402**/\r
80408db0 403UINT64\r
404EFIAPI\r
405DxePcdGet64 (\r
1436aea4 406 IN UINTN TokenNumber\r
80408db0 407 )\r
408{\r
1436aea4 409 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r
80408db0 410}\r
411\r
2ab6330e 412/**\r
413 Retrieves a pointer to a value for a given PCD token.\r
80408db0 414\r
d1102dba
LG
415 Retrieves the current pointer to the buffer for a PCD token number.\r
416 Do not make any assumptions about the alignment of the pointer that\r
417 is returned by this function call. If the TokenNumber is invalid,\r
2ab6330e 418 the results are unpredictable.\r
80408db0 419\r
d1102dba 420 @param[in] TokenNumber The PCD token number.\r
2ab6330e 421\r
422 @return The pointer to the buffer to be retrived.\r
d1102dba 423\r
2ab6330e 424**/\r
80408db0 425VOID *\r
426EFIAPI\r
427DxePcdGetPtr (\r
1436aea4 428 IN UINTN TokenNumber\r
80408db0 429 )\r
430{\r
431 return GetWorker (TokenNumber, 0);\r
432}\r
433\r
2ab6330e 434/**\r
435 Retrieves a Boolean value for a given PCD token.\r
436\r
d1102dba
LG
437 Retrieves the current boolean value for a PCD token number.\r
438 Do not make any assumptions about the alignment of the pointer that\r
439 is returned by this function call. If the TokenNumber is invalid,\r
2ab6330e 440 the results are unpredictable.\r
80408db0 441\r
d1102dba 442 @param[in] TokenNumber The PCD token number.\r
80408db0 443\r
2ab6330e 444 @return The Boolean value.\r
d1102dba 445\r
2ab6330e 446**/\r
80408db0 447BOOLEAN\r
448EFIAPI\r
449DxePcdGetBool (\r
1436aea4 450 IN UINTN TokenNumber\r
80408db0 451 )\r
452{\r
1436aea4 453 return *((BOOLEAN *)GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
80408db0 454}\r
455\r
2ab6330e 456/**\r
457 Retrieves the size of the value for a given PCD token.\r
80408db0 458\r
d1102dba 459 Retrieves the current size of a particular PCD token.\r
2ab6330e 460 If the TokenNumber is invalid, the results are unpredictable.\r
80408db0 461\r
d1102dba 462 @param[in] TokenNumber The PCD token number.\r
2ab6330e 463\r
464 @return The size of the value for the PCD token.\r
d1102dba 465\r
2ab6330e 466**/\r
80408db0 467UINTN\r
468EFIAPI\r
469DxePcdGetSize (\r
1436aea4 470 IN UINTN TokenNumber\r
80408db0 471 )\r
472{\r
1436aea4
MK
473 UINTN Size;\r
474 UINT32 *LocalTokenNumberTable;\r
475 BOOLEAN IsPeiDb;\r
476 UINTN MaxSize;\r
477 UINTN TmpTokenNumber;\r
478\r
80408db0 479 //\r
480 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
481 // We have to decrement TokenNumber by 1 to make it usable\r
482 // as the array index.\r
483 //\r
484 TokenNumber--;\r
485\r
486 //\r
487 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber\r
d1102dba 488 //\r
80408db0 489 TmpTokenNumber = TokenNumber;\r
490\r
491 // EBC compiler is very choosy. It may report warning about comparison\r
d1102dba 492 // between UINTN and 0 . So we add 1 in each size of the\r
80408db0 493 // comparison.\r
419db80b 494 ASSERT (TokenNumber + 1 < mPcdTotalTokenCount + 1);\r
80408db0 495\r
496 // EBC compiler is very choosy. It may report warning about comparison\r
d1102dba 497 // between UINTN and 0 . So we add 1 in each size of the\r
80408db0 498 // comparison.\r
1436aea4 499 IsPeiDb = (BOOLEAN)(TokenNumber + 1 < mPeiLocalTokenCount + 1);\r
d1102dba
LG
500\r
501 TokenNumber = IsPeiDb ? TokenNumber :\r
1436aea4 502 (TokenNumber - mPeiLocalTokenCount);\r
80408db0 503\r
d1102dba 504 LocalTokenNumberTable = IsPeiDb ? (UINT32 *)((UINT8 *)mPcdDatabase.PeiDb + mPcdDatabase.PeiDb->LocalTokenNumberTableOffset)\r
419db80b 505 : (UINT32 *)((UINT8 *)mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->LocalTokenNumberTableOffset);\r
80408db0 506\r
507 Size = (LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
508\r
509 if (Size == 0) {\r
510 //\r
511 // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r
512 //\r
513 return GetPtrTypeSize (TmpTokenNumber, &MaxSize);\r
514 } else {\r
515 return Size;\r
516 }\r
80408db0 517}\r
518\r
2ab6330e 519/**\r
520 Retrieves an 8-bit value for a given PCD token.\r
521\r
d1102dba 522 Retrieves the 8-bit value of a particular PCD token.\r
2ab6330e 523 If the TokenNumber is invalid or the token space\r
d1102dba 524 specified by Guid does not exist, the results are\r
2ab6330e 525 unpredictable.\r
80408db0 526\r
2ab6330e 527 @param[in] Guid The token space for the token number.\r
d1102dba 528 @param[in] ExTokenNumber The PCD token number.\r
80408db0 529\r
2ab6330e 530 @return The size 8-bit value for the PCD token.\r
d1102dba 531\r
2ab6330e 532**/\r
80408db0 533UINT8\r
534EFIAPI\r
535DxePcdGet8Ex (\r
1436aea4
MK
536 IN CONST EFI_GUID *Guid,\r
537 IN UINTN ExTokenNumber\r
80408db0 538 )\r
539{\r
1436aea4 540 return *((UINT8 *)ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
80408db0 541}\r
542\r
2ab6330e 543/**\r
544 Retrieves an 16-bit value for a given PCD token.\r
545\r
d1102dba 546 Retrieves the 16-bit value of a particular PCD token.\r
2ab6330e 547 If the TokenNumber is invalid or the token space\r
d1102dba 548 specified by Guid does not exist, the results are\r
2ab6330e 549 unpredictable.\r
80408db0 550\r
2ab6330e 551 @param[in] Guid The token space for the token number.\r
d1102dba 552 @param[in] ExTokenNumber The PCD token number.\r
80408db0 553\r
2ab6330e 554 @return The size 16-bit value for the PCD token.\r
d1102dba 555\r
2ab6330e 556**/\r
80408db0 557UINT16\r
558EFIAPI\r
559DxePcdGet16Ex (\r
1436aea4
MK
560 IN CONST EFI_GUID *Guid,\r
561 IN UINTN ExTokenNumber\r
80408db0 562 )\r
563{\r
1436aea4 564 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r
80408db0 565}\r
566\r
2ab6330e 567/**\r
568 Retrieves an 32-bit value for a given PCD token.\r
569\r
d1102dba 570 Retrieves the 32-bit value of a particular PCD token.\r
2ab6330e 571 If the TokenNumber is invalid or the token space\r
d1102dba 572 specified by Guid does not exist, the results are\r
2ab6330e 573 unpredictable.\r
80408db0 574\r
2ab6330e 575 @param[in] Guid The token space for the token number.\r
d1102dba 576 @param[in] ExTokenNumber The PCD token number.\r
80408db0 577\r
2ab6330e 578 @return The size 32-bit value for the PCD token.\r
d1102dba 579\r
2ab6330e 580**/\r
80408db0 581UINT32\r
582EFIAPI\r
583DxePcdGet32Ex (\r
1436aea4
MK
584 IN CONST EFI_GUID *Guid,\r
585 IN UINTN ExTokenNumber\r
80408db0 586 )\r
587{\r
1436aea4 588 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r
80408db0 589}\r
590\r
2ab6330e 591/**\r
592 Retrieves an 64-bit value for a given PCD token.\r
80408db0 593\r
d1102dba 594 Retrieves the 64-bit value of a particular PCD token.\r
2ab6330e 595 If the TokenNumber is invalid or the token space\r
d1102dba 596 specified by Guid does not exist, the results are\r
2ab6330e 597 unpredictable.\r
80408db0 598\r
2ab6330e 599 @param[in] Guid The token space for the token number.\r
d1102dba 600 @param[in] ExTokenNumber The PCD token number.\r
2ab6330e 601\r
602 @return The size 64-bit value for the PCD token.\r
d1102dba 603\r
2ab6330e 604**/\r
80408db0 605UINT64\r
606EFIAPI\r
607DxePcdGet64Ex (\r
1436aea4
MK
608 IN CONST EFI_GUID *Guid,\r
609 IN UINTN ExTokenNumber\r
80408db0 610 )\r
611{\r
1436aea4 612 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r
80408db0 613}\r
614\r
2ab6330e 615/**\r
616 Retrieves a pointer to a value for a given PCD token.\r
617\r
d1102dba
LG
618 Retrieves the current pointer to the buffer for a PCD token number.\r
619 Do not make any assumptions about the alignment of the pointer that\r
620 is returned by this function call. If the TokenNumber is invalid,\r
2ab6330e 621 the results are unpredictable.\r
80408db0 622\r
2ab6330e 623 @param[in] Guid The token space for the token number.\r
d1102dba 624 @param[in] ExTokenNumber The PCD token number.\r
80408db0 625\r
2ab6330e 626 @return The pointer to the buffer to be retrived.\r
d1102dba 627\r
2ab6330e 628**/\r
80408db0 629VOID *\r
630EFIAPI\r
631DxePcdGetPtrEx (\r
1436aea4
MK
632 IN CONST EFI_GUID *Guid,\r
633 IN UINTN ExTokenNumber\r
80408db0 634 )\r
635{\r
1436aea4 636 return ExGetWorker (Guid, ExTokenNumber, 0);\r
80408db0 637}\r
638\r
2ab6330e 639/**\r
640 Retrieves an Boolean value for a given PCD token.\r
80408db0 641\r
d1102dba 642 Retrieves the Boolean value of a particular PCD token.\r
2ab6330e 643 If the TokenNumber is invalid or the token space\r
d1102dba 644 specified by Guid does not exist, the results are\r
2ab6330e 645 unpredictable.\r
80408db0 646\r
2ab6330e 647 @param[in] Guid The token space for the token number.\r
d1102dba 648 @param[in] ExTokenNumber The PCD token number.\r
2ab6330e 649\r
650 @return The size Boolean value for the PCD token.\r
d1102dba 651\r
2ab6330e 652**/\r
80408db0 653BOOLEAN\r
654EFIAPI\r
655DxePcdGetBoolEx (\r
1436aea4
MK
656 IN CONST EFI_GUID *Guid,\r
657 IN UINTN ExTokenNumber\r
80408db0 658 )\r
659{\r
1436aea4 660 return *((BOOLEAN *)ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
80408db0 661}\r
662\r
2ab6330e 663/**\r
664 Retrieves the size of the value for a given PCD token.\r
665\r
d1102dba 666 Retrieves the current size of a particular PCD token.\r
2ab6330e 667 If the TokenNumber is invalid, the results are unpredictable.\r
80408db0 668\r
2ab6330e 669 @param[in] Guid The token space for the token number.\r
d1102dba 670 @param[in] ExTokenNumber The PCD token number.\r
80408db0 671\r
2ab6330e 672 @return The size of the value for the PCD token.\r
d1102dba 673\r
2ab6330e 674**/\r
80408db0 675UINTN\r
676EFIAPI\r
677DxePcdGetSizeEx (\r
1436aea4
MK
678 IN CONST EFI_GUID *Guid,\r
679 IN UINTN ExTokenNumber\r
80408db0 680 )\r
681{\r
1436aea4 682 return DxePcdGetSize (GetExPcdTokenNumber (Guid, (UINT32)ExTokenNumber));\r
80408db0 683}\r
684\r
2ab6330e 685/**\r
686 Sets an 8-bit value for a given PCD token.\r
687\r
d1102dba
LG
688 When the PCD service sets a value, it will check to ensure that the\r
689 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 690 If it is not, an error will be returned.\r
80408db0 691\r
d1102dba 692 @param[in] TokenNumber The PCD token number.\r
2ab6330e 693 @param[in] Value The value to set for the PCD token.\r
80408db0 694\r
2ab6330e 695 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
696 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
697 being set was incompatible with a call to this function.\r
2ab6330e 698 Use GetSize() to retrieve the size of the target data.\r
699 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 700\r
2ab6330e 701**/\r
80408db0 702EFI_STATUS\r
703EFIAPI\r
704DxePcdSet8 (\r
1436aea4
MK
705 IN UINTN TokenNumber,\r
706 IN UINT8 Value\r
80408db0 707 )\r
708{\r
709 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
710}\r
711\r
2ab6330e 712/**\r
713 Sets an 16-bit value for a given PCD token.\r
80408db0 714\r
d1102dba
LG
715 When the PCD service sets a value, it will check to ensure that the\r
716 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 717 If it is not, an error will be returned.\r
80408db0 718\r
d1102dba 719 @param[in] TokenNumber The PCD token number.\r
2ab6330e 720 @param[in] Value The value to set for the PCD token.\r
721\r
722 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
723 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
724 being set was incompatible with a call to this function.\r
2ab6330e 725 Use GetSize() to retrieve the size of the target data.\r
726 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 727\r
2ab6330e 728**/\r
80408db0 729EFI_STATUS\r
730EFIAPI\r
731DxePcdSet16 (\r
1436aea4
MK
732 IN UINTN TokenNumber,\r
733 IN UINT16 Value\r
80408db0 734 )\r
735{\r
736 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
737}\r
738\r
2ab6330e 739/**\r
740 Sets an 32-bit value for a given PCD token.\r
741\r
d1102dba
LG
742 When the PCD service sets a value, it will check to ensure that the\r
743 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 744 If it is not, an error will be returned.\r
80408db0 745\r
d1102dba 746 @param[in] TokenNumber The PCD token number.\r
2ab6330e 747 @param[in] Value The value to set for the PCD token.\r
80408db0 748\r
2ab6330e 749 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
750 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
751 being set was incompatible with a call to this function.\r
2ab6330e 752 Use GetSize() to retrieve the size of the target data.\r
753 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 754\r
2ab6330e 755**/\r
80408db0 756EFI_STATUS\r
757EFIAPI\r
758DxePcdSet32 (\r
1436aea4
MK
759 IN UINTN TokenNumber,\r
760 IN UINT32 Value\r
80408db0 761 )\r
762{\r
763 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
764}\r
765\r
2ab6330e 766/**\r
767 Sets an 64-bit value for a given PCD token.\r
80408db0 768\r
d1102dba
LG
769 When the PCD service sets a value, it will check to ensure that the\r
770 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 771 If it is not, an error will be returned.\r
80408db0 772\r
d1102dba 773 @param[in] TokenNumber The PCD token number.\r
2ab6330e 774 @param[in] Value The value to set for the PCD token.\r
775\r
776 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
777 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
778 being set was incompatible with a call to this function.\r
2ab6330e 779 Use GetSize() to retrieve the size of the target data.\r
780 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 781\r
2ab6330e 782**/\r
80408db0 783EFI_STATUS\r
784EFIAPI\r
785DxePcdSet64 (\r
1436aea4
MK
786 IN UINTN TokenNumber,\r
787 IN UINT64 Value\r
80408db0 788 )\r
789{\r
790 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
791}\r
792\r
2ab6330e 793/**\r
794 Sets a value of a specified size for a given PCD token.\r
795\r
d1102dba
LG
796 When the PCD service sets a value, it will check to ensure that the\r
797 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 798 If it is not, an error will be returned.\r
799\r
d1102dba
LG
800 @param[in] TokenNumber The PCD token number.\r
801 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.\r
802 On input, if the SizeOfValue is greater than the maximum size supported\r
803 for this TokenNumber then the output value of SizeOfValue will reflect\r
2ab6330e 804 the maximum size supported for this TokenNumber.\r
805 @param[in] Buffer The buffer to set for the PCD token.\r
806\r
807 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
808 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
809 being set was incompatible with a call to this function.\r
2ab6330e 810 Use GetSize() to retrieve the size of the target data.\r
811 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 812\r
2ab6330e 813**/\r
80408db0 814EFI_STATUS\r
815EFIAPI\r
816DxePcdSetPtr (\r
1436aea4
MK
817 IN UINTN TokenNumber,\r
818 IN OUT UINTN *SizeOfBuffer,\r
819 IN VOID *Buffer\r
80408db0 820 )\r
821{\r
822 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
823}\r
824\r
2ab6330e 825/**\r
826 Sets an Boolean value for a given PCD token.\r
80408db0 827\r
d1102dba
LG
828 When the PCD service sets a value, it will check to ensure that the\r
829 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 830 If it is not, an error will be returned.\r
80408db0 831\r
d1102dba 832 @param[in] TokenNumber The PCD token number.\r
2ab6330e 833 @param[in] Value The value to set for the PCD token.\r
834\r
835 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
836 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
837 being set was incompatible with a call to this function.\r
2ab6330e 838 Use GetSize() to retrieve the size of the target data.\r
839 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 840\r
2ab6330e 841**/\r
80408db0 842EFI_STATUS\r
843EFIAPI\r
844DxePcdSetBool (\r
1436aea4
MK
845 IN UINTN TokenNumber,\r
846 IN BOOLEAN Value\r
80408db0 847 )\r
848{\r
849 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
850}\r
851\r
2ab6330e 852/**\r
853 Sets an 8-bit value for a given PCD token.\r
854\r
d1102dba
LG
855 When the PCD service sets a value, it will check to ensure that the\r
856 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 857 If it is not, an error will be returned.\r
80408db0 858\r
2ab6330e 859 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
d1102dba 860 @param[in] ExTokenNumber The PCD token number.\r
2ab6330e 861 @param[in] Value The value to set for the PCD token.\r
80408db0 862\r
2ab6330e 863 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
864 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
865 being set was incompatible with a call to this function.\r
2ab6330e 866 Use GetSize() to retrieve the size of the target data.\r
867 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 868\r
2ab6330e 869**/\r
80408db0 870EFI_STATUS\r
871EFIAPI\r
872DxePcdSet8Ex (\r
1436aea4
MK
873 IN CONST EFI_GUID *Guid,\r
874 IN UINTN ExTokenNumber,\r
875 IN UINT8 Value\r
80408db0 876 )\r
877{\r
1436aea4 878 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
80408db0 879}\r
880\r
2ab6330e 881/**\r
882 Sets an 16-bit value for a given PCD token.\r
80408db0 883\r
d1102dba
LG
884 When the PCD service sets a value, it will check to ensure that the\r
885 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 886 If it is not, an error will be returned.\r
80408db0 887\r
2ab6330e 888 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
d1102dba 889 @param[in] ExTokenNumber The PCD token number.\r
2ab6330e 890 @param[in] Value The value to set for the PCD token.\r
891\r
892 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
893 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
894 being set was incompatible with a call to this function.\r
2ab6330e 895 Use GetSize() to retrieve the size of the target data.\r
896 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 897\r
2ab6330e 898**/\r
80408db0 899EFI_STATUS\r
900EFIAPI\r
901DxePcdSet16Ex (\r
1436aea4
MK
902 IN CONST EFI_GUID *Guid,\r
903 IN UINTN ExTokenNumber,\r
904 IN UINT16 Value\r
80408db0 905 )\r
906{\r
425084cd
SZ
907 //\r
908 // PcdSetNvStoreDefaultId should be set in PEI phase to take effect.\r
909 //\r
1436aea4
MK
910 ASSERT (\r
911 !(CompareGuid (Guid, &gEfiMdeModulePkgTokenSpaceGuid) &&\r
912 (ExTokenNumber == PcdToken (PcdSetNvStoreDefaultId)))\r
913 );\r
914 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
80408db0 915}\r
916\r
2ab6330e 917/**\r
918 Sets an 32-bit value for a given PCD token.\r
919\r
d1102dba
LG
920 When the PCD service sets a value, it will check to ensure that the\r
921 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 922 If it is not, an error will be returned.\r
80408db0 923\r
2ab6330e 924 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
d1102dba 925 @param[in] ExTokenNumber The PCD token number.\r
2ab6330e 926 @param[in] Value The value to set for the PCD token.\r
80408db0 927\r
2ab6330e 928 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
929 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
930 being set was incompatible with a call to this function.\r
2ab6330e 931 Use GetSize() to retrieve the size of the target data.\r
932 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 933\r
2ab6330e 934**/\r
80408db0 935EFI_STATUS\r
936EFIAPI\r
937DxePcdSet32Ex (\r
1436aea4
MK
938 IN CONST EFI_GUID *Guid,\r
939 IN UINTN ExTokenNumber,\r
940 IN UINT32 Value\r
80408db0 941 )\r
942{\r
1436aea4 943 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
80408db0 944}\r
945\r
2ab6330e 946/**\r
947 Sets an 64-bit value for a given PCD token.\r
948\r
d1102dba
LG
949 When the PCD service sets a value, it will check to ensure that the\r
950 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 951 If it is not, an error will be returned.\r
80408db0 952\r
2ab6330e 953 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
d1102dba 954 @param[in] ExTokenNumber The PCD token number.\r
2ab6330e 955 @param[in] Value The value to set for the PCD token.\r
80408db0 956\r
2ab6330e 957 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
958 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
959 being set was incompatible with a call to this function.\r
2ab6330e 960 Use GetSize() to retrieve the size of the target data.\r
961 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 962\r
2ab6330e 963**/\r
80408db0 964EFI_STATUS\r
965EFIAPI\r
966DxePcdSet64Ex (\r
1436aea4
MK
967 IN CONST EFI_GUID *Guid,\r
968 IN UINTN ExTokenNumber,\r
969 IN UINT64 Value\r
80408db0 970 )\r
971{\r
1436aea4 972 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
80408db0 973}\r
974\r
2ab6330e 975/**\r
976 Sets a value of a specified size for a given PCD token.\r
977\r
d1102dba
LG
978 When the PCD service sets a value, it will check to ensure that the\r
979 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 980 If it is not, an error will be returned.\r
981\r
982 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
d1102dba
LG
983 @param[in] ExTokenNumber The PCD token number.\r
984 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.\r
985 On input, if the SizeOfValue is greater than the maximum size supported\r
986 for this TokenNumber then the output value of SizeOfValue will reflect\r
2ab6330e 987 the maximum size supported for this TokenNumber.\r
988 @param[in] Buffer The buffer to set for the PCD token.\r
989\r
990 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
991 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
992 being set was incompatible with a call to this function.\r
2ab6330e 993 Use GetSize() to retrieve the size of the target data.\r
994 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 995\r
2ab6330e 996**/\r
80408db0 997EFI_STATUS\r
998EFIAPI\r
999DxePcdSetPtrEx (\r
1436aea4
MK
1000 IN CONST EFI_GUID *Guid,\r
1001 IN UINTN ExTokenNumber,\r
1002 IN OUT UINTN *SizeOfBuffer,\r
1003 IN VOID *Buffer\r
80408db0 1004 )\r
1005{\r
1436aea4 1006 return ExSetWorker (ExTokenNumber, Guid, Buffer, SizeOfBuffer, TRUE);\r
80408db0 1007}\r
1008\r
2ab6330e 1009/**\r
1010 Sets an Boolean value for a given PCD token.\r
80408db0 1011\r
d1102dba
LG
1012 When the PCD service sets a value, it will check to ensure that the\r
1013 size of the value being set is compatible with the Token's existing definition.\r
2ab6330e 1014 If it is not, an error will be returned.\r
80408db0 1015\r
2ab6330e 1016 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
d1102dba 1017 @param[in] ExTokenNumber The PCD token number.\r
2ab6330e 1018 @param[in] Value The value to set for the PCD token.\r
1019\r
1020 @retval EFI_SUCCESS Procedure returned successfully.\r
d1102dba
LG
1021 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
1022 being set was incompatible with a call to this function.\r
2ab6330e 1023 Use GetSize() to retrieve the size of the target data.\r
1024 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
d1102dba 1025\r
2ab6330e 1026**/\r
80408db0 1027EFI_STATUS\r
1028EFIAPI\r
1029DxePcdSetBoolEx (\r
1436aea4
MK
1030 IN CONST EFI_GUID *Guid,\r
1031 IN UINTN ExTokenNumber,\r
1032 IN BOOLEAN Value\r
80408db0 1033 )\r
1034{\r
1436aea4 1035 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
80408db0 1036}\r
1037\r
2ab6330e 1038/**\r
1039 Specifies a function to be called anytime the value of a designated token is changed.\r
80408db0 1040\r
2ab6330e 1041 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
d1102dba
LG
1042 @param[in] TokenNumber The PCD token number.\r
1043 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.\r
80408db0 1044\r
d1102dba 1045 @retval EFI_SUCCESS The PCD service has successfully established a call event\r
2ab6330e 1046 for the CallBackToken requested.\r
1047 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
80408db0 1048\r
2ab6330e 1049**/\r
80408db0 1050EFI_STATUS\r
1051EFIAPI\r
1052DxeRegisterCallBackOnSet (\r
1436aea4
MK
1053 IN CONST EFI_GUID *Guid OPTIONAL,\r
1054 IN UINTN TokenNumber,\r
1055 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
80408db0 1056 )\r
1057{\r
1436aea4 1058 EFI_STATUS Status;\r
d1102dba 1059\r
e4a3922f 1060 if (CallBackFunction == NULL) {\r
1061 return EFI_INVALID_PARAMETER;\r
1062 }\r
1436aea4 1063\r
80408db0 1064 //\r
1065 // Aquire lock to prevent reentrance from TPL_CALLBACK level\r
1066 //\r
1067 EfiAcquireLock (&mPcdDatabaseLock);\r
1068\r
1069 Status = DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
1070\r
1071 EfiReleaseLock (&mPcdDatabaseLock);\r
d1102dba 1072\r
80408db0 1073 return Status;\r
1074}\r
1075\r
2ab6330e 1076/**\r
1077 Cancels a previously set callback function for a particular PCD token number.\r
80408db0 1078\r
2ab6330e 1079 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
d1102dba
LG
1080 @param[in] TokenNumber The PCD token number.\r
1081 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.\r
80408db0 1082\r
d1102dba 1083 @retval EFI_SUCCESS The PCD service has successfully established a call event\r
2ab6330e 1084 for the CallBackToken requested.\r
1085 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
1086\r
1087**/\r
80408db0 1088EFI_STATUS\r
1089EFIAPI\r
1090DxeUnRegisterCallBackOnSet (\r
1436aea4
MK
1091 IN CONST EFI_GUID *Guid OPTIONAL,\r
1092 IN UINTN TokenNumber,\r
1093 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
80408db0 1094 )\r
1095{\r
1436aea4 1096 EFI_STATUS Status;\r
d1102dba 1097\r
e4a3922f 1098 if (CallBackFunction == NULL) {\r
1099 return EFI_INVALID_PARAMETER;\r
1100 }\r
80408db0 1101\r
1102 //\r
1103 // Aquire lock to prevent reentrance from TPL_CALLBACK level\r
1104 //\r
1105 EfiAcquireLock (&mPcdDatabaseLock);\r
d1102dba 1106\r
80408db0 1107 Status = DxeUnRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
1108\r
1109 EfiReleaseLock (&mPcdDatabaseLock);\r
d1102dba 1110\r
80408db0 1111 return Status;\r
1112}\r
1113\r
2ab6330e 1114/**\r
d1102dba
LG
1115 Retrieves the next valid token number in a given namespace.\r
1116\r
1117 This is useful since the PCD infrastructure contains a sparse list of token numbers,\r
1118 and one cannot a priori know what token numbers are valid in the database.\r
1119\r
1120 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.\r
1121 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.\r
1122 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.\r
1123 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.\r
1124 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.\r
1125 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.\r
1126 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
90e06556 1127 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
1128\r
1129\r
d1102dba
LG
1130 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.\r
1131 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is\r
90e06556 1132 being made to retrieve tokens from the default token space.\r
d1102dba
LG
1133 @param[in, out] TokenNumber\r
1134 A pointer to the PCD token number to use to find the subsequent token number.\r
90e06556 1135\r
419db80b
BF
1136 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.\r
1137 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.\r
2ab6330e 1138\r
1139**/\r
80408db0 1140EFI_STATUS\r
1141EFIAPI\r
1142DxePcdGetNextToken (\r
1436aea4
MK
1143 IN CONST EFI_GUID *Guid OPTIONAL,\r
1144 IN OUT UINTN *TokenNumber\r
80408db0 1145 )\r
1146{\r
1436aea4
MK
1147 EFI_STATUS Status;\r
1148 BOOLEAN PeiExMapTableEmpty;\r
1149 BOOLEAN DxeExMapTableEmpty;\r
80408db0 1150\r
1436aea4 1151 Status = EFI_NOT_FOUND;\r
419db80b
BF
1152 PeiExMapTableEmpty = mPeiExMapTableEmpty;\r
1153 DxeExMapTableEmpty = mDxeExMapTableEmpty;\r
80408db0 1154\r
1155 //\r
1156 // Scan the local token space\r
1157 //\r
1158 if (Guid == NULL) {\r
1159 // EBC compiler is very choosy. It may report warning about comparison\r
d1102dba 1160 // between UINTN and 0 . So we add 1 in each size of the\r
80408db0 1161 // comparison.\r
419db80b 1162 if (((*TokenNumber + 1 > mPeiNexTokenCount + 1) && (*TokenNumber + 1 <= mPeiLocalTokenCount + 1)) ||\r
1436aea4
MK
1163 ((*TokenNumber + 1 > (mPeiLocalTokenCount + mDxeNexTokenCount + 1))))\r
1164 {\r
419db80b 1165 return EFI_NOT_FOUND;\r
80408db0 1166 }\r
d1102dba 1167\r
80408db0 1168 (*TokenNumber)++;\r
419db80b 1169 if ((*TokenNumber + 1 > mPeiNexTokenCount + 1) &&\r
1436aea4
MK
1170 (*TokenNumber + 1 <= mPeiLocalTokenCount + 1))\r
1171 {\r
80408db0 1172 //\r
d1102dba 1173 // The first Non-Ex type Token Number for DXE PCD\r
419db80b 1174 // database is mPeiLocalTokenCount + 1\r
80408db0 1175 //\r
419db80b
BF
1176 if (mDxeNexTokenCount > 0) {\r
1177 *TokenNumber = mPeiLocalTokenCount + 1;\r
1178 } else {\r
1179 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
1180 return EFI_NOT_FOUND;\r
1181 }\r
1182 } else if (*TokenNumber + 1 > mDxeNexTokenCount + mPeiLocalTokenCount + 1) {\r
80408db0 1183 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
419db80b 1184 return EFI_NOT_FOUND;\r
80408db0 1185 }\r
1436aea4 1186\r
80408db0 1187 return EFI_SUCCESS;\r
1188 }\r
1189\r
1190 if (PeiExMapTableEmpty && DxeExMapTableEmpty) {\r
80408db0 1191 return EFI_NOT_FOUND;\r
1192 }\r
1193\r
1194 if (!PeiExMapTableEmpty) {\r
1195 Status = ExGetNextTokeNumber (\r
1436aea4
MK
1196 Guid,\r
1197 TokenNumber,\r
1198 (EFI_GUID *)((UINT8 *)mPcdDatabase.PeiDb + mPcdDatabase.PeiDb->GuidTableOffset),\r
1199 mPeiGuidTableSize,\r
1200 (DYNAMICEX_MAPPING *)((UINT8 *)mPcdDatabase.PeiDb + mPcdDatabase.PeiDb->ExMapTableOffset),\r
1201 mPeiExMapppingTableSize\r
1202 );\r
80408db0 1203 }\r
1204\r
1205 if (Status == EFI_SUCCESS) {\r
1206 return Status;\r
1207 }\r
1208\r
1209 if (!DxeExMapTableEmpty) {\r
1210 Status = ExGetNextTokeNumber (\r
1436aea4
MK
1211 Guid,\r
1212 TokenNumber,\r
1213 (EFI_GUID *)((UINT8 *)mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->GuidTableOffset),\r
1214 mDxeGuidTableSize,\r
1215 (DYNAMICEX_MAPPING *)((UINT8 *)mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->ExMapTableOffset),\r
1216 mDxeExMapppingTableSize\r
1217 );\r
80408db0 1218 }\r
1219\r
1220 return Status;\r
1221}\r
1222\r
2ab6330e 1223/**\r
1224 Get all token space guid table which is different with given token space guid.\r
1225\r
419db80b 1226 @param ExMapTableSize The size of ExMapTable in item\r
2ab6330e 1227 @param ExMapTable Token space guid table that want to be scaned.\r
1228 @param GuidTable Guid table\r
1229\r
1230 @return all token space guid table which is different with given token space guid.\r
1231\r
1232**/\r
80408db0 1233EFI_GUID **\r
1234GetDistinctTokenSpace (\r
1436aea4
MK
1235 IN OUT UINTN *ExMapTableSize,\r
1236 IN DYNAMICEX_MAPPING *ExMapTable,\r
1237 IN EFI_GUID *GuidTable\r
80408db0 1238 )\r
1239{\r
1240 EFI_GUID **DistinctTokenSpace;\r
1241 UINTN OldGuidIndex;\r
1242 UINTN TsIdx;\r
419db80b 1243 UINTN TempTsIdx;\r
80408db0 1244 UINTN Idx;\r
419db80b 1245 BOOLEAN Match;\r
80408db0 1246\r
1247 DistinctTokenSpace = AllocateZeroPool (*ExMapTableSize * sizeof (EFI_GUID *));\r
1248 ASSERT (DistinctTokenSpace != NULL);\r
1249\r
1436aea4
MK
1250 TsIdx = 0;\r
1251 OldGuidIndex = ExMapTable[0].ExGuidIndex;\r
80408db0 1252 DistinctTokenSpace[TsIdx] = &GuidTable[OldGuidIndex];\r
1253 for (Idx = 1; Idx < *ExMapTableSize; Idx++) {\r
1436aea4 1254 Match = FALSE;\r
419db80b
BF
1255 OldGuidIndex = ExMapTable[Idx].ExGuidIndex;\r
1256 for (TempTsIdx = 0; TempTsIdx <= TsIdx; TempTsIdx++) {\r
1257 if (&GuidTable[OldGuidIndex] == DistinctTokenSpace[TempTsIdx]) {\r
1258 //\r
1259 // Have recorded this GUID.\r
1260 //\r
1261 Match = TRUE;\r
1262 break;\r
1263 }\r
1264 }\r
1436aea4 1265\r
419db80b 1266 if (!Match) {\r
80408db0 1267 DistinctTokenSpace[++TsIdx] = &GuidTable[OldGuidIndex];\r
1268 }\r
1269 }\r
1270\r
1271 //\r
1272 // The total number of Distinct Token Space\r
1273 // is TsIdx + 1 because we use TsIdx as a index\r
1274 // to the DistinctTokenSpace[]\r
1275 //\r
1276 *ExMapTableSize = TsIdx + 1;\r
1277 return DistinctTokenSpace;\r
80408db0 1278}\r
d1102dba 1279\r
2ab6330e 1280/**\r
419db80b
BF
1281 Retrieves the next valid PCD token namespace for a given namespace.\r
1282\r
1283 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid\r
1284 token namespaces on a platform.\r
1285\r
1286 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token\r
1287 namespace from which the search will start. On output, it designates the next valid\r
1288 token namespace on the platform. If *Guid is NULL, then the GUID of the first token\r
1289 space of the current platform is returned. If the search cannot locate the next valid\r
1290 token namespace, an error is returned and the value of *Guid is undefined.\r
d1102dba 1291\r
419db80b
BF
1292 @retval EFI_SUCCESS The PCD service retrieved the value requested.\r
1293 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.\r
1294\r
2ab6330e 1295**/\r
80408db0 1296EFI_STATUS\r
1297EFIAPI\r
1298DxePcdGetNextTokenSpace (\r
1436aea4 1299 IN OUT CONST EFI_GUID **Guid\r
80408db0 1300 )\r
1301{\r
1436aea4
MK
1302 UINTN Idx;\r
1303 UINTN Idx2;\r
1304 UINTN Idx3;\r
1305 UINTN PeiTokenSpaceTableSize;\r
1306 UINTN DxeTokenSpaceTableSize;\r
1307 EFI_GUID **PeiTokenSpaceTable;\r
1308 EFI_GUID **DxeTokenSpaceTable;\r
1309 BOOLEAN Match;\r
1310 BOOLEAN PeiExMapTableEmpty;\r
1311 BOOLEAN DxeExMapTableEmpty;\r
80408db0 1312\r
80408db0 1313 ASSERT (Guid != NULL);\r
d1102dba 1314\r
419db80b
BF
1315 PeiExMapTableEmpty = mPeiExMapTableEmpty;\r
1316 DxeExMapTableEmpty = mDxeExMapTableEmpty;\r
80408db0 1317\r
1318 if (PeiExMapTableEmpty && DxeExMapTableEmpty) {\r
419db80b 1319 return EFI_NOT_FOUND;\r
80408db0 1320 }\r
d1102dba 1321\r
80408db0 1322 if (TmpTokenSpaceBuffer[0] == NULL) {\r
1323 PeiTokenSpaceTableSize = 0;\r
1324\r
1325 if (!PeiExMapTableEmpty) {\r
1436aea4
MK
1326 PeiTokenSpaceTableSize = mPeiExMapppingTableSize / sizeof (DYNAMICEX_MAPPING);\r
1327 PeiTokenSpaceTable = GetDistinctTokenSpace (\r
1328 &PeiTokenSpaceTableSize,\r
1329 (DYNAMICEX_MAPPING *)((UINT8 *)mPcdDatabase.PeiDb + mPcdDatabase.PeiDb->ExMapTableOffset),\r
1330 (EFI_GUID *)((UINT8 *)mPcdDatabase.PeiDb + mPcdDatabase.PeiDb->GuidTableOffset)\r
1331 );\r
1332 CopyMem (TmpTokenSpaceBuffer, PeiTokenSpaceTable, sizeof (EFI_GUID *) * PeiTokenSpaceTableSize);\r
da0df6ca 1333 TmpTokenSpaceBufferCount = PeiTokenSpaceTableSize;\r
419db80b 1334 FreePool (PeiTokenSpaceTable);\r
80408db0 1335 }\r
1336\r
1337 if (!DxeExMapTableEmpty) {\r
1436aea4
MK
1338 DxeTokenSpaceTableSize = mDxeExMapppingTableSize / sizeof (DYNAMICEX_MAPPING);\r
1339 DxeTokenSpaceTable = GetDistinctTokenSpace (\r
1340 &DxeTokenSpaceTableSize,\r
1341 (DYNAMICEX_MAPPING *)((UINT8 *)mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->ExMapTableOffset),\r
1342 (EFI_GUID *)((UINT8 *)mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->GuidTableOffset)\r
1343 );\r
80408db0 1344\r
1345 //\r
1346 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable\r
1347 //\r
1348 for (Idx2 = 0, Idx3 = PeiTokenSpaceTableSize; Idx2 < DxeTokenSpaceTableSize; Idx2++) {\r
1349 Match = FALSE;\r
1350 for (Idx = 0; Idx < PeiTokenSpaceTableSize; Idx++) {\r
1351 if (CompareGuid (TmpTokenSpaceBuffer[Idx], DxeTokenSpaceTable[Idx2])) {\r
1352 Match = TRUE;\r
1353 break;\r
1354 }\r
1355 }\r
1436aea4 1356\r
80408db0 1357 if (!Match) {\r
1358 TmpTokenSpaceBuffer[Idx3++] = DxeTokenSpaceTable[Idx2];\r
1359 }\r
1360 }\r
419db80b
BF
1361\r
1362 TmpTokenSpaceBufferCount = Idx3;\r
1363 FreePool (DxeTokenSpaceTable);\r
80408db0 1364 }\r
1365 }\r
1366\r
1367 if (*Guid == NULL) {\r
1368 *Guid = TmpTokenSpaceBuffer[0];\r
1369 return EFI_SUCCESS;\r
1370 }\r
d1102dba 1371\r
419db80b
BF
1372 for (Idx = 0; Idx < TmpTokenSpaceBufferCount; Idx++) {\r
1373 if (CompareGuid (*Guid, TmpTokenSpaceBuffer[Idx])) {\r
1374 if (Idx == TmpTokenSpaceBufferCount - 1) {\r
1375 //\r
1376 // It has been the last token namespace.\r
1377 //\r
1378 *Guid = NULL;\r
1379 return EFI_NOT_FOUND;\r
1380 } else {\r
1381 Idx++;\r
1382 *Guid = TmpTokenSpaceBuffer[Idx];\r
1383 return EFI_SUCCESS;\r
1384 }\r
80408db0 1385 }\r
1386 }\r
1387\r
1388 return EFI_NOT_FOUND;\r
80408db0 1389}\r