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