Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright(C) 2015-2018 Linaro Limited.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author: Tor Jeremiassen <tor@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/zalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <opencsd/c_api/opencsd_c_api.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <opencsd/etmv4/trc_pkt_types_etmv4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <opencsd/ocsd_if_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "cs-etm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "cs-etm-decoder.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "intlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* use raw logging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #ifdef CS_DEBUG_RAW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define CS_LOG_RAW_FRAMES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #ifdef CS_RAW_PACKED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define CS_RAW_DEBUG_FLAGS (OCSD_DFRMTR_UNPACKED_RAW_OUT | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			    OCSD_DFRMTR_PACKED_RAW_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define CS_RAW_DEBUG_FLAGS (OCSD_DFRMTR_UNPACKED_RAW_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct cs_etm_decoder {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	void (*packet_printer)(const char *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	dcd_tree_handle_t dcd_tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	cs_etm_mem_cb_type mem_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	ocsd_datapath_resp_t prev_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) cs_etm_decoder__mem_access(const void *context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			   const ocsd_vaddr_t address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			   const ocsd_mem_space_acc_t mem_space __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			   const u8 trace_chan_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			   const u32 req_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			   u8 *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	return decoder->mem_access(decoder->data, trace_chan_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				   address, req_size, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 				      u64 start, u64 end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				      cs_etm_mem_cb_type cb_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	decoder->mem_access = cb_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (ocsd_dt_add_callback_trcid_mem_acc(decoder->dcd_tree, start, end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 					       OCSD_MEM_SPACE_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 					       cs_etm_decoder__mem_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 					       decoder))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	ocsd_datapath_resp_t dp_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	decoder->prev_return = OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	dp_ret = ocsd_dt_process_data(decoder->dcd_tree, OCSD_OP_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 				      0, 0, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (OCSD_DATA_RESP_IS_FATAL(dp_ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			       struct cs_etm_packet *packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!packet_queue || !packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/* Nothing to do, might as well just return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (packet_queue->packet_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * The queueing process in function cs_etm_decoder__buffer_packet()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 * increments the tail *before* using it.  This is somewhat counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 * intuitive but it has the advantage of centralizing tail management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	 * at a single location.  Because of that we need to follow the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * heuristic with the head, i.e we increment it before using its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 * value.  Otherwise the first element of the packet queue is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	 * used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	packet_queue->head = (packet_queue->head + 1) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			     (CS_ETM_PACKET_MAX_BUFFER - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	*packet = packet_queue->packet_buffer[packet_queue->head];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	packet_queue->packet_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int cs_etm_decoder__gen_etmv3_config(struct cs_etm_trace_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 					    ocsd_etmv3_cfg *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	config->reg_idr = params->etmv3.reg_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	config->reg_ctrl = params->etmv3.reg_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	config->reg_ccer = params->etmv3.reg_ccer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	config->reg_trc_id = params->etmv3.reg_trc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	config->arch_ver = ARCH_V7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	config->core_prof = profile_CortexA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static void cs_etm_decoder__gen_etmv4_config(struct cs_etm_trace_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 					     ocsd_etmv4_cfg *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	config->reg_configr = params->etmv4.reg_configr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	config->reg_traceidr = params->etmv4.reg_traceidr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	config->reg_idr0 = params->etmv4.reg_idr0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	config->reg_idr1 = params->etmv4.reg_idr1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	config->reg_idr2 = params->etmv4.reg_idr2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	config->reg_idr8 = params->etmv4.reg_idr8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	config->reg_idr9 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	config->reg_idr10 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	config->reg_idr11 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	config->reg_idr12 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	config->reg_idr13 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	config->arch_ver = ARCH_V8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	config->core_prof = profile_CortexA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void cs_etm_decoder__print_str_cb(const void *p_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 					 const char *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 					 const int str_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (p_context && str_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		((struct cs_etm_decoder *)p_context)->packet_printer(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) cs_etm_decoder__init_def_logger_printing(struct cs_etm_decoder_params *d_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 					 struct cs_etm_decoder *decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (d_params->packet_printer == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	decoder->packet_printer = d_params->packet_printer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * Set up a library default logger to process any printers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * (packet/raw frame) we add later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	ret = ocsd_def_errlog_init(OCSD_ERR_SEV_ERROR, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* no stdout / err / file output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	ret = ocsd_def_errlog_config_output(C_API_MSGLOGOUT_FLG_NONE, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * Set the string CB for the default logger, passes strings to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 * perf print logger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	ret = ocsd_def_errlog_set_strprint_cb(decoder->dcd_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 					      (void *)decoder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 					      cs_etm_decoder__print_str_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #ifdef CS_LOG_RAW_FRAMES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) cs_etm_decoder__init_raw_frame_logging(struct cs_etm_decoder_params *d_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 				       struct cs_etm_decoder *decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	/* Only log these during a --dump operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (d_params->operation == CS_ETM_OPERATION_PRINT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		/* set up a library default logger to process the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		 *  raw frame printer we add later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		ocsd_def_errlog_init(OCSD_ERR_SEV_ERROR, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		/* no stdout / err / file output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		ocsd_def_errlog_config_output(C_API_MSGLOGOUT_FLG_NONE, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		/* set the string CB for the default logger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		 * passes strings to perf print logger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		ocsd_def_errlog_set_strprint_cb(decoder->dcd_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 						(void *)decoder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 						cs_etm_decoder__print_str_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		/* use the built in library printer for the raw frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		ocsd_dt_set_raw_frame_printer(decoder->dcd_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 					      CS_RAW_DEBUG_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) cs_etm_decoder__init_raw_frame_logging(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		struct cs_etm_decoder_params *d_params __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		struct cs_etm_decoder *decoder __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int cs_etm_decoder__create_packet_printer(struct cs_etm_decoder *decoder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 						 const char *decoder_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 						 void *trace_config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	u8 csid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (ocsd_dt_create_decoder(decoder->dcd_tree, decoder_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 				   OCSD_CREATE_FLG_PACKET_PROC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 				   trace_config, &csid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (ocsd_dt_set_pkt_protocol_printer(decoder->dcd_tree, csid, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) cs_etm_decoder__create_etm_packet_printer(struct cs_etm_trace_params *t_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 					  struct cs_etm_decoder *decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	const char *decoder_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	ocsd_etmv3_cfg config_etmv3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	ocsd_etmv4_cfg trace_config_etmv4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	void *trace_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	switch (t_params->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	case CS_ETM_PROTO_ETMV3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	case CS_ETM_PROTO_PTM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		cs_etm_decoder__gen_etmv3_config(t_params, &config_etmv3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		decoder_name = (t_params->protocol == CS_ETM_PROTO_ETMV3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 							OCSD_BUILTIN_DCD_ETMV3 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 							OCSD_BUILTIN_DCD_PTM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		trace_config = &config_etmv3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	case CS_ETM_PROTO_ETMV4i:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		cs_etm_decoder__gen_etmv4_config(t_params, &trace_config_etmv4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		trace_config = &trace_config_etmv4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return cs_etm_decoder__create_packet_printer(decoder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 						     decoder_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 						     trace_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static ocsd_datapath_resp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) cs_etm_decoder__do_soft_timestamp(struct cs_etm_queue *etmq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				  struct cs_etm_packet_queue *packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				  const uint8_t trace_chan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	/* No timestamp packet has been received, nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (!packet_queue->timestamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	packet_queue->timestamp = packet_queue->next_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	/* Estimate the timestamp for the next range packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	packet_queue->next_timestamp += packet_queue->instr_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	packet_queue->instr_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	/* Tell the front end which traceid_queue needs attention */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return OCSD_RESP_WAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static ocsd_datapath_resp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 				  const ocsd_generic_trace_elem *elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				  const uint8_t trace_chan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct cs_etm_packet_queue *packet_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	/* First get the packet queue for this traceID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (!packet_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		return OCSD_RESP_FATAL_SYS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 * We've seen a timestamp packet before - simply record the new value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 * Function do_soft_timestamp() will report the value to the front end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	 * hence asking the decoder to keep decoding rather than stopping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (packet_queue->timestamp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		packet_queue->next_timestamp = elem->timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		return OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	 * This is the first timestamp we've seen since the beginning of traces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	 * or a discontinuity.  Since timestamps packets are generated *after*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	 * range packets have been generated, we need to estimate the time at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 * which instructions started by substracting the number of instructions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	 * executed to the timestamp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	packet_queue->timestamp = elem->timestamp - packet_queue->instr_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	packet_queue->next_timestamp = elem->timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	packet_queue->instr_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	/* Tell the front end which traceid_queue needs attention */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	/* Halt processing until we are being told to proceed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return OCSD_RESP_WAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) cs_etm_decoder__reset_timestamp(struct cs_etm_packet_queue *packet_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	packet_queue->timestamp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	packet_queue->next_timestamp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	packet_queue->instr_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static ocsd_datapath_resp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			      const u8 trace_chan_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			      enum cs_etm_sample_type sample_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	u32 et = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	if (packet_queue->packet_count >= CS_ETM_PACKET_MAX_BUFFER - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		return OCSD_RESP_FATAL_SYS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		return OCSD_RESP_FATAL_SYS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	et = packet_queue->tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	et = (et + 1) & (CS_ETM_PACKET_MAX_BUFFER - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	packet_queue->tail = et;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	packet_queue->packet_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	packet_queue->packet_buffer[et].sample_type = sample_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	packet_queue->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	packet_queue->packet_buffer[et].cpu = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	packet_queue->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	packet_queue->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	packet_queue->packet_buffer[et].instr_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	packet_queue->packet_buffer[et].last_instr_taken_branch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	packet_queue->packet_buffer[et].last_instr_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	packet_queue->packet_buffer[et].last_instr_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	packet_queue->packet_buffer[et].last_instr_subtype = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	packet_queue->packet_buffer[et].last_instr_cond = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	packet_queue->packet_buffer[et].flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	packet_queue->packet_buffer[et].exception_number = UINT32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	packet_queue->packet_buffer[et].trace_chan_id = trace_chan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (packet_queue->packet_count == CS_ETM_PACKET_MAX_BUFFER - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return OCSD_RESP_WAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	return OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static ocsd_datapath_resp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			     struct cs_etm_packet_queue *packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			     const ocsd_generic_trace_elem *elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			     const uint8_t trace_chan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct cs_etm_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	ret = cs_etm_decoder__buffer_packet(packet_queue, trace_chan_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 					    CS_ETM_RANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	packet = &packet_queue->packet_buffer[packet_queue->tail];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	switch (elem->isa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	case ocsd_isa_aarch64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		packet->isa = CS_ETM_ISA_A64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	case ocsd_isa_arm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		packet->isa = CS_ETM_ISA_A32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	case ocsd_isa_thumb2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		packet->isa = CS_ETM_ISA_T32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	case ocsd_isa_tee:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	case ocsd_isa_jazelle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	case ocsd_isa_custom:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	case ocsd_isa_unknown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		packet->isa = CS_ETM_ISA_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	packet->start_addr = elem->st_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	packet->end_addr = elem->en_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	packet->instr_count = elem->num_instr_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	packet->last_instr_type = elem->last_i_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	packet->last_instr_subtype = elem->last_i_subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	packet->last_instr_cond = elem->last_instr_cond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	switch (elem->last_i_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	case OCSD_INSTR_BR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	case OCSD_INSTR_BR_INDIRECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		packet->last_instr_taken_branch = elem->last_instr_exec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	case OCSD_INSTR_ISB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	case OCSD_INSTR_DSB_DMB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	case OCSD_INSTR_WFI_WFE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	case OCSD_INSTR_OTHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		packet->last_instr_taken_branch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	packet->last_instr_size = elem->last_instr_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	/* per-thread scenario, no need to generate a timestamp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (cs_etm__etmq_is_timeless(etmq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	 * The packet queue is full and we haven't seen a timestamp (had we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	 * seen one the packet queue wouldn't be full).  Let the front end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	 * deal with it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	if (ret == OCSD_RESP_WAIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	packet_queue->instr_count += elem->num_instr_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	/* Tell the front end we have a new timestamp to process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	ret = cs_etm_decoder__do_soft_timestamp(etmq, packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 						trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static ocsd_datapath_resp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) cs_etm_decoder__buffer_discontinuity(struct cs_etm_packet_queue *queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 				     const uint8_t trace_chan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	 * Something happened and who knows when we'll get new traces so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	 * reset time statistics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	cs_etm_decoder__reset_timestamp(queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return cs_etm_decoder__buffer_packet(queue, trace_chan_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 					     CS_ETM_DISCONTINUITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static ocsd_datapath_resp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) cs_etm_decoder__buffer_exception(struct cs_etm_packet_queue *queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 				 const ocsd_generic_trace_elem *elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				 const uint8_t trace_chan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	struct cs_etm_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	ret = cs_etm_decoder__buffer_packet(queue, trace_chan_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 					    CS_ETM_EXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	packet = &queue->packet_buffer[queue->tail];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	packet->exception_number = elem->exception_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static ocsd_datapath_resp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) cs_etm_decoder__buffer_exception_ret(struct cs_etm_packet_queue *queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 				     const uint8_t trace_chan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	return cs_etm_decoder__buffer_packet(queue, trace_chan_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 					     CS_ETM_EXCEPTION_RET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static ocsd_datapath_resp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			struct cs_etm_packet_queue *packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			const ocsd_generic_trace_elem *elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 			const uint8_t trace_chan_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	pid_t tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	/* Ignore PE_CONTEXT packets that don't have a valid contextID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	if (!elem->context.ctxt_id_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		return OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	tid =  elem->context.context_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	if (cs_etm__etmq_set_tid(etmq, tid, trace_chan_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		return OCSD_RESP_FATAL_SYS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	 * A timestamp is generated after a PE_CONTEXT element so make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	 * to rely on that coming one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	cs_etm_decoder__reset_timestamp(packet_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	return OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 				const void *context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 				const ocsd_trc_index_t indx __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 				const u8 trace_chan_id __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 				const ocsd_generic_trace_elem *elem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	struct cs_etm_queue *etmq = decoder->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	struct cs_etm_packet_queue *packet_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	/* First get the packet queue for this traceID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if (!packet_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		return OCSD_RESP_FATAL_SYS_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	switch (elem->elem_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	case OCSD_GEN_TRC_ELEM_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	case OCSD_GEN_TRC_ELEM_EO_TRACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	case OCSD_GEN_TRC_ELEM_NO_SYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	case OCSD_GEN_TRC_ELEM_TRACE_ON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		resp = cs_etm_decoder__buffer_discontinuity(packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 							    trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	case OCSD_GEN_TRC_ELEM_INSTR_RANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		resp = cs_etm_decoder__buffer_range(etmq, packet_queue, elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 						    trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	case OCSD_GEN_TRC_ELEM_EXCEPTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		resp = cs_etm_decoder__buffer_exception(packet_queue, elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 							trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	case OCSD_GEN_TRC_ELEM_EXCEPTION_RET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		resp = cs_etm_decoder__buffer_exception_ret(packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 							    trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	case OCSD_GEN_TRC_ELEM_TIMESTAMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		resp = cs_etm_decoder__do_hard_timestamp(etmq, elem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 							 trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	case OCSD_GEN_TRC_ELEM_PE_CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		resp = cs_etm_decoder__set_tid(etmq, packet_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 					       elem, trace_chan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	/* Unused packet types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	case OCSD_GEN_TRC_ELEM_I_RANGE_NOPATH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	case OCSD_GEN_TRC_ELEM_ADDR_NACC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	case OCSD_GEN_TRC_ELEM_CYCLE_COUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	case OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	case OCSD_GEN_TRC_ELEM_EVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	case OCSD_GEN_TRC_ELEM_SWTRACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	case OCSD_GEN_TRC_ELEM_CUSTOM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	return resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static int cs_etm_decoder__create_etm_packet_decoder(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 					struct cs_etm_trace_params *t_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 					struct cs_etm_decoder *decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	const char *decoder_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	ocsd_etmv3_cfg config_etmv3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	ocsd_etmv4_cfg trace_config_etmv4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	void *trace_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	u8 csid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	switch (t_params->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	case CS_ETM_PROTO_ETMV3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	case CS_ETM_PROTO_PTM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		cs_etm_decoder__gen_etmv3_config(t_params, &config_etmv3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		decoder_name = (t_params->protocol == CS_ETM_PROTO_ETMV3) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 							OCSD_BUILTIN_DCD_ETMV3 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 							OCSD_BUILTIN_DCD_PTM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		trace_config = &config_etmv3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	case CS_ETM_PROTO_ETMV4i:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		cs_etm_decoder__gen_etmv4_config(t_params, &trace_config_etmv4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		decoder_name = OCSD_BUILTIN_DCD_ETMV4I;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 		trace_config = &trace_config_etmv4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	if (ocsd_dt_create_decoder(decoder->dcd_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 				     decoder_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 				     OCSD_CREATE_FLG_FULL_DECODER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 				     trace_config, &csid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	if (ocsd_dt_set_gen_elem_outfn(decoder->dcd_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 				       cs_etm_decoder__gen_trace_elem_printer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 				       decoder))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 				   struct cs_etm_trace_params *t_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 				   struct cs_etm_decoder *decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	if (d_params->operation == CS_ETM_OPERATION_PRINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		return cs_etm_decoder__create_etm_packet_printer(t_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 								 decoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	else if (d_params->operation == CS_ETM_OPERATION_DECODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		return cs_etm_decoder__create_etm_packet_decoder(t_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 								 decoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct cs_etm_decoder *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		    struct cs_etm_trace_params t_params[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	struct cs_etm_decoder *decoder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	ocsd_dcd_tree_src_t format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	if ((!t_params) || (!d_params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	decoder = zalloc(sizeof(*decoder));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	if (!decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	decoder->data = d_params->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	decoder->prev_return = OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	format = (d_params->formatted ? OCSD_TRC_SRC_FRAME_FORMATTED :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 					 OCSD_TRC_SRC_SINGLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	flags |= (d_params->fsyncs ? OCSD_DFRMTR_HAS_FSYNCS : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	flags |= (d_params->hsyncs ? OCSD_DFRMTR_HAS_HSYNCS : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	flags |= (d_params->frame_aligned ? OCSD_DFRMTR_FRAME_MEM_ALIGN : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	 * Drivers may add barrier frames when used with perf, set up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	 * handle this. Barriers const of FSYNC packet repeated 4 times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	flags |= OCSD_DFRMTR_RESET_ON_4X_FSYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	/* Create decode tree for the data source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	decoder->dcd_tree = ocsd_create_dcd_tree(format, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	if (decoder->dcd_tree == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		goto err_free_decoder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	/* init library print logging support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	ret = cs_etm_decoder__init_def_logger_printing(d_params, decoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		goto err_free_decoder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	/* init raw frame logging if required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	cs_etm_decoder__init_raw_frame_logging(d_params, decoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	for (i = 0; i < num_cpu; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		ret = cs_etm_decoder__create_etm_decoder(d_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 							 &t_params[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 							 decoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 			goto err_free_decoder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	return decoder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) err_free_decoder:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	cs_etm_decoder__free(decoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 				       u64 indx, const u8 *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 				       size_t len, size_t *consumed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	ocsd_datapath_resp_t cur = OCSD_RESP_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	ocsd_datapath_resp_t prev_return = decoder->prev_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	size_t processed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	while (processed < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		if (OCSD_DATA_RESP_IS_WAIT(prev_return)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 			cur = ocsd_dt_process_data(decoder->dcd_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 						   OCSD_OP_FLUSH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 						   0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 						   0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 						   NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 						   NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 		} else if (OCSD_DATA_RESP_IS_CONT(prev_return)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 			cur = ocsd_dt_process_data(decoder->dcd_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 						   OCSD_OP_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 						   indx + processed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 						   len - processed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 						   &buf[processed],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 						   &count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 			processed += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 		 * Return to the input code if the packet buffer is full.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 		 * Flushing will get done once the packet buffer has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		 * processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		if (OCSD_DATA_RESP_IS_WAIT(cur))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		prev_return = cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	decoder->prev_return = cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	*consumed = processed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) void cs_etm_decoder__free(struct cs_etm_decoder *decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	if (!decoder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	ocsd_destroy_dcd_tree(decoder->dcd_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	decoder->dcd_tree = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	free(decoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }