From patchwork Fri Sep 25 05:21:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 522635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A1EBC14027C for ; Fri, 25 Sep 2015 15:22:10 +1000 (AEST) Received: from localhost ([::1]:36547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfLSS-0007pb-Iw for incoming@patchwork.ozlabs.org; Fri, 25 Sep 2015 01:22:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfLRy-0007BQ-JJ for qemu-devel@nongnu.org; Fri, 25 Sep 2015 01:21:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfLRu-0001bU-2R for qemu-devel@nongnu.org; Fri, 25 Sep 2015 01:21:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfLRt-0001bN-Sv for qemu-devel@nongnu.org; Fri, 25 Sep 2015 01:21:33 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id C8FC02FAA67; Fri, 25 Sep 2015 05:21:32 +0000 (UTC) Received: from jason-ThinkPad-T430s.nay.redhat.com (dhcp-14-122.nay.redhat.com [10.66.14.122]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8P5LRrO011009; Fri, 25 Sep 2015 01:21:29 -0400 From: Jason Wang To: mst@redhat.com, qemu-devel@nongnu.org Date: Fri, 25 Sep 2015 13:21:28 +0800 Message-Id: <1443158490-16469-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Andrew James , Jason Wang , ppandit@redhat.com Subject: [Qemu-devel] [PATCH V2 1/3] virtio: introduce virtqueue_unmap_sg() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- Changes from V1: - Fix use of uninitialized var warning. --- hw/virtio/virtio.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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;