From: Jason Wang Date: Fri, 25 Sep 2015 05:21:28 +0000 (+0800) Subject: virtio: introduce virtqueue_unmap_sg() X-Git-Tag: TizenStudio_2.0_p2.3.2~174^2~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a64d4cafa9dedad93da475f2f1e41133f433be67;p=sdk%2Femulator%2Fqemu.git virtio: introduce virtqueue_unmap_sg() Factor out sg unmapping logic. This will be reused by the patch that can discard descriptor. Cc: Michael S. Tsirkin Cc: Andrew James Signed-off-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit ce317461573bac12b10d67699b4ddf1f97cf066c) Signed-off-by: Michael Roth --- diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 0832db9..bb2c4cf 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -243,14 +243,12 @@ int virtio_queue_empty(VirtQueue *vq) return vring_avail_idx(vq) == vq->last_avail_idx; } -void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, - unsigned int len, unsigned int idx) +static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, + unsigned int len) { unsigned int offset; int i; - trace_virtqueue_fill(vq, elem, len, idx); - offset = 0; for (i = 0; i < elem->in_num; i++) { size_t size = MIN(len - offset, elem->in_sg[i].iov_len); @@ -266,6 +264,14 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, cpu_physical_memory_unmap(elem->out_sg[i].iov_base, elem->out_sg[i].iov_len, 0, elem->out_sg[i].iov_len); +} + +void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, + unsigned int len, unsigned int idx) +{ + trace_virtqueue_fill(vq, elem, len, idx); + + virtqueue_unmap_sg(vq, elem, len); idx = (idx + vring_used_idx(vq)) % vq->vring.num;