]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/dh: Modify the dump of "ImageDevicePath" and "DevicePath"
[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 protocol information.
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 @param[in] Protocol The protocol is needed to dump.
858
859 @retval A pointer to a string containing the information.
860 **/
861 STATIC CHAR16*
862 EFIAPI
863 DevicePathProtocolDumpInformationEx (
864 IN CONST EFI_HANDLE TheHandle,
865 IN CONST BOOLEAN Verbose,
866 IN EFI_GUID *Protocol
867 )
868 {
869 EFI_DEVICE_PATH_PROTOCOL *DevPath;
870 CHAR16 *DevPathStr;
871 CHAR16 *DevPathStrTemp;
872 UINTN Size;
873 EFI_STATUS Status;
874 DevPathStr = NULL;
875 DevPathStrTemp = NULL;
876 Status = gBS->OpenProtocol(TheHandle, Protocol, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
877 if (!EFI_ERROR(Status)) {
878 DevPathStr = ConvertDevicePathToShortText (DevPath, Verbose, 30);
879 if (Verbose) {
880 Size = StrSize(DevPathStr) + sizeof(CHAR16) * 2;
881 DevPathStrTemp = AllocateZeroPool (Size);
882 if (DevPathStrTemp != NULL) {
883 StrnCatS (DevPathStrTemp, Size/sizeof(CHAR16), L" ", 2);
884 StrnCatS (DevPathStrTemp, Size/sizeof(CHAR16), DevPathStr, StrLen (DevPathStr));
885 }
886 FreePool (DevPathStr);
887 DevPathStr = DevPathStrTemp;
888 }
889 gBS->CloseProtocol(TheHandle, Protocol, gImageHandle, NULL);
890 }
891 return DevPathStr;
892 }
893
894 /**
895 Function to dump information about DevicePath protocol.
896
897 This will allocate the return buffer from boot services pool.
898
899 @param[in] TheHandle The handle that has the protocol installed.
900 @param[in] Verbose TRUE for additional information, FALSE otherwise.
901
902 @retval A pointer to a string containing the information.
903 **/
904 CHAR16*
905 EFIAPI
906 DevicePathProtocolDumpInformation(
907 IN CONST EFI_HANDLE TheHandle,
908 IN CONST BOOLEAN Verbose
909 )
910 {
911 return DevicePathProtocolDumpInformationEx (TheHandle, Verbose, &gEfiDevicePathProtocolGuid);
912 }
913
914 /**
915 Function to dump information about LoadedImageDevicePath protocol.
916
917 This will allocate the return buffer from boot services pool.
918
919 @param[in] TheHandle The handle that has the protocol installed.
920 @param[in] Verbose TRUE for additional information, FALSE otherwise.
921
922 @retval A pointer to a string containing the information.
923 **/
924 CHAR16*
925 EFIAPI
926 LoadedImageDevicePathProtocolDumpInformation(
927 IN CONST EFI_HANDLE TheHandle,
928 IN CONST BOOLEAN Verbose
929 )
930 {
931 return DevicePathProtocolDumpInformationEx (TheHandle, Verbose, &gEfiLoadedImageDevicePathProtocolGuid);
932 }
933
934 /**
935 Function to dump information about EfiAdapterInformation Protocol.
936
937 @param[in] TheHandle The handle that has the protocol installed.
938 @param[in] Verbose TRUE for additional information, FALSE otherwise.
939
940 @retval A pointer to a string containing the information.
941 **/
942 CHAR16*
943 EFIAPI
944 AdapterInformationDumpInformation (
945 IN CONST EFI_HANDLE TheHandle,
946 IN CONST BOOLEAN Verbose
947 )
948 {
949 EFI_STATUS Status;
950 EFI_ADAPTER_INFORMATION_PROTOCOL *EfiAdptrInfoProtocol;
951 UINTN InfoTypesBufferCount;
952 UINTN GuidIndex;
953 EFI_GUID *InfoTypesBuffer;
954 CHAR16 *GuidStr;
955 CHAR16 *TempStr;
956 CHAR16 *RetVal;
957 CHAR16 *TempRetVal;
958 VOID *InformationBlock;
959 UINTN InformationBlockSize;
960
961 if (!Verbose) {
962 return (CatSPrint(NULL, L"AdapterInfo"));
963 }
964
965 InfoTypesBuffer = NULL;
966 InformationBlock = NULL;
967
968
969 Status = gBS->OpenProtocol (
970 (EFI_HANDLE) (TheHandle),
971 &gEfiAdapterInformationProtocolGuid,
972 (VOID **) &EfiAdptrInfoProtocol,
973 NULL,
974 NULL,
975 EFI_OPEN_PROTOCOL_GET_PROTOCOL
976 );
977
978 if (EFI_ERROR (Status)) {
979 return NULL;
980 }
981
982 //
983 // Get a list of supported information types for this instance of the protocol.
984 //
985 Status = EfiAdptrInfoProtocol->GetSupportedTypes (
986 EfiAdptrInfoProtocol,
987 &InfoTypesBuffer,
988 &InfoTypesBufferCount
989 );
990 RetVal = NULL;
991 if (EFI_ERROR (Status)) {
992 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GET_SUPP_TYPES_FAILED), NULL);
993 if (TempStr != NULL) {
994 RetVal = CatSPrint (NULL, TempStr, Status);
995 } else {
996 goto ERROR_EXIT;
997 }
998 } else {
999 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SUPP_TYPE_HEADER), NULL);
1000 if (TempStr == NULL) {
1001 goto ERROR_EXIT;
1002 }
1003 RetVal = CatSPrint (NULL, TempStr);
1004 SHELL_FREE_NON_NULL (TempStr);
1005
1006 for (GuidIndex = 0; GuidIndex < InfoTypesBufferCount; GuidIndex++) {
1007 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_NUMBER), NULL);
1008 if (TempStr == NULL) {
1009 goto ERROR_EXIT;
1010 }
1011 TempRetVal = CatSPrint (RetVal, TempStr, (GuidIndex + 1), &InfoTypesBuffer[GuidIndex]);
1012 SHELL_FREE_NON_NULL (RetVal);
1013 RetVal = TempRetVal;
1014 SHELL_FREE_NON_NULL (TempStr);
1015
1016 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_STRING), NULL);
1017 if (TempStr == NULL) {
1018 goto ERROR_EXIT;
1019 }
1020
1021 if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) {
1022 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoMediaStateGuid");
1023 SHELL_FREE_NON_NULL (RetVal);
1024 RetVal = TempRetVal;
1025 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) {
1026 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoNetworkBootGuid");
1027 SHELL_FREE_NON_NULL (RetVal);
1028 RetVal = TempRetVal;
1029 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid)) {
1030 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoSanMacAddressGuid");
1031 SHELL_FREE_NON_NULL (RetVal);
1032 RetVal = TempRetVal;
1033 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoUndiIpv6SupportGuid)) {
1034 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoUndiIpv6SupportGuid");
1035 SHELL_FREE_NON_NULL (RetVal);
1036 RetVal = TempRetVal;
1037 } else {
1038
1039 GuidStr = GetStringNameFromGuid (&InfoTypesBuffer[GuidIndex], NULL);
1040 if (GuidStr == NULL) {
1041 TempRetVal = CatSPrint (RetVal, TempStr, L"UnknownInfoType");
1042 SHELL_FREE_NON_NULL (RetVal);
1043 RetVal = TempRetVal;
1044
1045 SHELL_FREE_NON_NULL (TempStr);
1046 SHELL_FREE_NON_NULL(GuidStr);
1047 //
1048 // So that we never have to pass this UnknownInfoType to the parsing function "GetInformation" service of AIP
1049 //
1050 continue;
1051 } else {
1052 TempRetVal = CatSPrint (RetVal, TempStr, GuidStr);
1053 SHELL_FREE_NON_NULL (RetVal);
1054 RetVal = TempRetVal;
1055 SHELL_FREE_NON_NULL(GuidStr);
1056 }
1057 }
1058
1059 SHELL_FREE_NON_NULL (TempStr);
1060
1061 Status = EfiAdptrInfoProtocol->GetInformation (
1062 EfiAdptrInfoProtocol,
1063 &InfoTypesBuffer[GuidIndex],
1064 &InformationBlock,
1065 &InformationBlockSize
1066 );
1067
1068 if (EFI_ERROR (Status)) {
1069 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GETINFO_FAILED), NULL);
1070 if (TempStr == NULL) {
1071 goto ERROR_EXIT;
1072 }
1073 TempRetVal = CatSPrint (RetVal, TempStr, Status);
1074 SHELL_FREE_NON_NULL (RetVal);
1075 RetVal = TempRetVal;
1076 } else {
1077 if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) {
1078 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_MEDIA_STATE), NULL);
1079 if (TempStr == NULL) {
1080 goto ERROR_EXIT;
1081 }
1082 TempRetVal = CatSPrint (
1083 RetVal,
1084 TempStr,
1085 ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState,
1086 ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState
1087 );
1088 SHELL_FREE_NON_NULL (RetVal);
1089 RetVal = TempRetVal;
1090 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) {
1091 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_NETWORK_BOOT_INFO), NULL);
1092 if (TempStr == NULL) {
1093 goto ERROR_EXIT;
1094 }
1095 TempRetVal = CatSPrint (
1096 RetVal,
1097 TempStr,
1098 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4BootCapablity,
1099 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6BootCapablity,
1100 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBootCapablity,
1101 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->OffloadCapability,
1102 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiMpioCapability,
1103 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4Boot,
1104 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6Boot,
1105 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBoot
1106 );
1107 SHELL_FREE_NON_NULL (RetVal);
1108 RetVal = TempRetVal;
1109 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid) == TRUE) {
1110 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SAN_MAC_ADDRESS_INFO), NULL);
1111 if (TempStr == NULL) {
1112 goto ERROR_EXIT;
1113 }
1114 TempRetVal = CatSPrint (
1115 RetVal,
1116 TempStr,
1117 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[0],
1118 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[1],
1119 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[2],
1120 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[3],
1121 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[4],
1122 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[5]
1123 );
1124 SHELL_FREE_NON_NULL (RetVal);
1125 RetVal = TempRetVal;
1126 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoUndiIpv6SupportGuid) == TRUE) {
1127 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNDI_IPV6_INFO), NULL);
1128 if (TempStr == NULL) {
1129 goto ERROR_EXIT;
1130 }
1131
1132 TempRetVal = CatSPrint (
1133 RetVal,
1134 TempStr,
1135 ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *)InformationBlock)->Ipv6Support
1136 );
1137 SHELL_FREE_NON_NULL (RetVal);
1138 RetVal = TempRetVal;
1139 } else {
1140 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNKNOWN_INFO_TYPE), NULL);
1141 if (TempStr == NULL) {
1142 goto ERROR_EXIT;
1143 }
1144 TempRetVal = CatSPrint (RetVal, TempStr, &InfoTypesBuffer[GuidIndex]);
1145 SHELL_FREE_NON_NULL (RetVal);
1146 RetVal = TempRetVal;
1147 }
1148 }
1149 SHELL_FREE_NON_NULL (TempStr);
1150 SHELL_FREE_NON_NULL (InformationBlock);
1151 }
1152 }
1153
1154 SHELL_FREE_NON_NULL (InfoTypesBuffer);
1155 return RetVal;
1156
1157 ERROR_EXIT:
1158 SHELL_FREE_NON_NULL (RetVal);
1159 SHELL_FREE_NON_NULL (InfoTypesBuffer);
1160 SHELL_FREE_NON_NULL (InformationBlock);
1161 return NULL;
1162 }
1163
1164 /**
1165 Function to dump information about EFI_FIRMWARE_MANAGEMENT_PROTOCOL Protocol.
1166
1167 @param[in] TheHandle The handle that has the protocol installed.
1168 @param[in] Verbose TRUE for additional information, FALSE otherwise.
1169
1170 @retval A pointer to a string containing the information.
1171 **/
1172 CHAR16*
1173 EFIAPI
1174 FirmwareManagementDumpInformation (
1175 IN CONST EFI_HANDLE TheHandle,
1176 IN CONST BOOLEAN Verbose
1177 )
1178 {
1179 EFI_STATUS Status;
1180 EFI_FIRMWARE_MANAGEMENT_PROTOCOL *EfiFwMgmtProtocol;
1181 EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo;
1182 EFI_FIRMWARE_IMAGE_DESCRIPTOR_V1 *ImageInfoV1;
1183 EFI_FIRMWARE_IMAGE_DESCRIPTOR_V2 *ImageInfoV2;
1184 UINT64 AttributeSetting;
1185 UINTN ImageInfoSize;
1186 UINTN DescriptorSize;
1187 UINT32 DescriptorVersion;
1188 UINT32 PackageVersion;
1189 UINT8 DescriptorCount;
1190 UINT8 Index;
1191 UINT8 Index1;
1192 UINT8 ImageCount;
1193 CHAR16 *PackageVersionName;
1194 CHAR16 *TempStr;
1195 CHAR16 *RetVal;
1196 CHAR16 *TempRetVal;
1197 CHAR16 *AttributeSettingStr;
1198 BOOLEAN Found;
1199 BOOLEAN AttributeSupported;
1200
1201 //
1202 // Initialize local variables
1203 //
1204 ImageCount = 0;
1205 ImageInfoSize = 1;
1206 AttributeSetting = 0;
1207 Found = FALSE;
1208 AttributeSupported = FALSE;
1209 ImageInfo = NULL;
1210 ImageInfoV1 = NULL;
1211 ImageInfoV2 = NULL;
1212 PackageVersionName = NULL;
1213 RetVal = NULL;
1214 TempRetVal = NULL;
1215 TempStr = NULL;
1216 AttributeSettingStr = NULL;
1217
1218 if (!Verbose) {
1219 return (CatSPrint(NULL, L"FirmwareManagement"));
1220 }
1221
1222 Status = gBS->OpenProtocol (
1223 (EFI_HANDLE) (TheHandle),
1224 &gEfiFirmwareManagementProtocolGuid,
1225 (VOID **) &EfiFwMgmtProtocol,
1226 NULL,
1227 NULL,
1228 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1229 );
1230
1231 if (EFI_ERROR (Status)) {
1232 return NULL;
1233 }
1234
1235 Status = EfiFwMgmtProtocol->GetImageInfo (
1236 EfiFwMgmtProtocol,
1237 &ImageInfoSize,
1238 ImageInfo,
1239 &DescriptorVersion,
1240 &DescriptorCount,
1241 &DescriptorSize,
1242 &PackageVersion,
1243 &PackageVersionName
1244 );
1245
1246 if (Status == EFI_BUFFER_TOO_SMALL) {
1247 ImageInfo = AllocateZeroPool (ImageInfoSize);
1248
1249 if (ImageInfo == NULL) {
1250 Status = EFI_OUT_OF_RESOURCES;
1251 } else {
1252 Status = EfiFwMgmtProtocol->GetImageInfo (
1253 EfiFwMgmtProtocol,
1254 &ImageInfoSize,
1255 ImageInfo,
1256 &DescriptorVersion,
1257 &DescriptorCount,
1258 &DescriptorSize,
1259 &PackageVersion,
1260 &PackageVersionName
1261 );
1262 }
1263 }
1264
1265 if (EFI_ERROR (Status)) {
1266 goto ERROR_EXIT;
1267 }
1268
1269 //
1270 // Decode Image Descriptor data only if its version is supported
1271 //
1272 if (DescriptorVersion <= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION) {
1273
1274 if (ImageInfo == NULL) {
1275 goto ERROR_EXIT;
1276 }
1277
1278 ImageInfoV1 = (EFI_FIRMWARE_IMAGE_DESCRIPTOR_V1 *)ImageInfo;
1279 ImageInfoV2 = (EFI_FIRMWARE_IMAGE_DESCRIPTOR_V2 *)ImageInfo;
1280
1281 //
1282 // Set ImageInfoSize in return buffer
1283 //
1284 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_INFO_SIZE), NULL);
1285 if (TempStr == NULL) {
1286 goto ERROR_EXIT;
1287 }
1288 RetVal = CatSPrint (NULL, TempStr, ImageInfoSize);
1289 SHELL_FREE_NON_NULL (TempStr);
1290
1291 //
1292 // Set DescriptorVersion in return buffer
1293 //
1294 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_VERSION), NULL);
1295 if (TempStr == NULL) {
1296 goto ERROR_EXIT;
1297 }
1298 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorVersion);
1299 SHELL_FREE_NON_NULL (RetVal);
1300 RetVal = TempRetVal;
1301 SHELL_FREE_NON_NULL (TempStr);
1302
1303 //
1304 // Set DescriptorCount in return buffer
1305 //
1306 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_COUNT), NULL);
1307 if (TempStr == NULL) {
1308 goto ERROR_EXIT;
1309 }
1310 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorCount);
1311 SHELL_FREE_NON_NULL (RetVal);
1312 RetVal = TempRetVal;
1313 SHELL_FREE_NON_NULL (TempStr);
1314
1315
1316 //
1317 // Set DescriptorSize in return buffer
1318 //
1319 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_SIZE), NULL);
1320 if (TempStr == NULL) {
1321 goto ERROR_EXIT;
1322 }
1323 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorSize);
1324 SHELL_FREE_NON_NULL (RetVal);
1325 RetVal = TempRetVal;
1326 SHELL_FREE_NON_NULL (TempStr);
1327
1328 //
1329 // Set PackageVersion in return buffer
1330 //
1331 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_PACKAGE_VERSION), NULL);
1332 if (TempStr == NULL) {
1333 goto ERROR_EXIT;
1334 }
1335 TempRetVal = CatSPrint (RetVal, TempStr, PackageVersion);
1336 SHELL_FREE_NON_NULL (RetVal);
1337 RetVal = TempRetVal;
1338 SHELL_FREE_NON_NULL (TempStr);
1339
1340 //
1341 // Set PackageVersionName in return buffer
1342 //
1343 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_PACKAGE_VERSION_NAME), NULL);
1344 if (TempStr == NULL) {
1345 goto ERROR_EXIT;
1346 }
1347 TempRetVal = CatSPrint (RetVal, TempStr, PackageVersionName);
1348 SHELL_FREE_NON_NULL (RetVal);
1349 RetVal = TempRetVal;
1350 SHELL_FREE_NON_NULL (TempStr);
1351
1352 for (Index = 0; Index < DescriptorCount; Index++) {
1353 //
1354 // First check if Attribute is supported
1355 // and generate a string for AttributeSetting field
1356 //
1357 SHELL_FREE_NON_NULL (AttributeSettingStr);
1358 AttributeSupported = FALSE;
1359 AttributeSetting = 0;
1360 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1361 if (ImageInfoV1[Index].AttributesSupported != 0x0) {
1362 AttributeSupported = TRUE;
1363 AttributeSetting = ImageInfoV1[Index].AttributesSetting;
1364 }
1365 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1366 if (ImageInfoV2[Index].AttributesSupported != 0x0) {
1367 AttributeSupported = TRUE;
1368 AttributeSetting = ImageInfoV2[Index].AttributesSetting;
1369 }
1370 } else {
1371 if (ImageInfo[Index].AttributesSupported != 0x0) {
1372 AttributeSupported = TRUE;
1373 AttributeSetting = ImageInfo[Index].AttributesSetting;
1374 }
1375 }
1376
1377 if (!AttributeSupported) {
1378 AttributeSettingStr = CatSPrint (NULL, L"None");
1379 } else {
1380 AttributeSettingStr = CatSPrint (NULL, L"(");
1381
1382 if ((AttributeSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) != 0x0) {
1383 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IMAGE_UPDATABLE");
1384 SHELL_FREE_NON_NULL (AttributeSettingStr);
1385 AttributeSettingStr = TempRetVal;
1386 }
1387 if ((AttributeSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED) != 0x0) {
1388 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_RESET_REQUIRED");
1389 SHELL_FREE_NON_NULL (AttributeSettingStr);
1390 AttributeSettingStr = TempRetVal;
1391 }
1392 if ((AttributeSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED) != 0x0) {
1393 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED");
1394 SHELL_FREE_NON_NULL (AttributeSettingStr);
1395 AttributeSettingStr = TempRetVal;
1396 }
1397 if ((AttributeSetting & IMAGE_ATTRIBUTE_IN_USE) != 0x0) {
1398 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IN_USE");
1399 SHELL_FREE_NON_NULL (AttributeSettingStr);
1400 AttributeSettingStr = TempRetVal;
1401 }
1402 if ((AttributeSetting & IMAGE_ATTRIBUTE_UEFI_IMAGE) != 0x0) {
1403 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_UEFI_IMAGE");
1404 SHELL_FREE_NON_NULL (AttributeSettingStr);
1405 AttributeSettingStr = TempRetVal;
1406 }
1407 TempRetVal = CatSPrint (AttributeSettingStr, L" )");
1408 SHELL_FREE_NON_NULL (AttributeSettingStr);
1409 AttributeSettingStr = TempRetVal;
1410 }
1411
1412 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1413 if (ImageInfoV1[Index].ImageIndex != 0x0) {
1414 ImageCount++;
1415 }
1416
1417 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO_V1), NULL);
1418 if (TempStr == NULL) {
1419 goto ERROR_EXIT;
1420 }
1421 TempRetVal = CatSPrint (
1422 RetVal,
1423 TempStr,
1424 Index,
1425 ImageInfoV1[Index].ImageIndex,
1426 &ImageInfoV1[Index].ImageTypeId,
1427 ImageInfoV1[Index].ImageId,
1428 ImageInfoV1[Index].ImageIdName,
1429 ImageInfoV1[Index].Version,
1430 ImageInfoV1[Index].VersionName,
1431 ImageInfoV1[Index].Size,
1432 ImageInfoV1[Index].AttributesSupported,
1433 AttributeSettingStr,
1434 ImageInfoV1[Index].Compatibilities
1435 );
1436 SHELL_FREE_NON_NULL (RetVal);
1437 RetVal = TempRetVal;
1438 SHELL_FREE_NON_NULL (TempStr);
1439 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1440 if (ImageInfoV2[Index].ImageIndex != 0x0) {
1441 ImageCount++;
1442 }
1443
1444 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO_V2), NULL);
1445 if (TempStr == NULL) {
1446 goto ERROR_EXIT;
1447 }
1448 TempRetVal = CatSPrint (
1449 RetVal,
1450 TempStr,
1451 Index,
1452 ImageInfoV2[Index].ImageIndex,
1453 &ImageInfoV2[Index].ImageTypeId,
1454 ImageInfoV2[Index].ImageId,
1455 ImageInfoV2[Index].ImageIdName,
1456 ImageInfoV2[Index].Version,
1457 ImageInfoV2[Index].VersionName,
1458 ImageInfoV2[Index].Size,
1459 ImageInfoV2[Index].AttributesSupported,
1460 AttributeSettingStr,
1461 ImageInfoV2[Index].Compatibilities,
1462 ImageInfoV2[Index].LowestSupportedImageVersion
1463 );
1464 SHELL_FREE_NON_NULL (RetVal);
1465 RetVal = TempRetVal;
1466 SHELL_FREE_NON_NULL (TempStr);
1467 } else {
1468 if (ImageInfo[Index].ImageIndex != 0x0) {
1469 ImageCount++;
1470 }
1471
1472 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO), NULL);
1473 if (TempStr == NULL) {
1474 goto ERROR_EXIT;
1475 }
1476 TempRetVal = CatSPrint (
1477 RetVal,
1478 TempStr,
1479 Index,
1480 ImageInfo[Index].ImageIndex,
1481 &ImageInfo[Index].ImageTypeId,
1482 ImageInfo[Index].ImageId,
1483 ImageInfo[Index].ImageIdName,
1484 ImageInfo[Index].Version,
1485 ImageInfo[Index].VersionName,
1486 ImageInfo[Index].Size,
1487 ImageInfo[Index].AttributesSupported,
1488 AttributeSettingStr,
1489 ImageInfo[Index].Compatibilities,
1490 ImageInfo[Index].LowestSupportedImageVersion,
1491 ImageInfo[Index].LastAttemptVersion,
1492 ImageInfo[Index].LastAttemptStatus,
1493 ImageInfo[Index].HardwareInstance
1494 );
1495 SHELL_FREE_NON_NULL (RetVal);
1496 RetVal = TempRetVal;
1497 SHELL_FREE_NON_NULL (TempStr);
1498 }
1499 }
1500 }
1501
1502 if (ImageCount > 0) {
1503 for (Index=0; Index<DescriptorCount; Index++) {
1504 for (Index1=Index+1; Index1<DescriptorCount; Index1++) {
1505 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1506 if (ImageInfoV1[Index].ImageId == ImageInfoV1[Index1].ImageId) {
1507 Found = TRUE;
1508 //
1509 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1510 //
1511 goto ENDLOOP;
1512 }
1513 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1514 if (ImageInfoV2[Index].ImageId == ImageInfoV2[Index1].ImageId) {
1515 Found = TRUE;
1516 //
1517 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1518 //
1519 goto ENDLOOP;
1520 }
1521 } else {
1522 if (ImageInfo[Index].ImageId == ImageInfo[Index1].ImageId) {
1523 Found = TRUE;
1524 //
1525 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1526 //
1527 goto ENDLOOP;
1528 }
1529 }
1530 }
1531 }
1532 }
1533
1534 ENDLOOP:
1535 //
1536 // Check if ImageId with duplicate value was found
1537 //
1538 if (Found) {
1539 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGEID_NON_UNIQUE), NULL);
1540 if (TempStr == NULL) {
1541 goto ERROR_EXIT;
1542 }
1543 TempRetVal = CatSPrint (RetVal, TempStr);
1544 SHELL_FREE_NON_NULL (RetVal);
1545 RetVal = TempRetVal;
1546 SHELL_FREE_NON_NULL (TempStr);
1547 }
1548
1549 SHELL_FREE_NON_NULL (ImageInfo);
1550 SHELL_FREE_NON_NULL (PackageVersionName);
1551 SHELL_FREE_NON_NULL (AttributeSettingStr);
1552
1553 return RetVal;
1554
1555 ERROR_EXIT:
1556 SHELL_FREE_NON_NULL (RetVal);
1557 SHELL_FREE_NON_NULL (ImageInfo);
1558 SHELL_FREE_NON_NULL (PackageVersionName);
1559 SHELL_FREE_NON_NULL (AttributeSettingStr);
1560
1561 return NULL;
1562 }
1563
1564 //
1565 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
1566 //
1567 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
1568 { \
1569 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1570 }
1571
1572 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
1573 { \
1574 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1575 }
1576
1577 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
1578 { \
1579 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1580 }
1581 STATIC CONST EFI_GUID WinNtThunkProtocolGuid = LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID;
1582 STATIC CONST EFI_GUID WinNtIoProtocolGuid = LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID;
1583 STATIC CONST EFI_GUID WinNtSerialPortGuid = LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID;
1584
1585 //
1586 // Deprecated protocols we dont want to link from IntelFrameworkModulePkg
1587 //
1588 #define LOCAL_EFI_ISA_IO_PROTOCOL_GUID \
1589 { \
1590 0x7ee2bd44, 0x3da0, 0x11d4, { 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
1591 }
1592 #define LOCAL_EFI_ISA_ACPI_PROTOCOL_GUID \
1593 { \
1594 0x64a892dc, 0x5561, 0x4536, { 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55 } \
1595 }
1596 STATIC CONST EFI_GUID EfiIsaIoProtocolGuid = LOCAL_EFI_ISA_IO_PROTOCOL_GUID;
1597 STATIC CONST EFI_GUID EfiIsaAcpiProtocolGuid = LOCAL_EFI_ISA_ACPI_PROTOCOL_GUID;
1598
1599
1600 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT[] = {
1601 {STRING_TOKEN(STR_WINNT_THUNK), (EFI_GUID*)&WinNtThunkProtocolGuid, NULL},
1602 {STRING_TOKEN(STR_WINNT_DRIVER_IO), (EFI_GUID*)&WinNtIoProtocolGuid, NULL},
1603 {STRING_TOKEN(STR_WINNT_SERIAL_PORT), (EFI_GUID*)&WinNtSerialPortGuid, NULL},
1604 {0, NULL, NULL},
1605 };
1606
1607 STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {
1608 {STRING_TOKEN(STR_LOADED_IMAGE), &gEfiLoadedImageProtocolGuid, LoadedImageProtocolDumpInformation},
1609 {STRING_TOKEN(STR_DEVICE_PATH), &gEfiDevicePathProtocolGuid, DevicePathProtocolDumpInformation},
1610 {STRING_TOKEN(STR_IMAGE_PATH), &gEfiLoadedImageDevicePathProtocolGuid, LoadedImageDevicePathProtocolDumpInformation},
1611 {STRING_TOKEN(STR_DEVICE_PATH_UTIL), &gEfiDevicePathUtilitiesProtocolGuid, NULL},
1612 {STRING_TOKEN(STR_DEVICE_PATH_TXT), &gEfiDevicePathToTextProtocolGuid, NULL},
1613 {STRING_TOKEN(STR_DEVICE_PATH_FTXT), &gEfiDevicePathFromTextProtocolGuid, NULL},
1614 {STRING_TOKEN(STR_DEVICE_PATH_PC), &gEfiPcAnsiGuid, NULL},
1615 {STRING_TOKEN(STR_DEVICE_PATH_VT100), &gEfiVT100Guid, NULL},
1616 {STRING_TOKEN(STR_DEVICE_PATH_VT100P), &gEfiVT100PlusGuid, NULL},
1617 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8), &gEfiVTUTF8Guid, NULL},
1618 {STRING_TOKEN(STR_DRIVER_BINDING), &gEfiDriverBindingProtocolGuid, NULL},
1619 {STRING_TOKEN(STR_PLATFORM_OVERRIDE), &gEfiPlatformDriverOverrideProtocolGuid, NULL},
1620 {STRING_TOKEN(STR_BUS_OVERRIDE), &gEfiBusSpecificDriverOverrideProtocolGuid, NULL},
1621 {STRING_TOKEN(STR_DRIVER_DIAG), &gEfiDriverDiagnosticsProtocolGuid, NULL},
1622 {STRING_TOKEN(STR_DRIVER_DIAG2), &gEfiDriverDiagnostics2ProtocolGuid, NULL},
1623 {STRING_TOKEN(STR_DRIVER_CN), &gEfiComponentNameProtocolGuid, NULL},
1624 {STRING_TOKEN(STR_DRIVER_CN2), &gEfiComponentName2ProtocolGuid, NULL},
1625 {STRING_TOKEN(STR_PLAT_DRV_CFG), &gEfiPlatformToDriverConfigurationProtocolGuid, NULL},
1626 {STRING_TOKEN(STR_DRIVER_VERSION), &gEfiDriverSupportedEfiVersionProtocolGuid, DriverEfiVersionProtocolDumpInformation},
1627 {STRING_TOKEN(STR_TXT_IN), &gEfiSimpleTextInProtocolGuid, NULL},
1628 {STRING_TOKEN(STR_TXT_IN_EX), &gEfiSimpleTextInputExProtocolGuid, NULL},
1629 {STRING_TOKEN(STR_TXT_OUT), &gEfiSimpleTextOutProtocolGuid, TxtOutProtocolDumpInformation},
1630 {STRING_TOKEN(STR_SIM_POINTER), &gEfiSimplePointerProtocolGuid, NULL},
1631 {STRING_TOKEN(STR_ABS_POINTER), &gEfiAbsolutePointerProtocolGuid, NULL},
1632 {STRING_TOKEN(STR_SERIAL_IO), &gEfiSerialIoProtocolGuid, NULL},
1633 {STRING_TOKEN(STR_GRAPHICS_OUTPUT), &gEfiGraphicsOutputProtocolGuid, GraphicsOutputProtocolDumpInformation},
1634 {STRING_TOKEN(STR_EDID_DISCOVERED), &gEfiEdidDiscoveredProtocolGuid, EdidDiscoveredProtocolDumpInformation},
1635 {STRING_TOKEN(STR_EDID_ACTIVE), &gEfiEdidActiveProtocolGuid, EdidActiveProtocolDumpInformation},
1636 {STRING_TOKEN(STR_EDID_OVERRIDE), &gEfiEdidOverrideProtocolGuid, NULL},
1637 {STRING_TOKEN(STR_CON_IN), &gEfiConsoleInDeviceGuid, NULL},
1638 {STRING_TOKEN(STR_CON_OUT), &gEfiConsoleOutDeviceGuid, NULL},
1639 {STRING_TOKEN(STR_STD_ERR), &gEfiStandardErrorDeviceGuid, NULL},
1640 {STRING_TOKEN(STR_LOAD_FILE), &gEfiLoadFileProtocolGuid, NULL},
1641 {STRING_TOKEN(STR_LOAD_FILE2), &gEfiLoadFile2ProtocolGuid, NULL},
1642 {STRING_TOKEN(STR_SIMPLE_FILE_SYS), &gEfiSimpleFileSystemProtocolGuid, NULL},
1643 {STRING_TOKEN(STR_TAPE_IO), &gEfiTapeIoProtocolGuid, NULL},
1644 {STRING_TOKEN(STR_DISK_IO), &gEfiDiskIoProtocolGuid, NULL},
1645 {STRING_TOKEN(STR_BLK_IO), &gEfiBlockIoProtocolGuid, NULL},
1646 {STRING_TOKEN(STR_UC), &gEfiUnicodeCollationProtocolGuid, NULL},
1647 {STRING_TOKEN(STR_UC2), &gEfiUnicodeCollation2ProtocolGuid, NULL},
1648 {STRING_TOKEN(STR_PCIRB_IO), &gEfiPciRootBridgeIoProtocolGuid, PciRootBridgeIoDumpInformation},
1649 {STRING_TOKEN(STR_PCI_IO), &gEfiPciIoProtocolGuid, NULL},
1650 {STRING_TOKEN(STR_SCSI_PT), &gEfiScsiPassThruProtocolGuid, NULL},
1651 {STRING_TOKEN(STR_SCSI_IO), &gEfiScsiIoProtocolGuid, NULL},
1652 {STRING_TOKEN(STR_SCSI_PT_EXT), &gEfiExtScsiPassThruProtocolGuid, NULL},
1653 {STRING_TOKEN(STR_ISCSI), &gEfiIScsiInitiatorNameProtocolGuid, NULL},
1654 {STRING_TOKEN(STR_USB_IO), &gEfiUsbIoProtocolGuid, NULL},
1655 {STRING_TOKEN(STR_USB_HC), &gEfiUsbHcProtocolGuid, NULL},
1656 {STRING_TOKEN(STR_USB_HC2), &gEfiUsb2HcProtocolGuid, NULL},
1657 {STRING_TOKEN(STR_DEBUG_SUPPORT), &gEfiDebugSupportProtocolGuid, NULL},
1658 {STRING_TOKEN(STR_DEBUG_PORT), &gEfiDebugPortProtocolGuid, NULL},
1659 {STRING_TOKEN(STR_DECOMPRESS), &gEfiDecompressProtocolGuid, NULL},
1660 {STRING_TOKEN(STR_ACPI_TABLE), &gEfiAcpiTableProtocolGuid, NULL},
1661 {STRING_TOKEN(STR_EBC_INTERPRETER), &gEfiEbcProtocolGuid, NULL},
1662 {STRING_TOKEN(STR_SNP), &gEfiSimpleNetworkProtocolGuid, NULL},
1663 {STRING_TOKEN(STR_NII), &gEfiNetworkInterfaceIdentifierProtocolGuid, NULL},
1664 {STRING_TOKEN(STR_NII_31), &gEfiNetworkInterfaceIdentifierProtocolGuid_31, NULL},
1665 {STRING_TOKEN(STR_PXE_BC), &gEfiPxeBaseCodeProtocolGuid, NULL},
1666 {STRING_TOKEN(STR_PXE_CB), &gEfiPxeBaseCodeCallbackProtocolGuid, NULL},
1667 {STRING_TOKEN(STR_BIS), &gEfiBisProtocolGuid, NULL},
1668 {STRING_TOKEN(STR_MNP_SB), &gEfiManagedNetworkServiceBindingProtocolGuid, NULL},
1669 {STRING_TOKEN(STR_MNP), &gEfiManagedNetworkProtocolGuid, NULL},
1670 {STRING_TOKEN(STR_ARP_SB), &gEfiArpServiceBindingProtocolGuid, NULL},
1671 {STRING_TOKEN(STR_ARP), &gEfiArpProtocolGuid, NULL},
1672 {STRING_TOKEN(STR_DHCPV4_SB), &gEfiDhcp4ServiceBindingProtocolGuid, NULL},
1673 {STRING_TOKEN(STR_DHCPV4), &gEfiDhcp4ProtocolGuid, NULL},
1674 {STRING_TOKEN(STR_TCPV4_SB), &gEfiTcp4ServiceBindingProtocolGuid, NULL},
1675 {STRING_TOKEN(STR_TCPV4), &gEfiTcp4ProtocolGuid, NULL},
1676 {STRING_TOKEN(STR_IPV4_SB), &gEfiIp4ServiceBindingProtocolGuid, NULL},
1677 {STRING_TOKEN(STR_IPV4), &gEfiIp4ProtocolGuid, NULL},
1678 {STRING_TOKEN(STR_IPV4_CFG), &gEfiIp4ConfigProtocolGuid, NULL},
1679 {STRING_TOKEN(STR_IPV4_CFG2), &gEfiIp4Config2ProtocolGuid, NULL},
1680 {STRING_TOKEN(STR_UDPV4_SB), &gEfiUdp4ServiceBindingProtocolGuid, NULL},
1681 {STRING_TOKEN(STR_UDPV4), &gEfiUdp4ProtocolGuid, NULL},
1682 {STRING_TOKEN(STR_MTFTPV4_SB), &gEfiMtftp4ServiceBindingProtocolGuid, NULL},
1683 {STRING_TOKEN(STR_MTFTPV4), &gEfiMtftp4ProtocolGuid, NULL},
1684 {STRING_TOKEN(STR_AUTH_INFO), &gEfiAuthenticationInfoProtocolGuid, NULL},
1685 {STRING_TOKEN(STR_HASH_SB), &gEfiHashServiceBindingProtocolGuid, NULL},
1686 {STRING_TOKEN(STR_HASH), &gEfiHashProtocolGuid, NULL},
1687 {STRING_TOKEN(STR_HII_FONT), &gEfiHiiFontProtocolGuid, NULL},
1688 {STRING_TOKEN(STR_HII_STRING), &gEfiHiiStringProtocolGuid, NULL},
1689 {STRING_TOKEN(STR_HII_IMAGE), &gEfiHiiImageProtocolGuid, NULL},
1690 {STRING_TOKEN(STR_HII_DATABASE), &gEfiHiiDatabaseProtocolGuid, NULL},
1691 {STRING_TOKEN(STR_HII_CONFIG_ROUT), &gEfiHiiConfigRoutingProtocolGuid, NULL},
1692 {STRING_TOKEN(STR_HII_CONFIG_ACC), &gEfiHiiConfigAccessProtocolGuid, NULL},
1693 {STRING_TOKEN(STR_HII_FORM_BROWSER2), &gEfiFormBrowser2ProtocolGuid, NULL},
1694 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE), &gEfiDriverFamilyOverrideProtocolGuid, NULL},
1695 {STRING_TOKEN(STR_PCD), &gPcdProtocolGuid, NULL},
1696 {STRING_TOKEN(STR_TCG), &gEfiTcgProtocolGuid, NULL},
1697 {STRING_TOKEN(STR_HII_PACKAGE_LIST), &gEfiHiiPackageListProtocolGuid, NULL},
1698
1699 //
1700 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
1701 //
1702 {STRING_TOKEN(STR_SHELL_INTERFACE), &gEfiShellInterfaceGuid, NULL},
1703 {STRING_TOKEN(STR_SHELL_ENV2), &gEfiShellEnvironment2Guid, NULL},
1704 {STRING_TOKEN(STR_SHELL_ENV), &gEfiShellEnvironment2Guid, NULL},
1705 {STRING_TOKEN(STR_DEVICE_IO), &gEfiDeviceIoProtocolGuid, NULL},
1706 {STRING_TOKEN(STR_UGA_DRAW), &gEfiUgaDrawProtocolGuid, NULL},
1707 {STRING_TOKEN(STR_UGA_IO), &gEfiUgaIoProtocolGuid, NULL},
1708 {STRING_TOKEN(STR_ESP), &gEfiPartTypeSystemPartGuid, NULL},
1709 {STRING_TOKEN(STR_GPT_NBR), &gEfiPartTypeLegacyMbrGuid, NULL},
1710 {STRING_TOKEN(STR_DRIVER_CONFIG), &gEfiDriverConfigurationProtocolGuid, NULL},
1711 {STRING_TOKEN(STR_DRIVER_CONFIG2), &gEfiDriverConfiguration2ProtocolGuid, NULL},
1712
1713 //
1714 // these are using local (non-global) definitions to reduce package dependancy.
1715 //
1716 {STRING_TOKEN(STR_ISA_IO), (EFI_GUID*)&EfiIsaIoProtocolGuid, NULL},
1717 {STRING_TOKEN(STR_ISA_ACPI), (EFI_GUID*)&EfiIsaAcpiProtocolGuid, NULL},
1718
1719 //
1720 // the ones under this are GUID identified structs, not protocols
1721 //
1722 {STRING_TOKEN(STR_FILE_INFO), &gEfiFileInfoGuid, NULL},
1723 {STRING_TOKEN(STR_FILE_SYS_INFO), &gEfiFileSystemInfoGuid, NULL},
1724
1725 //
1726 // the ones under this are misc GUIDS.
1727 //
1728 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE), &gEfiGlobalVariableGuid, NULL},
1729
1730 //
1731 // UEFI 2.2
1732 //
1733 {STRING_TOKEN(STR_IP6_SB), &gEfiIp6ServiceBindingProtocolGuid, NULL},
1734 {STRING_TOKEN(STR_IP6), &gEfiIp6ProtocolGuid, NULL},
1735 {STRING_TOKEN(STR_IP6_CONFIG), &gEfiIp6ConfigProtocolGuid, NULL},
1736 {STRING_TOKEN(STR_MTFTP6_SB), &gEfiMtftp6ServiceBindingProtocolGuid, NULL},
1737 {STRING_TOKEN(STR_MTFTP6), &gEfiMtftp6ProtocolGuid, NULL},
1738 {STRING_TOKEN(STR_DHCP6_SB), &gEfiDhcp6ServiceBindingProtocolGuid, NULL},
1739 {STRING_TOKEN(STR_DHCP6), &gEfiDhcp6ProtocolGuid, NULL},
1740 {STRING_TOKEN(STR_UDP6_SB), &gEfiUdp6ServiceBindingProtocolGuid, NULL},
1741 {STRING_TOKEN(STR_UDP6), &gEfiUdp6ProtocolGuid, NULL},
1742 {STRING_TOKEN(STR_TCP6_SB), &gEfiTcp6ServiceBindingProtocolGuid, NULL},
1743 {STRING_TOKEN(STR_TCP6), &gEfiTcp6ProtocolGuid, NULL},
1744 {STRING_TOKEN(STR_VLAN_CONFIG), &gEfiVlanConfigProtocolGuid, NULL},
1745 {STRING_TOKEN(STR_EAP), &gEfiEapProtocolGuid, NULL},
1746 {STRING_TOKEN(STR_EAP_MGMT), &gEfiEapManagementProtocolGuid, NULL},
1747 {STRING_TOKEN(STR_FTP4_SB), &gEfiFtp4ServiceBindingProtocolGuid, NULL},
1748 {STRING_TOKEN(STR_FTP4), &gEfiFtp4ProtocolGuid, NULL},
1749 {STRING_TOKEN(STR_IP_SEC_CONFIG), &gEfiIpSecConfigProtocolGuid, NULL},
1750 {STRING_TOKEN(STR_DH), &gEfiDriverHealthProtocolGuid, NULL},
1751 {STRING_TOKEN(STR_DEF_IMG_LOAD), &gEfiDeferredImageLoadProtocolGuid, NULL},
1752 {STRING_TOKEN(STR_USER_CRED), &gEfiUserCredentialProtocolGuid, NULL},
1753 {STRING_TOKEN(STR_USER_MNGR), &gEfiUserManagerProtocolGuid, NULL},
1754 {STRING_TOKEN(STR_ATA_PASS_THRU), &gEfiAtaPassThruProtocolGuid, NULL},
1755
1756 //
1757 // UEFI 2.3
1758 //
1759 {STRING_TOKEN(STR_FW_MGMT), &gEfiFirmwareManagementProtocolGuid, FirmwareManagementDumpInformation},
1760 {STRING_TOKEN(STR_IP_SEC), &gEfiIpSecProtocolGuid, NULL},
1761 {STRING_TOKEN(STR_IP_SEC2), &gEfiIpSec2ProtocolGuid, NULL},
1762
1763 //
1764 // UEFI 2.3.1
1765 //
1766 {STRING_TOKEN(STR_KMS), &gEfiKmsProtocolGuid, NULL},
1767 {STRING_TOKEN(STR_BLK_IO2), &gEfiBlockIo2ProtocolGuid, NULL},
1768 {STRING_TOKEN(STR_SSC), &gEfiStorageSecurityCommandProtocolGuid, NULL},
1769 {STRING_TOKEN(STR_UCRED2), &gEfiUserCredential2ProtocolGuid, NULL},
1770
1771 //
1772 // UEFI 2.4
1773 //
1774 {STRING_TOKEN(STR_DISK_IO2), &gEfiDiskIo2ProtocolGuid, NULL},
1775 {STRING_TOKEN(STR_ADAPTER_INFO), &gEfiAdapterInformationProtocolGuid, AdapterInformationDumpInformation},
1776
1777 //
1778 // PI Spec ones
1779 //
1780 {STRING_TOKEN(STR_IDE_CONT_INIT), &gEfiIdeControllerInitProtocolGuid, NULL},
1781 {STRING_TOKEN(STR_DISK_INFO), &gEfiDiskInfoProtocolGuid, NULL},
1782
1783 //
1784 // PI Spec 1.0
1785 //
1786 {STRING_TOKEN(STR_BDS_ARCH), &gEfiBdsArchProtocolGuid, NULL},
1787 {STRING_TOKEN(STR_CPU_ARCH), &gEfiCpuArchProtocolGuid, NULL},
1788 {STRING_TOKEN(STR_MET_ARCH), &gEfiMetronomeArchProtocolGuid, NULL},
1789 {STRING_TOKEN(STR_MON_ARCH), &gEfiMonotonicCounterArchProtocolGuid, NULL},
1790 {STRING_TOKEN(STR_RTC_ARCH), &gEfiRealTimeClockArchProtocolGuid, NULL},
1791 {STRING_TOKEN(STR_RESET_ARCH), &gEfiResetArchProtocolGuid, NULL},
1792 {STRING_TOKEN(STR_RT_ARCH), &gEfiRuntimeArchProtocolGuid, NULL},
1793 {STRING_TOKEN(STR_SEC_ARCH), &gEfiSecurityArchProtocolGuid, NULL},
1794 {STRING_TOKEN(STR_TIMER_ARCH), &gEfiTimerArchProtocolGuid, NULL},
1795 {STRING_TOKEN(STR_VAR_ARCH), &gEfiVariableWriteArchProtocolGuid, NULL},
1796 {STRING_TOKEN(STR_V_ARCH), &gEfiVariableArchProtocolGuid, NULL},
1797 {STRING_TOKEN(STR_SECP), &gEfiSecurityPolicyProtocolGuid, NULL},
1798 {STRING_TOKEN(STR_WDT_ARCH), &gEfiWatchdogTimerArchProtocolGuid, NULL},
1799 {STRING_TOKEN(STR_SCR), &gEfiStatusCodeRuntimeProtocolGuid, NULL},
1800 {STRING_TOKEN(STR_SMB_HC), &gEfiSmbusHcProtocolGuid, NULL},
1801 {STRING_TOKEN(STR_FV_2), &gEfiFirmwareVolume2ProtocolGuid, NULL},
1802 {STRING_TOKEN(STR_FV_BLOCK), &gEfiFirmwareVolumeBlockProtocolGuid, NULL},
1803 {STRING_TOKEN(STR_CAP_ARCH), &gEfiCapsuleArchProtocolGuid, NULL},
1804 {STRING_TOKEN(STR_MP_SERVICE), &gEfiMpServiceProtocolGuid, NULL},
1805 {STRING_TOKEN(STR_HBRAP), &gEfiPciHostBridgeResourceAllocationProtocolGuid, NULL},
1806 {STRING_TOKEN(STR_PCIP), &gEfiPciPlatformProtocolGuid, NULL},
1807 {STRING_TOKEN(STR_PCIO), &gEfiPciOverrideProtocolGuid, NULL},
1808 {STRING_TOKEN(STR_PCIE), &gEfiPciEnumerationCompleteProtocolGuid, NULL},
1809 {STRING_TOKEN(STR_IPCID), &gEfiIncompatiblePciDeviceSupportProtocolGuid, NULL},
1810 {STRING_TOKEN(STR_PCIHPI), &gEfiPciHotPlugInitProtocolGuid, NULL},
1811 {STRING_TOKEN(STR_PCIHPR), &gEfiPciHotPlugRequestProtocolGuid, NULL},
1812 {STRING_TOKEN(STR_SMBIOS), &gEfiSmbiosProtocolGuid, NULL},
1813 {STRING_TOKEN(STR_S3_SAVE), &gEfiS3SaveStateProtocolGuid, NULL},
1814 {STRING_TOKEN(STR_S3_S_SMM), &gEfiS3SmmSaveStateProtocolGuid, NULL},
1815 {STRING_TOKEN(STR_RSC), &gEfiRscHandlerProtocolGuid, NULL},
1816 {STRING_TOKEN(STR_S_RSC), &gEfiSmmRscHandlerProtocolGuid, NULL},
1817 {STRING_TOKEN(STR_ACPI_SDT), &gEfiAcpiSdtProtocolGuid, NULL},
1818 {STRING_TOKEN(STR_SIO), &gEfiSioProtocolGuid, NULL},
1819 {STRING_TOKEN(STR_S_CPU2), &gEfiSmmCpuIo2ProtocolGuid, NULL},
1820 {STRING_TOKEN(STR_S_BASE2), &gEfiSmmBase2ProtocolGuid, NULL},
1821 {STRING_TOKEN(STR_S_ACC_2), &gEfiSmmAccess2ProtocolGuid, NULL},
1822 {STRING_TOKEN(STR_S_CON_2), &gEfiSmmControl2ProtocolGuid, NULL},
1823 {STRING_TOKEN(STR_S_CONFIG), &gEfiSmmConfigurationProtocolGuid, NULL},
1824 {STRING_TOKEN(STR_S_RTL), &gEfiSmmReadyToLockProtocolGuid, NULL},
1825 {STRING_TOKEN(STR_DS_RTL), &gEfiDxeSmmReadyToLockProtocolGuid, NULL},
1826 {STRING_TOKEN(STR_S_COMM), &gEfiSmmCommunicationProtocolGuid, NULL},
1827 {STRING_TOKEN(STR_S_STAT), &gEfiSmmStatusCodeProtocolGuid, NULL},
1828 {STRING_TOKEN(STR_S_CPU), &gEfiSmmCpuProtocolGuid, NULL},
1829 {STRING_TOKEN(STR_S_PCIRBIO), &gEfiPciRootBridgeIoProtocolGuid, NULL},
1830 {STRING_TOKEN(STR_S_SWD), &gEfiSmmSwDispatch2ProtocolGuid, NULL},
1831 {STRING_TOKEN(STR_S_SXD), &gEfiSmmSxDispatch2ProtocolGuid, NULL},
1832 {STRING_TOKEN(STR_S_PTD2), &gEfiSmmPeriodicTimerDispatch2ProtocolGuid, NULL},
1833 {STRING_TOKEN(STR_S_UD2), &gEfiSmmUsbDispatch2ProtocolGuid, NULL},
1834 {STRING_TOKEN(STR_S_GD2), &gEfiSmmGpiDispatch2ProtocolGuid, NULL},
1835 {STRING_TOKEN(STR_S_SBD2), &gEfiSmmStandbyButtonDispatch2ProtocolGuid, NULL},
1836 {STRING_TOKEN(STR_S_PBD2), &gEfiSmmPowerButtonDispatch2ProtocolGuid, NULL},
1837 {STRING_TOKEN(STR_S_ITD2), &gEfiSmmIoTrapDispatch2ProtocolGuid, NULL},
1838 {STRING_TOKEN(STR_PCD), &gEfiPcdProtocolGuid, NULL},
1839 {STRING_TOKEN(STR_FVB2), &gEfiFirmwareVolumeBlock2ProtocolGuid, NULL},
1840 {STRING_TOKEN(STR_CPUIO2), &gEfiCpuIo2ProtocolGuid, NULL},
1841 {STRING_TOKEN(STR_LEGACY_R2), &gEfiLegacyRegion2ProtocolGuid, NULL},
1842 {STRING_TOKEN(STR_SAL_MIP), &gEfiSalMcaInitPmiProtocolGuid, NULL},
1843 {STRING_TOKEN(STR_ES_BS), &gEfiExtendedSalBootServiceProtocolGuid, NULL},
1844 {STRING_TOKEN(STR_ES_BIO), &gEfiExtendedSalBaseIoServicesProtocolGuid, NULL},
1845 {STRING_TOKEN(STR_ES_STALL), &gEfiExtendedSalStallServicesProtocolGuid, NULL},
1846 {STRING_TOKEN(STR_ES_RTC), &gEfiExtendedSalRtcServicesProtocolGuid, NULL},
1847 {STRING_TOKEN(STR_ES_VS), &gEfiExtendedSalVariableServicesProtocolGuid, NULL},
1848 {STRING_TOKEN(STR_ES_MTC), &gEfiExtendedSalMtcServicesProtocolGuid, NULL},
1849 {STRING_TOKEN(STR_ES_RESET), &gEfiExtendedSalResetServicesProtocolGuid, NULL},
1850 {STRING_TOKEN(STR_ES_SC), &gEfiExtendedSalStatusCodeServicesProtocolGuid, NULL},
1851 {STRING_TOKEN(STR_ES_FBS), &gEfiExtendedSalFvBlockServicesProtocolGuid, NULL},
1852 {STRING_TOKEN(STR_ES_MP), &gEfiExtendedSalMpServicesProtocolGuid, NULL},
1853 {STRING_TOKEN(STR_ES_PAL), &gEfiExtendedSalPalServicesProtocolGuid, NULL},
1854 {STRING_TOKEN(STR_ES_BASE), &gEfiExtendedSalBaseServicesProtocolGuid, NULL},
1855 {STRING_TOKEN(STR_ES_MCA), &gEfiExtendedSalMcaServicesProtocolGuid, NULL},
1856 {STRING_TOKEN(STR_ES_PCI), &gEfiExtendedSalPciServicesProtocolGuid, NULL},
1857 {STRING_TOKEN(STR_ES_CACHE), &gEfiExtendedSalCacheServicesProtocolGuid, NULL},
1858 {STRING_TOKEN(STR_ES_MCA_LOG), &gEfiExtendedSalMcaLogServicesProtocolGuid, NULL},
1859 {STRING_TOKEN(STR_S2ARCH), &gEfiSecurity2ArchProtocolGuid, NULL},
1860 {STRING_TOKEN(STR_EODXE), &gEfiSmmEndOfDxeProtocolGuid, NULL},
1861 {STRING_TOKEN(STR_ISAHC), &gEfiIsaHcProtocolGuid, NULL},
1862 {STRING_TOKEN(STR_ISAHC_B), &gEfiIsaHcServiceBindingProtocolGuid, NULL},
1863 {STRING_TOKEN(STR_SIO_C), &gEfiSioControlProtocolGuid, NULL},
1864 {STRING_TOKEN(STR_GET_PCD), &gEfiGetPcdInfoProtocolGuid, NULL},
1865 {STRING_TOKEN(STR_I2C_M), &gEfiI2cMasterProtocolGuid, NULL},
1866 {STRING_TOKEN(STR_I2CIO), &gEfiI2cIoProtocolGuid, NULL},
1867 {STRING_TOKEN(STR_I2CEN), &gEfiI2cEnumerateProtocolGuid, NULL},
1868 {STRING_TOKEN(STR_I2C_H), &gEfiI2cHostProtocolGuid, NULL},
1869 {STRING_TOKEN(STR_I2C_BCM), &gEfiI2cBusConfigurationManagementProtocolGuid, NULL},
1870 {STRING_TOKEN(STR_TREE), &gEfiTrEEProtocolGuid, NULL},
1871 {STRING_TOKEN(STR_TCG2), &gEfiTcg2ProtocolGuid, NULL},
1872 {STRING_TOKEN(STR_TIMESTAMP), &gEfiTimestampProtocolGuid, NULL},
1873 {STRING_TOKEN(STR_RNG), &gEfiRngProtocolGuid, NULL},
1874 {STRING_TOKEN(STR_NVMEPT), &gEfiNvmExpressPassThruProtocolGuid, NULL},
1875 {STRING_TOKEN(STR_H2_SB), &gEfiHash2ServiceBindingProtocolGuid, NULL},
1876 {STRING_TOKEN(STR_HASH2), &gEfiHash2ProtocolGuid, NULL},
1877 {STRING_TOKEN(STR_BIO_C), &gEfiBlockIoCryptoProtocolGuid, NULL},
1878 {STRING_TOKEN(STR_SCR), &gEfiSmartCardReaderProtocolGuid, NULL},
1879 {STRING_TOKEN(STR_SCE), &gEfiSmartCardEdgeProtocolGuid, NULL},
1880 {STRING_TOKEN(STR_USB_FIO), &gEfiUsbFunctionIoProtocolGuid, NULL},
1881 {STRING_TOKEN(STR_BC_HC), &gEfiBluetoothHcProtocolGuid, NULL},
1882 {STRING_TOKEN(STR_BC_IO_SB), &gEfiBluetoothIoServiceBindingProtocolGuid, NULL},
1883 {STRING_TOKEN(STR_BC_IO), &gEfiBluetoothIoProtocolGuid, NULL},
1884 {STRING_TOKEN(STR_BC_C), &gEfiBluetoothConfigProtocolGuid, NULL},
1885 {STRING_TOKEN(STR_REG_EXP), &gEfiRegularExpressionProtocolGuid, NULL},
1886 {STRING_TOKEN(STR_B_MGR_P), &gEfiBootManagerPolicyProtocolGuid, NULL},
1887 {STRING_TOKEN(STR_CKH), &gEfiConfigKeywordHandlerProtocolGuid, NULL},
1888 {STRING_TOKEN(STR_WIFI), &gEfiWiFiProtocolGuid, NULL},
1889 {STRING_TOKEN(STR_EAP_M), &gEfiEapManagement2ProtocolGuid, NULL},
1890 {STRING_TOKEN(STR_EAP_C), &gEfiEapConfigurationProtocolGuid, NULL},
1891 {STRING_TOKEN(STR_PKCS7), &gEfiPkcs7VerifyProtocolGuid, NULL},
1892 {STRING_TOKEN(STR_NET_DNS4_SB), &gEfiDns4ServiceBindingProtocolGuid, NULL},
1893 {STRING_TOKEN(STR_NET_DNS4), &gEfiDns4ProtocolGuid, NULL},
1894 {STRING_TOKEN(STR_NET_DNS6_SB), &gEfiDns6ServiceBindingProtocolGuid, NULL},
1895 {STRING_TOKEN(STR_NET_DNS6), &gEfiDns6ProtocolGuid, NULL},
1896 {STRING_TOKEN(STR_NET_HTTP_SB), &gEfiHttpServiceBindingProtocolGuid, NULL},
1897 {STRING_TOKEN(STR_NET_HTTP), &gEfiHttpProtocolGuid, NULL},
1898 {STRING_TOKEN(STR_NET_HTTP_U), &gEfiHttpUtilitiesProtocolGuid, NULL},
1899 {STRING_TOKEN(STR_REST), &gEfiRestProtocolGuid, NULL},
1900
1901 //
1902 // UEFI Shell Spec 2.0
1903 //
1904 {STRING_TOKEN(STR_SHELL_PARAMETERS), &gEfiShellParametersProtocolGuid, NULL},
1905 {STRING_TOKEN(STR_SHELL), &gEfiShellProtocolGuid, NULL},
1906
1907 //
1908 // UEFI Shell Spec 2.1
1909 //
1910 {STRING_TOKEN(STR_SHELL_DYNAMIC), &gEfiShellDynamicCommandProtocolGuid, NULL},
1911
1912 //
1913 // Misc
1914 //
1915 {STRING_TOKEN(STR_PCDINFOPROT), &gGetPcdInfoProtocolGuid, NULL},
1916
1917 //
1918 // terminator
1919 //
1920 {0, NULL, NULL},
1921 };
1922
1923 /**
1924 Function to get the node for a protocol or struct from it's GUID.
1925
1926 if Guid is NULL, then ASSERT.
1927
1928 @param[in] Guid The GUID to look for the name of.
1929
1930 @return The node.
1931 **/
1932 CONST GUID_INFO_BLOCK *
1933 InternalShellGetNodeFromGuid(
1934 IN CONST EFI_GUID* Guid
1935 )
1936 {
1937 CONST GUID_INFO_BLOCK *ListWalker;
1938 UINTN LoopCount;
1939
1940 ASSERT(Guid != NULL);
1941
1942 for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) {
1943 if (CompareGuid(ListWalker->GuidId, Guid)) {
1944 return (ListWalker);
1945 }
1946 }
1947
1948 if (PcdGetBool(PcdShellIncludeNtGuids)) {
1949 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
1950 if (CompareGuid(ListWalker->GuidId, Guid)) {
1951 return (ListWalker);
1952 }
1953 }
1954 }
1955 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
1956 if (CompareGuid(ListWalker->GuidId, Guid)) {
1957 return (ListWalker);
1958 }
1959 }
1960 return (NULL);
1961 }
1962
1963 /**
1964 Function to add a new GUID/Name mapping.
1965
1966 @param[in] Guid The Guid
1967 @param[in] NameID The STRING id of the HII string to use
1968 @param[in] DumpFunc The pointer to the dump function
1969
1970
1971 @retval EFI_SUCCESS The operation was sucessful
1972 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1973 @retval EFI_INVALID_PARAMETER Guid NameId was invalid
1974 **/
1975 EFI_STATUS
1976 InsertNewGuidNameMapping(
1977 IN CONST EFI_GUID *Guid,
1978 IN CONST EFI_STRING_ID NameID,
1979 IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
1980 )
1981 {
1982 ASSERT(Guid != NULL);
1983 ASSERT(NameID != 0);
1984
1985 mGuidList = ReallocatePool(mGuidListCount * sizeof(GUID_INFO_BLOCK), mGuidListCount+1 * sizeof(GUID_INFO_BLOCK), mGuidList);
1986 if (mGuidList == NULL) {
1987 mGuidListCount = 0;
1988 return (EFI_OUT_OF_RESOURCES);
1989 }
1990 mGuidListCount++;
1991
1992 mGuidList[mGuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid);
1993 mGuidList[mGuidListCount - 1].StringId = NameID;
1994 mGuidList[mGuidListCount - 1].DumpInfo = DumpFunc;
1995
1996 if (mGuidList[mGuidListCount - 1].GuidId == NULL) {
1997 return (EFI_OUT_OF_RESOURCES);
1998 }
1999
2000 return (EFI_SUCCESS);
2001 }
2002
2003 /**
2004 Function to add a new GUID/Name mapping.
2005
2006 This cannot overwrite an existing mapping.
2007
2008 @param[in] Guid The Guid
2009 @param[in] TheName The Guid's name
2010 @param[in] Lang RFC4646 language code list or NULL
2011
2012 @retval EFI_SUCCESS The operation was sucessful
2013 @retval EFI_ACCESS_DENIED There was a duplicate
2014 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
2015 @retval EFI_INVALID_PARAMETER Guid or TheName was NULL
2016 **/
2017 EFI_STATUS
2018 EFIAPI
2019 AddNewGuidNameMapping(
2020 IN CONST EFI_GUID *Guid,
2021 IN CONST CHAR16 *TheName,
2022 IN CONST CHAR8 *Lang OPTIONAL
2023 )
2024 {
2025 EFI_STRING_ID NameID;
2026
2027 HandleParsingHiiInit();
2028
2029 if (Guid == NULL || TheName == NULL){
2030 return (EFI_INVALID_PARAMETER);
2031 }
2032
2033 if ((InternalShellGetNodeFromGuid(Guid)) != NULL) {
2034 return (EFI_ACCESS_DENIED);
2035 }
2036
2037 NameID = HiiSetString(mHandleParsingHiiHandle, 0, (CHAR16*)TheName, Lang);
2038 if (NameID == 0) {
2039 return (EFI_OUT_OF_RESOURCES);
2040 }
2041
2042 return (InsertNewGuidNameMapping(Guid, NameID, NULL));
2043 }
2044
2045 /**
2046 Function to get the name of a protocol or struct from it's GUID.
2047
2048 if Guid is NULL, then ASSERT.
2049
2050 @param[in] Guid The GUID to look for the name of.
2051 @param[in] Lang The language to use.
2052
2053 @return pointer to string of the name. The caller
2054 is responsible to free this memory.
2055 **/
2056 CHAR16*
2057 EFIAPI
2058 GetStringNameFromGuid(
2059 IN CONST EFI_GUID *Guid,
2060 IN CONST CHAR8 *Lang OPTIONAL
2061 )
2062 {
2063 CONST GUID_INFO_BLOCK *Id;
2064
2065 HandleParsingHiiInit();
2066
2067 Id = InternalShellGetNodeFromGuid(Guid);
2068 if (Id == NULL) {
2069 return NULL;
2070 }
2071 return HiiGetString (mHandleParsingHiiHandle, Id->StringId, Lang);
2072 }
2073
2074 /**
2075 Function to dump protocol information from a handle.
2076
2077 This function will return a allocated string buffer containing the
2078 information. The caller is responsible for freeing the memory.
2079
2080 If Guid is NULL, ASSERT().
2081 If TheHandle is NULL, ASSERT().
2082
2083 @param[in] TheHandle The handle to dump information from.
2084 @param[in] Guid The GUID of the protocol to dump.
2085 @param[in] Verbose TRUE for extra info. FALSE otherwise.
2086
2087 @return The pointer to string.
2088 @retval NULL An error was encountered.
2089 **/
2090 CHAR16*
2091 EFIAPI
2092 GetProtocolInformationDump(
2093 IN CONST EFI_HANDLE TheHandle,
2094 IN CONST EFI_GUID *Guid,
2095 IN CONST BOOLEAN Verbose
2096 )
2097 {
2098 CONST GUID_INFO_BLOCK *Id;
2099
2100 ASSERT(TheHandle != NULL);
2101 ASSERT(Guid != NULL);
2102
2103 if (TheHandle == NULL || Guid == NULL) {
2104 return (NULL);
2105 }
2106
2107 Id = InternalShellGetNodeFromGuid(Guid);
2108 if (Id != NULL && Id->DumpInfo != NULL) {
2109 return (Id->DumpInfo(TheHandle, Verbose));
2110 }
2111 return (NULL);
2112 }
2113
2114 /**
2115 Function to get the Guid for a protocol or struct based on it's string name.
2116
2117 do not modify the returned Guid.
2118
2119 @param[in] Name The pointer to the string name.
2120 @param[in] Lang The pointer to the language code.
2121 @param[out] Guid The pointer to the Guid.
2122
2123 @retval EFI_SUCCESS The operation was sucessful.
2124 **/
2125 EFI_STATUS
2126 EFIAPI
2127 GetGuidFromStringName(
2128 IN CONST CHAR16 *Name,
2129 IN CONST CHAR8 *Lang OPTIONAL,
2130 OUT EFI_GUID **Guid
2131 )
2132 {
2133 CONST GUID_INFO_BLOCK *ListWalker;
2134 CHAR16 *String;
2135 UINTN LoopCount;
2136
2137 HandleParsingHiiInit();
2138
2139 ASSERT(Guid != NULL);
2140 if (Guid == NULL) {
2141 return (EFI_INVALID_PARAMETER);
2142 }
2143 *Guid = NULL;
2144
2145 if (PcdGetBool(PcdShellIncludeNtGuids)) {
2146 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2147 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2148 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2149 *Guid = ListWalker->GuidId;
2150 }
2151 SHELL_FREE_NON_NULL(String);
2152 if (*Guid != NULL) {
2153 return (EFI_SUCCESS);
2154 }
2155 }
2156 }
2157 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2158 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2159 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2160 *Guid = ListWalker->GuidId;
2161 }
2162 SHELL_FREE_NON_NULL(String);
2163 if (*Guid != NULL) {
2164 return (EFI_SUCCESS);
2165 }
2166 }
2167
2168 for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) {
2169 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2170 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2171 *Guid = ListWalker->GuidId;
2172 }
2173 SHELL_FREE_NON_NULL(String);
2174 if (*Guid != NULL) {
2175 return (EFI_SUCCESS);
2176 }
2177 }
2178
2179 return (EFI_NOT_FOUND);
2180 }
2181
2182 /**
2183 Get best support language for this driver.
2184
2185 First base on the user input language to search, second base on the current
2186 platform used language to search, third get the first language from the
2187 support language list. The caller need to free the buffer of the best language.
2188
2189 @param[in] SupportedLanguages The support languages for this driver.
2190 @param[in] InputLanguage The user input language.
2191 @param[in] Iso639Language Whether get language for ISO639.
2192
2193 @return The best support language for this driver.
2194 **/
2195 CHAR8 *
2196 EFIAPI
2197 GetBestLanguageForDriver (
2198 IN CONST CHAR8 *SupportedLanguages,
2199 IN CONST CHAR8 *InputLanguage,
2200 IN BOOLEAN Iso639Language
2201 )
2202 {
2203 CHAR8 *LanguageVariable;
2204 CHAR8 *BestLanguage;
2205
2206 GetVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid, (VOID**)&LanguageVariable, NULL);
2207
2208 BestLanguage = GetBestLanguage(
2209 SupportedLanguages,
2210 Iso639Language,
2211 (InputLanguage != NULL) ? InputLanguage : "",
2212 (LanguageVariable != NULL) ? LanguageVariable : "",
2213 SupportedLanguages,
2214 NULL
2215 );
2216
2217 if (LanguageVariable != NULL) {
2218 FreePool (LanguageVariable);
2219 }
2220
2221 return BestLanguage;
2222 }
2223
2224 /**
2225 Function to retrieve the driver name (if possible) from the ComponentName or
2226 ComponentName2 protocol
2227
2228 @param[in] TheHandle The driver handle to get the name of.
2229 @param[in] Language The language to use.
2230
2231 @retval NULL The name could not be found.
2232 @return A pointer to the string name. Do not de-allocate the memory.
2233 **/
2234 CONST CHAR16*
2235 EFIAPI
2236 GetStringNameFromHandle(
2237 IN CONST EFI_HANDLE TheHandle,
2238 IN CONST CHAR8 *Language
2239 )
2240 {
2241 EFI_COMPONENT_NAME2_PROTOCOL *CompNameStruct;
2242 EFI_STATUS Status;
2243 CHAR16 *RetVal;
2244 CHAR8 *BestLang;
2245
2246 BestLang = NULL;
2247
2248 Status = gBS->OpenProtocol(
2249 TheHandle,
2250 &gEfiComponentName2ProtocolGuid,
2251 (VOID**)&CompNameStruct,
2252 gImageHandle,
2253 NULL,
2254 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2255 if (!EFI_ERROR(Status)) {
2256 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
2257 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
2258 if (BestLang != NULL) {
2259 FreePool (BestLang);
2260 BestLang = NULL;
2261 }
2262 if (!EFI_ERROR(Status)) {
2263 return (RetVal);
2264 }
2265 }
2266 Status = gBS->OpenProtocol(
2267 TheHandle,
2268 &gEfiComponentNameProtocolGuid,
2269 (VOID**)&CompNameStruct,
2270 gImageHandle,
2271 NULL,
2272 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2273 if (!EFI_ERROR(Status)) {
2274 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
2275 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
2276 if (BestLang != NULL) {
2277 FreePool (BestLang);
2278 }
2279 if (!EFI_ERROR(Status)) {
2280 return (RetVal);
2281 }
2282 }
2283 return (NULL);
2284 }
2285
2286 /**
2287 Function to initialize the file global mHandleList object for use in
2288 vonverting handles to index and index to handle.
2289
2290 @retval EFI_SUCCESS The operation was successful.
2291 **/
2292 EFI_STATUS
2293 InternalShellInitHandleList(
2294 VOID
2295 )
2296 {
2297 EFI_STATUS Status;
2298 EFI_HANDLE *HandleBuffer;
2299 UINTN HandleCount;
2300 HANDLE_LIST *ListWalker;
2301
2302 if (mHandleList.NextIndex != 0) {
2303 return EFI_SUCCESS;
2304 }
2305 InitializeListHead(&mHandleList.List.Link);
2306 mHandleList.NextIndex = 1;
2307 Status = gBS->LocateHandleBuffer (
2308 AllHandles,
2309 NULL,
2310 NULL,
2311 &HandleCount,
2312 &HandleBuffer
2313 );
2314 ASSERT_EFI_ERROR(Status);
2315 if (EFI_ERROR(Status)) {
2316 return (Status);
2317 }
2318 for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){
2319 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
2320 if (ListWalker != NULL) {
2321 ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex - 1];
2322 ListWalker->TheIndex = mHandleList.NextIndex;
2323 InsertTailList (&mHandleList.List.Link, &ListWalker->Link);
2324 }
2325 }
2326 FreePool(HandleBuffer);
2327 return (EFI_SUCCESS);
2328 }
2329
2330 /**
2331 Function to retrieve the human-friendly index of a given handle. If the handle
2332 does not have a index one will be automatically assigned. The index value is valid
2333 until the termination of the shell application.
2334
2335 @param[in] TheHandle The handle to retrieve an index for.
2336
2337 @retval 0 A memory allocation failed.
2338 @return The index of the handle.
2339
2340 **/
2341 UINTN
2342 EFIAPI
2343 ConvertHandleToHandleIndex(
2344 IN CONST EFI_HANDLE TheHandle
2345 )
2346 {
2347 EFI_STATUS Status;
2348 EFI_GUID **ProtocolBuffer;
2349 UINTN ProtocolCount;
2350 HANDLE_LIST *ListWalker;
2351
2352 if (TheHandle == NULL) {
2353 return 0;
2354 }
2355
2356 InternalShellInitHandleList();
2357
2358 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
2359 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
2360 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
2361 ){
2362 if (ListWalker->TheHandle == TheHandle) {
2363 //
2364 // Verify that TheHandle is still present in the Handle Database
2365 //
2366 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
2367 if (EFI_ERROR (Status)) {
2368 //
2369 // TheHandle is not present in the Handle Database, so delete from the handle list
2370 //
2371 RemoveEntryList (&ListWalker->Link);
2372 return 0;
2373 }
2374 FreePool (ProtocolBuffer);
2375 return (ListWalker->TheIndex);
2376 }
2377 }
2378
2379 //
2380 // Verify that TheHandle is valid handle
2381 //
2382 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
2383 if (EFI_ERROR (Status)) {
2384 //
2385 // TheHandle is not valid, so do not add to handle list
2386 //
2387 return 0;
2388 }
2389 FreePool (ProtocolBuffer);
2390
2391 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
2392 if (ListWalker == NULL) {
2393 return 0;
2394 }
2395 ListWalker->TheHandle = TheHandle;
2396 ListWalker->TheIndex = mHandleList.NextIndex++;
2397 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);
2398 return (ListWalker->TheIndex);
2399 }
2400
2401
2402
2403 /**
2404 Function to retrieve the EFI_HANDLE from the human-friendly index.
2405
2406 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
2407
2408 @retval NULL The index was invalid.
2409 @return The EFI_HANDLE that index represents.
2410
2411 **/
2412 EFI_HANDLE
2413 EFIAPI
2414 ConvertHandleIndexToHandle(
2415 IN CONST UINTN TheIndex
2416 )
2417 {
2418 EFI_STATUS Status;
2419 EFI_GUID **ProtocolBuffer;
2420 UINTN ProtocolCount;
2421 HANDLE_LIST *ListWalker;
2422
2423 InternalShellInitHandleList();
2424
2425 if (TheIndex >= mHandleList.NextIndex) {
2426 return NULL;
2427 }
2428
2429 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
2430 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
2431 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
2432 ){
2433 if (ListWalker->TheIndex == TheIndex && ListWalker->TheHandle != NULL) {
2434 //
2435 // Verify that LinkWalker->TheHandle is valid handle
2436 //
2437 Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);
2438 if (!EFI_ERROR (Status)) {
2439 FreePool (ProtocolBuffer);
2440 } else {
2441 //
2442 // TheHandle is not valid, so do not add to handle list
2443 //
2444 ListWalker->TheHandle = NULL;
2445 }
2446 return (ListWalker->TheHandle);
2447 }
2448 }
2449 return NULL;
2450 }
2451
2452 /**
2453 Gets all the related EFI_HANDLEs based on the mask supplied.
2454
2455 This function scans all EFI_HANDLES in the UEFI environment's handle database
2456 and returns the ones with the specified relationship (Mask) to the specified
2457 controller handle.
2458
2459 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
2460 If MatchingHandleCount is NULL, then ASSERT.
2461
2462 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
2463 caller freed.
2464
2465 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
2466 @param[in] ControllerHandle The handle with Device Path protocol on it.
2467 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
2468 MatchingHandleBuffer.
2469 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
2470 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
2471 @param[out] HandleType An array of type information.
2472
2473 @retval EFI_SUCCESS The operation was successful, and any related handles
2474 are in MatchingHandleBuffer.
2475 @retval EFI_NOT_FOUND No matching handles were found.
2476 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
2477 **/
2478 EFI_STATUS
2479 EFIAPI
2480 ParseHandleDatabaseByRelationshipWithType (
2481 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
2482 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
2483 IN UINTN *HandleCount,
2484 OUT EFI_HANDLE **HandleBuffer,
2485 OUT UINTN **HandleType
2486 )
2487 {
2488 EFI_STATUS Status;
2489 UINTN HandleIndex;
2490 EFI_GUID **ProtocolGuidArray;
2491 UINTN ArrayCount;
2492 UINTN ProtocolIndex;
2493 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
2494 UINTN OpenInfoCount;
2495 UINTN OpenInfoIndex;
2496 UINTN ChildIndex;
2497 INTN DriverBindingHandleIndex;
2498
2499 ASSERT(HandleCount != NULL);
2500 ASSERT(HandleBuffer != NULL);
2501 ASSERT(HandleType != NULL);
2502 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
2503
2504 *HandleCount = 0;
2505 *HandleBuffer = NULL;
2506 *HandleType = NULL;
2507
2508 //
2509 // Retrieve the list of all handles from the handle database
2510 //
2511 Status = gBS->LocateHandleBuffer (
2512 AllHandles,
2513 NULL,
2514 NULL,
2515 HandleCount,
2516 HandleBuffer
2517 );
2518 if (EFI_ERROR (Status)) {
2519 return (Status);
2520 }
2521
2522 *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));
2523 if (*HandleType == NULL) {
2524 SHELL_FREE_NON_NULL (*HandleBuffer);
2525 *HandleCount = 0;
2526 return EFI_OUT_OF_RESOURCES;
2527 }
2528
2529 DriverBindingHandleIndex = -1;
2530 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
2531 if (DriverBindingHandle != NULL && (*HandleBuffer)[HandleIndex] == DriverBindingHandle) {
2532 DriverBindingHandleIndex = (INTN)HandleIndex;
2533 }
2534 }
2535
2536 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
2537 //
2538 // Retrieve the list of all the protocols on each handle
2539 //
2540 Status = gBS->ProtocolsPerHandle (
2541 (*HandleBuffer)[HandleIndex],
2542 &ProtocolGuidArray,
2543 &ArrayCount
2544 );
2545 if (EFI_ERROR (Status)) {
2546 continue;
2547 }
2548
2549 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
2550
2551 //
2552 // Set the bit describing what this handle has
2553 //
2554 if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) ) {
2555 (*HandleType)[HandleIndex] |= (UINTN)HR_IMAGE_HANDLE;
2556 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) ) {
2557 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_BINDING_HANDLE;
2558 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {
2559 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
2560 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {
2561 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
2562 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) ) {
2563 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
2564 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) ) {
2565 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
2566 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) ) {
2567 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
2568 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) ) {
2569 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
2570 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) {
2571 (*HandleType)[HandleIndex] |= (UINTN)HR_DEVICE_HANDLE;
2572 }
2573 //
2574 // Retrieve the list of agents that have opened each protocol
2575 //
2576 Status = gBS->OpenProtocolInformation (
2577 (*HandleBuffer)[HandleIndex],
2578 ProtocolGuidArray[ProtocolIndex],
2579 &OpenInfo,
2580 &OpenInfoCount
2581 );
2582 if (EFI_ERROR (Status)) {
2583 continue;
2584 }
2585
2586 if (ControllerHandle == NULL) {
2587 //
2588 // ControllerHandle == NULL and DriverBindingHandle != NULL.
2589 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
2590 //
2591 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2592 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2593 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2594 if (DriverBindingHandleIndex != -1) {
2595 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
2596 }
2597 }
2598 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2599 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2600 if (DriverBindingHandleIndex != -1) {
2601 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2602 }
2603 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2604 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2605 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2606 }
2607 }
2608 }
2609 }
2610 }
2611 if (DriverBindingHandle == NULL && ControllerHandle != NULL) {
2612 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
2613 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2614 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2615 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2616 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2617 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2618 (*HandleType)[ChildIndex] |= (UINTN)HR_DEVICE_DRIVER;
2619 }
2620 }
2621 }
2622 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2623 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2624 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2625 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2626 }
2627 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2628 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2629 }
2630 }
2631 }
2632 }
2633 } else {
2634 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2635 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2636 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
2637 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
2638 }
2639 }
2640 }
2641 }
2642 }
2643 if (DriverBindingHandle != NULL && ControllerHandle != NULL) {
2644 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
2645 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2646 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2647 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2648 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
2649 if (DriverBindingHandleIndex != -1) {
2650 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
2651 }
2652 }
2653 }
2654 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2655 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
2656 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2657 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2658 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2659 }
2660 }
2661 }
2662
2663 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2664 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2665 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2666 }
2667 }
2668 }
2669 }
2670 } else {
2671 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2672 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2673 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
2674 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
2675 }
2676 }
2677 }
2678 }
2679 }
2680 FreePool (OpenInfo);
2681 }
2682 FreePool (ProtocolGuidArray);
2683 }
2684 return EFI_SUCCESS;
2685 }
2686
2687 /**
2688 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
2689 supplied.
2690
2691 This function will scan all EFI_HANDLES in the UEFI environment's handle database
2692 and return all the ones with the specified relationship (Mask) to the specified
2693 controller handle.
2694
2695 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
2696 If MatchingHandleCount is NULL, then ASSERT.
2697
2698 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
2699 caller freed.
2700
2701 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
2702 on it.
2703 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
2704 @param[in] Mask Mask of what relationship(s) is desired.
2705 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
2706 MatchingHandleBuffer.
2707 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
2708 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
2709
2710 @retval EFI_SUCCESS The operation was sucessful and any related handles
2711 are in MatchingHandleBuffer;
2712 @retval EFI_NOT_FOUND No matching handles were found.
2713 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
2714 **/
2715 EFI_STATUS
2716 EFIAPI
2717 ParseHandleDatabaseByRelationship (
2718 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
2719 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
2720 IN CONST UINTN Mask,
2721 IN UINTN *MatchingHandleCount,
2722 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
2723 )
2724 {
2725 EFI_STATUS Status;
2726 UINTN HandleCount;
2727 EFI_HANDLE *HandleBuffer;
2728 UINTN *HandleType;
2729 UINTN HandleIndex;
2730
2731 ASSERT(MatchingHandleCount != NULL);
2732 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
2733
2734 if ((Mask & HR_VALID_MASK) != Mask) {
2735 return (EFI_INVALID_PARAMETER);
2736 }
2737
2738 if ((Mask & HR_CHILD_HANDLE) != 0 && DriverBindingHandle == NULL) {
2739 return (EFI_INVALID_PARAMETER);
2740 }
2741
2742 *MatchingHandleCount = 0;
2743 if (MatchingHandleBuffer != NULL) {
2744 *MatchingHandleBuffer = NULL;
2745 }
2746
2747 HandleBuffer = NULL;
2748 HandleType = NULL;
2749
2750 Status = ParseHandleDatabaseByRelationshipWithType (
2751 DriverBindingHandle,
2752 ControllerHandle,
2753 &HandleCount,
2754 &HandleBuffer,
2755 &HandleType
2756 );
2757 if (!EFI_ERROR (Status)) {
2758 //
2759 // Count the number of handles that match the attributes in Mask
2760 //
2761 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
2762 if ((HandleType[HandleIndex] & Mask) == Mask) {
2763 (*MatchingHandleCount)++;
2764 }
2765 }
2766 //
2767 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
2768 //
2769 if (*MatchingHandleCount == 0) {
2770 Status = EFI_NOT_FOUND;
2771 } else {
2772
2773 if (MatchingHandleBuffer == NULL) {
2774 //
2775 // Someone just wanted the count...
2776 //
2777 Status = EFI_SUCCESS;
2778 } else {
2779 //
2780 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
2781 //
2782 *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE));
2783 if (*MatchingHandleBuffer == NULL) {
2784 Status = EFI_OUT_OF_RESOURCES;
2785 } else {
2786 for (HandleIndex = 0, *MatchingHandleCount = 0
2787 ; HandleIndex < HandleCount
2788 ; HandleIndex++
2789 ) {
2790 //
2791 // Fill the allocated buffer with the handles that matched the attributes in Mask
2792 //
2793 if ((HandleType[HandleIndex] & Mask) == Mask) {
2794 (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex];
2795 }
2796 }
2797
2798 //
2799 // Make the last one NULL
2800 //
2801 (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL;
2802
2803 Status = EFI_SUCCESS;
2804 } // *MatchingHandleBuffer == NULL (ELSE)
2805 } // MacthingHandleBuffer == NULL (ELSE)
2806 } // *MatchingHandleCount == 0 (ELSE)
2807 } // no error on ParseHandleDatabaseByRelationshipWithType
2808
2809 if (HandleBuffer != NULL) {
2810 FreePool (HandleBuffer);
2811 }
2812
2813 if (HandleType != NULL) {
2814 FreePool (HandleType);
2815 }
2816
2817 ASSERT ((MatchingHandleBuffer == NULL) ||
2818 (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
2819 (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
2820 return Status;
2821 }
2822
2823 /**
2824 Gets handles for any child controllers of the passed in controller.
2825
2826 @param[in] ControllerHandle The handle of the "parent controller"
2827 @param[out] MatchingHandleCount Pointer to the number of handles in
2828 MatchingHandleBuffer on return.
2829 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
2830 return.
2831
2832
2833 @retval EFI_SUCCESS The operation was sucessful.
2834 **/
2835 EFI_STATUS
2836 EFIAPI
2837 ParseHandleDatabaseForChildControllers(
2838 IN CONST EFI_HANDLE ControllerHandle,
2839 OUT UINTN *MatchingHandleCount,
2840 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
2841 )
2842 {
2843 EFI_STATUS Status;
2844 UINTN HandleIndex;
2845 UINTN DriverBindingHandleCount;
2846 EFI_HANDLE *DriverBindingHandleBuffer;
2847 UINTN DriverBindingHandleIndex;
2848 UINTN ChildControllerHandleCount;
2849 EFI_HANDLE *ChildControllerHandleBuffer;
2850 UINTN ChildControllerHandleIndex;
2851 EFI_HANDLE *HandleBufferForReturn;
2852
2853 if (MatchingHandleCount == NULL) {
2854 return (EFI_INVALID_PARAMETER);
2855 }
2856 *MatchingHandleCount = 0;
2857
2858 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
2859 ControllerHandle,
2860 &DriverBindingHandleCount,
2861 &DriverBindingHandleBuffer
2862 );
2863 if (EFI_ERROR (Status)) {
2864 return Status;
2865 }
2866
2867 //
2868 // Get a buffer big enough for all the controllers.
2869 //
2870 HandleBufferForReturn = GetHandleListByProtocol(NULL);
2871 if (HandleBufferForReturn == NULL) {
2872 FreePool (DriverBindingHandleBuffer);
2873 return (EFI_NOT_FOUND);
2874 }
2875
2876 for (DriverBindingHandleIndex = 0; DriverBindingHandleIndex < DriverBindingHandleCount; DriverBindingHandleIndex++) {
2877 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
2878 DriverBindingHandleBuffer[DriverBindingHandleIndex],
2879 ControllerHandle,
2880 &ChildControllerHandleCount,
2881 &ChildControllerHandleBuffer
2882 );
2883 if (EFI_ERROR (Status)) {
2884 continue;
2885 }
2886
2887 for (ChildControllerHandleIndex = 0;
2888 ChildControllerHandleIndex < ChildControllerHandleCount;
2889 ChildControllerHandleIndex++
2890 ) {
2891 for (HandleIndex = 0; HandleIndex < *MatchingHandleCount; HandleIndex++) {
2892 if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {
2893 break;
2894 }
2895 }
2896 if (HandleIndex >= *MatchingHandleCount) {
2897 HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
2898 }
2899 }
2900
2901 FreePool (ChildControllerHandleBuffer);
2902 }
2903
2904 FreePool (DriverBindingHandleBuffer);
2905
2906 if (MatchingHandleBuffer == NULL || *MatchingHandleCount == 0) {
2907 //
2908 // The caller is not interested in the actual handles, or we've found none.
2909 //
2910 FreePool (HandleBufferForReturn);
2911 HandleBufferForReturn = NULL;
2912 }
2913
2914 if (MatchingHandleBuffer != NULL) {
2915 *MatchingHandleBuffer = HandleBufferForReturn;
2916 }
2917
2918 ASSERT ((MatchingHandleBuffer == NULL) ||
2919 (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
2920 (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
2921
2922 return (EFI_SUCCESS);
2923 }
2924
2925 /**
2926 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
2927 if necessary to fit all of the data.
2928
2929 If DestinationBuffer is NULL, then ASSERT().
2930
2931 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
2932 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
2933 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
2934 @param[in] SourceSize The number of bytes of SourceBuffer to append.
2935
2936 @retval NULL A memory allocation failed.
2937 @retval NULL A parameter was invalid.
2938 @return A pointer to (*DestinationBuffer).
2939 **/
2940 VOID*
2941 BuffernCatGrow (
2942 IN OUT VOID **DestinationBuffer,
2943 IN OUT UINTN *DestinationSize,
2944 IN VOID *SourceBuffer,
2945 IN UINTN SourceSize
2946 )
2947 {
2948 UINTN LocalDestinationSize;
2949 UINTN LocalDestinationFinalSize;
2950
2951 ASSERT(DestinationBuffer != NULL);
2952
2953 if (SourceSize == 0 || SourceBuffer == NULL) {
2954 return (*DestinationBuffer);
2955 }
2956
2957 if (DestinationSize == NULL) {
2958 LocalDestinationSize = 0;
2959 } else {
2960 LocalDestinationSize = *DestinationSize;
2961 }
2962
2963 LocalDestinationFinalSize = LocalDestinationSize + SourceSize;
2964
2965 if (DestinationSize != NULL) {
2966 *DestinationSize = LocalDestinationSize;
2967 }
2968
2969 if (LocalDestinationSize == 0) {
2970 // allcoate
2971 *DestinationBuffer = AllocateZeroPool(LocalDestinationFinalSize);
2972 } else {
2973 // reallocate
2974 *DestinationBuffer = ReallocatePool(LocalDestinationSize, LocalDestinationFinalSize, *DestinationBuffer);
2975 }
2976
2977 ASSERT(*DestinationBuffer != NULL);
2978
2979 // copy
2980 return (CopyMem(((UINT8*)(*DestinationBuffer)) + LocalDestinationSize, SourceBuffer, SourceSize));
2981 }
2982
2983 /**
2984 Gets handles for any child devices produced by the passed in driver.
2985
2986 @param[in] DriverHandle The handle of the driver.
2987 @param[in] MatchingHandleCount Pointer to the number of handles in
2988 MatchingHandleBuffer on return.
2989 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
2990 return.
2991 @retval EFI_SUCCESS The operation was sucessful.
2992 @sa ParseHandleDatabaseByRelationship
2993 **/
2994 EFI_STATUS
2995 EFIAPI
2996 ParseHandleDatabaseForChildDevices(
2997 IN CONST EFI_HANDLE DriverHandle,
2998 IN UINTN *MatchingHandleCount,
2999 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
3000 )
3001 {
3002 EFI_HANDLE *Buffer;
3003 EFI_HANDLE *Buffer2;
3004 UINTN Count1;
3005 UINTN Count2;
3006 UINTN HandleIndex;
3007 EFI_STATUS Status;
3008 UINTN HandleBufferSize;
3009
3010 ASSERT(MatchingHandleCount != NULL);
3011
3012 HandleBufferSize = 0;
3013 Buffer = NULL;
3014 Buffer2 = NULL;
3015 *MatchingHandleCount = 0;
3016
3017 Status = PARSE_HANDLE_DATABASE_DEVICES (
3018 DriverHandle,
3019 &Count1,
3020 &Buffer
3021 );
3022 if (!EFI_ERROR (Status)) {
3023 for (HandleIndex = 0; HandleIndex < Count1; HandleIndex++) {
3024 //
3025 // now find the children
3026 //
3027 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
3028 DriverHandle,
3029 Buffer[HandleIndex],
3030 &Count2,
3031 &Buffer2
3032 );
3033 if (EFI_ERROR(Status)) {
3034 break;
3035 }
3036 //
3037 // save out required and optional data elements
3038 //
3039 *MatchingHandleCount += Count2;
3040 if (MatchingHandleBuffer != NULL) {
3041 *MatchingHandleBuffer = BuffernCatGrow((VOID**)MatchingHandleBuffer, &HandleBufferSize, Buffer2, Count2 * sizeof(Buffer2[0]));
3042 }
3043
3044 //
3045 // free the memory
3046 //
3047 if (Buffer2 != NULL) {
3048 FreePool(Buffer2);
3049 }
3050 }
3051 }
3052
3053 if (Buffer != NULL) {
3054 FreePool(Buffer);
3055 }
3056 return (Status);
3057 }
3058
3059 /**
3060 Function to get all handles that support a given protocol or all handles.
3061
3062 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
3063 then the function will return all handles.
3064
3065 @retval NULL A memory allocation failed.
3066 @return A NULL terminated list of handles.
3067 **/
3068 EFI_HANDLE*
3069 EFIAPI
3070 GetHandleListByProtocol (
3071 IN CONST EFI_GUID *ProtocolGuid OPTIONAL
3072 )
3073 {
3074 EFI_HANDLE *HandleList;
3075 UINTN Size;
3076 EFI_STATUS Status;
3077
3078 Size = 0;
3079 HandleList = NULL;
3080
3081 //
3082 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
3083 //
3084 if (ProtocolGuid == NULL) {
3085 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
3086 if (Status == EFI_BUFFER_TOO_SMALL) {
3087 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
3088 if (HandleList == NULL) {
3089 return (NULL);
3090 }
3091 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
3092 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
3093 }
3094 } else {
3095 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
3096 if (Status == EFI_BUFFER_TOO_SMALL) {
3097 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
3098 if (HandleList == NULL) {
3099 return (NULL);
3100 }
3101 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
3102 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
3103 }
3104 }
3105 if (EFI_ERROR(Status)) {
3106 if (HandleList != NULL) {
3107 FreePool(HandleList);
3108 }
3109 return (NULL);
3110 }
3111 return (HandleList);
3112 }
3113
3114 /**
3115 Function to get all handles that support some protocols.
3116
3117 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
3118
3119 @retval NULL A memory allocation failed.
3120 @retval NULL ProtocolGuids was NULL.
3121 @return A NULL terminated list of EFI_HANDLEs.
3122 **/
3123 EFI_HANDLE*
3124 EFIAPI
3125 GetHandleListByProtocolList (
3126 IN CONST EFI_GUID **ProtocolGuids
3127 )
3128 {
3129 EFI_HANDLE *HandleList;
3130 UINTN Size;
3131 UINTN TotalSize;
3132 UINTN TempSize;
3133 EFI_STATUS Status;
3134 CONST EFI_GUID **GuidWalker;
3135 EFI_HANDLE *HandleWalker1;
3136 EFI_HANDLE *HandleWalker2;
3137
3138 Size = 0;
3139 HandleList = NULL;
3140 TotalSize = sizeof(EFI_HANDLE);
3141
3142 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++,Size = 0){
3143 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &Size, NULL);
3144 if (Status == EFI_BUFFER_TOO_SMALL) {
3145 TotalSize += Size;
3146 }
3147 }
3148
3149 //
3150 // No handles were found...
3151 //
3152 if (TotalSize == sizeof(EFI_HANDLE)) {
3153 return (NULL);
3154 }
3155
3156 HandleList = AllocateZeroPool(TotalSize);
3157 if (HandleList == NULL) {
3158 return (NULL);
3159 }
3160
3161 Size = 0;
3162 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++){
3163 TempSize = TotalSize - Size;
3164 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &TempSize, HandleList+(Size/sizeof(EFI_HANDLE)));
3165
3166 //
3167 // Allow for missing protocols... Only update the 'used' size upon success.
3168 //
3169 if (!EFI_ERROR(Status)) {
3170 Size += TempSize;
3171 }
3172 }
3173 ASSERT(HandleList[(TotalSize/sizeof(EFI_HANDLE))-1] == NULL);
3174
3175 for (HandleWalker1 = HandleList ; HandleWalker1 != NULL && *HandleWalker1 != NULL ; HandleWalker1++) {
3176 for (HandleWalker2 = HandleWalker1 + 1; HandleWalker2 != NULL && *HandleWalker2 != NULL ; HandleWalker2++) {
3177 if (*HandleWalker1 == *HandleWalker2) {
3178 //
3179 // copy memory back 1 handle width.
3180 //
3181 CopyMem(HandleWalker2, HandleWalker2 + 1, TotalSize - ((HandleWalker2-HandleList+1)*sizeof(EFI_HANDLE)));
3182 }
3183 }
3184 }
3185
3186 return (HandleList);
3187 }
3188
3189 /**
3190 Return all supported GUIDs.
3191
3192 @param[out] Guids The buffer to return all supported GUIDs.
3193 @param[in, out] Count On input, the count of GUIDs the buffer can hold,
3194 On output, the count of GUIDs to return.
3195
3196 @retval EFI_INVALID_PARAMETER Count is NULL.
3197 @retval EFI_BUFFER_TOO_SMALL Buffer is not enough to hold all GUIDs.
3198 @retval EFI_SUCCESS GUIDs are returned successfully.
3199 **/
3200 EFI_STATUS
3201 EFIAPI
3202 GetAllMappingGuids (
3203 OUT EFI_GUID *Guids,
3204 IN OUT UINTN *Count
3205 )
3206 {
3207 UINTN GuidCount;
3208 UINTN NtGuidCount;
3209 UINTN Index;
3210
3211 if (Count == NULL) {
3212 return EFI_INVALID_PARAMETER;
3213 }
3214
3215 NtGuidCount = 0;
3216 if (PcdGetBool (PcdShellIncludeNtGuids)) {
3217 NtGuidCount = ARRAY_SIZE (mGuidStringListNT) - 1;
3218 }
3219 GuidCount = ARRAY_SIZE (mGuidStringList) - 1;
3220
3221 if (*Count < NtGuidCount + GuidCount + mGuidListCount) {
3222 *Count = NtGuidCount + GuidCount + mGuidListCount;
3223 return EFI_BUFFER_TOO_SMALL;
3224 }
3225
3226 for (Index = 0; Index < NtGuidCount; Index++) {
3227 CopyGuid (&Guids[Index], mGuidStringListNT[Index].GuidId);
3228 }
3229
3230 for (Index = 0; Index < GuidCount; Index++) {
3231 CopyGuid (&Guids[NtGuidCount + Index], mGuidStringList[Index].GuidId);
3232 }
3233
3234 for (Index = 0; Index < mGuidListCount; Index++) {
3235 CopyGuid (&Guids[NtGuidCount + GuidCount + Index], mGuidList[Index].GuidId);
3236 }
3237
3238 return EFI_SUCCESS;
3239 }