没有在UEFI SPEC中找到一个非常清晰的Device Path的定义。
关于Device Path,UEFI SPEC中有如下的描述:
A Device Path is constructed and used by the firmware to convey the location of important devices, such as the boot device and console, consistent with the software-visible topology of the system.
A Device Path is used to define the programmatic path to a device.
A Device Path is designed to make maximum leverage of the ACPI name space.
The Device Path also is used to fill in the gaps where ACPI defers to buses with standard enumeration algorithms.
The Device Path is also used to define the location on a medium where a file should be, or where it was loaded from.
A special case of the Device Path can also be used to support the optional booting of legacy operating systems from legacy media.
总的来说,Device Path主要描述的是设备或总线或legacy启动项。
直观的来说,Device Path可以看成是一个字符串,下面是进入UEFI Shell时的打印:
其中的红框部分就是一个个Device Path的字符串表示。
通过UEFI提供的接口ConvertDevicePathToText(),可以将Device Path结构体转换成CHAR16字符串并打印。
Device Path Protocol是Device Path在UEFI下的另一种,也是最常用的表示。(字符串形式的只是打印出来给人看的)
每一个代表实际物理设备或者逻辑设备的Handle都会安装Device Path Protocol。
Device Path Protocol在UEFI下的通用结构体如下:
/**
This protocol can be used on any device handle to obtain generic path/location
information concerning the physical device or logical device. If the handle does
not logically map to a physical device, the handle may not necessarily support
the device path protocol. The device path describes the location of the device
the handle is for. The size of the Device Path can be determined from the structures
that make up the Device Path.
**/
typedef struct {
UINT8 Type; ///< 0x01 Hardware Device Path.
///< 0x02 ACPI Device Path.
///< 0x03 Messaging Device Path.
///< 0x04 Media Device Path.
///< 0x05 BIOS Boot Specification Device Path.
///< 0x7F End of Hardware Device Path.
UINT8 SubType; ///< Varies by Type
///< 0xFF End Entire Device Path, or
///< 0x01 End This Instance of a Device Path and start a new
///< Device Path.
UINT8 Length[2]; ///< Specific Device Path data. Type and Sub-Type define
///< type of data. Size of data is included in Length.
} EFI_DEVICE_PATH_PROTOCOL;
它是一个可变结构体,因为有不同种类的Device Path,它们的大小各不相同。
目前的UEFI版本(2.6版本)定义了6种Device Path,分别是:
对于不同的Device Path,它们的通用结构的取值也不一样,下面是具体的值:
需要说明下:
1. 一个Device Path可能说由多个Device Path组成的,则各个组成部分被称为Device Path Node;
2. 每个Device Path都由End of Hardware Device Path结尾;
3. End of Hardware Device Path由两种类型,一种是End of This Instance of a Device Path(Sub-Type是0x01),另一种是End Entire Device Path(Sub-Type是0xFF),前者用在Device Path Node的最后,后者用在整个Device Path的最后:
在UEFI中有指定的函数来判断这两种End of Hardware Device Path:
BOOLEAN
EFIAPI
IsDevicePathEnd (
IN CONST VOID *Node
)
{
ASSERT (Node != NULL);
return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);
}
BOOLEAN
EFIAPI
IsDevicePathEndInstance (
IN CONST VOID *Node
)
{
ASSERT (Node != NULL);
return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);
}
Hardware Device Path描述了与一个设备关联的系统资源,比如共享内存,MMIO,IO等。
Hardware Device Path有多种子类型,比如PCI Device Path:
其它的类型还有:
这里不多做介绍,可以去看UEFI SPEC。
ACPI Device Path包含了ACPI设备ID和其它的一些内容,有_HID、_CID、_UID等ID和_ADR等其它信息。
根据包含的ACPI信息的多少,也有不同的子类型,如:
关于Messaging Device Path,UEFI SPEC的定义如下:
This Device Path is used to describe the connection of devices outside the resource domain of the
system. This Device Path can describe physical messaging information like SCSI ID, or abstract
information like networking protocol IP addresses.
并不是很理解,不过看起来像是一些总线和协议对应的Device Path,它有如下的子类型:
各种意义不明...
Media Device Path表示了能够作为启动项的设备的Device Path。
下面是所有的子类型:
BIOS Boot Specification Device Path与前一种Media Device Path类型,不同的是它表示的是Legacy BIOS启动项设备。
其中的Device Type也有不同的类型:
• 00h = Reserved
• 01h = Floppy
• 02h = Hard Disk
• 03h = CD-ROM
• 04h = PCMCIA
• 05h = USB
• 06h = Embedded network
• 07h..7Fh = Reserved
• 80h = BEV device
• 81h..FEh = Reserved
• FFh = Unknown
回到最开始的UEFI Shell的图中,里面的Device Path:
PciRoot(0x0)/Pci(0x1,0x1)/Ata(0x0)
它由三个Device Path Node组成,分别是:
1. PciRoot(0x0):一个ACPI Device Path;
2. Pci(0x1,0x1):一个Hardware Device Path,子类型是PCI Device Path;
3. Ata(0x0):一个Messaging Device Path,子类型是ATAPI Device Path;
UEFI SPEC提供了一个工具接口来操作Device Path:
///
/// This protocol is used to creates and manipulates device paths and device nodes.
///
typedef struct {
EFI_DEVICE_PATH_UTILS_GET_DEVICE_PATH_SIZE GetDevicePathSize;
EFI_DEVICE_PATH_UTILS_DUP_DEVICE_PATH DuplicateDevicePath;
EFI_DEVICE_PATH_UTILS_APPEND_PATH AppendDevicePath;
EFI_DEVICE_PATH_UTILS_APPEND_NODE AppendDeviceNode;
EFI_DEVICE_PATH_UTILS_APPEND_INSTANCE AppendDevicePathInstance;
EFI_DEVICE_PATH_UTILS_GET_NEXT_INSTANCE GetNextDevicePathInstance;
EFI_DEVICE_PATH_UTILS_IS_MULTI_INSTANCE IsDevicePathMultiInstance;
EFI_DEVICE_PATH_UTILS_CREATE_NODE CreateDeviceNode;
} EFI_DEVICE_PATH_UTILITIES_PROTOCOL;
具体各个接口的作用不多做介绍。
另外在EDKII代码中还提供了UefiDevicePathLib,里面也有不少有用的接口。
在BIOS/UEFI基础——Protocol介绍中有介绍Device Path的使用示例。