1 /*!
2  * \file       opencsd/ocsd_if_types.h
3  * \brief      OpenCSD : Standard Types used in the library interfaces.
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 /*
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef ARM_OCSD_IF_TYPES_H_INCLUDED
36 #define ARM_OCSD_IF_TYPES_H_INCLUDED
37 
38 #include <stdint.h>
39 #include <stddef.h>
40 #if defined(_MSC_VER) && (_MSC_VER < 1900)
41 /** VS2010 does not support inttypes - remove when VS2010 support is dropped */
42 #define __PRI64_PREFIX "ll"
43 #define PRIX64 __PRI64_PREFIX "X"
44 #define PRIu64 __PRI64_PREFIX "u"
45 #define PRIu32 "u"
46 #else
47 #include <inttypes.h>
48 #endif
49 
50 
51 /** @defgroup ocsd_interfaces OpenCSD Library : Interfaces
52     @brief Set of types, structures and virtual interface classes making up the primary API
53 
54   Set of component interfaces that connect various source reader and decode components into a
55   decode tree to allow trace decode for the trace data being output by the source reader.
56 
57 @{*/
58 
59 
60 
61 /** @name Trace Indexing and Channel IDs
62 @{*/
63 #ifdef ENABLE_LARGE_TRACE_SOURCES
64 typedef uint64_t ocsd_trc_index_t;   /**< Trace source index type - 64 bit size */
65 #define OCSD_TRC_IDX_STR PRIu64
66 #else
67 typedef uint32_t ocsd_trc_index_t;   /**< Trace source index type - 32 bit size */
68 #define OCSD_TRC_IDX_STR PRIu32
69 #endif
70 
71 /** Invalid trace index value */
72 #define OCSD_BAD_TRC_INDEX           ((ocsd_trc_index_t)-1)
73 /** Invalid trace source ID value */
74 #define OCSD_BAD_CS_SRC_ID           ((uint8_t)-1)
75 /** macro returing true if trace source ID is in valid range (0x0 < ID < 0x70) */
76 #define OCSD_IS_VALID_CS_SRC_ID(id)      ((id > 0) && (id < 0x70))
77 /** macro returing true if trace source ID is in reserved range (ID == 0x0 || 0x70 <= ID <= 0x7F) */
78 #define OCSD_IS_RESERVED_CS_SRC_ID(id)   ((id == 0) || ((id >= 0x70) && (id <= 0x7F))
79 /** @}*/
80 
81 /** @name General Library Return and Error Codes
82 @{*/
83 
84 /** Library Error return type */
85 typedef enum _ocsd_err_t {
86 
87     /* general return errors */
88     OCSD_OK = 0,                   /**< No Error. */
89     OCSD_ERR_FAIL,                 /**< General systemic failure. */
90     OCSD_ERR_MEM,                  /**< Internal memory allocation error. */
91     OCSD_ERR_NOT_INIT,             /**< Component not initialised or initialisation failure. */
92     OCSD_ERR_INVALID_ID,           /**< Invalid CoreSight Trace Source ID.  */
93     OCSD_ERR_BAD_HANDLE,           /**< Invalid handle passed to component. */
94     OCSD_ERR_INVALID_PARAM_VAL,    /**< Invalid value parameter passed to component. */
95     OCSD_ERR_INVALID_PARAM_TYPE,   /**< Type mismatch on abstract interface */
96     OCSD_ERR_FILE_ERROR,           /**< File access error */
97     OCSD_ERR_NO_PROTOCOL,          /**< Trace protocol unsupported */
98     /* attachment point errors */
99     OCSD_ERR_ATTACH_TOO_MANY,      /**< Cannot attach - attach device limit reached. */
100     OCSD_ERR_ATTACH_INVALID_PARAM, /**< Cannot attach - invalid parameter. */
101     OCSD_ERR_ATTACH_COMP_NOT_FOUND,/**< Cannot detach - component not found. */
102     /* source reader errors */
103     OCSD_ERR_RDR_FILE_NOT_FOUND,   /**< source reader - file not found. */
104     OCSD_ERR_RDR_INVALID_INIT,     /**< source reader - invalid initialisation parameter. */
105     OCSD_ERR_RDR_NO_DECODER,       /**< source reader - not trace decoder set. */
106     /* data path errors */
107     OCSD_ERR_DATA_DECODE_FATAL,    /**< A decoder in the data path has returned a fatal error. */
108     /* frame deformatter errors */
109     OCSD_ERR_DFMTR_NOTCONTTRACE,    /**< Trace input to deformatter none-continuous */
110     /* packet processor errors - protocol issues etc */
111     OCSD_ERR_BAD_PACKET_SEQ,        /**< Bad packet sequence */
112     OCSD_ERR_INVALID_PCKT_HDR,      /**< Invalid packet header */
113     OCSD_ERR_PKT_INTERP_FAIL,       /**< Interpreter failed - cannot recover - bad data or sequence */
114     /* packet decoder errors */
115     OCSD_ERR_UNSUPPORTED_ISA,          /**< ISA not supported in decoder. */
116     OCSD_ERR_HW_CFG_UNSUPP,            /**< Programmed trace configuration not supported by decoder.*/
117     OCSD_ERR_UNSUPP_DECODE_PKT,        /**< Packet not supported in decoder */
118     OCSD_ERR_BAD_DECODE_PKT,           /**< reserved or unknown packet in decoder. */
119     OCSD_ERR_COMMIT_PKT_OVERRUN,       /**< overrun in commit packet stack - tried to commit more than available */
120     OCSD_ERR_MEM_NACC,                 /**< unable to access required memory address */
121     OCSD_ERR_RET_STACK_OVERFLOW,       /**< internal return stack overflow checks failed - popped more than we pushed. */
122     /* decode tree errors */
123     OCSD_ERR_DCDT_NO_FORMATTER,         /**< No formatter in use - operation not valid. */
124     /* target memory access errors */
125     OCSD_ERR_MEM_ACC_OVERLAP,           /**< Attempted to set an overlapping range in memory access map */
126     OCSD_ERR_MEM_ACC_FILE_NOT_FOUND,    /**< Memory access file could not be opened */
127     OCSD_ERR_MEM_ACC_FILE_DIFF_RANGE,   /**< Attempt to re-use the same memory access file for a different address range */
128     OCSD_ERR_MEM_ACC_RANGE_INVALID,     /**< Address range in accessor set to invalid values */
129     /* test errors - errors generated only by the test code, not the library */
130     OCSD_ERR_TEST_SNAPSHOT_PARSE,       /**< test snapshot file parse error */
131     OCSD_ERR_TEST_SNAPSHOT_PARSE_INFO,  /**< test snapshot file parse information */
132     OCSD_ERR_TEST_SNAPSHOT_READ,        /**< test snapshot reader error */
133     OCSD_ERR_TEST_SS_TO_DECODER,        /**< test snapshot to decode tree conversion error */
134     /* decoder registration */
135     OCSD_ERR_DCDREG_NAME_REPEAT,        /**< attempted to register a decoder with the same name as another one */
136     OCSD_ERR_DCDREG_NAME_UNKNOWN,       /**< attempted to find a decoder with a name that is not known in the library */
137     OCSD_ERR_DCDREG_TYPE_UNKNOWN,       /**< attempted to find a decoder with a type that is not known in the library */
138     OCSD_ERR_DCDREG_TOOMANY,            /**< attempted to register too many custom decoders */
139     /* decoder config */
140     OCSD_ERR_DCD_INTERFACE_UNUSED,      /**< Attempt to connect or use and inteface not supported by this decoder. */
141     /* end marker*/
142     OCSD_ERR_LAST
143 } ocsd_err_t;
144 
145 /* component handle types */
146 typedef unsigned int ocsd_hndl_rdr_t;      /**< reader control handle */
147 typedef unsigned int ocsd_hndl_err_log_t;  /**< error logger connection handle */
148 
149 /* common invalid handle type */
150 #define OCSD_INVALID_HANDLE (unsigned int)-1     /**< Global invalid handle value */
151 
152 /*!  Error Severity Type
153  *
154  *   Used to indicate the severity of an error, and also as the
155  *   error log verbosity level in the error logger.
156  *
157  *   The logger will ignore errors with a severity value higher than the
158  *   current verbosity level.
159  *
160  *   The value OCSD_ERR_SEV_NONE can only be used as a verbosity level to switch off logging,
161  *   not as a severity value on an error. The other values can be used as both error severity and
162  *   logger verbosity values.
163  */
164 typedef enum _ocsd_err_severity_t {
165     OCSD_ERR_SEV_NONE,     /**< No error logging. */
166     OCSD_ERR_SEV_ERROR,    /**< Most severe error - perhaps fatal. */
167     OCSD_ERR_SEV_WARN,     /**< Warning level. Inconsistent or incorrect data seen but can carry on decode processing */
168     OCSD_ERR_SEV_INFO,     /**< Information only message. Use for debugging code or suspect input data. */
169 } ocsd_err_severity_t;
170 
171 /** @}*/
172 
173 /** @name Trace Datapath
174 @{*/
175 
176 /** Trace Datapath operations.
177   */
178 typedef enum _ocsd_datapath_op_t {
179     OCSD_OP_DATA = 0, /**< Standard index + data packet */
180     OCSD_OP_EOT,   /**< End of available trace data. No data packet. */
181     OCSD_OP_FLUSH, /**< Flush existing data where possible, retain decode state. No data packet. */
182     OCSD_OP_RESET, /**< Reset decode state - drop any existing partial data. No data packet. */
183 } ocsd_datapath_op_t;
184 
185 /**
186   * Trace Datapath responses
187   */
188 typedef enum _ocsd_datapath_resp_t {
189     OCSD_RESP_CONT,                /**< Continue processing */
190     OCSD_RESP_WARN_CONT,           /**< Continue processing  : a component logged a warning. */
191     OCSD_RESP_ERR_CONT,            /**< Continue processing  : a component logged an error.*/
192     OCSD_RESP_WAIT,                /**< Pause processing */
193     OCSD_RESP_WARN_WAIT,           /**< Pause processing : a component logged a warning. */
194     OCSD_RESP_ERR_WAIT,            /**< Pause processing : a component logged an error. */
195     OCSD_RESP_FATAL_NOT_INIT,      /**< Processing Fatal Error :  component unintialised. */
196     OCSD_RESP_FATAL_INVALID_OP,    /**< Processing Fatal Error :  invalid data path operation. */
197     OCSD_RESP_FATAL_INVALID_PARAM, /**< Processing Fatal Error :  invalid parameter in datapath call. */
198     OCSD_RESP_FATAL_INVALID_DATA,  /**< Processing Fatal Error :  invalid trace data */
199     OCSD_RESP_FATAL_SYS_ERR,       /**< Processing Fatal Error :  internal system error. */
200 } ocsd_datapath_resp_t;
201 
202 /*! Macro returning true if datapath response value is FATAL. */
203 #define OCSD_DATA_RESP_IS_FATAL(x) (x >= OCSD_RESP_FATAL_NOT_INIT)
204 /*! Macro returning true if datapath response value indicates WARNING logged. */
205 #define OCSD_DATA_RESP_IS_WARN(x) ((x == OCSD_RESP_WARN_CONT) || (x == OCSD_RESP_WARN_WAIT))
206 /*! Macro returning true if datapath response value indicates ERROR logged. */
207 #define OCSD_DATA_RESP_IS_ERR(x) ((x == OCSD_RESP_ERR_CONT) || (x == OCSD_RESP_ERR_WAIT))
208 /*! Macro returning true if datapath response value indicates WARNING or ERROR logged. */
209 #define OCSD_DATA_RESP_IS_WARN_OR_ERR(x) (OCSD_DATA_RESP_IS_ERR(x) || OCSD_DATA_RESP_IS_WARN(x))
210 /*! Macro returning true if datapath response value is CONT. */
211 #define OCSD_DATA_RESP_IS_CONT(x) (x <  OCSD_RESP_WAIT)
212 /*! Macro returning true if datapath response value is WAIT. */
213 #define OCSD_DATA_RESP_IS_WAIT(x) ((x >= OCSD_RESP_WAIT) && (x < OCSD_RESP_FATAL_NOT_INIT))
214 
215 /** @}*/
216 
217 /** @name Trace Decode component types
218 @{*/
219 
220 
221 /** Raw frame element data types
222     Data blocks types output from ITrcRawFrameIn.
223 */
224 typedef enum _rcdtl_rawframe_elem_t {
225     OCSD_FRM_NONE,     /**< None data operation on data path. (EOT etc.) */
226     OCSD_FRM_PACKED,   /**< Raw packed frame data */
227     OCSD_FRM_HSYNC,    /**< HSYNC data */
228     OCSD_FRM_FSYNC,    /**< Frame Sync Data */
229     OCSD_FRM_ID_DATA,  /**< unpacked data for ID */
230 } ocsd_rawframe_elem_t;
231 
232 
233 /** Indicates if the trace source will be frame formatted or a single protocol source.
234     Used in decode tree creation and configuration code.
235 */
236 typedef enum _ocsd_dcd_tree_src_t {
237     OCSD_TRC_SRC_FRAME_FORMATTED,  /**< input source is frame formatted. */
238     OCSD_TRC_SRC_SINGLE,           /**< input source is from a single protocol generator. */
239 } ocsd_dcd_tree_src_t;
240 
241 #define OCSD_DFRMTR_HAS_FSYNCS         0x01 /**< Deformatter Config : formatted data has fsyncs - input data 4 byte aligned */
242 #define OCSD_DFRMTR_HAS_HSYNCS         0x02 /**< Deformatter Config : formatted data has hsyncs - input data 2 byte aligned */
243 #define OCSD_DFRMTR_FRAME_MEM_ALIGN    0x04 /**< Deformatter Config : formatted frames are memory aligned, no syncs. Input data 16 byte frame aligned. */
244 #define OCSD_DFRMTR_PACKED_RAW_OUT     0x08 /**< Deformatter Config : output raw packed frame data if raw monitor attached. */
245 #define OCSD_DFRMTR_UNPACKED_RAW_OUT   0x10 /**< Deformatter Config : output raw unpacked frame data if raw monitor attached. */
246 #define OCSD_DFRMTR_RESET_ON_4X_FSYNC  0x20 /**< Deformatter Config : reset downstream decoders if frame aligned 4x consecutive fsyncs spotted. (perf workaround) */
247 #define OCSD_DFRMTR_VALID_MASK         0x3F /**< Deformatter Config : valid mask for deformatter configuration */
248 
249 #define OCSD_DFRMTR_FRAME_SIZE         0x10 /**< CoreSight frame formatter frame size constant in bytes. */
250 
251 /** @}*/
252 
253 /** @name Trace Decode Component Name Prefixes
254  *
255  *  Set of standard prefixes to be used for component names
256 @{*/
257 
258 /** Component name prefix for trace source reader components */
259 #define OCSD_CMPNAME_PREFIX_SOURCE_READER "SRDR"
260 /** Component name prefix for trace frame deformatter component */
261 #define OCSD_CMPNAME_PREFIX_FRAMEDEFORMATTER "DFMT"
262 /** Component name prefix for trace packet processor. */
263 #define OCSD_CMPNAME_PREFIX_PKTPROC "PKTP"
264 /** Component name prefix for trace packet decoder. */
265 #define OCSD_CMPNAME_PREFIX_PKTDEC   "PDEC"
266 
267 /** @}*/
268 
269 /** @name Trace Decode Arch and Profile
270 @{*/
271 
272 /** Core Architecture Version */
273 typedef enum _ocsd_arch_version {
274     ARCH_UNKNOWN,   /**< unknown architecture */
275     ARCH_V7,        /**< V7 architecture */
276     ARCH_V8,        /**< V8 architecture */
277     ARCH_CUSTOM,    /**< None ARM, custom architecture */
278 } ocsd_arch_version_t;
279 
280 /** Core Profile  */
281 typedef enum _ocsd_core_profile {
282     profile_Unknown,    /**< Unknown profile */
283     profile_CortexM,    /**< Cortex-M profile */
284     profile_CortexR,    /**< Cortex-R profile */
285     profile_CortexA,    /**< Cortex-A profile */
286     profile_Custom,     /**< None ARM, custom arch profile */
287 } ocsd_core_profile_t;
288 
289 /** Combined architecture and profile descriptor for a core */
290 typedef struct _ocsd_arch_profile_t {
291     ocsd_arch_version_t arch;      /**< core architecture */
292     ocsd_core_profile_t profile;   /**< core profile */
293 } ocsd_arch_profile_t;
294 
295 /* may want to use a 32 bit v-addr when running on 32 bit only ARM platforms. */
296 #ifdef USE_32BIT_V_ADDR
297 typedef uint32_t ocsd_vaddr_t;     /**< 32 bit virtual addressing in library - use if compiling on 32 bit platforms */
298 #define OCSD_MAX_VA_BITSIZE 32     /**< 32 bit Virtual address bitsize macro */
299 #define OCSD_VA_MASK ~0UL          /**< 32 bit Virtual address bitsize mask */
300 #else
301 typedef uint64_t ocsd_vaddr_t;     /**< 64 bit virtual addressing in library */
302 #define OCSD_MAX_VA_BITSIZE 64     /**< 64 bit Virtual address bitsize macro */
303 #define OCSD_VA_MASK ~0ULL         /**< 64 bit Virtual address bitsize mask */
304 #endif
305 
306 /** A bit mask for the first 'bits' consecutive bits of an address */
307 #define OCSD_BIT_MASK(bits) (bits == OCSD_MAX_VA_BITSIZE) ? OCSD_VA_MASK : ((ocsd_vaddr_t)1 << bits) - 1
308 
309 /** @}*/
310 
311 /** @name Instruction Decode Information
312 @{*/
313 
314 /** Instruction Set Architecture type
315  *
316  */
317 typedef enum _ocsd_isa
318 {
319     ocsd_isa_arm,          /**< V7 ARM 32, V8 AArch32 */
320     ocsd_isa_thumb2,       /**< Thumb2 -> 16/32 bit instructions */
321     ocsd_isa_aarch64,      /**< V8 AArch64 */
322     ocsd_isa_tee,          /**< Thumb EE - unsupported */
323     ocsd_isa_jazelle,      /**< Jazelle - unsupported in trace */
324     ocsd_isa_custom,       /**< Instruction set - custom arch decoder */
325     ocsd_isa_unknown       /**< ISA not yet known */
326 } ocsd_isa;
327 
328 /** Security level type
329 */
330 typedef enum _ocsd_sec_level
331 {
332     ocsd_sec_secure,   /**< Core is in secure state */
333     ocsd_sec_nonsecure /**< Core is in non-secure state */
334 } ocsd_sec_level ;
335 
336 /** Exception level type
337 */
338 typedef enum _ocsd_ex_level
339 {
340     ocsd_EL_unknown = -1, /**< EL unknown / unsupported in trace */
341     ocsd_EL0 = 0,  /**< EL0 */
342     ocsd_EL1,      /**< EL1 */
343     ocsd_EL2,      /**< EL2 */
344     ocsd_EL3,      /**< EL3 */
345 } ocsd_ex_level;
346 
347 
348 /** instruction types - significant for waypoint calculaitons */
349 typedef enum _ocsd_instr_type {
350     OCSD_INSTR_OTHER,          /**< Other instruction - not significant for waypoints. */
351     OCSD_INSTR_BR,             /**< Immediate Branch instruction */
352     OCSD_INSTR_BR_INDIRECT,    /**< Indirect Branch instruction */
353     OCSD_INSTR_ISB,            /**< Barrier : ISB instruction */
354     OCSD_INSTR_DSB_DMB         /**< Barrier : DSB or DMB instruction */
355 } ocsd_instr_type;
356 
357 /** instruction sub types - addiitonal information passed to the output packets
358     for trace analysis tools.
359  */
360 typedef enum _ocsd_instr_subtype {
361     OCSD_S_INSTR_NONE,         /**< no subtype set */
362     OCSD_S_INSTR_BR_LINK,      /**< branch with link */
363     OCSD_S_INSTR_V8_RET,       /**< v8 ret instruction - subtype of BR_INDIRECT  */
364     OCSD_S_INSTR_V8_ERET,      /**< v8 eret instruction - subtype of BR_INDIRECT */
365 } ocsd_instr_subtype;
366 
367 /** Instruction decode request structure.
368  *
369  *   Used in IInstrDecode  interface.
370  *
371  *   Caller fills in the input: information, callee then fills in the decoder: information.
372  */
373 typedef struct _ocsd_instr_info {
374     /* input information */
375     ocsd_arch_profile_t pe_type;   /**< input: Core Arch and profile */
376     ocsd_isa isa;                  /**< Input: Current ISA. */
377     ocsd_vaddr_t instr_addr;       /**< Input: Instruction address. */
378     uint32_t opcode;                /**< Input: Opcode at address. 16 bit opcodes will use MS 16bits of parameter. */
379     uint8_t dsb_dmb_waypoints;      /**< Input: DMB and DSB are waypoints */
380 
381     /* instruction decode info */
382     ocsd_instr_type type;          /**< Decoder: Current instruction type. */
383     ocsd_vaddr_t branch_addr;      /**< Decoder: Calculated address of branch instrcution (direct branches only) */
384     ocsd_isa next_isa;             /**< Decoder: ISA for next intruction. */
385     uint8_t instr_size;             /**< Decoder : size of the decoded instruction */
386     uint8_t is_conditional;         /**< Decoder : set to 1 if this instruction is conditional */
387     uint8_t is_link;                /**< Decoder : is a branch with link instruction */
388     uint8_t thumb_it_conditions;    /**< Decoder : return number of following instructions set with conditions by this Thumb IT instruction */
389     ocsd_instr_subtype sub_type;   /**< Decoder : current instruction sub-type if known */
390 } ocsd_instr_info;
391 
392 
393 /** Core(PE) context structure
394     records current security state, exception level, VMID and ContextID for core.
395 */
396 typedef struct _ocsd_pe_context {
397     ocsd_sec_level security_level;     /**< security state */
398     ocsd_ex_level  exception_level;    /**< exception level */
399     uint32_t        context_id;         /**< context ID */
400     uint32_t        vmid;               /**< VMID */
401     struct {
402         uint32_t bits64:1;              /**< 1 if 64 bit operation */
403         uint32_t ctxt_id_valid:1;       /**< 1 if context ID value valid */
404         uint32_t vmid_valid:1;          /**< 1 if VMID value is valid */
405         uint32_t el_valid:1;            /**< 1 if EL value is valid (ETMv4 traces EL, other protocols do not) */
406     };
407 } ocsd_pe_context;
408 
409 
410 /** @}*/
411 
412 /** @name Opcode Memory Access
413     Types used when accessing memory storage for traced opcodes..
414 @{*/
415 
416 /** memory space bitfield enum for available security states and exception levels used
417    when accessing memory. */
418 typedef enum _ocsd_mem_space_acc_t {
419     OCSD_MEM_SPACE_EL1S = 0x1, /**<  S EL1/0 */
420     OCSD_MEM_SPACE_EL1N = 0x2, /**< NS EL1/0 */
421     OCSD_MEM_SPACE_EL2 =  0x4, /**< NS EL2   */
422     OCSD_MEM_SPACE_EL3 =  0x8, /**<  S EL3   */
423     OCSD_MEM_SPACE_S =    0x9, /**< Any  S   */
424     OCSD_MEM_SPACE_N =    0x6, /**< Any NS   */
425     OCSD_MEM_SPACE_ANY =  0xF, /**< Any sec level / EL - live system use current EL + sec state */
426 } ocsd_mem_space_acc_t;
427 
428 /**
429  * Callback function definition for callback function memory accessor type.
430  *
431  * When using callback memory accessor, the decoder will call this function to obtain the
432  * memory at the address for the current opcodes. The memory space will represent the current
433  * exception level and security context of the traced code.
434  *
435  * Return the number of bytes read, which can be less than the amount requested if this would take the
436  * access address outside the range of addresses defined when this callback was registered with the decoder.
437  *
438  * Return 0 bytes if start address out of covered range, or memory space is not one of those defined as supported
439  * when the callback was registered.
440  *
441  * @param p_context : opaque context pointer set by callback client.
442  * @param address : start address of memory to be accessed
443  * @param mem_space : memory space of accessed memory (current EL & security state)
444  * @param reqBytes : number of bytes required
445  * @param *byteBuffer : buffer for data.
446  *
447  * @return uint32_t  : Number of bytes actually read, or 0 for access error.
448  */
449 typedef uint32_t  (* Fn_MemAcc_CB)(const void *p_context, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint32_t reqBytes, uint8_t *byteBuffer);
450 
451 
452 /** memory region type for adding multi-region binary files to memory access interface */
453 typedef struct _ocsd_file_mem_region {
454     size_t                  file_offset;    /**< Offset from start of file for memory region */
455     ocsd_vaddr_t           start_address;  /**< Start address of memory region */
456     size_t                  region_size;    /**< size in bytes of memory region */
457 } ocsd_file_mem_region_t;
458 
459 /** @}*/
460 
461 /** @name Packet Processor Operation Control Flags
462     common operational flags - bottom 16 bits,
463     component specific - top 16 bits.
464 @{*/
465 
466 #define OCSD_OPFLG_PKTPROC_NOFWD_BAD_PKTS  0x00000001  /**< don't forward bad packets up data path */
467 #define OCSD_OPFLG_PKTPROC_NOMON_BAD_PKTS  0x00000002  /**< don't forward bad packets to monitor interface */
468 #define OCSD_OPFLG_PKTPROC_ERR_BAD_PKTS    0x00000004  /**< throw error for bad packets - halt decoding. */
469 #define OCSD_OPFLG_PKTPROC_UNSYNC_ON_BAD_PKTS 0x00000008  /**< switch to unsynced state on bad packets - wait for next sync point */
470 
471 /** mask to combine all common packet processor operational control flags */
472 #define OCSD_OPFLG_PKTPROC_COMMON (OCSD_OPFLG_PKTPROC_NOFWD_BAD_PKTS | \
473                                     OCSD_OPFLG_PKTPROC_NOMON_BAD_PKTS | \
474                                     OCSD_OPFLG_PKTPROC_ERR_BAD_PKTS | \
475                                     OCSD_OPFLG_PKTPROC_UNSYNC_ON_BAD_PKTS  )
476 
477 /** @}*/
478 
479 /** @name Packet Decoder Operation Control Flags
480     common operational flags - bottom 16 bits,
481     component specific - top 16 bits.
482 @{*/
483 
484 #define OCSD_OPFLG_PKTDEC_ERROR_BAD_PKTS  0x00000001  /**< throw error on bad packets input (default is to unsync and wait) */
485 
486 /** mask to combine all common packet processor operational control flags */
487 #define OCSD_OPFLG_PKTDEC_COMMON (OCSD_OPFLG_PKTDEC_ERROR_BAD_PKTS)
488 
489 /** @}*/
490 
491 /** @name Decoder creation information
492 
493     Flags to use when creating decoders by name
494 
495     Builtin decoder names.
496 
497     Protocol type enum.
498 @{*/
499 
500 #define OCSD_CREATE_FLG_PACKET_PROC     0x01    /**< Create packet processor only.              */
501 #define OCSD_CREATE_FLG_FULL_DECODER    0x02    /**< Create packet processor + decoder pair     */
502 #define OCSD_CREATE_FLG_INST_ID         0x04    /**< Use instance ID in decoder instance name   */
503 
504 #define OCSD_BUILTIN_DCD_STM        "STM"       /**< STM decoder */
505 #define OCSD_BUILTIN_DCD_ETMV3      "ETMV3"     /**< ETMv3 decoder */
506 #define OCSD_BUILTIN_DCD_ETMV4I     "ETMV4I"    /**< ETMv4 instruction decoder */
507 #define OCSD_BUILTIN_DCD_ETMV4D     "ETMV4D"    /**< ETMv4 data decoder */
508 #define OCSD_BUILTIN_DCD_PTM        "PTM"       /**< PTM decoder */
509 
510 /*! Trace Protocol Builtin Types + extern
511  */
512 typedef enum _ocsd_trace_protocol_t {
513     OCSD_PROTOCOL_UNKNOWN = 0, /**< Protocol unknown */
514 
515 /* Built in library decoders */
516     OCSD_PROTOCOL_ETMV3,   /**< ETMV3 instruction and data trace protocol decoder. */
517     OCSD_PROTOCOL_ETMV4I,  /**< ETMV4 instruction trace protocol decoder. */
518     OCSD_PROTOCOL_ETMV4D,  /**< ETMV4 data trace protocol decoder. */
519     OCSD_PROTOCOL_PTM,     /**< PTM program flow instruction trace protocol decoder. */
520     OCSD_PROTOCOL_STM,     /**< STM system trace protocol decoder. */
521 
522 /* others to be added here */
523     OCSD_PROTOCOL_BUILTIN_END,  /**< Invalid protocol - built-in protocol types end marker */
524 
525 /* Custom / external decoders */
526     OCSD_PROTOCOL_CUSTOM_0 = 100,   /**< Values from this onwards are assigned to external registered decoders */
527     OCSD_PROTOCOL_CUSTOM_1,
528     OCSD_PROTOCOL_CUSTOM_2,
529     OCSD_PROTOCOL_CUSTOM_3,
530     OCSD_PROTOCOL_CUSTOM_4,
531     OCSD_PROTOCOL_CUSTOM_5,
532     OCSD_PROTOCOL_CUSTOM_6,
533     OCSD_PROTOCOL_CUSTOM_7,
534     OCSD_PROTOCOL_CUSTOM_8,
535     OCSD_PROTOCOL_CUSTOM_9,
536 
537     OCSD_PROTOCOL_END      /**< Invalid protocol - protocol types end marker */
538 } ocsd_trace_protocol_t;
539 
540 /** Test if protocol type is a library built-in decoder */
541 #define OCSD_PROTOCOL_IS_BUILTIN(P) ((P > OCSD_PROTOCOL_UNKNOWN) && (P < OCSD_PROTOCOL_BUILTIN_END))
542 
543 /** Test if protocol type is a custom external registered decoder */
544 #define OCSD_PROTOCOL_IS_CUSTOM(P)  ((P >= OCSD_PROTOCOL_CUSTOM_0) && (P < OCSD_PROTOCOL_END ))
545 
546 /** @}*/
547 
548 
549 /** @name Software Trace Packets Info
550 
551     Contains the information for the generic software trace output packet.
552 
553     Software trace packet master and channel data.
554     Payload info:
555         size - packet payload size in bits;
556         marker - if this packet has a marker/flag
557         timestamp - if this packet has a timestamp associated
558         number of packets - packet processor can optionally correlate identically
559         sized packets on the same master / channel to be output as a single generic packet
560 
561     Payload output as separate LE buffer, of sufficient bytes to hold all the packets.
562 @{*/
563 
564 typedef struct _ocsd_swt_info {
565     uint16_t swt_master_id;
566     uint16_t swt_channel_id;
567     union {
568         struct {
569             uint32_t swt_payload_pkt_bitsize:8; /**< [bits 0:7 ] Packet size in bits of the payload packets */
570             uint32_t swt_payload_num_packets:8; /**< [bits 8:15 ] number of consecutive packets of this type in the payload data */
571             uint32_t swt_marker_packet:1;       /**< [bit 16 ] packet is marker / flag packet */
572             uint32_t swt_has_timestamp:1;       /**< [bit 17 ] packet has timestamp. */
573             uint32_t swt_marker_first:1;        /**< [bit 18 ] for multiple packet payloads, this indicates if any marker is on first or last packet */
574             uint32_t swt_master_err:1;          /**< [bit 19 ] current master has error - payload is error code */
575             uint32_t swt_global_err:1;          /**< [bit 20 ] global error - payload is error code - master and channel ID not valid */
576             uint32_t swt_trigger_event:1;       /**< [bit 21 ] trigger event packet - payload is event number */
577             uint32_t swt_frequency:1;           /**< [bit 22 ] frequency packet - payload is frequency */
578             uint32_t swt_id_valid:1;            /**< [bit 23 ] master & channel ID has been set by input stream  */
579         };
580         uint32_t swt_flag_bits;
581     };
582 } ocsd_swt_info_t;
583 
584 /** mask for the swt_id_valid flag - need to retain between packets */
585 #define SWT_ID_VALID_MASK (0x1 << 23)
586 
587 /** @}*/
588 
589 /** @}*/
590 #endif // ARM_OCSD_IF_TYPES_H_INCLUDED
591 
592 /* End of File opencsd/ocsd_if_types.h */
593