Added type cast (VOID *) to the third parameter of GetHiiVariable, to avoid compiling...
[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
64static EFI_HANDLE NewHandle = NULL;\r
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
83 //\r
84 // BugBug Check if PcdDatabase is already installed.\r
85 //\r
878ddf1f 86 \r
87 Status = gBS->InstallProtocolInterface (\r
88 &NewHandle,\r
89 &gPcdProtocolGuid,\r
90 EFI_NATIVE_INTERFACE,\r
91 &mPcdInstance\r
92 );\r
93\r
94 ASSERT_EFI_ERROR (Status);\r
95\r
96 return EFI_SUCCESS;\r
97\r
98}\r
99\r
100\r
00b7af13 101VOID\r
878ddf1f 102EFIAPI\r
103DxePcdSetSku (\r
8a43e8dd 104 IN UINTN SkuId\r
878ddf1f 105 )\r
106{\r
8a43e8dd 107 mPcdDatabase->PeiDb.Init.SystemSkuId = (SKU_ID) SkuId;\r
00b7af13 108 \r
109 return;\r
878ddf1f 110}\r
111\r
112\r
113\r
114UINT8\r
115EFIAPI\r
116DxePcdGet8 (\r
8a43e8dd 117 IN UINTN TokenNumber\r
878ddf1f 118 )\r
119{\r
9d6d8b24 120 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
878ddf1f 121}\r
122\r
123\r
124\r
125UINT16\r
126EFIAPI\r
127DxePcdGet16 (\r
8a43e8dd 128 IN UINTN TokenNumber\r
878ddf1f 129 )\r
130{\r
9d6d8b24 131 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
878ddf1f 132}\r
133\r
134\r
135\r
136UINT32\r
137EFIAPI\r
138DxePcdGet32 (\r
8a43e8dd 139 IN UINTN TokenNumber\r
878ddf1f 140 )\r
141{\r
9d6d8b24 142 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
878ddf1f 143}\r
144\r
145\r
146\r
147UINT64\r
148EFIAPI\r
149DxePcdGet64 (\r
8a43e8dd 150 IN UINTN TokenNumber\r
878ddf1f 151 )\r
152{\r
9d6d8b24 153 return ReadUnaligned64(GetWorker (TokenNumber, sizeof (UINT64)));\r
878ddf1f 154}\r
155\r
156\r
157\r
158VOID *\r
159EFIAPI\r
160DxePcdGetPtr (\r
8a43e8dd 161 IN UINTN TokenNumber\r
878ddf1f 162 )\r
163{\r
9d6d8b24 164 return GetWorker (TokenNumber, 0);\r
878ddf1f 165}\r
166\r
167\r
168\r
169BOOLEAN\r
170EFIAPI\r
171DxePcdGetBool (\r
8a43e8dd 172 IN UINTN TokenNumber\r
878ddf1f 173 )\r
174{\r
9d6d8b24 175 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
878ddf1f 176}\r
177\r
178\r
179\r
180UINTN\r
181EFIAPI\r
182DxePcdGetSize (\r
8a43e8dd 183 IN UINTN TokenNumber\r
878ddf1f 184 )\r
185{\r
1de04b4f 186 UINTN Size;\r
187 UINT32 *LocalTokenNumberTable;\r
188 BOOLEAN IsPeiDb;\r
189 UINTN MaxSize;\r
190 UINTN TmpTokenNumber;\r
58f1099f 191 //\r
192 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
193 // We have to decrement TokenNumber by 1 to make it usable\r
194 // as the array index.\r
195 //\r
196 TokenNumber--;\r
1de04b4f 197\r
198 //\r
199 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber\r
200 // \r
201 TmpTokenNumber = TokenNumber;\r
202\r
203 ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);\r
204\r
205 IsPeiDb = (BOOLEAN) (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);\r
58f1099f 206 \r
1de04b4f 207 TokenNumber = IsPeiDb ? TokenNumber : \r
208 (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);\r
52e1905d 209\r
1de04b4f 210 LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable \r
211 : mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;\r
52e1905d 212\r
1de04b4f 213 Size = (LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
214\r
215 if (Size == 0) {\r
216 //\r
217 // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r
218 //\r
219 return GetPtrTypeSize (TmpTokenNumber, &MaxSize);\r
220 } else {\r
221 return Size;\r
222 }\r
52e1905d 223\r
878ddf1f 224}\r
225\r
226\r
227\r
228UINT8\r
229EFIAPI\r
230DxePcdGet8Ex (\r
52e1905d 231 IN CONST EFI_GUID *Guid,\r
8a43e8dd 232 IN UINTN ExTokenNumber\r
878ddf1f 233 )\r
234{\r
52e1905d 235 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof(UINT8)));\r
878ddf1f 236}\r
237\r
238\r
239\r
240UINT16\r
241EFIAPI\r
242DxePcdGet16Ex (\r
243 IN CONST EFI_GUID *Guid,\r
8a43e8dd 244 IN UINTN ExTokenNumber\r
878ddf1f 245 )\r
246{\r
9d6d8b24 247 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT16)));\r
878ddf1f 248}\r
249\r
250\r
251\r
252UINT32\r
253EFIAPI\r
254DxePcdGet32Ex (\r
255 IN CONST EFI_GUID *Guid,\r
8a43e8dd 256 IN UINTN ExTokenNumber\r
878ddf1f 257 )\r
258{\r
9d6d8b24 259 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT32)));\r
878ddf1f 260}\r
261\r
262\r
263\r
264UINT64\r
265EFIAPI\r
266DxePcdGet64Ex (\r
267 IN CONST EFI_GUID *Guid,\r
8a43e8dd 268 IN UINTN ExTokenNumber\r
878ddf1f 269 )\r
270{\r
9d6d8b24 271 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof(UINT64)));\r
878ddf1f 272}\r
273\r
274\r
275\r
276VOID *\r
277EFIAPI\r
278DxePcdGetPtrEx (\r
279 IN CONST EFI_GUID *Guid,\r
8a43e8dd 280 IN UINTN ExTokenNumber\r
878ddf1f 281 )\r
282{\r
1de04b4f 283 return ExGetWorker (Guid, ExTokenNumber, 0);\r
878ddf1f 284}\r
285\r
286\r
287\r
288BOOLEAN\r
289EFIAPI\r
290DxePcdGetBoolEx (\r
291 IN CONST EFI_GUID *Guid,\r
8a43e8dd 292 IN UINTN ExTokenNumber\r
878ddf1f 293 )\r
294{\r
52e1905d 295 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof(BOOLEAN)));\r
878ddf1f 296}\r
297\r
298\r
299\r
300UINTN\r
301EFIAPI\r
302DxePcdGetSizeEx (\r
303 IN CONST EFI_GUID *Guid,\r
8a43e8dd 304 IN UINTN ExTokenNumber\r
878ddf1f 305 )\r
306{\r
4f242357 307 return DxePcdGetSize(GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber));\r
878ddf1f 308}\r
309\r
310\r
311\r
312EFI_STATUS\r
313EFIAPI\r
314DxePcdSet8 (\r
8a43e8dd 315 IN UINTN TokenNumber,\r
52e1905d 316 IN UINT8 Value\r
878ddf1f 317 )\r
318{\r
1de04b4f 319 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 320}\r
321\r
322\r
323\r
324EFI_STATUS\r
325EFIAPI\r
326DxePcdSet16 (\r
8a43e8dd 327 IN UINTN TokenNumber,\r
878ddf1f 328 IN UINT16 Value\r
329 )\r
330{\r
1de04b4f 331 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 332}\r
333\r
334\r
335\r
336EFI_STATUS\r
337EFIAPI\r
338DxePcdSet32 (\r
8a43e8dd 339 IN UINTN TokenNumber,\r
878ddf1f 340 IN UINT32 Value\r
341 )\r
342{\r
1de04b4f 343 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 344}\r
345\r
346\r
347\r
348EFI_STATUS\r
349EFIAPI\r
350DxePcdSet64 (\r
8a43e8dd 351 IN UINTN TokenNumber,\r
52e1905d 352 IN UINT64 Value\r
878ddf1f 353 )\r
354{\r
1de04b4f 355 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 356}\r
357\r
358\r
359\r
360EFI_STATUS\r
361EFIAPI\r
362DxePcdSetPtr (\r
1de04b4f 363 IN UINTN TokenNumber,\r
364 IN OUT UINTN *SizeOfBuffer,\r
365 IN VOID *Buffer\r
878ddf1f 366 )\r
367{\r
00b7af13 368 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
878ddf1f 369}\r
370\r
371\r
372\r
373EFI_STATUS\r
374EFIAPI\r
375DxePcdSetBool (\r
8a43e8dd 376 IN UINTN TokenNumber,\r
52e1905d 377 IN BOOLEAN Value\r
878ddf1f 378 )\r
379{\r
1de04b4f 380 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
878ddf1f 381}\r
382\r
383\r
384\r
385EFI_STATUS\r
386EFIAPI\r
387DxePcdSet8Ex (\r
4c114006 388 IN CONST EFI_GUID *Guid,\r
8a43e8dd 389 IN UINTN ExTokenNumber,\r
52e1905d 390 IN UINT8 Value\r
878ddf1f 391 )\r
392{\r
1de04b4f 393 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 394}\r
395\r
396\r
397\r
398EFI_STATUS\r
399EFIAPI\r
400DxePcdSet16Ex (\r
4c114006 401 IN CONST EFI_GUID *Guid,\r
8a43e8dd 402 IN UINTN ExTokenNumber,\r
878ddf1f 403 IN UINT16 Value\r
404 )\r
405{\r
1de04b4f 406 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 407}\r
408\r
409\r
410\r
411EFI_STATUS\r
412EFIAPI\r
413DxePcdSet32Ex (\r
4c114006 414 IN CONST EFI_GUID *Guid,\r
8a43e8dd 415 IN UINTN ExTokenNumber,\r
878ddf1f 416 IN UINT32 Value\r
417 )\r
418{\r
1de04b4f 419 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 420}\r
421\r
422\r
423\r
424EFI_STATUS\r
425EFIAPI\r
426DxePcdSet64Ex (\r
4c114006 427 IN CONST EFI_GUID *Guid,\r
8a43e8dd 428 IN UINTN ExTokenNumber,\r
878ddf1f 429 IN UINT64 Value\r
430 )\r
431{\r
1de04b4f 432 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 433}\r
434\r
435\r
436\r
437EFI_STATUS\r
438EFIAPI\r
439DxePcdSetPtrEx (\r
1de04b4f 440 IN CONST EFI_GUID *Guid,\r
441 IN UINTN ExTokenNumber,\r
442 IN OUT UINTN *SizeOfBuffer,\r
443 IN VOID *Buffer\r
878ddf1f 444 )\r
445{\r
1de04b4f 446 return ExSetWorker(ExTokenNumber, Guid, Buffer, SizeOfBuffer, TRUE);\r
878ddf1f 447}\r
448\r
449\r
450\r
451EFI_STATUS\r
452EFIAPI\r
453DxePcdSetBoolEx (\r
4c114006 454 IN CONST EFI_GUID *Guid,\r
8a43e8dd 455 IN UINTN ExTokenNumber,\r
878ddf1f 456 IN BOOLEAN Value\r
457 )\r
458{\r
1de04b4f 459 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
878ddf1f 460}\r
461\r
462\r
463\r
464\r
465EFI_STATUS\r
466EFIAPI\r
4c114006 467DxeRegisterCallBackOnSet (\r
8a43e8dd 468 IN UINTN TokenNumber,\r
4c114006 469 IN CONST EFI_GUID *Guid, OPTIONAL\r
878ddf1f 470 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
471 )\r
472{\r
4c114006 473 ASSERT (CallBackFunction != NULL);\r
474 \r
475 return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
878ddf1f 476}\r
477\r
478\r
479\r
480EFI_STATUS\r
481EFIAPI\r
4c114006 482DxeUnRegisterCallBackOnSet (\r
8a43e8dd 483 IN UINTN TokenNumber,\r
4c114006 484 IN CONST EFI_GUID *Guid, OPTIONAL\r
878ddf1f 485 IN PCD_PROTOCOL_CALLBACK CallBackFunction\r
486 )\r
487{\r
4c114006 488 ASSERT (CallBackFunction != NULL);\r
489 \r
58f1099f 490 return DxeUnRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);\r
878ddf1f 491}\r
492\r
493\r
494\r
495EFI_STATUS\r
496EFIAPI\r
497DxePcdGetNextToken (\r
4c114006 498 IN CONST EFI_GUID *Guid, OPTIONAL\r
8a43e8dd 499 IN OUT UINTN *TokenNumber\r
878ddf1f 500 )\r
501{\r
8a43e8dd 502 UINTN ExTokenNumber;\r
4c114006 503 \r
504 //\r
505 // Scan the local token space\r
506 //\r
507 if (Guid == NULL) {\r
dcec7651 508 (*TokenNumber)++;\r
c24ba2f6 509 if (*TokenNumber > PEI_NEX_TOKEN_NUMBER &&\r
510 *TokenNumber <= PEI_LOCAL_TOKEN_NUMBER) {\r
511 //\r
512 // The first Non-Ex type Token Number for DXE PCD \r
513 // database is PEI_LOCAL_TOKEN_NUMBER\r
514 //\r
515 *TokenNumber = PEI_LOCAL_TOKEN_NUMBER;\r
516 } else if (*TokenNumber > DXE_NEX_TOKEN_NUMBER + PEI_LOCAL_TOKEN_NUMBER) {\r
517 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
4c114006 518 }\r
c24ba2f6 519 return EFI_SUCCESS;\r
4c114006 520 }\r
521\r
c24ba2f6 522 if (PEI_EXMAP_TABLE_EMPTY && DXE_EXMAP_TABLE_EMPTY) {\r
523 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
4c114006 524 return EFI_NOT_FOUND;\r
525 }\r
526\r
4c114006 527 if (!PEI_EXMAP_TABLE_EMPTY) {\r
c24ba2f6 528 ExTokenNumber = *TokenNumber;\r
4c114006 529 ExTokenNumber = ExGetNextTokeNumber (\r
530 Guid,\r
531 ExTokenNumber,\r
532 mPcdDatabase->PeiDb.Init.GuidTable,\r
533 sizeof(mPcdDatabase->PeiDb.Init.GuidTable),\r
534 mPcdDatabase->PeiDb.Init.ExMapTable,\r
535 sizeof(mPcdDatabase->PeiDb.Init.ExMapTable)\r
536 );\r
537 }\r
538\r
4276d5da 539 if ((ExTokenNumber == PCD_INVALID_TOKEN_NUMBER) &&\r
540 !DXE_EXMAP_TABLE_EMPTY\r
541 ) {\r
c24ba2f6 542 ExTokenNumber = *TokenNumber;\r
4c114006 543 ExTokenNumber = ExGetNextTokeNumber (\r
544 Guid,\r
545 ExTokenNumber,\r
c24ba2f6 546 mPcdDatabase->DxeDb.Init.GuidTable,\r
547 sizeof(mPcdDatabase->DxeDb.Init.GuidTable),\r
548 mPcdDatabase->DxeDb.Init.ExMapTable,\r
549 sizeof(mPcdDatabase->DxeDb.Init.ExMapTable)\r
4c114006 550 );\r
551 }\r
552\r
553 *TokenNumber = ExTokenNumber;\r
554\r
555 return EFI_SUCCESS;\r
878ddf1f 556}\r
557\r
4276d5da 558\r
559EFI_GUID **\r
560GetDistinctTokenSpace (\r
561 IN OUT UINTN *ExMapTableSize,\r
562 IN DYNAMICEX_MAPPING *ExMapTable,\r
563 IN EFI_GUID *GuidTable\r
564 )\r
565{\r
566 EFI_GUID **DistinctTokenSpace;\r
567 UINTN OldGuidIndex;\r
568 UINTN TsIdx;\r
569 UINTN Idx;\r
570\r
571\r
572 DistinctTokenSpace = AllocateZeroPool (*ExMapTableSize * sizeof (EFI_GUID *));\r
573 ASSERT (DistinctTokenSpace != NULL);\r
574\r
575 TsIdx = 0;\r
576 OldGuidIndex = ExMapTable[0].ExGuidIndex;\r
577 DistinctTokenSpace[TsIdx] = &GuidTable[OldGuidIndex];\r
c24ba2f6 578 for (Idx = 1; Idx < *ExMapTableSize; Idx++) {\r
4276d5da 579 if (ExMapTable[Idx].ExGuidIndex != OldGuidIndex) {\r
580 OldGuidIndex = ExMapTable[Idx].ExGuidIndex;\r
581 DistinctTokenSpace[++TsIdx] = &GuidTable[OldGuidIndex];\r
582 }\r
583 }\r
584\r
c24ba2f6 585 //\r
586 // The total number of Distinct Token Space\r
587 // is TsIdx + 1 because we use TsIdx as a index\r
588 // to the DistinctTokenSpace[]\r
589 //\r
590 *ExMapTableSize = TsIdx + 1;\r
4276d5da 591 return DistinctTokenSpace;\r
592 \r
593}\r
594 \r
c24ba2f6 595//\r
596// Just pre-allocate a memory buffer that is big enough to\r
597// host all distinct TokenSpace guid in both\r
598// PEI ExMap and DXE ExMap.\r
599//\r
4276d5da 600STATIC EFI_GUID *TmpTokenSpaceBuffer[PEI_EXMAPPING_TABLE_SIZE + DXE_EXMAPPING_TABLE_SIZE] = { 0 };\r
601\r
602EFI_STATUS\r
603EFIAPI\r
604DxePcdGetNextTokenSpace (\r
605 IN OUT CONST EFI_GUID **Guid\r
606 )\r
607{\r
608 UINTN Idx;\r
609 UINTN Idx2;\r
610 UINTN Idx3;\r
611 UINTN PeiTokenSpaceTableSize;\r
612 UINTN DxeTokenSpaceTableSize;\r
613 EFI_GUID **PeiTokenSpaceTable;\r
614 EFI_GUID **DxeTokenSpaceTable;\r
615 BOOLEAN Match;\r
616\r
617 ASSERT (Guid != NULL);\r
618 \r
619 if (PEI_EXMAP_TABLE_EMPTY && DXE_EXMAP_TABLE_EMPTY) {\r
620 if (*Guid != NULL) {\r
621 return EFI_NOT_FOUND;\r
622 } else {\r
623 return EFI_SUCCESS;\r
624 }\r
625 }\r
626 \r
627 \r
c24ba2f6 628 if (TmpTokenSpaceBuffer[0] == NULL) {\r
4276d5da 629 PeiTokenSpaceTableSize = 0;\r
630\r
631 if (!PEI_EXMAP_TABLE_EMPTY) {\r
632 PeiTokenSpaceTableSize = PEI_EXMAPPING_TABLE_SIZE;\r
633 PeiTokenSpaceTable = GetDistinctTokenSpace (&PeiTokenSpaceTableSize,\r
634 mPcdDatabase->PeiDb.Init.ExMapTable,\r
635 mPcdDatabase->PeiDb.Init.GuidTable\r
636 );\r
637 CopyMem (TmpTokenSpaceBuffer, PeiTokenSpaceTable, sizeof (EFI_GUID*) * PeiTokenSpaceTableSize);\r
638 }\r
639\r
640 if (!DXE_EXMAP_TABLE_EMPTY) {\r
641 DxeTokenSpaceTableSize = DXE_EXMAPPING_TABLE_SIZE;\r
642 DxeTokenSpaceTable = GetDistinctTokenSpace (&DxeTokenSpaceTableSize,\r
643 mPcdDatabase->DxeDb.Init.ExMapTable,\r
644 mPcdDatabase->DxeDb.Init.GuidTable\r
645 );\r
646\r
647 //\r
648 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable\r
649 //\r
650 for (Idx2 = 0, Idx3 = PeiTokenSpaceTableSize; Idx2 < DxeTokenSpaceTableSize; Idx2++) {\r
651 Match = FALSE;\r
652 for (Idx = 0; Idx < PeiTokenSpaceTableSize; Idx++) {\r
653 if (CompareGuid (TmpTokenSpaceBuffer[Idx], DxeTokenSpaceTable[Idx2])) {\r
654 Match = TRUE;\r
655 break;\r
656 }\r
657 }\r
658 if (!Match) {\r
659 TmpTokenSpaceBuffer[Idx3++] = DxeTokenSpaceTable[Idx2];\r
660 }\r
661 }\r
662 }\r
663 }\r
664\r
665 if (*Guid == NULL) {\r
666 *Guid = TmpTokenSpaceBuffer[0];\r
667 return EFI_SUCCESS;\r
668 }\r
669 \r
670 for (Idx = 0; Idx < (PEI_EXMAPPING_TABLE_SIZE + DXE_EXMAPPING_TABLE_SIZE); Idx++) {\r
671 if(CompareGuid (*Guid, TmpTokenSpaceBuffer[Idx])) {\r
672 Idx++;\r
673 *Guid = TmpTokenSpaceBuffer[Idx];\r
674 return EFI_SUCCESS;\r
675 }\r
676 }\r
677\r
678 return EFI_NOT_FOUND;\r
679\r
680}\r
681\r
682\r