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