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