10 #include <linux/list.h> 12 #include <opencsd/c_api/opencsd_c_api.h> 13 #include <opencsd/etmv4/trc_pkt_types_etmv4.h> 14 #include <opencsd/ocsd_if_types.h> 21 #define MAX_BUFFER 1024 25 #define CS_LOG_RAW_FRAMES 27 #define CS_RAW_DEBUG_FLAGS (OCSD_DFRMTR_UNPACKED_RAW_OUT | \ 28 OCSD_DFRMTR_PACKED_RAW_OUT) 30 #define CS_RAW_DEBUG_FLAGS (OCSD_DFRMTR_UNPACKED_RAW_OUT) 49 const ocsd_vaddr_t address,
50 const ocsd_mem_space_acc_t mem_space __maybe_unused,
68 if (ocsd_dt_add_callback_mem_acc(decoder->
dcd_tree, start, end,
78 ocsd_datapath_resp_t dp_ret;
82 dp_ret = ocsd_dt_process_data(decoder->
dcd_tree, OCSD_OP_RESET,
84 if (OCSD_DATA_RESP_IS_FATAL(dp_ret))
93 if (!decoder || !packet)
126 config->reg_idr9 = 0;
127 config->reg_idr10 = 0;
128 config->reg_idr11 = 0;
129 config->reg_idr12 = 0;
130 config->reg_idr13 = 0;
131 config->arch_ver = ARCH_V8;
132 config->core_prof = profile_CortexA;
139 if (p_context && str_len)
158 ret = ocsd_def_errlog_init(OCSD_ERR_SEV_ERROR, 1);
163 ret = ocsd_def_errlog_config_output(C_API_MSGLOGOUT_FLG_NONE, NULL);
171 ret = ocsd_def_errlog_set_strprint_cb(decoder->
dcd_tree,
180 #ifdef CS_LOG_RAW_FRAMES 190 ocsd_def_errlog_init(OCSD_ERR_SEV_ERROR, 1);
193 ocsd_def_errlog_config_output(C_API_MSGLOGOUT_FLG_NONE, NULL);
198 ocsd_def_errlog_set_strprint_cb(decoder->
dcd_tree,
203 ocsd_dt_set_raw_frame_printer(decoder->dcd_tree,
217 const char *decoder_name,
222 if (ocsd_dt_create_decoder(decoder->
dcd_tree, decoder_name,
223 OCSD_CREATE_FLG_PACKET_PROC,
224 trace_config, &csid))
227 if (ocsd_dt_set_pkt_protocol_printer(decoder->
dcd_tree, csid, 0))
237 const char *decoder_name;
238 ocsd_etmv4_cfg trace_config_etmv4;
244 decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
245 trace_config = &trace_config_etmv4;
273 static ocsd_datapath_resp_t
275 const u8 trace_chan_id,
282 return OCSD_RESP_FATAL_SYS_ERR;
287 return OCSD_RESP_FATAL_SYS_ERR;
302 return OCSD_RESP_WAIT;
304 return OCSD_RESP_CONT;
307 static ocsd_datapath_resp_t
309 const ocsd_generic_trace_elem *elem,
310 const uint8_t trace_chan_id)
317 if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
324 switch (elem->last_i_type) {
326 case OCSD_INSTR_BR_INDIRECT:
330 case OCSD_INSTR_DSB_DMB:
331 case OCSD_INSTR_OTHER:
340 static ocsd_datapath_resp_t
342 const uint8_t trace_chan_id)
350 const ocsd_trc_index_t indx __maybe_unused,
351 const u8 trace_chan_id __maybe_unused,
352 const ocsd_generic_trace_elem *elem)
354 ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
357 switch (elem->elem_type) {
358 case OCSD_GEN_TRC_ELEM_UNKNOWN:
360 case OCSD_GEN_TRC_ELEM_NO_SYNC:
363 case OCSD_GEN_TRC_ELEM_TRACE_ON:
368 case OCSD_GEN_TRC_ELEM_INSTR_RANGE:
372 case OCSD_GEN_TRC_ELEM_EXCEPTION:
375 case OCSD_GEN_TRC_ELEM_EXCEPTION_RET:
378 case OCSD_GEN_TRC_ELEM_PE_CONTEXT:
379 case OCSD_GEN_TRC_ELEM_EO_TRACE:
380 case OCSD_GEN_TRC_ELEM_ADDR_NACC:
381 case OCSD_GEN_TRC_ELEM_TIMESTAMP:
382 case OCSD_GEN_TRC_ELEM_CYCLE_COUNT:
383 case OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN:
384 case OCSD_GEN_TRC_ELEM_EVENT:
385 case OCSD_GEN_TRC_ELEM_SWTRACE:
386 case OCSD_GEN_TRC_ELEM_CUSTOM:
398 const char *decoder_name;
399 ocsd_etmv4_cfg trace_config_etmv4;
406 decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
407 trace_config = &trace_config_etmv4;
413 if (ocsd_dt_create_decoder(decoder->
dcd_tree,
415 OCSD_CREATE_FLG_FULL_DECODER,
416 trace_config, &csid))
419 if (ocsd_dt_set_gen_elem_outfn(decoder->
dcd_tree,
447 ocsd_dcd_tree_src_t format;
451 if ((!t_params) || (!d_params))
454 decoder =
zalloc(
sizeof(*decoder));
462 format = (d_params->
formatted ? OCSD_TRC_SRC_FRAME_FORMATTED :
463 OCSD_TRC_SRC_SINGLE);
465 flags |= (d_params->
fsyncs ? OCSD_DFRMTR_HAS_FSYNCS : 0);
466 flags |= (d_params->
hsyncs ? OCSD_DFRMTR_HAS_HSYNCS : 0);
467 flags |= (d_params->
frame_aligned ? OCSD_DFRMTR_FRAME_MEM_ALIGN : 0);
473 flags |= OCSD_DFRMTR_RESET_ON_4X_FSYNC;
476 decoder->
dcd_tree = ocsd_create_dcd_tree(format, flags);
479 goto err_free_decoder;
484 goto err_free_decoder_tree;
489 for (i = 0; i < num_cpu; i++) {
494 goto err_free_decoder_tree;
499 err_free_decoder_tree:
500 ocsd_destroy_dcd_tree(decoder->
dcd_tree);
507 u64 indx,
const u8 *buf,
508 size_t len,
size_t *consumed)
511 ocsd_datapath_resp_t cur = OCSD_RESP_CONT;
513 size_t processed = 0;
516 while (processed < len) {
517 if (OCSD_DATA_RESP_IS_WAIT(prev_return)) {
518 cur = ocsd_dt_process_data(decoder->
dcd_tree,
524 }
else if (OCSD_DATA_RESP_IS_CONT(prev_return)) {
525 cur = ocsd_dt_process_data(decoder->
dcd_tree,
542 if (OCSD_DATA_RESP_IS_WAIT(cur))
549 *consumed = processed;
559 ocsd_destroy_dcd_tree(decoder->
dcd_tree);
static void cs_etm_decoder__gen_etmv4_config(struct cs_etm_trace_params *params, ocsd_etmv4_cfg *config)
void(* packet_printer)(const char *msg)
struct cs_etm_packet packet_buffer[MAX_BUFFER]
void(* packet_printer)(const char *msg)
ocsd_datapath_resp_t prev_return
static int cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, struct cs_etm_trace_params *t_params, struct cs_etm_decoder *decoder)
u32(* cs_etm_mem_cb_type)(struct cs_etm_queue *, u64, size_t, u8 *)
static ocsd_datapath_resp_t cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, const u8 trace_chan_id, enum cs_etm_sample_type sample_type)
enum cs_etm_sample_type sample_type
static void cs_etm_decoder__init_raw_frame_logging(struct cs_etm_decoder_params *d_params __maybe_unused, struct cs_etm_decoder *decoder __maybe_unused)
static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(const void *context, const ocsd_trc_index_t indx __maybe_unused, const u8 trace_chan_id __maybe_unused, const ocsd_generic_trace_elem *elem)
struct cs_etmv4_trace_params etmv4
cs_etm_mem_cb_type mem_access
struct int_node * intlist__find(struct intlist *ilist, int i)
static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder)
int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder, u64 start, u64 end, cs_etm_mem_cb_type cb_func)
u8 last_instr_taken_branch
struct cs_etm_decoder * cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, struct cs_etm_trace_params t_params[])
static ocsd_datapath_resp_t cs_etm_decoder__buffer_trace_on(struct cs_etm_decoder *decoder, const uint8_t trace_chan_id)
static int cs_etm_decoder__create_packet_printer(struct cs_etm_decoder *decoder, const char *decoder_name, void *trace_config)
int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder, u64 indx, const u8 *buf, size_t len, size_t *consumed)
static int cs_etm_decoder__create_etm_packet_printer(struct cs_etm_trace_params *t_params, struct cs_etm_decoder *decoder)
static int cs_etm_decoder__init_def_logger_printing(struct cs_etm_decoder_params *d_params, struct cs_etm_decoder *decoder)
static int cs_etm_decoder__create_etm_packet_decoder(struct cs_etm_trace_params *t_params, struct cs_etm_decoder *decoder)
dcd_tree_handle_t dcd_tree
struct intlist * traceid_list
static void cs_etm_decoder__print_str_cb(const void *p_context, const char *msg, const int str_len)
static ocsd_datapath_resp_t cs_etm_decoder__buffer_range(struct cs_etm_decoder *decoder, const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id)
void cs_etm_decoder__free(struct cs_etm_decoder *decoder)
int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder, struct cs_etm_packet *packet)
static u32 cs_etm_decoder__mem_access(const void *context, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space __maybe_unused, const u32 req_size, u8 *buffer)
void static void * zalloc(size_t size)