1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
|
/** @file
Main file for support of shell consist mapping.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "UefiShellCommandLib.h"
#include <Library/DevicePathLib.h>
#include <Library/SortLib.h>
#include <Library/UefiLib.h>
#include <Protocol/UsbIo.h>
#include <Protocol/BlockIo.h>
#include <Protocol/SimpleFileSystem.h>
typedef enum {
MTDTypeUnknown,
MTDTypeFloppy,
MTDTypeHardDisk,
MTDTypeCDRom,
MTDTypeEnd
} MTD_TYPE;
typedef struct {
CHAR16 *Str;
UINTN Len;
} POOL_PRINT;
typedef struct {
UINTN Hi;
MTD_TYPE Mtd;
POOL_PRINT Csd;
BOOLEAN Digital;
} DEVICE_CONSIST_MAPPING_INFO;
typedef struct {
MTD_TYPE MTDType;
CHAR16 *Name;
} MTD_NAME;
/**
Serial Decode function.
@param DevPath The Device path info.
@param MapInfo The map info.
@param OrigDevPath The original device path protocol.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
typedef
EFI_STATUS
(*SERIAL_DECODE_FUNCTION) (
EFI_DEVICE_PATH_PROTOCOL *DevPath,
DEVICE_CONSIST_MAPPING_INFO *MapInfo,
EFI_DEVICE_PATH_PROTOCOL *OrigDevPath
);
typedef struct {
UINT8 Type;
UINT8 SubType;
SERIAL_DECODE_FUNCTION SerialFun;
INTN (EFIAPI *CompareFun)(EFI_DEVICE_PATH_PROTOCOL *DevPath, EFI_DEVICE_PATH_PROTOCOL *DevPath2);
} DEV_PATH_CONSIST_MAPPING_TABLE;
/**
Concatenates a formatted unicode string to allocated pool.
The caller must free the resulting buffer.
@param Str Tracks the allocated pool, size in use, and amount of pool allocated.
@param Fmt The format string
@param ... The data will be printed.
@retval EFI_SUCCESS The string is concatenated successfully.
@retval EFI_OUT_OF_RESOURCES Out of resources.
**/
EFI_STATUS
EFIAPI
CatPrint (
IN OUT POOL_PRINT *Str,
IN CHAR16 *Fmt,
...
)
{
UINT16 *AppendStr;
VA_LIST Args;
UINTN StringSize;
CHAR16 *NewStr;
AppendStr = AllocateZeroPool (0x1000);
if (AppendStr == NULL) {
return EFI_OUT_OF_RESOURCES;
}
VA_START (Args, Fmt);
UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);
VA_END (Args);
if (NULL == Str->Str) {
StringSize = StrSize (AppendStr);
NewStr = AllocateZeroPool (StringSize);
} else {
StringSize = StrSize (AppendStr);
StringSize += (StrSize (Str->Str) - sizeof (UINT16));
NewStr = ReallocatePool (
StrSize (Str->Str),
StringSize,
Str->Str
);
}
if (NewStr == NULL) {
FreePool (AppendStr);
return EFI_OUT_OF_RESOURCES;
}
Str->Str = NewStr;
StrCatS (Str->Str, StringSize/sizeof (CHAR16), AppendStr);
Str->Len = StringSize;
FreePool (AppendStr);
return EFI_SUCCESS;
}
MTD_NAME mMTDName[] = {
{
MTDTypeUnknown,
L"F"
},
{
MTDTypeFloppy,
L"FP"
},
{
MTDTypeHardDisk,
L"HD"
},
{
MTDTypeCDRom,
L"CD"
},
{
MTDTypeEnd,
NULL
}
};
/**
Function to append a 64 bit number / 25 onto the string.
@param[in, out] Str The string so append onto.
@param[in] Num The number to divide and append.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
AppendCSDNum2 (
IN OUT POOL_PRINT *Str,
IN UINT64 Num
)
{
EFI_STATUS Status;
UINT64 Result;
UINT32 Rem;
ASSERT (Str != NULL);
Result = DivU64x32Remainder (Num, 25, &Rem);
if (Result > 0) {
Status = AppendCSDNum2 (Str, Result);
if (EFI_ERROR (Status)) {
return Status;
}
}
return CatPrint (Str, L"%c", Rem + 'a');
}
/**
Function to append a 64 bit number onto the mapping info.
@param[in, out] MappingItem The mapping info object to append onto.
@param[in] Num The info to append.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
AppendCSDNum (
IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN UINT64 Num
)
{
EFI_STATUS Status;
ASSERT (MappingItem != NULL);
if (MappingItem->Digital) {
Status = CatPrint (&MappingItem->Csd, L"%ld", Num);
} else {
Status = AppendCSDNum2 (&MappingItem->Csd, Num);
}
if (!EFI_ERROR (Status)) {
MappingItem->Digital = (BOOLEAN) !(MappingItem->Digital);
}
return Status;
}
/**
Function to append string into the mapping info.
@param[in, out] MappingItem The mapping info object to append onto.
@param[in] Str The info to append.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
AppendCSDStr (
IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN CHAR16 *Str
)
{
CHAR16 *Index;
EFI_STATUS Status;
ASSERT (Str != NULL && MappingItem != NULL);
Status = EFI_SUCCESS;
if (MappingItem->Digital) {
//
// To aVOID mult-meaning, the mapping is:
// 0 1 2 3 4 5 6 7 8 9 a b c d e f
// 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
for (Index = Str; *Index != 0; Index++) {
switch (*Index) {
case '0':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
Status = CatPrint (&MappingItem->Csd, L"%c", *Index);
break;
case '1':
Status = CatPrint (&MappingItem->Csd, L"16");
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
Status = CatPrint (&MappingItem->Csd, L"1%c", *Index - 'a' + '0');
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
Status = CatPrint (&MappingItem->Csd, L"1%c", *Index - 'A' + '0');
break;
}
if (EFI_ERROR (Status)) {
return Status;
}
}
} else {
for (Index = Str; *Index != 0; Index++) {
//
// The mapping is:
// 0 1 2 3 4 5 6 7 8 9 a b c d e f
// a b c d e f g h i j k l m n o p
//
if ((*Index >= '0') && (*Index <= '9')) {
Status = CatPrint (&MappingItem->Csd, L"%c", *Index - '0' + 'a');
} else if ((*Index >= 'a') && (*Index <= 'f')) {
Status = CatPrint (&MappingItem->Csd, L"%c", *Index - 'a' + 'k');
} else if ((*Index >= 'A') && (*Index <= 'F')) {
Status = CatPrint (&MappingItem->Csd, L"%c", *Index - 'A' + 'k');
}
if (EFI_ERROR (Status)) {
return Status;
}
}
}
MappingItem->Digital = (BOOLEAN) !(MappingItem->Digital);
return (EFI_SUCCESS);
}
/**
Function to append a Guid to the mapping item.
@param[in, out] MappingItem The item to append onto.
@param[in] Guid The guid to append.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
AppendCSDGuid (
DEVICE_CONSIST_MAPPING_INFO *MappingItem,
EFI_GUID *Guid
)
{
CHAR16 Buffer[64];
ASSERT (Guid != NULL && MappingItem != NULL);
UnicodeSPrint (
Buffer,
0,
L"%g",
Guid
);
return AppendCSDStr (MappingItem, Buffer);
}
/**
Function to compare 2 APCI device paths.
@param[in] DevicePath1 The first device path to compare.
@param[in] DevicePath2 The second device path to compare.
@retval 0 The device paths represent the same device.
@return Non zero if the devices are different, zero otherwise.
**/
INTN
EFIAPI
DevPathCompareAcpi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2
)
{
ACPI_HID_DEVICE_PATH *Acpi1;
ACPI_HID_DEVICE_PATH *Acpi2;
if ((DevicePath1 == NULL) || (DevicePath2 == NULL)) {
return (-2);
}
Acpi1 = (ACPI_HID_DEVICE_PATH *)DevicePath1;
Acpi2 = (ACPI_HID_DEVICE_PATH *)DevicePath2;
if ((Acpi1->HID > Acpi2->HID) || ((Acpi1->HID == Acpi2->HID) && (Acpi1->UID > Acpi2->UID))) {
return 1;
}
if ((Acpi1->HID == Acpi2->HID) && (Acpi1->UID == Acpi2->UID)) {
return 0;
}
return -1;
}
/**
Function to compare 2 PCI device paths.
@param[in] DevicePath1 The first device path to compare.
@param[in] DevicePath2 The second device path to compare.
@retval 0 The device paths represent the same device.
@return Non zero if the devices are different, zero otherwise.
**/
INTN
EFIAPI
DevPathComparePci (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2
)
{
PCI_DEVICE_PATH *Pci1;
PCI_DEVICE_PATH *Pci2;
ASSERT (DevicePath1 != NULL);
ASSERT (DevicePath2 != NULL);
Pci1 = (PCI_DEVICE_PATH *)DevicePath1;
Pci2 = (PCI_DEVICE_PATH *)DevicePath2;
if ((Pci1->Device > Pci2->Device) || ((Pci1->Device == Pci2->Device) && (Pci1->Function > Pci2->Function))) {
return 1;
}
if ((Pci1->Device == Pci2->Device) && (Pci1->Function == Pci2->Function)) {
return 0;
}
return -1;
}
/**
Do a comparison on 2 device paths.
@param[in] DevicePath1 The first device path.
@param[in] DevicePath2 The second device path.
@retval 0 The 2 device paths are the same.
@retval <0 DevicePath2 is greater than DevicePath1.
@retval >0 DevicePath1 is greater than DevicePath2.
**/
INTN
EFIAPI
DevPathCompareDefault (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2
)
{
UINTN DevPathSize1;
UINTN DevPathSize2;
ASSERT (DevicePath1 != NULL);
ASSERT (DevicePath2 != NULL);
DevPathSize1 = DevicePathNodeLength (DevicePath1);
DevPathSize2 = DevicePathNodeLength (DevicePath2);
if (DevPathSize1 > DevPathSize2) {
return 1;
} else if (DevPathSize1 < DevPathSize2) {
return -1;
} else {
return CompareMem (DevicePath1, DevicePath2, DevPathSize1);
}
}
/**
DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialHardDrive (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
HARDDRIVE_DEVICE_PATH *Hd;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Hd = (HARDDRIVE_DEVICE_PATH *)DevicePathNode;
if (MappingItem->Mtd == MTDTypeUnknown) {
MappingItem->Mtd = MTDTypeHardDisk;
}
return AppendCSDNum (MappingItem, Hd->PartitionNumber);
}
/**
DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialAtapi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
ATAPI_DEVICE_PATH *Atapi;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Atapi = (ATAPI_DEVICE_PATH *)DevicePathNode;
return AppendCSDNum (MappingItem, (Atapi->PrimarySecondary * 2 + Atapi->SlaveMaster));
}
/**
DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialCdRom (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
CDROM_DEVICE_PATH *Cd;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Cd = (CDROM_DEVICE_PATH *)DevicePathNode;
MappingItem->Mtd = MTDTypeCDRom;
return AppendCSDNum (MappingItem, Cd->BootEntry);
}
/**
DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialFibre (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
FIBRECHANNEL_DEVICE_PATH *Fibre;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Fibre = (FIBRECHANNEL_DEVICE_PATH *)DevicePathNode;
Status = AppendCSDNum (MappingItem, Fibre->WWN);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Fibre->Lun);
}
return Status;
}
/**
DevicePathNode must be SerialUart type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialUart (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
UART_DEVICE_PATH *Uart;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Uart = (UART_DEVICE_PATH *)DevicePathNode;
Status = AppendCSDNum (MappingItem, Uart->BaudRate);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Uart->DataBits);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Uart->Parity);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Uart->StopBits);
}
return Status;
}
/**
DevicePathNode must be SerialUSB type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialUsb (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
USB_DEVICE_PATH *Usb;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_HANDLE TempHandle;
EFI_STATUS Status;
USB_INTERFACE_DESCRIPTOR InterfaceDesc;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Usb = (USB_DEVICE_PATH *)DevicePathNode;
Status = AppendCSDNum (MappingItem, Usb->ParentPortNumber);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Usb->InterfaceNumber);
}
if (EFI_ERROR (Status)) {
return Status;
}
if (PcdGetBool (PcdUsbExtendedDecode)) {
Status = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid, &DevicePath, &TempHandle);
UsbIo = NULL;
if (!EFI_ERROR (Status)) {
Status = gBS->OpenProtocol (TempHandle, &gEfiUsbIoProtocolGuid, (VOID **)&UsbIo, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
}
if (!EFI_ERROR (Status)) {
ASSERT (UsbIo != NULL);
Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &InterfaceDesc);
if (!EFI_ERROR (Status)) {
if ((InterfaceDesc.InterfaceClass == USB_MASS_STORE_CLASS) && (MappingItem->Mtd == MTDTypeUnknown)) {
switch (InterfaceDesc.InterfaceSubClass) {
case USB_MASS_STORE_SCSI:
MappingItem->Mtd = MTDTypeHardDisk;
break;
case USB_MASS_STORE_8070I:
case USB_MASS_STORE_UFI:
MappingItem->Mtd = MTDTypeFloppy;
break;
case USB_MASS_STORE_8020I:
MappingItem->Mtd = MTDTypeCDRom;
break;
}
}
}
}
}
return Status;
}
/**
DevicePathNode must be SerialVendor type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialVendor (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
VENDOR_DEVICE_PATH *Vendor;
SAS_DEVICE_PATH *Sas;
UINTN TargetNameLength;
UINTN Index;
CHAR16 *Buffer;
CHAR16 *NewBuffer;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Vendor = (VENDOR_DEVICE_PATH *)DevicePathNode;
Status = AppendCSDGuid (MappingItem, &Vendor->Guid);
if (EFI_ERROR (Status)) {
return Status;
}
if (CompareGuid (&gEfiSasDevicePathGuid, &Vendor->Guid)) {
Sas = (SAS_DEVICE_PATH *)Vendor;
Status = AppendCSDNum (MappingItem, Sas->SasAddress);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Sas->Lun);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Sas->DeviceTopology);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Sas->RelativeTargetPort);
}
} else {
TargetNameLength = MIN (DevicePathNodeLength (DevicePathNode) - sizeof (VENDOR_DEVICE_PATH), PcdGet32 (PcdShellVendorExtendedDecode));
if (TargetNameLength != 0) {
//
// String is 2 chars per data byte, plus NULL terminator
//
Buffer = AllocateZeroPool (((TargetNameLength * 2) + 1) * sizeof (CHAR16));
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Build the string data
//
for (Index = 0; Index < TargetNameLength; Index++) {
NewBuffer = CatSPrint (Buffer, L"%02x", *((UINT8 *)Vendor + sizeof (VENDOR_DEVICE_PATH) + Index));
if (NewBuffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
break;
}
Buffer = NewBuffer;
}
//
// Append the new data block
//
if (!EFI_ERROR (Status)) {
Status = AppendCSDStr (MappingItem, Buffer);
}
FreePool (Buffer);
}
}
return Status;
}
/**
DevicePathNode must be SerialLun type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialLun (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
DEVICE_LOGICAL_UNIT_DEVICE_PATH *Lun;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Lun = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *)DevicePathNode;
return AppendCSDNum (MappingItem, Lun->Lun);
}
/**
DevicePathNode must be SerialSata type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialSata (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
SATA_DEVICE_PATH *Sata;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Sata = (SATA_DEVICE_PATH *)DevicePathNode;
Status = AppendCSDNum (MappingItem, Sata->HBAPortNumber);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Sata->PortMultiplierPortNumber);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Sata->Lun);
}
return Status;
}
/**
DevicePathNode must be SerialSCSI type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialIScsi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
ISCSI_DEVICE_PATH *IScsi;
UINT8 *IScsiTargetName;
CHAR16 *TargetName;
UINTN TargetNameLength;
UINTN Index;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Status = EFI_SUCCESS;
if (PcdGetBool (PcdShellDecodeIScsiMapNames)) {
IScsi = (ISCSI_DEVICE_PATH *)DevicePathNode;
Status = AppendCSDNum (MappingItem, IScsi->NetworkProtocol);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, IScsi->LoginOption);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, IScsi->Lun);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag);
}
if (EFI_ERROR (Status)) {
return Status;
}
TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH);
if (TargetNameLength > 0) {
TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16));
if (TargetName == NULL) {
Status = EFI_OUT_OF_RESOURCES;
} else {
IScsiTargetName = (UINT8 *)(IScsi + 1);
for (Index = 0; Index < TargetNameLength; Index++) {
TargetName[Index] = (CHAR16)IScsiTargetName[Index];
}
Status = AppendCSDStr (MappingItem, TargetName);
FreePool (TargetName);
}
}
}
return Status;
}
/**
DevicePathNode must be SerialI20 type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialI2O (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
I2O_DEVICE_PATH *DevicePath_I20;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
DevicePath_I20 = (I2O_DEVICE_PATH *)DevicePathNode;
return AppendCSDNum (MappingItem, DevicePath_I20->Tid);
}
/**
DevicePathNode must be Mac Address type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialMacAddr (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
MAC_ADDR_DEVICE_PATH *Mac;
UINTN HwAddressSize;
UINTN Index;
CHAR16 Buffer[64];
CHAR16 *PBuffer;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Mac = (MAC_ADDR_DEVICE_PATH *)DevicePathNode;
HwAddressSize = sizeof (EFI_MAC_ADDRESS);
if ((Mac->IfType == 0x01) || (Mac->IfType == 0x00)) {
HwAddressSize = 6;
}
for (Index = 0, PBuffer = Buffer; Index < HwAddressSize; Index++, PBuffer += 2) {
UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN)Mac->MacAddress.Addr[Index]);
}
return AppendCSDStr (MappingItem, Buffer);
}
/**
DevicePathNode must be InfiniBand type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialInfiniBand (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
INFINIBAND_DEVICE_PATH *InfiniBand;
UINTN Index;
CHAR16 Buffer[64];
CHAR16 *PBuffer;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
InfiniBand = (INFINIBAND_DEVICE_PATH *)DevicePathNode;
for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {
UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN)InfiniBand->PortGid[Index]);
}
Status = AppendCSDStr (MappingItem, Buffer);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, InfiniBand->ServiceId);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, InfiniBand->TargetPortId);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, InfiniBand->DeviceId);
}
return Status;
}
/**
DevicePathNode must be IPv4 type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialIPv4 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
IPv4_DEVICE_PATH *Ip;
CHAR16 Buffer[10];
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Ip = (IPv4_DEVICE_PATH *)DevicePathNode;
UnicodeSPrint (
Buffer,
0,
L"%02x%02x%02x%02x",
(UINTN)Ip->LocalIpAddress.Addr[0],
(UINTN)Ip->LocalIpAddress.Addr[1],
(UINTN)Ip->LocalIpAddress.Addr[2],
(UINTN)Ip->LocalIpAddress.Addr[3]
);
Status = AppendCSDStr (MappingItem, Buffer);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Ip->LocalPort);
}
if (!EFI_ERROR (Status)) {
UnicodeSPrint (
Buffer,
0,
L"%02x%02x%02x%02x",
(UINTN)Ip->RemoteIpAddress.Addr[0],
(UINTN)Ip->RemoteIpAddress.Addr[1],
(UINTN)Ip->RemoteIpAddress.Addr[2],
(UINTN)Ip->RemoteIpAddress.Addr[3]
);
Status = AppendCSDStr (MappingItem, Buffer);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Ip->RemotePort);
}
return Status;
}
/**
DevicePathNode must be IPv6 type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialIPv6 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
IPv6_DEVICE_PATH *Ip;
UINTN Index;
CHAR16 Buffer[64];
CHAR16 *PBuffer;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Ip = (IPv6_DEVICE_PATH *)DevicePathNode;
for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {
UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN)Ip->LocalIpAddress.Addr[Index]);
}
Status = AppendCSDStr (MappingItem, Buffer);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Ip->LocalPort);
}
if (!EFI_ERROR (Status)) {
for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {
UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN)Ip->RemoteIpAddress.Addr[Index]);
}
Status = AppendCSDStr (MappingItem, Buffer);
}
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Ip->RemotePort);
}
return Status;
}
/**
DevicePathNode must be SCSI type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialScsi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
SCSI_DEVICE_PATH *Scsi;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Scsi = (SCSI_DEVICE_PATH *)DevicePathNode;
Status = AppendCSDNum (MappingItem, Scsi->Pun);
if (!EFI_ERROR (Status)) {
Status = AppendCSDNum (MappingItem, Scsi->Lun);
}
return Status;
}
/**
DevicePathNode must be 1394 type and this will populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerial1394 (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
F1394_DEVICE_PATH *DevicePath_F1394;
CHAR16 Buffer[20];
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
DevicePath_F1394 = (F1394_DEVICE_PATH *)DevicePathNode;
UnicodeSPrint (Buffer, 0, L"%lx", DevicePath_F1394->Guid);
return AppendCSDStr (MappingItem, Buffer);
}
/**
If the node is floppy type then populate the MappingItem.
@param[in] DevicePathNode The node to get info on.
@param[in] MappingItem The info item to populate.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialAcpi (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
ACPI_HID_DEVICE_PATH *Acpi;
ASSERT (DevicePathNode != NULL);
ASSERT (MappingItem != NULL);
Acpi = (ACPI_HID_DEVICE_PATH *)DevicePathNode;
if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {
MappingItem->Mtd = MTDTypeFloppy;
return AppendCSDNum (MappingItem, Acpi->UID);
}
}
return EFI_SUCCESS;
}
/**
Empty function used for unknown devices.
@param[in] DevicePathNode Ignored.
@param[in] MappingItem Ignored.
@param[in] DevicePath Ignored.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS The appending was successful.
**/
EFI_STATUS
DevPathSerialDefault (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
return EFI_SUCCESS;
}
DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable[] = {
{
HARDWARE_DEVICE_PATH,
HW_PCI_DP,
DevPathSerialDefault,
DevPathComparePci
},
{
ACPI_DEVICE_PATH,
ACPI_DP,
DevPathSerialAcpi,
DevPathCompareAcpi
},
{
MESSAGING_DEVICE_PATH,
MSG_ATAPI_DP,
DevPathSerialAtapi,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_SCSI_DP,
DevPathSerialScsi,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_FIBRECHANNEL_DP,
DevPathSerialFibre,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_1394_DP,
DevPathSerial1394,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_USB_DP,
DevPathSerialUsb,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_I2O_DP,
DevPathSerialI2O,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_MAC_ADDR_DP,
DevPathSerialMacAddr,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_IPv4_DP,
DevPathSerialIPv4,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_IPv6_DP,
DevPathSerialIPv6,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_INFINIBAND_DP,
DevPathSerialInfiniBand,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_UART_DP,
DevPathSerialUart,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_VENDOR_DP,
DevPathSerialVendor,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_DEVICE_LOGICAL_UNIT_DP,
DevPathSerialLun,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_SATA_DP,
DevPathSerialSata,
DevPathCompareDefault
},
{
MESSAGING_DEVICE_PATH,
MSG_ISCSI_DP,
DevPathSerialIScsi,
DevPathCompareDefault
},
{
MEDIA_DEVICE_PATH,
MEDIA_HARDDRIVE_DP,
DevPathSerialHardDrive,
DevPathCompareDefault
},
{
MEDIA_DEVICE_PATH,
MEDIA_CDROM_DP,
DevPathSerialCdRom,
DevPathCompareDefault
},
{
MEDIA_DEVICE_PATH,
MEDIA_VENDOR_DP,
DevPathSerialVendor,
DevPathCompareDefault
},
{
0,
0,
NULL,
NULL
}
};
/**
Function to determine if a device path node is Hi or not.
@param[in] DevicePathNode The node to check.
@retval TRUE The node is Hi.
@retval FALSE The node is not Hi.
**/
BOOLEAN
IsHIDevicePathNode (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode
)
{
ACPI_HID_DEVICE_PATH *Acpi;
ASSERT (DevicePathNode != NULL);
if (DevicePathNode->Type == HARDWARE_DEVICE_PATH) {
return TRUE;
}
if (DevicePathNode->Type == ACPI_DEVICE_PATH) {
Acpi = (ACPI_HID_DEVICE_PATH *)DevicePathNode;
switch (EISA_ID_TO_NUM (Acpi->HID)) {
case 0x0301:
case 0x0401:
case 0x0501:
case 0x0604:
return FALSE;
}
return TRUE;
}
return FALSE;
}
/**
Function to convert a standard device path structure into a Hi version.
@param[in] DevicePath The device path to convert.
@return the device path portion that is Hi.
**/
EFI_DEVICE_PATH_PROTOCOL *
GetHIDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
UINTN NonHIDevicePathNodeCount;
UINTN Index;
EFI_DEV_PATH Node;
EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
ASSERT (DevicePath != NULL);
NonHIDevicePathNodeCount = 0;
HIDevicePath = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));
if (HIDevicePath == NULL) {
return NULL;
}
SetDevicePathEndNode (HIDevicePath);
Node.DevPath.Type = END_DEVICE_PATH_TYPE;
Node.DevPath.SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
Node.DevPath.Length[0] = (UINT8)sizeof (EFI_DEVICE_PATH_PROTOCOL);
Node.DevPath.Length[1] = 0;
while (!IsDevicePathEnd (DevicePath)) {
if (IsHIDevicePathNode (DevicePath)) {
for (Index = 0; Index < NonHIDevicePathNodeCount; Index++) {
TempDevicePath = AppendDevicePathNode (HIDevicePath, &Node.DevPath);
FreePool (HIDevicePath);
HIDevicePath = TempDevicePath;
}
TempDevicePath = AppendDevicePathNode (HIDevicePath, DevicePath);
FreePool (HIDevicePath);
HIDevicePath = TempDevicePath;
} else {
NonHIDevicePathNodeCount++;
}
//
// Next device path node
//
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)NextDevicePathNode (DevicePath);
}
return HIDevicePath;
}
/**
Function to walk the device path looking for a dumpable node.
@param[in] MappingItem The Item to fill with data.
@param[in] DevicePath The path of the item to get data on.
@return EFI_SUCCESS Always returns success.
**/
EFI_STATUS
GetDeviceConsistMappingInfo (
IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
SERIAL_DECODE_FUNCTION SerialFun;
UINTN Index;
EFI_DEVICE_PATH_PROTOCOL *OriginalDevicePath;
ASSERT (DevicePath != NULL);
ASSERT (MappingItem != NULL);
SetMem (&MappingItem->Csd, sizeof (POOL_PRINT), 0);
OriginalDevicePath = DevicePath;
while (!IsDevicePathEnd (DevicePath)) {
//
// Find the handler to dump this device path node and
// initialize with generic function in case nothing is found
//
for (SerialFun = DevPathSerialDefault, Index = 0; DevPathConsistMappingTable[Index].SerialFun != NULL; Index += 1) {
if ((DevicePathType (DevicePath) == DevPathConsistMappingTable[Index].Type) &&
(DevicePathSubType (DevicePath) == DevPathConsistMappingTable[Index].SubType)
)
{
SerialFun = DevPathConsistMappingTable[Index].SerialFun;
break;
}
}
Status = SerialFun (DevicePath, MappingItem, OriginalDevicePath);
if (EFI_ERROR (Status)) {
SHELL_FREE_NON_NULL (MappingItem->Csd.Str);
return Status;
}
//
// Next device path node
//
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)NextDevicePathNode (DevicePath);
}
return EFI_SUCCESS;
}
/**
Function to initialize the table for creating consistent map names.
@param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
@retval EFI_SUCCESS The table was created successfully.
**/
EFI_STATUS
EFIAPI
ShellCommandConsistMappingInitialize (
OUT EFI_DEVICE_PATH_PROTOCOL ***Table
)
{
EFI_HANDLE *HandleBuffer;
UINTN HandleNum;
UINTN HandleLoop;
EFI_DEVICE_PATH_PROTOCOL **TempTable;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
UINTN Index;
EFI_STATUS Status;
HandleBuffer = NULL;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiDevicePathProtocolGuid,
NULL,
&HandleNum,
&HandleBuffer
);
ASSERT_EFI_ERROR (Status);
TempTable = AllocateZeroPool ((HandleNum + 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL *));
if (TempTable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
for (HandleLoop = 0; HandleLoop < HandleNum; HandleLoop++) {
DevicePath = DevicePathFromHandle (HandleBuffer[HandleLoop]);
if (DevicePath == NULL) {
continue;
}
HIDevicePath = GetHIDevicePath (DevicePath);
if (HIDevicePath == NULL) {
continue;
}
Status = gBS->HandleProtocol (
HandleBuffer[HandleLoop],
&gEfiBlockIoProtocolGuid,
(VOID **)&BlockIo
);
if (EFI_ERROR (Status)) {
Status = gBS->HandleProtocol (
HandleBuffer[HandleLoop],
&gEfiSimpleFileSystemProtocolGuid,
(VOID **)&SimpleFileSystem
);
if (EFI_ERROR (Status)) {
FreePool (HIDevicePath);
continue;
}
}
for (Index = 0; TempTable[Index] != NULL; Index++) {
if (DevicePathCompare (&TempTable[Index], &HIDevicePath) == 0) {
FreePool (HIDevicePath);
break;
}
}
if (TempTable[Index] == NULL) {
TempTable[Index] = HIDevicePath;
}
}
for (Index = 0; TempTable[Index] != NULL; Index++) {
}
PerformQuickSort (TempTable, Index, sizeof (EFI_DEVICE_PATH_PROTOCOL *), DevicePathCompare);
*Table = TempTable;
if (HandleBuffer != NULL) {
FreePool (HandleBuffer);
}
return EFI_SUCCESS;
}
/**
Function to uninitialize the table for creating consistent map names.
The parameter must have been received from ShellCommandConsistMappingInitialize.
@param[out] Table The pointer to pointer to DevicePathProtocol object.
@retval EFI_SUCCESS The table was deleted successfully.
**/
EFI_STATUS
EFIAPI
ShellCommandConsistMappingUnInitialize (
EFI_DEVICE_PATH_PROTOCOL **Table
)
{
UINTN Index;
ASSERT (Table != NULL);
for (Index = 0; Table[Index] != NULL; Index++) {
FreePool (Table[Index]);
}
FreePool (Table);
return EFI_SUCCESS;
}
/**
Create a consistent mapped name for the device specified by DevicePath
based on the Table.
This must be called after ShellCommandConsistMappingInitialize() and
before ShellCommandConsistMappingUnInitialize() is called.
@param[in] DevicePath The pointer to the dev path for the device.
@param[in] Table The Table of mapping information.
@retval NULL A consistent mapped name could not be created.
@return A pointer to a string allocated from pool with the device name.
**/
CHAR16 *
EFIAPI
ShellCommandConsistMappingGenMappingName (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN EFI_DEVICE_PATH_PROTOCOL **Table
)
{
EFI_STATUS Status;
POOL_PRINT Str;
DEVICE_CONSIST_MAPPING_INFO MappingInfo;
EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;
UINTN Index;
ASSERT (DevicePath != NULL);
ASSERT (Table != NULL);
HIDevicePath = GetHIDevicePath (DevicePath);
if (HIDevicePath == NULL) {
return NULL;
}
for (Index = 0; Table[Index] != NULL; Index++) {
if (DevicePathCompare (&Table[Index], &HIDevicePath) == 0) {
break;
}
}
FreePool (HIDevicePath);
if (Table[Index] == NULL) {
return NULL;
}
MappingInfo.Hi = Index;
MappingInfo.Mtd = MTDTypeUnknown;
MappingInfo.Digital = FALSE;
Status = GetDeviceConsistMappingInfo (&MappingInfo, DevicePath);
if (EFI_ERROR (Status)) {
return NULL;
}
SetMem (&Str, sizeof (Str), 0);
for (Index = 0; mMTDName[Index].MTDType != MTDTypeEnd; Index++) {
if (MappingInfo.Mtd == mMTDName[Index].MTDType) {
break;
}
}
if (mMTDName[Index].MTDType != MTDTypeEnd) {
Status = CatPrint (&Str, L"%s", mMTDName[Index].Name);
}
if (!EFI_ERROR (Status)) {
Status = CatPrint (&Str, L"%d", (UINTN)MappingInfo.Hi);
}
if (!EFI_ERROR (Status) && (MappingInfo.Csd.Str != NULL)) {
Status = CatPrint (&Str, L"%s", MappingInfo.Csd.Str);
FreePool (MappingInfo.Csd.Str);
}
if (!EFI_ERROR (Status) && (Str.Str != NULL)) {
Status = CatPrint (&Str, L":");
}
if (EFI_ERROR (Status)) {
SHELL_FREE_NON_NULL (Str.Str);
return NULL;
}
return Str.Str;
}
/**
Function to search the list of mappings for the node on the list based on the key.
@param[in] MapKey String Key to search for on the map
@return the node on the list.
**/
SHELL_MAP_LIST *
EFIAPI
ShellCommandFindMapItem (
IN CONST CHAR16 *MapKey
)
{
SHELL_MAP_LIST *MapListItem;
for ( MapListItem = (SHELL_MAP_LIST *)GetFirstNode (&gShellMapList.Link)
; !IsNull (&gShellMapList.Link, &MapListItem->Link)
; MapListItem = (SHELL_MAP_LIST *)GetNextNode (&gShellMapList.Link, &MapListItem->Link)
)
{
if (gUnicodeCollation->StriColl (gUnicodeCollation, MapListItem->MapName, (CHAR16 *)MapKey) == 0) {
return (MapListItem);
}
}
return (NULL);
}
|