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_RANGE = 1 << 0,
27 	CS_ETM_TRACE_ON = 1 << 1,
28 };
29 
30 struct cs_etm_packet {
31 	enum cs_etm_sample_type sample_type;
32 	u64 start_addr;
33 	u64 end_addr;
34 	u8 last_instr_taken_branch;
35 	u8 exc;
36 	u8 exc_ret;
37 	int cpu;
38 };
39 
40 struct cs_etm_queue;
41 
42 typedef u32 (*cs_etm_mem_cb_type)(struct cs_etm_queue *, u64,
43 				  size_t, u8 *);
44 
45 struct cs_etmv4_trace_params {
46 	u32 reg_idr0;
47 	u32 reg_idr1;
48 	u32 reg_idr2;
49 	u32 reg_idr8;
50 	u32 reg_configr;
51 	u32 reg_traceidr;
52 };
53 
54 struct cs_etm_trace_params {
55 	int protocol;
56 	union {
57 		struct cs_etmv4_trace_params etmv4;
58 	};
59 };
60 
61 struct cs_etm_decoder_params {
62 	int operation;
63 	void (*packet_printer)(const char *msg);
64 	cs_etm_mem_cb_type mem_acc_cb;
65 	u8 formatted;
66 	u8 fsyncs;
67 	u8 hsyncs;
68 	u8 frame_aligned;
69 	void *data;
70 };
71 
72 /*
73  * The following enums are indexed starting with 1 to align with the
74  * open source coresight trace decoder library.
75  */
76 enum {
77 	CS_ETM_PROTO_ETMV3 = 1,
78 	CS_ETM_PROTO_ETMV4i,
79 	CS_ETM_PROTO_ETMV4d,
80 };
81 
82 enum {
83 	CS_ETM_OPERATION_PRINT = 1,
84 	CS_ETM_OPERATION_DECODE,
85 };
86 
87 int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
88 				       u64 indx, const u8 *buf,
89 				       size_t len, size_t *consumed);
90 
91 struct cs_etm_decoder *
92 cs_etm_decoder__new(int num_cpu,
93 		    struct cs_etm_decoder_params *d_params,
94 		    struct cs_etm_trace_params t_params[]);
95 
96 void cs_etm_decoder__free(struct cs_etm_decoder *decoder);
97 
98 int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
99 				      u64 start, u64 end,
100 				      cs_etm_mem_cb_type cb_func);
101 
102 int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder,
103 			       struct cs_etm_packet *packet);
104 
105 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
106 
107 #endif /* INCLUDE__CS_ETM_DECODER_H__ */
108