xref: /linux/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1a54ca194STan Xiaojun /* SPDX-License-Identifier: GPL-2.0 */
2a54ca194STan Xiaojun /*
3a54ca194STan Xiaojun  * arm_spe_decoder.h: Arm Statistical Profiling Extensions support
4a54ca194STan Xiaojun  * Copyright (c) 2019-2020, Arm Ltd.
5a54ca194STan Xiaojun  */
6a54ca194STan Xiaojun 
7a54ca194STan Xiaojun #ifndef INCLUDE__ARM_SPE_DECODER_H__
8a54ca194STan Xiaojun #define INCLUDE__ARM_SPE_DECODER_H__
9a54ca194STan Xiaojun 
10a54ca194STan Xiaojun #include <stdbool.h>
11a54ca194STan Xiaojun #include <stddef.h>
12a54ca194STan Xiaojun #include <stdint.h>
13a54ca194STan Xiaojun 
14a54ca194STan Xiaojun #include "arm-spe-pkt-decoder.h"
15a54ca194STan Xiaojun 
16a54ca194STan Xiaojun enum arm_spe_sample_type {
17a54ca194STan Xiaojun 	ARM_SPE_L1D_ACCESS		= 1 << 0,
18a54ca194STan Xiaojun 	ARM_SPE_L1D_MISS		= 1 << 1,
19a54ca194STan Xiaojun 	ARM_SPE_LLC_ACCESS		= 1 << 2,
20a54ca194STan Xiaojun 	ARM_SPE_LLC_MISS		= 1 << 3,
21a54ca194STan Xiaojun 	ARM_SPE_TLB_ACCESS		= 1 << 4,
22a54ca194STan Xiaojun 	ARM_SPE_TLB_MISS		= 1 << 5,
23a54ca194STan Xiaojun 	ARM_SPE_BRANCH_MISS		= 1 << 6,
24a54ca194STan Xiaojun 	ARM_SPE_REMOTE_ACCESS		= 1 << 7,
25*0066015aSGerman Gomez 	ARM_SPE_SVE_PARTIAL_PRED	= 1 << 8,
26*0066015aSGerman Gomez 	ARM_SPE_SVE_EMPTY_PRED		= 1 << 9,
27a54ca194STan Xiaojun };
28a54ca194STan Xiaojun 
2997ae666aSLeo Yan enum arm_spe_op_type {
30*0066015aSGerman Gomez 	/* First level operation type */
31*0066015aSGerman Gomez 	ARM_SPE_OP_OTHER	= 1 << 0,
32*0066015aSGerman Gomez 	ARM_SPE_OP_LDST		= 1 << 1,
33*0066015aSGerman Gomez 	ARM_SPE_OP_BRANCH_ERET	= 1 << 2,
34*0066015aSGerman Gomez 
35*0066015aSGerman Gomez 	/* Second level operation type for OTHER */
36*0066015aSGerman Gomez 	ARM_SPE_OP_SVE_OTHER		= 1 << 16,
37*0066015aSGerman Gomez 	ARM_SPE_OP_SVE_FP		= 1 << 17,
38*0066015aSGerman Gomez 	ARM_SPE_OP_SVE_PRED_OTHER	= 1 << 18,
39*0066015aSGerman Gomez 
40*0066015aSGerman Gomez 	/* Second level operation type for LDST */
41*0066015aSGerman Gomez 	ARM_SPE_OP_LD			= 1 << 16,
42*0066015aSGerman Gomez 	ARM_SPE_OP_ST			= 1 << 17,
43*0066015aSGerman Gomez 	ARM_SPE_OP_ATOMIC		= 1 << 18,
44*0066015aSGerman Gomez 	ARM_SPE_OP_EXCL			= 1 << 19,
45*0066015aSGerman Gomez 	ARM_SPE_OP_AR			= 1 << 20,
46*0066015aSGerman Gomez 	ARM_SPE_OP_SIMD_FP		= 1 << 21,
47*0066015aSGerman Gomez 	ARM_SPE_OP_GP_REG		= 1 << 22,
48*0066015aSGerman Gomez 	ARM_SPE_OP_UNSPEC_REG		= 1 << 23,
49*0066015aSGerman Gomez 	ARM_SPE_OP_NV_SYSREG		= 1 << 24,
50*0066015aSGerman Gomez 	ARM_SPE_OP_SVE_LDST		= 1 << 25,
51*0066015aSGerman Gomez 	ARM_SPE_OP_SVE_PRED_LDST	= 1 << 26,
52*0066015aSGerman Gomez 	ARM_SPE_OP_SVE_SG		= 1 << 27,
53*0066015aSGerman Gomez 
54*0066015aSGerman Gomez 	/* Second level operation type for BRANCH_ERET */
55*0066015aSGerman Gomez 	ARM_SPE_OP_BR_COND	= 1 << 16,
56*0066015aSGerman Gomez 	ARM_SPE_OP_BR_INDIRECT	= 1 << 17,
5797ae666aSLeo Yan };
5897ae666aSLeo Yan 
594e6430cbSAli Saidi enum arm_spe_neoverse_data_source {
604e6430cbSAli Saidi 	ARM_SPE_NV_L1D		 = 0x0,
614e6430cbSAli Saidi 	ARM_SPE_NV_L2		 = 0x8,
624e6430cbSAli Saidi 	ARM_SPE_NV_PEER_CORE	 = 0x9,
634e6430cbSAli Saidi 	ARM_SPE_NV_LOCAL_CLUSTER = 0xa,
644e6430cbSAli Saidi 	ARM_SPE_NV_SYS_CACHE	 = 0xb,
654e6430cbSAli Saidi 	ARM_SPE_NV_PEER_CLUSTER	 = 0xc,
664e6430cbSAli Saidi 	ARM_SPE_NV_REMOTE	 = 0xd,
674e6430cbSAli Saidi 	ARM_SPE_NV_DRAM		 = 0xe,
684e6430cbSAli Saidi };
694e6430cbSAli Saidi 
70a54ca194STan Xiaojun struct arm_spe_record {
71a54ca194STan Xiaojun 	enum arm_spe_sample_type type;
72a54ca194STan Xiaojun 	int err;
7397ae666aSLeo Yan 	u32 op;
74b0fde9c6SNamhyung Kim 	u32 latency;
75a54ca194STan Xiaojun 	u64 from_ip;
76a54ca194STan Xiaojun 	u64 to_ip;
77a54ca194STan Xiaojun 	u64 timestamp;
78265cfb95SLeo Yan 	u64 virt_addr;
79265cfb95SLeo Yan 	u64 phys_addr;
80169de64fSGerman Gomez 	u64 context_id;
814e6430cbSAli Saidi 	u16 source;
82a54ca194STan Xiaojun };
83a54ca194STan Xiaojun 
84a54ca194STan Xiaojun struct arm_spe_insn;
85a54ca194STan Xiaojun 
86a54ca194STan Xiaojun struct arm_spe_buffer {
87a54ca194STan Xiaojun 	const unsigned char *buf;
88a54ca194STan Xiaojun 	size_t len;
89a54ca194STan Xiaojun 	u64 offset;
90a54ca194STan Xiaojun 	u64 trace_nr;
91a54ca194STan Xiaojun };
92a54ca194STan Xiaojun 
93a54ca194STan Xiaojun struct arm_spe_params {
94a54ca194STan Xiaojun 	int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
95a54ca194STan Xiaojun 	void *data;
96a54ca194STan Xiaojun };
97a54ca194STan Xiaojun 
98a54ca194STan Xiaojun struct arm_spe_decoder {
99a54ca194STan Xiaojun 	int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
100a54ca194STan Xiaojun 	void *data;
101a54ca194STan Xiaojun 	struct arm_spe_record record;
102a54ca194STan Xiaojun 
103a54ca194STan Xiaojun 	const unsigned char *buf;
104a54ca194STan Xiaojun 	size_t len;
105a54ca194STan Xiaojun 
106a54ca194STan Xiaojun 	struct arm_spe_pkt packet;
107a54ca194STan Xiaojun };
108a54ca194STan Xiaojun 
109a54ca194STan Xiaojun struct arm_spe_decoder *arm_spe_decoder_new(struct arm_spe_params *params);
110a54ca194STan Xiaojun void arm_spe_decoder_free(struct arm_spe_decoder *decoder);
111a54ca194STan Xiaojun 
112a54ca194STan Xiaojun int arm_spe_decode(struct arm_spe_decoder *decoder);
113a54ca194STan Xiaojun 
114a54ca194STan Xiaojun #endif
115