diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 07:24:57 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 07:24:57 +0000 |
commit | 070852d8604cece0c31f28ff3eb8d21d9ba415fb (patch) | |
tree | 9097175a6a5b8b7e37af9a96269ac0b61a0189cd /decoder/include/opencsd/stm | |
parent | Initial commit. (diff) | |
download | libopencsd-070852d8604cece0c31f28ff3eb8d21d9ba415fb.tar.xz libopencsd-070852d8604cece0c31f28ff3eb8d21d9ba415fb.zip |
Adding upstream version 1.3.3.upstream/1.3.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'decoder/include/opencsd/stm')
-rw-r--r-- | decoder/include/opencsd/stm/stm_decoder.h | 45 | ||||
-rw-r--r-- | decoder/include/opencsd/stm/trc_cmp_cfg_stm.h | 161 | ||||
-rw-r--r-- | decoder/include/opencsd/stm/trc_dcd_mngr_stm.h | 57 | ||||
-rw-r--r-- | decoder/include/opencsd/stm/trc_pkt_decode_stm.h | 104 | ||||
-rw-r--r-- | decoder/include/opencsd/stm/trc_pkt_elem_stm.h | 238 | ||||
-rw-r--r-- | decoder/include/opencsd/stm/trc_pkt_proc_stm.h | 290 | ||||
-rw-r--r-- | decoder/include/opencsd/stm/trc_pkt_types_stm.h | 158 |
7 files changed, 1053 insertions, 0 deletions
diff --git a/decoder/include/opencsd/stm/stm_decoder.h b/decoder/include/opencsd/stm/stm_decoder.h new file mode 100644 index 0000000..1367cad --- /dev/null +++ b/decoder/include/opencsd/stm/stm_decoder.h @@ -0,0 +1,45 @@ +/* + * \file stm_decoder.h + * \brief OpenCSD : STM decoder + * + * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARM_STM_DECODER_H_INCLUDED +#define ARM_STM_DECODER_H_INCLUDED + +#include "trc_pkt_types_stm.h" +#include "trc_pkt_elem_stm.h" +#include "trc_pkt_proc_stm.h" + + +#endif // ARM_STM_DECODER_H_INCLUDED + +/* End of File stm_decoder.h */ diff --git a/decoder/include/opencsd/stm/trc_cmp_cfg_stm.h b/decoder/include/opencsd/stm/trc_cmp_cfg_stm.h new file mode 100644 index 0000000..41003ec --- /dev/null +++ b/decoder/include/opencsd/stm/trc_cmp_cfg_stm.h @@ -0,0 +1,161 @@ +/* + * \file trc_cmp_cfg_stm.h + * \brief OpenCSD : STM compnent configuration. + * + * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARM_TRC_CMP_CFG_STM_H_INCLUDED +#define ARM_TRC_CMP_CFG_STM_H_INCLUDED + +#include "trc_pkt_types_stm.h" +#include "common/trc_cs_config.h" + +/** @addtogroup ocsd_protocol_cfg +@{*/ + +/** @name STM configuration +@{*/ + +/*! + * @class STMConfig + * @brief STM hardware configuration data. + * + * Represents the programmed and hardware configured state of an STM device. + * Creates default values for most RO register values to effect a default STM + * with values of 256 masters, 65536 channels, HW event trace not present / disabled. + * + * If this default is sufficient a single call to setTraceID() will be all that is + * required to decode the STM protocol. + * + * Can also be initialised with a fully populated ocsd_stm_cfg structure. + */ +class STMConfig : public CSConfig // public ocsd_stm_cfg +{ +public: + STMConfig(); //!< Constructor - creates a default configuration + STMConfig(const ocsd_stm_cfg *cfg_regs); + ~STMConfig() {}; + +// operations to convert to and from C-API structure + + STMConfig & operator=(const ocsd_stm_cfg *p_cfg); //!< set from full configuration structure. + //! cast operator returning struct const reference + operator const ocsd_stm_cfg &() const { return m_cfg; }; + //! cast operator returning struct const pointer + operator const ocsd_stm_cfg *() const { return &m_cfg; }; + +// access functions + void setTraceID(const uint8_t traceID); //!< Set the CoreSight trace ID. + void setHWTraceFeat(const hw_event_feat_t hw_feat); //!< set usage of STM HW event trace. + + virtual const uint8_t getTraceID() const; //!< Get the CoreSight trace ID. + const uint8_t getMaxMasterIdx() const; //!< Get the maximum master index + const uint16_t getMaxChannelIdx() const; //!< Get the maximum channel index. + const uint16_t getHWTraceMasterIdx() const; //!< Get the master used for HW event trace. + bool getHWTraceEn() const; //!< return true if HW trace is present and enabled. + +private: + bool m_bHWTraceEn; + ocsd_stm_cfg m_cfg; +}; + +inline STMConfig::STMConfig() +{ + m_cfg.reg_tcsr = 0; + m_cfg.reg_devid = 0xFF; // default to 256 masters. + m_cfg.reg_feat3r = 0x10000; // default to 65536 channels. + m_cfg.reg_feat1r = 0x0; + m_cfg.reg_hwev_mast = 0; // default hwtrace master = 0; + m_cfg.hw_event = HwEvent_Unknown_Disabled; // default to not present / disabled. + m_bHWTraceEn = false; +} + +inline STMConfig::STMConfig(const ocsd_stm_cfg *cfg_regs) +{ + m_cfg = *cfg_regs; + setHWTraceFeat(m_cfg.hw_event); +} + +inline STMConfig & STMConfig::operator=(const ocsd_stm_cfg *p_cfg) +{ + m_cfg = *p_cfg; + setHWTraceFeat(p_cfg->hw_event); + return *this; +} + +inline void STMConfig::setTraceID(const uint8_t traceID) +{ + uint32_t IDmask = 0x007F0000; + m_cfg.reg_tcsr &= ~IDmask; + m_cfg.reg_tcsr |= (((uint32_t)traceID) << 16) & IDmask; +} + +inline void STMConfig::setHWTraceFeat(const hw_event_feat_t hw_feat) +{ + m_cfg.hw_event = hw_feat; + m_bHWTraceEn = (m_cfg.hw_event == HwEvent_Enabled); + if(m_cfg.hw_event == HwEvent_UseRegisters) + m_bHWTraceEn = (((m_cfg.reg_feat1r & 0xC0000) == 0x80000) && ((m_cfg.reg_tcsr & 0x8) == 0x8)); +} + +inline const uint8_t STMConfig::getTraceID() const +{ + return (uint8_t)((m_cfg.reg_tcsr >> 16) & 0x7F); +} + +inline const uint8_t STMConfig::getMaxMasterIdx() const +{ + return (uint8_t)(m_cfg.reg_devid & 0xFF); +} + +inline const uint16_t STMConfig::getMaxChannelIdx() const +{ + return (uint16_t)(m_cfg.reg_feat3r - 1); +} + +inline const uint16_t STMConfig::getHWTraceMasterIdx() const +{ + return (uint16_t)(m_cfg.reg_hwev_mast & 0xFFFF); +} + +inline bool STMConfig::getHWTraceEn() const +{ + return m_bHWTraceEn; +} + + +/** @}*/ + +/** @}*/ + +#endif // ARM_TRC_CMP_CFG_STM_H_INCLUDED + +/* End of File trc_cmp_cfg_stm.h */ diff --git a/decoder/include/opencsd/stm/trc_dcd_mngr_stm.h b/decoder/include/opencsd/stm/trc_dcd_mngr_stm.h new file mode 100644 index 0000000..33632c6 --- /dev/null +++ b/decoder/include/opencsd/stm/trc_dcd_mngr_stm.h @@ -0,0 +1,57 @@ +/* + * \file trc_dcd_mngr_stm.h + * \brief OpenCSD : STM decoder manager / handler specialisation + * + * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef ARM_TRC_DCD_MNGR_STM_H_INCLUDED +#define ARM_TRC_DCD_MNGR_STM_H_INCLUDED + +#include "common/ocsd_dcd_mngr.h" +#include "trc_pkt_decode_stm.h" +#include "trc_pkt_proc_stm.h" +#include "trc_cmp_cfg_stm.h" +#include "trc_pkt_types_stm.h" + +class DecoderMngrStm : public DecodeMngrFullDcd< StmTrcPacket, + ocsd_stm_pkt_type, + STMConfig, + ocsd_stm_cfg, + TrcPktProcStm, + TrcPktDecodeStm> +{ +public: + DecoderMngrStm(const std::string &name) : DecodeMngrFullDcd(name,OCSD_PROTOCOL_STM) {}; + virtual ~DecoderMngrStm() {}; +}; + +#endif // ARM_TRC_DCD_MNGR_STM_H_INCLUDED + +/* End of File trc_dcd_mngr_stm.h */ diff --git a/decoder/include/opencsd/stm/trc_pkt_decode_stm.h b/decoder/include/opencsd/stm/trc_pkt_decode_stm.h new file mode 100644 index 0000000..bd29caf --- /dev/null +++ b/decoder/include/opencsd/stm/trc_pkt_decode_stm.h @@ -0,0 +1,104 @@ +/* + * \file trc_pkt_decode_stm.h + * \brief OpenCSD : STM packet decoder + * + * Convert the incoming indidvidual STM packets to + * + * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. + */ + + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef ARM_TRC_PKT_DECODE_STM_H_INCLUDED +#define ARM_TRC_PKT_DECODE_STM_H_INCLUDED + + +#include "common/trc_pkt_decode_base.h" +#include "opencsd/stm/trc_pkt_elem_stm.h" +#include "opencsd/stm/trc_cmp_cfg_stm.h" +#include "common/trc_gen_elem.h" + +class TrcPktDecodeStm : public TrcPktDecodeBase<StmTrcPacket, STMConfig> +{ +public: + TrcPktDecodeStm(); + TrcPktDecodeStm(int instIDNum); + virtual ~TrcPktDecodeStm(); + +protected: + /* implementation packet decoding interface */ + virtual ocsd_datapath_resp_t processPacket(); + virtual ocsd_datapath_resp_t onEOT(); + virtual ocsd_datapath_resp_t onReset(); + virtual ocsd_datapath_resp_t onFlush(); + virtual ocsd_err_t onProtocolConfig(); + virtual const uint8_t getCoreSightTraceID() { return m_CSID; }; + + /* local decode methods */ + +private: + void initDecoder(); + void resetDecoder(); + void initPayloadBuffer(); + bool isInit() { return (bool)((m_config != 0) && (m_payload_buffer != 0)); }; + ocsd_datapath_resp_t decodePacket(bool &bPktDone); //!< decode the current incoming packet + void clearSWTPerPcktInfo(); + void updatePayload(bool &bSendPacket); + + typedef enum { + NO_SYNC, //!< pre start trace - init state or after reset or overflow, loss of sync. + WAIT_SYNC, //!< waiting for sync packet. + DECODE_PKTS //!< processing input packet. + } processor_state_t; + + processor_state_t m_curr_state; + unsync_info_t m_unsync_info; + + ocsd_swt_info_t m_swt_packet_info; + + uint8_t *m_payload_buffer; //!< payload buffer - allocated for one or multiple packets according to config + int m_payload_size; //!< payload buffer total size in bytes. + int m_payload_used; //!< payload buffer used in bytes - current payload size. + bool m_payload_odd_nibble; //!< last used byte in payload contains a single 4 bit packet. + int m_num_pkt_correlation; //!< number of identical payload packets to buffer up before output. - fixed at 1 till later update + + uint8_t m_CSID; //!< Coresight trace ID for this decoder. + + bool m_decode_pass1; //!< flag to indicate 1st pass of packet decode. + + + +//** output element + OcsdTraceElement m_output_elem; //!< output packet +}; + +#endif // ARM_TRC_PKT_DECODE_STM_H_INCLUDED + +/* End of File trc_pkt_decode_stm.h */ diff --git a/decoder/include/opencsd/stm/trc_pkt_elem_stm.h b/decoder/include/opencsd/stm/trc_pkt_elem_stm.h new file mode 100644 index 0000000..738e452 --- /dev/null +++ b/decoder/include/opencsd/stm/trc_pkt_elem_stm.h @@ -0,0 +1,238 @@ +/*! + * \file trc_pkt_elem_stm.h + * \brief OpenCSD : STM packet class. + * + * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARM_TRC_PKT_ELEM_STM_H_INCLUDED +#define ARM_TRC_PKT_ELEM_STM_H_INCLUDED + +#include "trc_pkt_types_stm.h" +#include "common/trc_printable_elem.h" +#include "common/trc_pkt_elem_base.h" + +/*! + * @class StmTrcPacket + * @brief STM trace packet with packet printing functionality + * + * This class allows for the update and access of the current STM trace + * packet, implementing the STM protocol rules as appropriate. Maintains + * the intra packet state as well as updates on a per packet basis. + * + * Based on data structure ocsd_stm_pkt. + * + */ +class StmTrcPacket : public TrcPacketBase, public ocsd_stm_pkt, public trcPrintableElem +{ +public: + StmTrcPacket(); + ~StmTrcPacket() {}; + + StmTrcPacket &operator =(const ocsd_stm_pkt *p_pkt); + + virtual const void *c_pkt() const { return (const ocsd_stm_pkt *)this; }; + + void initStartState(); //!< Initialise packet state at start of decoder. + void initNextPacket(); //!< Initialise state for next packet. + + void setPacketType(const ocsd_stm_pkt_type type, const bool bMarker); + void updateErrType(const ocsd_stm_pkt_type err_type); + void setMaster(const uint8_t master); + void setChannel(const uint16_t channel, const bool b8Bit); + void setTS(const uint64_t ts_val, const uint8_t updatedBits); + void onVersionPkt(const ocsd_stm_ts_type type); + + void setD4Payload(const uint8_t value); + void setD8Payload(const uint8_t value); + void setD16Payload(const uint16_t value); + void setD32Payload(const uint32_t value); + void setD64Payload(const uint64_t value); + + const bool isMarkerPkt() const; + const bool isTSPkt() const; + + const ocsd_stm_pkt_type getPktType() const; + const ocsd_stm_pkt_type getPktErrType() const; + const uint8_t getMaster() const; + const uint16_t getChannel() const; + const ocsd_stm_ts_type getTSType() const; + const uint64_t getTSVal() const; + + const uint8_t getD4Val() const; + const uint8_t getD8Val() const; + const uint16_t getD16Val() const; + const uint32_t getD32Val() const; + const uint64_t getD64Val() const; + + const bool isBadPacket() const; + + // printing + virtual void toString(std::string &str) const; + virtual void toStringFmt(const uint32_t fmtFlags, std::string &str) const; + + +private: + void pktTypeName(const ocsd_stm_pkt_type pkt_type, std::string &name, std::string &desc) const; +}; + +inline void StmTrcPacket::setPacketType(const ocsd_stm_pkt_type type, const bool bMarker) +{ + this->type = type; + if(bMarker) + pkt_has_marker = 1; +} + +inline void StmTrcPacket::updateErrType(const ocsd_stm_pkt_type err_type) +{ + this->err_type = this->type; // original type is the err type; + this->type = err_type; // mark main type as an error. +} + +inline void StmTrcPacket::setMaster(const uint8_t master) +{ + this->master = master; + channel = 0; // M8 forces current channel to 0. +} + +inline void StmTrcPacket::setChannel(const uint16_t channel, const bool b8Bit) +{ + if(b8Bit) + this->channel = (this->channel & 0xFF00) | (channel & 0xFF); + else + this->channel = channel; +} + +inline void StmTrcPacket::onVersionPkt(const ocsd_stm_ts_type type) +{ + this->ts_type = type; + master = 0; + channel = 0; +} + +inline void StmTrcPacket::setD4Payload(const uint8_t value) +{ + payload.D8 = value & 0xF; +} + +inline void StmTrcPacket::setD8Payload(const uint8_t value) +{ + payload.D8 = value; +} + +inline void StmTrcPacket::setD16Payload(const uint16_t value) +{ + payload.D16 = value; +} + +inline void StmTrcPacket::setD32Payload(const uint32_t value) +{ + payload.D32 = value; +} + +inline void StmTrcPacket::setD64Payload(const uint64_t value) +{ + payload.D64 = value; +} + +inline const bool StmTrcPacket::isMarkerPkt() const +{ + return (pkt_has_marker != 0); +} + +inline const bool StmTrcPacket::isTSPkt() const +{ + return (pkt_has_ts != 0); +} + +inline const ocsd_stm_pkt_type StmTrcPacket::getPktType() const +{ + return type; +} + +inline const ocsd_stm_pkt_type StmTrcPacket::getPktErrType() const +{ + return err_type; +} + +inline const uint8_t StmTrcPacket::getMaster() const +{ + return master; +} + +inline const uint16_t StmTrcPacket::getChannel() const +{ + return channel; +} + +inline const ocsd_stm_ts_type StmTrcPacket::getTSType() const +{ + return ts_type; +} + +inline const uint64_t StmTrcPacket::getTSVal() const +{ + return timestamp; +} + +inline const uint8_t StmTrcPacket::getD4Val() const +{ + return payload.D8; +} + +inline const uint8_t StmTrcPacket::getD8Val() const +{ + return payload.D8; +} + +inline const uint16_t StmTrcPacket::getD16Val() const +{ + return payload.D16; +} + +inline const uint32_t StmTrcPacket::getD32Val() const +{ + return payload.D32; +} + +inline const uint64_t StmTrcPacket::getD64Val() const +{ + return payload.D64; +} + +inline const bool StmTrcPacket::isBadPacket() const +{ + return (bool)(type >= STM_PKT_BAD_SEQUENCE); +} + + +#endif // ARM_TRC_PKT_ELEM_STM_H_INCLUDED + +/* End of File trc_pkt_elem_stm.h */ diff --git a/decoder/include/opencsd/stm/trc_pkt_proc_stm.h b/decoder/include/opencsd/stm/trc_pkt_proc_stm.h new file mode 100644 index 0000000..bc4391b --- /dev/null +++ b/decoder/include/opencsd/stm/trc_pkt_proc_stm.h @@ -0,0 +1,290 @@ +/* + * \file trc_pkt_proc_stm.h + * \brief OpenCSD : STM packet processing + * + * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ARM_TRC_PKT_PROC_STM_H_INCLUDED +#define ARM_TRC_PKT_PROC_STM_H_INCLUDED + +#include <vector> + +#include "trc_pkt_types_stm.h" +#include "common/trc_pkt_proc_base.h" +#include "trc_pkt_elem_stm.h" +#include "trc_cmp_cfg_stm.h" + +/** @addtogroup ocsd_pkt_proc +@{*/ + +class TrcPktProcStm : public TrcPktProcBase<StmTrcPacket, ocsd_stm_pkt_type, STMConfig> +{ +public: + TrcPktProcStm(); + TrcPktProcStm(int instIDNum); + virtual ~TrcPktProcStm(); + +protected: + /* implementation packet processing interface */ + virtual ocsd_datapath_resp_t processData( const ocsd_trc_index_t index, + const uint32_t dataBlockSize, + const uint8_t *pDataBlock, + uint32_t *numBytesProcessed); + virtual ocsd_datapath_resp_t onEOT(); + virtual ocsd_datapath_resp_t onReset(); + virtual ocsd_datapath_resp_t onFlush(); + virtual ocsd_err_t onProtocolConfig(); + virtual const bool isBadPacket() const; + + + typedef enum _process_state { + WAIT_SYNC, + PROC_HDR, + PROC_DATA, + SEND_PKT + } process_state; + + process_state m_proc_state; + +private: + + void initObj(); + void initProcessorState(); + void initNextPacket(); + void waitForSync(const ocsd_trc_index_t blk_st_index); + + ocsd_datapath_resp_t outputPacket(); //!< send packet on output + void sendPacket(); //!< mark packet for send. + void setProcUnsynced(); //!< set processor state to unsynced + void throwBadSequenceError(const char *pszMessage = ""); + void throwReservedHdrError(const char *pszMessage = ""); + + // packet processing routines + // 1 nibble opcodes + void stmPktReserved(); + void stmPktNull(); + void stmPktM8(); + void stmPktMERR(); + void stmPktC8(); + void stmPktD4(); + void stmPktD8(); + void stmPktD16(); + void stmPktD32(); + void stmPktD64(); + void stmPktD4MTS(); + void stmPktD8MTS(); + void stmPktD16MTS(); + void stmPktD32MTS(); + void stmPktD64MTS(); + void stmPktFlagTS(); + void stmPktFExt(); + + // 2 nibble opcodes 0xFn + void stmPktReservedFn(); + void stmPktF0Ext(); + void stmPktGERR(); + void stmPktC16(); + void stmPktD4TS(); + void stmPktD8TS(); + void stmPktD16TS(); + void stmPktD32TS(); + void stmPktD64TS(); + void stmPktD4M(); + void stmPktD8M(); + void stmPktD16M(); + void stmPktD32M(); + void stmPktD64M(); + void stmPktFlag(); + void stmPktASync(); + + // 3 nibble opcodes 0xF0n + void stmPktReservedF0n(); + void stmPktVersion(); + void stmPktNullTS(); + void stmPktTrigger(); + void stmPktTriggerTS(); + void stmPktFreq(); + + void stmExtractTS(); // extract a TS in packets that require it. + void stmExtractVal8(uint8_t nibbles_to_val); + void stmExtractVal16(uint8_t nibbles_to_val); + void stmExtractVal32(uint8_t nibbles_to_val); + void stmExtractVal64(uint8_t nibbles_to_val); + + uint64_t bin_to_gray(uint64_t bin_value); + uint64_t gray_to_bin(uint64_t gray_value); + void pktNeedsTS(); // init the TS extraction routines + + // data processing op function tables + void buildOpTables(); + + typedef void (TrcPktProcStm::*PPKTFN)(void); + PPKTFN m_pCurrPktFn; // current active processing function. + + PPKTFN m_1N_ops[0x10]; + PPKTFN m_2N_ops[0x10]; + PPKTFN m_3N_ops[0x10]; + + // read a nibble from the input data - may read a byte and set spare or return spare. + // handles setting up packet data block and end of input + bool readNibble(); + + const bool dataToProcess() const; //!< true if data to process, or packet to send + + void savePacketByte(const uint8_t val); //!< save data to packet buffer if we need it for monitor. + + // packet data + StmTrcPacket m_curr_packet; //!< current packet. + bool m_bNeedsTS; //!< packet requires a TS + bool m_bIsMarker; + + + bool m_bStreamSync; //!< packet stream is synced + + // input data handling + uint8_t m_num_nibbles; //!< number of nibbles in the current packet + uint8_t m_nibble; //!< current nibble being processed. + uint8_t m_nibble_2nd; //!< 2nd unused nibble from a processed byte. + bool m_nibble_2nd_valid; //!< 2nd nibble is valid; + uint8_t m_num_data_nibbles; //!< number of nibbles needed to acheive payload. + + const uint8_t *m_p_data_in; //!< pointer to input data. + uint32_t m_data_in_size; //!< amount of data in. + uint32_t m_data_in_used; //!< amount of data processed. + ocsd_trc_index_t m_packet_index; //!< byte index for start of current packet + + std::vector<uint8_t> m_packet_data; //!< current packet data (bytes) - only saved if needed to output to monitor. + bool m_bWaitSyncSaveSuppressed; //!< don't save byte at a time when waitsync + + // payload data + uint8_t m_val8; //!< 8 bit payload. + uint16_t m_val16; //!< 16 bit payload + uint32_t m_val32; //!< 32 bit payload + uint64_t m_val64; //!< 64 bit payload + + // timestamp handling + uint8_t m_req_ts_nibbles; + uint8_t m_curr_ts_nibbles; + uint64_t m_ts_update_value; + bool m_ts_req_set; + + + // sync handling - need to spot sync mid other packet in case of wrap / discontinuity + uint8_t m_num_F_nibbles; //!< count consecutive F nibbles. + bool m_sync_start; //!< possible start of sync + bool m_is_sync; //!< true if found sync at current nibble + ocsd_trc_index_t m_sync_index; //!< index of start of possible sync packet + + void checkSyncNibble(); //!< check current nibble as part of sync. + void clearSyncCount(); //!< valid packet, so clear sync counters (i.e. a trailing ffff is not part of sync). + + class monAttachNotify : public IComponentAttachNotifier + { + public: + monAttachNotify() { m_bInUse = false; }; + virtual ~monAttachNotify() {}; + virtual void attachNotify(const int num_attached) { m_bInUse = (num_attached > 0); }; + + const bool usingMonitor() const { return m_bInUse; }; + + private: + bool m_bInUse; + } mon_in_use; +}; + +inline const bool TrcPktProcStm::dataToProcess() const +{ + // data to process if + // 1) not processed all the input bytes + // 2) there is still a nibble available from the last byte. + // 3) bytes processed, but there is a full packet to send + return (m_data_in_used < m_data_in_size) || m_nibble_2nd_valid || (m_proc_state == SEND_PKT); +} + + +inline void TrcPktProcStm::checkSyncNibble() +{ + if(m_nibble != 0xF) + { + if(!m_sync_start) + return; + + if((m_nibble == 0) && (m_num_F_nibbles >= 21)) + { + m_is_sync = true; //this nibble marks a sync sequence + m_num_F_nibbles = 21; // set the F nibble count - lose any extra as unsynced data. + } + else + { + clearSyncCount(); // clear all sync counters + } + return; + } + + m_num_F_nibbles++; + if(!m_sync_start) + { + m_sync_start = true; + m_sync_index = m_packet_index + ((m_num_nibbles - 1) / 2); + } +} + +inline void TrcPktProcStm::clearSyncCount() +{ + m_num_F_nibbles = 0; + m_sync_start = false; + m_is_sync = false; +} + +inline void TrcPktProcStm::sendPacket() +{ + m_proc_state = SEND_PKT; +} + +inline void TrcPktProcStm::setProcUnsynced() +{ + m_proc_state = WAIT_SYNC; + m_bStreamSync = false; +} + + +inline void TrcPktProcStm::savePacketByte(const uint8_t val) +{ + // save packet data if using monitor and synchronised. + if(mon_in_use.usingMonitor() && !m_bWaitSyncSaveSuppressed) + m_packet_data.push_back(val); +} + +/** @}*/ + +#endif // ARM_TRC_PKT_PROC_STM_H_INCLUDED + +/* End of File trc_pkt_proc_stm.h */ diff --git a/decoder/include/opencsd/stm/trc_pkt_types_stm.h b/decoder/include/opencsd/stm/trc_pkt_types_stm.h new file mode 100644 index 0000000..fd44cea --- /dev/null +++ b/decoder/include/opencsd/stm/trc_pkt_types_stm.h @@ -0,0 +1,158 @@ +/* + * \file trc_pkt_types_stm.h + * \brief OpenCSD : STM decoder + * + * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef ARM_TRC_PKT_TYPES_STM_H_INCLUDED +#define ARM_TRC_PKT_TYPES_STM_H_INCLUDED + +#include "opencsd/trc_pkt_types.h" + +/** @addtogroup trc_pkts +@{*/ + +/** @name STM Packet Types +@{*/ + +/** STM protocol packet types. + Contains both protocol packet types and markers for unsynced processor + state and bad packet sequences. +*/ +typedef enum _ocsd_stm_pkt_type +{ +/* markers for unknown packets / state*/ + STM_PKT_NOTSYNC, /**< Not synchronised */ + STM_PKT_INCOMPLETE_EOT, /**< Incomplete packet flushed at end of trace. */ + STM_PKT_NO_ERR_TYPE, /**< No error in error packet marker. */ + +/* markers for valid packets*/ + STM_PKT_ASYNC, /**< Alignment synchronisation packet */ + STM_PKT_VERSION, /**< Version packet */ + STM_PKT_FREQ, /**< Frequency packet */ + STM_PKT_NULL, /**< Null packet */ + STM_PKT_TRIG, /**< Trigger event packet. */ + + STM_PKT_GERR, /**< Global error packet - protocol error but unknown which master had error */ + STM_PKT_MERR, /**< Master error packet - current master detected an error (e.g. dropped trace) */ + + STM_PKT_M8, /**< Set current master */ + STM_PKT_C8, /**< Set lower 8 bits of current channel */ + STM_PKT_C16, /**< Set current channel */ + + STM_PKT_FLAG, /**< Flag packet */ + + STM_PKT_D4, /**< 4 bit data payload packet */ + STM_PKT_D8, /**< 8 bit data payload packet */ + STM_PKT_D16, /**< 16 bit data payload packet */ + STM_PKT_D32, /**< 32 bit data payload packet */ + STM_PKT_D64, /**< 64 bit data payload packet */ + +/* packet errors.*/ + STM_PKT_BAD_SEQUENCE, /**< Incorrect protocol sequence */ + STM_PKT_RESERVED, /**< Reserved packet header / not supported by CS-STM */ + +} ocsd_stm_pkt_type; + +/** STM timestamp encoding type. + Extracted from STM version packet. + CS-STM supports Natural binary and grey encodings. +*/ +typedef enum _ocsd_stm_ts_type +{ + STM_TS_UNKNOWN, /**< TS encoding unknown at present. */ + STM_TS_NATBINARY, /**< TS encoding natural binary */ + STM_TS_GREY /**< TS encoding grey coded. */ +} ocsd_stm_ts_type; + +/** STM trace packet + + Structure containing the packet data for a single STM packet, plus + data persisting between packets (master, channel, last timestamp). +*/ +typedef struct _ocsd_stm_pkt +{ + ocsd_stm_pkt_type type; /**< STM packet type */ + + uint8_t master; /**< current master */ + uint16_t channel; /**< current channel */ + + uint64_t timestamp; /**< latest timestamp value -> as binary - packet processor does grey decoding */ + uint8_t pkt_ts_bits; /**< timestamp bits updated this packet */ + uint8_t pkt_has_ts; /**< current packet has associated timestamp (ts bits can be 0 if same value as last time) */ + + ocsd_stm_ts_type ts_type; /**< timestamp encoding type */ + + uint8_t pkt_has_marker; /**< flag to indicate current packet has marker */ + + union { + uint8_t D8; /**< payload for D8 or D4 data packet, or parameter value for other packets with 8 bit value [VERSION, TRIG, xERR] */ + uint16_t D16; /**< payload for D16 data packet, or reserved opcode in bad packet header (1-3 nibbles) */ + uint32_t D32; /**< payload for D32 data packet, or parameter value for other packets with 32 bit value [FREQ] */ + uint64_t D64; /**< payload for D64 data packet */ + } payload; + + ocsd_stm_pkt_type err_type; /**< Initial type of packet if type indicates bad sequence. */ + +} ocsd_stm_pkt; + +/** HW Event trace feature + Defines if the STM supports or has enabled the HW event trace feature. + This may not always be able to be determined by the registers, or the feature + values can override if HW event trace is to be ignored. +*/ +typedef enum _hw_event_feat { + HwEvent_Unknown_Disabled, /*!< status of HW event features not known - assume not present or disabled */ + HwEvent_Enabled, /*!< HW event present and enabled - ignore Feat regs, assume hwev_mast value valid */ + HwEvent_UseRegisters /*!< Feature Register values and enable bits used to determine HW event trace status */ +} hw_event_feat_t; + + +/** STM hardware configuration. + Contains hardware register values at time of trace capture and HW event feature + field to enable and control decode of STM trace stream. +*/ +typedef struct _ocsd_stm_cfg +{ + uint32_t reg_tcsr; /**< Contains CoreSight trace ID, HWTEN */ + uint32_t reg_feat3r; /**< defines number of masters */ + uint32_t reg_devid; /**< defines number of channels per master */ + + uint32_t reg_feat1r; /**< defines HW trace features */ + uint32_t reg_hwev_mast; /**< master ID for HW event trace */ + hw_event_feat_t hw_event; /**< status of HW event trace */ +} ocsd_stm_cfg; + +/** @}*/ +/** @}*/ + +#endif // ARM_TRC_PKT_TYPES_STM_H_INCLUDED + +/* End of File trc_pkt_types_stm.h */ |