提交 ab223c95 编写于 作者: C Cornelia Huck 提交者: Michael S. Tsirkin

virtio: allow virtio-1 queue layout

For virtio-1 devices, we allow a more complex queue layout that doesn't
require descriptor table and rings on a physically-contigous memory area:
add virtio_queue_set_rings() to allow transports to set this up.
Signed-off-by: NCornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
上级 3c185597
...@@ -333,8 +333,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, ...@@ -333,8 +333,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,
case VIRTIO_MMIO_QUEUENUM: case VIRTIO_MMIO_QUEUENUM:
DPRINTF("mmio_queue write %d max %d\n", (int)value, VIRTQUEUE_MAX_SIZE); DPRINTF("mmio_queue write %d max %d\n", (int)value, VIRTQUEUE_MAX_SIZE);
virtio_queue_set_num(vdev, vdev->queue_sel, value); virtio_queue_set_num(vdev, vdev->queue_sel, value);
/* Note: only call this function for legacy devices */
virtio_queue_update_rings(vdev, vdev->queue_sel);
break; break;
case VIRTIO_MMIO_QUEUEALIGN: case VIRTIO_MMIO_QUEUEALIGN:
/* Note: this is only valid for legacy devices */
virtio_queue_set_align(vdev, vdev->queue_sel, value); virtio_queue_set_align(vdev, vdev->queue_sel, value);
break; break;
case VIRTIO_MMIO_QUEUEPFN: case VIRTIO_MMIO_QUEUEPFN:
......
...@@ -69,7 +69,6 @@ typedef struct VRing ...@@ -69,7 +69,6 @@ typedef struct VRing
struct VirtQueue struct VirtQueue
{ {
VRing vring; VRing vring;
hwaddr pa;
uint16_t last_avail_idx; uint16_t last_avail_idx;
/* Last used index value we have signalled on */ /* Last used index value we have signalled on */
uint16_t signalled_used; uint16_t signalled_used;
...@@ -93,15 +92,18 @@ struct VirtQueue ...@@ -93,15 +92,18 @@ struct VirtQueue
}; };
/* virt queue functions */ /* virt queue functions */
static void virtqueue_init(VirtQueue *vq) void virtio_queue_update_rings(VirtIODevice *vdev, int n)
{ {
hwaddr pa = vq->pa; VRing *vring = &vdev->vq[n].vring;
vq->vring.desc = pa; if (!vring->desc) {
vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc); /* not yet setup -> nothing to do */
vq->vring.used = vring_align(vq->vring.avail + return;
offsetof(VRingAvail, ring[vq->vring.num]), }
vq->vring.align); vring->avail = vring->desc + vring->num * sizeof(VRingDesc);
vring->used = vring_align(vring->avail +
offsetof(VRingAvail, ring[vring->num]),
vring->align);
} }
static inline uint64_t vring_desc_addr(VirtIODevice *vdev, hwaddr desc_pa, static inline uint64_t vring_desc_addr(VirtIODevice *vdev, hwaddr desc_pa,
...@@ -605,7 +607,6 @@ void virtio_reset(void *opaque) ...@@ -605,7 +607,6 @@ void virtio_reset(void *opaque)
vdev->vq[i].vring.avail = 0; vdev->vq[i].vring.avail = 0;
vdev->vq[i].vring.used = 0; vdev->vq[i].vring.used = 0;
vdev->vq[i].last_avail_idx = 0; vdev->vq[i].last_avail_idx = 0;
vdev->vq[i].pa = 0;
virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR); virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR);
vdev->vq[i].signalled_used = 0; vdev->vq[i].signalled_used = 0;
vdev->vq[i].signalled_used_valid = false; vdev->vq[i].signalled_used_valid = false;
...@@ -708,13 +709,21 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data) ...@@ -708,13 +709,21 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr) void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
{ {
vdev->vq[n].pa = addr; vdev->vq[n].vring.desc = addr;
virtqueue_init(&vdev->vq[n]); virtio_queue_update_rings(vdev, n);
} }
hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n) hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n)
{ {
return vdev->vq[n].pa; return vdev->vq[n].vring.desc;
}
void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc,
hwaddr avail, hwaddr used)
{
vdev->vq[n].vring.desc = desc;
vdev->vq[n].vring.avail = avail;
vdev->vq[n].vring.used = used;
} }
void virtio_queue_set_num(VirtIODevice *vdev, int n, int num) void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
...@@ -728,7 +737,6 @@ void virtio_queue_set_num(VirtIODevice *vdev, int n, int num) ...@@ -728,7 +737,6 @@ void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
return; return;
} }
vdev->vq[n].vring.num = num; vdev->vq[n].vring.num = num;
virtqueue_init(&vdev->vq[n]);
} }
VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector) VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector)
...@@ -771,6 +779,11 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) ...@@ -771,6 +779,11 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
/* virtio-1 compliant devices cannot change the alignment */
if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
error_report("tried to modify queue alignment for virtio-1 device");
return;
}
/* Check that the transport told us it was going to do this /* Check that the transport told us it was going to do this
* (so a buggy transport will immediately assert rather than * (so a buggy transport will immediately assert rather than
* silently failing to migrate this state) * silently failing to migrate this state)
...@@ -778,7 +791,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) ...@@ -778,7 +791,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
assert(k->has_variable_vring_alignment); assert(k->has_variable_vring_alignment);
vdev->vq[n].vring.align = align; vdev->vq[n].vring.align = align;
virtqueue_init(&vdev->vq[n]); virtio_queue_update_rings(vdev, n);
} }
void virtio_queue_notify_vq(VirtQueue *vq) void virtio_queue_notify_vq(VirtQueue *vq)
...@@ -992,7 +1005,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) ...@@ -992,7 +1005,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
if (k->has_variable_vring_alignment) { if (k->has_variable_vring_alignment) {
qemu_put_be32(f, vdev->vq[i].vring.align); qemu_put_be32(f, vdev->vq[i].vring.align);
} }
qemu_put_be64(f, vdev->vq[i].pa); /* XXX virtio-1 devices */
qemu_put_be64(f, vdev->vq[i].vring.desc);
qemu_put_be16s(f, &vdev->vq[i].last_avail_idx); qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
if (k->save_queue) { if (k->save_queue) {
k->save_queue(qbus->parent, i, f); k->save_queue(qbus->parent, i, f);
...@@ -1076,13 +1090,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) ...@@ -1076,13 +1090,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
if (k->has_variable_vring_alignment) { if (k->has_variable_vring_alignment) {
vdev->vq[i].vring.align = qemu_get_be32(f); vdev->vq[i].vring.align = qemu_get_be32(f);
} }
vdev->vq[i].pa = qemu_get_be64(f); vdev->vq[i].vring.desc = qemu_get_be64(f);
qemu_get_be16s(f, &vdev->vq[i].last_avail_idx); qemu_get_be16s(f, &vdev->vq[i].last_avail_idx);
vdev->vq[i].signalled_used_valid = false; vdev->vq[i].signalled_used_valid = false;
vdev->vq[i].notification = true; vdev->vq[i].notification = true;
if (vdev->vq[i].pa) { if (vdev->vq[i].vring.desc) {
virtqueue_init(&vdev->vq[i]); /* XXX virtio-1 devices */
virtio_queue_update_rings(vdev, i);
} else if (vdev->vq[i].last_avail_idx) { } else if (vdev->vq[i].last_avail_idx) {
error_report("VQ %d address 0x0 " error_report("VQ %d address 0x0 "
"inconsistent with Host index 0x%x", "inconsistent with Host index 0x%x",
...@@ -1138,7 +1153,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) ...@@ -1138,7 +1153,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
} }
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
if (vdev->vq[i].pa) { if (vdev->vq[i].vring.desc) {
uint16_t nheads; uint16_t nheads;
nheads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx; nheads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx;
/* Check it isn't doing strange things with descriptor numbers. */ /* Check it isn't doing strange things with descriptor numbers. */
......
...@@ -177,6 +177,9 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n); ...@@ -177,6 +177,9 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n);
void virtio_queue_set_num(VirtIODevice *vdev, int n, int num); void virtio_queue_set_num(VirtIODevice *vdev, int n, int num);
int virtio_queue_get_num(VirtIODevice *vdev, int n); int virtio_queue_get_num(VirtIODevice *vdev, int n);
int virtio_get_num_queues(VirtIODevice *vdev); int virtio_get_num_queues(VirtIODevice *vdev);
void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc,
hwaddr avail, hwaddr used);
void virtio_queue_update_rings(VirtIODevice *vdev, int n);
void virtio_queue_set_align(VirtIODevice *vdev, int n, int align); void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);
void virtio_queue_notify(VirtIODevice *vdev, int n); void virtio_queue_notify(VirtIODevice *vdev, int n);
uint16_t virtio_queue_vector(VirtIODevice *vdev, int n); uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册