Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1476533lqt; Sat, 20 Apr 2024 18:05:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzwbCYHg2I12FTyh4PY0TzKDua/idybluYV0ZH3y2glrqF3GTDHdPFcksbu3BVO8zG9vLEI84sCwOP+JiTSMkDGVdNfeW/c2ViKncXuA== X-Google-Smtp-Source: AGHT+IFL8FvNE5zHS/SCOrt/73zADPFe+8/OxStz2O1Pl7/eOjaZOdnc/CXnP/KYsN70CE/hhUWU X-Received: by 2002:a05:6a21:1f0f:b0:1a7:4944:d32 with SMTP id ry15-20020a056a211f0f00b001a749440d32mr11799114pzb.7.1713661557449; Sat, 20 Apr 2024 18:05:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713661557; cv=pass; d=google.com; s=arc-20160816; b=kj14Ic5OjjCIOL9H5V871KXICKaX0JkGRo4YD9v7LNfePCWUAlJffjiPp0fJhDosKO YhcmFhRjHQ+R8xrybGv48nl8ONpqhCixYoDLcPyhgHX1K4CyDlHIaWhcuimfCBuj57+5 lY0BWNm6fueOdAQK/yVF1etu1NflfdMtWNAXmhLK8abalEvqjm588LWgVoiNsz26vdsk Qkgn8JwNgFnw0Q6THgX+HU8+ChaHrLYGc5ctPz6eAPZoQFiwxX6Yyp+nb0RRiIdThSm6 or8UbThz+MXg4GKDmtLCB8xLpl6JAJTLLrms6tVAFmtIKMo26B+heJFPdwbpb+tv9gGI SsCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=EwiZxNeYR2dsOfUqNH+FhNResBaJwUAOM6PgWjZ96ng=; fh=wMiunMUrWNWW+POFQMjaxYzGcYO2kG8FAXV9GUeGm/I=; b=ffMAQafLN9OS8yDf1eFkKA2ALA25TMMRXx2LmoKivAKpTNSKl0EoZ3G9MO9f/oCbhS oleCdbKGNO/m+YxsRijB4GHc5FZaS2TBy1xUN81pvgdfPmUsokFqBe/aUQqa5tdcFmrP ryjmmcVrfKCJ0riMeNjymRv5wofG8f0ns2LkLCyIzNNdv05MSk9TRdR0H7NrzXPceBAu pe+FszbuZvF3OAv7DLsGp5EjTMWiuxbyuwixBWpclEH1lAHO97ekqTkIyL2fyKvirJhI jmS5TfSv48X1UAPBzU5Z2e56bX6itxmXHDZwGH4k5JMSe8kXwNlRDvz6r/qPadJ5Z+lY bt3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hy0LN10F; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-152407-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152407-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j14-20020a63594e000000b005ce087e004dsi5372674pgm.799.2024.04.20.18.05.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 18:05:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152407-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=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hy0LN10F; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-152407-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152407-linux.lists.archive=gmail.com@vger.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D7718281810 for ; Sun, 21 Apr 2024 01:05:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE9351078F; Sun, 21 Apr 2024 01:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="hy0LN10F" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 8D200D2FE for ; Sun, 21 Apr 2024 01:04:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713661495; cv=none; b=KsdTl8c3DfWDcgQ7DWXldP8PclO5jV6DxYDT3hbHwdCj9D7NinmvaLXI68D0S6JEvDgksGT0Sx8rkq6W0cKScRjmpULYpWMJ3HrHhVVgMOTxh+qtb7mRwmofD6CHzEgJvCU7rI5BrAYjo64xlOKU6Ft9eOpWfKBYKhfnxt0LOrE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713661495; c=relaxed/simple; bh=2wg73hE7GfHtQm3h56N22EjVsvIgG2uOGknAS+HQCok=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q3uTGMwkKWd3M0mGOt+9gt1LOKI4ZySF45HauGUFW33nr/alqqjmAM58iK6BgpJ914mAKdlvf5rULQtSlbPmaC7i98ZokEHiM8JcWx5Ek85W0d6Eh7FF6wfGJKs0AcOxnYoht9qjnYykisC041sjf1zaJzSVb/2PegyuSaIz4OM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=hy0LN10F; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1e2c725e234so33221555ad.1 for ; Sat, 20 Apr 2024 18:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713661493; x=1714266293; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EwiZxNeYR2dsOfUqNH+FhNResBaJwUAOM6PgWjZ96ng=; b=hy0LN10FKAUvGCAyJySBNGWy+JOZYuTWFCC/bV9t4RQIBLWF8VAdoJmLoOqzUDAoXd OmctypurqvMJW8dn0R0l3SGfieF2dPI19IESEcEuswKsXYBrgLzvhKfPOkEOqIM9YBwC NTE7gVkthaaYnVIHpckRbWl90x2Y7/AYGPGXL9A509kH3tHKCAb/kWUJNSs8b+6cYoR6 RoMzlRfirkpiHAcXlOg/hpiPtHXaMjjXkYR9mrTlrk1dc32mq6k1FHi2iUj5WnqyK4jX x8KlbY551195/scMII92ujL7TKmBmGf5I9dL2mOvL2nbbDgA8j8C+atp5Xh20siIFrAQ sJBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713661493; x=1714266293; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EwiZxNeYR2dsOfUqNH+FhNResBaJwUAOM6PgWjZ96ng=; b=TeFk8xVJdeWGs002VSpz3oAECwzf02BqY5s7Yu2x4WMNhf7DEg3bLXZD2AYmn5NuqP DuYdnwKPzAPuoBokcoop4TR69Mr4Z/hM4KUlRBP/Bu834DyXIYGk3D8wqT6nzs0OYOq+ nqevadUQpGDQypMw9hczEjsMVUSXA7OoM2YBBjs4tdZF4cj9aE6tt+UAnkYQfgIQuOxL gIuFqu6Sp9qS/aJxz8ExeQpUVTOc9DgEi39Bw6+dSCDUS6w4zgRHlx2aq0a4+h0MtdzL xXw4QmxwQfu/RgHYWqHR/KoJOHyubw8s0SiSiZ6be1fOB2OBS/7Fd4TOFQdXDKahQ/U/ xkPg== X-Forwarded-Encrypted: i=1; AJvYcCWDRdQXnDMdpEnVz0Im0XDLV4OnIwcGS0ymb9VbKYEiVYdwuYbIIOjzZnwCDJVp0IsVck+nvbesGRrPWJorvDRS6uDQngveGc39c6xs X-Gm-Message-State: AOJu0YwL79cyTMgJIBqo5aJSKRBVMs6BhNQtt4fcXdD21QNTOFc7eBT7 H4eDOyf9v8BW3wTG3s44zaffxMBxm3tlPY26geCn628C9ZQxMLrvb/yYVLseEmA= X-Received: by 2002:a17:90b:3651:b0:2ac:e2c6:3d40 with SMTP id nh17-20020a17090b365100b002ace2c63d40mr4937324pjb.18.1713661492951; Sat, 20 Apr 2024 18:04:52 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d6-20020a63d646000000b005dc8702f0a9sm5249627pgj.1.2024.04.20.18.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 18:04:51 -0700 (PDT) From: Charlie Jenkins Date: Sat, 20 Apr 2024 18:04:36 -0700 Subject: [PATCH v3 04/17] riscv: vector: Use vlenb from DT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240420-dev-charlie-support_thead_vector_6_9-v3-4-67cff4271d1d@rivosinc.com> References: <20240420-dev-charlie-support_thead_vector_6_9-v3-0-67cff4271d1d@rivosinc.com> In-Reply-To: <20240420-dev-charlie-support_thead_vector_6_9-v3-0-67cff4271d1d@rivosinc.com> To: 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?q?Cl=C3=A9ment_L=C3=A9ger?= , Jonathan Corbet , Shuah Khan Cc: 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, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1713661481; l=3089; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=2wg73hE7GfHtQm3h56N22EjVsvIgG2uOGknAS+HQCok=; b=oM9AC2pUhODrL99+ED3B1dn5wieUo9QyYC4T1kj5tzYQfCtIJrkTGR8vysGpRIw+kQlGk+mi7 bsmO7wcPIwDB1FbAfGYW4T6Jm4ic0X5z8Xk03t1wB+GrmxR6X8cHp4S X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= If vlenb is provided in the device tree, prefer that over reading the vlenb csr. Signed-off-by: Charlie Jenkins --- arch/riscv/include/asm/cpufeature.h | 2 ++ arch/riscv/kernel/cpufeature.c | 26 ++++++++++++++++++++++++++ arch/riscv/kernel/vector.c | 13 +++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 347805446151..809f61ffb667 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_dt[NR_CPUS]; + void riscv_user_isa_enable(void); #if defined(CONFIG_RISCV_MISALIGNED) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index c6e27b45e192..48874aac4871 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) __read_mostly; /* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS]; +u32 riscv_vlenb_dt[NR_CPUS]; + /** * riscv_isa_extension_base() - Get base extension word * @@ -656,6 +658,28 @@ static int __init riscv_isa_fallback_setup(char *__unused) early_param("riscv_isa_fallback", riscv_isa_fallback_setup); #endif +static void riscv_set_vlenb_from_dt(void) +{ + int cpu; + + for_each_possible_cpu(cpu) { + struct device_node *cpu_node; + + cpu_node = of_cpu_device_node_get(cpu); + if (!cpu_node) { + pr_warn("Unable to find cpu node\n"); + continue; + } + + if (!of_property_read_u32(cpu_node, "riscv,vlenb", &riscv_vlenb_dt[cpu])) { + of_node_put(cpu_node); + continue; + } + + of_node_put(cpu_node); + } +} + void __init riscv_fill_hwcap(void) { char print_str[NUM_ALPHA_EXTS + 1]; @@ -675,6 +699,8 @@ void __init riscv_fill_hwcap(void) } else { int ret = riscv_fill_hwcap_from_ext_list(isa2hwcap); + riscv_set_vlenb_from_dt(); + if (ret && riscv_isa_fallback) { pr_info("Falling back to deprecated \"riscv,isa\"\n"); riscv_fill_hwcap_from_isa_string(isa2hwcap); diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c index 6727d1d3b8f2..fb7f3ca80d9e 100644 --- a/arch/riscv/kernel/vector.c +++ b/arch/riscv/kernel/vector.c @@ -32,11 +32,16 @@ EXPORT_SYMBOL_GPL(riscv_v_vsize); int riscv_v_setup_vsize(void) { unsigned long this_vsize; + int cpu = smp_processor_id(); - /* There are 32 vector registers with vlenb length. */ - riscv_v_enable(); - this_vsize = csr_read(CSR_VLENB) * 32; - riscv_v_disable(); + if (riscv_vlenb_dt[cpu]) { + this_vsize = riscv_vlenb_dt[cpu]; + } else { + /* There are 32 vector registers with vlenb length. */ + riscv_v_enable(); + this_vsize = csr_read(CSR_VLENB) * 32; + riscv_v_disable(); + } if (!riscv_v_vsize) { riscv_v_vsize = this_vsize; -- 2.44.0