]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DevicePathDxe/DevicePathToText.c
Code scrub for DevicePathDxe driver.
[mirror_edk2.git] / MdeModulePkg / Universal / DevicePathDxe / DevicePathToText.c
1 /** @file
2 DevicePathToText protocol as defined in the UEFI 2.0 specification.
3
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DevicePath.h"
16
17 /**
18 Function unpacks a device path data structure so that all the nodes of a device path
19 are naturally aligned.
20
21 @param DevPath A pointer to a device path data structure
22
23 @return If the memory for the device path is successfully allocated, then a pointer to the
24 new device path is returned. Otherwise, NULL is returned.
25
26 **/
27 EFI_DEVICE_PATH_PROTOCOL *
28 UnpackDevicePath (
29 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath
30 )
31 {
32 CONST EFI_DEVICE_PATH_PROTOCOL *Src;
33 EFI_DEVICE_PATH_PROTOCOL *Dest;
34 EFI_DEVICE_PATH_PROTOCOL *NewPath;
35 UINTN Size;
36
37 if (DevPath == NULL) {
38 return NULL;
39 }
40 //
41 // Walk device path and round sizes to valid boundries
42 //
43 Src = DevPath;
44 Size = 0;
45 for (;;) {
46 Size += DevicePathNodeLength (Src);
47 Size += ALIGN_SIZE (Size);
48
49 if (IsDevicePathEnd (Src)) {
50 break;
51 }
52
53 Src = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (Src);
54 }
55 //
56 // Allocate space for the unpacked path
57 //
58 NewPath = AllocateZeroPool (Size);
59 if (NewPath != NULL) {
60
61 ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0);
62
63 //
64 // Copy each node
65 //
66 Src = DevPath;
67 Dest = NewPath;
68 for (;;) {
69 Size = DevicePathNodeLength (Src);
70 CopyMem (Dest, Src, Size);
71 Size += ALIGN_SIZE (Size);
72 SetDevicePathNodeLength (Dest, Size);
73 Dest->Type |= EFI_DP_TYPE_UNPACKED;
74 Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size);
75
76 if (IsDevicePathEnd (Src)) {
77 break;
78 }
79
80 Src = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (Src);
81 }
82 }
83
84 return NewPath;
85 }
86
87 /**
88 Adjusts the size of a previously allocated buffer.
89
90 @param OldPool A pointer to the buffer whose size is being adjusted.
91 @param OldSize The size of the current buffer.
92 @param NewSize The size of the new buffer.
93
94 @return A pointer to the new buffer or NULL if allocation fails.
95
96 **/
97 VOID *
98 ReallocatePool (
99 IN VOID *OldPool,
100 IN UINTN OldSize,
101 IN UINTN NewSize
102 )
103 {
104 VOID *NewPool;
105
106 NewPool = NULL;
107 if (NewSize != 0) {
108 NewPool = AllocateZeroPool (NewSize);
109 }
110
111 if (OldPool != NULL) {
112 if (NewPool != NULL) {
113 CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
114 }
115
116 FreePool (OldPool);
117 }
118
119 return NewPool;
120 }
121
122 /**
123 Concatenates a formatted unicode string to allocated pool. The caller must
124 free the resulting buffer.
125
126 @param Str Tracks the allocated pool, size in use, and
127 amount of pool allocated.
128 @param Fmt The format string
129 @param ... Variable arguments based on the format string.
130
131 @return Allocated buffer with the formatted string printed in it.
132 The caller must free the allocated buffer. The buffer
133 allocation is not packed.
134
135 **/
136 CHAR16 *
137 CatPrint (
138 IN OUT POOL_PRINT *Str,
139 IN CHAR16 *Fmt,
140 ...
141 )
142 {
143 UINT16 *AppendStr;
144 VA_LIST Args;
145 UINTN Size;
146
147 AppendStr = AllocateZeroPool (0x1000);
148 if (AppendStr == NULL) {
149 return Str->Str;
150 }
151
152 VA_START (Args, Fmt);
153 UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);
154 VA_END (Args);
155 if (NULL == Str->Str) {
156 Size = StrSize (AppendStr);
157 Str->Str = AllocateZeroPool (Size);
158 ASSERT (Str->Str != NULL);
159 } else {
160 Size = StrSize (AppendStr) - sizeof (UINT16);
161 Size = Size + StrSize (Str->Str);
162 Str->Str = ReallocatePool (
163 Str->Str,
164 StrSize (Str->Str),
165 Size
166 );
167 ASSERT (Str->Str != NULL);
168 }
169
170 Str->MaxLen = MAX_CHAR * sizeof (UINT16);
171 if (Size < Str->MaxLen) {
172 StrCat (Str->Str, AppendStr);
173 Str->Len = Size - sizeof (UINT16);
174 }
175
176 FreePool (AppendStr);
177 return Str->Str;
178 }
179
180 /**
181 Converts a PCI device path structure to its string representive.
182
183 @param Str The string representive of input device.
184 @param DevPath The input device path structure.
185 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
186 of the display node is used, where applicable. If DisplayOnly
187 is FALSE, then the longer text representation of the display node
188 is used.
189 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
190 representation for a device node can be used, where applicable.
191
192 **/
193 VOID
194 DevPathToTextPci (
195 IN OUT POOL_PRINT *Str,
196 IN VOID *DevPath,
197 IN BOOLEAN DisplayOnly,
198 IN BOOLEAN AllowShortcuts
199 )
200 {
201 PCI_DEVICE_PATH *Pci;
202
203 Pci = DevPath;
204 CatPrint (Str, L"Pci(0x%x,0x%x)", Pci->Device, Pci->Function);
205 }
206
207 /**
208 Converts a PC Card device path structure to its string representive.
209
210 @param Str The string representive of input device.
211 @param DevPath The input device path structure.
212 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
213 of the display node is used, where applicable. If DisplayOnly
214 is FALSE, then the longer text representation of the display node
215 is used.
216 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
217 representation for a device node can be used, where applicable.
218
219 **/
220 VOID
221 DevPathToTextPccard (
222 IN OUT POOL_PRINT *Str,
223 IN VOID *DevPath,
224 IN BOOLEAN DisplayOnly,
225 IN BOOLEAN AllowShortcuts
226 )
227 {
228 PCCARD_DEVICE_PATH *Pccard;
229
230 Pccard = DevPath;
231 CatPrint (Str, L"PcCard(0x%x)", Pccard->FunctionNumber);
232 }
233
234 /**
235 Converts a Memory Map device path structure to its string representive.
236
237 @param Str The string representive of input device.
238 @param DevPath The input device path structure.
239 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
240 of the display node is used, where applicable. If DisplayOnly
241 is FALSE, then the longer text representation of the display node
242 is used.
243 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
244 representation for a device node can be used, where applicable.
245
246 **/
247 VOID
248 DevPathToTextMemMap (
249 IN OUT POOL_PRINT *Str,
250 IN VOID *DevPath,
251 IN BOOLEAN DisplayOnly,
252 IN BOOLEAN AllowShortcuts
253 )
254 {
255 MEMMAP_DEVICE_PATH *MemMap;
256
257 MemMap = DevPath;
258 CatPrint (
259 Str,
260 L"MemoryMapped(0x%x,0x%lx,0x%lx)",
261 MemMap->MemoryType,
262 MemMap->StartingAddress,
263 MemMap->EndingAddress
264 );
265 }
266
267 /**
268 Converts a Vendor device path structure to its string representive.
269
270 @param Str The string representive of input device.
271 @param DevPath The input device path structure.
272 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
273 of the display node is used, where applicable. If DisplayOnly
274 is FALSE, then the longer text representation of the display node
275 is used.
276 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
277 representation for a device node can be used, where applicable.
278
279 **/
280 VOID
281 DevPathToTextVendor (
282 IN OUT POOL_PRINT *Str,
283 IN VOID *DevPath,
284 IN BOOLEAN DisplayOnly,
285 IN BOOLEAN AllowShortcuts
286 )
287 {
288 VENDOR_DEVICE_PATH *Vendor;
289 CHAR16 *Type;
290 UINTN Index;
291 UINTN DataLength;
292 UINT32 FlowControlMap;
293 UINT16 Info;
294
295 Vendor = (VENDOR_DEVICE_PATH *) DevPath;
296 switch (DevicePathType (&Vendor->Header)) {
297 case HARDWARE_DEVICE_PATH:
298 Type = L"Hw";
299 break;
300
301 case MESSAGING_DEVICE_PATH:
302 Type = L"Msg";
303 if (AllowShortcuts) {
304 if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
305 CatPrint (Str, L"VenPcAnsi()");
306 return ;
307 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
308 CatPrint (Str, L"VenVt100()");
309 return ;
310 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
311 CatPrint (Str, L"VenVt100Plus()");
312 return ;
313 } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
314 CatPrint (Str, L"VenUft8()");
315 return ;
316 } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingUartFlowControlGuid)) {
317 FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);
318 switch (FlowControlMap & 0x00000003) {
319 case 0:
320 CatPrint (Str, L"UartFlowCtrl(%s)", L"None");
321 break;
322
323 case 1:
324 CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
325 break;
326
327 case 2:
328 CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
329 break;
330
331 default:
332 break;
333 }
334
335 return ;
336 } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingSASGuid)) {
337 CatPrint (
338 Str,
339 L"SAS(0x%lx,0x%lx,0x%x,",
340 ((SAS_DEVICE_PATH *) Vendor)->SasAddress,
341 ((SAS_DEVICE_PATH *) Vendor)->Lun,
342 ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort
343 );
344 Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
345 if ((Info & 0x0f) == 0) {
346 CatPrint (Str, L"NoTopology,0,0,0,");
347 } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {
348 CatPrint (
349 Str,
350 L"%s,%s,%s,",
351 ((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",
352 ((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",
353 ((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"
354 );
355 if ((Info & 0x0f) == 1) {
356 CatPrint (Str, L"0,");
357 } else {
358 CatPrint (Str, L"0x%x,", (Info >> 8) & 0xff);
359 }
360 } else {
361 CatPrint (Str, L"0,0,0,0,");
362 }
363
364 CatPrint (Str, L"0x%x)", ((SAS_DEVICE_PATH *) Vendor)->Reserved);
365 return ;
366 } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
367 CatPrint (Str, L"DebugPort()");
368 return ;
369 }
370 }
371 break;
372
373 case MEDIA_DEVICE_PATH:
374 Type = L"Media";
375 break;
376
377 default:
378 Type = L"?";
379 break;
380 }
381
382 DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
383 CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
384 if (DataLength != 0) {
385 CatPrint (Str, L",");
386 for (Index = 0; Index < DataLength; Index++) {
387 CatPrint (Str, L"%02x", ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
388 }
389 }
390
391 CatPrint (Str, L")");
392 }
393
394 /**
395 Converts a Controller device path structure to its string representive.
396
397 @param Str The string representive of input device.
398 @param DevPath The input device path structure.
399 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
400 of the display node is used, where applicable. If DisplayOnly
401 is FALSE, then the longer text representation of the display node
402 is used.
403 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
404 representation for a device node can be used, where applicable.
405
406 **/
407 VOID
408 DevPathToTextController (
409 IN OUT POOL_PRINT *Str,
410 IN VOID *DevPath,
411 IN BOOLEAN DisplayOnly,
412 IN BOOLEAN AllowShortcuts
413 )
414 {
415 CONTROLLER_DEVICE_PATH *Controller;
416
417 Controller = DevPath;
418 CatPrint (
419 Str,
420 L"Ctrl(0x%x)",
421 Controller->ControllerNumber
422 );
423 }
424
425 /**
426 Converts a ACPI device path structure to its string representive.
427
428 @param Str The string representive of input device.
429 @param DevPath The input device path structure.
430 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
431 of the display node is used, where applicable. If DisplayOnly
432 is FALSE, then the longer text representation of the display node
433 is used.
434 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
435 representation for a device node can be used, where applicable.
436
437 **/
438 VOID
439 DevPathToTextAcpi (
440 IN OUT POOL_PRINT *Str,
441 IN VOID *DevPath,
442 IN BOOLEAN DisplayOnly,
443 IN BOOLEAN AllowShortcuts
444 )
445 {
446 ACPI_HID_DEVICE_PATH *Acpi;
447
448 Acpi = DevPath;
449 if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
450 switch (EISA_ID_TO_NUM (Acpi->HID)) {
451 case 0x0a03:
452 CatPrint (Str, L"PciRoot(0x%x)", Acpi->UID);
453 break;
454
455 case 0x0604:
456 CatPrint (Str, L"Floppy(0x%x)", Acpi->UID);
457 break;
458
459 case 0x0301:
460 CatPrint (Str, L"Keyboard(0x%x)", Acpi->UID);
461 break;
462
463 case 0x0501:
464 CatPrint (Str, L"Serial(0x%x)", Acpi->UID);
465 break;
466
467 case 0x0401:
468 CatPrint (Str, L"ParallelPort(0x%x)", Acpi->UID);
469 break;
470
471 default:
472 CatPrint (Str, L"Acpi(PNP%04x,0x%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);
473 break;
474 }
475 } else {
476 CatPrint (Str, L"Acpi(0x%08x,0x%x)", Acpi->HID, Acpi->UID);
477 }
478 }
479
480 /**
481 Converts EISA identification to string.
482
483 @param EisaId The input EISA identification.
484 @param Text A pointer to the output string.
485
486 **/
487 VOID
488 EisaIdToText (
489 IN UINT32 EisaId,
490 IN OUT CHAR16 *Text
491 )
492 {
493 CHAR16 PnpIdStr[17];
494
495 //
496 //UnicodeSPrint ("%X", 0x0a03) => "0000000000000A03"
497 //
498 UnicodeSPrint (PnpIdStr, 17 * 2, L"%16X", EisaId >> 16);
499
500 UnicodeSPrint (
501 Text,
502 sizeof (CHAR16) + sizeof (CHAR16) + sizeof (CHAR16) + sizeof (PnpIdStr),
503 L"%c%c%c%s",
504 '@' + ((EisaId >> 10) & 0x1f),
505 '@' + ((EisaId >> 5) & 0x1f),
506 '@' + ((EisaId >> 0) & 0x1f),
507 PnpIdStr + (16 - 4)
508 );
509 }
510
511 /**
512 Converts a ACPI extended HID device path structure to its string representive.
513
514 @param Str The string representive of input device.
515 @param DevPath The input device path structure.
516 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
517 of the display node is used, where applicable. If DisplayOnly
518 is FALSE, then the longer text representation of the display node
519 is used.
520 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
521 representation for a device node can be used, where applicable.
522
523 **/
524 VOID
525 DevPathToTextAcpiEx (
526 IN OUT POOL_PRINT *Str,
527 IN VOID *DevPath,
528 IN BOOLEAN DisplayOnly,
529 IN BOOLEAN AllowShortcuts
530 )
531 {
532 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
533 CHAR8 *HIDStr;
534 CHAR8 *UIDStr;
535 CHAR8 *CIDStr;
536 CHAR16 HIDText[11];
537 CHAR16 CIDText[11];
538
539 AcpiEx = DevPath;
540 HIDStr = (CHAR8 *) (((UINT8 *) AcpiEx) + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
541 UIDStr = HIDStr + AsciiStrLen (HIDStr) + 1;
542 CIDStr = UIDStr + AsciiStrLen (UIDStr) + 1;
543
544 EisaIdToText (AcpiEx->HID, HIDText);
545 EisaIdToText (AcpiEx->CID, CIDText);
546
547 if ((*HIDStr == '\0') && (*CIDStr == '\0') && (AcpiEx->UID == 0)) {
548 //
549 // use AcpiExp()
550 //
551 CatPrint (
552 Str,
553 L"AcpiExp(%s,%s,%a)",
554 HIDText,
555 CIDText,
556 UIDStr
557 );
558 } else {
559 if (AllowShortcuts) {
560 //
561 // display only
562 //
563 if (AcpiEx->HID == 0) {
564 CatPrint (Str, L"AcpiEx(%a,", HIDStr);
565 } else {
566 CatPrint (Str, L"AcpiEx(%s,", HIDText);
567 }
568
569 if (AcpiEx->UID == 0) {
570 CatPrint (Str, L"%a,", UIDStr);
571 } else {
572 CatPrint (Str, L"0x%x,", AcpiEx->UID);
573 }
574
575 if (AcpiEx->CID == 0) {
576 CatPrint (Str, L"%a)", CIDStr);
577 } else {
578 CatPrint (Str, L"%s)", CIDText);
579 }
580 } else {
581 CatPrint (
582 Str,
583 L"AcpiEx(%s,%s,0x%x,%a,%a,%a)",
584 HIDText,
585 CIDText,
586 AcpiEx->UID,
587 HIDStr,
588 CIDStr,
589 UIDStr
590 );
591 }
592 }
593 }
594
595 /**
596 Converts a ACPI address device path structure to its string representive.
597
598 @param Str The string representive of input device.
599 @param DevPath The input device path structure.
600 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
601 of the display node is used, where applicable. If DisplayOnly
602 is FALSE, then the longer text representation of the display node
603 is used.
604 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
605 representation for a device node can be used, where applicable.
606
607 **/
608 VOID
609 DevPathToTextAcpiAdr (
610 IN OUT POOL_PRINT *Str,
611 IN VOID *DevPath,
612 IN BOOLEAN DisplayOnly,
613 IN BOOLEAN AllowShortcuts
614 )
615 {
616 ACPI_ADR_DEVICE_PATH *AcpiAdr;
617 UINT16 Index;
618 UINT16 Length;
619 UINT16 AdditionalAdrCount;
620
621 AcpiAdr = DevPath;
622 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
623 AdditionalAdrCount = (UINT16) ((Length - 8) / 4);
624
625 CatPrint (Str, L"AcpiAdr(0x%x", AcpiAdr->ADR);
626 for (Index = 0; Index < AdditionalAdrCount; Index++) {
627 CatPrint (Str, L",0x%x", *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
628 }
629 CatPrint (Str, L")");
630 }
631
632 /**
633 Converts a ATAPI device path structure to its string representive.
634
635 @param Str The string representive of input device.
636 @param DevPath The input device path structure.
637 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
638 of the display node is used, where applicable. If DisplayOnly
639 is FALSE, then the longer text representation of the display node
640 is used.
641 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
642 representation for a device node can be used, where applicable.
643
644 **/
645 VOID
646 DevPathToTextAtapi (
647 IN OUT POOL_PRINT *Str,
648 IN VOID *DevPath,
649 IN BOOLEAN DisplayOnly,
650 IN BOOLEAN AllowShortcuts
651 )
652 {
653 ATAPI_DEVICE_PATH *Atapi;
654
655 Atapi = DevPath;
656
657 if (DisplayOnly) {
658 CatPrint (Str, L"Ata(0x%x)", Atapi->Lun);
659 } else {
660 CatPrint (
661 Str,
662 L"Ata(%s,%s,0x%x)",
663 Atapi->PrimarySecondary ? L"Secondary" : L"Primary",
664 Atapi->SlaveMaster ? L"Slave" : L"Master",
665 Atapi->Lun
666 );
667 }
668 }
669
670 /**
671 Converts a SCSI device path structure to its string representive.
672
673 @param Str The string representive of input device.
674 @param DevPath The input device path structure.
675 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
676 of the display node is used, where applicable. If DisplayOnly
677 is FALSE, then the longer text representation of the display node
678 is used.
679 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
680 representation for a device node can be used, where applicable.
681
682 **/
683 VOID
684 DevPathToTextScsi (
685 IN OUT POOL_PRINT *Str,
686 IN VOID *DevPath,
687 IN BOOLEAN DisplayOnly,
688 IN BOOLEAN AllowShortcuts
689 )
690 {
691 SCSI_DEVICE_PATH *Scsi;
692
693 Scsi = DevPath;
694 CatPrint (Str, L"Scsi(0x%x,0x%x)", Scsi->Pun, Scsi->Lun);
695 }
696
697 /**
698 Converts a Fibre device path structure to its string representive.
699
700 @param Str The string representive of input device.
701 @param DevPath The input device path structure.
702 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
703 of the display node is used, where applicable. If DisplayOnly
704 is FALSE, then the longer text representation of the display node
705 is used.
706 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
707 representation for a device node can be used, where applicable.
708
709 **/
710 VOID
711 DevPathToTextFibre (
712 IN OUT POOL_PRINT *Str,
713 IN VOID *DevPath,
714 IN BOOLEAN DisplayOnly,
715 IN BOOLEAN AllowShortcuts
716 )
717 {
718 FIBRECHANNEL_DEVICE_PATH *Fibre;
719
720 Fibre = DevPath;
721 CatPrint (Str, L"Fibre(0x%lx,0x%lx)", Fibre->WWN, Fibre->Lun);
722 }
723
724 /**
725 Converts a 1394 device path structure to its string representive.
726
727 @param Str The string representive of input device.
728 @param DevPath The input device path structure.
729 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
730 of the display node is used, where applicable. If DisplayOnly
731 is FALSE, then the longer text representation of the display node
732 is used.
733 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
734 representation for a device node can be used, where applicable.
735
736 **/
737 VOID
738 DevPathToText1394 (
739 IN OUT POOL_PRINT *Str,
740 IN VOID *DevPath,
741 IN BOOLEAN DisplayOnly,
742 IN BOOLEAN AllowShortcuts
743 )
744 {
745 F1394_DEVICE_PATH *F1394DevPath;
746
747 F1394DevPath = DevPath;
748 //
749 // Guid has format of IEEE-EUI64
750 //
751 CatPrint (Str, L"I1394(%016lx)", F1394DevPath->Guid);
752 }
753
754 /**
755 Converts a USB device path structure to its string representive.
756
757 @param Str The string representive of input device.
758 @param DevPath The input device path structure.
759 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
760 of the display node is used, where applicable. If DisplayOnly
761 is FALSE, then the longer text representation of the display node
762 is used.
763 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
764 representation for a device node can be used, where applicable.
765
766 **/
767 VOID
768 DevPathToTextUsb (
769 IN OUT POOL_PRINT *Str,
770 IN VOID *DevPath,
771 IN BOOLEAN DisplayOnly,
772 IN BOOLEAN AllowShortcuts
773 )
774 {
775 USB_DEVICE_PATH *Usb;
776
777 Usb = DevPath;
778 CatPrint (Str, L"USB(0x%x,0x%x)", Usb->ParentPortNumber, Usb->InterfaceNumber);
779 }
780
781 /**
782 Converts a USB WWID device path structure to its string representive.
783
784 @param Str The string representive of input device.
785 @param DevPath The input device path structure.
786 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
787 of the display node is used, where applicable. If DisplayOnly
788 is FALSE, then the longer text representation of the display node
789 is used.
790 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
791 representation for a device node can be used, where applicable.
792
793 **/
794 VOID
795 DevPathToTextUsbWWID (
796 IN OUT POOL_PRINT *Str,
797 IN VOID *DevPath,
798 IN BOOLEAN DisplayOnly,
799 IN BOOLEAN AllowShortcuts
800 )
801 {
802 USB_WWID_DEVICE_PATH *UsbWWId;
803 CHAR16 *SerialNumberStr;
804 CHAR16 *NewStr;
805 UINT16 Length;
806
807 UsbWWId = DevPath;
808
809 SerialNumberStr = (CHAR16 *) ((UINT8 *) UsbWWId + sizeof (USB_WWID_DEVICE_PATH));
810 Length = (UINT16) ((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16));
811 if (SerialNumberStr [Length - 1] != 0) {
812 //
813 // In case no NULL terminator in SerialNumber, create a new one with NULL terminator
814 //
815 NewStr = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), SerialNumberStr);
816 NewStr [Length] = 0;
817 SerialNumberStr = NewStr;
818 }
819
820 CatPrint (
821 Str,
822 L"UsbWwid(0x%x,0x%x,0x%x,\"%s\")",
823 UsbWWId->VendorId,
824 UsbWWId->ProductId,
825 UsbWWId->InterfaceNumber,
826 SerialNumberStr
827 );
828 }
829
830 /**
831 Converts a Logic Unit device path structure to its string representive.
832
833 @param Str The string representive of input device.
834 @param DevPath The input device path structure.
835 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
836 of the display node is used, where applicable. If DisplayOnly
837 is FALSE, then the longer text representation of the display node
838 is used.
839 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
840 representation for a device node can be used, where applicable.
841
842 **/
843 VOID
844 DevPathToTextLogicalUnit (
845 IN OUT POOL_PRINT *Str,
846 IN VOID *DevPath,
847 IN BOOLEAN DisplayOnly,
848 IN BOOLEAN AllowShortcuts
849 )
850 {
851 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
852
853 LogicalUnit = DevPath;
854 CatPrint (Str, L"Unit(0x%x)", LogicalUnit->Lun);
855 }
856
857 /**
858 Converts a USB class device path structure to its string representive.
859
860 @param Str The string representive of input device.
861 @param DevPath The input device path structure.
862 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
863 of the display node is used, where applicable. If DisplayOnly
864 is FALSE, then the longer text representation of the display node
865 is used.
866 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
867 representation for a device node can be used, where applicable.
868
869 **/
870 VOID
871 DevPathToTextUsbClass (
872 IN OUT POOL_PRINT *Str,
873 IN VOID *DevPath,
874 IN BOOLEAN DisplayOnly,
875 IN BOOLEAN AllowShortcuts
876 )
877 {
878 USB_CLASS_DEVICE_PATH *UsbClass;
879 BOOLEAN IsKnownSubClass;
880
881
882 UsbClass = DevPath;
883
884 IsKnownSubClass = TRUE;
885 switch (UsbClass->DeviceClass) {
886 case USB_CLASS_AUDIO:
887 CatPrint (Str, L"UsbAudio");
888 break;
889
890 case USB_CLASS_CDCCONTROL:
891 CatPrint (Str, L"UsbCDCControl");
892 break;
893
894 case USB_CLASS_HID:
895 CatPrint (Str, L"UsbHID");
896 break;
897
898 case USB_CLASS_IMAGE:
899 CatPrint (Str, L"UsbImage");
900 break;
901
902 case USB_CLASS_PRINTER:
903 CatPrint (Str, L"UsbPrinter");
904 break;
905
906 case USB_CLASS_MASS_STORAGE:
907 CatPrint (Str, L"UsbMassStorage");
908 break;
909
910 case USB_CLASS_HUB:
911 CatPrint (Str, L"UsbHub");
912 break;
913
914 case USB_CLASS_CDCDATA:
915 CatPrint (Str, L"UsbCDCData");
916 break;
917
918 case USB_CLASS_SMART_CARD:
919 CatPrint (Str, L"UsbSmartCard");
920 break;
921
922 case USB_CLASS_VIDEO:
923 CatPrint (Str, L"UsbVideo");
924 break;
925
926 case USB_CLASS_DIAGNOSTIC:
927 CatPrint (Str, L"UsbDiagnostic");
928 break;
929
930 case USB_CLASS_WIRELESS:
931 CatPrint (Str, L"UsbWireless");
932 break;
933
934 default:
935 IsKnownSubClass = FALSE;
936 break;
937 }
938
939 if (IsKnownSubClass) {
940 CatPrint (
941 Str,
942 L"(0x%x,0x%x,0x%x,0x%x)",
943 UsbClass->VendorId,
944 UsbClass->ProductId,
945 UsbClass->DeviceSubClass,
946 UsbClass->DeviceProtocol
947 );
948 return;
949 }
950
951 if (UsbClass->DeviceClass == USB_CLASS_RESERVE) {
952 if (UsbClass->DeviceSubClass == USB_SUBCLASS_FW_UPDATE) {
953 CatPrint (
954 Str,
955 L"UsbDeviceFirmwareUpdate(0x%x,0x%x,0x%x)",
956 UsbClass->VendorId,
957 UsbClass->ProductId,
958 UsbClass->DeviceProtocol
959 );
960 return;
961 } else if (UsbClass->DeviceSubClass == USB_SUBCLASS_IRDA_BRIDGE) {
962 CatPrint (
963 Str,
964 L"UsbIrdaBridge(0x%x,0x%x,0x%x)",
965 UsbClass->VendorId,
966 UsbClass->ProductId,
967 UsbClass->DeviceProtocol
968 );
969 return;
970 } else if (UsbClass->DeviceSubClass == USB_SUBCLASS_TEST) {
971 CatPrint (
972 Str,
973 L"UsbTestAndMeasurement(0x%x,0x%x,0x%x)",
974 UsbClass->VendorId,
975 UsbClass->ProductId,
976 UsbClass->DeviceProtocol
977 );
978 return;
979 }
980 }
981
982 CatPrint (
983 Str,
984 L"UsbClass(0x%x,0x%x,0x%x,0x%x,0x%x)",
985 UsbClass->VendorId,
986 UsbClass->ProductId,
987 UsbClass->DeviceClass,
988 UsbClass->DeviceSubClass,
989 UsbClass->DeviceProtocol
990 );
991 }
992
993 /**
994 Converts a SATA device path structure to its string representive.
995
996 @param Str The string representive of input device.
997 @param DevPath The input device path structure.
998 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
999 of the display node is used, where applicable. If DisplayOnly
1000 is FALSE, then the longer text representation of the display node
1001 is used.
1002 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1003 representation for a device node can be used, where applicable.
1004
1005 **/
1006 VOID
1007 DevPathToTextSata (
1008 IN OUT POOL_PRINT *Str,
1009 IN VOID *DevPath,
1010 IN BOOLEAN DisplayOnly,
1011 IN BOOLEAN AllowShortcuts
1012 )
1013 {
1014 SATA_DEVICE_PATH *Sata;
1015
1016 Sata = DevPath;
1017 CatPrint (
1018 Str,
1019 L"Sata(0x%x,0x%x,0x%x)",
1020 (UINTN) Sata->HBAPortNumber,
1021 (UINTN) Sata->PortMultiplierPortNumber,
1022 (UINTN) Sata->Lun
1023 );
1024 }
1025
1026 /**
1027 Converts a I20 device path structure to its string representive.
1028
1029 @param Str The string representive of input device.
1030 @param DevPath The input device path structure.
1031 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1032 of the display node is used, where applicable. If DisplayOnly
1033 is FALSE, then the longer text representation of the display node
1034 is used.
1035 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1036 representation for a device node can be used, where applicable.
1037
1038 **/
1039 VOID
1040 DevPathToTextI2O (
1041 IN OUT POOL_PRINT *Str,
1042 IN VOID *DevPath,
1043 IN BOOLEAN DisplayOnly,
1044 IN BOOLEAN AllowShortcuts
1045 )
1046 {
1047 I2O_DEVICE_PATH *I2ODevPath;
1048
1049 I2ODevPath = DevPath;
1050 CatPrint (Str, L"I2O(0x%x)", I2ODevPath->Tid);
1051 }
1052
1053 /**
1054 Converts a MAC address device path structure to its string representive.
1055
1056 @param Str The string representive of input device.
1057 @param DevPath The input device path structure.
1058 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1059 of the display node is used, where applicable. If DisplayOnly
1060 is FALSE, then the longer text representation of the display node
1061 is used.
1062 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1063 representation for a device node can be used, where applicable.
1064
1065 **/
1066 VOID
1067 DevPathToTextMacAddr (
1068 IN OUT POOL_PRINT *Str,
1069 IN VOID *DevPath,
1070 IN BOOLEAN DisplayOnly,
1071 IN BOOLEAN AllowShortcuts
1072 )
1073 {
1074 MAC_ADDR_DEVICE_PATH *MacDevPath;
1075 UINTN HwAddressSize;
1076 UINTN Index;
1077
1078 MacDevPath = DevPath;
1079
1080 HwAddressSize = sizeof (EFI_MAC_ADDRESS);
1081 if (MacDevPath->IfType == 0x01 || MacDevPath->IfType == 0x00) {
1082 HwAddressSize = 6;
1083 }
1084
1085 CatPrint (Str, L"MAC(");
1086
1087 for (Index = 0; Index < HwAddressSize; Index++) {
1088 CatPrint (Str, L"%02x", MacDevPath->MacAddress.Addr[Index]);
1089 }
1090
1091 CatPrint (Str, L",0x%x)", MacDevPath->IfType);
1092 }
1093
1094 /**
1095 Converts a IPv4 device path structure to its string representive.
1096
1097 @param Str The string representive of input device.
1098 @param DevPath The input device path structure.
1099 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1100 of the display node is used, where applicable. If DisplayOnly
1101 is FALSE, then the longer text representation of the display node
1102 is used.
1103 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1104 representation for a device node can be used, where applicable.
1105
1106 **/
1107 VOID
1108 DevPathToTextIPv4 (
1109 IN OUT POOL_PRINT *Str,
1110 IN VOID *DevPath,
1111 IN BOOLEAN DisplayOnly,
1112 IN BOOLEAN AllowShortcuts
1113 )
1114 {
1115 IPv4_DEVICE_PATH *IPDevPath;
1116
1117 IPDevPath = DevPath;
1118 if (DisplayOnly) {
1119 CatPrint (
1120 Str,
1121 L"IPv4(%d.%d.%d.%d)",
1122 IPDevPath->RemoteIpAddress.Addr[0],
1123 IPDevPath->RemoteIpAddress.Addr[1],
1124 IPDevPath->RemoteIpAddress.Addr[2],
1125 IPDevPath->RemoteIpAddress.Addr[3]
1126 );
1127 return ;
1128 }
1129
1130 CatPrint (
1131 Str,
1132 L"IPv4(%d.%d.%d.%d,%s,%s,%d.%d.%d.%d)",
1133 IPDevPath->RemoteIpAddress.Addr[0],
1134 IPDevPath->RemoteIpAddress.Addr[1],
1135 IPDevPath->RemoteIpAddress.Addr[2],
1136 IPDevPath->RemoteIpAddress.Addr[3],
1137 IPDevPath->Protocol ? L"TCP" : L"UDP",
1138 (IPDevPath->StaticIpAddress == TRUE) ? L"Static" : L"DHCP",
1139 IPDevPath->LocalIpAddress.Addr[0],
1140 IPDevPath->LocalIpAddress.Addr[1],
1141 IPDevPath->LocalIpAddress.Addr[2],
1142 IPDevPath->LocalIpAddress.Addr[3]
1143 );
1144 }
1145
1146 /**
1147 Converts a IPv6 device path structure to its string representive.
1148
1149 @param Str The string representive of input device.
1150 @param DevPath The input device path structure.
1151 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1152 of the display node is used, where applicable. If DisplayOnly
1153 is FALSE, then the longer text representation of the display node
1154 is used.
1155 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1156 representation for a device node can be used, where applicable.
1157
1158 **/
1159 VOID
1160 DevPathToTextIPv6 (
1161 IN OUT POOL_PRINT *Str,
1162 IN VOID *DevPath,
1163 IN BOOLEAN DisplayOnly,
1164 IN BOOLEAN AllowShortcuts
1165 )
1166 {
1167 IPv6_DEVICE_PATH *IPDevPath;
1168
1169 IPDevPath = DevPath;
1170 if (DisplayOnly) {
1171 CatPrint (
1172 Str,
1173 L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
1174 IPDevPath->RemoteIpAddress.Addr[0],
1175 IPDevPath->RemoteIpAddress.Addr[1],
1176 IPDevPath->RemoteIpAddress.Addr[2],
1177 IPDevPath->RemoteIpAddress.Addr[3],
1178 IPDevPath->RemoteIpAddress.Addr[4],
1179 IPDevPath->RemoteIpAddress.Addr[5],
1180 IPDevPath->RemoteIpAddress.Addr[6],
1181 IPDevPath->RemoteIpAddress.Addr[7],
1182 IPDevPath->RemoteIpAddress.Addr[8],
1183 IPDevPath->RemoteIpAddress.Addr[9],
1184 IPDevPath->RemoteIpAddress.Addr[10],
1185 IPDevPath->RemoteIpAddress.Addr[11],
1186 IPDevPath->RemoteIpAddress.Addr[12],
1187 IPDevPath->RemoteIpAddress.Addr[13],
1188 IPDevPath->RemoteIpAddress.Addr[14],
1189 IPDevPath->RemoteIpAddress.Addr[15]
1190 );
1191 return ;
1192 }
1193
1194 CatPrint (
1195 Str,
1196 L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x,%s,%s,%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
1197 IPDevPath->RemoteIpAddress.Addr[0],
1198 IPDevPath->RemoteIpAddress.Addr[1],
1199 IPDevPath->RemoteIpAddress.Addr[2],
1200 IPDevPath->RemoteIpAddress.Addr[3],
1201 IPDevPath->RemoteIpAddress.Addr[4],
1202 IPDevPath->RemoteIpAddress.Addr[5],
1203 IPDevPath->RemoteIpAddress.Addr[6],
1204 IPDevPath->RemoteIpAddress.Addr[7],
1205 IPDevPath->RemoteIpAddress.Addr[8],
1206 IPDevPath->RemoteIpAddress.Addr[9],
1207 IPDevPath->RemoteIpAddress.Addr[10],
1208 IPDevPath->RemoteIpAddress.Addr[11],
1209 IPDevPath->RemoteIpAddress.Addr[12],
1210 IPDevPath->RemoteIpAddress.Addr[13],
1211 IPDevPath->RemoteIpAddress.Addr[14],
1212 IPDevPath->RemoteIpAddress.Addr[15],
1213 IPDevPath->Protocol ? L"TCP" : L"UDP",
1214 (IPDevPath->StaticIpAddress == TRUE) ? L"Static" : L"DHCP",
1215 IPDevPath->LocalIpAddress.Addr[0],
1216 IPDevPath->LocalIpAddress.Addr[1],
1217 IPDevPath->LocalIpAddress.Addr[2],
1218 IPDevPath->LocalIpAddress.Addr[3],
1219 IPDevPath->LocalIpAddress.Addr[4],
1220 IPDevPath->LocalIpAddress.Addr[5],
1221 IPDevPath->LocalIpAddress.Addr[6],
1222 IPDevPath->LocalIpAddress.Addr[7],
1223 IPDevPath->LocalIpAddress.Addr[8],
1224 IPDevPath->LocalIpAddress.Addr[9],
1225 IPDevPath->LocalIpAddress.Addr[10],
1226 IPDevPath->LocalIpAddress.Addr[11],
1227 IPDevPath->LocalIpAddress.Addr[12],
1228 IPDevPath->LocalIpAddress.Addr[13],
1229 IPDevPath->LocalIpAddress.Addr[14],
1230 IPDevPath->LocalIpAddress.Addr[15]
1231 );
1232 }
1233
1234 /**
1235 Converts an Infini Band device path structure to its string representive.
1236
1237 @param Str The string representive of input device.
1238 @param DevPath The input device path structure.
1239 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1240 of the display node is used, where applicable. If DisplayOnly
1241 is FALSE, then the longer text representation of the display node
1242 is used.
1243 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1244 representation for a device node can be used, where applicable.
1245
1246 **/
1247 VOID
1248 DevPathToTextInfiniBand (
1249 IN OUT POOL_PRINT *Str,
1250 IN VOID *DevPath,
1251 IN BOOLEAN DisplayOnly,
1252 IN BOOLEAN AllowShortcuts
1253 )
1254 {
1255 INFINIBAND_DEVICE_PATH *InfiniBand;
1256
1257 InfiniBand = DevPath;
1258 CatPrint (
1259 Str,
1260 L"Infiniband(0x%x,%g,0x%lx,0x%lx,0x%lx)",
1261 InfiniBand->ResourceFlags,
1262 InfiniBand->PortGid,
1263 InfiniBand->ServiceId,
1264 InfiniBand->TargetPortId,
1265 InfiniBand->DeviceId
1266 );
1267 }
1268
1269 /**
1270 Converts a UART device path structure to its string representive.
1271
1272 @param Str The string representive of input device.
1273 @param DevPath The input device path structure.
1274 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1275 of the display node is used, where applicable. If DisplayOnly
1276 is FALSE, then the longer text representation of the display node
1277 is used.
1278 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1279 representation for a device node can be used, where applicable.
1280
1281 **/
1282 VOID
1283 DevPathToTextUart (
1284 IN OUT POOL_PRINT *Str,
1285 IN VOID *DevPath,
1286 IN BOOLEAN DisplayOnly,
1287 IN BOOLEAN AllowShortcuts
1288 )
1289 {
1290 UART_DEVICE_PATH *Uart;
1291 CHAR8 Parity;
1292
1293 Uart = DevPath;
1294 switch (Uart->Parity) {
1295 case 0:
1296 Parity = 'D';
1297 break;
1298
1299 case 1:
1300 Parity = 'N';
1301 break;
1302
1303 case 2:
1304 Parity = 'E';
1305 break;
1306
1307 case 3:
1308 Parity = 'O';
1309 break;
1310
1311 case 4:
1312 Parity = 'M';
1313 break;
1314
1315 case 5:
1316 Parity = 'S';
1317 break;
1318
1319 default:
1320 Parity = 'x';
1321 break;
1322 }
1323
1324 if (Uart->BaudRate == 0) {
1325 CatPrint (Str, L"Uart(DEFAULT,");
1326 } else {
1327 CatPrint (Str, L"Uart(%ld,", Uart->BaudRate);
1328 }
1329
1330 if (Uart->DataBits == 0) {
1331 CatPrint (Str, L"DEFAULT,");
1332 } else {
1333 CatPrint (Str, L"%d,", Uart->DataBits);
1334 }
1335
1336 CatPrint (Str, L"%c,", Parity);
1337
1338 switch (Uart->StopBits) {
1339 case 0:
1340 CatPrint (Str, L"D)");
1341 break;
1342
1343 case 1:
1344 CatPrint (Str, L"1)");
1345 break;
1346
1347 case 2:
1348 CatPrint (Str, L"1.5)");
1349 break;
1350
1351 case 3:
1352 CatPrint (Str, L"2)");
1353 break;
1354
1355 default:
1356 CatPrint (Str, L"x)");
1357 break;
1358 }
1359 }
1360
1361 /**
1362 Converts an iSCSI device path structure to its string representive.
1363
1364 @param Str The string representive of input device.
1365 @param DevPath The input device path structure.
1366 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1367 of the display node is used, where applicable. If DisplayOnly
1368 is FALSE, then the longer text representation of the display node
1369 is used.
1370 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1371 representation for a device node can be used, where applicable.
1372
1373 **/
1374 VOID
1375 DevPathToTextiSCSI (
1376 IN OUT POOL_PRINT *Str,
1377 IN VOID *DevPath,
1378 IN BOOLEAN DisplayOnly,
1379 IN BOOLEAN AllowShortcuts
1380 )
1381 {
1382 ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
1383 UINT16 Options;
1384
1385 ISCSIDevPath = DevPath;
1386 CatPrint (
1387 Str,
1388 L"iSCSI(%a,0x%x,0x%lx,",
1389 ISCSIDevPath->iSCSITargetName,
1390 ISCSIDevPath->TargetPortalGroupTag,
1391 ISCSIDevPath->Lun
1392 );
1393
1394 Options = ISCSIDevPath->LoginOption;
1395 CatPrint (Str, L"%s,", (((Options >> 1) & 0x0001) != 0) ? L"CRC32C" : L"None");
1396 CatPrint (Str, L"%s,", (((Options >> 3) & 0x0001) != 0) ? L"CRC32C" : L"None");
1397 if (((Options >> 11) & 0x0001) != 0) {
1398 CatPrint (Str, L"%s,", L"None");
1399 } else if (((Options >> 12) & 0x0001) != 0) {
1400 CatPrint (Str, L"%s,", L"CHAP_UNI");
1401 } else {
1402 CatPrint (Str, L"%s,", L"CHAP_BI");
1403
1404 }
1405
1406 CatPrint (Str, L"%s)", (ISCSIDevPath->NetworkProtocol == 0) ? L"TCP" : L"reserved");
1407 }
1408
1409 /**
1410 Converts a Hard drive device path structure to its string representive.
1411
1412 @param Str The string representive of input device.
1413 @param DevPath The input device path structure.
1414 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1415 of the display node is used, where applicable. If DisplayOnly
1416 is FALSE, then the longer text representation of the display node
1417 is used.
1418 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1419 representation for a device node can be used, where applicable.
1420
1421 **/
1422 VOID
1423 DevPathToTextHardDrive (
1424 IN OUT POOL_PRINT *Str,
1425 IN VOID *DevPath,
1426 IN BOOLEAN DisplayOnly,
1427 IN BOOLEAN AllowShortcuts
1428 )
1429 {
1430 HARDDRIVE_DEVICE_PATH *Hd;
1431
1432 Hd = DevPath;
1433 switch (Hd->SignatureType) {
1434 case SIGNATURE_TYPE_MBR:
1435 CatPrint (
1436 Str,
1437 L"HD(%d,%s,0x%08x,",
1438 Hd->PartitionNumber,
1439 L"MBR",
1440 *((UINT32 *) (&(Hd->Signature[0])))
1441 );
1442 break;
1443
1444 case SIGNATURE_TYPE_GUID:
1445 CatPrint (
1446 Str,
1447 L"HD(%d,%s,%g,",
1448 Hd->PartitionNumber,
1449 L"GPT",
1450 (EFI_GUID *) &(Hd->Signature[0])
1451 );
1452 break;
1453
1454 default:
1455 CatPrint (
1456 Str,
1457 L"HD(%d,%d,0,",
1458 Hd->PartitionNumber,
1459 Hd->SignatureType
1460 );
1461 break;
1462 }
1463
1464 CatPrint (Str, L"0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);
1465 }
1466
1467 /**
1468 Converts a CDROM device path structure to its string representive.
1469
1470 @param Str The string representive of input device.
1471 @param DevPath The input device path structure.
1472 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1473 of the display node is used, where applicable. If DisplayOnly
1474 is FALSE, then the longer text representation of the display node
1475 is used.
1476 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1477 representation for a device node can be used, where applicable.
1478
1479 **/
1480 VOID
1481 DevPathToTextCDROM (
1482 IN OUT POOL_PRINT *Str,
1483 IN VOID *DevPath,
1484 IN BOOLEAN DisplayOnly,
1485 IN BOOLEAN AllowShortcuts
1486 )
1487 {
1488 CDROM_DEVICE_PATH *Cd;
1489
1490 Cd = DevPath;
1491 if (DisplayOnly) {
1492 CatPrint (Str, L"CDROM(0x%x)", Cd->BootEntry);
1493 return ;
1494 }
1495
1496 CatPrint (Str, L"CDROM(0x%x,0x%lx,0x%lx)", Cd->BootEntry, Cd->PartitionStart, Cd->PartitionSize);
1497 }
1498
1499 /**
1500 Converts a File device path structure to its string representive.
1501
1502 @param Str The string representive of input device.
1503 @param DevPath The input device path structure.
1504 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1505 of the display node is used, where applicable. If DisplayOnly
1506 is FALSE, then the longer text representation of the display node
1507 is used.
1508 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1509 representation for a device node can be used, where applicable.
1510
1511 **/
1512 VOID
1513 DevPathToTextFilePath (
1514 IN OUT POOL_PRINT *Str,
1515 IN VOID *DevPath,
1516 IN BOOLEAN DisplayOnly,
1517 IN BOOLEAN AllowShortcuts
1518 )
1519 {
1520 FILEPATH_DEVICE_PATH *Fp;
1521
1522 Fp = DevPath;
1523 CatPrint (Str, L"%s", Fp->PathName);
1524 }
1525
1526 /**
1527 Converts a Media protocol device path structure to its string representive.
1528
1529 @param Str The string representive of input device.
1530 @param DevPath The input device path structure.
1531 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1532 of the display node is used, where applicable. If DisplayOnly
1533 is FALSE, then the longer text representation of the display node
1534 is used.
1535 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1536 representation for a device node can be used, where applicable.
1537
1538 **/
1539 VOID
1540 DevPathToTextMediaProtocol (
1541 IN OUT POOL_PRINT *Str,
1542 IN VOID *DevPath,
1543 IN BOOLEAN DisplayOnly,
1544 IN BOOLEAN AllowShortcuts
1545 )
1546 {
1547 MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
1548
1549 MediaProt = DevPath;
1550 CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
1551 }
1552
1553 /**
1554 Converts a Firmware Volume device path structure to its string representive.
1555
1556 @param Str The string representive of input device.
1557 @param DevPath The input device path structure.
1558 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1559 of the display node is used, where applicable. If DisplayOnly
1560 is FALSE, then the longer text representation of the display node
1561 is used.
1562 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1563 representation for a device node can be used, where applicable.
1564
1565 **/
1566 VOID
1567 DevPathToTextFv (
1568 IN OUT POOL_PRINT *Str,
1569 IN VOID *DevPath,
1570 IN BOOLEAN DisplayOnly,
1571 IN BOOLEAN AllowShortcuts
1572 )
1573 {
1574 MEDIA_FW_VOL_DEVICE_PATH *Fv;
1575
1576 Fv = DevPath;
1577 CatPrint (Str, L"Fv(%g)", &Fv->FvName);
1578 }
1579
1580 /**
1581 Converts a Firmware Volume File device path structure to its string representive.
1582
1583 @param Str The string representive of input device.
1584 @param DevPath The input device path structure.
1585 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1586 of the display node is used, where applicable. If DisplayOnly
1587 is FALSE, then the longer text representation of the display node
1588 is used.
1589 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1590 representation for a device node can be used, where applicable.
1591
1592 **/
1593 VOID
1594 DevPathToTextFvFile (
1595 IN OUT POOL_PRINT *Str,
1596 IN VOID *DevPath,
1597 IN BOOLEAN DisplayOnly,
1598 IN BOOLEAN AllowShortcuts
1599 )
1600 {
1601 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;
1602
1603 FvFile = DevPath;
1604 CatPrint (Str, L"FvFile(%g)", &FvFile->FvFileName);
1605 }
1606
1607 /**
1608 Converts a BIOS Boot Specification device path structure to its string representive.
1609
1610 @param Str The string representive of input device.
1611 @param DevPath The input device path structure.
1612 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1613 of the display node is used, where applicable. If DisplayOnly
1614 is FALSE, then the longer text representation of the display node
1615 is used.
1616 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1617 representation for a device node can be used, where applicable.
1618
1619 **/
1620 VOID
1621 DevPathToTextBBS (
1622 IN OUT POOL_PRINT *Str,
1623 IN VOID *DevPath,
1624 IN BOOLEAN DisplayOnly,
1625 IN BOOLEAN AllowShortcuts
1626 )
1627 {
1628 BBS_BBS_DEVICE_PATH *Bbs;
1629 CHAR16 *Type;
1630
1631 Bbs = DevPath;
1632 switch (Bbs->DeviceType) {
1633 case BBS_TYPE_FLOPPY:
1634 Type = L"Floppy";
1635 break;
1636
1637 case BBS_TYPE_HARDDRIVE:
1638 Type = L"HD";
1639 break;
1640
1641 case BBS_TYPE_CDROM:
1642 Type = L"CDROM";
1643 break;
1644
1645 case BBS_TYPE_PCMCIA:
1646 Type = L"PCMCIA";
1647 break;
1648
1649 case BBS_TYPE_USB:
1650 Type = L"USB";
1651 break;
1652
1653 case BBS_TYPE_EMBEDDED_NETWORK:
1654 Type = L"Network";
1655 break;
1656
1657 default:
1658 Type = NULL;
1659 break;
1660 }
1661
1662 if (Type != NULL) {
1663 CatPrint (Str, L"BBS(%s,%a", Type, Bbs->String);
1664 } else {
1665 CatPrint (Str, L"BBS(0x%x,%a", Bbs->DeviceType, Bbs->String);
1666 }
1667
1668 if (DisplayOnly) {
1669 CatPrint (Str, L")");
1670 return ;
1671 }
1672
1673 CatPrint (Str, L",0x%x)", Bbs->StatusFlag);
1674 }
1675
1676 /**
1677 Converts an End-of-Device-Path structure to its string representive.
1678
1679 @param Str The string representive of input device.
1680 @param DevPath The input device path structure.
1681 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1682 of the display node is used, where applicable. If DisplayOnly
1683 is FALSE, then the longer text representation of the display node
1684 is used.
1685 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1686 representation for a device node can be used, where applicable.
1687
1688 **/
1689 VOID
1690 DevPathToTextEndInstance (
1691 IN OUT POOL_PRINT *Str,
1692 IN VOID *DevPath,
1693 IN BOOLEAN DisplayOnly,
1694 IN BOOLEAN AllowShortcuts
1695 )
1696 {
1697 CatPrint (Str, L",");
1698 }
1699
1700 /**
1701 Converts an unknown device path structure to its string representive.
1702
1703 @param Str The string representive of input device.
1704 @param DevPath The input device path structure.
1705 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1706 of the display node is used, where applicable. If DisplayOnly
1707 is FALSE, then the longer text representation of the display node
1708 is used.
1709 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1710 representation for a device node can be used, where applicable.
1711
1712 **/
1713 VOID
1714 DevPathToTextNodeUnknown (
1715 IN OUT POOL_PRINT *Str,
1716 IN VOID *DevPath,
1717 IN BOOLEAN DisplayOnly,
1718 IN BOOLEAN AllowShortcuts
1719 )
1720 {
1721 CatPrint (Str, L"?");
1722 }
1723
1724 GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE DevPathToTextTable[] = {
1725 {HARDWARE_DEVICE_PATH, HW_PCI_DP, DevPathToTextPci},
1726 {HARDWARE_DEVICE_PATH, HW_PCCARD_DP, DevPathToTextPccard},
1727 {HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, DevPathToTextMemMap},
1728 {HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DevPathToTextVendor},
1729 {HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, DevPathToTextController},
1730 {ACPI_DEVICE_PATH, ACPI_DP, DevPathToTextAcpi},
1731 {ACPI_DEVICE_PATH, ACPI_EXTENDED_DP, DevPathToTextAcpiEx},
1732 {ACPI_DEVICE_PATH, ACPI_ADR_DP, DevPathToTextAcpiAdr},
1733 {MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, DevPathToTextAtapi},
1734 {MESSAGING_DEVICE_PATH, MSG_SCSI_DP, DevPathToTextScsi},
1735 {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, DevPathToTextFibre},
1736 {MESSAGING_DEVICE_PATH, MSG_1394_DP, DevPathToText1394},
1737 {MESSAGING_DEVICE_PATH, MSG_USB_DP, DevPathToTextUsb},
1738 {MESSAGING_DEVICE_PATH, MSG_USB_WWID_DP, DevPathToTextUsbWWID},
1739 {MESSAGING_DEVICE_PATH, MSG_DEVICE_LOGICAL_UNIT_DP, DevPathToTextLogicalUnit},
1740 {MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, DevPathToTextUsbClass},
1741 {MESSAGING_DEVICE_PATH, MSG_SATA_DP, DevPathToTextSata},
1742 {MESSAGING_DEVICE_PATH, MSG_I2O_DP, DevPathToTextI2O},
1743 {MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, DevPathToTextMacAddr},
1744 {MESSAGING_DEVICE_PATH, MSG_IPv4_DP, DevPathToTextIPv4},
1745 {MESSAGING_DEVICE_PATH, MSG_IPv6_DP, DevPathToTextIPv6},
1746 {MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, DevPathToTextInfiniBand},
1747 {MESSAGING_DEVICE_PATH, MSG_UART_DP, DevPathToTextUart},
1748 {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, DevPathToTextVendor},
1749 {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, DevPathToTextiSCSI},
1750 {MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, DevPathToTextHardDrive},
1751 {MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, DevPathToTextCDROM},
1752 {MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, DevPathToTextVendor},
1753 {MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, DevPathToTextFilePath},
1754 {MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, DevPathToTextMediaProtocol},
1755 {MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, DevPathToTextFilePath},
1756 {MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_VOL_DP, DevPathToTextFv},
1757 {MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP, DevPathToTextFvFile},
1758 {BBS_DEVICE_PATH, BBS_BBS_DP, DevPathToTextBBS},
1759 {END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, DevPathToTextEndInstance},
1760 {0, 0, NULL}
1761 };
1762
1763 /**
1764 Converts a device node to its string representation.
1765
1766 @param DeviceNode A Pointer to the device node to be converted.
1767 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1768 of the display node is used, where applicable. If DisplayOnly
1769 is FALSE, then the longer text representation of the display node
1770 is used.
1771 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1772 representation for a device node can be used, where applicable.
1773
1774 @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
1775 is NULL or there was insufficient memory.
1776
1777 **/
1778 CHAR16 *
1779 EFIAPI
1780 ConvertDeviceNodeToText (
1781 IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
1782 IN BOOLEAN DisplayOnly,
1783 IN BOOLEAN AllowShortcuts
1784 )
1785 {
1786 POOL_PRINT Str;
1787 UINTN Index;
1788 UINTN NewSize;
1789 VOID (*DumpNode)(POOL_PRINT *, VOID *, BOOLEAN, BOOLEAN);
1790
1791 if (DeviceNode == NULL) {
1792 return NULL;
1793 }
1794
1795 ZeroMem (&Str, sizeof (Str));
1796
1797 //
1798 // Process the device path node
1799 //
1800 DumpNode = NULL;
1801 for (Index = 0; DevPathToTextTable[Index].Function != NULL; Index++) {
1802 if (DevicePathType (DeviceNode) == DevPathToTextTable[Index].Type &&
1803 DevicePathSubType (DeviceNode) == DevPathToTextTable[Index].SubType
1804 ) {
1805 DumpNode = DevPathToTextTable[Index].Function;
1806 break;
1807 }
1808 }
1809 //
1810 // If not found, use a generic function
1811 //
1812 if (DumpNode == NULL) {
1813 DumpNode = DevPathToTextNodeUnknown;
1814 }
1815
1816 //
1817 // Print this node
1818 //
1819 DumpNode (&Str, (VOID *) DeviceNode, DisplayOnly, AllowShortcuts);
1820
1821 //
1822 // Shrink pool used for string allocation
1823 //
1824 NewSize = (Str.Len + 1) * sizeof (CHAR16);
1825 Str.Str = ReallocatePool (Str.Str, NewSize, NewSize);
1826 ASSERT (Str.Str != NULL);
1827 Str.Str[Str.Len] = 0;
1828 return Str.Str;
1829 }
1830
1831 /**
1832 Converts a device path to its text representation.
1833
1834 @param DevicePath A Pointer to the device to be converted.
1835 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1836 of the display node is used, where applicable. If DisplayOnly
1837 is FALSE, then the longer text representation of the display node
1838 is used.
1839 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1840 representation for a device node can be used, where applicable.
1841
1842 @return A pointer to the allocated text representation of the device path or
1843 NULL if DeviceNode is NULL or there was insufficient memory.
1844
1845 **/
1846 CHAR16 *
1847 EFIAPI
1848 ConvertDevicePathToText (
1849 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
1850 IN BOOLEAN DisplayOnly,
1851 IN BOOLEAN AllowShortcuts
1852 )
1853 {
1854 POOL_PRINT Str;
1855 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
1856 EFI_DEVICE_PATH_PROTOCOL *UnpackDevPath;
1857 UINTN Index;
1858 UINTN NewSize;
1859 VOID (*DumpNode) (POOL_PRINT *, VOID *, BOOLEAN, BOOLEAN);
1860
1861 if (DevicePath == NULL) {
1862 return NULL;
1863 }
1864
1865 ZeroMem (&Str, sizeof (Str));
1866
1867 //
1868 // Unpacked the device path
1869 //
1870 UnpackDevPath = UnpackDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath);
1871 ASSERT (UnpackDevPath != NULL);
1872
1873 //
1874 // Process each device path node
1875 //
1876 DevPathNode = UnpackDevPath;
1877 while (!IsDevicePathEnd (DevPathNode)) {
1878 //
1879 // Find the handler to dump this device path node
1880 //
1881 DumpNode = NULL;
1882 for (Index = 0; DevPathToTextTable[Index].Function; Index += 1) {
1883
1884 if (DevicePathType (DevPathNode) == DevPathToTextTable[Index].Type &&
1885 DevicePathSubType (DevPathNode) == DevPathToTextTable[Index].SubType
1886 ) {
1887 DumpNode = DevPathToTextTable[Index].Function;
1888 break;
1889 }
1890 }
1891 //
1892 // If not found, use a generic function
1893 //
1894 if (!DumpNode) {
1895 DumpNode = DevPathToTextNodeUnknown;
1896 }
1897 //
1898 // Put a path seperator in if needed
1899 //
1900 if ((Str.Len != 0) && DumpNode != DevPathToTextEndInstance) {
1901 if (*(Str.Str + Str.Len / sizeof (CHAR16) - 1) != L',') {
1902 CatPrint (&Str, L"/");
1903 }
1904 }
1905 //
1906 // Print this node of the device path
1907 //
1908 DumpNode (&Str, DevPathNode, DisplayOnly, AllowShortcuts);
1909
1910 //
1911 // Next device path node
1912 //
1913 DevPathNode = NextDevicePathNode (DevPathNode);
1914 }
1915 //
1916 // Shrink pool used for string allocation
1917 //
1918 FreePool (UnpackDevPath);
1919
1920 NewSize = (Str.Len + 1) * sizeof (CHAR16);
1921 Str.Str = ReallocatePool (Str.Str, NewSize, NewSize);
1922 ASSERT (Str.Str != NULL);
1923 Str.Str[Str.Len] = 0;
1924 return Str.Str;
1925 }