From patchwork Mon Nov 14 14:55:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 5105 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 495FD23FEF for ; Mon, 14 Nov 2011 14:55:37 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 83CE4A18115 for ; Mon, 14 Nov 2011 14:55:36 +0000 (UTC) Received: by faaa26 with SMTP id a26so583418faa.11 for ; Mon, 14 Nov 2011 06:55:36 -0800 (PST) Received: by 10.152.144.136 with SMTP id sm8mr14297788lab.33.1321282536275; Mon, 14 Nov 2011 06:55:36 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.40.7 with SMTP id t7cs42486lak; Mon, 14 Nov 2011 06:55:35 -0800 (PST) Received: by 10.213.114.18 with SMTP id c18mr534604ebq.68.1321282532340; Mon, 14 Nov 2011 06:55:32 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id v43si1883188eeb.151.2011.11.14.06.55.31 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Nov 2011 06:55:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1RPxwW-0004y5-GW; Mon, 14 Nov 2011 14:55:28 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Pawel Moll , Anthony Liguori Subject: [RFC 2/4] virtio: Support transports which can specify the vring alignment Date: Mon, 14 Nov 2011 14:55:26 +0000 Message-Id: <1321282528-19070-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1321282528-19070-1-git-send-email-peter.maydell@linaro.org> References: <1321282528-19070-1-git-send-email-peter.maydell@linaro.org> 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.) FIXME save/load support for this new field! Signed-off-by: Peter Maydell --- hw/virtio.c | 14 ++++++++++++-- hw/virtio.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/virtio.c b/hw/virtio.c index 5bd43a1..a08bacb 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -19,7 +19,9 @@ #include "qemu-barrier.h" /* The alignment to use between consumer and producer parts of vring. - * x86 pagesize again. */ + * 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 typedef struct VRingDesc @@ -53,6 +55,7 @@ typedef struct VRingUsed typedef struct VRing { unsigned int num; + unsigned int align; target_phys_addr_t desc; target_phys_addr_t avail; target_phys_addr_t used; @@ -90,7 +93,7 @@ static void virtqueue_init(VirtQueue *vq) vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc); vq->vring.used = vring_align(vq->vring.avail + offsetof(VRingAvail, ring[vq->vring.num]), - VIRTIO_PCI_VRING_ALIGN); + vq->vring.align); } static inline uint64_t vring_desc_addr(target_phys_addr_t desc_pa, int i) @@ -630,6 +633,12 @@ int virtio_queue_get_num(VirtIODevice *vdev, int n) return vdev->vq[n].vring.num; } +void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) +{ + vdev->vq[n].vring.align = align; + virtqueue_init(&vdev->vq[n]); +} + void virtio_queue_notify_vq(VirtQueue *vq) { if (vq->vring.desc) { @@ -670,6 +679,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, abort(); vdev->vq[i].vring.num = queue_size; + vdev->vq[i].vring.align = VIRTIO_PCI_VRING_ALIGN; vdev->vq[i].handle_output = handle_output; return &vdev->vq[i]; diff --git a/hw/virtio.h b/hw/virtio.h index 352aba6..9b068e3 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -180,6 +180,7 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, target_phys_addr_t addr); target_phys_addr_t virtio_queue_get_addr(VirtIODevice *vdev, int n); void virtio_queue_set_num(VirtIODevice *vdev, int n, int num); 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); uint16_t virtio_queue_vector(VirtIODevice *vdev, int n); void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);