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