From patchwork Wed Aug 16 23:23:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 13355773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F2A0C27C7A for ; Wed, 16 Aug 2023 23:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jODcD0j9bG2XR5ujBo+1BO41hCYdVMFUlo2RC4qTZB8=; b=BPU9EUwVjGGPrB Vz5zbCace+zvTT4TewyKmuc5ZeaYT5AIy2GT/vv9dkK4ahs3zYPPMsyueMUhmV0H4Tduzo+mpQ3BR ElQK03TM+FXWB24F5rOpwDqI19yljH0CF1OTH86m37Lh7chlEJTZdDsktaQh0Q0MO6l9kycvxkgcV APj7y72ezEe8KYUhzLIwnMhz7JqK5TX6bj4AescrOorHjnVeUGQO2nsEmtGD/Kf/+RDIqNwlDmTZp nH8J4f0f1TtbfJzRAYMZ8T0N1tUfNUy3WbCzFb0+2uNfM2myC49WaJjVf1jCELWr3vRO5kWduBSRV WLn8opA1XaLefDHAGnbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qWPrj-005A9U-1N; Wed, 16 Aug 2023 23:23:51 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qWPrf-005A8G-2B for linux-riscv@lists.infradead.org; Wed, 16 Aug 2023 23:23:49 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe426b8583so71994815e9.2 for ; Wed, 16 Aug 2023 16:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692228226; x=1692833026; 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=Z3QZb2R3EdSRGjNldFEi1fV9QVZELOWJSDHH54gUih4=; b=lxO1UAr4NneU+P6Ihb8bkx/VGrROmaqowPU14iRlhaBcEsBBUdJxksJxlCRA9CwkWj 0K7pbCpiUVKHSucjlDfysFP9QM7lhCmB3z93KBLq0ivmXhN5CHHoCpwFQ1TXGaRbZeaW HAm3YcHxdA3UWYYSAeCVwP5sBve3HbXdjGQIcXUiD5My1JU0+nEdoGu3gzv5WH95S4dl n+qxFbotzHG4sAsD8mfY7mQwTSAunSbjRE2Y3HT+JvZcZ7qSLV2UVa05X82kLCtEGv/S OwdbKJ6X9Zj6/LKSLYRBCKveneRYhLxhLY6mAy5UfKaY0iqZGd5eIWRmcAjQARJWqQLd U0hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692228226; x=1692833026; 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=Z3QZb2R3EdSRGjNldFEi1fV9QVZELOWJSDHH54gUih4=; b=l3uZy0ttQthvakjb7J9QKcu8YNS8RzTprUA6JaQkYpjT+88r4tMMOPxONgK9ktaab3 aVmslVK2zaPPsgMS/RynCajVDLyN79+KjnIZCETLpZZ+tVCaQ7zufSEjDdQC30a24bUy OJ0FdJCnwLnCJssZa7PhAFnedI4HX9xFWONEukGnwTJQORyhyaWJ+wOu1ky+8GJEb0D6 vpTAnwfnnys8sSIUmOqZ0Wi/IA6pfMhs/rwKv1lpZoiIuU9SynndestP9guxOffrpFBP Jb77kiQPkAG3Rvs5pYCWbk8Q21jV/a4naq6HXag19m5GI0oSswAoTpC7hIER0ETOoqd1 /vmA== X-Gm-Message-State: AOJu0YxDQ9J18fe/rQiuwerTvE/fOk5P8niou4rygaZhfp9TqWdlVW7I C2pogk4+mHAQpCKWSgD44Hw= X-Google-Smtp-Source: AGHT+IEJnRIZ1RA+2A8XOGo4qJdGXnm7sLvGhrm0Oh2ZgRs2v30ncOfTStpL4pgYtbcwGDoCsAU2Qg== X-Received: by 2002:adf:f7c9:0:b0:315:a32d:311f with SMTP id a9-20020adff7c9000000b00315a32d311fmr277540wrq.14.1692228225599; Wed, 16 Aug 2023 16:23:45 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:aeb8:832b:ebc0:1bbf]) by smtp.gmail.com with ESMTPSA id q4-20020adff944000000b003143c9beeaesm22752617wrr.44.2023.08.16.16.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 16:23:44 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Arnd Bergmann , Christoph Hellwig , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Anup Patel , Andrew Jones , Jisheng Zhang , linux-kernel@vger.kernel.org Cc: Geert Uytterhoeven , Samuel Holland , linux-riscv@lists.infradead.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Lad Prabhakar , Palmer Dabbelt Subject: [PATCH v3 1/3] riscv: dma-mapping: only invalidate after DMA, not flush Date: Thu, 17 Aug 2023 00:23:34 +0100 Message-Id: <20230816232336.164413-2-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816232336.164413-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230816232336.164413-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230816_162347_713768_F33D5BA1 X-CRM114-Status: GOOD ( 13.54 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann No other architecture intentionally writes back dirty cache lines into a buffer that a device has just finished writing into. If the cache is clean, this has no effect at all, but if a cacheline in the buffer has actually been written by the CPU, there is a driver bug that is likely made worse by overwriting that buffer. Signed-off-by: Arnd Bergmann Reviewed-by: Conor Dooley Reviewed-by: Lad Prabhakar Acked-by: Palmer Dabbelt Signed-off-by: Lad Prabhakar --- v2->v3 * No change v1->v2 * Fixed typo drive->driver in commit message * Included RB and ACKs --- arch/riscv/mm/dma-noncoherent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoherent.c index d51a75864e53..94614cf61cdd 100644 --- a/arch/riscv/mm/dma-noncoherent.c +++ b/arch/riscv/mm/dma-noncoherent.c @@ -42,7 +42,7 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, break; case DMA_FROM_DEVICE: case DMA_BIDIRECTIONAL: - ALT_CMO_OP(flush, vaddr, size, riscv_cbom_block_size); + ALT_CMO_OP(inval, vaddr, size, riscv_cbom_block_size); break; default: break; From patchwork Wed Aug 16 23:23:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 13355775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 372C3C27C7A for ; Wed, 16 Aug 2023 23:24:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/J1v8VIikNj8CXWcNllkqjbEdo/19g2b6yIvGn8GblU=; b=YB23f6Ic7v57gu +QtohczO3xsceoMfd6/jnAy6DgrgSkn6bLpNpYzG0sMxocnoWGtVtBPFzuCdj1bu5TKtA2RLG0GlZ sRXLidLhIxaqmMe7QqvW4lm/DXz6VEpLgHxLQUbKCK9NbaDyT/yq0ElD2YZ5m4eNrp2iDogYrz2Bb syoxXHXr1JLmvVELfgwRhPO6OQmwJLSYTUya47ZyALXz5FsSTh2uc0Y6B9VL0xPK+JWT8W2KY5eJo /nUmUPKnlTEVjsCPFxP3XsYdNzPPz8wdLldPqy62k1xhe08TfKP5yzE+kEf+d/WoboFxcU8qq8HJ8 f+Zr8Fw6R6CdnTGU8kBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qWPrk-005A9w-1v; Wed, 16 Aug 2023 23:23:52 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qWPrg-005A8R-2g for linux-riscv@lists.infradead.org; Wed, 16 Aug 2023 23:23:50 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3159d5e409dso236492f8f.0 for ; Wed, 16 Aug 2023 16:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692228227; x=1692833027; 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=CGdlWqc1rkzIUGoDyoTEaUD3c+T74fuHGIBlF6hhRXE=; b=i1rMqkAX0KYQmr3hX4gpHJcpZAnDSPY8FLQjmOcFH3IWzsZwip4k+YHeb5V/KxJnpF q4TAqYenmaiCEY3J97LGLYQGw7eJ2N/2/dohn9ZdiJpMRm8Bej5E6vNa/L/rNEbX4Pwd hGhjFUsAvEUj3b7xE3U1OtrsvSSninqiC2JU+tamUiDAcQOpP87MxwfCpaVsQCw8ymh2 FztCPo83D2R4gVCMS/kU/XhbDdDdPFnhiNZu5FI4YCkQFkFJZycKAVLvazdTOH5OEmGn U7zf/orzzZgyY6Sn8ZjbSSglKNIJRoRTb6+PNjK87rFAEFx1Ou7YFmyFIlWI9PDI9iCM k+OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692228227; x=1692833027; 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=CGdlWqc1rkzIUGoDyoTEaUD3c+T74fuHGIBlF6hhRXE=; b=HveXw8McbgCoBK+LcjKLL7Npuzi7rAv5U7n7PmCatoRqVT1KBnUPHG8HVp3ArQ8YHD RqqaXrCC37XTIzz9wGxYb8CqKPu/YTQ+34RPeiSUkuz++cfy+Q1JmyXRkDN8PvaG5biN FypXLaAxPN1Njs0R/QZkERp5j2p9iB6t3rb1qcJN2gUawb9f6EezgcLE+ns7RXaHhr81 FlimRJKETKvybUo97V5kvS6jgrja1ouXDDYY40NCmI7ug6IuHTWJXZOFHg6hzEYt4sDo rdXk9e+woZK+lKYV6JtFaZ9LvTI95ID6s1wdmPi3pXxoe/uslsUAtlN6BV74zxRukLKi EXpw== X-Gm-Message-State: AOJu0Yy0KWOkV7dFnCg1zs1SinYz4jSlT+vUUXdsTICX/pJoCjq9a+ig M8V+au3KBCfTpRpOH7zPNVA= X-Google-Smtp-Source: AGHT+IHmS0dmKyTUvNIRhuKNUSwUXxoC4kjuGiODOZEK2LaKsTUEMw6dOQBcO1DBZTrwrVq3tbjfOg== X-Received: by 2002:adf:e78e:0:b0:314:2f3e:dca5 with SMTP id n14-20020adfe78e000000b003142f3edca5mr791297wrm.28.1692228226969; Wed, 16 Aug 2023 16:23:46 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:aeb8:832b:ebc0:1bbf]) by smtp.gmail.com with ESMTPSA id q4-20020adff944000000b003143c9beeaesm22752617wrr.44.2023.08.16.16.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 16:23:46 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Arnd Bergmann , Christoph Hellwig , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Anup Patel , Andrew Jones , Jisheng Zhang , linux-kernel@vger.kernel.org Cc: Geert Uytterhoeven , Samuel Holland , linux-riscv@lists.infradead.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Lad Prabhakar , Palmer Dabbelt , Guo Ren Subject: [PATCH v3 2/3] riscv: dma-mapping: skip invalidation before bidirectional DMA Date: Thu, 17 Aug 2023 00:23:35 +0100 Message-Id: <20230816232336.164413-3-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816232336.164413-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230816232336.164413-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230816_162348_867116_E6F12C74 X-CRM114-Status: GOOD ( 12.88 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Arnd Bergmann For a DMA_BIDIRECTIONAL transfer, the caches have to be cleaned first to let the device see data written by the CPU, and invalidated after the transfer to let the CPU see data written by the device. riscv also invalidates the caches before the transfer, which does not appear to serve any purpose. Signed-off-by: Arnd Bergmann Reviewed-by: Conor Dooley Reviewed-by: Lad Prabhakar Acked-by: Palmer Dabbelt Acked-by: Guo Ren Signed-off-by: Lad Prabhakar --- v2->v3 * No change v1->v2 * Included RB and ACKs --- arch/riscv/mm/dma-noncoherent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoherent.c index 94614cf61cdd..fc6377a64c8d 100644 --- a/arch/riscv/mm/dma-noncoherent.c +++ b/arch/riscv/mm/dma-noncoherent.c @@ -25,7 +25,7 @@ void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, ALT_CMO_OP(clean, vaddr, size, riscv_cbom_block_size); break; case DMA_BIDIRECTIONAL: - ALT_CMO_OP(flush, vaddr, size, riscv_cbom_block_size); + ALT_CMO_OP(clean, vaddr, size, riscv_cbom_block_size); break; default: break; From patchwork Wed Aug 16 23:23:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 13355774 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9DC3C27C53 for ; Wed, 16 Aug 2023 23:23:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QiW4Dd1MGXWNhUEed4NenbG4La/klmgrFXqI7ZQYV40=; b=ny+c9pS4tevE8B mo/YNC6eG7Ep2sTLsgwcpkuwwsp4ouYDd/x2W7H62d9GyADPjfju2vULUHdg0UKXTMUsXMgF49YBT LeX77Zqe0g0YpzuWOK0+8Sp6VHxtBVgSfs8V2YfZoIGsvptWHWqV6d69FIHUo9jCaVI4Yykq05H3S 9jiJBSSymV7aTuotMx5HK68JQkvBh1O7yo7xP+bScmi3egJ9V8B7lzTjXJoR6y/PHwz8NZ1Bk0F7s ZBeL9dgW3wAdirsKTNrvE927mjWrwySSs7GL5aAX7DQI32iRamko9lr2Ka/3M1lLtYrtcHBPWjLE3 9qfqFqYeMKQpB5HF7rwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qWPro-005AAy-0k; Wed, 16 Aug 2023 23:23:56 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qWPri-005A8w-2O for linux-riscv@lists.infradead.org; Wed, 16 Aug 2023 23:23:52 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbd33a57b6so70853825e9.2 for ; Wed, 16 Aug 2023 16:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692228229; x=1692833029; 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=Qa3AibLZ/flcMM8pjMbhTffSCLpDoNcTFNENKYYaFNY=; b=HVyU7R+7NAHiP1FHnuES28Woqar0atRkeoYGbaaacWeuA4/koMeyt7sWGUK2Ynjwk6 47O7kvMM9nK3nI36bqh4DSCXGzVwhx0oTCphBopPWKKMVjyz/xjtF/WK2UmC7BukPkFc j/TiiIgSJqnuheF9Rsdz6rOCZIT7SGCP9aaFepCP6Sgr1qBAXitiX1NBq2QfoY7lZYN+ V2g9luT63NSlPJCzbfSbqJZdutg+mM+QoCfCJ0cwJgwA2FiVj3rGoSvL0G3lfgqxZ9dT kQQuCXiima/MAqL5WWi71hRzx2jA9zZfbP5gvYXrqBH7aTwz5NxMSAf94rAhe8HsqTI1 ODUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692228229; x=1692833029; 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=Qa3AibLZ/flcMM8pjMbhTffSCLpDoNcTFNENKYYaFNY=; b=NaDB1+vp3r2rZEq4MIh9f33aDhMnirdrAi/KcNOVfKph7jWWxowQeTa+GP4yE4kZ4X T+Eoeafx8y/U6U5Dz/LlRT3GeWDdC8dOsrINHCt8wE44dgqPaaSo+cZ78OqzAkzEJ4xb zxBq2IzdAPfAZ3gGlUdSzbEdwWoH6WGtfxBVt6a92ThkJXv9EaFjW63F1TqaG5TUAnws w3MHqRy/djnMtiGaiLL1ntrVkeYA5OOgEIfLyn9TRoBHIgbVjEqRT+a3OmG7TX1RkcxL c1kQWGlGH0uV7hzzcLXX/A83kyNZO3eqJI6RaRXLU9YnaCp0Db7NSoeb9K/5TKeCdoar rEHQ== X-Gm-Message-State: AOJu0Yzov/GtUw8LEZs6SrOXJBsp2qPhQk30iOKsUCBfS2ynW7wUW/54 1r5XvdM9g7ZkYVI2RBwH0QM= X-Google-Smtp-Source: AGHT+IFnz3zO5DhsTq/r4acaRKYRoJxmqtk6kyVWxCNSs6D3aHnm7Cqcu25/wzXO/Vs8/Q9UZVonkA== X-Received: by 2002:a7b:c8ca:0:b0:3f6:1474:905 with SMTP id f10-20020a7bc8ca000000b003f614740905mr2692739wml.29.1692228228455; Wed, 16 Aug 2023 16:23:48 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:aeb8:832b:ebc0:1bbf]) by smtp.gmail.com with ESMTPSA id q4-20020adff944000000b003143c9beeaesm22752617wrr.44.2023.08.16.16.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 16:23:47 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Arnd Bergmann , Christoph Hellwig , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Anup Patel , Andrew Jones , Jisheng Zhang , linux-kernel@vger.kernel.org Cc: Geert Uytterhoeven , Samuel Holland , linux-riscv@lists.infradead.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Lad Prabhakar Subject: [PATCH v3 3/3] riscv: dma-mapping: switch over to generic implementation Date: Thu, 17 Aug 2023 00:23:36 +0100 Message-Id: <20230816232336.164413-4-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816232336.164413-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230816232336.164413-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230816_162350_779006_BFD22B76 X-CRM114-Status: GOOD ( 14.38 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Lad Prabhakar Add helper functions for cache wback/inval/clean and use them arch_sync_dma_for_device()/arch_sync_dma_for_cpu() functions. The proposed changes are in preparation for switching over to generic implementation. Reorganization of the code is based on the patch (Link[0]) from Arnd. For now I have dropped CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU check as this will be enabled by default upon selection of RISCV_DMA_NONCOHERENT and also dropped arch_dma_mark_dcache_clean(). Link[0]: https://lore.kernel.org/all/20230327121317.4081816-22-arnd@kernel.org/ Signed-off-by: Arnd Bergmann Signed-off-by: Lad Prabhakar --- Hi Arnd, I have kept the changes minimal here as compared to your original patch and dropped arch_dma_mark_dcache_clean() function and config checks for now as we are currently implementing for riscv only. Cheers, Prabhakar v3: * New patch --- arch/riscv/mm/dma-noncoherent.c | 60 ++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoherent.c index fc6377a64c8d..06b8fea58e20 100644 --- a/arch/riscv/mm/dma-noncoherent.c +++ b/arch/riscv/mm/dma-noncoherent.c @@ -12,21 +12,61 @@ static bool noncoherent_supported __ro_after_init; -void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, - enum dma_data_direction dir) +static inline void arch_dma_cache_wback(phys_addr_t paddr, size_t size) +{ + void *vaddr = phys_to_virt(paddr); + + ALT_CMO_OP(clean, vaddr, size, riscv_cbom_block_size); +} + +static inline void arch_dma_cache_inv(phys_addr_t paddr, size_t size) +{ + void *vaddr = phys_to_virt(paddr); + + ALT_CMO_OP(inval, vaddr, size, riscv_cbom_block_size); +} + +static inline void arch_dma_cache_wback_inv(phys_addr_t paddr, size_t size) { void *vaddr = phys_to_virt(paddr); + ALT_CMO_OP(flush, vaddr, size, riscv_cbom_block_size); +} + +static inline bool arch_sync_dma_clean_before_fromdevice(void) +{ + return true; +} + +static inline bool arch_sync_dma_cpu_needs_post_dma_flush(void) +{ + return true; +} + +void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, + enum dma_data_direction dir) +{ switch (dir) { case DMA_TO_DEVICE: - ALT_CMO_OP(clean, vaddr, size, riscv_cbom_block_size); + arch_dma_cache_wback(paddr, size); break; + case DMA_FROM_DEVICE: - ALT_CMO_OP(clean, vaddr, size, riscv_cbom_block_size); - break; + if (!arch_sync_dma_clean_before_fromdevice()) { + arch_dma_cache_inv(paddr, size); + break; + } + fallthrough; + case DMA_BIDIRECTIONAL: - ALT_CMO_OP(clean, vaddr, size, riscv_cbom_block_size); + /* Skip the invalidate here if it's done later */ + if (IS_ENABLED(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) && + arch_sync_dma_cpu_needs_post_dma_flush()) + arch_dma_cache_wback(paddr, size); + else + arch_dma_cache_wback_inv(paddr, size); break; + default: break; } @@ -35,15 +75,17 @@ void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, enum dma_data_direction dir) { - void *vaddr = phys_to_virt(paddr); - switch (dir) { case DMA_TO_DEVICE: break; + case DMA_FROM_DEVICE: case DMA_BIDIRECTIONAL: - ALT_CMO_OP(inval, vaddr, size, riscv_cbom_block_size); + /* FROM_DEVICE invalidate needed if speculative CPU prefetch only */ + if (arch_sync_dma_cpu_needs_post_dma_flush()) + arch_dma_cache_inv(paddr, size); break; + default: break; }