2 Main file for support of shell consist mapping.
4 Copyright (c) 2005 - 2014, 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>
36 } DEVICE_CONSIST_MAPPING_INFO
;
46 VOID (EFIAPI
*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, DEVICE_CONSIST_MAPPING_INFO
*MapInfo
);
47 INTN (EFIAPI
*CompareFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, EFI_DEVICE_PATH_PROTOCOL
*DevPath2
);
48 } DEV_PATH_CONSIST_MAPPING_TABLE
;
52 Concatenates a formatted unicode string to allocated pool.
53 The caller must free the resulting buffer.
55 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.
56 @param Fmt The format string
57 @param ... The data will be printed.
59 @return Allocated buffer with the formatted string printed in it.
60 The caller must free the allocated buffer.
61 The buffer allocation is not packed.
67 IN OUT POOL_PRINT
*Str
,
76 AppendStr
= AllocateZeroPool (0x1000);
77 if (AppendStr
== NULL
) {
83 UnicodeVSPrint (AppendStr
, 0x1000, Fmt
, Args
);
85 if (NULL
== Str
->Str
) {
86 StringSize
= StrSize (AppendStr
);
87 Str
->Str
= AllocateZeroPool (StringSize
);
88 ASSERT (Str
->Str
!= NULL
);
90 StringSize
= StrSize (AppendStr
);
91 StringSize
+= (StrSize (Str
->Str
) - sizeof (UINT16
));
93 Str
->Str
= ReallocatePool (
98 ASSERT (Str
->Str
!= NULL
);
101 StrnCat (Str
->Str
, AppendStr
, StringSize
/sizeof(CHAR16
) - 1 - StrLen(Str
->Str
));
102 Str
->Len
= StringSize
;
104 FreePool (AppendStr
);
108 MTD_NAME mMTDName
[] = {
132 Function to append a 64 bit number / 25 onto the string.
134 @param[in, out] Str The string so append onto.
135 @param[in] Num The number to divide and append.
137 @retval EFI_INVALID_PARAMETER A parameter was NULL.
138 @retval EFI_SUCCESS The appending was successful.
143 IN OUT POOL_PRINT
*Str
,
151 return (EFI_INVALID_PARAMETER
);
154 Result
= DivU64x32Remainder (Num
, 25, &Rem
);
156 AppendCSDNum2 (Str
, Result
);
159 CatPrint (Str
, L
"%c", Rem
+ 'a');
160 return (EFI_SUCCESS
);
164 Function to append a 64 bit number onto the mapping info.
166 @param[in, out] MappingItem The mapping info object to append onto.
167 @param[in] Num The info to append.
169 @retval EFI_INVALID_PARAMETER A parameter was NULL.
170 @retval EFI_SUCCESS The appending was successful.
175 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
179 if (MappingItem
== NULL
) {
180 return EFI_INVALID_PARAMETER
;
183 if (MappingItem
->Digital
) {
184 CatPrint (&MappingItem
->Csd
, L
"%ld", Num
);
186 AppendCSDNum2 (&MappingItem
->Csd
, Num
);
189 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
191 return (EFI_SUCCESS
);
195 Function to append string into the mapping info.
197 @param[in, out] MappingItem The mapping info object to append onto.
198 @param[in] Str The info to append.
200 @retval EFI_INVALID_PARAMETER A parameter was NULL.
201 @retval EFI_SUCCESS The appending was successful.
206 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
212 if (Str
== NULL
|| MappingItem
== NULL
) {
213 return (EFI_INVALID_PARAMETER
);
216 if (MappingItem
->Digital
) {
218 // To aVOID mult-meaning, the mapping is:
219 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
220 // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15
222 for (Index
= Str
; *Index
!= 0; Index
++) {
233 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
);
237 CatPrint (&MappingItem
->Csd
, L
"16");
246 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'a' + '0');
255 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'A' + '0');
260 for (Index
= Str
; *Index
!= 0; Index
++) {
263 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
264 // a b c d e f g h i j k l m n o p
266 if (*Index
>= '0' && *Index
<= '9') {
267 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- '0' + 'a');
268 } else if (*Index
>= 'a' && *Index
<= 'f') {
269 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'a' + 'k');
270 } else if (*Index
>= 'A' && *Index
<= 'F') {
271 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'A' + 'k');
276 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
278 return (EFI_SUCCESS
);
282 Function to append a Guid to the mapping item.
284 @param[in, out] MappingItem The item to append onto.
285 @param[in] Guid The guid to append.
287 @retval EFI_SUCCESS The appending operation was successful.
288 @retval EFI_INVALID_PARAMETER A parameter was NULL.
293 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
299 if (Guid
== NULL
|| MappingItem
== NULL
) {
300 return (EFI_INVALID_PARAMETER
);
310 AppendCSDStr (MappingItem
, Buffer
);
312 return (EFI_SUCCESS
);
316 Function to compare 2 APCI device paths.
318 @param[in] DevicePath1 The first device path to compare.
319 @param[in] DevicePath2 The second device path to compare.
321 @retval 0 The device paths represent the same device.
322 @return Non zero if the devices are different, zero otherwise.
327 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
328 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
331 ACPI_HID_DEVICE_PATH
*Acpi1
;
332 ACPI_HID_DEVICE_PATH
*Acpi2
;
334 if (DevicePath1
== NULL
|| DevicePath2
== NULL
) {
338 Acpi1
= (ACPI_HID_DEVICE_PATH
*) DevicePath1
;
339 Acpi2
= (ACPI_HID_DEVICE_PATH
*) DevicePath2
;
340 if (Acpi1
->HID
> Acpi2
->HID
|| (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
> Acpi2
->UID
)) {
344 if (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
== Acpi2
->UID
) {
352 Function to compare 2 PCI device paths.
354 @param[in] DevicePath1 The first device path to compare.
355 @param[in] DevicePath2 The second device path to compare.
357 @retval 0 The device paths represent the same device.
358 @return Non zero if the devices are different, zero otherwise.
363 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
364 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
367 PCI_DEVICE_PATH
*Pci1
;
368 PCI_DEVICE_PATH
*Pci2
;
370 ASSERT(DevicePath1
!= NULL
);
371 ASSERT(DevicePath2
!= NULL
);
373 Pci1
= (PCI_DEVICE_PATH
*) DevicePath1
;
374 Pci2
= (PCI_DEVICE_PATH
*) DevicePath2
;
375 if (Pci1
->Device
> Pci2
->Device
|| (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
> Pci2
->Function
)) {
379 if (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
== Pci2
->Function
) {
387 Do a comparison on 2 device paths.
389 @param[in] DevicePath1 The first device path.
390 @param[in] DevicePath2 The second device path.
392 @retval 0 The 2 device paths are the same.
393 @retval <0 DevicePath2 is greater than DevicePath1.
394 @retval >0 DevicePath1 is greater than DevicePath2.
398 DevPathCompareDefault (
399 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
400 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
406 ASSERT(DevicePath1
!= NULL
);
407 ASSERT(DevicePath2
!= NULL
);
409 DevPathSize1
= DevicePathNodeLength (DevicePath1
);
410 DevPathSize2
= DevicePathNodeLength (DevicePath2
);
411 if (DevPathSize1
> DevPathSize2
) {
413 } else if (DevPathSize1
< DevPathSize2
) {
416 return CompareMem (DevicePath1
, DevicePath2
, DevPathSize1
);
421 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
423 @param[in] DevicePathNode The node to get info on.
424 @param[in] MappingItem The info item to populate.
428 DevPathSerialHardDrive (
429 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
430 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
433 HARDDRIVE_DEVICE_PATH
*Hd
;
435 ASSERT(DevicePathNode
!= NULL
);
436 ASSERT(MappingItem
!= NULL
);
438 Hd
= (HARDDRIVE_DEVICE_PATH
*) DevicePathNode
;
439 if (MappingItem
->Mtd
== MTDTypeUnknown
) {
440 MappingItem
->Mtd
= MTDTypeHardDisk
;
443 AppendCSDNum (MappingItem
, Hd
->PartitionNumber
);
447 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
449 @param[in] DevicePathNode The node to get info on.
450 @param[in] MappingItem The info item to populate.
455 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
456 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
459 ATAPI_DEVICE_PATH
*Atapi
;
461 ASSERT(DevicePathNode
!= NULL
);
462 ASSERT(MappingItem
!= NULL
);
464 Atapi
= (ATAPI_DEVICE_PATH
*) DevicePathNode
;
465 AppendCSDNum (MappingItem
, (Atapi
->PrimarySecondary
* 2 + Atapi
->SlaveMaster
));
469 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
471 @param[in] DevicePathNode The node to get info on.
472 @param[in] MappingItem The info item to populate.
477 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
478 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
481 CDROM_DEVICE_PATH
*Cd
;
483 ASSERT(DevicePathNode
!= NULL
);
484 ASSERT(MappingItem
!= NULL
);
486 Cd
= (CDROM_DEVICE_PATH
*) DevicePathNode
;
487 MappingItem
->Mtd
= MTDTypeCDRom
;
488 AppendCSDNum (MappingItem
, Cd
->BootEntry
);
492 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
494 @param[in] DevicePathNode The node to get info on.
495 @param[in] MappingItem The info item to populate.
500 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
501 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
504 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
506 ASSERT(DevicePathNode
!= NULL
);
507 ASSERT(MappingItem
!= NULL
);
509 Fibre
= (FIBRECHANNEL_DEVICE_PATH
*) DevicePathNode
;
510 AppendCSDNum (MappingItem
, Fibre
->WWN
);
511 AppendCSDNum (MappingItem
, Fibre
->Lun
);
515 DevicePathNode must be SerialUart type and this will populate the MappingItem.
517 @param[in] DevicePathNode The node to get info on.
518 @param[in] MappingItem The info item to populate.
523 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
524 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
527 UART_DEVICE_PATH
*Uart
;
529 ASSERT(DevicePathNode
!= NULL
);
530 ASSERT(MappingItem
!= NULL
);
532 Uart
= (UART_DEVICE_PATH
*) DevicePathNode
;
533 AppendCSDNum (MappingItem
, Uart
->BaudRate
);
534 AppendCSDNum (MappingItem
, Uart
->DataBits
);
535 AppendCSDNum (MappingItem
, Uart
->Parity
);
536 AppendCSDNum (MappingItem
, Uart
->StopBits
);
540 DevicePathNode must be SerialUSB type and this will populate the MappingItem.
542 @param[in] DevicePathNode The node to get info on.
543 @param[in] MappingItem The info item to populate.
548 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
549 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
552 USB_DEVICE_PATH
*Usb
;
554 ASSERT(DevicePathNode
!= NULL
);
555 ASSERT(MappingItem
!= NULL
);
557 Usb
= (USB_DEVICE_PATH
*) DevicePathNode
;
558 AppendCSDNum (MappingItem
, Usb
->ParentPortNumber
);
559 AppendCSDNum (MappingItem
, Usb
->InterfaceNumber
);
563 DevicePathNode must be SerialVendor type and this will populate the MappingItem.
565 @param[in] DevicePathNode The node to get info on.
566 @param[in] MappingItem The info item to populate.
571 DevPathSerialVendor (
572 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
573 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
576 VENDOR_DEVICE_PATH
*Vendor
;
577 SAS_DEVICE_PATH
*Sas
;
579 if (DevicePathNode
== NULL
|| MappingItem
== NULL
) {
583 Vendor
= (VENDOR_DEVICE_PATH
*) DevicePathNode
;
584 AppendCSDGuid (MappingItem
, &Vendor
->Guid
);
586 if (CompareGuid (&gEfiSasDevicePathGuid
, &Vendor
->Guid
)) {
587 Sas
= (SAS_DEVICE_PATH
*) Vendor
;
588 AppendCSDNum (MappingItem
, Sas
->SasAddress
);
589 AppendCSDNum (MappingItem
, Sas
->Lun
);
590 AppendCSDNum (MappingItem
, Sas
->DeviceTopology
);
591 AppendCSDNum (MappingItem
, Sas
->RelativeTargetPort
);
596 DevicePathNode must be SerialLun type and this will populate the MappingItem.
598 @param[in] DevicePathNode The node to get info on.
599 @param[in] MappingItem The info item to populate.
604 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
605 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
608 DEVICE_LOGICAL_UNIT_DEVICE_PATH
*Lun
;
610 ASSERT(DevicePathNode
!= NULL
);
611 ASSERT(MappingItem
!= NULL
);
613 Lun
= (DEVICE_LOGICAL_UNIT_DEVICE_PATH
*) DevicePathNode
;
614 AppendCSDNum (MappingItem
, Lun
->Lun
);
618 DevicePathNode must be SerialSata type and this will populate the MappingItem.
620 @param[in] DevicePathNode The node to get info on.
621 @param[in] MappingItem The info item to populate.
626 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
627 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
630 SATA_DEVICE_PATH
*Sata
;
632 ASSERT(DevicePathNode
!= NULL
);
633 ASSERT(MappingItem
!= NULL
);
635 Sata
= (SATA_DEVICE_PATH
*) DevicePathNode
;
636 AppendCSDNum (MappingItem
, Sata
->HBAPortNumber
);
637 AppendCSDNum (MappingItem
, Sata
->PortMultiplierPortNumber
);
638 AppendCSDNum (MappingItem
, Sata
->Lun
);
642 DevicePathNode must be SerialSCSI type and this will populate the MappingItem.
644 @param[in] DevicePathNode The node to get info on.
645 @param[in] MappingItem The info item to populate.
650 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
651 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
654 ISCSI_DEVICE_PATH
*IScsi
;
655 UINT8
*IScsiTargetName
;
657 UINTN TargetNameLength
;
660 ASSERT(DevicePathNode
!= NULL
);
661 ASSERT(MappingItem
!= NULL
);
663 if (PcdGetBool(PcdShellDecodeIScsiMapNames
)) {
664 IScsi
= (ISCSI_DEVICE_PATH
*) DevicePathNode
;
665 AppendCSDNum (MappingItem
, IScsi
->NetworkProtocol
);
666 AppendCSDNum (MappingItem
, IScsi
->LoginOption
);
667 AppendCSDNum (MappingItem
, IScsi
->Lun
);
668 AppendCSDNum (MappingItem
, IScsi
->TargetPortalGroupTag
);
669 TargetNameLength
= DevicePathNodeLength (DevicePathNode
) - sizeof (ISCSI_DEVICE_PATH
);
670 if (TargetNameLength
> 0) {
671 TargetName
= AllocateZeroPool ((TargetNameLength
+ 1) * sizeof (CHAR16
));
672 if (TargetName
!= NULL
) {
673 IScsiTargetName
= (UINT8
*) (IScsi
+ 1);
674 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
675 TargetName
[Index
] = (CHAR16
) IScsiTargetName
[Index
];
677 AppendCSDStr (MappingItem
, TargetName
);
678 FreePool (TargetName
);
685 DevicePathNode must be SerialI20 type and this will populate the MappingItem.
687 @param[in] DevicePathNode The node to get info on.
688 @param[in] MappingItem The info item to populate.
693 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
694 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
697 I2O_DEVICE_PATH
*DevicePath_I20
;
699 ASSERT(DevicePathNode
!= NULL
);
700 ASSERT(MappingItem
!= NULL
);
702 DevicePath_I20
= (I2O_DEVICE_PATH
*) DevicePathNode
;
703 AppendCSDNum (MappingItem
, DevicePath_I20
->Tid
);
707 DevicePathNode must be Mac Address type and this will populate the MappingItem.
709 @param[in] DevicePathNode The node to get info on.
710 @param[in] MappingItem The info item to populate.
714 DevPathSerialMacAddr (
715 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
716 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
719 MAC_ADDR_DEVICE_PATH
*Mac
;
725 ASSERT(DevicePathNode
!= NULL
);
726 ASSERT(MappingItem
!= NULL
);
728 Mac
= (MAC_ADDR_DEVICE_PATH
*) DevicePathNode
;
730 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
731 if (Mac
->IfType
== 0x01 || Mac
->IfType
== 0x00) {
735 for (Index
= 0, PBuffer
= Buffer
; Index
< HwAddressSize
; Index
++, PBuffer
+= 2) {
736 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Mac
->MacAddress
.Addr
[Index
]);
739 AppendCSDStr (MappingItem
, Buffer
);
743 DevicePathNode must be InfiniBand type and this will populate the MappingItem.
745 @param[in] DevicePathNode The node to get info on.
746 @param[in] MappingItem The info item to populate.
750 DevPathSerialInfiniBand (
751 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
752 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
755 INFINIBAND_DEVICE_PATH
*InfiniBand
;
760 ASSERT(DevicePathNode
!= NULL
);
761 ASSERT(MappingItem
!= NULL
);
763 InfiniBand
= (INFINIBAND_DEVICE_PATH
*) DevicePathNode
;
764 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
765 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) InfiniBand
->PortGid
[Index
]);
768 AppendCSDStr (MappingItem
, Buffer
);
769 AppendCSDNum (MappingItem
, InfiniBand
->ServiceId
);
770 AppendCSDNum (MappingItem
, InfiniBand
->TargetPortId
);
771 AppendCSDNum (MappingItem
, InfiniBand
->DeviceId
);
775 DevicePathNode must be IPv4 type and this will populate the MappingItem.
777 @param[in] DevicePathNode The node to get info on.
778 @param[in] MappingItem The info item to populate.
783 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
784 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
787 IPv4_DEVICE_PATH
*Ip
;
790 ASSERT(DevicePathNode
!= NULL
);
791 ASSERT(MappingItem
!= NULL
);
793 Ip
= (IPv4_DEVICE_PATH
*) DevicePathNode
;
798 (UINTN
) Ip
->LocalIpAddress
.Addr
[0],
799 (UINTN
) Ip
->LocalIpAddress
.Addr
[1],
800 (UINTN
) Ip
->LocalIpAddress
.Addr
[2],
801 (UINTN
) Ip
->LocalIpAddress
.Addr
[3]
803 AppendCSDStr (MappingItem
, Buffer
);
804 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
809 (UINTN
) Ip
->RemoteIpAddress
.Addr
[0],
810 (UINTN
) Ip
->RemoteIpAddress
.Addr
[1],
811 (UINTN
) Ip
->RemoteIpAddress
.Addr
[2],
812 (UINTN
) Ip
->RemoteIpAddress
.Addr
[3]
814 AppendCSDStr (MappingItem
, Buffer
);
815 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
819 DevicePathNode must be IPv6 type and this will populate the MappingItem.
821 @param[in] DevicePathNode The node to get info on.
822 @param[in] MappingItem The info item to populate.
827 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
828 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
831 IPv6_DEVICE_PATH
*Ip
;
836 ASSERT(DevicePathNode
!= NULL
);
837 ASSERT(MappingItem
!= NULL
);
839 Ip
= (IPv6_DEVICE_PATH
*) DevicePathNode
;
840 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
841 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->LocalIpAddress
.Addr
[Index
]);
844 AppendCSDStr (MappingItem
, Buffer
);
845 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
846 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
847 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->RemoteIpAddress
.Addr
[Index
]);
850 AppendCSDStr (MappingItem
, Buffer
);
851 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
855 DevicePathNode must be SCSI type and this will populate the MappingItem.
857 @param[in] DevicePathNode The node to get info on.
858 @param[in] MappingItem The info item to populate.
863 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
864 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
867 SCSI_DEVICE_PATH
*Scsi
;
869 ASSERT(DevicePathNode
!= NULL
);
870 ASSERT(MappingItem
!= NULL
);
872 Scsi
= (SCSI_DEVICE_PATH
*) DevicePathNode
;
873 AppendCSDNum (MappingItem
, Scsi
->Pun
);
874 AppendCSDNum (MappingItem
, Scsi
->Lun
);
878 DevicePathNode must be 1394 type and this will populate the MappingItem.
880 @param[in] DevicePathNode The node to get info on.
881 @param[in] MappingItem The info item to populate.
886 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
887 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
890 F1394_DEVICE_PATH
*DevicePath_F1394
;
893 ASSERT(DevicePathNode
!= NULL
);
894 ASSERT(MappingItem
!= NULL
);
896 DevicePath_F1394
= (F1394_DEVICE_PATH
*) DevicePathNode
;
897 UnicodeSPrint (Buffer
, 0, L
"%lx", DevicePath_F1394
->Guid
);
898 AppendCSDStr (MappingItem
, Buffer
);
902 If the node is floppy type then populate the MappingItem.
904 @param[in] DevicePathNode The node to get info on.
905 @param[in] MappingItem The info item to populate.
910 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
911 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
914 ACPI_HID_DEVICE_PATH
*Acpi
;
916 ASSERT(DevicePathNode
!= NULL
);
917 ASSERT(MappingItem
!= NULL
);
919 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
920 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
921 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
922 MappingItem
->Mtd
= MTDTypeFloppy
;
923 AppendCSDNum (MappingItem
, Acpi
->UID
);
929 Empty function used for unknown devices.
931 @param[in] DevicePathNode Ignored.
932 @param[in] MappingItem Ignored.
938 DevPathSerialDefault (
939 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
940 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
946 DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable
[] = {
948 HARDWARE_DEVICE_PATH
,
950 DevPathSerialDefault
,
960 MESSAGING_DEVICE_PATH
,
963 DevPathCompareDefault
966 MESSAGING_DEVICE_PATH
,
969 DevPathCompareDefault
972 MESSAGING_DEVICE_PATH
,
975 DevPathCompareDefault
978 MESSAGING_DEVICE_PATH
,
981 DevPathCompareDefault
984 MESSAGING_DEVICE_PATH
,
987 DevPathCompareDefault
990 MESSAGING_DEVICE_PATH
,
993 DevPathCompareDefault
996 MESSAGING_DEVICE_PATH
,
998 DevPathSerialMacAddr
,
999 DevPathCompareDefault
1002 MESSAGING_DEVICE_PATH
,
1005 DevPathCompareDefault
1008 MESSAGING_DEVICE_PATH
,
1011 DevPathCompareDefault
1014 MESSAGING_DEVICE_PATH
,
1016 DevPathSerialInfiniBand
,
1017 DevPathCompareDefault
1020 MESSAGING_DEVICE_PATH
,
1023 DevPathCompareDefault
1026 MESSAGING_DEVICE_PATH
,
1028 DevPathSerialVendor
,
1029 DevPathCompareDefault
1032 MESSAGING_DEVICE_PATH
,
1033 MSG_DEVICE_LOGICAL_UNIT_DP
,
1035 DevPathCompareDefault
1038 MESSAGING_DEVICE_PATH
,
1041 DevPathCompareDefault
1044 MESSAGING_DEVICE_PATH
,
1047 DevPathCompareDefault
1052 DevPathSerialHardDrive
,
1053 DevPathCompareDefault
1059 DevPathCompareDefault
1064 DevPathSerialVendor
,
1065 DevPathCompareDefault
1076 Function to determine if a device path node is Hi or not.
1078 @param[in] DevicePathNode The node to check.
1080 @retval TRUE The node is Hi.
1081 @retval FALSE The node is not Hi.
1085 IsHIDevicePathNode (
1086 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
1089 ACPI_HID_DEVICE_PATH
*Acpi
;
1091 ASSERT(DevicePathNode
!= NULL
);
1093 if (DevicePathNode
->Type
== HARDWARE_DEVICE_PATH
) {
1097 if (DevicePathNode
->Type
== ACPI_DEVICE_PATH
) {
1098 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1099 switch (EISA_ID_TO_NUM (Acpi
->HID
)) {
1114 Function to convert a standard device path structure into a Hi version.
1116 @param[in] DevicePath The device path to convert.
1118 @return the device path portion that is Hi.
1120 EFI_DEVICE_PATH_PROTOCOL
*
1123 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1126 UINTN NonHIDevicePathNodeCount
;
1129 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1130 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1132 ASSERT(DevicePath
!= NULL
);
1134 NonHIDevicePathNodeCount
= 0;
1136 HIDevicePath
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1137 SetDevicePathEndNode (HIDevicePath
);
1139 Node
.DevPath
.Type
= END_DEVICE_PATH_TYPE
;
1140 Node
.DevPath
.SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
1141 Node
.DevPath
.Length
[0] = (UINT8
)sizeof (EFI_DEVICE_PATH_PROTOCOL
);
1142 Node
.DevPath
.Length
[1] = 0;
1144 while (!IsDevicePathEnd (DevicePath
)) {
1145 if (IsHIDevicePathNode (DevicePath
)) {
1146 for (Index
= 0; Index
< NonHIDevicePathNodeCount
; Index
++) {
1147 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, &Node
.DevPath
);
1148 FreePool (HIDevicePath
);
1149 HIDevicePath
= TempDevicePath
;
1152 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, DevicePath
);
1153 FreePool (HIDevicePath
);
1154 HIDevicePath
= TempDevicePath
;
1156 NonHIDevicePathNodeCount
++;
1159 // Next device path node
1161 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1164 return HIDevicePath
;
1168 Function to walk the device path looking for a dumpable node.
1170 @param[in] MappingItem The Item to fill with data.
1171 @param[in] DevicePath The path of the item to get data on.
1173 @return EFI_SUCCESS Always returns success.
1177 GetDeviceConsistMappingInfo (
1178 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1179 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1182 VOID (EFIAPI
*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*, DEVICE_CONSIST_MAPPING_INFO
*);
1186 ASSERT(DevicePath
!= NULL
);
1187 ASSERT(MappingItem
!= NULL
);
1189 SetMem (&MappingItem
->Csd
, sizeof (POOL_PRINT
), 0);
1191 while (!IsDevicePathEnd (DevicePath
)) {
1193 // Find the handler to dump this device path node
1196 for (Index
= 0; DevPathConsistMappingTable
[Index
].SerialFun
!= NULL
; Index
+= 1) {
1198 if (DevicePathType (DevicePath
) == DevPathConsistMappingTable
[Index
].Type
&&
1199 DevicePathSubType (DevicePath
) == DevPathConsistMappingTable
[Index
].SubType
1201 SerialFun
= DevPathConsistMappingTable
[Index
].SerialFun
;
1206 // If not found, use a generic function
1209 SerialFun
= DevPathSerialDefault
;
1212 SerialFun (DevicePath
, MappingItem
);
1215 // Next device path node
1217 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1224 Function to initialize the table for creating consistent map names.
1226 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
1228 @retval EFI_SUCCESS The table was created successfully.
1232 ShellCommandConsistMappingInitialize (
1233 OUT EFI_DEVICE_PATH_PROTOCOL
***Table
1236 EFI_HANDLE
*HandleBuffer
;
1239 EFI_DEVICE_PATH_PROTOCOL
**TempTable
;
1240 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1241 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1245 HandleBuffer
= NULL
;
1247 Status
= gBS
->LocateHandleBuffer (
1254 ASSERT_EFI_ERROR(Status
);
1256 TempTable
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
1257 if (TempTable
== NULL
) {
1258 return EFI_OUT_OF_RESOURCES
;
1261 for (HandleLoop
= 0 ; HandleLoop
< HandleNum
; HandleLoop
++) {
1262 DevicePath
= DevicePathFromHandle (HandleBuffer
[HandleLoop
]);
1263 if (DevicePath
== NULL
) {
1267 HIDevicePath
= GetHIDevicePath (DevicePath
);
1268 if (HIDevicePath
== NULL
) {
1272 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++) {
1273 if (DevicePathCompare (&TempTable
[Index
], &HIDevicePath
) == 0) {
1274 FreePool (HIDevicePath
);
1279 if (TempTable
[Index
] == NULL
) {
1280 TempTable
[Index
] = HIDevicePath
;
1284 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++);
1285 PerformQuickSort(TempTable
, Index
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1288 if (HandleBuffer
!= NULL
) {
1289 FreePool (HandleBuffer
);
1296 Function to uninitialize the table for creating consistent map names.
1298 The parameter must have been received from ShellCommandConsistMappingInitialize.
1300 @param[out] Table The pointer to pointer to DevicePathProtocol object.
1302 @retval EFI_SUCCESS The table was deleted successfully.
1306 ShellCommandConsistMappingUnInitialize (
1307 EFI_DEVICE_PATH_PROTOCOL
**Table
1312 ASSERT(Table
!= NULL
);
1314 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1315 FreePool (Table
[Index
]);
1323 Create a consistent mapped name for the device specified by DevicePath
1326 This must be called after ShellCommandConsistMappingInitialize() and
1327 before ShellCommandConsistMappingUnInitialize() is called.
1329 @param[in] DevicePath The pointer to the dev path for the device.
1330 @param[in] Table The Table of mapping information.
1332 @retval NULL A consistent mapped name could not be created.
1333 @return A pointer to a string allocated from pool with the device name.
1337 ShellCommandConsistMappingGenMappingName (
1338 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1339 IN EFI_DEVICE_PATH_PROTOCOL
**Table
1343 DEVICE_CONSIST_MAPPING_INFO MappingInfo
;
1344 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1348 ASSERT(DevicePath
!= NULL
);
1349 ASSERT(Table
!= NULL
);
1351 HIDevicePath
= GetHIDevicePath (DevicePath
);
1352 if (HIDevicePath
== NULL
) {
1356 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1357 if (DevicePathCompare (&Table
[Index
], &HIDevicePath
) == 0) {
1362 FreePool (HIDevicePath
);
1363 if (Table
[Index
] == NULL
) {
1367 MappingInfo
.Hi
= Index
;
1368 MappingInfo
.Mtd
= MTDTypeUnknown
;
1369 MappingInfo
.Digital
= FALSE
;
1371 GetDeviceConsistMappingInfo (&MappingInfo
, DevicePath
);
1373 SetMem (&Str
, sizeof (Str
), 0);
1374 for (Index
= 0; mMTDName
[Index
].MTDType
!= MTDTypeEnd
; Index
++) {
1375 if (MappingInfo
.Mtd
== mMTDName
[Index
].MTDType
) {
1380 if (mMTDName
[Index
].MTDType
!= MTDTypeEnd
) {
1381 CatPrint (&Str
, L
"%s", mMTDName
[Index
].Name
);
1384 CatPrint (&Str
, L
"%d", (UINTN
) MappingInfo
.Hi
);
1385 if (MappingInfo
.Csd
.Str
!= NULL
) {
1386 CatPrint (&Str
, L
"%s", MappingInfo
.Csd
.Str
);
1387 FreePool (MappingInfo
.Csd
.Str
);
1390 if (Str
.Str
!= NULL
) {
1391 CatPrint (&Str
, L
":");
1394 NewSize
= (Str
.Len
+ 1) * sizeof (CHAR16
);
1395 Str
.Str
= ReallocatePool (Str
.Len
, NewSize
, Str
.Str
);
1396 if (Str
.Str
== NULL
) {
1399 Str
.Str
[Str
.Len
] = CHAR_NULL
;
1404 Function to search the list of mappings for the node on the list based on the key.
1406 @param[in] MapKey String Key to search for on the map
1408 @return the node on the list.
1412 ShellCommandFindMapItem (
1413 IN CONST CHAR16
*MapKey
1416 SHELL_MAP_LIST
*MapListItem
;
1418 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1419 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
1420 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
1422 if (gUnicodeCollation
->StriColl(gUnicodeCollation
,MapListItem
->MapName
,(CHAR16
*)MapKey
) == 0) {
1423 return (MapListItem
);