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 (*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*, DEVICE_CONSIST_MAPPING_INFO
*);
47 INTN (*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
);
262 _DevPathCompareAcpi (
263 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
264 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
267 ACPI_HID_DEVICE_PATH
*Acpi1
;
268 ACPI_HID_DEVICE_PATH
*Acpi2
;
270 ASSERT(DevicePath1
!= NULL
);
271 ASSERT(DevicePath2
!= NULL
);
273 Acpi1
= (ACPI_HID_DEVICE_PATH
*) DevicePath1
;
274 Acpi2
= (ACPI_HID_DEVICE_PATH
*) DevicePath2
;
275 if (Acpi1
->HID
> Acpi2
->HID
|| (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
> Acpi2
->UID
)) {
279 if (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
== Acpi2
->UID
) {
288 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
289 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
292 PCI_DEVICE_PATH
*Pci1
;
293 PCI_DEVICE_PATH
*Pci2
;
295 ASSERT(DevicePath1
!= NULL
);
296 ASSERT(DevicePath2
!= NULL
);
298 Pci1
= (PCI_DEVICE_PATH
*) DevicePath1
;
299 Pci2
= (PCI_DEVICE_PATH
*) DevicePath2
;
300 if (Pci1
->Device
> Pci2
->Device
|| (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
> Pci2
->Function
)) {
304 if (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
== Pci2
->Function
) {
312 Do a comparison on 2 device paths.
314 @param[in] DevicePath1 The first device path.
315 @param[in] DevicePath2 The second device path.
317 @retval 0 The 2 device paths are the same.
318 @retval <0 DevicePath2 is greater than DevicePath1.
319 @retval >0 DevicePath1 is greater than DevicePath2.
323 DevPathCompareDefault (
324 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
325 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
331 ASSERT(DevicePath1
!= NULL
);
332 ASSERT(DevicePath2
!= NULL
);
334 DevPathSize1
= DevicePathNodeLength (DevicePath1
);
335 DevPathSize2
= DevicePathNodeLength (DevicePath2
);
336 if (DevPathSize1
> DevPathSize2
) {
338 } else if (DevPathSize1
< DevPathSize2
) {
341 return CompareMem (DevicePath1
, DevicePath2
, DevPathSize1
);
346 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
348 @param[in] DevicePathNode The node to get info on.
349 @param[in] MappingItem The info item to populate.
353 DevPathSerialHardDrive (
354 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
355 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
358 HARDDRIVE_DEVICE_PATH
*Hd
;
360 ASSERT(DevicePathNode
!= NULL
);
361 ASSERT(MappingItem
!= NULL
);
363 Hd
= (HARDDRIVE_DEVICE_PATH
*) DevicePathNode
;
364 if (MappingItem
->MTD
== MTDTypeUnknown
) {
365 MappingItem
->MTD
= MTDTypeHardDisk
;
368 AppendCSDNum (MappingItem
, Hd
->PartitionNumber
);
372 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
374 @param[in] DevicePathNode The node to get info on.
375 @param[in] MappingItem The info item to populate.
380 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
381 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
384 ATAPI_DEVICE_PATH
*Atapi
;
386 ASSERT(DevicePathNode
!= NULL
);
387 ASSERT(MappingItem
!= NULL
);
389 Atapi
= (ATAPI_DEVICE_PATH
*) DevicePathNode
;
390 AppendCSDNum (MappingItem
, (Atapi
->PrimarySecondary
* 2 + Atapi
->SlaveMaster
));
394 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
396 @param[in] DevicePathNode The node to get info on.
397 @param[in] MappingItem The info item to populate.
402 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
403 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
406 CDROM_DEVICE_PATH
*Cd
;
408 ASSERT(DevicePathNode
!= NULL
);
409 ASSERT(MappingItem
!= NULL
);
411 Cd
= (CDROM_DEVICE_PATH
*) DevicePathNode
;
412 MappingItem
->MTD
= MTDTypeCDRom
;
413 AppendCSDNum (MappingItem
, Cd
->BootEntry
);
417 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
419 @param[in] DevicePathNode The node to get info on.
420 @param[in] MappingItem The info item to populate.
425 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
426 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
429 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
431 ASSERT(DevicePathNode
!= NULL
);
432 ASSERT(MappingItem
!= NULL
);
434 Fibre
= (FIBRECHANNEL_DEVICE_PATH
*) DevicePathNode
;
435 AppendCSDNum (MappingItem
, Fibre
->WWN
);
436 AppendCSDNum (MappingItem
, Fibre
->Lun
);
440 DevicePathNode must be SerialUart type and this will populate the MappingItem.
442 @param[in] DevicePathNode The node to get info on.
443 @param[in] MappingItem The info item to populate.
448 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
449 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
452 UART_DEVICE_PATH
*Uart
;
454 ASSERT(DevicePathNode
!= NULL
);
455 ASSERT(MappingItem
!= NULL
);
457 Uart
= (UART_DEVICE_PATH
*) DevicePathNode
;
458 AppendCSDNum (MappingItem
, Uart
->BaudRate
);
459 AppendCSDNum (MappingItem
, Uart
->DataBits
);
460 AppendCSDNum (MappingItem
, Uart
->Parity
);
461 AppendCSDNum (MappingItem
, Uart
->StopBits
);
465 DevicePathNode must be SerialUSB type and this will populate the MappingItem.
467 @param[in] DevicePathNode The node to get info on.
468 @param[in] MappingItem The info item to populate.
473 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
474 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
477 USB_DEVICE_PATH
*Usb
;
479 ASSERT(DevicePathNode
!= NULL
);
480 ASSERT(MappingItem
!= NULL
);
482 Usb
= (USB_DEVICE_PATH
*) DevicePathNode
;
483 AppendCSDNum (MappingItem
, Usb
->ParentPortNumber
);
484 AppendCSDNum (MappingItem
, Usb
->InterfaceNumber
);
488 DevicePathNode must be SerialVendor type and this will populate the MappingItem.
490 @param[in] DevicePathNode The node to get info on.
491 @param[in] MappingItem The info item to populate.
495 DevPathSerialVendor (
496 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
497 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
500 VENDOR_DEVICE_PATH
*Vendor
;
501 SAS_DEVICE_PATH
*Sas
;
502 EFI_GUID SasVendorGuid
= DEVICE_PATH_MESSAGING_SAS
;
504 ASSERT(DevicePathNode
!= NULL
);
505 ASSERT(MappingItem
!= NULL
);
507 Vendor
= (VENDOR_DEVICE_PATH
*) DevicePathNode
;
508 AppendCSDGuid (MappingItem
, &Vendor
->Guid
);
510 if (CompareGuid (&SasVendorGuid
, &Vendor
->Guid
) == 0) {
511 Sas
= (SAS_DEVICE_PATH
*) Vendor
;
512 AppendCSDNum (MappingItem
, Sas
->SasAddress
);
513 AppendCSDNum (MappingItem
, Sas
->Lun
);
514 AppendCSDNum (MappingItem
, Sas
->DeviceTopology
);
515 AppendCSDNum (MappingItem
, Sas
->RelativeTargetPort
);
520 DevicePathNode must be SerialLun type and this will populate the MappingItem.
522 @param[in] DevicePathNode The node to get info on.
523 @param[in] MappingItem The info item to populate.
528 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
529 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
532 DEVICE_LOGICAL_UNIT_DEVICE_PATH
*Lun
;
534 ASSERT(DevicePathNode
!= NULL
);
535 ASSERT(MappingItem
!= NULL
);
537 Lun
= (DEVICE_LOGICAL_UNIT_DEVICE_PATH
*) DevicePathNode
;
538 AppendCSDNum (MappingItem
, Lun
->Lun
);
542 DevicePathNode must be SerialSata type and this will populate the MappingItem.
544 @param[in] DevicePathNode The node to get info on.
545 @param[in] MappingItem The info item to populate.
550 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
551 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
554 SATA_DEVICE_PATH
*Sata
;
556 ASSERT(DevicePathNode
!= NULL
);
557 ASSERT(MappingItem
!= NULL
);
559 Sata
= (SATA_DEVICE_PATH
*) DevicePathNode
;
560 AppendCSDNum (MappingItem
, Sata
->HBAPortNumber
);
561 AppendCSDNum (MappingItem
, Sata
->PortMultiplierPortNumber
);
562 AppendCSDNum (MappingItem
, Sata
->Lun
);
566 DevicePathNode must be SerialSCSI type and this will populate the MappingItem.
568 @param[in] DevicePathNode The node to get info on.
569 @param[in] MappingItem The info item to populate.
574 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
575 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
578 ///@todo make this a PCD
580 // As CSD of ISCSI node is quite long, we comment
581 // the code below to keep the consistent mapping
582 // short. Uncomment if you really need it.
585 ISCSI_DEVICE_PATH *IScsi;
586 UINT8 *IScsiTargetName;
588 UINTN TargetNameLength;
591 ASSERT(DevicePathNode != NULL);
592 ASSERT(MappingItem != NULL);
594 IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode;
595 AppendCSDNum (MappingItem, IScsi->NetworkProtocol);
596 AppendCSDNum (MappingItem, IScsi->LoginOption);
597 AppendCSDNum (MappingItem, IScsi->Lun);
598 AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag);
599 TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH);
600 if (TargetNameLength > 0) {
601 TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16));
602 if (TargetName != NULL) {
603 IScsiTargetName = (UINT8 *) (IScsi + 1);
604 for (Index = 0; Index < TargetNameLength; Index++) {
605 TargetName[Index] = (CHAR16) IScsiTargetName[Index];
607 AppendCSDStr (MappingItem, TargetName);
608 FreePool (TargetName);
615 DevicePathNode must be SerialI20 type and this will populate the MappingItem.
617 @param[in] DevicePathNode The node to get info on.
618 @param[in] MappingItem The info item to populate.
623 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
624 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
627 I2O_DEVICE_PATH
*I2O
;
629 ASSERT(DevicePathNode
!= NULL
);
630 ASSERT(MappingItem
!= NULL
);
632 I2O
= (I2O_DEVICE_PATH
*) DevicePathNode
;
633 AppendCSDNum (MappingItem
, I2O
->Tid
);
637 DevicePathNode must be Mac Address type and this will populate the MappingItem.
639 @param[in] DevicePathNode The node to get info on.
640 @param[in] MappingItem The info item to populate.
644 DevPathSerialMacAddr (
645 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
646 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
649 MAC_ADDR_DEVICE_PATH
*Mac
;
655 ASSERT(DevicePathNode
!= NULL
);
656 ASSERT(MappingItem
!= NULL
);
658 Mac
= (MAC_ADDR_DEVICE_PATH
*) DevicePathNode
;
660 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
661 if (Mac
->IfType
== 0x01 || Mac
->IfType
== 0x00) {
665 for (Index
= 0, PBuffer
= Buffer
; Index
< HwAddressSize
; Index
++, PBuffer
+= 2) {
666 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Mac
->MacAddress
.Addr
[Index
]);
669 AppendCSDStr (MappingItem
, Buffer
);
673 DevicePathNode must be InfiniBand type and this will populate the MappingItem.
675 @param[in] DevicePathNode The node to get info on.
676 @param[in] MappingItem The info item to populate.
680 DevPathSerialInfiniBand (
681 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
682 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
685 INFINIBAND_DEVICE_PATH
*InfiniBand
;
690 ASSERT(DevicePathNode
!= NULL
);
691 ASSERT(MappingItem
!= NULL
);
693 InfiniBand
= (INFINIBAND_DEVICE_PATH
*) DevicePathNode
;
694 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
695 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) InfiniBand
->PortGid
[Index
]);
698 AppendCSDStr (MappingItem
, Buffer
);
699 AppendCSDNum (MappingItem
, InfiniBand
->ServiceId
);
700 AppendCSDNum (MappingItem
, InfiniBand
->TargetPortId
);
701 AppendCSDNum (MappingItem
, InfiniBand
->DeviceId
);
705 DevicePathNode must be IPv4 type and this will populate the MappingItem.
707 @param[in] DevicePathNode The node to get info on.
708 @param[in] MappingItem The info item to populate.
713 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
714 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
717 IPv4_DEVICE_PATH
*Ip
;
720 ASSERT(DevicePathNode
!= NULL
);
721 ASSERT(MappingItem
!= NULL
);
723 Ip
= (IPv4_DEVICE_PATH
*) DevicePathNode
;
728 (UINTN
) Ip
->LocalIpAddress
.Addr
[0],
729 (UINTN
) Ip
->LocalIpAddress
.Addr
[1],
730 (UINTN
) Ip
->LocalIpAddress
.Addr
[2],
731 (UINTN
) Ip
->LocalIpAddress
.Addr
[3]
733 AppendCSDStr (MappingItem
, Buffer
);
734 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
739 (UINTN
) Ip
->RemoteIpAddress
.Addr
[0],
740 (UINTN
) Ip
->RemoteIpAddress
.Addr
[1],
741 (UINTN
) Ip
->RemoteIpAddress
.Addr
[2],
742 (UINTN
) Ip
->RemoteIpAddress
.Addr
[3]
744 AppendCSDStr (MappingItem
, Buffer
);
745 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
749 DevicePathNode must be IPv6 type and this will populate the MappingItem.
751 @param[in] DevicePathNode The node to get info on.
752 @param[in] MappingItem The info item to populate.
757 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
758 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
761 IPv6_DEVICE_PATH
*Ip
;
766 ASSERT(DevicePathNode
!= NULL
);
767 ASSERT(MappingItem
!= NULL
);
769 Ip
= (IPv6_DEVICE_PATH
*) DevicePathNode
;
770 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
771 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->LocalIpAddress
.Addr
[Index
]);
774 AppendCSDStr (MappingItem
, Buffer
);
775 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
776 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
777 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->RemoteIpAddress
.Addr
[Index
]);
780 AppendCSDStr (MappingItem
, Buffer
);
781 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
785 DevicePathNode must be SCSI 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.
793 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
794 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
797 SCSI_DEVICE_PATH
*Scsi
;
799 ASSERT(DevicePathNode
!= NULL
);
800 ASSERT(MappingItem
!= NULL
);
802 Scsi
= (SCSI_DEVICE_PATH
*) DevicePathNode
;
803 AppendCSDNum (MappingItem
, Scsi
->Pun
);
804 AppendCSDNum (MappingItem
, Scsi
->Lun
);
808 DevicePathNode must be 1394 type and this will populate the MappingItem.
810 @param[in] DevicePathNode The node to get info on.
811 @param[in] MappingItem The info item to populate.
816 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
817 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
820 F1394_DEVICE_PATH
*F1394
;
823 ASSERT(DevicePathNode
!= NULL
);
824 ASSERT(MappingItem
!= NULL
);
826 F1394
= (F1394_DEVICE_PATH
*) DevicePathNode
;
827 UnicodeSPrint (Buffer
, 0, L
"%lx", F1394
->Guid
);
828 AppendCSDStr (MappingItem
, Buffer
);
832 If the node is floppy type then populate the MappingItem.
834 @param[in] DevicePathNode The node to get info on.
835 @param[in] MappingItem The info item to populate.
840 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
841 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
844 ACPI_HID_DEVICE_PATH
*Acpi
;
846 ASSERT(DevicePathNode
!= NULL
);
847 ASSERT(MappingItem
!= NULL
);
849 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
850 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
851 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
852 MappingItem
->MTD
= MTDTypeFloppy
;
853 AppendCSDNum (MappingItem
, Acpi
->UID
);
859 Empty function used for unknown devices.
865 DevPathSerialDefault (
866 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
867 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
872 DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable
[] = {
873 HARDWARE_DEVICE_PATH
,
875 DevPathSerialDefault
,
881 MESSAGING_DEVICE_PATH
,
884 DevPathCompareDefault
,
885 MESSAGING_DEVICE_PATH
,
888 DevPathCompareDefault
,
889 MESSAGING_DEVICE_PATH
,
892 DevPathCompareDefault
,
893 MESSAGING_DEVICE_PATH
,
896 DevPathCompareDefault
,
897 MESSAGING_DEVICE_PATH
,
900 DevPathCompareDefault
,
901 MESSAGING_DEVICE_PATH
,
904 DevPathCompareDefault
,
905 MESSAGING_DEVICE_PATH
,
907 DevPathSerialMacAddr
,
908 DevPathCompareDefault
,
909 MESSAGING_DEVICE_PATH
,
912 DevPathCompareDefault
,
913 MESSAGING_DEVICE_PATH
,
916 DevPathCompareDefault
,
917 MESSAGING_DEVICE_PATH
,
919 DevPathSerialInfiniBand
,
920 DevPathCompareDefault
,
921 MESSAGING_DEVICE_PATH
,
924 DevPathCompareDefault
,
925 MESSAGING_DEVICE_PATH
,
928 DevPathCompareDefault
,
929 MESSAGING_DEVICE_PATH
,
930 MSG_DEVICE_LOGICAL_UNIT_DP
,
932 DevPathCompareDefault
,
933 MESSAGING_DEVICE_PATH
,
936 DevPathCompareDefault
,
937 MESSAGING_DEVICE_PATH
,
940 DevPathCompareDefault
,
943 DevPathSerialHardDrive
,
944 DevPathCompareDefault
,
948 DevPathCompareDefault
,
952 DevPathCompareDefault
,
960 Function to determine if a device path node is Hi or not.
962 @param[in] DevicePathNode The node to check.
964 @retval TRUE The node is HI.
965 @retval FALSE The node is not HI.
970 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
973 ACPI_HID_DEVICE_PATH
*Acpi
;
975 ASSERT(DevicePathNode
!= NULL
);
977 if (DevicePathNode
->Type
== HARDWARE_DEVICE_PATH
) {
981 if (DevicePathNode
->Type
== ACPI_DEVICE_PATH
) {
982 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
983 switch (EISA_ID_TO_NUM (Acpi
->HID
)) {
998 Function to convert a standard device path structure into a HI version.
1000 @param[in] DevicePath The device path to convert.
1002 @return the device path portion that is HI.
1004 EFI_DEVICE_PATH_PROTOCOL
*
1007 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1010 UINTN NonHIDevicePathNodeCount
;
1013 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1014 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1016 ASSERT(DevicePath
!= NULL
);
1018 NonHIDevicePathNodeCount
= 0;
1020 HIDevicePath
= AllocatePool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1021 SetDevicePathEndNode (HIDevicePath
);
1023 Node
.DevPath
.Type
= END_DEVICE_PATH_TYPE
;
1024 Node
.DevPath
.SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
1025 Node
.DevPath
.Length
[0] = (UINT8
)sizeof (EFI_DEVICE_PATH_PROTOCOL
);
1026 Node
.DevPath
.Length
[1] = 0;
1028 while (!IsDevicePathEnd (DevicePath
)) {
1029 if (IsHIDevicePathNode (DevicePath
)) {
1030 for (Index
= 0; Index
< NonHIDevicePathNodeCount
; Index
++) {
1031 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, &Node
.DevPath
);
1032 FreePool (HIDevicePath
);
1033 HIDevicePath
= TempDevicePath
;
1036 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, DevicePath
);
1037 FreePool (HIDevicePath
);
1038 HIDevicePath
= TempDevicePath
;
1040 NonHIDevicePathNodeCount
++;
1043 // Next device path node
1045 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1048 return HIDevicePath
;
1052 Function to walk the device path looking for a dumpable node.
1054 @param[in] MappingItem The Item to fill with data.
1055 @param[in] DevicePath The path of the item to get data on.
1057 @return EFI_SUCCESS Always returns success.
1061 GetDeviceConsistMappingInfo (
1062 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1063 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1066 VOID (*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*, DEVICE_CONSIST_MAPPING_INFO
*);
1070 ASSERT(DevicePath
!= NULL
);
1071 ASSERT(MappingItem
!= NULL
);
1073 SetMem (&MappingItem
->CSD
, sizeof (POOL_PRINT
), 0);
1075 while (!IsDevicePathEnd (DevicePath
)) {
1077 // Find the handler to dump this device path node
1080 for (Index
= 0; DevPathConsistMappingTable
[Index
].SerialFun
!= NULL
; Index
+= 1) {
1082 if (DevicePathType (DevicePath
) == DevPathConsistMappingTable
[Index
].Type
&&
1083 DevicePathSubType (DevicePath
) == DevPathConsistMappingTable
[Index
].SubType
1085 SerialFun
= DevPathConsistMappingTable
[Index
].SerialFun
;
1090 // If not found, use a generic function
1093 SerialFun
= DevPathSerialDefault
;
1096 SerialFun (DevicePath
, MappingItem
);
1099 // Next device path node
1101 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1108 Function to initialize the table for creating consistent map names.
1110 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
1112 @retval EFI_SUCCESS The table was created successfully.
1116 ShellCommandConsistMappingInitialize (
1117 OUT EFI_DEVICE_PATH_PROTOCOL
***Table
1120 EFI_HANDLE
*HandleBuffer
;
1123 EFI_DEVICE_PATH_PROTOCOL
**TempTable
;
1124 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1125 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1129 HandleBuffer
= NULL
;
1131 Status
= gBS
->LocateHandleBuffer (
1138 ASSERT_EFI_ERROR(Status
);
1140 TempTable
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
1141 if (TempTable
== NULL
) {
1142 return EFI_OUT_OF_RESOURCES
;
1145 for (HandleLoop
= 0 ; HandleLoop
< HandleNum
; HandleLoop
++) {
1146 DevicePath
= DevicePathFromHandle (HandleBuffer
[HandleLoop
]);
1147 if (DevicePath
== NULL
) {
1151 HIDevicePath
= GetHIDevicePath (DevicePath
);
1152 if (HIDevicePath
== NULL
) {
1156 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++) {
1157 if (DevicePathCompare (&TempTable
[Index
], &HIDevicePath
) == 0) {
1158 FreePool (HIDevicePath
);
1163 if (TempTable
[Index
] == NULL
) {
1164 TempTable
[Index
] = HIDevicePath
;
1168 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++);
1169 PerformQuickSort(TempTable
, Index
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1172 if (HandleBuffer
!= NULL
) {
1173 FreePool (HandleBuffer
);
1180 Function to uninitialize the table for creating consistent map names.
1182 The parameter must have been received from ShellCommandConsistMappingInitialize.
1184 @param[out] Table The pointer to pointer to DevicePathProtocol object.
1186 @retval EFI_SUCCESS The table was deleted successfully.
1190 ShellCommandConsistMappingUnInitialize (
1191 EFI_DEVICE_PATH_PROTOCOL
**Table
1196 ASSERT(Table
!= NULL
);
1198 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1199 FreePool (Table
[Index
]);
1207 Create a consistent mapped name for the device specified by DevicePath
1210 This must be called after ShellCommandConsistMappingInitialize() and
1211 before ShellCommandConsistMappingUnInitialize() is called.
1213 @param[in] DeviecPath The pointer to the dev path for the device.
1214 @param[in] Table The Table of mapping information.
1216 @retval NULL A consistent mapped name could not be created.
1217 @return A pointer to a string allocated from pool with the device name.
1221 ShellCommandConsistMappingGenMappingName (
1222 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1223 EFI_DEVICE_PATH_PROTOCOL
**Table
1227 DEVICE_CONSIST_MAPPING_INFO MappingInfo
;
1228 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1232 ASSERT(DevicePath
!= NULL
);
1233 ASSERT(Table
!= NULL
);
1235 HIDevicePath
= GetHIDevicePath (DevicePath
);
1236 if (HIDevicePath
== NULL
) {
1240 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1241 if (DevicePathCompare (&Table
[Index
], &HIDevicePath
) == 0) {
1246 FreePool (HIDevicePath
);
1247 if (Table
[Index
] == NULL
) {
1251 MappingInfo
.HI
= Index
;
1252 MappingInfo
.MTD
= MTDTypeUnknown
;
1253 MappingInfo
.Digital
= FALSE
;
1255 GetDeviceConsistMappingInfo (&MappingInfo
, DevicePath
);
1257 SetMem (&Str
, sizeof (Str
), 0);
1258 for (Index
= 0; mMTDName
[Index
].MTDType
!= MTDTypeEnd
; Index
++) {
1259 if (MappingInfo
.MTD
== mMTDName
[Index
].MTDType
) {
1264 if (mMTDName
[Index
].MTDType
!= MTDTypeEnd
) {
1265 CatPrint (&Str
, L
"%s", mMTDName
[Index
].Name
);
1268 CatPrint (&Str
, L
"%d", (UINTN
) MappingInfo
.HI
);
1269 if (MappingInfo
.CSD
.Str
!= NULL
) {
1270 CatPrint (&Str
, L
"%s", MappingInfo
.CSD
.Str
);
1271 FreePool (MappingInfo
.CSD
.Str
);
1274 if (Str
.Str
!= NULL
) {
1275 CatPrint (&Str
, L
":");
1278 NewSize
= (Str
.Len
+ 1) * sizeof (CHAR16
);
1279 Str
.Str
= ReallocatePool (Str
.Len
, NewSize
, Str
.Str
);
1280 Str
.Str
[Str
.Len
] = CHAR_NULL
;
1285 Function to search the list of mappings for the node on the list based on the key.
1287 @param[in] MapKey String Key to search for on the map
1289 @return the node on the list.
1293 ShellCommandFindMapItem (
1294 IN CONST CHAR16
*MapKey
1297 SHELL_MAP_LIST
*MapListItem
;
1299 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1300 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
1301 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
1303 if (gUnicodeCollation
->StriColl(gUnicodeCollation
,MapListItem
->MapName
,(CHAR16
*)MapKey
) == 0) {
1304 return (MapListItem
);