Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp290887rdb; Sat, 19 Aug 2023 01:45:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7t/cFZ8RUM/Lj2/R6FsJxHRV4GlYi+L8rnBIBjJ/22KwGSEcLylRDW2dru2RnjZgKlfz1 X-Received: by 2002:a17:902:ea04:b0:1b8:811:b079 with SMTP id s4-20020a170902ea0400b001b80811b079mr1854086plg.0.1692434712075; Sat, 19 Aug 2023 01:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692434712; cv=none; d=google.com; s=arc-20160816; b=rnZ6lWYscUO6qKMgggNNY9rUV2RPYGHLH/ERBxDOzdGmUbozuE8hvsmvTk/0Udh7M1 dzomG/XfWAXBgu2coqh1EjSkH1RrCMGuTu+9HOFWQlvfLyZ9IkwkAvD2XuxZr6dBFgeV 6ZixXEg1exvh3qiFKsUZsBUHFumxMRqkGlWgtiNmsDDfiYOVPdcYj5d5n3mydRQJnRYQ 0M5GpTCSvSno8a2oMYWJw6Cj5vh6zx72ur1v4GslDAPyY018jRBHO9SgoC0VGyF74Ktq t3JSUa7kbm780VIzuwHQd18QkZ5jO55mCILYMkLhGKqIUN165iILph35p8wASj3fbEJW L/iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=3TQ4tvtMT0eRr/6y3AA5pQgog1fMxlbrTcPcxQMF188=; fh=FfIXM7A67ShcP3RJ6FoImXcD5/6RmHXsjifl7BnOrMY=; b=olhhq4Tz69+Vf9cTus90PCBpDasve11pRNSBJtzvFsQijlhKxDmpSQjVs9O8dAXRED nBLLP0aq4EekCizYAUKlbKRfpnFYza3/uIiGpboRf3CFNCxbfZMf5sg9L7cMq2O1wA94 AsiWiW3o9CS3BPAr7glxQjpKYoO5dWGC/mugt/fDqo9mF3oqwBfXj4U0S7uxBgutPbQ1 TQpNmmTdBZjeFsSdpKNX6cjgfTSm5IEx3HqYyMUTP6T0bdsXvgp8CcHyWrmDQKjXPbz+ gvsjNOQz17ihKiZDD28JqWXrzq7IWpYVDEMNtNmxXtO/BQT5Z6Sl3256uS6yD5q1W5WY y8qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Txv3H08e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id cp12-20020a170902e78c00b001b9d180fd9asi3065651plb.121.2023.08.19.01.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 01:45:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Txv3H08e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31CA17680; Sat, 19 Aug 2023 01:25:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350093AbjHQLA0 (ORCPT + 99 others); Thu, 17 Aug 2023 07:00:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350092AbjHQK7y (ORCPT ); Thu, 17 Aug 2023 06:59:54 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2F652D4A; Thu, 17 Aug 2023 03:59:52 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-349a7cb1a5cso21780685ab.0; Thu, 17 Aug 2023 03:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692269992; x=1692874792; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3TQ4tvtMT0eRr/6y3AA5pQgog1fMxlbrTcPcxQMF188=; b=Txv3H08eo8bHyYkj9tUjOe62ROpPG7oUtFu/1OSBY0f8nUhe04BnPLeNgykO3PTQNg AVKIcNP0SU05DSziel69DOciTf4y5vHunWM0fMVPSlQWWyzcPGksEXGtHLR1832hUIjB /G061LBkJWZ7M4p6PfHKFzjBn0cQFaYiFfoMDpEaXadLlSps4lm/2pSmEcsGlFRdJiQC PjSC8H3EkeZRj0iD9orLOCuT0UZYqywDu9BixmfUp79oz3w0vm2rUvpVcjkx2bE5GFVg PhObXggIcEeYD+sQviPE2hq6g8isi4Vh2eDMHEZSblIrB50geQdKuxK5dGFJKbBCHMhH 91xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692269992; x=1692874792; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3TQ4tvtMT0eRr/6y3AA5pQgog1fMxlbrTcPcxQMF188=; b=SyCv0QQKQCCo5EFwHhydkE3PQHvDCfCf7o+MqxruxsPcLHnmX3Dvcs39GcZ7jOMv4i dKh3M9KrmpWow0DkVb4HVaKwFfGYHcq6zZkghi8h/eHT6ZXO6WdF3UsuVek3jUts0+Me 0d2Ob9oVW0vdwFVgXJvLv4hvdZSkwSlwtb3H6jSJWy1NN5QTmvNJDncG+ZV4JunFhdhz ZiQQwedCVIwSLTqyU7J3HTDv7TtDcr/LxgR3MW5918WI5lsqQZU4jykPquMW19EN5pBB FWrkbSH4sxlw4YcDp7wXWxlKET1SQqeQtjn8kfvZwt7YyWr7hARI+1sO49xRSHdS6JZ9 6XxQ== X-Gm-Message-State: AOJu0YzNKaWL7mQm93apy/LwvJH4bFhGYiTVVYw3ZAxAPJT0XQt2s+Vg Po76F0Vo9kD1eUskRNyybMvhO4xkww72DTtfBWFJorHdYVo= X-Received: by 2002:a05:6e02:1c28:b0:348:d5dd:247 with SMTP id m8-20020a056e021c2800b00348d5dd0247mr6285271ilh.6.1692269992063; Thu, 17 Aug 2023 03:59:52 -0700 (PDT) MIME-Version: 1.0 References: <20230814205719.79647-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20230814205719.79647-4-prabhakar.mahadev-lad.rj@bp.renesas.com> In-Reply-To: From: "Lad, Prabhakar" Date: Thu, 17 Aug 2023 11:59:23 +0100 Message-ID: Subject: Re: [PATCH v11 3/6] riscv: mm: dma-noncoherent: nonstandard cache operations support To: Emil Renner Berthing Cc: Arnd Bergmann , Conor Dooley , Geert Uytterhoeven , Guo Ren , Andrew Jones , Paul Walmsley , Palmer Dabbelt , Albert Ou , Samuel Holland , linux-riscv@lists.infradead.org, Christoph Hellwig , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Biju Das , Lad Prabhakar Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Emil, Thank you for the review. On Thu, Aug 17, 2023 at 11:54=E2=80=AFAM Emil Renner Berthing wrote: > > On Mon, 14 Aug 2023 at 23:00, Prabhakar wrot= e: > > From: Lad Prabhakar > > > > Introduce support for nonstandard noncoherent systems in the RISC-V > > architecture. It enables function pointer support to handle cache > > management in such systems. > > > > This patch adds a new configuration option called > > "RISCV_NONSTANDARD_CACHE_OPS." This option is a boolean flag that > > depends on "RISCV_DMA_NONCOHERENT" and enables the function pointer > > support for cache management in nonstandard noncoherent systems. > > > > Signed-off-by: Lad Prabhakar > > Reviewed-by: Conor Dooley > > Tested-by: Conor Dooley # tyre-kicking on = a d1 > > --- > > v10 -> v11 > > * Changed data type of size from unsigned long to size_t > > * Reworded doc for struct riscv_cache_ops > > > > v9 -> v10 > > * Added __ro_after_init compiler attribute for noncoherent_cache_ops > > * Renamed clean -> wback > > * Renamed inval -> inv > > * Renamed flush -> wback_inv > > > > v8 -> v9 > > * New patch > > --- > > arch/riscv/Kconfig | 7 ++++ > > arch/riscv/include/asm/dma-noncoherent.h | 28 +++++++++++++++ > > arch/riscv/mm/dma-noncoherent.c | 43 ++++++++++++++++++++++++ > > arch/riscv/mm/pmem.c | 13 +++++++ > > 4 files changed, 91 insertions(+) > > create mode 100644 arch/riscv/include/asm/dma-noncoherent.h > > > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > index f52dd125ac5e..a629d383affb 100644 > > --- a/arch/riscv/Kconfig > > +++ b/arch/riscv/Kconfig > > @@ -269,6 +269,13 @@ config RISCV_DMA_NONCOHERENT > > select ARCH_HAS_SYNC_DMA_FOR_DEVICE > > select DMA_DIRECT_REMAP > > > > +config RISCV_NONSTANDARD_CACHE_OPS > > + bool > > + depends on RISCV_DMA_NONCOHERENT > > + help > > + This enables function pointer support for non-standard noncoh= erent > > + systems to handle cache management. > > + > > config AS_HAS_INSN > > def_bool $(as-instr,.insn r 51$(comma) 0$(comma) 0$(comma) t0$(= comma) t0$(comma) zero) > > > > diff --git a/arch/riscv/include/asm/dma-noncoherent.h b/arch/riscv/incl= ude/asm/dma-noncoherent.h > > new file mode 100644 > > index 000000000000..2fc43f73f766 > > --- /dev/null > > +++ b/arch/riscv/include/asm/dma-noncoherent.h > > @@ -0,0 +1,28 @@ > > +/* SPDX-License-Identifier: GPL-2.0-only */ > > +/* > > + * Copyright (C) 2023 Renesas Electronics Corp. > > + */ > > + > > +#ifndef __ASM_DMA_NONCOHERENT_H > > +#define __ASM_DMA_NONCOHERENT_H > > + > > +#include > > + > > +/* > > + * struct riscv_nonstd_cache_ops - Structure for non-standard CMO func= tion pointers > > It seems you updated the name in this comment.. > > > + * > > + * @wback: Function pointer for cache writeback > > + * @inv: Function pointer for invalidating cache > > + * @wback_inv: Function pointer for flushing the cache (writeback + in= validating) > > + */ > > +struct riscv_cache_ops { > > ..but not the actual struct. I don't have any opinion on which is the > best name, but they should probably match. > Argh! Thanks for pointing out that I'll fix it and resend the series. Cheers, Prabhakar > > + void (*wback)(phys_addr_t paddr, size_t size); > > + void (*inv)(phys_addr_t paddr, size_t size); > > + void (*wback_inv)(phys_addr_t paddr, size_t size); > > +}; > > + > > +extern struct riscv_cache_ops noncoherent_cache_ops; > > + > > +void riscv_noncoherent_register_cache_ops(const struct riscv_cache_ops= *ops); > > + > > +#endif /* __ASM_DMA_NONCOHERENT_H */ > > diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoh= erent.c > > index b6a1e9cc9339..853446525a19 100644 > > --- a/arch/riscv/mm/dma-noncoherent.c > > +++ b/arch/riscv/mm/dma-noncoherent.c > > @@ -9,13 +9,26 @@ > > #include > > #include > > #include > > +#include > > > > static bool noncoherent_supported __ro_after_init; > > > > +struct riscv_cache_ops noncoherent_cache_ops __ro_after_init =3D { > > + .wback =3D NULL, > > + .inv =3D NULL, > > + .wback_inv =3D NULL, > > +}; > > + > > static inline void arch_dma_cache_wback(phys_addr_t paddr, size_t size= ) > > { > > void *vaddr =3D phys_to_virt(paddr); > > > > +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS > > + if (unlikely(noncoherent_cache_ops.wback)) { > > + noncoherent_cache_ops.wback(paddr, size); > > + return; > > + } > > +#endif > > ALT_CMO_OP(clean, vaddr, size, riscv_cbom_block_size); > > } > > > > @@ -23,6 +36,13 @@ static inline void arch_dma_cache_inv(phys_addr_t pa= ddr, size_t size) > > { > > void *vaddr =3D phys_to_virt(paddr); > > > > +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS > > + if (unlikely(noncoherent_cache_ops.inv)) { > > + noncoherent_cache_ops.inv(paddr, size); > > + return; > > + } > > +#endif > > + > > ALT_CMO_OP(inval, vaddr, size, riscv_cbom_block_size); > > } > > > > @@ -30,6 +50,13 @@ static inline void arch_dma_cache_wback_inv(phys_add= r_t paddr, size_t size) > > { > > void *vaddr =3D phys_to_virt(paddr); > > > > +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS > > + if (unlikely(noncoherent_cache_ops.wback_inv)) { > > + noncoherent_cache_ops.wback_inv(paddr, size); > > + return; > > + } > > +#endif > > + > > ALT_CMO_OP(flush, vaddr, size, riscv_cbom_block_size); > > } > > > > @@ -49,6 +76,13 @@ void arch_dma_prep_coherent(struct page *page, size_= t size) > > { > > void *flush_addr =3D page_address(page); > > > > +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS > > + if (unlikely(noncoherent_cache_ops.wback_inv)) { > > + noncoherent_cache_ops.wback_inv(page_to_phys(page), siz= e); > > + return; > > + } > > +#endif > > + > > ALT_CMO_OP(flush, flush_addr, size, riscv_cbom_block_size); > > } > > > > @@ -74,3 +108,12 @@ void riscv_noncoherent_supported(void) > > "Non-coherent DMA support enabled without a block size\n")= ; > > noncoherent_supported =3D true; > > } > > + > > +void riscv_noncoherent_register_cache_ops(const struct riscv_cache_ops= *ops) > > +{ > > + if (!ops) > > + return; > > + > > + noncoherent_cache_ops =3D *ops; > > +} > > +EXPORT_SYMBOL_GPL(riscv_noncoherent_register_cache_ops); > > diff --git a/arch/riscv/mm/pmem.c b/arch/riscv/mm/pmem.c > > index 089df92ae876..c5fc5ec96f6d 100644 > > --- a/arch/riscv/mm/pmem.c > > +++ b/arch/riscv/mm/pmem.c > > @@ -7,15 +7,28 @@ > > #include > > > > #include > > +#include > > > > void arch_wb_cache_pmem(void *addr, size_t size) > > { > > +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS > > + if (unlikely(noncoherent_cache_ops.wback)) { > > + noncoherent_cache_ops.wback(virt_to_phys(addr), size); > > + return; > > + } > > +#endif > > ALT_CMO_OP(clean, addr, size, riscv_cbom_block_size); > > } > > EXPORT_SYMBOL_GPL(arch_wb_cache_pmem); > > > > void arch_invalidate_pmem(void *addr, size_t size) > > { > > +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS > > + if (unlikely(noncoherent_cache_ops.inv)) { > > + noncoherent_cache_ops.inv(virt_to_phys(addr), size); > > + return; > > + } > > +#endif > > ALT_CMO_OP(inval, addr, size, riscv_cbom_block_size); > > } > > EXPORT_SYMBOL_GPL(arch_invalidate_pmem); > > -- > > 2.34.1 > > > > > > _______________________________________________ > > linux-riscv mailing list > > linux-riscv@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-riscv