xref: /openbmc/linux/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h (revision 97ae666ae03606e254ffb478673d4e311a35fd83)
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,
25a54ca194STan Xiaojun };
26a54ca194STan Xiaojun 
27*97ae666aSLeo Yan enum arm_spe_op_type {
28*97ae666aSLeo Yan 	ARM_SPE_LD		= 1 << 0,
29*97ae666aSLeo Yan 	ARM_SPE_ST		= 1 << 1,
30*97ae666aSLeo Yan };
31*97ae666aSLeo Yan 
32a54ca194STan Xiaojun struct arm_spe_record {
33a54ca194STan Xiaojun 	enum arm_spe_sample_type type;
34a54ca194STan Xiaojun 	int err;
35*97ae666aSLeo Yan 	u32 op;
36a54ca194STan Xiaojun 	u64 from_ip;
37a54ca194STan Xiaojun 	u64 to_ip;
38a54ca194STan Xiaojun 	u64 timestamp;
39265cfb95SLeo Yan 	u64 virt_addr;
40265cfb95SLeo Yan 	u64 phys_addr;
41a54ca194STan Xiaojun };
42a54ca194STan Xiaojun 
43a54ca194STan Xiaojun struct arm_spe_insn;
44a54ca194STan Xiaojun 
45a54ca194STan Xiaojun struct arm_spe_buffer {
46a54ca194STan Xiaojun 	const unsigned char *buf;
47a54ca194STan Xiaojun 	size_t len;
48a54ca194STan Xiaojun 	u64 offset;
49a54ca194STan Xiaojun 	u64 trace_nr;
50a54ca194STan Xiaojun };
51a54ca194STan Xiaojun 
52a54ca194STan Xiaojun struct arm_spe_params {
53a54ca194STan Xiaojun 	int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
54a54ca194STan Xiaojun 	void *data;
55a54ca194STan Xiaojun };
56a54ca194STan Xiaojun 
57a54ca194STan Xiaojun struct arm_spe_decoder {
58a54ca194STan Xiaojun 	int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
59a54ca194STan Xiaojun 	void *data;
60a54ca194STan Xiaojun 	struct arm_spe_record record;
61a54ca194STan Xiaojun 
62a54ca194STan Xiaojun 	const unsigned char *buf;
63a54ca194STan Xiaojun 	size_t len;
64a54ca194STan Xiaojun 
65a54ca194STan Xiaojun 	struct arm_spe_pkt packet;
66a54ca194STan Xiaojun };
67a54ca194STan Xiaojun 
68a54ca194STan Xiaojun struct arm_spe_decoder *arm_spe_decoder_new(struct arm_spe_params *params);
69a54ca194STan Xiaojun void arm_spe_decoder_free(struct arm_spe_decoder *decoder);
70a54ca194STan Xiaojun 
71a54ca194STan Xiaojun int arm_spe_decode(struct arm_spe_decoder *decoder);
72a54ca194STan Xiaojun 
73a54ca194STan Xiaojun #endif
74