Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp6313lqp; Mon, 10 Jun 2024 15:59:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPjswcrYUDEs9TEc4DhQ2Q2SIG2Gb59NUdtb/DoX66s4QdCucsjcRFkC1JIlTdkXVUhMiuGYFD8yp0/TuFYrR102NGhH7MHDMzoM8PFg== X-Google-Smtp-Source: AGHT+IHHVRPgCuELCaWInx+Z2R/oRw0NwQZjTrBZhXb1kZZ8H7k15GjFVVgVex49eUTH1C5I8dJc X-Received: by 2002:a17:902:ec8d:b0:1f6:138e:59e8 with SMTP id d9443c01a7336-1f6d02e08f8mr123882025ad.22.1718060397303; Mon, 10 Jun 2024 15:59:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718060397; cv=pass; d=google.com; s=arc-20160816; b=j4BdDCpAIptl1XXq8RiUwJZgeuL8adbxdZi4V4ZHLjYt7mmJSbG+mrjDnJwZd1FAEW DIDR7Vl/vhsvbYPiyMvglDkuXYkVPFeintmJyBRR58TPneVlyl8+JfUpFrQsen1EHf+L uW1iGjVcA5hdV6MbXsrN89LMZ0UNVIB19q2DsPk330WgpVaG4TN8znH1AYJNo0PRGek6 EHUJzpv3p4Cy+itnn010PFp4XTEOpNZ7ezTE/6mCSFdZ9a+gLF5QxkJFqEIEJQ9qENXD KFdaU+DFJU9E8+OcLR3VTiTdcu/PK5MNSdzSCus83AAV0Uzh8SvO2vFgaLxcCsGYTJFt Mh9w== 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=oHTAY5yEl/Y6PpmusZpcPgurACNcOhKAZ/OtUZtn5aY=; b=tCzfyIWJeyMcPMXUfrX8HqDpJp9Gp1D/lCuztNUIKs8lES9nHS63dtpGIv1EjWFA00 7Z8njxPI1u684sDL21RqaQpXnBJwF6oBnebSvVWNJb9O67UoaHreTnfLVfALTM+O2c06 4pXegw5ekj8IBTxy4CAgk7TDUNxTxnX/qYZSASnTN2SBQ0UePCAPM11XhskKQ+sWTmUj rzkIquQFCsD/wXTyccgEWEVAyM8GjVEotRI+ZRwtCGlISoKuaMWJSMkstWDw3sELadFQ PUE1XCzW3wFqVldXNLLAo4eO2tLmNA6sCeaQGjjin0wVqZU651hfNXyieSYcTNP61GfY eOeA==; 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=Ul3q1k6W; 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-209025-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209025-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6da3a26c5si41115775ad.345.2024.06.10.15.59.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 15:59:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209025-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Ul3q1k6W; 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-209025-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209025-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A7980B23816 for ; Mon, 10 Jun 2024 22:58:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B05B154430; Mon, 10 Jun 2024 22:56:58 +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="Ul3q1k6W" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 BF9351534EB for ; Mon, 10 Jun 2024 22:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718060217; cv=none; b=tTD5TsazEk4msSsUnfCH2IRgnqUZvUKfKh354i3K2R1bOEoeDYjp2WBSCSkOg+4OIfG8r3V5RV2Ntbppx67jWGC9Ew6wZIiiUTjIZW4oTHKAO6ej2X11bCaPCQwmZgnuTGoJtUw3pw7C2CUS9amcqZp0x1RVQNRMl8scGiGHtfk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718060217; c=relaxed/simple; bh=Be9GFskCPaOhLa/vnEPQwyxN6jle/+xWeXOMsnFs0uY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MaAygv7rO3UGC1kgEAkUYhK128c8MS+AI4ss57lva7ZDhuRiA5ajffwsbrtoacU0l4GF2HEa6NOeJ4g1WJ/zfj8X/+8VlRjaQd5eXvGWFnFp6ldcV2LTqa215zaZFpSJAgSju5giN0Jm+LrbcKTBwQs4wv2jfc/HrPs4icZQUJM= 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=Ul3q1k6W; arc=none smtp.client-ip=209.85.214.178 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-f178.google.com with SMTP id d9443c01a7336-1f7274a453bso3742625ad.2 for ; Mon, 10 Jun 2024 15:56:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1718060214; x=1718665014; 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=Ul3q1k6WiMj2TGLBzsTjKODbQqmMPZMIwKcEoMcplnYbhQ/6MUs52bzU4X0v8FMjEj OuP8HLTrHks09lpqykSib2qJDqq2f4QTT7cCi5OfqV7AE/gpisppZ8k5+bJbjgxZ+1RK GUy1hrg6QD0q+JnFDRz/3I7z2kPnE5UxrAWIa9rANOA61wXWzKlAqR7WDTqIb5is6yP8 RC/Qap+LcbxIu/xTzsHS2WIN22Qt4h6Kcc/w7BdRlhmNjguR3nc9/2SdhYhe8gu6OJ7C 2SKOd5WNoMcuM7hgf/QJY8PKVK6sGTQktP/IjGK0DNSB/T+wKc8F6Yfkg7wPAWEaQh8F 4pPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718060214; x=1718665014; 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=QUnRZQ+ZnxF0zuMV0CIOX+kmAcSgjOEQ8dEA93oExOyQHRx658KQ8K2OICO0iKpBZo dHyPRcLCbqGgM13Uvy8tHWPRye3Ax1QH/9fA+iasJ1IJ72A0GRcv6e9CgcAtBKXngbR5 dkaaRFr1NjmSt3U2CiHNhvXQvstGfN5L//82YUaPX86J3BGLGX9svJ1DYwwkPChkGz6A bCd9j4F7o18/86QETTV2oalytophOi/l6TfUzG10TKIdkP6ztAU3Mz9f5BkJwxkclaDY dePrYQVo0eDmFsnoC3AqCzbQB8YmizsDNBAJUoDGFZgzoij9o9LnAYJ7IUfbS/I4VhlV V5Ww== X-Forwarded-Encrypted: i=1; AJvYcCW+rX4uhmFfI+97ixm85HC/PIp7nRKSg/ypNG0kwRMKN6ab1g5l786XSfTBNHDXKT3VSiuYsdci/fjYvQH7yGWQH4gfPRowAmd4cVSa X-Gm-Message-State: AOJu0YyFmgq2zMIwDJkWpricNxt1DDT+o6LdDvjmrxHuZjFxRZPi78gp KPdAE28QUXnSSYIM9Hs6mi2FojqM/tEwh28to/XZM0sPJIrrOpTVbcfHsHvSlv0= X-Received: by 2002:a17:903:183:b0:1f6:225e:67a1 with SMTP id d9443c01a7336-1f6d03ca5femr131064715ad.56.1718060214052; Mon, 10 Jun 2024 15:56:54 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f71b597072sm18355865ad.99.2024.06.10.15.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 15:56:53 -0700 (PDT) From: Charlie Jenkins Date: Mon, 10 Jun 2024 15:56:41 -0700 Subject: [PATCH v2 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: <20240610-xtheadvector-v2-4-97a48613ad64@rivosinc.com> References: <20240610-xtheadvector-v2-0-97a48613ad64@rivosinc.com> In-Reply-To: <20240610-xtheadvector-v2-0-97a48613ad64@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 , Jessica Clarke 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=1718060203; l=4997; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=Be9GFskCPaOhLa/vnEPQwyxN6jle/+xWeXOMsnFs0uY=; b=RC7ToHOdBgiWxMdyMqRsLKTuCAuSk+knvsLRi71xDnNautlNotdlEUZg7JILaAMRLtgXvbamE a+j+1i4ckiNDcblcxj/LeFJ0+fmv5x1yhyE1T4vZdkuP7brD28WWC5m 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