virtio驱动如何同设备交互

virtio设备作为PCI设备工作,其配置空间包含设备特性、队列选择、状态等。驱动通过读写配置空间与qemu-kvm交互,如选择队列、设置队列地址。qemu-kvm通过MemoryRegionPortio响应读写请求。guest分配vring表空间,通过PCI配置空间传递地址给qemu-kvm,两者共享vring进行通信,并通过中断机制同步处理状态。
摘要由CSDN通过智能技术生成

virtio设备是作为pci设备被使用的,因此具有pci设备的所有属性:

virtio header占用pci设备的24字节的配置空间:32 * (0 - 5)
virtio header后面跟随一个device specific的config结构

virtio header包括:
/* A 32-bit r/o bitmask of the features supported by the host */
#define VIRTIO_PCI_HOST_FEATURES 0

/* A 32-bit r/w bitmask of features activated by the guest */
#define VIRTIO_PCI_GUEST_FEATURES 4

/* A 32-bit r/w PFN for the currently selected queue */
#define VIRTIO_PCI_QUEUE_PFN  8

/* A 16-bit r/o queue size for the currently selected queue */
#define VIRTIO_PCI_QUEUE_NUM  12

/* A 16-bit r/w queue selector */
#define VIRTIO_PCI_QUEUE_SEL  14

/* A 16-bit r/w queue notifier */
#define VIRTIO_PCI_QUEUE_NOTIFY  16

/* An 8-bit device status register.  */
#define VIRTIO_PCI_STATUS  18

/* An 8-bit r/o interrupt status register.  Reading the value will

return the
 * current contents of the ISR and will also clear it.  This is

effectively
 * a read-and-acknowledge. */
#define VIRTIO_PCI_ISR   19

/* The bit of the ISR which indicates a device configuration change. */
#define VIRTIO_PCI_ISR_CONFIG  0x2

/* MSI-X registers: only enabled if MSI-X is enabled. */
/* A 16-bit vector for configuration changes. */
#define VIRTIO_MSI_CONFIG_VECTOR        20
/* A 16-bit vector for s

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值