2 Main file for support of shell consist mapping.
4 Copyright (c) 2005 - 2010, 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
*, DEVICE_CONSIST_MAPPING_INFO
*);
47 INTN (EFIAPI
*CompareFun
) (EFI_DEVICE_PATH_PROTOCOL
*, EFI_DEVICE_PATH_PROTOCOL
*);
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 StrCat (Str
->Str
, AppendStr
);
102 Str
->Len
= StringSize
;
104 FreePool (AppendStr
);
108 MTD_NAME mMTDName
[] = {
133 IN OUT POOL_PRINT
*Str
,
142 Result
= DivU64x32Remainder (Num
, 25, &Rem
);
144 AppendCSDNum2 (Str
, Result
);
147 CatPrint (Str
, L
"%c", Rem
+ 'a');
152 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
156 ASSERT(MappingItem
!= NULL
);
158 if (MappingItem
->Digital
) {
159 CatPrint (&MappingItem
->CSD
, L
"%ld", Num
);
161 AppendCSDNum2 (&MappingItem
->CSD
, Num
);
164 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
169 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
176 ASSERT(MappingItem
!= NULL
);
178 if (MappingItem
->Digital
) {
180 // To aVOID mult-meaning, the mapping is:
181 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
182 // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15
184 for (Index
= Str
; *Index
!= 0; Index
++) {
195 CatPrint (&MappingItem
->CSD
, L
"%c", *Index
);
199 CatPrint (&MappingItem
->CSD
, L
"16");
208 CatPrint (&MappingItem
->CSD
, L
"1%c", *Index
- 'a' + '0');
217 CatPrint (&MappingItem
->CSD
, L
"1%c", *Index
- 'A' + '0');
222 for (Index
= Str
; *Index
!= 0; Index
++) {
225 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
226 // a b c d e f g h i j k l m n o p
228 if (*Index
>= '0' && *Index
<= '9') {
229 CatPrint (&MappingItem
->CSD
, L
"%c", *Index
- '0' + 'a');
230 } else if (*Index
>= 'a' && *Index
<= 'f') {
231 CatPrint (&MappingItem
->CSD
, L
"%c", *Index
- 'a' + 'k');
232 } else if (*Index
>= 'A' && *Index
<= 'F') {
233 CatPrint (&MappingItem
->CSD
, L
"%c", *Index
- 'A' + 'k');
238 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
243 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
248 ASSERT(Guid
!= NULL
);
249 ASSERT(MappingItem
!= NULL
);
258 AppendCSDStr (MappingItem
, Buffer
);
263 _DevPathCompareAcpi (
264 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
265 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
268 ACPI_HID_DEVICE_PATH
*Acpi1
;
269 ACPI_HID_DEVICE_PATH
*Acpi2
;
271 ASSERT(DevicePath1
!= NULL
);
272 ASSERT(DevicePath2
!= NULL
);
274 Acpi1
= (ACPI_HID_DEVICE_PATH
*) DevicePath1
;
275 Acpi2
= (ACPI_HID_DEVICE_PATH
*) DevicePath2
;
276 if (Acpi1
->HID
> Acpi2
->HID
|| (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
> Acpi2
->UID
)) {
280 if (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
== Acpi2
->UID
) {
290 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
291 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
294 PCI_DEVICE_PATH
*Pci1
;
295 PCI_DEVICE_PATH
*Pci2
;
297 ASSERT(DevicePath1
!= NULL
);
298 ASSERT(DevicePath2
!= NULL
);
300 Pci1
= (PCI_DEVICE_PATH
*) DevicePath1
;
301 Pci2
= (PCI_DEVICE_PATH
*) DevicePath2
;
302 if (Pci1
->Device
> Pci2
->Device
|| (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
> Pci2
->Function
)) {
306 if (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
== Pci2
->Function
) {
314 Do a comparison on 2 device paths.
316 @param[in] DevicePath1 The first device path.
317 @param[in] DevicePath2 The second device path.
319 @retval 0 The 2 device paths are the same.
320 @retval <0 DevicePath2 is greater than DevicePath1.
321 @retval >0 DevicePath1 is greater than DevicePath2.
325 DevPathCompareDefault (
326 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
327 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
333 ASSERT(DevicePath1
!= NULL
);
334 ASSERT(DevicePath2
!= NULL
);
336 DevPathSize1
= DevicePathNodeLength (DevicePath1
);
337 DevPathSize2
= DevicePathNodeLength (DevicePath2
);
338 if (DevPathSize1
> DevPathSize2
) {
340 } else if (DevPathSize1
< DevPathSize2
) {
343 return CompareMem (DevicePath1
, DevicePath2
, DevPathSize1
);
348 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
350 @param[in] DevicePathNode The node to get info on.
351 @param[in] MappingItem The info item to populate.
355 DevPathSerialHardDrive (
356 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
357 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
360 HARDDRIVE_DEVICE_PATH
*Hd
;
362 ASSERT(DevicePathNode
!= NULL
);
363 ASSERT(MappingItem
!= NULL
);
365 Hd
= (HARDDRIVE_DEVICE_PATH
*) DevicePathNode
;
366 if (MappingItem
->MTD
== MTDTypeUnknown
) {
367 MappingItem
->MTD
= MTDTypeHardDisk
;
370 AppendCSDNum (MappingItem
, Hd
->PartitionNumber
);
374 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
376 @param[in] DevicePathNode The node to get info on.
377 @param[in] MappingItem The info item to populate.
382 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
383 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
386 ATAPI_DEVICE_PATH
*Atapi
;
388 ASSERT(DevicePathNode
!= NULL
);
389 ASSERT(MappingItem
!= NULL
);
391 Atapi
= (ATAPI_DEVICE_PATH
*) DevicePathNode
;
392 AppendCSDNum (MappingItem
, (Atapi
->PrimarySecondary
* 2 + Atapi
->SlaveMaster
));
396 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
398 @param[in] DevicePathNode The node to get info on.
399 @param[in] MappingItem The info item to populate.
404 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
405 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
408 CDROM_DEVICE_PATH
*Cd
;
410 ASSERT(DevicePathNode
!= NULL
);
411 ASSERT(MappingItem
!= NULL
);
413 Cd
= (CDROM_DEVICE_PATH
*) DevicePathNode
;
414 MappingItem
->MTD
= MTDTypeCDRom
;
415 AppendCSDNum (MappingItem
, Cd
->BootEntry
);
419 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
421 @param[in] DevicePathNode The node to get info on.
422 @param[in] MappingItem The info item to populate.
427 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
428 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
431 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
433 ASSERT(DevicePathNode
!= NULL
);
434 ASSERT(MappingItem
!= NULL
);
436 Fibre
= (FIBRECHANNEL_DEVICE_PATH
*) DevicePathNode
;
437 AppendCSDNum (MappingItem
, Fibre
->WWN
);
438 AppendCSDNum (MappingItem
, Fibre
->Lun
);
442 DevicePathNode must be SerialUart type and this will populate the MappingItem.
444 @param[in] DevicePathNode The node to get info on.
445 @param[in] MappingItem The info item to populate.
450 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
451 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
454 UART_DEVICE_PATH
*Uart
;
456 ASSERT(DevicePathNode
!= NULL
);
457 ASSERT(MappingItem
!= NULL
);
459 Uart
= (UART_DEVICE_PATH
*) DevicePathNode
;
460 AppendCSDNum (MappingItem
, Uart
->BaudRate
);
461 AppendCSDNum (MappingItem
, Uart
->DataBits
);
462 AppendCSDNum (MappingItem
, Uart
->Parity
);
463 AppendCSDNum (MappingItem
, Uart
->StopBits
);
467 DevicePathNode must be SerialUSB 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.
475 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
476 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
479 USB_DEVICE_PATH
*Usb
;
481 ASSERT(DevicePathNode
!= NULL
);
482 ASSERT(MappingItem
!= NULL
);
484 Usb
= (USB_DEVICE_PATH
*) DevicePathNode
;
485 AppendCSDNum (MappingItem
, Usb
->ParentPortNumber
);
486 AppendCSDNum (MappingItem
, Usb
->InterfaceNumber
);
490 DevicePathNode must be SerialVendor type and this will populate the MappingItem.
492 @param[in] DevicePathNode The node to get info on.
493 @param[in] MappingItem The info item to populate.
497 DevPathSerialVendor (
498 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
499 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
502 VENDOR_DEVICE_PATH
*Vendor
;
503 SAS_DEVICE_PATH
*Sas
;
504 EFI_GUID SasVendorGuid
= DEVICE_PATH_MESSAGING_SAS
;
506 ASSERT(DevicePathNode
!= NULL
);
507 ASSERT(MappingItem
!= NULL
);
509 Vendor
= (VENDOR_DEVICE_PATH
*) DevicePathNode
;
510 AppendCSDGuid (MappingItem
, &Vendor
->Guid
);
512 if (CompareGuid (&SasVendorGuid
, &Vendor
->Guid
) == 0) {
513 Sas
= (SAS_DEVICE_PATH
*) Vendor
;
514 AppendCSDNum (MappingItem
, Sas
->SasAddress
);
515 AppendCSDNum (MappingItem
, Sas
->Lun
);
516 AppendCSDNum (MappingItem
, Sas
->DeviceTopology
);
517 AppendCSDNum (MappingItem
, Sas
->RelativeTargetPort
);
522 DevicePathNode must be SerialLun type and this will populate the MappingItem.
524 @param[in] DevicePathNode The node to get info on.
525 @param[in] MappingItem The info item to populate.
530 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
531 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
534 DEVICE_LOGICAL_UNIT_DEVICE_PATH
*Lun
;
536 ASSERT(DevicePathNode
!= NULL
);
537 ASSERT(MappingItem
!= NULL
);
539 Lun
= (DEVICE_LOGICAL_UNIT_DEVICE_PATH
*) DevicePathNode
;
540 AppendCSDNum (MappingItem
, Lun
->Lun
);
544 DevicePathNode must be SerialSata type and this will populate the MappingItem.
546 @param[in] DevicePathNode The node to get info on.
547 @param[in] MappingItem The info item to populate.
552 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
553 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
556 SATA_DEVICE_PATH
*Sata
;
558 ASSERT(DevicePathNode
!= NULL
);
559 ASSERT(MappingItem
!= NULL
);
561 Sata
= (SATA_DEVICE_PATH
*) DevicePathNode
;
562 AppendCSDNum (MappingItem
, Sata
->HBAPortNumber
);
563 AppendCSDNum (MappingItem
, Sata
->PortMultiplierPortNumber
);
564 AppendCSDNum (MappingItem
, Sata
->Lun
);
568 DevicePathNode must be SerialSCSI 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.
576 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
577 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
580 ///@todo make this a PCD
582 // As CSD of ISCSI node is quite long, we comment
583 // the code below to keep the consistent mapping
584 // short. Uncomment if you really need it.
587 ISCSI_DEVICE_PATH *IScsi;
588 UINT8 *IScsiTargetName;
590 UINTN TargetNameLength;
593 ASSERT(DevicePathNode != NULL);
594 ASSERT(MappingItem != NULL);
596 IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode;
597 AppendCSDNum (MappingItem, IScsi->NetworkProtocol);
598 AppendCSDNum (MappingItem, IScsi->LoginOption);
599 AppendCSDNum (MappingItem, IScsi->Lun);
600 AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag);
601 TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH);
602 if (TargetNameLength > 0) {
603 TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16));
604 if (TargetName != NULL) {
605 IScsiTargetName = (UINT8 *) (IScsi + 1);
606 for (Index = 0; Index < TargetNameLength; Index++) {
607 TargetName[Index] = (CHAR16) IScsiTargetName[Index];
609 AppendCSDStr (MappingItem, TargetName);
610 FreePool (TargetName);
617 DevicePathNode must be SerialI20 type and this will populate the MappingItem.
619 @param[in] DevicePathNode The node to get info on.
620 @param[in] MappingItem The info item to populate.
625 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
626 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
629 I2O_DEVICE_PATH
*I2O
;
631 ASSERT(DevicePathNode
!= NULL
);
632 ASSERT(MappingItem
!= NULL
);
634 I2O
= (I2O_DEVICE_PATH
*) DevicePathNode
;
635 AppendCSDNum (MappingItem
, I2O
->Tid
);
639 DevicePathNode must be Mac Address type and this will populate the MappingItem.
641 @param[in] DevicePathNode The node to get info on.
642 @param[in] MappingItem The info item to populate.
646 DevPathSerialMacAddr (
647 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
648 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
651 MAC_ADDR_DEVICE_PATH
*Mac
;
657 ASSERT(DevicePathNode
!= NULL
);
658 ASSERT(MappingItem
!= NULL
);
660 Mac
= (MAC_ADDR_DEVICE_PATH
*) DevicePathNode
;
662 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
663 if (Mac
->IfType
== 0x01 || Mac
->IfType
== 0x00) {
667 for (Index
= 0, PBuffer
= Buffer
; Index
< HwAddressSize
; Index
++, PBuffer
+= 2) {
668 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Mac
->MacAddress
.Addr
[Index
]);
671 AppendCSDStr (MappingItem
, Buffer
);
675 DevicePathNode must be InfiniBand type and this will populate the MappingItem.
677 @param[in] DevicePathNode The node to get info on.
678 @param[in] MappingItem The info item to populate.
682 DevPathSerialInfiniBand (
683 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
684 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
687 INFINIBAND_DEVICE_PATH
*InfiniBand
;
692 ASSERT(DevicePathNode
!= NULL
);
693 ASSERT(MappingItem
!= NULL
);
695 InfiniBand
= (INFINIBAND_DEVICE_PATH
*) DevicePathNode
;
696 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
697 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) InfiniBand
->PortGid
[Index
]);
700 AppendCSDStr (MappingItem
, Buffer
);
701 AppendCSDNum (MappingItem
, InfiniBand
->ServiceId
);
702 AppendCSDNum (MappingItem
, InfiniBand
->TargetPortId
);
703 AppendCSDNum (MappingItem
, InfiniBand
->DeviceId
);
707 DevicePathNode must be IPv4 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.
715 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
716 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
719 IPv4_DEVICE_PATH
*Ip
;
722 ASSERT(DevicePathNode
!= NULL
);
723 ASSERT(MappingItem
!= NULL
);
725 Ip
= (IPv4_DEVICE_PATH
*) DevicePathNode
;
730 (UINTN
) Ip
->LocalIpAddress
.Addr
[0],
731 (UINTN
) Ip
->LocalIpAddress
.Addr
[1],
732 (UINTN
) Ip
->LocalIpAddress
.Addr
[2],
733 (UINTN
) Ip
->LocalIpAddress
.Addr
[3]
735 AppendCSDStr (MappingItem
, Buffer
);
736 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
741 (UINTN
) Ip
->RemoteIpAddress
.Addr
[0],
742 (UINTN
) Ip
->RemoteIpAddress
.Addr
[1],
743 (UINTN
) Ip
->RemoteIpAddress
.Addr
[2],
744 (UINTN
) Ip
->RemoteIpAddress
.Addr
[3]
746 AppendCSDStr (MappingItem
, Buffer
);
747 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
751 DevicePathNode must be IPv6 type and this will populate the MappingItem.
753 @param[in] DevicePathNode The node to get info on.
754 @param[in] MappingItem The info item to populate.
759 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
760 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
763 IPv6_DEVICE_PATH
*Ip
;
768 ASSERT(DevicePathNode
!= NULL
);
769 ASSERT(MappingItem
!= NULL
);
771 Ip
= (IPv6_DEVICE_PATH
*) DevicePathNode
;
772 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
773 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->LocalIpAddress
.Addr
[Index
]);
776 AppendCSDStr (MappingItem
, Buffer
);
777 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
778 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
779 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->RemoteIpAddress
.Addr
[Index
]);
782 AppendCSDStr (MappingItem
, Buffer
);
783 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
787 DevicePathNode must be SCSI type and this will populate the MappingItem.
789 @param[in] DevicePathNode The node to get info on.
790 @param[in] MappingItem The info item to populate.
795 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
796 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
799 SCSI_DEVICE_PATH
*Scsi
;
801 ASSERT(DevicePathNode
!= NULL
);
802 ASSERT(MappingItem
!= NULL
);
804 Scsi
= (SCSI_DEVICE_PATH
*) DevicePathNode
;
805 AppendCSDNum (MappingItem
, Scsi
->Pun
);
806 AppendCSDNum (MappingItem
, Scsi
->Lun
);
810 DevicePathNode must be 1394 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.
818 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
819 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
822 F1394_DEVICE_PATH
*F1394
;
825 ASSERT(DevicePathNode
!= NULL
);
826 ASSERT(MappingItem
!= NULL
);
828 F1394
= (F1394_DEVICE_PATH
*) DevicePathNode
;
829 UnicodeSPrint (Buffer
, 0, L
"%lx", F1394
->Guid
);
830 AppendCSDStr (MappingItem
, Buffer
);
834 If the node is floppy type then populate the MappingItem.
836 @param[in] DevicePathNode The node to get info on.
837 @param[in] MappingItem The info item to populate.
842 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
843 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
846 ACPI_HID_DEVICE_PATH
*Acpi
;
848 ASSERT(DevicePathNode
!= NULL
);
849 ASSERT(MappingItem
!= NULL
);
851 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
852 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
853 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
854 MappingItem
->MTD
= MTDTypeFloppy
;
855 AppendCSDNum (MappingItem
, Acpi
->UID
);
861 Empty function used for unknown devices.
867 DevPathSerialDefault (
868 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
869 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
874 DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable
[] = {
875 HARDWARE_DEVICE_PATH
,
877 DevPathSerialDefault
,
883 MESSAGING_DEVICE_PATH
,
886 DevPathCompareDefault
,
887 MESSAGING_DEVICE_PATH
,
890 DevPathCompareDefault
,
891 MESSAGING_DEVICE_PATH
,
894 DevPathCompareDefault
,
895 MESSAGING_DEVICE_PATH
,
898 DevPathCompareDefault
,
899 MESSAGING_DEVICE_PATH
,
902 DevPathCompareDefault
,
903 MESSAGING_DEVICE_PATH
,
906 DevPathCompareDefault
,
907 MESSAGING_DEVICE_PATH
,
909 DevPathSerialMacAddr
,
910 DevPathCompareDefault
,
911 MESSAGING_DEVICE_PATH
,
914 DevPathCompareDefault
,
915 MESSAGING_DEVICE_PATH
,
918 DevPathCompareDefault
,
919 MESSAGING_DEVICE_PATH
,
921 DevPathSerialInfiniBand
,
922 DevPathCompareDefault
,
923 MESSAGING_DEVICE_PATH
,
926 DevPathCompareDefault
,
927 MESSAGING_DEVICE_PATH
,
930 DevPathCompareDefault
,
931 MESSAGING_DEVICE_PATH
,
932 MSG_DEVICE_LOGICAL_UNIT_DP
,
934 DevPathCompareDefault
,
935 MESSAGING_DEVICE_PATH
,
938 DevPathCompareDefault
,
939 MESSAGING_DEVICE_PATH
,
942 DevPathCompareDefault
,
945 DevPathSerialHardDrive
,
946 DevPathCompareDefault
,
950 DevPathCompareDefault
,
954 DevPathCompareDefault
,
962 Function to determine if a device path node is Hi or not.
964 @param[in] DevicePathNode The node to check.
966 @retval TRUE The node is HI.
967 @retval FALSE The node is not HI.
972 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
975 ACPI_HID_DEVICE_PATH
*Acpi
;
977 ASSERT(DevicePathNode
!= NULL
);
979 if (DevicePathNode
->Type
== HARDWARE_DEVICE_PATH
) {
983 if (DevicePathNode
->Type
== ACPI_DEVICE_PATH
) {
984 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
985 switch (EISA_ID_TO_NUM (Acpi
->HID
)) {
1000 Function to convert a standard device path structure into a HI version.
1002 @param[in] DevicePath The device path to convert.
1004 @return the device path portion that is HI.
1006 EFI_DEVICE_PATH_PROTOCOL
*
1009 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1012 UINTN NonHIDevicePathNodeCount
;
1015 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1016 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1018 ASSERT(DevicePath
!= NULL
);
1020 NonHIDevicePathNodeCount
= 0;
1022 HIDevicePath
= AllocatePool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1023 SetDevicePathEndNode (HIDevicePath
);
1025 Node
.DevPath
.Type
= END_DEVICE_PATH_TYPE
;
1026 Node
.DevPath
.SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
1027 Node
.DevPath
.Length
[0] = (UINT8
)sizeof (EFI_DEVICE_PATH_PROTOCOL
);
1028 Node
.DevPath
.Length
[1] = 0;
1030 while (!IsDevicePathEnd (DevicePath
)) {
1031 if (IsHIDevicePathNode (DevicePath
)) {
1032 for (Index
= 0; Index
< NonHIDevicePathNodeCount
; Index
++) {
1033 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, &Node
.DevPath
);
1034 FreePool (HIDevicePath
);
1035 HIDevicePath
= TempDevicePath
;
1038 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, DevicePath
);
1039 FreePool (HIDevicePath
);
1040 HIDevicePath
= TempDevicePath
;
1042 NonHIDevicePathNodeCount
++;
1045 // Next device path node
1047 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1050 return HIDevicePath
;
1054 Function to walk the device path looking for a dumpable node.
1056 @param[in] MappingItem The Item to fill with data.
1057 @param[in] DevicePath The path of the item to get data on.
1059 @return EFI_SUCCESS Always returns success.
1063 GetDeviceConsistMappingInfo (
1064 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1065 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1068 VOID (EFIAPI
*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*, DEVICE_CONSIST_MAPPING_INFO
*);
1072 ASSERT(DevicePath
!= NULL
);
1073 ASSERT(MappingItem
!= NULL
);
1075 SetMem (&MappingItem
->CSD
, sizeof (POOL_PRINT
), 0);
1077 while (!IsDevicePathEnd (DevicePath
)) {
1079 // Find the handler to dump this device path node
1082 for (Index
= 0; DevPathConsistMappingTable
[Index
].SerialFun
!= NULL
; Index
+= 1) {
1084 if (DevicePathType (DevicePath
) == DevPathConsistMappingTable
[Index
].Type
&&
1085 DevicePathSubType (DevicePath
) == DevPathConsistMappingTable
[Index
].SubType
1087 SerialFun
= DevPathConsistMappingTable
[Index
].SerialFun
;
1092 // If not found, use a generic function
1095 SerialFun
= DevPathSerialDefault
;
1098 SerialFun (DevicePath
, MappingItem
);
1101 // Next device path node
1103 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1110 Function to initialize the table for creating consistent map names.
1112 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
1114 @retval EFI_SUCCESS The table was created successfully.
1118 ShellCommandConsistMappingInitialize (
1119 OUT EFI_DEVICE_PATH_PROTOCOL
***Table
1122 EFI_HANDLE
*HandleBuffer
;
1125 EFI_DEVICE_PATH_PROTOCOL
**TempTable
;
1126 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1127 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1131 HandleBuffer
= NULL
;
1133 Status
= gBS
->LocateHandleBuffer (
1140 ASSERT_EFI_ERROR(Status
);
1142 TempTable
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
1143 if (TempTable
== NULL
) {
1144 return EFI_OUT_OF_RESOURCES
;
1147 for (HandleLoop
= 0 ; HandleLoop
< HandleNum
; HandleLoop
++) {
1148 DevicePath
= DevicePathFromHandle (HandleBuffer
[HandleLoop
]);
1149 if (DevicePath
== NULL
) {
1153 HIDevicePath
= GetHIDevicePath (DevicePath
);
1154 if (HIDevicePath
== NULL
) {
1158 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++) {
1159 if (DevicePathCompare (&TempTable
[Index
], &HIDevicePath
) == 0) {
1160 FreePool (HIDevicePath
);
1165 if (TempTable
[Index
] == NULL
) {
1166 TempTable
[Index
] = HIDevicePath
;
1170 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++);
1171 PerformQuickSort(TempTable
, Index
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1174 if (HandleBuffer
!= NULL
) {
1175 FreePool (HandleBuffer
);
1182 Function to uninitialize the table for creating consistent map names.
1184 The parameter must have been received from ShellCommandConsistMappingInitialize.
1186 @param[out] Table The pointer to pointer to DevicePathProtocol object.
1188 @retval EFI_SUCCESS The table was deleted successfully.
1192 ShellCommandConsistMappingUnInitialize (
1193 EFI_DEVICE_PATH_PROTOCOL
**Table
1198 ASSERT(Table
!= NULL
);
1200 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1201 FreePool (Table
[Index
]);
1209 Create a consistent mapped name for the device specified by DevicePath
1212 This must be called after ShellCommandConsistMappingInitialize() and
1213 before ShellCommandConsistMappingUnInitialize() is called.
1215 @param[in] DeviecPath The pointer to the dev path for the device.
1216 @param[in] Table The Table of mapping information.
1218 @retval NULL A consistent mapped name could not be created.
1219 @return A pointer to a string allocated from pool with the device name.
1223 ShellCommandConsistMappingGenMappingName (
1224 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1225 EFI_DEVICE_PATH_PROTOCOL
**Table
1229 DEVICE_CONSIST_MAPPING_INFO MappingInfo
;
1230 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1234 ASSERT(DevicePath
!= NULL
);
1235 ASSERT(Table
!= NULL
);
1237 HIDevicePath
= GetHIDevicePath (DevicePath
);
1238 if (HIDevicePath
== NULL
) {
1242 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1243 if (DevicePathCompare (&Table
[Index
], &HIDevicePath
) == 0) {
1248 FreePool (HIDevicePath
);
1249 if (Table
[Index
] == NULL
) {
1253 MappingInfo
.HI
= Index
;
1254 MappingInfo
.MTD
= MTDTypeUnknown
;
1255 MappingInfo
.Digital
= FALSE
;
1257 GetDeviceConsistMappingInfo (&MappingInfo
, DevicePath
);
1259 SetMem (&Str
, sizeof (Str
), 0);
1260 for (Index
= 0; mMTDName
[Index
].MTDType
!= MTDTypeEnd
; Index
++) {
1261 if (MappingInfo
.MTD
== mMTDName
[Index
].MTDType
) {
1266 if (mMTDName
[Index
].MTDType
!= MTDTypeEnd
) {
1267 CatPrint (&Str
, L
"%s", mMTDName
[Index
].Name
);
1270 CatPrint (&Str
, L
"%d", (UINTN
) MappingInfo
.HI
);
1271 if (MappingInfo
.CSD
.Str
!= NULL
) {
1272 CatPrint (&Str
, L
"%s", MappingInfo
.CSD
.Str
);
1273 FreePool (MappingInfo
.CSD
.Str
);
1276 if (Str
.Str
!= NULL
) {
1277 CatPrint (&Str
, L
":");
1280 NewSize
= (Str
.Len
+ 1) * sizeof (CHAR16
);
1281 Str
.Str
= ReallocatePool (Str
.Len
, NewSize
, Str
.Str
);
1282 if (Str
.Str
== NULL
) {
1285 Str
.Str
[Str
.Len
] = CHAR_NULL
;
1290 Function to search the list of mappings for the node on the list based on the key.
1292 @param[in] MapKey String Key to search for on the map
1294 @return the node on the list.
1298 ShellCommandFindMapItem (
1299 IN CONST CHAR16
*MapKey
1302 SHELL_MAP_LIST
*MapListItem
;
1304 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1305 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
1306 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
1308 if (gUnicodeCollation
->StriColl(gUnicodeCollation
,MapListItem
->MapName
,(CHAR16
*)MapKey
) == 0) {
1309 return (MapListItem
);