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