From patchwork Wed Mar 29 14:24:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Liu X-Patchwork-Id: 668119 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp394763wrt; Wed, 29 Mar 2023 07:27:21 -0700 (PDT) X-Google-Smtp-Source: AK7set9u3PcRlMumWYO9ys2EPJnoPfYAlSg0n0bZml6Y+CyFemEgxCDTfEamgq8o7Vjhbmqe/src X-Received: by 2002:a05:6a20:3382:b0:d6:82a:ab45 with SMTP id f2-20020a056a20338200b000d6082aab45mr17715705pzd.29.1680100040996; Wed, 29 Mar 2023 07:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680100040; cv=none; d=google.com; s=arc-20160816; b=aUIdB+BgCXZLFfwuEP7nTH0DLIV8rJdrwdJIDydQvWNopx2g/tMxZClB24caL5+kYh sJwU5oZ56dO8DsYocE5jl9aYCxRPdtSGOR4jE6A0OaGjquumXQ31OXOIep6kV3GGYyIr EvspB0WVlEG9BXs7bNOuXrkHL1zuUnff4VBWP94fRjv6DWQNhuIHYv3qv57T5XUYPlOW EbVi0VrJS44buPzLJHTI1tz5CRnp3LsxofWY6Djn+c1ZHv9xB/+2jfGCWSQkiqATWVm7 dxBR1a2WQPz6nWBJ5aqNEmz0/xG/ifOGdesfnAc+EiM/B9g/8eG8pscp2rHE7Iog0XjE tDYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=78c+VmxN2b0SFyURnVGYa2t6nzYxxe4ORfj7VC7bhoQ=; b=yM0Ea2m5nX0KpkgZ9X26BpLrUGTk+1VA9xA8zTBTu2Z4X8VYz8BONrA+aKaMkAwyKg pC+e2ifJjFaPluyTsAr4PxS3FmUVCTEhrkM30AG1W2Ss+KvItTBazQ+2lNGB5OtgQo7q O+nHn3VkLIYlLUa1+hbwBo1fUMFj5jCYE++ugXPLaPWRlWimzVbDXkpLQYq+eKC93PdN fJHaLY19OekKrngw6bifp6p5aJOffj5TVjJ1pbaNz0aOH1YO+yjK+y5hHVFzwBgyC56M e0DdVJ+Uhx4+5kddSJV2rrRC/0xD2yYlL7kIFWvgwrRJwbh4BdOnFvELjPx+6mNo5oUf O03Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H18Ap8EI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a21-20020aa794b5000000b006262531b3e2si30003088pfl.361.2023.03.29.07.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:27:20 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H18Ap8EI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DB4438602D; Wed, 29 Mar 2023 16:27:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="H18Ap8EI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D130E85D34; Wed, 29 Mar 2023 16:25:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F35A985DD6 for ; Wed, 29 Mar 2023 16:25:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=paul.liu@linaro.org Received: by mail-pj1-x1035.google.com with SMTP id fy10-20020a17090b020a00b0023b4bcf0727so16351827pjb.0 for ; Wed, 29 Mar 2023 07:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680099915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=78c+VmxN2b0SFyURnVGYa2t6nzYxxe4ORfj7VC7bhoQ=; b=H18Ap8EIoLTo1IxWCQMgOQbv5XvH80moji0hPpznSiWDg8WqoCIhYBDDAJ7t7ZlGZk awPkCAasGeBnIPOnLd0gvCy7AyEZ3V01SaLrlRAPVtVH0A31ee86pQaL8AVfvWwWE/Dl K+CLjEx9/1L2WPDcHzcCDjXFydc4/FZWLBRnrCJKs/T3B3WL6eW+T55OVKYHcDKp+aaf lo0Xv0yvBdPKdqrCHC3CPG+uir3eGG+euN9jWwPtjPmXrxcPOl6B1ltFs4gBuZBNNmTf 0ZxCl4SxWAAdBP7A0EdiOMJ14sg2+qZS9FrnWq6HhS+QwrPEHrvf8u0tD2CSFUYc+e2D kbjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680099915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=78c+VmxN2b0SFyURnVGYa2t6nzYxxe4ORfj7VC7bhoQ=; b=rKpwWaw4L+URoI+NJL1bm8fVahJAVSglAxmC8TTlyTo+Auz6XG/f1KBUfW/To+r0xv oFflM3/curSkFoVMOSAl4kFE7HfO1k3YOY7ZVPNdq5rzE6iMB2dCHAQjNXnVgV9K3CDW /UJ66Qi6j0oN/V2IXWiSLS7pBf0V6av03X1MQX+yZRLjnGlJUf1wrfJPgNxuoI8gpQVy s/nyYHl5jyvfYk0O64ZniVQewx1JfuM39f/bH4rzoJSIDYfUZG2jyZgEA5IzHKKcttSf QnPUIl1Qc9MnTWZAuY/auibUs95zUlC4+okrbhoDWESCMWO/5YwGNtxpIdqTzbxcwk6V 8ZOQ== X-Gm-Message-State: AAQBX9dgJso8rX2V5f1AHlJNNZXa5KWcjXhNOR9Wc9I7mWesrsJYUj63 XvWVKp1fnU/ISFECybdB38Pv5TrsL7dGZ66/GTo= X-Received: by 2002:a17:903:1c7:b0:19d:323:e68 with SMTP id e7-20020a17090301c700b0019d03230e68mr23752087plh.1.1680099914921; Wed, 29 Mar 2023 07:25:14 -0700 (PDT) Received: from localhost ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id iz4-20020a170902ef8400b0019aa4c00ff4sm23132545plb.206.2023.03.29.07.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:25:14 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: Will Deacon , Ying-Chun Liu , Bin Meng Subject: [PATCH 5/6] virtio: Allocate bounce buffers for devices with VIRTIO_F_IOMMU_PLATFORM Date: Wed, 29 Mar 2023 22:24:59 +0800 Message-Id: <20230329142500.682922-6-paul.liu@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329142500.682922-1-paul.liu@linaro.org> References: <20230329142500.682922-1-paul.liu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Will Deacon In preparation for bouncing virtio data for devices advertising the VIRTIO_F_IOMMU_PLATFORM feature, allocate an array of bounce buffer structures in the vring, one per descriptor. Signed-off-by: Will Deacon [ Paul: pick from the Android tree. Rebase to the upstream ] Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Bin Meng Link: https://android.googlesource.com/platform/external/u-boot/+/3e052749e7c50c4c1a6014e645ae3b9be3710c07 Reviewed-by: Simon Glass --- drivers/virtio/virtio_ring.c | 25 ++++++++++++++++++++----- include/virtio_ring.h | 5 ++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 1bd19add75..de75786ca7 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -6,6 +6,7 @@ * virtio ring implementation */ +#include #include #include #include @@ -292,6 +293,7 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num, struct udevice *vdev = uc_priv->vdev; struct virtqueue *vq; void *queue = NULL; + struct bounce_buffer *bbs = NULL; struct vring vring; /* We assume num is a power of 2 */ @@ -320,17 +322,29 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num, return NULL; memset(queue, 0, vring_size(num, vring_align)); - vring_init(&vring, num, queue, vring_align); - vq = __vring_new_virtqueue(index, vring, udev); - if (!vq) { - virtio_free_pages(vdev, queue, DIV_ROUND_UP(vring.size, PAGE_SIZE)); - return NULL; + if (virtio_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) { + bbs = calloc(num, sizeof(*bbs)); + if (!bbs) + goto err_free_queue; } + + vring_init(&vring, num, queue, vring_align, bbs); + + vq = __vring_new_virtqueue(index, vring, udev); + if (!vq) + goto err_free_bbs; + debug("(%s): created vring @ %p for vq @ %p with num %u\n", udev->name, queue, vq, num); return vq; + +err_free_bbs: + free(bbs); +err_free_queue: + virtio_free_pages(vdev, queue, DIV_ROUND_UP(vring.size, PAGE_SIZE)); + return NULL; } void vring_del_virtqueue(struct virtqueue *vq) @@ -339,6 +353,7 @@ void vring_del_virtqueue(struct virtqueue *vq) DIV_ROUND_UP(vq->vring.size, PAGE_SIZE)); free(vq->vring_desc_shadow); list_del(&vq->list); + free(vq->vring.bouncebufs); free(vq); } diff --git a/include/virtio_ring.h b/include/virtio_ring.h index 8f8a55c7bd..e8e91044a2 100644 --- a/include/virtio_ring.h +++ b/include/virtio_ring.h @@ -87,6 +87,7 @@ struct vring_used { struct vring { unsigned int num; size_t size; + struct bounce_buffer *bouncebufs; struct vring_desc *desc; struct vring_avail *avail; struct vring_used *used; @@ -146,10 +147,12 @@ static inline unsigned int vring_size(unsigned int num, unsigned long align) } static inline void vring_init(struct vring *vr, unsigned int num, void *p, - unsigned long align) + unsigned long align, + struct bounce_buffer *bouncebufs) { vr->num = num; vr->size = vring_size(num, align); + vr->bouncebufs = bouncebufs; vr->desc = p; vr->avail = p + num * sizeof(struct vring_desc); vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] +