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