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