Prefixed global variable with "m"
[mirror_edk2.git] / EdkModulePkg / Universal / PCD / Dxe / Pcd.c
CommitLineData
878ddf1f 1/** @file\r
2PCD DXE driver\r
3\r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13\r
14Module Name: Pcd.c\r
15\r
16**/\r
17\r
878ddf1f 18#include "Service.h"\r
19\r
20\r
21PCD_PROTOCOL mPcdInstance = {\r
22 DxePcdSetSku,\r
23\r
24 DxePcdGet8,\r
25 DxePcdGet16,\r
26 DxePcdGet32,\r
27 DxePcdGet64,\r
28 DxePcdGetPtr,\r
29 DxePcdGetBool,\r
30 DxePcdGetSize,\r
31\r
32 DxePcdGet8Ex,\r
33 DxePcdGet16Ex,\r
34 DxePcdGet32Ex,\r
35 DxePcdGet64Ex,\r
36 DxePcdGetPtrEx,\r
37 DxePcdGetBoolEx,\r
38 DxePcdGetSizeEx,\r
39\r
40 DxePcdSet8,\r
41 DxePcdSet16,\r
42 DxePcdSet32,\r
43 DxePcdSet64,\r
44 DxePcdSetPtr,\r
45 DxePcdSetBool,\r
46\r
47 DxePcdSet8Ex,\r
48 DxePcdSet16Ex,\r
49 DxePcdSet32Ex,\r
50 DxePcdSet64Ex,\r
51 DxePcdSetPtrEx,\r
52 DxePcdSetBoolEx,\r
53\r
4c114006 54 DxeRegisterCallBackOnSet,\r
55 DxeUnRegisterCallBackOnSet,\r
c24ba2f6 56 DxePcdGetNextToken,\r
57 DxePcdGetNextTokenSpace\r
878ddf1f 58};\r
59\r
60\r
61//\r
62// Static global to reduce the code size\r
63//\r
3b06f97c 64static EFI_HANDLE mNewHandle = NULL;\r
878ddf1f 65\r
66EFI_STATUS\r
67EFIAPI\r
68PcdDxeInit (\r
69 IN EFI_HANDLE ImageHandle,\r
70 IN EFI_SYSTEM_TABLE *SystemTable\r
71 )\r
72{\r
52e1905d 73 EFI_STATUS Status;\r
74\r
75 //\r
76 // Make sure the Pcd Protocol is not already installed in the system\r
77 //\r
4f242357 78\r
52e1905d 79 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gPcdProtocolGuid);\r
2a505eac 80\r
52e1905d 81 BuildPcdDxeDataBase ();\r
82\r
878ddf1f 83 Status = gBS->InstallProtocolInterface (\r
3b06f97c 84 &mNewHandle,\r
878ddf1f 85 &gPcdProtocolGuid,\r
86 EFI_NATIVE_INTERFACE,\r
87 &mPcdInstance\r
88 );\r
89\r
90 ASSERT_EFI_ERROR (Status);\r
91\r
92 return EFI_SUCCESS;\r
93\r
94}\r
95\r
96\r
00b7af13 97VOID\r
878ddf1f 98EFIAPI\r
99DxePcdSetSku (\r
8a43e8dd 100 IN UINTN SkuId\r
878ddf1f 101 )\r
102{\r
8a43e8dd 103 mPcdDatabase->PeiDb.Init.SystemSkuId = (SKU_ID) SkuId;\r
00b7af13 104 \r
105 return;\r
878ddf1f 106}\r
107\r
108\r
109\r
110UINT8\r
111EFIAPI\r
112DxePcdGet8 (\r
8a43e8dd 113 IN UINTN TokenNumber\r
878ddf1f 114 )\r
115{\r
9d6d8b24 116 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
878ddf1f 117}\r
118\r
119\r
120\r
121UINT16\r
122EFIAPI\r
123DxePcdGet16 (\r
8a43e8dd 124 IN UINTN TokenNumber\r
878ddf1f 125 )\r
126{\r
9d6d8b24 127 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
878ddf1f 128}\r
129\r
130\r
131\r
132UINT32\r
133EFIAPI\r
134DxePcdGet32 (\r
8a43e8dd 135 IN UINTN TokenNumber\r
878ddf1f 136 )\r
137{\r
9d6d8b24 138 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
878ddf1f 139}\r
140\r
141\r
142\r
143UINT64\r
144EFIAPI\r
145DxePcdGet64 (\r
8a43e8dd 146 IN UINTN TokenNumber\r
878ddf1f 147 )\r
148{\r
9d6d8b24 149 return ReadUnaligned64(GetWorker (TokenNumber, sizeof (UINT64)));\r
878ddf1f 150}\r
151\r
152\r
153\r
154VOID *\r
155EFIAPI\r
156DxePcdGetPtr (\r
8a43e8dd 157 IN UINTN TokenNumber\r
878ddf1f 158 )\r
159{\r
9d6d8b24 160 return GetWorker (TokenNumber, 0);\r
878ddf1f 161}\r
162\r
163\r
164\r
165BOOLEAN\r
166EFIAPI\r
167DxePcdGetBool (\r
8a43e8dd 168 IN UINTN TokenNumber\r
878ddf1f 169 )\r
170{\r
9d6d8b24 171 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
878ddf1f 172}\r
173\r
174\r
175\r
176UINTN\r
177EFIAPI\r
178DxePcdGetSize (\r
8a43e8dd 179 IN UINTN TokenNumber\r
878ddf1f 180 )\r
181{\r
1de04b4f 182 UINTN Size;\r
183 UINT32 *LocalTokenNumberTable;\r
184 BOOLEAN IsPeiDb;\r
185 UINTN MaxSize;\r
186 UINTN TmpTokenNumber;\r
58f1099f 187 //\r
188 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
189 // We have to decrement TokenNumber by 1 to make it usable\r
190 // as the array index.\r
191 //\r
192 TokenNumber--;\r
1de04b4f 193\r
194 //\r
195 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber\r
196 // \r
197 TmpTokenNumber = TokenNumber;\r
198\r
4f914125 199 // EBC compiler is very choosy. It may report warning about comparison\r
200 // between UINTN and 0 . So we add 1 in each size of the \r
201 // comparison.\r
202 ASSERT (TokenNumber + 1 < PCD_TOTAL_TOKEN_NUMBER + 1);\r
203\r
204 // EBC compiler is very choosy. It may report warning about comparison\r
205 // between UINTN and 0 . So we add 1 in each size of the \r
206 // comparison.\r
207 IsPeiDb = (BOOLEAN) (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);\r
58f1099f 208 \r
1de04b4f 209 TokenNumber = IsPeiDb ? TokenNumber : \r
210 (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);\r
52e1905d 211\r
1de04b4f 212 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable \r
213 : mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;\r
52e1905d 214\r
1de04b4f 215 Size = (LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
216\r
217 if (Size == 0) {\r
218 //\r
219 // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r
220 //\r
221 return GetPtrTypeSize (TmpTokenNumber, &MaxSize);\r
222 } else {\r
223 return Size;\r
224 }\r
52e1905d 225\r
878ddf1f 226}\r
227\r
228\r
229\r
230UINT8\r
231EFIAPI\r
232DxePcdGet8Ex (\r
52e1905d 233 IN CONST EFI_GUID *Guid,\r
8a43e8dd 234 IN UINTN ExTokenNumber\r
878ddf1f 235 )\r
236{\r
52e1905d 237 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));\r
878ddf1f 238}\r
239\r
240\r
241\r
242UINT16\r
243EFIAPI\r
244DxePcdGet16Ex (\r
245 IN CONST EFI_GUID *Guid,\r
8a43e8dd 246 IN UINTN ExTokenNumber\r
878ddf1f 247 )\r
248{\r
9d6d8b24 249 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));\r
878ddf1f 250}\r
251\r
252\r
253\r
254UINT32\r
255EFIAPI\r
256DxePcdGet32Ex (\r
257 IN CONST EFI_GUID *Guid,\r
8a43e8dd 258 IN UINTN ExTokenNumber\r
878ddf1f 259 )\r
260{\r
9d6d8b24 261 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));\r
878ddf1f 262}\r
263\r
264\r
265\r
266UINT64\r
267EFIAPI\r
268DxePcdGet64Ex (\r
269 IN CONST EFI_GUID *Guid,\r
8a43e8dd 270 IN UINTN ExTokenNumber\r
878ddf1f 271 )\r
272{\r
9d6d8b24 273 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));\r
878ddf1f 274}\r
275\r
276\r
277\r
278VOID *\r
279EFIAPI\r
280DxePcdGetPtrEx (\r
281 IN CONST EFI_GUID *Guid,\r
8a43e8dd 282 IN UINTN ExTokenNumber\r
878ddf1f 283 )\r
284{\r
1de04b4f 285 return ExGetWorker (Guid, ExTokenNumber, 0);\r
878ddf1f 286}\r
287\r
288\r
289\r
290BOOLEAN\r
291EFIAPI\r
292DxePcdGetBoolEx (\r
293 IN CONST EFI_GUID *Guid,\r
8a43e8dd 294 IN UINTN ExTokenNumber\r
878ddf1f 295 )\r
296{\r
52e1905d 297 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));\r
878ddf1f 298}\r
299\r
300\r
301\r
302UINTN\r
303EFIAPI\r
304DxePcdGetSizeEx (\r
305 IN CONST EFI_GUID *Guid,\r
8a43e8dd 306 IN UINTN ExTokenNumber\r
878ddf1f 307 )\r
308{\r
4f242357 309 return DxePcdGetSize(GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber));\r
878ddf1f 310}\r
311\r
312\r
313\r
314EFI_STATUS\r
315EFIAPI\r
316DxePcdSet8 (\r
8a43e8dd 317 IN UINTN TokenNumber,\r
52e1905d 318 IN UINT8 Value\r
878ddf1f 319 )\r
320{\r
1de04b4f 321 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 322}\r
323\r
324\r
325\r
326EFI_STATUS\r
327EFIAPI\r
328DxePcdSet16 (\r
8a43e8dd 329 IN UINTN TokenNumber,\r
878ddf1f 330 IN UINT16 Value\r
331 )\r
332{\r
1de04b4f 333 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 334}\r
335\r
336\r
337\r
338EFI_STATUS\r
339EFIAPI\r
340DxePcdSet32 (\r
8a43e8dd 341 IN UINTN TokenNumber,\r
878ddf1f 342 IN UINT32 Value\r
343 )\r
344{\r
1de04b4f 345 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 346}\r
347\r
348\r
349\r
350EFI_STATUS\r
351EFIAPI\r
352DxePcdSet64 (\r
8a43e8dd 353 IN UINTN TokenNumber,\r
52e1905d 354 IN UINT64 Value\r
878ddf1f 355 )\r
356{\r
1de04b4f 357 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 358}\r
359\r
360\r
361\r
362EFI_STATUS\r
363EFIAPI\r
364DxePcdSetPtr (\r
1de04b4f 365 IN UINTN TokenNumber,\r
366 IN OUT UINTN *SizeOfBuffer,\r
367 IN VOID *Buffer\r
878ddf1f 368 )\r
369{\r
00b7af13 370 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
878ddf1f 371}\r
372\r
373\r
374\r
375EFI_STATUS\r
376EFIAPI\r
377DxePcdSetBool (\r
8a43e8dd 378 IN UINTN TokenNumber,\r
52e1905d 379 IN BOOLEAN Value\r
878ddf1f 380 )\r
381{\r
1de04b4f 382 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 383}\r
384\r
385\r
386\r
387EFI_STATUS\r
388EFIAPI\r
389DxePcdSet8Ex (\r
4c114006 390 IN CONST EFI_GUID *Guid,\r
8a43e8dd 391 IN UINTN ExTokenNumber,\r
52e1905d 392 IN UINT8 Value\r
878ddf1f 393 )\r
394{\r
1de04b4f 395 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 396}\r
397\r
398\r
399\r
400EFI_STATUS\r
401EFIAPI\r
402DxePcdSet16Ex (\r
4c114006 403 IN CONST EFI_GUID *Guid,\r
8a43e8dd 404 IN UINTN ExTokenNumber,\r
878ddf1f 405 IN UINT16 Value\r
406 )\r
407{\r
1de04b4f 408 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 409}\r
410\r
411\r
412\r
413EFI_STATUS\r
414EFIAPI\r
415DxePcdSet32Ex (\r
4c114006 416 IN CONST EFI_GUID *Guid,\r
8a43e8dd 417 IN UINTN ExTokenNumber,\r
878ddf1f 418 IN UINT32 Value\r
419 )\r
420{\r
1de04b4f 421 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 422}\r
423\r
424\r
425\r
426EFI_STATUS\r
427EFIAPI\r
428DxePcdSet64Ex (\r
4c114006 429 IN CONST EFI_GUID *Guid,\r
8a43e8dd 430 IN UINTN ExTokenNumber,\r
878ddf1f 431 IN UINT64 Value\r
432 )\r
433{\r
1de04b4f 434 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 435}\r
436\r
437\r
438\r
439EFI_STATUS\r
440EFIAPI\r
441DxePcdSetPtrEx (\r
1de04b4f 442 IN CONST EFI_GUID *Guid,\r
443 IN UINTN ExTokenNumber,\r
444 IN OUT UINTN *SizeOfBuffer,\r
445 IN VOID *Buffer\r
878ddf1f 446 )\r
447{\r
1de04b4f 448 return ExSetWorker(ExTokenNumber, Guid, Buffer, SizeOfBuffer, TRUE);\r
878ddf1f 449}\r
450\r
451\r
452\r
453EFI_STATUS\r
454EFIAPI\r
455DxePcdSetBoolEx (\r
4c114006 456 IN CONST EFI_GUID *Guid,\r
8a43e8dd 457 IN UINTN ExTokenNumber,\r
878ddf1f 458 IN BOOLEAN Value\r
459 )\r
460{\r
1de04b4f 461 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 462}\r
463\r
464\r
465\r
466\r
467EFI_STATUS\r
468EFIAPI\r
4c114006 469DxeRegisterCallBackOnSet (\r
4c114006 470 IN CONST EFI_GUID *Guid, OPTIONAL\r
2a870f53 471 IN UINTN TokenNumber,\r
878ddf1f 472 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
473 )\r
474{\r
4c114006 475 ASSERT (CallBackFunction != NULL);\r
476 \r
477 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
878ddf1f 478}\r
479\r
480\r
481\r
482EFI_STATUS\r
483EFIAPI\r
4c114006 484DxeUnRegisterCallBackOnSet (\r
4c114006 485 IN CONST EFI_GUID *Guid, OPTIONAL\r
2a870f53 486 IN UINTN TokenNumber,\r
878ddf1f 487 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
488 )\r
489{\r
4c114006 490 ASSERT (CallBackFunction != NULL);\r
491 \r
58f1099f 492 return DxeUnRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
878ddf1f 493}\r
494\r
495\r
496\r
497EFI_STATUS\r
498EFIAPI\r
499DxePcdGetNextToken (\r
4c114006 500 IN CONST EFI_GUID *Guid, OPTIONAL\r
8a43e8dd 501 IN OUT UINTN *TokenNumber\r
878ddf1f 502 )\r
503{\r
2b21a971 504 EFI_STATUS Status;\r
505\r
4f914125 506 if (!FeaturePcdGet (PcdDxePcdDatabaseTraverseEnabled)) {\r
507 return EFI_UNSUPPORTED;\r
508 }\r
509\r
2b21a971 510 Status = EFI_NOT_FOUND;\r
4c114006 511 //\r
512 // Scan the local token space\r
513 //\r
514 if (Guid == NULL) {\r
4f914125 515 // EBC compiler is very choosy. It may report warning about comparison\r
516 // between UINTN and 0 . So we add 1 in each size of the \r
517 // comparison.\r
518 if (((*TokenNumber + 1 > PEI_NEX_TOKEN_NUMBER + 1) && (*TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1)) ||\r
519 ((*TokenNumber + 1 > (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER + 1)))) {\r
2b21a971 520 return EFI_NOT_FOUND;\r
521 }\r
522 \r
dcec7651 523 (*TokenNumber)++;\r
4f914125 524 if ((*TokenNumber + 1 > PEI_NEX_TOKEN_NUMBER + 1) &&\r
525 (*TokenNumber <= PEI_LOCAL_TOKEN_NUMBER)) {\r
c24ba2f6 526 //\r
527 // The first Non-Ex type Token Number for DXE PCD \r
528 // database is PEI_LOCAL_TOKEN_NUMBER\r
529 //\r
530 *TokenNumber = PEI_LOCAL_TOKEN_NUMBER;\r
4f914125 531 } else if (*TokenNumber + 1 > DXE_NEX_TOKEN_NUMBER + PEI_LOCAL_TOKEN_NUMBER + 1) {\r
c24ba2f6 532 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
4c114006 533 }\r
c24ba2f6 534 return EFI_SUCCESS;\r
4c114006 535 }\r
536\r
c24ba2f6 537 if (PEI_EXMAP_TABLE_EMPTY && DXE_EXMAP_TABLE_EMPTY) {\r
538 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
4c114006 539 return EFI_NOT_FOUND;\r
540 }\r
541\r
4c114006 542 if (!PEI_EXMAP_TABLE_EMPTY) {\r
2b21a971 543 Status = ExGetNextTokeNumber (\r
4c114006 544 Guid,\r
2b21a971 545 TokenNumber,\r
4c114006 546 mPcdDatabase->PeiDb.Init.GuidTable,\r
547 sizeof(mPcdDatabase->PeiDb.Init.GuidTable),\r
548 mPcdDatabase->PeiDb.Init.ExMapTable,\r
549 sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)\r
550 );\r
551 }\r
552\r
2b21a971 553 if (Status == EFI_SUCCESS) {\r
554 return Status;\r
555 }\r
556\r
557 if (!DXE_EXMAP_TABLE_EMPTY) {\r
558 Status = ExGetNextTokeNumber (\r
4c114006 559 Guid,\r
2b21a971 560 TokenNumber,\r
c24ba2f6 561 mPcdDatabase->DxeDb.Init.GuidTable,\r
562 sizeof(mPcdDatabase->DxeDb.Init.GuidTable),\r
563 mPcdDatabase->DxeDb.Init.ExMapTable,\r
564 sizeof(mPcdDatabase->DxeDb.Init.ExMapTable)\r
4c114006 565 );\r
566 }\r
567\r
2b21a971 568 return Status;\r
878ddf1f 569}\r
570\r
4276d5da 571\r
572EFI_GUID **\r
573GetDistinctTokenSpace (\r
574 IN OUT UINTN *ExMapTableSize,\r
575 IN DYNAMICEX_MAPPING *ExMapTable,\r
576 IN EFI_GUID *GuidTable\r
577 )\r
578{\r
579 EFI_GUID **DistinctTokenSpace;\r
580 UINTN OldGuidIndex;\r
581 UINTN TsIdx;\r
582 UINTN Idx;\r
583\r
584\r
585 DistinctTokenSpace = AllocateZeroPool (*ExMapTableSize * sizeof (EFI_GUID *));\r
586 ASSERT (DistinctTokenSpace != NULL);\r
587\r
588 TsIdx = 0;\r
589 OldGuidIndex = ExMapTable[0].ExGuidIndex;\r
590 DistinctTokenSpace[TsIdx] = &GuidTable[OldGuidIndex];\r
c24ba2f6 591 for (Idx = 1; Idx < *ExMapTableSize; Idx++) {\r
4276d5da 592 if (ExMapTable[Idx].ExGuidIndex != OldGuidIndex) {\r
593 OldGuidIndex = ExMapTable[Idx].ExGuidIndex;\r
594 DistinctTokenSpace[++TsIdx] = &GuidTable[OldGuidIndex];\r
595 }\r
596 }\r
597\r
c24ba2f6 598 //\r
599 // The total number of Distinct Token Space\r
600 // is TsIdx + 1 because we use TsIdx as a index\r
601 // to the DistinctTokenSpace[]\r
602 //\r
603 *ExMapTableSize = TsIdx + 1;\r
4276d5da 604 return DistinctTokenSpace;\r
605 \r
606}\r
607 \r
c24ba2f6 608//\r
609// Just pre-allocate a memory buffer that is big enough to\r
610// host all distinct TokenSpace guid in both\r
611// PEI ExMap and DXE ExMap.\r
612//\r
4276d5da 613STATIC EFI_GUID *TmpTokenSpaceBuffer[PEI_EXMAPPING_TABLE_SIZE + DXE_EXMAPPING_TABLE_SIZE] = { 0 };\r
614\r
615EFI_STATUS\r
616EFIAPI\r
617DxePcdGetNextTokenSpace (\r
618 IN OUT CONST EFI_GUID **Guid\r
619 )\r
620{\r
621 UINTN Idx;\r
622 UINTN Idx2;\r
623 UINTN Idx3;\r
624 UINTN PeiTokenSpaceTableSize;\r
625 UINTN DxeTokenSpaceTableSize;\r
626 EFI_GUID **PeiTokenSpaceTable;\r
627 EFI_GUID **DxeTokenSpaceTable;\r
628 BOOLEAN Match;\r
629\r
4f914125 630 if (!FeaturePcdGet (PcdDxePcdDatabaseTraverseEnabled)) {\r
631 return EFI_UNSUPPORTED;\r
632 }\r
633\r
4276d5da 634 ASSERT (Guid != NULL);\r
635 \r
636 if (PEI_EXMAP_TABLE_EMPTY && DXE_EXMAP_TABLE_EMPTY) {\r
637 if (*Guid != NULL) {\r
638 return EFI_NOT_FOUND;\r
639 } else {\r
640 return EFI_SUCCESS;\r
641 }\r
642 }\r
643 \r
644 \r
c24ba2f6 645 if (TmpTokenSpaceBuffer[0] == NULL) {\r
4276d5da 646 PeiTokenSpaceTableSize = 0;\r
647\r
648 if (!PEI_EXMAP_TABLE_EMPTY) {\r
649 PeiTokenSpaceTableSize = PEI_EXMAPPING_TABLE_SIZE;\r
650 PeiTokenSpaceTable = GetDistinctTokenSpace (&PeiTokenSpaceTableSize,\r
651 mPcdDatabase->PeiDb.Init.ExMapTable,\r
652 mPcdDatabase->PeiDb.Init.GuidTable\r
653 );\r
654 CopyMem (TmpTokenSpaceBuffer, PeiTokenSpaceTable, sizeof (EFI_GUID*) * PeiTokenSpaceTableSize);\r
655 }\r
656\r
657 if (!DXE_EXMAP_TABLE_EMPTY) {\r
658 DxeTokenSpaceTableSize = DXE_EXMAPPING_TABLE_SIZE;\r
659 DxeTokenSpaceTable = GetDistinctTokenSpace (&DxeTokenSpaceTableSize,\r
660 mPcdDatabase->DxeDb.Init.ExMapTable,\r
661 mPcdDatabase->DxeDb.Init.GuidTable\r
662 );\r
663\r
664 //\r
665 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable\r
666 //\r
667 for (Idx2 = 0, Idx3 = PeiTokenSpaceTableSize; Idx2 < DxeTokenSpaceTableSize; Idx2++) {\r
668 Match = FALSE;\r
669 for (Idx = 0; Idx < PeiTokenSpaceTableSize; Idx++) {\r
670 if (CompareGuid (TmpTokenSpaceBuffer[Idx], DxeTokenSpaceTable[Idx2])) {\r
671 Match = TRUE;\r
672 break;\r
673 }\r
674 }\r
675 if (!Match) {\r
676 TmpTokenSpaceBuffer[Idx3++] = DxeTokenSpaceTable[Idx2];\r
677 }\r
678 }\r
679 }\r
680 }\r
681\r
682 if (*Guid == NULL) {\r
683 *Guid = TmpTokenSpaceBuffer[0];\r
684 return EFI_SUCCESS;\r
685 }\r
686 \r
687 for (Idx = 0; Idx < (PEI_EXMAPPING_TABLE_SIZE + DXE_EXMAPPING_TABLE_SIZE); Idx++) {\r
688 if(CompareGuid (*Guid, TmpTokenSpaceBuffer[Idx])) {\r
689 Idx++;\r
690 *Guid = TmpTokenSpaceBuffer[Idx];\r
691 return EFI_SUCCESS;\r
692 }\r
693 }\r
694\r
695 return EFI_NOT_FOUND;\r
696\r
697}\r
698\r
699\r