1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(C) 2015-2018 Linaro Limited.
5 * Author: Tor Jeremiassen <tor@ti.com>
6 * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
10 #include <linux/coresight-pmu.h>
11 #include <linux/err.h>
12 #include <linux/list.h>
13 #include <linux/zalloc.h>
15 #include <opencsd/c_api/opencsd_c_api.h>
18 #include "cs-etm-decoder.h"
24 #define CS_LOG_RAW_FRAMES
26 #define CS_RAW_DEBUG_FLAGS (OCSD_DFRMTR_UNPACKED_RAW_OUT | \
27 OCSD_DFRMTR_PACKED_RAW_OUT)
29 #define CS_RAW_DEBUG_FLAGS (OCSD_DFRMTR_UNPACKED_RAW_OUT)
33 struct cs_etm_decoder {
35 void (*packet_printer)(const char *msg);
36 bool suppress_printing;
37 dcd_tree_handle_t dcd_tree;
38 cs_etm_mem_cb_type mem_access;
39 ocsd_datapath_resp_t prev_return;
40 const char *decoder_name;
44 cs_etm_decoder__mem_access(const void *context,
45 const ocsd_vaddr_t address,
46 const ocsd_mem_space_acc_t mem_space __maybe_unused,
47 const u8 trace_chan_id,
51 struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
53 return decoder->mem_access(decoder->data, trace_chan_id,
54 address, req_size, buffer);
57 int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
59 cs_etm_mem_cb_type cb_func)
61 decoder->mem_access = cb_func;
63 if (ocsd_dt_add_callback_trcid_mem_acc(decoder->dcd_tree, start, end,
65 cs_etm_decoder__mem_access,
72 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
74 ocsd_datapath_resp_t dp_ret;
76 decoder->prev_return = OCSD_RESP_CONT;
77 decoder->suppress_printing = true;
78 dp_ret = ocsd_dt_process_data(decoder->dcd_tree, OCSD_OP_RESET,
80 decoder->suppress_printing = false;
81 if (OCSD_DATA_RESP_IS_FATAL(dp_ret))
87 int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
88 struct cs_etm_packet *packet)
90 if (!packet_queue || !packet)
93 /* Nothing to do, might as well just return */
94 if (packet_queue->packet_count == 0)
97 * The queueing process in function cs_etm_decoder__buffer_packet()
98 * increments the tail *before* using it. This is somewhat counter
99 * intuitive but it has the advantage of centralizing tail management
100 * at a single location. Because of that we need to follow the same
101 * heuristic with the head, i.e we increment it before using its
102 * value. Otherwise the first element of the packet queue is not
105 packet_queue->head = (packet_queue->head + 1) &
106 (CS_ETM_PACKET_MAX_BUFFER - 1);
108 *packet = packet_queue->packet_buffer[packet_queue->head];
110 packet_queue->packet_count--;
115 static int cs_etm_decoder__gen_etmv3_config(struct cs_etm_trace_params *params,
116 ocsd_etmv3_cfg *config)
118 config->reg_idr = params->etmv3.reg_idr;
119 config->reg_ctrl = params->etmv3.reg_ctrl;
120 config->reg_ccer = params->etmv3.reg_ccer;
121 config->reg_trc_id = params->etmv3.reg_trc_id;
122 config->arch_ver = ARCH_V7;
123 config->core_prof = profile_CortexA;
128 #define TRCIDR1_TRCARCHMIN_SHIFT 4
129 #define TRCIDR1_TRCARCHMIN_MASK GENMASK(7, 4)
130 #define TRCIDR1_TRCARCHMIN(x) (((x) & TRCIDR1_TRCARCHMIN_MASK) >> TRCIDR1_TRCARCHMIN_SHIFT)
132 static enum _ocsd_arch_version cs_etm_decoder__get_etmv4_arch_ver(u32 reg_idr1)
135 * For ETMv4 if the trace minor version is 4 or more then we can assume
136 * the architecture is ARCH_AA64 rather than just V8.
137 * ARCH_V8 = V8 architecture
138 * ARCH_AA64 = Min v8r3 plus additional AA64 PE features
140 return TRCIDR1_TRCARCHMIN(reg_idr1) >= 4 ? ARCH_AA64 : ARCH_V8;
143 static void cs_etm_decoder__gen_etmv4_config(struct cs_etm_trace_params *params,
144 ocsd_etmv4_cfg *config)
146 config->reg_configr = params->etmv4.reg_configr;
147 config->reg_traceidr = params->etmv4.reg_traceidr;
148 config->reg_idr0 = params->etmv4.reg_idr0;
149 config->reg_idr1 = params->etmv4.reg_idr1;
150 config->reg_idr2 = params->etmv4.reg_idr2;
151 config->reg_idr8 = params->etmv4.reg_idr8;
152 config->reg_idr9 = 0;
153 config->reg_idr10 = 0;
154 config->reg_idr11 = 0;
155 config->reg_idr12 = 0;
156 config->reg_idr13 = 0;
157 config->arch_ver = cs_etm_decoder__get_etmv4_arch_ver(params->etmv4.reg_idr1);
158 config->core_prof = profile_CortexA;
161 static void cs_etm_decoder__gen_ete_config(struct cs_etm_trace_params *params,
162 ocsd_ete_cfg *config)
164 config->reg_configr = params->ete.reg_configr;
165 config->reg_traceidr = params->ete.reg_traceidr;
166 config->reg_idr0 = params->ete.reg_idr0;
167 config->reg_idr1 = params->ete.reg_idr1;
168 config->reg_idr2 = params->ete.reg_idr2;
169 config->reg_idr8 = params->ete.reg_idr8;
170 config->reg_devarch = params->ete.reg_devarch;
171 config->arch_ver = ARCH_AA64;
172 config->core_prof = profile_CortexA;
175 static void cs_etm_decoder__print_str_cb(const void *p_context,
179 const struct cs_etm_decoder *decoder = p_context;
181 if (p_context && str_len && !decoder->suppress_printing)
182 decoder->packet_printer(msg);
186 cs_etm_decoder__init_def_logger_printing(struct cs_etm_decoder_params *d_params,
187 struct cs_etm_decoder *decoder)
191 if (d_params->packet_printer == NULL)
194 decoder->packet_printer = d_params->packet_printer;
197 * Set up a library default logger to process any printers
198 * (packet/raw frame) we add later.
200 ret = ocsd_def_errlog_init(OCSD_ERR_SEV_ERROR, 1);
204 /* no stdout / err / file output */
205 ret = ocsd_def_errlog_config_output(C_API_MSGLOGOUT_FLG_NONE, NULL);
210 * Set the string CB for the default logger, passes strings to
213 ret = ocsd_def_errlog_set_strprint_cb(decoder->dcd_tree,
215 cs_etm_decoder__print_str_cb);
222 #ifdef CS_LOG_RAW_FRAMES
224 cs_etm_decoder__init_raw_frame_logging(struct cs_etm_decoder_params *d_params,
225 struct cs_etm_decoder *decoder)
227 /* Only log these during a --dump operation */
228 if (d_params->operation == CS_ETM_OPERATION_PRINT) {
229 /* set up a library default logger to process the
230 * raw frame printer we add later
232 ocsd_def_errlog_init(OCSD_ERR_SEV_ERROR, 1);
234 /* no stdout / err / file output */
235 ocsd_def_errlog_config_output(C_API_MSGLOGOUT_FLG_NONE, NULL);
237 /* set the string CB for the default logger,
238 * passes strings to perf print logger.
240 ocsd_def_errlog_set_strprint_cb(decoder->dcd_tree,
242 cs_etm_decoder__print_str_cb);
244 /* use the built in library printer for the raw frames */
245 ocsd_dt_set_raw_frame_printer(decoder->dcd_tree,
251 cs_etm_decoder__init_raw_frame_logging(
252 struct cs_etm_decoder_params *d_params __maybe_unused,
253 struct cs_etm_decoder *decoder __maybe_unused)
258 static ocsd_datapath_resp_t
259 cs_etm_decoder__do_soft_timestamp(struct cs_etm_queue *etmq,
260 struct cs_etm_packet_queue *packet_queue,
261 const uint8_t trace_chan_id)
263 /* No timestamp packet has been received, nothing to do */
264 if (!packet_queue->cs_timestamp)
265 return OCSD_RESP_CONT;
267 packet_queue->cs_timestamp = packet_queue->next_cs_timestamp;
269 /* Estimate the timestamp for the next range packet */
270 packet_queue->next_cs_timestamp += packet_queue->instr_count;
271 packet_queue->instr_count = 0;
273 /* Tell the front end which traceid_queue needs attention */
274 cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id);
276 return OCSD_RESP_WAIT;
279 static ocsd_datapath_resp_t
280 cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
281 const ocsd_generic_trace_elem *elem,
282 const uint8_t trace_chan_id,
283 const ocsd_trc_index_t indx)
285 struct cs_etm_packet_queue *packet_queue;
287 /* First get the packet queue for this traceID */
288 packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id);
290 return OCSD_RESP_FATAL_SYS_ERR;
293 * We've seen a timestamp packet before - simply record the new value.
294 * Function do_soft_timestamp() will report the value to the front end,
295 * hence asking the decoder to keep decoding rather than stopping.
297 if (packet_queue->cs_timestamp) {
298 packet_queue->next_cs_timestamp = elem->timestamp;
299 return OCSD_RESP_CONT;
303 if (!elem->timestamp) {
305 * Zero timestamps can be seen due to misconfiguration or hardware bugs.
306 * Warn once, and don't try to subtract instr_count as it would result in an
309 packet_queue->cs_timestamp = 0;
310 if (!cs_etm__etmq_is_timeless(etmq))
311 pr_warning_once("Zero Coresight timestamp found at Idx:%" OCSD_TRC_IDX_STR
312 ". Decoding may be improved by prepending 'Z' to your current --itrace arguments.\n",
315 } else if (packet_queue->instr_count > elem->timestamp) {
317 * Sanity check that the elem->timestamp - packet_queue->instr_count would not
318 * result in an underflow. Warn and clamp at 0 if it would.
320 packet_queue->cs_timestamp = 0;
321 pr_err("Timestamp calculation underflow at Idx:%" OCSD_TRC_IDX_STR "\n", indx);
324 * This is the first timestamp we've seen since the beginning of traces
325 * or a discontinuity. Since timestamps packets are generated *after*
326 * range packets have been generated, we need to estimate the time at
327 * which instructions started by subtracting the number of instructions
328 * executed to the timestamp.
330 packet_queue->cs_timestamp = elem->timestamp - packet_queue->instr_count;
332 packet_queue->next_cs_timestamp = elem->timestamp;
333 packet_queue->instr_count = 0;
335 /* Tell the front end which traceid_queue needs attention */
336 cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id);
338 /* Halt processing until we are being told to proceed */
339 return OCSD_RESP_WAIT;
343 cs_etm_decoder__reset_timestamp(struct cs_etm_packet_queue *packet_queue)
345 packet_queue->cs_timestamp = 0;
346 packet_queue->next_cs_timestamp = 0;
347 packet_queue->instr_count = 0;
350 static ocsd_datapath_resp_t
351 cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue,
352 const u8 trace_chan_id,
353 enum cs_etm_sample_type sample_type)
358 if (packet_queue->packet_count >= CS_ETM_PACKET_MAX_BUFFER - 1)
359 return OCSD_RESP_FATAL_SYS_ERR;
361 if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0)
362 return OCSD_RESP_FATAL_SYS_ERR;
364 et = packet_queue->tail;
365 et = (et + 1) & (CS_ETM_PACKET_MAX_BUFFER - 1);
366 packet_queue->tail = et;
367 packet_queue->packet_count++;
369 packet_queue->packet_buffer[et].sample_type = sample_type;
370 packet_queue->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN;
371 packet_queue->packet_buffer[et].cpu = cpu;
372 packet_queue->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR;
373 packet_queue->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR;
374 packet_queue->packet_buffer[et].instr_count = 0;
375 packet_queue->packet_buffer[et].last_instr_taken_branch = false;
376 packet_queue->packet_buffer[et].last_instr_size = 0;
377 packet_queue->packet_buffer[et].last_instr_type = 0;
378 packet_queue->packet_buffer[et].last_instr_subtype = 0;
379 packet_queue->packet_buffer[et].last_instr_cond = 0;
380 packet_queue->packet_buffer[et].flags = 0;
381 packet_queue->packet_buffer[et].exception_number = UINT32_MAX;
382 packet_queue->packet_buffer[et].trace_chan_id = trace_chan_id;
384 if (packet_queue->packet_count == CS_ETM_PACKET_MAX_BUFFER - 1)
385 return OCSD_RESP_WAIT;
387 return OCSD_RESP_CONT;
390 static ocsd_datapath_resp_t
391 cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
392 struct cs_etm_packet_queue *packet_queue,
393 const ocsd_generic_trace_elem *elem,
394 const uint8_t trace_chan_id)
397 struct cs_etm_packet *packet;
399 ret = cs_etm_decoder__buffer_packet(packet_queue, trace_chan_id,
401 if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
404 packet = &packet_queue->packet_buffer[packet_queue->tail];
407 case ocsd_isa_aarch64:
408 packet->isa = CS_ETM_ISA_A64;
411 packet->isa = CS_ETM_ISA_A32;
413 case ocsd_isa_thumb2:
414 packet->isa = CS_ETM_ISA_T32;
417 case ocsd_isa_jazelle:
418 case ocsd_isa_custom:
419 case ocsd_isa_unknown:
421 packet->isa = CS_ETM_ISA_UNKNOWN;
424 packet->start_addr = elem->st_addr;
425 packet->end_addr = elem->en_addr;
426 packet->instr_count = elem->num_instr_range;
427 packet->last_instr_type = elem->last_i_type;
428 packet->last_instr_subtype = elem->last_i_subtype;
429 packet->last_instr_cond = elem->last_instr_cond;
431 if (elem->last_i_type == OCSD_INSTR_BR || elem->last_i_type == OCSD_INSTR_BR_INDIRECT)
432 packet->last_instr_taken_branch = elem->last_instr_exec;
434 packet->last_instr_taken_branch = false;
436 packet->last_instr_size = elem->last_instr_sz;
438 /* per-thread scenario, no need to generate a timestamp */
439 if (cs_etm__etmq_is_timeless(etmq))
443 * The packet queue is full and we haven't seen a timestamp (had we
444 * seen one the packet queue wouldn't be full). Let the front end
447 if (ret == OCSD_RESP_WAIT)
450 packet_queue->instr_count += elem->num_instr_range;
451 /* Tell the front end we have a new timestamp to process */
452 ret = cs_etm_decoder__do_soft_timestamp(etmq, packet_queue,
458 static ocsd_datapath_resp_t
459 cs_etm_decoder__buffer_discontinuity(struct cs_etm_packet_queue *queue,
460 const uint8_t trace_chan_id)
463 * Something happened and who knows when we'll get new traces so
464 * reset time statistics.
466 cs_etm_decoder__reset_timestamp(queue);
467 return cs_etm_decoder__buffer_packet(queue, trace_chan_id,
468 CS_ETM_DISCONTINUITY);
471 static ocsd_datapath_resp_t
472 cs_etm_decoder__buffer_exception(struct cs_etm_packet_queue *queue,
473 const ocsd_generic_trace_elem *elem,
474 const uint8_t trace_chan_id)
476 struct cs_etm_packet *packet;
478 ret = cs_etm_decoder__buffer_packet(queue, trace_chan_id,
480 if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
483 packet = &queue->packet_buffer[queue->tail];
484 packet->exception_number = elem->exception_number;
489 static ocsd_datapath_resp_t
490 cs_etm_decoder__buffer_exception_ret(struct cs_etm_packet_queue *queue,
491 const uint8_t trace_chan_id)
493 return cs_etm_decoder__buffer_packet(queue, trace_chan_id,
494 CS_ETM_EXCEPTION_RET);
497 static ocsd_datapath_resp_t
498 cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
499 struct cs_etm_packet_queue *packet_queue,
500 const ocsd_generic_trace_elem *elem,
501 const uint8_t trace_chan_id)
508 * As all the ETMs run at the same exception level, the system should
509 * have the same PID format crossing CPUs. So cache the PID format
510 * and reuse it for sequential decoding.
513 ret = cs_etm__get_pid_fmt(trace_chan_id, &pid_fmt);
515 return OCSD_RESP_FATAL_SYS_ERR;
519 * Process the PE_CONTEXT packets if we have a valid contextID or VMID.
520 * If the kernel is running at EL2, the PID is traced in CONTEXTIDR_EL2
521 * as VMID, Bit ETM_OPT_CTXTID2 is set in this case.
524 case BIT(ETM_OPT_CTXTID):
525 if (elem->context.ctxt_id_valid)
526 tid = elem->context.context_id;
528 case BIT(ETM_OPT_CTXTID2):
529 if (elem->context.vmid_valid)
530 tid = elem->context.vmid;
537 return OCSD_RESP_CONT;
539 if (cs_etm__etmq_set_tid(etmq, tid, trace_chan_id))
540 return OCSD_RESP_FATAL_SYS_ERR;
543 * A timestamp is generated after a PE_CONTEXT element so make sure
544 * to rely on that coming one.
546 cs_etm_decoder__reset_timestamp(packet_queue);
548 return OCSD_RESP_CONT;
551 static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
553 const ocsd_trc_index_t indx,
554 const u8 trace_chan_id __maybe_unused,
555 const ocsd_generic_trace_elem *elem)
557 ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
558 struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
559 struct cs_etm_queue *etmq = decoder->data;
560 struct cs_etm_packet_queue *packet_queue;
562 /* First get the packet queue for this traceID */
563 packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id);
565 return OCSD_RESP_FATAL_SYS_ERR;
567 switch (elem->elem_type) {
568 case OCSD_GEN_TRC_ELEM_UNKNOWN:
570 case OCSD_GEN_TRC_ELEM_EO_TRACE:
571 case OCSD_GEN_TRC_ELEM_NO_SYNC:
572 case OCSD_GEN_TRC_ELEM_TRACE_ON:
573 resp = cs_etm_decoder__buffer_discontinuity(packet_queue,
576 case OCSD_GEN_TRC_ELEM_INSTR_RANGE:
577 resp = cs_etm_decoder__buffer_range(etmq, packet_queue, elem,
580 case OCSD_GEN_TRC_ELEM_EXCEPTION:
581 resp = cs_etm_decoder__buffer_exception(packet_queue, elem,
584 case OCSD_GEN_TRC_ELEM_EXCEPTION_RET:
585 resp = cs_etm_decoder__buffer_exception_ret(packet_queue,
588 case OCSD_GEN_TRC_ELEM_TIMESTAMP:
589 resp = cs_etm_decoder__do_hard_timestamp(etmq, elem,
593 case OCSD_GEN_TRC_ELEM_PE_CONTEXT:
594 resp = cs_etm_decoder__set_tid(etmq, packet_queue,
595 elem, trace_chan_id);
597 /* Unused packet types */
598 case OCSD_GEN_TRC_ELEM_I_RANGE_NOPATH:
599 case OCSD_GEN_TRC_ELEM_ADDR_NACC:
600 case OCSD_GEN_TRC_ELEM_CYCLE_COUNT:
601 case OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN:
602 case OCSD_GEN_TRC_ELEM_EVENT:
603 case OCSD_GEN_TRC_ELEM_SWTRACE:
604 case OCSD_GEN_TRC_ELEM_CUSTOM:
605 case OCSD_GEN_TRC_ELEM_SYNC_MARKER:
606 case OCSD_GEN_TRC_ELEM_MEMTRANS:
615 cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
616 struct cs_etm_trace_params *t_params,
617 struct cs_etm_decoder *decoder)
619 ocsd_etmv3_cfg config_etmv3;
620 ocsd_etmv4_cfg trace_config_etmv4;
621 ocsd_ete_cfg trace_config_ete;
625 switch (t_params->protocol) {
626 case CS_ETM_PROTO_ETMV3:
627 case CS_ETM_PROTO_PTM:
628 cs_etm_decoder__gen_etmv3_config(t_params, &config_etmv3);
629 decoder->decoder_name = (t_params->protocol == CS_ETM_PROTO_ETMV3) ?
630 OCSD_BUILTIN_DCD_ETMV3 :
631 OCSD_BUILTIN_DCD_PTM;
632 trace_config = &config_etmv3;
634 case CS_ETM_PROTO_ETMV4i:
635 cs_etm_decoder__gen_etmv4_config(t_params, &trace_config_etmv4);
636 decoder->decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
637 trace_config = &trace_config_etmv4;
639 case CS_ETM_PROTO_ETE:
640 cs_etm_decoder__gen_ete_config(t_params, &trace_config_ete);
641 decoder->decoder_name = OCSD_BUILTIN_DCD_ETE;
642 trace_config = &trace_config_ete;
648 if (d_params->operation == CS_ETM_OPERATION_DECODE) {
649 if (ocsd_dt_create_decoder(decoder->dcd_tree,
650 decoder->decoder_name,
651 OCSD_CREATE_FLG_FULL_DECODER,
652 trace_config, &csid))
655 if (ocsd_dt_set_gen_elem_outfn(decoder->dcd_tree,
656 cs_etm_decoder__gen_trace_elem_printer,
661 } else if (d_params->operation == CS_ETM_OPERATION_PRINT) {
662 if (ocsd_dt_create_decoder(decoder->dcd_tree, decoder->decoder_name,
663 OCSD_CREATE_FLG_PACKET_PROC,
664 trace_config, &csid))
667 if (ocsd_dt_set_pkt_protocol_printer(decoder->dcd_tree, csid, 0))
676 struct cs_etm_decoder *
677 cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params,
678 struct cs_etm_trace_params t_params[])
680 struct cs_etm_decoder *decoder;
681 ocsd_dcd_tree_src_t format;
685 if ((!t_params) || (!d_params))
688 decoder = zalloc(sizeof(*decoder));
693 decoder->data = d_params->data;
694 decoder->prev_return = OCSD_RESP_CONT;
695 format = (d_params->formatted ? OCSD_TRC_SRC_FRAME_FORMATTED :
696 OCSD_TRC_SRC_SINGLE);
698 flags |= (d_params->fsyncs ? OCSD_DFRMTR_HAS_FSYNCS : 0);
699 flags |= (d_params->hsyncs ? OCSD_DFRMTR_HAS_HSYNCS : 0);
700 flags |= (d_params->frame_aligned ? OCSD_DFRMTR_FRAME_MEM_ALIGN : 0);
703 * Drivers may add barrier frames when used with perf, set up to
704 * handle this. Barriers const of FSYNC packet repeated 4 times.
706 flags |= OCSD_DFRMTR_RESET_ON_4X_FSYNC;
708 /* Create decode tree for the data source */
709 decoder->dcd_tree = ocsd_create_dcd_tree(format, flags);
711 if (decoder->dcd_tree == 0)
712 goto err_free_decoder;
714 /* init library print logging support */
715 ret = cs_etm_decoder__init_def_logger_printing(d_params, decoder);
717 goto err_free_decoder;
719 /* init raw frame logging if required */
720 cs_etm_decoder__init_raw_frame_logging(d_params, decoder);
722 for (i = 0; i < decoders; i++) {
723 ret = cs_etm_decoder__create_etm_decoder(d_params,
727 goto err_free_decoder;
733 cs_etm_decoder__free(decoder);
737 int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
738 u64 indx, const u8 *buf,
739 size_t len, size_t *consumed)
742 ocsd_datapath_resp_t cur = OCSD_RESP_CONT;
743 ocsd_datapath_resp_t prev_return = decoder->prev_return;
744 size_t processed = 0;
747 while (processed < len) {
748 if (OCSD_DATA_RESP_IS_WAIT(prev_return)) {
749 cur = ocsd_dt_process_data(decoder->dcd_tree,
755 } else if (OCSD_DATA_RESP_IS_CONT(prev_return)) {
756 cur = ocsd_dt_process_data(decoder->dcd_tree,
769 * Return to the input code if the packet buffer is full.
770 * Flushing will get done once the packet buffer has been
773 if (OCSD_DATA_RESP_IS_WAIT(cur))
779 decoder->prev_return = cur;
780 *consumed = processed;
785 void cs_etm_decoder__free(struct cs_etm_decoder *decoder)
790 ocsd_destroy_dcd_tree(decoder->dcd_tree);
791 decoder->dcd_tree = NULL;
795 const char *cs_etm_decoder__get_name(struct cs_etm_decoder *decoder)
797 return decoder->decoder_name;