xref: /freebsd/contrib/opencsd/decoder/include/common/ocsd_gen_elem_stack.h (revision b6aadd183a8fc19317f893a41f252b32a87759af)
1 /*
2 * \file       ocsd_gen_elem_stack.h
3 * \brief      OpenCSD : Generic element output stack.
4 *
5 * \copyright  Copyright (c) 2020, 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 #include "trc_gen_elem.h"
36 #include "comp_attach_pt_t.h"
37 #include "interfaces/trc_gen_elem_in_i.h"
38 
39 /* element stack to handle cases where a trace element can generate multiple output packets
40 
41    maintains the "current" element, which might be sent independently of this stack, and also
42    ensures that persistent data in the output elements is maintained between elements.
43 */
44 class OcsdGenElemStack
45 {
46 public:
47     OcsdGenElemStack();
48     ~OcsdGenElemStack();
49 
50     void initSendIf(componentAttachPt<ITrcGenElemIn> *pGenElemIf);
initCSID(const uint8_t CSID)51     void initCSID(const uint8_t CSID) { m_CSID = CSID; };
52 
53     OcsdTraceElement &getCurrElem();    //!< get the current element.
54     ocsd_err_t resetElemStack();        //!< set pointers to base of stack
55     ocsd_err_t addElem(const ocsd_trc_index_t trc_pkt_idx);    //!< add elem to stack and set current.
56     void setCurrElemIdx(const ocsd_trc_index_t trc_pkt_idx);   //!< packet index for this element
57     ocsd_err_t addElemType(const ocsd_trc_index_t trc_pkt_idx, ocsd_gen_trc_elem_t elem_type);
58 
59     ocsd_datapath_resp_t sendElements();    //!< send elements on the stack
60     const int numElemToSend() const;
61 
62 private:
63     typedef struct _elemPtr {
64         OcsdTraceElement *pElem;        //!< pointer to the listed trace element
65         ocsd_trc_index_t trc_pkt_idx;   //!< packet index in the trace stream
66     } elemPtr_t;
67 
68     const bool isInit();              //!< check correctly initialised.
69 
70     ocsd_err_t growArray();
71     void copyPersistentData(int src, int dst);  //!< copy across persistent state data between elements
72     void resetIndexes();    //!< clear down all indexes - reset or send complete.
73 
74     elemPtr_t *m_pElemArray;    //!< an array of pointers to elements.
75     int m_elemArraySize;        //!< number of element pointers in the array
76 
77     int m_elem_to_send;     //!< number of live elements in the stack - init to 1.
78     int m_curr_elem_idx;    //!< index into the element array.
79     int m_send_elem_idx;    //!< next element to send.
80 
81     //!< send packet info
82     uint8_t m_CSID;
83     componentAttachPt<ITrcGenElemIn> *m_sendIf; //!< element send interface.
84 
85     bool m_is_init;
86 };
87 
numElemToSend()88 inline const int OcsdGenElemStack::numElemToSend() const
89 {
90     return m_elem_to_send;
91 }
92 
initSendIf(componentAttachPt<ITrcGenElemIn> * pGenElemIf)93 inline void OcsdGenElemStack::initSendIf(componentAttachPt<ITrcGenElemIn> *pGenElemIf)
94 {
95     m_sendIf = pGenElemIf;
96 }
97 
setCurrElemIdx(const ocsd_trc_index_t trc_pkt_idx)98 inline void OcsdGenElemStack::setCurrElemIdx(const ocsd_trc_index_t trc_pkt_idx)
99 {
100     m_pElemArray[m_curr_elem_idx].trc_pkt_idx = trc_pkt_idx;
101 }
102 
getCurrElem()103 inline OcsdTraceElement &OcsdGenElemStack::getCurrElem()
104 {
105     return *(m_pElemArray[m_curr_elem_idx].pElem);
106 }
107 
108 
109 /* End of File ocsd_gen_elem_stack.h */
110