xref: /openbmc/linux/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h (revision 22fc4c4c9fd60427bcda00878cee94e7622cfa7a)
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,
27 	CS_ETM_RANGE,
28 	CS_ETM_DISCONTINUITY,
29 	CS_ETM_EXCEPTION,
30 	CS_ETM_EXCEPTION_RET,
31 };
32 
33 enum cs_etm_isa {
34 	CS_ETM_ISA_UNKNOWN,
35 	CS_ETM_ISA_A64,
36 	CS_ETM_ISA_A32,
37 	CS_ETM_ISA_T32,
38 };
39 
40 struct cs_etm_packet {
41 	enum cs_etm_sample_type sample_type;
42 	enum cs_etm_isa isa;
43 	u64 start_addr;
44 	u64 end_addr;
45 	u32 instr_count;
46 	u8 last_instr_taken_branch;
47 	u8 last_instr_size;
48 	int cpu;
49 };
50 
51 struct cs_etm_queue;
52 
53 typedef u32 (*cs_etm_mem_cb_type)(struct cs_etm_queue *, u64,
54 				  size_t, u8 *);
55 
56 struct cs_etmv3_trace_params {
57 	u32 reg_ctrl;
58 	u32 reg_trc_id;
59 	u32 reg_ccer;
60 	u32 reg_idr;
61 };
62 
63 struct cs_etmv4_trace_params {
64 	u32 reg_idr0;
65 	u32 reg_idr1;
66 	u32 reg_idr2;
67 	u32 reg_idr8;
68 	u32 reg_configr;
69 	u32 reg_traceidr;
70 };
71 
72 struct cs_etm_trace_params {
73 	int protocol;
74 	union {
75 		struct cs_etmv3_trace_params etmv3;
76 		struct cs_etmv4_trace_params etmv4;
77 	};
78 };
79 
80 struct cs_etm_decoder_params {
81 	int operation;
82 	void (*packet_printer)(const char *msg);
83 	cs_etm_mem_cb_type mem_acc_cb;
84 	u8 formatted;
85 	u8 fsyncs;
86 	u8 hsyncs;
87 	u8 frame_aligned;
88 	void *data;
89 };
90 
91 /*
92  * The following enums are indexed starting with 1 to align with the
93  * open source coresight trace decoder library.
94  */
95 enum {
96 	CS_ETM_PROTO_ETMV3 = 1,
97 	CS_ETM_PROTO_ETMV4i,
98 	CS_ETM_PROTO_ETMV4d,
99 	CS_ETM_PROTO_PTM,
100 };
101 
102 enum {
103 	CS_ETM_OPERATION_PRINT = 1,
104 	CS_ETM_OPERATION_DECODE,
105 };
106 
107 int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
108 				       u64 indx, const u8 *buf,
109 				       size_t len, size_t *consumed);
110 
111 struct cs_etm_decoder *
112 cs_etm_decoder__new(int num_cpu,
113 		    struct cs_etm_decoder_params *d_params,
114 		    struct cs_etm_trace_params t_params[]);
115 
116 void cs_etm_decoder__free(struct cs_etm_decoder *decoder);
117 
118 int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
119 				      u64 start, u64 end,
120 				      cs_etm_mem_cb_type cb_func);
121 
122 int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder,
123 			       struct cs_etm_packet *packet);
124 
125 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
126 
127 #endif /* INCLUDE__CS_ETM_DECODER_H__ */
128