]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/GenericBdsLib/DevicePath.c
Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its...
[mirror_edk2.git] / MdeModulePkg / Library / GenericBdsLib / DevicePath.c
CommitLineData
897f0eee 1/** @file\r
2 BDS internal function define the default device path string, it can be\r
3 replaced by platform device path.\r
4\r
5Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "InternalBdsLib.h"\r
17\r
11ef23f9 18/**\r
897f0eee 19\r
20 Adjusts the size of a previously allocated buffer.\r
21\r
11ef23f9 22 @param OldPool A pointer to the buffer whose size is being adjusted.\r
23 @param OldSize The size of the current buffer.\r
24 @param NewSize The size of the new buffer.\r
897f0eee 25\r
11ef23f9 26 @return The new buffer allocated. If allocatio failed, NULL will be returned.\r
897f0eee 27\r
11ef23f9 28**/\r
29VOID *\r
30ReallocatePool (\r
31 IN VOID *OldPool,\r
32 IN UINTN OldSize,\r
33 IN UINTN NewSize\r
34 )\r
897f0eee 35{\r
36 VOID *NewPool;\r
37\r
38 NewPool = NULL;\r
11ef23f9 39 if (NewSize != 0) {\r
897f0eee 40 NewPool = AllocateZeroPool (NewSize);\r
41 }\r
42\r
11ef23f9 43 if (OldPool != NULL) {\r
44 if (NewPool != NULL) {\r
897f0eee 45 CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);\r
46 }\r
47\r
676df92c 48 FreePool (OldPool);\r
897f0eee 49 }\r
50\r
51 return NewPool;\r
52}\r
53\r
897f0eee 54/**\r
55 Concatenates a formatted unicode string to allocated pool.\r
56 The caller must free the resulting buffer.\r
57\r
58 @param Str Tracks the allocated pool, size in use, and amount of pool\r
59 allocated.\r
60 @param fmt The format string\r
61\r
11ef23f9 62 @param ... Variable argument list.\r
63\r
897f0eee 64 @return Allocated buffer with the formatted string printed in it.\r
11ef23f9 65 The caller must free the allocated buffer. The buffer\r
66 allocation is not packed.\r
897f0eee 67\r
68**/\r
69CHAR16 *\r
70EFIAPI\r
71CatPrint (\r
72 IN OUT POOL_PRINT *Str,\r
73 IN CHAR16 *fmt,\r
74 ...\r
75 )\r
76{\r
77 UINT16 *AppendStr;\r
11ef23f9 78 VA_LIST Args;\r
79 UINTN StringSize;\r
897f0eee 80\r
81 AppendStr = AllocateZeroPool (0x1000);\r
82 if (AppendStr == NULL) {\r
83 return Str->str;\r
84 }\r
85\r
11ef23f9 86 VA_START (Args, fmt);\r
87 UnicodeVSPrint (AppendStr, 0x1000, fmt, Args);\r
88 VA_END (Args);\r
897f0eee 89 if (NULL == Str->str) {\r
11ef23f9 90 StringSize = StrSize (AppendStr);\r
91 Str->str = AllocateZeroPool (StringSize);\r
897f0eee 92 ASSERT (Str->str != NULL);\r
93 } else {\r
11ef23f9 94 StringSize = StrSize (AppendStr);\r
95 StringSize += (StrSize (Str->str) - sizeof (UINT16));\r
897f0eee 96\r
97 Str->str = ReallocatePool (\r
98 Str->str,\r
99 StrSize (Str->str),\r
11ef23f9 100 StringSize\r
897f0eee 101 );\r
102 ASSERT (Str->str != NULL);\r
103 }\r
104\r
105 Str->maxlen = MAX_CHAR * sizeof (UINT16);\r
11ef23f9 106 if (StringSize < Str->maxlen) {\r
897f0eee 107 StrCat (Str->str, AppendStr);\r
11ef23f9 108 Str->len = StringSize - sizeof (UINT16);\r
897f0eee 109 }\r
110\r
676df92c 111 FreePool (AppendStr);\r
897f0eee 112 return Str->str;\r
113}\r
114\r
115\r
116/**\r
117 Function unpacks a device path data structure so that all the nodes\r
118 of a device path are naturally aligned.\r
119\r
120 @param DevPath A pointer to a device path data structure\r
121\r
122 @return A ponter to new device If the memory for the device path is successfully allocated, then a\r
123 pointer to the new device path is returned. Otherwise, NULL is returned.\r
124\r
125**/\r
126EFI_DEVICE_PATH_PROTOCOL *\r
127EFIAPI\r
128BdsLibUnpackDevicePath (\r
129 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
130 )\r
131{\r
132 EFI_DEVICE_PATH_PROTOCOL *Src;\r
133 EFI_DEVICE_PATH_PROTOCOL *Dest;\r
134 EFI_DEVICE_PATH_PROTOCOL *NewPath;\r
135 UINTN Size;\r
136\r
137 //\r
138 // Walk device path and round sizes to valid boundries\r
139 //\r
140 Src = DevPath;\r
141 Size = 0;\r
142 for (;;) {\r
143 Size += DevicePathNodeLength (Src);\r
144 Size += ALIGN_SIZE (Size);\r
145\r
146 if (IsDevicePathEnd (Src)) {\r
147 break;\r
148 }\r
149\r
150 Src = NextDevicePathNode (Src);\r
151 }\r
152 //\r
153 // Allocate space for the unpacked path\r
154 //\r
155 NewPath = AllocateZeroPool (Size);\r
11ef23f9 156 if (NewPath != NULL) {\r
897f0eee 157\r
158 ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0);\r
159\r
160 //\r
161 // Copy each node\r
162 //\r
163 Src = DevPath;\r
164 Dest = NewPath;\r
165 for (;;) {\r
166 Size = DevicePathNodeLength (Src);\r
167 CopyMem (Dest, Src, Size);\r
168 Size += ALIGN_SIZE (Size);\r
169 SetDevicePathNodeLength (Dest, Size);\r
170 Dest->Type |= EFI_DP_TYPE_UNPACKED;\r
171 Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size);\r
172\r
173 if (IsDevicePathEnd (Src)) {\r
174 break;\r
175 }\r
176\r
177 Src = NextDevicePathNode (Src);\r
178 }\r
179 }\r
180\r
181 return NewPath;\r
182}\r
183\r
11ef23f9 184/**\r
185 Convert Device Path to a Unicode string for printing.\r
186\r
187 @param Str The buffer holding the output string.\r
188 This buffer contains the length of the\r
189 string and the maixmum length reserved\r
190 for the string buffer.\r
191 @param DevPath The device path.\r
192\r
193**/\r
897f0eee 194VOID\r
195DevPathPci (\r
196 IN OUT POOL_PRINT *Str,\r
197 IN VOID *DevPath\r
198 )\r
199{\r
200 PCI_DEVICE_PATH *Pci;\r
201\r
202 Pci = DevPath;\r
203 CatPrint (Str, L"Pci(%x|%x)", (UINTN) Pci->Device, (UINTN) Pci->Function);\r
204}\r
205\r
11ef23f9 206/**\r
207 Convert Device Path to a Unicode string for printing.\r
208\r
209 @param Str The buffer holding the output string.\r
210 This buffer contains the length of the\r
211 string and the maixmum length reserved\r
212 for the string buffer.\r
213 @param DevPath The device path.\r
214\r
215**/\r
897f0eee 216VOID\r
217DevPathPccard (\r
218 IN OUT POOL_PRINT *Str,\r
219 IN VOID *DevPath\r
220 )\r
221{\r
222 PCCARD_DEVICE_PATH *Pccard;\r
223\r
224 Pccard = DevPath;\r
225 CatPrint (Str, L"Pcmcia(Function%x)", (UINTN) Pccard->FunctionNumber);\r
226}\r
227\r
11ef23f9 228/**\r
229 Convert Device Path to a Unicode string for printing.\r
230\r
231 @param Str The buffer holding the output string.\r
232 This buffer contains the length of the\r
233 string and the maixmum length reserved\r
234 for the string buffer.\r
235 @param DevPath The device path.\r
236\r
237**/\r
897f0eee 238VOID\r
239DevPathMemMap (\r
240 IN OUT POOL_PRINT *Str,\r
241 IN VOID *DevPath\r
242 )\r
243{\r
244 MEMMAP_DEVICE_PATH *MemMap;\r
245\r
246 MemMap = DevPath;\r
247 CatPrint (\r
248 Str,\r
249 L"MemMap(%d:%lx-%lx)",\r
250 MemMap->MemoryType,\r
251 MemMap->StartingAddress,\r
252 MemMap->EndingAddress\r
253 );\r
254}\r
255\r
11ef23f9 256/**\r
257 Convert Device Path to a Unicode string for printing.\r
258\r
259 @param Str The buffer holding the output string.\r
260 This buffer contains the length of the\r
261 string and the maixmum length reserved\r
262 for the string buffer.\r
263 @param DevPath The device path.\r
264\r
265**/\r
897f0eee 266VOID\r
267DevPathController (\r
268 IN OUT POOL_PRINT *Str,\r
269 IN VOID *DevPath\r
270 )\r
271{\r
272 CONTROLLER_DEVICE_PATH *Controller;\r
273\r
274 Controller = DevPath;\r
275 CatPrint (Str, L"Ctrl(%d)", (UINTN) Controller->ControllerNumber);\r
276}\r
277\r
278\r
279/**\r
11ef23f9 280 Convert Device Path to a Unicode string for printing.\r
897f0eee 281\r
11ef23f9 282 @param Str The buffer holding the output string.\r
283 This buffer contains the length of the\r
284 string and the maixmum length reserved\r
285 for the string buffer.\r
286 @param DevPath The device path.\r
897f0eee 287\r
288**/\r
289VOID\r
290EFIAPI\r
291DevPathVendor (\r
292 IN OUT POOL_PRINT *Str,\r
293 IN VOID *DevPath\r
294 )\r
295{\r
296 VENDOR_DEVICE_PATH *Vendor;\r
297 CHAR16 *Type;\r
298 UINTN DataLength;\r
299 UINTN Index;\r
300 UINT32 FlowControlMap;\r
301\r
302 UINT16 Info;\r
303\r
304 Vendor = DevPath;\r
305\r
306 switch (DevicePathType (&Vendor->Header)) {\r
307 case HARDWARE_DEVICE_PATH:\r
308 Type = L"Hw";\r
897f0eee 309 break;\r
310\r
311 case MESSAGING_DEVICE_PATH:\r
312 Type = L"Msg";\r
313 if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {\r
314 CatPrint (Str, L"VenPcAnsi()");\r
315 return ;\r
316 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {\r
317 CatPrint (Str, L"VenVt100()");\r
318 return ;\r
319 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {\r
320 CatPrint (Str, L"VenVt100Plus()");\r
321 return ;\r
322 } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {\r
323 CatPrint (Str, L"VenUft8()");\r
324 return ;\r
ec8cd35c 325 } else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid )) {\r
897f0eee 326 FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);\r
327 switch (FlowControlMap & 0x00000003) {\r
328 case 0:\r
329 CatPrint (Str, L"UartFlowCtrl(%s)", L"None");\r
330 break;\r
331\r
332 case 1:\r
333 CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");\r
334 break;\r
335\r
336 case 2:\r
337 CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");\r
338 break;\r
339\r
340 default:\r
341 break;\r
342 }\r
343\r
344 return ;\r
345\r
ec8cd35c 346 } else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {\r
897f0eee 347 CatPrint (\r
348 Str,\r
349 L"SAS(%lx,%lx,%x,",\r
350 ((SAS_DEVICE_PATH *) Vendor)->SasAddress,\r
351 ((SAS_DEVICE_PATH *) Vendor)->Lun,\r
352 ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort\r
353 );\r
354 Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);\r
355 if ((Info & 0x0f) == 0) {\r
356 CatPrint (Str, L"NoTopology,0,0,0,");\r
357 } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {\r
358 CatPrint (\r
359 Str,\r
360 L"%s,%s,%s,",\r
11ef23f9 361 ((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",\r
362 ((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",\r
363 ((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"\r
897f0eee 364 );\r
365 if ((Info & 0x0f) == 1) {\r
366 CatPrint (Str, L"0,");\r
367 } else {\r
368 CatPrint (Str, L"%x,", (UINTN) ((Info >> 8) & 0xff));\r
369 }\r
370 } else {\r
371 CatPrint (Str, L"0,0,0,0,");\r
372 }\r
373\r
374 CatPrint (Str, L"%x)", (UINTN) ((SAS_DEVICE_PATH *) Vendor)->Reserved);\r
375 return ;\r
376\r
377 } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {\r
378 CatPrint (Str, L"DebugPort()");\r
379 return ;\r
380 }\r
381 break;\r
382\r
383 case MEDIA_DEVICE_PATH:\r
384 Type = L"Media";\r
385 break;\r
386\r
387 default:\r
388 Type = L"?";\r
389 break;\r
390 }\r
391\r
392 CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);\r
393 DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);\r
394 if (DataLength > 0) {\r
395 CatPrint (Str, L",");\r
396 for (Index = 0; Index < DataLength; Index++) {\r
397 CatPrint (Str, L"%02x", (UINTN) ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);\r
398 }\r
399 }\r
400 CatPrint (Str, L")");\r
401}\r
402\r
11ef23f9 403/**\r
404 Convert Device Path to a Unicode string for printing.\r
405\r
406 @param Str The buffer holding the output string.\r
407 This buffer contains the length of the\r
408 string and the maixmum length reserved\r
409 for the string buffer.\r
410 @param DevPath The device path.\r
411\r
412**/\r
897f0eee 413VOID\r
414DevPathAcpi (\r
415 IN OUT POOL_PRINT *Str,\r
416 IN VOID *DevPath\r
417 )\r
418{\r
419 ACPI_HID_DEVICE_PATH *Acpi;\r
420\r
421 Acpi = DevPath;\r
422 if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
423 CatPrint (Str, L"Acpi(PNP%04x,%x)", (UINTN) EISA_ID_TO_NUM (Acpi->HID), (UINTN) Acpi->UID);\r
424 } else {\r
425 CatPrint (Str, L"Acpi(%08x,%x)", (UINTN) Acpi->HID, (UINTN) Acpi->UID);\r
426 }\r
427}\r
428\r
11ef23f9 429/**\r
430 Convert Device Path to a Unicode string for printing.\r
431\r
432 @param Str The buffer holding the output string.\r
433 This buffer contains the length of the\r
434 string and the maixmum length reserved\r
435 for the string buffer.\r
436 @param DevPath The device path.\r
437\r
438**/\r
897f0eee 439VOID\r
440DevPathExtendedAcpi (\r
441 IN OUT POOL_PRINT *Str,\r
442 IN VOID *DevPath\r
443 )\r
444{\r
445 ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi;\r
ec8cd35c 446 \r
897f0eee 447 //\r
448 // Index for HID, UID and CID strings, 0 for non-exist\r
449 //\r
450 UINT16 HIDSTRIdx;\r
451 UINT16 UIDSTRIdx;\r
452 UINT16 CIDSTRIdx;\r
453 UINT16 Index;\r
454 UINT16 Length;\r
455 UINT16 Anchor;\r
456 CHAR8 *AsChar8Array;\r
457\r
458 ASSERT (Str != NULL);\r
459 ASSERT (DevPath != NULL);\r
460\r
461 HIDSTRIdx = 0;\r
462 UIDSTRIdx = 0;\r
463 CIDSTRIdx = 0;\r
464 ExtendedAcpi = DevPath;\r
465 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);\r
466\r
467 ASSERT (Length >= 19);\r
468 AsChar8Array = (CHAR8 *) ExtendedAcpi;\r
469\r
470 //\r
471 // find HIDSTR\r
472 //\r
473 Anchor = 16;\r
11ef23f9 474 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {\r
897f0eee 475 ;\r
476 }\r
477 if (Index > Anchor) {\r
478 HIDSTRIdx = Anchor;\r
479 }\r
480 //\r
481 // find UIDSTR\r
482 //\r
483 Anchor = (UINT16) (Index + 1);\r
11ef23f9 484 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {\r
897f0eee 485 ;\r
486 }\r
487 if (Index > Anchor) {\r
488 UIDSTRIdx = Anchor;\r
489 }\r
490 //\r
491 // find CIDSTR\r
492 //\r
493 Anchor = (UINT16) (Index + 1);\r
11ef23f9 494 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {\r
897f0eee 495 ;\r
496 }\r
497 if (Index > Anchor) {\r
498 CIDSTRIdx = Anchor;\r
499 }\r
500\r
501 if (HIDSTRIdx == 0 && CIDSTRIdx == 0 && ExtendedAcpi->UID == 0) {\r
502 CatPrint (Str, L"AcpiExp(");\r
503 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
504 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));\r
505 } else {\r
506 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);\r
507 }\r
508 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
509 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));\r
510 } else {\r
511 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);\r
512 }\r
513 if (UIDSTRIdx != 0) {\r
514 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);\r
515 } else {\r
516 CatPrint (Str, L"\"\")");\r
517 }\r
518 } else {\r
519 CatPrint (Str, L"AcpiEx(");\r
520 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
521 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));\r
522 } else {\r
523 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);\r
524 }\r
525 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
526 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));\r
527 } else {\r
528 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);\r
529 }\r
530 CatPrint (Str, L"%x,", (UINTN) ExtendedAcpi->UID);\r
531\r
532 if (HIDSTRIdx != 0) {\r
533 CatPrint (Str, L"%a,", AsChar8Array + HIDSTRIdx);\r
534 } else {\r
535 CatPrint (Str, L"\"\",");\r
536 }\r
537 if (CIDSTRIdx != 0) {\r
538 CatPrint (Str, L"%a,", AsChar8Array + CIDSTRIdx);\r
539 } else {\r
540 CatPrint (Str, L"\"\",");\r
541 }\r
542 if (UIDSTRIdx != 0) {\r
543 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);\r
544 } else {\r
545 CatPrint (Str, L"\"\")");\r
546 }\r
547 }\r
548\r
549}\r
550\r
11ef23f9 551/**\r
552 Convert Device Path to a Unicode string for printing.\r
553\r
554 @param Str The buffer holding the output string.\r
555 This buffer contains the length of the\r
556 string and the maixmum length reserved\r
557 for the string buffer.\r
558 @param DevPath The device path.\r
559\r
560**/\r
897f0eee 561VOID\r
562DevPathAdrAcpi (\r
563 IN OUT POOL_PRINT *Str,\r
564 IN VOID *DevPath\r
565 )\r
566{\r
567 ACPI_ADR_DEVICE_PATH *AcpiAdr;\r
568 UINT16 Index;\r
569 UINT16 Length;\r
570 UINT16 AdditionalAdrCount;\r
571\r
572 AcpiAdr = DevPath;\r
573 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);\r
574 AdditionalAdrCount = (UINT16) ((Length - 8) / 4);\r
575\r
576 CatPrint (Str, L"AcpiAdr(%x", (UINTN) AcpiAdr->ADR);\r
577 for (Index = 0; Index < AdditionalAdrCount; Index++) {\r
578 CatPrint (Str, L",%x", (UINTN) *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));\r
579 }\r
580 CatPrint (Str, L")");\r
581}\r
582\r
11ef23f9 583/**\r
584 Convert Device Path to a Unicode string for printing.\r
585\r
586 @param Str The buffer holding the output string.\r
587 This buffer contains the length of the\r
588 string and the maixmum length reserved\r
589 for the string buffer.\r
590 @param DevPath The device path.\r
591\r
592**/\r
897f0eee 593VOID\r
594DevPathAtapi (\r
595 IN OUT POOL_PRINT *Str,\r
596 IN VOID *DevPath\r
597 )\r
598{\r
599 ATAPI_DEVICE_PATH *Atapi;\r
600\r
601 Atapi = DevPath;\r
602 CatPrint (\r
603 Str,\r
604 L"Ata(%s,%s)",\r
605 Atapi->PrimarySecondary ? L"Secondary" : L"Primary",\r
606 Atapi->SlaveMaster ? L"Slave" : L"Master"\r
607 );\r
608}\r
609\r
11ef23f9 610/**\r
611 Convert Device Path to a Unicode string for printing.\r
612\r
613 @param Str The buffer holding the output string.\r
614 This buffer contains the length of the\r
615 string and the maixmum length reserved\r
616 for the string buffer.\r
617 @param DevPath The device path.\r
618\r
619**/\r
897f0eee 620VOID\r
621DevPathScsi (\r
622 IN OUT POOL_PRINT *Str,\r
623 IN VOID *DevPath\r
624 )\r
625{\r
626 SCSI_DEVICE_PATH *Scsi;\r
627\r
628 Scsi = DevPath;\r
629 CatPrint (Str, L"Scsi(Pun%x,Lun%x)", (UINTN) Scsi->Pun, (UINTN) Scsi->Lun);\r
630}\r
631\r
11ef23f9 632/**\r
633 Convert Device Path to a Unicode string for printing.\r
634\r
635 @param Str The buffer holding the output string.\r
636 This buffer contains the length of the\r
637 string and the maixmum length reserved\r
638 for the string buffer.\r
639 @param DevPath The device path.\r
640\r
641**/\r
897f0eee 642VOID\r
643DevPathFibre (\r
644 IN OUT POOL_PRINT *Str,\r
645 IN VOID *DevPath\r
646 )\r
647{\r
648 FIBRECHANNEL_DEVICE_PATH *Fibre;\r
649\r
650 Fibre = DevPath;\r
651 CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);\r
652}\r
653\r
11ef23f9 654/**\r
655 Convert Device Path to a Unicode string for printing.\r
656\r
657 @param Str The buffer holding the output string.\r
658 This buffer contains the length of the\r
659 string and the maixmum length reserved\r
660 for the string buffer.\r
661 @param DevPath The device path.\r
662\r
663**/\r
897f0eee 664VOID\r
665DevPath1394 (\r
666 IN OUT POOL_PRINT *Str,\r
667 IN VOID *DevPath\r
668 )\r
669{\r
11ef23f9 670 F1394_DEVICE_PATH *F1394Path;\r
897f0eee 671\r
11ef23f9 672 F1394Path = DevPath;\r
673 CatPrint (Str, L"1394(%g)", &F1394Path->Guid);\r
897f0eee 674}\r
675\r
11ef23f9 676/**\r
677 Convert Device Path to a Unicode string for printing.\r
678\r
679 @param Str The buffer holding the output string.\r
680 This buffer contains the length of the\r
681 string and the maixmum length reserved\r
682 for the string buffer.\r
683 @param DevPath The device path.\r
684\r
685**/\r
897f0eee 686VOID\r
687DevPathUsb (\r
688 IN OUT POOL_PRINT *Str,\r
689 IN VOID *DevPath\r
690 )\r
691{\r
692 USB_DEVICE_PATH *Usb;\r
693\r
694 Usb = DevPath;\r
695 CatPrint (Str, L"Usb(%x,%x)", (UINTN) Usb->ParentPortNumber, (UINTN) Usb->InterfaceNumber);\r
696}\r
697\r
11ef23f9 698/**\r
699 Convert Device Path to a Unicode string for printing.\r
700\r
701 @param Str The buffer holding the output string.\r
702 This buffer contains the length of the\r
703 string and the maixmum length reserved\r
704 for the string buffer.\r
705 @param DevPath The device path.\r
706\r
707**/\r
897f0eee 708VOID\r
709DevPathUsbWWID (\r
710 IN OUT POOL_PRINT *Str,\r
711 IN VOID *DevPath\r
712 )\r
713{\r
714 USB_WWID_DEVICE_PATH *UsbWWId;\r
715\r
716 UsbWWId = DevPath;\r
717 CatPrint (\r
718 Str,\r
719 L"UsbWwid(%x,%x,%x,\"WWID\")",\r
720 (UINTN) UsbWWId->VendorId,\r
721 (UINTN) UsbWWId->ProductId,\r
722 (UINTN) UsbWWId->InterfaceNumber\r
723 );\r
724}\r
725\r
11ef23f9 726/**\r
727 Convert Device Path to a Unicode string for printing.\r
728\r
729 @param Str The buffer holding the output string.\r
730 This buffer contains the length of the\r
731 string and the maixmum length reserved\r
732 for the string buffer.\r
733 @param DevPath The device path.\r
734\r
735**/\r
897f0eee 736VOID\r
737DevPathLogicalUnit (\r
738 IN OUT POOL_PRINT *Str,\r
739 IN VOID *DevPath\r
740 )\r
741{\r
742 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;\r
743\r
744 LogicalUnit = DevPath;\r
745 CatPrint (Str, L"Unit(%x)", (UINTN) LogicalUnit->Lun);\r
746}\r
747\r
11ef23f9 748/**\r
749 Convert Device Path to a Unicode string for printing.\r
750\r
751 @param Str The buffer holding the output string.\r
752 This buffer contains the length of the\r
753 string and the maixmum length reserved\r
754 for the string buffer.\r
755 @param DevPath The device path.\r
756\r
757**/\r
897f0eee 758VOID\r
759DevPathUsbClass (\r
760 IN OUT POOL_PRINT *Str,\r
761 IN VOID *DevPath\r
762 )\r
763{\r
764 USB_CLASS_DEVICE_PATH *UsbClass;\r
765\r
766 UsbClass = DevPath;\r
767 CatPrint (\r
768 Str,\r
769 L"Usb Class(%x,%x,%x,%x,%x)",\r
770 (UINTN) UsbClass->VendorId,\r
771 (UINTN) UsbClass->ProductId,\r
772 (UINTN) UsbClass->DeviceClass,\r
773 (UINTN) UsbClass->DeviceSubClass,\r
774 (UINTN) UsbClass->DeviceProtocol\r
775 );\r
776}\r
777\r
11ef23f9 778/**\r
779 Convert Device Path to a Unicode string for printing.\r
780\r
781 @param Str The buffer holding the output string.\r
782 This buffer contains the length of the\r
783 string and the maixmum length reserved\r
784 for the string buffer.\r
785 @param DevPath The device path.\r
786\r
787**/\r
897f0eee 788VOID\r
789DevPathSata (\r
790 IN OUT POOL_PRINT *Str,\r
791 IN VOID *DevPath\r
792 )\r
793{\r
794 SATA_DEVICE_PATH *Sata;\r
795\r
796 Sata = DevPath;\r
797 CatPrint (\r
798 Str,\r
799 L"Sata(%x,%x,%x)",\r
800 (UINTN) Sata->HBAPortNumber,\r
801 (UINTN) Sata->PortMultiplierPortNumber,\r
802 (UINTN) Sata->Lun\r
803 );\r
804}\r
805\r
11ef23f9 806/**\r
807 Convert Device Path to a Unicode string for printing.\r
808\r
809 @param Str The buffer holding the output string.\r
810 This buffer contains the length of the\r
811 string and the maixmum length reserved\r
812 for the string buffer.\r
813 @param DevPath The device path.\r
814\r
815**/\r
897f0eee 816VOID\r
817DevPathI2O (\r
818 IN OUT POOL_PRINT *Str,\r
819 IN VOID *DevPath\r
820 )\r
821{\r
11ef23f9 822 I2O_DEVICE_PATH *I2OPath;\r
897f0eee 823\r
11ef23f9 824 I2OPath = DevPath;\r
825 CatPrint (Str, L"I2O(%x)", (UINTN) I2OPath->Tid);\r
897f0eee 826}\r
827\r
11ef23f9 828/**\r
829 Convert Device Path to a Unicode string for printing.\r
830\r
831 @param Str The buffer holding the output string.\r
832 This buffer contains the length of the\r
833 string and the maixmum length reserved\r
834 for the string buffer.\r
835 @param DevPath The device path.\r
836\r
837**/\r
897f0eee 838VOID\r
839DevPathMacAddr (\r
840 IN OUT POOL_PRINT *Str,\r
841 IN VOID *DevPath\r
842 )\r
843{\r
11ef23f9 844 MAC_ADDR_DEVICE_PATH *MACDevPath;\r
897f0eee 845 UINTN HwAddressSize;\r
846 UINTN Index;\r
847\r
11ef23f9 848 MACDevPath = DevPath;\r
897f0eee 849\r
850 HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r
11ef23f9 851 if (MACDevPath->IfType == 0x01 || MACDevPath->IfType == 0x00) {\r
897f0eee 852 HwAddressSize = 6;\r
853 }\r
854\r
855 CatPrint (Str, L"Mac(");\r
856\r
857 for (Index = 0; Index < HwAddressSize; Index++) {\r
11ef23f9 858 CatPrint (Str, L"%02x", (UINTN) MACDevPath->MacAddress.Addr[Index]);\r
897f0eee 859 }\r
860\r
861 CatPrint (Str, L")");\r
862}\r
863\r
11ef23f9 864/**\r
865 Convert Device Path to a Unicode string for printing.\r
866\r
867 @param Str The buffer holding the output string.\r
868 This buffer contains the length of the\r
869 string and the maixmum length reserved\r
870 for the string buffer.\r
871 @param DevPath The device path.\r
872\r
873**/\r
897f0eee 874VOID\r
875DevPathIPv4 (\r
876 IN OUT POOL_PRINT *Str,\r
877 IN VOID *DevPath\r
878 )\r
879{\r
11ef23f9 880 IPv4_DEVICE_PATH *IPDevPath;\r
897f0eee 881\r
11ef23f9 882 IPDevPath = DevPath;\r
897f0eee 883 CatPrint (\r
884 Str,\r
885 L"IPv4(%d.%d.%d.%d:%d)",\r
11ef23f9 886 (UINTN) IPDevPath->RemoteIpAddress.Addr[0],\r
887 (UINTN) IPDevPath->RemoteIpAddress.Addr[1],\r
888 (UINTN) IPDevPath->RemoteIpAddress.Addr[2],\r
889 (UINTN) IPDevPath->RemoteIpAddress.Addr[3],\r
890 (UINTN) IPDevPath->RemotePort\r
897f0eee 891 );\r
892}\r
893\r
11ef23f9 894/**\r
895 Convert Device Path to a Unicode string for printing.\r
896\r
897 @param Str The buffer holding the output string.\r
898 This buffer contains the length of the\r
899 string and the maixmum length reserved\r
900 for the string buffer.\r
901 @param DevPath The device path.\r
902\r
903**/\r
897f0eee 904VOID\r
905DevPathIPv6 (\r
906 IN OUT POOL_PRINT *Str,\r
907 IN VOID *DevPath\r
908 )\r
909{\r
11ef23f9 910 IPv6_DEVICE_PATH *IPv6DevPath;\r
897f0eee 911\r
11ef23f9 912 IPv6DevPath = DevPath;\r
897f0eee 913 CatPrint (\r
914 Str,\r
915 L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",\r
11ef23f9 916 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[0],\r
917 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[1],\r
918 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[2],\r
919 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[3],\r
920 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[4],\r
921 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[5],\r
922 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[6],\r
923 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[7],\r
924 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[8],\r
925 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[9],\r
926 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[10],\r
927 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[11],\r
928 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[12],\r
929 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[13],\r
930 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[14],\r
931 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[15]\r
897f0eee 932 );\r
933}\r
934\r
11ef23f9 935/**\r
936 Convert Device Path to a Unicode string for printing.\r
937\r
938 @param Str The buffer holding the output string.\r
939 This buffer contains the length of the\r
940 string and the maixmum length reserved\r
941 for the string buffer.\r
942 @param DevPath The device path.\r
943\r
944**/\r
897f0eee 945VOID\r
946DevPathInfiniBand (\r
947 IN OUT POOL_PRINT *Str,\r
948 IN VOID *DevPath\r
949 )\r
950{\r
951 INFINIBAND_DEVICE_PATH *InfiniBand;\r
952\r
953 InfiniBand = DevPath;\r
954 CatPrint (\r
955 Str,\r
956 L"Infiniband(%x,%g,%lx,%lx,%lx)",\r
957 (UINTN) InfiniBand->ResourceFlags,\r
958 InfiniBand->PortGid,\r
959 InfiniBand->ServiceId,\r
960 InfiniBand->TargetPortId,\r
961 InfiniBand->DeviceId\r
962 );\r
963}\r
964\r
11ef23f9 965/**\r
966 Convert Device Path to a Unicode string for printing.\r
967\r
968 @param Str The buffer holding the output string.\r
969 This buffer contains the length of the\r
970 string and the maixmum length reserved\r
971 for the string buffer.\r
972 @param DevPath The device path.\r
973\r
974**/\r
897f0eee 975VOID\r
976DevPathUart (\r
977 IN OUT POOL_PRINT *Str,\r
978 IN VOID *DevPath\r
979 )\r
980{\r
981 UART_DEVICE_PATH *Uart;\r
982 CHAR8 Parity;\r
983\r
984 Uart = DevPath;\r
985 switch (Uart->Parity) {\r
986 case 0:\r
987 Parity = 'D';\r
988 break;\r
989\r
990 case 1:\r
991 Parity = 'N';\r
992 break;\r
993\r
994 case 2:\r
995 Parity = 'E';\r
996 break;\r
997\r
998 case 3:\r
999 Parity = 'O';\r
1000 break;\r
1001\r
1002 case 4:\r
1003 Parity = 'M';\r
1004 break;\r
1005\r
1006 case 5:\r
1007 Parity = 'S';\r
1008 break;\r
1009\r
1010 default:\r
1011 Parity = 'x';\r
1012 break;\r
1013 }\r
1014\r
1015 if (Uart->BaudRate == 0) {\r
1016 CatPrint (Str, L"Uart(DEFAULT,%c,", Parity);\r
1017 } else {\r
1018 CatPrint (Str, L"Uart(%d,%c,", Uart->BaudRate, Parity);\r
1019 }\r
1020\r
1021 if (Uart->DataBits == 0) {\r
1022 CatPrint (Str, L"D,");\r
1023 } else {\r
1024 CatPrint (Str, L"%d,", (UINTN) Uart->DataBits);\r
1025 }\r
1026\r
1027 switch (Uart->StopBits) {\r
1028 case 0:\r
1029 CatPrint (Str, L"D)");\r
1030 break;\r
1031\r
1032 case 1:\r
1033 CatPrint (Str, L"1)");\r
1034 break;\r
1035\r
1036 case 2:\r
1037 CatPrint (Str, L"1.5)");\r
1038 break;\r
1039\r
1040 case 3:\r
1041 CatPrint (Str, L"2)");\r
1042 break;\r
1043\r
1044 default:\r
1045 CatPrint (Str, L"x)");\r
1046 break;\r
1047 }\r
1048}\r
1049\r
11ef23f9 1050/**\r
1051 Convert Device Path to a Unicode string for printing.\r
1052\r
1053 @param Str The buffer holding the output string.\r
1054 This buffer contains the length of the\r
1055 string and the maixmum length reserved\r
1056 for the string buffer.\r
1057 @param DevPath The device path.\r
1058\r
1059**/\r
897f0eee 1060VOID\r
1061DevPathiSCSI (\r
1062 IN OUT POOL_PRINT *Str,\r
1063 IN VOID *DevPath\r
1064 )\r
1065{\r
11ef23f9 1066 ISCSI_DEVICE_PATH_WITH_NAME *IScsi;\r
897f0eee 1067 UINT16 Options;\r
1068\r
1069 ASSERT (Str != NULL);\r
1070 ASSERT (DevPath != NULL);\r
1071\r
11ef23f9 1072 IScsi = DevPath;\r
897f0eee 1073 CatPrint (\r
1074 Str,\r
1075 L"iSCSI(%s,%x,%lx,",\r
11ef23f9 1076 IScsi->iSCSITargetName,\r
1077 IScsi->TargetPortalGroupTag,\r
1078 IScsi->Lun\r
897f0eee 1079 );\r
1080\r
11ef23f9 1081 Options = IScsi->LoginOption;\r
1082 CatPrint (Str, L"%s,", (((Options >> 1) & 0x0001) != 0) ? L"CRC32C" : L"None");\r
1083 CatPrint (Str, L"%s,", (((Options >> 3) & 0x0001) != 0) ? L"CRC32C" : L"None");\r
1084 if (((Options >> 11) & 0x0001) != 0) {\r
897f0eee 1085 CatPrint (Str, L"%s,", L"None");\r
11ef23f9 1086 } else if (((Options >> 12) & 0x0001) != 0) {\r
897f0eee 1087 CatPrint (Str, L"%s,", L"CHAP_UNI");\r
1088 } else {\r
1089 CatPrint (Str, L"%s,", L"CHAP_BI");\r
1090\r
1091 }\r
1092\r
11ef23f9 1093 CatPrint (Str, L"%s)", (IScsi->NetworkProtocol == 0) ? L"TCP" : L"reserved");\r
897f0eee 1094}\r
1095\r
11ef23f9 1096/**\r
1097 Convert Device Path to a Unicode string for printing.\r
1098\r
1099 @param Str The buffer holding the output string.\r
1100 This buffer contains the length of the\r
1101 string and the maixmum length reserved\r
1102 for the string buffer.\r
1103 @param DevPath The device path.\r
1104\r
1105**/\r
897f0eee 1106VOID\r
1107DevPathHardDrive (\r
1108 IN OUT POOL_PRINT *Str,\r
1109 IN VOID *DevPath\r
1110 )\r
1111{\r
1112 HARDDRIVE_DEVICE_PATH *Hd;\r
1113\r
1114 Hd = DevPath;\r
1115 switch (Hd->SignatureType) {\r
1116 case SIGNATURE_TYPE_MBR:\r
1117 CatPrint (\r
1118 Str,\r
1119 L"HD(Part%d,Sig%08x)",\r
1120 (UINTN) Hd->PartitionNumber,\r
1121 (UINTN) *((UINT32 *) (&(Hd->Signature[0])))\r
1122 );\r
1123 break;\r
1124\r
1125 case SIGNATURE_TYPE_GUID:\r
1126 CatPrint (\r
1127 Str,\r
1128 L"HD(Part%d,Sig%g)",\r
1129 (UINTN) Hd->PartitionNumber,\r
1130 (EFI_GUID *) &(Hd->Signature[0])\r
1131 );\r
1132 break;\r
1133\r
1134 default:\r
1135 CatPrint (\r
1136 Str,\r
1137 L"HD(Part%d,MBRType=%02x,SigType=%02x)",\r
1138 (UINTN) Hd->PartitionNumber,\r
1139 (UINTN) Hd->MBRType,\r
1140 (UINTN) Hd->SignatureType\r
1141 );\r
1142 break;\r
1143 }\r
1144}\r
1145\r
11ef23f9 1146/**\r
1147 Convert Device Path to a Unicode string for printing.\r
1148\r
1149 @param Str The buffer holding the output string.\r
1150 This buffer contains the length of the\r
1151 string and the maixmum length reserved\r
1152 for the string buffer.\r
1153 @param DevPath The device path.\r
1154\r
1155**/\r
897f0eee 1156VOID\r
1157DevPathCDROM (\r
1158 IN OUT POOL_PRINT *Str,\r
1159 IN VOID *DevPath\r
1160 )\r
1161{\r
1162 CDROM_DEVICE_PATH *Cd;\r
1163\r
1164 Cd = DevPath;\r
1165 CatPrint (Str, L"CDROM(Entry%x)", (UINTN) Cd->BootEntry);\r
1166}\r
1167\r
11ef23f9 1168/**\r
1169 Convert Device Path to a Unicode string for printing.\r
1170\r
1171 @param Str The buffer holding the output string.\r
1172 This buffer contains the length of the\r
1173 string and the maixmum length reserved\r
1174 for the string buffer.\r
1175 @param DevPath The device path.\r
1176\r
1177**/\r
897f0eee 1178VOID\r
1179DevPathFilePath (\r
1180 IN OUT POOL_PRINT *Str,\r
1181 IN VOID *DevPath\r
1182 )\r
1183{\r
1184 FILEPATH_DEVICE_PATH *Fp;\r
1185\r
1186 Fp = DevPath;\r
1187 CatPrint (Str, L"%s", Fp->PathName);\r
1188}\r
1189\r
11ef23f9 1190/**\r
1191 Convert Device Path to a Unicode string for printing.\r
1192\r
1193 @param Str The buffer holding the output string.\r
1194 This buffer contains the length of the\r
1195 string and the maixmum length reserved\r
1196 for the string buffer.\r
1197 @param DevPath The device path.\r
1198\r
1199**/\r
897f0eee 1200VOID\r
1201DevPathMediaProtocol (\r
1202 IN OUT POOL_PRINT *Str,\r
1203 IN VOID *DevPath\r
1204 )\r
1205{\r
1206 MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;\r
1207\r
1208 MediaProt = DevPath;\r
1209 CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);\r
1210}\r
1211\r
11ef23f9 1212/**\r
1213 Convert Device Path to a Unicode string for printing.\r
1214\r
1215 @param Str The buffer holding the output string.\r
1216 This buffer contains the length of the\r
1217 string and the maixmum length reserved\r
1218 for the string buffer.\r
1219 @param DevPath The device path.\r
1220\r
1221**/\r
897f0eee 1222VOID\r
1223DevPathFvFilePath (\r
1224 IN OUT POOL_PRINT *Str,\r
1225 IN VOID *DevPath\r
1226 )\r
1227{\r
1228 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;\r
1229\r
1230 FvFilePath = DevPath;\r
1231 CatPrint (Str, L"%g", &FvFilePath->FvFileName);\r
1232}\r
1233\r
11ef23f9 1234/**\r
1235 Convert Device Path to a Unicode string for printing.\r
1236\r
1237 @param Str The buffer holding the output string.\r
1238 This buffer contains the length of the\r
1239 string and the maixmum length reserved\r
1240 for the string buffer.\r
1241 @param DevPath The device path.\r
1242\r
1243**/\r
897f0eee 1244VOID\r
1245DevPathBssBss (\r
1246 IN OUT POOL_PRINT *Str,\r
1247 IN VOID *DevPath\r
1248 )\r
1249{\r
1250 BBS_BBS_DEVICE_PATH *Bbs;\r
1251 CHAR16 *Type;\r
1252\r
1253 Bbs = DevPath;\r
1254 switch (Bbs->DeviceType) {\r
1255 case BBS_TYPE_FLOPPY:\r
1256 Type = L"Floppy";\r
1257 break;\r
1258\r
1259 case BBS_TYPE_HARDDRIVE:\r
1260 Type = L"Harddrive";\r
1261 break;\r
1262\r
1263 case BBS_TYPE_CDROM:\r
1264 Type = L"CDROM";\r
1265 break;\r
1266\r
1267 case BBS_TYPE_PCMCIA:\r
1268 Type = L"PCMCIA";\r
1269 break;\r
1270\r
1271 case BBS_TYPE_USB:\r
1272 Type = L"Usb";\r
1273 break;\r
1274\r
1275 case BBS_TYPE_EMBEDDED_NETWORK:\r
1276 Type = L"Net";\r
1277 break;\r
1278\r
1279 case BBS_TYPE_BEV:\r
1280 Type = L"BEV";\r
1281 break;\r
1282\r
1283 default:\r
1284 Type = L"?";\r
1285 break;\r
1286 }\r
1287 CatPrint (Str, L"Legacy-%s", Type);\r
1288}\r
1289\r
11ef23f9 1290/**\r
1291 Convert Device Path to a Unicode string for printing.\r
1292\r
1293 @param Str The buffer holding the output string.\r
1294 This buffer contains the length of the\r
1295 string and the maixmum length reserved\r
1296 for the string buffer.\r
1297 @param DevPath The device path.\r
1298\r
1299**/\r
897f0eee 1300VOID\r
1301DevPathEndInstance (\r
1302 IN OUT POOL_PRINT *Str,\r
1303 IN VOID *DevPath\r
1304 )\r
1305{\r
1306 CatPrint (Str, L",");\r
1307}\r
1308\r
11ef23f9 1309/**\r
1310 Convert Device Path to a Unicode string for printing.\r
1311\r
1312 @param Str The buffer holding the output string.\r
1313 This buffer contains the length of the\r
1314 string and the maixmum length reserved\r
1315 for the string buffer.\r
1316 @param DevPath The device path.\r
1317\r
1318**/\r
897f0eee 1319VOID\r
1320DevPathNodeUnknown (\r
1321 IN OUT POOL_PRINT *Str,\r
1322 IN VOID *DevPath\r
1323 )\r
1324{\r
1325 CatPrint (Str, L"?");\r
1326}\r
1327\r
1328DEVICE_PATH_STRING_TABLE DevPathTable[] = {\r
7b25a79d 1329 {\r
1330 HARDWARE_DEVICE_PATH,\r
1331 HW_PCI_DP,\r
1332 DevPathPci\r
1333 },\r
1334 {\r
1335 HARDWARE_DEVICE_PATH,\r
1336 HW_PCCARD_DP,\r
1337 DevPathPccard\r
1338 },\r
1339 {\r
1340 HARDWARE_DEVICE_PATH,\r
1341 HW_MEMMAP_DP,\r
1342 DevPathMemMap\r
1343 },\r
1344 {\r
1345 HARDWARE_DEVICE_PATH,\r
1346 HW_VENDOR_DP,\r
1347 DevPathVendor\r
1348 },\r
1349 {\r
1350 HARDWARE_DEVICE_PATH,\r
1351 HW_CONTROLLER_DP,\r
1352 DevPathController\r
1353 },\r
1354 {\r
1355 ACPI_DEVICE_PATH,\r
1356 ACPI_DP,\r
1357 DevPathAcpi\r
1358 },\r
1359 {\r
1360 ACPI_DEVICE_PATH,\r
1361 ACPI_EXTENDED_DP,\r
1362 DevPathExtendedAcpi\r
1363 },\r
1364 {\r
1365 ACPI_DEVICE_PATH,\r
1366 ACPI_ADR_DP,\r
1367 DevPathAdrAcpi\r
1368 },\r
1369 {\r
1370 MESSAGING_DEVICE_PATH,\r
1371 MSG_ATAPI_DP,\r
1372 DevPathAtapi\r
1373 },\r
1374 {\r
1375 MESSAGING_DEVICE_PATH,\r
1376 MSG_SCSI_DP,\r
1377 DevPathScsi\r
1378 },\r
1379 {\r
1380 MESSAGING_DEVICE_PATH,\r
1381 MSG_FIBRECHANNEL_DP,\r
1382 DevPathFibre\r
1383 },\r
1384 {\r
1385 MESSAGING_DEVICE_PATH,\r
1386 MSG_1394_DP,\r
1387 DevPath1394\r
1388 },\r
1389 {\r
1390 MESSAGING_DEVICE_PATH,\r
1391 MSG_USB_DP,\r
1392 DevPathUsb\r
1393 },\r
1394 {\r
1395 MESSAGING_DEVICE_PATH,\r
1396 MSG_USB_WWID_DP,\r
1397 DevPathUsbWWID\r
1398 },\r
1399 {\r
1400 MESSAGING_DEVICE_PATH,\r
1401 MSG_DEVICE_LOGICAL_UNIT_DP,\r
1402 DevPathLogicalUnit\r
1403 },\r
1404 {\r
1405 MESSAGING_DEVICE_PATH,\r
1406 MSG_USB_CLASS_DP,\r
1407 DevPathUsbClass\r
1408 },\r
1409 {\r
1410 MESSAGING_DEVICE_PATH,\r
1411 MSG_SATA_DP,\r
1412 DevPathSata\r
1413 },\r
1414 {\r
1415 MESSAGING_DEVICE_PATH,\r
1416 MSG_I2O_DP,\r
1417 DevPathI2O\r
1418 },\r
1419 {\r
1420 MESSAGING_DEVICE_PATH,\r
1421 MSG_MAC_ADDR_DP,\r
1422 DevPathMacAddr\r
1423 },\r
1424 {\r
1425 MESSAGING_DEVICE_PATH,\r
1426 MSG_IPv4_DP,\r
1427 DevPathIPv4\r
1428 },\r
1429 {\r
1430 MESSAGING_DEVICE_PATH,\r
1431 MSG_IPv6_DP,\r
1432 DevPathIPv6\r
1433 },\r
1434 {\r
1435 MESSAGING_DEVICE_PATH,\r
1436 MSG_INFINIBAND_DP,\r
1437 DevPathInfiniBand\r
1438 },\r
1439 {\r
1440 MESSAGING_DEVICE_PATH,\r
1441 MSG_UART_DP,\r
1442 DevPathUart\r
1443 },\r
1444 {\r
1445 MESSAGING_DEVICE_PATH,\r
1446 MSG_VENDOR_DP,\r
1447 DevPathVendor\r
1448 },\r
1449 {\r
1450 MESSAGING_DEVICE_PATH,\r
1451 MSG_ISCSI_DP,\r
1452 DevPathiSCSI\r
1453 },\r
1454 {\r
1455 MEDIA_DEVICE_PATH,\r
1456 MEDIA_HARDDRIVE_DP,\r
1457 DevPathHardDrive\r
1458 },\r
1459 {\r
1460 MEDIA_DEVICE_PATH,\r
1461 MEDIA_CDROM_DP,\r
1462 DevPathCDROM\r
1463 },\r
1464 {\r
1465 MEDIA_DEVICE_PATH,\r
1466 MEDIA_VENDOR_DP,\r
1467 DevPathVendor\r
1468 },\r
1469 {\r
1470 MEDIA_DEVICE_PATH,\r
1471 MEDIA_FILEPATH_DP,\r
1472 DevPathFilePath\r
1473 },\r
1474 {\r
1475 MEDIA_DEVICE_PATH,\r
1476 MEDIA_PROTOCOL_DP,\r
1477 DevPathMediaProtocol\r
1478 },\r
1479 {\r
1480 MEDIA_DEVICE_PATH,\r
1481 MEDIA_PIWG_FW_FILE_DP,\r
1482 DevPathFvFilePath\r
1483 },\r
1484 {\r
1485 BBS_DEVICE_PATH,\r
1486 BBS_BBS_DP,\r
1487 DevPathBssBss\r
1488 },\r
1489 {\r
1490 END_DEVICE_PATH_TYPE,\r
1491 END_INSTANCE_DEVICE_PATH_SUBTYPE,\r
1492 DevPathEndInstance\r
1493 },\r
1494 {\r
1495 0,\r
1496 0,\r
1497 NULL\r
1498 }\r
897f0eee 1499};\r
1500\r
1501\r
1502/**\r
1503 This function converts an input device structure to a Unicode string.\r
1504\r
1505 @param DevPath A pointer to the device path structure.\r
1506\r
1507 @return A new allocated Unicode string that represents the device path.\r
1508\r
1509**/\r
1510CHAR16 *\r
1511EFIAPI\r
1512DevicePathToStr (\r
1513 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
1514 )\r
1515{\r
1516 POOL_PRINT Str;\r
1517 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;\r
1518 VOID (*DumpNode) (POOL_PRINT *, VOID *);\r
1519\r
1520 UINTN Index;\r
1521 UINTN NewSize;\r
1522\r
1523 EFI_STATUS Status;\r
1524 CHAR16 *ToText;\r
1525 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;\r
1526\r
1527 ZeroMem (&Str, sizeof (Str));\r
1528\r
1529 if (DevPath == NULL) {\r
1530 goto Done;\r
1531 }\r
1532\r
1533 Status = gBS->LocateProtocol (\r
1534 &gEfiDevicePathToTextProtocolGuid,\r
1535 NULL,\r
1536 (VOID **) &DevPathToText\r
1537 );\r
1538 if (!EFI_ERROR (Status)) {\r
1539 ToText = DevPathToText->ConvertDevicePathToText (\r
1540 DevPath,\r
1541 FALSE,\r
1542 TRUE\r
1543 );\r
1544 ASSERT (ToText != NULL);\r
1545 return ToText;\r
1546 }\r
1547\r
1548 //\r
1549 // Unpacked the device path\r
1550 //\r
1551 DevPath = BdsLibUnpackDevicePath (DevPath);\r
1552 ASSERT (DevPath);\r
1553\r
1554 //\r
1555 // Process each device path node\r
1556 //\r
1557 DevPathNode = DevPath;\r
1558 while (!IsDevicePathEnd (DevPathNode)) {\r
1559 //\r
1560 // Find the handler to dump this device path node\r
1561 //\r
1562 DumpNode = NULL;\r
1563 for (Index = 0; DevPathTable[Index].Function; Index += 1) {\r
1564\r
1565 if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&\r
1566 DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType\r
1567 ) {\r
1568 DumpNode = DevPathTable[Index].Function;\r
1569 break;\r
1570 }\r
1571 }\r
1572 //\r
1573 // If not found, use a generic function\r
1574 //\r
1575 if (!DumpNode) {\r
1576 DumpNode = DevPathNodeUnknown;\r
1577 }\r
1578 //\r
1579 // Put a path seperator in if needed\r
1580 //\r
1581 if (Str.len && DumpNode != DevPathEndInstance) {\r
1582 CatPrint (&Str, L"/");\r
1583 }\r
1584 //\r
1585 // Print this node of the device path\r
1586 //\r
1587 DumpNode (&Str, DevPathNode);\r
1588\r
1589 //\r
1590 // Next device path node\r
1591 //\r
1592 DevPathNode = NextDevicePathNode (DevPathNode);\r
1593 }\r
1594 //\r
1595 // Shrink pool used for string allocation\r
1596 //\r
676df92c 1597 FreePool (DevPath);\r
897f0eee 1598\r
1599Done:\r
1600 NewSize = (Str.len + 1) * sizeof (CHAR16);\r
1601 Str.str = ReallocatePool (Str.str, NewSize, NewSize);\r
1602 ASSERT (Str.str != NULL);\r
1603 Str.str[Str.len] = 0;\r
1604 return Str.str;\r
1605}\r
1606\r
897f0eee 1607/**\r
1608 Function creates a device path data structure that identically matches the\r
1609 device path passed in.\r
1610\r
1611 @param DevPath A pointer to a device path data structure.\r
1612\r
1613 @return The new copy of DevPath is created to identically match the input.\r
1614 @return Otherwise, NULL is returned.\r
1615\r
1616**/\r
1617EFI_DEVICE_PATH_PROTOCOL *\r
1618LibDuplicateDevicePathInstance (\r
1619 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
1620 )\r
1621{\r
1622 EFI_DEVICE_PATH_PROTOCOL *NewDevPath;\r
1623 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
1624 EFI_DEVICE_PATH_PROTOCOL *Temp;\r
1625 UINTN Size;\r
1626\r
1627 //\r
1628 // get the size of an instance from the input\r
1629 //\r
1630 Temp = DevPath;\r
1631 DevicePathInst = GetNextDevicePathInstance (&Temp, &Size);\r
1632\r
1633 //\r
1634 // Make a copy\r
1635 //\r
1636 NewDevPath = NULL;\r
11ef23f9 1637 if (Size != 0) {\r
897f0eee 1638 NewDevPath = AllocateZeroPool (Size);\r
1639 ASSERT (NewDevPath != NULL);\r
1640 }\r
1641\r
11ef23f9 1642 if (NewDevPath != NULL) {\r
897f0eee 1643 CopyMem (NewDevPath, DevicePathInst, Size);\r
1644 }\r
1645\r
1646 return NewDevPath;\r
1647}\r