xref: /linux/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h (revision 95298d63c67673c654c08952672d016212b26054)
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 struct cs_etm_packet;
18 struct cs_etm_packet_queue;
19 
20 struct cs_etm_queue;
21 
22 typedef u32 (*cs_etm_mem_cb_type)(struct cs_etm_queue *, u8, u64, size_t, u8 *);
23 
24 struct cs_etmv3_trace_params {
25 	u32 reg_ctrl;
26 	u32 reg_trc_id;
27 	u32 reg_ccer;
28 	u32 reg_idr;
29 };
30 
31 struct cs_etmv4_trace_params {
32 	u32 reg_idr0;
33 	u32 reg_idr1;
34 	u32 reg_idr2;
35 	u32 reg_idr8;
36 	u32 reg_configr;
37 	u32 reg_traceidr;
38 };
39 
40 struct cs_etm_trace_params {
41 	int protocol;
42 	union {
43 		struct cs_etmv3_trace_params etmv3;
44 		struct cs_etmv4_trace_params etmv4;
45 	};
46 };
47 
48 struct cs_etm_decoder_params {
49 	int operation;
50 	void (*packet_printer)(const char *msg);
51 	cs_etm_mem_cb_type mem_acc_cb;
52 	u8 formatted;
53 	u8 fsyncs;
54 	u8 hsyncs;
55 	u8 frame_aligned;
56 	void *data;
57 };
58 
59 /*
60  * The following enums are indexed starting with 1 to align with the
61  * open source coresight trace decoder library.
62  */
63 enum {
64 	CS_ETM_PROTO_ETMV3 = 1,
65 	CS_ETM_PROTO_ETMV4i,
66 	CS_ETM_PROTO_ETMV4d,
67 	CS_ETM_PROTO_PTM,
68 };
69 
70 enum cs_etm_decoder_operation {
71 	CS_ETM_OPERATION_PRINT = 1,
72 	CS_ETM_OPERATION_DECODE,
73 	CS_ETM_OPERATION_MAX,
74 };
75 
76 int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
77 				       u64 indx, const u8 *buf,
78 				       size_t len, size_t *consumed);
79 
80 struct cs_etm_decoder *
81 cs_etm_decoder__new(int num_cpu,
82 		    struct cs_etm_decoder_params *d_params,
83 		    struct cs_etm_trace_params t_params[]);
84 
85 void cs_etm_decoder__free(struct cs_etm_decoder *decoder);
86 
87 int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
88 				      u64 start, u64 end,
89 				      cs_etm_mem_cb_type cb_func);
90 
91 int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
92 			       struct cs_etm_packet *packet);
93 
94 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder);
95 
96 #endif /* INCLUDE__CS_ETM_DECODER_H__ */
97