From patchwork Wed Mar 29 14:24:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Liu X-Patchwork-Id: 668114 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp393952wrt; Wed, 29 Mar 2023 07:25:47 -0700 (PDT) X-Google-Smtp-Source: AKy350ZFe+WxhzV7qk0RJVN+QvHHNRw4YQQSICRJct17nmKntBvEk+SV0hGjneAQ6l7xgM2L7MCF X-Received: by 2002:a17:902:e88a:b0:1a1:db10:7ba5 with SMTP id w10-20020a170902e88a00b001a1db107ba5mr22246708plg.41.1680099947492; Wed, 29 Mar 2023 07:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099947; cv=none; d=google.com; s=arc-20160816; b=AbQXl1RcL7woI8+51Osyy3TQ+1GzF5zwj+cGX/5qIhKaOd6ZnWzzwF1K16pGXYeW4W 6Zhu5stczQMYhyKjhZ4Ap7vLXdpY5SoJUNWKH9cx87A8L538H3Vm4/iJdSvx6IzNTtBQ YqvB7/St7CLj1B33UWoT8bSA5mf3QtZswI63QDiB4TiSCD79D/JqjYGtfAv5j09exvwL +VMemCQkckcYa1Hlpy+IoIic/NpTPX0kaUtKFyV/F7KxwT6MJ+K+pv3jvXBjsSH9rL9B 7SmlXb8JooRxU8gW9857/2HHMF15mNL72GntiPp7WCbsfb7VKbVKFiSiLxZXGAgjb4tb Qmyw== 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=vVWfuFTi6CGOvULV2NyogvxEpPwylC83/+tW9ePSOKM=; b=dSs2vHMLsDIdkHKlti9ngEEdWRstvlsFUGNeSKTagxbDhzvA+HA0mH21rR9MxVaakB WSYjPIW24m/mA6ngtFUuKKGEZl5dl03qyk4uhrtZI+er9/dIZtWntXpiYeU2rwEv6CSB 1NHtweUq7yzAJ8Fp8OJFQYWaVxwF6Fu17WDtmG3mSPHyuj8j7CT/Ed62M1LgxWpITdPZ IZT9JgeyA1Ro5yUYBKRtSY6vIzKsiiMvDGk7omRVWAXDJDFo8lWaD3Hg3xIcYcIC2TKr qvklsiI3z0RDLzGv2ta3rPGTnP+1BYpCSsZtAWLJvkk6kU508tX/ADZiGoEFnHZJ8opT 4c/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gaezu2se; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id z36-20020a630a64000000b0050bf56c35c3si31107723pgk.81.2023.03.29.07.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:25:47 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gaezu2se; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 77FB085D74; Wed, 29 Mar 2023 16:25:42 +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="gaezu2se"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A379B85D4E; Wed, 29 Mar 2023 16:25:12 +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-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (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 0A64E85D34 for ; Wed, 29 Mar 2023 16:25:09 +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-x1032.google.com with SMTP id l9-20020a17090a3f0900b0023d32684e7fso3898345pjc.1 for ; Wed, 29 Mar 2023 07:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680099907; 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=vVWfuFTi6CGOvULV2NyogvxEpPwylC83/+tW9ePSOKM=; b=gaezu2se2oFAVMqBfHlm3vzE6YUrLa/gPb+M8+OjR0qCW9K0Fdmis9UAzPc8F83pRN l6DN2BWU485/KUG7uk1OUqyi2QrqtVgBDCZhnYVYjZD9fHgpTh9WPcF2j+BW3AgFAn3S GNnR1koqA5HIhzxkkAlRzZpv/WuSCcpJw+7kcikz9MzKjjFjtIiL8zScrqBsCBAu8+fg RLoAn+PRx3gmWlXQdXI5jx22FCNyVySQOOcKvmEAgUROTFVvIaMlqxB48BB0odAvgFMF wI7t7g1PW/kPomeRvzchX/2VcJRwBaK9JQXKRycOxqQYoIWhGJp97TWqLrOSoTeUHEPX urCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680099907; 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=vVWfuFTi6CGOvULV2NyogvxEpPwylC83/+tW9ePSOKM=; b=Ygx3A897ffpO2Pjx533u53IG/6IWgkvew9L+s+LzUCtr5bGYgXR0pshh11jRl4X6pz UDo1GuG4cVCBgeWaxdohAC62/Sp/tiKhSC0YCW9NmavICvHUe0f05RC5soIdsrCwwN4b IhgY2ELsJ4Tjy2maKpyLdbMRwPc0dYi0DWhTYbjV8viBXIIQsyrvHl7DKQzB45aBAu3A Vne9OSVG7mEEnKJqA3lSkA+OH2b9LsmcCCafQMbwgDOPj9w32fBWWjnodzEgvwdj/lMJ 1L349qAnFjZiweTR1rk7GA0pU/xRcvN5s2tTzd0tvjvV+4wzfh0EYBAVDHL0yJpMeEor Obeg== X-Gm-Message-State: AAQBX9fp8uLZwkpe0nweojm+GTcMk1xIu3iajsmGmKVIL8GEluS5Gv1D Vxdg8nslDT6VM9cmud3hjpP5vVH6CpX5H3DTDfE= X-Received: by 2002:a05:6a20:7883:b0:df:81de:93dd with SMTP id d3-20020a056a20788300b000df81de93ddmr11816810pzg.44.1680099907187; Wed, 29 Mar 2023 07:25:07 -0700 (PDT) Received: from localhost ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id d17-20020aa78e51000000b00627fea66a4asm18353637pfr.39.2023.03.29.07.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:25:06 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: Will Deacon , Ying-Chun Liu , Bin Meng Subject: [PATCH 1/6] virtio: Expose VIRTIO_F_IOMMU_PLATFORM in device features Date: Wed, 29 Mar 2023 22:24:55 +0800 Message-Id: <20230329142500.682922-2-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 If we detect the VIRTIO_F_IOMMU_PLATFORM transport feature for a device, then expose it in the device features. 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/+/9693bd26bfcfe77d6a1295a561420e08c5daf019 Reviewed-by: Simon Glass --- drivers/virtio/virtio-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c index de9bc90359..b3fb3dbfad 100644 --- a/drivers/virtio/virtio-uclass.c +++ b/drivers/virtio/virtio-uclass.c @@ -336,7 +336,7 @@ static int virtio_uclass_child_pre_probe(struct udevice *vdev) /* Transport features always preserved to pass to finalize_features */ for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) if ((device_features & (1ULL << i)) && - (i == VIRTIO_F_VERSION_1)) + (i == VIRTIO_F_VERSION_1 || i == VIRTIO_F_IOMMU_PLATFORM)) __virtio_set_bit(vdev->parent, i); debug("(%s) final negotiated features supported %016llx\n", From patchwork Wed Mar 29 14:24:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Liu X-Patchwork-Id: 668117 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp394331wrt; Wed, 29 Mar 2023 07:26:33 -0700 (PDT) X-Google-Smtp-Source: AK7set97E9Uc6CZ9a96UfT8GHExNAFHRObRrXdaWJsXouLDkfUMAD44crHBYIVmq+/cdLIe2Xupq X-Received: by 2002:a05:6a20:29b:b0:d9:e6a9:d3e2 with SMTP id 27-20020a056a20029b00b000d9e6a9d3e2mr18217449pza.3.1680099993562; Wed, 29 Mar 2023 07:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099993; cv=none; d=google.com; s=arc-20160816; b=lWuizSjzkNWTaj1hCjzLugg+owgIyetnt1S4hlojEeCPe61/avq5Q3BOgmMXF/+6H7 Qqfi1sj/DnKiv0n0TNTIOxyUIVyT5vJ4NV68UICMM9VtIMJHK4W8TBBC4Km3z3bIMtkn ducG9Wj/eo3f/P+iyJOkyH04eMkHAfFVgp3WQIEo6R1N/WHk0X/YW573p8MN5wes7Lp2 FlIJz6+rjnR3ODXRmCsDI2e7M2qFdILDkPCXXyqfbCXMvilkjOrJGuxtyJpcCEsqITOv L0iZ/TLsrv39qJIZmZ8J4vQ4LGf5mduQzb/goendGWLZVzz6Oa5XkVfNae+CwQKNt1Va fOWg== 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=qZKRTe43fTUAf6jNqgVqthTcj5zQAj6pnK6PTXqrmTM=; b=c1UkTfQUG71l6xWAyeq58AEXz+fJKD9Lan+xqoQPIvPo9u185cSIc+/qTyAFeP7ITd SrDlB17wxo1GMU6F5T97jrb+fnJxg6Hrv0Y3UWvud54qA3CurA10P935szS3lhCCzYW0 0Cz7GEoNjAla0MxH2aJBrvG41dhrwUc2hPsydaOmOiJl68KrBGE0yHAXLV1V9sIlPt8a EplyNLaYTLIUzw6Iym3dNqiWHiQVNrNsXgtmrmcBMGDYs4VB4qr0PTvUtB0AvdMK2eqz 4hTiSCk9vLE5BVJQpzKfePIBiCdWawsKv54+phGGxuh5ije78pid0e0KNXSL8MKYmUQA x4tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Clzgspvu; 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 q1-20020a056a00084100b006257c287ddcsi32881969pfk.45.2023.03.29.07.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:26:33 -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=Clzgspvu; 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 B471E85E45; Wed, 29 Mar 2023 16:26:02 +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="Clzgspvu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A994285D74; Wed, 29 Mar 2023 16:25:24 +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-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) (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 B998E85858 for ; Wed, 29 Mar 2023 16:25:11 +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-x102c.google.com with SMTP id q102so14195760pjq.3 for ; Wed, 29 Mar 2023 07:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680099910; 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=qZKRTe43fTUAf6jNqgVqthTcj5zQAj6pnK6PTXqrmTM=; b=Clzgspvu2FzckY5ssnenYFHh/4q2xT/kquwCSwbi7fkUWoZXjKccgtBI6eLo7TUlek ZWG7Frct4uGicDcjpmNW71J2mmj33fhwdykh07kSK8ZohC9KRl+EM4DkDjNjpKcWZ1Jy K1m7BvCarBwZPHD//G3QMdZ+kKyCfCQjEQH9kenzgQezWrEWF3iMSIyQ9rxtefdaK/7a QHGcTAOSEYdH4IMZR18Dqh4WbsqVTM7fHCh7Mo2NEpysftGiKqFwrhOPnT11YZKF5Frr W2ArOn0Kdjvs9Be7ZM2hnBC1WV607gTE8XEJpfRx2OLahnvMtUoYxt8smGjdogPNmMqF obtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680099910; 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=qZKRTe43fTUAf6jNqgVqthTcj5zQAj6pnK6PTXqrmTM=; b=T/sppBiMpr6y0AdrGSsa1ECTzWzU7vq0L29A6W1azP4yeSzYwKOWI3sjYz6BakMIoE PtmqWubcxqvhMMrwaOTQDxm9qMDYZkE3Vda6/1aVmpXNEhYZvO+rol14zzoIL45ykORE ULxXarInpwDOQQH2CNfUYiOf2pGaAo3tyKGRWWfPJU88n7M43oF0MPBIsXVfL6q57khI Xx4eutGVTnPnQ07udGxxCN7WvRGNxkSkdpZba6e9zv/Gt5tKJZbHVWgaNiMNj9doRvS0 WB4R6GVjrh8Psk6OCj68whXbQSrphoay76vUYXzsJjfCYW7RxPQDBCAqmd6reT0j+67q 0UAQ== X-Gm-Message-State: AAQBX9ecIfHZDfnijYSfLHAvfaUhRPYrds8WuacnSy2KmWGMmMj+FAQN 43l81AmdBl96BE18lzLfRtrlbBkE5ReP0JLj9s8= X-Received: by 2002:a17:90b:3b8a:b0:23f:9be4:9bb7 with SMTP id pc10-20020a17090b3b8a00b0023f9be49bb7mr21600333pjb.9.1680099909801; Wed, 29 Mar 2023 07:25:09 -0700 (PDT) Received: from localhost ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id ge18-20020a17090b0e1200b00234e6d2de3dsm1503744pjb.11.2023.03.29.07.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:25:09 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: Will Deacon , Ying-Chun Liu , Bin Meng Subject: [PATCH 2/6] virtio: pci: Tear down VQs in virtio_pci_reset() Date: Wed, 29 Mar 2023 22:24:56 +0800 Message-Id: <20230329142500.682922-3-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 The pages backing the virtqueues for virtio PCI devices are not freed on reset, despite the virtqueue structure being freed as part of the driver '->priv_auto' destruction at ->remove() time. Call virtio_pci_del_vqs() from virtio_pci_reset() to free the virtqueue pages before freeing the virtqueue structure itself. 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/+/5ed54ccd83cbffd0d8719ce650604b4e44b5b0d8 Reviewed-by: Simon Glass --- drivers/virtio/virtio_pci_modern.c | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c index cfde4007f5..3cdc2d2d6f 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -218,25 +218,6 @@ static int virtio_pci_set_status(struct udevice *udev, u8 status) return 0; } -static int virtio_pci_reset(struct udevice *udev) -{ - struct virtio_pci_priv *priv = dev_get_priv(udev); - - /* 0 status means a reset */ - iowrite8(0, &priv->common->device_status); - - /* - * After writing 0 to device_status, the driver MUST wait for a read - * of device_status to return 0 before reinitializing the device. - * This will flush out the status write, and flush in device writes, - * including MSI-X interrupts, if any. - */ - while (ioread8(&priv->common->device_status)) - udelay(1000); - - return 0; -} - static int virtio_pci_get_features(struct udevice *udev, u64 *features) { struct virtio_pci_priv *priv = dev_get_priv(udev); @@ -363,6 +344,25 @@ static int virtio_pci_find_vqs(struct udevice *udev, unsigned int nvqs, return 0; } +static int virtio_pci_reset(struct udevice *udev) +{ + struct virtio_pci_priv *priv = dev_get_priv(udev); + + /* 0 status means a reset */ + iowrite8(0, &priv->common->device_status); + + /* + * After writing 0 to device_status, the driver MUST wait for a read + * of device_status to return 0 before reinitializing the device. + * This will flush out the status write, and flush in device writes, + * including MSI-X interrupts, if any. + */ + while (ioread8(&priv->common->device_status)) + udelay(1000); + + return virtio_pci_del_vqs(udev); +} + static int virtio_pci_notify(struct udevice *udev, struct virtqueue *vq) { struct virtio_pci_priv *priv = dev_get_priv(udev); From patchwork Wed Mar 29 14:24:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Liu X-Patchwork-Id: 668115 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp394069wrt; Wed, 29 Mar 2023 07:26:01 -0700 (PDT) X-Google-Smtp-Source: AKy350Y5E1hMoEfY+erBbtO4ymm0ZCDJ4h1otTxl4wzBmYbWLkPAToydZSmCLxhfWK4hk2k/g9BX X-Received: by 2002:aa7:968b:0:b0:627:e61e:1ae with SMTP id f11-20020aa7968b000000b00627e61e01aemr18223986pfk.12.1680099961586; Wed, 29 Mar 2023 07:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099961; cv=none; d=google.com; s=arc-20160816; b=YLzZoRIvIB2itlOA69FqczORo05HU45Hhz5j8hTIkJ9VB6Eg22DDwRG1olOD8mFS+r 0z4/8uUnLZCz3G4cfQkVAd3w/gVYBpzJew1cau9IqPMAjJ6bLePFIHlolQMX3yjXyRJi /kQndHNiBw2MROPRc7O38oYGXFFRep+pltu9zQYlM1Csi3wmN/roUSS+KVTD8AwenR9y Bwygd4b81nZ6SJ5p1DXqduRB+GiAAHJ2Ef5ULh2D+VrSyRmM9dQ6FwUmo1OrHZ+toDLd sj/onquO437rC1z0FfNbZG3nFeqd+BJi4zCqL58cV5JTQs+3H2vTyrm72r5eUs6RKkVf DEYQ== 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=lshIgirxJIJIK51W/n1rok2n86MeghDPYgGiKNUxpYA=; b=ZqzTc+DHJSstEfC7u7Cwdv/fwaXggH8Fdk39Q4BGhHcIEUeddi8FJFz6aiuxkGNjCy Am++jejA2+P3bh8mtYjIRfdNXUOK360oCQrNjBcWFq05zgg98N/fKd/8Dk3cTGiiHK6E XfRsXjbDb8shfj9QtvtP7/RJe540Y4J6ctb5ov8sZJYmXtJE8hKFxasb0ajfmV15cdet WJ2tk+QwZ8bKzyF6ApRzNe6zXQjK0XMHnzA2dc4dpwR5qQNHvGlkRDD1/MYeIc2kfleL xDzVr9/4TKQX1m/IsM+wx9hR//SMObhPP1nmgwC0Oh+E0MDSzS9RQCmTxBGFMPB5RBne cVGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="aXQ/kWlT"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id f26-20020aa7969a000000b0062dbc05a323si299974pfk.298.2023.03.29.07.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:26:01 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="aXQ/kWlT"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 C88ED85DDB; Wed, 29 Mar 2023 16:25:49 +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="aXQ/kWlT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8138185CB4; Wed, 29 Mar 2023 16:25:26 +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-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 5215985D34 for ; Wed, 29 Mar 2023 16:25:13 +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-pl1-x62b.google.com with SMTP id z19so15103778plo.2 for ; Wed, 29 Mar 2023 07:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680099911; 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=lshIgirxJIJIK51W/n1rok2n86MeghDPYgGiKNUxpYA=; b=aXQ/kWlTKRtG8bkczLrLmFWp753PX9aMVc6gvcLlCFHZq1500MyOYA6H5IN3XSUZFD PhWxYEptfYhXfefWF2p025MmD3F0Y71v5SfwNQ3fJsvKIVdVl5RDIScZndWs0DStqkEy wh2CpP9UjGqJWC/GmFOIGG0f7J6ur+4h9Lqep9Qw7GINhDpFH0P/NScj0jsSiP/PH+u+ MqRtiAg4mil06bObxMCzpunwvB+DpKIDhEEDavsIv7pAV7SLS4+JHMG3uxf/Asb0murU G2uG246FIX22m9nmO88rlgR+riAadAQOvNshGhX202XAFIol5ko/tgEgvnJ8tXvZCAKJ A7cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680099911; 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=lshIgirxJIJIK51W/n1rok2n86MeghDPYgGiKNUxpYA=; b=zAYGrQOpG59YYNef1fSC1VMP2hB7kD8dwfgvAcUBfe522hnM8ARzsIhQEEyafdsWEO r5dRMbQ4cKa74vQu/LZqx012SgJ6Bzw7Nv2lbE7QuhW6/ruPv1oi3fDLm6iqi2i0YKW5 G2/j+StBg1Zsb4+xRmwfSw6D8oDOQqqe+YVzQ3MWIVlX4WPm4cGRs/jOtnj06hRJCOzl hvbzy9vLu/BulRP5S2VHTW4SbzIyNBwPJEMqnhozqqxojL1tB/zvblIL/OZR9RAaHZLm iDP4g58z0Fk3dOvlanozeaw3Ywt4GBO+ii5/cyIqidFdkL3tFeHAtk+kJisHXbX7wTYX jdIg== X-Gm-Message-State: AAQBX9fFMb+/gKGTaUYlsqngp5aZSfoQRawV4BMKLlcqexcjg32s5OYu MZzwAZl2fuko8BLLFZZzic9IBZ0DTcc8miui3uM= X-Received: by 2002:a17:90b:4f86:b0:237:9fbd:31c8 with SMTP id qe6-20020a17090b4f8600b002379fbd31c8mr20994574pjb.15.1680099911380; Wed, 29 Mar 2023 07:25:11 -0700 (PDT) Received: from localhost ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id e12-20020a17090ab38c00b0023d16f05dd8sm1481294pjr.36.2023.03.29.07.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:25:11 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: Will Deacon , Ying-Chun Liu , Bin Meng Subject: [PATCH 3/6] virtio: Allocate virtqueue in page-size units Date: Wed, 29 Mar 2023 22:24:57 +0800 Message-Id: <20230329142500.682922-4-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 explicit bouncing of virtqueue pages for devices advertising the VIRTIO_F_IOMMU_PLATFORM feature, introduce a couple of wrappers around virtqueue allocation and freeing operations, ensuring that buffers are handled in terms of page-size units. 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/+/b4bb5227d4cf4fdfcd8b4e1ff2692d3a54d1482a Reviewed-by: Simon Glass --- drivers/virtio/virtio_ring.c | 24 ++++++++++++++++++++---- include/virtio_ring.h | 16 +++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index f71bab7847..5aeb13fd59 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -15,6 +15,17 @@ #include #include #include +#include + +static void *virtio_alloc_pages(struct udevice *vdev, u32 npages) +{ + return memalign(PAGE_SIZE, npages * PAGE_SIZE); +} + +static void virtio_free_pages(struct udevice *vdev, void *ptr, u32 npages) +{ + free(ptr); +} static unsigned int virtqueue_attach_desc(struct virtqueue *vq, unsigned int i, struct virtio_sg *sg, u16 flags) @@ -271,6 +282,8 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num, unsigned int vring_align, struct udevice *udev) { + struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev); + struct udevice *vdev = uc_priv->vdev; struct virtqueue *vq; void *queue = NULL; struct vring vring; @@ -283,7 +296,9 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num, /* TODO: allocate each queue chunk individually */ for (; num && vring_size(num, vring_align) > PAGE_SIZE; num /= 2) { - queue = memalign(PAGE_SIZE, vring_size(num, vring_align)); + size_t sz = vring_size(num, vring_align); + + queue = virtio_alloc_pages(vdev, DIV_ROUND_UP(sz, PAGE_SIZE)); if (queue) break; } @@ -293,7 +308,7 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num, if (!queue) { /* Try to get a single page. You are my only hope! */ - queue = memalign(PAGE_SIZE, vring_size(num, vring_align)); + queue = virtio_alloc_pages(vdev, 1); } if (!queue) return NULL; @@ -303,7 +318,7 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num, vq = __vring_new_virtqueue(index, vring, udev); if (!vq) { - free(queue); + virtio_free_pages(vdev, queue, DIV_ROUND_UP(vring.size, PAGE_SIZE)); return NULL; } debug("(%s): created vring @ %p for vq @ %p with num %u\n", udev->name, @@ -314,7 +329,8 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num, void vring_del_virtqueue(struct virtqueue *vq) { - free(vq->vring.desc); + virtio_free_pages(vq->vdev, vq->vring.desc, + DIV_ROUND_UP(vq->vring.size, PAGE_SIZE)); free(vq->vring_desc_shadow); list_del(&vq->list); free(vq); diff --git a/include/virtio_ring.h b/include/virtio_ring.h index c77c212cff..8f8a55c7bd 100644 --- a/include/virtio_ring.h +++ b/include/virtio_ring.h @@ -86,6 +86,7 @@ struct vring_used { struct vring { unsigned int num; + size_t size; struct vring_desc *desc; struct vring_avail *avail; struct vring_used *used; @@ -137,23 +138,24 @@ struct virtqueue { #define vring_used_event(vr) ((vr)->avail->ring[(vr)->num]) #define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num]) +static inline unsigned int vring_size(unsigned int num, unsigned long align) +{ + return ((sizeof(struct vring_desc) * num + + sizeof(__virtio16) * (3 + num) + align - 1) & ~(align - 1)) + + sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num; +} + static inline void vring_init(struct vring *vr, unsigned int num, void *p, unsigned long align) { vr->num = num; + vr->size = vring_size(num, align); vr->desc = p; vr->avail = p + num * sizeof(struct vring_desc); vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16) + align - 1) & ~(align - 1)); } -static inline unsigned int vring_size(unsigned int num, unsigned long align) -{ - return ((sizeof(struct vring_desc) * num + - sizeof(__virtio16) * (3 + num) + align - 1) & ~(align - 1)) + - sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num; -} - /* * The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX. * Assuming a given event_idx value from the other side, if we have just From patchwork Wed Mar 29 14:24:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Liu X-Patchwork-Id: 668116 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp394223wrt; Wed, 29 Mar 2023 07:26:19 -0700 (PDT) X-Google-Smtp-Source: AKy350b6v67IJyP4atHzuUUcT2SttVv0FExX5ndxwA9j/3B9NmB7Xh2uuyg0EOrJY+yg1fmFmHr1 X-Received: by 2002:a17:903:32d2:b0:19e:68b1:65b9 with SMTP id i18-20020a17090332d200b0019e68b165b9mr24856162plr.12.1680099979639; Wed, 29 Mar 2023 07:26:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680099979; cv=none; d=google.com; s=arc-20160816; b=tdC7F3n/LE8sNjvToBJGYtCqx8JUXJ3vGwswHPjUq9cV2t0MBr70NkgS1H+ThHtb/b j9JO2rXK/i58G5C4xPU6iWLPw0vACXGaYDHXexZekZa2FYnJp9baPYmGcQsTm5ri6+VH aeKJXY7lJ8jx5nZmppoT9njc2AWocXgKYMb/OTYY3ljhixdeulOeJziUyHNrf0sswlgj d0ssGpfrcpIFFCPlp59DJo2x4u4wffcA7e4iDm4+h6TVDE3Mw0vuFSBb8r3F3L+jVH50 mdtaZaD0tlwoQgtvT9TfbrrZJtOkAq6gD3EIWQHPGf0/dRlCPnU2rwf0lKxqZjY19wwH 8K2Q== 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=LpDtt87OxGD+muZENoIEPV8oFk/2pLQeuGUBm3CU2UM=; b=oOJNJK0WxZ+WO/8RVWtiOXIVszDd0nTZMieF5z6TJ6Ox1w5SE2pWQbUXn42HS3rO+X akg8eJMeiJ9x5vRFfkBmfKlSR3punQ371FxlNtjbkMCc9BWG/Q/DjGoP7Q3yNEvAY6hT sB2e0m3QreTOeXExKHv5amYruG6ks+36NnCXrPebEbAYuKQKQemowDbya1ekhqUwf59J ALH3m0h33eH25E7lrgYoGCGWIpiO0LJTQkS7YLSlS4KONBEp1B1AaboiePKa4vROlWX8 QJ/SIdHpAU5fUUgHeq9jdLCcDis1aAePPtuKfZSoc1C203wBbSYVBa2PRXTndj0BmmCn +aKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IKRh8YEQ; 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 e12-20020a17090301cc00b001a221acb462si11686532plh.73.2023.03.29.07.26.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:26:19 -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=IKRh8YEQ; 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 4201086027; Wed, 29 Mar 2023 16:25:57 +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="IKRh8YEQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3647485858; Wed, 29 Mar 2023 16:25:25 +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-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 3BBF585D4E for ; Wed, 29 Mar 2023 16:25:15 +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-pl1-x629.google.com with SMTP id u10so15074813plz.7 for ; Wed, 29 Mar 2023 07:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680099913; 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=LpDtt87OxGD+muZENoIEPV8oFk/2pLQeuGUBm3CU2UM=; b=IKRh8YEQ77Q2szFi8TIHUbaQWSRXptcwxxuZ6lOaXrfOLfHmBJtgBkIXcLfHHGNkLv XKwR7AxzwOCxk/4MkyZY6ZDZiqOaVfi9dWWpBAuZTbrg0XPnVxMt1CjiEs3/zq4JU7n4 xMlrO6m7QwdKAV3tvTcaefDc/+PMxxRMD9AqF46+gC0VRRYTloUeVe+QvBCcWgd9Eeru A26LmCtMOyaFstFKLuDUPfu/IaMlcuugOxAChvPN8QhvswmyAp8GKyEInoiLkYCHS8zW 7mHkHcNqDr1MUEE4/T6y6Vs3bx+cwANl251GE4mAiH01qjdpJX/jVUpTxqYQzOKnbcwz VInA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680099913; 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=LpDtt87OxGD+muZENoIEPV8oFk/2pLQeuGUBm3CU2UM=; b=paVpq0lqSFgYRvTuzl5INHlVCVglHgNuwHgbCZ27Rs8RoA42iVd1ApXtESUwxiqVdv loR6FWNn04KS7iLg/L1rnJDBstia2PIZ9qSAKUqiTweqrELnYke6E1iBE1dqoBVe2N5M 7W2xafF69YXRSB+SUl+ALrMj+dmw7dblzwdH7qPz5z0vzHLPy1zOj9RHrvoN/YtRmYs2 0pb+a1EdkHCJfwqAFURVUwFX5vGEp3LdrHQkw9qW63PyJcEfECv9GdELN9YTidJhtMSb C+WOCY9abotbZC2J8aF2T5i1oHto2v2w2VJMyzUn1k1V7FZ67jbZ2hCmjabuYh3tants 4dvA== X-Gm-Message-State: AAQBX9cgHiZNR24a+TzctOpaYPp98rRRBK5w2blLtQ6ObR3aFGC1kRtr dSlSmsePoIOMnOn3NGMMu90WwECAwqwgdKeUbl4= X-Received: by 2002:a17:90b:4f8c:b0:23f:ef7:7897 with SMTP id qe12-20020a17090b4f8c00b0023f0ef77897mr20055566pjb.49.1680099912993; Wed, 29 Mar 2023 07:25:12 -0700 (PDT) Received: from localhost ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id z12-20020a17090a1fcc00b0023b15e61f07sm1505239pjz.12.2023.03.29.07.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:25:12 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: Will Deacon , Ying-Chun Liu , Bin Meng Subject: [PATCH 4/6] virtio: Add helper functions to attach/detach vring descriptors Date: Wed, 29 Mar 2023 22:24:58 +0800 Message-Id: <20230329142500.682922-5-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 Move the attach and detach logic for manipulating vring descriptors out into their own functions so that we can later extend these to bounce the data for devices with VIRTIO_F_IOMMU_PLATFORM set. 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/+/f73258a4bfe968c5f935db45f2ec5cc0104ee796 Reviewed-by: Simon Glass --- drivers/virtio/virtio_ring.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 5aeb13fd59..1bd19add75 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -47,6 +47,10 @@ static unsigned int virtqueue_attach_desc(struct virtqueue *vq, unsigned int i, return desc_shadow->next; } +static void virtqueue_detach_desc(struct virtqueue *vq, unsigned int idx) +{ +} + int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[], unsigned int out_sgs, unsigned int in_sgs) { @@ -165,10 +169,12 @@ static void detach_buf(struct virtqueue *vq, unsigned int head) i = head; while (vq->vring_desc_shadow[i].flags & VRING_DESC_F_NEXT) { + virtqueue_detach_desc(vq, i); i = vq->vring_desc_shadow[i].next; vq->num_free++; } + virtqueue_detach_desc(vq, i); vq->vring_desc_shadow[i].next = vq->free_head; vq->free_head = head; 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] + From patchwork Wed Mar 29 14:25:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Liu X-Patchwork-Id: 668118 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp394612wrt; Wed, 29 Mar 2023 07:27:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YJsr79rCPySrP7X9V3kSQAvYWpMf/hhqdAyX/5aNVem+5Y1BDpf5hdys0WlWH2Q/x8IDwl X-Received: by 2002:a17:90b:3851:b0:23d:4e9d:2eb0 with SMTP id nl17-20020a17090b385100b0023d4e9d2eb0mr21044372pjb.36.1680100024819; Wed, 29 Mar 2023 07:27:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680100024; cv=none; d=google.com; s=arc-20160816; b=Pcy1khbsk2NP42/pZeG0iP0bjsXpR54gMZ5cBUOM20Jm5fT5AbonRJwIm0Wbu8dQuX /Zg92LB3FIYWG1IFkhpR2QUm2OfXnJHLeGw/xFkZOOEi2lu/uC0PCwr3pouwuai9x+Zf rDCs8u7dJbVKtA0JSDaeZL0afUMZEQf1muC/fTL7zS7faXogyIw+KWmnl4uiMcDycPRX lKK8SGP1SQY18Rr/rwAFtAUj6bIFWCS6EWaRaJznHSaTOcv0wj8cfJwjkj9eLDscGa78 RomqciHsmT6CQOmyiloycUTdZpaVIj4NF9KVcYj8WFaaPZ5N3PCNppZFkIlCp6c+ikrC GX2A== 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=SrYDOGu77eGaRtbf1G+Dcj+IX0mHeAKzIJwgu0r4OJU=; b=F4ZzlLni/yOHN1SaZpO/DMo5i51S96HVbhWSTZQcx3cfyUWPCLy/t8gDyv9wHjf9/P 2HtuogA9wFQXXMwiGesZgvubj+Ir2xYfGHQNjfrVzGHMxvkEDrGjtFsJeiSU58rRQe3B w3YS3scTwW17D7SncA3eAzfJo8bQL8eYw/fXIYkWT4KJXi11qBgEfxiX43f5GbnhEUQ1 GnhVR6smLk9WMwQuDoNHbnDT5bU+mOKrHpXoG1M/JQcb0+Ks9YDg51MhJxv3hGUl6z8F FAexDICVqWBCetO/QWTrJ+AuAnQytkWJJyAvlupTl9suT3arB49r1y5MhNfOOh07J+Kt GHTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VffcFn5r; 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 o35-20020a635a23000000b00513234112b9si424606pgb.901.2023.03.29.07.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:27:04 -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=VffcFn5r; 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 565EC85DDB; Wed, 29 Mar 2023 16:26:59 +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="VffcFn5r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C490985D4E; Wed, 29 Mar 2023 16:25:34 +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-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) (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 0BB2985DDB for ; Wed, 29 Mar 2023 16:25:19 +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-x1036.google.com with SMTP id gp15-20020a17090adf0f00b0023d1bbd9f9eso18770108pjb.0 for ; Wed, 29 Mar 2023 07:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680099916; 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=SrYDOGu77eGaRtbf1G+Dcj+IX0mHeAKzIJwgu0r4OJU=; b=VffcFn5r+HgO1ke/zmM6mALDrEwf6NGmXhksXpPW9hU0p+lIrDbZnMkEW8lUnihJR5 BVhpwoxN5pJMx7m0njoDnLXn8m9o/yVXZBrL62UoFaEiudjxGiuqYrnIHjDVP8h/jWM+ FtNdmHIBfbDVbD4JBZ1hew+EauvbgTJSDUy9cJZwyYpOaH8whZrkITlobgjByjXkYFgz 2eBi42b430rrFeywmh0lRHYCAz1QVXqd6syKSBOluc8eERnV+MhCGNIjUJwUBKfewMvN abM3mcRLYYvctriIvvEDoW3e9NJbqVE7zMabD4naCHSvDHtYMKH0yCx9Aft5hUl3gtVA fsuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680099916; 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=SrYDOGu77eGaRtbf1G+Dcj+IX0mHeAKzIJwgu0r4OJU=; b=VPefzB1omP3xyQ0I53aAGDpeJiQYfgwKfOXHFBrmj+jrswpbfXPU/rCxssCTY42yCB YyRiLfBQo2RRT4xoTUq9hpdBaJjSRKRXUiLty0/wHIEjU6WWjVc2u28JOzowU2Qvw3/H 9LXclB3bt/V1ZO3HkqrdhzwjIhj9U3nKEzGIqJKP1EY8VopV2o5TFIsqM7UC6lNwvFtn 5U21MqP0w1jGX+BJF5eCNPt5e4iT67RQgUiS4qpSmesdqoF9QiHeUNkLpZ/TqmbwnIsD di9HWQLVB7/LJkB7pH/qfEDT+1Zzwx6i+3q8NSip3bf/76vVhW8j3zuhB5ZKslE+phma g+DQ== X-Gm-Message-State: AAQBX9eBxyHeOzCup5J7Pbt42ZWzw0snyslmuxGmXphi5Day4BadS/4p bfAsYY5Sa3kisVd10x2IsfK3B2ckXI20/7GhjVk= X-Received: by 2002:a17:90b:4d92:b0:23d:3c7b:8684 with SMTP id oj18-20020a17090b4d9200b0023d3c7b8684mr21414390pjb.41.1680099916518; Wed, 29 Mar 2023 07:25:16 -0700 (PDT) Received: from localhost ([111.184.129.17]) by smtp.gmail.com with ESMTPSA id x5-20020a1709028ec500b001a04d37a4acsm23119432plo.9.2023.03.29.07.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 07:25:16 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: Will Deacon , Ying-Chun Liu , Bin Meng Subject: [PATCH 6/6] virtio: Use bounce buffers when VIRTIO_F_IOMMU_PLATFORM is set Date: Wed, 29 Mar 2023 22:25:00 +0800 Message-Id: <20230329142500.682922-7-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 Devices advertising the VIRTIO_F_IOMMU_PLATFORM feature require platform-specific handling to configure their DMA transactions. When handling virtio descriptors for such a device, use bounce buffers to ensure that the underlying buffers are always aligned to and padded to PAGE_SIZE in preparation for platform specific handling at page granularity. 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/+/1eff171e613ee67dca71dbe97be7282e2db17011 Reviewed-by: Simon Glass --- drivers/virtio/virtio_ring.c | 48 +++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index de75786ca7..c9adcce5c0 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -28,14 +28,51 @@ static void virtio_free_pages(struct udevice *vdev, void *ptr, u32 npages) free(ptr); } +static int __bb_force_page_align(struct bounce_buffer *state) +{ + const ulong align_mask = PAGE_SIZE - 1; + + if ((ulong)state->user_buffer & align_mask) + return 0; + + if (state->len != state->len_aligned) + return 0; + + return 1; +} + static unsigned int virtqueue_attach_desc(struct virtqueue *vq, unsigned int i, struct virtio_sg *sg, u16 flags) { struct vring_desc_shadow *desc_shadow = &vq->vring_desc_shadow[i]; struct vring_desc *desc = &vq->vring.desc[i]; + void *addr; + + if (IS_ENABLED(CONFIG_BOUNCE_BUFFER) && vq->vring.bouncebufs) { + struct bounce_buffer *bb = &vq->vring.bouncebufs[i]; + unsigned int bbflags; + int ret; + + if (flags & VRING_DESC_F_WRITE) + bbflags = GEN_BB_WRITE; + else + bbflags = GEN_BB_READ; + + ret = bounce_buffer_start_extalign(bb, sg->addr, sg->length, + bbflags, PAGE_SIZE, + __bb_force_page_align); + if (ret) { + debug("%s: failed to allocate bounce buffer (length 0x%zx)\n", + vq->vdev->name, sg->length); + } + + addr = bb->bounce_buffer; + } else { + addr = sg->addr; + } /* Update the shadow descriptor. */ - desc_shadow->addr = (u64)(uintptr_t)sg->addr; + desc_shadow->addr = (u64)(uintptr_t)addr; desc_shadow->len = sg->length; desc_shadow->flags = flags; @@ -50,6 +87,15 @@ static unsigned int virtqueue_attach_desc(struct virtqueue *vq, unsigned int i, static void virtqueue_detach_desc(struct virtqueue *vq, unsigned int idx) { + struct vring_desc *desc = &vq->vring.desc[idx]; + struct bounce_buffer *bb; + + if (!IS_ENABLED(CONFIG_BOUNCE_BUFFER) || !vq->vring.bouncebufs) + return; + + bb = &vq->vring.bouncebufs[idx]; + bounce_buffer_stop(bb); + desc->addr = cpu_to_virtio64(vq->vdev, (u64)(uintptr_t)bb->user_buffer); } int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[],