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 <opencsd/ocsd_if_types.h>
15 #include <stdio.h>
16 
17 struct cs_etm_decoder;
18 struct cs_etm_packet;
19 struct cs_etm_packet_queue;
20 
21 struct cs_etm_queue;
22 
23 typedef u32 (*cs_etm_mem_cb_type)(struct cs_etm_queue *, u8, u64, size_t, u8 *,
24 				  const ocsd_mem_space_acc_t);
25 
26 struct cs_etmv3_trace_params {
27 	u32 reg_ctrl;
28 	u32 reg_trc_id;
29 	u32 reg_ccer;
30 	u32 reg_idr;
31 };
32 
33 struct cs_etmv4_trace_params {
34 	u32 reg_idr0;
35 	u32 reg_idr1;
36 	u32 reg_idr2;
37 	u32 reg_idr8;
38 	u32 reg_configr;
39 	u32 reg_traceidr;
40 };
41 
42 struct cs_ete_trace_params {
43 	u32 reg_idr0;
44 	u32 reg_idr1;
45 	u32 reg_idr2;
46 	u32 reg_idr8;
47 	u32 reg_configr;
48 	u32 reg_traceidr;
49 	u32 reg_devarch;
50 };
51 
52 struct cs_etm_trace_params {
53 	int protocol;
54 	union {
55 		struct cs_etmv3_trace_params etmv3;
56 		struct cs_etmv4_trace_params etmv4;
57 		struct cs_ete_trace_params ete;
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 	bool formatted;
66 	bool fsyncs;
67 	bool hsyncs;
68 	bool 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 	CS_ETM_PROTO_PTM,
81 	CS_ETM_PROTO_ETE
82 };
83 
84 enum cs_etm_decoder_operation {
85 	CS_ETM_OPERATION_PRINT = 1,
86 	CS_ETM_OPERATION_DECODE,
87 	CS_ETM_OPERATION_MAX,
88 };
89 
90 int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
91 				       u64 indx, const u8 *buf,
92 				       size_t len, size_t *consumed);
93 
94 struct cs_etm_decoder *
95 cs_etm_decoder__new(int num_cpu,
96 		    struct cs_etm_decoder_params *d_params,
97 		    struct cs_etm_trace_params t_params[]);
98 
99 void cs_etm_decoder__free(struct cs_etm_decoder *decoder);
100 
101 int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
102 				      u64 start, u64 end,
103 				      cs_etm_mem_cb_type cb_func);
104 
105 int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
106 			       struct cs_etm_packet *packet);
107 
108 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
109 const char *cs_etm_decoder__get_name(struct cs_etm_decoder *decoder);
110 
111 #endif /* INCLUDE__CS_ETM_DECODER_H__ */
112