]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/opencsd/decoder/source/c_api/ocsd_c_api_custom_obj.h
Re-add opencsd as a vendor import from the dist directory
[FreeBSD/FreeBSD.git] / contrib / opencsd / decoder / source / c_api / ocsd_c_api_custom_obj.h
1 /*
2  * \file       ocsd_c_api_custom_obj.h
3  * \brief      OpenCSD : 
4  * 
5  * \copyright  Copyright (c) 2016, 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
36 #ifndef ARM_OCSD_C_API_CUSTOM_OBJ_H_INCLUDED
37 #define ARM_OCSD_C_API_CUSTOM_OBJ_H_INCLUDED
38
39 #include "opencsd/c_api/ocsd_c_api_custom.h"
40 #include "common/ocsd_dcd_mngr_i.h"
41
42 /***** Decoder manager interface ******************************/
43 class CustomDcdMngrWrapper : public IDecoderMngr
44 {
45 public:
46     CustomDcdMngrWrapper();
47     virtual ~CustomDcdMngrWrapper() {};
48
49     // set the C-API decoder factory interface.
50     void setAPIDcdFact(ocsd_extern_dcd_fact_t *p_dcd_fact);
51
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);
55
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;
58
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);
63
64 // pkt decoder only 
65     //! attach instruction decoder to pkt decoder
66     virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec);
67
68     //! attach memory accessor to pkt decoder
69     virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor);
70
71     //! attach generic output interface to pkt decoder
72     virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink);
73
74 // pkt processor only
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);
77
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);
80
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);
83
84 // data input connection interface
85     //! get raw data input interface from packet processor
86     virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn);
87
88 // create configuration from data structure
89     virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct);
90
91 // custom packet to string interface.
92     void pktToString(const void *pkt, char *pStrBuffer, int bufSize);
93
94 private:
95
96     ocsd_extern_dcd_fact_t m_dcd_fact;
97 };
98
99 /**** Decoder instance wrapper */
100 class CustomDecoderWrapper : public TraceComponent, public ITrcDataIn
101 {
102 public:
103     CustomDecoderWrapper();
104     virtual ~CustomDecoderWrapper();
105     ocsd_extern_dcd_inst_t *getDecoderInstInfo() { return &m_decoder_inst; }
106
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);
112
113     void attachGenElemI(ITrcGenElemIn *pIF) { m_pGenElemIn = pIF; };
114     void attachInstrDecI(IInstrDecode *pIF) { m_pIInstrDec = pIF; };
115     void attachMemAccI(ITargetMemAccess *pIF) { m_pMemAccessor = pIF; };
116
117     void attachPtkMonI(IPktRawDataMon<void> *pIF);
118     void attachPtkSinkI(IPktDataIn<void> *pIF);
119
120     void updateNameFromDcdInst();
121
122     static void SetCallbacks(ocsd_extern_dcd_cb_fns &callbacks);
123
124 private:
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);
130
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, 
136                                 const char *pMsg);
137
138     friend void LogMsgCB(const void *lib_context,
139         const ocsd_err_severity_t filter_level,
140         const char *msg);
141         
142     friend ocsd_err_t DecodeArmInstCB(const void *lib_context, ocsd_instr_info *instr_info);
143
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,
148         uint32_t *num_bytes,
149         uint8_t *p_buffer);
150
151     friend void PktMonCB(const void *lib_context,
152         const ocsd_datapath_op_t op,
153         const ocsd_trc_index_t index_sop,
154         const void *pkt,
155         const uint32_t size,
156         const uint8_t *p_data);
157
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,
161         const void *pkt);
162
163 private:
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).
169
170     ocsd_extern_dcd_inst_t m_decoder_inst;    
171 };
172
173 /**** Decoder configuration wrapper - implements CSConfig base class interface ***/
174 class CustomConfigWrapper : public CSConfig
175 {
176 public:
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; };
182 private:
183     const void *m_p_config;
184     uint8_t m_CSID;
185 };
186
187 #endif // ARM_OCSD_C_API_CUSTOM_OBJ_H_INCLUDED
188
189 /* End of File ocsd_c_api_custom_obj.h */