Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6382964rdb; Mon, 1 Jan 2024 22:51:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwWZdWkayzdHfVB2XkrpSHf4SxcDfYJ7QzPWgmCLiDdQKMweVsBPIVUortam1wiWgcx6GB X-Received: by 2002:a17:906:71cf:b0:a27:ee21:58c with SMTP id i15-20020a17090671cf00b00a27ee21058cmr1121345ejk.155.1704178267208; Mon, 01 Jan 2024 22:51:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704178267; cv=none; d=google.com; s=arc-20160816; b=mSpsDD3Y1UlF2ghbIoDf8Qrvk66bm57y9eKEdSgl04Xiw5Tmb3uyOtY+ol3U5Jlebk XKnYIDKYyD23iFHuqk1lw3Coq4Hy0WOhs3FfHyCAVeohYfrHk4e3BmKHsvY+01+6OioU F4TXri7vEZwBqNjouGE4n9yU7SPw5bzvssovIV+Sxw3HHxO0NA3o95pfpo6Y5nJosUme ux2GNUVVgYey9bCVCHfiNZMuklQsZZhQhfXMl5PGhmQo0ugbTsi+bW4ANu97xHpDQk1c Zd5nfLg7oR3NMpOKmGpgxe7cWR5GaSeeKdlGlYI4jUtIB0f4D7kcxMvoVd/cXFQDk+Ze dUBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qjYxaQ8wDzEgeZztF8rA+gTEGRKeXBX2J8nFa0Lrwaw=; fh=h+xnY7OmAuCe6mDtzOXAt9rxrYcugKBVBTM4XWhheuU=; b=cjj5C8zjDPeUz7miAKANOSACWA+TQXuoO16HVBDUpPtrYX42PH95kyDdhpN4N2aa3i X0yJ8AGPhulDZ3rYKesLEaiQU2GkiqHUrqMp58G5dI2FsK2uGDSpOYX4sAI5wDnf1dLt lBtF19u6hZzaDWY6e34Qjmh7Z6ORY54bfWDQw78rCjKnD1Ndm4J5u61yH/5zIG4y3Vm1 aun2NAlBF7v6Az4hH0ETSU1ccsfDqWhomjp1Vi9AgZ4x0DfDKVacrqMUQoEPkpCRifZ4 lJAqnWUqBvzPUcDP5F0q493IGLuMe+9oAOfegIe7UHZyHAUbEgZ2d2azr2kHBRX+nssn XwHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=anPdWyAQ; spf=pass (google.com: domain of linux-crypto+bounces-1182-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1182-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i17-20020a17090671d100b00a26896e3316si10528166ejk.775.2024.01.01.22.51.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jan 2024 22:51:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1182-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=anPdWyAQ; spf=pass (google.com: domain of linux-crypto+bounces-1182-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1182-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id ED3711F21189 for ; Tue, 2 Jan 2024 06:51:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4196D46B1; Tue, 2 Jan 2024 06:50:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="anPdWyAQ" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C8072592; Tue, 2 Jan 2024 06:50:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD24AC433C9; Tue, 2 Jan 2024 06:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704178220; bh=nsJfxzeMQv5O8Qx1VjRmXPmszEADwolhj0yHfx5D/74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=anPdWyAQc4OldYWoDG3/Qx2GKPTJX8ENGqrwU5HD3FYzCzs5gi7nGGCJhKdadGucD 6UYhGgSBEjqq/ybXUmaiGJIR5D2V7/B8r2tKyFqm6EpD/BmihHEe6HhDt4oHKpF/IE P1oOj2MN+Z/n9mzwuViN3bII9vKjRUpX47zdFe9XUI+yE/A71RQSsIXbU9OhTMZhOq gobyOSH5yprvo0759gUY71T0U6NxkOnOrsBq3+f54VmEmcSWz5ATStJ6DQ8iAi2gdJ KajkksRDzd5WVxoGP9WO1qqWMIVhUckvXhzSA4WHBISvzKaZed7GtS/9kslZHeMoSe F+gfVVZ7uBKPA== From: Eric Biggers To: linux-crypto@vger.kernel.org, linux-riscv@lists.infradead.org, Jerry Shih Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Heiko Stuebner , Phoebe Chen , hongrong.hsu@sifive.com, Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , Heiko Stuebner Subject: [RFC PATCH 03/13] RISC-V: add helper function to read the vector VLEN Date: Tue, 2 Jan 2024 00:47:29 -0600 Message-ID: <20240102064743.220490-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240102064743.220490-1-ebiggers@kernel.org> References: <20240102064743.220490-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Heiko Stuebner VLEN describes the length of each vector register and some instructions need specific minimal VLENs to work correctly. The vector code already includes a variable riscv_v_vsize that contains the value of "32 vector registers with vlenb length" that gets filled during boot. vlenb is the value contained in the CSR_VLENB register and the value represents "VLEN / 8". So add riscv_vector_vlen() to return the actual VLEN value for in-kernel users when they need to check the available VLEN. Signed-off-by: Heiko Stuebner Reviewed-by: Eric Biggers Signed-off-by: Jerry Shih Signed-off-by: Eric Biggers --- arch/riscv/include/asm/vector.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 71af3404fda14..ae724e016fe24 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -218,11 +218,22 @@ static inline bool riscv_v_vstate_ctrl_user_allowed(void) { return false; } #define riscv_v_vsize (0) #define riscv_v_vstate_discard(regs) do {} while (0) #define riscv_v_vstate_save(task, regs) do {} while (0) #define riscv_v_vstate_restore(task, regs) do {} while (0) #define __switch_to_vector(__prev, __next) do {} while (0) #define riscv_v_vstate_off(regs) do {} while (0) #define riscv_v_vstate_on(regs) do {} while (0) #endif /* CONFIG_RISCV_ISA_V */ +/* + * Return the implementation's vlen value. + * + * riscv_v_vsize contains the value of "32 vector registers with vlenb length" + * so rebuild the vlen value in bits from it. + */ +static inline int riscv_vector_vlen(void) +{ + return riscv_v_vsize / 32 * 8; +} + #endif /* ! __ASM_RISCV_VECTOR_H */ -- 2.43.0