Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5583522rdb; Sun, 31 Dec 2023 07:28:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IERh1iFxro+z9+D1txjSdN2sMd7YN3ZRiSSOz5h8PkvVHq+EAc5cywGomIKb7nUnoSyQGKv X-Received: by 2002:a05:6a21:498b:b0:196:a4c2:5a10 with SMTP id ax11-20020a056a21498b00b00196a4c25a10mr2911176pzc.57.1704036496327; Sun, 31 Dec 2023 07:28:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704036496; cv=none; d=google.com; s=arc-20160816; b=S6eq4eV6CSF1mPG56THhwg9Ho9TV5FJ8OMGtA1SJfNGwpEriDx/RFoEJwlVgKpZJxe WkdyDwK9KxUxYtpPU1tddSlwDirWyBJJU4ooTl49KAlbtKYOi0NwIYk9Oamlets5PlTc W0QDfhxSLR1etHCtXp5aKO3+x1qXQmmMQyAR6aCOJfwYcF64RPTH6tNi0KoDLxnBtxh3 H1G/woXd2CwtxuP2LvsXmo/BPDTDProc1hyYm8QrW8cGXLceRGG1gGV4/xcuMW6q4Qhx j3A1WjIZlrnzoY4FeSWsVQ3jHb4s+YtI3fwOVVRmOPPQM+mLu4Q9lRaxe1xZM2D9aWxN GKgA== 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=Iifngznp+ertIjgLYKgYyodchJA69bCk2AsJZ4z1PYM=; fh=EdrkxR6/0cUzdeRoIO4nQ0kc+YBaYAptqDtNOny9eFo=; b=RR35Evk8cNDFbTIYKfU0ZgkwTtlFF7VOcZojDIhh9hUbf7zbobf/H2qbTlskE3TAxw gDYY/r66AGU4kGV7i3ed0s6MCOYz6tp1i16D29pqtu4hpmRaJk19w/epo7IpXunaZasa RtPNKea1AEyPEZU2h6RKoBbFQ/vm2pYUacW17x/wByNdl6ucHDz/dMi0AmYcWXd65Lx3 D6xJILe7Mg/EC+yXMgUbgSbDfR/3jX3FvkPOi2JHptwR8JG7cVLsoNnAdY9wE7LT5ze+ IIKUbRjKEhcqebryMr0zG1Mz0H4PW8zfZQkjmlUtZLzDXzHlTFkS0Nk+D2OTUfJY5NiU 771A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=amBL++QD; spf=pass (google.com: domain of linux-kernel+bounces-13731-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13731-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o23-20020a637317000000b005cdff83cbe6si14381158pgc.700.2023.12.31.07.28.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 07:28:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13731-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=amBL++QD; spf=pass (google.com: domain of linux-kernel+bounces-13731-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13731-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F29F9281C23 for ; Sun, 31 Dec 2023 15:28:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8315D8F6F; Sun, 31 Dec 2023 15:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="amBL++QD" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DC7779D4 for ; Sun, 31 Dec 2023 15:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-28bd623c631so6766408a91.3 for ; Sun, 31 Dec 2023 07:27:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704036477; x=1704641277; darn=vger.kernel.org; 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=Iifngznp+ertIjgLYKgYyodchJA69bCk2AsJZ4z1PYM=; b=amBL++QDsc+EE5EFmrVMy/WSKZtIGyKBE02sIoMt/Jr+ZrP1A33/zVgpdnEDnLGMfg YHaV0WGyrqWOZOZT2ukv9Rnn3faVBaDwm+wVOngbsk5tx/9qlD8c7wYa6n/mDxsngQrq GcdfjpONGDDy9EkTOVk1SqjRIQ4gIvWN1MVedVnQF/lNeqc4pMTR33KvNLhFyjfRg/Gn X46Nyj8QwgWMss84zYz24HFrsQbNBPwGBncTRDUzL4xf9AbzsEMWberEUI9yezmOFh04 ZfT850gB2pK/NeNqtMO0sck0A9MCJb2Gi3J6VuJPJwSGrUOden8f/MkoeTAy8amjHXOM TyCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704036477; x=1704641277; 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=Iifngznp+ertIjgLYKgYyodchJA69bCk2AsJZ4z1PYM=; b=HUq/Daf6dABrSh5mYNKNVAyo8jk+b628cXqe/1LqejAA4QTRIXBZJOITJtYOgxxW5s bubM9yO3fv5ZM0AJGfWjshPHPciIh9adlJJMe8fjTZyrYQtWNmj8Bj95nkeHlEq2dQW7 n8EViKlHlIkm48yK3F0beDptVN7BOZhSEyqHrKn8tp+i4qWtvWPOOqJ0Mtrg1/IqurDY f2nbjAau5yOB9+yMtyYqIm0coxwSD1neJo0O5i8xfOOJ5YiKIw/TSlNA+RCfoDtC8Teq LM+X7smBqGeK9hJBiz1f8amNvkQC3lObxkmHQ/hikylAsPlhrSZEJiNx9QtU5q3ZHq0B Jcjw== X-Gm-Message-State: AOJu0YwQTBuLd/owGnPoiuEazDp8iSfcL95uEfcLXJadV1FYxobq4zEX 3GCc3xide51ZWJ8YZeEzdwS0aPMMuxyvPQ== X-Received: by 2002:a17:902:684f:b0:1d0:6ffe:9f5 with SMTP id f15-20020a170902684f00b001d06ffe09f5mr5478381pln.83.1704036476827; Sun, 31 Dec 2023 07:27:56 -0800 (PST) Received: from localhost.localdomain ([49.216.222.63]) by smtp.gmail.com with ESMTPSA id n4-20020a170902e54400b001cc3c521affsm18624430plf.300.2023.12.31.07.27.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Dec 2023 07:27:56 -0800 (PST) From: Jerry Shih To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, herbert@gondor.apana.org.au, davem@davemloft.net, conor.dooley@microchip.com, ebiggers@kernel.org, ardb@kernel.org Cc: heiko@sntech.de, phoebe.chen@sifive.com, hongrong.hsu@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Subject: [PATCH v4 01/11] RISC-V: add helper function to read the vector VLEN Date: Sun, 31 Dec 2023 23:27:33 +0800 Message-Id: <20231231152743.6304-2-jerry.shih@sifive.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20231231152743.6304-1-jerry.shih@sifive.com> References: <20231231152743.6304-1-jerry.shih@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@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 --- 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 d69844906d51..b04ee0a50315 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -294,4 +294,15 @@ static inline bool riscv_v_vstate_ctrl_user_allowed(void) { return false; } #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.28.0