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