virtio: Support transports which can specify the vring alignment
Support virtio transports which can specify the vring alignment (ie where the guest communicates this to the host) by providing a new virtio_queue_set_align() function. (The default alignment remains as before.) Transports which wish to make use of this must set the has_variable_vring_alignment field in their VirtioBusClass struct to true; they can then change the alignment via virtio_queue_set_align(). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 1373977512-28932-5-git-send-email-peter.maydell@linaro.org
This commit is contained in:
parent
e63c0ba1bc
commit
6ce69d1c77
@ -19,8 +19,11 @@
|
|||||||
#include "qemu/atomic.h"
|
#include "qemu/atomic.h"
|
||||||
#include "hw/virtio/virtio-bus.h"
|
#include "hw/virtio/virtio-bus.h"
|
||||||
|
|
||||||
/* The alignment to use between consumer and producer parts of vring.
|
/*
|
||||||
* x86 pagesize again. */
|
* The alignment to use between consumer and producer parts of vring.
|
||||||
|
* x86 pagesize again. This is the default, used by transports like PCI
|
||||||
|
* which don't provide a means for the guest to tell the host the alignment.
|
||||||
|
*/
|
||||||
#define VIRTIO_PCI_VRING_ALIGN 4096
|
#define VIRTIO_PCI_VRING_ALIGN 4096
|
||||||
|
|
||||||
typedef struct VRingDesc
|
typedef struct VRingDesc
|
||||||
@ -54,6 +57,7 @@ typedef struct VRingUsed
|
|||||||
typedef struct VRing
|
typedef struct VRing
|
||||||
{
|
{
|
||||||
unsigned int num;
|
unsigned int num;
|
||||||
|
unsigned int align;
|
||||||
hwaddr desc;
|
hwaddr desc;
|
||||||
hwaddr avail;
|
hwaddr avail;
|
||||||
hwaddr used;
|
hwaddr used;
|
||||||
@ -93,7 +97,7 @@ static void virtqueue_init(VirtQueue *vq)
|
|||||||
vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc);
|
vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc);
|
||||||
vq->vring.used = vring_align(vq->vring.avail +
|
vq->vring.used = vring_align(vq->vring.avail +
|
||||||
offsetof(VRingAvail, ring[vq->vring.num]),
|
offsetof(VRingAvail, ring[vq->vring.num]),
|
||||||
VIRTIO_PCI_VRING_ALIGN);
|
vq->vring.align);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t vring_desc_addr(hwaddr desc_pa, int i)
|
static inline uint64_t vring_desc_addr(hwaddr desc_pa, int i)
|
||||||
@ -687,6 +691,21 @@ int virtio_queue_get_id(VirtQueue *vq)
|
|||||||
return vq - &vdev->vq[0];
|
return vq - &vdev->vq[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
|
||||||
|
{
|
||||||
|
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
|
||||||
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
||||||
|
|
||||||
|
/* Check that the transport told us it was going to do this
|
||||||
|
* (so a buggy transport will immediately assert rather than
|
||||||
|
* silently failing to migrate this state)
|
||||||
|
*/
|
||||||
|
assert(k->has_variable_vring_alignment);
|
||||||
|
|
||||||
|
vdev->vq[n].vring.align = align;
|
||||||
|
virtqueue_init(&vdev->vq[n]);
|
||||||
|
}
|
||||||
|
|
||||||
void virtio_queue_notify_vq(VirtQueue *vq)
|
void virtio_queue_notify_vq(VirtQueue *vq)
|
||||||
{
|
{
|
||||||
if (vq->vring.desc) {
|
if (vq->vring.desc) {
|
||||||
@ -727,6 +746,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
|
|||||||
abort();
|
abort();
|
||||||
|
|
||||||
vdev->vq[i].vring.num = queue_size;
|
vdev->vq[i].vring.num = queue_size;
|
||||||
|
vdev->vq[i].vring.align = VIRTIO_PCI_VRING_ALIGN;
|
||||||
vdev->vq[i].handle_output = handle_output;
|
vdev->vq[i].handle_output = handle_output;
|
||||||
|
|
||||||
return &vdev->vq[i];
|
return &vdev->vq[i];
|
||||||
@ -833,6 +853,9 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
qemu_put_be32(f, vdev->vq[i].vring.num);
|
qemu_put_be32(f, vdev->vq[i].vring.num);
|
||||||
|
if (k->has_variable_vring_alignment) {
|
||||||
|
qemu_put_be32(f, vdev->vq[i].vring.align);
|
||||||
|
}
|
||||||
qemu_put_be64(f, vdev->vq[i].pa);
|
qemu_put_be64(f, vdev->vq[i].pa);
|
||||||
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) {
|
||||||
@ -889,6 +912,9 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
|
|||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
vdev->vq[i].vring.num = qemu_get_be32(f);
|
vdev->vq[i].vring.num = qemu_get_be32(f);
|
||||||
|
if (k->has_variable_vring_alignment) {
|
||||||
|
vdev->vq[i].vring.align = qemu_get_be32(f);
|
||||||
|
}
|
||||||
vdev->vq[i].pa = qemu_get_be64(f);
|
vdev->vq[i].pa = 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;
|
||||||
|
@ -62,6 +62,12 @@ typedef struct VirtioBusClass {
|
|||||||
* This is called by virtio-bus just before the device is unplugged.
|
* This is called by virtio-bus just before the device is unplugged.
|
||||||
*/
|
*/
|
||||||
void (*device_unplug)(DeviceState *d);
|
void (*device_unplug)(DeviceState *d);
|
||||||
|
/*
|
||||||
|
* Does the transport have variable vring alignment?
|
||||||
|
* (ie can it ever call virtio_queue_set_align()?)
|
||||||
|
* Note that changing this will break migration for this transport.
|
||||||
|
*/
|
||||||
|
bool has_variable_vring_alignment;
|
||||||
} VirtioBusClass;
|
} VirtioBusClass;
|
||||||
|
|
||||||
struct VirtioBusState {
|
struct VirtioBusState {
|
||||||
|
@ -202,6 +202,7 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);
|
|||||||
hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n);
|
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);
|
||||||
|
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);
|
||||||
void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
|
void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user