Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14776201rwb; Mon, 28 Nov 2022 05:01:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5vmjhCj80J4Rsk8o6jDC0h4W7alsZL4pgKeEZsJdwgZ3qxuxSRv/okLZ2dn2B/dUml0E8h X-Received: by 2002:a63:1f21:0:b0:476:ea6e:fcbe with SMTP id f33-20020a631f21000000b00476ea6efcbemr45156142pgf.108.1669640496247; Mon, 28 Nov 2022 05:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669640496; cv=none; d=google.com; s=arc-20160816; b=ZJl02U6Bgku/XT1M05QiSkeQEv5Pv8Stdz8Fu9uCYMHgczVaJMwJ5Psd8ZQoWnOgJK AnkGV2du/huQv6Y8MzAIJXUcX88eGdDiu0XCQ57qYYh0arBagQrfPJBPkJkqESsbJBeF hDtpF+LyFdn3AoLEagNSkkFBK/bNnXMOroEi2tQ326kuEJDVMfCKvlGXM86aypwmV7F+ nNCUdr/C7+3QtcI5IMG1V0UU7rAGVD+gkq8AcVthmUS0v7iE+Jq0RbedR9rQIN/jf0yF L9+oL6hQD+6w6OpwiOJjZmwZXf8UCRxNX/dKX+/KoIFJHgxNeNRPkYcVuXeOuFoTz1NU k28A== 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=R+LQlj7xgpzysitHuN8QQ6CAzeMP7xdAT3qKXB4PYg8=; b=vaOBdFOMG9o8+vfYPmzc8a+Xef+olxCcS+0MGVNmF95DSX1UYYNkkVjtyu0HBg5gmd heCBhwFYhH97xbWBqW99VbqIJrfW8KPXm888vd3vebbrDQKAjC/O+/zpG0p+I+LBOI8T J/BBPRTFzlUL2nDuOMnKG3tUcDWrKoYxKM3GDJgdKiWCFsoIZDWi72vZ+uc3ioJYSyiy 7MA8tyYoBNaETIze7Jg08Uay8Fw82vfBmI7orfKstRqCr52sC4mQr5+OqVHDYyjfYGgT 6QU2lAyaQyBuLr8CAv1OkDSont65jhGJwe1nmcetP1ok1fJWnCEksz1mQvjVkJWMMTEu cTig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=T557FQNj; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14-20020a637a0e000000b0046f583c8c4asi12790121pgc.315.2022.11.28.05.01.01; Mon, 28 Nov 2022 05:01:36 -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=@gmail.com header.s=20210112 header.b=T557FQNj; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbiK1MRz (ORCPT + 84 others); Mon, 28 Nov 2022 07:17:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbiK1MR2 (ORCPT ); Mon, 28 Nov 2022 07:17:28 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0C51EC46; Mon, 28 Nov 2022 04:08:42 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id ud5so25243083ejc.4; Mon, 28 Nov 2022 04:08:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=R+LQlj7xgpzysitHuN8QQ6CAzeMP7xdAT3qKXB4PYg8=; b=T557FQNjTVqcQOajSa+tqlb3v2VcbLQdUR5oEF8sRgBv4KpD9q5lv66/LsoQxTI1QD VRL80QCcumabZVPr0ajn4eqPVxQ+3Bb4C3v1N3O5ygkpzQE+mY6PvGDW9aKgP5UWn3L6 hquZ8rbMqEolm01p0qR4Vczv8Jn/+kO4TIvvokceNwyKgL0XJHLv66Jko7IhhHMXc5vE wXTXbRE6lYKXItc5AEkJN0zvvaWn2Fk89PYzenMeMeEKxNqDvgi791M7KkoH8y0rl0BK sNK4rNpG3Xqx2BxRO4ATvP0gnhU9DT1gHcb1qdUrXyQwKcSYQiskXAb2ckfdDPuHLpKx oFLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=R+LQlj7xgpzysitHuN8QQ6CAzeMP7xdAT3qKXB4PYg8=; b=zleUURx/XXHgdamHv4/KbXmNqDOtpVlpSXYxY2KNy9Mo4MUKcWP33Y/T84oxsVwb4L 45kvOogfGQJC9olLn7GylK+/+CCAEp8z5M9ABGdMRLxMwlIvISoJpDIcbvRfcfacDD47 43V5edrblW/sbI1CNn0q8K3RmbJlGSZu936myYjpkf57f2M3j6YOqDX0g9ULmBsZJQvU c3DTHkcqFt46m4N+3sCRFOCNyh2KsMvbENlGjciXUkXeeJ5dfgkHLZCxKFEKTit6gcNM 7MeTkStBF/EU6GNFD05pBbp0byhOui2kgrQLm9NGQ8BfjRjS1ef33FyzhMBi26Dnz8tZ WCfw== X-Gm-Message-State: ANoB5pluVMaTOuJMbiRexbmDyYL67ZBBPt3QmMCh3Ka1ZWHAvpZy3Z87 4d27tX3uZVlnTFTSyiCnQPtHzyb2p/dh8gIrNGw= X-Received: by 2002:a17:907:9895:b0:7c0:7db3:82e3 with SMTP id ja21-20020a170907989500b007c07db382e3mr1223559ejc.480.1669637320781; Mon, 28 Nov 2022 04:08:40 -0800 (PST) MIME-Version: 1.0 References: <20221124172207.153718-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20221124172207.153718-8-prabhakar.mahadev-lad.rj@bp.renesas.com> In-Reply-To: From: "Lad, Prabhakar" Date: Mon, 28 Nov 2022 12:08:14 +0000 Message-ID: Subject: Re: [PATCH v4 7/7] soc: renesas: Add L2 cache management for RZ/Five SoC To: Geert Uytterhoeven Cc: Samuel Holland , opensbi@lists.infradead.org, Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Geert Uytterhoeven , Magnus Damm , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Guo Ren , Jisheng Zhang , Atish Patra , Andrew Jones , Nathan Chancellor , Philipp Tomsich , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-renesas-soc@vger.kernel.org, Biju Das , Lad Prabhakar Content-Type: text/plain; charset="UTF-8" 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_NONE,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 Geert, On Sun, Nov 27, 2022 at 9:55 AM Geert Uytterhoeven wrote: > > Hi Prabhakar, > > On Sat, Nov 26, 2022 at 10:10 PM Lad, Prabhakar > wrote: > > On Fri, Nov 25, 2022 at 7:43 PM Samuel Holland wrote: > > > On 11/24/22 11:22, Prabhakar wrote: > > > > From: Lad Prabhakar > > > > > > > > On the AX45MP core, cache coherency is a specification option so it may > > > > not be supported. In this case DMA will fail. As a workaround, firstly we > > > > allocate a global dma coherent pool from which DMA allocations are taken > > > > and marked as non-cacheable + bufferable using the PMA region as specified > > > > in the device tree. Synchronization callbacks are implemented to > > > > synchronize when doing DMA transactions. > > > > > > > > The Andes AX45MP core has a Programmable Physical Memory Attributes (PMA) > > > > block that allows dynamic adjustment of memory attributes in the runtime. > > > > It contains a configurable amount of PMA entries implemented as CSR > > > > registers to control the attributes of memory locations in interest. > > > > > > > > Below are the memory attributes supported: > > > > * Device, Non-bufferable > > > > * Device, bufferable > > > > * Memory, Non-cacheable, Non-bufferable > > > > * Memory, Non-cacheable, Bufferable > > > > * Memory, Write-back, No-allocate > > > > * Memory, Write-back, Read-allocate > > > > * Memory, Write-back, Write-allocate > > > > * Memory, Write-back, Read and Write-allocate > > > > > > > > This patch adds support to configure the memory attributes of the memory > > > > regions as passed from the l2 cache node and exposes the cache management > > > > ops. > > > > > > Forgive my ignorance, but why do you need both a DMA pool and explicit > > > cache maintenance? Wouldn't the purpose of marking a memory region as > > > permanently non-cacheable be to avoid cache maintenance? And likewise, > > > if you are doing cache maintenance anyway, why does it matter if/how the > > > memory is cacheable? > > > > > "Memory, Non-cacheable, Bufferable" raises an AXI signal for > > transactions hence needing SW implementation for cache maintenance. > > > > > > More info about PMA (section 10.3): > > > > Link: http://www.andestech.com/wp-content/uploads/AX45MP-1C-Rev.-5.0.0-Datasheet.pdf > > > > > > > > Signed-off-by: Lad Prabhakar > > > > > +static int ax45mp_configure_pma_regions(struct device_node *np) > > > > +{ > > > > + const char *propname = "andestech,pma-regions"; > > > > + u32 start, size, flags; > > > > + unsigned int entry_id; > > > > + unsigned int i; > > > > + int count; > > > > + int ret; > > > > + > > > > + count = of_property_count_elems_of_size(np, propname, sizeof(u32) * 3); > > > > + if (count < 0) > > > > + return count; > > > > + > > > > + if (count > AX45MP_MAX_PMA_REGIONS) > > > > + return -EINVAL; > > > > + > > > > + for (i = 0, entry_id = 0 ; entry_id < count ; i += 3, entry_id++) { > > > > + of_property_read_u32_index(np, propname, i, &start); > > > > + of_property_read_u32_index(np, propname, i + 1, &size); > > > > + of_property_read_u32_index(np, propname, i + 2, &flags); > > > > + ret = ax45mp_sbi_set_pma(start, size, flags, entry_id); > > > > + if (!ret) > > > > + pr_err("Failed to setup PMA region 0x%x - 0x%x flags: 0x%x", > > > > + start, start + size, flags); > > > > + } > > > > + > > > > + return 0; > > > > +} > > > > > > If firmware support is required to set up these PMA regions, why is > > > Linux doing this at all? The firmware has access to the devicetree as > > > well. It can set this up before entering S-mode, and then you don't need > > > to expose this capability via an SBI extension. In fact, firmware could > > > generate the reserved-memory node based on these regions at runtime (or > > > vice versa). > > > > > That's a good point. I'll do some research on this and get back. > > > > Btw are there any existing examples where the firmware adds DT nodes? > > /memory, reserved-memory, optee on ARM, RPC status on R-Car Gen3/4, ... > On the TF-A we pass the FDT blob to u-boot and this does the magic. On the RISC-V what would be the correct approach? - We setup the PMA regions in OpenSBI - We provide a vendor specific EXT to check if the PMA is setup - In u-boot ft_board_setup() callback add the reserved-memory node Does the above approach sound good or is there a better approach I'm missing? Cheers, Prabhakar