2 * \file ocsd_c_api_custom_obj.h
5 * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
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.
36 #ifndef ARM_OCSD_C_API_CUSTOM_OBJ_H_INCLUDED
37 #define ARM_OCSD_C_API_CUSTOM_OBJ_H_INCLUDED
39 #include "opencsd/c_api/ocsd_c_api_custom.h"
40 #include "common/ocsd_dcd_mngr_i.h"
42 /***** Decoder manager interface ******************************/
43 class CustomDcdMngrWrapper : public IDecoderMngr
46 CustomDcdMngrWrapper();
47 virtual ~CustomDcdMngrWrapper() {};
49 // set the C-API decoder factory interface.
50 void setAPIDcdFact(ocsd_extern_dcd_fact_t *p_dcd_fact);
52 // create and destroy decoders
53 virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **ppComponent);
54 virtual ocsd_err_t destroyDecoder(TraceComponent *pComponent);
56 //! Get the built in protocol type ID managed by this instance - extern for custom decoders
57 virtual const ocsd_trace_protocol_t getProtocolType() const;
59 // connect decoders to other components - (replace current / 0 pointer value to detach );
60 // compatible with all decoders
61 //!attach error logger to ptk-processor, or both of pkt processor and pkt decoder pair
62 virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog);
65 //! attach instruction decoder to pkt decoder
66 virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec);
68 //! attach memory accessor to pkt decoder
69 virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor);
71 //! attach generic output interface to pkt decoder
72 virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink);
75 //! attach a raw packet monitor to pkt processor (solo pkt processor, or pkt processor part of pair)
76 virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon);
78 //! attach a packet indexer to pkt processor (solo pkt processor, or pkt processor part of pair)
79 virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer);
81 //! attach a packet data sink to pkt processor output (solo pkt processor only - instead of decoder when pkt processor only created.)
82 virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink);
84 // data input connection interface
85 //! get raw data input interface from packet processor
86 virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn);
88 // create configuration from data structure
89 virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct);
91 // custom packet to string interface.
92 void pktToString(const void *pkt, char *pStrBuffer, int bufSize);
96 ocsd_extern_dcd_fact_t m_dcd_fact;
99 /**** Decoder instance wrapper */
100 class CustomDecoderWrapper : public TraceComponent, public ITrcDataIn
103 CustomDecoderWrapper();
104 virtual ~CustomDecoderWrapper();
105 ocsd_extern_dcd_inst_t *getDecoderInstInfo() { return &m_decoder_inst; }
107 virtual ocsd_datapath_resp_t TraceDataIn( const ocsd_datapath_op_t op,
108 const ocsd_trc_index_t index,
109 const uint32_t dataBlockSize,
110 const uint8_t *pDataBlock,
111 uint32_t *numBytesProcessed);
113 void attachGenElemI(ITrcGenElemIn *pIF) { m_pGenElemIn = pIF; };
114 void attachInstrDecI(IInstrDecode *pIF) { m_pIInstrDec = pIF; };
115 void attachMemAccI(ITargetMemAccess *pIF) { m_pMemAccessor = pIF; };
117 void attachPtkMonI(IPktRawDataMon<void> *pIF);
118 void attachPtkSinkI(IPktDataIn<void> *pIF);
120 void updateNameFromDcdInst();
122 static void SetCallbacks(ocsd_extern_dcd_cb_fns &callbacks);
125 // declare the callback functions as friend functions.
126 friend ocsd_datapath_resp_t GenElemOpCB( const void *lib_context,
127 const ocsd_trc_index_t index_sop,
128 const uint8_t trc_chan_id,
129 const ocsd_generic_trace_elem *elem);
131 friend void LogErrorCB( const void *lib_context,
132 const ocsd_err_severity_t filter_level,
133 const ocsd_err_t code,
134 const ocsd_trc_index_t idx,
135 const uint8_t chan_id,
138 friend void LogMsgCB(const void *lib_context,
139 const ocsd_err_severity_t filter_level,
142 friend ocsd_err_t DecodeArmInstCB(const void *lib_context, ocsd_instr_info *instr_info);
144 friend ocsd_err_t MemAccessCB(const void *lib_context,
145 const ocsd_vaddr_t address,
146 const uint8_t cs_trace_id,
147 const ocsd_mem_space_acc_t mem_space,
151 friend void PktMonCB(const void *lib_context,
152 const ocsd_datapath_op_t op,
153 const ocsd_trc_index_t index_sop,
156 const uint8_t *p_data);
158 friend ocsd_datapath_resp_t PktDataSinkCB(const void *lib_context,
159 const ocsd_datapath_op_t op,
160 const ocsd_trc_index_t index_sop,
164 ITrcGenElemIn *m_pGenElemIn; //!< generic element sink interface - output from decoder fed to common sink.
165 IInstrDecode *m_pIInstrDec; //!< arm instruction decode interface - decoder may want to use this.
166 ITargetMemAccess *m_pMemAccessor; //!< system memory accessor insterface - decoder may want to use this.
167 IPktRawDataMon<void> *m_pPktMon; //!< interface to packet monitor (full or packet only decode).
168 IPktDataIn<void> *m_pPktIn; //!< interface to packet sink (decode packets only).
170 ocsd_extern_dcd_inst_t m_decoder_inst;
173 /**** Decoder configuration wrapper - implements CSConfig base class interface ***/
174 class CustomConfigWrapper : public CSConfig
177 CustomConfigWrapper(const void *p_config) : m_p_config(p_config), m_CSID(0) {};
178 virtual ~CustomConfigWrapper() {};
179 virtual const uint8_t getTraceID() const { return m_CSID; };
180 void setCSID(const uint8_t CSID) { m_CSID = CSID; };
181 const void *getConfig() { return m_p_config; };
183 const void *m_p_config;
187 #endif // ARM_OCSD_C_API_CUSTOM_OBJ_H_INCLUDED
189 /* End of File ocsd_c_api_custom_obj.h */