]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/GenericBdsLib/DevicePath.c
Clean up Device Manager module in BdsDxe.
[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
18\r
19EFI_GUID mEfiDevicePathMessagingUartFlowControlGuid = DEVICE_PATH_MESSAGING_UART_FLOW_CONTROL;\r
20\r
21EFI_GUID mEfiDevicePathMessagingSASGuid = DEVICE_PATH_MESSAGING_SAS;\r
22\r
23\r
24VOID *\r
25ReallocatePool (\r
26 IN VOID *OldPool,\r
27 IN UINTN OldSize,\r
28 IN UINTN NewSize\r
29 )\r
30/*++\r
31\r
32Routine Description:\r
33\r
34 Adjusts the size of a previously allocated buffer.\r
35\r
36Arguments:\r
37\r
38 OldPool - A pointer to the buffer whose size is being adjusted.\r
39\r
40 OldSize - The size of the current buffer.\r
41\r
42 NewSize - The size of the new buffer.\r
43\r
44Returns:\r
45\r
46 EFI_SUCEESS - The requested number of bytes were allocated.\r
47\r
48 EFI_OUT_OF_RESOURCES - The pool requested could not be allocated.\r
49\r
50 EFI_INVALID_PARAMETER - The buffer was invalid.\r
51\r
52--*/\r
53{\r
54 VOID *NewPool;\r
55\r
56 NewPool = NULL;\r
57 if (NewSize) {\r
58 NewPool = AllocateZeroPool (NewSize);\r
59 }\r
60\r
61 if (OldPool) {\r
62 if (NewPool) {\r
63 CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);\r
64 }\r
65\r
66 gBS->FreePool (OldPool);\r
67 }\r
68\r
69 return NewPool;\r
70}\r
71\r
72\r
73/**\r
74 Concatenates a formatted unicode string to allocated pool.\r
75 The caller must free the resulting buffer.\r
76\r
77 @param Str Tracks the allocated pool, size in use, and amount of pool\r
78 allocated.\r
79 @param fmt The format string\r
80\r
81 @return Allocated buffer with the formatted string printed in it.\r
82 @return The caller must free the allocated buffer. The buffer\r
83 @return allocation is not packed.\r
84\r
85**/\r
86CHAR16 *\r
87EFIAPI\r
88CatPrint (\r
89 IN OUT POOL_PRINT *Str,\r
90 IN CHAR16 *fmt,\r
91 ...\r
92 )\r
93{\r
94 UINT16 *AppendStr;\r
95 VA_LIST args;\r
96 UINTN strsize;\r
97\r
98 AppendStr = AllocateZeroPool (0x1000);\r
99 if (AppendStr == NULL) {\r
100 return Str->str;\r
101 }\r
102\r
103 VA_START (args, fmt);\r
104 UnicodeVSPrint (AppendStr, 0x1000, fmt, args);\r
105 VA_END (args);\r
106 if (NULL == Str->str) {\r
107 strsize = StrSize (AppendStr);\r
108 Str->str = AllocateZeroPool (strsize);\r
109 ASSERT (Str->str != NULL);\r
110 } else {\r
111 strsize = StrSize (AppendStr);\r
112 strsize += (StrSize (Str->str) - sizeof (UINT16));\r
113\r
114 Str->str = ReallocatePool (\r
115 Str->str,\r
116 StrSize (Str->str),\r
117 strsize\r
118 );\r
119 ASSERT (Str->str != NULL);\r
120 }\r
121\r
122 Str->maxlen = MAX_CHAR * sizeof (UINT16);\r
123 if (strsize < Str->maxlen) {\r
124 StrCat (Str->str, AppendStr);\r
125 Str->len = strsize - sizeof (UINT16);\r
126 }\r
127\r
128 gBS->FreePool (AppendStr);\r
129 return Str->str;\r
130}\r
131\r
132\r
133/**\r
134 Function unpacks a device path data structure so that all the nodes\r
135 of a device path are naturally aligned.\r
136\r
137 @param DevPath A pointer to a device path data structure\r
138\r
139 @return A ponter to new device If the memory for the device path is successfully allocated, then a\r
140 pointer to the new device path is returned. Otherwise, NULL is returned.\r
141\r
142**/\r
143EFI_DEVICE_PATH_PROTOCOL *\r
144EFIAPI\r
145BdsLibUnpackDevicePath (\r
146 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
147 )\r
148{\r
149 EFI_DEVICE_PATH_PROTOCOL *Src;\r
150 EFI_DEVICE_PATH_PROTOCOL *Dest;\r
151 EFI_DEVICE_PATH_PROTOCOL *NewPath;\r
152 UINTN Size;\r
153\r
154 //\r
155 // Walk device path and round sizes to valid boundries\r
156 //\r
157 Src = DevPath;\r
158 Size = 0;\r
159 for (;;) {\r
160 Size += DevicePathNodeLength (Src);\r
161 Size += ALIGN_SIZE (Size);\r
162\r
163 if (IsDevicePathEnd (Src)) {\r
164 break;\r
165 }\r
166\r
167 Src = NextDevicePathNode (Src);\r
168 }\r
169 //\r
170 // Allocate space for the unpacked path\r
171 //\r
172 NewPath = AllocateZeroPool (Size);\r
173 if (NewPath) {\r
174\r
175 ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0);\r
176\r
177 //\r
178 // Copy each node\r
179 //\r
180 Src = DevPath;\r
181 Dest = NewPath;\r
182 for (;;) {\r
183 Size = DevicePathNodeLength (Src);\r
184 CopyMem (Dest, Src, Size);\r
185 Size += ALIGN_SIZE (Size);\r
186 SetDevicePathNodeLength (Dest, Size);\r
187 Dest->Type |= EFI_DP_TYPE_UNPACKED;\r
188 Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size);\r
189\r
190 if (IsDevicePathEnd (Src)) {\r
191 break;\r
192 }\r
193\r
194 Src = NextDevicePathNode (Src);\r
195 }\r
196 }\r
197\r
198 return NewPath;\r
199}\r
200\r
201VOID\r
202DevPathPci (\r
203 IN OUT POOL_PRINT *Str,\r
204 IN VOID *DevPath\r
205 )\r
206{\r
207 PCI_DEVICE_PATH *Pci;\r
208\r
209 Pci = DevPath;\r
210 CatPrint (Str, L"Pci(%x|%x)", (UINTN) Pci->Device, (UINTN) Pci->Function);\r
211}\r
212\r
213VOID\r
214DevPathPccard (\r
215 IN OUT POOL_PRINT *Str,\r
216 IN VOID *DevPath\r
217 )\r
218{\r
219 PCCARD_DEVICE_PATH *Pccard;\r
220\r
221 Pccard = DevPath;\r
222 CatPrint (Str, L"Pcmcia(Function%x)", (UINTN) Pccard->FunctionNumber);\r
223}\r
224\r
225VOID\r
226DevPathMemMap (\r
227 IN OUT POOL_PRINT *Str,\r
228 IN VOID *DevPath\r
229 )\r
230{\r
231 MEMMAP_DEVICE_PATH *MemMap;\r
232\r
233 MemMap = DevPath;\r
234 CatPrint (\r
235 Str,\r
236 L"MemMap(%d:%lx-%lx)",\r
237 MemMap->MemoryType,\r
238 MemMap->StartingAddress,\r
239 MemMap->EndingAddress\r
240 );\r
241}\r
242\r
243VOID\r
244DevPathController (\r
245 IN OUT POOL_PRINT *Str,\r
246 IN VOID *DevPath\r
247 )\r
248{\r
249 CONTROLLER_DEVICE_PATH *Controller;\r
250\r
251 Controller = DevPath;\r
252 CatPrint (Str, L"Ctrl(%d)", (UINTN) Controller->ControllerNumber);\r
253}\r
254\r
255\r
256/**\r
257 Convert Vendor device path to device name\r
258\r
259 @param Str The buffer store device name\r
260 @param DevPath Pointer to vendor device path\r
261\r
262 @return When it return, the device name have been stored in *Str.\r
263\r
264**/\r
265VOID\r
266EFIAPI\r
267DevPathVendor (\r
268 IN OUT POOL_PRINT *Str,\r
269 IN VOID *DevPath\r
270 )\r
271{\r
272 VENDOR_DEVICE_PATH *Vendor;\r
273 CHAR16 *Type;\r
274 UINTN DataLength;\r
275 UINTN Index;\r
276 UINT32 FlowControlMap;\r
277\r
278 UINT16 Info;\r
279\r
280 Vendor = DevPath;\r
281\r
282 switch (DevicePathType (&Vendor->Header)) {\r
283 case HARDWARE_DEVICE_PATH:\r
284 Type = L"Hw";\r
285// bugbug: nt 32 specific definition\r
286#if 0\r
287 //\r
288 // If the device is a winntbus device, we will give it a readable device name.\r
289 //\r
290 if (CompareGuid (&Vendor->Guid, &mEfiWinNtThunkProtocolGuid)) {\r
291 CatPrint (Str, L"%s", L"WinNtBus");\r
292 return ;\r
293 } else if (CompareGuid (&Vendor->Guid, &mEfiWinNtGopGuid)) {\r
294 CatPrint (Str, L"%s", L"GOP");\r
295 return ;\r
296 } else if (CompareGuid (&Vendor->Guid, &mEfiWinNtSerialPortGuid)) {\r
297 CatPrint (Str, L"%s", L"Serial");\r
298 return ;\r
299 }\r
300#endif\r
301 break;\r
302\r
303 case MESSAGING_DEVICE_PATH:\r
304 Type = L"Msg";\r
305 if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {\r
306 CatPrint (Str, L"VenPcAnsi()");\r
307 return ;\r
308 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {\r
309 CatPrint (Str, L"VenVt100()");\r
310 return ;\r
311 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {\r
312 CatPrint (Str, L"VenVt100Plus()");\r
313 return ;\r
314 } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {\r
315 CatPrint (Str, L"VenUft8()");\r
316 return ;\r
317 } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingUartFlowControlGuid)) {\r
318 FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);\r
319 switch (FlowControlMap & 0x00000003) {\r
320 case 0:\r
321 CatPrint (Str, L"UartFlowCtrl(%s)", L"None");\r
322 break;\r
323\r
324 case 1:\r
325 CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");\r
326 break;\r
327\r
328 case 2:\r
329 CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");\r
330 break;\r
331\r
332 default:\r
333 break;\r
334 }\r
335\r
336 return ;\r
337\r
338 } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingSASGuid)) {\r
339 CatPrint (\r
340 Str,\r
341 L"SAS(%lx,%lx,%x,",\r
342 ((SAS_DEVICE_PATH *) Vendor)->SasAddress,\r
343 ((SAS_DEVICE_PATH *) Vendor)->Lun,\r
344 ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort\r
345 );\r
346 Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);\r
347 if ((Info & 0x0f) == 0) {\r
348 CatPrint (Str, L"NoTopology,0,0,0,");\r
349 } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {\r
350 CatPrint (\r
351 Str,\r
352 L"%s,%s,%s,",\r
353 (Info & (0x1 << 4)) ? L"SATA" : L"SAS",\r
354 (Info & (0x1 << 5)) ? L"External" : L"Internal",\r
355 (Info & (0x1 << 6)) ? L"Expanded" : L"Direct"\r
356 );\r
357 if ((Info & 0x0f) == 1) {\r
358 CatPrint (Str, L"0,");\r
359 } else {\r
360 CatPrint (Str, L"%x,", (UINTN) ((Info >> 8) & 0xff));\r
361 }\r
362 } else {\r
363 CatPrint (Str, L"0,0,0,0,");\r
364 }\r
365\r
366 CatPrint (Str, L"%x)", (UINTN) ((SAS_DEVICE_PATH *) Vendor)->Reserved);\r
367 return ;\r
368\r
369 } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {\r
370 CatPrint (Str, L"DebugPort()");\r
371 return ;\r
372 }\r
373 break;\r
374\r
375 case MEDIA_DEVICE_PATH:\r
376 Type = L"Media";\r
377 break;\r
378\r
379 default:\r
380 Type = L"?";\r
381 break;\r
382 }\r
383\r
384 CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);\r
385 DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);\r
386 if (DataLength > 0) {\r
387 CatPrint (Str, L",");\r
388 for (Index = 0; Index < DataLength; Index++) {\r
389 CatPrint (Str, L"%02x", (UINTN) ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);\r
390 }\r
391 }\r
392 CatPrint (Str, L")");\r
393}\r
394\r
395\r
396VOID\r
397DevPathAcpi (\r
398 IN OUT POOL_PRINT *Str,\r
399 IN VOID *DevPath\r
400 )\r
401{\r
402 ACPI_HID_DEVICE_PATH *Acpi;\r
403\r
404 Acpi = DevPath;\r
405 if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
406 CatPrint (Str, L"Acpi(PNP%04x,%x)", (UINTN) EISA_ID_TO_NUM (Acpi->HID), (UINTN) Acpi->UID);\r
407 } else {\r
408 CatPrint (Str, L"Acpi(%08x,%x)", (UINTN) Acpi->HID, (UINTN) Acpi->UID);\r
409 }\r
410}\r
411\r
412VOID\r
413DevPathExtendedAcpi (\r
414 IN OUT POOL_PRINT *Str,\r
415 IN VOID *DevPath\r
416 )\r
417{\r
418 ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi;\r
419 //\r
420 // Index for HID, UID and CID strings, 0 for non-exist\r
421 //\r
422 UINT16 HIDSTRIdx;\r
423 UINT16 UIDSTRIdx;\r
424 UINT16 CIDSTRIdx;\r
425 UINT16 Index;\r
426 UINT16 Length;\r
427 UINT16 Anchor;\r
428 CHAR8 *AsChar8Array;\r
429\r
430 ASSERT (Str != NULL);\r
431 ASSERT (DevPath != NULL);\r
432\r
433 HIDSTRIdx = 0;\r
434 UIDSTRIdx = 0;\r
435 CIDSTRIdx = 0;\r
436 ExtendedAcpi = DevPath;\r
437 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);\r
438\r
439 ASSERT (Length >= 19);\r
440 AsChar8Array = (CHAR8 *) ExtendedAcpi;\r
441\r
442 //\r
443 // find HIDSTR\r
444 //\r
445 Anchor = 16;\r
446 for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {\r
447 ;\r
448 }\r
449 if (Index > Anchor) {\r
450 HIDSTRIdx = Anchor;\r
451 }\r
452 //\r
453 // find UIDSTR\r
454 //\r
455 Anchor = (UINT16) (Index + 1);\r
456 for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {\r
457 ;\r
458 }\r
459 if (Index > Anchor) {\r
460 UIDSTRIdx = Anchor;\r
461 }\r
462 //\r
463 // find CIDSTR\r
464 //\r
465 Anchor = (UINT16) (Index + 1);\r
466 for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {\r
467 ;\r
468 }\r
469 if (Index > Anchor) {\r
470 CIDSTRIdx = Anchor;\r
471 }\r
472\r
473 if (HIDSTRIdx == 0 && CIDSTRIdx == 0 && ExtendedAcpi->UID == 0) {\r
474 CatPrint (Str, L"AcpiExp(");\r
475 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
476 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));\r
477 } else {\r
478 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);\r
479 }\r
480 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
481 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));\r
482 } else {\r
483 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);\r
484 }\r
485 if (UIDSTRIdx != 0) {\r
486 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);\r
487 } else {\r
488 CatPrint (Str, L"\"\")");\r
489 }\r
490 } else {\r
491 CatPrint (Str, L"AcpiEx(");\r
492 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
493 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));\r
494 } else {\r
495 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);\r
496 }\r
497 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
498 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));\r
499 } else {\r
500 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);\r
501 }\r
502 CatPrint (Str, L"%x,", (UINTN) ExtendedAcpi->UID);\r
503\r
504 if (HIDSTRIdx != 0) {\r
505 CatPrint (Str, L"%a,", AsChar8Array + HIDSTRIdx);\r
506 } else {\r
507 CatPrint (Str, L"\"\",");\r
508 }\r
509 if (CIDSTRIdx != 0) {\r
510 CatPrint (Str, L"%a,", AsChar8Array + CIDSTRIdx);\r
511 } else {\r
512 CatPrint (Str, L"\"\",");\r
513 }\r
514 if (UIDSTRIdx != 0) {\r
515 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);\r
516 } else {\r
517 CatPrint (Str, L"\"\")");\r
518 }\r
519 }\r
520\r
521}\r
522\r
523VOID\r
524DevPathAdrAcpi (\r
525 IN OUT POOL_PRINT *Str,\r
526 IN VOID *DevPath\r
527 )\r
528{\r
529 ACPI_ADR_DEVICE_PATH *AcpiAdr;\r
530 UINT16 Index;\r
531 UINT16 Length;\r
532 UINT16 AdditionalAdrCount;\r
533\r
534 AcpiAdr = DevPath;\r
535 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);\r
536 AdditionalAdrCount = (UINT16) ((Length - 8) / 4);\r
537\r
538 CatPrint (Str, L"AcpiAdr(%x", (UINTN) AcpiAdr->ADR);\r
539 for (Index = 0; Index < AdditionalAdrCount; Index++) {\r
540 CatPrint (Str, L",%x", (UINTN) *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));\r
541 }\r
542 CatPrint (Str, L")");\r
543}\r
544\r
545VOID\r
546DevPathAtapi (\r
547 IN OUT POOL_PRINT *Str,\r
548 IN VOID *DevPath\r
549 )\r
550{\r
551 ATAPI_DEVICE_PATH *Atapi;\r
552\r
553 Atapi = DevPath;\r
554 CatPrint (\r
555 Str,\r
556 L"Ata(%s,%s)",\r
557 Atapi->PrimarySecondary ? L"Secondary" : L"Primary",\r
558 Atapi->SlaveMaster ? L"Slave" : L"Master"\r
559 );\r
560}\r
561\r
562VOID\r
563DevPathScsi (\r
564 IN OUT POOL_PRINT *Str,\r
565 IN VOID *DevPath\r
566 )\r
567{\r
568 SCSI_DEVICE_PATH *Scsi;\r
569\r
570 Scsi = DevPath;\r
571 CatPrint (Str, L"Scsi(Pun%x,Lun%x)", (UINTN) Scsi->Pun, (UINTN) Scsi->Lun);\r
572}\r
573\r
574VOID\r
575DevPathFibre (\r
576 IN OUT POOL_PRINT *Str,\r
577 IN VOID *DevPath\r
578 )\r
579{\r
580 FIBRECHANNEL_DEVICE_PATH *Fibre;\r
581\r
582 Fibre = DevPath;\r
583 CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);\r
584}\r
585\r
586VOID\r
587DevPath1394 (\r
588 IN OUT POOL_PRINT *Str,\r
589 IN VOID *DevPath\r
590 )\r
591{\r
592 F1394_DEVICE_PATH *F1394;\r
593\r
594 F1394 = DevPath;\r
595 CatPrint (Str, L"1394(%g)", &F1394->Guid);\r
596}\r
597\r
598VOID\r
599DevPathUsb (\r
600 IN OUT POOL_PRINT *Str,\r
601 IN VOID *DevPath\r
602 )\r
603{\r
604 USB_DEVICE_PATH *Usb;\r
605\r
606 Usb = DevPath;\r
607 CatPrint (Str, L"Usb(%x,%x)", (UINTN) Usb->ParentPortNumber, (UINTN) Usb->InterfaceNumber);\r
608}\r
609\r
610VOID\r
611DevPathUsbWWID (\r
612 IN OUT POOL_PRINT *Str,\r
613 IN VOID *DevPath\r
614 )\r
615{\r
616 USB_WWID_DEVICE_PATH *UsbWWId;\r
617\r
618 UsbWWId = DevPath;\r
619 CatPrint (\r
620 Str,\r
621 L"UsbWwid(%x,%x,%x,\"WWID\")",\r
622 (UINTN) UsbWWId->VendorId,\r
623 (UINTN) UsbWWId->ProductId,\r
624 (UINTN) UsbWWId->InterfaceNumber\r
625 );\r
626}\r
627\r
628VOID\r
629DevPathLogicalUnit (\r
630 IN OUT POOL_PRINT *Str,\r
631 IN VOID *DevPath\r
632 )\r
633{\r
634 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;\r
635\r
636 LogicalUnit = DevPath;\r
637 CatPrint (Str, L"Unit(%x)", (UINTN) LogicalUnit->Lun);\r
638}\r
639\r
640VOID\r
641DevPathUsbClass (\r
642 IN OUT POOL_PRINT *Str,\r
643 IN VOID *DevPath\r
644 )\r
645{\r
646 USB_CLASS_DEVICE_PATH *UsbClass;\r
647\r
648 UsbClass = DevPath;\r
649 CatPrint (\r
650 Str,\r
651 L"Usb Class(%x,%x,%x,%x,%x)",\r
652 (UINTN) UsbClass->VendorId,\r
653 (UINTN) UsbClass->ProductId,\r
654 (UINTN) UsbClass->DeviceClass,\r
655 (UINTN) UsbClass->DeviceSubClass,\r
656 (UINTN) UsbClass->DeviceProtocol\r
657 );\r
658}\r
659\r
660VOID\r
661DevPathSata (\r
662 IN OUT POOL_PRINT *Str,\r
663 IN VOID *DevPath\r
664 )\r
665{\r
666 SATA_DEVICE_PATH *Sata;\r
667\r
668 Sata = DevPath;\r
669 CatPrint (\r
670 Str,\r
671 L"Sata(%x,%x,%x)",\r
672 (UINTN) Sata->HBAPortNumber,\r
673 (UINTN) Sata->PortMultiplierPortNumber,\r
674 (UINTN) Sata->Lun\r
675 );\r
676}\r
677\r
678VOID\r
679DevPathI2O (\r
680 IN OUT POOL_PRINT *Str,\r
681 IN VOID *DevPath\r
682 )\r
683{\r
684 I2O_DEVICE_PATH *I2O;\r
685\r
686 I2O = DevPath;\r
687 CatPrint (Str, L"I2O(%x)", (UINTN) I2O->Tid);\r
688}\r
689\r
690VOID\r
691DevPathMacAddr (\r
692 IN OUT POOL_PRINT *Str,\r
693 IN VOID *DevPath\r
694 )\r
695{\r
696 MAC_ADDR_DEVICE_PATH *MAC;\r
697 UINTN HwAddressSize;\r
698 UINTN Index;\r
699\r
700 MAC = DevPath;\r
701\r
702 HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r
703 if (MAC->IfType == 0x01 || MAC->IfType == 0x00) {\r
704 HwAddressSize = 6;\r
705 }\r
706\r
707 CatPrint (Str, L"Mac(");\r
708\r
709 for (Index = 0; Index < HwAddressSize; Index++) {\r
710 CatPrint (Str, L"%02x", (UINTN) MAC->MacAddress.Addr[Index]);\r
711 }\r
712\r
713 CatPrint (Str, L")");\r
714}\r
715\r
716VOID\r
717DevPathIPv4 (\r
718 IN OUT POOL_PRINT *Str,\r
719 IN VOID *DevPath\r
720 )\r
721{\r
722 IPv4_DEVICE_PATH *IP;\r
723\r
724 IP = DevPath;\r
725 CatPrint (\r
726 Str,\r
727 L"IPv4(%d.%d.%d.%d:%d)",\r
728 (UINTN) IP->RemoteIpAddress.Addr[0],\r
729 (UINTN) IP->RemoteIpAddress.Addr[1],\r
730 (UINTN) IP->RemoteIpAddress.Addr[2],\r
731 (UINTN) IP->RemoteIpAddress.Addr[3],\r
732 (UINTN) IP->RemotePort\r
733 );\r
734}\r
735\r
736VOID\r
737DevPathIPv6 (\r
738 IN OUT POOL_PRINT *Str,\r
739 IN VOID *DevPath\r
740 )\r
741{\r
742 IPv6_DEVICE_PATH *IP;\r
743\r
744 IP = DevPath;\r
745 CatPrint (\r
746 Str,\r
747 L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",\r
748 (UINTN) IP->RemoteIpAddress.Addr[0],\r
749 (UINTN) IP->RemoteIpAddress.Addr[1],\r
750 (UINTN) IP->RemoteIpAddress.Addr[2],\r
751 (UINTN) IP->RemoteIpAddress.Addr[3],\r
752 (UINTN) IP->RemoteIpAddress.Addr[4],\r
753 (UINTN) IP->RemoteIpAddress.Addr[5],\r
754 (UINTN) IP->RemoteIpAddress.Addr[6],\r
755 (UINTN) IP->RemoteIpAddress.Addr[7],\r
756 (UINTN) IP->RemoteIpAddress.Addr[8],\r
757 (UINTN) IP->RemoteIpAddress.Addr[9],\r
758 (UINTN) IP->RemoteIpAddress.Addr[10],\r
759 (UINTN) IP->RemoteIpAddress.Addr[11],\r
760 (UINTN) IP->RemoteIpAddress.Addr[12],\r
761 (UINTN) IP->RemoteIpAddress.Addr[13],\r
762 (UINTN) IP->RemoteIpAddress.Addr[14],\r
763 (UINTN) IP->RemoteIpAddress.Addr[15]\r
764 );\r
765}\r
766\r
767VOID\r
768DevPathInfiniBand (\r
769 IN OUT POOL_PRINT *Str,\r
770 IN VOID *DevPath\r
771 )\r
772{\r
773 INFINIBAND_DEVICE_PATH *InfiniBand;\r
774\r
775 InfiniBand = DevPath;\r
776 CatPrint (\r
777 Str,\r
778 L"Infiniband(%x,%g,%lx,%lx,%lx)",\r
779 (UINTN) InfiniBand->ResourceFlags,\r
780 InfiniBand->PortGid,\r
781 InfiniBand->ServiceId,\r
782 InfiniBand->TargetPortId,\r
783 InfiniBand->DeviceId\r
784 );\r
785}\r
786\r
787VOID\r
788DevPathUart (\r
789 IN OUT POOL_PRINT *Str,\r
790 IN VOID *DevPath\r
791 )\r
792{\r
793 UART_DEVICE_PATH *Uart;\r
794 CHAR8 Parity;\r
795\r
796 Uart = DevPath;\r
797 switch (Uart->Parity) {\r
798 case 0:\r
799 Parity = 'D';\r
800 break;\r
801\r
802 case 1:\r
803 Parity = 'N';\r
804 break;\r
805\r
806 case 2:\r
807 Parity = 'E';\r
808 break;\r
809\r
810 case 3:\r
811 Parity = 'O';\r
812 break;\r
813\r
814 case 4:\r
815 Parity = 'M';\r
816 break;\r
817\r
818 case 5:\r
819 Parity = 'S';\r
820 break;\r
821\r
822 default:\r
823 Parity = 'x';\r
824 break;\r
825 }\r
826\r
827 if (Uart->BaudRate == 0) {\r
828 CatPrint (Str, L"Uart(DEFAULT,%c,", Parity);\r
829 } else {\r
830 CatPrint (Str, L"Uart(%d,%c,", Uart->BaudRate, Parity);\r
831 }\r
832\r
833 if (Uart->DataBits == 0) {\r
834 CatPrint (Str, L"D,");\r
835 } else {\r
836 CatPrint (Str, L"%d,", (UINTN) Uart->DataBits);\r
837 }\r
838\r
839 switch (Uart->StopBits) {\r
840 case 0:\r
841 CatPrint (Str, L"D)");\r
842 break;\r
843\r
844 case 1:\r
845 CatPrint (Str, L"1)");\r
846 break;\r
847\r
848 case 2:\r
849 CatPrint (Str, L"1.5)");\r
850 break;\r
851\r
852 case 3:\r
853 CatPrint (Str, L"2)");\r
854 break;\r
855\r
856 default:\r
857 CatPrint (Str, L"x)");\r
858 break;\r
859 }\r
860}\r
861\r
862VOID\r
863DevPathiSCSI (\r
864 IN OUT POOL_PRINT *Str,\r
865 IN VOID *DevPath\r
866 )\r
867{\r
868 ISCSI_DEVICE_PATH_WITH_NAME *iSCSI;\r
869 UINT16 Options;\r
870\r
871 ASSERT (Str != NULL);\r
872 ASSERT (DevPath != NULL);\r
873\r
874 iSCSI = DevPath;\r
875 CatPrint (\r
876 Str,\r
877 L"iSCSI(%s,%x,%lx,",\r
878 iSCSI->iSCSITargetName,\r
879 iSCSI->TargetPortalGroupTag,\r
880 iSCSI->Lun\r
881 );\r
882\r
883 Options = iSCSI->LoginOption;\r
884 CatPrint (Str, L"%s,", ((Options >> 1) & 0x0001) ? L"CRC32C" : L"None");\r
885 CatPrint (Str, L"%s,", ((Options >> 3) & 0x0001) ? L"CRC32C" : L"None");\r
886 if ((Options >> 11) & 0x0001) {\r
887 CatPrint (Str, L"%s,", L"None");\r
888 } else if ((Options >> 12) & 0x0001) {\r
889 CatPrint (Str, L"%s,", L"CHAP_UNI");\r
890 } else {\r
891 CatPrint (Str, L"%s,", L"CHAP_BI");\r
892\r
893 }\r
894\r
895 CatPrint (Str, L"%s)", (iSCSI->NetworkProtocol == 0) ? L"TCP" : L"reserved");\r
896}\r
897\r
898VOID\r
899DevPathHardDrive (\r
900 IN OUT POOL_PRINT *Str,\r
901 IN VOID *DevPath\r
902 )\r
903{\r
904 HARDDRIVE_DEVICE_PATH *Hd;\r
905\r
906 Hd = DevPath;\r
907 switch (Hd->SignatureType) {\r
908 case SIGNATURE_TYPE_MBR:\r
909 CatPrint (\r
910 Str,\r
911 L"HD(Part%d,Sig%08x)",\r
912 (UINTN) Hd->PartitionNumber,\r
913 (UINTN) *((UINT32 *) (&(Hd->Signature[0])))\r
914 );\r
915 break;\r
916\r
917 case SIGNATURE_TYPE_GUID:\r
918 CatPrint (\r
919 Str,\r
920 L"HD(Part%d,Sig%g)",\r
921 (UINTN) Hd->PartitionNumber,\r
922 (EFI_GUID *) &(Hd->Signature[0])\r
923 );\r
924 break;\r
925\r
926 default:\r
927 CatPrint (\r
928 Str,\r
929 L"HD(Part%d,MBRType=%02x,SigType=%02x)",\r
930 (UINTN) Hd->PartitionNumber,\r
931 (UINTN) Hd->MBRType,\r
932 (UINTN) Hd->SignatureType\r
933 );\r
934 break;\r
935 }\r
936}\r
937\r
938VOID\r
939DevPathCDROM (\r
940 IN OUT POOL_PRINT *Str,\r
941 IN VOID *DevPath\r
942 )\r
943{\r
944 CDROM_DEVICE_PATH *Cd;\r
945\r
946 Cd = DevPath;\r
947 CatPrint (Str, L"CDROM(Entry%x)", (UINTN) Cd->BootEntry);\r
948}\r
949\r
950VOID\r
951DevPathFilePath (\r
952 IN OUT POOL_PRINT *Str,\r
953 IN VOID *DevPath\r
954 )\r
955{\r
956 FILEPATH_DEVICE_PATH *Fp;\r
957\r
958 Fp = DevPath;\r
959 CatPrint (Str, L"%s", Fp->PathName);\r
960}\r
961\r
962VOID\r
963DevPathMediaProtocol (\r
964 IN OUT POOL_PRINT *Str,\r
965 IN VOID *DevPath\r
966 )\r
967{\r
968 MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;\r
969\r
970 MediaProt = DevPath;\r
971 CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);\r
972}\r
973\r
974VOID\r
975DevPathFvFilePath (\r
976 IN OUT POOL_PRINT *Str,\r
977 IN VOID *DevPath\r
978 )\r
979{\r
980 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;\r
981\r
982 FvFilePath = DevPath;\r
983 CatPrint (Str, L"%g", &FvFilePath->FvFileName);\r
984}\r
985\r
986VOID\r
987DevPathBssBss (\r
988 IN OUT POOL_PRINT *Str,\r
989 IN VOID *DevPath\r
990 )\r
991{\r
992 BBS_BBS_DEVICE_PATH *Bbs;\r
993 CHAR16 *Type;\r
994\r
995 Bbs = DevPath;\r
996 switch (Bbs->DeviceType) {\r
997 case BBS_TYPE_FLOPPY:\r
998 Type = L"Floppy";\r
999 break;\r
1000\r
1001 case BBS_TYPE_HARDDRIVE:\r
1002 Type = L"Harddrive";\r
1003 break;\r
1004\r
1005 case BBS_TYPE_CDROM:\r
1006 Type = L"CDROM";\r
1007 break;\r
1008\r
1009 case BBS_TYPE_PCMCIA:\r
1010 Type = L"PCMCIA";\r
1011 break;\r
1012\r
1013 case BBS_TYPE_USB:\r
1014 Type = L"Usb";\r
1015 break;\r
1016\r
1017 case BBS_TYPE_EMBEDDED_NETWORK:\r
1018 Type = L"Net";\r
1019 break;\r
1020\r
1021 case BBS_TYPE_BEV:\r
1022 Type = L"BEV";\r
1023 break;\r
1024\r
1025 default:\r
1026 Type = L"?";\r
1027 break;\r
1028 }\r
1029 CatPrint (Str, L"Legacy-%s", Type);\r
1030}\r
1031\r
1032VOID\r
1033DevPathEndInstance (\r
1034 IN OUT POOL_PRINT *Str,\r
1035 IN VOID *DevPath\r
1036 )\r
1037{\r
1038 CatPrint (Str, L",");\r
1039}\r
1040\r
1041VOID\r
1042DevPathNodeUnknown (\r
1043 IN OUT POOL_PRINT *Str,\r
1044 IN VOID *DevPath\r
1045 )\r
1046{\r
1047 CatPrint (Str, L"?");\r
1048}\r
1049\r
1050DEVICE_PATH_STRING_TABLE DevPathTable[] = {\r
1051 HARDWARE_DEVICE_PATH,\r
1052 HW_PCI_DP,\r
1053 DevPathPci,\r
1054 HARDWARE_DEVICE_PATH,\r
1055 HW_PCCARD_DP,\r
1056 DevPathPccard,\r
1057 HARDWARE_DEVICE_PATH,\r
1058 HW_MEMMAP_DP,\r
1059 DevPathMemMap,\r
1060 HARDWARE_DEVICE_PATH,\r
1061 HW_VENDOR_DP,\r
1062 DevPathVendor,\r
1063 HARDWARE_DEVICE_PATH,\r
1064 HW_CONTROLLER_DP,\r
1065 DevPathController,\r
1066 ACPI_DEVICE_PATH,\r
1067 ACPI_DP,\r
1068 DevPathAcpi,\r
1069 ACPI_DEVICE_PATH,\r
1070 ACPI_EXTENDED_DP,\r
1071 DevPathExtendedAcpi,\r
1072 ACPI_DEVICE_PATH,\r
1073 ACPI_ADR_DP,\r
1074 DevPathAdrAcpi,\r
1075 MESSAGING_DEVICE_PATH,\r
1076 MSG_ATAPI_DP,\r
1077 DevPathAtapi,\r
1078 MESSAGING_DEVICE_PATH,\r
1079 MSG_SCSI_DP,\r
1080 DevPathScsi,\r
1081 MESSAGING_DEVICE_PATH,\r
1082 MSG_FIBRECHANNEL_DP,\r
1083 DevPathFibre,\r
1084 MESSAGING_DEVICE_PATH,\r
1085 MSG_1394_DP,\r
1086 DevPath1394,\r
1087 MESSAGING_DEVICE_PATH,\r
1088 MSG_USB_DP,\r
1089 DevPathUsb,\r
1090 MESSAGING_DEVICE_PATH,\r
1091 MSG_USB_WWID_DP,\r
1092 DevPathUsbWWID,\r
1093 MESSAGING_DEVICE_PATH,\r
1094 MSG_DEVICE_LOGICAL_UNIT_DP,\r
1095 DevPathLogicalUnit,\r
1096 MESSAGING_DEVICE_PATH,\r
1097 MSG_USB_CLASS_DP,\r
1098 DevPathUsbClass,\r
1099 MESSAGING_DEVICE_PATH,\r
1100 MSG_SATA_DP,\r
1101 DevPathSata,\r
1102 MESSAGING_DEVICE_PATH,\r
1103 MSG_I2O_DP,\r
1104 DevPathI2O,\r
1105 MESSAGING_DEVICE_PATH,\r
1106 MSG_MAC_ADDR_DP,\r
1107 DevPathMacAddr,\r
1108 MESSAGING_DEVICE_PATH,\r
1109 MSG_IPv4_DP,\r
1110 DevPathIPv4,\r
1111 MESSAGING_DEVICE_PATH,\r
1112 MSG_IPv6_DP,\r
1113 DevPathIPv6,\r
1114 MESSAGING_DEVICE_PATH,\r
1115 MSG_INFINIBAND_DP,\r
1116 DevPathInfiniBand,\r
1117 MESSAGING_DEVICE_PATH,\r
1118 MSG_UART_DP,\r
1119 DevPathUart,\r
1120 MESSAGING_DEVICE_PATH,\r
1121 MSG_VENDOR_DP,\r
1122 DevPathVendor,\r
1123 MESSAGING_DEVICE_PATH,\r
1124 MSG_ISCSI_DP,\r
1125 DevPathiSCSI,\r
1126 MEDIA_DEVICE_PATH,\r
1127 MEDIA_HARDDRIVE_DP,\r
1128 DevPathHardDrive,\r
1129 MEDIA_DEVICE_PATH,\r
1130 MEDIA_CDROM_DP,\r
1131 DevPathCDROM,\r
1132 MEDIA_DEVICE_PATH,\r
1133 MEDIA_VENDOR_DP,\r
1134 DevPathVendor,\r
1135 MEDIA_DEVICE_PATH,\r
1136 MEDIA_FILEPATH_DP,\r
1137 DevPathFilePath,\r
1138 MEDIA_DEVICE_PATH,\r
1139 MEDIA_PROTOCOL_DP,\r
1140 DevPathMediaProtocol,\r
1141 MEDIA_DEVICE_PATH,\r
1142 MEDIA_PIWG_FW_FILE_DP,\r
1143 DevPathFvFilePath,\r
1144 BBS_DEVICE_PATH,\r
1145 BBS_BBS_DP,\r
1146 DevPathBssBss,\r
1147 END_DEVICE_PATH_TYPE,\r
1148 END_INSTANCE_DEVICE_PATH_SUBTYPE,\r
1149 DevPathEndInstance,\r
1150 0,\r
1151 0,\r
1152 NULL\r
1153};\r
1154\r
1155\r
1156/**\r
1157 This function converts an input device structure to a Unicode string.\r
1158\r
1159 @param DevPath A pointer to the device path structure.\r
1160\r
1161 @return A new allocated Unicode string that represents the device path.\r
1162\r
1163**/\r
1164CHAR16 *\r
1165EFIAPI\r
1166DevicePathToStr (\r
1167 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
1168 )\r
1169{\r
1170 POOL_PRINT Str;\r
1171 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;\r
1172 VOID (*DumpNode) (POOL_PRINT *, VOID *);\r
1173\r
1174 UINTN Index;\r
1175 UINTN NewSize;\r
1176\r
1177 EFI_STATUS Status;\r
1178 CHAR16 *ToText;\r
1179 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;\r
1180\r
1181 ZeroMem (&Str, sizeof (Str));\r
1182\r
1183 if (DevPath == NULL) {\r
1184 goto Done;\r
1185 }\r
1186\r
1187 Status = gBS->LocateProtocol (\r
1188 &gEfiDevicePathToTextProtocolGuid,\r
1189 NULL,\r
1190 (VOID **) &DevPathToText\r
1191 );\r
1192 if (!EFI_ERROR (Status)) {\r
1193 ToText = DevPathToText->ConvertDevicePathToText (\r
1194 DevPath,\r
1195 FALSE,\r
1196 TRUE\r
1197 );\r
1198 ASSERT (ToText != NULL);\r
1199 return ToText;\r
1200 }\r
1201\r
1202 //\r
1203 // Unpacked the device path\r
1204 //\r
1205 DevPath = BdsLibUnpackDevicePath (DevPath);\r
1206 ASSERT (DevPath);\r
1207\r
1208 //\r
1209 // Process each device path node\r
1210 //\r
1211 DevPathNode = DevPath;\r
1212 while (!IsDevicePathEnd (DevPathNode)) {\r
1213 //\r
1214 // Find the handler to dump this device path node\r
1215 //\r
1216 DumpNode = NULL;\r
1217 for (Index = 0; DevPathTable[Index].Function; Index += 1) {\r
1218\r
1219 if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&\r
1220 DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType\r
1221 ) {\r
1222 DumpNode = DevPathTable[Index].Function;\r
1223 break;\r
1224 }\r
1225 }\r
1226 //\r
1227 // If not found, use a generic function\r
1228 //\r
1229 if (!DumpNode) {\r
1230 DumpNode = DevPathNodeUnknown;\r
1231 }\r
1232 //\r
1233 // Put a path seperator in if needed\r
1234 //\r
1235 if (Str.len && DumpNode != DevPathEndInstance) {\r
1236 CatPrint (&Str, L"/");\r
1237 }\r
1238 //\r
1239 // Print this node of the device path\r
1240 //\r
1241 DumpNode (&Str, DevPathNode);\r
1242\r
1243 //\r
1244 // Next device path node\r
1245 //\r
1246 DevPathNode = NextDevicePathNode (DevPathNode);\r
1247 }\r
1248 //\r
1249 // Shrink pool used for string allocation\r
1250 //\r
1251 gBS->FreePool (DevPath);\r
1252\r
1253Done:\r
1254 NewSize = (Str.len + 1) * sizeof (CHAR16);\r
1255 Str.str = ReallocatePool (Str.str, NewSize, NewSize);\r
1256 ASSERT (Str.str != NULL);\r
1257 Str.str[Str.len] = 0;\r
1258 return Str.str;\r
1259}\r
1260\r
1261\r
1262/**\r
1263 Function creates a device path data structure that identically matches the\r
1264 device path passed in.\r
1265\r
1266 @param DevPath A pointer to a device path data structure.\r
1267\r
1268 @return The new copy of DevPath is created to identically match the input.\r
1269 @return Otherwise, NULL is returned.\r
1270\r
1271**/\r
1272EFI_DEVICE_PATH_PROTOCOL *\r
1273LibDuplicateDevicePathInstance (\r
1274 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
1275 )\r
1276{\r
1277 EFI_DEVICE_PATH_PROTOCOL *NewDevPath;\r
1278 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
1279 EFI_DEVICE_PATH_PROTOCOL *Temp;\r
1280 UINTN Size;\r
1281\r
1282 //\r
1283 // get the size of an instance from the input\r
1284 //\r
1285 Temp = DevPath;\r
1286 DevicePathInst = GetNextDevicePathInstance (&Temp, &Size);\r
1287\r
1288 //\r
1289 // Make a copy\r
1290 //\r
1291 NewDevPath = NULL;\r
1292 if (Size) {\r
1293 NewDevPath = AllocateZeroPool (Size);\r
1294 ASSERT (NewDevPath != NULL);\r
1295 }\r
1296\r
1297 if (NewDevPath) {\r
1298 CopyMem (NewDevPath, DevicePathInst, Size);\r
1299 }\r
1300\r
1301 return NewDevPath;\r
1302}\r