Message ID | 1417525227-14051-8-git-send-email-cornelia.huck@de.ibm.com |
---|---|
State | New |
Headers | show |
On Tue, Dec 02, 2014 at 02:00:15PM +0100, Cornelia Huck wrote: > 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: Cornelia Huck <cornelia.huck@de.ibm.com> > --- > hw/virtio/virtio.c | 16 ++++++++++++++++ > include/hw/virtio/virtio.h | 2 ++ > 2 files changed, 18 insertions(+) > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 8f69ffa..508dccf 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -96,6 +96,13 @@ static void virtqueue_init(VirtQueue *vq) > { > hwaddr pa = vq->pa; > > + if (pa == -1ULL) { > + /* > + * This is a virtio-1 style vq that has already been setup > + * in virtio_queue_set. > + */ > + return; > + } > vq->vring.desc = pa; > vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc); > vq->vring.used = vring_align(vq->vring.avail + > @@ -717,6 +724,15 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n) > return vdev->vq[n].pa; > } > > +void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc, > + hwaddr avail, hwaddr used) > +{ > + vdev->vq[n].pa = -1ULL; > + 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) > { > /* Don't allow guest to flip queue between existent and pa == -1ULL tricks look quite ugly. Can't we set desc/avail/used unconditionally, and drop the pa value? > diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h > index 68c40db..80ee313 100644 > --- a/include/hw/virtio/virtio.h > +++ b/include/hw/virtio/virtio.h > @@ -224,6 +224,8 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr); > hwaddr 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_rings(VirtIODevice *vdev, int n, hwaddr desc, > + hwaddr avail, hwaddr used); > 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); > -- > 1.7.9.5
On Tue, 2 Dec 2014 16:46:28 +0200 "Michael S. Tsirkin" <mst@redhat.com> wrote: > On Tue, Dec 02, 2014 at 02:00:15PM +0100, Cornelia Huck wrote: > > 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: Cornelia Huck <cornelia.huck@de.ibm.com> > > --- > > hw/virtio/virtio.c | 16 ++++++++++++++++ > > include/hw/virtio/virtio.h | 2 ++ > > 2 files changed, 18 insertions(+) > > > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > > index 8f69ffa..508dccf 100644 > > --- a/hw/virtio/virtio.c > > +++ b/hw/virtio/virtio.c > > @@ -96,6 +96,13 @@ static void virtqueue_init(VirtQueue *vq) > > { > > hwaddr pa = vq->pa; > > > > + if (pa == -1ULL) { > > + /* > > + * This is a virtio-1 style vq that has already been setup > > + * in virtio_queue_set. > > + */ > > + return; > > + } > > vq->vring.desc = pa; > > vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc); > > vq->vring.used = vring_align(vq->vring.avail + > > @@ -717,6 +724,15 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n) > > return vdev->vq[n].pa; > > } > > > > +void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc, > > + hwaddr avail, hwaddr used) > > +{ > > + vdev->vq[n].pa = -1ULL; > > + 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) > > { > > /* Don't allow guest to flip queue between existent and > > pa == -1ULL tricks look quite ugly. > Can't we set desc/avail/used unconditionally, and drop > the pa value? And have virtio_queue_get_addr() return desc? Let me see if I can come up with a patch.
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 8f69ffa..508dccf 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -96,6 +96,13 @@ static void virtqueue_init(VirtQueue *vq) { hwaddr pa = vq->pa; + if (pa == -1ULL) { + /* + * This is a virtio-1 style vq that has already been setup + * in virtio_queue_set. + */ + return; + } vq->vring.desc = pa; vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc); vq->vring.used = vring_align(vq->vring.avail + @@ -717,6 +724,15 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n) return vdev->vq[n].pa; } +void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc, + hwaddr avail, hwaddr used) +{ + vdev->vq[n].pa = -1ULL; + 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) { /* Don't allow guest to flip queue between existent and diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 68c40db..80ee313 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -224,6 +224,8 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr); hwaddr 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_rings(VirtIODevice *vdev, int n, hwaddr desc, + hwaddr avail, hwaddr used); 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);
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: Cornelia Huck <cornelia.huck@de.ibm.com> --- hw/virtio/virtio.c | 16 ++++++++++++++++ include/hw/virtio/virtio.h | 2 ++ 2 files changed, 18 insertions(+)