From patchwork Fri May 3 18:18:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13653281 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 A1A7AC10F16 for ; Fri, 3 May 2024 18:19:46 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8GuJW3OcPDIfsEfPCX1msNsMEmC+kEWmRABKEb/r9xY=; b=Ix8qmbnRi/F2by +1Xon9brDjks4Ga4tyNo0+UMk9EHytNTAf/dJg1qtL64CTE763Uts/ECB/00x2Mql0cZi0z1tVDVF aoTe20PmTPfc3Qs9msve/khAjdaaUEW4UIBZJzu6bzjP00aGxkam5VUeS9Jol3Qaioyxvrouy6xJ1 +2nM5Rc9EP0iB9V861r/Yhl8x7BO59vNyBjl0iofIFA1PXn1r/lrfl9sTcApq2w82YMSzXNL48OQM YvmyNA7Oxur6C+NlgU64ME4VlADNoDLbVVfRAOyorX1jchp0TAUxE75OlT8nZ4iC4UDMVPT9CCYYD Nb74oEfUF3OU/dJiJZpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2xVP-0000000HXP1-3IZc; Fri, 03 May 2024 18:19:35 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2xUx-0000000HX2K-02M0 for linux-arm-kernel@bombadil.infradead.org; Fri, 03 May 2024 18:19:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Cc:To:In-Reply-To:References:Message-Id :Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender :Reply-To:Content-ID:Content-Description; bh=UELmH9bdU4ZSPQgKMmBgWTS7NE5GHKJ3ouLiPma73xo=; b=F8P1PW/2pM35GWJJ1FGdAlUQtE uDuzrwIONYf6wc2aAuq1gmF3dsqez8bJdbBITB8ztBluLsLrY7UU5/pu4Zs1yZdx39W5+KjUxg7wA 20npUBLBO5I5O35z72hElEPbc01FTRhwTxGnz4cxSfuj3mBLmWzL19dZBz+gLq3y+yO8Jsj0+ydaf qDR2dyb4T6ptOyg9Y0DUsSbOzeMYkn+6qv9yPvCXQ5+oIkV54sQDPJ3r+lyighvvsdNGNr62mSAyk 7Q8zIhXQs64/WiyAP4/yISqHdyicnWSTUbbfuTLnWV2/Vva6K849qeDn5yqniR2xyH832qrWvyE7G zLHD6fnw==; Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by casper.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2xUt-00000004cx5-0npo for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2024 18:19:05 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6f453d2c5a1so2644b3a.2 for ; Fri, 03 May 2024 11:18:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1714760328; x=1715365128; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UELmH9bdU4ZSPQgKMmBgWTS7NE5GHKJ3ouLiPma73xo=; b=xxyuOdR2fZXilqA+hwJdlQ5lHoyA+O7VY8RnHqYhAJWIINIHY5imy5e8EIOamCDR/a vsZ86KXtFxpjaIFAD6hTMzJorLq1ZRIBDcN4xdMi/i2uW6sUL5t8Q0/N+CrmJnQ4GuBY 957gBcmXpnJwqMfRokQVXC68OS7APwlYDUMLLpKifu6M9YmG6Qrx/xBAjDhxvci+b6Yz hpNPEtAYqW+LJn/VWjmqUxkMq9IMacrGHVi8jkYRejl4byInKynDStPh4sWyLK0Gw6qw oKD6cmmVFn27jpgyQBK8ifWLeUTM5RXbCevOmxXS6VtMlXaPRAB+LsnjbVeaexa7EDpS jU7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714760328; x=1715365128; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UELmH9bdU4ZSPQgKMmBgWTS7NE5GHKJ3ouLiPma73xo=; b=ZYF3Km6ePWK+HVR738S7GjanSHWxarW2D6URiZhA2d5KNepRYbxPRg7hEUXkaDjWAn UI/LueOUVSiCKBAafKjB75dOidlW9Ie6R2LTB/VSBEJ+Talm7IiiEjk/DY0s5cxNYFMS n5m/xGjMIqi+ahUykKclYkR8byZE2XuDB+pKGF7Di+7vawXenZ00AokEsdnDwX5ASKdm fE24zTyxfh6KBnX21C/FbzAMGFCF/gIvg/KcTs06i6TxSTGKtQUz+H6Ew9VOrcpFRVOF kIDH69WxZaAxI1J3/xUmjCjuVuZ8Zo1cVE1J1swqovVnnoAAwrUH6AHfyN0bn04FEGWY 4cyA== X-Forwarded-Encrypted: i=1; AJvYcCUqLo7e90ht94zgCNuYKscRqmh2bUTsPV9tEhbTweMQf5hqWCsrhP3EQ2a1eBG8fLVgaGfP/5ODZKo2AcDN6R3nRFAseUWJm7m9f5iIP2bMcB/Vucw= X-Gm-Message-State: AOJu0YyuY1nJY1yHLgKhz1dg1T+QAAkQGU7WFHVHeoQLZWsdXrnKUhwZ T2ZYlC0QZZd8/KabsCVOKbymxsTT2BhaYhgP9Ip9zbISMCEpQcGIchCcA+G0TWA= X-Google-Smtp-Source: AGHT+IHSeSxim8Qie379bt05mqGRZw+x+rJOj0l9EjBmEgtLA/oB2Gus8wU0QZSnJSgImr9jdtGkdQ== X-Received: by 2002:a05:6a00:1897:b0:6ec:fdcc:40b9 with SMTP id x23-20020a056a00189700b006ecfdcc40b9mr3795178pfh.9.1714760327698; Fri, 03 May 2024 11:18:47 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id fu6-20020a056a00610600b006f3f5d3595fsm3355421pfb.80.2024.05.03.11.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 11:18:46 -0700 (PDT) From: Charlie Jenkins Date: Fri, 03 May 2024 11:18:18 -0700 Subject: [PATCH v6 03/17] riscv: vector: Use vlenb from DT MIME-Version: 1.0 Message-Id: <20240503-dev-charlie-support_thead_vector_6_9-v6-3-cb7624e65d82@rivosinc.com> References: <20240503-dev-charlie-support_thead_vector_6_9-v6-0-cb7624e65d82@rivosinc.com> In-Reply-To: <20240503-dev-charlie-support_thead_vector_6_9-v6-0-cb7624e65d82@rivosinc.com> To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Conor Dooley , Evan Green , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Jonathan Corbet , Shuah Khan Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714760318; l=3440; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=oKiZfXeAlbmWslfugUa98N+u2COwHbBKOONuYtbD/2E=; b=gfKoxKMSSQz8r6+tcijyhi+4U18/WrrOFL15fJ+mhnQVhKqAancI568aLKq2Is+Du4UAyl3x/ yVwCsTQhI99DwYhAkoplUp4CczCsAQa6F+e+H8A5ovtuIOa4g2ecIyY X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240503_191903_381952_9180D2B6 X-CRM114-Status: GOOD ( 17.09 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If vlenb is provided in the device tree, prefer that over reading the vlenb csr. Signed-off-by: Charlie Jenkins Reviewed-by: Conor Dooley Reviewed-by: Andy Chiu --- arch/riscv/include/asm/cpufeature.h | 2 ++ arch/riscv/kernel/cpufeature.c | 47 +++++++++++++++++++++++++++++++++++++ arch/riscv/kernel/vector.c | 12 +++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 347805446151..0c4f08577015 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -31,6 +31,8 @@ DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); /* Per-cpu ISA extensions. */ extern struct riscv_isainfo hart_isa[NR_CPUS]; +extern u32 riscv_vlenb_of; + void riscv_user_isa_enable(void); #if defined(CONFIG_RISCV_MISALIGNED) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 3ed2359eae35..6c143ea9592b 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -35,6 +35,8 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly; /* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS]; +u32 riscv_vlenb_of; + /** * riscv_isa_extension_base() - Get base extension word * @@ -648,6 +650,46 @@ static int __init riscv_isa_fallback_setup(char *__unused) early_param("riscv_isa_fallback", riscv_isa_fallback_setup); #endif +static int has_riscv_homogeneous_vlenb(void) +{ + int cpu; + u32 prev_vlenb = 0; + u32 vlenb; + + /* Ignore vlenb if vector is not enabled in the kernel */ + if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) + return 0; + + for_each_possible_cpu(cpu) { + struct device_node *cpu_node; + + cpu_node = of_cpu_device_node_get(cpu); + if (!cpu_node) { + pr_warn("Unable to find cpu node\n"); + return -ENOENT; + } + + if (of_property_read_u32(cpu_node, "riscv,vlenb", &vlenb)) { + of_node_put(cpu_node); + + if (prev_vlenb) + return -ENOENT; + continue; + } + + if (prev_vlenb && vlenb != prev_vlenb) { + of_node_put(cpu_node); + return -ENOENT; + } + + prev_vlenb = vlenb; + of_node_put(cpu_node); + } + + riscv_vlenb_of = vlenb; + return 0; +} + void __init riscv_fill_hwcap(void) { char print_str[NUM_ALPHA_EXTS + 1]; @@ -671,6 +713,11 @@ void __init riscv_fill_hwcap(void) pr_info("Falling back to deprecated \"riscv,isa\"\n"); riscv_fill_hwcap_from_isa_string(isa2hwcap); } + + if (elf_hwcap & COMPAT_HWCAP_ISA_V && has_riscv_homogeneous_vlenb() < 0) { + pr_warn("Unsupported heterogeneous vlen detected, vector extension disabled.\n"); + elf_hwcap &= ~COMPAT_HWCAP_ISA_V; + } } /* diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c index 6727d1d3b8f2..e04586cdb7f0 100644 --- a/arch/riscv/kernel/vector.c +++ b/arch/riscv/kernel/vector.c @@ -33,7 +33,17 @@ int riscv_v_setup_vsize(void) { unsigned long this_vsize; - /* There are 32 vector registers with vlenb length. */ + /* + * There are 32 vector registers with vlenb length. + * + * If the riscv,vlenb property was provided by the firmware, use that + * instead of probing the CSRs. + */ + if (riscv_vlenb_of) { + this_vsize = riscv_vlenb_of * 32; + return 0; + } + riscv_v_enable(); this_vsize = csr_read(CSR_VLENB) * 32; riscv_v_disable();