]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/UefiHandleParsingLib: Remove some unused Guids
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
1 /** @file
2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
3
4 Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
6 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
7 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_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 // PI Spec ones
2255 //
2256 {STRING_TOKEN(STR_IDE_CONT_INIT), &gEfiIdeControllerInitProtocolGuid, NULL},
2257 {STRING_TOKEN(STR_DISK_INFO), &gEfiDiskInfoProtocolGuid, NULL},
2258
2259 //
2260 // PI Spec 1.0
2261 //
2262 {STRING_TOKEN(STR_BDS_ARCH), &gEfiBdsArchProtocolGuid, NULL},
2263 {STRING_TOKEN(STR_CPU_ARCH), &gEfiCpuArchProtocolGuid, NULL},
2264 {STRING_TOKEN(STR_MET_ARCH), &gEfiMetronomeArchProtocolGuid, NULL},
2265 {STRING_TOKEN(STR_MON_ARCH), &gEfiMonotonicCounterArchProtocolGuid, NULL},
2266 {STRING_TOKEN(STR_RTC_ARCH), &gEfiRealTimeClockArchProtocolGuid, NULL},
2267 {STRING_TOKEN(STR_RESET_ARCH), &gEfiResetArchProtocolGuid, NULL},
2268 {STRING_TOKEN(STR_RT_ARCH), &gEfiRuntimeArchProtocolGuid, NULL},
2269 {STRING_TOKEN(STR_SEC_ARCH), &gEfiSecurityArchProtocolGuid, NULL},
2270 {STRING_TOKEN(STR_TIMER_ARCH), &gEfiTimerArchProtocolGuid, NULL},
2271 {STRING_TOKEN(STR_VAR_ARCH), &gEfiVariableWriteArchProtocolGuid, NULL},
2272 {STRING_TOKEN(STR_V_ARCH), &gEfiVariableArchProtocolGuid, NULL},
2273 {STRING_TOKEN(STR_SECP), &gEfiSecurityPolicyProtocolGuid, NULL},
2274 {STRING_TOKEN(STR_WDT_ARCH), &gEfiWatchdogTimerArchProtocolGuid, NULL},
2275 {STRING_TOKEN(STR_SCR), &gEfiStatusCodeRuntimeProtocolGuid, NULL},
2276 {STRING_TOKEN(STR_SMB_HC), &gEfiSmbusHcProtocolGuid, NULL},
2277 {STRING_TOKEN(STR_FV_2), &gEfiFirmwareVolume2ProtocolGuid, NULL},
2278 {STRING_TOKEN(STR_FV_BLOCK), &gEfiFirmwareVolumeBlockProtocolGuid, NULL},
2279 {STRING_TOKEN(STR_CAP_ARCH), &gEfiCapsuleArchProtocolGuid, NULL},
2280 {STRING_TOKEN(STR_MP_SERVICE), &gEfiMpServiceProtocolGuid, NULL},
2281 {STRING_TOKEN(STR_HBRAP), &gEfiPciHostBridgeResourceAllocationProtocolGuid, NULL},
2282 {STRING_TOKEN(STR_PCIP), &gEfiPciPlatformProtocolGuid, NULL},
2283 {STRING_TOKEN(STR_PCIO), &gEfiPciOverrideProtocolGuid, NULL},
2284 {STRING_TOKEN(STR_PCIE), &gEfiPciEnumerationCompleteProtocolGuid, NULL},
2285 {STRING_TOKEN(STR_IPCID), &gEfiIncompatiblePciDeviceSupportProtocolGuid, NULL},
2286 {STRING_TOKEN(STR_PCIHPI), &gEfiPciHotPlugInitProtocolGuid, NULL},
2287 {STRING_TOKEN(STR_PCIHPR), &gEfiPciHotPlugRequestProtocolGuid, NULL},
2288 {STRING_TOKEN(STR_SMBIOS), &gEfiSmbiosProtocolGuid, NULL},
2289 {STRING_TOKEN(STR_S3_SAVE), &gEfiS3SaveStateProtocolGuid, NULL},
2290 {STRING_TOKEN(STR_S3_S_SMM), &gEfiS3SmmSaveStateProtocolGuid, NULL},
2291 {STRING_TOKEN(STR_RSC), &gEfiRscHandlerProtocolGuid, NULL},
2292 {STRING_TOKEN(STR_S_RSC), &gEfiSmmRscHandlerProtocolGuid, NULL},
2293 {STRING_TOKEN(STR_ACPI_SDT), &gEfiAcpiSdtProtocolGuid, NULL},
2294 {STRING_TOKEN(STR_SIO), &gEfiSioProtocolGuid, NULL},
2295 {STRING_TOKEN(STR_S_CPU2), &gEfiSmmCpuIo2ProtocolGuid, NULL},
2296 {STRING_TOKEN(STR_S_BASE2), &gEfiSmmBase2ProtocolGuid, NULL},
2297 {STRING_TOKEN(STR_S_ACC_2), &gEfiSmmAccess2ProtocolGuid, NULL},
2298 {STRING_TOKEN(STR_S_CON_2), &gEfiSmmControl2ProtocolGuid, NULL},
2299 {STRING_TOKEN(STR_S_CONFIG), &gEfiSmmConfigurationProtocolGuid, NULL},
2300 {STRING_TOKEN(STR_S_RTL), &gEfiSmmReadyToLockProtocolGuid, NULL},
2301 {STRING_TOKEN(STR_DS_RTL), &gEfiDxeSmmReadyToLockProtocolGuid, NULL},
2302 {STRING_TOKEN(STR_S_COMM), &gEfiSmmCommunicationProtocolGuid, NULL},
2303 {STRING_TOKEN(STR_S_STAT), &gEfiSmmStatusCodeProtocolGuid, NULL},
2304 {STRING_TOKEN(STR_S_CPU), &gEfiSmmCpuProtocolGuid, NULL},
2305 {STRING_TOKEN(STR_S_PCIRBIO), &gEfiSmmPciRootBridgeIoProtocolGuid, NULL},
2306 {STRING_TOKEN(STR_S_SWD), &gEfiSmmSwDispatch2ProtocolGuid, NULL},
2307 {STRING_TOKEN(STR_S_SXD), &gEfiSmmSxDispatch2ProtocolGuid, NULL},
2308 {STRING_TOKEN(STR_S_PTD2), &gEfiSmmPeriodicTimerDispatch2ProtocolGuid, NULL},
2309 {STRING_TOKEN(STR_S_UD2), &gEfiSmmUsbDispatch2ProtocolGuid, NULL},
2310 {STRING_TOKEN(STR_S_GD2), &gEfiSmmGpiDispatch2ProtocolGuid, NULL},
2311 {STRING_TOKEN(STR_S_SBD2), &gEfiSmmStandbyButtonDispatch2ProtocolGuid, NULL},
2312 {STRING_TOKEN(STR_S_PBD2), &gEfiSmmPowerButtonDispatch2ProtocolGuid, NULL},
2313 {STRING_TOKEN(STR_S_ITD2), &gEfiSmmIoTrapDispatch2ProtocolGuid, NULL},
2314 {STRING_TOKEN(STR_PCD), &gEfiPcdProtocolGuid, NULL},
2315 {STRING_TOKEN(STR_FVB2), &gEfiFirmwareVolumeBlock2ProtocolGuid, NULL},
2316 {STRING_TOKEN(STR_CPUIO2), &gEfiCpuIo2ProtocolGuid, NULL},
2317 {STRING_TOKEN(STR_LEGACY_R2), &gEfiLegacyRegion2ProtocolGuid, NULL},
2318 {STRING_TOKEN(STR_S2ARCH), &gEfiSecurity2ArchProtocolGuid, NULL},
2319 {STRING_TOKEN(STR_EODXE), &gEfiSmmEndOfDxeProtocolGuid, NULL},
2320 {STRING_TOKEN(STR_ISAHC), &gEfiIsaHcProtocolGuid, NULL},
2321 {STRING_TOKEN(STR_ISAHC_B), &gEfiIsaHcServiceBindingProtocolGuid, NULL},
2322 {STRING_TOKEN(STR_SIO_C), &gEfiSioControlProtocolGuid, NULL},
2323 {STRING_TOKEN(STR_GET_PCD), &gEfiGetPcdInfoProtocolGuid, NULL},
2324 {STRING_TOKEN(STR_I2C_M), &gEfiI2cMasterProtocolGuid, NULL},
2325 {STRING_TOKEN(STR_I2CIO), &gEfiI2cIoProtocolGuid, NULL},
2326 {STRING_TOKEN(STR_I2CEN), &gEfiI2cEnumerateProtocolGuid, NULL},
2327 {STRING_TOKEN(STR_I2C_H), &gEfiI2cHostProtocolGuid, NULL},
2328 {STRING_TOKEN(STR_I2C_BCM), &gEfiI2cBusConfigurationManagementProtocolGuid, NULL},
2329 {STRING_TOKEN(STR_TCG2), &gEfiTcg2ProtocolGuid, NULL},
2330 {STRING_TOKEN(STR_TIMESTAMP), &gEfiTimestampProtocolGuid, NULL},
2331 {STRING_TOKEN(STR_RNG), &gEfiRngProtocolGuid, NULL},
2332 {STRING_TOKEN(STR_NVMEPT), &gEfiNvmExpressPassThruProtocolGuid, NULL},
2333 {STRING_TOKEN(STR_H2_SB), &gEfiHash2ServiceBindingProtocolGuid, NULL},
2334 {STRING_TOKEN(STR_HASH2), &gEfiHash2ProtocolGuid, NULL},
2335 {STRING_TOKEN(STR_BIO_C), &gEfiBlockIoCryptoProtocolGuid, NULL},
2336 {STRING_TOKEN(STR_SCR), &gEfiSmartCardReaderProtocolGuid, NULL},
2337 {STRING_TOKEN(STR_SCE), &gEfiSmartCardEdgeProtocolGuid, NULL},
2338 {STRING_TOKEN(STR_USB_FIO), &gEfiUsbFunctionIoProtocolGuid, NULL},
2339 {STRING_TOKEN(STR_BC_HC), &gEfiBluetoothHcProtocolGuid, NULL},
2340 {STRING_TOKEN(STR_BC_IO_SB), &gEfiBluetoothIoServiceBindingProtocolGuid, NULL},
2341 {STRING_TOKEN(STR_BC_IO), &gEfiBluetoothIoProtocolGuid, NULL},
2342 {STRING_TOKEN(STR_BC_C), &gEfiBluetoothConfigProtocolGuid, NULL},
2343 {STRING_TOKEN(STR_REG_EXP), &gEfiRegularExpressionProtocolGuid, NULL},
2344 {STRING_TOKEN(STR_B_MGR_P), &gEfiBootManagerPolicyProtocolGuid, NULL},
2345 {STRING_TOKEN(STR_CKH), &gEfiConfigKeywordHandlerProtocolGuid, NULL},
2346 {STRING_TOKEN(STR_WIFI), &gEfiWiFiProtocolGuid, NULL},
2347 {STRING_TOKEN(STR_EAP_M), &gEfiEapManagement2ProtocolGuid, NULL},
2348 {STRING_TOKEN(STR_EAP_C), &gEfiEapConfigurationProtocolGuid, NULL},
2349 {STRING_TOKEN(STR_PKCS7), &gEfiPkcs7VerifyProtocolGuid, NULL},
2350 {STRING_TOKEN(STR_NET_DNS4_SB), &gEfiDns4ServiceBindingProtocolGuid, NULL},
2351 {STRING_TOKEN(STR_NET_DNS4), &gEfiDns4ProtocolGuid, NULL},
2352 {STRING_TOKEN(STR_NET_DNS6_SB), &gEfiDns6ServiceBindingProtocolGuid, NULL},
2353 {STRING_TOKEN(STR_NET_DNS6), &gEfiDns6ProtocolGuid, NULL},
2354 {STRING_TOKEN(STR_NET_HTTP_SB), &gEfiHttpServiceBindingProtocolGuid, NULL},
2355 {STRING_TOKEN(STR_NET_HTTP), &gEfiHttpProtocolGuid, NULL},
2356 {STRING_TOKEN(STR_NET_HTTP_U), &gEfiHttpUtilitiesProtocolGuid, NULL},
2357 {STRING_TOKEN(STR_REST), &gEfiRestProtocolGuid, NULL},
2358
2359 //
2360 // PI 1.5
2361 //
2362 {STRING_TOKEN(STR_MM_EOD), &gEfiMmEndOfDxeProtocolGuid, NULL},
2363 {STRING_TOKEN(STR_MM_ITD), &gEfiMmIoTrapDispatchProtocolGuid, NULL},
2364 {STRING_TOKEN(STR_MM_PBD), &gEfiMmPowerButtonDispatchProtocolGuid, NULL},
2365 {STRING_TOKEN(STR_MM_SBD), &gEfiMmStandbyButtonDispatchProtocolGuid, NULL},
2366 {STRING_TOKEN(STR_MM_GD), &gEfiMmGpiDispatchProtocolGuid, NULL},
2367 {STRING_TOKEN(STR_MM_UD), &gEfiMmUsbDispatchProtocolGuid, NULL},
2368 {STRING_TOKEN(STR_MM_PTD), &gEfiMmPeriodicTimerDispatchProtocolGuid, NULL},
2369 {STRING_TOKEN(STR_MM_SXD), &gEfiMmSxDispatchProtocolGuid, NULL},
2370 {STRING_TOKEN(STR_MM_SWD), &gEfiMmSwDispatchProtocolGuid, NULL},
2371 {STRING_TOKEN(STR_MM_PRBI), &gEfiMmPciRootBridgeIoProtocolGuid, NULL},
2372 {STRING_TOKEN(STR_MM_CPU), &gEfiMmCpuProtocolGuid, NULL},
2373 {STRING_TOKEN(STR_MM_STACODE), &gEfiMmStatusCodeProtocolGuid, NULL},
2374 {STRING_TOKEN(STR_DXEMM_RTL), &gEfiDxeMmReadyToLockProtocolGuid, NULL},
2375 {STRING_TOKEN(STR_MM_CONFIG), &gEfiMmConfigurationProtocolGuid, NULL},
2376 {STRING_TOKEN(STR_MM_RTL), &gEfiMmReadyToLockProtocolGuid, NULL},
2377 {STRING_TOKEN(STR_MM_CONTROL), &gEfiMmControlProtocolGuid, NULL},
2378 {STRING_TOKEN(STR_MM_ACCESS), &gEfiMmAccessProtocolGuid, NULL},
2379 {STRING_TOKEN(STR_MM_BASE), &gEfiMmBaseProtocolGuid, NULL},
2380 {STRING_TOKEN(STR_MM_CPUIO), &gEfiMmCpuIoProtocolGuid, NULL},
2381 {STRING_TOKEN(STR_MM_RH), &gEfiMmRscHandlerProtocolGuid, NULL},
2382 {STRING_TOKEN(STR_MM_COM), &gEfiMmCommunicationProtocolGuid, NULL},
2383
2384 //
2385 // UEFI Shell Spec 2.0
2386 //
2387 {STRING_TOKEN(STR_SHELL_PARAMETERS), &gEfiShellParametersProtocolGuid, NULL},
2388 {STRING_TOKEN(STR_SHELL), &gEfiShellProtocolGuid, NULL},
2389
2390 //
2391 // UEFI Shell Spec 2.1
2392 //
2393 {STRING_TOKEN(STR_SHELL_DYNAMIC), &gEfiShellDynamicCommandProtocolGuid, NULL},
2394
2395 //
2396 // Misc
2397 //
2398 {STRING_TOKEN(STR_PCDINFOPROT), &gGetPcdInfoProtocolGuid, NULL},
2399
2400 //
2401 // terminator
2402 //
2403 {0, NULL, NULL},
2404 };
2405
2406 /**
2407 Function to get the node for a protocol or struct from it's GUID.
2408
2409 if Guid is NULL, then ASSERT.
2410
2411 @param[in] Guid The GUID to look for the name of.
2412
2413 @return The node.
2414 **/
2415 CONST GUID_INFO_BLOCK *
2416 InternalShellGetNodeFromGuid(
2417 IN CONST EFI_GUID* Guid
2418 )
2419 {
2420 CONST GUID_INFO_BLOCK *ListWalker;
2421 UINTN LoopCount;
2422
2423 ASSERT(Guid != NULL);
2424
2425 for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) {
2426 if (CompareGuid(ListWalker->GuidId, Guid)) {
2427 return (ListWalker);
2428 }
2429 }
2430
2431 if (PcdGetBool(PcdShellIncludeNtGuids)) {
2432 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2433 if (CompareGuid(ListWalker->GuidId, Guid)) {
2434 return (ListWalker);
2435 }
2436 }
2437 }
2438 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2439 if (CompareGuid(ListWalker->GuidId, Guid)) {
2440 return (ListWalker);
2441 }
2442 }
2443 return (NULL);
2444 }
2445
2446 /**
2447 Function to add a new GUID/Name mapping.
2448
2449 @param[in] Guid The Guid
2450 @param[in] NameID The STRING id of the HII string to use
2451 @param[in] DumpFunc The pointer to the dump function
2452
2453
2454 @retval EFI_SUCCESS The operation was sucessful
2455 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
2456 @retval EFI_INVALID_PARAMETER Guid NameId was invalid
2457 **/
2458 EFI_STATUS
2459 InsertNewGuidNameMapping(
2460 IN CONST EFI_GUID *Guid,
2461 IN CONST EFI_STRING_ID NameID,
2462 IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
2463 )
2464 {
2465 ASSERT(Guid != NULL);
2466 ASSERT(NameID != 0);
2467
2468 mGuidList = ReallocatePool(mGuidListCount * sizeof(GUID_INFO_BLOCK), mGuidListCount+1 * sizeof(GUID_INFO_BLOCK), mGuidList);
2469 if (mGuidList == NULL) {
2470 mGuidListCount = 0;
2471 return (EFI_OUT_OF_RESOURCES);
2472 }
2473 mGuidListCount++;
2474
2475 mGuidList[mGuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid);
2476 mGuidList[mGuidListCount - 1].StringId = NameID;
2477 mGuidList[mGuidListCount - 1].DumpInfo = DumpFunc;
2478
2479 if (mGuidList[mGuidListCount - 1].GuidId == NULL) {
2480 return (EFI_OUT_OF_RESOURCES);
2481 }
2482
2483 return (EFI_SUCCESS);
2484 }
2485
2486 /**
2487 Function to add a new GUID/Name mapping.
2488
2489 This cannot overwrite an existing mapping.
2490
2491 @param[in] Guid The Guid
2492 @param[in] TheName The Guid's name
2493 @param[in] Lang RFC4646 language code list or NULL
2494
2495 @retval EFI_SUCCESS The operation was sucessful
2496 @retval EFI_ACCESS_DENIED There was a duplicate
2497 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
2498 @retval EFI_INVALID_PARAMETER Guid or TheName was NULL
2499 **/
2500 EFI_STATUS
2501 EFIAPI
2502 AddNewGuidNameMapping(
2503 IN CONST EFI_GUID *Guid,
2504 IN CONST CHAR16 *TheName,
2505 IN CONST CHAR8 *Lang OPTIONAL
2506 )
2507 {
2508 EFI_STRING_ID NameID;
2509
2510 HandleParsingHiiInit();
2511
2512 if (Guid == NULL || TheName == NULL){
2513 return (EFI_INVALID_PARAMETER);
2514 }
2515
2516 if ((InternalShellGetNodeFromGuid(Guid)) != NULL) {
2517 return (EFI_ACCESS_DENIED);
2518 }
2519
2520 NameID = HiiSetString(mHandleParsingHiiHandle, 0, (CHAR16*)TheName, Lang);
2521 if (NameID == 0) {
2522 return (EFI_OUT_OF_RESOURCES);
2523 }
2524
2525 return (InsertNewGuidNameMapping(Guid, NameID, NULL));
2526 }
2527
2528 /**
2529 Function to get the name of a protocol or struct from it's GUID.
2530
2531 if Guid is NULL, then ASSERT.
2532
2533 @param[in] Guid The GUID to look for the name of.
2534 @param[in] Lang The language to use.
2535
2536 @return pointer to string of the name. The caller
2537 is responsible to free this memory.
2538 **/
2539 CHAR16*
2540 EFIAPI
2541 GetStringNameFromGuid(
2542 IN CONST EFI_GUID *Guid,
2543 IN CONST CHAR8 *Lang OPTIONAL
2544 )
2545 {
2546 CONST GUID_INFO_BLOCK *Id;
2547
2548 HandleParsingHiiInit();
2549
2550 Id = InternalShellGetNodeFromGuid(Guid);
2551 if (Id == NULL) {
2552 return NULL;
2553 }
2554 return HiiGetString (mHandleParsingHiiHandle, Id->StringId, Lang);
2555 }
2556
2557 /**
2558 Function to dump protocol information from a handle.
2559
2560 This function will return a allocated string buffer containing the
2561 information. The caller is responsible for freeing the memory.
2562
2563 If Guid is NULL, ASSERT().
2564 If TheHandle is NULL, ASSERT().
2565
2566 @param[in] TheHandle The handle to dump information from.
2567 @param[in] Guid The GUID of the protocol to dump.
2568 @param[in] Verbose TRUE for extra info. FALSE otherwise.
2569
2570 @return The pointer to string.
2571 @retval NULL An error was encountered.
2572 **/
2573 CHAR16*
2574 EFIAPI
2575 GetProtocolInformationDump(
2576 IN CONST EFI_HANDLE TheHandle,
2577 IN CONST EFI_GUID *Guid,
2578 IN CONST BOOLEAN Verbose
2579 )
2580 {
2581 CONST GUID_INFO_BLOCK *Id;
2582
2583 ASSERT(TheHandle != NULL);
2584 ASSERT(Guid != NULL);
2585
2586 if (TheHandle == NULL || Guid == NULL) {
2587 return (NULL);
2588 }
2589
2590 Id = InternalShellGetNodeFromGuid(Guid);
2591 if (Id != NULL && Id->DumpInfo != NULL) {
2592 return (Id->DumpInfo(TheHandle, Verbose));
2593 }
2594 return (NULL);
2595 }
2596
2597 /**
2598 Function to get the Guid for a protocol or struct based on it's string name.
2599
2600 do not modify the returned Guid.
2601
2602 @param[in] Name The pointer to the string name.
2603 @param[in] Lang The pointer to the language code.
2604 @param[out] Guid The pointer to the Guid.
2605
2606 @retval EFI_SUCCESS The operation was sucessful.
2607 **/
2608 EFI_STATUS
2609 EFIAPI
2610 GetGuidFromStringName(
2611 IN CONST CHAR16 *Name,
2612 IN CONST CHAR8 *Lang OPTIONAL,
2613 OUT EFI_GUID **Guid
2614 )
2615 {
2616 CONST GUID_INFO_BLOCK *ListWalker;
2617 CHAR16 *String;
2618 UINTN LoopCount;
2619
2620 HandleParsingHiiInit();
2621
2622 ASSERT(Guid != NULL);
2623 if (Guid == NULL) {
2624 return (EFI_INVALID_PARAMETER);
2625 }
2626 *Guid = NULL;
2627
2628 if (PcdGetBool(PcdShellIncludeNtGuids)) {
2629 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2630 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2631 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2632 *Guid = ListWalker->GuidId;
2633 }
2634 SHELL_FREE_NON_NULL(String);
2635 if (*Guid != NULL) {
2636 return (EFI_SUCCESS);
2637 }
2638 }
2639 }
2640 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2641 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2642 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2643 *Guid = ListWalker->GuidId;
2644 }
2645 SHELL_FREE_NON_NULL(String);
2646 if (*Guid != NULL) {
2647 return (EFI_SUCCESS);
2648 }
2649 }
2650
2651 for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) {
2652 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2653 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2654 *Guid = ListWalker->GuidId;
2655 }
2656 SHELL_FREE_NON_NULL(String);
2657 if (*Guid != NULL) {
2658 return (EFI_SUCCESS);
2659 }
2660 }
2661
2662 return (EFI_NOT_FOUND);
2663 }
2664
2665 /**
2666 Get best support language for this driver.
2667
2668 First base on the user input language to search, second base on the current
2669 platform used language to search, third get the first language from the
2670 support language list. The caller need to free the buffer of the best language.
2671
2672 @param[in] SupportedLanguages The support languages for this driver.
2673 @param[in] InputLanguage The user input language.
2674 @param[in] Iso639Language Whether get language for ISO639.
2675
2676 @return The best support language for this driver.
2677 **/
2678 CHAR8 *
2679 EFIAPI
2680 GetBestLanguageForDriver (
2681 IN CONST CHAR8 *SupportedLanguages,
2682 IN CONST CHAR8 *InputLanguage,
2683 IN BOOLEAN Iso639Language
2684 )
2685 {
2686 CHAR8 *LanguageVariable;
2687 CHAR8 *BestLanguage;
2688
2689 GetVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid, (VOID**)&LanguageVariable, NULL);
2690
2691 BestLanguage = GetBestLanguage(
2692 SupportedLanguages,
2693 Iso639Language,
2694 (InputLanguage != NULL) ? InputLanguage : "",
2695 (LanguageVariable != NULL) ? LanguageVariable : "",
2696 SupportedLanguages,
2697 NULL
2698 );
2699
2700 if (LanguageVariable != NULL) {
2701 FreePool (LanguageVariable);
2702 }
2703
2704 return BestLanguage;
2705 }
2706
2707 /**
2708 Function to retrieve the driver name (if possible) from the ComponentName or
2709 ComponentName2 protocol
2710
2711 @param[in] TheHandle The driver handle to get the name of.
2712 @param[in] Language The language to use.
2713
2714 @retval NULL The name could not be found.
2715 @return A pointer to the string name. Do not de-allocate the memory.
2716 **/
2717 CONST CHAR16*
2718 EFIAPI
2719 GetStringNameFromHandle(
2720 IN CONST EFI_HANDLE TheHandle,
2721 IN CONST CHAR8 *Language
2722 )
2723 {
2724 EFI_COMPONENT_NAME2_PROTOCOL *CompNameStruct;
2725 EFI_STATUS Status;
2726 CHAR16 *RetVal;
2727 CHAR8 *BestLang;
2728
2729 BestLang = NULL;
2730
2731 Status = gBS->OpenProtocol(
2732 TheHandle,
2733 &gEfiComponentName2ProtocolGuid,
2734 (VOID**)&CompNameStruct,
2735 gImageHandle,
2736 NULL,
2737 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2738 if (!EFI_ERROR(Status)) {
2739 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
2740 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
2741 if (BestLang != NULL) {
2742 FreePool (BestLang);
2743 BestLang = NULL;
2744 }
2745 if (!EFI_ERROR(Status)) {
2746 return (RetVal);
2747 }
2748 }
2749 Status = gBS->OpenProtocol(
2750 TheHandle,
2751 &gEfiComponentNameProtocolGuid,
2752 (VOID**)&CompNameStruct,
2753 gImageHandle,
2754 NULL,
2755 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2756 if (!EFI_ERROR(Status)) {
2757 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
2758 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
2759 if (BestLang != NULL) {
2760 FreePool (BestLang);
2761 }
2762 if (!EFI_ERROR(Status)) {
2763 return (RetVal);
2764 }
2765 }
2766 return (NULL);
2767 }
2768
2769 /**
2770 Function to initialize the file global mHandleList object for use in
2771 vonverting handles to index and index to handle.
2772
2773 @retval EFI_SUCCESS The operation was successful.
2774 **/
2775 EFI_STATUS
2776 InternalShellInitHandleList(
2777 VOID
2778 )
2779 {
2780 EFI_STATUS Status;
2781 EFI_HANDLE *HandleBuffer;
2782 UINTN HandleCount;
2783 HANDLE_LIST *ListWalker;
2784
2785 if (mHandleList.NextIndex != 0) {
2786 return EFI_SUCCESS;
2787 }
2788 InitializeListHead(&mHandleList.List.Link);
2789 mHandleList.NextIndex = 1;
2790 Status = gBS->LocateHandleBuffer (
2791 AllHandles,
2792 NULL,
2793 NULL,
2794 &HandleCount,
2795 &HandleBuffer
2796 );
2797 ASSERT_EFI_ERROR(Status);
2798 if (EFI_ERROR(Status)) {
2799 return (Status);
2800 }
2801 for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){
2802 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
2803 if (ListWalker != NULL) {
2804 ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex - 1];
2805 ListWalker->TheIndex = mHandleList.NextIndex;
2806 InsertTailList (&mHandleList.List.Link, &ListWalker->Link);
2807 }
2808 }
2809 FreePool(HandleBuffer);
2810 return (EFI_SUCCESS);
2811 }
2812
2813 /**
2814 Function to retrieve the human-friendly index of a given handle. If the handle
2815 does not have a index one will be automatically assigned. The index value is valid
2816 until the termination of the shell application.
2817
2818 @param[in] TheHandle The handle to retrieve an index for.
2819
2820 @retval 0 A memory allocation failed.
2821 @return The index of the handle.
2822
2823 **/
2824 UINTN
2825 EFIAPI
2826 ConvertHandleToHandleIndex(
2827 IN CONST EFI_HANDLE TheHandle
2828 )
2829 {
2830 EFI_STATUS Status;
2831 EFI_GUID **ProtocolBuffer;
2832 UINTN ProtocolCount;
2833 HANDLE_LIST *ListWalker;
2834
2835 if (TheHandle == NULL) {
2836 return 0;
2837 }
2838
2839 InternalShellInitHandleList();
2840
2841 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
2842 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
2843 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
2844 ){
2845 if (ListWalker->TheHandle == TheHandle) {
2846 //
2847 // Verify that TheHandle is still present in the Handle Database
2848 //
2849 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
2850 if (EFI_ERROR (Status)) {
2851 //
2852 // TheHandle is not present in the Handle Database, so delete from the handle list
2853 //
2854 RemoveEntryList (&ListWalker->Link);
2855 return 0;
2856 }
2857 FreePool (ProtocolBuffer);
2858 return (ListWalker->TheIndex);
2859 }
2860 }
2861
2862 //
2863 // Verify that TheHandle is valid handle
2864 //
2865 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
2866 if (EFI_ERROR (Status)) {
2867 //
2868 // TheHandle is not valid, so do not add to handle list
2869 //
2870 return 0;
2871 }
2872 FreePool (ProtocolBuffer);
2873
2874 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
2875 if (ListWalker == NULL) {
2876 return 0;
2877 }
2878 ListWalker->TheHandle = TheHandle;
2879 ListWalker->TheIndex = mHandleList.NextIndex++;
2880 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);
2881 return (ListWalker->TheIndex);
2882 }
2883
2884
2885
2886 /**
2887 Function to retrieve the EFI_HANDLE from the human-friendly index.
2888
2889 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
2890
2891 @retval NULL The index was invalid.
2892 @return The EFI_HANDLE that index represents.
2893
2894 **/
2895 EFI_HANDLE
2896 EFIAPI
2897 ConvertHandleIndexToHandle(
2898 IN CONST UINTN TheIndex
2899 )
2900 {
2901 EFI_STATUS Status;
2902 EFI_GUID **ProtocolBuffer;
2903 UINTN ProtocolCount;
2904 HANDLE_LIST *ListWalker;
2905
2906 InternalShellInitHandleList();
2907
2908 if (TheIndex >= mHandleList.NextIndex) {
2909 return NULL;
2910 }
2911
2912 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
2913 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
2914 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
2915 ){
2916 if (ListWalker->TheIndex == TheIndex && ListWalker->TheHandle != NULL) {
2917 //
2918 // Verify that LinkWalker->TheHandle is valid handle
2919 //
2920 Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);
2921 if (!EFI_ERROR (Status)) {
2922 FreePool (ProtocolBuffer);
2923 } else {
2924 //
2925 // TheHandle is not valid, so do not add to handle list
2926 //
2927 ListWalker->TheHandle = NULL;
2928 }
2929 return (ListWalker->TheHandle);
2930 }
2931 }
2932 return NULL;
2933 }
2934
2935 /**
2936 Gets all the related EFI_HANDLEs based on the mask supplied.
2937
2938 This function scans all EFI_HANDLES in the UEFI environment's handle database
2939 and returns the ones with the specified relationship (Mask) to the specified
2940 controller handle.
2941
2942 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
2943 If MatchingHandleCount is NULL, then ASSERT.
2944
2945 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
2946 caller freed.
2947
2948 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
2949 @param[in] ControllerHandle The handle with Device Path protocol on it.
2950 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
2951 MatchingHandleBuffer.
2952 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
2953 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
2954 @param[out] HandleType An array of type information.
2955
2956 @retval EFI_SUCCESS The operation was successful, and any related handles
2957 are in MatchingHandleBuffer.
2958 @retval EFI_NOT_FOUND No matching handles were found.
2959 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
2960 **/
2961 EFI_STATUS
2962 EFIAPI
2963 ParseHandleDatabaseByRelationshipWithType (
2964 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
2965 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
2966 IN UINTN *HandleCount,
2967 OUT EFI_HANDLE **HandleBuffer,
2968 OUT UINTN **HandleType
2969 )
2970 {
2971 EFI_STATUS Status;
2972 UINTN HandleIndex;
2973 EFI_GUID **ProtocolGuidArray;
2974 UINTN ArrayCount;
2975 UINTN ProtocolIndex;
2976 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
2977 UINTN OpenInfoCount;
2978 UINTN OpenInfoIndex;
2979 UINTN ChildIndex;
2980 INTN DriverBindingHandleIndex;
2981
2982 ASSERT(HandleCount != NULL);
2983 ASSERT(HandleBuffer != NULL);
2984 ASSERT(HandleType != NULL);
2985 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
2986
2987 *HandleCount = 0;
2988 *HandleBuffer = NULL;
2989 *HandleType = NULL;
2990
2991 //
2992 // Retrieve the list of all handles from the handle database
2993 //
2994 Status = gBS->LocateHandleBuffer (
2995 AllHandles,
2996 NULL,
2997 NULL,
2998 HandleCount,
2999 HandleBuffer
3000 );
3001 if (EFI_ERROR (Status)) {
3002 return (Status);
3003 }
3004
3005 *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));
3006 if (*HandleType == NULL) {
3007 SHELL_FREE_NON_NULL (*HandleBuffer);
3008 *HandleCount = 0;
3009 return EFI_OUT_OF_RESOURCES;
3010 }
3011
3012 DriverBindingHandleIndex = -1;
3013 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
3014 if (DriverBindingHandle != NULL && (*HandleBuffer)[HandleIndex] == DriverBindingHandle) {
3015 DriverBindingHandleIndex = (INTN)HandleIndex;
3016 }
3017 }
3018
3019 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
3020 //
3021 // Retrieve the list of all the protocols on each handle
3022 //
3023 Status = gBS->ProtocolsPerHandle (
3024 (*HandleBuffer)[HandleIndex],
3025 &ProtocolGuidArray,
3026 &ArrayCount
3027 );
3028 if (EFI_ERROR (Status)) {
3029 continue;
3030 }
3031
3032 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
3033
3034 //
3035 // Set the bit describing what this handle has
3036 //
3037 if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) ) {
3038 (*HandleType)[HandleIndex] |= (UINTN)HR_IMAGE_HANDLE;
3039 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) ) {
3040 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_BINDING_HANDLE;
3041 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {
3042 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
3043 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {
3044 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
3045 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) ) {
3046 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
3047 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) ) {
3048 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
3049 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) ) {
3050 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
3051 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) ) {
3052 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
3053 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) {
3054 (*HandleType)[HandleIndex] |= (UINTN)HR_DEVICE_HANDLE;
3055 }
3056 //
3057 // Retrieve the list of agents that have opened each protocol
3058 //
3059 Status = gBS->OpenProtocolInformation (
3060 (*HandleBuffer)[HandleIndex],
3061 ProtocolGuidArray[ProtocolIndex],
3062 &OpenInfo,
3063 &OpenInfoCount
3064 );
3065 if (EFI_ERROR (Status)) {
3066 continue;
3067 }
3068
3069 if (ControllerHandle == NULL) {
3070 //
3071 // ControllerHandle == NULL and DriverBindingHandle != NULL.
3072 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
3073 //
3074 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
3075 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
3076 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
3077 if (DriverBindingHandleIndex != -1) {
3078 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
3079 }
3080 }
3081 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
3082 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
3083 if (DriverBindingHandleIndex != -1) {
3084 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
3085 }
3086 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
3087 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
3088 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
3089 }
3090 }
3091 }
3092 }
3093 }
3094 if (DriverBindingHandle == NULL && ControllerHandle != NULL) {
3095 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
3096 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
3097 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
3098 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
3099 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
3100 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
3101 (*HandleType)[ChildIndex] |= (UINTN)HR_DEVICE_DRIVER;
3102 }
3103 }
3104 }
3105 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
3106 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
3107 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
3108 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
3109 }
3110 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
3111 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
3112 }
3113 }
3114 }
3115 }
3116 } else {
3117 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
3118 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
3119 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
3120 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
3121 }
3122 }
3123 }
3124 }
3125 }
3126 if (DriverBindingHandle != NULL && ControllerHandle != NULL) {
3127 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
3128 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
3129 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
3130 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
3131 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
3132 if (DriverBindingHandleIndex != -1) {
3133 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
3134 }
3135 }
3136 }
3137 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
3138 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
3139 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
3140 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
3141 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
3142 }
3143 }
3144 }
3145
3146 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
3147 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
3148 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
3149 }
3150 }
3151 }
3152 }
3153 } else {
3154 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
3155 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
3156 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
3157 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
3158 }
3159 }
3160 }
3161 }
3162 }
3163 FreePool (OpenInfo);
3164 }
3165 FreePool (ProtocolGuidArray);
3166 }
3167 return EFI_SUCCESS;
3168 }
3169
3170 /**
3171 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
3172 supplied.
3173
3174 This function will scan all EFI_HANDLES in the UEFI environment's handle database
3175 and return all the ones with the specified relationship (Mask) to the specified
3176 controller handle.
3177
3178 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
3179 If MatchingHandleCount is NULL, then ASSERT.
3180
3181 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
3182 caller freed.
3183
3184 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
3185 on it.
3186 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
3187 @param[in] Mask Mask of what relationship(s) is desired.
3188 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
3189 MatchingHandleBuffer.
3190 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
3191 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
3192
3193 @retval EFI_SUCCESS The operation was sucessful and any related handles
3194 are in MatchingHandleBuffer;
3195 @retval EFI_NOT_FOUND No matching handles were found.
3196 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
3197 **/
3198 EFI_STATUS
3199 EFIAPI
3200 ParseHandleDatabaseByRelationship (
3201 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
3202 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
3203 IN CONST UINTN Mask,
3204 IN UINTN *MatchingHandleCount,
3205 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
3206 )
3207 {
3208 EFI_STATUS Status;
3209 UINTN HandleCount;
3210 EFI_HANDLE *HandleBuffer;
3211 UINTN *HandleType;
3212 UINTN HandleIndex;
3213
3214 ASSERT(MatchingHandleCount != NULL);
3215 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
3216
3217 if ((Mask & HR_VALID_MASK) != Mask) {
3218 return (EFI_INVALID_PARAMETER);
3219 }
3220
3221 if ((Mask & HR_CHILD_HANDLE) != 0 && DriverBindingHandle == NULL) {
3222 return (EFI_INVALID_PARAMETER);
3223 }
3224
3225 *MatchingHandleCount = 0;
3226 if (MatchingHandleBuffer != NULL) {
3227 *MatchingHandleBuffer = NULL;
3228 }
3229
3230 HandleBuffer = NULL;
3231 HandleType = NULL;
3232
3233 Status = ParseHandleDatabaseByRelationshipWithType (
3234 DriverBindingHandle,
3235 ControllerHandle,
3236 &HandleCount,
3237 &HandleBuffer,
3238 &HandleType
3239 );
3240 if (!EFI_ERROR (Status)) {
3241 //
3242 // Count the number of handles that match the attributes in Mask
3243 //
3244 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
3245 if ((HandleType[HandleIndex] & Mask) == Mask) {
3246 (*MatchingHandleCount)++;
3247 }
3248 }
3249 //
3250 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
3251 //
3252 if (*MatchingHandleCount == 0) {
3253 Status = EFI_NOT_FOUND;
3254 } else {
3255
3256 if (MatchingHandleBuffer == NULL) {
3257 //
3258 // Someone just wanted the count...
3259 //
3260 Status = EFI_SUCCESS;
3261 } else {
3262 //
3263 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
3264 //
3265 *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE));
3266 if (*MatchingHandleBuffer == NULL) {
3267 Status = EFI_OUT_OF_RESOURCES;
3268 } else {
3269 for (HandleIndex = 0, *MatchingHandleCount = 0
3270 ; HandleIndex < HandleCount
3271 ; HandleIndex++
3272 ) {
3273 //
3274 // Fill the allocated buffer with the handles that matched the attributes in Mask
3275 //
3276 if ((HandleType[HandleIndex] & Mask) == Mask) {
3277 (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex];
3278 }
3279 }
3280
3281 //
3282 // Make the last one NULL
3283 //
3284 (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL;
3285
3286 Status = EFI_SUCCESS;
3287 } // *MatchingHandleBuffer == NULL (ELSE)
3288 } // MacthingHandleBuffer == NULL (ELSE)
3289 } // *MatchingHandleCount == 0 (ELSE)
3290 } // no error on ParseHandleDatabaseByRelationshipWithType
3291
3292 if (HandleBuffer != NULL) {
3293 FreePool (HandleBuffer);
3294 }
3295
3296 if (HandleType != NULL) {
3297 FreePool (HandleType);
3298 }
3299
3300 ASSERT ((MatchingHandleBuffer == NULL) ||
3301 (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
3302 (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
3303 return Status;
3304 }
3305
3306 /**
3307 Gets handles for any child controllers of the passed in controller.
3308
3309 @param[in] ControllerHandle The handle of the "parent controller"
3310 @param[out] MatchingHandleCount Pointer to the number of handles in
3311 MatchingHandleBuffer on return.
3312 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
3313 return.
3314
3315
3316 @retval EFI_SUCCESS The operation was sucessful.
3317 **/
3318 EFI_STATUS
3319 EFIAPI
3320 ParseHandleDatabaseForChildControllers(
3321 IN CONST EFI_HANDLE ControllerHandle,
3322 OUT UINTN *MatchingHandleCount,
3323 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
3324 )
3325 {
3326 EFI_STATUS Status;
3327 UINTN HandleIndex;
3328 UINTN DriverBindingHandleCount;
3329 EFI_HANDLE *DriverBindingHandleBuffer;
3330 UINTN DriverBindingHandleIndex;
3331 UINTN ChildControllerHandleCount;
3332 EFI_HANDLE *ChildControllerHandleBuffer;
3333 UINTN ChildControllerHandleIndex;
3334 EFI_HANDLE *HandleBufferForReturn;
3335
3336 if (MatchingHandleCount == NULL) {
3337 return (EFI_INVALID_PARAMETER);
3338 }
3339 *MatchingHandleCount = 0;
3340
3341 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
3342 ControllerHandle,
3343 &DriverBindingHandleCount,
3344 &DriverBindingHandleBuffer
3345 );
3346 if (EFI_ERROR (Status)) {
3347 return Status;
3348 }
3349
3350 //
3351 // Get a buffer big enough for all the controllers.
3352 //
3353 HandleBufferForReturn = GetHandleListByProtocol(NULL);
3354 if (HandleBufferForReturn == NULL) {
3355 FreePool (DriverBindingHandleBuffer);
3356 return (EFI_NOT_FOUND);
3357 }
3358
3359 for (DriverBindingHandleIndex = 0; DriverBindingHandleIndex < DriverBindingHandleCount; DriverBindingHandleIndex++) {
3360 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
3361 DriverBindingHandleBuffer[DriverBindingHandleIndex],
3362 ControllerHandle,
3363 &ChildControllerHandleCount,
3364 &ChildControllerHandleBuffer
3365 );
3366 if (EFI_ERROR (Status)) {
3367 continue;
3368 }
3369
3370 for (ChildControllerHandleIndex = 0;
3371 ChildControllerHandleIndex < ChildControllerHandleCount;
3372 ChildControllerHandleIndex++
3373 ) {
3374 for (HandleIndex = 0; HandleIndex < *MatchingHandleCount; HandleIndex++) {
3375 if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {
3376 break;
3377 }
3378 }
3379 if (HandleIndex >= *MatchingHandleCount) {
3380 HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
3381 }
3382 }
3383
3384 FreePool (ChildControllerHandleBuffer);
3385 }
3386
3387 FreePool (DriverBindingHandleBuffer);
3388
3389 if (MatchingHandleBuffer == NULL || *MatchingHandleCount == 0) {
3390 //
3391 // The caller is not interested in the actual handles, or we've found none.
3392 //
3393 FreePool (HandleBufferForReturn);
3394 HandleBufferForReturn = NULL;
3395 }
3396
3397 if (MatchingHandleBuffer != NULL) {
3398 *MatchingHandleBuffer = HandleBufferForReturn;
3399 }
3400
3401 ASSERT ((MatchingHandleBuffer == NULL) ||
3402 (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
3403 (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
3404
3405 return (EFI_SUCCESS);
3406 }
3407
3408 /**
3409 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
3410 if necessary to fit all of the data.
3411
3412 If DestinationBuffer is NULL, then ASSERT().
3413
3414 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
3415 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
3416 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
3417 @param[in] SourceSize The number of bytes of SourceBuffer to append.
3418
3419 @retval NULL A memory allocation failed.
3420 @retval NULL A parameter was invalid.
3421 @return A pointer to (*DestinationBuffer).
3422 **/
3423 VOID*
3424 BuffernCatGrow (
3425 IN OUT VOID **DestinationBuffer,
3426 IN OUT UINTN *DestinationSize,
3427 IN VOID *SourceBuffer,
3428 IN UINTN SourceSize
3429 )
3430 {
3431 UINTN LocalDestinationSize;
3432 UINTN LocalDestinationFinalSize;
3433
3434 ASSERT(DestinationBuffer != NULL);
3435
3436 if (SourceSize == 0 || SourceBuffer == NULL) {
3437 return (*DestinationBuffer);
3438 }
3439
3440 if (DestinationSize == NULL) {
3441 LocalDestinationSize = 0;
3442 } else {
3443 LocalDestinationSize = *DestinationSize;
3444 }
3445
3446 LocalDestinationFinalSize = LocalDestinationSize + SourceSize;
3447
3448 if (DestinationSize != NULL) {
3449 *DestinationSize = LocalDestinationSize;
3450 }
3451
3452 if (LocalDestinationSize == 0) {
3453 // allcoate
3454 *DestinationBuffer = AllocateZeroPool(LocalDestinationFinalSize);
3455 } else {
3456 // reallocate
3457 *DestinationBuffer = ReallocatePool(LocalDestinationSize, LocalDestinationFinalSize, *DestinationBuffer);
3458 }
3459
3460 ASSERT(*DestinationBuffer != NULL);
3461
3462 // copy
3463 return (CopyMem(((UINT8*)(*DestinationBuffer)) + LocalDestinationSize, SourceBuffer, SourceSize));
3464 }
3465
3466 /**
3467 Gets handles for any child devices produced by the passed in driver.
3468
3469 @param[in] DriverHandle The handle of the driver.
3470 @param[in] MatchingHandleCount Pointer to the number of handles in
3471 MatchingHandleBuffer on return.
3472 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
3473 return.
3474 @retval EFI_SUCCESS The operation was sucessful.
3475 @sa ParseHandleDatabaseByRelationship
3476 **/
3477 EFI_STATUS
3478 EFIAPI
3479 ParseHandleDatabaseForChildDevices(
3480 IN CONST EFI_HANDLE DriverHandle,
3481 IN UINTN *MatchingHandleCount,
3482 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
3483 )
3484 {
3485 EFI_HANDLE *Buffer;
3486 EFI_HANDLE *Buffer2;
3487 UINTN Count1;
3488 UINTN Count2;
3489 UINTN HandleIndex;
3490 EFI_STATUS Status;
3491 UINTN HandleBufferSize;
3492
3493 ASSERT(MatchingHandleCount != NULL);
3494
3495 HandleBufferSize = 0;
3496 Buffer = NULL;
3497 Buffer2 = NULL;
3498 *MatchingHandleCount = 0;
3499
3500 Status = PARSE_HANDLE_DATABASE_DEVICES (
3501 DriverHandle,
3502 &Count1,
3503 &Buffer
3504 );
3505 if (!EFI_ERROR (Status)) {
3506 for (HandleIndex = 0; HandleIndex < Count1; HandleIndex++) {
3507 //
3508 // now find the children
3509 //
3510 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
3511 DriverHandle,
3512 Buffer[HandleIndex],
3513 &Count2,
3514 &Buffer2
3515 );
3516 if (EFI_ERROR(Status)) {
3517 break;
3518 }
3519 //
3520 // save out required and optional data elements
3521 //
3522 *MatchingHandleCount += Count2;
3523 if (MatchingHandleBuffer != NULL) {
3524 *MatchingHandleBuffer = BuffernCatGrow((VOID**)MatchingHandleBuffer, &HandleBufferSize, Buffer2, Count2 * sizeof(Buffer2[0]));
3525 }
3526
3527 //
3528 // free the memory
3529 //
3530 if (Buffer2 != NULL) {
3531 FreePool(Buffer2);
3532 }
3533 }
3534 }
3535
3536 if (Buffer != NULL) {
3537 FreePool(Buffer);
3538 }
3539 return (Status);
3540 }
3541
3542 /**
3543 Function to get all handles that support a given protocol or all handles.
3544
3545 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
3546 then the function will return all handles.
3547
3548 @retval NULL A memory allocation failed.
3549 @return A NULL terminated list of handles.
3550 **/
3551 EFI_HANDLE*
3552 EFIAPI
3553 GetHandleListByProtocol (
3554 IN CONST EFI_GUID *ProtocolGuid OPTIONAL
3555 )
3556 {
3557 EFI_HANDLE *HandleList;
3558 UINTN Size;
3559 EFI_STATUS Status;
3560
3561 Size = 0;
3562 HandleList = NULL;
3563
3564 //
3565 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
3566 //
3567 if (ProtocolGuid == NULL) {
3568 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
3569 if (Status == EFI_BUFFER_TOO_SMALL) {
3570 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
3571 if (HandleList == NULL) {
3572 return (NULL);
3573 }
3574 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
3575 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
3576 }
3577 } else {
3578 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, 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(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
3585 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
3586 }
3587 }
3588 if (EFI_ERROR(Status)) {
3589 if (HandleList != NULL) {
3590 FreePool(HandleList);
3591 }
3592 return (NULL);
3593 }
3594 return (HandleList);
3595 }
3596
3597 /**
3598 Function to get all handles that support some protocols.
3599
3600 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
3601
3602 @retval NULL A memory allocation failed.
3603 @retval NULL ProtocolGuids was NULL.
3604 @return A NULL terminated list of EFI_HANDLEs.
3605 **/
3606 EFI_HANDLE*
3607 EFIAPI
3608 GetHandleListByProtocolList (
3609 IN CONST EFI_GUID **ProtocolGuids
3610 )
3611 {
3612 EFI_HANDLE *HandleList;
3613 UINTN Size;
3614 UINTN TotalSize;
3615 UINTN TempSize;
3616 EFI_STATUS Status;
3617 CONST EFI_GUID **GuidWalker;
3618 EFI_HANDLE *HandleWalker1;
3619 EFI_HANDLE *HandleWalker2;
3620
3621 Size = 0;
3622 HandleList = NULL;
3623 TotalSize = sizeof(EFI_HANDLE);
3624
3625 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++,Size = 0){
3626 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &Size, NULL);
3627 if (Status == EFI_BUFFER_TOO_SMALL) {
3628 TotalSize += Size;
3629 }
3630 }
3631
3632 //
3633 // No handles were found...
3634 //
3635 if (TotalSize == sizeof(EFI_HANDLE)) {
3636 return (NULL);
3637 }
3638
3639 HandleList = AllocateZeroPool(TotalSize);
3640 if (HandleList == NULL) {
3641 return (NULL);
3642 }
3643
3644 Size = 0;
3645 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++){
3646 TempSize = TotalSize - Size;
3647 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &TempSize, HandleList+(Size/sizeof(EFI_HANDLE)));
3648
3649 //
3650 // Allow for missing protocols... Only update the 'used' size upon success.
3651 //
3652 if (!EFI_ERROR(Status)) {
3653 Size += TempSize;
3654 }
3655 }
3656 ASSERT(HandleList[(TotalSize/sizeof(EFI_HANDLE))-1] == NULL);
3657
3658 for (HandleWalker1 = HandleList ; HandleWalker1 != NULL && *HandleWalker1 != NULL ; HandleWalker1++) {
3659 for (HandleWalker2 = HandleWalker1 + 1; HandleWalker2 != NULL && *HandleWalker2 != NULL ; HandleWalker2++) {
3660 if (*HandleWalker1 == *HandleWalker2) {
3661 //
3662 // copy memory back 1 handle width.
3663 //
3664 CopyMem(HandleWalker2, HandleWalker2 + 1, TotalSize - ((HandleWalker2-HandleList+1)*sizeof(EFI_HANDLE)));
3665 }
3666 }
3667 }
3668
3669 return (HandleList);
3670 }
3671
3672 /**
3673 Return all supported GUIDs.
3674
3675 @param[out] Guids The buffer to return all supported GUIDs.
3676 @param[in, out] Count On input, the count of GUIDs the buffer can hold,
3677 On output, the count of GUIDs to return.
3678
3679 @retval EFI_INVALID_PARAMETER Count is NULL.
3680 @retval EFI_BUFFER_TOO_SMALL Buffer is not enough to hold all GUIDs.
3681 @retval EFI_SUCCESS GUIDs are returned successfully.
3682 **/
3683 EFI_STATUS
3684 EFIAPI
3685 GetAllMappingGuids (
3686 OUT EFI_GUID *Guids,
3687 IN OUT UINTN *Count
3688 )
3689 {
3690 UINTN GuidCount;
3691 UINTN NtGuidCount;
3692 UINTN Index;
3693
3694 if (Count == NULL) {
3695 return EFI_INVALID_PARAMETER;
3696 }
3697
3698 NtGuidCount = 0;
3699 if (PcdGetBool (PcdShellIncludeNtGuids)) {
3700 NtGuidCount = ARRAY_SIZE (mGuidStringListNT) - 1;
3701 }
3702 GuidCount = ARRAY_SIZE (mGuidStringList) - 1;
3703
3704 if (*Count < NtGuidCount + GuidCount + mGuidListCount) {
3705 *Count = NtGuidCount + GuidCount + mGuidListCount;
3706 return EFI_BUFFER_TOO_SMALL;
3707 }
3708
3709 for (Index = 0; Index < NtGuidCount; Index++) {
3710 CopyGuid (&Guids[Index], mGuidStringListNT[Index].GuidId);
3711 }
3712
3713 for (Index = 0; Index < GuidCount; Index++) {
3714 CopyGuid (&Guids[NtGuidCount + Index], mGuidStringList[Index].GuidId);
3715 }
3716
3717 for (Index = 0; Index < mGuidListCount; Index++) {
3718 CopyGuid (&Guids[NtGuidCount + GuidCount + Index], mGuidList[Index].GuidId);
3719 }
3720
3721 return EFI_SUCCESS;
3722 }