xref: /freebsd/lib/libefivar/efivar-dp-format.c (revision 3f0efe05432b1633991114ca4ca330102a561959)
17270962aSWarner Losh /*-
27270962aSWarner Losh  * Copyright (c) 2017 Netflix, Inc.
37270962aSWarner Losh  *
47270962aSWarner Losh  * Redistribution and use in source and binary forms, with or without
57270962aSWarner Losh  * modification, are permitted provided that the following conditions
67270962aSWarner Losh  * are met:
77270962aSWarner Losh  * 1. Redistributions of source code must retain the above copyright
86decf2ccSEd Maste  *    notice, this list of conditions and the following disclaimer.
97270962aSWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
107270962aSWarner Losh  *    notice, this list of conditions and the following disclaimer in the
117270962aSWarner Losh  *    documentation and/or other materials provided with the distribution.
127270962aSWarner Losh  *
136decf2ccSEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
146decf2ccSEd Maste  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
156decf2ccSEd Maste  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
166decf2ccSEd Maste  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
176decf2ccSEd Maste  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
186decf2ccSEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
196decf2ccSEd Maste  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
206decf2ccSEd Maste  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
216decf2ccSEd Maste  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
226decf2ccSEd Maste  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
236decf2ccSEd Maste  * SUCH DAMAGE.
247270962aSWarner Losh  */
257270962aSWarner Losh 
267270962aSWarner Losh /*
277270962aSWarner Losh  * Routines to format EFI_DEVICE_PATHs from the UEFI standard. Much of
287270962aSWarner Losh  * this file is taken from EDK2 and rototilled.
297270962aSWarner Losh  */
307270962aSWarner Losh 
317270962aSWarner Losh #include <sys/cdefs.h>
327270962aSWarner Losh #include <efivar.h>
337270962aSWarner Losh #include <stdio.h>
347270962aSWarner Losh #include <string.h>
357270962aSWarner Losh 
360d802f5aSWarner Losh #include "efichar.h"
370d802f5aSWarner Losh 
387270962aSWarner Losh #include "efi-osdep.h"
397270962aSWarner Losh #include "efivar-dp.h"
407270962aSWarner Losh 
417270962aSWarner Losh #include "uefi-dplib.h"
427270962aSWarner Losh 
437270962aSWarner Losh /*
447270962aSWarner Losh  * This is a lie, but since we have converted everything
457270962aSWarner Losh  * from wide to narrow, it's the right lie now.
467270962aSWarner Losh  */
477270962aSWarner Losh #define UnicodeSPrint snprintf
487270962aSWarner Losh 
497270962aSWarner Losh /*
507270962aSWarner Losh  * Taken from MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
517270962aSWarner Losh  * heavily modified:
527270962aSWarner Losh  *	wide strings converted to narrow
537270962aSWarner Losh  *	Low level printing code redone for narrow strings
547270962aSWarner Losh  *	Routines made static
557270962aSWarner Losh  *	%s -> %S in spots (where it is still UCS-2)
567270962aSWarner Losh  *	%a (ascii) -> %s
577270962aSWarner Losh  *	%g -> %36s hack to print guid (see above for caveat)
587270962aSWarner Losh  *	some tidying up of const and deconsting. It's evil, but const
597270962aSWarner Losh  *	  poisoning the whole file was too much.
607270962aSWarner Losh  */
617270962aSWarner Losh 
627270962aSWarner Losh /** @file
637270962aSWarner Losh   DevicePathToText protocol as defined in the UEFI 2.0 specification.
647270962aSWarner Losh 
657270962aSWarner Losh   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
6650668299SJose Luis Duran Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
6711a9ff5bSJose Luis Duran SPDX-License-Identifier: BSD-2-Clause-Patent
687270962aSWarner Losh 
697270962aSWarner Losh **/
707270962aSWarner Losh 
717270962aSWarner Losh // #include "UefiDevicePathLib.h"
727270962aSWarner Losh 
737270962aSWarner Losh /**
747270962aSWarner Losh   Concatenates a formatted unicode string to allocated pool. The caller must
757270962aSWarner Losh   free the resulting buffer.
767270962aSWarner Losh 
777270962aSWarner Losh   @param Str             Tracks the allocated pool, size in use, and
787270962aSWarner Losh                          amount of pool allocated.
797270962aSWarner Losh   @param Fmt             The format string
807270962aSWarner Losh   @param ...             Variable arguments based on the format string.
817270962aSWarner Losh 
827270962aSWarner Losh   @return Allocated buffer with the formatted string printed in it.
837270962aSWarner Losh           The caller must free the allocated buffer. The buffer
847270962aSWarner Losh           allocation is not packed.
857270962aSWarner Losh 
867270962aSWarner Losh **/
877270962aSWarner Losh static char *
887270962aSWarner Losh EFIAPI
UefiDevicePathLibCatPrint(IN OUT POOL_PRINT * Str,IN const char * Fmt,...)897270962aSWarner Losh UefiDevicePathLibCatPrint (
907270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
917270962aSWarner Losh   IN const char      *Fmt,
927270962aSWarner Losh   ...
937270962aSWarner Losh   )
947270962aSWarner Losh {
957270962aSWarner Losh   UINTN    Count;
967270962aSWarner Losh   VA_LIST  Args;
977270962aSWarner Losh 
987270962aSWarner Losh   VA_START (Args, Fmt);
997270962aSWarner Losh   Count = vsnprintf (NULL, 0, Fmt, Args);
1007270962aSWarner Losh   VA_END (Args);
1017270962aSWarner Losh 
1027270962aSWarner Losh   if ((Str->Count + (Count + 1)) > Str->Capacity) {
1037270962aSWarner Losh     Str->Capacity = (Str->Count + (Count + 1) * 2);
1045754f582SJose Luis Duran     Str->Str      = reallocf (
1055754f582SJose Luis Duran                       Str->Str,
1065754f582SJose Luis Duran                       Str->Capacity
1075754f582SJose Luis Duran                       );
1087270962aSWarner Losh     ASSERT (Str->Str != NULL);
1097270962aSWarner Losh   }
1105754f582SJose Luis Duran 
1117270962aSWarner Losh   VA_START (Args, Fmt);
1127270962aSWarner Losh   vsnprintf (Str->Str + Str->Count, Str->Capacity - Str->Count, Fmt, Args);
1137270962aSWarner Losh   Str->Count += Count;
1147270962aSWarner Losh 
1157270962aSWarner Losh   VA_END (Args);
1167270962aSWarner Losh   return Str->Str;
1177270962aSWarner Losh }
1187270962aSWarner Losh 
1197270962aSWarner Losh /**
1207270962aSWarner Losh   Converts a PCI device path structure to its string representative.
1217270962aSWarner Losh 
1227270962aSWarner Losh   @param Str             The string representative of input device.
1237270962aSWarner Losh   @param DevPath         The input device path structure.
1247270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
1257270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
1267270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
1277270962aSWarner Losh                          is used.
1287270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
1297270962aSWarner Losh                          representation for a device node can be used, where applicable.
1307270962aSWarner Losh 
1317270962aSWarner Losh **/
1327270962aSWarner Losh static VOID
DevPathToTextPci(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)1337270962aSWarner Losh DevPathToTextPci (
1347270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
1357270962aSWarner Losh   IN VOID            *DevPath,
1367270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
1377270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
1387270962aSWarner Losh   )
1397270962aSWarner Losh {
1407270962aSWarner Losh   PCI_DEVICE_PATH  *Pci;
1417270962aSWarner Losh 
1427270962aSWarner Losh   Pci = DevPath;
1437270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Pci(0x%x,0x%x)", Pci->Device, Pci->Function);
1447270962aSWarner Losh }
1457270962aSWarner Losh 
1467270962aSWarner Losh /**
1477270962aSWarner Losh   Converts a PC Card device path structure to its string representative.
1487270962aSWarner Losh 
1497270962aSWarner Losh   @param Str             The string representative of input device.
1507270962aSWarner Losh   @param DevPath         The input device path structure.
1517270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
1527270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
1537270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
1547270962aSWarner Losh                          is used.
1557270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
1567270962aSWarner Losh                          representation for a device node can be used, where applicable.
1577270962aSWarner Losh 
1587270962aSWarner Losh **/
1597270962aSWarner Losh static VOID
DevPathToTextPccard(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)1607270962aSWarner Losh DevPathToTextPccard (
1617270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
1627270962aSWarner Losh   IN VOID            *DevPath,
1637270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
1647270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
1657270962aSWarner Losh   )
1667270962aSWarner Losh {
1677270962aSWarner Losh   PCCARD_DEVICE_PATH  *Pccard;
1687270962aSWarner Losh 
1697270962aSWarner Losh   Pccard = DevPath;
1707270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "PcCard(0x%x)", Pccard->FunctionNumber);
1717270962aSWarner Losh }
1727270962aSWarner Losh 
1737270962aSWarner Losh /**
1747270962aSWarner Losh   Converts a Memory Map device path structure to its string representative.
1757270962aSWarner Losh 
1767270962aSWarner Losh   @param Str             The string representative of input device.
1777270962aSWarner Losh   @param DevPath         The input device path structure.
1787270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
1797270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
1807270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
1817270962aSWarner Losh                          is used.
1827270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
1837270962aSWarner Losh                          representation for a device node can be used, where applicable.
1847270962aSWarner Losh 
1857270962aSWarner Losh **/
1867270962aSWarner Losh static VOID
DevPathToTextMemMap(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)1877270962aSWarner Losh DevPathToTextMemMap (
1887270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
1897270962aSWarner Losh   IN VOID            *DevPath,
1907270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
1917270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
1927270962aSWarner Losh   )
1937270962aSWarner Losh {
1947270962aSWarner Losh   MEMMAP_DEVICE_PATH  *MemMap;
1957270962aSWarner Losh 
1967270962aSWarner Losh   MemMap = DevPath;
1977270962aSWarner Losh   UefiDevicePathLibCatPrint (
1987270962aSWarner Losh     Str,
1997270962aSWarner Losh     "MemoryMapped(0x%x,0x%lx,0x%lx)",
2007270962aSWarner Losh     MemMap->MemoryType,
2017270962aSWarner Losh     MemMap->StartingAddress,
2027270962aSWarner Losh     MemMap->EndingAddress
2037270962aSWarner Losh     );
2047270962aSWarner Losh }
2057270962aSWarner Losh 
2067270962aSWarner Losh /**
2077270962aSWarner Losh   Converts a Vendor device path structure to its string representative.
2087270962aSWarner Losh 
2097270962aSWarner Losh   @param Str             The string representative of input device.
2107270962aSWarner Losh   @param DevPath         The input device path structure.
2117270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
2127270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
2137270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
2147270962aSWarner Losh                          is used.
2157270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
2167270962aSWarner Losh                          representation for a device node can be used, where applicable.
2177270962aSWarner Losh 
2187270962aSWarner Losh **/
2197270962aSWarner Losh static VOID
DevPathToTextVendor(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)2207270962aSWarner Losh DevPathToTextVendor (
2217270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
2227270962aSWarner Losh   IN VOID            *DevPath,
2237270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
2247270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
2257270962aSWarner Losh   )
2267270962aSWarner Losh {
2277270962aSWarner Losh   VENDOR_DEVICE_PATH  *Vendor;
2287270962aSWarner Losh   const char          *Type;
2297270962aSWarner Losh   UINTN               Index;
2307270962aSWarner Losh   UINTN               DataLength;
2317270962aSWarner Losh   UINT32              FlowControlMap;
2327270962aSWarner Losh   UINT16              Info;
2337270962aSWarner Losh 
2347270962aSWarner Losh   Vendor = (VENDOR_DEVICE_PATH *)DevPath;
2357270962aSWarner Losh   switch (DevicePathType (&Vendor->Header)) {
2367270962aSWarner Losh     case HARDWARE_DEVICE_PATH:
2377270962aSWarner Losh       Type = "Hw";
2387270962aSWarner Losh       break;
2397270962aSWarner Losh 
2407270962aSWarner Losh     case MESSAGING_DEVICE_PATH:
2417270962aSWarner Losh       Type = "Msg";
2427270962aSWarner Losh       if (AllowShortcuts) {
2437270962aSWarner Losh         if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
2447270962aSWarner Losh           UefiDevicePathLibCatPrint (Str, "VenPcAnsi()");
2457270962aSWarner Losh           return;
2467270962aSWarner Losh         } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
2477270962aSWarner Losh           UefiDevicePathLibCatPrint (Str, "VenVt100()");
2487270962aSWarner Losh           return;
2497270962aSWarner Losh         } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
2507270962aSWarner Losh           UefiDevicePathLibCatPrint (Str, "VenVt100Plus()");
2517270962aSWarner Losh           return;
2527270962aSWarner Losh         } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
25391a35e58SJose Luis Duran           UefiDevicePathLibCatPrint (Str, "VenUtf8()");
2547270962aSWarner Losh           return;
2557270962aSWarner Losh         } else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid)) {
2567270962aSWarner Losh           FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *)Vendor)->FlowControlMap);
2577270962aSWarner Losh           switch (FlowControlMap & 0x00000003) {
2587270962aSWarner Losh             case 0:
2597270962aSWarner Losh               UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "None");
2607270962aSWarner Losh               break;
2617270962aSWarner Losh 
2627270962aSWarner Losh             case 1:
2637270962aSWarner Losh               UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "Hardware");
2647270962aSWarner Losh               break;
2657270962aSWarner Losh 
2667270962aSWarner Losh             case 2:
2677270962aSWarner Losh               UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "XonXoff");
2687270962aSWarner Losh               break;
2697270962aSWarner Losh 
2707270962aSWarner Losh             default:
2717270962aSWarner Losh               break;
2727270962aSWarner Losh           }
2737270962aSWarner Losh 
2747270962aSWarner Losh           return;
2757270962aSWarner Losh         } else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {
2767270962aSWarner Losh           UefiDevicePathLibCatPrint (
2777270962aSWarner Losh             Str,
2787270962aSWarner Losh             "SAS(0x%lx,0x%lx,0x%x,",
2797270962aSWarner Losh             ((SAS_DEVICE_PATH *)Vendor)->SasAddress,
2807270962aSWarner Losh             ((SAS_DEVICE_PATH *)Vendor)->Lun,
2817270962aSWarner Losh             ((SAS_DEVICE_PATH *)Vendor)->RelativeTargetPort
2827270962aSWarner Losh             );
2837270962aSWarner Losh           Info = (((SAS_DEVICE_PATH *)Vendor)->DeviceTopology);
2847270962aSWarner Losh           if (((Info & 0x0f) == 0) && ((Info & BIT7) == 0)) {
2857270962aSWarner Losh             UefiDevicePathLibCatPrint (Str, "NoTopology,0,0,0,");
2867270962aSWarner Losh           } else if (((Info & 0x0f) <= 2) && ((Info & BIT7) == 0)) {
2877270962aSWarner Losh             UefiDevicePathLibCatPrint (
2887270962aSWarner Losh               Str,
2897270962aSWarner Losh               "%s,%s,%s,",
2907270962aSWarner Losh               ((Info & BIT4) != 0) ? "SATA" : "SAS",
2917270962aSWarner Losh               ((Info & BIT5) != 0) ? "External" : "Internal",
2927270962aSWarner Losh               ((Info & BIT6) != 0) ? "Expanded" : "Direct"
2937270962aSWarner Losh               );
2947270962aSWarner Losh             if ((Info & 0x0f) == 1) {
2957270962aSWarner Losh               UefiDevicePathLibCatPrint (Str, "0,");
2967270962aSWarner Losh             } else {
2977270962aSWarner Losh               //
2987270962aSWarner Losh               // Value 0x0 thru 0xFF -> Drive 1 thru Drive 256
2997270962aSWarner Losh               //
3007270962aSWarner Losh               UefiDevicePathLibCatPrint (Str, "0x%x,", ((Info >> 8) & 0xff) + 1);
3017270962aSWarner Losh             }
3027270962aSWarner Losh           } else {
3037270962aSWarner Losh             UefiDevicePathLibCatPrint (Str, "0x%x,0,0,0,", Info);
3047270962aSWarner Losh           }
3057270962aSWarner Losh 
3067270962aSWarner Losh           UefiDevicePathLibCatPrint (Str, "0x%x)", ((SAS_DEVICE_PATH *)Vendor)->Reserved);
3077270962aSWarner Losh           return;
3087270962aSWarner Losh         } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
3097270962aSWarner Losh           UefiDevicePathLibCatPrint (Str, "DebugPort()");
3107270962aSWarner Losh           return;
3117270962aSWarner Losh         }
3127270962aSWarner Losh       }
3135754f582SJose Luis Duran 
3147270962aSWarner Losh       break;
3157270962aSWarner Losh 
3167270962aSWarner Losh     case MEDIA_DEVICE_PATH:
3177270962aSWarner Losh       Type = "Media";
3187270962aSWarner Losh       break;
3197270962aSWarner Losh 
3207270962aSWarner Losh     default:
3217270962aSWarner Losh       Type = "?";
3227270962aSWarner Losh       break;
3237270962aSWarner Losh   }
3247270962aSWarner Losh 
3257270962aSWarner Losh   DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
3267270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Ven%s(%36s", Type, G(&Vendor->Guid));
3277270962aSWarner Losh   if (DataLength != 0) {
3287270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ",");
3297270962aSWarner Losh     for (Index = 0; Index < DataLength; Index++) {
3307270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "%02x", ((VENDOR_DEVICE_PATH_WITH_DATA *)Vendor)->VendorDefinedData[Index]);
3317270962aSWarner Losh     }
3327270962aSWarner Losh   }
3337270962aSWarner Losh 
3347270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ")");
3357270962aSWarner Losh }
3367270962aSWarner Losh 
3377270962aSWarner Losh /**
3387270962aSWarner Losh   Converts a Controller device path structure to its string representative.
3397270962aSWarner Losh 
3407270962aSWarner Losh   @param Str             The string representative of input device.
3417270962aSWarner Losh   @param DevPath         The input device path structure.
3427270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
3437270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
3447270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
3457270962aSWarner Losh                          is used.
3467270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
3477270962aSWarner Losh                          representation for a device node can be used, where applicable.
3487270962aSWarner Losh 
3497270962aSWarner Losh **/
3507270962aSWarner Losh static VOID
DevPathToTextController(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)3517270962aSWarner Losh DevPathToTextController (
3527270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
3537270962aSWarner Losh   IN VOID            *DevPath,
3547270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
3557270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
3567270962aSWarner Losh   )
3577270962aSWarner Losh {
3587270962aSWarner Losh   CONTROLLER_DEVICE_PATH  *Controller;
3597270962aSWarner Losh 
3607270962aSWarner Losh   Controller = DevPath;
3617270962aSWarner Losh   UefiDevicePathLibCatPrint (
3627270962aSWarner Losh     Str,
3637270962aSWarner Losh     "Ctrl(0x%x)",
3647270962aSWarner Losh     Controller->ControllerNumber
3657270962aSWarner Losh     );
3667270962aSWarner Losh }
3677270962aSWarner Losh 
3687270962aSWarner Losh /**
3697270962aSWarner Losh   Converts a BMC device path structure to its string representative.
3707270962aSWarner Losh 
3717270962aSWarner Losh   @param Str             The string representative of input device.
3727270962aSWarner Losh   @param DevPath         The input device path structure.
3737270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
3747270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
3757270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
3767270962aSWarner Losh                          is used.
3777270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
3787270962aSWarner Losh                          representation for a device node can be used, where applicable.
3797270962aSWarner Losh 
3807270962aSWarner Losh **/
3817270962aSWarner Losh static VOID
DevPathToTextBmc(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)3827270962aSWarner Losh DevPathToTextBmc (
3837270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
3847270962aSWarner Losh   IN VOID            *DevPath,
3857270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
3867270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
3877270962aSWarner Losh   )
3887270962aSWarner Losh {
3897270962aSWarner Losh   BMC_DEVICE_PATH  *Bmc;
3907270962aSWarner Losh 
3917270962aSWarner Losh   Bmc = DevPath;
3927270962aSWarner Losh   UefiDevicePathLibCatPrint (
3937270962aSWarner Losh     Str,
3947270962aSWarner Losh     "BMC(0x%x,0x%lx)",
3957270962aSWarner Losh     Bmc->InterfaceType,
3967270962aSWarner Losh     ReadUnaligned64 ((&Bmc->BaseAddress))
3977270962aSWarner Losh     );
3987270962aSWarner Losh }
3997270962aSWarner Losh 
4007270962aSWarner Losh /**
4017270962aSWarner Losh   Converts a ACPI device path structure to its string representative.
4027270962aSWarner Losh 
4037270962aSWarner Losh   @param Str             The string representative of input device.
4047270962aSWarner Losh   @param DevPath         The input device path structure.
4057270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
4067270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
4077270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
4087270962aSWarner Losh                          is used.
4097270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
4107270962aSWarner Losh                          representation for a device node can be used, where applicable.
4117270962aSWarner Losh 
4127270962aSWarner Losh **/
4137270962aSWarner Losh static VOID
DevPathToTextAcpi(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)4147270962aSWarner Losh DevPathToTextAcpi (
4157270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
4167270962aSWarner Losh   IN VOID            *DevPath,
4177270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
4187270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
4197270962aSWarner Losh   )
4207270962aSWarner Losh {
4217270962aSWarner Losh   ACPI_HID_DEVICE_PATH  *Acpi;
4227270962aSWarner Losh 
4237270962aSWarner Losh   Acpi = DevPath;
4247270962aSWarner Losh   if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
4257270962aSWarner Losh     switch (EISA_ID_TO_NUM (Acpi->HID)) {
4267270962aSWarner Losh       case 0x0a03:
4277270962aSWarner Losh         UefiDevicePathLibCatPrint (Str, "PciRoot(0x%x)", Acpi->UID);
4287270962aSWarner Losh         break;
4297270962aSWarner Losh 
4307270962aSWarner Losh       case 0x0a08:
4317270962aSWarner Losh         UefiDevicePathLibCatPrint (Str, "PcieRoot(0x%x)", Acpi->UID);
4327270962aSWarner Losh         break;
4337270962aSWarner Losh 
4347270962aSWarner Losh       case 0x0604:
4357270962aSWarner Losh         UefiDevicePathLibCatPrint (Str, "Floppy(0x%x)", Acpi->UID);
4367270962aSWarner Losh         break;
4377270962aSWarner Losh 
4387270962aSWarner Losh       case 0x0301:
4397270962aSWarner Losh         UefiDevicePathLibCatPrint (Str, "Keyboard(0x%x)", Acpi->UID);
4407270962aSWarner Losh         break;
4417270962aSWarner Losh 
4427270962aSWarner Losh       case 0x0501:
4437270962aSWarner Losh         UefiDevicePathLibCatPrint (Str, "Serial(0x%x)", Acpi->UID);
4447270962aSWarner Losh         break;
4457270962aSWarner Losh 
4467270962aSWarner Losh       case 0x0401:
4477270962aSWarner Losh         UefiDevicePathLibCatPrint (Str, "ParallelPort(0x%x)", Acpi->UID);
4487270962aSWarner Losh         break;
4497270962aSWarner Losh 
4507270962aSWarner Losh       default:
4517270962aSWarner Losh         UefiDevicePathLibCatPrint (Str, "Acpi(PNP%04x,0x%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);
4527270962aSWarner Losh         break;
4537270962aSWarner Losh     }
4547270962aSWarner Losh   } else {
4557270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "Acpi(0x%08x,0x%x)", Acpi->HID, Acpi->UID);
4567270962aSWarner Losh   }
4577270962aSWarner Losh }
4587270962aSWarner Losh 
4597270962aSWarner Losh /**
4607270962aSWarner Losh   Converts a ACPI extended HID device path structure to its string representative.
4617270962aSWarner Losh 
4627270962aSWarner Losh   @param Str             The string representative of input device.
4637270962aSWarner Losh   @param DevPath         The input device path structure.
4647270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
4657270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
4667270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
4677270962aSWarner Losh                          is used.
4687270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
4697270962aSWarner Losh                          representation for a device node can be used, where applicable.
4707270962aSWarner Losh 
4717270962aSWarner Losh **/
4727270962aSWarner Losh static VOID
DevPathToTextAcpiEx(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)4737270962aSWarner Losh DevPathToTextAcpiEx (
4747270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
4757270962aSWarner Losh   IN VOID            *DevPath,
4767270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
4777270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
4787270962aSWarner Losh   )
4797270962aSWarner Losh {
4807270962aSWarner Losh   ACPI_EXTENDED_HID_DEVICE_PATH  *AcpiEx;
4817270962aSWarner Losh   char                           HIDText[11];
4827270962aSWarner Losh   char                           CIDText[11];
483*3f0efe05SJose Luis Duran   UINTN                          CurrentLength;
484*3f0efe05SJose Luis Duran   CHAR8                          *CurrentPos;
485*3f0efe05SJose Luis Duran   UINTN                          NextStringOffset;
486*3f0efe05SJose Luis Duran   CHAR8                          *Strings[3];
487*3f0efe05SJose Luis Duran   UINT8                          HidStrIndex;
488*3f0efe05SJose Luis Duran   UINT8                          UidStrIndex;
489*3f0efe05SJose Luis Duran   UINT8                          CidStrIndex;
490*3f0efe05SJose Luis Duran   UINT8                          StrIndex;
4917270962aSWarner Losh 
492*3f0efe05SJose Luis Duran   HidStrIndex          = 0;
493*3f0efe05SJose Luis Duran   UidStrIndex          = 1;
494*3f0efe05SJose Luis Duran   CidStrIndex          = 2;
4957270962aSWarner Losh   AcpiEx               = DevPath;
496*3f0efe05SJose Luis Duran   Strings[HidStrIndex] = NULL;
497*3f0efe05SJose Luis Duran   Strings[UidStrIndex] = NULL;
498*3f0efe05SJose Luis Duran   Strings[CidStrIndex] = NULL;
499*3f0efe05SJose Luis Duran   CurrentLength        = sizeof (ACPI_EXTENDED_HID_DEVICE_PATH);
500*3f0efe05SJose Luis Duran   CurrentPos           = (CHAR8 *)(((UINT8 *)AcpiEx) + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
501*3f0efe05SJose Luis Duran   StrIndex             = 0;
502*3f0efe05SJose Luis Duran   while (CurrentLength < AcpiEx->Header.Length[0] && StrIndex < ARRAY_SIZE (Strings)) {
503*3f0efe05SJose Luis Duran     Strings[StrIndex] = CurrentPos;
504*3f0efe05SJose Luis Duran     NextStringOffset  = AsciiStrLen (CurrentPos) + 1;
505*3f0efe05SJose Luis Duran     CurrentLength    += NextStringOffset;
506*3f0efe05SJose Luis Duran     CurrentPos       += NextStringOffset;
507*3f0efe05SJose Luis Duran     StrIndex++;
508*3f0efe05SJose Luis Duran   }
5097270962aSWarner Losh 
510a51ae721SJose Luis Duran   if (DisplayOnly) {
511a51ae721SJose Luis Duran     if ((EISA_ID_TO_NUM (AcpiEx->HID) == 0x0A03) ||
5125754f582SJose Luis Duran         ((EISA_ID_TO_NUM (AcpiEx->CID) == 0x0A03) && (EISA_ID_TO_NUM (AcpiEx->HID) != 0x0A08)))
5135754f582SJose Luis Duran     {
514*3f0efe05SJose Luis Duran       if (Strings[UidStrIndex] != NULL) {
515*3f0efe05SJose Luis Duran         UefiDevicePathLibCatPrint (Str, "PciRoot(%s)", Strings[UidStrIndex]);
516a51ae721SJose Luis Duran       } else {
517a51ae721SJose Luis Duran         UefiDevicePathLibCatPrint (Str, "PciRoot(0x%x)", AcpiEx->UID);
518a51ae721SJose Luis Duran       }
5195754f582SJose Luis Duran 
520a51ae721SJose Luis Duran       return;
521a51ae721SJose Luis Duran     }
522a51ae721SJose Luis Duran 
5235754f582SJose Luis Duran     if ((EISA_ID_TO_NUM (AcpiEx->HID) == 0x0A08) || (EISA_ID_TO_NUM (AcpiEx->CID) == 0x0A08)) {
524*3f0efe05SJose Luis Duran       if (Strings[UidStrIndex] != NULL) {
525*3f0efe05SJose Luis Duran         UefiDevicePathLibCatPrint (Str, "PcieRoot(%s)", Strings[UidStrIndex]);
526a51ae721SJose Luis Duran       } else {
527a51ae721SJose Luis Duran         UefiDevicePathLibCatPrint (Str, "PcieRoot(0x%x)", AcpiEx->UID);
528a51ae721SJose Luis Duran       }
5295754f582SJose Luis Duran 
530a51ae721SJose Luis Duran       return;
531a51ae721SJose Luis Duran     }
532a51ae721SJose Luis Duran   }
533a51ae721SJose Luis Duran 
5347270962aSWarner Losh   //
5357270962aSWarner Losh   // Converts EISA identification to string.
5367270962aSWarner Losh   //
5377270962aSWarner Losh   UnicodeSPrint (
5387270962aSWarner Losh     HIDText,
5397270962aSWarner Losh     sizeof (HIDText),
5407270962aSWarner Losh     "%c%c%c%04X",
5417270962aSWarner Losh     ((AcpiEx->HID >> 10) & 0x1f) + 'A' - 1,
5427270962aSWarner Losh     ((AcpiEx->HID >>  5) & 0x1f) + 'A' - 1,
5437270962aSWarner Losh     ((AcpiEx->HID >>  0) & 0x1f) + 'A' - 1,
5447270962aSWarner Losh     (AcpiEx->HID >> 16) & 0xFFFF
5457270962aSWarner Losh     );
5467270962aSWarner Losh   UnicodeSPrint (
5477270962aSWarner Losh     CIDText,
5487270962aSWarner Losh     sizeof (CIDText),
5497270962aSWarner Losh     "%c%c%c%04X",
5507270962aSWarner Losh     ((AcpiEx->CID >> 10) & 0x1f) + 'A' - 1,
5517270962aSWarner Losh     ((AcpiEx->CID >>  5) & 0x1f) + 'A' - 1,
5527270962aSWarner Losh     ((AcpiEx->CID >>  0) & 0x1f) + 'A' - 1,
5537270962aSWarner Losh     (AcpiEx->CID >> 16) & 0xFFFF
5547270962aSWarner Losh     );
5557270962aSWarner Losh 
556*3f0efe05SJose Luis Duran   if (((Strings[HidStrIndex] != NULL) && (*Strings[HidStrIndex] == '\0')) &&
557*3f0efe05SJose Luis Duran       ((Strings[CidStrIndex] != NULL) && (*Strings[CidStrIndex] == '\0')) &&
558*3f0efe05SJose Luis Duran       ((Strings[UidStrIndex] != NULL) && (*Strings[UidStrIndex] != '\0')))
559*3f0efe05SJose Luis Duran   {
5607270962aSWarner Losh     //
5617270962aSWarner Losh     // use AcpiExp()
5627270962aSWarner Losh     //
563492d9953SJose Luis Duran     if (AcpiEx->CID == 0) {
564492d9953SJose Luis Duran       UefiDevicePathLibCatPrint (
565492d9953SJose Luis Duran         Str,
566492d9953SJose Luis Duran         "AcpiExp(%s,0,%s)",
567492d9953SJose Luis Duran         HIDText,
568*3f0efe05SJose Luis Duran         Strings[UidStrIndex]
569492d9953SJose Luis Duran         );
570492d9953SJose Luis Duran     } else {
5717270962aSWarner Losh       UefiDevicePathLibCatPrint (
5727270962aSWarner Losh         Str,
5737270962aSWarner Losh         "AcpiExp(%s,%s,%s)",
5747270962aSWarner Losh         HIDText,
5757270962aSWarner Losh         CIDText,
576*3f0efe05SJose Luis Duran         Strings[UidStrIndex]
5777270962aSWarner Losh         );
578492d9953SJose Luis Duran     }
5797270962aSWarner Losh   } else {
580c1fa6f4cSJose Luis Duran     if (DisplayOnly) {
581*3f0efe05SJose Luis Duran       if (Strings[HidStrIndex] != NULL) {
582*3f0efe05SJose Luis Duran         UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", Strings[HidStrIndex]);
5837270962aSWarner Losh       } else {
5847270962aSWarner Losh         UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", HIDText);
5857270962aSWarner Losh       }
5867270962aSWarner Losh 
587*3f0efe05SJose Luis Duran       if (Strings[CidStrIndex] != NULL) {
588*3f0efe05SJose Luis Duran         UefiDevicePathLibCatPrint (Str, "%s,", Strings[CidStrIndex]);
5897270962aSWarner Losh       } else {
5908278071aSJose Luis Duran         UefiDevicePathLibCatPrint (Str, "%s,", CIDText);
5917270962aSWarner Losh       }
5927270962aSWarner Losh 
593*3f0efe05SJose Luis Duran       if (Strings[UidStrIndex] != NULL) {
594*3f0efe05SJose Luis Duran         UefiDevicePathLibCatPrint (Str, "%s)", Strings[UidStrIndex]);
5957270962aSWarner Losh       } else {
5968278071aSJose Luis Duran         UefiDevicePathLibCatPrint (Str, "0x%x)", AcpiEx->UID);
5977270962aSWarner Losh       }
5987270962aSWarner Losh     } else {
5997270962aSWarner Losh       UefiDevicePathLibCatPrint (
6007270962aSWarner Losh         Str,
6017270962aSWarner Losh         "AcpiEx(%s,%s,0x%x,%s,%s,%s)",
6027270962aSWarner Losh         HIDText,
6037270962aSWarner Losh         CIDText,
6047270962aSWarner Losh         AcpiEx->UID,
605*3f0efe05SJose Luis Duran         Strings[HidStrIndex] != NULL ? Strings[HidStrIndex] : '\0',
606*3f0efe05SJose Luis Duran         Strings[CidStrIndex] != NULL ? Strings[CidStrIndex] : '\0',
607*3f0efe05SJose Luis Duran         Strings[UidStrIndex] != NULL ? Strings[UidStrIndex] : '\0'
6087270962aSWarner Losh         );
6097270962aSWarner Losh     }
6107270962aSWarner Losh   }
6117270962aSWarner Losh }
6127270962aSWarner Losh 
6137270962aSWarner Losh /**
6147270962aSWarner Losh   Converts a ACPI address device path structure to its string representative.
6157270962aSWarner Losh 
6167270962aSWarner Losh   @param Str             The string representative of input device.
6177270962aSWarner Losh   @param DevPath         The input device path structure.
6187270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
6197270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
6207270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
6217270962aSWarner Losh                          is used.
6227270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
6237270962aSWarner Losh                          representation for a device node can be used, where applicable.
6247270962aSWarner Losh 
6257270962aSWarner Losh **/
6267270962aSWarner Losh static VOID
DevPathToTextAcpiAdr(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)6277270962aSWarner Losh DevPathToTextAcpiAdr (
6287270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
6297270962aSWarner Losh   IN VOID            *DevPath,
6307270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
6317270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
6327270962aSWarner Losh   )
6337270962aSWarner Losh {
6347270962aSWarner Losh   ACPI_ADR_DEVICE_PATH  *AcpiAdr;
6357270962aSWarner Losh   UINT32                *Addr;
6367270962aSWarner Losh   UINT16                Index;
6377270962aSWarner Losh   UINT16                Length;
6387270962aSWarner Losh   UINT16                AdditionalAdrCount;
6397270962aSWarner Losh 
6407270962aSWarner Losh   AcpiAdr            = DevPath;
6417270962aSWarner Losh   Length             = (UINT16)DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr);
6427270962aSWarner Losh   AdditionalAdrCount = (UINT16)((Length - 8) / 4);
6437270962aSWarner Losh 
6447270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "AcpiAdr(0x%x", AcpiAdr->ADR);
6457270962aSWarner Losh   Addr = &AcpiAdr->ADR + 1;
6467270962aSWarner Losh   for (Index = 0; Index < AdditionalAdrCount; Index++) {
6477270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ",0x%x", Addr[Index]);
6487270962aSWarner Losh   }
6495754f582SJose Luis Duran 
6507270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ")");
6517270962aSWarner Losh }
6527270962aSWarner Losh 
6537270962aSWarner Losh /**
6547270962aSWarner Losh   Converts a ATAPI device path structure to its string representative.
6557270962aSWarner Losh 
6567270962aSWarner Losh   @param Str             The string representative of input device.
6577270962aSWarner Losh   @param DevPath         The input device path structure.
6587270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
6597270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
6607270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
6617270962aSWarner Losh                          is used.
6627270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
6637270962aSWarner Losh                          representation for a device node can be used, where applicable.
6647270962aSWarner Losh 
6657270962aSWarner Losh **/
6667270962aSWarner Losh static VOID
DevPathToTextAtapi(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)6677270962aSWarner Losh DevPathToTextAtapi (
6687270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
6697270962aSWarner Losh   IN VOID            *DevPath,
6707270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
6717270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
6727270962aSWarner Losh   )
6737270962aSWarner Losh {
6747270962aSWarner Losh   ATAPI_DEVICE_PATH  *Atapi;
6757270962aSWarner Losh 
6767270962aSWarner Losh   Atapi = DevPath;
6777270962aSWarner Losh 
6787270962aSWarner Losh   if (DisplayOnly) {
6797270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "Ata(0x%x)", Atapi->Lun);
6807270962aSWarner Losh   } else {
6817270962aSWarner Losh     UefiDevicePathLibCatPrint (
6827270962aSWarner Losh       Str,
6837270962aSWarner Losh       "Ata(%s,%s,0x%x)",
6847270962aSWarner Losh       (Atapi->PrimarySecondary == 1) ? "Secondary" : "Primary",
6857270962aSWarner Losh       (Atapi->SlaveMaster == 1) ? "Slave" : "Master",
6867270962aSWarner Losh       Atapi->Lun
6877270962aSWarner Losh       );
6887270962aSWarner Losh   }
6897270962aSWarner Losh }
6907270962aSWarner Losh 
6917270962aSWarner Losh /**
6927270962aSWarner Losh   Converts a SCSI device path structure to its string representative.
6937270962aSWarner Losh 
6947270962aSWarner Losh   @param Str             The string representative of input device.
6957270962aSWarner Losh   @param DevPath         The input device path structure.
6967270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
6977270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
6987270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
6997270962aSWarner Losh                          is used.
7007270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
7017270962aSWarner Losh                          representation for a device node can be used, where applicable.
7027270962aSWarner Losh 
7037270962aSWarner Losh **/
7047270962aSWarner Losh static VOID
DevPathToTextScsi(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)7057270962aSWarner Losh DevPathToTextScsi (
7067270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
7077270962aSWarner Losh   IN VOID            *DevPath,
7087270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
7097270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
7107270962aSWarner Losh   )
7117270962aSWarner Losh {
7127270962aSWarner Losh   SCSI_DEVICE_PATH  *Scsi;
7137270962aSWarner Losh 
7147270962aSWarner Losh   Scsi = DevPath;
7157270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Scsi(0x%x,0x%x)", Scsi->Pun, Scsi->Lun);
7167270962aSWarner Losh }
7177270962aSWarner Losh 
7187270962aSWarner Losh /**
7197270962aSWarner Losh   Converts a Fibre device path structure to its string representative.
7207270962aSWarner Losh 
7217270962aSWarner Losh   @param Str             The string representative of input device.
7227270962aSWarner Losh   @param DevPath         The input device path structure.
7237270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
7247270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
7257270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
7267270962aSWarner Losh                          is used.
7277270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
7287270962aSWarner Losh                          representation for a device node can be used, where applicable.
7297270962aSWarner Losh 
7307270962aSWarner Losh **/
7317270962aSWarner Losh static VOID
DevPathToTextFibre(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)7327270962aSWarner Losh DevPathToTextFibre (
7337270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
7347270962aSWarner Losh   IN VOID            *DevPath,
7357270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
7367270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
7377270962aSWarner Losh   )
7387270962aSWarner Losh {
7397270962aSWarner Losh   FIBRECHANNEL_DEVICE_PATH  *Fibre;
7407270962aSWarner Losh 
7417270962aSWarner Losh   Fibre = DevPath;
7427270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Fibre(0x%lx,0x%lx)", Fibre->WWN, Fibre->Lun);
7437270962aSWarner Losh }
7447270962aSWarner Losh 
7457270962aSWarner Losh /**
7467270962aSWarner Losh   Converts a FibreEx device path structure to its string representative.
7477270962aSWarner Losh 
7487270962aSWarner Losh   @param Str             The string representative of input device.
7497270962aSWarner Losh   @param DevPath         The input device path structure.
7507270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
7517270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
7527270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
7537270962aSWarner Losh                          is used.
7547270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
7557270962aSWarner Losh                          representation for a device node can be used, where applicable.
7567270962aSWarner Losh 
7577270962aSWarner Losh **/
7587270962aSWarner Losh static VOID
DevPathToTextFibreEx(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)7597270962aSWarner Losh DevPathToTextFibreEx (
7607270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
7617270962aSWarner Losh   IN VOID            *DevPath,
7627270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
7637270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
7647270962aSWarner Losh   )
7657270962aSWarner Losh {
7667270962aSWarner Losh   FIBRECHANNELEX_DEVICE_PATH  *FibreEx;
7677270962aSWarner Losh   UINTN                       Index;
7687270962aSWarner Losh 
7697270962aSWarner Losh   FibreEx = DevPath;
7707270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "FibreEx(0x");
7717270962aSWarner Losh   for (Index = 0; Index < sizeof (FibreEx->WWN) / sizeof (FibreEx->WWN[0]); Index++) {
7727270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%02x", FibreEx->WWN[Index]);
7737270962aSWarner Losh   }
7745754f582SJose Luis Duran 
7757270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",0x");
7767270962aSWarner Losh   for (Index = 0; Index < sizeof (FibreEx->Lun) / sizeof (FibreEx->Lun[0]); Index++) {
7777270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%02x", FibreEx->Lun[Index]);
7787270962aSWarner Losh   }
7795754f582SJose Luis Duran 
7807270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ")");
7817270962aSWarner Losh }
7827270962aSWarner Losh 
7837270962aSWarner Losh /**
7847270962aSWarner Losh   Converts a Sas Ex device path structure to its string representative.
7857270962aSWarner Losh 
7867270962aSWarner Losh   @param Str             The string representative of input device.
7877270962aSWarner Losh   @param DevPath         The input device path structure.
7887270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
7897270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
7907270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
7917270962aSWarner Losh                          is used.
7927270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
7937270962aSWarner Losh                          representation for a device node can be used, where applicable.
7947270962aSWarner Losh 
7957270962aSWarner Losh **/
7967270962aSWarner Losh static VOID
DevPathToTextSasEx(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)7977270962aSWarner Losh DevPathToTextSasEx (
7987270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
7997270962aSWarner Losh   IN VOID            *DevPath,
8007270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
8017270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
8027270962aSWarner Losh   )
8037270962aSWarner Losh {
8047270962aSWarner Losh   SASEX_DEVICE_PATH  *SasEx;
8057270962aSWarner Losh   UINTN              Index;
8067270962aSWarner Losh 
8077270962aSWarner Losh   SasEx = DevPath;
8087270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "SasEx(0x");
8097270962aSWarner Losh 
8107270962aSWarner Losh   for (Index = 0; Index < sizeof (SasEx->SasAddress) / sizeof (SasEx->SasAddress[0]); Index++) {
8117270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%02x", SasEx->SasAddress[Index]);
8127270962aSWarner Losh   }
8135754f582SJose Luis Duran 
8147270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",0x");
8157270962aSWarner Losh   for (Index = 0; Index < sizeof (SasEx->Lun) / sizeof (SasEx->Lun[0]); Index++) {
8167270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%02x", SasEx->Lun[Index]);
8177270962aSWarner Losh   }
8185754f582SJose Luis Duran 
8197270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",0x%x,", SasEx->RelativeTargetPort);
8207270962aSWarner Losh 
8217270962aSWarner Losh   if (((SasEx->DeviceTopology & 0x0f) == 0) && ((SasEx->DeviceTopology & BIT7) == 0)) {
8227270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "NoTopology,0,0,0");
8237270962aSWarner Losh   } else if (((SasEx->DeviceTopology & 0x0f) <= 2) && ((SasEx->DeviceTopology & BIT7) == 0)) {
8247270962aSWarner Losh     UefiDevicePathLibCatPrint (
8257270962aSWarner Losh       Str,
8267270962aSWarner Losh       "%s,%s,%s,",
8277270962aSWarner Losh       ((SasEx->DeviceTopology & BIT4) != 0) ? "SATA" : "SAS",
8287270962aSWarner Losh       ((SasEx->DeviceTopology & BIT5) != 0) ? "External" : "Internal",
8297270962aSWarner Losh       ((SasEx->DeviceTopology & BIT6) != 0) ? "Expanded" : "Direct"
8307270962aSWarner Losh       );
8317270962aSWarner Losh     if ((SasEx->DeviceTopology & 0x0f) == 1) {
8327270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "0");
8337270962aSWarner Losh     } else {
8347270962aSWarner Losh       //
8357270962aSWarner Losh       // Value 0x0 thru 0xFF -> Drive 1 thru Drive 256
8367270962aSWarner Losh       //
8377270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "0x%x", ((SasEx->DeviceTopology >> 8) & 0xff) + 1);
8387270962aSWarner Losh     }
8397270962aSWarner Losh   } else {
8407270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "0x%x,0,0,0", SasEx->DeviceTopology);
8417270962aSWarner Losh   }
8427270962aSWarner Losh 
8437270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ")");
8447270962aSWarner Losh   return;
8457270962aSWarner Losh }
8467270962aSWarner Losh 
8477270962aSWarner Losh /**
8487270962aSWarner Losh   Converts a NVM Express Namespace device path structure to its string representative.
8497270962aSWarner Losh 
8507270962aSWarner Losh   @param Str             The string representative of input device.
8517270962aSWarner Losh   @param DevPath         The input device path structure.
8527270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
8537270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
8547270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
8557270962aSWarner Losh                          is used.
8567270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
8577270962aSWarner Losh                          representation for a device node can be used, where applicable.
8587270962aSWarner Losh 
8597270962aSWarner Losh **/
8607270962aSWarner Losh static VOID
DevPathToTextNVMe(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)8617270962aSWarner Losh DevPathToTextNVMe (
8627270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
8637270962aSWarner Losh   IN VOID            *DevPath,
8647270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
8657270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
8667270962aSWarner Losh   )
8677270962aSWarner Losh {
8687270962aSWarner Losh   NVME_NAMESPACE_DEVICE_PATH  *Nvme;
8697270962aSWarner Losh   UINT8                       *Uuid;
8707270962aSWarner Losh 
8717270962aSWarner Losh   Nvme = DevPath;
8727270962aSWarner Losh   Uuid = (UINT8 *)&Nvme->NamespaceUuid;
8737270962aSWarner Losh   UefiDevicePathLibCatPrint (
8747270962aSWarner Losh     Str,
8757270962aSWarner Losh     "NVMe(0x%x,%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x)",
8767270962aSWarner Losh     Nvme->NamespaceId,
8775754f582SJose Luis Duran     Uuid[7],
8785754f582SJose Luis Duran     Uuid[6],
8795754f582SJose Luis Duran     Uuid[5],
8805754f582SJose Luis Duran     Uuid[4],
8815754f582SJose Luis Duran     Uuid[3],
8825754f582SJose Luis Duran     Uuid[2],
8835754f582SJose Luis Duran     Uuid[1],
8845754f582SJose Luis Duran     Uuid[0]
8857270962aSWarner Losh     );
8867270962aSWarner Losh }
8877270962aSWarner Losh 
8887270962aSWarner Losh /**
8897270962aSWarner Losh   Converts a UFS device path structure to its string representative.
8907270962aSWarner Losh 
8917270962aSWarner Losh   @param Str             The string representative of input device.
8927270962aSWarner Losh   @param DevPath         The input device path structure.
8937270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
8947270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
8957270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
8967270962aSWarner Losh                          is used.
8977270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
8987270962aSWarner Losh                          representation for a device node can be used, where applicable.
8997270962aSWarner Losh 
9007270962aSWarner Losh **/
9017270962aSWarner Losh static VOID
DevPathToTextUfs(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)9027270962aSWarner Losh DevPathToTextUfs (
9037270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
9047270962aSWarner Losh   IN VOID            *DevPath,
9057270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
9067270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
9077270962aSWarner Losh   )
9087270962aSWarner Losh {
9097270962aSWarner Losh   UFS_DEVICE_PATH  *Ufs;
9107270962aSWarner Losh 
9117270962aSWarner Losh   Ufs = DevPath;
9127270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "UFS(0x%x,0x%x)", Ufs->Pun, Ufs->Lun);
9137270962aSWarner Losh }
9147270962aSWarner Losh 
9157270962aSWarner Losh /**
9167270962aSWarner Losh   Converts a SD (Secure Digital) device path structure to its string representative.
9177270962aSWarner Losh 
9187270962aSWarner Losh   @param Str             The string representative of input device.
9197270962aSWarner Losh   @param DevPath         The input device path structure.
9207270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
9217270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
9227270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
9237270962aSWarner Losh                          is used.
9247270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
9257270962aSWarner Losh                          representation for a device node can be used, where applicable.
9267270962aSWarner Losh 
9277270962aSWarner Losh **/
9287270962aSWarner Losh static VOID
DevPathToTextSd(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)9297270962aSWarner Losh DevPathToTextSd (
9307270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
9317270962aSWarner Losh   IN VOID            *DevPath,
9327270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
9337270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
9347270962aSWarner Losh   )
9357270962aSWarner Losh {
9367270962aSWarner Losh   SD_DEVICE_PATH  *Sd;
9377270962aSWarner Losh 
9387270962aSWarner Losh   Sd = DevPath;
9397270962aSWarner Losh   UefiDevicePathLibCatPrint (
9407270962aSWarner Losh     Str,
9417270962aSWarner Losh     "SD(0x%x)",
9427270962aSWarner Losh     Sd->SlotNumber
9437270962aSWarner Losh     );
9447270962aSWarner Losh }
9457270962aSWarner Losh 
9467270962aSWarner Losh /**
9477270962aSWarner Losh   Converts a EMMC (Embedded MMC) device path structure to its string representative.
9487270962aSWarner Losh 
9497270962aSWarner Losh   @param Str             The string representative of input device.
9507270962aSWarner Losh   @param DevPath         The input device path structure.
9517270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
9527270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
9537270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
9547270962aSWarner Losh                          is used.
9557270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
9567270962aSWarner Losh                          representation for a device node can be used, where applicable.
9577270962aSWarner Losh 
9587270962aSWarner Losh **/
9597270962aSWarner Losh static VOID
DevPathToTextEmmc(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)9607270962aSWarner Losh DevPathToTextEmmc (
9617270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
9627270962aSWarner Losh   IN VOID            *DevPath,
9637270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
9647270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
9657270962aSWarner Losh   )
9667270962aSWarner Losh {
9677270962aSWarner Losh   EMMC_DEVICE_PATH  *Emmc;
9687270962aSWarner Losh 
9697270962aSWarner Losh   Emmc = DevPath;
9707270962aSWarner Losh   UefiDevicePathLibCatPrint (
9717270962aSWarner Losh     Str,
9727270962aSWarner Losh     "eMMC(0x%x)",
9737270962aSWarner Losh     Emmc->SlotNumber
9747270962aSWarner Losh     );
9757270962aSWarner Losh }
9767270962aSWarner Losh 
9777270962aSWarner Losh /**
9787270962aSWarner Losh   Converts a 1394 device path structure to its string representative.
9797270962aSWarner Losh 
9807270962aSWarner Losh   @param Str             The string representative of input device.
9817270962aSWarner Losh   @param DevPath         The input device path structure.
9827270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
9837270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
9847270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
9857270962aSWarner Losh                          is used.
9867270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
9877270962aSWarner Losh                          representation for a device node can be used, where applicable.
9887270962aSWarner Losh 
9897270962aSWarner Losh **/
9907270962aSWarner Losh static VOID
DevPathToText1394(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)9917270962aSWarner Losh DevPathToText1394 (
9927270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
9937270962aSWarner Losh   IN VOID            *DevPath,
9947270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
9957270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
9967270962aSWarner Losh   )
9977270962aSWarner Losh {
9987270962aSWarner Losh   F1394_DEVICE_PATH  *F1394DevPath;
9997270962aSWarner Losh 
10007270962aSWarner Losh   F1394DevPath = DevPath;
10017270962aSWarner Losh   //
10027270962aSWarner Losh   // Guid has format of IEEE-EUI64
10037270962aSWarner Losh   //
10047270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "I1394(%016lx)", F1394DevPath->Guid);
10057270962aSWarner Losh }
10067270962aSWarner Losh 
10077270962aSWarner Losh /**
10087270962aSWarner Losh   Converts a USB device path structure to its string representative.
10097270962aSWarner Losh 
10107270962aSWarner Losh   @param Str             The string representative of input device.
10117270962aSWarner Losh   @param DevPath         The input device path structure.
10127270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
10137270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
10147270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
10157270962aSWarner Losh                          is used.
10167270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
10177270962aSWarner Losh                          representation for a device node can be used, where applicable.
10187270962aSWarner Losh 
10197270962aSWarner Losh **/
10207270962aSWarner Losh static VOID
DevPathToTextUsb(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)10217270962aSWarner Losh DevPathToTextUsb (
10227270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
10237270962aSWarner Losh   IN VOID            *DevPath,
10247270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
10257270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
10267270962aSWarner Losh   )
10277270962aSWarner Losh {
10287270962aSWarner Losh   USB_DEVICE_PATH  *Usb;
10297270962aSWarner Losh 
10307270962aSWarner Losh   Usb = DevPath;
10317270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "USB(0x%x,0x%x)", Usb->ParentPortNumber, Usb->InterfaceNumber);
10327270962aSWarner Losh }
10337270962aSWarner Losh 
10347270962aSWarner Losh /**
10357270962aSWarner Losh   Converts a USB WWID device path structure to its string representative.
10367270962aSWarner Losh 
10377270962aSWarner Losh   @param Str             The string representative of input device.
10387270962aSWarner Losh   @param DevPath         The input device path structure.
10397270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
10407270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
10417270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
10427270962aSWarner Losh                          is used.
10437270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
10447270962aSWarner Losh                          representation for a device node can be used, where applicable.
10457270962aSWarner Losh 
10467270962aSWarner Losh **/
10477270962aSWarner Losh static VOID
DevPathToTextUsbWWID(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)10487270962aSWarner Losh DevPathToTextUsbWWID (
10497270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
10507270962aSWarner Losh   IN VOID            *DevPath,
10517270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
10527270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
10537270962aSWarner Losh   )
10547270962aSWarner Losh {
10557270962aSWarner Losh   USB_WWID_DEVICE_PATH  *UsbWWId;
10567270962aSWarner Losh   CHAR16                *SerialNumberStr;
10577270962aSWarner Losh   CHAR16                *NewStr;
10587270962aSWarner Losh   UINT16                Length;
10597270962aSWarner Losh 
10607270962aSWarner Losh   UsbWWId = DevPath;
10617270962aSWarner Losh 
10627270962aSWarner Losh   SerialNumberStr = (CHAR16 *)(&UsbWWId + 1);
10637270962aSWarner Losh   Length          = (UINT16)((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *)UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16));
10645754f582SJose Luis Duran   if ((Length >= 1) && (SerialNumberStr[Length - 1] != 0)) {
10657270962aSWarner Losh     //
10667270962aSWarner Losh     // In case no NULL terminator in SerialNumber, create a new one with NULL terminator
10677270962aSWarner Losh     //
1068d30a1689SJohn Baldwin     NewStr = AllocatePool ((Length + 1) * sizeof (CHAR16));
10697270962aSWarner Losh     ASSERT (NewStr != NULL);
1070d30a1689SJohn Baldwin     CopyMem (NewStr, SerialNumberStr, Length * sizeof (CHAR16));
10717270962aSWarner Losh     NewStr[Length]  = 0;
10727270962aSWarner Losh     SerialNumberStr = NewStr;
10737270962aSWarner Losh   }
10747270962aSWarner Losh 
10757270962aSWarner Losh   UefiDevicePathLibCatPrint (
10767270962aSWarner Losh     Str,
10777270962aSWarner Losh     "UsbWwid(0x%x,0x%x,0x%x,\"%S\")",
10787270962aSWarner Losh     UsbWWId->VendorId,
10797270962aSWarner Losh     UsbWWId->ProductId,
10807270962aSWarner Losh     UsbWWId->InterfaceNumber,
10817270962aSWarner Losh     SerialNumberStr
10827270962aSWarner Losh     );
10837270962aSWarner Losh }
10847270962aSWarner Losh 
10857270962aSWarner Losh /**
10867270962aSWarner Losh   Converts a Logic Unit device path structure to its string representative.
10877270962aSWarner Losh 
10887270962aSWarner Losh   @param Str             The string representative of input device.
10897270962aSWarner Losh   @param DevPath         The input device path structure.
10907270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
10917270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
10927270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
10937270962aSWarner Losh                          is used.
10947270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
10957270962aSWarner Losh                          representation for a device node can be used, where applicable.
10967270962aSWarner Losh 
10977270962aSWarner Losh **/
10987270962aSWarner Losh static VOID
DevPathToTextLogicalUnit(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)10997270962aSWarner Losh DevPathToTextLogicalUnit (
11007270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
11017270962aSWarner Losh   IN VOID            *DevPath,
11027270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
11037270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
11047270962aSWarner Losh   )
11057270962aSWarner Losh {
11067270962aSWarner Losh   DEVICE_LOGICAL_UNIT_DEVICE_PATH  *LogicalUnit;
11077270962aSWarner Losh 
11087270962aSWarner Losh   LogicalUnit = DevPath;
11097270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Unit(0x%x)", LogicalUnit->Lun);
11107270962aSWarner Losh }
11117270962aSWarner Losh 
11127270962aSWarner Losh /**
11137270962aSWarner Losh   Converts a USB class device path structure to its string representative.
11147270962aSWarner Losh 
11157270962aSWarner Losh   @param Str             The string representative of input device.
11167270962aSWarner Losh   @param DevPath         The input device path structure.
11177270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
11187270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
11197270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
11207270962aSWarner Losh                          is used.
11217270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
11227270962aSWarner Losh                          representation for a device node can be used, where applicable.
11237270962aSWarner Losh 
11247270962aSWarner Losh **/
11257270962aSWarner Losh static VOID
DevPathToTextUsbClass(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)11267270962aSWarner Losh DevPathToTextUsbClass (
11277270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
11287270962aSWarner Losh   IN VOID            *DevPath,
11297270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
11307270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
11317270962aSWarner Losh   )
11327270962aSWarner Losh {
11337270962aSWarner Losh   USB_CLASS_DEVICE_PATH  *UsbClass;
11347270962aSWarner Losh   BOOLEAN                IsKnownSubClass;
11357270962aSWarner Losh 
11367270962aSWarner Losh   UsbClass = DevPath;
11377270962aSWarner Losh 
11387270962aSWarner Losh   IsKnownSubClass = TRUE;
11397270962aSWarner Losh   switch (UsbClass->DeviceClass) {
11407270962aSWarner Losh     case USB_CLASS_AUDIO:
11417270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbAudio");
11427270962aSWarner Losh       break;
11437270962aSWarner Losh 
11447270962aSWarner Losh     case USB_CLASS_CDCCONTROL:
11457270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbCDCControl");
11467270962aSWarner Losh       break;
11477270962aSWarner Losh 
11487270962aSWarner Losh     case USB_CLASS_HID:
11497270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbHID");
11507270962aSWarner Losh       break;
11517270962aSWarner Losh 
11527270962aSWarner Losh     case USB_CLASS_IMAGE:
11537270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbImage");
11547270962aSWarner Losh       break;
11557270962aSWarner Losh 
11567270962aSWarner Losh     case USB_CLASS_PRINTER:
11577270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbPrinter");
11587270962aSWarner Losh       break;
11597270962aSWarner Losh 
11607270962aSWarner Losh     case USB_CLASS_MASS_STORAGE:
11617270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbMassStorage");
11627270962aSWarner Losh       break;
11637270962aSWarner Losh 
11647270962aSWarner Losh     case USB_CLASS_HUB:
11657270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbHub");
11667270962aSWarner Losh       break;
11677270962aSWarner Losh 
11687270962aSWarner Losh     case USB_CLASS_CDCDATA:
11697270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbCDCData");
11707270962aSWarner Losh       break;
11717270962aSWarner Losh 
11727270962aSWarner Losh     case USB_CLASS_SMART_CARD:
11737270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbSmartCard");
11747270962aSWarner Losh       break;
11757270962aSWarner Losh 
11767270962aSWarner Losh     case USB_CLASS_VIDEO:
11777270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbVideo");
11787270962aSWarner Losh       break;
11797270962aSWarner Losh 
11807270962aSWarner Losh     case USB_CLASS_DIAGNOSTIC:
11817270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbDiagnostic");
11827270962aSWarner Losh       break;
11837270962aSWarner Losh 
11847270962aSWarner Losh     case USB_CLASS_WIRELESS:
11857270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "UsbWireless");
11867270962aSWarner Losh       break;
11877270962aSWarner Losh 
11887270962aSWarner Losh     default:
11897270962aSWarner Losh       IsKnownSubClass = FALSE;
11907270962aSWarner Losh       break;
11917270962aSWarner Losh   }
11927270962aSWarner Losh 
11937270962aSWarner Losh   if (IsKnownSubClass) {
11947270962aSWarner Losh     UefiDevicePathLibCatPrint (
11957270962aSWarner Losh       Str,
11967270962aSWarner Losh       "(0x%x,0x%x,0x%x,0x%x)",
11977270962aSWarner Losh       UsbClass->VendorId,
11987270962aSWarner Losh       UsbClass->ProductId,
11997270962aSWarner Losh       UsbClass->DeviceSubClass,
12007270962aSWarner Losh       UsbClass->DeviceProtocol
12017270962aSWarner Losh       );
12027270962aSWarner Losh     return;
12037270962aSWarner Losh   }
12047270962aSWarner Losh 
12057270962aSWarner Losh   if (UsbClass->DeviceClass == USB_CLASS_RESERVE) {
12067270962aSWarner Losh     if (UsbClass->DeviceSubClass == USB_SUBCLASS_FW_UPDATE) {
12077270962aSWarner Losh       UefiDevicePathLibCatPrint (
12087270962aSWarner Losh         Str,
12097270962aSWarner Losh         "UsbDeviceFirmwareUpdate(0x%x,0x%x,0x%x)",
12107270962aSWarner Losh         UsbClass->VendorId,
12117270962aSWarner Losh         UsbClass->ProductId,
12127270962aSWarner Losh         UsbClass->DeviceProtocol
12137270962aSWarner Losh         );
12147270962aSWarner Losh       return;
12157270962aSWarner Losh     } else if (UsbClass->DeviceSubClass == USB_SUBCLASS_IRDA_BRIDGE) {
12167270962aSWarner Losh       UefiDevicePathLibCatPrint (
12177270962aSWarner Losh         Str,
12187270962aSWarner Losh         "UsbIrdaBridge(0x%x,0x%x,0x%x)",
12197270962aSWarner Losh         UsbClass->VendorId,
12207270962aSWarner Losh         UsbClass->ProductId,
12217270962aSWarner Losh         UsbClass->DeviceProtocol
12227270962aSWarner Losh         );
12237270962aSWarner Losh       return;
12247270962aSWarner Losh     } else if (UsbClass->DeviceSubClass == USB_SUBCLASS_TEST) {
12257270962aSWarner Losh       UefiDevicePathLibCatPrint (
12267270962aSWarner Losh         Str,
12277270962aSWarner Losh         "UsbTestAndMeasurement(0x%x,0x%x,0x%x)",
12287270962aSWarner Losh         UsbClass->VendorId,
12297270962aSWarner Losh         UsbClass->ProductId,
12307270962aSWarner Losh         UsbClass->DeviceProtocol
12317270962aSWarner Losh         );
12327270962aSWarner Losh       return;
12337270962aSWarner Losh     }
12347270962aSWarner Losh   }
12357270962aSWarner Losh 
12367270962aSWarner Losh   UefiDevicePathLibCatPrint (
12377270962aSWarner Losh     Str,
12387270962aSWarner Losh     "UsbClass(0x%x,0x%x,0x%x,0x%x,0x%x)",
12397270962aSWarner Losh     UsbClass->VendorId,
12407270962aSWarner Losh     UsbClass->ProductId,
12417270962aSWarner Losh     UsbClass->DeviceClass,
12427270962aSWarner Losh     UsbClass->DeviceSubClass,
12437270962aSWarner Losh     UsbClass->DeviceProtocol
12447270962aSWarner Losh     );
12457270962aSWarner Losh }
12467270962aSWarner Losh 
12477270962aSWarner Losh /**
12487270962aSWarner Losh   Converts a SATA device path structure to its string representative.
12497270962aSWarner Losh 
12507270962aSWarner Losh   @param Str             The string representative of input device.
12517270962aSWarner Losh   @param DevPath         The input device path structure.
12527270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
12537270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
12547270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
12557270962aSWarner Losh                          is used.
12567270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
12577270962aSWarner Losh                          representation for a device node can be used, where applicable.
12587270962aSWarner Losh 
12597270962aSWarner Losh **/
12607270962aSWarner Losh static VOID
DevPathToTextSata(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)12617270962aSWarner Losh DevPathToTextSata (
12627270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
12637270962aSWarner Losh   IN VOID            *DevPath,
12647270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
12657270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
12667270962aSWarner Losh   )
12677270962aSWarner Losh {
12687270962aSWarner Losh   SATA_DEVICE_PATH  *Sata;
12697270962aSWarner Losh 
12707270962aSWarner Losh   Sata = DevPath;
12717270962aSWarner Losh   UefiDevicePathLibCatPrint (
12727270962aSWarner Losh     Str,
12737270962aSWarner Losh     "Sata(0x%x,0x%x,0x%x)",
12747270962aSWarner Losh     Sata->HBAPortNumber,
12757270962aSWarner Losh     Sata->PortMultiplierPortNumber,
12767270962aSWarner Losh     Sata->Lun
12777270962aSWarner Losh     );
12787270962aSWarner Losh }
12797270962aSWarner Losh 
12807270962aSWarner Losh /**
12817270962aSWarner Losh   Converts a I20 device path structure to its string representative.
12827270962aSWarner Losh 
12837270962aSWarner Losh   @param Str             The string representative of input device.
12847270962aSWarner Losh   @param DevPath         The input device path structure.
12857270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
12867270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
12877270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
12887270962aSWarner Losh                          is used.
12897270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
12907270962aSWarner Losh                          representation for a device node can be used, where applicable.
12917270962aSWarner Losh 
12927270962aSWarner Losh **/
12937270962aSWarner Losh static VOID
DevPathToTextI2O(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)12947270962aSWarner Losh DevPathToTextI2O (
12957270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
12967270962aSWarner Losh   IN VOID            *DevPath,
12977270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
12987270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
12997270962aSWarner Losh   )
13007270962aSWarner Losh {
13017270962aSWarner Losh   I2O_DEVICE_PATH  *I2ODevPath;
13027270962aSWarner Losh 
13037270962aSWarner Losh   I2ODevPath = DevPath;
13047270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "I2O(0x%x)", I2ODevPath->Tid);
13057270962aSWarner Losh }
13067270962aSWarner Losh 
13077270962aSWarner Losh /**
13087270962aSWarner Losh   Converts a MAC address device path structure to its string representative.
13097270962aSWarner Losh 
13107270962aSWarner Losh   @param Str             The string representative of input device.
13117270962aSWarner Losh   @param DevPath         The input device path structure.
13127270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
13137270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
13147270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
13157270962aSWarner Losh                          is used.
13167270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
13177270962aSWarner Losh                          representation for a device node can be used, where applicable.
13187270962aSWarner Losh 
13197270962aSWarner Losh **/
13207270962aSWarner Losh static VOID
DevPathToTextMacAddr(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)13217270962aSWarner Losh DevPathToTextMacAddr (
13227270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
13237270962aSWarner Losh   IN VOID            *DevPath,
13247270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
13257270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
13267270962aSWarner Losh   )
13277270962aSWarner Losh {
13287270962aSWarner Losh   MAC_ADDR_DEVICE_PATH  *MacDevPath;
13297270962aSWarner Losh   UINTN                 HwAddressSize;
13307270962aSWarner Losh   UINTN                 Index;
13317270962aSWarner Losh 
13327270962aSWarner Losh   MacDevPath = DevPath;
13337270962aSWarner Losh 
13347270962aSWarner Losh   HwAddressSize = sizeof (EFI_MAC_ADDRESS);
13355754f582SJose Luis Duran   if ((MacDevPath->IfType == 0x01) || (MacDevPath->IfType == 0x00)) {
13367270962aSWarner Losh     HwAddressSize = 6;
13377270962aSWarner Losh   }
13387270962aSWarner Losh 
13397270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "MAC(");
13407270962aSWarner Losh 
13417270962aSWarner Losh   for (Index = 0; Index < HwAddressSize; Index++) {
13427270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%02x", MacDevPath->MacAddress.Addr[Index]);
13437270962aSWarner Losh   }
13447270962aSWarner Losh 
13457270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",0x%x)", MacDevPath->IfType);
13467270962aSWarner Losh }
13477270962aSWarner Losh 
13487270962aSWarner Losh /**
13497270962aSWarner Losh   Converts network protocol string to its text representation.
13507270962aSWarner Losh 
13517270962aSWarner Losh   @param Str             The string representative of input device.
13527270962aSWarner Losh   @param Protocol        The network protocol ID.
13537270962aSWarner Losh 
13547270962aSWarner Losh **/
13557270962aSWarner Losh static VOID
CatNetworkProtocol(IN OUT POOL_PRINT * Str,IN UINT16 Protocol)13567270962aSWarner Losh CatNetworkProtocol (
13577270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
13587270962aSWarner Losh   IN UINT16          Protocol
13597270962aSWarner Losh   )
13607270962aSWarner Losh {
13617270962aSWarner Losh   if (Protocol == RFC_1700_TCP_PROTOCOL) {
13627270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "TCP");
13637270962aSWarner Losh   } else if (Protocol == RFC_1700_UDP_PROTOCOL) {
13647270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "UDP");
13657270962aSWarner Losh   } else {
13667270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "0x%x", Protocol);
13677270962aSWarner Losh   }
13687270962aSWarner Losh }
13697270962aSWarner Losh 
13707270962aSWarner Losh /**
13717270962aSWarner Losh   Converts IP v4 address to its text representation.
13727270962aSWarner Losh 
13737270962aSWarner Losh   @param Str             The string representative of input device.
13747270962aSWarner Losh   @param Address         The IP v4 address.
13757270962aSWarner Losh **/
13767270962aSWarner Losh static VOID
CatIPv4Address(IN OUT POOL_PRINT * Str,IN EFI_IPv4_ADDRESS * Address)13777270962aSWarner Losh CatIPv4Address (
13787270962aSWarner Losh   IN OUT POOL_PRINT    *Str,
13797270962aSWarner Losh   IN EFI_IPv4_ADDRESS  *Address
13807270962aSWarner Losh   )
13817270962aSWarner Losh {
13827270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "%d.%d.%d.%d", Address->Addr[0], Address->Addr[1], Address->Addr[2], Address->Addr[3]);
13837270962aSWarner Losh }
13847270962aSWarner Losh 
13857270962aSWarner Losh /**
13867270962aSWarner Losh   Converts IP v6 address to its text representation.
13877270962aSWarner Losh 
13887270962aSWarner Losh   @param Str             The string representative of input device.
13897270962aSWarner Losh   @param Address         The IP v6 address.
13907270962aSWarner Losh **/
13917270962aSWarner Losh static VOID
CatIPv6Address(IN OUT POOL_PRINT * Str,IN EFI_IPv6_ADDRESS * Address)13927270962aSWarner Losh CatIPv6Address (
13937270962aSWarner Losh   IN OUT POOL_PRINT    *Str,
13947270962aSWarner Losh   IN EFI_IPv6_ADDRESS  *Address
13957270962aSWarner Losh   )
13967270962aSWarner Losh {
13977270962aSWarner Losh   UefiDevicePathLibCatPrint (
13985754f582SJose Luis Duran     Str,
13995754f582SJose Luis Duran     "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
14005754f582SJose Luis Duran     Address->Addr[0],
14015754f582SJose Luis Duran     Address->Addr[1],
14025754f582SJose Luis Duran     Address->Addr[2],
14035754f582SJose Luis Duran     Address->Addr[3],
14045754f582SJose Luis Duran     Address->Addr[4],
14055754f582SJose Luis Duran     Address->Addr[5],
14065754f582SJose Luis Duran     Address->Addr[6],
14075754f582SJose Luis Duran     Address->Addr[7],
14085754f582SJose Luis Duran     Address->Addr[8],
14095754f582SJose Luis Duran     Address->Addr[9],
14105754f582SJose Luis Duran     Address->Addr[10],
14115754f582SJose Luis Duran     Address->Addr[11],
14125754f582SJose Luis Duran     Address->Addr[12],
14135754f582SJose Luis Duran     Address->Addr[13],
14145754f582SJose Luis Duran     Address->Addr[14],
14155754f582SJose Luis Duran     Address->Addr[15]
14167270962aSWarner Losh     );
14177270962aSWarner Losh }
14187270962aSWarner Losh 
14197270962aSWarner Losh /**
14207270962aSWarner Losh   Converts a IPv4 device path structure to its string representative.
14217270962aSWarner Losh 
14227270962aSWarner Losh   @param Str             The string representative of input device.
14237270962aSWarner Losh   @param DevPath         The input device path structure.
14247270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
14257270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
14267270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
14277270962aSWarner Losh                          is used.
14287270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
14297270962aSWarner Losh                          representation for a device node can be used, where applicable.
14307270962aSWarner Losh 
14317270962aSWarner Losh **/
14327270962aSWarner Losh static VOID
DevPathToTextIPv4(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)14337270962aSWarner Losh DevPathToTextIPv4 (
14347270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
14357270962aSWarner Losh   IN VOID            *DevPath,
14367270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
14377270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
14387270962aSWarner Losh   )
14397270962aSWarner Losh {
14407270962aSWarner Losh   IPv4_DEVICE_PATH  *IPDevPath;
14417270962aSWarner Losh 
14427270962aSWarner Losh   IPDevPath = DevPath;
14437270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "IPv4(");
14447270962aSWarner Losh   CatIPv4Address (Str, &IPDevPath->RemoteIpAddress);
14457270962aSWarner Losh 
14467270962aSWarner Losh   if (DisplayOnly) {
14477270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ")");
14487270962aSWarner Losh     return;
14497270962aSWarner Losh   }
14507270962aSWarner Losh 
14517270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",");
14527270962aSWarner Losh   CatNetworkProtocol (Str, IPDevPath->Protocol);
14537270962aSWarner Losh 
14547270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",%s,", IPDevPath->StaticIpAddress ? "Static" : "DHCP");
14557270962aSWarner Losh   CatIPv4Address (Str, &IPDevPath->LocalIpAddress);
14567270962aSWarner Losh   if (DevicePathNodeLength (IPDevPath) == sizeof (IPv4_DEVICE_PATH)) {
14577270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ",");
14587270962aSWarner Losh     CatIPv4Address (Str, &IPDevPath->GatewayIpAddress);
14597270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ",");
14607270962aSWarner Losh     CatIPv4Address (Str, &IPDevPath->SubnetMask);
14617270962aSWarner Losh   }
14625754f582SJose Luis Duran 
14637270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ")");
14647270962aSWarner Losh }
14657270962aSWarner Losh 
14667270962aSWarner Losh /**
14677270962aSWarner Losh   Converts a IPv6 device path structure to its string representative.
14687270962aSWarner Losh 
14697270962aSWarner Losh   @param Str             The string representative of input device.
14707270962aSWarner Losh   @param DevPath         The input device path structure.
14717270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
14727270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
14737270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
14747270962aSWarner Losh                          is used.
14757270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
14767270962aSWarner Losh                          representation for a device node can be used, where applicable.
14777270962aSWarner Losh 
14787270962aSWarner Losh **/
14797270962aSWarner Losh static VOID
DevPathToTextIPv6(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)14807270962aSWarner Losh DevPathToTextIPv6 (
14817270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
14827270962aSWarner Losh   IN VOID            *DevPath,
14837270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
14847270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
14857270962aSWarner Losh   )
14867270962aSWarner Losh {
14877270962aSWarner Losh   IPv6_DEVICE_PATH  *IPDevPath;
14887270962aSWarner Losh 
14897270962aSWarner Losh   IPDevPath = DevPath;
14907270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "IPv6(");
14917270962aSWarner Losh   CatIPv6Address (Str, &IPDevPath->RemoteIpAddress);
14927270962aSWarner Losh   if (DisplayOnly) {
14937270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ")");
14947270962aSWarner Losh     return;
14957270962aSWarner Losh   }
14967270962aSWarner Losh 
14977270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",");
14987270962aSWarner Losh   CatNetworkProtocol (Str, IPDevPath->Protocol);
14997270962aSWarner Losh 
15007270962aSWarner Losh   switch (IPDevPath->IpAddressOrigin) {
15017270962aSWarner Losh     case 0:
15027270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, ",Static,");
15037270962aSWarner Losh       break;
15047270962aSWarner Losh     case 1:
15057270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, ",StatelessAutoConfigure,");
15067270962aSWarner Losh       break;
15077270962aSWarner Losh     default:
15087270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, ",StatefulAutoConfigure,");
15097270962aSWarner Losh       break;
15107270962aSWarner Losh   }
15117270962aSWarner Losh 
15127270962aSWarner Losh   CatIPv6Address (Str, &IPDevPath->LocalIpAddress);
15137270962aSWarner Losh 
15147270962aSWarner Losh   if (DevicePathNodeLength (IPDevPath) == sizeof (IPv6_DEVICE_PATH)) {
15157270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ",0x%x,", IPDevPath->PrefixLength);
15167270962aSWarner Losh     CatIPv6Address (Str, &IPDevPath->GatewayIpAddress);
15177270962aSWarner Losh   }
15185754f582SJose Luis Duran 
15197270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ")");
15207270962aSWarner Losh }
15217270962aSWarner Losh 
15227270962aSWarner Losh /**
15237270962aSWarner Losh   Converts an Infini Band device path structure to its string representative.
15247270962aSWarner Losh 
15257270962aSWarner Losh   @param Str             The string representative of input device.
15267270962aSWarner Losh   @param DevPath         The input device path structure.
15277270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
15287270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
15297270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
15307270962aSWarner Losh                          is used.
15317270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
15327270962aSWarner Losh                          representation for a device node can be used, where applicable.
15337270962aSWarner Losh 
15347270962aSWarner Losh **/
15357270962aSWarner Losh static VOID
DevPathToTextInfiniBand(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)15367270962aSWarner Losh DevPathToTextInfiniBand (
15377270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
15387270962aSWarner Losh   IN VOID            *DevPath,
15397270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
15407270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
15417270962aSWarner Losh   )
15427270962aSWarner Losh {
15437270962aSWarner Losh   INFINIBAND_DEVICE_PATH  *InfiniBand;
15447270962aSWarner Losh 
15457270962aSWarner Losh   InfiniBand = DevPath;
15467270962aSWarner Losh   UefiDevicePathLibCatPrint (
15477270962aSWarner Losh     Str,
15487270962aSWarner Losh     "Infiniband(0x%x,%36s,0x%lx,0x%lx,0x%lx)",
15497270962aSWarner Losh     InfiniBand->ResourceFlags,
15507270962aSWarner Losh     G(InfiniBand->PortGid),
15517270962aSWarner Losh     InfiniBand->ServiceId,
15527270962aSWarner Losh     InfiniBand->TargetPortId,
15537270962aSWarner Losh     InfiniBand->DeviceId
15547270962aSWarner Losh     );
15557270962aSWarner Losh }
15567270962aSWarner Losh 
15577270962aSWarner Losh /**
15587270962aSWarner Losh   Converts a UART device path structure to its string representative.
15597270962aSWarner Losh 
15607270962aSWarner Losh   @param Str             The string representative of input device.
15617270962aSWarner Losh   @param DevPath         The input device path structure.
15627270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
15637270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
15647270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
15657270962aSWarner Losh                          is used.
15667270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
15677270962aSWarner Losh                          representation for a device node can be used, where applicable.
15687270962aSWarner Losh 
15697270962aSWarner Losh **/
15707270962aSWarner Losh static VOID
DevPathToTextUart(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)15717270962aSWarner Losh DevPathToTextUart (
15727270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
15737270962aSWarner Losh   IN VOID            *DevPath,
15747270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
15757270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
15767270962aSWarner Losh   )
15777270962aSWarner Losh {
15787270962aSWarner Losh   UART_DEVICE_PATH  *Uart;
15797270962aSWarner Losh   CHAR8             Parity;
15807270962aSWarner Losh 
15817270962aSWarner Losh   Uart = DevPath;
15827270962aSWarner Losh   switch (Uart->Parity) {
15837270962aSWarner Losh     case 0:
15847270962aSWarner Losh       Parity = 'D';
15857270962aSWarner Losh       break;
15867270962aSWarner Losh 
15877270962aSWarner Losh     case 1:
15887270962aSWarner Losh       Parity = 'N';
15897270962aSWarner Losh       break;
15907270962aSWarner Losh 
15917270962aSWarner Losh     case 2:
15927270962aSWarner Losh       Parity = 'E';
15937270962aSWarner Losh       break;
15947270962aSWarner Losh 
15957270962aSWarner Losh     case 3:
15967270962aSWarner Losh       Parity = 'O';
15977270962aSWarner Losh       break;
15987270962aSWarner Losh 
15997270962aSWarner Losh     case 4:
16007270962aSWarner Losh       Parity = 'M';
16017270962aSWarner Losh       break;
16027270962aSWarner Losh 
16037270962aSWarner Losh     case 5:
16047270962aSWarner Losh       Parity = 'S';
16057270962aSWarner Losh       break;
16067270962aSWarner Losh 
16077270962aSWarner Losh     default:
16087270962aSWarner Losh       Parity = 'x';
16097270962aSWarner Losh       break;
16107270962aSWarner Losh   }
16117270962aSWarner Losh 
16127270962aSWarner Losh   if (Uart->BaudRate == 0) {
16137270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "Uart(DEFAULT,");
16147270962aSWarner Losh   } else {
16157270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "Uart(%ld,", Uart->BaudRate);
16167270962aSWarner Losh   }
16177270962aSWarner Losh 
16187270962aSWarner Losh   if (Uart->DataBits == 0) {
16197270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "DEFAULT,");
16207270962aSWarner Losh   } else {
16217270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%d,", Uart->DataBits);
16227270962aSWarner Losh   }
16237270962aSWarner Losh 
16247270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "%c,", Parity);
16257270962aSWarner Losh 
16267270962aSWarner Losh   switch (Uart->StopBits) {
16277270962aSWarner Losh     case 0:
16287270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "D)");
16297270962aSWarner Losh       break;
16307270962aSWarner Losh 
16317270962aSWarner Losh     case 1:
16327270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "1)");
16337270962aSWarner Losh       break;
16347270962aSWarner Losh 
16357270962aSWarner Losh     case 2:
16367270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "1.5)");
16377270962aSWarner Losh       break;
16387270962aSWarner Losh 
16397270962aSWarner Losh     case 3:
16407270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "2)");
16417270962aSWarner Losh       break;
16427270962aSWarner Losh 
16437270962aSWarner Losh     default:
16447270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "x)");
16457270962aSWarner Losh       break;
16467270962aSWarner Losh   }
16477270962aSWarner Losh }
16487270962aSWarner Losh 
16497270962aSWarner Losh /**
16507270962aSWarner Losh   Converts an iSCSI device path structure to its string representative.
16517270962aSWarner Losh 
16527270962aSWarner Losh   @param Str             The string representative of input device.
16537270962aSWarner Losh   @param DevPath         The input device path structure.
16547270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
16557270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
16567270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
16577270962aSWarner Losh                          is used.
16587270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
16597270962aSWarner Losh                          representation for a device node can be used, where applicable.
16607270962aSWarner Losh 
16617270962aSWarner Losh **/
16627270962aSWarner Losh static VOID
DevPathToTextiSCSI(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)16637270962aSWarner Losh DevPathToTextiSCSI (
16647270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
16657270962aSWarner Losh   IN VOID            *DevPath,
16667270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
16677270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
16687270962aSWarner Losh   )
16697270962aSWarner Losh {
16707270962aSWarner Losh   ISCSI_DEVICE_PATH_WITH_NAME  *ISCSIDevPath;
16717270962aSWarner Losh   UINT16                       Options;
167250668299SJose Luis Duran   UINTN                        Index;
16737270962aSWarner Losh 
16747270962aSWarner Losh   ISCSIDevPath = DevPath;
16757270962aSWarner Losh   UefiDevicePathLibCatPrint (
16767270962aSWarner Losh     Str,
167750668299SJose Luis Duran     "iSCSI(%s,0x%x,0x",
16787270962aSWarner Losh     ISCSIDevPath->TargetName,
167950668299SJose Luis Duran     ISCSIDevPath->TargetPortalGroupTag
16807270962aSWarner Losh     );
168150668299SJose Luis Duran   for (Index = 0; Index < sizeof (ISCSIDevPath->Lun) / sizeof (UINT8); Index++) {
168250668299SJose Luis Duran     UefiDevicePathLibCatPrint (Str, "%02x", ((UINT8 *)&ISCSIDevPath->Lun)[Index]);
168350668299SJose Luis Duran   }
16845754f582SJose Luis Duran 
16857270962aSWarner Losh   Options = ISCSIDevPath->LoginOption;
168650668299SJose Luis Duran   UefiDevicePathLibCatPrint (Str, ",%s,", (((Options >> 1) & 0x0001) != 0) ? "CRC32C" : "None");
16877270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "%s,", (((Options >> 3) & 0x0001) != 0) ? "CRC32C" : "None");
16887270962aSWarner Losh   if (((Options >> 11) & 0x0001) != 0) {
16897270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%s,", "None");
16907270962aSWarner Losh   } else if (((Options >> 12) & 0x0001) != 0) {
16917270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%s,", "CHAP_UNI");
16927270962aSWarner Losh   } else {
16937270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%s,", "CHAP_BI");
16947270962aSWarner Losh   }
16957270962aSWarner Losh 
16967270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "%s)", (ISCSIDevPath->NetworkProtocol == 0) ? "TCP" : "reserved");
16977270962aSWarner Losh }
16987270962aSWarner Losh 
16997270962aSWarner Losh /**
17007270962aSWarner Losh   Converts a VLAN device path structure to its string representative.
17017270962aSWarner Losh 
17027270962aSWarner Losh   @param Str             The string representative of input device.
17037270962aSWarner Losh   @param DevPath         The input device path structure.
17047270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
17057270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
17067270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
17077270962aSWarner Losh                          is used.
17087270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
17097270962aSWarner Losh                          representation for a device node can be used, where applicable.
17107270962aSWarner Losh 
17117270962aSWarner Losh **/
17127270962aSWarner Losh static VOID
DevPathToTextVlan(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)17137270962aSWarner Losh DevPathToTextVlan (
17147270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
17157270962aSWarner Losh   IN VOID            *DevPath,
17167270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
17177270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
17187270962aSWarner Losh   )
17197270962aSWarner Losh {
17207270962aSWarner Losh   VLAN_DEVICE_PATH  *Vlan;
17217270962aSWarner Losh 
17227270962aSWarner Losh   Vlan = DevPath;
17237270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Vlan(%d)", Vlan->VlanId);
17247270962aSWarner Losh }
17257270962aSWarner Losh 
17267270962aSWarner Losh /**
17277270962aSWarner Losh   Converts a Bluetooth device path structure to its string representative.
17287270962aSWarner Losh 
17297270962aSWarner Losh   @param Str             The string representative of input device.
17307270962aSWarner Losh   @param DevPath         The input device path structure.
17317270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
17327270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
17337270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
17347270962aSWarner Losh                          is used.
17357270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
17367270962aSWarner Losh                          representation for a device node can be used, where applicable.
17377270962aSWarner Losh 
17387270962aSWarner Losh **/
17397270962aSWarner Losh static VOID
DevPathToTextBluetooth(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)17407270962aSWarner Losh DevPathToTextBluetooth (
17417270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
17427270962aSWarner Losh   IN VOID            *DevPath,
17437270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
17447270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
17457270962aSWarner Losh   )
17467270962aSWarner Losh {
17477270962aSWarner Losh   BLUETOOTH_DEVICE_PATH  *Bluetooth;
17487270962aSWarner Losh 
17497270962aSWarner Losh   Bluetooth = DevPath;
17507270962aSWarner Losh   UefiDevicePathLibCatPrint (
17517270962aSWarner Losh     Str,
17527270962aSWarner Losh     "Bluetooth(%02x%02x%02x%02x%02x%02x)",
175300816383SJose Luis Duran     Bluetooth->BD_ADDR.Address[0],
17547270962aSWarner Losh     Bluetooth->BD_ADDR.Address[1],
175500816383SJose Luis Duran     Bluetooth->BD_ADDR.Address[2],
175600816383SJose Luis Duran     Bluetooth->BD_ADDR.Address[3],
175700816383SJose Luis Duran     Bluetooth->BD_ADDR.Address[4],
175800816383SJose Luis Duran     Bluetooth->BD_ADDR.Address[5]
17597270962aSWarner Losh     );
17607270962aSWarner Losh }
17617270962aSWarner Losh 
17627270962aSWarner Losh /**
17637270962aSWarner Losh   Converts a Wi-Fi device path structure to its string representative.
17647270962aSWarner Losh 
17657270962aSWarner Losh   @param Str             The string representative of input device.
17667270962aSWarner Losh   @param DevPath         The input device path structure.
17677270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
17687270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
17697270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
17707270962aSWarner Losh                          is used.
17717270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
17727270962aSWarner Losh                          representation for a device node can be used, where applicable.
17737270962aSWarner Losh 
17747270962aSWarner Losh **/
17757270962aSWarner Losh static VOID
DevPathToTextWiFi(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)17767270962aSWarner Losh DevPathToTextWiFi (
17777270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
17787270962aSWarner Losh   IN VOID            *DevPath,
17797270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
17807270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
17817270962aSWarner Losh   )
17827270962aSWarner Losh {
17837270962aSWarner Losh   WIFI_DEVICE_PATH  *WiFi;
17847270962aSWarner Losh   UINT8             SSId[33];
17857270962aSWarner Losh 
17867270962aSWarner Losh   WiFi = DevPath;
17877270962aSWarner Losh 
17887270962aSWarner Losh   SSId[32] = '\0';
17897270962aSWarner Losh   CopyMem (SSId, WiFi->SSId, 32);
17907270962aSWarner Losh 
17917270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Wi-Fi(%s)", SSId);
17927270962aSWarner Losh }
17937270962aSWarner Losh 
17947270962aSWarner Losh /**
1795e8fc7f11SJose Luis Duran   Converts a Bluetooth device path structure to its string representative.
1796e8fc7f11SJose Luis Duran 
1797e8fc7f11SJose Luis Duran   @param Str             The string representative of input device.
1798e8fc7f11SJose Luis Duran   @param DevPath         The input device path structure.
1799e8fc7f11SJose Luis Duran   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
1800e8fc7f11SJose Luis Duran                          of the display node is used, where applicable. If DisplayOnly
1801e8fc7f11SJose Luis Duran                          is FALSE, then the longer text representation of the display node
1802e8fc7f11SJose Luis Duran                          is used.
1803e8fc7f11SJose Luis Duran   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
1804e8fc7f11SJose Luis Duran                          representation for a device node can be used, where applicable.
1805e8fc7f11SJose Luis Duran 
1806e8fc7f11SJose Luis Duran **/
1807e8fc7f11SJose Luis Duran static VOID
DevPathToTextBluetoothLE(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)1808e8fc7f11SJose Luis Duran DevPathToTextBluetoothLE (
1809e8fc7f11SJose Luis Duran   IN OUT POOL_PRINT  *Str,
1810e8fc7f11SJose Luis Duran   IN VOID            *DevPath,
1811e8fc7f11SJose Luis Duran   IN BOOLEAN         DisplayOnly,
1812e8fc7f11SJose Luis Duran   IN BOOLEAN         AllowShortcuts
1813e8fc7f11SJose Luis Duran   )
1814e8fc7f11SJose Luis Duran {
1815e8fc7f11SJose Luis Duran   BLUETOOTH_LE_DEVICE_PATH  *BluetoothLE;
1816e8fc7f11SJose Luis Duran 
1817e8fc7f11SJose Luis Duran   BluetoothLE = DevPath;
1818e8fc7f11SJose Luis Duran   UefiDevicePathLibCatPrint (
1819e8fc7f11SJose Luis Duran     Str,
1820e8fc7f11SJose Luis Duran     "BluetoothLE(%02x%02x%02x%02x%02x%02x,0x%02x)",
1821e8fc7f11SJose Luis Duran     BluetoothLE->Address.Address[0],
1822e8fc7f11SJose Luis Duran     BluetoothLE->Address.Address[1],
1823e8fc7f11SJose Luis Duran     BluetoothLE->Address.Address[2],
1824e8fc7f11SJose Luis Duran     BluetoothLE->Address.Address[3],
1825e8fc7f11SJose Luis Duran     BluetoothLE->Address.Address[4],
1826e8fc7f11SJose Luis Duran     BluetoothLE->Address.Address[5],
1827e8fc7f11SJose Luis Duran     BluetoothLE->Address.Type
1828e8fc7f11SJose Luis Duran     );
1829e8fc7f11SJose Luis Duran }
1830e8fc7f11SJose Luis Duran 
1831e8fc7f11SJose Luis Duran /**
1832d9d1a1e7SJose Luis Duran   Converts a DNS device path structure to its string representative.
1833d9d1a1e7SJose Luis Duran 
1834d9d1a1e7SJose Luis Duran   @param Str             The string representative of input device.
1835d9d1a1e7SJose Luis Duran   @param DevPath         The input device path structure.
1836d9d1a1e7SJose Luis Duran   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
1837d9d1a1e7SJose Luis Duran                          of the display node is used, where applicable. If DisplayOnly
1838d9d1a1e7SJose Luis Duran                          is FALSE, then the longer text representation of the display node
1839d9d1a1e7SJose Luis Duran                          is used.
1840d9d1a1e7SJose Luis Duran   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
1841d9d1a1e7SJose Luis Duran                          representation for a device node can be used, where applicable.
1842d9d1a1e7SJose Luis Duran 
1843d9d1a1e7SJose Luis Duran **/
1844d9d1a1e7SJose Luis Duran static VOID
DevPathToTextDns(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)1845d9d1a1e7SJose Luis Duran DevPathToTextDns (
1846d9d1a1e7SJose Luis Duran   IN OUT POOL_PRINT  *Str,
1847d9d1a1e7SJose Luis Duran   IN VOID            *DevPath,
1848d9d1a1e7SJose Luis Duran   IN BOOLEAN         DisplayOnly,
1849d9d1a1e7SJose Luis Duran   IN BOOLEAN         AllowShortcuts
1850d9d1a1e7SJose Luis Duran   )
1851d9d1a1e7SJose Luis Duran {
1852d9d1a1e7SJose Luis Duran   DNS_DEVICE_PATH  *DnsDevPath;
1853d9d1a1e7SJose Luis Duran   UINT32           DnsServerIpCount;
1854d9d1a1e7SJose Luis Duran   UINT32           DnsServerIpIndex;
1855d9d1a1e7SJose Luis Duran 
1856d9d1a1e7SJose Luis Duran   DnsDevPath       = DevPath;
1857d9d1a1e7SJose Luis Duran   DnsServerIpCount = (UINT32)(DevicePathNodeLength (DnsDevPath) - sizeof (EFI_DEVICE_PATH_PROTOCOL) - sizeof (DnsDevPath->IsIPv6)) / sizeof (EFI_IP_ADDRESS);
1858d9d1a1e7SJose Luis Duran 
1859d9d1a1e7SJose Luis Duran   UefiDevicePathLibCatPrint (Str, "Dns(");
1860d9d1a1e7SJose Luis Duran 
1861d9d1a1e7SJose Luis Duran   for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {
1862d9d1a1e7SJose Luis Duran     if (DnsDevPath->IsIPv6 == 0x00) {
1863d9d1a1e7SJose Luis Duran       CatIPv4Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v4));
1864d9d1a1e7SJose Luis Duran     } else {
1865d9d1a1e7SJose Luis Duran       CatIPv6Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v6));
1866d9d1a1e7SJose Luis Duran     }
1867d9d1a1e7SJose Luis Duran 
1868d9d1a1e7SJose Luis Duran     if (DnsServerIpIndex < DnsServerIpCount - 1) {
1869d9d1a1e7SJose Luis Duran       UefiDevicePathLibCatPrint (Str, ",");
1870d9d1a1e7SJose Luis Duran     }
1871d9d1a1e7SJose Luis Duran   }
1872d9d1a1e7SJose Luis Duran 
1873d9d1a1e7SJose Luis Duran   UefiDevicePathLibCatPrint (Str, ")");
1874d9d1a1e7SJose Luis Duran }
1875d9d1a1e7SJose Luis Duran 
1876d9d1a1e7SJose Luis Duran /**
18777270962aSWarner Losh   Converts a URI device path structure to its string representative.
18787270962aSWarner Losh 
18797270962aSWarner Losh   @param Str             The string representative of input device.
18807270962aSWarner Losh   @param DevPath         The input device path structure.
18817270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
18827270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
18837270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
18847270962aSWarner Losh                          is used.
18857270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
18867270962aSWarner Losh                          representation for a device node can be used, where applicable.
18877270962aSWarner Losh 
18887270962aSWarner Losh **/
18897270962aSWarner Losh static VOID
DevPathToTextUri(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)18907270962aSWarner Losh DevPathToTextUri (
18917270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
18927270962aSWarner Losh   IN VOID            *DevPath,
18937270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
18947270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
18957270962aSWarner Losh   )
18967270962aSWarner Losh {
18977270962aSWarner Losh   URI_DEVICE_PATH  *Uri;
18987270962aSWarner Losh   UINTN            UriLength;
18997270962aSWarner Losh   CHAR8            *UriStr;
19007270962aSWarner Losh 
19017270962aSWarner Losh   //
19027270962aSWarner Losh   // Uri in the device path may not be null terminated.
19037270962aSWarner Losh   //
19047270962aSWarner Losh   Uri       = DevPath;
19057270962aSWarner Losh   UriLength = DevicePathNodeLength (Uri) - sizeof (URI_DEVICE_PATH);
19067270962aSWarner Losh   UriStr    = AllocatePool (UriLength + 1);
19077270962aSWarner Losh   ASSERT (UriStr != NULL);
19087270962aSWarner Losh 
19097270962aSWarner Losh   CopyMem (UriStr, Uri->Uri, UriLength);
19107270962aSWarner Losh   UriStr[UriLength] = '\0';
19117270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Uri(%s)", UriStr);
19127270962aSWarner Losh   FreePool (UriStr);
19137270962aSWarner Losh }
19147270962aSWarner Losh 
19157270962aSWarner Losh /**
19167270962aSWarner Losh   Converts a Hard drive device path structure to its string representative.
19177270962aSWarner Losh 
19187270962aSWarner Losh   @param Str             The string representative of input device.
19197270962aSWarner Losh   @param DevPath         The input device path structure.
19207270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
19217270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
19227270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
19237270962aSWarner Losh                          is used.
19247270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
19257270962aSWarner Losh                          representation for a device node can be used, where applicable.
19267270962aSWarner Losh 
19277270962aSWarner Losh **/
19287270962aSWarner Losh static VOID
DevPathToTextHardDrive(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)19297270962aSWarner Losh DevPathToTextHardDrive (
19307270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
19317270962aSWarner Losh   IN VOID            *DevPath,
19327270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
19337270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
19347270962aSWarner Losh   )
19357270962aSWarner Losh {
19367270962aSWarner Losh   HARDDRIVE_DEVICE_PATH  *Hd;
19377270962aSWarner Losh 
19387270962aSWarner Losh   Hd = DevPath;
19397270962aSWarner Losh   switch (Hd->SignatureType) {
19407270962aSWarner Losh     case SIGNATURE_TYPE_MBR:
19417270962aSWarner Losh       UefiDevicePathLibCatPrint (
19427270962aSWarner Losh         Str,
19437270962aSWarner Losh         "HD(%d,%s,0x%08x,",
19447270962aSWarner Losh         Hd->PartitionNumber,
19457270962aSWarner Losh         "MBR",
19467270962aSWarner Losh //      *((UINT32 *)(&(Hd->Signature[0])))
19477270962aSWarner Losh         le32dec(&(Hd->Signature[0]))
19487270962aSWarner Losh         );
19497270962aSWarner Losh       break;
19507270962aSWarner Losh 
19517270962aSWarner Losh     case SIGNATURE_TYPE_GUID:
19527270962aSWarner Losh       UefiDevicePathLibCatPrint (
19537270962aSWarner Losh         Str,
19547270962aSWarner Losh         "HD(%d,%s,%36s,",
19557270962aSWarner Losh         Hd->PartitionNumber,
19567270962aSWarner Losh         "GPT",
19577270962aSWarner Losh         G(&(Hd->Signature[0]))
19587270962aSWarner Losh         );
19597270962aSWarner Losh       break;
19607270962aSWarner Losh 
19617270962aSWarner Losh     default:
19627270962aSWarner Losh       UefiDevicePathLibCatPrint (
19637270962aSWarner Losh         Str,
19647270962aSWarner Losh         "HD(%d,%d,0,",
19657270962aSWarner Losh         Hd->PartitionNumber,
19667270962aSWarner Losh         Hd->SignatureType
19677270962aSWarner Losh         );
19687270962aSWarner Losh       break;
19697270962aSWarner Losh   }
19707270962aSWarner Losh 
19717270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);
19727270962aSWarner Losh }
19737270962aSWarner Losh 
19747270962aSWarner Losh /**
19757270962aSWarner Losh   Converts a CDROM device path structure to its string representative.
19767270962aSWarner Losh 
19777270962aSWarner Losh   @param Str             The string representative of input device.
19787270962aSWarner Losh   @param DevPath         The input device path structure.
19797270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
19807270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
19817270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
19827270962aSWarner Losh                          is used.
19837270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
19847270962aSWarner Losh                          representation for a device node can be used, where applicable.
19857270962aSWarner Losh 
19867270962aSWarner Losh **/
19877270962aSWarner Losh static VOID
DevPathToTextCDROM(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)19887270962aSWarner Losh DevPathToTextCDROM (
19897270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
19907270962aSWarner Losh   IN VOID            *DevPath,
19917270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
19927270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
19937270962aSWarner Losh   )
19947270962aSWarner Losh {
19957270962aSWarner Losh   CDROM_DEVICE_PATH  *Cd;
19967270962aSWarner Losh 
19977270962aSWarner Losh   Cd = DevPath;
19987270962aSWarner Losh   if (DisplayOnly) {
19997270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "CDROM(0x%x)", Cd->BootEntry);
20007270962aSWarner Losh     return;
20017270962aSWarner Losh   }
20027270962aSWarner Losh 
20037270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "CDROM(0x%x,0x%lx,0x%lx)", Cd->BootEntry, Cd->PartitionStart, Cd->PartitionSize);
20047270962aSWarner Losh }
20057270962aSWarner Losh 
20067270962aSWarner Losh /**
20077270962aSWarner Losh   Converts a File device path structure to its string representative.
20087270962aSWarner Losh 
20097270962aSWarner Losh   @param Str             The string representative of input device.
20107270962aSWarner Losh   @param DevPath         The input device path structure.
20117270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
20127270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
20137270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
20147270962aSWarner Losh                          is used.
20157270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
20167270962aSWarner Losh                          representation for a device node can be used, where applicable.
20177270962aSWarner Losh 
20187270962aSWarner Losh **/
20197270962aSWarner Losh static VOID
DevPathToTextFilePath(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)20207270962aSWarner Losh DevPathToTextFilePath (
20217270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
20227270962aSWarner Losh   IN VOID            *DevPath,
20237270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
20247270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
20257270962aSWarner Losh   )
20267270962aSWarner Losh {
20277270962aSWarner Losh   FILEPATH_DEVICE_PATH  *Fp;
20280d802f5aSWarner Losh   char *name = NULL;
20297270962aSWarner Losh 
20307270962aSWarner Losh   Fp = DevPath;
20310d802f5aSWarner Losh   ucs2_to_utf8(Fp->PathName, &name);
20320d802f5aSWarner Losh   UefiDevicePathLibCatPrint (Str, "File(%s)", name);
20330d802f5aSWarner Losh   free(name);
20347270962aSWarner Losh }
20357270962aSWarner Losh 
20367270962aSWarner Losh /**
20377270962aSWarner Losh   Converts a Media protocol device path structure to its string representative.
20387270962aSWarner Losh 
20397270962aSWarner Losh   @param Str             The string representative of input device.
20407270962aSWarner Losh   @param DevPath         The input device path structure.
20417270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
20427270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
20437270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
20447270962aSWarner Losh                          is used.
20457270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
20467270962aSWarner Losh                          representation for a device node can be used, where applicable.
20477270962aSWarner Losh 
20487270962aSWarner Losh **/
20497270962aSWarner Losh static VOID
DevPathToTextMediaProtocol(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)20507270962aSWarner Losh DevPathToTextMediaProtocol (
20517270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
20527270962aSWarner Losh   IN VOID            *DevPath,
20537270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
20547270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
20557270962aSWarner Losh   )
20567270962aSWarner Losh {
20577270962aSWarner Losh   MEDIA_PROTOCOL_DEVICE_PATH  *MediaProt;
20587270962aSWarner Losh 
20597270962aSWarner Losh   MediaProt = DevPath;
20607270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Media(%36s)", G(&MediaProt->Protocol));
20617270962aSWarner Losh }
20627270962aSWarner Losh 
20637270962aSWarner Losh /**
20647270962aSWarner Losh   Converts a Firmware Volume device path structure to its string representative.
20657270962aSWarner Losh 
20667270962aSWarner Losh   @param Str             The string representative of input device.
20677270962aSWarner Losh   @param DevPath         The input device path structure.
20687270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
20697270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
20707270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
20717270962aSWarner Losh                          is used.
20727270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
20737270962aSWarner Losh                          representation for a device node can be used, where applicable.
20747270962aSWarner Losh 
20757270962aSWarner Losh **/
20767270962aSWarner Losh static VOID
DevPathToTextFv(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)20777270962aSWarner Losh DevPathToTextFv (
20787270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
20797270962aSWarner Losh   IN VOID            *DevPath,
20807270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
20817270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
20827270962aSWarner Losh   )
20837270962aSWarner Losh {
20847270962aSWarner Losh   MEDIA_FW_VOL_DEVICE_PATH  *Fv;
20857270962aSWarner Losh 
20867270962aSWarner Losh   Fv = DevPath;
20877270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "Fv(%36s)", G(&Fv->FvName));
20887270962aSWarner Losh }
20897270962aSWarner Losh 
20907270962aSWarner Losh /**
20917270962aSWarner Losh   Converts a Firmware Volume File device path structure to its string representative.
20927270962aSWarner Losh 
20937270962aSWarner Losh   @param Str             The string representative of input device.
20947270962aSWarner Losh   @param DevPath         The input device path structure.
20957270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
20967270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
20977270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
20987270962aSWarner Losh                          is used.
20997270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
21007270962aSWarner Losh                          representation for a device node can be used, where applicable.
21017270962aSWarner Losh 
21027270962aSWarner Losh **/
21037270962aSWarner Losh static VOID
DevPathToTextFvFile(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)21047270962aSWarner Losh DevPathToTextFvFile (
21057270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
21067270962aSWarner Losh   IN VOID            *DevPath,
21077270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
21087270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
21097270962aSWarner Losh   )
21107270962aSWarner Losh {
21117270962aSWarner Losh   MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  *FvFile;
21127270962aSWarner Losh 
21137270962aSWarner Losh   FvFile = DevPath;
21147270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, "FvFile(%36s)", G(&FvFile->FvFileName));
21157270962aSWarner Losh }
21167270962aSWarner Losh 
21177270962aSWarner Losh /**
21187270962aSWarner Losh   Converts a Relative Offset device path structure to its string representative.
21197270962aSWarner Losh 
21207270962aSWarner Losh   @param Str             The string representative of input device.
21217270962aSWarner Losh   @param DevPath         The input device path structure.
21227270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
21237270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
21247270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
21257270962aSWarner Losh                          is used.
21267270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
21277270962aSWarner Losh                          representation for a device node can be used, where applicable.
21287270962aSWarner Losh 
21297270962aSWarner Losh **/
21307270962aSWarner Losh static VOID
DevPathRelativeOffsetRange(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)21317270962aSWarner Losh DevPathRelativeOffsetRange (
21327270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
21337270962aSWarner Losh   IN VOID            *DevPath,
21347270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
21357270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
21367270962aSWarner Losh   )
21377270962aSWarner Losh {
21387270962aSWarner Losh   MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH  *Offset;
21397270962aSWarner Losh 
21407270962aSWarner Losh   Offset = DevPath;
21417270962aSWarner Losh   UefiDevicePathLibCatPrint (
21427270962aSWarner Losh     Str,
21437270962aSWarner Losh     "Offset(0x%lx,0x%lx)",
21447270962aSWarner Losh     Offset->StartingOffset,
21457270962aSWarner Losh     Offset->EndingOffset
21467270962aSWarner Losh     );
21477270962aSWarner Losh }
21487270962aSWarner Losh 
21497270962aSWarner Losh /**
21507270962aSWarner Losh   Converts a Ram Disk device path structure to its string representative.
21517270962aSWarner Losh 
21527270962aSWarner Losh   @param Str             The string representative of input device.
21537270962aSWarner Losh   @param DevPath         The input device path structure.
21547270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
21557270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
21567270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
21577270962aSWarner Losh                          is used.
21587270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
21597270962aSWarner Losh                          representation for a device node can be used, where applicable.
21607270962aSWarner Losh 
21617270962aSWarner Losh **/
21627270962aSWarner Losh static VOID
DevPathToTextRamDisk(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)21637270962aSWarner Losh DevPathToTextRamDisk (
21647270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
21657270962aSWarner Losh   IN VOID            *DevPath,
21667270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
21677270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
21687270962aSWarner Losh   )
21697270962aSWarner Losh {
21707270962aSWarner Losh   MEDIA_RAM_DISK_DEVICE_PATH  *RamDisk;
21717270962aSWarner Losh 
21727270962aSWarner Losh   RamDisk = DevPath;
21737270962aSWarner Losh 
21747270962aSWarner Losh   if (CompareGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid)) {
21757270962aSWarner Losh     UefiDevicePathLibCatPrint (
21767270962aSWarner Losh       Str,
21777270962aSWarner Losh       "VirtualDisk(0x%lx,0x%lx,%d)",
21787270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],
21797270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],
21807270962aSWarner Losh       RamDisk->Instance
21817270962aSWarner Losh       );
21827270962aSWarner Losh   } else if (CompareGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid)) {
21837270962aSWarner Losh     UefiDevicePathLibCatPrint (
21847270962aSWarner Losh       Str,
21857270962aSWarner Losh       "VirtualCD(0x%lx,0x%lx,%d)",
21867270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],
21877270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],
21887270962aSWarner Losh       RamDisk->Instance
21897270962aSWarner Losh       );
21907270962aSWarner Losh   } else if (CompareGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid)) {
21917270962aSWarner Losh     UefiDevicePathLibCatPrint (
21927270962aSWarner Losh       Str,
21937270962aSWarner Losh       "PersistentVirtualDisk(0x%lx,0x%lx,%d)",
21947270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],
21957270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],
21967270962aSWarner Losh       RamDisk->Instance
21977270962aSWarner Losh       );
21987270962aSWarner Losh   } else if (CompareGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid)) {
21997270962aSWarner Losh     UefiDevicePathLibCatPrint (
22007270962aSWarner Losh       Str,
22017270962aSWarner Losh       "PersistentVirtualCD(0x%lx,0x%lx,%d)",
22027270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],
22037270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],
22047270962aSWarner Losh       RamDisk->Instance
22057270962aSWarner Losh       );
22067270962aSWarner Losh   } else {
22077270962aSWarner Losh     UefiDevicePathLibCatPrint (
22087270962aSWarner Losh       Str,
22097270962aSWarner Losh       "RamDisk(0x%lx,0x%lx,%d,%36s)",
22107270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],
22117270962aSWarner Losh       LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],
22127270962aSWarner Losh       RamDisk->Instance,
22137270962aSWarner Losh       G(&RamDisk->TypeGuid)
22147270962aSWarner Losh       );
22157270962aSWarner Losh   }
22167270962aSWarner Losh }
22177270962aSWarner Losh 
22187270962aSWarner Losh /**
22197270962aSWarner Losh   Converts a BIOS Boot Specification device path structure to its string representative.
22207270962aSWarner Losh 
22217270962aSWarner Losh   @param Str             The string representative of input device.
22227270962aSWarner Losh   @param DevPath         The input device path structure.
22237270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
22247270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
22257270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
22267270962aSWarner Losh                          is used.
22277270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
22287270962aSWarner Losh                          representation for a device node can be used, where applicable.
22297270962aSWarner Losh 
22307270962aSWarner Losh **/
22317270962aSWarner Losh static VOID
DevPathToTextBBS(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)22327270962aSWarner Losh DevPathToTextBBS (
22337270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
22347270962aSWarner Losh   IN VOID            *DevPath,
22357270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
22367270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
22377270962aSWarner Losh   )
22387270962aSWarner Losh {
22397270962aSWarner Losh   BBS_BBS_DEVICE_PATH  *Bbs;
22407270962aSWarner Losh   const char           *Type;
22417270962aSWarner Losh 
22427270962aSWarner Losh   Bbs = DevPath;
22437270962aSWarner Losh   switch (Bbs->DeviceType) {
22447270962aSWarner Losh     case BBS_TYPE_FLOPPY:
22457270962aSWarner Losh       Type = "Floppy";
22467270962aSWarner Losh       break;
22477270962aSWarner Losh 
22487270962aSWarner Losh     case BBS_TYPE_HARDDRIVE:
22497270962aSWarner Losh       Type = "HD";
22507270962aSWarner Losh       break;
22517270962aSWarner Losh 
22527270962aSWarner Losh     case BBS_TYPE_CDROM:
22537270962aSWarner Losh       Type = "CDROM";
22547270962aSWarner Losh       break;
22557270962aSWarner Losh 
22567270962aSWarner Losh     case BBS_TYPE_PCMCIA:
22577270962aSWarner Losh       Type = "PCMCIA";
22587270962aSWarner Losh       break;
22597270962aSWarner Losh 
22607270962aSWarner Losh     case BBS_TYPE_USB:
22617270962aSWarner Losh       Type = "USB";
22627270962aSWarner Losh       break;
22637270962aSWarner Losh 
22647270962aSWarner Losh     case BBS_TYPE_EMBEDDED_NETWORK:
22657270962aSWarner Losh       Type = "Network";
22667270962aSWarner Losh       break;
22677270962aSWarner Losh 
22687270962aSWarner Losh     default:
22697270962aSWarner Losh       Type = NULL;
22707270962aSWarner Losh       break;
22717270962aSWarner Losh   }
22727270962aSWarner Losh 
22737270962aSWarner Losh   if (Type != NULL) {
22747270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "BBS(%s,%s", Type, Bbs->String);
22757270962aSWarner Losh   } else {
22767270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "BBS(0x%x,%s", Bbs->DeviceType, Bbs->String);
22777270962aSWarner Losh   }
22787270962aSWarner Losh 
22797270962aSWarner Losh   if (DisplayOnly) {
22807270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ")");
22817270962aSWarner Losh     return;
22827270962aSWarner Losh   }
22837270962aSWarner Losh 
22847270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",0x%x)", Bbs->StatusFlag);
22857270962aSWarner Losh }
22867270962aSWarner Losh 
22877270962aSWarner Losh /**
22887270962aSWarner Losh   Converts an End-of-Device-Path structure to its string representative.
22897270962aSWarner Losh 
22907270962aSWarner Losh   @param Str             The string representative of input device.
22917270962aSWarner Losh   @param DevPath         The input device path structure.
22927270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
22937270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
22947270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
22957270962aSWarner Losh                          is used.
22967270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
22977270962aSWarner Losh                          representation for a device node can be used, where applicable.
22987270962aSWarner Losh 
22997270962aSWarner Losh **/
23007270962aSWarner Losh static VOID
DevPathToTextEndInstance(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)23017270962aSWarner Losh DevPathToTextEndInstance (
23027270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
23037270962aSWarner Losh   IN VOID            *DevPath,
23047270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
23057270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
23067270962aSWarner Losh   )
23077270962aSWarner Losh {
23087270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ",");
23097270962aSWarner Losh }
23107270962aSWarner Losh 
23117270962aSWarner Losh GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_GENERIC_TABLE  mUefiDevicePathLibToTextTableGeneric[] = {
23127270962aSWarner Losh   { HARDWARE_DEVICE_PATH,  "HardwarePath" },
23137270962aSWarner Losh   { ACPI_DEVICE_PATH,      "AcpiPath"     },
23147270962aSWarner Losh   { MESSAGING_DEVICE_PATH, "Msg"          },
23157270962aSWarner Losh   { MEDIA_DEVICE_PATH,     "MediaPath"    },
23167270962aSWarner Losh   { BBS_DEVICE_PATH,       "BbsPath"      },
23177270962aSWarner Losh   { 0,                     NULL            }
23187270962aSWarner Losh };
23197270962aSWarner Losh 
23207270962aSWarner Losh /**
23217270962aSWarner Losh   Converts an unknown device path structure to its string representative.
23227270962aSWarner Losh 
23237270962aSWarner Losh   @param Str             The string representative of input device.
23247270962aSWarner Losh   @param DevPath         The input device path structure.
23257270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
23267270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
23277270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
23287270962aSWarner Losh                          is used.
23297270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
23307270962aSWarner Losh                          representation for a device node can be used, where applicable.
23317270962aSWarner Losh 
23327270962aSWarner Losh **/
23337270962aSWarner Losh static VOID
DevPathToTextNodeGeneric(IN OUT POOL_PRINT * Str,IN VOID * DevPath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)23347270962aSWarner Losh DevPathToTextNodeGeneric (
23357270962aSWarner Losh   IN OUT POOL_PRINT  *Str,
23367270962aSWarner Losh   IN VOID            *DevPath,
23377270962aSWarner Losh   IN BOOLEAN         DisplayOnly,
23387270962aSWarner Losh   IN BOOLEAN         AllowShortcuts
23397270962aSWarner Losh   )
23407270962aSWarner Losh {
23417270962aSWarner Losh   EFI_DEVICE_PATH_PROTOCOL  *Node;
23427270962aSWarner Losh   UINTN                     Index;
23437270962aSWarner Losh 
23447270962aSWarner Losh   Node = DevPath;
23457270962aSWarner Losh 
23467270962aSWarner Losh   for (Index = 0; mUefiDevicePathLibToTextTableGeneric[Index].Text != NULL; Index++) {
23477270962aSWarner Losh     if (DevicePathType (Node) == mUefiDevicePathLibToTextTableGeneric[Index].Type) {
23487270962aSWarner Losh       break;
23497270962aSWarner Losh     }
23507270962aSWarner Losh   }
23517270962aSWarner Losh 
23527270962aSWarner Losh   if (mUefiDevicePathLibToTextTableGeneric[Index].Text == NULL) {
23537270962aSWarner Losh     //
23547270962aSWarner Losh     // It's a node whose type cannot be recognized
23557270962aSWarner Losh     //
23567270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "Path(%d,%d", DevicePathType (Node), DevicePathSubType (Node));
23577270962aSWarner Losh   } else {
23587270962aSWarner Losh     //
23597270962aSWarner Losh     // It's a node whose type can be recognized
23607270962aSWarner Losh     //
23617270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, "%s(%d", mUefiDevicePathLibToTextTableGeneric[Index].Text, DevicePathSubType (Node));
23627270962aSWarner Losh   }
23637270962aSWarner Losh 
23647270962aSWarner Losh   Index = sizeof (EFI_DEVICE_PATH_PROTOCOL);
23657270962aSWarner Losh   if (Index < DevicePathNodeLength (Node)) {
23667270962aSWarner Losh     UefiDevicePathLibCatPrint (Str, ",");
23677270962aSWarner Losh     for ( ; Index < DevicePathNodeLength (Node); Index++) {
23687270962aSWarner Losh       UefiDevicePathLibCatPrint (Str, "%02x", ((UINT8 *)Node)[Index]);
23697270962aSWarner Losh     }
23707270962aSWarner Losh   }
23717270962aSWarner Losh 
23727270962aSWarner Losh   UefiDevicePathLibCatPrint (Str, ")");
23737270962aSWarner Losh }
23747270962aSWarner Losh 
23757270962aSWarner Losh static const DEVICE_PATH_TO_TEXT_TABLE  mUefiDevicePathLibToTextTable[] = {
23767270962aSWarner Losh   { HARDWARE_DEVICE_PATH,  HW_PCI_DP,                        DevPathToTextPci           },
23777270962aSWarner Losh   { HARDWARE_DEVICE_PATH,  HW_PCCARD_DP,                     DevPathToTextPccard        },
23787270962aSWarner Losh   { HARDWARE_DEVICE_PATH,  HW_MEMMAP_DP,                     DevPathToTextMemMap        },
23797270962aSWarner Losh   { HARDWARE_DEVICE_PATH,  HW_VENDOR_DP,                     DevPathToTextVendor        },
23807270962aSWarner Losh   { HARDWARE_DEVICE_PATH,  HW_CONTROLLER_DP,                 DevPathToTextController    },
23817270962aSWarner Losh   { HARDWARE_DEVICE_PATH,  HW_BMC_DP,                        DevPathToTextBmc           },
23827270962aSWarner Losh   { ACPI_DEVICE_PATH,      ACPI_DP,                          DevPathToTextAcpi          },
23837270962aSWarner Losh   { ACPI_DEVICE_PATH,      ACPI_EXTENDED_DP,                 DevPathToTextAcpiEx        },
23847270962aSWarner Losh   { ACPI_DEVICE_PATH,      ACPI_ADR_DP,                      DevPathToTextAcpiAdr       },
23857270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_ATAPI_DP,                     DevPathToTextAtapi         },
23867270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_SCSI_DP,                      DevPathToTextScsi          },
23877270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP,              DevPathToTextFibre         },
23887270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP,            DevPathToTextFibreEx       },
23897270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_SASEX_DP,                     DevPathToTextSasEx         },
23907270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_NVME_NAMESPACE_DP,            DevPathToTextNVMe          },
23917270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_UFS_DP,                       DevPathToTextUfs           },
23927270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_SD_DP,                        DevPathToTextSd            },
23937270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_EMMC_DP,                      DevPathToTextEmmc          },
23947270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_1394_DP,                      DevPathToText1394          },
23957270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_USB_DP,                       DevPathToTextUsb           },
23967270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_USB_WWID_DP,                  DevPathToTextUsbWWID       },
23977270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_DEVICE_LOGICAL_UNIT_DP,       DevPathToTextLogicalUnit   },
23987270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,                 DevPathToTextUsbClass      },
23997270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_SATA_DP,                      DevPathToTextSata          },
24007270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_I2O_DP,                       DevPathToTextI2O           },
24017270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP,                  DevPathToTextMacAddr       },
24027270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_IPv4_DP,                      DevPathToTextIPv4          },
24037270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_IPv6_DP,                      DevPathToTextIPv6          },
24047270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP,                DevPathToTextInfiniBand    },
24057270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_UART_DP,                      DevPathToTextUart          },
24067270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,                    DevPathToTextVendor        },
24077270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_ISCSI_DP,                     DevPathToTextiSCSI         },
24087270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_VLAN_DP,                      DevPathToTextVlan          },
2409d9d1a1e7SJose Luis Duran   { MESSAGING_DEVICE_PATH, MSG_DNS_DP,                       DevPathToTextDns           },
24107270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_URI_DP,                       DevPathToTextUri           },
24117270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_DP,                 DevPathToTextBluetooth     },
24127270962aSWarner Losh   { MESSAGING_DEVICE_PATH, MSG_WIFI_DP,                      DevPathToTextWiFi          },
2413e8fc7f11SJose Luis Duran   { MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_LE_DP,              DevPathToTextBluetoothLE   },
24147270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_HARDDRIVE_DP,               DevPathToTextHardDrive     },
24157270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_CDROM_DP,                   DevPathToTextCDROM         },
24167270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_VENDOR_DP,                  DevPathToTextVendor        },
24177270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_PROTOCOL_DP,                DevPathToTextMediaProtocol },
24187270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_FILEPATH_DP,                DevPathToTextFilePath      },
24197270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_PIWG_FW_VOL_DP,             DevPathToTextFv            },
24207270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_PIWG_FW_FILE_DP,            DevPathToTextFvFile        },
24217270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_RELATIVE_OFFSET_RANGE_DP,   DevPathRelativeOffsetRange },
24227270962aSWarner Losh   { MEDIA_DEVICE_PATH,     MEDIA_RAM_DISK_DP,                DevPathToTextRamDisk       },
24237270962aSWarner Losh   { BBS_DEVICE_PATH,       BBS_BBS_DP,                       DevPathToTextBBS           },
24247270962aSWarner Losh   { END_DEVICE_PATH_TYPE,  END_INSTANCE_DEVICE_PATH_SUBTYPE, DevPathToTextEndInstance   },
24257270962aSWarner Losh   { 0,                     0,                                NULL                       }
24267270962aSWarner Losh };
24277270962aSWarner Losh 
24287270962aSWarner Losh /**
24297270962aSWarner Losh   Converts a device node to its string representation.
24307270962aSWarner Losh 
24317270962aSWarner Losh   @param DeviceNode        A Pointer to the device node to be converted.
24327270962aSWarner Losh   @param DisplayOnly       If DisplayOnly is TRUE, then the shorter text representation
24337270962aSWarner Losh                            of the display node is used, where applicable. If DisplayOnly
24347270962aSWarner Losh                            is FALSE, then the longer text representation of the display node
24357270962aSWarner Losh                            is used.
24367270962aSWarner Losh   @param AllowShortcuts    If AllowShortcuts is TRUE, then the shortcut forms of text
24377270962aSWarner Losh                            representation for a device node can be used, where applicable.
24387270962aSWarner Losh 
24397270962aSWarner Losh   @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
24407270962aSWarner Losh           is NULL or there was insufficient memory.
24417270962aSWarner Losh 
24427270962aSWarner Losh **/
24435320ef6aSWarner Losh static char *
24447270962aSWarner Losh EFIAPI
UefiDevicePathLibConvertDeviceNodeToText(IN CONST EFI_DEVICE_PATH_PROTOCOL * DeviceNode,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)24457270962aSWarner Losh UefiDevicePathLibConvertDeviceNodeToText (
24467270962aSWarner Losh   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DeviceNode,
24477270962aSWarner Losh   IN BOOLEAN                         DisplayOnly,
24487270962aSWarner Losh   IN BOOLEAN                         AllowShortcuts
24497270962aSWarner Losh   )
24507270962aSWarner Losh {
24517270962aSWarner Losh   POOL_PRINT           Str;
24527270962aSWarner Losh   UINTN                Index;
24537270962aSWarner Losh   DEVICE_PATH_TO_TEXT  ToText;
24545320ef6aSWarner Losh   EFI_DEVICE_PATH_PROTOCOL  *Node;
24557270962aSWarner Losh 
24567270962aSWarner Losh   if (DeviceNode == NULL) {
24577270962aSWarner Losh     return NULL;
24587270962aSWarner Losh   }
24597270962aSWarner Losh 
24607270962aSWarner Losh   ZeroMem (&Str, sizeof (Str));
24617270962aSWarner Losh 
24627270962aSWarner Losh   //
24637270962aSWarner Losh   // Process the device path node
24647270962aSWarner Losh   // If not found, use a generic function
24657270962aSWarner Losh   //
24665320ef6aSWarner Losh   Node = __DECONST(EFI_DEVICE_PATH_PROTOCOL *, DeviceNode);
24677270962aSWarner Losh   ToText = DevPathToTextNodeGeneric;
24687270962aSWarner Losh   for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index++) {
24695754f582SJose Luis Duran     if ((DevicePathType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].Type) &&
24705754f582SJose Luis Duran         (DevicePathSubType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].SubType)
24715754f582SJose Luis Duran         )
24725754f582SJose Luis Duran     {
24737270962aSWarner Losh       ToText = mUefiDevicePathLibToTextTable[Index].Function;
24747270962aSWarner Losh       break;
24757270962aSWarner Losh     }
24767270962aSWarner Losh   }
24777270962aSWarner Losh 
24787270962aSWarner Losh   //
24797270962aSWarner Losh   // Print this node
24807270962aSWarner Losh   //
24815320ef6aSWarner Losh   ToText (&Str, (VOID *)Node, DisplayOnly, AllowShortcuts);
24827270962aSWarner Losh 
24837270962aSWarner Losh   ASSERT (Str.Str != NULL);
24847270962aSWarner Losh   return Str.Str;
24857270962aSWarner Losh }
24867270962aSWarner Losh 
24877270962aSWarner Losh /**
24887270962aSWarner Losh   Converts a device path to its text representation.
24897270962aSWarner Losh 
24907270962aSWarner Losh   @param DevicePath      A Pointer to the device to be converted.
24917270962aSWarner Losh   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
24927270962aSWarner Losh                          of the display node is used, where applicable. If DisplayOnly
24937270962aSWarner Losh                          is FALSE, then the longer text representation of the display node
24947270962aSWarner Losh                          is used.
24957270962aSWarner Losh   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
24967270962aSWarner Losh                          representation for a device node can be used, where applicable.
24977270962aSWarner Losh 
24987270962aSWarner Losh   @return A pointer to the allocated text representation of the device path or
24997270962aSWarner Losh           NULL if DeviceNode is NULL or there was insufficient memory.
25007270962aSWarner Losh 
25017270962aSWarner Losh **/
25027270962aSWarner Losh static char *
25037270962aSWarner Losh EFIAPI
UefiDevicePathLibConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL * DevicePath,IN BOOLEAN DisplayOnly,IN BOOLEAN AllowShortcuts)25047270962aSWarner Losh UefiDevicePathLibConvertDevicePathToText (
25057270962aSWarner Losh   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,
25067270962aSWarner Losh   IN BOOLEAN                         DisplayOnly,
25077270962aSWarner Losh   IN BOOLEAN                         AllowShortcuts
25087270962aSWarner Losh   )
25097270962aSWarner Losh {
25107270962aSWarner Losh   POOL_PRINT                Str;
25117270962aSWarner Losh   EFI_DEVICE_PATH_PROTOCOL  *Node;
25127270962aSWarner Losh   EFI_DEVICE_PATH_PROTOCOL  *AlignedNode;
25137270962aSWarner Losh   UINTN                     Index;
25147270962aSWarner Losh   DEVICE_PATH_TO_TEXT       ToText;
25157270962aSWarner Losh 
25167270962aSWarner Losh   if (DevicePath == NULL) {
25177270962aSWarner Losh     return NULL;
25187270962aSWarner Losh   }
25197270962aSWarner Losh 
25207270962aSWarner Losh   ZeroMem (&Str, sizeof (Str));
25217270962aSWarner Losh 
25227270962aSWarner Losh   //
25237270962aSWarner Losh   // Process each device path node
25247270962aSWarner Losh   //
25257270962aSWarner Losh   Node = __DECONST(EFI_DEVICE_PATH_PROTOCOL *, DevicePath);
25267270962aSWarner Losh   while (!IsDevicePathEnd (Node)) {
25277270962aSWarner Losh     //
25287270962aSWarner Losh     // Find the handler to dump this device path node
25297270962aSWarner Losh     // If not found, use a generic function
25307270962aSWarner Losh     //
25317270962aSWarner Losh     ToText = DevPathToTextNodeGeneric;
25327270962aSWarner Losh     for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index += 1) {
25335754f582SJose Luis Duran       if ((DevicePathType (Node) == mUefiDevicePathLibToTextTable[Index].Type) &&
25345754f582SJose Luis Duran           (DevicePathSubType (Node) == mUefiDevicePathLibToTextTable[Index].SubType)
25355754f582SJose Luis Duran           )
25365754f582SJose Luis Duran       {
25377270962aSWarner Losh         ToText = mUefiDevicePathLibToTextTable[Index].Function;
25387270962aSWarner Losh         break;
25397270962aSWarner Losh       }
25407270962aSWarner Losh     }
25415754f582SJose Luis Duran 
25427270962aSWarner Losh     //
25437270962aSWarner Losh     //  Put a path separator in if needed
25447270962aSWarner Losh     //
25457270962aSWarner Losh     if ((Str.Count != 0) && (ToText != DevPathToTextEndInstance)) {
25467270962aSWarner Losh       if (Str.Str[Str.Count] != ',') {
25477270962aSWarner Losh         UefiDevicePathLibCatPrint (&Str, "/");
25487270962aSWarner Losh       }
25497270962aSWarner Losh     }
25507270962aSWarner Losh 
25517270962aSWarner Losh     AlignedNode = AllocateCopyPool (DevicePathNodeLength (Node), Node);
25527270962aSWarner Losh     //
25537270962aSWarner Losh     // Print this node of the device path
25547270962aSWarner Losh     //
25557270962aSWarner Losh     ToText (&Str, AlignedNode, DisplayOnly, AllowShortcuts);
25567270962aSWarner Losh     FreePool (AlignedNode);
25577270962aSWarner Losh 
25587270962aSWarner Losh     //
25597270962aSWarner Losh     // Next device path node
25607270962aSWarner Losh     //
25617270962aSWarner Losh     Node = NextDevicePathNode (Node);
25627270962aSWarner Losh   }
25637270962aSWarner Losh 
25647270962aSWarner Losh   if (Str.Str == NULL) {
25657270962aSWarner Losh     return AllocateZeroPool (sizeof (CHAR16));
25667270962aSWarner Losh   } else {
25677270962aSWarner Losh     return Str.Str;
25687270962aSWarner Losh   }
25697270962aSWarner Losh }
25707270962aSWarner Losh 
25717270962aSWarner Losh ssize_t
efidp_format_device_path(char * buf,size_t len,const_efidp dp,ssize_t max)25727270962aSWarner Losh efidp_format_device_path(char *buf, size_t len, const_efidp dp, ssize_t max)
25737270962aSWarner Losh {
25747270962aSWarner Losh 	char *str;
25757270962aSWarner Losh 	ssize_t retval;
25767270962aSWarner Losh 
2577366a7b3dSWarner Losh 	/*
2578366a7b3dSWarner Losh 	 * Basic sanity check on the device path.
2579366a7b3dSWarner Losh 	 */
2580366a7b3dSWarner Losh 	if (!IsDevicePathValid((CONST EFI_DEVICE_PATH_PROTOCOL *) dp, max)) {
2581366a7b3dSWarner Losh 		*buf = '\0';
2582366a7b3dSWarner Losh 		return 0;
2583366a7b3dSWarner Losh 	}
2584366a7b3dSWarner Losh 
25857270962aSWarner Losh 	str = UefiDevicePathLibConvertDevicePathToText (
25867270962aSWarner Losh 		__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp), FALSE, TRUE);
25877270962aSWarner Losh 	if (str == NULL)
25887270962aSWarner Losh 		return -1;
25897270962aSWarner Losh 	strlcpy(buf, str, len);
25907270962aSWarner Losh 	retval = strlen(str);
25917270962aSWarner Losh 	free(str);
25927270962aSWarner Losh 
25937270962aSWarner Losh 	return retval;
25947270962aSWarner Losh }
25951028a2d4SWarner Losh 
25965320ef6aSWarner Losh ssize_t
efidp_format_device_path_node(char * buf,size_t len,const_efidp dp)259709ee5d8aSWarner Losh efidp_format_device_path_node(char *buf, size_t len, const_efidp dp)
25985320ef6aSWarner Losh {
25995320ef6aSWarner Losh 	char *str;
26005320ef6aSWarner Losh 	ssize_t retval;
26015320ef6aSWarner Losh 
26025320ef6aSWarner Losh 	str = UefiDevicePathLibConvertDeviceNodeToText (
26035320ef6aSWarner Losh 		__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp), FALSE, TRUE);
26045320ef6aSWarner Losh 	if (str == NULL)
26055320ef6aSWarner Losh 		return -1;
26065320ef6aSWarner Losh 	strlcpy(buf, str, len);
26075320ef6aSWarner Losh 	retval = strlen(str);
26085320ef6aSWarner Losh 	free(str);
26095320ef6aSWarner Losh 
26105320ef6aSWarner Losh 	return retval;
26115320ef6aSWarner Losh }
26125320ef6aSWarner Losh 
26131028a2d4SWarner Losh size_t
efidp_size(const_efidp dp)26141028a2d4SWarner Losh efidp_size(const_efidp dp)
26151028a2d4SWarner Losh {
26165320ef6aSWarner Losh 
26171028a2d4SWarner Losh 	return GetDevicePathSize(__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp));
26181028a2d4SWarner Losh }
261909ee5d8aSWarner Losh 
262009ee5d8aSWarner Losh char *
efidp_extract_file_path(const_efidp dp)262109ee5d8aSWarner Losh efidp_extract_file_path(const_efidp dp)
262209ee5d8aSWarner Losh {
262309ee5d8aSWarner Losh 	const FILEPATH_DEVICE_PATH  *fp;
262409ee5d8aSWarner Losh 	char *name = NULL;
262509ee5d8aSWarner Losh 
262609ee5d8aSWarner Losh 	fp = (const void *)dp;
262709ee5d8aSWarner Losh 	ucs2_to_utf8(fp->PathName, &name);
262809ee5d8aSWarner Losh 	return name;
262909ee5d8aSWarner Losh }
2630