This document describes the specifications of the “virtio” family of devices. These devices are found in virtual environments, yet by design they look like physical devices to the guest within the virtual machine - and this document treats them as such. This similarity allows the guest to use standard drivers and discovery mechanisms.
本文档描述了“virtio”系列设备的规格。这些设备位于虚拟环境中,但根据设计,它们看起来就像虚拟机中的客户所使用的物理设备——本文档也这样对待它们。这种相似性允许客户机使用标准的驱动程序和发现机制。
The purpose of virtio and this specification is that virtual environments and guests should have a straightforward, efficient, standard and extensible mechanism for virtual devices, rather than boutique per-environment or per-OS mechanisms.
virtio和这个规范的目的是让虚拟环境和来宾应该为虚拟设备提供一个简单、高效、标准和可扩展的机制,而不是每个环境或每个操作系统的精品机制。
[RFC2119] Bradner S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP 14, RFC 2119, March 1997.
http://www.ietf.org/rfc/rfc2119.txt
[RFC4122] Leach, P., Mealling, M., and R. Salz, “A Universally Unique IDentifier (UUID) URN Namespace”, RFC 4122, DOI 10.17487/RFC4122, July 2005.
http://www.ietf.org/rfc/rfc4122.txt
[S390 PoP] z/Architecture Principles of Operation, IBM Publication SA22-7832, https://www.ibm.com/docs/en/SSQ2R2_15.0.0/com.ibm.tpf.toolkit.hlasm.doc/ dz9zr006.pdf, and any future revisions
[S390 Common I/O] ESA/390 Common I/O-Device and Self-Description, IBM Publication SA22-7204, https://www.ibm.com/resources/publications/OutputPubsDetails?PubID=
SA22720401, and any future revisions
[PCI] Conventional PCI Specifications, http://www.pcisig.com/specifications/conventional/, PCI-SIG
[PCIe] PCI Express Specifications http://www.pcisig.com/specifications/pciexpress/, PCI-SIG
[IEEE 802] IEEE Standard for Local and Metropolitan Area Networks: Overview and Architec- ture,
http://www.ieee802.org/, IEEE
[SAM] SCSI Architectural Model,
http://www.t10.org/cgi-bin/ac.pl?t=f&f=sam4r05.pdf
[SCSI MMC] SCSI Multimedia Commands, http://www.t10.org/cgi-bin/ac.pl?t=f&f=mmc6r00.pdf
[FUSE] Linux FUSE interface, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/ linux/fuse.h
[eMMC] eMMC Electrical Standard (5.1), JESD84-B51, http://www.jedec.org/sites/default/files/docs/JESD84-B51.pdf
[HDA] High Definition Audio Specification, https://www.intel.com/content/dam/www/public/us/en/documents/ product-specifications/high-definition-audio-specification.pdf
[I2C] I2C-bus specification and user manual, https://www.nxp.com/docs/en/user-guide/UM10204.pdf
[SCMI] Arm System Control and Management Interface, DEN0056, https://developer.arm.com/docs/den0056/c, version C and any future revisions
[Virtio PCI Draft] Virtio PCI Draft Specification
http://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in [RFC2119].
本文件中的关键词“必须”、“必须不”、“必需”、“应”、“不应”、“应该”、“不应该”、“推荐”、“可能”和“可选”的解释为[RFC2119]中所述。
Specification drafts preceding version 1.0 of this specification (e.g. see [Virtio PCI Draft]) defined a similar, but different interface between the driver and the device. Since these are widely deployed, this specification accommodates OPTIONAL features to simplify transition from these earlier draft interfaces.
本规范1.0版之前的规范草案(例如,参见[Virtio PCI草案])在驱动程序和设备之间定义了一个相似但不同的接口。由于这些特性被广泛部署,该规范容纳了可选特性,以简化从这些早期草案接口的转换。
Specifically devices and drivers MAY support:
特别是设备和驱动程序可能支持:
Legacy Interface is an interface specified by an earlier draft of this specification (before 1.0)
Legacy Interface是本规范的早期草案(1.0之前)指定的接口
Legacy Device is a device implemented before this specification was released, and implementing a legacy interface on the host side
Legacy Device 是在此规范发布之前实现的设备,并在主机端实现了 legacy interface
Legacy Driver is a driver implemented before this specification was released, and implementing a legacy interface on the guest side
Legacy Driver 是在此规范发布之前实现的驱动程序,并在客户端实现了 legacy interface
Legacy devices and legacy drivers are not compliant with this specification.
Legacy devices 和 legacy drivers不符合此规范。
To simplify transition from these earlier draft interfaces, a device MAY implement:
为了简化从这些早期草案接口进行的转换,设备可以实现:
Transitional Device a device supporting both drivers conforming to this specification, and allowing legacy drivers.
Transitional Device 一种支持符合本规范的驱动程序,并允许遗留驱动程序的设备。
Similarly, a driver MAY implement:
类似地,一个驱动程序可以实现:
Transitional Driver a driver supporting both devices conforming to this specification, and legacy devices.
过渡驱动程序,一个支持符合本规范的设备和 legacy devices的驱动程序。
Note: Legacy interfaces are not required; ie. don’t implement them unless you have a need for backwards compatibility!
注意:不需要旧版接口。除非你需要向后兼容性,否则不要实现它们!
Devices or drivers with no legacy compatibility are referred to as non-transitional devices and drivers, respectively.
没有遗留兼容性的设备或驱动程序分别被称为非过渡性(non-transitional)设备和驱动程序。
For devices and drivers already implementing the legacy interface, some changes will have to be made to support this specification.
对于已经实现遗留接口(legacy interface)的设备和驱动程序,必须进行一些更改以支持此规范。
In this case, it might be beneficial for the reader to focus on sections tagged ”Legacy Interface” in the section title. These highlight the changes made since the earlier drafts.
在这种情况下,读者可以集中关注章节标题中标记为“遗留界面”的章节。这些都突出显示了自早期草案以来所做的改变。
Many device and driver in-memory structure layouts are documented using the C struct syntax. All structures are assumed to be without additional padding. To stress this, cases where common C compilers are known to insert extra padding within structures are tagged using the GNU C attribute((packed)) syntax.
许多设备和驱动器中的内存结构布局都是使用C结构语法记录的。所有的结构都被假设为没有额外的padding。为了强调这一点,已知通用C编译器在结构中插入额外padding 的情况将使用GNU C__attribute__((packed))
语法进行标记。
For the integer data types used in the structure definitions, the following conventions are used:
对于结构定义中使用的整数数据类型,将使用以下约定:
u8, u16, u32, u64 An unsigned integer of the specified length in bits.
u8, u16, u32, u64 一个以位为单位的指定长度的无符号整数。
le16, le32, le64 An unsigned integer of the specified length in bits, in little-endian byte order.
le16, le32, le64 一种以位为单位的指定长度的无符号整数,以小端点字节顺序排列。
be16, be32, be64 An unsigned integer of the specified length in bits, in big-endian byte order.
be16,be32,be64一个指定长度的无符号整数,按大端字节顺序排列
Some of the fields to be defined in this specification don’t start or don’t end on a byte boundary. Such fields are called bit-fields. A set of bit-fields is always a sub-division of an integer typed field.
在此规范中定义的一些字段不会在字节边界上开始或结束。这样的字段被称为位字段。一组位字段总是一个整数类型字段的细分。
Bit-fields within integer fields are always listed in order, from the least significant to the most significant bit. The bit-fields are considered unsigned integers of the specified width with the next in significance relationship of the bits preserved.
整数字段中的位字段总是按顺序列出,从最不重要位到最重要位。位字段被认为是指定宽度的无符号整数,下一个保留位的重要关系。
For example:
struct S {
be16 {
A : 15;
B : 1;
} x;
be16 y;
};
documents the value A stored in the low 15 bit of x and the value B stored in the high bit of x, the 16-bit integer x in turn stored using the big-endian byte order at the beginning of the structure S, and being followed immediately by an unsigned integer y stored in big-endian byte order at an offset of 2 bytes (16 bits) from the beginning of the structure.
记录存储在低15位x中的值A和存储在高位x中的值B,依次使用结构S开头的大字节顺序存储,紧接着是从结构开始的2位)的大字节顺序存储无符号整数y。
Note that this notation somewhat resembles the C bitfield syntax but should not be naively converted to a bitfield notation for portable code: it matches the way bitfields are packed by C compilers on little-endian architectures but not the way bitfields are packed by C compilers on big-endian architectures.
注意,这个符号有点类似于C位字段语法,但不应该天真地转换为可移植代码的位字段符号:它匹配小端架构上的C编译器打包的方式,而不是大端架构上的C编译器打包的位字段的方式。
Assuming that CPU_TO_BE16 converts a 16-bit integer from a native CPU to the big-endian byte order, the following is the equivalent portable C code to generate a value to be stored into x:
假设CPU_TO_BE16将一个16位整数从本地CPU转换为大端字节顺序,下面是生成存储在x中的值的等价可移植C代码:
CPU_TO_BE16(B << 15 | A)
In many cases, numeric values used in the interface between the device and the driver are documented using the C #define and /* */ comment syntax. Multiple related values are grouped together with a common name as a prefix, using _
as a separator. Using _XXX
as a suffix refers to all values in a group. For example:
在许多情况下,在设备和驱动程序之间的接口中使用的数值是使用c语言的#define和/**/注释语法记录的。多个相关值作为分隔符作为前缀,使用_作为公共符。使用_XXX作为后缀是指一个组中的所有值。例如:
/* Field Fld value A description */
#define VIRTIO_FLD_A (1 << 0)
/* Field Fld value B description */
#define VIRTIO_FLD_B (1 << 1)
documents two numeric values for a field Fld, with Fld having value 1 referring to A and Fld having value 2 referring to B. Note that << refers to the shift-left operation.
文档记录字段Fld的两个数值,Fld值1表示A,Fld值2表示B。注意,<<表示左移操作。
Further, in this case VIRTIO_FLD_A and VIRTIO_FLD_B refer to values 1 and 2 of Fld respectively. Further, VIRTIO_FLD_XXX refers to either VIRTIO_FLD_A or VIRTIO_FLD_B.
此外,在本例中,VIRTIO_FLD_A和VIRTIO_FLD_B分别表示Fld的值1和值2。此外,VIRTIO_FLD_XXX是指VIRTIO_FLD_A或VIRTIO_FLD_B。