1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * arm_spe_decoder.h: Arm Statistical Profiling Extensions support
4  * Copyright (c) 2019-2020, Arm Ltd.
5  */
6 
7 #ifndef INCLUDE__ARM_SPE_DECODER_H__
8 #define INCLUDE__ARM_SPE_DECODER_H__
9 
10 #include <stdbool.h>
11 #include <stddef.h>
12 #include <stdint.h>
13 
14 #include "arm-spe-pkt-decoder.h"
15 
16 enum arm_spe_sample_type {
17 	ARM_SPE_L1D_ACCESS	= 1 << 0,
18 	ARM_SPE_L1D_MISS	= 1 << 1,
19 	ARM_SPE_LLC_ACCESS	= 1 << 2,
20 	ARM_SPE_LLC_MISS	= 1 << 3,
21 	ARM_SPE_TLB_ACCESS	= 1 << 4,
22 	ARM_SPE_TLB_MISS	= 1 << 5,
23 	ARM_SPE_BRANCH_MISS	= 1 << 6,
24 	ARM_SPE_REMOTE_ACCESS	= 1 << 7,
25 };
26 
27 enum arm_spe_op_type {
28 	ARM_SPE_LD		= 1 << 0,
29 	ARM_SPE_ST		= 1 << 1,
30 };
31 
32 struct arm_spe_record {
33 	enum arm_spe_sample_type type;
34 	int err;
35 	u32 op;
36 	u64 from_ip;
37 	u64 to_ip;
38 	u64 timestamp;
39 	u64 virt_addr;
40 	u64 phys_addr;
41 	u64 context_id;
42 };
43 
44 struct arm_spe_insn;
45 
46 struct arm_spe_buffer {
47 	const unsigned char *buf;
48 	size_t len;
49 	u64 offset;
50 	u64 trace_nr;
51 };
52 
53 struct arm_spe_params {
54 	int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
55 	void *data;
56 };
57 
58 struct arm_spe_decoder {
59 	int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
60 	void *data;
61 	struct arm_spe_record record;
62 
63 	const unsigned char *buf;
64 	size_t len;
65 
66 	struct arm_spe_pkt packet;
67 };
68 
69 struct arm_spe_decoder *arm_spe_decoder_new(struct arm_spe_params *params);
70 void arm_spe_decoder_free(struct arm_spe_decoder *decoder);
71 
72 int arm_spe_decode(struct arm_spe_decoder *decoder);
73 
74 #endif
75