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