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