Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2836757rdh; Sun, 26 Nov 2023 23:07:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEdM5YZIJsmPb2X6NS3+KcJObjnp3kc1oaNtxuZqylC4ehsxIzw0XvGuHIcw1IDB21fyHc X-Received: by 2002:a17:902:c945:b0:1cf:c340:c1e2 with SMTP id i5-20020a170902c94500b001cfc340c1e2mr3325123pla.50.1701068877520; Sun, 26 Nov 2023 23:07:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701068877; cv=none; d=google.com; s=arc-20160816; b=OjrF/GFRyJTl4DHnYwE5lCJ9n0HVSaChiXc9ndMg5Z6lGieNflhs1ZtzyExnARu+wd jOW7EMfhV1nrGcwU//ADka6fb8HhXteHkt5pRANPW7X/pg+1tZkBDv0VJivmqYL+LG0X oDuHvnKuXa6Ut12fSZpce0hKzhWQ1Jj7azg/gVJCdpNJKFfWjajj46DJbl5KNAK4r2e/ bZHZV5rLaDcCRS94PVEmObzPY6giMNufFC9WJBW+AYja1O8F7ZbtcybncLdALzH4L2vT N3AFg5Yc/N/5ak7WNdm/hhvvdXuLMLDbz823Z8XcyTQ+aaWbsrR8kJGP63heNgy3kduL hDKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/AQWefridDFzEX+S3QZsEdRxceu5Syx5iK5d77pjmdM=; fh=EdrkxR6/0cUzdeRoIO4nQ0kc+YBaYAptqDtNOny9eFo=; b=HGt/yGYEwOz//H6Km8fPdWAGSvWQNTOB7sy4gTkz2BUsIkDWirxTUZvvwEQVgvgwCK eOBmHtiOWa35v6OzZ8USdKEFsa9rNA7YpOTx/R0qur+W58iB23dCG6AbDH9SIxCd7wGS 9Ciof7zc6eb+2Cp7B8/fqFCF8EaynOeJ3l9rSCm0mUa6tGjNUfITtp8/qTTv35hQXMSc rMo7U+tbg/tPjHfjG4lzZzRQ1WrEmMqC6y5F02+Mil0K2mehkPS09/aOmvTYqcZrtWke kEVJ6Y6Ol7BNAgb3n6Z0Zb3ZMwI8RsMWPktrYKvmxGRbCWINSIbWsieA4r6BanjOW4CC ifsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="U0MvI4S/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id d5-20020a170903230500b001cfd9ad64a3si346610plh.144.2023.11.26.23.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 23:07:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="U0MvI4S/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id BD7C6804747A; Sun, 26 Nov 2023 23:07:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231464AbjK0HHN (ORCPT + 99 others); Mon, 27 Nov 2023 02:07:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjK0HHL (ORCPT ); Mon, 27 Nov 2023 02:07:11 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB464133 for ; Sun, 26 Nov 2023 23:07:16 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5bd6ac9833fso2121566a12.0 for ; Sun, 26 Nov 2023 23:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1701068836; x=1701673636; 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=/AQWefridDFzEX+S3QZsEdRxceu5Syx5iK5d77pjmdM=; b=U0MvI4S/Fs3gjOilMQuu49WHu6Aof9dzgAdbM5Gsk8W2BqwNx80zFGD484TPqf1t1u VX6fURDhE6Xyt2X5Wqw4IqvWlNuldcazkBUpcL6P1C+peZcn/qbD+irTxJ3OZ/XbC8Od r+Y9F/wjZe+ke/gjwQF3IJ4xclvHIMEc7zIlxVAb53S90NFgYS/+V+eaj37ztdMXvwt0 pa6NaxRroYqM1FK6Oy0vbX5zt19f1YXjVJ2XP/DbsDN3hhOSRx/mjg2ZkenjuTiFlKRc E8LFZV1h8EuWLPOmsY/pgCi14KZ+vAybmubgh4dcIMWehM4v741xreEDFeTA75jy38+3 SpNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701068836; x=1701673636; 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=/AQWefridDFzEX+S3QZsEdRxceu5Syx5iK5d77pjmdM=; b=vS7zfCoW5aFF6jGZaSNswdSROq/TBJg9KHI3J198dKSqODJrnX8R/z6ZTCOJRtROka 4Pd9N/Kui4PiOwUv08GbdsgRF2rs97Z4f1npCyHgRvLSQZiXypDOdOVQBKHJVWkaOhWa u2JMH5RSZYT9DHSb0NmLw45KgoVEsJHQRZ4GMA7dDVnwOrZRqicX70ToC1MZIza4HBoJ /lhJLOj5dO9YRAELczhbZtL8X72hAkxnurar5rBi3u2nP9t4PVLJAgBIE8/P8xRKY8/N dA060L9NrQWuQk2A0wenPzbN1RCXjjXJkatoSTJ3ZnrOgAunK17T+S64CkVsODX/qEvO gZgg== X-Gm-Message-State: AOJu0YwUW6q59lNN1UIt+hScfmIUNHUBm6yKaXgdBKNibI/aLfAS/FrB /C2MTtBm/Zo+BOPRFk84i6W1zA== X-Received: by 2002:a05:6a20:d48e:b0:187:3b1f:219c with SMTP id im14-20020a056a20d48e00b001873b1f219cmr12639143pzb.10.1701068836407; Sun, 26 Nov 2023 23:07:16 -0800 (PST) Received: from localhost.localdomain ([101.10.45.230]) by smtp.gmail.com with ESMTPSA id jh15-20020a170903328f00b001cfcd3a764esm1340134plb.77.2023.11.26.23.07.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Nov 2023 23:07:16 -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 v2 01/13] RISC-V: add helper function to read the vector VLEN Date: Mon, 27 Nov 2023 15:06:51 +0800 Message-Id: <20231127070703.1697-2-jerry.shih@sifive.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20231127070703.1697-1-jerry.shih@sifive.com> References: <20231127070703.1697-1-jerry.shih@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sun, 26 Nov 2023 23:07:41 -0800 (PST) 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 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 9fb2dea66abd..1fd3e5510b64 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -244,4 +244,15 @@ void kernel_vector_allow_preemption(void); #define kernel_vector_allow_preemption() do {} while (0) #endif +/* + * 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