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