From patchwork Mon Jan 22 00:19:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 189863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2295131dyb; Sun, 21 Jan 2024 16:24:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDjAeUq73pDN77O0fgb69dYPvIptiRfiF2hcOu81orJnDucl4lhVSusp80Trp77v6PwQV3 X-Received: by 2002:a2e:8057:0:b0:2cd:50a7:12d2 with SMTP id p23-20020a2e8057000000b002cd50a712d2mr1152486ljg.58.1705883052242; Sun, 21 Jan 2024 16:24:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705883052; cv=pass; d=google.com; s=arc-20160816; b=E65sJFcMxpI9xDJWafXWJ99bSE9kliGq3E5k0JW73W3VW5gvcexx3RAkorCvxdHxmQ MafSMoIvC7DpQqCsGaTN0W8KFoKelsB0UALblMnSzTy5LaxClR/uhzWLRUv/W8A5JRQD taRBORvO9mc1vDvECHsEmIfHYRBwXMIZ9XPAUmv1Cw1EFyjBWS+GwzsoY5rzLzP7s/E7 hZ6BBwHp9SqFLT+IZfGsQuac+/edtFRXqgrz3jR2qFfsR2Rq9ALRM2i5G9P5DUqtCBx2 OPty7SAHylJMV6BpFi/26sqC74bn1S3Wky81ptJRnWMmd2zUHI09Isw9Zv+9pm6/S41e avmg== ARC-Message-Signature: i=2; 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=Xw5iDfRjDtoLBTAN5YgOznJxS3TZJRIRKeU1HTKSb+M=; fh=gyibMVRMMHot5utPiR7aeWZkR96ebFgyaWxYaKfV2b8=; b=dGY9Uwj2vV2c36G3zWtyXKaV+o22xNSAXuDipRuC49/pJfXwhZfOgv7saePckBqqsE vMedWpIl2305bZPln/fZ/YfUQDNeMdUmA1MKE0cGMshXJZd8pSPpZoTj313hiHl9loOS qMGkFWjYU8aRGB01fgrzo3LlYqIatnLFCA7n66LAJGtKLACkTkecUElAy8T0NzxtWbpL 54frv+p5EzIcdb95Avo6VGEyyeaafOUJRN8qCt7EaOtA/4fi6W+MXquCxMYFPvc9ne2d NFpxM4i8CbYnxgziOePTW52tmx3YiL4DrZe5qnh5QG9UowaREp8/kEaSp6lzhxcXGCnV 9cAw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="pHW/j+hV"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-32234-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32234-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q10-20020a5085ca000000b00557c1791121si10695473edh.439.2024.01.21.16.24.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 16:24:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32234-ouuuleilei=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="pHW/j+hV"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-32234-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32234-ouuuleilei=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 B69871F22C2F for ; Mon, 22 Jan 2024 00:24:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09B984C83; Mon, 22 Jan 2024 00:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pHW/j+hV" 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 50E1537E; Mon, 22 Jan 2024 00:22:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705882979; cv=none; b=eE4bCHO+bY/+CXG3u4X2Pta23ENtDKufKpCUHfItVeeXgCL5dkKEhfL5TCWvSDAXzCgeR/qKAxJmB+50u6c4CXtnui9/uKfePURcnWW3f00mt0zfj/EidWLRGV6Q6FLTJVOHbRf8WYQW7YC3iCK2Soce10direMMN6WPwmoJgZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705882979; c=relaxed/simple; bh=cu/x3ItAEqexfto4Q62/HSpF8UbXNvIBvj4vMpklLig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hilg/JWPBMQ4TDShslQ5k7jbAIYa2GGO9ko8YWJu3wHvpOHL8Cjvg9sKYLL4xhSoVmOUWWcOtUt6lmnJaAd3FRpP7zuCJbzXCWDKwjDcUB7y7oPKlXStKVMSI2Tt5MbdteFH6IYY7y7alYXxwzSyM/tsScbvh86uBCNe4iEqSZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pHW/j+hV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB036C43390; Mon, 22 Jan 2024 00:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705882978; bh=cu/x3ItAEqexfto4Q62/HSpF8UbXNvIBvj4vMpklLig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pHW/j+hVYcQ07mUuVmoaaAsGPm/61eCDdoJM0ufsYRwR6PrpSPg84A+/4jl51OZqh gRJqHPELv2mQnKLWkuFWnmN6bOuwlKBmo1kkltWLEMQiZiPjAKFOdrKl4xdlX2EfZf MFIuQ/hgBkYKXEw4jZWDBPoLXota/bOJ7wWH+VHTnNr0myYVIsGWL+dLXfLSG7ByEZ 1BvesMZ2YNLNAY8HD4twt8KK1b+kp7/ituTaaXKMTwHXvZAWuFnNZpnQ8pFjZEo8cg 5W2ZkYpsq0PQFU3itAG689+XqQbphjP4Fji+0DZ+zAUPDz9JKqxZOdTSz6bQEq3q68 HayS0AbAwrKxg== From: Eric Biggers To: linux-crypto@vger.kernel.org, linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Albert Ou , Andy Chiu , Ard Biesheuvel , =?utf-8?q?Christoph_M=C3=BCllner?= , Heiko Stuebner , Jerry Shih , Palmer Dabbelt , Paul Walmsley , Phoebe Chen , hongrong.hsu@sifive.com, Heiko Stuebner Subject: [PATCH v3 01/10] RISC-V: add helper function to read the vector VLEN Date: Sun, 21 Jan 2024 16:19:12 -0800 Message-ID: <20240122002024.27477-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122002024.27477-1-ebiggers@kernel.org> References: <20240122002024.27477-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788748027607977898 X-GMAIL-MSGID: 1788748027607977898 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 0cd6f0a027d1f..731dcd0ed4de9 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -277,11 +277,22 @@ static inline bool riscv_v_vstate_ctrl_user_allowed(void) { return false; } #define riscv_v_vstate_restore(vstate, 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) #define riscv_v_thread_free(tsk) do {} while (0) #define riscv_v_setup_ctx_cache() do {} while (0) #define riscv_v_thread_alloc(tsk) 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 */