GNU Linux-libre 4.19.211-gnu1
[releases.git] / tools / perf / util / cs-etm-decoder / cs-etm-decoder.h
1 /*
2  * SPDX-License-Identifier: GPL-2.0
3  *
4  * Copyright(C) 2015-2018 Linaro Limited.
5  *
6  * Author: Tor Jeremiassen <tor@ti.com>
7  * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
8  */
9
10 #ifndef INCLUDE__CS_ETM_DECODER_H__
11 #define INCLUDE__CS_ETM_DECODER_H__
12
13 #include <linux/types.h>
14 #include <stdio.h>
15
16 struct cs_etm_decoder;
17
18 struct cs_etm_buffer {
19         const unsigned char *buf;
20         size_t len;
21         u64 offset;
22         u64 ref_timestamp;
23 };
24
25 enum cs_etm_sample_type {
26         CS_ETM_EMPTY = 0,
27         CS_ETM_RANGE = 1 << 0,
28         CS_ETM_TRACE_ON = 1 << 1,
29 };
30
31 struct cs_etm_packet {
32         enum cs_etm_sample_type sample_type;
33         u64 start_addr;
34         u64 end_addr;
35         u8 last_instr_taken_branch;
36         u8 exc;
37         u8 exc_ret;
38         int cpu;
39 };
40
41 struct cs_etm_queue;
42
43 typedef u32 (*cs_etm_mem_cb_type)(struct cs_etm_queue *, u64,
44                                   size_t, u8 *);
45
46 struct cs_etmv4_trace_params {
47         u32 reg_idr0;
48         u32 reg_idr1;
49         u32 reg_idr2;
50         u32 reg_idr8;
51         u32 reg_configr;
52         u32 reg_traceidr;
53 };
54
55 struct cs_etm_trace_params {
56         int protocol;
57         union {
58                 struct cs_etmv4_trace_params etmv4;
59         };
60 };
61
62 struct cs_etm_decoder_params {
63         int operation;
64         void (*packet_printer)(const char *msg);
65         cs_etm_mem_cb_type mem_acc_cb;
66         u8 formatted;
67         u8 fsyncs;
68         u8 hsyncs;
69         u8 frame_aligned;
70         void *data;
71 };
72
73 /*
74  * The following enums are indexed starting with 1 to align with the
75  * open source coresight trace decoder library.
76  */
77 enum {
78         CS_ETM_PROTO_ETMV3 = 1,
79         CS_ETM_PROTO_ETMV4i,
80         CS_ETM_PROTO_ETMV4d,
81 };
82
83 enum {
84         CS_ETM_OPERATION_PRINT = 1,
85         CS_ETM_OPERATION_DECODE,
86 };
87
88 int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
89                                        u64 indx, const u8 *buf,
90                                        size_t len, size_t *consumed);
91
92 struct cs_etm_decoder *
93 cs_etm_decoder__new(int num_cpu,
94                     struct cs_etm_decoder_params *d_params,
95                     struct cs_etm_trace_params t_params[]);
96
97 void cs_etm_decoder__free(struct cs_etm_decoder *decoder);
98
99 int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
100                                       u64 start, u64 end,
101                                       cs_etm_mem_cb_type cb_func);
102
103 int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder,
104                                struct cs_etm_packet *packet);
105
106 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
107
108 #endif /* INCLUDE__CS_ETM_DECODER_H__ */