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>
17 #include <Library/UefiLib.h>
37 } DEVICE_CONSIST_MAPPING_INFO
;
47 VOID (EFIAPI
*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, DEVICE_CONSIST_MAPPING_INFO
*MapInfo
);
48 INTN (EFIAPI
*CompareFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, EFI_DEVICE_PATH_PROTOCOL
*DevPath2
);
49 } DEV_PATH_CONSIST_MAPPING_TABLE
;
53 Concatenates a formatted unicode string to allocated pool.
54 The caller must free the resulting buffer.
56 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.
57 @param Fmt The format string
58 @param ... The data will be printed.
60 @return Allocated buffer with the formatted string printed in it.
61 The caller must free the allocated buffer.
62 The buffer allocation is not packed.
68 IN OUT POOL_PRINT
*Str
,
77 AppendStr
= AllocateZeroPool (0x1000);
78 if (AppendStr
== NULL
) {
84 UnicodeVSPrint (AppendStr
, 0x1000, Fmt
, Args
);
86 if (NULL
== Str
->Str
) {
87 StringSize
= StrSize (AppendStr
);
88 Str
->Str
= AllocateZeroPool (StringSize
);
89 ASSERT (Str
->Str
!= NULL
);
91 StringSize
= StrSize (AppendStr
);
92 StringSize
+= (StrSize (Str
->Str
) - sizeof (UINT16
));
94 Str
->Str
= ReallocatePool (
99 ASSERT (Str
->Str
!= NULL
);
102 StrnCat (Str
->Str
, AppendStr
, StringSize
/sizeof(CHAR16
) - 1 - StrLen(Str
->Str
));
103 Str
->Len
= StringSize
;
105 FreePool (AppendStr
);
109 MTD_NAME mMTDName
[] = {
133 Function to append a 64 bit number / 25 onto the string.
135 @param[in, out] Str The string so append onto.
136 @param[in] Num The number to divide and append.
138 @retval EFI_INVALID_PARAMETER A parameter was NULL.
139 @retval EFI_SUCCESS The appending was successful.
144 IN OUT POOL_PRINT
*Str
,
152 return (EFI_INVALID_PARAMETER
);
155 Result
= DivU64x32Remainder (Num
, 25, &Rem
);
157 AppendCSDNum2 (Str
, Result
);
160 CatPrint (Str
, L
"%c", Rem
+ 'a');
161 return (EFI_SUCCESS
);
165 Function to append a 64 bit number onto the mapping info.
167 @param[in, out] MappingItem The mapping info object to append onto.
168 @param[in] Num The info to append.
170 @retval EFI_INVALID_PARAMETER A parameter was NULL.
171 @retval EFI_SUCCESS The appending was successful.
176 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
180 if (MappingItem
== NULL
) {
181 return EFI_INVALID_PARAMETER
;
184 if (MappingItem
->Digital
) {
185 CatPrint (&MappingItem
->Csd
, L
"%ld", Num
);
187 AppendCSDNum2 (&MappingItem
->Csd
, Num
);
190 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
192 return (EFI_SUCCESS
);
196 Function to append string into the mapping info.
198 @param[in, out] MappingItem The mapping info object to append onto.
199 @param[in] Str The info to append.
201 @retval EFI_INVALID_PARAMETER A parameter was NULL.
202 @retval EFI_SUCCESS The appending was successful.
207 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
213 if (Str
== NULL
|| MappingItem
== NULL
) {
214 return (EFI_INVALID_PARAMETER
);
217 if (MappingItem
->Digital
) {
219 // To aVOID mult-meaning, the mapping is:
220 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
221 // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15
223 for (Index
= Str
; *Index
!= 0; Index
++) {
234 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
);
238 CatPrint (&MappingItem
->Csd
, L
"16");
247 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'a' + '0');
256 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'A' + '0');
261 for (Index
= Str
; *Index
!= 0; Index
++) {
264 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
265 // a b c d e f g h i j k l m n o p
267 if (*Index
>= '0' && *Index
<= '9') {
268 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- '0' + 'a');
269 } else if (*Index
>= 'a' && *Index
<= 'f') {
270 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'a' + 'k');
271 } else if (*Index
>= 'A' && *Index
<= 'F') {
272 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'A' + 'k');
277 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
279 return (EFI_SUCCESS
);
283 Function to append a Guid to the mapping item.
285 @param[in, out] MappingItem The item to append onto.
286 @param[in] Guid The guid to append.
288 @retval EFI_SUCCESS The appending operation was successful.
289 @retval EFI_INVALID_PARAMETER A parameter was NULL.
294 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
300 if (Guid
== NULL
|| MappingItem
== NULL
) {
301 return (EFI_INVALID_PARAMETER
);
311 AppendCSDStr (MappingItem
, Buffer
);
313 return (EFI_SUCCESS
);
317 Function to compare 2 APCI device paths.
319 @param[in] DevicePath1 The first device path to compare.
320 @param[in] DevicePath2 The second device path to compare.
322 @retval 0 The device paths represent the same device.
323 @return Non zero if the devices are different, zero otherwise.
328 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
329 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
332 ACPI_HID_DEVICE_PATH
*Acpi1
;
333 ACPI_HID_DEVICE_PATH
*Acpi2
;
335 if (DevicePath1
== NULL
|| DevicePath2
== NULL
) {
339 Acpi1
= (ACPI_HID_DEVICE_PATH
*) DevicePath1
;
340 Acpi2
= (ACPI_HID_DEVICE_PATH
*) DevicePath2
;
341 if (Acpi1
->HID
> Acpi2
->HID
|| (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
> Acpi2
->UID
)) {
345 if (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
== Acpi2
->UID
) {
353 Function to compare 2 PCI device paths.
355 @param[in] DevicePath1 The first device path to compare.
356 @param[in] DevicePath2 The second device path to compare.
358 @retval 0 The device paths represent the same device.
359 @return Non zero if the devices are different, zero otherwise.
364 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
365 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
368 PCI_DEVICE_PATH
*Pci1
;
369 PCI_DEVICE_PATH
*Pci2
;
371 ASSERT(DevicePath1
!= NULL
);
372 ASSERT(DevicePath2
!= NULL
);
374 Pci1
= (PCI_DEVICE_PATH
*) DevicePath1
;
375 Pci2
= (PCI_DEVICE_PATH
*) DevicePath2
;
376 if (Pci1
->Device
> Pci2
->Device
|| (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
> Pci2
->Function
)) {
380 if (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
== Pci2
->Function
) {
388 Do a comparison on 2 device paths.
390 @param[in] DevicePath1 The first device path.
391 @param[in] DevicePath2 The second device path.
393 @retval 0 The 2 device paths are the same.
394 @retval <0 DevicePath2 is greater than DevicePath1.
395 @retval >0 DevicePath1 is greater than DevicePath2.
399 DevPathCompareDefault (
400 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
401 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
407 ASSERT(DevicePath1
!= NULL
);
408 ASSERT(DevicePath2
!= NULL
);
410 DevPathSize1
= DevicePathNodeLength (DevicePath1
);
411 DevPathSize2
= DevicePathNodeLength (DevicePath2
);
412 if (DevPathSize1
> DevPathSize2
) {
414 } else if (DevPathSize1
< DevPathSize2
) {
417 return CompareMem (DevicePath1
, DevicePath2
, DevPathSize1
);
422 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
424 @param[in] DevicePathNode The node to get info on.
425 @param[in] MappingItem The info item to populate.
429 DevPathSerialHardDrive (
430 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
431 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
434 HARDDRIVE_DEVICE_PATH
*Hd
;
436 ASSERT(DevicePathNode
!= NULL
);
437 ASSERT(MappingItem
!= NULL
);
439 Hd
= (HARDDRIVE_DEVICE_PATH
*) DevicePathNode
;
440 if (MappingItem
->Mtd
== MTDTypeUnknown
) {
441 MappingItem
->Mtd
= MTDTypeHardDisk
;
444 AppendCSDNum (MappingItem
, Hd
->PartitionNumber
);
448 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
450 @param[in] DevicePathNode The node to get info on.
451 @param[in] MappingItem The info item to populate.
456 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
457 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
460 ATAPI_DEVICE_PATH
*Atapi
;
462 ASSERT(DevicePathNode
!= NULL
);
463 ASSERT(MappingItem
!= NULL
);
465 Atapi
= (ATAPI_DEVICE_PATH
*) DevicePathNode
;
466 AppendCSDNum (MappingItem
, (Atapi
->PrimarySecondary
* 2 + Atapi
->SlaveMaster
));
470 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
472 @param[in] DevicePathNode The node to get info on.
473 @param[in] MappingItem The info item to populate.
478 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
479 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
482 CDROM_DEVICE_PATH
*Cd
;
484 ASSERT(DevicePathNode
!= NULL
);
485 ASSERT(MappingItem
!= NULL
);
487 Cd
= (CDROM_DEVICE_PATH
*) DevicePathNode
;
488 MappingItem
->Mtd
= MTDTypeCDRom
;
489 AppendCSDNum (MappingItem
, Cd
->BootEntry
);
493 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
495 @param[in] DevicePathNode The node to get info on.
496 @param[in] MappingItem The info item to populate.
501 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
502 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
505 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
507 ASSERT(DevicePathNode
!= NULL
);
508 ASSERT(MappingItem
!= NULL
);
510 Fibre
= (FIBRECHANNEL_DEVICE_PATH
*) DevicePathNode
;
511 AppendCSDNum (MappingItem
, Fibre
->WWN
);
512 AppendCSDNum (MappingItem
, Fibre
->Lun
);
516 DevicePathNode must be SerialUart 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.
524 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
525 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
528 UART_DEVICE_PATH
*Uart
;
530 ASSERT(DevicePathNode
!= NULL
);
531 ASSERT(MappingItem
!= NULL
);
533 Uart
= (UART_DEVICE_PATH
*) DevicePathNode
;
534 AppendCSDNum (MappingItem
, Uart
->BaudRate
);
535 AppendCSDNum (MappingItem
, Uart
->DataBits
);
536 AppendCSDNum (MappingItem
, Uart
->Parity
);
537 AppendCSDNum (MappingItem
, Uart
->StopBits
);
541 DevicePathNode must be SerialUSB 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.
549 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
550 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
553 USB_DEVICE_PATH
*Usb
;
555 ASSERT(DevicePathNode
!= NULL
);
556 ASSERT(MappingItem
!= NULL
);
558 Usb
= (USB_DEVICE_PATH
*) DevicePathNode
;
559 AppendCSDNum (MappingItem
, Usb
->ParentPortNumber
);
560 AppendCSDNum (MappingItem
, Usb
->InterfaceNumber
);
564 DevicePathNode must be SerialVendor type and this will populate the MappingItem.
566 @param[in] DevicePathNode The node to get info on.
567 @param[in] MappingItem The info item to populate.
572 DevPathSerialVendor (
573 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
574 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
577 VENDOR_DEVICE_PATH
*Vendor
;
578 SAS_DEVICE_PATH
*Sas
;
579 UINTN TargetNameLength
;
583 if (DevicePathNode
== NULL
|| MappingItem
== NULL
) {
587 Vendor
= (VENDOR_DEVICE_PATH
*) DevicePathNode
;
588 AppendCSDGuid (MappingItem
, &Vendor
->Guid
);
590 if (CompareGuid (&gEfiSasDevicePathGuid
, &Vendor
->Guid
)) {
591 Sas
= (SAS_DEVICE_PATH
*) Vendor
;
592 AppendCSDNum (MappingItem
, Sas
->SasAddress
);
593 AppendCSDNum (MappingItem
, Sas
->Lun
);
594 AppendCSDNum (MappingItem
, Sas
->DeviceTopology
);
595 AppendCSDNum (MappingItem
, Sas
->RelativeTargetPort
);
597 TargetNameLength
= MIN(DevicePathNodeLength (DevicePathNode
) - sizeof (VENDOR_DEVICE_PATH
), PcdGet32(PcdShellVendorExtendedDecode
));
598 if (TargetNameLength
!= 0) {
600 // String is 2 chars per data byte, plus NULL terminator
602 Buffer
= AllocateZeroPool (((TargetNameLength
* 2) + 1) * sizeof(CHAR16
));
603 ASSERT(Buffer
!= NULL
);
604 if (Buffer
== NULL
) {
609 // Build the string data
611 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
612 Buffer
= CatSPrint (Buffer
, L
"%02x", *((UINT8
*)Vendor
+ sizeof (VENDOR_DEVICE_PATH
) + Index
));
616 // Append the new data block
618 AppendCSDStr (MappingItem
, Buffer
);
626 DevicePathNode must be SerialLun type and this will populate the MappingItem.
628 @param[in] DevicePathNode The node to get info on.
629 @param[in] MappingItem The info item to populate.
634 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
635 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
638 DEVICE_LOGICAL_UNIT_DEVICE_PATH
*Lun
;
640 ASSERT(DevicePathNode
!= NULL
);
641 ASSERT(MappingItem
!= NULL
);
643 Lun
= (DEVICE_LOGICAL_UNIT_DEVICE_PATH
*) DevicePathNode
;
644 AppendCSDNum (MappingItem
, Lun
->Lun
);
648 DevicePathNode must be SerialSata type and this will populate the MappingItem.
650 @param[in] DevicePathNode The node to get info on.
651 @param[in] MappingItem The info item to populate.
656 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
657 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
660 SATA_DEVICE_PATH
*Sata
;
662 ASSERT(DevicePathNode
!= NULL
);
663 ASSERT(MappingItem
!= NULL
);
665 Sata
= (SATA_DEVICE_PATH
*) DevicePathNode
;
666 AppendCSDNum (MappingItem
, Sata
->HBAPortNumber
);
667 AppendCSDNum (MappingItem
, Sata
->PortMultiplierPortNumber
);
668 AppendCSDNum (MappingItem
, Sata
->Lun
);
672 DevicePathNode must be SerialSCSI type and this will populate the MappingItem.
674 @param[in] DevicePathNode The node to get info on.
675 @param[in] MappingItem The info item to populate.
680 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
681 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
684 ISCSI_DEVICE_PATH
*IScsi
;
685 UINT8
*IScsiTargetName
;
687 UINTN TargetNameLength
;
690 ASSERT(DevicePathNode
!= NULL
);
691 ASSERT(MappingItem
!= NULL
);
693 if (PcdGetBool(PcdShellDecodeIScsiMapNames
)) {
694 IScsi
= (ISCSI_DEVICE_PATH
*) DevicePathNode
;
695 AppendCSDNum (MappingItem
, IScsi
->NetworkProtocol
);
696 AppendCSDNum (MappingItem
, IScsi
->LoginOption
);
697 AppendCSDNum (MappingItem
, IScsi
->Lun
);
698 AppendCSDNum (MappingItem
, IScsi
->TargetPortalGroupTag
);
699 TargetNameLength
= DevicePathNodeLength (DevicePathNode
) - sizeof (ISCSI_DEVICE_PATH
);
700 if (TargetNameLength
> 0) {
701 TargetName
= AllocateZeroPool ((TargetNameLength
+ 1) * sizeof (CHAR16
));
702 if (TargetName
!= NULL
) {
703 IScsiTargetName
= (UINT8
*) (IScsi
+ 1);
704 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
705 TargetName
[Index
] = (CHAR16
) IScsiTargetName
[Index
];
707 AppendCSDStr (MappingItem
, TargetName
);
708 FreePool (TargetName
);
715 DevicePathNode must be SerialI20 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.
723 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
724 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
727 I2O_DEVICE_PATH
*DevicePath_I20
;
729 ASSERT(DevicePathNode
!= NULL
);
730 ASSERT(MappingItem
!= NULL
);
732 DevicePath_I20
= (I2O_DEVICE_PATH
*) DevicePathNode
;
733 AppendCSDNum (MappingItem
, DevicePath_I20
->Tid
);
737 DevicePathNode must be Mac Address type and this will populate the MappingItem.
739 @param[in] DevicePathNode The node to get info on.
740 @param[in] MappingItem The info item to populate.
744 DevPathSerialMacAddr (
745 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
746 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
749 MAC_ADDR_DEVICE_PATH
*Mac
;
755 ASSERT(DevicePathNode
!= NULL
);
756 ASSERT(MappingItem
!= NULL
);
758 Mac
= (MAC_ADDR_DEVICE_PATH
*) DevicePathNode
;
760 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
761 if (Mac
->IfType
== 0x01 || Mac
->IfType
== 0x00) {
765 for (Index
= 0, PBuffer
= Buffer
; Index
< HwAddressSize
; Index
++, PBuffer
+= 2) {
766 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Mac
->MacAddress
.Addr
[Index
]);
769 AppendCSDStr (MappingItem
, Buffer
);
773 DevicePathNode must be InfiniBand type and this will populate the MappingItem.
775 @param[in] DevicePathNode The node to get info on.
776 @param[in] MappingItem The info item to populate.
780 DevPathSerialInfiniBand (
781 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
782 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
785 INFINIBAND_DEVICE_PATH
*InfiniBand
;
790 ASSERT(DevicePathNode
!= NULL
);
791 ASSERT(MappingItem
!= NULL
);
793 InfiniBand
= (INFINIBAND_DEVICE_PATH
*) DevicePathNode
;
794 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
795 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) InfiniBand
->PortGid
[Index
]);
798 AppendCSDStr (MappingItem
, Buffer
);
799 AppendCSDNum (MappingItem
, InfiniBand
->ServiceId
);
800 AppendCSDNum (MappingItem
, InfiniBand
->TargetPortId
);
801 AppendCSDNum (MappingItem
, InfiniBand
->DeviceId
);
805 DevicePathNode must be IPv4 type and this will populate the MappingItem.
807 @param[in] DevicePathNode The node to get info on.
808 @param[in] MappingItem The info item to populate.
813 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
814 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
817 IPv4_DEVICE_PATH
*Ip
;
820 ASSERT(DevicePathNode
!= NULL
);
821 ASSERT(MappingItem
!= NULL
);
823 Ip
= (IPv4_DEVICE_PATH
*) DevicePathNode
;
828 (UINTN
) Ip
->LocalIpAddress
.Addr
[0],
829 (UINTN
) Ip
->LocalIpAddress
.Addr
[1],
830 (UINTN
) Ip
->LocalIpAddress
.Addr
[2],
831 (UINTN
) Ip
->LocalIpAddress
.Addr
[3]
833 AppendCSDStr (MappingItem
, Buffer
);
834 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
839 (UINTN
) Ip
->RemoteIpAddress
.Addr
[0],
840 (UINTN
) Ip
->RemoteIpAddress
.Addr
[1],
841 (UINTN
) Ip
->RemoteIpAddress
.Addr
[2],
842 (UINTN
) Ip
->RemoteIpAddress
.Addr
[3]
844 AppendCSDStr (MappingItem
, Buffer
);
845 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
849 DevicePathNode must be IPv6 type and this will populate the MappingItem.
851 @param[in] DevicePathNode The node to get info on.
852 @param[in] MappingItem The info item to populate.
857 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
858 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
861 IPv6_DEVICE_PATH
*Ip
;
866 ASSERT(DevicePathNode
!= NULL
);
867 ASSERT(MappingItem
!= NULL
);
869 Ip
= (IPv6_DEVICE_PATH
*) DevicePathNode
;
870 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
871 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->LocalIpAddress
.Addr
[Index
]);
874 AppendCSDStr (MappingItem
, Buffer
);
875 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
876 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
877 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->RemoteIpAddress
.Addr
[Index
]);
880 AppendCSDStr (MappingItem
, Buffer
);
881 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
885 DevicePathNode must be SCSI type and this will populate the MappingItem.
887 @param[in] DevicePathNode The node to get info on.
888 @param[in] MappingItem The info item to populate.
893 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
894 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
897 SCSI_DEVICE_PATH
*Scsi
;
899 ASSERT(DevicePathNode
!= NULL
);
900 ASSERT(MappingItem
!= NULL
);
902 Scsi
= (SCSI_DEVICE_PATH
*) DevicePathNode
;
903 AppendCSDNum (MappingItem
, Scsi
->Pun
);
904 AppendCSDNum (MappingItem
, Scsi
->Lun
);
908 DevicePathNode must be 1394 type and this will populate the MappingItem.
910 @param[in] DevicePathNode The node to get info on.
911 @param[in] MappingItem The info item to populate.
916 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
917 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
920 F1394_DEVICE_PATH
*DevicePath_F1394
;
923 ASSERT(DevicePathNode
!= NULL
);
924 ASSERT(MappingItem
!= NULL
);
926 DevicePath_F1394
= (F1394_DEVICE_PATH
*) DevicePathNode
;
927 UnicodeSPrint (Buffer
, 0, L
"%lx", DevicePath_F1394
->Guid
);
928 AppendCSDStr (MappingItem
, Buffer
);
932 If the node is floppy type then populate the MappingItem.
934 @param[in] DevicePathNode The node to get info on.
935 @param[in] MappingItem The info item to populate.
940 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
941 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
944 ACPI_HID_DEVICE_PATH
*Acpi
;
946 ASSERT(DevicePathNode
!= NULL
);
947 ASSERT(MappingItem
!= NULL
);
949 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
950 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
951 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
952 MappingItem
->Mtd
= MTDTypeFloppy
;
953 AppendCSDNum (MappingItem
, Acpi
->UID
);
959 Empty function used for unknown devices.
961 @param[in] DevicePathNode Ignored.
962 @param[in] MappingItem Ignored.
968 DevPathSerialDefault (
969 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
970 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
976 DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable
[] = {
978 HARDWARE_DEVICE_PATH
,
980 DevPathSerialDefault
,
990 MESSAGING_DEVICE_PATH
,
993 DevPathCompareDefault
996 MESSAGING_DEVICE_PATH
,
999 DevPathCompareDefault
1002 MESSAGING_DEVICE_PATH
,
1003 MSG_FIBRECHANNEL_DP
,
1005 DevPathCompareDefault
1008 MESSAGING_DEVICE_PATH
,
1011 DevPathCompareDefault
1014 MESSAGING_DEVICE_PATH
,
1017 DevPathCompareDefault
1020 MESSAGING_DEVICE_PATH
,
1023 DevPathCompareDefault
1026 MESSAGING_DEVICE_PATH
,
1028 DevPathSerialMacAddr
,
1029 DevPathCompareDefault
1032 MESSAGING_DEVICE_PATH
,
1035 DevPathCompareDefault
1038 MESSAGING_DEVICE_PATH
,
1041 DevPathCompareDefault
1044 MESSAGING_DEVICE_PATH
,
1046 DevPathSerialInfiniBand
,
1047 DevPathCompareDefault
1050 MESSAGING_DEVICE_PATH
,
1053 DevPathCompareDefault
1056 MESSAGING_DEVICE_PATH
,
1058 DevPathSerialVendor
,
1059 DevPathCompareDefault
1062 MESSAGING_DEVICE_PATH
,
1063 MSG_DEVICE_LOGICAL_UNIT_DP
,
1065 DevPathCompareDefault
1068 MESSAGING_DEVICE_PATH
,
1071 DevPathCompareDefault
1074 MESSAGING_DEVICE_PATH
,
1077 DevPathCompareDefault
1082 DevPathSerialHardDrive
,
1083 DevPathCompareDefault
1089 DevPathCompareDefault
1094 DevPathSerialVendor
,
1095 DevPathCompareDefault
1106 Function to determine if a device path node is Hi or not.
1108 @param[in] DevicePathNode The node to check.
1110 @retval TRUE The node is Hi.
1111 @retval FALSE The node is not Hi.
1115 IsHIDevicePathNode (
1116 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
1119 ACPI_HID_DEVICE_PATH
*Acpi
;
1121 ASSERT(DevicePathNode
!= NULL
);
1123 if (DevicePathNode
->Type
== HARDWARE_DEVICE_PATH
) {
1127 if (DevicePathNode
->Type
== ACPI_DEVICE_PATH
) {
1128 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1129 switch (EISA_ID_TO_NUM (Acpi
->HID
)) {
1144 Function to convert a standard device path structure into a Hi version.
1146 @param[in] DevicePath The device path to convert.
1148 @return the device path portion that is Hi.
1150 EFI_DEVICE_PATH_PROTOCOL
*
1153 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1156 UINTN NonHIDevicePathNodeCount
;
1159 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1160 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1162 ASSERT(DevicePath
!= NULL
);
1164 NonHIDevicePathNodeCount
= 0;
1166 HIDevicePath
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1167 SetDevicePathEndNode (HIDevicePath
);
1169 Node
.DevPath
.Type
= END_DEVICE_PATH_TYPE
;
1170 Node
.DevPath
.SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
1171 Node
.DevPath
.Length
[0] = (UINT8
)sizeof (EFI_DEVICE_PATH_PROTOCOL
);
1172 Node
.DevPath
.Length
[1] = 0;
1174 while (!IsDevicePathEnd (DevicePath
)) {
1175 if (IsHIDevicePathNode (DevicePath
)) {
1176 for (Index
= 0; Index
< NonHIDevicePathNodeCount
; Index
++) {
1177 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, &Node
.DevPath
);
1178 FreePool (HIDevicePath
);
1179 HIDevicePath
= TempDevicePath
;
1182 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, DevicePath
);
1183 FreePool (HIDevicePath
);
1184 HIDevicePath
= TempDevicePath
;
1186 NonHIDevicePathNodeCount
++;
1189 // Next device path node
1191 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1194 return HIDevicePath
;
1198 Function to walk the device path looking for a dumpable node.
1200 @param[in] MappingItem The Item to fill with data.
1201 @param[in] DevicePath The path of the item to get data on.
1203 @return EFI_SUCCESS Always returns success.
1207 GetDeviceConsistMappingInfo (
1208 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1209 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1212 VOID (EFIAPI
*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*, DEVICE_CONSIST_MAPPING_INFO
*);
1216 ASSERT(DevicePath
!= NULL
);
1217 ASSERT(MappingItem
!= NULL
);
1219 SetMem (&MappingItem
->Csd
, sizeof (POOL_PRINT
), 0);
1221 while (!IsDevicePathEnd (DevicePath
)) {
1223 // Find the handler to dump this device path node
1226 for (Index
= 0; DevPathConsistMappingTable
[Index
].SerialFun
!= NULL
; Index
+= 1) {
1228 if (DevicePathType (DevicePath
) == DevPathConsistMappingTable
[Index
].Type
&&
1229 DevicePathSubType (DevicePath
) == DevPathConsistMappingTable
[Index
].SubType
1231 SerialFun
= DevPathConsistMappingTable
[Index
].SerialFun
;
1236 // If not found, use a generic function
1239 SerialFun
= DevPathSerialDefault
;
1242 SerialFun (DevicePath
, MappingItem
);
1245 // Next device path node
1247 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1254 Function to initialize the table for creating consistent map names.
1256 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
1258 @retval EFI_SUCCESS The table was created successfully.
1262 ShellCommandConsistMappingInitialize (
1263 OUT EFI_DEVICE_PATH_PROTOCOL
***Table
1266 EFI_HANDLE
*HandleBuffer
;
1269 EFI_DEVICE_PATH_PROTOCOL
**TempTable
;
1270 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1271 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1275 HandleBuffer
= NULL
;
1277 Status
= gBS
->LocateHandleBuffer (
1284 ASSERT_EFI_ERROR(Status
);
1286 TempTable
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
1287 if (TempTable
== NULL
) {
1288 return EFI_OUT_OF_RESOURCES
;
1291 for (HandleLoop
= 0 ; HandleLoop
< HandleNum
; HandleLoop
++) {
1292 DevicePath
= DevicePathFromHandle (HandleBuffer
[HandleLoop
]);
1293 if (DevicePath
== NULL
) {
1297 HIDevicePath
= GetHIDevicePath (DevicePath
);
1298 if (HIDevicePath
== NULL
) {
1302 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++) {
1303 if (DevicePathCompare (&TempTable
[Index
], &HIDevicePath
) == 0) {
1304 FreePool (HIDevicePath
);
1309 if (TempTable
[Index
] == NULL
) {
1310 TempTable
[Index
] = HIDevicePath
;
1314 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++);
1315 PerformQuickSort(TempTable
, Index
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1318 if (HandleBuffer
!= NULL
) {
1319 FreePool (HandleBuffer
);
1326 Function to uninitialize the table for creating consistent map names.
1328 The parameter must have been received from ShellCommandConsistMappingInitialize.
1330 @param[out] Table The pointer to pointer to DevicePathProtocol object.
1332 @retval EFI_SUCCESS The table was deleted successfully.
1336 ShellCommandConsistMappingUnInitialize (
1337 EFI_DEVICE_PATH_PROTOCOL
**Table
1342 ASSERT(Table
!= NULL
);
1344 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1345 FreePool (Table
[Index
]);
1353 Create a consistent mapped name for the device specified by DevicePath
1356 This must be called after ShellCommandConsistMappingInitialize() and
1357 before ShellCommandConsistMappingUnInitialize() is called.
1359 @param[in] DevicePath The pointer to the dev path for the device.
1360 @param[in] Table The Table of mapping information.
1362 @retval NULL A consistent mapped name could not be created.
1363 @return A pointer to a string allocated from pool with the device name.
1367 ShellCommandConsistMappingGenMappingName (
1368 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1369 IN EFI_DEVICE_PATH_PROTOCOL
**Table
1373 DEVICE_CONSIST_MAPPING_INFO MappingInfo
;
1374 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1378 ASSERT(DevicePath
!= NULL
);
1379 ASSERT(Table
!= NULL
);
1381 HIDevicePath
= GetHIDevicePath (DevicePath
);
1382 if (HIDevicePath
== NULL
) {
1386 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1387 if (DevicePathCompare (&Table
[Index
], &HIDevicePath
) == 0) {
1392 FreePool (HIDevicePath
);
1393 if (Table
[Index
] == NULL
) {
1397 MappingInfo
.Hi
= Index
;
1398 MappingInfo
.Mtd
= MTDTypeUnknown
;
1399 MappingInfo
.Digital
= FALSE
;
1401 GetDeviceConsistMappingInfo (&MappingInfo
, DevicePath
);
1403 SetMem (&Str
, sizeof (Str
), 0);
1404 for (Index
= 0; mMTDName
[Index
].MTDType
!= MTDTypeEnd
; Index
++) {
1405 if (MappingInfo
.Mtd
== mMTDName
[Index
].MTDType
) {
1410 if (mMTDName
[Index
].MTDType
!= MTDTypeEnd
) {
1411 CatPrint (&Str
, L
"%s", mMTDName
[Index
].Name
);
1414 CatPrint (&Str
, L
"%d", (UINTN
) MappingInfo
.Hi
);
1415 if (MappingInfo
.Csd
.Str
!= NULL
) {
1416 CatPrint (&Str
, L
"%s", MappingInfo
.Csd
.Str
);
1417 FreePool (MappingInfo
.Csd
.Str
);
1420 if (Str
.Str
!= NULL
) {
1421 CatPrint (&Str
, L
":");
1424 NewSize
= (Str
.Len
+ 1) * sizeof (CHAR16
);
1425 Str
.Str
= ReallocatePool (Str
.Len
, NewSize
, Str
.Str
);
1426 if (Str
.Str
== NULL
) {
1429 Str
.Str
[Str
.Len
] = CHAR_NULL
;
1434 Function to search the list of mappings for the node on the list based on the key.
1436 @param[in] MapKey String Key to search for on the map
1438 @return the node on the list.
1442 ShellCommandFindMapItem (
1443 IN CONST CHAR16
*MapKey
1446 SHELL_MAP_LIST
*MapListItem
;
1448 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1449 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
1450 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
1452 if (gUnicodeCollation
->StriColl(gUnicodeCollation
,MapListItem
->MapName
,(CHAR16
*)MapKey
) == 0) {
1453 return (MapListItem
);