3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 BDS internal function define the default device path string, it can be
19 replaced by platform device path.
24 #ifdef TIANO_EXTENSION_FLAG
25 EFI_GUID UnknownDeviceGuid
= UNKNOWN_DEVICE_GUID
;
28 EFI_GUID mEfiWinNtThunkProtocolGuid
= EFI_WIN_NT_THUNK_PROTOCOL_GUID
;
29 EFI_GUID mEfiWinNtUgaGuid
= EFI_WIN_NT_UGA_GUID
;
30 EFI_GUID mEfiWinNtSerialPortGuid
= EFI_WIN_NT_SERIAL_PORT_GUID
;
31 EFI_GUID mEfiMsgPcAnsiGuid
= DEVICE_PATH_MESSAGING_PC_ANSI
;
32 EFI_GUID mEfiMsgVt100Guid
= DEVICE_PATH_MESSAGING_VT_100
;
33 EFI_GUID mEfiMsgVt100PlusGuid
= DEVICE_PATH_MESSAGING_VT_100_PLUS
;
34 EFI_GUID mEfiMsgVt100Utf8Guid
= DEVICE_PATH_MESSAGING_VT_UTF8
;
46 Adjusts the size of a previously allocated buffer.
50 OldPool - A pointer to the buffer whose size is being adjusted.
52 OldSize - The size of the current buffer.
54 NewSize - The size of the new buffer.
58 EFI_SUCEESS - The requested number of bytes were allocated.
60 EFI_OUT_OF_RESOURCES - The pool requested could not be allocated.
62 EFI_INVALID_PARAMETER - The buffer was invalid.
70 NewPool
= AllocateZeroPool (NewSize
);
75 CopyMem (NewPool
, OldPool
, OldSize
< NewSize
? OldSize
: NewSize
);
78 gBS
->FreePool (OldPool
);
86 IN OUT POOL_PRINT
*Str
,
94 Concatenates a formatted unicode string to allocated pool.
95 The caller must free the resulting buffer.
99 Str - Tracks the allocated pool, size in use, and
100 amount of pool allocated.
102 fmt - The format string
106 Allocated buffer with the formatted string printed in it.
107 The caller must free the allocated buffer. The buffer
108 allocation is not packed.
116 AppendStr
= AllocateZeroPool (0x1000);
117 if (AppendStr
== NULL
) {
121 VA_START (args
, fmt
);
122 UnicodeVSPrint (AppendStr
, 0x1000, fmt
, args
);
124 if (NULL
== Str
->str
) {
125 strsize
= StrSize (AppendStr
);
126 Str
->str
= AllocateZeroPool (strsize
);
127 ASSERT (Str
->str
!= NULL
);
129 strsize
= StrSize (AppendStr
) + StrSize (Str
->str
) - sizeof (UINT16
);
130 Str
->str
= ReallocatePool (
135 ASSERT (Str
->str
!= NULL
);
138 Str
->maxlen
= MAX_CHAR
* sizeof (UINT16
);
139 if (strsize
< Str
->maxlen
) {
140 StrCat (Str
->str
, AppendStr
);
141 Str
->len
= strsize
- sizeof (UINT16
);
144 gBS
->FreePool (AppendStr
);
148 EFI_DEVICE_PATH_PROTOCOL
*
149 BdsLibUnpackDevicePath (
150 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
156 Function unpacks a device path data structure so that all the nodes
157 of a device path are naturally aligned.
161 DevPath - A pointer to a device path data structure
165 If the memory for the device path is successfully allocated, then a
166 pointer to the new device path is returned. Otherwise, NULL is returned.
170 EFI_DEVICE_PATH_PROTOCOL
*Src
;
171 EFI_DEVICE_PATH_PROTOCOL
*Dest
;
172 EFI_DEVICE_PATH_PROTOCOL
*NewPath
;
176 // Walk device path and round sizes to valid boundries
181 Size
+= DevicePathNodeLength (Src
);
182 Size
+= ALIGN_SIZE (Size
);
184 if (IsDevicePathEnd (Src
)) {
188 Src
= NextDevicePathNode (Src
);
191 // Allocate space for the unpacked path
193 NewPath
= AllocateZeroPool (Size
);
196 ASSERT (((UINTN
) NewPath
) % MIN_ALIGNMENT_SIZE
== 0);
204 Size
= DevicePathNodeLength (Src
);
205 CopyMem (Dest
, Src
, Size
);
206 Size
+= ALIGN_SIZE (Size
);
207 SetDevicePathNodeLength (Dest
, Size
);
208 Dest
->Type
|= EFI_DP_TYPE_UNPACKED
;
209 Dest
= (EFI_DEVICE_PATH_PROTOCOL
*) (((UINT8
*) Dest
) + Size
);
211 if (IsDevicePathEnd (Src
)) {
215 Src
= NextDevicePathNode (Src
);
224 IN OUT POOL_PRINT
*Str
,
228 PCI_DEVICE_PATH
*Pci
;
231 CatPrint (Str
, L
"Pci(%x|%x)", Pci
->Device
, Pci
->Function
);
236 IN OUT POOL_PRINT
*Str
,
240 PCCARD_DEVICE_PATH
*Pccard
;
243 CatPrint (Str
, L
"Pcmcia(Function%x)", Pccard
->FunctionNumber
);
248 IN OUT POOL_PRINT
*Str
,
252 MEMMAP_DEVICE_PATH
*MemMap
;
257 L
"MemMap(%d:%.lx-%.lx)",
259 MemMap
->StartingAddress
,
260 MemMap
->EndingAddress
266 IN OUT POOL_PRINT
*Str
,
270 CONTROLLER_DEVICE_PATH
*Controller
;
272 Controller
= DevPath
;
273 CatPrint (Str
, L
"Ctrl(%d)", Controller
->ControllerNumber
);
278 IN OUT POOL_PRINT
*Str
,
285 Convert Vendor device path to device name
289 Str - The buffer store device name
290 DevPath - Pointer to vendor device path
294 When it return, the device name have been stored in *Str.
298 VENDOR_DEVICE_PATH
*Vendor
;
303 Temp
= (INT32
*) (&Vendor
->Guid
);
305 switch (DevicePathType (&Vendor
->Header
)) {
306 case HARDWARE_DEVICE_PATH
:
308 // If the device is a winntbus device, we will give it a readable device name.
310 if (CompareGuid (&Vendor
->Guid
, &mEfiWinNtThunkProtocolGuid
)) {
311 CatPrint (Str
, L
"%s", L
"WinNtBus");
313 } else if (CompareGuid (&Vendor
->Guid
, &mEfiWinNtUgaGuid
)) {
314 CatPrint (Str
, L
"%s", L
"UGA");
316 } else if (CompareGuid (&Vendor
->Guid
, &mEfiWinNtSerialPortGuid
)) {
317 CatPrint (Str
, L
"%s", L
"Serial");
324 case MESSAGING_DEVICE_PATH
:
326 // If the device is a winntbus device, we will give it a readable device name.
328 if (CompareGuid (&Vendor
->Guid
, &mEfiMsgPcAnsiGuid
)) {
329 CatPrint (Str
, L
"%s", L
"PC-ANSI");
331 } else if (CompareGuid (&Vendor
->Guid
, &mEfiMsgVt100Guid
)) {
332 CatPrint (Str
, L
"%s", L
"VT100");
334 } else if (CompareGuid (&Vendor
->Guid
, &mEfiMsgVt100PlusGuid
)) {
335 CatPrint (Str
, L
"%s", L
"VT100+");
337 } else if (CompareGuid (&Vendor
->Guid
, &mEfiMsgVt100Utf8Guid
)) {
338 CatPrint (Str
, L
"%s", L
"VT100-UTF8");
345 case MEDIA_DEVICE_PATH
:
354 CatPrint (Str
, L
"Ven%s(%g)", Type
, &Vendor
->Guid
);
359 IN OUT POOL_PRINT
*Str
,
363 ACPI_HID_DEVICE_PATH
*Acpi
;
366 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
367 CatPrint (Str
, L
"Acpi(PNP%04x,%x)", EISA_ID_TO_NUM (Acpi
->HID
), Acpi
->UID
);
369 CatPrint (Str
, L
"Acpi(%08x,%x)", Acpi
->HID
, Acpi
->UID
);
375 IN OUT POOL_PRINT
*Str
,
379 ATAPI_DEVICE_PATH
*Atapi
;
385 Atapi
->PrimarySecondary
? L
"Secondary" : L
"Primary",
386 Atapi
->SlaveMaster
? L
"Slave" : L
"Master"
392 IN OUT POOL_PRINT
*Str
,
396 SCSI_DEVICE_PATH
*Scsi
;
399 CatPrint (Str
, L
"Scsi(Pun%x,Lun%x)", Scsi
->Pun
, Scsi
->Lun
);
404 IN OUT POOL_PRINT
*Str
,
408 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
411 CatPrint (Str
, L
"Fibre(Wwn%lx,Lun%x)", Fibre
->WWN
, Fibre
->Lun
);
416 IN OUT POOL_PRINT
*Str
,
420 F1394_DEVICE_PATH
*F1394
;
423 CatPrint (Str
, L
"1394(%g)", &F1394
->Guid
);
428 IN OUT POOL_PRINT
*Str
,
432 USB_DEVICE_PATH
*Usb
;
435 CatPrint (Str
, L
"Usb(%x, %x)", Usb
->ParentPortNumber
, Usb
->InterfaceNumber
);
440 IN OUT POOL_PRINT
*Str
,
444 USB_CLASS_DEVICE_PATH
*UsbClass
;
449 L
"Usb Class(%x, %x, %x, %x, %x)",
452 UsbClass
->DeviceClass
,
453 UsbClass
->DeviceSubClass
,
454 UsbClass
->DeviceProtocol
460 IN OUT POOL_PRINT
*Str
,
464 I2O_DEVICE_PATH
*I2O
;
467 CatPrint (Str
, L
"I2O(%x)", I2O
->Tid
);
472 IN OUT POOL_PRINT
*Str
,
476 MAC_ADDR_DEVICE_PATH
*MAC
;
482 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
483 if (MAC
->IfType
== 0x01 || MAC
->IfType
== 0x00) {
487 CatPrint (Str
, L
"Mac(");
489 for (Index
= 0; Index
< HwAddressSize
; Index
++) {
490 CatPrint (Str
, L
"%02x", MAC
->MacAddress
.Addr
[Index
]);
493 CatPrint (Str
, L
")");
498 IN OUT POOL_PRINT
*Str
,
502 IPv4_DEVICE_PATH
*IP
;
507 L
"IPv4(%d.%d.%d.%d:%d)",
508 IP
->RemoteIpAddress
.Addr
[0],
509 IP
->RemoteIpAddress
.Addr
[1],
510 IP
->RemoteIpAddress
.Addr
[2],
511 IP
->RemoteIpAddress
.Addr
[3],
518 IN OUT POOL_PRINT
*Str
,
522 IPv6_DEVICE_PATH
*IP
;
525 CatPrint (Str
, L
"IP-v6(not-done)");
530 IN OUT POOL_PRINT
*Str
,
534 INFINIBAND_DEVICE_PATH
*InfiniBand
;
536 InfiniBand
= DevPath
;
537 CatPrint (Str
, L
"InfiniBand(not-done)");
542 IN OUT POOL_PRINT
*Str
,
546 UART_DEVICE_PATH
*Uart
;
550 switch (Uart
->Parity
) {
580 if (Uart
->BaudRate
== 0) {
581 CatPrint (Str
, L
"Uart(DEFAULT %c", Parity
);
583 CatPrint (Str
, L
"Uart(%d %c", Uart
->BaudRate
, Parity
);
586 if (Uart
->DataBits
== 0) {
587 CatPrint (Str
, L
"D");
589 CatPrint (Str
, L
"%d", Uart
->DataBits
);
592 switch (Uart
->StopBits
) {
594 CatPrint (Str
, L
"D)");
598 CatPrint (Str
, L
"1)");
602 CatPrint (Str
, L
"1.5)");
606 CatPrint (Str
, L
"2)");
610 CatPrint (Str
, L
"x)");
617 IN OUT POOL_PRINT
*Str
,
621 HARDDRIVE_DEVICE_PATH
*Hd
;
624 switch (Hd
->SignatureType
) {
625 case SIGNATURE_TYPE_MBR
:
628 L
"HD(Part%d,Sig%08x)",
630 *((UINT32
*) (&(Hd
->Signature
[0])))
634 case SIGNATURE_TYPE_GUID
:
639 (EFI_GUID
*) &(Hd
->Signature
[0])
646 L
"HD(Part%d,MBRType=%02x,SigType=%02x)",
657 IN OUT POOL_PRINT
*Str
,
661 CDROM_DEVICE_PATH
*Cd
;
664 CatPrint (Str
, L
"CDROM(Entry%x)", Cd
->BootEntry
);
669 IN OUT POOL_PRINT
*Str
,
673 FILEPATH_DEVICE_PATH
*Fp
;
676 CatPrint (Str
, L
"%s", Fp
->PathName
);
680 DevPathMediaProtocol (
681 IN OUT POOL_PRINT
*Str
,
685 MEDIA_PROTOCOL_DEVICE_PATH
*MediaProt
;
688 CatPrint (Str
, L
"%g", &MediaProt
->Protocol
);
693 IN OUT POOL_PRINT
*Str
,
697 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
699 FvFilePath
= DevPath
;
700 CatPrint (Str
, L
"%g", &FvFilePath
->NameGuid
);
705 IN OUT POOL_PRINT
*Str
,
709 BBS_BBS_DEVICE_PATH
*Bbs
;
713 switch (Bbs
->DeviceType
) {
714 case BBS_TYPE_FLOPPY
:
718 case BBS_TYPE_HARDDRIVE
:
726 case BBS_TYPE_PCMCIA
:
734 case BBS_TYPE_EMBEDDED_NETWORK
:
743 // Since current Print function hasn't implemented %a (for ansi string)
744 // we will only print Unicode strings.
746 CatPrint (Str
, L
"Legacy-%s", Type
);
751 IN OUT POOL_PRINT
*Str
,
755 CatPrint (Str
, L
",");
760 IN OUT POOL_PRINT
*Str
,
764 CatPrint (Str
, L
"?");
767 DEVICE_PATH_STRING_TABLE DevPathTable
[] = {
768 HARDWARE_DEVICE_PATH
,
771 HARDWARE_DEVICE_PATH
,
774 HARDWARE_DEVICE_PATH
,
777 HARDWARE_DEVICE_PATH
,
780 HARDWARE_DEVICE_PATH
,
786 MESSAGING_DEVICE_PATH
,
789 MESSAGING_DEVICE_PATH
,
792 MESSAGING_DEVICE_PATH
,
795 MESSAGING_DEVICE_PATH
,
798 MESSAGING_DEVICE_PATH
,
801 MESSAGING_DEVICE_PATH
,
804 MESSAGING_DEVICE_PATH
,
807 MESSAGING_DEVICE_PATH
,
810 MESSAGING_DEVICE_PATH
,
813 MESSAGING_DEVICE_PATH
,
816 MESSAGING_DEVICE_PATH
,
819 MESSAGING_DEVICE_PATH
,
822 MESSAGING_DEVICE_PATH
,
839 DevPathMediaProtocol
,
841 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
843 MEDIA_FV_FILEPATH_DP
,
850 END_DEVICE_PATH_TYPE
,
851 END_INSTANCE_DEVICE_PATH_SUBTYPE
,
860 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
864 Turns the Device Path into a printable string. Allcoates
865 the string from pool. The caller must SafeFreePool the returned
871 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
872 VOID (*DumpNode
) (POOL_PRINT
*, VOID
*);
877 ZeroMem (&Str
, sizeof (Str
));
879 if (DevPath
== NULL
) {
883 // Unpacked the device path
885 DevPath
= BdsLibUnpackDevicePath (DevPath
);
889 // Process each device path node
891 DevPathNode
= DevPath
;
892 while (!IsDevicePathEnd (DevPathNode
)) {
894 // Find the handler to dump this device path node
897 for (Index
= 0; DevPathTable
[Index
].Function
; Index
+= 1) {
899 if (DevicePathType (DevPathNode
) == DevPathTable
[Index
].Type
&&
900 DevicePathSubType (DevPathNode
) == DevPathTable
[Index
].SubType
902 DumpNode
= DevPathTable
[Index
].Function
;
907 // If not found, use a generic function
910 DumpNode
= DevPathNodeUnknown
;
913 // Put a path seperator in if needed
915 if (Str
.len
&& DumpNode
!= DevPathEndInstance
) {
916 CatPrint (&Str
, L
"/");
919 // Print this node of the device path
921 DumpNode (&Str
, DevPathNode
);
924 // Next device path node
926 DevPathNode
= NextDevicePathNode (DevPathNode
);
929 // Shrink pool used for string allocation
931 gBS
->FreePool (DevPath
);
934 NewSize
= (Str
.len
+ 1) * sizeof (CHAR16
);
935 Str
.str
= ReallocatePool (Str
.str
, NewSize
, NewSize
);
936 ASSERT (Str
.str
!= NULL
);
937 Str
.str
[Str
.len
] = 0;
941 EFI_DEVICE_PATH_PROTOCOL
*
942 LibDuplicateDevicePathInstance (
943 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
949 Function creates a device path data structure that identically matches the
950 device path passed in.
954 DevPath - A pointer to a device path data structure.
958 The new copy of DevPath is created to identically match the input.
959 Otherwise, NULL is returned.
963 EFI_DEVICE_PATH_PROTOCOL
*NewDevPath
;
964 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInst
;
965 EFI_DEVICE_PATH_PROTOCOL
*Temp
;
969 // get the size of an instance from the input
972 DevicePathInst
= GetNextDevicePathInstance (&Temp
, &Size
);
979 NewDevPath
= AllocateZeroPool (Size
);
980 ASSERT (NewDevPath
!= NULL
);
984 CopyMem (NewDevPath
, DevicePathInst
, Size
);