Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp856664pxb; Mon, 16 Aug 2021 20:28:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5cHR/rbUiFIR0D9oiOqk2QqnWiPxhK74Dn6PWdisk2yttsu23tpr1lFfroVOwXYIFOckP X-Received: by 2002:aa7:c64f:: with SMTP id z15mr1669081edr.54.1629170931510; Mon, 16 Aug 2021 20:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629170931; cv=none; d=google.com; s=arc-20160816; b=ZdRTYfZrpZAcr86mCXjdM7XleSjSpNeEof4gqJHiH16DmfcPlFCGLTJeH9DGcdBZji UY3obiibMpix4MenYRBjtutXeHVtP78WMl+cS8DV4wR5WCEbDBmrTOdUmyXK+zP0Xxbe VfMIk+1Qots0+aCrFZm4f5qxrgCVQ05Rh0rmdq46Jlr8XRUqdAbA3mrqjXI6kb4crZFM U5ENENrBH3dbc7MtaXVkTYTRKrV2eGeadhQOFdc53unQjKEFu7YcW/C0h3vaa5ItWdWy 5PvDlQvHIkgACijrXmA29Dc/4SBYZ66dv/xaar3B1mW12ERiSR5X6oYIQUI5BLQZ6W39 REwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=R7t78EbJ4SBQR4PW9PP+EHALfMTimXWJ4a8o/k9vg3E=; b=HzINol+oM9Mw+IjjnCRQMo4Jke75qsy4uq4ke5KUfx24xN3jLvOrUD0BKJpGzMFuiN eMsI66U/39AjWfPJ6DDebgUhJUdjFbvQhudYICZtaGqq/GbHjUyVATQCyov74A/8xNzU 3obPb8Qba+RWOsKt/Qz/QfGijjSv9l5HO29lLHmsEd5XnF3TsQ1ahblfxeGBqCanilkr Ap58xPPgFMYlEERuIkkpBIWm/5rpz2CQuhpLLhjPqEO3MPrL6t2Q0z1v8QCiSLNWZQQK Rwhk6WDo7Eu4XBUsbHojYfUnJsErG3qK3HjMKHHXozH9VZxRiTTnGGCd7w9rvxxk2MvU iK+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=TvFFwtml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si905512edr.230.2021.08.16.20.28.26; Mon, 16 Aug 2021 20:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=TvFFwtml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233724AbhHQDZL (ORCPT + 99 others); Mon, 16 Aug 2021 23:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233637AbhHQDZK (ORCPT ); Mon, 16 Aug 2021 23:25:10 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7AB3C061764 for ; Mon, 16 Aug 2021 20:24:37 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id i8so14108440ybt.7 for ; Mon, 16 Aug 2021 20:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=R7t78EbJ4SBQR4PW9PP+EHALfMTimXWJ4a8o/k9vg3E=; b=TvFFwtmlL3L2+ir/JLvkG9HSbp6wG0WN7eoWHjuvbqXI/776osypQlgOrDrJUXLFjL 94vLmlXhpIhhPlKhhiwszEk5kK6XzKmgsMfM/A3jvpMEuqbVyeX3vxyGQeKdQZFR3yr3 Ioj8WJTKLQsxO2rclDVfBKJYXSWlDN3Tu90wM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=R7t78EbJ4SBQR4PW9PP+EHALfMTimXWJ4a8o/k9vg3E=; b=o26IQGxrHh2v9VpjYBQ/FguqQndJwQZ0C0sy5J7I/xvkd0ne6GmbMhyZ5W57avIAfs /KvnIreBqGAgZFqwTVPh/FutV2JL1WZ1ZwYfTXdqt1ZyRcTJ8lZcBry5uQjEukX3iO2W /n2hJDRp/Z8qWP2R+D2LBkFk6qBrrpCjB2FQ/gtiYQ0mVnNQqwx+kG3wM6Z/lBWjLizH 4d2FWhnvqsguEdGfSrmJWl3BOsdt7yD2KBo93AH2GzQPaxL7p09B7Ct/X8e8ZUhpEPXM 5iDzXlRU8Oznct5oXbSeaLLjFjxF4cfDjXDvndDEIXn37c8j4+qJUpybo/P6dfcARVHB y7VA== X-Gm-Message-State: AOAM531U/BP14q08GE7C8U2FmqNOCNfGU6kAORjxNWxjSJBRQKE5QJNl kc/cFNpAwbH3LtmbLxm/AHf34WdvQiUPoGpR0s7h X-Received: by 2002:a25:3f85:: with SMTP id m127mr1773427yba.21.1629170676840; Mon, 16 Aug 2021 20:24:36 -0700 (PDT) MIME-Version: 1.0 References: <20210723214031.3251801-1-atish.patra@wdc.com> <20210723214031.3251801-2-atish.patra@wdc.com> In-Reply-To: From: Atish Patra Date: Mon, 16 Aug 2021 20:24:26 -0700 Message-ID: Subject: Re: [RFC 1/5] RISC-V: Implement arch_sync_dma* functions To: Guo Ren Cc: Atish Patra , devicetree , Albert Ou , Guo Ren , Frank Rowand , Linux Kernel Mailing List , Christoph Hellwig , iommu@lists.linux-foundation.org, Rob Herring , Palmer Dabbelt , Paul Walmsley , Tobias Klauser , Robin Murphy , linux-riscv , Dmitry Vyukov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 16, 2021 at 6:48 PM Guo Ren wrote: > > On Sat, Jul 24, 2021 at 5:40 AM Atish Patra wrote: > > > > To facilitate streaming DMA APIs, this patch introduces a set of generic > > cache operations related dma sync. Any platform can use the generic ops > > to provide platform specific cache management operations. Once the > > standard RISC-V CMO extension is available, it can be built on top of it. > > > > Signed-off-by: Atish Patra > > --- > > arch/riscv/include/asm/dma-noncoherent.h | 19 +++++++ > > arch/riscv/mm/Makefile | 1 + > > arch/riscv/mm/dma-noncoherent.c | 66 ++++++++++++++++++++++++ > > 3 files changed, 86 insertions(+) > > create mode 100644 arch/riscv/include/asm/dma-noncoherent.h > > create mode 100644 arch/riscv/mm/dma-noncoherent.c > > > > diff --git a/arch/riscv/include/asm/dma-noncoherent.h b/arch/riscv/include/asm/dma-noncoherent.h > > new file mode 100644 > > index 000000000000..5bdb03c9c427 > > --- /dev/null > > +++ b/arch/riscv/include/asm/dma-noncoherent.h > > @@ -0,0 +1,19 @@ > > +/* SPDX-License-Identifier: GPL-2.0-only */ > > +/* > > + * Copyright (c) 2021 Western Digital Corporation or its affiliates. > > + */ > > + > > +#ifndef __ASM_RISCV_DMA_NON_COHERENT_H > > +#define __ASM_RISCV_DMA_NON_COHERENT_H > > + > > +#ifdef CONFIG_RISCV_DMA_NONCOHERENT > > +struct riscv_dma_cache_sync { > > + void (*cache_invalidate)(phys_addr_t paddr, size_t size); > > + void (*cache_clean)(phys_addr_t paddr, size_t size); > > + void (*cache_flush)(phys_addr_t paddr, size_t size); > > +}; > I like the style like this than my previous patch which using > sbi_call. The c906 has custom instructions that could be called in > S-mode directly. > How are you going to include the custom instructions in the upstream kernel ? > Hope the patch could be soon merged, after correct the > DMA_FROM/TO_DEVICE/BIDIRECTIONAL and alternatives ops_set. > > > + > > +void riscv_dma_cache_sync_set(struct riscv_dma_cache_sync *ops); > > +#endif > > + > > +#endif > > diff --git a/arch/riscv/mm/Makefile b/arch/riscv/mm/Makefile > > index 7ebaef10ea1b..959bef49098b 100644 > > --- a/arch/riscv/mm/Makefile > > +++ b/arch/riscv/mm/Makefile > > @@ -27,3 +27,4 @@ KASAN_SANITIZE_init.o := n > > endif > > > > obj-$(CONFIG_DEBUG_VIRTUAL) += physaddr.o > > +obj-$(CONFIG_RISCV_DMA_NONCOHERENT) += dma-noncoherent.o > > diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoherent.c > > new file mode 100644 > > index 000000000000..2f6e9627c4aa > > --- /dev/null > > +++ b/arch/riscv/mm/dma-noncoherent.c > > @@ -0,0 +1,66 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > +/* > > + * RISC-V specific functions to support DMA for non-coherent devices > > + * > > + * Copyright (c) 2021 Western Digital Corporation or its affiliates. > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +static struct riscv_dma_cache_sync *dma_cache_sync; > > +unsigned long riscv_dma_uc_offset; > > + > > +static void __dma_sync(phys_addr_t paddr, size_t size, enum dma_data_direction dir) > > +{ > > + if ((dir == DMA_FROM_DEVICE) && (dma_cache_sync->cache_invalidate)) > > + dma_cache_sync->cache_invalidate(paddr, size); > > + else if ((dir == DMA_TO_DEVICE) && (dma_cache_sync->cache_clean)) > > + dma_cache_sync->cache_clean(paddr, size); > > + else if ((dir == DMA_BIDIRECTIONAL) && dma_cache_sync->cache_flush) > > + dma_cache_sync->cache_flush(paddr, size); > > +} > > + > > +void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, enum dma_data_direction dir) > > +{ > > + if (!dma_cache_sync) > > + return; > > + > > + __dma_sync(paddr, size, dir); > > +} > > + > > +void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, enum dma_data_direction dir) > > +{ > > + if (!dma_cache_sync) > > + return; > > + > > + __dma_sync(paddr, size, dir); > > +} > > + > > +void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, > > + const struct iommu_ops *iommu, bool coherent) > > +{ > > + /* If a specific device is dma-coherent, set it here */ > > + dev->dma_coherent = coherent; > > +} > > + > > +void arch_dma_prep_coherent(struct page *page, size_t size) > > +{ > > + void *flush_addr = page_address(page); > > + > > + memset(flush_addr, 0, size); > > + if (dma_cache_sync && dma_cache_sync->cache_flush) > > + dma_cache_sync->cache_flush(__pa(flush_addr), size); > > +} > > + > > +void riscv_dma_cache_sync_set(struct riscv_dma_cache_sync *ops) > > +{ > > + dma_cache_sync = ops; > > +} > > -- > > 2.31.1 > > > > _______________________________________________ > > iommu mailing list > > iommu@lists.linux-foundation.org > > https://lists.linuxfoundation.org/mailman/listinfo/iommu > > > > -- > Best Regards > Guo Ren > > ML: https://lore.kernel.org/linux-csky/ > _______________________________________________ > iommu mailing list > iommu@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/iommu -- Regards, Atish