Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2776855rda; Wed, 25 Oct 2023 11:59:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYQzcrkPzjT63+BM4Ueq3KfTS26lBw1DBQ9AFmFCckBWrC6urInoifZ2OTGQUOCLm4k+Ri X-Received: by 2002:a81:7c82:0:b0:59f:6675:7771 with SMTP id x124-20020a817c82000000b0059f66757771mr16012928ywc.35.1698260376285; Wed, 25 Oct 2023 11:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698260376; cv=none; d=google.com; s=arc-20160816; b=RPFaZnRqaYUX4FEiAQzc9+S7lTZDPA17My/j94On3w88zCcffo0fSaiGeGy+AaWKHz But6rwAj/1JDYdjxhYsfjzsPXVZmCH0IAFvldT3QWCy35kAx6Aqi7203UvQA7pgM0YYS qqyclk5p/huR/PXJocoG8dYx0vxqa84AZOetdSal8yISRLCVO9mOwGK/QNcGTgKBg2cA XpnPg8xYkLvYpDFV+WkUWNn2brcflEpi2ab95IEazYKRujrcTQi3GFmUco8M+/PFyVPG tVIVMOxeOzWiiyzMbFecZeUSiz3m8+QCS8CaeCkTbXOUu5prP6CSEDh1e6onl7Mou4kZ mGBg== 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:mime-version :dkim-signature; bh=72yTSynUrDUHeNGfbDrBCEgB1J8riTYEUtHwwC8rPyQ=; fh=GKwi3PIaODeWWi7LRupwzJjuTN6YK5tMuKf9v4MgXdc=; b=lV3M294eJ50RgTQbwxcB/ogWT/46RoEoybbjs8w/mWBHnFFs/D2zn8cwQsznwaiHN1 eeYUgum2ukSgzB1WBuyQVXDFszJXd0AB20K9f3GIy5NBLoIueSRTTWzMCZheyDf2yA+Y eenbnNA41auXaLICzdaPniGW6sOsN46UmkNWrPOh+3RFGjU3cA00litj2ftEmHQKq1/G YUZOvD0ivXEecwsUu/VtADrpOhrWM7MwVaQ5GoiQ5rI2LxLIenqbRgb1oTh8+mZN2jzp M+SkYc3Gt4ekaFB4w+9usUqSs1pFHXOHB/z74v4k7+J5DvXBdI/EerIA6a6OGAnz9Vem G/jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=If+kDKHe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x83-20020a814a56000000b005a242ee87e5si11864033ywa.483.2023.10.25.11.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 11:59:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=If+kDKHe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BCD49809E70F; Wed, 25 Oct 2023 11:57:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233387AbjJYS4y (ORCPT + 99 others); Wed, 25 Oct 2023 14:56:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233303AbjJYS4t (ORCPT ); Wed, 25 Oct 2023 14:56:49 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83969138 for ; Wed, 25 Oct 2023 11:56:47 -0700 (PDT) Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 61E2A420BB for ; Wed, 25 Oct 2023 18:56:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1698260206; bh=72yTSynUrDUHeNGfbDrBCEgB1J8riTYEUtHwwC8rPyQ=; h=MIME-Version:From:Date:Message-ID:Subject:To:Cc:Content-Type; b=If+kDKHeuT2EMsw92xqfmlqXDH3ramsZx0OPNFo05CzPW6IzPJXEgCM9sqx28lSet iO/k+Ed6G8bYm24NN9bCSmPCKB90vXyjsUewYsZET2bIfnPL1C7dyKPUCYh/qsOJQI SGqWhbY6wiSTH8A0JeQ0L7yK7xsDlFLCuJ3+eHTVkOpZI2bLp5Qwi6noWjYlZw7Uic X0T3HlHZmN4ds6obzGV0kVkXRaof/mnXeUiIpbm9JeywgNEtvcJE4BvzvifW9KWRSK qHwddJUubiP4KK9FC+GAN/g7v7bphg8b2xhrKXwYj5MQ2oXbwH/qarlI00hMv04Xhb ux4UWtt4U7GLA== Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-66d20c7dad2so1017936d6.2 for ; Wed, 25 Oct 2023 11:56:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698260204; x=1698865004; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=72yTSynUrDUHeNGfbDrBCEgB1J8riTYEUtHwwC8rPyQ=; b=wrapd+jnfZKCRdTl2sqDkJwPcugm1O5MkATKogwI5ZEZMniVO6LkDqFHUmsxLTkpPU KWzGo2OTrgBGGPnbCArwKyvI12JlVt92arjrJRgQk3omm+X5oqk9tuBxcJKbA+s1iA8C x9Ototwq1mfC5afFV6enPZThH7NAD95JxqfXU5PtteBLY/c/v6ou4dgm89SQYTt2cRGn 5At4XwQwp4IgefUmXrMYhOtC8p96Is+zJbRu0XNb9G36DhHXYl16Nb4HeHncGjZqzJeQ +MMN7G0CccoxkJmKBE+R8YHLd+uGhbbTKPUay6piu2ZHZJco4ZKHLcC4Dji19LZNRf1L sUfw== X-Gm-Message-State: AOJu0YwqadESz7IRG0cMNGIkA165TJhQ7OCqkINzdOd0n9ZQIXAfmPu+ nDb1EPQMjtmBupudJhexLZzypibU+4PofvXeDCSceATKaYlqSCBZ134XaC4fVy4VNXOusS9V1aw 3C2ffyf8refmE1bq9dWrsg0Qq3cMrTC2RC8KxjyB+sX8q5fUfLzV+NaWqDgy/EKmSMw== X-Received: by 2002:a05:6214:500a:b0:66d:1ff3:31ed with SMTP id jo10-20020a056214500a00b0066d1ff331edmr18230017qvb.52.1698260204377; Wed, 25 Oct 2023 11:56:44 -0700 (PDT) MIME-Version: 1.0 X-Received: by 2002:a05:6214:500a:b0:66d:1ff3:31ed with SMTP id jo10-20020a056214500a00b0066d1ff331edmr18230005qvb.52.1698260204165; Wed, 25 Oct 2023 11:56:44 -0700 (PDT) Received: from 348282803490 named unknown by gmailapi.google.com with HTTPREST; Wed, 25 Oct 2023 11:56:43 -0700 From: emil.renner.berthing@canonical.com Date: Wed, 25 Oct 2023 11:56:43 -0700 Message-ID: Subject: [PATCH 4/4] soc: sifive: ccache: Support cache management operations To: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Palmer Dabbelt , Paul Walmsley , Emil Renner Berthing Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 25 Oct 2023 11:57:03 -0700 (PDT) This cache controller also supports flushing cache lines by writing their address to a register. This can be used for cache management on SoCs with non-coherent DMAs that predate the RISC-V Zicbom extension such as the StarFive JH7100 SoC. Signed-off-by: Emil Renner Berthing --- drivers/soc/sifive/sifive_ccache.c | 45 +++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/soc/sifive/sifive_ccache.c b/drivers/soc/sifive/sifive_ccache.c index 676468c35859..9bf94c22cad9 100644 --- a/drivers/soc/sifive/sifive_ccache.c +++ b/drivers/soc/sifive/sifive_ccache.c @@ -8,13 +8,16 @@ #define pr_fmt(fmt) "CCACHE: " fmt +#include #include #include #include #include #include #include +#include #include +#include #include #define SIFIVE_CCACHE_DIRECCFIX_LOW 0x100 @@ -39,10 +42,14 @@ #define SIFIVE_CCACHE_CONFIG_SETS_MASK GENMASK_ULL(23, 16) #define SIFIVE_CCACHE_CONFIG_BLKS_MASK GENMASK_ULL(31, 24) +#define SIFIVE_CCACHE_FLUSH64 0x200 +#define SIFIVE_CCACHE_FLUSH32 0x240 + #define SIFIVE_CCACHE_WAYENABLE 0x08 #define SIFIVE_CCACHE_ECCINJECTERR 0x40 #define SIFIVE_CCACHE_MAX_ECCINTR 4 +#define SIFIVE_CCACHE_LINE_SIZE 64 static void __iomem *ccache_base; static int g_irq[SIFIVE_CCACHE_MAX_ECCINTR]; @@ -125,6 +132,34 @@ int unregister_sifive_ccache_error_notifier(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(unregister_sifive_ccache_error_notifier); +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS +static void ccache_flush_range(phys_addr_t start, size_t len) +{ + phys_addr_t end = start + len; + phys_addr_t line; + + if (!len) + return; + + mb(); + for (line = ALIGN_DOWN(start, SIFIVE_CCACHE_LINE_SIZE); line < end; + line += SIFIVE_CCACHE_LINE_SIZE) { +#ifdef CONFIG_32BIT + writel(line >> 4, ccache_base + SIFIVE_CCACHE_FLUSH32); +#else + writeq(line, ccache_base + SIFIVE_CCACHE_FLUSH64); +#endif + mb(); + } +} + +static const struct riscv_nonstd_cache_ops ccache_mgmt_ops __initdata = { + .wback = &ccache_flush_range, + .inv = &ccache_flush_range, + .wback_inv = &ccache_flush_range, +}; +#endif /* CONFIG_RISCV_NONSTANDARD_CACHE_OPS */ + static int ccache_largest_wayenabled(void) { return readl(ccache_base + SIFIVE_CCACHE_WAYENABLE) & 0xFF; @@ -258,6 +293,14 @@ static int __init sifive_ccache_init(void) } of_node_put(np); +#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS + if (of_property_read_bool(np, "sifive,cache-ops")) { + riscv_cbom_block_size = SIFIVE_CCACHE_LINE_SIZE; + riscv_noncoherent_supported(); + riscv_noncoherent_register_cache_ops(&ccache_mgmt_ops); + } +#endif + ccache_config_read(); ccache_cache_ops.get_priv_group = ccache_get_priv_group; @@ -278,4 +321,4 @@ static int __init sifive_ccache_init(void) return rc; } -device_initcall(sifive_ccache_init); +arch_initcall(sifive_ccache_init); -- 2.40.1