xref: /openbmc/linux/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h (revision b0fde9c6e291e528878ea3713997777713fe44c6)
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 
2797ae666aSLeo Yan enum arm_spe_op_type {
2897ae666aSLeo Yan 	ARM_SPE_LD		= 1 << 0,
2997ae666aSLeo Yan 	ARM_SPE_ST		= 1 << 1,
3097ae666aSLeo Yan };
3197ae666aSLeo Yan 
32a54ca194STan Xiaojun struct arm_spe_record {
33a54ca194STan Xiaojun 	enum arm_spe_sample_type type;
34a54ca194STan Xiaojun 	int err;
3597ae666aSLeo Yan 	u32 op;
36*b0fde9c6SNamhyung Kim 	u32 latency;
37a54ca194STan Xiaojun 	u64 from_ip;
38a54ca194STan Xiaojun 	u64 to_ip;
39a54ca194STan Xiaojun 	u64 timestamp;
40265cfb95SLeo Yan 	u64 virt_addr;
41265cfb95SLeo Yan 	u64 phys_addr;
42169de64fSGerman Gomez 	u64 context_id;
43a54ca194STan Xiaojun };
44a54ca194STan Xiaojun 
45a54ca194STan Xiaojun struct arm_spe_insn;
46a54ca194STan Xiaojun 
47a54ca194STan Xiaojun struct arm_spe_buffer {
48a54ca194STan Xiaojun 	const unsigned char *buf;
49a54ca194STan Xiaojun 	size_t len;
50a54ca194STan Xiaojun 	u64 offset;
51a54ca194STan Xiaojun 	u64 trace_nr;
52a54ca194STan Xiaojun };
53a54ca194STan Xiaojun 
54a54ca194STan Xiaojun struct arm_spe_params {
55a54ca194STan Xiaojun 	int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
56a54ca194STan Xiaojun 	void *data;
57a54ca194STan Xiaojun };
58a54ca194STan Xiaojun 
59a54ca194STan Xiaojun struct arm_spe_decoder {
60a54ca194STan Xiaojun 	int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
61a54ca194STan Xiaojun 	void *data;
62a54ca194STan Xiaojun 	struct arm_spe_record record;
63a54ca194STan Xiaojun 
64a54ca194STan Xiaojun 	const unsigned char *buf;
65a54ca194STan Xiaojun 	size_t len;
66a54ca194STan Xiaojun 
67a54ca194STan Xiaojun 	struct arm_spe_pkt packet;
68a54ca194STan Xiaojun };
69a54ca194STan Xiaojun 
70a54ca194STan Xiaojun struct arm_spe_decoder *arm_spe_decoder_new(struct arm_spe_params *params);
71a54ca194STan Xiaojun void arm_spe_decoder_free(struct arm_spe_decoder *decoder);
72a54ca194STan Xiaojun 
73a54ca194STan Xiaojun int arm_spe_decode(struct arm_spe_decoder *decoder);
74a54ca194STan Xiaojun 
75a54ca194STan Xiaojun #endif
76