]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/UefiHandleParsingLib: fix IN/OUT notation in child ctrlr parsing
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
1 /** @file
2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
3
4 Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
6 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "UefiHandleParsingLib.h"
18 #include "IndustryStandard/Acpi10.h"
19
20 EFI_HANDLE mHandleParsingHiiHandle = NULL;
21 HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};
22 GUID_INFO_BLOCK *GuidList;
23 UINTN GuidListCount;
24 /**
25 Function to translate the EFI_MEMORY_TYPE into a string.
26
27 @param[in] Memory The memory type.
28
29 @retval A string representation of the type allocated from BS Pool.
30 **/
31 CHAR16*
32 EFIAPI
33 ConvertMemoryType (
34 IN CONST EFI_MEMORY_TYPE Memory
35 )
36 {
37 CHAR16 *RetVal;
38 RetVal = NULL;
39
40 switch (Memory) {
41 case EfiReservedMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiReservedMemoryType", 0); break;
42 case EfiLoaderCode: StrnCatGrow(&RetVal, NULL, L"EfiLoaderCode", 0); break;
43 case EfiLoaderData: StrnCatGrow(&RetVal, NULL, L"EfiLoaderData", 0); break;
44 case EfiBootServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesCode", 0); break;
45 case EfiBootServicesData: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesData", 0); break;
46 case EfiRuntimeServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesCode", 0); break;
47 case EfiRuntimeServicesData: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesData", 0); break;
48 case EfiConventionalMemory: StrnCatGrow(&RetVal, NULL, L"EfiConventionalMemory", 0); break;
49 case EfiUnusableMemory: StrnCatGrow(&RetVal, NULL, L"EfiUnusableMemory", 0); break;
50 case EfiACPIReclaimMemory: StrnCatGrow(&RetVal, NULL, L"EfiACPIReclaimMemory", 0); break;
51 case EfiACPIMemoryNVS: StrnCatGrow(&RetVal, NULL, L"EfiACPIMemoryNVS", 0); break;
52 case EfiMemoryMappedIO: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIO", 0); break;
53 case EfiMemoryMappedIOPortSpace: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIOPortSpace", 0); break;
54 case EfiPalCode: StrnCatGrow(&RetVal, NULL, L"EfiPalCode", 0); break;
55 case EfiMaxMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiMaxMemoryType", 0); break;
56 default: ASSERT(FALSE);
57 }
58 return (RetVal);
59 }
60
61 /**
62 Function to translate the EFI_GRAPHICS_PIXEL_FORMAT into a string.
63
64 @param[in] Fmt The format type.
65
66 @retval A string representation of the type allocated from BS Pool.
67 **/
68 CHAR16*
69 EFIAPI
70 ConvertPixelFormat (
71 IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt
72 )
73 {
74 CHAR16 *RetVal;
75 RetVal = NULL;
76
77 switch (Fmt) {
78 case PixelRedGreenBlueReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelRedGreenBlueReserved8BitPerColor", 0); break;
79 case PixelBlueGreenRedReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelBlueGreenRedReserved8BitPerColor", 0); break;
80 case PixelBitMask: StrnCatGrow(&RetVal, NULL, L"PixelBitMask", 0); break;
81 case PixelBltOnly: StrnCatGrow(&RetVal, NULL, L"PixelBltOnly", 0); break;
82 case PixelFormatMax: StrnCatGrow(&RetVal, NULL, L"PixelFormatMax", 0); break;
83 default: ASSERT(FALSE);
84 }
85 return (RetVal);
86 }
87
88 /**
89 Constructor for the library.
90
91 @param[in] ImageHandle Ignored.
92 @param[in] SystemTable Ignored.
93
94 @retval EFI_SUCCESS The operation was successful.
95 **/
96 EFI_STATUS
97 EFIAPI
98 HandleParsingLibConstructor (
99 IN EFI_HANDLE ImageHandle,
100 IN EFI_SYSTEM_TABLE *SystemTable
101 )
102 {
103 GuidListCount = 0;
104 GuidList = NULL;
105
106 //
107 // Do nothing with mHandleParsingHiiHandle. Initialize HII as needed.
108 //
109 return (EFI_SUCCESS);
110 }
111
112 /**
113 Initialization function for HII packages.
114
115 **/
116 VOID
117 HandleParsingHiiInit (VOID)
118 {
119 if (mHandleParsingHiiHandle == NULL) {
120 mHandleParsingHiiHandle = HiiAddPackages (&gHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);
121 ASSERT (mHandleParsingHiiHandle != NULL);
122 }
123 }
124
125 /**
126 Destructor for the library. free any resources.
127
128 @param[in] ImageHandle Ignored.
129 @param[in] SystemTable Ignored.
130
131 @retval EFI_SUCCESS The operation was successful.
132 **/
133 EFI_STATUS
134 EFIAPI
135 HandleParsingLibDestructor (
136 IN EFI_HANDLE ImageHandle,
137 IN EFI_SYSTEM_TABLE *SystemTable
138 )
139 {
140 UINTN LoopCount;
141
142 for (LoopCount = 0; GuidList != NULL && LoopCount < GuidListCount; LoopCount++) {
143 SHELL_FREE_NON_NULL(GuidList[LoopCount].GuidId);
144 }
145
146 SHELL_FREE_NON_NULL(GuidList);
147 if (mHandleParsingHiiHandle != NULL) {
148 HiiRemovePackages(mHandleParsingHiiHandle);
149 }
150 return (EFI_SUCCESS);
151 }
152
153 /**
154 Function to dump information about LoadedImage.
155
156 This will allocate the return buffer from boot services pool.
157
158 @param[in] TheHandle The handle that has LoadedImage installed.
159 @param[in] Verbose TRUE for additional information, FALSE otherwise.
160
161 @retval A poitner to a string containing the information.
162 **/
163 CHAR16*
164 EFIAPI
165 LoadedImageProtocolDumpInformation(
166 IN CONST EFI_HANDLE TheHandle,
167 IN CONST BOOLEAN Verbose
168 )
169 {
170 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
171 EFI_STATUS Status;
172 CHAR16 *RetVal;
173 CHAR16 *Temp;
174 CHAR16 *CodeType;
175 CHAR16 *DataType;
176
177 if (!Verbose) {
178 return (CatSPrint(NULL, L"LoadedImage"));
179 }
180
181 HandleParsingHiiInit();
182
183 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);
184 if (Temp == NULL) {
185 return NULL;
186 }
187
188 Status = gBS->OpenProtocol (
189 TheHandle,
190 &gEfiLoadedImageProtocolGuid,
191 (VOID**)&LoadedImage,
192 gImageHandle,
193 NULL,
194 EFI_OPEN_PROTOCOL_GET_PROTOCOL
195 );
196
197 if (EFI_ERROR (Status)) {
198 SHELL_FREE_NON_NULL (Temp);
199 return NULL;
200 }
201
202 DataType = ConvertMemoryType(LoadedImage->ImageDataType);
203 CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);
204
205 RetVal = CatSPrint(
206 NULL,
207 Temp,
208 LoadedImage->Revision,
209 LoadedImage->ParentHandle,
210 LoadedImage->SystemTable,
211 LoadedImage->DeviceHandle,
212 LoadedImage->FilePath,
213 LoadedImage->LoadOptionsSize,
214 LoadedImage->LoadOptions,
215 LoadedImage->ImageBase,
216 LoadedImage->ImageSize,
217 CodeType,
218 DataType,
219 LoadedImage->Unload
220 );
221
222
223 SHELL_FREE_NON_NULL(Temp);
224 SHELL_FREE_NON_NULL(CodeType);
225 SHELL_FREE_NON_NULL(DataType);
226
227 return RetVal;
228 }
229
230 /**
231 Function to dump information about GOP.
232
233 This will allocate the return buffer from boot services pool.
234
235 @param[in] TheHandle The handle that has LoadedImage installed.
236 @param[in] Verbose TRUE for additional information, FALSE otherwise.
237
238 @retval A poitner to a string containing the information.
239 **/
240 CHAR16*
241 EFIAPI
242 GraphicsOutputProtocolDumpInformation(
243 IN CONST EFI_HANDLE TheHandle,
244 IN CONST BOOLEAN Verbose
245 )
246 {
247 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
248 EFI_STATUS Status;
249 CHAR16 *RetVal;
250 CHAR16 *Temp;
251 CHAR16 *Fmt;
252 CHAR16 *TempRetVal;
253 UINTN GopInfoSize;
254 UINT32 Mode;
255 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopInfo;
256
257 if (!Verbose) {
258 return (CatSPrint(NULL, L"GraphicsOutput"));
259 }
260
261 HandleParsingHiiInit();
262
263 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_GOP_DUMP_MAIN), NULL);
264 if (Temp == NULL) {
265 return NULL;
266 }
267
268 Status = gBS->OpenProtocol (
269 TheHandle,
270 &gEfiGraphicsOutputProtocolGuid,
271 (VOID**)&GraphicsOutput,
272 gImageHandle,
273 NULL,
274 EFI_OPEN_PROTOCOL_GET_PROTOCOL
275 );
276
277 if (EFI_ERROR (Status)) {
278 SHELL_FREE_NON_NULL (Temp);
279 return NULL;
280 }
281
282 Fmt = ConvertPixelFormat(GraphicsOutput->Mode->Info->PixelFormat);
283
284 RetVal = CatSPrint(
285 NULL,
286 Temp,
287 GraphicsOutput->Mode->MaxMode,
288 GraphicsOutput->Mode->Mode,
289 GraphicsOutput->Mode->FrameBufferBase,
290 (UINT64)GraphicsOutput->Mode->FrameBufferSize,
291 (UINT64)GraphicsOutput->Mode->SizeOfInfo,
292 GraphicsOutput->Mode->Info->Version,
293 GraphicsOutput->Mode->Info->HorizontalResolution,
294 GraphicsOutput->Mode->Info->VerticalResolution,
295 Fmt,
296 GraphicsOutput->Mode->Info->PixelsPerScanLine,
297 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.RedMask,
298 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.GreenMask,
299 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.BlueMask
300 );
301
302 SHELL_FREE_NON_NULL (Temp);
303
304 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_GOP_RES_LIST_MAIN), NULL);
305 if (Temp == NULL) {
306 SHELL_FREE_NON_NULL (RetVal);
307 goto EXIT;
308 }
309
310 TempRetVal = CatSPrint (RetVal, Temp);
311 SHELL_FREE_NON_NULL (RetVal);
312 if (TempRetVal == NULL) {
313 goto EXIT;
314 }
315 RetVal = TempRetVal;
316 SHELL_FREE_NON_NULL (Temp);
317
318 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_GOP_RES_LIST_ENTRY), NULL);
319 if (Temp == NULL) {
320 SHELL_FREE_NON_NULL (RetVal);
321 goto EXIT;
322 }
323
324
325 for (Mode = 0; Mode < GraphicsOutput->Mode->MaxMode; Mode++) {
326 Status = GraphicsOutput->QueryMode (
327 GraphicsOutput,
328 Mode,
329 &GopInfoSize,
330 &GopInfo
331 );
332 if (EFI_ERROR (Status)) {
333 continue;
334 }
335
336 TempRetVal = CatSPrint (
337 RetVal,
338 Temp,
339 Mode,
340 GopInfo->HorizontalResolution,
341 GopInfo->VerticalResolution
342 );
343
344 SHELL_FREE_NON_NULL (GopInfo);
345 SHELL_FREE_NON_NULL (RetVal);
346 RetVal = TempRetVal;
347 }
348
349
350 EXIT:
351 SHELL_FREE_NON_NULL(Temp);
352 SHELL_FREE_NON_NULL(Fmt);
353
354 return RetVal;
355 }
356
357 /**
358 Function to dump information about EDID Discovered Protocol.
359
360 This will allocate the return buffer from boot services pool.
361
362 @param[in] TheHandle The handle that has LoadedImage installed.
363 @param[in] Verbose TRUE for additional information, FALSE otherwise.
364
365 @retval A pointer to a string containing the information.
366 **/
367 CHAR16*
368 EFIAPI
369 EdidDiscoveredProtocolDumpInformation (
370 IN CONST EFI_HANDLE TheHandle,
371 IN CONST BOOLEAN Verbose
372 )
373 {
374 EFI_EDID_DISCOVERED_PROTOCOL *EdidDiscovered;
375 EFI_STATUS Status;
376 CHAR16 *RetVal;
377 CHAR16 *Temp;
378 CHAR16 *TempRetVal;
379
380 if (!Verbose) {
381 return (CatSPrint (NULL, L"EDIDDiscovered"));
382 }
383
384 Status = gBS->OpenProtocol (
385 TheHandle,
386 &gEfiEdidDiscoveredProtocolGuid,
387 (VOID**)&EdidDiscovered,
388 NULL,
389 NULL,
390 EFI_OPEN_PROTOCOL_GET_PROTOCOL
391 );
392
393 if (EFI_ERROR (Status)) {
394 return NULL;
395 }
396
397 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_DISCOVERED_MAIN), NULL);
398 if (Temp == NULL) {
399 return NULL;
400 }
401
402 RetVal = CatSPrint (NULL, Temp, EdidDiscovered->SizeOfEdid);
403 SHELL_FREE_NON_NULL (Temp);
404
405 if (EdidDiscovered->SizeOfEdid != 0) {
406 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_DISCOVERED_DATA), NULL);
407 if (Temp == NULL) {
408 SHELL_FREE_NON_NULL (RetVal);
409 return NULL;
410 }
411 TempRetVal = CatSPrint (RetVal, Temp);
412 SHELL_FREE_NON_NULL (RetVal);
413 RetVal = TempRetVal;
414
415 TempRetVal = CatSDumpHex (RetVal, 7, 0, EdidDiscovered->SizeOfEdid, EdidDiscovered->Edid);
416 RetVal = TempRetVal;
417 }
418 return RetVal;
419 }
420
421 /**
422 Function to dump information about EDID Active Protocol.
423
424 This will allocate the return buffer from boot services pool.
425
426 @param[in] TheHandle The handle that has LoadedImage installed.
427 @param[in] Verbose TRUE for additional information, FALSE otherwise.
428
429 @retval A pointer to a string containing the information.
430 **/
431 CHAR16*
432 EFIAPI
433 EdidActiveProtocolDumpInformation (
434 IN CONST EFI_HANDLE TheHandle,
435 IN CONST BOOLEAN Verbose
436 )
437 {
438 EFI_EDID_ACTIVE_PROTOCOL *EdidActive;
439 EFI_STATUS Status;
440 CHAR16 *RetVal;
441 CHAR16 *Temp;
442 CHAR16 *TempRetVal;
443
444 if (!Verbose) {
445 return (CatSPrint (NULL, L"EDIDActive"));
446 }
447
448 Status = gBS->OpenProtocol (
449 TheHandle,
450 &gEfiEdidActiveProtocolGuid,
451 (VOID**)&EdidActive,
452 NULL,
453 NULL,
454 EFI_OPEN_PROTOCOL_GET_PROTOCOL
455 );
456
457 if (EFI_ERROR (Status)) {
458 return NULL;
459 }
460
461 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_ACTIVE_MAIN), NULL);
462 if (Temp == NULL) {
463 return NULL;
464 }
465
466 RetVal = CatSPrint (NULL, Temp, EdidActive->SizeOfEdid);
467 SHELL_FREE_NON_NULL (Temp);
468
469 if (EdidActive->SizeOfEdid != 0) {
470 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_ACTIVE_DATA), NULL);
471 if (Temp == NULL) {
472 SHELL_FREE_NON_NULL (RetVal);
473 return NULL;
474 }
475 TempRetVal = CatSPrint (RetVal, Temp);
476 SHELL_FREE_NON_NULL (RetVal);
477 RetVal = TempRetVal;
478
479 TempRetVal = CatSDumpHex (RetVal, 7, 0, EdidActive->SizeOfEdid, EdidActive->Edid);
480 RetVal = TempRetVal;
481 }
482 return RetVal;
483 }
484
485 /**
486 Function to dump information about PciRootBridgeIo.
487
488 This will allocate the return buffer from boot services pool.
489
490 @param[in] TheHandle The handle that has PciRootBridgeIo installed.
491 @param[in] Verbose TRUE for additional information, FALSE otherwise.
492
493 @retval A poitner to a string containing the information.
494 **/
495 CHAR16*
496 EFIAPI
497 PciRootBridgeIoDumpInformation(
498 IN CONST EFI_HANDLE TheHandle,
499 IN CONST BOOLEAN Verbose
500 )
501 {
502 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
503 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration;
504 UINT64 Supports;
505 UINT64 Attributes;
506 CHAR16 *Temp;
507 CHAR16 *Temp2;
508 CHAR16 *RetVal;
509 EFI_STATUS Status;
510
511 RetVal = NULL;
512
513 if (!Verbose) {
514 return (CatSPrint(NULL, L"PciRootBridgeIo"));
515 }
516
517 HandleParsingHiiInit();
518
519 Status = gBS->HandleProtocol(
520 TheHandle,
521 &gEfiPciRootBridgeIoProtocolGuid,
522 (VOID**)&PciRootBridgeIo);
523
524 if (EFI_ERROR(Status)) {
525 return NULL;
526 }
527
528 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_PH), NULL);
529 if (Temp == NULL) {
530 return NULL;
531 }
532 Temp2 = CatSPrint(L"\r\n", Temp, PciRootBridgeIo->ParentHandle);
533 FreePool(Temp);
534 RetVal = Temp2;
535 Temp2 = NULL;
536
537 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SEG), NULL);
538 if (Temp == NULL) {
539 SHELL_FREE_NON_NULL(RetVal);
540 return NULL;
541 }
542 Temp2 = CatSPrint(RetVal, Temp, PciRootBridgeIo->SegmentNumber);
543 FreePool(Temp);
544 FreePool(RetVal);
545 RetVal = Temp2;
546 Temp2 = NULL;
547
548 Supports = 0;
549 Attributes = 0;
550 Status = PciRootBridgeIo->GetAttributes (PciRootBridgeIo, &Supports, &Attributes);
551 if (!EFI_ERROR(Status)) {
552 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_ATT), NULL);
553 if (Temp == NULL) {
554 SHELL_FREE_NON_NULL(RetVal);
555 return NULL;
556 }
557 Temp2 = CatSPrint(RetVal, Temp, Attributes);
558 FreePool(Temp);
559 FreePool(RetVal);
560 RetVal = Temp2;
561 Temp2 = NULL;
562
563 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS), NULL);
564 if (Temp == NULL) {
565 SHELL_FREE_NON_NULL(RetVal);
566 return NULL;
567 }
568 Temp2 = CatSPrint(RetVal, Temp, Supports);
569 FreePool(Temp);
570 FreePool(RetVal);
571 RetVal = Temp2;
572 Temp2 = NULL;
573 }
574
575 Configuration = NULL;
576 Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Configuration);
577 if (!EFI_ERROR(Status) && Configuration != NULL) {
578 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_TITLE), NULL);
579 if (Temp == NULL) {
580 SHELL_FREE_NON_NULL(RetVal);
581 return NULL;
582 }
583 Temp2 = CatSPrint(RetVal, Temp, Supports);
584 FreePool(Temp);
585 FreePool(RetVal);
586 RetVal = Temp2;
587 Temp2 = NULL;
588 while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
589 Temp = NULL;
590 switch (Configuration->ResType) {
591 case ACPI_ADDRESS_SPACE_TYPE_MEM:
592 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_MEM), NULL);
593 break;
594 case ACPI_ADDRESS_SPACE_TYPE_IO:
595 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_IO), NULL);
596 break;
597 case ACPI_ADDRESS_SPACE_TYPE_BUS:
598 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_BUS), NULL);
599 break;
600 }
601 if (Temp != NULL) {
602 Temp2 = CatSPrint(RetVal, L"%s", Temp);
603 FreePool(Temp);
604 FreePool(RetVal);
605 RetVal = Temp2;
606 Temp2 = NULL;
607 }
608
609 Temp2 = CatSPrint(RetVal,
610 L"%H%02x %016lx %016lx %02x%N\r\n",
611 Configuration->SpecificFlag,
612 Configuration->AddrRangeMin,
613 Configuration->AddrRangeMax,
614 Configuration->AddrSpaceGranularity
615 );
616 FreePool(RetVal);
617 RetVal = Temp2;
618 Temp2 = NULL;
619 Configuration++;
620 }
621 }
622 return (RetVal);
623 }
624
625 /**
626 Function to dump information about SimpleTextOut.
627
628 This will allocate the return buffer from boot services pool.
629
630 @param[in] TheHandle The handle that has SimpleTextOut installed.
631 @param[in] Verbose TRUE for additional information, FALSE otherwise.
632
633 @retval A poitner to a string containing the information.
634 **/
635 CHAR16*
636 EFIAPI
637 TxtOutProtocolDumpInformation(
638 IN CONST EFI_HANDLE TheHandle,
639 IN CONST BOOLEAN Verbose
640 )
641 {
642 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Dev;
643 INTN Index;
644 UINTN Col;
645 UINTN Row;
646 EFI_STATUS Status;
647 CHAR16 *RetVal;
648 UINTN Size;
649 CHAR16 *Temp;
650 UINTN NewSize;
651
652 if (!Verbose) {
653 return (NULL);
654 }
655
656 HandleParsingHiiInit();
657
658 RetVal = NULL;
659 Size = 0;
660
661 Status = gBS->HandleProtocol(
662 TheHandle,
663 &gEfiSimpleTextOutProtocolGuid,
664 (VOID**)&Dev);
665
666 ASSERT_EFI_ERROR(Status);
667 ASSERT (Dev != NULL && Dev->Mode != NULL);
668
669 Size = (Dev->Mode->MaxMode + 1) * 80;
670 RetVal = AllocateZeroPool(Size);
671
672 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER), NULL);
673 if (Temp != NULL) {
674 UnicodeSPrint(RetVal, Size, Temp, Dev, Dev->Mode->Attribute);
675 FreePool(Temp);
676 }
677
678 //
679 // Dump TextOut Info
680 //
681 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE), NULL);
682 for (Index = 0; Index < Dev->Mode->MaxMode; Index++) {
683 Status = Dev->QueryMode (Dev, Index, &Col, &Row);
684 NewSize = Size - StrSize(RetVal);
685 UnicodeSPrint(
686 RetVal + StrLen(RetVal),
687 NewSize,
688 Temp == NULL?L"":Temp,
689 Index == Dev->Mode->Mode ? L'*' : L' ',
690 Index,
691 !EFI_ERROR(Status)?(INTN)Col:-1,
692 !EFI_ERROR(Status)?(INTN)Row:-1
693 );
694 }
695 FreePool(Temp);
696 return (RetVal);
697 }
698
699 STATIC CONST UINTN VersionStringSize = 60;
700
701 /**
702 Function to dump information about EfiDriverSupportedEfiVersion protocol.
703
704 This will allocate the return buffer from boot services pool.
705
706 @param[in] TheHandle The handle that has the protocol installed.
707 @param[in] Verbose TRUE for additional information, FALSE otherwise.
708
709 @retval A poitner to a string containing the information.
710 **/
711 CHAR16*
712 EFIAPI
713 DriverEfiVersionProtocolDumpInformation(
714 IN CONST EFI_HANDLE TheHandle,
715 IN CONST BOOLEAN Verbose
716 )
717 {
718 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL *DriverEfiVersion;
719 EFI_STATUS Status;
720 CHAR16 *RetVal;
721
722 Status = gBS->HandleProtocol(
723 TheHandle,
724 &gEfiDriverSupportedEfiVersionProtocolGuid,
725 (VOID**)&DriverEfiVersion);
726
727 ASSERT_EFI_ERROR(Status);
728
729 RetVal = AllocateZeroPool(VersionStringSize);
730 if (RetVal != NULL) {
731 UnicodeSPrint (RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion);
732 }
733 return (RetVal);
734 }
735 /**
736 Function to convert device path to string.
737
738 This will allocate the return buffer from boot services pool.
739
740 @param[in] DevPath Pointer to device path instance.
741 @param[in] Verbose TRUE for additional information, FALSE otherwise.
742 @param[in] Length Maximum allowed text length of the device path.
743
744 @retval A pointer to a string containing the information.
745 **/
746 CHAR16*
747 ConvertDevicePathToShortText(
748 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath,
749 IN CONST BOOLEAN Verbose,
750 IN CONST UINTN Length
751 )
752 {
753 CHAR16 *Temp;
754 CHAR16 *Temp2;
755 UINTN Size;
756
757 //
758 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
759 //
760 Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);
761 if (!Verbose && Temp != NULL && StrLen(Temp) > Length) {
762 Temp2 = NULL;
763 Size = 0;
764 Temp2 = StrnCatGrow(&Temp2, &Size, L"..", 0);
765 Temp2 = StrnCatGrow(&Temp2, &Size, Temp+(StrLen(Temp) - (Length - 2)), 0);
766 FreePool(Temp);
767 Temp = Temp2;
768 }
769 return (Temp);
770 }
771
772 /**
773 Function to dump information about DevicePath protocol.
774
775 This will allocate the return buffer from boot services pool.
776
777 @param[in] TheHandle The handle that has the protocol installed.
778 @param[in] Verbose TRUE for additional information, FALSE otherwise.
779
780 @retval A pointer to a string containing the information.
781 **/
782 CHAR16*
783 EFIAPI
784 DevicePathProtocolDumpInformation(
785 IN CONST EFI_HANDLE TheHandle,
786 IN CONST BOOLEAN Verbose
787 )
788 {
789 EFI_DEVICE_PATH_PROTOCOL *DevPath;
790 CHAR16 *Temp;
791 EFI_STATUS Status;
792 Temp = NULL;
793
794 Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
795 if (!EFI_ERROR(Status)) {
796 Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30);
797 gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);
798 }
799 return (Temp);
800 }
801
802 /**
803 Function to dump information about LoadedImageDevicePath protocol.
804
805 This will allocate the return buffer from boot services pool.
806
807 @param[in] TheHandle The handle that has the protocol installed.
808 @param[in] Verbose TRUE for additional information, FALSE otherwise.
809
810 @retval A pointer to a string containing the information.
811 **/
812 CHAR16*
813 EFIAPI
814 LoadedImageDevicePathProtocolDumpInformation(
815 IN CONST EFI_HANDLE TheHandle,
816 IN CONST BOOLEAN Verbose
817 )
818 {
819 EFI_DEVICE_PATH_PROTOCOL *DevPath;
820 CHAR16 *Temp;
821 EFI_STATUS Status;
822 Temp = NULL;
823
824 Status = gBS->OpenProtocol(TheHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
825 if (!EFI_ERROR(Status)) {
826 Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30);
827 gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);
828 }
829 return (Temp);
830 }
831
832 /**
833 Function to dump information about EfiAdapterInformation Protocol.
834
835 @param[in] TheHandle The handle that has the protocol installed.
836 @param[in] Verbose TRUE for additional information, FALSE otherwise.
837
838 @retval A pointer to a string containing the information.
839 **/
840 CHAR16*
841 EFIAPI
842 AdapterInformationDumpInformation (
843 IN CONST EFI_HANDLE TheHandle,
844 IN CONST BOOLEAN Verbose
845 )
846 {
847 EFI_STATUS Status;
848 EFI_ADAPTER_INFORMATION_PROTOCOL *EfiAdptrInfoProtocol;
849 UINTN InfoTypesBufferCount;
850 UINTN GuidIndex;
851 EFI_GUID *InfoTypesBuffer;
852 CHAR16 *GuidStr;
853 CHAR16 *TempStr;
854 CHAR16 *RetVal;
855 CHAR16 *TempRetVal;
856 VOID *InformationBlock;
857 UINTN InformationBlockSize;
858
859 if (!Verbose) {
860 return (CatSPrint(NULL, L"AdapterInfo"));
861 }
862
863 InfoTypesBuffer = NULL;
864 InformationBlock = NULL;
865
866
867 Status = gBS->OpenProtocol (
868 (EFI_HANDLE) (TheHandle),
869 &gEfiAdapterInformationProtocolGuid,
870 (VOID **) &EfiAdptrInfoProtocol,
871 NULL,
872 NULL,
873 EFI_OPEN_PROTOCOL_GET_PROTOCOL
874 );
875
876 if (EFI_ERROR (Status)) {
877 return NULL;
878 }
879
880 //
881 // Get a list of supported information types for this instance of the protocol.
882 //
883 Status = EfiAdptrInfoProtocol->GetSupportedTypes (
884 EfiAdptrInfoProtocol,
885 &InfoTypesBuffer,
886 &InfoTypesBufferCount
887 );
888 RetVal = NULL;
889 if (EFI_ERROR (Status)) {
890 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GET_SUPP_TYPES_FAILED), NULL);
891 if (TempStr != NULL) {
892 RetVal = CatSPrint (NULL, TempStr, Status);
893 } else {
894 goto ERROR_EXIT;
895 }
896 } else {
897 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SUPP_TYPE_HEADER), NULL);
898 if (TempStr == NULL) {
899 goto ERROR_EXIT;
900 }
901 RetVal = CatSPrint (NULL, TempStr);
902 SHELL_FREE_NON_NULL (TempStr);
903
904 for (GuidIndex = 0; GuidIndex < InfoTypesBufferCount; GuidIndex++) {
905 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_NUMBER), NULL);
906 if (TempStr == NULL) {
907 goto ERROR_EXIT;
908 }
909 TempRetVal = CatSPrint (RetVal, TempStr, (GuidIndex + 1), &InfoTypesBuffer[GuidIndex]);
910 SHELL_FREE_NON_NULL (RetVal);
911 RetVal = TempRetVal;
912 SHELL_FREE_NON_NULL (TempStr);
913
914 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_STRING), NULL);
915 if (TempStr == NULL) {
916 goto ERROR_EXIT;
917 }
918
919 if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) {
920 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoMediaStateGuid");
921 SHELL_FREE_NON_NULL (RetVal);
922 RetVal = TempRetVal;
923 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) {
924 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoNetworkBootGuid");
925 SHELL_FREE_NON_NULL (RetVal);
926 RetVal = TempRetVal;
927 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid)) {
928 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoSanMacAddressGuid");
929 SHELL_FREE_NON_NULL (RetVal);
930 RetVal = TempRetVal;
931 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoUndiIpv6SupportGuid)) {
932 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoUndiIpv6SupportGuid");
933 SHELL_FREE_NON_NULL (RetVal);
934 RetVal = TempRetVal;
935 } else {
936
937 GuidStr = GetStringNameFromGuid (&InfoTypesBuffer[GuidIndex], NULL);
938
939 if (GuidStr != NULL) {
940 if (StrCmp(GuidStr, L"UnknownDevice") == 0) {
941 TempRetVal = CatSPrint (RetVal, TempStr, L"UnknownInfoType");
942 SHELL_FREE_NON_NULL (RetVal);
943 RetVal = TempRetVal;
944
945 SHELL_FREE_NON_NULL (TempStr);
946 SHELL_FREE_NON_NULL(GuidStr);
947 //
948 // So that we never have to pass this UnknownInfoType to the parsing function "GetInformation" service of AIP
949 //
950 continue;
951 } else {
952 TempRetVal = CatSPrint (RetVal, TempStr, GuidStr);
953 SHELL_FREE_NON_NULL (RetVal);
954 RetVal = TempRetVal;
955 SHELL_FREE_NON_NULL(GuidStr);
956 }
957 }
958 }
959
960 SHELL_FREE_NON_NULL (TempStr);
961
962 Status = EfiAdptrInfoProtocol->GetInformation (
963 EfiAdptrInfoProtocol,
964 &InfoTypesBuffer[GuidIndex],
965 &InformationBlock,
966 &InformationBlockSize
967 );
968
969 if (EFI_ERROR (Status)) {
970 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GETINFO_FAILED), NULL);
971 if (TempStr == NULL) {
972 goto ERROR_EXIT;
973 }
974 TempRetVal = CatSPrint (RetVal, TempStr, Status);
975 SHELL_FREE_NON_NULL (RetVal);
976 RetVal = TempRetVal;
977 } else {
978 if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) {
979 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_MEDIA_STATE), NULL);
980 if (TempStr == NULL) {
981 goto ERROR_EXIT;
982 }
983 TempRetVal = CatSPrint (
984 RetVal,
985 TempStr,
986 ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState,
987 ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState
988 );
989 SHELL_FREE_NON_NULL (RetVal);
990 RetVal = TempRetVal;
991 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) {
992 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_NETWORK_BOOT_INFO), NULL);
993 if (TempStr == NULL) {
994 goto ERROR_EXIT;
995 }
996 TempRetVal = CatSPrint (
997 RetVal,
998 TempStr,
999 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4BootCapablity,
1000 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6BootCapablity,
1001 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBootCapablity,
1002 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->OffloadCapability,
1003 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiMpioCapability,
1004 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4Boot,
1005 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6Boot,
1006 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBoot
1007 );
1008 SHELL_FREE_NON_NULL (RetVal);
1009 RetVal = TempRetVal;
1010 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid) == TRUE) {
1011 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SAN_MAC_ADDRESS_INFO), NULL);
1012 if (TempStr == NULL) {
1013 goto ERROR_EXIT;
1014 }
1015 TempRetVal = CatSPrint (
1016 RetVal,
1017 TempStr,
1018 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[0],
1019 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[1],
1020 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[2],
1021 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[3],
1022 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[4],
1023 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[5]
1024 );
1025 SHELL_FREE_NON_NULL (RetVal);
1026 RetVal = TempRetVal;
1027 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoUndiIpv6SupportGuid) == TRUE) {
1028 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNDI_IPV6_INFO), NULL);
1029 if (TempStr == NULL) {
1030 goto ERROR_EXIT;
1031 }
1032
1033 TempRetVal = CatSPrint (
1034 RetVal,
1035 TempStr,
1036 ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *)InformationBlock)->Ipv6Support
1037 );
1038 SHELL_FREE_NON_NULL (RetVal);
1039 RetVal = TempRetVal;
1040 } else {
1041 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNKNOWN_INFO_TYPE), NULL);
1042 if (TempStr == NULL) {
1043 goto ERROR_EXIT;
1044 }
1045 TempRetVal = CatSPrint (RetVal, TempStr, &InfoTypesBuffer[GuidIndex]);
1046 SHELL_FREE_NON_NULL (RetVal);
1047 RetVal = TempRetVal;
1048 }
1049 }
1050 SHELL_FREE_NON_NULL (TempStr);
1051 SHELL_FREE_NON_NULL (InformationBlock);
1052 }
1053 }
1054
1055 SHELL_FREE_NON_NULL (InfoTypesBuffer);
1056 return RetVal;
1057
1058 ERROR_EXIT:
1059 SHELL_FREE_NON_NULL (RetVal);
1060 SHELL_FREE_NON_NULL (InfoTypesBuffer);
1061 SHELL_FREE_NON_NULL (InformationBlock);
1062 return NULL;
1063 }
1064
1065 /**
1066 Function to dump information about EFI_FIRMWARE_MANAGEMENT_PROTOCOL Protocol.
1067
1068 @param[in] TheHandle The handle that has the protocol installed.
1069 @param[in] Verbose TRUE for additional information, FALSE otherwise.
1070
1071 @retval A pointer to a string containing the information.
1072 **/
1073 CHAR16*
1074 EFIAPI
1075 FirmwareManagementDumpInformation (
1076 IN CONST EFI_HANDLE TheHandle,
1077 IN CONST BOOLEAN Verbose
1078 )
1079 {
1080 EFI_STATUS Status;
1081 EFI_FIRMWARE_MANAGEMENT_PROTOCOL *EfiFwMgmtProtocol;
1082 EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo;
1083 EFI_FIRMWARE_IMAGE_DESCRIPTOR_V1 *ImageInfoV1;
1084 EFI_FIRMWARE_IMAGE_DESCRIPTOR_V2 *ImageInfoV2;
1085 UINT64 AttributeSetting;
1086 UINTN ImageInfoSize;
1087 UINTN DescriptorSize;
1088 UINT32 DescriptorVersion;
1089 UINT32 PackageVersion;
1090 UINT8 DescriptorCount;
1091 UINT8 Index;
1092 UINT8 Index1;
1093 UINT8 ImageCount;
1094 CHAR16 *PackageVersionName;
1095 CHAR16 *TempStr;
1096 CHAR16 *RetVal;
1097 CHAR16 *TempRetVal;
1098 CHAR16 *AttributeSettingStr;
1099 BOOLEAN Found;
1100 BOOLEAN AttributeSupported;
1101
1102 //
1103 // Initialize local variables
1104 //
1105 ImageCount = 0;
1106 ImageInfoSize = 1;
1107 AttributeSetting = 0;
1108 Found = FALSE;
1109 AttributeSupported = FALSE;
1110 ImageInfo = NULL;
1111 ImageInfoV1 = NULL;
1112 ImageInfoV2 = NULL;
1113 PackageVersionName = NULL;
1114 RetVal = NULL;
1115 TempRetVal = NULL;
1116 TempStr = NULL;
1117 AttributeSettingStr = NULL;
1118
1119 if (!Verbose) {
1120 return (CatSPrint(NULL, L"FirmwareManagement"));
1121 }
1122
1123 Status = gBS->OpenProtocol (
1124 (EFI_HANDLE) (TheHandle),
1125 &gEfiFirmwareManagementProtocolGuid,
1126 (VOID **) &EfiFwMgmtProtocol,
1127 NULL,
1128 NULL,
1129 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1130 );
1131
1132 if (EFI_ERROR (Status)) {
1133 return NULL;
1134 }
1135
1136 Status = EfiFwMgmtProtocol->GetImageInfo (
1137 EfiFwMgmtProtocol,
1138 &ImageInfoSize,
1139 ImageInfo,
1140 &DescriptorVersion,
1141 &DescriptorCount,
1142 &DescriptorSize,
1143 &PackageVersion,
1144 &PackageVersionName
1145 );
1146
1147 if (Status == EFI_BUFFER_TOO_SMALL) {
1148 ImageInfo = AllocateZeroPool (ImageInfoSize);
1149
1150 if (ImageInfo == NULL) {
1151 Status = EFI_OUT_OF_RESOURCES;
1152 } else {
1153 Status = EfiFwMgmtProtocol->GetImageInfo (
1154 EfiFwMgmtProtocol,
1155 &ImageInfoSize,
1156 ImageInfo,
1157 &DescriptorVersion,
1158 &DescriptorCount,
1159 &DescriptorSize,
1160 &PackageVersion,
1161 &PackageVersionName
1162 );
1163 }
1164 }
1165
1166 if (EFI_ERROR (Status)) {
1167 goto ERROR_EXIT;
1168 }
1169
1170 //
1171 // Decode Image Descriptor data only if its version is supported
1172 //
1173 if (DescriptorVersion <= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION) {
1174
1175 if (ImageInfo == NULL) {
1176 goto ERROR_EXIT;
1177 }
1178
1179 ImageInfoV1 = (EFI_FIRMWARE_IMAGE_DESCRIPTOR_V1 *)ImageInfo;
1180 ImageInfoV2 = (EFI_FIRMWARE_IMAGE_DESCRIPTOR_V2 *)ImageInfo;
1181
1182 //
1183 // Set ImageInfoSize in return buffer
1184 //
1185 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_INFO_SIZE), NULL);
1186 if (TempStr == NULL) {
1187 goto ERROR_EXIT;
1188 }
1189 RetVal = CatSPrint (NULL, TempStr, ImageInfoSize);
1190 SHELL_FREE_NON_NULL (TempStr);
1191
1192 //
1193 // Set DescriptorVersion in return buffer
1194 //
1195 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_VERSION), NULL);
1196 if (TempStr == NULL) {
1197 goto ERROR_EXIT;
1198 }
1199 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorVersion);
1200 SHELL_FREE_NON_NULL (RetVal);
1201 RetVal = TempRetVal;
1202 SHELL_FREE_NON_NULL (TempStr);
1203
1204 //
1205 // Set DescriptorCount in return buffer
1206 //
1207 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_COUNT), NULL);
1208 if (TempStr == NULL) {
1209 goto ERROR_EXIT;
1210 }
1211 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorCount);
1212 SHELL_FREE_NON_NULL (RetVal);
1213 RetVal = TempRetVal;
1214 SHELL_FREE_NON_NULL (TempStr);
1215
1216
1217 //
1218 // Set DescriptorSize in return buffer
1219 //
1220 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_SIZE), NULL);
1221 if (TempStr == NULL) {
1222 goto ERROR_EXIT;
1223 }
1224 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorSize);
1225 SHELL_FREE_NON_NULL (RetVal);
1226 RetVal = TempRetVal;
1227 SHELL_FREE_NON_NULL (TempStr);
1228
1229 //
1230 // Set PackageVersion in return buffer
1231 //
1232 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_PACKAGE_VERSION), NULL);
1233 if (TempStr == NULL) {
1234 goto ERROR_EXIT;
1235 }
1236 TempRetVal = CatSPrint (RetVal, TempStr, PackageVersion);
1237 SHELL_FREE_NON_NULL (RetVal);
1238 RetVal = TempRetVal;
1239 SHELL_FREE_NON_NULL (TempStr);
1240
1241 //
1242 // Set PackageVersionName in return buffer
1243 //
1244 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_PACKAGE_VERSION_NAME), NULL);
1245 if (TempStr == NULL) {
1246 goto ERROR_EXIT;
1247 }
1248 TempRetVal = CatSPrint (RetVal, TempStr, PackageVersionName);
1249 SHELL_FREE_NON_NULL (RetVal);
1250 RetVal = TempRetVal;
1251 SHELL_FREE_NON_NULL (TempStr);
1252
1253 for (Index = 0; Index < DescriptorCount; Index++) {
1254 //
1255 // First check if Attribute is supported
1256 // and generate a string for AttributeSetting field
1257 //
1258 SHELL_FREE_NON_NULL (AttributeSettingStr);
1259 AttributeSupported = FALSE;
1260 AttributeSetting = 0;
1261 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1262 if (ImageInfoV1[Index].AttributesSupported != 0x0) {
1263 AttributeSupported = TRUE;
1264 AttributeSetting = ImageInfoV1[Index].AttributesSetting;
1265 }
1266 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1267 if (ImageInfoV2[Index].AttributesSupported != 0x0) {
1268 AttributeSupported = TRUE;
1269 AttributeSetting = ImageInfoV2[Index].AttributesSetting;
1270 }
1271 } else {
1272 if (ImageInfo[Index].AttributesSupported != 0x0) {
1273 AttributeSupported = TRUE;
1274 AttributeSetting = ImageInfo[Index].AttributesSetting;
1275 }
1276 }
1277
1278 if (!AttributeSupported) {
1279 AttributeSettingStr = CatSPrint (NULL, L"None");
1280 } else {
1281 AttributeSettingStr = CatSPrint (NULL, L"(");
1282
1283 if ((AttributeSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) != 0x0) {
1284 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IMAGE_UPDATABLE");
1285 SHELL_FREE_NON_NULL (AttributeSettingStr);
1286 AttributeSettingStr = TempRetVal;
1287 }
1288 if ((AttributeSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED) != 0x0) {
1289 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_RESET_REQUIRED");
1290 SHELL_FREE_NON_NULL (AttributeSettingStr);
1291 AttributeSettingStr = TempRetVal;
1292 }
1293 if ((AttributeSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED) != 0x0) {
1294 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED");
1295 SHELL_FREE_NON_NULL (AttributeSettingStr);
1296 AttributeSettingStr = TempRetVal;
1297 }
1298 if ((AttributeSetting & IMAGE_ATTRIBUTE_IN_USE) != 0x0) {
1299 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IN_USE");
1300 SHELL_FREE_NON_NULL (AttributeSettingStr);
1301 AttributeSettingStr = TempRetVal;
1302 }
1303 if ((AttributeSetting & IMAGE_ATTRIBUTE_UEFI_IMAGE) != 0x0) {
1304 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_UEFI_IMAGE");
1305 SHELL_FREE_NON_NULL (AttributeSettingStr);
1306 AttributeSettingStr = TempRetVal;
1307 }
1308 TempRetVal = CatSPrint (AttributeSettingStr, L" )");
1309 SHELL_FREE_NON_NULL (AttributeSettingStr);
1310 AttributeSettingStr = TempRetVal;
1311 }
1312
1313 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1314 if (ImageInfoV1[Index].ImageIndex != 0x0) {
1315 ImageCount++;
1316 }
1317
1318 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO_V1), NULL);
1319 if (TempStr == NULL) {
1320 goto ERROR_EXIT;
1321 }
1322 TempRetVal = CatSPrint (
1323 RetVal,
1324 TempStr,
1325 Index,
1326 ImageInfoV1[Index].ImageIndex,
1327 &ImageInfoV1[Index].ImageTypeId,
1328 ImageInfoV1[Index].ImageId,
1329 ImageInfoV1[Index].ImageIdName,
1330 ImageInfoV1[Index].Version,
1331 ImageInfoV1[Index].VersionName,
1332 ImageInfoV1[Index].Size,
1333 ImageInfoV1[Index].AttributesSupported,
1334 AttributeSettingStr,
1335 ImageInfoV1[Index].Compatibilities
1336 );
1337 SHELL_FREE_NON_NULL (RetVal);
1338 RetVal = TempRetVal;
1339 SHELL_FREE_NON_NULL (TempStr);
1340 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1341 if (ImageInfoV2[Index].ImageIndex != 0x0) {
1342 ImageCount++;
1343 }
1344
1345 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO_V2), NULL);
1346 if (TempStr == NULL) {
1347 goto ERROR_EXIT;
1348 }
1349 TempRetVal = CatSPrint (
1350 RetVal,
1351 TempStr,
1352 Index,
1353 ImageInfoV2[Index].ImageIndex,
1354 &ImageInfoV2[Index].ImageTypeId,
1355 ImageInfoV2[Index].ImageId,
1356 ImageInfoV2[Index].ImageIdName,
1357 ImageInfoV2[Index].Version,
1358 ImageInfoV2[Index].VersionName,
1359 ImageInfoV2[Index].Size,
1360 ImageInfoV2[Index].AttributesSupported,
1361 AttributeSettingStr,
1362 ImageInfoV2[Index].Compatibilities,
1363 ImageInfoV2[Index].LowestSupportedImageVersion
1364 );
1365 SHELL_FREE_NON_NULL (RetVal);
1366 RetVal = TempRetVal;
1367 SHELL_FREE_NON_NULL (TempStr);
1368 } else {
1369 if (ImageInfo[Index].ImageIndex != 0x0) {
1370 ImageCount++;
1371 }
1372
1373 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO), NULL);
1374 if (TempStr == NULL) {
1375 goto ERROR_EXIT;
1376 }
1377 TempRetVal = CatSPrint (
1378 RetVal,
1379 TempStr,
1380 Index,
1381 ImageInfo[Index].ImageIndex,
1382 &ImageInfo[Index].ImageTypeId,
1383 ImageInfo[Index].ImageId,
1384 ImageInfo[Index].ImageIdName,
1385 ImageInfo[Index].Version,
1386 ImageInfo[Index].VersionName,
1387 ImageInfo[Index].Size,
1388 ImageInfo[Index].AttributesSupported,
1389 AttributeSettingStr,
1390 ImageInfo[Index].Compatibilities,
1391 ImageInfo[Index].LowestSupportedImageVersion,
1392 ImageInfo[Index].LastAttemptVersion,
1393 ImageInfo[Index].LastAttemptStatus,
1394 ImageInfo[Index].HardwareInstance
1395 );
1396 SHELL_FREE_NON_NULL (RetVal);
1397 RetVal = TempRetVal;
1398 SHELL_FREE_NON_NULL (TempStr);
1399 }
1400 }
1401 }
1402
1403 if (ImageCount > 0) {
1404 for (Index=0; Index<DescriptorCount; Index++) {
1405 for (Index1=Index+1; Index1<DescriptorCount; Index1++) {
1406 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1407 if (ImageInfoV1[Index].ImageId == ImageInfoV1[Index1].ImageId) {
1408 Found = TRUE;
1409 //
1410 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1411 //
1412 goto ENDLOOP;
1413 }
1414 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1415 if (ImageInfoV2[Index].ImageId == ImageInfoV2[Index1].ImageId) {
1416 Found = TRUE;
1417 //
1418 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1419 //
1420 goto ENDLOOP;
1421 }
1422 } else {
1423 if (ImageInfo[Index].ImageId == ImageInfo[Index1].ImageId) {
1424 Found = TRUE;
1425 //
1426 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1427 //
1428 goto ENDLOOP;
1429 }
1430 }
1431 }
1432 }
1433 }
1434
1435 ENDLOOP:
1436 //
1437 // Check if ImageId with duplicate value was found
1438 //
1439 if (Found) {
1440 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGEID_NON_UNIQUE), NULL);
1441 if (TempStr == NULL) {
1442 goto ERROR_EXIT;
1443 }
1444 TempRetVal = CatSPrint (RetVal, TempStr);
1445 SHELL_FREE_NON_NULL (RetVal);
1446 RetVal = TempRetVal;
1447 SHELL_FREE_NON_NULL (TempStr);
1448 }
1449
1450 SHELL_FREE_NON_NULL (ImageInfo);
1451 SHELL_FREE_NON_NULL (PackageVersionName);
1452 SHELL_FREE_NON_NULL (AttributeSettingStr);
1453
1454 return RetVal;
1455
1456 ERROR_EXIT:
1457 SHELL_FREE_NON_NULL (RetVal);
1458 SHELL_FREE_NON_NULL (ImageInfo);
1459 SHELL_FREE_NON_NULL (PackageVersionName);
1460 SHELL_FREE_NON_NULL (AttributeSettingStr);
1461
1462 return NULL;
1463 }
1464
1465 //
1466 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
1467 //
1468 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
1469 { \
1470 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1471 }
1472
1473 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
1474 { \
1475 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1476 }
1477
1478 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
1479 { \
1480 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1481 }
1482 STATIC CONST EFI_GUID WinNtThunkProtocolGuid = LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID;
1483 STATIC CONST EFI_GUID WinNtIoProtocolGuid = LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID;
1484 STATIC CONST EFI_GUID WinNtSerialPortGuid = LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID;
1485
1486 //
1487 // Deprecated protocols we dont want to link from IntelFrameworkModulePkg
1488 //
1489 #define LOCAL_EFI_ISA_IO_PROTOCOL_GUID \
1490 { \
1491 0x7ee2bd44, 0x3da0, 0x11d4, { 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
1492 }
1493 #define LOCAL_EFI_ISA_ACPI_PROTOCOL_GUID \
1494 { \
1495 0x64a892dc, 0x5561, 0x4536, { 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55 } \
1496 }
1497 STATIC CONST EFI_GUID EfiIsaIoProtocolGuid = LOCAL_EFI_ISA_IO_PROTOCOL_GUID;
1498 STATIC CONST EFI_GUID EfiIsaAcpiProtocolGuid = LOCAL_EFI_ISA_ACPI_PROTOCOL_GUID;
1499
1500
1501 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT[] = {
1502 {STRING_TOKEN(STR_WINNT_THUNK), (EFI_GUID*)&WinNtThunkProtocolGuid, NULL},
1503 {STRING_TOKEN(STR_WINNT_DRIVER_IO), (EFI_GUID*)&WinNtIoProtocolGuid, NULL},
1504 {STRING_TOKEN(STR_WINNT_SERIAL_PORT), (EFI_GUID*)&WinNtSerialPortGuid, NULL},
1505 {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},
1506 };
1507
1508 STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {
1509 {STRING_TOKEN(STR_LOADED_IMAGE), &gEfiLoadedImageProtocolGuid, LoadedImageProtocolDumpInformation},
1510 {STRING_TOKEN(STR_DEVICE_PATH), &gEfiDevicePathProtocolGuid, DevicePathProtocolDumpInformation},
1511 {STRING_TOKEN(STR_IMAGE_PATH), &gEfiLoadedImageDevicePathProtocolGuid, LoadedImageDevicePathProtocolDumpInformation},
1512 {STRING_TOKEN(STR_DEVICE_PATH_UTIL), &gEfiDevicePathUtilitiesProtocolGuid, NULL},
1513 {STRING_TOKEN(STR_DEVICE_PATH_TXT), &gEfiDevicePathToTextProtocolGuid, NULL},
1514 {STRING_TOKEN(STR_DEVICE_PATH_FTXT), &gEfiDevicePathFromTextProtocolGuid, NULL},
1515 {STRING_TOKEN(STR_DEVICE_PATH_PC), &gEfiPcAnsiGuid, NULL},
1516 {STRING_TOKEN(STR_DEVICE_PATH_VT100), &gEfiVT100Guid, NULL},
1517 {STRING_TOKEN(STR_DEVICE_PATH_VT100P), &gEfiVT100PlusGuid, NULL},
1518 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8), &gEfiVTUTF8Guid, NULL},
1519 {STRING_TOKEN(STR_DRIVER_BINDING), &gEfiDriverBindingProtocolGuid, NULL},
1520 {STRING_TOKEN(STR_PLATFORM_OVERRIDE), &gEfiPlatformDriverOverrideProtocolGuid, NULL},
1521 {STRING_TOKEN(STR_BUS_OVERRIDE), &gEfiBusSpecificDriverOverrideProtocolGuid, NULL},
1522 {STRING_TOKEN(STR_DRIVER_DIAG), &gEfiDriverDiagnosticsProtocolGuid, NULL},
1523 {STRING_TOKEN(STR_DRIVER_DIAG2), &gEfiDriverDiagnostics2ProtocolGuid, NULL},
1524 {STRING_TOKEN(STR_DRIVER_CN), &gEfiComponentNameProtocolGuid, NULL},
1525 {STRING_TOKEN(STR_DRIVER_CN2), &gEfiComponentName2ProtocolGuid, NULL},
1526 {STRING_TOKEN(STR_PLAT_DRV_CFG), &gEfiPlatformToDriverConfigurationProtocolGuid, NULL},
1527 {STRING_TOKEN(STR_DRIVER_VERSION), &gEfiDriverSupportedEfiVersionProtocolGuid, DriverEfiVersionProtocolDumpInformation},
1528 {STRING_TOKEN(STR_TXT_IN), &gEfiSimpleTextInProtocolGuid, NULL},
1529 {STRING_TOKEN(STR_TXT_IN_EX), &gEfiSimpleTextInputExProtocolGuid, NULL},
1530 {STRING_TOKEN(STR_TXT_OUT), &gEfiSimpleTextOutProtocolGuid, TxtOutProtocolDumpInformation},
1531 {STRING_TOKEN(STR_SIM_POINTER), &gEfiSimplePointerProtocolGuid, NULL},
1532 {STRING_TOKEN(STR_ABS_POINTER), &gEfiAbsolutePointerProtocolGuid, NULL},
1533 {STRING_TOKEN(STR_SERIAL_IO), &gEfiSerialIoProtocolGuid, NULL},
1534 {STRING_TOKEN(STR_GRAPHICS_OUTPUT), &gEfiGraphicsOutputProtocolGuid, GraphicsOutputProtocolDumpInformation},
1535 {STRING_TOKEN(STR_EDID_DISCOVERED), &gEfiEdidDiscoveredProtocolGuid, EdidDiscoveredProtocolDumpInformation},
1536 {STRING_TOKEN(STR_EDID_ACTIVE), &gEfiEdidActiveProtocolGuid, EdidActiveProtocolDumpInformation},
1537 {STRING_TOKEN(STR_EDID_OVERRIDE), &gEfiEdidOverrideProtocolGuid, NULL},
1538 {STRING_TOKEN(STR_CON_IN), &gEfiConsoleInDeviceGuid, NULL},
1539 {STRING_TOKEN(STR_CON_OUT), &gEfiConsoleOutDeviceGuid, NULL},
1540 {STRING_TOKEN(STR_STD_ERR), &gEfiStandardErrorDeviceGuid, NULL},
1541 {STRING_TOKEN(STR_LOAD_FILE), &gEfiLoadFileProtocolGuid, NULL},
1542 {STRING_TOKEN(STR_LOAD_FILE2), &gEfiLoadFile2ProtocolGuid, NULL},
1543 {STRING_TOKEN(STR_SIMPLE_FILE_SYS), &gEfiSimpleFileSystemProtocolGuid, NULL},
1544 {STRING_TOKEN(STR_TAPE_IO), &gEfiTapeIoProtocolGuid, NULL},
1545 {STRING_TOKEN(STR_DISK_IO), &gEfiDiskIoProtocolGuid, NULL},
1546 {STRING_TOKEN(STR_BLK_IO), &gEfiBlockIoProtocolGuid, NULL},
1547 {STRING_TOKEN(STR_UC), &gEfiUnicodeCollationProtocolGuid, NULL},
1548 {STRING_TOKEN(STR_UC2), &gEfiUnicodeCollation2ProtocolGuid, NULL},
1549 {STRING_TOKEN(STR_PCIRB_IO), &gEfiPciRootBridgeIoProtocolGuid, PciRootBridgeIoDumpInformation},
1550 {STRING_TOKEN(STR_PCI_IO), &gEfiPciIoProtocolGuid, NULL},
1551 {STRING_TOKEN(STR_SCSI_PT), &gEfiScsiPassThruProtocolGuid, NULL},
1552 {STRING_TOKEN(STR_SCSI_IO), &gEfiScsiIoProtocolGuid, NULL},
1553 {STRING_TOKEN(STR_SCSI_PT_EXT), &gEfiExtScsiPassThruProtocolGuid, NULL},
1554 {STRING_TOKEN(STR_ISCSI), &gEfiIScsiInitiatorNameProtocolGuid, NULL},
1555 {STRING_TOKEN(STR_USB_IO), &gEfiUsbIoProtocolGuid, NULL},
1556 {STRING_TOKEN(STR_USB_HC), &gEfiUsbHcProtocolGuid, NULL},
1557 {STRING_TOKEN(STR_USB_HC2), &gEfiUsb2HcProtocolGuid, NULL},
1558 {STRING_TOKEN(STR_DEBUG_SUPPORT), &gEfiDebugSupportProtocolGuid, NULL},
1559 {STRING_TOKEN(STR_DEBUG_PORT), &gEfiDebugPortProtocolGuid, NULL},
1560 {STRING_TOKEN(STR_DECOMPRESS), &gEfiDecompressProtocolGuid, NULL},
1561 {STRING_TOKEN(STR_ACPI_TABLE), &gEfiAcpiTableProtocolGuid, NULL},
1562 {STRING_TOKEN(STR_EBC_INTERPRETER), &gEfiEbcProtocolGuid, NULL},
1563 {STRING_TOKEN(STR_SNP), &gEfiSimpleNetworkProtocolGuid, NULL},
1564 {STRING_TOKEN(STR_NII), &gEfiNetworkInterfaceIdentifierProtocolGuid, NULL},
1565 {STRING_TOKEN(STR_NII_31), &gEfiNetworkInterfaceIdentifierProtocolGuid_31, NULL},
1566 {STRING_TOKEN(STR_PXE_BC), &gEfiPxeBaseCodeProtocolGuid, NULL},
1567 {STRING_TOKEN(STR_PXE_CB), &gEfiPxeBaseCodeCallbackProtocolGuid, NULL},
1568 {STRING_TOKEN(STR_BIS), &gEfiBisProtocolGuid, NULL},
1569 {STRING_TOKEN(STR_MNP_SB), &gEfiManagedNetworkServiceBindingProtocolGuid, NULL},
1570 {STRING_TOKEN(STR_MNP), &gEfiManagedNetworkProtocolGuid, NULL},
1571 {STRING_TOKEN(STR_ARP_SB), &gEfiArpServiceBindingProtocolGuid, NULL},
1572 {STRING_TOKEN(STR_ARP), &gEfiArpProtocolGuid, NULL},
1573 {STRING_TOKEN(STR_DHCPV4_SB), &gEfiDhcp4ServiceBindingProtocolGuid, NULL},
1574 {STRING_TOKEN(STR_DHCPV4), &gEfiDhcp4ProtocolGuid, NULL},
1575 {STRING_TOKEN(STR_TCPV4_SB), &gEfiTcp4ServiceBindingProtocolGuid, NULL},
1576 {STRING_TOKEN(STR_TCPV4), &gEfiTcp4ProtocolGuid, NULL},
1577 {STRING_TOKEN(STR_IPV4_SB), &gEfiIp4ServiceBindingProtocolGuid, NULL},
1578 {STRING_TOKEN(STR_IPV4), &gEfiIp4ProtocolGuid, NULL},
1579 {STRING_TOKEN(STR_IPV4_CFG), &gEfiIp4ConfigProtocolGuid, NULL},
1580 {STRING_TOKEN(STR_IPV4_CFG2), &gEfiIp4Config2ProtocolGuid, NULL},
1581 {STRING_TOKEN(STR_UDPV4_SB), &gEfiUdp4ServiceBindingProtocolGuid, NULL},
1582 {STRING_TOKEN(STR_UDPV4), &gEfiUdp4ProtocolGuid, NULL},
1583 {STRING_TOKEN(STR_MTFTPV4_SB), &gEfiMtftp4ServiceBindingProtocolGuid, NULL},
1584 {STRING_TOKEN(STR_MTFTPV4), &gEfiMtftp4ProtocolGuid, NULL},
1585 {STRING_TOKEN(STR_AUTH_INFO), &gEfiAuthenticationInfoProtocolGuid, NULL},
1586 {STRING_TOKEN(STR_HASH_SB), &gEfiHashServiceBindingProtocolGuid, NULL},
1587 {STRING_TOKEN(STR_HASH), &gEfiHashProtocolGuid, NULL},
1588 {STRING_TOKEN(STR_HII_FONT), &gEfiHiiFontProtocolGuid, NULL},
1589 {STRING_TOKEN(STR_HII_STRING), &gEfiHiiStringProtocolGuid, NULL},
1590 {STRING_TOKEN(STR_HII_IMAGE), &gEfiHiiImageProtocolGuid, NULL},
1591 {STRING_TOKEN(STR_HII_DATABASE), &gEfiHiiDatabaseProtocolGuid, NULL},
1592 {STRING_TOKEN(STR_HII_CONFIG_ROUT), &gEfiHiiConfigRoutingProtocolGuid, NULL},
1593 {STRING_TOKEN(STR_HII_CONFIG_ACC), &gEfiHiiConfigAccessProtocolGuid, NULL},
1594 {STRING_TOKEN(STR_HII_FORM_BROWSER2), &gEfiFormBrowser2ProtocolGuid, NULL},
1595 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE), &gEfiDriverFamilyOverrideProtocolGuid, NULL},
1596 {STRING_TOKEN(STR_PCD), &gPcdProtocolGuid, NULL},
1597 {STRING_TOKEN(STR_TCG), &gEfiTcgProtocolGuid, NULL},
1598 {STRING_TOKEN(STR_HII_PACKAGE_LIST), &gEfiHiiPackageListProtocolGuid, NULL},
1599
1600 //
1601 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
1602 //
1603 {STRING_TOKEN(STR_SHELL_INTERFACE), &gEfiShellInterfaceGuid, NULL},
1604 {STRING_TOKEN(STR_SHELL_ENV2), &gEfiShellEnvironment2Guid, NULL},
1605 {STRING_TOKEN(STR_SHELL_ENV), &gEfiShellEnvironment2Guid, NULL},
1606 {STRING_TOKEN(STR_DEVICE_IO), &gEfiDeviceIoProtocolGuid, NULL},
1607 {STRING_TOKEN(STR_UGA_DRAW), &gEfiUgaDrawProtocolGuid, NULL},
1608 {STRING_TOKEN(STR_UGA_IO), &gEfiUgaIoProtocolGuid, NULL},
1609 {STRING_TOKEN(STR_ESP), &gEfiPartTypeSystemPartGuid, NULL},
1610 {STRING_TOKEN(STR_GPT_NBR), &gEfiPartTypeLegacyMbrGuid, NULL},
1611 {STRING_TOKEN(STR_DRIVER_CONFIG), &gEfiDriverConfigurationProtocolGuid, NULL},
1612 {STRING_TOKEN(STR_DRIVER_CONFIG2), &gEfiDriverConfiguration2ProtocolGuid, NULL},
1613
1614 //
1615 // these are using local (non-global) definitions to reduce package dependancy.
1616 //
1617 {STRING_TOKEN(STR_ISA_IO), (EFI_GUID*)&EfiIsaIoProtocolGuid, NULL},
1618 {STRING_TOKEN(STR_ISA_ACPI), (EFI_GUID*)&EfiIsaAcpiProtocolGuid, NULL},
1619
1620 //
1621 // the ones under this are GUID identified structs, not protocols
1622 //
1623 {STRING_TOKEN(STR_FILE_INFO), &gEfiFileInfoGuid, NULL},
1624 {STRING_TOKEN(STR_FILE_SYS_INFO), &gEfiFileSystemInfoGuid, NULL},
1625
1626 //
1627 // the ones under this are misc GUIDS.
1628 //
1629 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE), &gEfiGlobalVariableGuid, NULL},
1630
1631 //
1632 // UEFI 2.2
1633 //
1634 {STRING_TOKEN(STR_IP6_SB), &gEfiIp6ServiceBindingProtocolGuid, NULL},
1635 {STRING_TOKEN(STR_IP6), &gEfiIp6ProtocolGuid, NULL},
1636 {STRING_TOKEN(STR_IP6_CONFIG), &gEfiIp6ConfigProtocolGuid, NULL},
1637 {STRING_TOKEN(STR_MTFTP6_SB), &gEfiMtftp6ServiceBindingProtocolGuid, NULL},
1638 {STRING_TOKEN(STR_MTFTP6), &gEfiMtftp6ProtocolGuid, NULL},
1639 {STRING_TOKEN(STR_DHCP6_SB), &gEfiDhcp6ServiceBindingProtocolGuid, NULL},
1640 {STRING_TOKEN(STR_DHCP6), &gEfiDhcp6ProtocolGuid, NULL},
1641 {STRING_TOKEN(STR_UDP6_SB), &gEfiUdp6ServiceBindingProtocolGuid, NULL},
1642 {STRING_TOKEN(STR_UDP6), &gEfiUdp6ProtocolGuid, NULL},
1643 {STRING_TOKEN(STR_TCP6_SB), &gEfiTcp6ServiceBindingProtocolGuid, NULL},
1644 {STRING_TOKEN(STR_TCP6), &gEfiTcp6ProtocolGuid, NULL},
1645 {STRING_TOKEN(STR_VLAN_CONFIG), &gEfiVlanConfigProtocolGuid, NULL},
1646 {STRING_TOKEN(STR_EAP), &gEfiEapProtocolGuid, NULL},
1647 {STRING_TOKEN(STR_EAP_MGMT), &gEfiEapManagementProtocolGuid, NULL},
1648 {STRING_TOKEN(STR_FTP4_SB), &gEfiFtp4ServiceBindingProtocolGuid, NULL},
1649 {STRING_TOKEN(STR_FTP4), &gEfiFtp4ProtocolGuid, NULL},
1650 {STRING_TOKEN(STR_IP_SEC_CONFIG), &gEfiIpSecConfigProtocolGuid, NULL},
1651 {STRING_TOKEN(STR_DH), &gEfiDriverHealthProtocolGuid, NULL},
1652 {STRING_TOKEN(STR_DEF_IMG_LOAD), &gEfiDeferredImageLoadProtocolGuid, NULL},
1653 {STRING_TOKEN(STR_USER_CRED), &gEfiUserCredentialProtocolGuid, NULL},
1654 {STRING_TOKEN(STR_USER_MNGR), &gEfiUserManagerProtocolGuid, NULL},
1655 {STRING_TOKEN(STR_ATA_PASS_THRU), &gEfiAtaPassThruProtocolGuid, NULL},
1656
1657 //
1658 // UEFI 2.3
1659 //
1660 {STRING_TOKEN(STR_FW_MGMT), &gEfiFirmwareManagementProtocolGuid, FirmwareManagementDumpInformation},
1661 {STRING_TOKEN(STR_IP_SEC), &gEfiIpSecProtocolGuid, NULL},
1662 {STRING_TOKEN(STR_IP_SEC2), &gEfiIpSec2ProtocolGuid, NULL},
1663
1664 //
1665 // UEFI 2.3.1
1666 //
1667 {STRING_TOKEN(STR_KMS), &gEfiKmsProtocolGuid, NULL},
1668 {STRING_TOKEN(STR_BLK_IO2), &gEfiBlockIo2ProtocolGuid, NULL},
1669 {STRING_TOKEN(STR_SSC), &gEfiStorageSecurityCommandProtocolGuid, NULL},
1670 {STRING_TOKEN(STR_UCRED2), &gEfiUserCredential2ProtocolGuid, NULL},
1671
1672 //
1673 // UEFI 2.4
1674 //
1675 {STRING_TOKEN(STR_DISK_IO2), &gEfiDiskIo2ProtocolGuid, NULL},
1676 {STRING_TOKEN(STR_ADAPTER_INFO), &gEfiAdapterInformationProtocolGuid, AdapterInformationDumpInformation},
1677
1678 //
1679 // PI Spec ones
1680 //
1681 {STRING_TOKEN(STR_IDE_CONT_INIT), &gEfiIdeControllerInitProtocolGuid, NULL},
1682 {STRING_TOKEN(STR_DISK_INFO), &gEfiDiskInfoProtocolGuid, NULL},
1683
1684 //
1685 // PI Spec 1.0
1686 //
1687 {STRING_TOKEN(STR_BDS_ARCH), &gEfiBdsArchProtocolGuid, NULL},
1688 {STRING_TOKEN(STR_CPU_ARCH), &gEfiCpuArchProtocolGuid, NULL},
1689 {STRING_TOKEN(STR_MET_ARCH), &gEfiMetronomeArchProtocolGuid, NULL},
1690 {STRING_TOKEN(STR_MON_ARCH), &gEfiMonotonicCounterArchProtocolGuid, NULL},
1691 {STRING_TOKEN(STR_RTC_ARCH), &gEfiRealTimeClockArchProtocolGuid, NULL},
1692 {STRING_TOKEN(STR_RESET_ARCH), &gEfiResetArchProtocolGuid, NULL},
1693 {STRING_TOKEN(STR_RT_ARCH), &gEfiRuntimeArchProtocolGuid, NULL},
1694 {STRING_TOKEN(STR_SEC_ARCH), &gEfiSecurityArchProtocolGuid, NULL},
1695 {STRING_TOKEN(STR_TIMER_ARCH), &gEfiTimerArchProtocolGuid, NULL},
1696 {STRING_TOKEN(STR_VAR_ARCH), &gEfiVariableWriteArchProtocolGuid, NULL},
1697 {STRING_TOKEN(STR_V_ARCH), &gEfiVariableArchProtocolGuid, NULL},
1698 {STRING_TOKEN(STR_SECP), &gEfiSecurityPolicyProtocolGuid, NULL},
1699 {STRING_TOKEN(STR_WDT_ARCH), &gEfiWatchdogTimerArchProtocolGuid, NULL},
1700 {STRING_TOKEN(STR_SCR), &gEfiStatusCodeRuntimeProtocolGuid, NULL},
1701 {STRING_TOKEN(STR_SMB_HC), &gEfiSmbusHcProtocolGuid, NULL},
1702 {STRING_TOKEN(STR_FV_2), &gEfiFirmwareVolume2ProtocolGuid, NULL},
1703 {STRING_TOKEN(STR_FV_BLOCK), &gEfiFirmwareVolumeBlockProtocolGuid, NULL},
1704 {STRING_TOKEN(STR_CAP_ARCH), &gEfiCapsuleArchProtocolGuid, NULL},
1705 {STRING_TOKEN(STR_MP_SERVICE), &gEfiMpServiceProtocolGuid, NULL},
1706 {STRING_TOKEN(STR_HBRAP), &gEfiPciHostBridgeResourceAllocationProtocolGuid, NULL},
1707 {STRING_TOKEN(STR_PCIP), &gEfiPciPlatformProtocolGuid, NULL},
1708 {STRING_TOKEN(STR_PCIO), &gEfiPciOverrideProtocolGuid, NULL},
1709 {STRING_TOKEN(STR_PCIE), &gEfiPciEnumerationCompleteProtocolGuid, NULL},
1710 {STRING_TOKEN(STR_IPCID), &gEfiIncompatiblePciDeviceSupportProtocolGuid, NULL},
1711 {STRING_TOKEN(STR_PCIHPI), &gEfiPciHotPlugInitProtocolGuid, NULL},
1712 {STRING_TOKEN(STR_PCIHPR), &gEfiPciHotPlugRequestProtocolGuid, NULL},
1713 {STRING_TOKEN(STR_SMBIOS), &gEfiSmbiosProtocolGuid, NULL},
1714 {STRING_TOKEN(STR_S3_SAVE), &gEfiS3SaveStateProtocolGuid, NULL},
1715 {STRING_TOKEN(STR_S3_S_SMM), &gEfiS3SmmSaveStateProtocolGuid, NULL},
1716 {STRING_TOKEN(STR_RSC), &gEfiRscHandlerProtocolGuid, NULL},
1717 {STRING_TOKEN(STR_S_RSC), &gEfiSmmRscHandlerProtocolGuid, NULL},
1718 {STRING_TOKEN(STR_ACPI_SDT), &gEfiAcpiSdtProtocolGuid, NULL},
1719 {STRING_TOKEN(STR_SIO), &gEfiSioProtocolGuid, NULL},
1720 {STRING_TOKEN(STR_S_CPU2), &gEfiSmmCpuIo2ProtocolGuid, NULL},
1721 {STRING_TOKEN(STR_S_BASE2), &gEfiSmmBase2ProtocolGuid, NULL},
1722 {STRING_TOKEN(STR_S_ACC_2), &gEfiSmmAccess2ProtocolGuid, NULL},
1723 {STRING_TOKEN(STR_S_CON_2), &gEfiSmmControl2ProtocolGuid, NULL},
1724 {STRING_TOKEN(STR_S_CONFIG), &gEfiSmmConfigurationProtocolGuid, NULL},
1725 {STRING_TOKEN(STR_S_RTL), &gEfiSmmReadyToLockProtocolGuid, NULL},
1726 {STRING_TOKEN(STR_DS_RTL), &gEfiDxeSmmReadyToLockProtocolGuid, NULL},
1727 {STRING_TOKEN(STR_S_COMM), &gEfiSmmCommunicationProtocolGuid, NULL},
1728 {STRING_TOKEN(STR_S_STAT), &gEfiSmmStatusCodeProtocolGuid, NULL},
1729 {STRING_TOKEN(STR_S_CPU), &gEfiSmmCpuProtocolGuid, NULL},
1730 {STRING_TOKEN(STR_S_PCIRBIO), &gEfiPciRootBridgeIoProtocolGuid, NULL},
1731 {STRING_TOKEN(STR_S_SWD), &gEfiSmmSwDispatch2ProtocolGuid, NULL},
1732 {STRING_TOKEN(STR_S_SXD), &gEfiSmmSxDispatch2ProtocolGuid, NULL},
1733 {STRING_TOKEN(STR_S_PTD2), &gEfiSmmPeriodicTimerDispatch2ProtocolGuid, NULL},
1734 {STRING_TOKEN(STR_S_UD2), &gEfiSmmUsbDispatch2ProtocolGuid, NULL},
1735 {STRING_TOKEN(STR_S_GD2), &gEfiSmmGpiDispatch2ProtocolGuid, NULL},
1736 {STRING_TOKEN(STR_S_SBD2), &gEfiSmmStandbyButtonDispatch2ProtocolGuid, NULL},
1737 {STRING_TOKEN(STR_S_PBD2), &gEfiSmmPowerButtonDispatch2ProtocolGuid, NULL},
1738 {STRING_TOKEN(STR_S_ITD2), &gEfiSmmIoTrapDispatch2ProtocolGuid, NULL},
1739 {STRING_TOKEN(STR_PCD), &gEfiPcdProtocolGuid, NULL},
1740 {STRING_TOKEN(STR_FVB2), &gEfiFirmwareVolumeBlock2ProtocolGuid, NULL},
1741 {STRING_TOKEN(STR_CPUIO2), &gEfiCpuIo2ProtocolGuid, NULL},
1742 {STRING_TOKEN(STR_LEGACY_R2), &gEfiLegacyRegion2ProtocolGuid, NULL},
1743 {STRING_TOKEN(STR_SAL_MIP), &gEfiSalMcaInitPmiProtocolGuid, NULL},
1744 {STRING_TOKEN(STR_ES_BS), &gEfiExtendedSalBootServiceProtocolGuid, NULL},
1745 {STRING_TOKEN(STR_ES_BIO), &gEfiExtendedSalBaseIoServicesProtocolGuid, NULL},
1746 {STRING_TOKEN(STR_ES_STALL), &gEfiExtendedSalStallServicesProtocolGuid, NULL},
1747 {STRING_TOKEN(STR_ES_RTC), &gEfiExtendedSalRtcServicesProtocolGuid, NULL},
1748 {STRING_TOKEN(STR_ES_VS), &gEfiExtendedSalVariableServicesProtocolGuid, NULL},
1749 {STRING_TOKEN(STR_ES_MTC), &gEfiExtendedSalMtcServicesProtocolGuid, NULL},
1750 {STRING_TOKEN(STR_ES_RESET), &gEfiExtendedSalResetServicesProtocolGuid, NULL},
1751 {STRING_TOKEN(STR_ES_SC), &gEfiExtendedSalStatusCodeServicesProtocolGuid, NULL},
1752 {STRING_TOKEN(STR_ES_FBS), &gEfiExtendedSalFvBlockServicesProtocolGuid, NULL},
1753 {STRING_TOKEN(STR_ES_MP), &gEfiExtendedSalMpServicesProtocolGuid, NULL},
1754 {STRING_TOKEN(STR_ES_PAL), &gEfiExtendedSalPalServicesProtocolGuid, NULL},
1755 {STRING_TOKEN(STR_ES_BASE), &gEfiExtendedSalBaseServicesProtocolGuid, NULL},
1756 {STRING_TOKEN(STR_ES_MCA), &gEfiExtendedSalMcaServicesProtocolGuid, NULL},
1757 {STRING_TOKEN(STR_ES_PCI), &gEfiExtendedSalPciServicesProtocolGuid, NULL},
1758 {STRING_TOKEN(STR_ES_CACHE), &gEfiExtendedSalCacheServicesProtocolGuid, NULL},
1759 {STRING_TOKEN(STR_ES_MCA_LOG), &gEfiExtendedSalMcaLogServicesProtocolGuid, NULL},
1760 {STRING_TOKEN(STR_S2ARCH), &gEfiSecurity2ArchProtocolGuid, NULL},
1761 {STRING_TOKEN(STR_EODXE), &gEfiSmmEndOfDxeProtocolGuid, NULL},
1762 {STRING_TOKEN(STR_ISAHC), &gEfiIsaHcProtocolGuid, NULL},
1763 {STRING_TOKEN(STR_ISAHC_B), &gEfiIsaHcServiceBindingProtocolGuid, NULL},
1764 {STRING_TOKEN(STR_SIO_C), &gEfiSioControlProtocolGuid, NULL},
1765 {STRING_TOKEN(STR_GET_PCD), &gEfiGetPcdInfoProtocolGuid, NULL},
1766 {STRING_TOKEN(STR_I2C_M), &gEfiI2cMasterProtocolGuid, NULL},
1767 {STRING_TOKEN(STR_I2CIO), &gEfiI2cIoProtocolGuid, NULL},
1768 {STRING_TOKEN(STR_I2CEN), &gEfiI2cEnumerateProtocolGuid, NULL},
1769 {STRING_TOKEN(STR_I2C_H), &gEfiI2cHostProtocolGuid, NULL},
1770 {STRING_TOKEN(STR_I2C_BCM), &gEfiI2cBusConfigurationManagementProtocolGuid, NULL},
1771 {STRING_TOKEN(STR_TREE), &gEfiTrEEProtocolGuid, NULL},
1772 {STRING_TOKEN(STR_TCG2), &gEfiTcg2ProtocolGuid, NULL},
1773 {STRING_TOKEN(STR_TIMESTAMP), &gEfiTimestampProtocolGuid, NULL},
1774 {STRING_TOKEN(STR_RNG), &gEfiRngProtocolGuid, NULL},
1775 {STRING_TOKEN(STR_NVMEPT), &gEfiNvmExpressPassThruProtocolGuid, NULL},
1776 {STRING_TOKEN(STR_H2_SB), &gEfiHash2ServiceBindingProtocolGuid, NULL},
1777 {STRING_TOKEN(STR_HASH2), &gEfiHash2ProtocolGuid, NULL},
1778 {STRING_TOKEN(STR_BIO_C), &gEfiBlockIoCryptoProtocolGuid, NULL},
1779 {STRING_TOKEN(STR_SCR), &gEfiSmartCardReaderProtocolGuid, NULL},
1780 {STRING_TOKEN(STR_SCE), &gEfiSmartCardEdgeProtocolGuid, NULL},
1781 {STRING_TOKEN(STR_USB_FIO), &gEfiUsbFunctionIoProtocolGuid, NULL},
1782 {STRING_TOKEN(STR_BC_HC), &gEfiBluetoothHcProtocolGuid, NULL},
1783 {STRING_TOKEN(STR_BC_IO_SB), &gEfiBluetoothIoServiceBindingProtocolGuid, NULL},
1784 {STRING_TOKEN(STR_BC_IO), &gEfiBluetoothIoProtocolGuid, NULL},
1785 {STRING_TOKEN(STR_BC_C), &gEfiBluetoothConfigProtocolGuid, NULL},
1786 {STRING_TOKEN(STR_REG_EXP), &gEfiRegularExpressionProtocolGuid, NULL},
1787 {STRING_TOKEN(STR_B_MGR_P), &gEfiBootManagerPolicyProtocolGuid, NULL},
1788 {STRING_TOKEN(STR_CKH), &gEfiConfigKeywordHandlerProtocolGuid, NULL},
1789 {STRING_TOKEN(STR_WIFI), &gEfiWiFiProtocolGuid, NULL},
1790 {STRING_TOKEN(STR_EAP_M), &gEfiEapManagement2ProtocolGuid, NULL},
1791 {STRING_TOKEN(STR_EAP_C), &gEfiEapConfigurationProtocolGuid, NULL},
1792 {STRING_TOKEN(STR_PKCS7), &gEfiPkcs7VerifyProtocolGuid, NULL},
1793 {STRING_TOKEN(STR_NET_DNS4_SB), &gEfiDns4ServiceBindingProtocolGuid, NULL},
1794 {STRING_TOKEN(STR_NET_DNS4), &gEfiDns4ProtocolGuid, NULL},
1795 {STRING_TOKEN(STR_NET_DNS6_SB), &gEfiDns6ServiceBindingProtocolGuid, NULL},
1796 {STRING_TOKEN(STR_NET_DNS6), &gEfiDns6ProtocolGuid, NULL},
1797 {STRING_TOKEN(STR_NET_HTTP_SB), &gEfiHttpServiceBindingProtocolGuid, NULL},
1798 {STRING_TOKEN(STR_NET_HTTP), &gEfiHttpProtocolGuid, NULL},
1799 {STRING_TOKEN(STR_NET_HTTP_U), &gEfiHttpUtilitiesProtocolGuid, NULL},
1800 {STRING_TOKEN(STR_REST), &gEfiRestProtocolGuid, NULL},
1801
1802 //
1803 // UEFI Shell Spec 2.0
1804 //
1805 {STRING_TOKEN(STR_SHELL_PARAMETERS), &gEfiShellParametersProtocolGuid, NULL},
1806 {STRING_TOKEN(STR_SHELL), &gEfiShellProtocolGuid, NULL},
1807
1808 //
1809 // UEFI Shell Spec 2.1
1810 //
1811 {STRING_TOKEN(STR_SHELL_DYNAMIC), &gEfiShellDynamicCommandProtocolGuid, NULL},
1812
1813 //
1814 // Misc
1815 //
1816 {STRING_TOKEN(STR_PCDINFOPROT), &gGetPcdInfoProtocolGuid, NULL},
1817
1818 //
1819 // terminator
1820 //
1821 {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},
1822 };
1823
1824 /**
1825 Function to get the node for a protocol or struct from it's GUID.
1826
1827 if Guid is NULL, then ASSERT.
1828
1829 @param[in] Guid The GUID to look for the name of.
1830
1831 @return The node.
1832 **/
1833 CONST GUID_INFO_BLOCK *
1834 EFIAPI
1835 InternalShellGetNodeFromGuid(
1836 IN CONST EFI_GUID* Guid
1837 )
1838 {
1839 CONST GUID_INFO_BLOCK *ListWalker;
1840 UINTN LoopCount;
1841
1842 ASSERT(Guid != NULL);
1843
1844 for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {
1845 if (CompareGuid(ListWalker->GuidId, Guid)) {
1846 return (ListWalker);
1847 }
1848 }
1849
1850 if (PcdGetBool(PcdShellIncludeNtGuids)) {
1851 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
1852 if (CompareGuid(ListWalker->GuidId, Guid)) {
1853 return (ListWalker);
1854 }
1855 }
1856 }
1857 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
1858 if (CompareGuid(ListWalker->GuidId, Guid)) {
1859 return (ListWalker);
1860 }
1861 }
1862 return (NULL);
1863 }
1864
1865 /**
1866 Function to add a new GUID/Name mapping.
1867
1868 @param[in] Guid The Guid
1869 @param[in] NameID The STRING id of the HII string to use
1870 @param[in] DumpFunc The pointer to the dump function
1871
1872
1873 @retval EFI_SUCCESS The operation was sucessful
1874 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1875 @retval EFI_INVALID_PARAMETER Guid NameId was invalid
1876 **/
1877 EFI_STATUS
1878 EFIAPI
1879 InsertNewGuidNameMapping(
1880 IN CONST EFI_GUID *Guid,
1881 IN CONST EFI_STRING_ID NameID,
1882 IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
1883 )
1884 {
1885 ASSERT(Guid != NULL);
1886 ASSERT(NameID != 0);
1887
1888 GuidList = ReallocatePool(GuidListCount * sizeof(GUID_INFO_BLOCK), GuidListCount+1 * sizeof(GUID_INFO_BLOCK), GuidList);
1889 if (GuidList == NULL) {
1890 GuidListCount = 0;
1891 return (EFI_OUT_OF_RESOURCES);
1892 }
1893 GuidListCount++;
1894
1895 GuidList[GuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid);
1896 GuidList[GuidListCount - 1].StringId = NameID;
1897 GuidList[GuidListCount - 1].DumpInfo = DumpFunc;
1898
1899 if (GuidList[GuidListCount - 1].GuidId == NULL) {
1900 return (EFI_OUT_OF_RESOURCES);
1901 }
1902
1903 return (EFI_SUCCESS);
1904 }
1905
1906 /**
1907 Function to add a new GUID/Name mapping.
1908
1909 This cannot overwrite an existing mapping.
1910
1911 @param[in] Guid The Guid
1912 @param[in] TheName The Guid's name
1913 @param[in] Lang RFC4646 language code list or NULL
1914
1915 @retval EFI_SUCCESS The operation was sucessful
1916 @retval EFI_ACCESS_DENIED There was a duplicate
1917 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1918 @retval EFI_INVALID_PARAMETER Guid or TheName was NULL
1919 **/
1920 EFI_STATUS
1921 EFIAPI
1922 AddNewGuidNameMapping(
1923 IN CONST EFI_GUID *Guid,
1924 IN CONST CHAR16 *TheName,
1925 IN CONST CHAR8 *Lang OPTIONAL
1926 )
1927 {
1928 EFI_STRING_ID NameID;
1929
1930 HandleParsingHiiInit();
1931
1932 if (Guid == NULL || TheName == NULL){
1933 return (EFI_INVALID_PARAMETER);
1934 }
1935
1936 if ((InternalShellGetNodeFromGuid(Guid)) != NULL) {
1937 return (EFI_ACCESS_DENIED);
1938 }
1939
1940 NameID = HiiSetString(mHandleParsingHiiHandle, 0, (CHAR16*)TheName, Lang);
1941 if (NameID == 0) {
1942 return (EFI_OUT_OF_RESOURCES);
1943 }
1944
1945 return (InsertNewGuidNameMapping(Guid, NameID, NULL));
1946 }
1947
1948 /**
1949 Function to get the name of a protocol or struct from it's GUID.
1950
1951 if Guid is NULL, then ASSERT.
1952
1953 @param[in] Guid The GUID to look for the name of.
1954 @param[in] Lang The language to use.
1955
1956 @return pointer to string of the name. The caller
1957 is responsible to free this memory.
1958 **/
1959 CHAR16*
1960 EFIAPI
1961 GetStringNameFromGuid(
1962 IN CONST EFI_GUID *Guid,
1963 IN CONST CHAR8 *Lang OPTIONAL
1964 )
1965 {
1966 CONST GUID_INFO_BLOCK *Id;
1967
1968 HandleParsingHiiInit();
1969
1970 Id = InternalShellGetNodeFromGuid(Guid);
1971 return (HiiGetString(mHandleParsingHiiHandle, Id==NULL?STRING_TOKEN(STR_UNKNOWN_DEVICE):Id->StringId, Lang));
1972 }
1973
1974 /**
1975 Function to dump protocol information from a handle.
1976
1977 This function will return a allocated string buffer containing the
1978 information. The caller is responsible for freeing the memory.
1979
1980 If Guid is NULL, ASSERT().
1981 If TheHandle is NULL, ASSERT().
1982
1983 @param[in] TheHandle The handle to dump information from.
1984 @param[in] Guid The GUID of the protocol to dump.
1985 @param[in] Verbose TRUE for extra info. FALSE otherwise.
1986
1987 @return The pointer to string.
1988 @retval NULL An error was encountered.
1989 **/
1990 CHAR16*
1991 EFIAPI
1992 GetProtocolInformationDump(
1993 IN CONST EFI_HANDLE TheHandle,
1994 IN CONST EFI_GUID *Guid,
1995 IN CONST BOOLEAN Verbose
1996 )
1997 {
1998 CONST GUID_INFO_BLOCK *Id;
1999
2000 ASSERT(TheHandle != NULL);
2001 ASSERT(Guid != NULL);
2002
2003 if (TheHandle == NULL || Guid == NULL) {
2004 return (NULL);
2005 }
2006
2007 Id = InternalShellGetNodeFromGuid(Guid);
2008 if (Id != NULL && Id->DumpInfo != NULL) {
2009 return (Id->DumpInfo(TheHandle, Verbose));
2010 }
2011 return (NULL);
2012 }
2013
2014 /**
2015 Function to get the Guid for a protocol or struct based on it's string name.
2016
2017 do not modify the returned Guid.
2018
2019 @param[in] Name The pointer to the string name.
2020 @param[in] Lang The pointer to the language code.
2021 @param[out] Guid The pointer to the Guid.
2022
2023 @retval EFI_SUCCESS The operation was sucessful.
2024 **/
2025 EFI_STATUS
2026 EFIAPI
2027 GetGuidFromStringName(
2028 IN CONST CHAR16 *Name,
2029 IN CONST CHAR8 *Lang OPTIONAL,
2030 OUT EFI_GUID **Guid
2031 )
2032 {
2033 CONST GUID_INFO_BLOCK *ListWalker;
2034 CHAR16 *String;
2035 UINTN LoopCount;
2036
2037 HandleParsingHiiInit();
2038
2039 ASSERT(Guid != NULL);
2040 if (Guid == NULL) {
2041 return (EFI_INVALID_PARAMETER);
2042 }
2043 *Guid = NULL;
2044
2045 if (PcdGetBool(PcdShellIncludeNtGuids)) {
2046 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2047 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2048 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2049 *Guid = ListWalker->GuidId;
2050 }
2051 SHELL_FREE_NON_NULL(String);
2052 if (*Guid != NULL) {
2053 return (EFI_SUCCESS);
2054 }
2055 }
2056 }
2057 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2058 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2059 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2060 *Guid = ListWalker->GuidId;
2061 }
2062 SHELL_FREE_NON_NULL(String);
2063 if (*Guid != NULL) {
2064 return (EFI_SUCCESS);
2065 }
2066 }
2067
2068 for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {
2069 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2070 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2071 *Guid = ListWalker->GuidId;
2072 }
2073 SHELL_FREE_NON_NULL(String);
2074 if (*Guid != NULL) {
2075 return (EFI_SUCCESS);
2076 }
2077 }
2078
2079 return (EFI_NOT_FOUND);
2080 }
2081
2082 /**
2083 Get best support language for this driver.
2084
2085 First base on the user input language to search, second base on the current
2086 platform used language to search, third get the first language from the
2087 support language list. The caller need to free the buffer of the best language.
2088
2089 @param[in] SupportedLanguages The support languages for this driver.
2090 @param[in] InputLanguage The user input language.
2091 @param[in] Iso639Language Whether get language for ISO639.
2092
2093 @return The best support language for this driver.
2094 **/
2095 CHAR8 *
2096 EFIAPI
2097 GetBestLanguageForDriver (
2098 IN CONST CHAR8 *SupportedLanguages,
2099 IN CONST CHAR8 *InputLanguage,
2100 IN BOOLEAN Iso639Language
2101 )
2102 {
2103 CHAR8 *LanguageVariable;
2104 CHAR8 *BestLanguage;
2105
2106 GetVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid, (VOID**)&LanguageVariable, NULL);
2107
2108 BestLanguage = GetBestLanguage(
2109 SupportedLanguages,
2110 Iso639Language,
2111 (InputLanguage != NULL) ? InputLanguage : "",
2112 (LanguageVariable != NULL) ? LanguageVariable : "",
2113 SupportedLanguages,
2114 NULL
2115 );
2116
2117 if (LanguageVariable != NULL) {
2118 FreePool (LanguageVariable);
2119 }
2120
2121 return BestLanguage;
2122 }
2123
2124 /**
2125 Function to retrieve the driver name (if possible) from the ComponentName or
2126 ComponentName2 protocol
2127
2128 @param[in] TheHandle The driver handle to get the name of.
2129 @param[in] Language The language to use.
2130
2131 @retval NULL The name could not be found.
2132 @return A pointer to the string name. Do not de-allocate the memory.
2133 **/
2134 CONST CHAR16*
2135 EFIAPI
2136 GetStringNameFromHandle(
2137 IN CONST EFI_HANDLE TheHandle,
2138 IN CONST CHAR8 *Language
2139 )
2140 {
2141 EFI_COMPONENT_NAME2_PROTOCOL *CompNameStruct;
2142 EFI_STATUS Status;
2143 CHAR16 *RetVal;
2144 CHAR8 *BestLang;
2145
2146 BestLang = NULL;
2147
2148 Status = gBS->OpenProtocol(
2149 TheHandle,
2150 &gEfiComponentName2ProtocolGuid,
2151 (VOID**)&CompNameStruct,
2152 gImageHandle,
2153 NULL,
2154 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2155 if (!EFI_ERROR(Status)) {
2156 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
2157 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
2158 if (BestLang != NULL) {
2159 FreePool (BestLang);
2160 BestLang = NULL;
2161 }
2162 if (!EFI_ERROR(Status)) {
2163 return (RetVal);
2164 }
2165 }
2166 Status = gBS->OpenProtocol(
2167 TheHandle,
2168 &gEfiComponentNameProtocolGuid,
2169 (VOID**)&CompNameStruct,
2170 gImageHandle,
2171 NULL,
2172 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2173 if (!EFI_ERROR(Status)) {
2174 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
2175 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
2176 if (BestLang != NULL) {
2177 FreePool (BestLang);
2178 }
2179 if (!EFI_ERROR(Status)) {
2180 return (RetVal);
2181 }
2182 }
2183 return (NULL);
2184 }
2185
2186 /**
2187 Function to initialize the file global mHandleList object for use in
2188 vonverting handles to index and index to handle.
2189
2190 @retval EFI_SUCCESS The operation was successful.
2191 **/
2192 EFI_STATUS
2193 EFIAPI
2194 InternalShellInitHandleList(
2195 VOID
2196 )
2197 {
2198 EFI_STATUS Status;
2199 EFI_HANDLE *HandleBuffer;
2200 UINTN HandleCount;
2201 HANDLE_LIST *ListWalker;
2202
2203 if (mHandleList.NextIndex != 0) {
2204 return EFI_SUCCESS;
2205 }
2206 InitializeListHead(&mHandleList.List.Link);
2207 mHandleList.NextIndex = 1;
2208 Status = gBS->LocateHandleBuffer (
2209 AllHandles,
2210 NULL,
2211 NULL,
2212 &HandleCount,
2213 &HandleBuffer
2214 );
2215 ASSERT_EFI_ERROR(Status);
2216 if (EFI_ERROR(Status)) {
2217 return (Status);
2218 }
2219 for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){
2220 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
2221 if (ListWalker != NULL) {
2222 ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex - 1];
2223 ListWalker->TheIndex = mHandleList.NextIndex;
2224 InsertTailList (&mHandleList.List.Link, &ListWalker->Link);
2225 }
2226 }
2227 FreePool(HandleBuffer);
2228 return (EFI_SUCCESS);
2229 }
2230
2231 /**
2232 Function to retrieve the human-friendly index of a given handle. If the handle
2233 does not have a index one will be automatically assigned. The index value is valid
2234 until the termination of the shell application.
2235
2236 @param[in] TheHandle The handle to retrieve an index for.
2237
2238 @retval 0 A memory allocation failed.
2239 @return The index of the handle.
2240
2241 **/
2242 UINTN
2243 EFIAPI
2244 ConvertHandleToHandleIndex(
2245 IN CONST EFI_HANDLE TheHandle
2246 )
2247 {
2248 EFI_STATUS Status;
2249 EFI_GUID **ProtocolBuffer;
2250 UINTN ProtocolCount;
2251 HANDLE_LIST *ListWalker;
2252
2253 if (TheHandle == NULL) {
2254 return 0;
2255 }
2256
2257 InternalShellInitHandleList();
2258
2259 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
2260 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
2261 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
2262 ){
2263 if (ListWalker->TheHandle == TheHandle) {
2264 //
2265 // Verify that TheHandle is still present in the Handle Database
2266 //
2267 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
2268 if (EFI_ERROR (Status)) {
2269 //
2270 // TheHandle is not present in the Handle Database, so delete from the handle list
2271 //
2272 RemoveEntryList (&ListWalker->Link);
2273 return 0;
2274 }
2275 FreePool (ProtocolBuffer);
2276 return (ListWalker->TheIndex);
2277 }
2278 }
2279
2280 //
2281 // Verify that TheHandle is valid handle
2282 //
2283 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
2284 if (EFI_ERROR (Status)) {
2285 //
2286 // TheHandle is not valid, so do not add to handle list
2287 //
2288 return 0;
2289 }
2290 FreePool (ProtocolBuffer);
2291
2292 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
2293 if (ListWalker == NULL) {
2294 return 0;
2295 }
2296 ListWalker->TheHandle = TheHandle;
2297 ListWalker->TheIndex = mHandleList.NextIndex++;
2298 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);
2299 return (ListWalker->TheIndex);
2300 }
2301
2302
2303
2304 /**
2305 Function to retrieve the EFI_HANDLE from the human-friendly index.
2306
2307 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
2308
2309 @retval NULL The index was invalid.
2310 @return The EFI_HANDLE that index represents.
2311
2312 **/
2313 EFI_HANDLE
2314 EFIAPI
2315 ConvertHandleIndexToHandle(
2316 IN CONST UINTN TheIndex
2317 )
2318 {
2319 EFI_STATUS Status;
2320 EFI_GUID **ProtocolBuffer;
2321 UINTN ProtocolCount;
2322 HANDLE_LIST *ListWalker;
2323
2324 InternalShellInitHandleList();
2325
2326 if (TheIndex >= mHandleList.NextIndex) {
2327 return NULL;
2328 }
2329
2330 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
2331 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
2332 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
2333 ){
2334 if (ListWalker->TheIndex == TheIndex && ListWalker->TheHandle != NULL) {
2335 //
2336 // Verify that LinkWalker->TheHandle is valid handle
2337 //
2338 Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);
2339 if (EFI_ERROR (Status)) {
2340 //
2341 // TheHandle is not valid, so do not add to handle list
2342 //
2343 ListWalker->TheHandle = NULL;
2344 }
2345 return (ListWalker->TheHandle);
2346 }
2347 }
2348 return NULL;
2349 }
2350
2351 /**
2352 Gets all the related EFI_HANDLEs based on the mask supplied.
2353
2354 This function scans all EFI_HANDLES in the UEFI environment's handle database
2355 and returns the ones with the specified relationship (Mask) to the specified
2356 controller handle.
2357
2358 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
2359 If MatchingHandleCount is NULL, then ASSERT.
2360
2361 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
2362 caller freed.
2363
2364 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
2365 @param[in] ControllerHandle The handle with Device Path protocol on it.
2366 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
2367 MatchingHandleBuffer.
2368 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
2369 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
2370 @param[out] HandleType An array of type information.
2371
2372 @retval EFI_SUCCESS The operation was successful, and any related handles
2373 are in MatchingHandleBuffer.
2374 @retval EFI_NOT_FOUND No matching handles were found.
2375 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
2376 **/
2377 EFI_STATUS
2378 EFIAPI
2379 ParseHandleDatabaseByRelationshipWithType (
2380 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
2381 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
2382 IN UINTN *HandleCount,
2383 OUT EFI_HANDLE **HandleBuffer,
2384 OUT UINTN **HandleType
2385 )
2386 {
2387 EFI_STATUS Status;
2388 UINTN HandleIndex;
2389 EFI_GUID **ProtocolGuidArray;
2390 UINTN ArrayCount;
2391 UINTN ProtocolIndex;
2392 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
2393 UINTN OpenInfoCount;
2394 UINTN OpenInfoIndex;
2395 UINTN ChildIndex;
2396 INTN DriverBindingHandleIndex;
2397
2398 ASSERT(HandleCount != NULL);
2399 ASSERT(HandleBuffer != NULL);
2400 ASSERT(HandleType != NULL);
2401 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
2402
2403 *HandleCount = 0;
2404 *HandleBuffer = NULL;
2405 *HandleType = NULL;
2406
2407 //
2408 // Retrieve the list of all handles from the handle database
2409 //
2410 Status = gBS->LocateHandleBuffer (
2411 AllHandles,
2412 NULL,
2413 NULL,
2414 HandleCount,
2415 HandleBuffer
2416 );
2417 if (EFI_ERROR (Status)) {
2418 return (Status);
2419 }
2420
2421 *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));
2422 if (*HandleType == NULL) {
2423 SHELL_FREE_NON_NULL (*HandleBuffer);
2424 *HandleCount = 0;
2425 return EFI_OUT_OF_RESOURCES;
2426 }
2427
2428 DriverBindingHandleIndex = -1;
2429 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
2430 if (DriverBindingHandle != NULL && (*HandleBuffer)[HandleIndex] == DriverBindingHandle) {
2431 DriverBindingHandleIndex = (INTN)HandleIndex;
2432 }
2433 }
2434
2435 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
2436 //
2437 // Retrieve the list of all the protocols on each handle
2438 //
2439 Status = gBS->ProtocolsPerHandle (
2440 (*HandleBuffer)[HandleIndex],
2441 &ProtocolGuidArray,
2442 &ArrayCount
2443 );
2444 if (EFI_ERROR (Status)) {
2445 continue;
2446 }
2447
2448 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
2449
2450 //
2451 // Set the bit describing what this handle has
2452 //
2453 if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) ) {
2454 (*HandleType)[HandleIndex] |= (UINTN)HR_IMAGE_HANDLE;
2455 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) ) {
2456 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_BINDING_HANDLE;
2457 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {
2458 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
2459 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {
2460 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
2461 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) ) {
2462 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
2463 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) ) {
2464 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
2465 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) ) {
2466 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
2467 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) ) {
2468 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
2469 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) {
2470 (*HandleType)[HandleIndex] |= (UINTN)HR_DEVICE_HANDLE;
2471 }
2472 //
2473 // Retrieve the list of agents that have opened each protocol
2474 //
2475 Status = gBS->OpenProtocolInformation (
2476 (*HandleBuffer)[HandleIndex],
2477 ProtocolGuidArray[ProtocolIndex],
2478 &OpenInfo,
2479 &OpenInfoCount
2480 );
2481 if (EFI_ERROR (Status)) {
2482 continue;
2483 }
2484
2485 if (ControllerHandle == NULL) {
2486 //
2487 // ControllerHandle == NULL and DriverBindingHandle != NULL.
2488 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
2489 //
2490 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2491 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2492 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2493 if (DriverBindingHandleIndex != -1) {
2494 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
2495 }
2496 }
2497 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2498 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2499 if (DriverBindingHandleIndex != -1) {
2500 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2501 }
2502 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2503 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2504 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2505 }
2506 }
2507 }
2508 }
2509 }
2510 if (DriverBindingHandle == NULL && ControllerHandle != NULL) {
2511 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
2512 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2513 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2514 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2515 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2516 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2517 (*HandleType)[ChildIndex] |= (UINTN)HR_DEVICE_DRIVER;
2518 }
2519 }
2520 }
2521 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2522 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2523 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2524 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2525 }
2526 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2527 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2528 }
2529 }
2530 }
2531 }
2532 } else {
2533 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2534 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2535 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
2536 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
2537 }
2538 }
2539 }
2540 }
2541 }
2542 if (DriverBindingHandle != NULL && ControllerHandle != NULL) {
2543 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
2544 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2545 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2546 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2547 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
2548 if (DriverBindingHandleIndex != -1) {
2549 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
2550 }
2551 }
2552 }
2553 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2554 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
2555 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2556 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2557 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2558 }
2559 }
2560 }
2561
2562 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2563 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2564 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2565 }
2566 }
2567 }
2568 }
2569 } else {
2570 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2571 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2572 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
2573 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
2574 }
2575 }
2576 }
2577 }
2578 }
2579 FreePool (OpenInfo);
2580 }
2581 FreePool (ProtocolGuidArray);
2582 }
2583 return EFI_SUCCESS;
2584 }
2585
2586 /**
2587 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
2588 supplied.
2589
2590 This function will scan all EFI_HANDLES in the UEFI environment's handle database
2591 and return all the ones with the specified relationship (Mask) to the specified
2592 controller handle.
2593
2594 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
2595 If MatchingHandleCount is NULL, then ASSERT.
2596
2597 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
2598 caller freed.
2599
2600 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
2601 on it.
2602 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
2603 @param[in] Mask Mask of what relationship(s) is desired.
2604 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
2605 MatchingHandleBuffer.
2606 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
2607 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
2608
2609 @retval EFI_SUCCESS The operation was sucessful and any related handles
2610 are in MatchingHandleBuffer;
2611 @retval EFI_NOT_FOUND No matching handles were found.
2612 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
2613 **/
2614 EFI_STATUS
2615 EFIAPI
2616 ParseHandleDatabaseByRelationship (
2617 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
2618 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
2619 IN CONST UINTN Mask,
2620 IN UINTN *MatchingHandleCount,
2621 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
2622 )
2623 {
2624 EFI_STATUS Status;
2625 UINTN HandleCount;
2626 EFI_HANDLE *HandleBuffer;
2627 UINTN *HandleType;
2628 UINTN HandleIndex;
2629
2630 ASSERT(MatchingHandleCount != NULL);
2631 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
2632
2633 if ((Mask & HR_VALID_MASK) != Mask) {
2634 return (EFI_INVALID_PARAMETER);
2635 }
2636
2637 if ((Mask & HR_CHILD_HANDLE) != 0 && DriverBindingHandle == NULL) {
2638 return (EFI_INVALID_PARAMETER);
2639 }
2640
2641 *MatchingHandleCount = 0;
2642 if (MatchingHandleBuffer != NULL) {
2643 *MatchingHandleBuffer = NULL;
2644 }
2645
2646 HandleBuffer = NULL;
2647 HandleType = NULL;
2648
2649 Status = ParseHandleDatabaseByRelationshipWithType (
2650 DriverBindingHandle,
2651 ControllerHandle,
2652 &HandleCount,
2653 &HandleBuffer,
2654 &HandleType
2655 );
2656 if (!EFI_ERROR (Status)) {
2657 //
2658 // Count the number of handles that match the attributes in Mask
2659 //
2660 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
2661 if ((HandleType[HandleIndex] & Mask) == Mask) {
2662 (*MatchingHandleCount)++;
2663 }
2664 }
2665 //
2666 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
2667 //
2668 if (*MatchingHandleCount == 0) {
2669 Status = EFI_NOT_FOUND;
2670 } else {
2671
2672 if (MatchingHandleBuffer == NULL) {
2673 //
2674 // Someone just wanted the count...
2675 //
2676 Status = EFI_SUCCESS;
2677 } else {
2678 //
2679 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
2680 //
2681 *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE));
2682 if (*MatchingHandleBuffer == NULL) {
2683 Status = EFI_OUT_OF_RESOURCES;
2684 } else {
2685 for (HandleIndex = 0, *MatchingHandleCount = 0
2686 ; HandleIndex < HandleCount
2687 ; HandleIndex++
2688 ) {
2689 //
2690 // Fill the allocated buffer with the handles that matched the attributes in Mask
2691 //
2692 if ((HandleType[HandleIndex] & Mask) == Mask) {
2693 (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex];
2694 }
2695 }
2696
2697 //
2698 // Make the last one NULL
2699 //
2700 (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL;
2701
2702 Status = EFI_SUCCESS;
2703 } // *MatchingHandleBuffer == NULL (ELSE)
2704 } // MacthingHandleBuffer == NULL (ELSE)
2705 } // *MatchingHandleCount == 0 (ELSE)
2706 } // no error on ParseHandleDatabaseByRelationshipWithType
2707
2708 if (HandleBuffer != NULL) {
2709 FreePool (HandleBuffer);
2710 }
2711
2712 if (HandleType != NULL) {
2713 FreePool (HandleType);
2714 }
2715
2716 ASSERT ((MatchingHandleBuffer == NULL) ||
2717 (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
2718 (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
2719 return Status;
2720 }
2721
2722 /**
2723 Gets handles for any child controllers of the passed in controller.
2724
2725 @param[in] ControllerHandle The handle of the "parent controller"
2726 @param[out] MatchingHandleCount Pointer to the number of handles in
2727 MatchingHandleBuffer on return.
2728 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
2729 return.
2730
2731
2732 @retval EFI_SUCCESS The operation was sucessful.
2733 **/
2734 EFI_STATUS
2735 EFIAPI
2736 ParseHandleDatabaseForChildControllers(
2737 IN CONST EFI_HANDLE ControllerHandle,
2738 OUT UINTN *MatchingHandleCount,
2739 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
2740 )
2741 {
2742 EFI_STATUS Status;
2743 UINTN HandleIndex;
2744 UINTN DriverBindingHandleCount;
2745 EFI_HANDLE *DriverBindingHandleBuffer;
2746 UINTN DriverBindingHandleIndex;
2747 UINTN ChildControllerHandleCount;
2748 EFI_HANDLE *ChildControllerHandleBuffer;
2749 UINTN ChildControllerHandleIndex;
2750 EFI_HANDLE *HandleBufferForReturn;
2751
2752 if (MatchingHandleCount == NULL) {
2753 return (EFI_INVALID_PARAMETER);
2754 }
2755 *MatchingHandleCount = 0;
2756
2757 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
2758 ControllerHandle,
2759 &DriverBindingHandleCount,
2760 &DriverBindingHandleBuffer
2761 );
2762 if (EFI_ERROR (Status)) {
2763 return Status;
2764 }
2765
2766 //
2767 // Get a buffer big enough for all the controllers.
2768 //
2769 HandleBufferForReturn = GetHandleListByProtocol(NULL);
2770 if (HandleBufferForReturn == NULL) {
2771 FreePool (DriverBindingHandleBuffer);
2772 return (EFI_NOT_FOUND);
2773 }
2774
2775 for (DriverBindingHandleIndex = 0; DriverBindingHandleIndex < DriverBindingHandleCount; DriverBindingHandleIndex++) {
2776 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
2777 DriverBindingHandleBuffer[DriverBindingHandleIndex],
2778 ControllerHandle,
2779 &ChildControllerHandleCount,
2780 &ChildControllerHandleBuffer
2781 );
2782 if (EFI_ERROR (Status)) {
2783 continue;
2784 }
2785
2786 for (ChildControllerHandleIndex = 0;
2787 ChildControllerHandleIndex < ChildControllerHandleCount;
2788 ChildControllerHandleIndex++
2789 ) {
2790 for (HandleIndex = 0; HandleIndex < *MatchingHandleCount; HandleIndex++) {
2791 if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {
2792 break;
2793 }
2794 }
2795 if (HandleIndex >= *MatchingHandleCount) {
2796 HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
2797 }
2798 }
2799
2800 FreePool (ChildControllerHandleBuffer);
2801 }
2802
2803 FreePool (DriverBindingHandleBuffer);
2804
2805 if (MatchingHandleBuffer != NULL) {
2806 *MatchingHandleBuffer = HandleBufferForReturn;
2807 } else {
2808 FreePool(HandleBufferForReturn);
2809 }
2810 ASSERT ((MatchingHandleBuffer == NULL) ||
2811 (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
2812 (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
2813
2814 return (EFI_SUCCESS);
2815 }
2816
2817 /**
2818 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
2819 if necessary to fit all of the data.
2820
2821 If DestinationBuffer is NULL, then ASSERT().
2822
2823 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
2824 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
2825 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
2826 @param[in] SourceSize The number of bytes of SourceBuffer to append.
2827
2828 @retval NULL A memory allocation failed.
2829 @retval NULL A parameter was invalid.
2830 @return A pointer to (*DestinationBuffer).
2831 **/
2832 VOID*
2833 EFIAPI
2834 BuffernCatGrow (
2835 IN OUT VOID **DestinationBuffer,
2836 IN OUT UINTN *DestinationSize,
2837 IN VOID *SourceBuffer,
2838 IN UINTN SourceSize
2839 )
2840 {
2841 UINTN LocalDestinationSize;
2842 UINTN LocalDestinationFinalSize;
2843
2844 ASSERT(DestinationBuffer != NULL);
2845
2846 if (SourceSize == 0 || SourceBuffer == NULL) {
2847 return (*DestinationBuffer);
2848 }
2849
2850 if (DestinationSize == NULL) {
2851 LocalDestinationSize = 0;
2852 } else {
2853 LocalDestinationSize = *DestinationSize;
2854 }
2855
2856 LocalDestinationFinalSize = LocalDestinationSize + SourceSize;
2857
2858 if (DestinationSize != NULL) {
2859 *DestinationSize = LocalDestinationSize;
2860 }
2861
2862 if (LocalDestinationSize == 0) {
2863 // allcoate
2864 *DestinationBuffer = AllocateZeroPool(LocalDestinationFinalSize);
2865 } else {
2866 // reallocate
2867 *DestinationBuffer = ReallocatePool(LocalDestinationSize, LocalDestinationFinalSize, *DestinationBuffer);
2868 }
2869
2870 ASSERT(*DestinationBuffer != NULL);
2871
2872 // copy
2873 return (CopyMem(((UINT8*)(*DestinationBuffer)) + LocalDestinationSize, SourceBuffer, SourceSize));
2874 }
2875
2876 /**
2877 Gets handles for any child devices produced by the passed in driver.
2878
2879 @param[in] DriverHandle The handle of the driver.
2880 @param[in] MatchingHandleCount Pointer to the number of handles in
2881 MatchingHandleBuffer on return.
2882 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
2883 return.
2884 @retval EFI_SUCCESS The operation was sucessful.
2885 @sa ParseHandleDatabaseByRelationship
2886 **/
2887 EFI_STATUS
2888 EFIAPI
2889 ParseHandleDatabaseForChildDevices(
2890 IN CONST EFI_HANDLE DriverHandle,
2891 IN UINTN *MatchingHandleCount,
2892 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
2893 )
2894 {
2895 EFI_HANDLE *Buffer;
2896 EFI_HANDLE *Buffer2;
2897 UINTN Count1;
2898 UINTN Count2;
2899 UINTN HandleIndex;
2900 EFI_STATUS Status;
2901 UINTN HandleBufferSize;
2902
2903 ASSERT(MatchingHandleCount != NULL);
2904
2905 HandleBufferSize = 0;
2906 Buffer = NULL;
2907 Buffer2 = NULL;
2908 *MatchingHandleCount = 0;
2909
2910 Status = PARSE_HANDLE_DATABASE_DEVICES (
2911 DriverHandle,
2912 &Count1,
2913 &Buffer
2914 );
2915 if (!EFI_ERROR (Status)) {
2916 for (HandleIndex = 0; HandleIndex < Count1; HandleIndex++) {
2917 //
2918 // now find the children
2919 //
2920 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
2921 DriverHandle,
2922 Buffer[HandleIndex],
2923 &Count2,
2924 &Buffer2
2925 );
2926 if (EFI_ERROR(Status)) {
2927 break;
2928 }
2929 //
2930 // save out required and optional data elements
2931 //
2932 *MatchingHandleCount += Count2;
2933 if (MatchingHandleBuffer != NULL) {
2934 *MatchingHandleBuffer = BuffernCatGrow((VOID**)MatchingHandleBuffer, &HandleBufferSize, Buffer2, Count2 * sizeof(Buffer2[0]));
2935 }
2936
2937 //
2938 // free the memory
2939 //
2940 if (Buffer2 != NULL) {
2941 FreePool(Buffer2);
2942 }
2943 }
2944 }
2945
2946 if (Buffer != NULL) {
2947 FreePool(Buffer);
2948 }
2949 return (Status);
2950 }
2951
2952 /**
2953 Function to get all handles that support a given protocol or all handles.
2954
2955 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
2956 then the function will return all handles.
2957
2958 @retval NULL A memory allocation failed.
2959 @return A NULL terminated list of handles.
2960 **/
2961 EFI_HANDLE*
2962 EFIAPI
2963 GetHandleListByProtocol (
2964 IN CONST EFI_GUID *ProtocolGuid OPTIONAL
2965 )
2966 {
2967 EFI_HANDLE *HandleList;
2968 UINTN Size;
2969 EFI_STATUS Status;
2970
2971 Size = 0;
2972 HandleList = NULL;
2973
2974 //
2975 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
2976 //
2977 if (ProtocolGuid == NULL) {
2978 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
2979 if (Status == EFI_BUFFER_TOO_SMALL) {
2980 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
2981 if (HandleList == NULL) {
2982 return (NULL);
2983 }
2984 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
2985 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
2986 }
2987 } else {
2988 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
2989 if (Status == EFI_BUFFER_TOO_SMALL) {
2990 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
2991 if (HandleList == NULL) {
2992 return (NULL);
2993 }
2994 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
2995 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
2996 }
2997 }
2998 if (EFI_ERROR(Status)) {
2999 if (HandleList != NULL) {
3000 FreePool(HandleList);
3001 }
3002 return (NULL);
3003 }
3004 return (HandleList);
3005 }
3006
3007 /**
3008 Function to get all handles that support some protocols.
3009
3010 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
3011
3012 @retval NULL A memory allocation failed.
3013 @retval NULL ProtocolGuids was NULL.
3014 @return A NULL terminated list of EFI_HANDLEs.
3015 **/
3016 EFI_HANDLE*
3017 EFIAPI
3018 GetHandleListByProtocolList (
3019 IN CONST EFI_GUID **ProtocolGuids
3020 )
3021 {
3022 EFI_HANDLE *HandleList;
3023 UINTN Size;
3024 UINTN TotalSize;
3025 UINTN TempSize;
3026 EFI_STATUS Status;
3027 CONST EFI_GUID **GuidWalker;
3028 EFI_HANDLE *HandleWalker1;
3029 EFI_HANDLE *HandleWalker2;
3030
3031 Size = 0;
3032 HandleList = NULL;
3033 TotalSize = sizeof(EFI_HANDLE);
3034
3035 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++,Size = 0){
3036 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &Size, NULL);
3037 if (Status == EFI_BUFFER_TOO_SMALL) {
3038 TotalSize += Size;
3039 }
3040 }
3041
3042 //
3043 // No handles were found...
3044 //
3045 if (TotalSize == sizeof(EFI_HANDLE)) {
3046 return (NULL);
3047 }
3048
3049 HandleList = AllocateZeroPool(TotalSize);
3050 if (HandleList == NULL) {
3051 return (NULL);
3052 }
3053
3054 Size = 0;
3055 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++){
3056 TempSize = TotalSize - Size;
3057 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &TempSize, HandleList+(Size/sizeof(EFI_HANDLE)));
3058
3059 //
3060 // Allow for missing protocols... Only update the 'used' size upon success.
3061 //
3062 if (!EFI_ERROR(Status)) {
3063 Size += TempSize;
3064 }
3065 }
3066 ASSERT(HandleList[(TotalSize/sizeof(EFI_HANDLE))-1] == NULL);
3067
3068 for (HandleWalker1 = HandleList ; HandleWalker1 != NULL && *HandleWalker1 != NULL ; HandleWalker1++) {
3069 for (HandleWalker2 = HandleWalker1 + 1; HandleWalker2 != NULL && *HandleWalker2 != NULL ; HandleWalker2++) {
3070 if (*HandleWalker1 == *HandleWalker2) {
3071 //
3072 // copy memory back 1 handle width.
3073 //
3074 CopyMem(HandleWalker2, HandleWalker2 + 1, TotalSize - ((HandleWalker2-HandleList+1)*sizeof(EFI_HANDLE)));
3075 }
3076 }
3077 }
3078
3079 return (HandleList);
3080 }