]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
udk2010.up2.shell initial release.
[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
4 Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12**/\r
13\r
14#include "UefiShellCommandLib.h"\r
15#include <Library/DevicePathLib.h>\r
16#include <Library/SortLib.h>\r
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
32 UINTN HI;\r
33 MTD_TYPE MTD;\r
34 POOL_PRINT CSD;\r
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
43typedef struct {\r
44 UINT8 Type;\r
45 UINT8 SubType;\r
46 VOID (*SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *);\r
47 INTN (*CompareFun) (EFI_DEVICE_PATH_PROTOCOL *, EFI_DEVICE_PATH_PROTOCOL *);\r
48} DEV_PATH_CONSIST_MAPPING_TABLE;\r
49\r
50\r
51/**\r
52 Concatenates a formatted unicode string to allocated pool.\r
53 The caller must free the resulting buffer.\r
54\r
55 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.\r
56 @param Fmt The format string\r
57 @param ... The data will be printed.\r
58\r
59 @return Allocated buffer with the formatted string printed in it.\r
60 The caller must free the allocated buffer.\r
61 The buffer allocation is not packed.\r
62\r
63**/\r
64CHAR16 *\r
65EFIAPI\r
66CatPrint (\r
67 IN OUT POOL_PRINT *Str,\r
68 IN CHAR16 *Fmt,\r
69 ...\r
70 )\r
71{\r
72 UINT16 *AppendStr;\r
73 VA_LIST Args;\r
74 UINTN StringSize;\r
75\r
76 AppendStr = AllocateZeroPool (0x1000);\r
77 if (AppendStr == NULL) {\r
78 ASSERT(FALSE);\r
79 return Str->Str;\r
80 }\r
81\r
82 VA_START (Args, Fmt);\r
83 UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);\r
84 VA_END (Args);\r
85 if (NULL == Str->Str) {\r
86 StringSize = StrSize (AppendStr);\r
87 Str->Str = AllocateZeroPool (StringSize);\r
88 ASSERT (Str->Str != NULL);\r
89 } else {\r
90 StringSize = StrSize (AppendStr);\r
91 StringSize += (StrSize (Str->Str) - sizeof (UINT16));\r
92\r
93 Str->Str = ReallocatePool (\r
94 StrSize (Str->Str),\r
95 StringSize,\r
96 Str->Str\r
97 );\r
98 ASSERT (Str->Str != NULL);\r
99 }\r
100\r
101 StrCat (Str->Str, AppendStr);\r
102 Str->Len = StringSize;\r
103\r
104 FreePool (AppendStr);\r
105 return Str->Str;\r
106}\r
107\r
108MTD_NAME mMTDName[] = {\r
109 {\r
110 MTDTypeUnknown,\r
111 L"F"\r
112 },\r
113 {\r
114 MTDTypeFloppy,\r
115 L"FP"\r
116 },\r
117 {\r
118 MTDTypeHardDisk,\r
119 L"HD"\r
120 },\r
121 {\r
122 MTDTypeCDRom,\r
123 L"CD"\r
124 },\r
125 {\r
126 MTDTypeEnd,\r
127 NULL\r
128 }\r
129};\r
130\r
131VOID\r
132AppendCSDNum2 (\r
133 IN OUT POOL_PRINT *Str,\r
134 IN UINT64 Num\r
135 )\r
136{\r
137 UINT64 Result;\r
138 UINT32 Rem;\r
139\r
140 ASSERT(Str != NULL);\r
141\r
142 Result = DivU64x32Remainder (Num, 25, &Rem);\r
143 if (Result > 0) {\r
144 AppendCSDNum2 (Str, Result);\r
145 }\r
146\r
147 CatPrint (Str, L"%c", Rem + 'a');\r
148}\r
149\r
150VOID\r
151AppendCSDNum (\r
152 DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r
153 UINT64 Num\r
154 )\r
155{\r
156 ASSERT(MappingItem != NULL);\r
157\r
158 if (MappingItem->Digital) {\r
159 CatPrint (&MappingItem->CSD, L"%ld", Num);\r
160 } else {\r
161 AppendCSDNum2 (&MappingItem->CSD, Num);\r
162 }\r
163\r
164 MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital);\r
165}\r
166\r
167VOID\r
168AppendCSDStr (\r
169 DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r
170 CHAR16 *Str\r
171 )\r
172{\r
173 CHAR16 *Index;\r
174\r
175 ASSERT(Str != NULL);\r
176 ASSERT(MappingItem != NULL);\r
177\r
178 if (MappingItem->Digital) {\r
179 //\r
180 // To aVOID mult-meaning, the mapping is:\r
181 // 0 1 2 3 4 5 6 7 8 9 a b c d e f\r
182 // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15\r
183 //\r
184 for (Index = Str; *Index != 0; Index++) {\r
185 switch (*Index) {\r
186 case '0':\r
187 case '2':\r
188 case '3':\r
189 case '4':\r
190 case '5':\r
191 case '6':\r
192 case '7':\r
193 case '8':\r
194 case '9':\r
195 CatPrint (&MappingItem->CSD, L"%c", *Index);\r
196 break;\r
197\r
198 case '1':\r
199 CatPrint (&MappingItem->CSD, L"16");\r
200 break;\r
201\r
202 case 'a':\r
203 case 'b':\r
204 case 'c':\r
205 case 'd':\r
206 case 'e':\r
207 case 'f':\r
208 CatPrint (&MappingItem->CSD, L"1%c", *Index - 'a' + '0');\r
209 break;\r
210\r
211 case 'A':\r
212 case 'B':\r
213 case 'C':\r
214 case 'D':\r
215 case 'E':\r
216 case 'F':\r
217 CatPrint (&MappingItem->CSD, L"1%c", *Index - 'A' + '0');\r
218 break;\r
219 }\r
220 }\r
221 } else {\r
222 for (Index = Str; *Index != 0; Index++) {\r
223 //\r
224 // The mapping is:\r
225 // 0 1 2 3 4 5 6 7 8 9 a b c d e f\r
226 // a b c d e f g h i j k l m n o p\r
227 //\r
228 if (*Index >= '0' && *Index <= '9') {\r
229 CatPrint (&MappingItem->CSD, L"%c", *Index - '0' + 'a');\r
230 } else if (*Index >= 'a' && *Index <= 'f') {\r
231 CatPrint (&MappingItem->CSD, L"%c", *Index - 'a' + 'k');\r
232 } else if (*Index >= 'A' && *Index <= 'F') {\r
233 CatPrint (&MappingItem->CSD, L"%c", *Index - 'A' + 'k');\r
234 }\r
235 }\r
236 }\r
237\r
238 MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital);\r
239}\r
240\r
241VOID\r
242AppendCSDGuid (\r
243 DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r
244 EFI_GUID *Guid\r
245 )\r
246{\r
247 CHAR16 Buffer[64];\r
248 ASSERT(Guid != NULL);\r
249 ASSERT(MappingItem != NULL);\r
250\r
251 UnicodeSPrint (\r
252 Buffer,\r
253 0,\r
254 L"%g",\r
255 Guid\r
256 );\r
257// StrLwr (Buffer);\r
258 AppendCSDStr (MappingItem, Buffer);\r
259}\r
260\r
261INTN\r
262_DevPathCompareAcpi (\r
263 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,\r
264 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2\r
265 )\r
266{\r
267 ACPI_HID_DEVICE_PATH *Acpi1;\r
268 ACPI_HID_DEVICE_PATH *Acpi2;\r
269\r
270 ASSERT(DevicePath1 != NULL);\r
271 ASSERT(DevicePath2 != NULL);\r
272\r
273 Acpi1 = (ACPI_HID_DEVICE_PATH *) DevicePath1;\r
274 Acpi2 = (ACPI_HID_DEVICE_PATH *) DevicePath2;\r
275 if (Acpi1->HID > Acpi2->HID || (Acpi1->HID == Acpi2->HID && Acpi1->UID > Acpi2->UID)) {\r
276 return 1;\r
277 }\r
278\r
279 if (Acpi1->HID == Acpi2->HID && Acpi1->UID == Acpi2->UID) {\r
280 return 0;\r
281 }\r
282\r
283 return -1;\r
284}\r
285\r
286INTN\r
287_DevPathComparePci (\r
288 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,\r
289 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2\r
290 )\r
291{\r
292 PCI_DEVICE_PATH *Pci1;\r
293 PCI_DEVICE_PATH *Pci2;\r
294\r
295 ASSERT(DevicePath1 != NULL);\r
296 ASSERT(DevicePath2 != NULL);\r
297\r
298 Pci1 = (PCI_DEVICE_PATH *) DevicePath1;\r
299 Pci2 = (PCI_DEVICE_PATH *) DevicePath2;\r
300 if (Pci1->Device > Pci2->Device || (Pci1->Device == Pci2->Device && Pci1->Function > Pci2->Function)) {\r
301 return 1;\r
302 }\r
303\r
304 if (Pci1->Device == Pci2->Device && Pci1->Function == Pci2->Function) {\r
305 return 0;\r
306 }\r
307\r
308 return -1;\r
309}\r
310\r
311/**\r
312 Do a comparison on 2 device paths.\r
313\r
314 @param[in] DevicePath1 The first device path.\r
315 @param[in] DevicePath2 The second device path.\r
316\r
317 @retval 0 The 2 device paths are the same.\r
318 @retval <0 DevicePath2 is greater than DevicePath1.\r
319 @retval >0 DevicePath1 is greater than DevicePath2.\r
320**/\r
321INTN\r
322EFIAPI\r
323DevPathCompareDefault (\r
324 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,\r
325 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2\r
326 )\r
327{\r
328 UINTN DevPathSize1;\r
329 UINTN DevPathSize2;\r
330\r
331 ASSERT(DevicePath1 != NULL);\r
332 ASSERT(DevicePath2 != NULL);\r
333\r
334 DevPathSize1 = DevicePathNodeLength (DevicePath1);\r
335 DevPathSize2 = DevicePathNodeLength (DevicePath2);\r
336 if (DevPathSize1 > DevPathSize2) {\r
337 return 1;\r
338 } else if (DevPathSize1 < DevPathSize2) {\r
339 return -1;\r
340 } else {\r
341 return CompareMem (DevicePath1, DevicePath2, DevPathSize1);\r
342 }\r
343}\r
344\r
345/**\r
346 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.\r
347\r
348 @param[in] DevicePathNode The node to get info on.\r
349 @param[in] MappingItem The info item to populate.\r
350**/\r
351VOID\r
352EFIAPI\r
353DevPathSerialHardDrive (\r
354 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
355 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
356 )\r
357{\r
358 HARDDRIVE_DEVICE_PATH *Hd;\r
359\r
360 ASSERT(DevicePathNode != NULL);\r
361 ASSERT(MappingItem != NULL);\r
362\r
363 Hd = (HARDDRIVE_DEVICE_PATH *) DevicePathNode;\r
364 if (MappingItem->MTD == MTDTypeUnknown) {\r
365 MappingItem->MTD = MTDTypeHardDisk;\r
366 }\r
367\r
368 AppendCSDNum (MappingItem, Hd->PartitionNumber);\r
369}\r
370\r
371/**\r
372 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.\r
373\r
374 @param[in] DevicePathNode The node to get info on.\r
375 @param[in] MappingItem The info item to populate.\r
376**/\r
377VOID\r
378EFIAPI\r
379DevPathSerialAtapi (\r
380 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
381 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
382 )\r
383{\r
384 ATAPI_DEVICE_PATH *Atapi;\r
385\r
386 ASSERT(DevicePathNode != NULL);\r
387 ASSERT(MappingItem != NULL);\r
388\r
389 Atapi = (ATAPI_DEVICE_PATH *) DevicePathNode;\r
390 AppendCSDNum (MappingItem, (Atapi->PrimarySecondary * 2 + Atapi->SlaveMaster));\r
391}\r
392\r
393/**\r
394 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.\r
395\r
396 @param[in] DevicePathNode The node to get info on.\r
397 @param[in] MappingItem The info item to populate.\r
398**/\r
399VOID\r
400EFIAPI\r
401DevPathSerialCdRom (\r
402 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
403 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
404 )\r
405{\r
406 CDROM_DEVICE_PATH *Cd;\r
407\r
408 ASSERT(DevicePathNode != NULL);\r
409 ASSERT(MappingItem != NULL);\r
410\r
411 Cd = (CDROM_DEVICE_PATH *) DevicePathNode;\r
412 MappingItem->MTD = MTDTypeCDRom;\r
413 AppendCSDNum (MappingItem, Cd->BootEntry);\r
414}\r
415\r
416/**\r
417 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.\r
418\r
419 @param[in] DevicePathNode The node to get info on.\r
420 @param[in] MappingItem The info item to populate.\r
421**/\r
422VOID\r
423EFIAPI\r
424DevPathSerialFibre (\r
425 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
426 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
427 )\r
428{\r
429 FIBRECHANNEL_DEVICE_PATH *Fibre;\r
430\r
431 ASSERT(DevicePathNode != NULL);\r
432 ASSERT(MappingItem != NULL);\r
433\r
434 Fibre = (FIBRECHANNEL_DEVICE_PATH *) DevicePathNode;\r
435 AppendCSDNum (MappingItem, Fibre->WWN);\r
436 AppendCSDNum (MappingItem, Fibre->Lun);\r
437}\r
438\r
439/**\r
440 DevicePathNode must be SerialUart type and this will populate the MappingItem.\r
441\r
442 @param[in] DevicePathNode The node to get info on.\r
443 @param[in] MappingItem The info item to populate.\r
444**/\r
445VOID\r
446EFIAPI\r
447DevPathSerialUart (\r
448 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
449 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
450 )\r
451{\r
452 UART_DEVICE_PATH *Uart;\r
453\r
454 ASSERT(DevicePathNode != NULL);\r
455 ASSERT(MappingItem != NULL);\r
456\r
457 Uart = (UART_DEVICE_PATH *) DevicePathNode;\r
458 AppendCSDNum (MappingItem, Uart->BaudRate);\r
459 AppendCSDNum (MappingItem, Uart->DataBits);\r
460 AppendCSDNum (MappingItem, Uart->Parity);\r
461 AppendCSDNum (MappingItem, Uart->StopBits);\r
462}\r
463\r
464/**\r
465 DevicePathNode must be SerialUSB type and this will populate the MappingItem.\r
466\r
467 @param[in] DevicePathNode The node to get info on.\r
468 @param[in] MappingItem The info item to populate.\r
469**/\r
470VOID\r
471EFIAPI\r
472DevPathSerialUsb (\r
473 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
474 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
475 )\r
476{\r
477 USB_DEVICE_PATH *Usb;\r
478\r
479 ASSERT(DevicePathNode != NULL);\r
480 ASSERT(MappingItem != NULL);\r
481\r
482 Usb = (USB_DEVICE_PATH *) DevicePathNode;\r
483 AppendCSDNum (MappingItem, Usb->ParentPortNumber);\r
484 AppendCSDNum (MappingItem, Usb->InterfaceNumber);\r
485}\r
486\r
487/**\r
488 DevicePathNode must be SerialVendor type and this will populate the MappingItem.\r
489\r
490 @param[in] DevicePathNode The node to get info on.\r
491 @param[in] MappingItem The info item to populate.\r
492**/\r
493VOID\r
494EFIAPI\r
495DevPathSerialVendor (\r
496 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
497 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
498 )\r
499{\r
500 VENDOR_DEVICE_PATH *Vendor;\r
501 SAS_DEVICE_PATH *Sas;\r
502 EFI_GUID SasVendorGuid = DEVICE_PATH_MESSAGING_SAS;\r
503\r
504 ASSERT(DevicePathNode != NULL);\r
505 ASSERT(MappingItem != NULL);\r
506\r
507 Vendor = (VENDOR_DEVICE_PATH *) DevicePathNode;\r
508 AppendCSDGuid (MappingItem, &Vendor->Guid);\r
509\r
510 if (CompareGuid (&SasVendorGuid, &Vendor->Guid) == 0) {\r
511 Sas = (SAS_DEVICE_PATH *) Vendor;\r
512 AppendCSDNum (MappingItem, Sas->SasAddress);\r
513 AppendCSDNum (MappingItem, Sas->Lun);\r
514 AppendCSDNum (MappingItem, Sas->DeviceTopology);\r
515 AppendCSDNum (MappingItem, Sas->RelativeTargetPort);\r
516 }\r
517}\r
518\r
519/**\r
520 DevicePathNode must be SerialLun type and this will populate the MappingItem.\r
521\r
522 @param[in] DevicePathNode The node to get info on.\r
523 @param[in] MappingItem The info item to populate.\r
524**/\r
525VOID\r
526EFIAPI\r
527DevPathSerialLun (\r
528 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
529 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
530 )\r
531{\r
532 DEVICE_LOGICAL_UNIT_DEVICE_PATH *Lun;\r
533\r
534 ASSERT(DevicePathNode != NULL);\r
535 ASSERT(MappingItem != NULL);\r
536\r
537 Lun = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) DevicePathNode;\r
538 AppendCSDNum (MappingItem, Lun->Lun);\r
539}\r
540\r
541/**\r
542 DevicePathNode must be SerialSata type and this will populate the MappingItem.\r
543\r
544 @param[in] DevicePathNode The node to get info on.\r
545 @param[in] MappingItem The info item to populate.\r
546**/\r
547VOID\r
548EFIAPI\r
549DevPathSerialSata (\r
550 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
551 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
552 )\r
553{\r
554 SATA_DEVICE_PATH *Sata;\r
555\r
556 ASSERT(DevicePathNode != NULL);\r
557 ASSERT(MappingItem != NULL);\r
558\r
559 Sata = (SATA_DEVICE_PATH *) DevicePathNode;\r
560 AppendCSDNum (MappingItem, Sata->HBAPortNumber);\r
561 AppendCSDNum (MappingItem, Sata->PortMultiplierPortNumber);\r
562 AppendCSDNum (MappingItem, Sata->Lun);\r
563}\r
564\r
565/**\r
566 DevicePathNode must be SerialSCSI type and this will populate the MappingItem.\r
567\r
568 @param[in] DevicePathNode The node to get info on.\r
569 @param[in] MappingItem The info item to populate.\r
570**/\r
571VOID\r
572EFIAPI\r
573DevPathSerialIScsi (\r
574 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
575 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
576 )\r
577{\r
578///@todo make this a PCD\r
579//\r
580// As CSD of ISCSI node is quite long, we comment\r
581// the code below to keep the consistent mapping\r
582// short. Uncomment if you really need it.\r
583//\r
584/*\r
585 ISCSI_DEVICE_PATH *IScsi;\r
586 UINT8 *IScsiTargetName;\r
587 CHAR16 *TargetName;\r
588 UINTN TargetNameLength;\r
589 UINTN Index;\r
590\r
591 ASSERT(DevicePathNode != NULL);\r
592 ASSERT(MappingItem != NULL);\r
593\r
594 IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode;\r
595 AppendCSDNum (MappingItem, IScsi->NetworkProtocol);\r
596 AppendCSDNum (MappingItem, IScsi->LoginOption);\r
597 AppendCSDNum (MappingItem, IScsi->Lun);\r
598 AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag);\r
599 TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH);\r
600 if (TargetNameLength > 0) {\r
601 TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16));\r
602 if (TargetName != NULL) {\r
603 IScsiTargetName = (UINT8 *) (IScsi + 1);\r
604 for (Index = 0; Index < TargetNameLength; Index++) {\r
605 TargetName[Index] = (CHAR16) IScsiTargetName[Index];\r
606 }\r
607 AppendCSDStr (MappingItem, TargetName);\r
608 FreePool (TargetName);\r
609 }\r
610 }\r
611 */\r
612}\r
613\r
614/**\r
615 DevicePathNode must be SerialI20 type and this will populate the MappingItem.\r
616\r
617 @param[in] DevicePathNode The node to get info on.\r
618 @param[in] MappingItem The info item to populate.\r
619**/\r
620VOID\r
621EFIAPI\r
622DevPathSerialI2O (\r
623 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
624 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
625 )\r
626{\r
627 I2O_DEVICE_PATH *I2O;\r
628\r
629 ASSERT(DevicePathNode != NULL);\r
630 ASSERT(MappingItem != NULL);\r
631\r
632 I2O = (I2O_DEVICE_PATH *) DevicePathNode;\r
633 AppendCSDNum (MappingItem, I2O->Tid);\r
634}\r
635\r
636/**\r
637 DevicePathNode must be Mac Address type and this will populate the MappingItem.\r
638\r
639 @param[in] DevicePathNode The node to get info on.\r
640 @param[in] MappingItem The info item to populate.\r
641**/\r
642VOID\r
643EFIAPI\r
644DevPathSerialMacAddr (\r
645 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
646 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
647 )\r
648{\r
649 MAC_ADDR_DEVICE_PATH *Mac;\r
650 UINTN HwAddressSize;\r
651 UINTN Index;\r
652 CHAR16 Buffer[64];\r
653 CHAR16 *PBuffer;\r
654\r
655 ASSERT(DevicePathNode != NULL);\r
656 ASSERT(MappingItem != NULL);\r
657\r
658 Mac = (MAC_ADDR_DEVICE_PATH *) DevicePathNode;\r
659\r
660 HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r
661 if (Mac->IfType == 0x01 || Mac->IfType == 0x00) {\r
662 HwAddressSize = 6;\r
663 }\r
664\r
665 for (Index = 0, PBuffer = Buffer; Index < HwAddressSize; Index++, PBuffer += 2) {\r
666 UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Mac->MacAddress.Addr[Index]);\r
667 }\r
668\r
669 AppendCSDStr (MappingItem, Buffer);\r
670}\r
671\r
672/**\r
673 DevicePathNode must be InfiniBand type and this will populate the MappingItem.\r
674\r
675 @param[in] DevicePathNode The node to get info on.\r
676 @param[in] MappingItem The info item to populate.\r
677**/\r
678VOID\r
679EFIAPI\r
680DevPathSerialInfiniBand (\r
681 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
682 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
683 )\r
684{\r
685 INFINIBAND_DEVICE_PATH *InfiniBand;\r
686 UINTN Index;\r
687 CHAR16 Buffer[64];\r
688 CHAR16 *PBuffer;\r
689\r
690 ASSERT(DevicePathNode != NULL);\r
691 ASSERT(MappingItem != NULL);\r
692\r
693 InfiniBand = (INFINIBAND_DEVICE_PATH *) DevicePathNode;\r
694 for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {\r
695 UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) InfiniBand->PortGid[Index]);\r
696 }\r
697\r
698 AppendCSDStr (MappingItem, Buffer);\r
699 AppendCSDNum (MappingItem, InfiniBand->ServiceId);\r
700 AppendCSDNum (MappingItem, InfiniBand->TargetPortId);\r
701 AppendCSDNum (MappingItem, InfiniBand->DeviceId);\r
702}\r
703\r
704/**\r
705 DevicePathNode must be IPv4 type and this will populate the MappingItem.\r
706\r
707 @param[in] DevicePathNode The node to get info on.\r
708 @param[in] MappingItem The info item to populate.\r
709**/\r
710VOID\r
711EFIAPI\r
712DevPathSerialIPv4 (\r
713 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
714 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
715 )\r
716{\r
717 IPv4_DEVICE_PATH *Ip;\r
718 CHAR16 Buffer[10];\r
719\r
720 ASSERT(DevicePathNode != NULL);\r
721 ASSERT(MappingItem != NULL);\r
722\r
723 Ip = (IPv4_DEVICE_PATH *) DevicePathNode;\r
724 UnicodeSPrint (\r
725 Buffer,\r
726 0,\r
727 L"%02x%02x%02x%02x",\r
728 (UINTN) Ip->LocalIpAddress.Addr[0],\r
729 (UINTN) Ip->LocalIpAddress.Addr[1],\r
730 (UINTN) Ip->LocalIpAddress.Addr[2],\r
731 (UINTN) Ip->LocalIpAddress.Addr[3]\r
732 );\r
733 AppendCSDStr (MappingItem, Buffer);\r
734 AppendCSDNum (MappingItem, Ip->LocalPort);\r
735 UnicodeSPrint (\r
736 Buffer,\r
737 0,\r
738 L"%02x%02x%02x%02x",\r
739 (UINTN) Ip->RemoteIpAddress.Addr[0],\r
740 (UINTN) Ip->RemoteIpAddress.Addr[1],\r
741 (UINTN) Ip->RemoteIpAddress.Addr[2],\r
742 (UINTN) Ip->RemoteIpAddress.Addr[3]\r
743 );\r
744 AppendCSDStr (MappingItem, Buffer);\r
745 AppendCSDNum (MappingItem, Ip->RemotePort);\r
746}\r
747\r
748/**\r
749 DevicePathNode must be IPv6 type and this will populate the MappingItem.\r
750\r
751 @param[in] DevicePathNode The node to get info on.\r
752 @param[in] MappingItem The info item to populate.\r
753**/\r
754VOID\r
755EFIAPI\r
756DevPathSerialIPv6 (\r
757 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
758 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
759 )\r
760{\r
761 IPv6_DEVICE_PATH *Ip;\r
762 UINTN Index;\r
763 CHAR16 Buffer[64];\r
764 CHAR16 *PBuffer;\r
765\r
766 ASSERT(DevicePathNode != NULL);\r
767 ASSERT(MappingItem != NULL);\r
768\r
769 Ip = (IPv6_DEVICE_PATH *) DevicePathNode;\r
770 for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {\r
771 UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->LocalIpAddress.Addr[Index]);\r
772 }\r
773\r
774 AppendCSDStr (MappingItem, Buffer);\r
775 AppendCSDNum (MappingItem, Ip->LocalPort);\r
776 for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {\r
777 UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->RemoteIpAddress.Addr[Index]);\r
778 }\r
779\r
780 AppendCSDStr (MappingItem, Buffer);\r
781 AppendCSDNum (MappingItem, Ip->RemotePort);\r
782}\r
783\r
784/**\r
785 DevicePathNode must be SCSI type and this will populate the MappingItem.\r
786\r
787 @param[in] DevicePathNode The node to get info on.\r
788 @param[in] MappingItem The info item to populate.\r
789**/\r
790VOID\r
791EFIAPI\r
792DevPathSerialScsi (\r
793 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
794 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
795 )\r
796{\r
797 SCSI_DEVICE_PATH *Scsi;\r
798\r
799 ASSERT(DevicePathNode != NULL);\r
800 ASSERT(MappingItem != NULL);\r
801\r
802 Scsi = (SCSI_DEVICE_PATH *) DevicePathNode;\r
803 AppendCSDNum (MappingItem, Scsi->Pun);\r
804 AppendCSDNum (MappingItem, Scsi->Lun);\r
805}\r
806\r
807/**\r
808 DevicePathNode must be 1394 type and this will populate the MappingItem.\r
809\r
810 @param[in] DevicePathNode The node to get info on.\r
811 @param[in] MappingItem The info item to populate.\r
812**/\r
813VOID\r
814EFIAPI\r
815DevPathSerial1394 (\r
816 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
817 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
818 )\r
819{\r
820 F1394_DEVICE_PATH *F1394;\r
821 CHAR16 Buffer[20];\r
822\r
823 ASSERT(DevicePathNode != NULL);\r
824 ASSERT(MappingItem != NULL);\r
825\r
826 F1394 = (F1394_DEVICE_PATH *) DevicePathNode;\r
827 UnicodeSPrint (Buffer, 0, L"%lx", F1394->Guid);\r
828 AppendCSDStr (MappingItem, Buffer);\r
829}\r
830\r
831/**\r
832 If the node is floppy type then populate the MappingItem.\r
833\r
834 @param[in] DevicePathNode The node to get info on.\r
835 @param[in] MappingItem The info item to populate.\r
836**/\r
837VOID\r
838EFIAPI\r
839DevPathSerialAcpi (\r
840 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
841 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
842 )\r
843{\r
844 ACPI_HID_DEVICE_PATH *Acpi;\r
845\r
846 ASSERT(DevicePathNode != NULL);\r
847 ASSERT(MappingItem != NULL);\r
848\r
849 Acpi = (ACPI_HID_DEVICE_PATH *) DevicePathNode;\r
850 if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
851 if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {\r
852 MappingItem->MTD = MTDTypeFloppy;\r
853 AppendCSDNum (MappingItem, Acpi->UID);\r
854 }\r
855 }\r
856}\r
857\r
858/**\r
859 Empty function used for unknown devices.\r
860\r
861 Does nothing.\r
862**/\r
863VOID\r
864EFIAPI\r
865DevPathSerialDefault (\r
866 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
867 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem\r
868 )\r
869{\r
870}\r
871\r
872DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable[] = {\r
873 HARDWARE_DEVICE_PATH,\r
874 HW_PCI_DP,\r
875 DevPathSerialDefault,\r
876 _DevPathComparePci,\r
877 ACPI_DEVICE_PATH,\r
878 ACPI_DP,\r
879 DevPathSerialAcpi,\r
880 _DevPathCompareAcpi,\r
881 MESSAGING_DEVICE_PATH,\r
882 MSG_ATAPI_DP,\r
883 DevPathSerialAtapi,\r
884 DevPathCompareDefault,\r
885 MESSAGING_DEVICE_PATH,\r
886 MSG_SCSI_DP,\r
887 DevPathSerialScsi,\r
888 DevPathCompareDefault,\r
889 MESSAGING_DEVICE_PATH,\r
890 MSG_FIBRECHANNEL_DP,\r
891 DevPathSerialFibre,\r
892 DevPathCompareDefault,\r
893 MESSAGING_DEVICE_PATH,\r
894 MSG_1394_DP,\r
895 DevPathSerial1394,\r
896 DevPathCompareDefault,\r
897 MESSAGING_DEVICE_PATH,\r
898 MSG_USB_DP,\r
899 DevPathSerialUsb,\r
900 DevPathCompareDefault,\r
901 MESSAGING_DEVICE_PATH,\r
902 MSG_I2O_DP,\r
903 DevPathSerialI2O,\r
904 DevPathCompareDefault,\r
905 MESSAGING_DEVICE_PATH,\r
906 MSG_MAC_ADDR_DP,\r
907 DevPathSerialMacAddr,\r
908 DevPathCompareDefault,\r
909 MESSAGING_DEVICE_PATH,\r
910 MSG_IPv4_DP,\r
911 DevPathSerialIPv4,\r
912 DevPathCompareDefault,\r
913 MESSAGING_DEVICE_PATH,\r
914 MSG_IPv6_DP,\r
915 DevPathSerialIPv6,\r
916 DevPathCompareDefault,\r
917 MESSAGING_DEVICE_PATH,\r
918 MSG_INFINIBAND_DP,\r
919 DevPathSerialInfiniBand,\r
920 DevPathCompareDefault,\r
921 MESSAGING_DEVICE_PATH,\r
922 MSG_UART_DP,\r
923 DevPathSerialUart,\r
924 DevPathCompareDefault,\r
925 MESSAGING_DEVICE_PATH,\r
926 MSG_VENDOR_DP,\r
927 DevPathSerialVendor,\r
928 DevPathCompareDefault,\r
929 MESSAGING_DEVICE_PATH,\r
930 MSG_DEVICE_LOGICAL_UNIT_DP,\r
931 DevPathSerialLun,\r
932 DevPathCompareDefault,\r
933 MESSAGING_DEVICE_PATH,\r
934 MSG_SATA_DP,\r
935 DevPathSerialSata,\r
936 DevPathCompareDefault,\r
937 MESSAGING_DEVICE_PATH,\r
938 MSG_ISCSI_DP,\r
939 DevPathSerialIScsi,\r
940 DevPathCompareDefault,\r
941 MEDIA_DEVICE_PATH,\r
942 MEDIA_HARDDRIVE_DP,\r
943 DevPathSerialHardDrive,\r
944 DevPathCompareDefault,\r
945 MEDIA_DEVICE_PATH,\r
946 MEDIA_CDROM_DP,\r
947 DevPathSerialCdRom,\r
948 DevPathCompareDefault,\r
949 MEDIA_DEVICE_PATH,\r
950 MEDIA_VENDOR_DP,\r
951 DevPathSerialVendor,\r
952 DevPathCompareDefault,\r
953 0,\r
954 0,\r
955 NULL,\r
956 NULL\r
957};\r
958\r
959/**\r
960 Function to determine if a device path node is Hi or not.\r
961\r
962 @param[in] DevicePathNode The node to check.\r
963\r
964 @retval TRUE The node is HI.\r
965 @retval FALSE The node is not HI.\r
966**/\r
967BOOLEAN\r
968EFIAPI\r
969IsHIDevicePathNode (\r
970 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode\r
971 )\r
972{\r
973 ACPI_HID_DEVICE_PATH *Acpi;\r
974\r
975 ASSERT(DevicePathNode != NULL);\r
976\r
977 if (DevicePathNode->Type == HARDWARE_DEVICE_PATH) {\r
978 return TRUE;\r
979 }\r
980\r
981 if (DevicePathNode->Type == ACPI_DEVICE_PATH) {\r
982 Acpi = (ACPI_HID_DEVICE_PATH *) DevicePathNode;\r
983 switch (EISA_ID_TO_NUM (Acpi->HID)) {\r
984 case 0x0301:\r
985 case 0x0401:\r
986 case 0x0501:\r
987 case 0x0604:\r
988 return FALSE;\r
989 }\r
990\r
991 return TRUE;\r
992 }\r
993\r
994 return FALSE;\r
995}\r
996\r
997/**\r
998 Function to convert a standard device path structure into a HI version.\r
999\r
1000 @param[in] DevicePath The device path to convert.\r
1001\r
1002 @return the device path portion that is HI.\r
1003**/\r
1004EFI_DEVICE_PATH_PROTOCOL *\r
1005EFIAPI\r
1006GetHIDevicePath (\r
1007 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
1008 )\r
1009{\r
1010 UINTN NonHIDevicePathNodeCount;\r
1011 UINTN Index;\r
1012 EFI_DEV_PATH Node;\r
1013 EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;\r
1014 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
1015\r
1016 ASSERT(DevicePath != NULL);\r
1017\r
1018 NonHIDevicePathNodeCount = 0;\r
1019\r
1020 HIDevicePath = AllocatePool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
1021 SetDevicePathEndNode (HIDevicePath);\r
1022\r
1023 Node.DevPath.Type = END_DEVICE_PATH_TYPE;\r
1024 Node.DevPath.SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
1025 Node.DevPath.Length[0] = (UINT8)sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
1026 Node.DevPath.Length[1] = 0;\r
1027\r
1028 while (!IsDevicePathEnd (DevicePath)) {\r
1029 if (IsHIDevicePathNode (DevicePath)) {\r
1030 for (Index = 0; Index < NonHIDevicePathNodeCount; Index++) {\r
1031 TempDevicePath = AppendDevicePathNode (HIDevicePath, &Node.DevPath);\r
1032 FreePool (HIDevicePath);\r
1033 HIDevicePath = TempDevicePath;\r
1034 }\r
1035\r
1036 TempDevicePath = AppendDevicePathNode (HIDevicePath, DevicePath);\r
1037 FreePool (HIDevicePath);\r
1038 HIDevicePath = TempDevicePath;\r
1039 } else {\r
1040 NonHIDevicePathNodeCount++;\r
1041 }\r
1042 //\r
1043 // Next device path node\r
1044 //\r
1045 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (DevicePath);\r
1046 }\r
1047\r
1048 return HIDevicePath;\r
1049}\r
1050\r
1051/**\r
1052 Function to walk the device path looking for a dumpable node.\r
1053\r
1054 @param[in] MappingItem The Item to fill with data.\r
1055 @param[in] DevicePath The path of the item to get data on.\r
1056\r
1057 @return EFI_SUCCESS Always returns success.\r
1058**/\r
1059EFI_STATUS\r
1060EFIAPI\r
1061GetDeviceConsistMappingInfo (\r
1062 IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r
1063 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
1064 )\r
1065{\r
1066 VOID (*SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *);\r
1067\r
1068 UINTN Index;\r
1069\r
1070 ASSERT(DevicePath != NULL);\r
1071 ASSERT(MappingItem != NULL);\r
1072\r
1073 SetMem (&MappingItem->CSD, sizeof (POOL_PRINT), 0);\r
1074\r
1075 while (!IsDevicePathEnd (DevicePath)) {\r
1076 //\r
1077 // Find the handler to dump this device path node\r
1078 //\r
1079 SerialFun = NULL;\r
1080 for (Index = 0; DevPathConsistMappingTable[Index].SerialFun != NULL; Index += 1) {\r
1081\r
1082 if (DevicePathType (DevicePath) == DevPathConsistMappingTable[Index].Type &&\r
1083 DevicePathSubType (DevicePath) == DevPathConsistMappingTable[Index].SubType\r
1084 ) {\r
1085 SerialFun = DevPathConsistMappingTable[Index].SerialFun;\r
1086 break;\r
1087 }\r
1088 }\r
1089 //\r
1090 // If not found, use a generic function\r
1091 //\r
1092 if (!SerialFun) {\r
1093 SerialFun = DevPathSerialDefault;\r
1094 }\r
1095\r
1096 SerialFun (DevicePath, MappingItem);\r
1097\r
1098 //\r
1099 // Next device path node\r
1100 //\r
1101 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (DevicePath);\r
1102 }\r
1103\r
1104 return EFI_SUCCESS;\r
1105}\r
1106\r
1107/**\r
1108 Function to initialize the table for creating consistent map names.\r
1109\r
1110 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.\r
1111\r
1112 @retval EFI_SUCCESS The table was created successfully.\r
1113**/\r
1114EFI_STATUS\r
1115EFIAPI\r
1116ShellCommandConsistMappingInitialize (\r
1117 OUT EFI_DEVICE_PATH_PROTOCOL ***Table\r
1118 )\r
1119{\r
1120 EFI_HANDLE *HandleBuffer;\r
1121 UINTN HandleNum;\r
1122 UINTN HandleLoop;\r
1123 EFI_DEVICE_PATH_PROTOCOL **TempTable;\r
1124 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
1125 EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;\r
1126 UINTN Index;\r
1127 EFI_STATUS Status;\r
1128\r
1129 HandleBuffer = NULL;\r
1130\r
1131 Status = gBS->LocateHandleBuffer (\r
1132 AllHandles,\r
1133 NULL,\r
1134 NULL,\r
1135 &HandleNum,\r
1136 &HandleBuffer\r
1137 );\r
1138 ASSERT_EFI_ERROR(Status);\r
1139\r
1140 TempTable = AllocateZeroPool ((HandleNum + 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL *));\r
1141 if (TempTable == NULL) {\r
1142 return EFI_OUT_OF_RESOURCES;\r
1143 }\r
1144\r
1145 for (HandleLoop = 0 ; HandleLoop < HandleNum ; HandleLoop++) {\r
1146 DevicePath = DevicePathFromHandle (HandleBuffer[HandleLoop]);\r
1147 if (DevicePath == NULL) {\r
1148 continue;\r
1149 }\r
1150\r
1151 HIDevicePath = GetHIDevicePath (DevicePath);\r
1152 if (HIDevicePath == NULL) {\r
1153 continue;\r
1154 }\r
1155\r
1156 for (Index = 0; TempTable[Index] != NULL; Index++) {\r
1157 if (DevicePathCompare (&TempTable[Index], &HIDevicePath) == 0) {\r
1158 FreePool (HIDevicePath);\r
1159 break;\r
1160 }\r
1161 }\r
1162\r
1163 if (TempTable[Index] == NULL) {\r
1164 TempTable[Index] = HIDevicePath;\r
1165 }\r
1166 }\r
1167\r
1168 for (Index = 0; TempTable[Index] != NULL; Index++);\r
1169 PerformQuickSort(TempTable, Index, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);\r
1170 *Table = TempTable;\r
1171\r
1172 if (HandleBuffer != NULL) {\r
1173 FreePool (HandleBuffer);\r
1174 }\r
1175\r
1176 return EFI_SUCCESS;\r
1177}\r
1178\r
1179/**\r
1180 Function to uninitialize the table for creating consistent map names.\r
1181\r
1182 The parameter must have been received from ShellCommandConsistMappingInitialize.\r
1183\r
1184 @param[out] Table The pointer to pointer to DevicePathProtocol object.\r
1185\r
1186 @retval EFI_SUCCESS The table was deleted successfully.\r
1187**/\r
1188EFI_STATUS\r
1189EFIAPI\r
1190ShellCommandConsistMappingUnInitialize (\r
1191 EFI_DEVICE_PATH_PROTOCOL **Table\r
1192 )\r
1193{\r
1194 UINTN Index;\r
1195\r
1196 ASSERT(Table != NULL);\r
1197\r
1198 for (Index = 0; Table[Index] != NULL; Index++) {\r
1199 FreePool (Table[Index]);\r
1200 }\r
1201\r
1202 FreePool (Table);\r
1203 return EFI_SUCCESS;\r
1204}\r
1205\r
1206/**\r
1207 Create a consistent mapped name for the device specified by DevicePath \r
1208 based on the Table.\r
1209\r
1210 This must be called after ShellCommandConsistMappingInitialize() and \r
1211 before ShellCommandConsistMappingUnInitialize() is called.\r
1212\r
1213 @param[in] DeviecPath The pointer to the dev path for the device.\r
1214 @param[in] Table The Table of mapping information.\r
1215\r
1216 @retval NULL A consistent mapped name could not be created.\r
1217 @return A pointer to a string allocated from pool with the device name.\r
1218**/\r
1219CHAR16 *\r
1220EFIAPI\r
1221ShellCommandConsistMappingGenMappingName (\r
1222 EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
1223 EFI_DEVICE_PATH_PROTOCOL **Table\r
1224 )\r
1225{\r
1226 POOL_PRINT Str;\r
1227 DEVICE_CONSIST_MAPPING_INFO MappingInfo;\r
1228 EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;\r
1229 UINTN Index;\r
1230 UINTN NewSize;\r
1231\r
1232 ASSERT(DevicePath != NULL);\r
1233 ASSERT(Table != NULL);\r
1234\r
1235 HIDevicePath = GetHIDevicePath (DevicePath);\r
1236 if (HIDevicePath == NULL) {\r
1237 return NULL;\r
1238 }\r
1239\r
1240 for (Index = 0; Table[Index] != NULL; Index++) {\r
1241 if (DevicePathCompare (&Table[Index], &HIDevicePath) == 0) {\r
1242 break;\r
1243 }\r
1244 }\r
1245\r
1246 FreePool (HIDevicePath);\r
1247 if (Table[Index] == NULL) {\r
1248 return NULL;\r
1249 }\r
1250\r
1251 MappingInfo.HI = Index;\r
1252 MappingInfo.MTD = MTDTypeUnknown;\r
1253 MappingInfo.Digital = FALSE;\r
1254\r
1255 GetDeviceConsistMappingInfo (&MappingInfo, DevicePath);\r
1256\r
1257 SetMem (&Str, sizeof (Str), 0);\r
1258 for (Index = 0; mMTDName[Index].MTDType != MTDTypeEnd; Index++) {\r
1259 if (MappingInfo.MTD == mMTDName[Index].MTDType) {\r
1260 break;\r
1261 }\r
1262 }\r
1263\r
1264 if (mMTDName[Index].MTDType != MTDTypeEnd) {\r
1265 CatPrint (&Str, L"%s", mMTDName[Index].Name);\r
1266 }\r
1267\r
1268 CatPrint (&Str, L"%d", (UINTN) MappingInfo.HI);\r
1269 if (MappingInfo.CSD.Str != NULL) {\r
1270 CatPrint (&Str, L"%s", MappingInfo.CSD.Str);\r
1271 FreePool (MappingInfo.CSD.Str);\r
1272 }\r
1273\r
1274 if (Str.Str != NULL) {\r
1275 CatPrint (&Str, L":");\r
1276 }\r
1277\r
1278 NewSize = (Str.Len + 1) * sizeof (CHAR16);\r
1279 Str.Str = ReallocatePool (Str.Len, NewSize, Str.Str);\r
1280 Str.Str[Str.Len] = CHAR_NULL;\r
1281 return Str.Str;\r
1282}\r
1283\r
1284/**\r
1285 Function to search the list of mappings for the node on the list based on the key.\r
1286\r
1287 @param[in] MapKey String Key to search for on the map\r
1288\r
1289 @return the node on the list.\r
1290**/\r
1291SHELL_MAP_LIST *\r
1292EFIAPI\r
1293ShellCommandFindMapItem (\r
1294 IN CONST CHAR16 *MapKey\r
1295 )\r
1296{\r
1297 SHELL_MAP_LIST *MapListItem;\r
1298\r
1299 for ( MapListItem = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r
1300 ; !IsNull(&gShellMapList.Link, &MapListItem->Link)\r
1301 ; MapListItem = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &MapListItem->Link)\r
1302 ){\r
1303 if (gUnicodeCollation->StriColl(gUnicodeCollation,MapListItem->MapName,(CHAR16*)MapKey) == 0) {\r
1304 return (MapListItem);\r
1305 }\r
1306 }\r
1307 return (NULL);\r
1308}\r
1309\r
1310\r