xref: /freebsd/contrib/opencsd/decoder/source/trc_frame_deformatter_impl.h (revision 46e6e290975f19ea62d03f90ac3e523af4dae557)
1 /*
2  * \file       trc_frame_decoder_impl.h
3  * \brief      OpenCSD : Trace Deformatter implementation.
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_TRC_FRAME_DECODER_IMPL_H_INCLUDED
36 #define ARM_TRC_FRAME_DECODER_IMPL_H_INCLUDED
37 
38 #include "opencsd/ocsd_if_types.h"
39 #include "common/comp_attach_pt_t.h"
40 #include "interfaces/trc_data_raw_in_i.h"
41 #include "interfaces/trc_data_rawframe_in_i.h"
42 #include "interfaces/trc_indexer_src_i.h"
43 #include "common/trc_component.h"
44 
45 //! output data fragment from the current frame - collates bytes associated with an ID.
46 typedef struct _out_chan_data {
47     ocsd_trc_index_t index;      //!< trace source index for start of these bytes
48     uint8_t id;             //!< Id for these bytes
49     uint8_t data[15];       //!< frame data bytes for this ID
50     uint32_t valid;         //!< Valid data bytes.
51     uint32_t used;          //!< Data bytes output (used by attached processor).
52 } out_chan_data;
53 
54 class TraceFmtDcdImpl : public TraceComponent, ITrcDataIn
55 {
56 private:
57     TraceFmtDcdImpl();
58     TraceFmtDcdImpl(int instNum);
59     virtual ~TraceFmtDcdImpl();
60 
61     /* the data input interface from the reader */
62     virtual ocsd_datapath_resp_t TraceDataIn(  const ocsd_datapath_op_t op,
63                                                 const ocsd_trc_index_t index,
64                                                 const uint32_t dataBlockSize,
65                                                 const uint8_t *pDataBlock,
66                                                 uint32_t *numBytesProcessed);
67 
68     /* enable / disable ID streams - default as all enabled */
69     ocsd_err_t OutputFilterIDs(std::vector<uint8_t> &id_list, bool bEnable);
70     ocsd_err_t OutputFilterAllIDs(bool bEnable);
71 
72     /* decode control */
73     ocsd_datapath_resp_t Reset();    /* reset the decode to the start state, drop partial data - propogate to attached components */
74     ocsd_datapath_resp_t Flush();
75     ocsd_err_t DecodeConfigure(uint32_t flags);
76     ocsd_err_t SetForcedSyncIndex(ocsd_trc_index_t index, bool bSet);
77 
SetDemuxStatsBlock(ocsd_demux_stats_t * pStatsBlock)78     void SetDemuxStatsBlock(ocsd_demux_stats_t *pStatsBlock) { m_pStatsBlock = pStatsBlock; };
79 
80 private:
81     ocsd_datapath_resp_t executeNoneDataOpAllIDs(ocsd_datapath_op_t op, const ocsd_trc_index_t index = 0);
82     ocsd_datapath_resp_t processTraceData(const ocsd_trc_index_t index,
83                                                 const uint32_t dataBlockSize,
84                                                 const uint8_t *pDataBlock,
85                                                 uint32_t *numBytesProcessed);
86     // process phases
87     bool checkForSync(); // find the sync point in the incoming block
88     bool extractFrame(); // extract the frame data from incoming stream
89     bool unpackFrame(); // process a complete frame.
90     bool outputFrame(); // output data to channels.
91 
92 
93     // managing data path responses.
InitCollateDataPathResp()94     void InitCollateDataPathResp() { m_highestResp = OCSD_RESP_CONT; };
95     void CollateDataPathResp(const ocsd_datapath_resp_t resp);
highestDataPathResp()96     const ocsd_datapath_resp_t highestDataPathResp() const { return m_highestResp; };
dataPathCont()97     const bool dataPathCont() const { return (bool)(m_highestResp < OCSD_RESP_WAIT); };
98 
99     // deformat state
100     void resetStateParams();
101 
102     // synchronisation
103     uint32_t findfirstFSync();
104     void outputUnsyncedBytes(uint32_t num_bytes);  // output bytes as unsynced from current buffer position.
105 
106     // output bytes to raw frame monitor
107     void outputRawMonBytes(const ocsd_datapath_op_t op,
108                            const ocsd_trc_index_t index,
109                            const ocsd_rawframe_elem_t frame_element,
110                            const int dataBlockSize,
111                            const uint8_t *pDataBlock,
112                            const uint8_t traceID);
113 
114 
115     void setRawChanFilterAll(bool bEnable);
116     const bool rawChanEnabled(const uint8_t id) const;
117 
118 	ocsd_err_t checkForResetFSyncPatterns(uint32_t &f_sync_bytes);
119 
120     friend class TraceFormatterFrameDecoder;
121 
122     // stats updates
123     void addToIDStats(uint64_t val);
124     void addToNoIDStats(uint64_t val);
125     void addToFrameStats(uint64_t val);
126     void addToUnknownIDStats(uint64_t val);
127     void addToReservedIDStats(uint64_t val);
128 
isReservedID(uint8_t ID)129     bool isReservedID(uint8_t ID) { return ((ID == 0) || (ID >= 0x70)); };
130 
131     // attachment points
132     componentAttachPt<ITrcDataIn> m_IDStreams[128];
133     componentAttachPt<ITrcRawFrameIn> m_RawTraceFrame;
134 
135     componentAttachPt<ITrcSrcIndexCreator> m_SrcIndexer;
136 
137 
138     ocsd_datapath_resp_t m_highestResp;
139 
140     /* static configuration */
141     uint32_t m_cfgFlags;        /* configuration flags */
142     ocsd_trc_index_t m_force_sync_idx;
143     bool m_use_force_sync;
144     uint32_t m_alignment;
145 
146     /* dynamic state */
147     ocsd_trc_index_t m_trc_curr_idx;    /* index of current trace data */
148     bool m_frame_synced;
149     bool m_first_data;
150     uint8_t m_curr_src_ID;
151 
152     // incoming frame buffer
153     uint8_t m_ex_frm_data[OCSD_DFRMTR_FRAME_SIZE]; // buffer the current frame in case we have to stop part way through
154     int m_ex_frm_n_bytes;   // number of valid bytes in the current frame (extraction)
155     bool m_b_fsync_start_eob;  // flag to indicate that the end of the last buffer was a pair of bytes
156                                // (0xffff) that could only validly be the start and FSYNC.
157     ocsd_trc_index_t m_trc_curr_idx_sof; // trace source index at start of frame.
158 
159     /* channel output data - can never be more than a frame of data for a single ID.
160      * 8 possible ID changes per frame. Although the final one can have no associated data, a pathological
161      * case exists with 7 ID changes, all data associated with a previous frame, except for last
162      * ID / data byte which is data. Not possible with normal hardware but guard against corrupt input.
163      */
164     out_chan_data m_out_data[8]; // output data for a given ID
165     int m_out_data_idx;          // number of out_chan_data frames used.
166     int m_out_processed;         // number of complete out_chan_data frames output.
167 
168     /* local copy of input buffer pointers*/
169     const uint8_t *m_in_block_base;
170     uint32_t m_in_block_size;
171     uint32_t m_in_block_processed;
172 
173     /* raw output options */
174     bool m_b_output_packed_raw;
175     bool m_b_output_unpacked_raw;
176 
177     bool m_raw_chan_enable[128];
178 
179     ocsd_demux_stats_t *m_pStatsBlock;
180 };
181 
182 
183 #endif // ARM_TRC_FRAME_DECODER_IMPL_H_INCLUDED
184 
185 /* End of File trc_frame_decoder_impl.h */
186