2 Main file for support of shell consist mapping.
4 Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include "UefiShellCommandLib.h"
15 #include <Library/DevicePathLib.h>
16 #include <Library/SortLib.h>
17 #include <Library/UefiLib.h>
18 #include <Protocol/UsbIo.h>
38 } DEVICE_CONSIST_MAPPING_INFO
;
46 Serial Decode function.
48 @param DevPath The Device path info.
49 @param MapInfo The map info.
50 @param OrigDevPath The original device path protocol.
55 (EFIAPI
*SERIAL_DECODE_FUNCTION
) (
56 EFI_DEVICE_PATH_PROTOCOL
*DevPath
,
57 DEVICE_CONSIST_MAPPING_INFO
*MapInfo
,
58 EFI_DEVICE_PATH_PROTOCOL
*OrigDevPath
64 SERIAL_DECODE_FUNCTION SerialFun
;
65 INTN (EFIAPI
*CompareFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, EFI_DEVICE_PATH_PROTOCOL
*DevPath2
);
66 } DEV_PATH_CONSIST_MAPPING_TABLE
;
70 Concatenates a formatted unicode string to allocated pool.
71 The caller must free the resulting buffer.
73 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.
74 @param Fmt The format string
75 @param ... The data will be printed.
77 @return Allocated buffer with the formatted string printed in it.
78 The caller must free the allocated buffer.
79 The buffer allocation is not packed.
85 IN OUT POOL_PRINT
*Str
,
94 AppendStr
= AllocateZeroPool (0x1000);
95 if (AppendStr
== NULL
) {
100 VA_START (Args
, Fmt
);
101 UnicodeVSPrint (AppendStr
, 0x1000, Fmt
, Args
);
103 if (NULL
== Str
->Str
) {
104 StringSize
= StrSize (AppendStr
);
105 Str
->Str
= AllocateZeroPool (StringSize
);
106 ASSERT (Str
->Str
!= NULL
);
108 StringSize
= StrSize (AppendStr
);
109 StringSize
+= (StrSize (Str
->Str
) - sizeof (UINT16
));
111 Str
->Str
= ReallocatePool (
116 ASSERT (Str
->Str
!= NULL
);
119 StrCatS (Str
->Str
, StringSize
/sizeof(CHAR16
), AppendStr
);
120 Str
->Len
= StringSize
;
122 FreePool (AppendStr
);
126 MTD_NAME mMTDName
[] = {
150 Function to append a 64 bit number / 25 onto the string.
152 @param[in, out] Str The string so append onto.
153 @param[in] Num The number to divide and append.
155 @retval EFI_INVALID_PARAMETER A parameter was NULL.
156 @retval EFI_SUCCESS The appending was successful.
161 IN OUT POOL_PRINT
*Str
,
169 return (EFI_INVALID_PARAMETER
);
172 Result
= DivU64x32Remainder (Num
, 25, &Rem
);
174 AppendCSDNum2 (Str
, Result
);
177 CatPrint (Str
, L
"%c", Rem
+ 'a');
178 return (EFI_SUCCESS
);
182 Function to append a 64 bit number onto the mapping info.
184 @param[in, out] MappingItem The mapping info object to append onto.
185 @param[in] Num The info to append.
187 @retval EFI_INVALID_PARAMETER A parameter was NULL.
188 @retval EFI_SUCCESS The appending was successful.
193 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
197 if (MappingItem
== NULL
) {
198 return EFI_INVALID_PARAMETER
;
201 if (MappingItem
->Digital
) {
202 CatPrint (&MappingItem
->Csd
, L
"%ld", Num
);
204 AppendCSDNum2 (&MappingItem
->Csd
, Num
);
207 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
209 return (EFI_SUCCESS
);
213 Function to append string into the mapping info.
215 @param[in, out] MappingItem The mapping info object to append onto.
216 @param[in] Str The info to append.
218 @retval EFI_INVALID_PARAMETER A parameter was NULL.
219 @retval EFI_SUCCESS The appending was successful.
224 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
230 if (Str
== NULL
|| MappingItem
== NULL
) {
231 return (EFI_INVALID_PARAMETER
);
234 if (MappingItem
->Digital
) {
236 // To aVOID mult-meaning, the mapping is:
237 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
238 // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15
240 for (Index
= Str
; *Index
!= 0; Index
++) {
251 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
);
255 CatPrint (&MappingItem
->Csd
, L
"16");
264 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'a' + '0');
273 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'A' + '0');
278 for (Index
= Str
; *Index
!= 0; Index
++) {
281 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
282 // a b c d e f g h i j k l m n o p
284 if (*Index
>= '0' && *Index
<= '9') {
285 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- '0' + 'a');
286 } else if (*Index
>= 'a' && *Index
<= 'f') {
287 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'a' + 'k');
288 } else if (*Index
>= 'A' && *Index
<= 'F') {
289 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'A' + 'k');
294 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
296 return (EFI_SUCCESS
);
300 Function to append a Guid to the mapping item.
302 @param[in, out] MappingItem The item to append onto.
303 @param[in] Guid The guid to append.
305 @retval EFI_SUCCESS The appending operation was successful.
306 @retval EFI_INVALID_PARAMETER A parameter was NULL.
311 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
317 if (Guid
== NULL
|| MappingItem
== NULL
) {
318 return (EFI_INVALID_PARAMETER
);
328 AppendCSDStr (MappingItem
, Buffer
);
330 return (EFI_SUCCESS
);
334 Function to compare 2 APCI device paths.
336 @param[in] DevicePath1 The first device path to compare.
337 @param[in] DevicePath2 The second device path to compare.
339 @retval 0 The device paths represent the same device.
340 @return Non zero if the devices are different, zero otherwise.
345 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
346 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
349 ACPI_HID_DEVICE_PATH
*Acpi1
;
350 ACPI_HID_DEVICE_PATH
*Acpi2
;
352 if (DevicePath1
== NULL
|| DevicePath2
== NULL
) {
356 Acpi1
= (ACPI_HID_DEVICE_PATH
*) DevicePath1
;
357 Acpi2
= (ACPI_HID_DEVICE_PATH
*) DevicePath2
;
358 if (Acpi1
->HID
> Acpi2
->HID
|| (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
> Acpi2
->UID
)) {
362 if (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
== Acpi2
->UID
) {
370 Function to compare 2 PCI device paths.
372 @param[in] DevicePath1 The first device path to compare.
373 @param[in] DevicePath2 The second device path to compare.
375 @retval 0 The device paths represent the same device.
376 @return Non zero if the devices are different, zero otherwise.
381 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
382 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
385 PCI_DEVICE_PATH
*Pci1
;
386 PCI_DEVICE_PATH
*Pci2
;
388 ASSERT(DevicePath1
!= NULL
);
389 ASSERT(DevicePath2
!= NULL
);
391 Pci1
= (PCI_DEVICE_PATH
*) DevicePath1
;
392 Pci2
= (PCI_DEVICE_PATH
*) DevicePath2
;
393 if (Pci1
->Device
> Pci2
->Device
|| (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
> Pci2
->Function
)) {
397 if (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
== Pci2
->Function
) {
405 Do a comparison on 2 device paths.
407 @param[in] DevicePath1 The first device path.
408 @param[in] DevicePath2 The second device path.
410 @retval 0 The 2 device paths are the same.
411 @retval <0 DevicePath2 is greater than DevicePath1.
412 @retval >0 DevicePath1 is greater than DevicePath2.
416 DevPathCompareDefault (
417 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
418 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
424 ASSERT(DevicePath1
!= NULL
);
425 ASSERT(DevicePath2
!= NULL
);
427 DevPathSize1
= DevicePathNodeLength (DevicePath1
);
428 DevPathSize2
= DevicePathNodeLength (DevicePath2
);
429 if (DevPathSize1
> DevPathSize2
) {
431 } else if (DevPathSize1
< DevPathSize2
) {
434 return CompareMem (DevicePath1
, DevicePath2
, DevPathSize1
);
439 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
441 @param[in] DevicePathNode The node to get info on.
442 @param[in] MappingItem The info item to populate.
443 @param[in] DevicePath Ignored.
447 DevPathSerialHardDrive (
448 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
449 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
450 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
453 HARDDRIVE_DEVICE_PATH
*Hd
;
455 ASSERT(DevicePathNode
!= NULL
);
456 ASSERT(MappingItem
!= NULL
);
458 Hd
= (HARDDRIVE_DEVICE_PATH
*) DevicePathNode
;
459 if (MappingItem
->Mtd
== MTDTypeUnknown
) {
460 MappingItem
->Mtd
= MTDTypeHardDisk
;
463 AppendCSDNum (MappingItem
, Hd
->PartitionNumber
);
467 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
469 @param[in] DevicePathNode The node to get info on.
470 @param[in] MappingItem The info item to populate.
471 @param[in] DevicePath Ignored.
476 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
477 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
478 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
481 ATAPI_DEVICE_PATH
*Atapi
;
483 ASSERT(DevicePathNode
!= NULL
);
484 ASSERT(MappingItem
!= NULL
);
486 Atapi
= (ATAPI_DEVICE_PATH
*) DevicePathNode
;
487 AppendCSDNum (MappingItem
, (Atapi
->PrimarySecondary
* 2 + Atapi
->SlaveMaster
));
491 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
493 @param[in] DevicePathNode The node to get info on.
494 @param[in] MappingItem The info item to populate.
495 @param[in] DevicePath Ignored.
500 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
501 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
502 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
505 CDROM_DEVICE_PATH
*Cd
;
507 ASSERT(DevicePathNode
!= NULL
);
508 ASSERT(MappingItem
!= NULL
);
510 Cd
= (CDROM_DEVICE_PATH
*) DevicePathNode
;
511 MappingItem
->Mtd
= MTDTypeCDRom
;
512 AppendCSDNum (MappingItem
, Cd
->BootEntry
);
516 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
518 @param[in] DevicePathNode The node to get info on.
519 @param[in] MappingItem The info item to populate.
520 @param[in] DevicePath Ignored.
525 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
526 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
527 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
530 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
532 ASSERT(DevicePathNode
!= NULL
);
533 ASSERT(MappingItem
!= NULL
);
535 Fibre
= (FIBRECHANNEL_DEVICE_PATH
*) DevicePathNode
;
536 AppendCSDNum (MappingItem
, Fibre
->WWN
);
537 AppendCSDNum (MappingItem
, Fibre
->Lun
);
541 DevicePathNode must be SerialUart type and this will populate the MappingItem.
543 @param[in] DevicePathNode The node to get info on.
544 @param[in] MappingItem The info item to populate.
545 @param[in] DevicePath Ignored.
550 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
551 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
552 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
555 UART_DEVICE_PATH
*Uart
;
557 ASSERT(DevicePathNode
!= NULL
);
558 ASSERT(MappingItem
!= NULL
);
560 Uart
= (UART_DEVICE_PATH
*) DevicePathNode
;
561 AppendCSDNum (MappingItem
, Uart
->BaudRate
);
562 AppendCSDNum (MappingItem
, Uart
->DataBits
);
563 AppendCSDNum (MappingItem
, Uart
->Parity
);
564 AppendCSDNum (MappingItem
, Uart
->StopBits
);
568 DevicePathNode must be SerialUSB type and this will populate the MappingItem.
570 @param[in] DevicePathNode The node to get info on.
571 @param[in] MappingItem The info item to populate.
572 @param[in] DevicePath Ignored.
577 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
578 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
579 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
582 USB_DEVICE_PATH
*Usb
;
583 EFI_USB_IO_PROTOCOL
*UsbIo
;
584 EFI_HANDLE TempHandle
;
586 USB_INTERFACE_DESCRIPTOR InterfaceDesc
;
589 ASSERT(DevicePathNode
!= NULL
);
590 ASSERT(MappingItem
!= NULL
);
592 Usb
= (USB_DEVICE_PATH
*) DevicePathNode
;
593 AppendCSDNum (MappingItem
, Usb
->ParentPortNumber
);
594 AppendCSDNum (MappingItem
, Usb
->InterfaceNumber
);
596 if (PcdGetBool(PcdUsbExtendedDecode
)) {
597 Status
= gBS
->LocateDevicePath( &gEfiUsbIoProtocolGuid
, &DevicePath
, &TempHandle
);
599 if (!EFI_ERROR(Status
)) {
600 Status
= gBS
->OpenProtocol(TempHandle
, &gEfiUsbIoProtocolGuid
, (VOID
**)&UsbIo
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
603 if (!EFI_ERROR(Status
)) {
604 ASSERT(UsbIo
!= NULL
);
605 Status
= UsbIo
->UsbGetInterfaceDescriptor(UsbIo
, &InterfaceDesc
);
606 if (!EFI_ERROR(Status
)) {
607 if (InterfaceDesc
.InterfaceClass
== USB_MASS_STORE_CLASS
&& MappingItem
->Mtd
== MTDTypeUnknown
) {
608 switch (InterfaceDesc
.InterfaceSubClass
){
609 case USB_MASS_STORE_SCSI
:
610 MappingItem
->Mtd
= MTDTypeHardDisk
;
612 case USB_MASS_STORE_8070I
:
613 case USB_MASS_STORE_UFI
:
614 MappingItem
->Mtd
= MTDTypeFloppy
;
616 case USB_MASS_STORE_8020I
:
617 MappingItem
->Mtd
= MTDTypeCDRom
;
627 DevicePathNode must be SerialVendor type and this will populate the MappingItem.
629 @param[in] DevicePathNode The node to get info on.
630 @param[in] MappingItem The info item to populate.
631 @param[in] DevicePath Ignored.
636 DevPathSerialVendor (
637 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
638 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
639 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
642 VENDOR_DEVICE_PATH
*Vendor
;
643 SAS_DEVICE_PATH
*Sas
;
644 UINTN TargetNameLength
;
648 if (DevicePathNode
== NULL
|| MappingItem
== NULL
) {
652 Vendor
= (VENDOR_DEVICE_PATH
*) DevicePathNode
;
653 AppendCSDGuid (MappingItem
, &Vendor
->Guid
);
655 if (CompareGuid (&gEfiSasDevicePathGuid
, &Vendor
->Guid
)) {
656 Sas
= (SAS_DEVICE_PATH
*) Vendor
;
657 AppendCSDNum (MappingItem
, Sas
->SasAddress
);
658 AppendCSDNum (MappingItem
, Sas
->Lun
);
659 AppendCSDNum (MappingItem
, Sas
->DeviceTopology
);
660 AppendCSDNum (MappingItem
, Sas
->RelativeTargetPort
);
662 TargetNameLength
= MIN(DevicePathNodeLength (DevicePathNode
) - sizeof (VENDOR_DEVICE_PATH
), PcdGet32(PcdShellVendorExtendedDecode
));
663 if (TargetNameLength
!= 0) {
665 // String is 2 chars per data byte, plus NULL terminator
667 Buffer
= AllocateZeroPool (((TargetNameLength
* 2) + 1) * sizeof(CHAR16
));
668 ASSERT(Buffer
!= NULL
);
669 if (Buffer
== NULL
) {
674 // Build the string data
676 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
677 Buffer
= CatSPrint (Buffer
, L
"%02x", *((UINT8
*)Vendor
+ sizeof (VENDOR_DEVICE_PATH
) + Index
));
681 // Append the new data block
683 AppendCSDStr (MappingItem
, Buffer
);
691 DevicePathNode must be SerialLun type and this will populate the MappingItem.
693 @param[in] DevicePathNode The node to get info on.
694 @param[in] MappingItem The info item to populate.
695 @param[in] DevicePath Ignored.
700 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
701 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
702 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
705 DEVICE_LOGICAL_UNIT_DEVICE_PATH
*Lun
;
707 ASSERT(DevicePathNode
!= NULL
);
708 ASSERT(MappingItem
!= NULL
);
710 Lun
= (DEVICE_LOGICAL_UNIT_DEVICE_PATH
*) DevicePathNode
;
711 AppendCSDNum (MappingItem
, Lun
->Lun
);
715 DevicePathNode must be SerialSata type and this will populate the MappingItem.
717 @param[in] DevicePathNode The node to get info on.
718 @param[in] MappingItem The info item to populate.
719 @param[in] DevicePath Ignored.
724 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
725 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
726 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
729 SATA_DEVICE_PATH
*Sata
;
731 ASSERT(DevicePathNode
!= NULL
);
732 ASSERT(MappingItem
!= NULL
);
734 Sata
= (SATA_DEVICE_PATH
*) DevicePathNode
;
735 AppendCSDNum (MappingItem
, Sata
->HBAPortNumber
);
736 AppendCSDNum (MappingItem
, Sata
->PortMultiplierPortNumber
);
737 AppendCSDNum (MappingItem
, Sata
->Lun
);
741 DevicePathNode must be SerialSCSI type and this will populate the MappingItem.
743 @param[in] DevicePathNode The node to get info on.
744 @param[in] MappingItem The info item to populate.
745 @param[in] DevicePath Ignored.
750 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
751 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
752 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
755 ISCSI_DEVICE_PATH
*IScsi
;
756 UINT8
*IScsiTargetName
;
758 UINTN TargetNameLength
;
761 ASSERT(DevicePathNode
!= NULL
);
762 ASSERT(MappingItem
!= NULL
);
764 if (PcdGetBool(PcdShellDecodeIScsiMapNames
)) {
765 IScsi
= (ISCSI_DEVICE_PATH
*) DevicePathNode
;
766 AppendCSDNum (MappingItem
, IScsi
->NetworkProtocol
);
767 AppendCSDNum (MappingItem
, IScsi
->LoginOption
);
768 AppendCSDNum (MappingItem
, IScsi
->Lun
);
769 AppendCSDNum (MappingItem
, IScsi
->TargetPortalGroupTag
);
770 TargetNameLength
= DevicePathNodeLength (DevicePathNode
) - sizeof (ISCSI_DEVICE_PATH
);
771 if (TargetNameLength
> 0) {
772 TargetName
= AllocateZeroPool ((TargetNameLength
+ 1) * sizeof (CHAR16
));
773 if (TargetName
!= NULL
) {
774 IScsiTargetName
= (UINT8
*) (IScsi
+ 1);
775 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
776 TargetName
[Index
] = (CHAR16
) IScsiTargetName
[Index
];
778 AppendCSDStr (MappingItem
, TargetName
);
779 FreePool (TargetName
);
786 DevicePathNode must be SerialI20 type and this will populate the MappingItem.
788 @param[in] DevicePathNode The node to get info on.
789 @param[in] MappingItem The info item to populate.
790 @param[in] DevicePath Ignored.
795 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
796 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
797 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
800 I2O_DEVICE_PATH
*DevicePath_I20
;
802 ASSERT(DevicePathNode
!= NULL
);
803 ASSERT(MappingItem
!= NULL
);
805 DevicePath_I20
= (I2O_DEVICE_PATH
*) DevicePathNode
;
806 AppendCSDNum (MappingItem
, DevicePath_I20
->Tid
);
810 DevicePathNode must be Mac Address type and this will populate the MappingItem.
812 @param[in] DevicePathNode The node to get info on.
813 @param[in] MappingItem The info item to populate.
814 @param[in] DevicePath Ignored.
818 DevPathSerialMacAddr (
819 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
820 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
821 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
824 MAC_ADDR_DEVICE_PATH
*Mac
;
830 ASSERT(DevicePathNode
!= NULL
);
831 ASSERT(MappingItem
!= NULL
);
833 Mac
= (MAC_ADDR_DEVICE_PATH
*) DevicePathNode
;
835 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
836 if (Mac
->IfType
== 0x01 || Mac
->IfType
== 0x00) {
840 for (Index
= 0, PBuffer
= Buffer
; Index
< HwAddressSize
; Index
++, PBuffer
+= 2) {
841 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Mac
->MacAddress
.Addr
[Index
]);
844 AppendCSDStr (MappingItem
, Buffer
);
848 DevicePathNode must be InfiniBand type and this will populate the MappingItem.
850 @param[in] DevicePathNode The node to get info on.
851 @param[in] MappingItem The info item to populate.
852 @param[in] DevicePath Ignored.
856 DevPathSerialInfiniBand (
857 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
858 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
859 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
862 INFINIBAND_DEVICE_PATH
*InfiniBand
;
867 ASSERT(DevicePathNode
!= NULL
);
868 ASSERT(MappingItem
!= NULL
);
870 InfiniBand
= (INFINIBAND_DEVICE_PATH
*) DevicePathNode
;
871 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
872 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) InfiniBand
->PortGid
[Index
]);
875 AppendCSDStr (MappingItem
, Buffer
);
876 AppendCSDNum (MappingItem
, InfiniBand
->ServiceId
);
877 AppendCSDNum (MappingItem
, InfiniBand
->TargetPortId
);
878 AppendCSDNum (MappingItem
, InfiniBand
->DeviceId
);
882 DevicePathNode must be IPv4 type and this will populate the MappingItem.
884 @param[in] DevicePathNode The node to get info on.
885 @param[in] MappingItem The info item to populate.
886 @param[in] DevicePath Ignored.
891 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
892 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
893 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
896 IPv4_DEVICE_PATH
*Ip
;
899 ASSERT(DevicePathNode
!= NULL
);
900 ASSERT(MappingItem
!= NULL
);
902 Ip
= (IPv4_DEVICE_PATH
*) DevicePathNode
;
907 (UINTN
) Ip
->LocalIpAddress
.Addr
[0],
908 (UINTN
) Ip
->LocalIpAddress
.Addr
[1],
909 (UINTN
) Ip
->LocalIpAddress
.Addr
[2],
910 (UINTN
) Ip
->LocalIpAddress
.Addr
[3]
912 AppendCSDStr (MappingItem
, Buffer
);
913 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
918 (UINTN
) Ip
->RemoteIpAddress
.Addr
[0],
919 (UINTN
) Ip
->RemoteIpAddress
.Addr
[1],
920 (UINTN
) Ip
->RemoteIpAddress
.Addr
[2],
921 (UINTN
) Ip
->RemoteIpAddress
.Addr
[3]
923 AppendCSDStr (MappingItem
, Buffer
);
924 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
928 DevicePathNode must be IPv6 type and this will populate the MappingItem.
930 @param[in] DevicePathNode The node to get info on.
931 @param[in] MappingItem The info item to populate.
932 @param[in] DevicePath Ignored.
938 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
939 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
940 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
943 IPv6_DEVICE_PATH
*Ip
;
948 ASSERT(DevicePathNode
!= NULL
);
949 ASSERT(MappingItem
!= NULL
);
951 Ip
= (IPv6_DEVICE_PATH
*) DevicePathNode
;
952 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
953 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->LocalIpAddress
.Addr
[Index
]);
956 AppendCSDStr (MappingItem
, Buffer
);
957 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
958 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
959 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->RemoteIpAddress
.Addr
[Index
]);
962 AppendCSDStr (MappingItem
, Buffer
);
963 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
967 DevicePathNode must be SCSI type and this will populate the MappingItem.
969 @param[in] DevicePathNode The node to get info on.
970 @param[in] MappingItem The info item to populate.
971 @param[in] DevicePath Ignored.
977 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
978 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
979 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
982 SCSI_DEVICE_PATH
*Scsi
;
984 ASSERT(DevicePathNode
!= NULL
);
985 ASSERT(MappingItem
!= NULL
);
987 Scsi
= (SCSI_DEVICE_PATH
*) DevicePathNode
;
988 AppendCSDNum (MappingItem
, Scsi
->Pun
);
989 AppendCSDNum (MappingItem
, Scsi
->Lun
);
993 DevicePathNode must be 1394 type and this will populate the MappingItem.
995 @param[in] DevicePathNode The node to get info on.
996 @param[in] MappingItem The info item to populate.
997 @param[in] DevicePath Ignored.
1002 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
1003 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1004 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1007 F1394_DEVICE_PATH
*DevicePath_F1394
;
1010 ASSERT(DevicePathNode
!= NULL
);
1011 ASSERT(MappingItem
!= NULL
);
1013 DevicePath_F1394
= (F1394_DEVICE_PATH
*) DevicePathNode
;
1014 UnicodeSPrint (Buffer
, 0, L
"%lx", DevicePath_F1394
->Guid
);
1015 AppendCSDStr (MappingItem
, Buffer
);
1019 If the node is floppy type then populate the MappingItem.
1021 @param[in] DevicePathNode The node to get info on.
1022 @param[in] MappingItem The info item to populate.
1023 @param[in] DevicePath Ignored.
1028 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
1029 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1030 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1033 ACPI_HID_DEVICE_PATH
*Acpi
;
1035 ASSERT(DevicePathNode
!= NULL
);
1036 ASSERT(MappingItem
!= NULL
);
1038 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1039 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
1040 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
1041 MappingItem
->Mtd
= MTDTypeFloppy
;
1042 AppendCSDNum (MappingItem
, Acpi
->UID
);
1048 Empty function used for unknown devices.
1050 @param[in] DevicePathNode Ignored.
1051 @param[in] MappingItem Ignored.
1052 @param[in] DevicePath Ignored.
1058 DevPathSerialDefault (
1059 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
1060 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1061 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1067 DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable
[] = {
1069 HARDWARE_DEVICE_PATH
,
1071 DevPathSerialDefault
,
1081 MESSAGING_DEVICE_PATH
,
1084 DevPathCompareDefault
1087 MESSAGING_DEVICE_PATH
,
1090 DevPathCompareDefault
1093 MESSAGING_DEVICE_PATH
,
1094 MSG_FIBRECHANNEL_DP
,
1096 DevPathCompareDefault
1099 MESSAGING_DEVICE_PATH
,
1102 DevPathCompareDefault
1105 MESSAGING_DEVICE_PATH
,
1108 DevPathCompareDefault
1111 MESSAGING_DEVICE_PATH
,
1114 DevPathCompareDefault
1117 MESSAGING_DEVICE_PATH
,
1119 DevPathSerialMacAddr
,
1120 DevPathCompareDefault
1123 MESSAGING_DEVICE_PATH
,
1126 DevPathCompareDefault
1129 MESSAGING_DEVICE_PATH
,
1132 DevPathCompareDefault
1135 MESSAGING_DEVICE_PATH
,
1137 DevPathSerialInfiniBand
,
1138 DevPathCompareDefault
1141 MESSAGING_DEVICE_PATH
,
1144 DevPathCompareDefault
1147 MESSAGING_DEVICE_PATH
,
1149 DevPathSerialVendor
,
1150 DevPathCompareDefault
1153 MESSAGING_DEVICE_PATH
,
1154 MSG_DEVICE_LOGICAL_UNIT_DP
,
1156 DevPathCompareDefault
1159 MESSAGING_DEVICE_PATH
,
1162 DevPathCompareDefault
1165 MESSAGING_DEVICE_PATH
,
1168 DevPathCompareDefault
1173 DevPathSerialHardDrive
,
1174 DevPathCompareDefault
1180 DevPathCompareDefault
1185 DevPathSerialVendor
,
1186 DevPathCompareDefault
1197 Function to determine if a device path node is Hi or not.
1199 @param[in] DevicePathNode The node to check.
1201 @retval TRUE The node is Hi.
1202 @retval FALSE The node is not Hi.
1206 IsHIDevicePathNode (
1207 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
1210 ACPI_HID_DEVICE_PATH
*Acpi
;
1212 ASSERT(DevicePathNode
!= NULL
);
1214 if (DevicePathNode
->Type
== HARDWARE_DEVICE_PATH
) {
1218 if (DevicePathNode
->Type
== ACPI_DEVICE_PATH
) {
1219 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1220 switch (EISA_ID_TO_NUM (Acpi
->HID
)) {
1235 Function to convert a standard device path structure into a Hi version.
1237 @param[in] DevicePath The device path to convert.
1239 @return the device path portion that is Hi.
1241 EFI_DEVICE_PATH_PROTOCOL
*
1244 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1247 UINTN NonHIDevicePathNodeCount
;
1250 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1251 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1253 ASSERT(DevicePath
!= NULL
);
1255 NonHIDevicePathNodeCount
= 0;
1257 HIDevicePath
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1258 SetDevicePathEndNode (HIDevicePath
);
1260 Node
.DevPath
.Type
= END_DEVICE_PATH_TYPE
;
1261 Node
.DevPath
.SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
1262 Node
.DevPath
.Length
[0] = (UINT8
)sizeof (EFI_DEVICE_PATH_PROTOCOL
);
1263 Node
.DevPath
.Length
[1] = 0;
1265 while (!IsDevicePathEnd (DevicePath
)) {
1266 if (IsHIDevicePathNode (DevicePath
)) {
1267 for (Index
= 0; Index
< NonHIDevicePathNodeCount
; Index
++) {
1268 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, &Node
.DevPath
);
1269 FreePool (HIDevicePath
);
1270 HIDevicePath
= TempDevicePath
;
1273 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, DevicePath
);
1274 FreePool (HIDevicePath
);
1275 HIDevicePath
= TempDevicePath
;
1277 NonHIDevicePathNodeCount
++;
1280 // Next device path node
1282 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1285 return HIDevicePath
;
1289 Function to walk the device path looking for a dumpable node.
1291 @param[in] MappingItem The Item to fill with data.
1292 @param[in] DevicePath The path of the item to get data on.
1294 @return EFI_SUCCESS Always returns success.
1298 GetDeviceConsistMappingInfo (
1299 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1300 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1303 SERIAL_DECODE_FUNCTION SerialFun
;
1305 EFI_DEVICE_PATH_PROTOCOL
*OriginalDevicePath
;
1307 ASSERT(DevicePath
!= NULL
);
1308 ASSERT(MappingItem
!= NULL
);
1310 SetMem (&MappingItem
->Csd
, sizeof (POOL_PRINT
), 0);
1311 OriginalDevicePath
= DevicePath
;
1313 while (!IsDevicePathEnd (DevicePath
)) {
1315 // Find the handler to dump this device path node and
1316 // initialize with generic function in case nothing is found
1318 for (SerialFun
= DevPathSerialDefault
, Index
= 0; DevPathConsistMappingTable
[Index
].SerialFun
!= NULL
; Index
+= 1) {
1320 if (DevicePathType (DevicePath
) == DevPathConsistMappingTable
[Index
].Type
&&
1321 DevicePathSubType (DevicePath
) == DevPathConsistMappingTable
[Index
].SubType
1323 SerialFun
= DevPathConsistMappingTable
[Index
].SerialFun
;
1328 SerialFun (DevicePath
, MappingItem
, OriginalDevicePath
);
1331 // Next device path node
1333 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1340 Function to initialize the table for creating consistent map names.
1342 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
1344 @retval EFI_SUCCESS The table was created successfully.
1348 ShellCommandConsistMappingInitialize (
1349 OUT EFI_DEVICE_PATH_PROTOCOL
***Table
1352 EFI_HANDLE
*HandleBuffer
;
1355 EFI_DEVICE_PATH_PROTOCOL
**TempTable
;
1356 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1357 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1361 HandleBuffer
= NULL
;
1363 Status
= gBS
->LocateHandleBuffer (
1370 ASSERT_EFI_ERROR(Status
);
1372 TempTable
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
1373 if (TempTable
== NULL
) {
1374 return EFI_OUT_OF_RESOURCES
;
1377 for (HandleLoop
= 0 ; HandleLoop
< HandleNum
; HandleLoop
++) {
1378 DevicePath
= DevicePathFromHandle (HandleBuffer
[HandleLoop
]);
1379 if (DevicePath
== NULL
) {
1383 HIDevicePath
= GetHIDevicePath (DevicePath
);
1384 if (HIDevicePath
== NULL
) {
1388 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++) {
1389 if (DevicePathCompare (&TempTable
[Index
], &HIDevicePath
) == 0) {
1390 FreePool (HIDevicePath
);
1395 if (TempTable
[Index
] == NULL
) {
1396 TempTable
[Index
] = HIDevicePath
;
1400 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++);
1401 PerformQuickSort(TempTable
, Index
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1404 if (HandleBuffer
!= NULL
) {
1405 FreePool (HandleBuffer
);
1412 Function to uninitialize the table for creating consistent map names.
1414 The parameter must have been received from ShellCommandConsistMappingInitialize.
1416 @param[out] Table The pointer to pointer to DevicePathProtocol object.
1418 @retval EFI_SUCCESS The table was deleted successfully.
1422 ShellCommandConsistMappingUnInitialize (
1423 EFI_DEVICE_PATH_PROTOCOL
**Table
1428 ASSERT(Table
!= NULL
);
1430 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1431 FreePool (Table
[Index
]);
1439 Create a consistent mapped name for the device specified by DevicePath
1442 This must be called after ShellCommandConsistMappingInitialize() and
1443 before ShellCommandConsistMappingUnInitialize() is called.
1445 @param[in] DevicePath The pointer to the dev path for the device.
1446 @param[in] Table The Table of mapping information.
1448 @retval NULL A consistent mapped name could not be created.
1449 @return A pointer to a string allocated from pool with the device name.
1453 ShellCommandConsistMappingGenMappingName (
1454 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1455 IN EFI_DEVICE_PATH_PROTOCOL
**Table
1459 DEVICE_CONSIST_MAPPING_INFO MappingInfo
;
1460 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1464 ASSERT(DevicePath
!= NULL
);
1465 ASSERT(Table
!= NULL
);
1467 HIDevicePath
= GetHIDevicePath (DevicePath
);
1468 if (HIDevicePath
== NULL
) {
1472 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1473 if (DevicePathCompare (&Table
[Index
], &HIDevicePath
) == 0) {
1478 FreePool (HIDevicePath
);
1479 if (Table
[Index
] == NULL
) {
1483 MappingInfo
.Hi
= Index
;
1484 MappingInfo
.Mtd
= MTDTypeUnknown
;
1485 MappingInfo
.Digital
= FALSE
;
1487 GetDeviceConsistMappingInfo (&MappingInfo
, DevicePath
);
1489 SetMem (&Str
, sizeof (Str
), 0);
1490 for (Index
= 0; mMTDName
[Index
].MTDType
!= MTDTypeEnd
; Index
++) {
1491 if (MappingInfo
.Mtd
== mMTDName
[Index
].MTDType
) {
1496 if (mMTDName
[Index
].MTDType
!= MTDTypeEnd
) {
1497 CatPrint (&Str
, L
"%s", mMTDName
[Index
].Name
);
1500 CatPrint (&Str
, L
"%d", (UINTN
) MappingInfo
.Hi
);
1501 if (MappingInfo
.Csd
.Str
!= NULL
) {
1502 CatPrint (&Str
, L
"%s", MappingInfo
.Csd
.Str
);
1503 FreePool (MappingInfo
.Csd
.Str
);
1506 if (Str
.Str
!= NULL
) {
1507 CatPrint (&Str
, L
":");
1510 NewSize
= (Str
.Len
+ 1) * sizeof (CHAR16
);
1511 Str
.Str
= ReallocatePool (Str
.Len
, NewSize
, Str
.Str
);
1512 if (Str
.Str
== NULL
) {
1515 Str
.Str
[Str
.Len
] = CHAR_NULL
;
1520 Function to search the list of mappings for the node on the list based on the key.
1522 @param[in] MapKey String Key to search for on the map
1524 @return the node on the list.
1528 ShellCommandFindMapItem (
1529 IN CONST CHAR16
*MapKey
1532 SHELL_MAP_LIST
*MapListItem
;
1534 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1535 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
1536 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
1538 if (gUnicodeCollation
->StriColl(gUnicodeCollation
,MapListItem
->MapName
,(CHAR16
*)MapKey
) == 0) {
1539 return (MapListItem
);