Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp835416lqb; Wed, 29 May 2024 11:54:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVftkLzjGzCom09tmT5rCZjcjTCYhXyGdKGDPSuu96Xq3pSK8Wbnsw3A03llj1TXy8ywcmbQGkvIIAEiGv/nNqkDBcWTw1qOv1T68zGvg== X-Google-Smtp-Source: AGHT+IEY+bRneNZunOucdCIr3lWePP2wnfupfbzZON8UHxl/eylar8yaO7uMeDOOGLnIA4r7c2sm X-Received: by 2002:a05:6a21:621:b0:1b0:106e:89c2 with SMTP id adf61e73a8af0-1b259a093acmr3977833637.2.1717008893203; Wed, 29 May 2024 11:54:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717008893; cv=pass; d=google.com; s=arc-20160816; b=FbclYUiZm3ViPjaDflYQAtnrCyT2f7CAyG48gte51npbgNszIZo3Ab0S8t/QkJN977 7GpQSVgZMi5e5unvy5ftEYyXk8tV6CgWAkubGbcklXI4D+rhCbokPjp0WesWcBJ0FOLH YpF/VLoGTnpu1vXEM+fdcFYgwNnAj+L0TXJpATO5Ye4J8hmyWy49I9nXkdZn6BlmajGi peweEZftYbtH+vre24YfZO2ItGrYpdZ9Lapun/9YvnvB8ebpzk3xrKI/SDDIZiw40gup wmSReIIkl4eFgZgz2Z/L6CCvyTtk+vIAaIGnrJHsPM0Ae+sa6+ku0pI8nKKvZRmslFS/ 84UA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9bkrwFm3shuYsCyMH7CeeRCQ3k6hoLktrnsincGFelA=; fh=kBdCQaOVNAy9qSG3CDpsA+r2JBl8hKEllFYDBUVF5kM=; b=F3X1EdsORuT4q5j5Ag0ztpcoGR9tOKYwK5O2Qi2qO7at9rRaynAoCS9OwmN5fYkWwv eW/RHCSMz7ojLikl9HTKoUBdbcl3hsjm7SkmDf9YoA/kMAH5U8NzpT1xvOmXnMeaw/5/ 4lOmBEdsyMYe+buIuDwPzHE0TqW4jO/VMaOWnhB4K+vlHB/rbZR8iAxXdaR92f6+6e/Y 1qCd9wlBdiAPDlPTDK4X3vAAUDXmtLhcRSkc3mv3fQm+ojI6Ew7U1t7+uoudJY2f8Cuh f/kVjgci2D+giErUUnpRqy6+oILy1pxXK3IiC5b+8KrAxiifG4fHpYtGNhsZQ3doSJzk KayA==; 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=PkslBels; 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-194585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194585-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6822779ba0bsi10731873a12.418.2024.05.29.11.54.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 11:54:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=PkslBels; 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-194585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194585-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 A0D722838AC for ; Wed, 29 May 2024 18:54:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C1FC1C230B; Wed, 29 May 2024 18:54:36 +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="PkslBels" Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 C6A911C2312 for ; Wed, 29 May 2024 18:54:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717008875; cv=none; b=hVMJS8F6L8sL17nGtP8wdtZWN5sKk3bT7YZM6UsAu86oM4+S9n/DKIygazSnuA8ainSLKeRVwPK90iCJyXGcuA6TUyIvtTF5y0VJ8S8fAvuwwZep5DUIU/a8LEgVkLE8NLs0dVrTZCgO+BgKkgVQxefdSgfh3S8WRYyHrLXNYtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717008875; c=relaxed/simple; bh=cxmtmKz3E4f94afNiy72jSn+uklIphZ48Rhdqmo7TFI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cuxbpm/H9wt+fCapvSOI24Wzs5YQYGAmS5NTaM42FVNIRb8LwhbabuagVikxhMy+94auM7O2pg/wivSaHwNt9WPdVSlt0bq6B4bFFumtZsmPsudpQLbzkeBJstNUMGYdxMqiqet2tS+INLuHP5KYvDmzICusIBVPE1yXkz5Gvhg= 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=PkslBels; arc=none smtp.client-ip=209.85.221.51 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-wr1-f51.google.com with SMTP id ffacd0b85a97d-354de3c5d00so20231f8f.1 for ; Wed, 29 May 2024 11:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1717008872; x=1717613672; 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=9bkrwFm3shuYsCyMH7CeeRCQ3k6hoLktrnsincGFelA=; b=PkslBelsXIwtqdornnU135YD2O0Nb8KaXLpKAcQ+R/ytmxrPk2UDu2lK5MxejiDxfu vyMYnBrxZisYWjHAYR3l36PmA3PDRlrJODZ56bviN2CIOboNjCtopDjJgvItK83YTOUc 5S+SjotwhkwexD1w1foWM6QPw90CyFyBLh/U48CjCVn9vZk5WT0bMvtL1GKQzfSM57gV wHhH5JadINFX0Iy62QplGfEVwTSSyp8cNEGB0dzdtCxXOi60sFD8fHwXcv6k39iioqL4 OCof61XVbs1iQ2xWXbN+6qSdbxpogBnZisDwmoS3ZPQIoWUzEOkH9qN9Oym1Z9+CSJd6 GJmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717008872; x=1717613672; 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=9bkrwFm3shuYsCyMH7CeeRCQ3k6hoLktrnsincGFelA=; b=LZoFI1xtlMWAu6O6elchLGv2Xt7mbsOnHUe5TIeexK1GbxATCqhIEK7tukvC0GV35r hN1Ymd60534fboWB5gw+rwq9mR4P/7FwRUjkayCROC5q95UMyFfMFkQTKOJ04F9LLA2K v6jMaFn8p5NbEFu1WknusgNVAFR7GEEObZNc9KOf+Cp4xm4wpLEDq4XtHU74bv3eKKiE 46Udc6q+/BQkO9o8vuM4XbrTqNmsm4sGCc5g5H7mYv22n8obHsnukSLgFI+cEYfw+BsK G7z2JDDaJgVhphZL0OfxFBUs9t0vlpB9KgCvs1LD1QZzIBHOFBg9urvzlAFblnscNfsn /nGg== X-Gm-Message-State: AOJu0YxAC6AnfFpO48G+rvYKhDx5BIp0S1yvXw6rdbzK4QDZ1bc/c/IK HhH1hDh1XBVfNX21AGP4f+ST55LazyJYWCMAk8RWDBIhu+P9fG12S3wQRwdrEt95P1iTxN5QWZg t X-Received: by 2002:adf:e3c1:0:b0:34d:9b4d:2a43 with SMTP id ffacd0b85a97d-35c7672a78bmr2946621f8f.0.1717008871994; Wed, 29 May 2024 11:54:31 -0700 (PDT) Received: from rkanwal-XPS-15-9520.Home ([2a02:c7c:7527:ee00:7446:71c1:a41a:da9b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4212706a23csm2787885e9.27.2024.05.29.11.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 11:54:31 -0700 (PDT) From: Rajnesh Kanwal To: linux-kernel@vger.kernel.org Cc: linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, ajones@ventanamicro.com, anup@brainfault.org, acme@kernel.org, atishp@rivosinc.com, beeman@rivosinc.com, brauner@kernel.org, conor@kernel.org, heiko@sntech.de, irogers@google.com, mingo@redhat.com, james.clark@arm.com, renyu.zj@linux.alibaba.com, jolsa@kernel.org, jisheng.teoh@starfivetech.com, palmer@dabbelt.com, tech-control-transfer-records@lists.riscv.org, will@kernel.org, kaiwenxue1@gmail.com, Rajnesh Kanwal Subject: [PATCH RFC 2/6] riscv: perf: Add Control transfer records CSR definations. Date: Wed, 29 May 2024 19:53:33 +0100 Message-Id: <20240529185337.182722-3-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529185337.182722-1-rkanwal@rivosinc.com> References: <20240529185337.182722-1-rkanwal@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Adding CSR defines for RISCV Control Transfer Records extension [0] along with bit-field macros for each CSR. [0]: https://github.com/riscv/riscv-control-transfer-records Signed-off-by: Rajnesh Kanwal --- arch/riscv/include/asm/csr.h | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 701963b64fc4..a80a2ee9d44e 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -309,6 +309,85 @@ #define CSR_SSCOUNTOVF 0xda0 +/* M-mode Control Transfer Records CSRs */ +#define CSR_MCTRCTL 0x34e + +/* S-mode Control Transfer Records CSRs */ +#define CSR_SCTRCTL 0x14e +#define CSR_SCTRSTATUS 0x14f +#define CSR_SCTRDEPTH 0x15f + +/* VS-mode Control Transfer Records CSRs */ +#define CSR_VSCTRCTL 0x24e + +/* xctrtl CSR bits. */ +#define CTRCTL_U_ENABLE _AC(0x1, UL) +#define CTRCTL_S_ENABLE _AC(0x2, UL) +#define CTRCTL_M_ENABLE _AC(0x4, UL) +#define CTRCTL_RASEMU _AC(0x80, UL) +#define CTRCTL_STE _AC(0x100, UL) +#define CTRCTL_MTE _AC(0x200, UL) +#define CTRCTL_BPFRZ _AC(0x800, UL) +#define CTRCTL_LCOFIFRZ _AC(0x1000, UL) +#define CTRCTL_EXCINH _AC(0x200000000, UL) +#define CTRCTL_INTRINH _AC(0x400000000, UL) +#define CTRCTL_TRETINH _AC(0x800000000, UL) +#define CTRCTL_NTBREN _AC(0x1000000000, UL) +#define CTRCTL_TKBRINH _AC(0x2000000000, UL) +#define CTRCTL_INDCALL_INH _AC(0x10000000000, UL) +#define CTRCTL_DIRCALL_INH _AC(0x20000000000, UL) +#define CTRCTL_INDJUMP_INH _AC(0x40000000000, UL) +#define CTRCTL_DIRJUMP_INH _AC(0x80000000000, UL) +#define CTRCTL_CORSWAP_INH _AC(0x100000000000, UL) +#define CTRCTL_RET_INH _AC(0x200000000000, UL) +#define CTRCTL_INDOJUMP_INH _AC(0x400000000000, UL) +#define CTRCTL_DIROJUMP_INH _AC(0x800000000000, UL) + +/* sctrstatus CSR bits. */ +#define SCTRSTATUS_WRPTR_MASK 0xFF +#define SCTRSTATUS_FROZEN _AC(0x80000000, UL) + +#ifdef CONFIG_RISCV_M_MODE +#define CTRCTL_KERNEL_ENABLE CTRCTL_M_ENABLE +#else +#define CTRCTL_KERNEL_ENABLE CTRCTL_S_ENABLE +#endif + +/* sctrdepth CSR bits. */ +#define SCTRDEPTH_MASK 0x7 + +#define SCTRDEPTH_MIN 0x0 /* 16 Entries. */ +#define SCTRDEPTH_MAX 0x4 /* 256 Entries. */ + +/* ctrsource, ctrtarget and ctrdata CSR bits. */ +#define CTRSOURCE_VALID 0x1ULL +#define CTRTARGET_MISP 0x1ULL + +#define CTRDATA_TYPE_MASK 0xF +#define CTRDATA_CCV 0x8000 +#define CTRDATA_CCM_MASK 0xFFF0000 +#define CTRDATA_CCE_MASK 0xF0000000 + +#define CTRDATA_TYPE_NONE 0 +#define CTRDATA_TYPE_EXCEPTION 1 +#define CTRDATA_TYPE_INTERRUPT 2 +#define CTRDATA_TYPE_TRAP_RET 3 +#define CTRDATA_TYPE_NONTAKEN_BRANCH 4 +#define CTRDATA_TYPE_TAKEN_BRANCH 5 +#define CTRDATA_TYPE_RESERVED_6 6 +#define CTRDATA_TYPE_RESERVED_7 7 +#define CTRDATA_TYPE_INDIRECT_CALL 8 +#define CTRDATA_TYPE_DIRECT_CALL 9 +#define CTRDATA_TYPE_INDIRECT_JUMP 10 +#define CTRDATA_TYPE_DIRECT_JUMP 11 +#define CTRDATA_TYPE_CO_ROUTINE_SWAP 12 +#define CTRDATA_TYPE_RETURN 13 +#define CTRDATA_TYPE_OTHER_INDIRECT_JUMP 14 +#define CTRDATA_TYPE_OTHER_DIRECT_JUMP 15 + +#define CTR_ENTRIES_FIRST 0x200 +#define CTR_ENTRIES_LAST 0x2ff + #define CSR_SSTATUS 0x100 #define CSR_SIE 0x104 #define CSR_STVEC 0x105 @@ -490,6 +569,8 @@ # define CSR_TOPEI CSR_MTOPEI # define CSR_TOPI CSR_MTOPI +# define CSR_CTRCTL CSR_MCTRCTL + # define SR_IE SR_MIE # define SR_PIE SR_MPIE # define SR_PP SR_MPP @@ -520,6 +601,8 @@ # define CSR_TOPEI CSR_STOPEI # define CSR_TOPI CSR_STOPI +# define CSR_CTRCTL CSR_SCTRCTL + # define SR_IE SR_SIE # define SR_PIE SR_SPIE # define SR_PP SR_SPP -- 2.34.1