From patchwork Mon Jan 30 12:01:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13120981 X-Patchwork-Delegate: palmer@dabbelt.com 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07528C54EAA for ; Mon, 30 Jan 2023 12:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0zVQwc++q8HUagN9MCNYz2HFep6/p9dSVpH0VNzzoRs=; b=u41JYVjUHNmU9o JvkQzdI+8w3xglxrU+c85Y8YivcpWIoJKituAhGoeQXdUz2A/WPx98lgMlNvizT1bjd47amTpIS+Q sMs1bEmUVPgfO/I2Mhpwp2C/tkccNw7nO7/X9hT56v3ErL4m5eVv2ANudPIWN2Qz1vfuNihpLIu0F oP7EHucy0PVXqPDV2j96ZhMGS5se0913+Y6hYDv6yPgB7mevvuZq88aVx/3ouXnTrrFdGP0dAWkIU bVN0kSl9m9gBLBVjH3Tg8/+s/7wEY+Kb/XRp6gy3Tk5U5NQ3eR+tY6gkQtwB0vrzWgHlz3KWS9UiK aO1VV5aOhkb16X2sZusg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMSr2-003PDe-5P; Mon, 30 Jan 2023 12:01:44 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMSqu-003P7p-9I for linux-riscv@lists.infradead.org; Mon, 30 Jan 2023 12:01:37 +0000 Received: by mail-wm1-x330.google.com with SMTP id bg26so1967805wmb.0 for ; Mon, 30 Jan 2023 04:01:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=i6UAT/lkfohFOOd5Gpj9LH7cNIgjJcQBN1fpGpSr8xc=; b=YAJkFwZgJ0LA+Bn91S1gW2IYB2sIPvhW6e6BW2FC0ggX9BN2VdTIs6eo0COXLeNbXl 0xZQZZMwH7BG/U/cSI8XUpSxSkP7ifpTzPsFNuEMkY6ZtNrHN+YkxBgNtCN3LmqEWUwh UMIQvi289QOP68BL6Z7bAP+mltjwervb7q/27sPJNkA2T8g02Csve6BMietLfOs7MEmK 5riyFYTlmpvRyPmOEu8goWTZ3PMU+LCqD1bFeXC7WbNXLODd0vJ624AozbExD0JUAivm xJ6knoiMfRNR8hBBei7t02fEZmRJMqaHHqXpuP77nD/+k0JTcRgDki9jjvtjK5wkJ4Ik TcNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=i6UAT/lkfohFOOd5Gpj9LH7cNIgjJcQBN1fpGpSr8xc=; b=tNHcmI3h0Q43x8XGsHzDqDYtaMadgWIILMpyBab5XEQYPtr7SNVP69fEJLai4wXJEe CYauZe2ZJGZiIZGIODg0J0psVnlkkeXC2RoF/xHwazX6Y+9zri9FYCiB61EjWFbxc4ej LE5RF4cl9bNfXz+Htu7aBT90sn8HtSQP6cKuln0KzeaX2wVgXqCtPB1NS6f6OxZnUSvG YN51o0dJCySUuvyQf4xy9cjfYP2vpYWP3rcgK5K19v1KrpfZjkQzMs97JVirsq9ZnxmT Tvw06ZVibt3YLtNx4ifDW/Khxl9U/NIVPAtLI30BwTI/xWZp9Qwhn+kyWXKjKJL/CJr4 QghQ== X-Gm-Message-State: AFqh2krVir2adSUujrRhsUWRf/0xaiTEycSzS8hpiLrd9B+HALXSdy8J ykx0SPHvNZnWXjaRmlsRP/fHL13XKcDTtRVz X-Google-Smtp-Source: AMrXdXvvCERJn5Fz/gBHngbNbmXcmEiiEfNEU7a7OZnVnONN33npyUcEEU5gzZTIrGKZSlRlA45H4A== X-Received: by 2002:a1c:ed1a:0:b0:3da:c07:c5fe with SMTP id l26-20020a1ced1a000000b003da0c07c5femr46386974wmh.5.1675080094397; Mon, 30 Jan 2023 04:01:34 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id o16-20020a05600c379000b003dc49e0132asm7126453wmr.1.2023.01.30.04.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 04:01:34 -0800 (PST) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, devicetree@vger.kernel.org Cc: 'Heiko Stuebner ' , 'Krzysztof Kozlowski ' , 'Anup Patel ' , 'Palmer Dabbelt ' , 'Atish Patra ' , 'Paul Walmsley ' , 'Albert Ou ' , 'Conor Dooley ' , 'Rob Herring ' , 'Jisheng Zhang ' Subject: [PATCH v3 3/6] RISC-V: Add Zicboz detection and block size parsing Date: Mon, 30 Jan 2023 13:01:25 +0100 Message-Id: <20230130120128.1349464-4-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130120128.1349464-1-ajones@ventanamicro.com> References: <20230130120128.1349464-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230130_040136_356006_BF641B1C X-CRM114-Status: GOOD ( 15.40 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Parse "riscv,cboz-block-size" from the DT by piggybacking on Zicbom's riscv_init_cbom_blocksize(). Additionally check the DT for the presence of the "zicboz" extension and, when it's present, validate the parsed cboz block size as we do Zicbom's cbom block size with riscv_isa_extension_check(). Signed-off-by: Andrew Jones Reviewed-by: Heiko Stuebner Reviewed-by: Conor Dooley --- arch/riscv/include/asm/cacheflush.h | 3 ++- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 10 ++++++++++ arch/riscv/kernel/setup.c | 2 +- arch/riscv/mm/cacheflush.c | 23 +++++++++++++++-------- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index 03e3b95ae6da..8091b8bf4883 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -50,7 +50,8 @@ void flush_icache_mm(struct mm_struct *mm, bool local); #endif /* CONFIG_SMP */ extern unsigned int riscv_cbom_block_size; -void riscv_init_cbom_blocksize(void); +extern unsigned int riscv_cboz_block_size; +void riscv_init_cbo_blocksizes(void); #ifdef CONFIG_RISCV_DMA_NONCOHERENT void riscv_noncoherent_supported(void); diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 7936ae6f7bdf..7d1e88d7320d 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -46,6 +46,7 @@ #define RISCV_ISA_EXT_SVPBMT 29 #define RISCV_ISA_EXT_ZICBOM 30 #define RISCV_ISA_EXT_ZIHINTPAUSE 31 +#define RISCV_ISA_EXT_ZICBOZ 32 #ifndef __ASSEMBLY__ #include diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index 0bf1c7f663fc..578c1093b839 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -186,6 +186,7 @@ arch_initcall(riscv_cpuinfo_init); */ static struct riscv_isa_ext_data isa_ext_arr[] = { __RISCV_ISA_EXT_DATA(zicbom, RISCV_ISA_EXT_ZICBOM), + __RISCV_ISA_EXT_DATA(zicboz, RISCV_ISA_EXT_ZICBOZ), __RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index a4f737bc7530..5d278d2c48fb 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -78,6 +78,15 @@ static bool riscv_isa_extension_check(int id) return false; } return true; + case RISCV_ISA_EXT_ZICBOZ: + if (!riscv_cboz_block_size) { + pr_err("Zicboz detected in ISA string, but no cboz-block-size found\n"); + return false; + } else if (!is_power_of_2(riscv_cboz_block_size)) { + pr_err("cboz-block-size present, but is not a power-of-2\n"); + return false; + } + return true; } return true; @@ -225,6 +234,7 @@ void __init riscv_fill_hwcap(void) SET_ISA_EXT_MAP("svinval", RISCV_ISA_EXT_SVINVAL); SET_ISA_EXT_MAP("svpbmt", RISCV_ISA_EXT_SVPBMT); SET_ISA_EXT_MAP("zicbom", RISCV_ISA_EXT_ZICBOM); + SET_ISA_EXT_MAP("zicboz", RISCV_ISA_EXT_ZICBOZ); SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE); } #undef SET_ISA_EXT_MAP diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 376d2827e736..5d3184cbf518 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -297,7 +297,7 @@ void __init setup_arch(char **cmdline_p) setup_smp(); #endif - riscv_init_cbom_blocksize(); + riscv_init_cbo_blocksizes(); riscv_fill_hwcap(); apply_boot_alternatives(); if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) && diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index eaf23fc14966..ba4832bb949b 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -98,6 +98,9 @@ void flush_icache_pte(pte_t pte) unsigned int riscv_cbom_block_size; EXPORT_SYMBOL_GPL(riscv_cbom_block_size); +unsigned int riscv_cboz_block_size; +EXPORT_SYMBOL_GPL(riscv_cboz_block_size); + static void cbo_get_block_size(struct device_node *node, const char *name, u32 *block_size, unsigned long *first_hartid) @@ -120,19 +123,23 @@ static void cbo_get_block_size(struct device_node *node, } } -void riscv_init_cbom_blocksize(void) +void riscv_init_cbo_blocksizes(void) { + unsigned long cbom_hartid, cboz_hartid; + u32 cbom_block_size = 0, cboz_block_size = 0; struct device_node *node; - unsigned long cbom_hartid; - u32 probed_block_size; - probed_block_size = 0; for_each_of_cpu_node(node) { - /* set block-size for cbom extension if available */ + /* set block-size for cbom and/or cboz extension if available */ cbo_get_block_size(node, "riscv,cbom-block-size", - &probed_block_size, &cbom_hartid); + &cbom_block_size, &cbom_hartid); + cbo_get_block_size(node, "riscv,cboz-block-size", + &cboz_block_size, &cboz_hartid); } - if (probed_block_size) - riscv_cbom_block_size = probed_block_size; + if (cbom_block_size) + riscv_cbom_block_size = cbom_block_size; + + if (cboz_block_size) + riscv_cboz_block_size = cboz_block_size; }