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>
18 #include <Protocol/UsbIo.h>
38 } DEVICE_CONSIST_MAPPING_INFO
;
45 typedef VOID (EFIAPI
*SerialDecodeFucntion
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, DEVICE_CONSIST_MAPPING_INFO
*MapInfo
,EFI_DEVICE_PATH_PROTOCOL
*);
50 SerialDecodeFucntion SerialFun
;
51 INTN (EFIAPI
*CompareFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, EFI_DEVICE_PATH_PROTOCOL
*DevPath2
);
52 } DEV_PATH_CONSIST_MAPPING_TABLE
;
56 Concatenates a formatted unicode string to allocated pool.
57 The caller must free the resulting buffer.
59 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.
60 @param Fmt The format string
61 @param ... The data will be printed.
63 @return Allocated buffer with the formatted string printed in it.
64 The caller must free the allocated buffer.
65 The buffer allocation is not packed.
71 IN OUT POOL_PRINT
*Str
,
80 AppendStr
= AllocateZeroPool (0x1000);
81 if (AppendStr
== NULL
) {
87 UnicodeVSPrint (AppendStr
, 0x1000, Fmt
, Args
);
89 if (NULL
== Str
->Str
) {
90 StringSize
= StrSize (AppendStr
);
91 Str
->Str
= AllocateZeroPool (StringSize
);
92 ASSERT (Str
->Str
!= NULL
);
94 StringSize
= StrSize (AppendStr
);
95 StringSize
+= (StrSize (Str
->Str
) - sizeof (UINT16
));
97 Str
->Str
= ReallocatePool (
102 ASSERT (Str
->Str
!= NULL
);
105 StrnCat (Str
->Str
, AppendStr
, StringSize
/sizeof(CHAR16
) - 1 - StrLen(Str
->Str
));
106 Str
->Len
= StringSize
;
108 FreePool (AppendStr
);
112 MTD_NAME mMTDName
[] = {
136 Function to append a 64 bit number / 25 onto the string.
138 @param[in, out] Str The string so append onto.
139 @param[in] Num The number to divide and append.
141 @retval EFI_INVALID_PARAMETER A parameter was NULL.
142 @retval EFI_SUCCESS The appending was successful.
147 IN OUT POOL_PRINT
*Str
,
155 return (EFI_INVALID_PARAMETER
);
158 Result
= DivU64x32Remainder (Num
, 25, &Rem
);
160 AppendCSDNum2 (Str
, Result
);
163 CatPrint (Str
, L
"%c", Rem
+ 'a');
164 return (EFI_SUCCESS
);
168 Function to append a 64 bit number onto the mapping info.
170 @param[in, out] MappingItem The mapping info object to append onto.
171 @param[in] Num The info to append.
173 @retval EFI_INVALID_PARAMETER A parameter was NULL.
174 @retval EFI_SUCCESS The appending was successful.
179 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
183 if (MappingItem
== NULL
) {
184 return EFI_INVALID_PARAMETER
;
187 if (MappingItem
->Digital
) {
188 CatPrint (&MappingItem
->Csd
, L
"%ld", Num
);
190 AppendCSDNum2 (&MappingItem
->Csd
, Num
);
193 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
195 return (EFI_SUCCESS
);
199 Function to append string into the mapping info.
201 @param[in, out] MappingItem The mapping info object to append onto.
202 @param[in] Str The info to append.
204 @retval EFI_INVALID_PARAMETER A parameter was NULL.
205 @retval EFI_SUCCESS The appending was successful.
210 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
216 if (Str
== NULL
|| MappingItem
== NULL
) {
217 return (EFI_INVALID_PARAMETER
);
220 if (MappingItem
->Digital
) {
222 // To aVOID mult-meaning, the mapping is:
223 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
224 // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15
226 for (Index
= Str
; *Index
!= 0; Index
++) {
237 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
);
241 CatPrint (&MappingItem
->Csd
, L
"16");
250 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'a' + '0');
259 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'A' + '0');
264 for (Index
= Str
; *Index
!= 0; Index
++) {
267 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
268 // a b c d e f g h i j k l m n o p
270 if (*Index
>= '0' && *Index
<= '9') {
271 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- '0' + 'a');
272 } else if (*Index
>= 'a' && *Index
<= 'f') {
273 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'a' + 'k');
274 } else if (*Index
>= 'A' && *Index
<= 'F') {
275 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'A' + 'k');
280 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
282 return (EFI_SUCCESS
);
286 Function to append a Guid to the mapping item.
288 @param[in, out] MappingItem The item to append onto.
289 @param[in] Guid The guid to append.
291 @retval EFI_SUCCESS The appending operation was successful.
292 @retval EFI_INVALID_PARAMETER A parameter was NULL.
297 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
303 if (Guid
== NULL
|| MappingItem
== NULL
) {
304 return (EFI_INVALID_PARAMETER
);
314 AppendCSDStr (MappingItem
, Buffer
);
316 return (EFI_SUCCESS
);
320 Function to compare 2 APCI device paths.
322 @param[in] DevicePath1 The first device path to compare.
323 @param[in] DevicePath2 The second device path to compare.
325 @retval 0 The device paths represent the same device.
326 @return Non zero if the devices are different, zero otherwise.
331 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
332 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
335 ACPI_HID_DEVICE_PATH
*Acpi1
;
336 ACPI_HID_DEVICE_PATH
*Acpi2
;
338 if (DevicePath1
== NULL
|| DevicePath2
== NULL
) {
342 Acpi1
= (ACPI_HID_DEVICE_PATH
*) DevicePath1
;
343 Acpi2
= (ACPI_HID_DEVICE_PATH
*) DevicePath2
;
344 if (Acpi1
->HID
> Acpi2
->HID
|| (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
> Acpi2
->UID
)) {
348 if (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
== Acpi2
->UID
) {
356 Function to compare 2 PCI device paths.
358 @param[in] DevicePath1 The first device path to compare.
359 @param[in] DevicePath2 The second device path to compare.
361 @retval 0 The device paths represent the same device.
362 @return Non zero if the devices are different, zero otherwise.
367 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
368 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
371 PCI_DEVICE_PATH
*Pci1
;
372 PCI_DEVICE_PATH
*Pci2
;
374 ASSERT(DevicePath1
!= NULL
);
375 ASSERT(DevicePath2
!= NULL
);
377 Pci1
= (PCI_DEVICE_PATH
*) DevicePath1
;
378 Pci2
= (PCI_DEVICE_PATH
*) DevicePath2
;
379 if (Pci1
->Device
> Pci2
->Device
|| (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
> Pci2
->Function
)) {
383 if (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
== Pci2
->Function
) {
391 Do a comparison on 2 device paths.
393 @param[in] DevicePath1 The first device path.
394 @param[in] DevicePath2 The second device path.
396 @retval 0 The 2 device paths are the same.
397 @retval <0 DevicePath2 is greater than DevicePath1.
398 @retval >0 DevicePath1 is greater than DevicePath2.
402 DevPathCompareDefault (
403 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
404 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
410 ASSERT(DevicePath1
!= NULL
);
411 ASSERT(DevicePath2
!= NULL
);
413 DevPathSize1
= DevicePathNodeLength (DevicePath1
);
414 DevPathSize2
= DevicePathNodeLength (DevicePath2
);
415 if (DevPathSize1
> DevPathSize2
) {
417 } else if (DevPathSize1
< DevPathSize2
) {
420 return CompareMem (DevicePath1
, DevicePath2
, DevPathSize1
);
425 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
427 @param[in] DevicePathNode The node to get info on.
428 @param[in] MappingItem The info item to populate.
432 DevPathSerialHardDrive (
433 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
434 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
435 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
438 HARDDRIVE_DEVICE_PATH
*Hd
;
440 ASSERT(DevicePathNode
!= NULL
);
441 ASSERT(MappingItem
!= NULL
);
443 Hd
= (HARDDRIVE_DEVICE_PATH
*) DevicePathNode
;
444 if (MappingItem
->Mtd
== MTDTypeUnknown
) {
445 MappingItem
->Mtd
= MTDTypeHardDisk
;
448 AppendCSDNum (MappingItem
, Hd
->PartitionNumber
);
452 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
454 @param[in] DevicePathNode The node to get info on.
455 @param[in] MappingItem The info item to populate.
460 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
461 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
462 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
465 ATAPI_DEVICE_PATH
*Atapi
;
467 ASSERT(DevicePathNode
!= NULL
);
468 ASSERT(MappingItem
!= NULL
);
470 Atapi
= (ATAPI_DEVICE_PATH
*) DevicePathNode
;
471 AppendCSDNum (MappingItem
, (Atapi
->PrimarySecondary
* 2 + Atapi
->SlaveMaster
));
475 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
477 @param[in] DevicePathNode The node to get info on.
478 @param[in] MappingItem The info item to populate.
483 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
484 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
485 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
488 CDROM_DEVICE_PATH
*Cd
;
490 ASSERT(DevicePathNode
!= NULL
);
491 ASSERT(MappingItem
!= NULL
);
493 Cd
= (CDROM_DEVICE_PATH
*) DevicePathNode
;
494 MappingItem
->Mtd
= MTDTypeCDRom
;
495 AppendCSDNum (MappingItem
, Cd
->BootEntry
);
499 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
501 @param[in] DevicePathNode The node to get info on.
502 @param[in] MappingItem The info item to populate.
507 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
508 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
509 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
512 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
514 ASSERT(DevicePathNode
!= NULL
);
515 ASSERT(MappingItem
!= NULL
);
517 Fibre
= (FIBRECHANNEL_DEVICE_PATH
*) DevicePathNode
;
518 AppendCSDNum (MappingItem
, Fibre
->WWN
);
519 AppendCSDNum (MappingItem
, Fibre
->Lun
);
523 DevicePathNode must be SerialUart type and this will populate the MappingItem.
525 @param[in] DevicePathNode The node to get info on.
526 @param[in] MappingItem The info item to populate.
531 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
532 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
533 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
536 UART_DEVICE_PATH
*Uart
;
538 ASSERT(DevicePathNode
!= NULL
);
539 ASSERT(MappingItem
!= NULL
);
541 Uart
= (UART_DEVICE_PATH
*) DevicePathNode
;
542 AppendCSDNum (MappingItem
, Uart
->BaudRate
);
543 AppendCSDNum (MappingItem
, Uart
->DataBits
);
544 AppendCSDNum (MappingItem
, Uart
->Parity
);
545 AppendCSDNum (MappingItem
, Uart
->StopBits
);
549 DevicePathNode must be SerialUSB type and this will populate the MappingItem.
551 @param[in] DevicePathNode The node to get info on.
552 @param[in] MappingItem The info item to populate.
557 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
558 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
559 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
562 USB_DEVICE_PATH
*Usb
;
563 EFI_USB_IO_PROTOCOL
*UsbIo
;
564 EFI_HANDLE TempHandle
;
566 USB_INTERFACE_DESCRIPTOR InterfaceDesc
;
569 ASSERT(DevicePathNode
!= NULL
);
570 ASSERT(MappingItem
!= NULL
);
572 Usb
= (USB_DEVICE_PATH
*) DevicePathNode
;
573 AppendCSDNum (MappingItem
, Usb
->ParentPortNumber
);
574 AppendCSDNum (MappingItem
, Usb
->InterfaceNumber
);
576 if (PcdGetBool(PcdUsbExtendedDecode
)) {
577 Status
= gBS
->LocateDevicePath( &gEfiUsbIoProtocolGuid
, &DevicePath
, &TempHandle
);
579 if (!EFI_ERROR(Status
)) {
580 Status
= gBS
->OpenProtocol(TempHandle
, &gEfiUsbIoProtocolGuid
, (VOID
**)&UsbIo
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
583 if (!EFI_ERROR(Status
)) {
584 ASSERT(UsbIo
!= NULL
);
585 Status
= UsbIo
->UsbGetInterfaceDescriptor(UsbIo
, &InterfaceDesc
);
586 if (!EFI_ERROR(Status
)) {
587 if (InterfaceDesc
.InterfaceClass
== USB_MASS_STORE_CLASS
&& MappingItem
->Mtd
== MTDTypeUnknown
) {
588 switch (InterfaceDesc
.InterfaceSubClass
){
589 case USB_MASS_STORE_SCSI
:
590 MappingItem
->Mtd
= MTDTypeHardDisk
;
592 case USB_MASS_STORE_8070I
:
593 case USB_MASS_STORE_UFI
:
594 MappingItem
->Mtd
= MTDTypeFloppy
;
596 case USB_MASS_STORE_8020I
:
597 MappingItem
->Mtd
= MTDTypeCDRom
;
607 DevicePathNode must be SerialVendor type and this will populate the MappingItem.
609 @param[in] DevicePathNode The node to get info on.
610 @param[in] MappingItem The info item to populate.
615 DevPathSerialVendor (
616 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
617 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
618 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
621 VENDOR_DEVICE_PATH
*Vendor
;
622 SAS_DEVICE_PATH
*Sas
;
623 UINTN TargetNameLength
;
627 if (DevicePathNode
== NULL
|| MappingItem
== NULL
) {
631 Vendor
= (VENDOR_DEVICE_PATH
*) DevicePathNode
;
632 AppendCSDGuid (MappingItem
, &Vendor
->Guid
);
634 if (CompareGuid (&gEfiSasDevicePathGuid
, &Vendor
->Guid
)) {
635 Sas
= (SAS_DEVICE_PATH
*) Vendor
;
636 AppendCSDNum (MappingItem
, Sas
->SasAddress
);
637 AppendCSDNum (MappingItem
, Sas
->Lun
);
638 AppendCSDNum (MappingItem
, Sas
->DeviceTopology
);
639 AppendCSDNum (MappingItem
, Sas
->RelativeTargetPort
);
641 TargetNameLength
= MIN(DevicePathNodeLength (DevicePathNode
) - sizeof (VENDOR_DEVICE_PATH
), PcdGet32(PcdShellVendorExtendedDecode
));
642 if (TargetNameLength
!= 0) {
644 // String is 2 chars per data byte, plus NULL terminator
646 Buffer
= AllocateZeroPool (((TargetNameLength
* 2) + 1) * sizeof(CHAR16
));
647 ASSERT(Buffer
!= NULL
);
648 if (Buffer
== NULL
) {
653 // Build the string data
655 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
656 Buffer
= CatSPrint (Buffer
, L
"%02x", *((UINT8
*)Vendor
+ sizeof (VENDOR_DEVICE_PATH
) + Index
));
660 // Append the new data block
662 AppendCSDStr (MappingItem
, Buffer
);
670 DevicePathNode must be SerialLun type and this will populate the MappingItem.
672 @param[in] DevicePathNode The node to get info on.
673 @param[in] MappingItem The info item to populate.
678 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
679 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
680 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
683 DEVICE_LOGICAL_UNIT_DEVICE_PATH
*Lun
;
685 ASSERT(DevicePathNode
!= NULL
);
686 ASSERT(MappingItem
!= NULL
);
688 Lun
= (DEVICE_LOGICAL_UNIT_DEVICE_PATH
*) DevicePathNode
;
689 AppendCSDNum (MappingItem
, Lun
->Lun
);
693 DevicePathNode must be SerialSata type and this will populate the MappingItem.
695 @param[in] DevicePathNode The node to get info on.
696 @param[in] MappingItem The info item to populate.
701 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
702 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
703 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
706 SATA_DEVICE_PATH
*Sata
;
708 ASSERT(DevicePathNode
!= NULL
);
709 ASSERT(MappingItem
!= NULL
);
711 Sata
= (SATA_DEVICE_PATH
*) DevicePathNode
;
712 AppendCSDNum (MappingItem
, Sata
->HBAPortNumber
);
713 AppendCSDNum (MappingItem
, Sata
->PortMultiplierPortNumber
);
714 AppendCSDNum (MappingItem
, Sata
->Lun
);
718 DevicePathNode must be SerialSCSI type and this will populate the MappingItem.
720 @param[in] DevicePathNode The node to get info on.
721 @param[in] MappingItem The info item to populate.
726 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
727 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
728 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
731 ISCSI_DEVICE_PATH
*IScsi
;
732 UINT8
*IScsiTargetName
;
734 UINTN TargetNameLength
;
737 ASSERT(DevicePathNode
!= NULL
);
738 ASSERT(MappingItem
!= NULL
);
740 if (PcdGetBool(PcdShellDecodeIScsiMapNames
)) {
741 IScsi
= (ISCSI_DEVICE_PATH
*) DevicePathNode
;
742 AppendCSDNum (MappingItem
, IScsi
->NetworkProtocol
);
743 AppendCSDNum (MappingItem
, IScsi
->LoginOption
);
744 AppendCSDNum (MappingItem
, IScsi
->Lun
);
745 AppendCSDNum (MappingItem
, IScsi
->TargetPortalGroupTag
);
746 TargetNameLength
= DevicePathNodeLength (DevicePathNode
) - sizeof (ISCSI_DEVICE_PATH
);
747 if (TargetNameLength
> 0) {
748 TargetName
= AllocateZeroPool ((TargetNameLength
+ 1) * sizeof (CHAR16
));
749 if (TargetName
!= NULL
) {
750 IScsiTargetName
= (UINT8
*) (IScsi
+ 1);
751 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
752 TargetName
[Index
] = (CHAR16
) IScsiTargetName
[Index
];
754 AppendCSDStr (MappingItem
, TargetName
);
755 FreePool (TargetName
);
762 DevicePathNode must be SerialI20 type and this will populate the MappingItem.
764 @param[in] DevicePathNode The node to get info on.
765 @param[in] MappingItem The info item to populate.
770 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
771 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
772 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
775 I2O_DEVICE_PATH
*DevicePath_I20
;
777 ASSERT(DevicePathNode
!= NULL
);
778 ASSERT(MappingItem
!= NULL
);
780 DevicePath_I20
= (I2O_DEVICE_PATH
*) DevicePathNode
;
781 AppendCSDNum (MappingItem
, DevicePath_I20
->Tid
);
785 DevicePathNode must be Mac Address type and this will populate the MappingItem.
787 @param[in] DevicePathNode The node to get info on.
788 @param[in] MappingItem The info item to populate.
792 DevPathSerialMacAddr (
793 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
794 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
795 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
798 MAC_ADDR_DEVICE_PATH
*Mac
;
804 ASSERT(DevicePathNode
!= NULL
);
805 ASSERT(MappingItem
!= NULL
);
807 Mac
= (MAC_ADDR_DEVICE_PATH
*) DevicePathNode
;
809 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
810 if (Mac
->IfType
== 0x01 || Mac
->IfType
== 0x00) {
814 for (Index
= 0, PBuffer
= Buffer
; Index
< HwAddressSize
; Index
++, PBuffer
+= 2) {
815 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Mac
->MacAddress
.Addr
[Index
]);
818 AppendCSDStr (MappingItem
, Buffer
);
822 DevicePathNode must be InfiniBand type and this will populate the MappingItem.
824 @param[in] DevicePathNode The node to get info on.
825 @param[in] MappingItem The info item to populate.
829 DevPathSerialInfiniBand (
830 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
831 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
832 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
835 INFINIBAND_DEVICE_PATH
*InfiniBand
;
840 ASSERT(DevicePathNode
!= NULL
);
841 ASSERT(MappingItem
!= NULL
);
843 InfiniBand
= (INFINIBAND_DEVICE_PATH
*) DevicePathNode
;
844 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
845 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) InfiniBand
->PortGid
[Index
]);
848 AppendCSDStr (MappingItem
, Buffer
);
849 AppendCSDNum (MappingItem
, InfiniBand
->ServiceId
);
850 AppendCSDNum (MappingItem
, InfiniBand
->TargetPortId
);
851 AppendCSDNum (MappingItem
, InfiniBand
->DeviceId
);
855 DevicePathNode must be IPv4 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
,
865 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
868 IPv4_DEVICE_PATH
*Ip
;
871 ASSERT(DevicePathNode
!= NULL
);
872 ASSERT(MappingItem
!= NULL
);
874 Ip
= (IPv4_DEVICE_PATH
*) DevicePathNode
;
879 (UINTN
) Ip
->LocalIpAddress
.Addr
[0],
880 (UINTN
) Ip
->LocalIpAddress
.Addr
[1],
881 (UINTN
) Ip
->LocalIpAddress
.Addr
[2],
882 (UINTN
) Ip
->LocalIpAddress
.Addr
[3]
884 AppendCSDStr (MappingItem
, Buffer
);
885 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
890 (UINTN
) Ip
->RemoteIpAddress
.Addr
[0],
891 (UINTN
) Ip
->RemoteIpAddress
.Addr
[1],
892 (UINTN
) Ip
->RemoteIpAddress
.Addr
[2],
893 (UINTN
) Ip
->RemoteIpAddress
.Addr
[3]
895 AppendCSDStr (MappingItem
, Buffer
);
896 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
900 DevicePathNode must be IPv6 type and this will populate the MappingItem.
902 @param[in] DevicePathNode The node to get info on.
903 @param[in] MappingItem The info item to populate.
908 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
909 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
910 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
913 IPv6_DEVICE_PATH
*Ip
;
918 ASSERT(DevicePathNode
!= NULL
);
919 ASSERT(MappingItem
!= NULL
);
921 Ip
= (IPv6_DEVICE_PATH
*) DevicePathNode
;
922 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
923 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->LocalIpAddress
.Addr
[Index
]);
926 AppendCSDStr (MappingItem
, Buffer
);
927 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
928 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
929 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->RemoteIpAddress
.Addr
[Index
]);
932 AppendCSDStr (MappingItem
, Buffer
);
933 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
937 DevicePathNode must be SCSI type and this will populate the MappingItem.
939 @param[in] DevicePathNode The node to get info on.
940 @param[in] MappingItem The info item to populate.
945 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
946 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
947 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
950 SCSI_DEVICE_PATH
*Scsi
;
952 ASSERT(DevicePathNode
!= NULL
);
953 ASSERT(MappingItem
!= NULL
);
955 Scsi
= (SCSI_DEVICE_PATH
*) DevicePathNode
;
956 AppendCSDNum (MappingItem
, Scsi
->Pun
);
957 AppendCSDNum (MappingItem
, Scsi
->Lun
);
961 DevicePathNode must be 1394 type and this will populate the MappingItem.
963 @param[in] DevicePathNode The node to get info on.
964 @param[in] MappingItem The info item to populate.
969 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
970 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
971 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
974 F1394_DEVICE_PATH
*DevicePath_F1394
;
977 ASSERT(DevicePathNode
!= NULL
);
978 ASSERT(MappingItem
!= NULL
);
980 DevicePath_F1394
= (F1394_DEVICE_PATH
*) DevicePathNode
;
981 UnicodeSPrint (Buffer
, 0, L
"%lx", DevicePath_F1394
->Guid
);
982 AppendCSDStr (MappingItem
, Buffer
);
986 If the node is floppy type then populate the MappingItem.
988 @param[in] DevicePathNode The node to get info on.
989 @param[in] MappingItem The info item to populate.
994 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
995 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
996 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
999 ACPI_HID_DEVICE_PATH
*Acpi
;
1001 ASSERT(DevicePathNode
!= NULL
);
1002 ASSERT(MappingItem
!= NULL
);
1004 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1005 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
1006 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
1007 MappingItem
->Mtd
= MTDTypeFloppy
;
1008 AppendCSDNum (MappingItem
, Acpi
->UID
);
1014 Empty function used for unknown devices.
1016 @param[in] DevicePathNode Ignored.
1017 @param[in] MappingItem Ignored.
1023 DevPathSerialDefault (
1024 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
1025 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1026 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1032 DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable
[] = {
1034 HARDWARE_DEVICE_PATH
,
1036 DevPathSerialDefault
,
1046 MESSAGING_DEVICE_PATH
,
1049 DevPathCompareDefault
1052 MESSAGING_DEVICE_PATH
,
1055 DevPathCompareDefault
1058 MESSAGING_DEVICE_PATH
,
1059 MSG_FIBRECHANNEL_DP
,
1061 DevPathCompareDefault
1064 MESSAGING_DEVICE_PATH
,
1067 DevPathCompareDefault
1070 MESSAGING_DEVICE_PATH
,
1073 DevPathCompareDefault
1076 MESSAGING_DEVICE_PATH
,
1079 DevPathCompareDefault
1082 MESSAGING_DEVICE_PATH
,
1084 DevPathSerialMacAddr
,
1085 DevPathCompareDefault
1088 MESSAGING_DEVICE_PATH
,
1091 DevPathCompareDefault
1094 MESSAGING_DEVICE_PATH
,
1097 DevPathCompareDefault
1100 MESSAGING_DEVICE_PATH
,
1102 DevPathSerialInfiniBand
,
1103 DevPathCompareDefault
1106 MESSAGING_DEVICE_PATH
,
1109 DevPathCompareDefault
1112 MESSAGING_DEVICE_PATH
,
1114 DevPathSerialVendor
,
1115 DevPathCompareDefault
1118 MESSAGING_DEVICE_PATH
,
1119 MSG_DEVICE_LOGICAL_UNIT_DP
,
1121 DevPathCompareDefault
1124 MESSAGING_DEVICE_PATH
,
1127 DevPathCompareDefault
1130 MESSAGING_DEVICE_PATH
,
1133 DevPathCompareDefault
1138 DevPathSerialHardDrive
,
1139 DevPathCompareDefault
1145 DevPathCompareDefault
1150 DevPathSerialVendor
,
1151 DevPathCompareDefault
1162 Function to determine if a device path node is Hi or not.
1164 @param[in] DevicePathNode The node to check.
1166 @retval TRUE The node is Hi.
1167 @retval FALSE The node is not Hi.
1171 IsHIDevicePathNode (
1172 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
1175 ACPI_HID_DEVICE_PATH
*Acpi
;
1177 ASSERT(DevicePathNode
!= NULL
);
1179 if (DevicePathNode
->Type
== HARDWARE_DEVICE_PATH
) {
1183 if (DevicePathNode
->Type
== ACPI_DEVICE_PATH
) {
1184 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1185 switch (EISA_ID_TO_NUM (Acpi
->HID
)) {
1200 Function to convert a standard device path structure into a Hi version.
1202 @param[in] DevicePath The device path to convert.
1204 @return the device path portion that is Hi.
1206 EFI_DEVICE_PATH_PROTOCOL
*
1209 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1212 UINTN NonHIDevicePathNodeCount
;
1215 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1216 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1218 ASSERT(DevicePath
!= NULL
);
1220 NonHIDevicePathNodeCount
= 0;
1222 HIDevicePath
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1223 SetDevicePathEndNode (HIDevicePath
);
1225 Node
.DevPath
.Type
= END_DEVICE_PATH_TYPE
;
1226 Node
.DevPath
.SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
1227 Node
.DevPath
.Length
[0] = (UINT8
)sizeof (EFI_DEVICE_PATH_PROTOCOL
);
1228 Node
.DevPath
.Length
[1] = 0;
1230 while (!IsDevicePathEnd (DevicePath
)) {
1231 if (IsHIDevicePathNode (DevicePath
)) {
1232 for (Index
= 0; Index
< NonHIDevicePathNodeCount
; Index
++) {
1233 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, &Node
.DevPath
);
1234 FreePool (HIDevicePath
);
1235 HIDevicePath
= TempDevicePath
;
1238 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, DevicePath
);
1239 FreePool (HIDevicePath
);
1240 HIDevicePath
= TempDevicePath
;
1242 NonHIDevicePathNodeCount
++;
1245 // Next device path node
1247 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1250 return HIDevicePath
;
1254 Function to walk the device path looking for a dumpable node.
1256 @param[in] MappingItem The Item to fill with data.
1257 @param[in] DevicePath The path of the item to get data on.
1259 @return EFI_SUCCESS Always returns success.
1263 GetDeviceConsistMappingInfo (
1264 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1265 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1268 SerialDecodeFucntion SerialFun
;
1270 EFI_DEVICE_PATH_PROTOCOL
*OriginalDevicePath
;
1272 ASSERT(DevicePath
!= NULL
);
1273 ASSERT(MappingItem
!= NULL
);
1275 SetMem (&MappingItem
->Csd
, sizeof (POOL_PRINT
), 0);
1276 OriginalDevicePath
= DevicePath
;
1278 while (!IsDevicePathEnd (DevicePath
)) {
1280 // Find the handler to dump this device path node and
1281 // initialize with generic function in case nothing is found
1283 for (SerialFun
= DevPathSerialDefault
, Index
= 0; DevPathConsistMappingTable
[Index
].SerialFun
!= NULL
; Index
+= 1) {
1285 if (DevicePathType (DevicePath
) == DevPathConsistMappingTable
[Index
].Type
&&
1286 DevicePathSubType (DevicePath
) == DevPathConsistMappingTable
[Index
].SubType
1288 SerialFun
= DevPathConsistMappingTable
[Index
].SerialFun
;
1293 SerialFun (DevicePath
, MappingItem
, OriginalDevicePath
);
1296 // Next device path node
1298 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1305 Function to initialize the table for creating consistent map names.
1307 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
1309 @retval EFI_SUCCESS The table was created successfully.
1313 ShellCommandConsistMappingInitialize (
1314 OUT EFI_DEVICE_PATH_PROTOCOL
***Table
1317 EFI_HANDLE
*HandleBuffer
;
1320 EFI_DEVICE_PATH_PROTOCOL
**TempTable
;
1321 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1322 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1326 HandleBuffer
= NULL
;
1328 Status
= gBS
->LocateHandleBuffer (
1335 ASSERT_EFI_ERROR(Status
);
1337 TempTable
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
1338 if (TempTable
== NULL
) {
1339 return EFI_OUT_OF_RESOURCES
;
1342 for (HandleLoop
= 0 ; HandleLoop
< HandleNum
; HandleLoop
++) {
1343 DevicePath
= DevicePathFromHandle (HandleBuffer
[HandleLoop
]);
1344 if (DevicePath
== NULL
) {
1348 HIDevicePath
= GetHIDevicePath (DevicePath
);
1349 if (HIDevicePath
== NULL
) {
1353 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++) {
1354 if (DevicePathCompare (&TempTable
[Index
], &HIDevicePath
) == 0) {
1355 FreePool (HIDevicePath
);
1360 if (TempTable
[Index
] == NULL
) {
1361 TempTable
[Index
] = HIDevicePath
;
1365 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++);
1366 PerformQuickSort(TempTable
, Index
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1369 if (HandleBuffer
!= NULL
) {
1370 FreePool (HandleBuffer
);
1377 Function to uninitialize the table for creating consistent map names.
1379 The parameter must have been received from ShellCommandConsistMappingInitialize.
1381 @param[out] Table The pointer to pointer to DevicePathProtocol object.
1383 @retval EFI_SUCCESS The table was deleted successfully.
1387 ShellCommandConsistMappingUnInitialize (
1388 EFI_DEVICE_PATH_PROTOCOL
**Table
1393 ASSERT(Table
!= NULL
);
1395 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1396 FreePool (Table
[Index
]);
1404 Create a consistent mapped name for the device specified by DevicePath
1407 This must be called after ShellCommandConsistMappingInitialize() and
1408 before ShellCommandConsistMappingUnInitialize() is called.
1410 @param[in] DevicePath The pointer to the dev path for the device.
1411 @param[in] Table The Table of mapping information.
1413 @retval NULL A consistent mapped name could not be created.
1414 @return A pointer to a string allocated from pool with the device name.
1418 ShellCommandConsistMappingGenMappingName (
1419 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1420 IN EFI_DEVICE_PATH_PROTOCOL
**Table
1424 DEVICE_CONSIST_MAPPING_INFO MappingInfo
;
1425 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1429 ASSERT(DevicePath
!= NULL
);
1430 ASSERT(Table
!= NULL
);
1432 HIDevicePath
= GetHIDevicePath (DevicePath
);
1433 if (HIDevicePath
== NULL
) {
1437 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1438 if (DevicePathCompare (&Table
[Index
], &HIDevicePath
) == 0) {
1443 FreePool (HIDevicePath
);
1444 if (Table
[Index
] == NULL
) {
1448 MappingInfo
.Hi
= Index
;
1449 MappingInfo
.Mtd
= MTDTypeUnknown
;
1450 MappingInfo
.Digital
= FALSE
;
1452 GetDeviceConsistMappingInfo (&MappingInfo
, DevicePath
);
1454 SetMem (&Str
, sizeof (Str
), 0);
1455 for (Index
= 0; mMTDName
[Index
].MTDType
!= MTDTypeEnd
; Index
++) {
1456 if (MappingInfo
.Mtd
== mMTDName
[Index
].MTDType
) {
1461 if (mMTDName
[Index
].MTDType
!= MTDTypeEnd
) {
1462 CatPrint (&Str
, L
"%s", mMTDName
[Index
].Name
);
1465 CatPrint (&Str
, L
"%d", (UINTN
) MappingInfo
.Hi
);
1466 if (MappingInfo
.Csd
.Str
!= NULL
) {
1467 CatPrint (&Str
, L
"%s", MappingInfo
.Csd
.Str
);
1468 FreePool (MappingInfo
.Csd
.Str
);
1471 if (Str
.Str
!= NULL
) {
1472 CatPrint (&Str
, L
":");
1475 NewSize
= (Str
.Len
+ 1) * sizeof (CHAR16
);
1476 Str
.Str
= ReallocatePool (Str
.Len
, NewSize
, Str
.Str
);
1477 if (Str
.Str
== NULL
) {
1480 Str
.Str
[Str
.Len
] = CHAR_NULL
;
1485 Function to search the list of mappings for the node on the list based on the key.
1487 @param[in] MapKey String Key to search for on the map
1489 @return the node on the list.
1493 ShellCommandFindMapItem (
1494 IN CONST CHAR16
*MapKey
1497 SHELL_MAP_LIST
*MapListItem
;
1499 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1500 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
1501 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
1503 if (gUnicodeCollation
->StriColl(gUnicodeCollation
,MapListItem
->MapName
,(CHAR16
*)MapKey
) == 0) {
1504 return (MapListItem
);