Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3041348rwl; Fri, 6 Jan 2023 14:47:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXuvOVApUibp55uYecQTqhBea7l8NmkehcQ104OsZm/CdfFjMZbOdojs0uTyNM9jShosyJKh X-Received: by 2002:aa7:d984:0:b0:496:9d0f:3081 with SMTP id u4-20020aa7d984000000b004969d0f3081mr3182581eds.3.1673045267587; Fri, 06 Jan 2023 14:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673045267; cv=none; d=google.com; s=arc-20160816; b=xbUBIeE61FlBG8+qM7UyEQ7tBLR8m1aCRiJ0EPaneMw7xg5YT0d+h1fMGaLq05z4Rj oJcvRXefgdT5mU+4X7ThhrsFyo/LagdKqix6QbkxpkwKzw8bb/Iep4V9ILyVGfm+dsNp JO4FyM4tt6jP+LzbAtyOjKqJSC1q8ZBcQiKKXHbf7drPznphdkuISAz9rSw4DHMO8683 RmgliZc/XEOYhRuRAFISuNUI0eCx1eBn+0phiX8k8ohnMSLKo/3L0e3Icb7WD+/+tsrC v6VzyTVs7dMY3+qEXLOxPzq0dHLnXY0qGRh1Bbg8Xhb0CnHlXApULl0QUxDpbB/s6jqw Ix4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=ZsG681Pan5CKaukkBdKOCNuqBF9WuoTwPInsMRA5Jvw=; b=pUYCW9uVZ0CLBeoZ1ZZQeims/o/ltMzzpj+HNhC0ilRZkiVBKkIzrjBZzaZaJAJEsa RE6pH08LrRlduy+2HmGEjUwGfvaTZloZ4FK9EpU5oAx+8S1dg4BBLLqxCEkc3FpP8lKP Kg68s5DZlxQNyyf6O1owCzla9M8owL3eAViQjpPhy8MUxJ2oIcx0abG5/rlBgNqSoUcF 0YjylcufoQ0bjX70r27uKkZ3B+a1oS92ITLFHi2bSwc1wKL/8wQd5YgcTVny4lOZ0qhe P/oJUyS2THMozHmm3iAMfuU+Nc0TojyusKUyOj9Ezo3x79CQ04pmNhGM7LlybZH53G1j pXqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b="b/o6dQTh"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=mUHHxCzI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a50c88b000000b0048b6bca0c4bsi2350377edh.565.2023.01.06.14.47.34; Fri, 06 Jan 2023 14:47:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b="b/o6dQTh"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=mUHHxCzI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbjAFWb7 (ORCPT + 55 others); Fri, 6 Jan 2023 17:31:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230326AbjAFWb5 (ORCPT ); Fri, 6 Jan 2023 17:31:57 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96E308462F; Fri, 6 Jan 2023 14:31:55 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 0C62E5C00C1; Fri, 6 Jan 2023 17:31:55 -0500 (EST) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Fri, 06 Jan 2023 17:31:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1673044315; x=1673130715; bh=ZsG681Pan5 CKaukkBdKOCNuqBF9WuoTwPInsMRA5Jvw=; b=b/o6dQThSZfMkHb++Pw/ySr5UY FihsdtJLv5QO3McakdeePVZ5f3Y2PFrSplcpbKL21hz75paeL24g/0EUQyVfMkK4 CNUEUfb0BbVSQIMNBCHJFYh3U8ypcaU+KNBa1ozUEufvqM0VYxYYjzL7lFZxONeu 3RxwQIbX4AXlQzjDeAJoA0U1/fuUhsz0CkG8nk6aJz6b7/HOhwbF4seYSRCt1dWN CPTIrQtSWEQecX265bLmKb/RPYTOAt7nmKHujVJQ6A6sIWt55iBm3vO2izZesbB4 x95e8d5rgixkFsfc0F4oqQifPzAFuSqRbWKLcnYXDljKbcai/Fvrd/uQ6Oog== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1673044315; x=1673130715; bh=ZsG681Pan5CKaukkBdKOCNuqBF9W uoTwPInsMRA5Jvw=; b=mUHHxCzISNevnvH8fxu8sc3D8JiLLOuy/eEBP0aCi6Z0 eRymmdb8U8JSgIwEsrRQBu5U2LI5KP4saU4p9owK3ht0fI4zsgVyjqrrmiq5Ub8W rAx+1XhKjeGsI2RBltZOTUU+IS8+WdEpn8j/d2R1rcSwLjIQNUoE+OR9QY0KiYuT 4ayMJRu63wh1T4T8gTlpBa6S4Zw3uvlvCeUpPqdKStagu/L/YWYPzLb+hn9r9fAp LdcuEoO0BvEMQsNZt1sBhXqD9aW8OBqRF/7EgYNGsq6cIrqFOAeuEzDOfOGj4bWu mETFBe9r5vCMupzA4DCP8uxArjwTHErdCWbLVZ7Vww== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrkedtgdduiedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehr nhguuceuvghrghhmrghnnhdfuceorghrnhgusegrrhhnuggsrdguvgeqnecuggftrfgrth htvghrnhepffehueegteeihfegtefhjefgtdeugfegjeelheejueethfefgeeghfektdek teffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hrnhgusegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 01B77B60086; Fri, 6 Jan 2023 17:31:52 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1185-g841157300a-fm-20221208.002-g84115730 Mime-Version: 1.0 Message-Id: <6f7d06ef-d74d-4dfc-9b77-6ae83e0d7816@app.fastmail.com> In-Reply-To: <20230106185526.260163-2-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230106185526.260163-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20230106185526.260163-2-prabhakar.mahadev-lad.rj@bp.renesas.com> Date: Fri, 06 Jan 2023 23:31:33 +0100 From: "Arnd Bergmann" To: Prabhakar , "Conor.Dooley" , "Geert Uytterhoeven" , =?UTF-8?Q?Heiko_St=C3=BCbner?= , guoren , "Andrew Jones" , "Paul Walmsley" , "Palmer Dabbelt" , "Albert Ou" , "open list:RISC-V ARCHITECTURE" , "open list" Cc: devicetree@vger.kernel.org, Linux-Renesas , "Lad, Prabhakar" , "Philipp Tomsich" , "Nathan Chancellor" , "Atish Patra" , "Anup Patel" , "Tsukasa OI" , "Jisheng Zhang" , "Mayuresh Chitale" Subject: Re: [RFC PATCH v6 1/6] riscv: mm: dma-noncoherent: Switch using function pointers for cache management Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 On Fri, Jan 6, 2023, at 19:55, Prabhakar wrote: > From: Lad Prabhakar > > The current implementation of CMO was handled using the ALTERNATIVE_X() > macro; this was manageable when there were a limited number of platforms > using this. Now that we are having more and more platforms coming through > with the CMO the use of the ALTERNATIVE_X() macro becomes unmanageable. > > To avoid such issues this patch switches to use of function pointers > instead of ALTERNATIVE_X() macro for cache management (the only draw being > performance over the previous approach). > > void (*clean_range)(unsigned long addr, unsigned long size); > void (*inv_range)(unsigned long addr, unsigned long size); > void (*flush_range)(unsigned long addr, unsigned long size); > > The above function pointers are provided to be overridden where platforms > using standard approach and for platforms who want handle the operation > based on the operation the below function pointer is provided: > > void (*riscv_dma_noncoherent_cmo_ops)(void *vaddr, size_t size, > enum dma_data_direction dir, > enum dma_noncoherent_ops ops); > > In the current patch we have moved the ZICBOM and T-Head CMO to use > function pointers. > > Signed-off-by: Lad Prabhakar This looks like a nice improvement! I have a few suggestions for improvements, but no objections here. > diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c > index fac5742d1c1e..826b2ba3e61e 100644 > --- a/arch/riscv/errata/thead/errata.c > +++ b/arch/riscv/errata/thead/errata.c ... > @@ -44,6 +106,15 @@ static bool errata_probe_cmo(unsigned int stage, > > riscv_cbom_block_size = L1_CACHE_BYTES; > riscv_noncoherent_supported(); > + > + memset(&thead_cmo_ops, 0x0, sizeof(thead_cmo_ops)); > + if (IS_ENABLED(CONFIG_ERRATA_THEAD_CMO)) { > + thead_cmo_ops.clean_range = &thead_cmo_clean_range; > + thead_cmo_ops.inv_range = &thead_cmo_inval_range; > + thead_cmo_ops.flush_range = &thead_cmo_flush_range; > + riscv_noncoherent_register_cache_ops(&thead_cmo_ops); > + } The implementation here looks reasonable, just wonder whether the classification as an 'errata' makes sense. I would probably consider this a 'driver' at this point, but that's just a question of personal preference. For the operations structure, I think a 'static const struct riscv_cache_ops' is more intuitive than assigning the members individually. > + > +enum dma_noncoherent_ops { > + NON_COHERENT_SYNC_DMA_FOR_DEVICE = 0, > + NON_COHERENT_SYNC_DMA_FOR_CPU, > + NON_COHERENT_DMA_PREP, > + NON_COHERENT_DMA_PMEM, > +}; > + > +/* > + * struct riscv_cache_ops - Structure for CMO function pointers > + * @clean_range: Function pointer for clean cache > + * @inv_range: Function pointer for invalidate cache > + * @flush_range: Function pointer for flushing the cache > + * @riscv_dma_noncoherent_cmo_ops: Function pointer for platforms who > want > + * to handle CMO themselves. If this function pointer is set rest of > the > + * function pointers will be NULL. > + */ > +struct riscv_cache_ops { > + void (*clean_range)(unsigned long addr, unsigned long size); > + void (*inv_range)(unsigned long addr, unsigned long size); > + void (*flush_range)(unsigned long addr, unsigned long size); > + void (*riscv_dma_noncoherent_cmo_ops)(void *vaddr, size_t size, > + enum dma_data_direction dir, > + enum dma_noncoherent_ops ops); > +}; I don't quite see how the fourth operation is used here. Are there cache controllers that need something beyond clean/inv/flush? > + > +#else > + > +static void riscv_noncoherent_register_cache_ops(struct > riscv_cache_ops *ops) {} > + > +static inline void riscv_dma_noncoherent_clean(void *vaddr, size_t > size) {} > + > +static inline void riscv_dma_noncoherent_flush(void *vaddr, size_t > size) {} > + > +static inline void riscv_dma_noncoherent_inval(void *vaddr, size_t > size) {} I think you can drop the #else path here: if there is no noncoherent DMA, then nothing should ever call these functions, right? > + > +#ifdef CONFIG_RISCV_ISA_ZICBOM ... > +struct riscv_cache_ops zicbom_cmo_ops = { > + .clean_range = &zicbom_cmo_clean_range, > + .inv_range = &zicbom_cmo_inval_range, > + .flush_range = &zicbom_cmo_flush_range, > +}; > +#else > +struct riscv_cache_ops zicbom_cmo_ops = { > + .clean_range = NULL, > + .inv_range = NULL, > + .flush_range = NULL, > + .riscv_dma_noncoherent_cmo_ops = NULL, > +}; > +#endif > +EXPORT_SYMBOL(zicbom_cmo_ops); Same here: If the ZICBOM ISA is disabled, nothing should reference zicbom_cmo_ops. Also, since ZICBOM is a standard extension, I think it makes sense to always have it enabled, at least whenever noncoherent DMA is supported, that way it can be the default that gets used in the absence of any nonstandard cache controller. Arnd