Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp144233lqp; Sun, 9 Jun 2024 21:46:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWiUxcZviPXWqu6KXuEgJqSXfGnY+ySaQNbb5bzVJGxAC59KVdFAYW3v50qlJIGXG+qDgb3YVU4S0YjtsrHafdRKr+4E4zynuMz/6Iiig== X-Google-Smtp-Source: AGHT+IEB6AjNOgEQo9kOtkCYDsuaHtCXlOfNqKwVax8fjVtyrzPyTgDT7CUO1WtG0OKqHibWK332 X-Received: by 2002:a50:8d5c:0:b0:57a:3046:1cd8 with SMTP id 4fb4d7f45d1cf-57c5085eb2bmr6354897a12.7.1717994800431; Sun, 09 Jun 2024 21:46:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717994800; cv=pass; d=google.com; s=arc-20160816; b=uacrEN9yZbwPqieeXsxfDzprWid6CjQmrf25DXM+farl16kyUhlUgzoWvdd4/DDLI0 QL6sZIeNuvT65OzZTbycS1QK7dDNttjJXPfPQ25pOvUB/jo7U3nodoLbMPNjqwcRQ9ah 2vzZ2t10RMpbG7mSjH037VJondTomfowgRWNE8BYjqZRtGSQIg3cNiCbtEfvPcL4nIrI G1bpicUf8rmJdCKlPilC12Hl81i7xZc1LCK62PSoKoMI44pUCGIUEVxEqWalPcEt8Gzl MoMuQJPIUGmZzFzpPuKrHZcCdCUEnxFQYID7szov2Fs0B4cXaCyVH6UE6O+BzZ1H21r0 QtiA== 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=bt/OPDG5ozolIGkzcJWAUq0hvCz2HvO0aGCtSKiuUJE=; fh=bMEVpQp0R/16zr29N9ujEUSWvCfpka1pDrgi8Cr54Ic=; b=X7MRGa9TSL/R3yNtFfF6MChnxwiz4prz+b+B/+q/R5SDWkzWvjU2Tyn60pknkqMfaM G5kDKzmd/SSo0/5yI9p26MnqP1hh2KzwS+oFvM566OZNiPBy+O/W7vMiHDIFKuiM6a1e u84OjNc+xKIgB+oxz4SgkG/BLHtdYgvu1nrDPpZsubG5/JVZKoUmxTaefUjDqzWHCo9T gOjbs7hxk/YGgGObC7O2mYRo5cp0ccyEcuI4ztyMV91s2ZSGu1ZPHTKxXJWbW1rd2Jyk YJv+GtpjZbNfnKGxr1U76gVTLwSxwrwWVfD5cD5Gs5w0qfwCG3cVFMQUftaQTOHrDWfC FQeQ==; 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=M+uPt7vf; 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-207629-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207629-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae22aa6csi4299091a12.403.2024.06.09.21.46.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 21:46:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207629-linux.lists.archive=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=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=M+uPt7vf; 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-207629-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207629-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C78F01F219F3 for ; Mon, 10 Jun 2024 04:46:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9DA020B34; Mon, 10 Jun 2024 04:45:46 +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="M+uPt7vf" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 3195A1C694 for ; Mon, 10 Jun 2024 04:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717994745; cv=none; b=dMY9QsvK7gEYRElgrOicqhCiSjtBBLnuXC0RyZ/UdZMkNAZpgpQTkiMJS3Wkwc7rEf22wqZ5qn7ahvzOantuOfXhf70R955OwpajVUzCkuLy0Yaro8KZwuQDZVQibko31oBNz//n7rwlx2ZcD/mbwgEoN5Ohms525UGH1X7+T3Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717994745; c=relaxed/simple; bh=Be9GFskCPaOhLa/vnEPQwyxN6jle/+xWeXOMsnFs0uY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=svldQ4bSp/XM0MXqm5GnKJZQN99dcqw3BtcnZYkOPWNj150+kJacWEhRXFbbMCfhwxZo0eTcxi2VWaKmeHDtnIAYkazH/o/CAB9JdPuEUHYkj+eyuppQc9aB/CPkqhtrpe9UrgreWknqFn0Fl00JQ9Dl9mAehWvB0umS4WZeq1k= 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=M+uPt7vf; arc=none smtp.client-ip=209.85.214.180 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-f180.google.com with SMTP id d9443c01a7336-1f6f1677b26so8866935ad.0 for ; Sun, 09 Jun 2024 21:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1717994743; x=1718599543; 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=bt/OPDG5ozolIGkzcJWAUq0hvCz2HvO0aGCtSKiuUJE=; b=M+uPt7vfqyVlGb1n2WPLgWSOadfeyu9e4XzbVgDvwJgCoE5q9gKvG8BPfNMo13/+s/ Eqp2lM0aqENduJMeIyxP7SVPQTP5Zj9m9WRp98pBSFTN/WkCcA3y8a/uh+XlizvcLsUM DWH06n46Mf1x9IxKqoonLDGFe70zm8VnAxcv8ahugKTfWF7MalNZLpSg0TcU5qBU6LUy GigUcPjAvpmVM7Bu+GsSVjeV4ly90lQZDpV+QWhh0dMeEIPKFxPidgmopP301EG/6qzF ifs4WZu97XXX1osp0UleBFY5ajdEEbXyfK2vuec8tfE9JhMegJ9rTSrokRQBqvdA+GGy SWUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717994743; x=1718599543; 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=bt/OPDG5ozolIGkzcJWAUq0hvCz2HvO0aGCtSKiuUJE=; b=uRYzKFUr3d0xKfkBsTmx712t2q4U8QOlWUFw0q5zIQZd2aDQuNwWKmHTjT64Fu7KAY Qe3o6KxYrVTUQbQ1qRiw9R0YBfa2PgS4x0PpJTJMR0Y2z0q7pAUcFIf1wEc0ZFoQ6NS4 0iIazc9b5PTjT1m0MRj4Dkl/uzTs92SyfjK0A45O8w9AA8dBdnFvFXQgJMyNDZQSC3AX 86nfbMQTIYSyI4MprnvzMy4wZdA+jW+ZOmFa4TXMQuzHA1dp6U95txMJTOWDftjtyJs4 YdSAUNEV+TOyF1onxnrFxdIxOI91oaeTQwVuwWSlXqtFfwuz6sQu49X84nSmz9ZgvRMC OvhQ== X-Forwarded-Encrypted: i=1; AJvYcCVnewN2gsCKmzYZfibR4SL9jHs7tsjhDtD4hqquqiuh46NSkI9W67DRCPh7Eb/3viyHAt0airVMEhn9bHjUEnfUC2KP5V9+Ufmifvwo X-Gm-Message-State: AOJu0YzubE7RLhEYSk6c/T16d7t0nO0CbkiFaBwsIfGILfwsdX/kfC5D J+7FncsIXLKqWYoeAJVHK8VdjR4DlhKWZjDsaO2Fa7WoaKPer49g/t8Xgx7HiHw= X-Received: by 2002:a17:903:2444:b0:1f2:fe12:b7be with SMTP id d9443c01a7336-1f6b8f1c342mr174009835ad.32.1717994743536; Sun, 09 Jun 2024 21:45:43 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd76ce8asm73124095ad.77.2024.06.09.21.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 21:45:42 -0700 (PDT) From: Charlie Jenkins Date: Sun, 09 Jun 2024 21:45:09 -0700 Subject: [PATCH 04/13] riscv: Add thead and xtheadvector as a vendor extension 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: <20240609-xtheadvector-v1-4-3fe591d7f109@rivosinc.com> References: <20240609-xtheadvector-v1-0-3fe591d7f109@rivosinc.com> In-Reply-To: <20240609-xtheadvector-v1-0-3fe591d7f109@rivosinc.com> To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Corbet , Shuah Khan , Guo Ren , Evan Green , Andy Chiu Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.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=1717994732; l=4997; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=Be9GFskCPaOhLa/vnEPQwyxN6jle/+xWeXOMsnFs0uY=; b=mbzwm8EukXWWDz6wv6ztY1IDvgb2VXzMgEVGb5A9fHOy+U+h4tTF63h034I5z0jaG+9yErwwt vq3iXh7htG3D40mNmInAP0Pl5djxcFil2xteOUkUvuMiAvjABAek3yM X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Add support to the kernel for THead vendor extensions with the target of the new extension xtheadvector. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig.vendor | 13 +++++++++++++ arch/riscv/include/asm/vendor_extensions/thead.h | 16 ++++++++++++++++ arch/riscv/kernel/cpufeature.c | 1 + arch/riscv/kernel/vendor_extensions.c | 10 ++++++++++ arch/riscv/kernel/vendor_extensions/Makefile | 1 + arch/riscv/kernel/vendor_extensions/thead.c | 18 ++++++++++++++++++ 6 files changed, 59 insertions(+) diff --git a/arch/riscv/Kconfig.vendor b/arch/riscv/Kconfig.vendor index 6f1cdd32ed29..9897442bd44f 100644 --- a/arch/riscv/Kconfig.vendor +++ b/arch/riscv/Kconfig.vendor @@ -16,4 +16,17 @@ config RISCV_ISA_VENDOR_EXT_ANDES If you don't know what to do here, say Y. endmenu +menu "T-Head" +config RISCV_ISA_VENDOR_EXT_THEAD + bool "T-Head vendor extension support" + select RISCV_ISA_VENDOR_EXT + default y + help + Say N here to disable detection of and support for all T-Head vendor + extensions. Without this option enabled, T-Head vendor extensions will + not be detected at boot and their presence not reported to userspace. + + If you don't know what to do here, say Y. +endmenu + endmenu diff --git a/arch/riscv/include/asm/vendor_extensions/thead.h b/arch/riscv/include/asm/vendor_extensions/thead.h new file mode 100644 index 000000000000..48421d1553ad --- /dev/null +++ b/arch/riscv/include/asm/vendor_extensions/thead.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RISCV_VENDOR_EXTENSIONS_THEAD_H +#define _ASM_RISCV_VENDOR_EXTENSIONS_THEAD_H + +#include + +#include + +/* + * Extension keys must be strictly less than RISCV_ISA_VENDOR_EXT_MAX. + */ +#define RISCV_ISA_VENDOR_EXT_XTHEADVECTOR 0 + +extern struct riscv_isa_vendor_ext_data_list riscv_isa_vendor_ext_list_thead; + +#endif diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index f2c24820700b..2107c59575dd 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -25,6 +25,7 @@ #include #include #include +#include #define NUM_ALPHA_EXTS ('z' - 'a' + 1) diff --git a/arch/riscv/kernel/vendor_extensions.c b/arch/riscv/kernel/vendor_extensions.c index b6c1e7b5d34b..662ba64a8f93 100644 --- a/arch/riscv/kernel/vendor_extensions.c +++ b/arch/riscv/kernel/vendor_extensions.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -14,6 +15,9 @@ struct riscv_isa_vendor_ext_data_list *riscv_isa_vendor_ext_list[] = { #ifdef CONFIG_RISCV_ISA_VENDOR_EXT_ANDES &riscv_isa_vendor_ext_list_andes, #endif +#ifdef CONFIG_RISCV_ISA_VENDOR_EXT_THEAD + &riscv_isa_vendor_ext_list_thead, +#endif }; const size_t riscv_isa_vendor_ext_list_size = ARRAY_SIZE(riscv_isa_vendor_ext_list); @@ -41,6 +45,12 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig cpu_bmap = &riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap[cpu]; break; #endif + #ifdef CONFIG_RISCV_ISA_VENDOR_EXT_THEAD + case THEAD_VENDOR_ID: + bmap = &riscv_isa_vendor_ext_list_thead.all_harts_isa_bitmap; + cpu_bmap = &riscv_isa_vendor_ext_list_thead.per_hart_isa_bitmap[cpu]; + break; + #endif default: return false; } diff --git a/arch/riscv/kernel/vendor_extensions/Makefile b/arch/riscv/kernel/vendor_extensions/Makefile index 6a61aed944f1..353522cb3bf0 100644 --- a/arch/riscv/kernel/vendor_extensions/Makefile +++ b/arch/riscv/kernel/vendor_extensions/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_RISCV_ISA_VENDOR_EXT_ANDES) += andes.o +obj-$(CONFIG_RISCV_ISA_VENDOR_EXT_THEAD) += thead.o diff --git a/arch/riscv/kernel/vendor_extensions/thead.c b/arch/riscv/kernel/vendor_extensions/thead.c new file mode 100644 index 000000000000..0934a2086473 --- /dev/null +++ b/arch/riscv/kernel/vendor_extensions/thead.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include + +#include +#include + +/* All T-Head vendor extensions supported in Linux */ +const struct riscv_isa_ext_data riscv_isa_vendor_ext_thead[] = { + __RISCV_ISA_EXT_DATA(xtheadvector, RISCV_ISA_VENDOR_EXT_XTHEADVECTOR), +}; + +struct riscv_isa_vendor_ext_data_list riscv_isa_vendor_ext_list_thead = { + .ext_data_count = ARRAY_SIZE(riscv_isa_vendor_ext_thead), + .ext_data = riscv_isa_vendor_ext_thead, +}; -- 2.44.0