From nobody Mon Feb 9 14:02:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3592C001DE for ; Sun, 2 Jul 2023 20:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbjGBUez (ORCPT ); Sun, 2 Jul 2023 16:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjGBUew (ORCPT ); Sun, 2 Jul 2023 16:34:52 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5447BE4D; Sun, 2 Jul 2023 13:34:51 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3142a9ff6d8so1880841f8f.3; Sun, 02 Jul 2023 13:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688330090; x=1690922090; 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=ID8kESIcXo+JBd9ohyZe9IZLbyTyjD8SbfRbMI5qFEo=; b=BAuhXWyxUV9jb2UkRQTf9DPJNkmILjxCO5NWyiVZ/O2FX1ngphoU4v2czSJDx8AItf lvxD8Lxu1jXc22ZXwp5l8kNG9BwtcfNp0yltgOOqN7jdtr0PNWgFiCsbCt3zl+jjnqdf Tx4BxoJM357CkqkNVVkHnv/04rd2KR41O2XYeJwJRzs/KrSyqiNCBaA/ayPqzHRPYsPG dG/v8xp2+K9hQGRuw3+5hXcZFm66D368KDRr6KVqwDy990c8d0HwleuPNP04BtzfGmna ZaWZCg8Bp3ZTCVq23Z6WvP2z9DbpSb4nJO+QmnbYP2mEa4UvckUsRIP4bljz2xOoQhjD wXXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688330090; x=1690922090; 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=ID8kESIcXo+JBd9ohyZe9IZLbyTyjD8SbfRbMI5qFEo=; b=NMXqsMT7iVM57B1jKJO9+TAcl7BIQhAHqYs3gaF1d9zhL2XDpKmh10znesxTYhlp+1 q1lvwn9hFy3nsVfbiWqkV/mU6Cb7HAtNg3QCRT0hGWmMPtziFvMSjIdyEDVeKdCUXFdw t6cCugRqpL7pPZa1LcW0P3SoyzTYFwG8/zRzgURDuiDWTh+ouS6hwpYaGMbGvR6Kh3tG 8hoduAWonrfvy/9XFjy4U9I/bYgHTdkjUt7+ado/5U35xIrGFcUjrGSiw02Oa1U63o/R H+KIfLo6Oc/WcoRhtG//zg57l82vUpR2DovcGmun1ivFgMvtaXplJpImDELNjmJf9ue1 c/fw== X-Gm-Message-State: ABy/qLYp08y+0l0hhsbGVWJcegzd3rEJu1H21o2ZxMCksw+L1vMpWkEY gTNHvvxH1/m+1utolsszCF8= X-Google-Smtp-Source: APBJJlF/U8GeITsUI1y3/TsqaILmZuxoWDfflBDvjfxNDCBS2XuisYyt26PsVfIBN97jJ0wEbKaJhg== X-Received: by 2002:adf:fc08:0:b0:314:824:378c with SMTP id i8-20020adffc08000000b003140824378cmr6798565wrr.20.1688330089839; Sun, 02 Jul 2023 13:34:49 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:b4ae:ae48:2e1b:1dcd]) by smtp.gmail.com with ESMTPSA id f1-20020a5d5681000000b0030647449730sm24000478wrv.74.2023.07.02.13.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 13:34:49 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: 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 Cc: Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar , Heiko Stuebner Subject: [PATCH v10 1/6] riscv: asm: vendorid_list: Add Andes Technology to the vendors list Date: Sun, 2 Jul 2023 21:34:24 +0100 Message-Id: <20230702203429.237615-2-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Add Andes Technology to the vendors list. Signed-off-by: Lad Prabhakar Reviewed-by: Heiko Stuebner Reviewed-by: Conor Dooley Reviewed-by: Geert Uytterhoeven Tested-by: Conor Dooley # tyre-kicking on a d1 --- v9 -> v10 * Included TB tag from Conor v8 -> v9 * Included RB tag from Geert v7 -> v8 * No change v6 -> v7 * No change v5 -> v6 * No change v4 -> v5 * Included RB tags RFC v3 -> v4 * New patch --- arch/riscv/include/asm/vendorid_list.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/include/asm/vendorid_list.h b/arch/riscv/include/as= m/vendorid_list.h index cb89af3f0704..e55407ace0c3 100644 --- a/arch/riscv/include/asm/vendorid_list.h +++ b/arch/riscv/include/asm/vendorid_list.h @@ -5,6 +5,7 @@ #ifndef ASM_VENDOR_LIST_H #define ASM_VENDOR_LIST_H =20 +#define ANDESTECH_VENDOR_ID 0x31e #define SIFIVE_VENDOR_ID 0x489 #define THEAD_VENDOR_ID 0x5b7 =20 --=20 2.34.1 From nobody Mon Feb 9 14:02:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A8D4EB64D9 for ; Sun, 2 Jul 2023 20:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230201AbjGBUe6 (ORCPT ); Sun, 2 Jul 2023 16:34:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbjGBUex (ORCPT ); Sun, 2 Jul 2023 16:34:53 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D8D3E6; Sun, 2 Jul 2023 13:34:52 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-312824aa384so4163631f8f.1; Sun, 02 Jul 2023 13:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688330091; x=1690922091; 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=bBA4mxMo21nxV3389WkUubCwMwiWrbVQrJuncENzqoM=; b=h0K5X4E/BX9EG9FUinKp5BGjaldwdJwJXJ0rGTIji1HrcsyOxr4Iu0DIUAHL1MRuaH 5d8DfWAD9CfZkfcNTe77nJplZ+7zQR/cvXMo6rIUHycjbo6AefR9PpowTI5eAc0jlE1f 57UnNbsdDGGgq+1T/feQW6Rmfmutcn5YlEVJYwrq83S2IqS8P0i4JCmoACAp+UX/QDIf myeH9Gw29fp3yO8j3gE/PlpKHplloE+86vpQ2DllB35V18MGnsIiKJ2/ryp5VuFItTM0 F51XPT5WWUWyszw9cX6L4QcpYc8qnzXMMx25A9S8DHieCZKdGtqDweEcC9rNyUfZc8Zn cc7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688330091; x=1690922091; 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=bBA4mxMo21nxV3389WkUubCwMwiWrbVQrJuncENzqoM=; b=haiw9pr6Rw5Eyi53WhPR/EohhfFbtYxLuUN70lJJ8qyvOI6HUxNHaMo4ljH+eyZDOM SQnKNubyRMT8r3cLRbCw3jVEdKUhynsvz3OkIaSx8EkFtD3nDtCeQDIPmN4wst0Soqkp N3TDblj/h6Ir3gR2ceg3Q5YhDxF9eAO24kADCA6OFTuAyZcmwFLBk6fAmQA0JjIJAzXF f0UPlQggK0J7Zc/hiLQTlopQZaSacedZkjUteGwvJ7wYxaRWBBe+6G9bRaHlyrS54O+k WKKhuYZrolt55Nojuet7OU6FkS8VMGRchBdx2gTNK4wDirk/idT0D+adrBJMQhNDZyaO llkg== X-Gm-Message-State: ABy/qLYJOFMhWtwkwQwtGY9dfOfyTEFVVnizY37afeu3KvN2cx0qxyjf GjwWoJmwoOizbQNkbO4cUNqUomL95fRU3g== X-Google-Smtp-Source: APBJJlEvws3JsnEhaAg/cod4oQJtWJnlJc8JT+wwaZSN7WlaNjKWPIfRMWxGvdIDdcsIspJ+C/zdzg== X-Received: by 2002:adf:ee51:0:b0:313:fbd0:9810 with SMTP id w17-20020adfee51000000b00313fbd09810mr7166168wro.4.1688330090869; Sun, 02 Jul 2023 13:34:50 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:b4ae:ae48:2e1b:1dcd]) by smtp.gmail.com with ESMTPSA id f1-20020a5d5681000000b0030647449730sm24000478wrv.74.2023.07.02.13.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 13:34:50 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: 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 Cc: Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [PATCH v10 2/6] riscv: errata: Add Andes alternative ports Date: Sun, 2 Jul 2023 21:34:25 +0100 Message-Id: <20230702203429.237615-3-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Add required ports of the Alternative scheme for Andes CPU cores. I/O Coherence Port (IOCP) provides an AXI interface for connecting external non-caching masters, such as DMA controllers. IOCP is a specification option and is disabled on the Renesas RZ/Five SoC due to this reason cache management needs a software workaround. Signed-off-by: Lad Prabhakar Reviewed-by: Conor Dooley Tested-by: Conor Dooley # tyre-kicking on a d1 --- v9 -> v10 * Included TB tag from Conor v8 -> v9 * Rebased to code on Palmer's for/next * Dropped calling patch_text_nosync() as dont use patch_text_nosync() call v7 -> v8 * Now patching the code using patch_text_nosync() and riscv_alternative_fix= _offsets() v6 -> v7 * Renamed RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND -> ANDES_SBI_EXT_IOCP_SW_WORKAR= OUND * Dropped "depends on !XIP_KERNEL" for ERRATA_ANDES config v5 -> v6 * Dropped patching alternative and now just probing IOCP v4 -> v5 * Sorted the Kconfig/Makefile/Switch based on Core name * Added a comments * Introduced RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND SBI EXT ID to check if CMO needs to be applied. Is there a way we can access the DTB while patch= ing as we can drop this SBI EXT ID and add a DT property instead for cmo? RFC v3 -> v4 * New patch --- arch/riscv/Kconfig.errata | 21 +++++++++ arch/riscv/errata/Makefile | 1 + arch/riscv/errata/andes/Makefile | 1 + arch/riscv/errata/andes/errata.c | 66 ++++++++++++++++++++++++++++ arch/riscv/include/asm/alternative.h | 3 ++ arch/riscv/include/asm/errata_list.h | 5 +++ arch/riscv/kernel/alternative.c | 5 +++ 7 files changed, 102 insertions(+) create mode 100644 arch/riscv/errata/andes/Makefile create mode 100644 arch/riscv/errata/andes/errata.c diff --git a/arch/riscv/Kconfig.errata b/arch/riscv/Kconfig.errata index 0c8f4652cd82..92c779764b27 100644 --- a/arch/riscv/Kconfig.errata +++ b/arch/riscv/Kconfig.errata @@ -1,5 +1,26 @@ menu "CPU errata selection" =20 +config ERRATA_ANDES + bool "Andes AX45MP errata" + depends on RISCV_ALTERNATIVE + help + All Andes errata Kconfig depend on this Kconfig. Disabling + this Kconfig will disable all Andes errata. Please say "Y" + here if your platform uses Andes CPU cores. + + Otherwise, please say "N" here to avoid unnecessary overhead. + +config ERRATA_ANDES_CMO + bool "Apply Andes cache management errata" + depends on ERRATA_ANDES && MMU && ARCH_R9A07G043 + select RISCV_DMA_NONCOHERENT + default y + help + This will apply the cache management errata to handle the + non-standard handling on non-coherent operations on Andes cores. + + If you don't know what to do here, say "Y". + config ERRATA_SIFIVE bool "SiFive errata" depends on RISCV_ALTERNATIVE diff --git a/arch/riscv/errata/Makefile b/arch/riscv/errata/Makefile index 7b2637c8c332..8a2739485123 100644 --- a/arch/riscv/errata/Makefile +++ b/arch/riscv/errata/Makefile @@ -2,5 +2,6 @@ ifdef CONFIG_RELOCATABLE KBUILD_CFLAGS +=3D -fno-pie endif =20 +obj-$(CONFIG_ERRATA_ANDES) +=3D andes/ obj-$(CONFIG_ERRATA_SIFIVE) +=3D sifive/ obj-$(CONFIG_ERRATA_THEAD) +=3D thead/ diff --git a/arch/riscv/errata/andes/Makefile b/arch/riscv/errata/andes/Mak= efile new file mode 100644 index 000000000000..2d644e19caef --- /dev/null +++ b/arch/riscv/errata/andes/Makefile @@ -0,0 +1 @@ +obj-y +=3D errata.o diff --git a/arch/riscv/errata/andes/errata.c b/arch/riscv/errata/andes/err= ata.c new file mode 100644 index 000000000000..197db68cc8da --- /dev/null +++ b/arch/riscv/errata/andes/errata.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Erratas to be applied for Andes CPU cores + * + * Copyright (C) 2023 Renesas Electronics Corporation. + * + * Author: Lad Prabhakar + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define ANDESTECH_AX45MP_MARCHID 0x8000000000008a45UL +#define ANDESTECH_AX45MP_MIMPID 0x500UL +#define ANDESTECH_SBI_EXT_ANDES 0x0900031E + +#define ANDES_SBI_EXT_IOCP_SW_WORKAROUND 1 + +static long ax45mp_iocp_sw_workaround(void) +{ + struct sbiret ret; + + /* + * ANDES_SBI_EXT_IOCP_SW_WORKAROUND SBI EXT checks if the IOCP is missing= and + * cache is controllable only then CMO will be applied to the platform. + */ + ret =3D sbi_ecall(ANDESTECH_SBI_EXT_ANDES, ANDES_SBI_EXT_IOCP_SW_WORKAROU= ND, + 0, 0, 0, 0, 0, 0); + + return ret.error ? 0 : ret.value; +} + +static bool errata_probe_iocp(unsigned int stage, unsigned long arch_id, u= nsigned long impid) +{ + if (!IS_ENABLED(CONFIG_ERRATA_ANDES_CMO)) + return false; + + if (arch_id !=3D ANDESTECH_AX45MP_MARCHID || impid !=3D ANDESTECH_AX45MP_= MIMPID) + return false; + + if (!ax45mp_iocp_sw_workaround()) + return false; + + /* Set this just to make core cbo code happy */ + riscv_cbom_block_size =3D 1; + riscv_noncoherent_supported(); + + return true; +} + +void __init_or_module andes_errata_patch_func(struct alt_entry *begin, str= uct alt_entry *end, + unsigned long archid, unsigned long impid, + unsigned int stage) +{ + errata_probe_iocp(stage, archid, impid); + + /* we have nothing to patch here ATM so just return back */ +} diff --git a/arch/riscv/include/asm/alternative.h b/arch/riscv/include/asm/= alternative.h index 6a41537826a7..f6cfca939c92 100644 --- a/arch/riscv/include/asm/alternative.h +++ b/arch/riscv/include/asm/alternative.h @@ -46,6 +46,9 @@ struct alt_entry { u32 patch_id; /* The patch ID (erratum ID or cpufeature ID) */ }; =20 +void andes_errata_patch_func(struct alt_entry *begin, struct alt_entry *en= d, + unsigned long archid, unsigned long impid, + unsigned int stage); void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *e= nd, unsigned long archid, unsigned long impid, unsigned int stage); diff --git a/arch/riscv/include/asm/errata_list.h b/arch/riscv/include/asm/= errata_list.h index fb1a810f3d8c..e2ecd01bfac7 100644 --- a/arch/riscv/include/asm/errata_list.h +++ b/arch/riscv/include/asm/errata_list.h @@ -11,6 +11,11 @@ #include #include =20 +#ifdef CONFIG_ERRATA_ANDES +#define ERRATA_ANDESTECH_NO_IOCP 0 +#define ERRATA_ANDESTECH_NUMBER 1 +#endif + #ifdef CONFIG_ERRATA_SIFIVE #define ERRATA_SIFIVE_CIP_453 0 #define ERRATA_SIFIVE_CIP_1200 1 diff --git a/arch/riscv/kernel/alternative.c b/arch/riscv/kernel/alternativ= e.c index 6b75788c18e6..b0345992a35e 100644 --- a/arch/riscv/kernel/alternative.c +++ b/arch/riscv/kernel/alternative.c @@ -45,6 +45,11 @@ static void riscv_fill_cpu_mfr_info(struct cpu_manufactu= rer_info_t *cpu_mfr_info =20 cpu_mfr_info->feature_probe_func =3D NULL; switch (cpu_mfr_info->vendor_id) { +#ifdef CONFIG_ERRATA_ANDES + case ANDESTECH_VENDOR_ID: + cpu_mfr_info->patch_func =3D andes_errata_patch_func; + break; +#endif #ifdef CONFIG_ERRATA_SIFIVE case SIFIVE_VENDOR_ID: cpu_mfr_info->patch_func =3D sifive_errata_patch_func; --=20 2.34.1 From nobody Mon Feb 9 14:02:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 679ECC04A94 for ; Sun, 2 Jul 2023 20:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbjGBUfG (ORCPT ); Sun, 2 Jul 2023 16:35:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbjGBUez (ORCPT ); Sun, 2 Jul 2023 16:34:55 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0F931BB; Sun, 2 Jul 2023 13:34:53 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-313f3a6db22so4359502f8f.3; Sun, 02 Jul 2023 13:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688330092; x=1690922092; 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=HcexdVQPBw2rdGBbBDTUXB1gr2v058VsgGzEZRfGeYk=; b=W8dcPNYnPZAWz3dYwbstWsoxXj+8ieIe2ZACK45R6iQD9OdL3Gy2TO0CWBtp1kxaDa vTRHRwAEprccmKG8vy38zpgvzWFypTDDA8GovnGn/eeSyIJ4Ckc+ithLylcmW+GVBODd R2eUS1peu6eFmEuYpa+3QuCcjNXdGV15ufgf3vgpd07a87ptdodxyMMCMwGD1l+6F6d3 oYKsBWv3LS2nVapLuMJvMFP9ieN95Mol4ZMQhxvAoGSGGLN7gTyb1sUDJ7MRkyPT6Ci+ N8kalFqhyDwpEFX0S3S4hXcituOGzj+Gra5Hmu0HOCbH1EM2YwcR1Lw6pGLjptCx8+pw FUfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688330092; x=1690922092; 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=HcexdVQPBw2rdGBbBDTUXB1gr2v058VsgGzEZRfGeYk=; b=hxG8BoHmp8DNJOHocvOXtgrhLSMqjti1cT5dbyvaMYOgodut+TQX18gHswweZ1MbRH CM89aF+hrrhrtRgm3OYPPhS3ymryBUF7OTE4uDGzpZcJ2tG87x26BQBjd3KANZvShO5V htl+JewDhVecY7T75r+Z6GKxFsTojc+0vKINIlQDzTV50zuiiMxl8rF6C5eL+YYH0cgf yWfgmUMiXw2/yWJ9GZazWM3DCaO7MdocIXz5JCX2/QrD9GlJuqbAkxgkyli5hRycctTl 8eo1mJ18OF35//7PdLABHIkPROJQ/Z7aqLkLyJ0qwg6ccy50qsXazm4eQt+0XfrVWkWK b07w== X-Gm-Message-State: ABy/qLZ+w7S3SQmajzBdxef+iH338WhWN833r6VPmmtVLx4pZcpTw0x8 uF9GJ6KuV7J+yRUUWHMJm9U= X-Google-Smtp-Source: APBJJlG42eS96skXsOTDvhF78VPlj2Mt2tn2mqA2+pz+TVnhqMqFgowZn5j4VbBKwM4H2pSg0/GMxA== X-Received: by 2002:adf:e9c2:0:b0:313:fff0:ff44 with SMTP id l2-20020adfe9c2000000b00313fff0ff44mr8062417wrn.38.1688330091931; Sun, 02 Jul 2023 13:34:51 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:b4ae:ae48:2e1b:1dcd]) by smtp.gmail.com with ESMTPSA id f1-20020a5d5681000000b0030647449730sm24000478wrv.74.2023.07.02.13.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 13:34:51 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: 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 Cc: Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [PATCH v10 3/6] riscv: mm: dma-noncoherent: nonstandard cache operations support Date: Sun, 2 Jul 2023 21:34:26 +0100 Message-Id: <20230702203429.237615-4-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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 d9e451ac862a..42c86b13c5e1 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -265,6 +265,13 @@ config RISCV_DMA_NONCOHERENT select ARCH_HAS_SYNC_DMA_FOR_DEVICE select DMA_DIRECT_REMAP =20 +config RISCV_NONSTANDARD_CACHE_OPS + bool + depends on RISCV_DMA_NONCOHERENT + help + This enables function pointer support for non-standard noncoherent + 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) =20 diff --git a/arch/riscv/include/asm/dma-noncoherent.h b/arch/riscv/include/= asm/dma-noncoherent.h new file mode 100644 index 000000000000..969cf1f1363a --- /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_cache_ops - Structure for CMO function pointers + * + * @wback: Function pointer for cache writeback + * @inv: Function pointer for invalidating cache + * @wback_inv: Function pointer for flushing the cache (writeback + invali= dating) + */ +struct riscv_cache_ops { + void (*wback)(phys_addr_t paddr, unsigned long size); + void (*inv)(phys_addr_t paddr, unsigned long size); + void (*wback_inv)(phys_addr_t paddr, unsigned long size); +}; + +extern struct riscv_cache_ops noncoherent_cache_ops; + +void riscv_noncoherent_register_cache_ops(const struct riscv_cache_ops *op= s); + +#endif /* __ASM_DMA_NONCOHERENT_H */ diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoheren= t.c index b9a9f57e02be..4c2e3f1cdfe6 100644 --- a/arch/riscv/mm/dma-noncoherent.c +++ b/arch/riscv/mm/dma-noncoherent.c @@ -9,13 +9,26 @@ #include #include #include +#include =20 static bool noncoherent_supported; =20 +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); =20 +#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); } =20 @@ -23,6 +36,13 @@ static inline void arch_dma_cache_inv(phys_addr_t paddr,= size_t size) { void *vaddr =3D phys_to_virt(paddr); =20 +#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); } =20 @@ -30,6 +50,13 @@ static inline void arch_dma_cache_wback_inv(phys_addr_t = paddr, size_t size) { void *vaddr =3D phys_to_virt(paddr); =20 +#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); } =20 @@ -50,6 +77,13 @@ void arch_dma_prep_coherent(struct page *page, size_t si= ze) { void *flush_addr =3D page_address(page); =20 +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS + if (unlikely(noncoherent_cache_ops.wback_inv)) { + noncoherent_cache_ops.wback_inv(page_to_phys(page), size); + return; + } +#endif + ALT_CMO_OP(flush, flush_addr, size, riscv_cbom_block_size); } =20 @@ -75,3 +109,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 *op= s) +{ + 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 =20 #include +#include =20 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); =20 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); --=20 2.34.1 From nobody Mon Feb 9 14:02:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA048EB64DD for ; Sun, 2 Jul 2023 20:35:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231367AbjGBUfJ (ORCPT ); Sun, 2 Jul 2023 16:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230126AbjGBUez (ORCPT ); Sun, 2 Jul 2023 16:34:55 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1578E4E; Sun, 2 Jul 2023 13:34:54 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3113da5260dso4139269f8f.2; Sun, 02 Jul 2023 13:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688330093; x=1690922093; 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=LaAnY2MYt0RLcMUJbL7J5suwKGVCMC1VbS7DigqvURE=; b=eiFrJewPOXpmbgCxu0MGAOK/yP08hkAJXGkhsXJChai9swwd2mULgbWQRFWK/1bXYX ypHFJ0ew9zdAB+2VagoBcwIN452aFLfic7sAXvNTM2RYNA4kR4sF2G96lBa+gKOJBfZr ceoto7mNjX+FxDrY8LQEWuLiwnOpq2ztMykf7+varARw+4vAVq5TJ5AjlqCnF0oMyNZ4 IF559ehbVw4JeFWn4vbp0HLoEtqByPDrKtFbnmfu3JWrOOVMAaag40SOhlkYkbhR9myw TT6DoBQNjncgUKb19I83RIjrO7CILEL8IrrannO3E2XnMR5OydeoYHiPK47ccLzgzwFO RpHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688330093; x=1690922093; 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=LaAnY2MYt0RLcMUJbL7J5suwKGVCMC1VbS7DigqvURE=; b=i0w+Mve5VTKXO1nuTn7jB3gwsJjDgvuuJJDXacTWNPXYyh5OeHiG3pU001PoN7jQ54 VsAsSUKOvdlV/mrmQlz5Dsjh7kTAxC7gZX73ciGxBJWG4b/dIQrAeVlZ9ZEzfFq3++IF SogdtM5bqXmfgr6wtFVbL8zu278A6Lnoy2gtsPL1KCeldqSKNrVdXfPhAv5rA+nkr5K2 +fmMz8BOrhfLw4mJGbpWS4AmHs7lac4r4oiRsgSeFECIJzPZKXAf0YHQRjcP5AcCeMIz UAlZACitxQb3JfVoOf5LkvJR6iA4xGCZg1lYpzd540X9+CHlQiRTzvCorJEFPYlMnhhy cHiA== X-Gm-Message-State: ABy/qLaIF5XlfnFGHFqQrT6nWQbWvliAwKFrmu34R8OHSO12aygCsK5z qzPm+9DZTtTaVxrnxXIWWbE= X-Google-Smtp-Source: APBJJlExfIi1htPAWuwGuJA3assg5RdUAYRwBkW1/5OraOyqze7LAGXwW8RLaFwvDI1798iteTb+3A== X-Received: by 2002:adf:e6ce:0:b0:313:ef96:84c8 with SMTP id y14-20020adfe6ce000000b00313ef9684c8mr6311811wrm.67.1688330093125; Sun, 02 Jul 2023 13:34:53 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:b4ae:ae48:2e1b:1dcd]) by smtp.gmail.com with ESMTPSA id f1-20020a5d5681000000b0030647449730sm24000478wrv.74.2023.07.02.13.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 13:34:52 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: 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 Cc: Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar , Rob Herring Subject: [PATCH v10 4/6] dt-bindings: cache: andestech,ax45mp-cache: Add DT binding documentation for L2 cache controller Date: Sun, 2 Jul 2023 21:34:27 +0100 Message-Id: <20230702203429.237615-5-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Add DT binding documentation for L2 cache controller found on RZ/Five SoC. The Renesas RZ/Five microprocessor includes a RISC-V CPU Core (AX45MP Single) from Andes. The AX45MP core has an L2 cache controller, this patch describes the L2 cache block. Signed-off-by: Lad Prabhakar Reviewed-by: Rob Herring Reviewed-by: Conor Dooley Tested-by: Conor Dooley # tyre-kicking on a d1 --- v9 -> v10 * No Change v8 -> v9 * No Change v7 -> v8 * Updated commit header message v6 -> v7 * No Change v5 -> v6 * Included RB tag from Rob v4 -> v5 * Dropped L2 cache configuration properties * Dropped PMA configuration properties * Ordered the required list to match the properties list RFC v3 -> v4 * Dropped l2 cache configuration parameters * s/larger/large * Added minItems/maxItems for andestech,pma-regions --- .../cache/andestech,ax45mp-cache.yaml | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Documentation/devicetree/bindings/cache/andestech,ax45m= p-cache.yaml diff --git a/Documentation/devicetree/bindings/cache/andestech,ax45mp-cache= .yaml b/Documentation/devicetree/bindings/cache/andestech,ax45mp-cache.yaml new file mode 100644 index 000000000000..9ab5f0c435d4 --- /dev/null +++ b/Documentation/devicetree/bindings/cache/andestech,ax45mp-cache.yaml @@ -0,0 +1,81 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright (C) 2023 Renesas Electronics Corp. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/cache/andestech,ax45mp-cache.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Andestech AX45MP L2 Cache Controller + +maintainers: + - Lad Prabhakar + +description: + A level-2 cache (L2C) is used to improve the system performance by provi= ding + a large amount of cache line entries and reasonable access delays. The L= 2C + is shared between cores, and a non-inclusive non-exclusive policy is use= d. + +select: + properties: + compatible: + contains: + enum: + - andestech,ax45mp-cache + + required: + - compatible + +properties: + compatible: + items: + - const: andestech,ax45mp-cache + - const: cache + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + cache-line-size: + const: 64 + + cache-level: + const: 2 + + cache-sets: + const: 1024 + + cache-size: + enum: [131072, 262144, 524288, 1048576, 2097152] + + cache-unified: true + + next-level-cache: true + +additionalProperties: false + +required: + - compatible + - reg + - interrupts + - cache-line-size + - cache-level + - cache-sets + - cache-size + - cache-unified + +examples: + - | + #include + + cache-controller@2010000 { + compatible =3D "andestech,ax45mp-cache", "cache"; + reg =3D <0x13400000 0x100000>; + interrupts =3D <508 IRQ_TYPE_LEVEL_HIGH>; + cache-line-size =3D <64>; + cache-level =3D <2>; + cache-sets =3D <1024>; + cache-size =3D <262144>; + cache-unified; + }; --=20 2.34.1 From nobody Mon Feb 9 14:02:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C80BCEB64D9 for ; Sun, 2 Jul 2023 20:35:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231979AbjGBUfN (ORCPT ); Sun, 2 Jul 2023 16:35:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230246AbjGBUfD (ORCPT ); Sun, 2 Jul 2023 16:35:03 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF274E54; Sun, 2 Jul 2023 13:34:55 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31438512cafso146448f8f.2; Sun, 02 Jul 2023 13:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688330094; x=1690922094; 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=zJjSJrFD46rql5SQeLkNxGE/SD7DDj1gOMvfywUg8kE=; b=DKYNThji4fHZYvAL5uJx15V2GgkZCF9YK9Rq31Zsd8kuUKdHofjX7ZSoh32NOaOmnb AomhXEqCRAwImMV+qbXVfPA2l0dz6oHO38Kg6Tpabk1mW7dn8VnaE35V9MNR2GJii8DR ta1SSwuNsdr/flAVWupy+xecDS45KAxbM9Tig08eaVHYm28yz+ZFx76Hg7Ep4tURxqwe OOHWz3ovWYdtmfTQ23tFAeAVAOtKpOCdfLq9hwB0EklT+kczl+SbwxUzHo2LXQr0D3Gj osMB33EC3qDc8FKOGu4Ob9yNASz3ARj6UWc8AVHJ/kwc69bomeOlbUBHvD1Gj2+6xaAI BqxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688330094; x=1690922094; 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=zJjSJrFD46rql5SQeLkNxGE/SD7DDj1gOMvfywUg8kE=; b=cPtIkZQ4l37LQqMHN304MyOqzKOpK7ZVHIB6wueuzOgJL+TbZJ1+lD1K+EanxvxZln oDk4okrcGRkeNrL/Gnf5KgAxQvZU4E26bdx7kFmDp2GjW8tDMjQDLo5dqPUGdo5Ie8Ky dRKwsdRCpC5xOqMVnhc+6GBBTo7OrsN9TUbdtsWTiIwyhjzBnZ+DSsBDMnqyJo9NTvfM i5I0JrvZJIbsS88BkAwrZeBHxheqiHLA8ZP4yQ4/WzZsa4GYB4p9+wiSsug3jQa9Vfvw NAAQfHFcV/uv40ZrcjATnn5axsd7OTCi4UuGRXixwVB6Z+YxO6BGqPwzVS9WlWcTzH6D I2Dw== X-Gm-Message-State: ABy/qLZwnrG10p1RgoqgP7yduYPiGmYZ3A+G2LxkzEKMZof/2/5wrtDd DcuSB3418unLVaVvPalrf1A= X-Google-Smtp-Source: APBJJlFn18kQm5JPRKao2mRHhRAEAM3sOtcZJ+g0yVJQR4RfiYh0Aa1Df+2TzrcScnsR36vcGPCB6g== X-Received: by 2002:a5d:56d2:0:b0:30f:d1e3:22b7 with SMTP id m18-20020a5d56d2000000b0030fd1e322b7mr7170502wrw.6.1688330094158; Sun, 02 Jul 2023 13:34:54 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:b4ae:ae48:2e1b:1dcd]) by smtp.gmail.com with ESMTPSA id f1-20020a5d5681000000b0030647449730sm24000478wrv.74.2023.07.02.13.34.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 13:34:53 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: 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 Cc: Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [PATCH v10 5/6] cache: Add L2 cache management for Andes AX45MP RISC-V core Date: Sun, 2 Jul 2023 21:34:28 +0100 Message-Id: <20230702203429.237615-6-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar I/O Coherence Port (IOCP) provides an AXI interface for connecting external non-caching masters, such as DMA controllers. The accesses from IOCP are coherent with D-Caches and L2 Cache. IOCP is a specification option and is disabled on the Renesas RZ/Five SoC due to this reason IP blocks using DMA will fail. 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 More info about PMA (section 10.3): Link: http://www.andestech.com/wp-content/uploads/AX45MP-1C-Rev.-5.0.0-Data= sheet.pdf As a workaround for SoCs with IOCP disabled CMO needs to be handled by software. Firstly OpenSBI configures the memory region as "Memory, Non-cacheable, Bufferable" and passes this region as a global shared dma pool as a DT node. With DMA_GLOBAL_POOL enabled all DMA allocations happen from this region and synchronization callbacks are implemented to synchronize when doing DMA transactions. Example PMA region passes as a DT node from OpenSBI: reserved-memory { #address-cells =3D <2>; #size-cells =3D <2>; ranges; pma_resv0@58000000 { compatible =3D "shared-dma-pool"; reg =3D <0x0 0x58000000 0x0 0x08000000>; no-map; linux,dma-default; }; }; Signed-off-by: Lad Prabhakar Reviewed-by: Conor Dooley Tested-by: Conor Dooley # tyre-kicking on a d1 --- v8 -> v9 * Updated function pointers v8 -> v9 * Dropped exporting CMO functions as we no more used ALTERNATIVE_X() macro * Now using the riscv_noncoherent_register_cache_ops() for registering CMO ops * Added RB tag from Conor v7 -> v8 * Dropped function pointer usage * Now exporting the functions for clean/inval/flush * Switched to using early_initcall instead of arch_initcall * Dropped entry for "include/cache" from MAINTAINERS * Dropped dependency of RISCV on AX45MP_L2_CACHE * Returning error in case of cache line mismatch * Renamed clean/inval/flush functions v6 -> v7 * Implemented flush callback * Dropped using riscv_dma_noncoherent_cmo_ops v5 -> v6 * Moved driver to cache folder * Switched to new API for CMO v4 -> v5 * Dropped code for configuring L2 cache * Dropped code for configuring PMA * Updated commit message * Added comments * Changed static branch enable/disable order RFC v3 -> v4 * Made use of runtime patching instead of compile time * Now just exposing single function ax45mp_no_iocp_cmo() for CMO handling * Added a check to make sure cache line size is always 64 bytes * Renamed folder rzf -> rzfive * Improved Kconfig description * Dropped L2 cache configuration * Dropped unnecessary casts * Fixed comments pointed by Geert. --- MAINTAINERS | 7 ++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/cache/Kconfig | 11 ++ drivers/cache/Makefile | 3 + drivers/cache/ax45mp_cache.c | 213 +++++++++++++++++++++++++++++++++++ 6 files changed, 237 insertions(+) create mode 100644 drivers/cache/Kconfig create mode 100644 drivers/cache/Makefile create mode 100644 drivers/cache/ax45mp_cache.c diff --git a/MAINTAINERS b/MAINTAINERS index 55ac73793856..899452038a5b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20073,6 +20073,13 @@ S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git F: drivers/staging/ =20 +STANDALONE CACHE CONTROLLER DRIVERS +M: Conor Dooley +L: linux-riscv@lists.infradead.org +S: Maintained +T: git https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/ +F: drivers/cache + STARFIRE/DURALAN NETWORK DRIVER M: Ion Badulescu S: Odd Fixes diff --git a/drivers/Kconfig b/drivers/Kconfig index 514ae6b24cb2..2ae1b6707c2c 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -15,6 +15,8 @@ source "drivers/base/Kconfig" =20 source "drivers/bus/Kconfig" =20 +source "drivers/cache/Kconfig" + source "drivers/connector/Kconfig" =20 source "drivers/firmware/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index 7241d80a7b29..23eb201fe18a 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -11,6 +11,7 @@ ifdef building_out_of_srctree MAKEFLAGS +=3D --include-dir=3D$(srctree) endif =20 +obj-y +=3D cache/ obj-y +=3D irqchip/ obj-y +=3D bus/ =20 diff --git a/drivers/cache/Kconfig b/drivers/cache/Kconfig new file mode 100644 index 000000000000..a57677f908f3 --- /dev/null +++ b/drivers/cache/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +menu "Cache Drivers" + +config AX45MP_L2_CACHE + bool "Andes Technology AX45MP L2 Cache controller" + depends on RISCV_DMA_NONCOHERENT + select RISCV_NONSTANDARD_CACHE_OPS + help + Support for the L2 cache controller on Andes Technology AX45MP platform= s. + +endmenu diff --git a/drivers/cache/Makefile b/drivers/cache/Makefile new file mode 100644 index 000000000000..2012e7fb978d --- /dev/null +++ b/drivers/cache/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_AX45MP_L2_CACHE) +=3D ax45mp_cache.o diff --git a/drivers/cache/ax45mp_cache.c b/drivers/cache/ax45mp_cache.c new file mode 100644 index 000000000000..863bf0bfef98 --- /dev/null +++ b/drivers/cache/ax45mp_cache.c @@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * non-coherent cache functions for Andes AX45MP + * + * Copyright (C) 2023 Renesas Electronics Corp. + */ + +#include +#include +#include +#include +#include + +#include + +/* L2 cache registers */ +#define AX45MP_L2C_REG_CTL_OFFSET 0x8 + +#define AX45MP_L2C_REG_C0_CMD_OFFSET 0x40 +#define AX45MP_L2C_REG_C0_ACC_OFFSET 0x48 +#define AX45MP_L2C_REG_STATUS_OFFSET 0x80 + +/* D-cache operation */ +#define AX45MP_CCTL_L1D_VA_INVAL 0 /* Invalidate an L1 cache entry */ +#define AX45MP_CCTL_L1D_VA_WB 1 /* Write-back an L1 cache entry */ + +/* L2 CCTL status */ +#define AX45MP_CCTL_L2_STATUS_IDLE 0 + +/* L2 CCTL status cores mask */ +#define AX45MP_CCTL_L2_STATUS_C0_MASK 0xf + +/* L2 cache operation */ +#define AX45MP_CCTL_L2_PA_INVAL 0x8 /* Invalidate an L2 cache entry */ +#define AX45MP_CCTL_L2_PA_WB 0x9 /* Write-back an L2 cache entry */ + +#define AX45MP_L2C_REG_PER_CORE_OFFSET 0x10 +#define AX45MP_CCTL_L2_STATUS_PER_CORE_OFFSET 4 + +#define AX45MP_L2C_REG_CN_CMD_OFFSET(n) \ + (AX45MP_L2C_REG_C0_CMD_OFFSET + ((n) * AX45MP_L2C_REG_PER_CORE_OFFSET)) +#define AX45MP_L2C_REG_CN_ACC_OFFSET(n) \ + (AX45MP_L2C_REG_C0_ACC_OFFSET + ((n) * AX45MP_L2C_REG_PER_CORE_OFFSET)) +#define AX45MP_CCTL_L2_STATUS_CN_MASK(n) \ + (AX45MP_CCTL_L2_STATUS_C0_MASK << ((n) * AX45MP_CCTL_L2_STATUS_PER_CORE_O= FFSET)) + +#define AX45MP_CCTL_REG_UCCTLBEGINADDR_NUM 0x80b +#define AX45MP_CCTL_REG_UCCTLCOMMAND_NUM 0x80c + +#define AX45MP_CACHE_LINE_SIZE 64 + +struct ax45mp_priv { + void __iomem *l2c_base; + u32 ax45mp_cache_line_size; +}; + +static struct ax45mp_priv ax45mp_priv; + +/* L2 Cache operations */ +static inline uint32_t ax45mp_cpu_l2c_get_cctl_status(void) +{ + return readl(ax45mp_priv.l2c_base + AX45MP_L2C_REG_STATUS_OFFSET); +} + +static void ax45mp_cpu_cache_operation(unsigned long start, unsigned long = end, + unsigned int l1_op, unsigned int l2_op) +{ + unsigned long line_size =3D ax45mp_priv.ax45mp_cache_line_size; + void __iomem *base =3D ax45mp_priv.l2c_base; + int mhartid =3D smp_processor_id(); + unsigned long pa; + + while (end > start) { + csr_write(AX45MP_CCTL_REG_UCCTLBEGINADDR_NUM, start); + csr_write(AX45MP_CCTL_REG_UCCTLCOMMAND_NUM, l1_op); + + pa =3D virt_to_phys((void *)start); + writel(pa, base + AX45MP_L2C_REG_CN_ACC_OFFSET(mhartid)); + writel(l2_op, base + AX45MP_L2C_REG_CN_CMD_OFFSET(mhartid)); + while ((ax45mp_cpu_l2c_get_cctl_status() & + AX45MP_CCTL_L2_STATUS_CN_MASK(mhartid)) !=3D + AX45MP_CCTL_L2_STATUS_IDLE) + ; + + start +=3D line_size; + } +} + +/* Write-back L1 and L2 cache entry */ +static inline void ax45mp_cpu_dcache_wb_range(unsigned long start, unsigne= d long end) +{ + ax45mp_cpu_cache_operation(start, end, AX45MP_CCTL_L1D_VA_WB, + AX45MP_CCTL_L2_PA_WB); +} + +/* Invalidate the L1 and L2 cache entry */ +static inline void ax45mp_cpu_dcache_inval_range(unsigned long start, unsi= gned long end) +{ + ax45mp_cpu_cache_operation(start, end, AX45MP_CCTL_L1D_VA_INVAL, + AX45MP_CCTL_L2_PA_INVAL); +} + +static void ax45mp_dma_cache_inv(phys_addr_t paddr, unsigned long size) +{ + unsigned long start =3D (unsigned long)phys_to_virt(paddr); + unsigned long end =3D start + size; + unsigned long line_size; + unsigned long flags; + + if (unlikely(start =3D=3D end)) + return; + + line_size =3D ax45mp_priv.ax45mp_cache_line_size; + + start =3D start & (~(line_size - 1)); + end =3D ((end + line_size - 1) & (~(line_size - 1))); + + local_irq_save(flags); + + ax45mp_cpu_dcache_inval_range(start, end); + + local_irq_restore(flags); +} + +static void ax45mp_dma_cache_wback(phys_addr_t paddr, unsigned long size) +{ + unsigned long start =3D (unsigned long)phys_to_virt(paddr); + unsigned long end =3D start + size; + unsigned long line_size; + unsigned long flags; + + line_size =3D ax45mp_priv.ax45mp_cache_line_size; + start =3D start & (~(line_size - 1)); + local_irq_save(flags); + ax45mp_cpu_dcache_wb_range(start, end); + local_irq_restore(flags); +} + +static void ax45mp_dma_cache_wback_inv(phys_addr_t paddr, unsigned long si= ze) +{ + ax45mp_dma_cache_wback(paddr, size); + ax45mp_dma_cache_inv(paddr, size); +} + +static int ax45mp_get_l2_line_size(struct device_node *np) +{ + int ret; + + ret =3D of_property_read_u32(np, "cache-line-size", &ax45mp_priv.ax45mp_c= ache_line_size); + if (ret) { + pr_err("Failed to get cache-line-size, defaulting to 64 bytes\n"); + return ret; + } + + if (ax45mp_priv.ax45mp_cache_line_size !=3D AX45MP_CACHE_LINE_SIZE) { + pr_err("Expected cache-line-size to be 64 bytes (found:%u)\n", + ax45mp_priv.ax45mp_cache_line_size); + return -EINVAL; + } + + return 0; +} + +static const struct riscv_cache_ops ax45mp_cmo_ops =3D { + .wback =3D &ax45mp_dma_cache_wback, + .inv =3D &ax45mp_dma_cache_inv, + .wback_inv =3D &ax45mp_dma_cache_wback_inv, +}; + +static const struct of_device_id ax45mp_cache_ids[] =3D { + { .compatible =3D "andestech,ax45mp-cache" }, + { /* sentinel */ } +}; + +static int __init ax45mp_cache_init(void) +{ + struct device_node *np; + struct resource res; + int ret; + + np =3D of_find_matching_node(NULL, ax45mp_cache_ids); + if (!of_device_is_available(np)) + return -ENODEV; + + ret =3D of_address_to_resource(np, 0, &res); + if (ret) + return ret; + + /* + * If IOCP is present on the Andes AX45MP core riscv_cbom_block_size + * will be 0 for sure, so we can definitely rely on it. If + * riscv_cbom_block_size =3D 0 we don't need to handle CMO using SW any + * more so we just return success here and only if its being set we + * continue further in the probe path. + */ + if (!riscv_cbom_block_size) + return 0; + + ax45mp_priv.l2c_base =3D ioremap(res.start, resource_size(&res)); + if (!ax45mp_priv.l2c_base) + return -ENOMEM; + + ret =3D ax45mp_get_l2_line_size(np); + if (ret) { + iounmap(ax45mp_priv.l2c_base); + return ret; + } + + riscv_noncoherent_register_cache_ops(&ax45mp_cmo_ops); + + return 0; +} +early_initcall(ax45mp_cache_init); --=20 2.34.1 From nobody Mon Feb 9 14:02:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF398EB64DA for ; Sun, 2 Jul 2023 20:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232005AbjGBUfQ (ORCPT ); Sun, 2 Jul 2023 16:35:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbjGBUfD (ORCPT ); Sun, 2 Jul 2023 16:35:03 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1DAEE56; Sun, 2 Jul 2023 13:34:56 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3142ee41fd2so1139871f8f.3; Sun, 02 Jul 2023 13:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688330095; x=1690922095; 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=Urzo+tFsGAkOnz5ecpB6iDl1xPRU1BRxrnQ2HFHQvFc=; b=JzpxMDAE4UcE4qgKpe2qIYa1+chuZrFCRU5IBISMlKC+1W5ZrRnTTJtoWOhZPEWjE9 P0DG8/CQ4j8Ufs9qfrVLSY4zr7NrFnk6Qosqy8NxOCFg707x3R5WyAqWo2zE4NCAbWig SReNgwntctr7AaU1AiUNleX6xt0G/S0OQ1kXb5qFn8qk1SqDuNwh4HhRAVGqmFmWZsjM 6VLRcowSvOLGLgfSGWzZ3rlAzkmQ+vZynmeC1ceyDimJfuOW/DQGb4q9lPbGPVl6ugMR N/JgfMbzQV1ZJob2PK/kRlxrzoa/OJtEUzVg0lsHRctldfKLmKQdicP344vj6D4OYyXg bU2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688330095; x=1690922095; 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=Urzo+tFsGAkOnz5ecpB6iDl1xPRU1BRxrnQ2HFHQvFc=; b=C2Qyz+6t382NWfYKtp0bbRp19HH7sayonoTUk+ppSoIGi0mByj9nWMu4E/wXGUYEv0 TYqwEnNRkSz6UK2PbWHabtqX8qPYRLl6OrgKVpTbNAy830xLYOWgQmvI1sURogQAG+nZ f8BQG4uiTikvKKzlRJBhHIV3HdIGyX6i/kyujg9aiFe3mChDBnzNv9PYRsHSGgEZycDV XqgaltEch1KJtjyHDq2CM5IeLxZD/cbNYb4rYO6ZYsyHuCY/d6as8IhgYy52WeRK1Ob4 XtvuPxakcwv6JlKWki95XY3khbDPxadoebJy4kqeAIicQryS9SJXyT/4tk3BwP4KYlf1 Kalw== X-Gm-Message-State: ABy/qLZm2auINwSQg9guab/OLExv9ct6UHLuHxWemKC4ajqEvIflTfyq I3zGkr4TbB/S/zMzdHfV9N0= X-Google-Smtp-Source: APBJJlElm9XqeQdO3+GTDFDpJLzuHY/UR2rcUieG+OuqysMrqplFSVn/oZ4mIw5L5cVrvaghmfyvnw== X-Received: by 2002:adf:f504:0:b0:30f:be04:5b5e with SMTP id q4-20020adff504000000b0030fbe045b5emr6227046wro.37.1688330095191; Sun, 02 Jul 2023 13:34:55 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:b4ae:ae48:2e1b:1dcd]) by smtp.gmail.com with ESMTPSA id f1-20020a5d5681000000b0030647449730sm24000478wrv.74.2023.07.02.13.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 13:34:54 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: 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 Cc: Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [PATCH v10 6/6] soc: renesas: Kconfig: Select the required configs for RZ/Five SoC Date: Sun, 2 Jul 2023 21:34:29 +0100 Message-Id: <20230702203429.237615-7-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230702203429.237615-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Explicitly select the required Cache management and Errata configs required for the RZ/Five SoC. Signed-off-by: Lad Prabhakar Reviewed-by: Conor Dooley Reviewed-by: Geert Uytterhoeven Acked-by: Geert Uytterhoeven Tested-by: Conor Dooley # tyre-kicking on a d1 --- v9 -> v10 * No change v8 -> v9 * No change v7 -> v8 * Included RB tag from Geert v6 -> v7 * Included RB tag from Conor v5 -> v6 * New patch --- drivers/soc/renesas/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/soc/renesas/Kconfig b/drivers/soc/renesas/Kconfig index de31589ed054..67604f24973e 100644 --- a/drivers/soc/renesas/Kconfig +++ b/drivers/soc/renesas/Kconfig @@ -334,6 +334,10 @@ if RISCV config ARCH_R9A07G043 bool "RISC-V Platform support for RZ/Five" select ARCH_RZG2L + select AX45MP_L2_CACHE + select DMA_GLOBAL_POOL + select ERRATA_ANDES + select ERRATA_ANDES_CMO help This enables support for the Renesas RZ/Five SoC. =20 --=20 2.34.1