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