Virtio - General Initialization And Device Operation

该文是通过对virtio-1.2官方文档翻译生成的,文档的下载地址为: http://docs.oasis-open.org/virtio/virtio/v1.2/


We start with an overview of device initialization, then expand on the details of the device and how each step is preformed. This section is best read along with the bus-specific section which describes how to communicate with the specific device.
我们首先概述设备初始化,然后扩展设备的细节以及每个步骤是如何执行的。本节最好与特定于总线的部分一起阅读,其中描述了如何与特定的设备进行通信。

3.1 Device Initialization

3.1.1 Driver Requirements: Device Initialization

The driver MUST follow this sequence to initialize a device:
驱动程序必须按照以下顺序来初始化一个设备:

  1. Reset the device. 复位设备
  2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device. 设置ACKNOWLEDGE 状态位:guest操作系统会注意到该设备。
  3. Set the DRIVER status bit: the guest OS knows how to drive the device. 设置驱动程序状态位:guest操作系统知道如何驱动该设备。
  4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it. 读取设备特征位,并将操作系统和驱动程序所理解的特征位的子集写入设备。在此步骤中,驱动程序可以读取(但不能写入)特定于设备的配置字段,以在接受它之前检查它是否可以支持该设备。
  5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step. 设置FEATURES_OK状态位。驱动程序在这个步骤之后不能接受新的特性位。
  6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable. 重新读取设备状态,以确保FEATURES_OK位仍然被设置:否则,该设备不支持我们的特性子集,并且该设备不可用。
  7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues. 执行特定于设备的设置,包括发现设备的virtqueues ,可选的每个总线设置,读取和可能写入设备的virtio 配置空间,以及virtqueues的填充。
  8. Set the DRIVER_OK status bit. At this point the device is “live” . 设置DRIVER_OK状态位。此时,该设备将变为可用。
    If any of these steps go irrecoverably wrong, the driver SHOULD set the FAILED status bit to indicate that it has given up on the device (it can reset the device later to restart if desired). The driver MUST NOT continue initialization in that case.
    如果这些步骤出现不可恢复的错误,驱动程序应该将失败状态位设置为表示它在设备上已经放弃(如果需要,它如果想可以稍后重置设备以重新启动)。在这种情况下,驱动程序不能继续初始化。
    The driver MUST NOT send any buffer available notifications to the device before setting DRIVER_OK.
    在设置DRIVER_OK之前,驱动程序不能向设备发送任何可用的缓冲区通知。

3.1.2 Legacy Interface: Device Initialization

Legacy devices did not support the FEATURES_OK status bit, and thus did not have a graceful way for the device to indicate unsupported feature combinations. They also did not provide a clear mechanism to end feature negotiation, which meant that devices finalized features on first-use, and no features could be introduced which radically changed the initial operation of the device.
遗留设备不支持FEATURES_OK状态位,因此该设备没有一种优雅的方式来指示不受支持的功能组合。它们也没有提供一个明确的机制来结束功能协商,这意味着设备在首次使用时最终确定了功能,也没有引入任何从根本上改变设备最初操作的功能。
Legacy driver implementations often used the device before setting the DRIVER_OK bit, and sometimes even before writing the feature bits to the device.
传统的驱动程序实现通常在设置DRIVER_OK位之前使用该设备,有时甚至在将特性位写入设备之前也会使用该设备。
The result was the steps 5 and 6 were omitted, and steps 4, 7 and 8 were conflated.
结果是省略了步骤5和步骤6,并将步骤4、步骤7和步骤8合并。
Therefore, when using the legacy interface:
因此,在使用遗留接口时:
• The transitional driver MUST execute the initialization sequence as described in 3.1 but omitting the steps 5 and 6.
过渡驱动程序必须执行3.1中描述的初始化序列,但省略了步骤5和步骤6。
• The transitional device MUST support the driver writing device configuration fields before the step 4.
过渡设备必须支持在步骤4之前的驱动程序写入设备配置字段。
• The transitional device MUST support the driver using the device before the step 8.
过渡设备必须在步骤8之前支持使用该设备的驱动程序。

3.2 Device Operation

When operating the device, each field in the device configuration space can be changed by either the driver or the device.
在操作设备时,驱动程序或设备都可以更改设备配置空间中的每个字段。
Whenever such a configuration change is triggered by the device, driver is notified. This makes it possible for drivers to cache device configuration, avoiding expensive configuration reads unless notified.
每当设备触发这样的配置更改时,就会通知驱动程序。这使得驱动程序可以缓存设备配置,避免了昂贵的配置读取,除非得到通知。

3.2.1 Notification of Device Configuration Changes

For devices where the device-specific configuration information can be changed, a configuration change notification is sent when a device-specific configuration change occurs.
对于可以更改特定于设备的配置信息的设备,当设备特定的配置更改发生时,会发送配置更改通知。
In addition, this notification is triggered by the device setting DEVICE_NEEDS_RESET (see 2.1.2).
此外,此通知将由设备设置DEVICE_NEEDS_RESET触发(参见2.1.2)。

3.3 Device Cleanup

Once the driver has set the DRIVER_OK status bit, all the configured virtqueue of the device are considered live. None of the virtqueues of a device are live once the device has been reset.
一旦驱动程序设置了DRIVER_OK状态位,设备的所有配置的virtqueue 都被认为是可用的。一旦设备被重置,设备的virtqueues都不再可用。

3.3.1 Driver Requirements: Device Cleanup

A driver MUST NOT alter virtqueue entries for exposed buffers, i.e., buffers which have been made available to the device (and not been used by the device) of a live virtqueue.
驱动程序不能更改暴露的缓冲区的virtqueue 条目,即已提供给实时virtqueue 的设备(但未被设备使用)的缓冲区。
Thus a driver MUST ensure a virtqueue isn’t live (by device reset) before removing exposed buffers.
因此,在删除暴露的缓冲区之前,驱动程序必须确保virtqueue 不活动(通过设备重置)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值