Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp277370lqo; Thu, 16 May 2024 06:13:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5n/ZFJRJaafplnFdR60Nj/1E7moSAvk3pMgIN0zOBev9oepdsIygbyv4wp+p4sJtQCsQJdqkLDkMXceNDGPzXdsLM62oxEK06TNBt5Q== X-Google-Smtp-Source: AGHT+IF8mbNKQMw4R4L06R8EDIncy9+49P/MDibvF9Lw4kzqHwkQnQ/ze5Os3fpvOo+dwHq6ZQMb X-Received: by 2002:a05:6a21:6d9c:b0:1b0:20e9:d215 with SMTP id adf61e73a8af0-1b020e9d7c7mr5192358637.14.1715865237672; Thu, 16 May 2024 06:13:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715865237; cv=pass; d=google.com; s=arc-20160816; b=M8ajcIgsL4JhVlEUrqeS5ngIRPh1SjuHTgikgaUjHYOR3EJcTJGI3nGqGfq9xb9aIn inx4Ennd7KnaLQAXvTeUGQ/eB9t6/1VR6R5urOceQH27KIV6qjyunYYPAKms3C+DafSl kTuN+tXP5/PQy/GIPCJrlfzpfb2Nyj57YOcnWN6PxwZOp+B9V4EzxI7+hdih6lAE48Wf NYG5RpTrDSjjVNy2zEC0mXn27ZjbJ6PLy2rLfI9AUo88n0HmSdRMqYoTe1+1PpQVBd91 L+P/2120g6BS8a40By24TSULTOGjg2FmzNoSIGVXHq+ZMzUZc5ycMkmlZfxdJHVqdg8X GNPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=4V904prVi6oQ5IyZz7aDLXAgfOChEzLZtTfRAaiZkwU=; fh=oHvrGczvVc/qNieQhDfn0PUZ2mqqD+LXPdBWabUo63Q=; b=TTID0+4ue8+2vUVwv8wYMvAKBDhbHXvkaGRBGmD9hQvkHQwiHyLApsLO5RbHraWtgy eVr553DAaRyuL8Dhas72/7EuW9avQXxHpP/0MkfPmij1+WIGASaKRw1z2jS6DuLgc75q R6zTTOl5R0jTw68kaAkiOC+EY3g+T9UDV9h0u4kEwSaZw2/iredZTipFO6vg91H3noc0 7RlkiK+QZ5u4QFax7IdCenAyMThGq/qs3CXwJ8tv4To1bqbLpf19JnSenGjYfxtgCyH3 HpNjCyStpmGCT4qtGyHK0CLHJ498fS4rT7YjbTbZXPeVHlKUsoxn9K3+c35L2tSjH5Tt M4Dg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=HKkIiKKg; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-181092-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181092-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 d2e1a72fcca58-6f4d2a72a19si15557588b3a.72.2024.05.16.06.13.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 06:13:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181092-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=HKkIiKKg; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-181092-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181092-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 D7D60282E88 for ; Thu, 16 May 2024 13:11:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34D82143862; Thu, 16 May 2024 13:11:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="HKkIiKKg" Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 B0FE9146A72 for ; Thu, 16 May 2024 13:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715865108; cv=none; b=b++/ckMhuDbNK9lrHzU+gqA+SF5GfUm9Ve34Dz4hpY8JjtE6cuC56oLmEw6T+JeyWbEGugHN2ELAGCh+75+TrhOYiVTybFFQT8dXQqw7IVQMCcIonbMmsXL5oyWyAJtIyfJlHQIKdEsOfduwoXTUF2VhpgVnsLCq9C/RBfCtL9U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715865108; c=relaxed/simple; bh=Wi6fPWBM2N13lqz1ePjmrOpqRQ8zl8M+Hd0GZZShN44=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mItJRC6x2p99V5YqGMi+kMI2Hh21Mvj8qY9Ly9t24Z9U9sQHAP/MYoeHlDyjoDwCzrBqyuFKRW2qpUwQecqfZhZgGhaKXe7mz0w/Razhnkk+JLtcWct59rF68HnWIEBuaqzLqZ/OenEnnxoGaXWin8qDFIzbPDxu3/fGX87gcWI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=HKkIiKKg; arc=none smtp.client-ip=209.85.128.179 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-yw1-f179.google.com with SMTP id 00721157ae682-6277a2bb35fso5282517b3.1 for ; Thu, 16 May 2024 06:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1715865106; x=1716469906; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4V904prVi6oQ5IyZz7aDLXAgfOChEzLZtTfRAaiZkwU=; b=HKkIiKKglEbZ0hNaJB/6vEr2kjrfTrAMUPaj+Ct9bWmyMQA8SkQKvrQg76KjBrhUDw q8pq4iGam6QFNqGlYJ8XhdLlsbe8rwle8BtK8Yzs15RQbF855DfywMB7pBLjcnaj2wOl rcktK0svtAULtALURw4vcFxNsJzMgU7QBe9+zLUlTZ+3n+Mxl55MoOIu3uNbJWmth10o rYXY1FBNrUN1miG65K942JxmgsxAIQeibboAPzgXzJB2qYI5aq7GaJG1fSZkC/2DMdMY q+PZrMLZtF1XCXtv6AwqUtmKFy/mVByqlYuE14B6xeelv2axt6X0fNVBPYacEP7tdK92 rx0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715865106; x=1716469906; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4V904prVi6oQ5IyZz7aDLXAgfOChEzLZtTfRAaiZkwU=; b=vwxi4TRng2SY8mlWASWYu8/Ahi78uKXzCtTEriTSmwcbYY2jptMpcgWwJG1mMwRmge 8lCqf3rsUFaQxX620czKq7KAo8U4OMf4hc/2gHhRc6oIJf3B9YtZawFRHsjDDT8GmmOf EFM/eo938i0o2DiSIoLCDwT70kefXkCN/4N8/S+tQvAE4YCOHnEnk34JH5gFOdFhMRlu P2/eaQyBn1A1zMuOw+5Q5XfSMaldxwkggUmyBLqt2t6i8wZvfYAppByAf43aLe9CJrry K0F4SL+TYM2iJTbrfXdEqbhJIxz0g5fP5+aj9kBUnizLswhapl0aH/cm2U7aS+hjprnx OnSA== X-Forwarded-Encrypted: i=1; AJvYcCXTQ6W7BmRBMotWdRkkyqllLxqDby6N+s43u/aPJ/zA8qYEb7k2wafUebEpfvlVJlWxZERTEj5prjngGb9PsULwLM5iQuoMLzqCdIDo X-Gm-Message-State: AOJu0YymxWSjMj00R6k2MXuUhL1rVz7/+KI+RrEgWBDSzgTA5lKSItw1 hW196EL0ne/k+Tbimjg1pLuwtf9wmwJVAUVKkiNMpeum3j/tnDEmHr4MQwHmN95bbj30q7eky8R ULKR4M0TLQzUKDofR5eF3CveV3Zn0EkIGAi3hRQ== X-Received: by 2002:a81:77c2:0:b0:618:9198:1a9b with SMTP id 00721157ae682-622af7af307mr115191067b3.3.1715865105680; Thu, 16 May 2024 06:11:45 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240503-dev-charlie-support_thead_vector_6_9-v6-0-cb7624e65d82@rivosinc.com> <20240503-dev-charlie-support_thead_vector_6_9-v6-3-cb7624e65d82@rivosinc.com> In-Reply-To: <20240503-dev-charlie-support_thead_vector_6_9-v6-3-cb7624e65d82@rivosinc.com> From: Andy Chiu Date: Thu, 16 May 2024 21:11:33 +0800 Message-ID: Subject: Re: [PATCH v6 03/17] riscv: vector: Use vlenb from DT To: Charlie Jenkins Cc: 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 , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, May 4, 2024 at 2:21=E2=80=AFAM Charlie Jenkins wrote: > > If vlenb is provided in the device tree, prefer that over reading the > vlenb csr. > > Signed-off-by: Charlie Jenkins I agree with Conor that we need a mechanism to turn off v and all depending extensions with has_riscv_homogeneous_vlenb(). And that can come after this. Thanks for adding the homogeneous vlen checking! 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/cpufeatur= e.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) __r= ead_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 *__u= nused) > early_param("riscv_isa_fallback", riscv_isa_fallback_setup); > #endif > > +static int has_riscv_homogeneous_vlenb(void) > +{ > + int cpu; > + u32 prev_vlenb =3D 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 =3D 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 !=3D prev_vlenb) { > + of_node_put(cpu_node); > + return -ENOENT; > + } > + > + prev_vlenb =3D vlenb; > + of_node_put(cpu_node); > + } > + > + riscv_vlenb_of =3D 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_homogeneo= us_vlenb() < 0) { > + pr_warn("Unsupported heterogeneous vlen detected,= vector extension disabled.\n"); > + elf_hwcap &=3D ~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 =3D riscv_vlenb_of * 32; > + return 0; > + } > + > riscv_v_enable(); > this_vsize =3D csr_read(CSR_VLENB) * 32; > riscv_v_disable(); > > -- > 2.44.0 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv