Loading...
Searching...
No Matches
trc_pkt_decode_base.h
Go to the documentation of this file.
/*
* 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_BASE_H_INCLUDED
#define ARM_TRC_PKT_DECODE_BASE_H_INCLUDED
#include "trc_component.h"
#include "comp_attach_pt_t.h"
#include "interfaces/trc_pkt_in_i.h"
#include "interfaces/trc_gen_elem_in_i.h"
#include "interfaces/trc_tgt_mem_access_i.h"
#include "interfaces/trc_instr_decode_i.h"
class TrcPktDecodeI : public TraceComponent
{
public:
TrcPktDecodeI(const char *component_name);
TrcPktDecodeI(const char *component_name, int instIDNum);
virtual ~TrcPktDecodeI() {};
componentAttachPt<ITrcGenElemIn> *getTraceElemOutAttachPt() { return &m_trace_elem_out; };
componentAttachPt<ITargetMemAccess> *getMemoryAccessAttachPt() { return &m_mem_access; };
componentAttachPt<IInstrDecode> *getInstrDecodeAttachPt() { return &m_instr_decode; };
void setUsesMemAccess(bool bUsesMemaccess) { m_uses_memaccess = bUsesMemaccess; };
const bool getUsesMemAccess() const { return m_uses_memaccess; };
void setUsesIDecode(bool bUsesIDecode) { m_uses_idecode = bUsesIDecode; };
const bool getUsesIDecode() const { return m_uses_idecode; };
protected:
/* implementation packet decoding interface */
virtual ocsd_datapath_resp_t processPacket() = 0;
virtual ocsd_datapath_resp_t onEOT() = 0;
virtual ocsd_datapath_resp_t onReset() = 0;
virtual ocsd_datapath_resp_t onFlush() = 0;
virtual ocsd_err_t onProtocolConfig() = 0;
virtual const uint8_t getCoreSightTraceID() = 0;
/* init handling */
const bool checkInit();
/* Called on first init confirmation */
virtual void onFirstInitOK() {};
/* data output */
ocsd_datapath_resp_t outputTraceElement(const OcsdTraceElement &elem); // use current index
ocsd_datapath_resp_t outputTraceElementIdx(ocsd_trc_index_t idx, const OcsdTraceElement &elem); // use supplied index (where decoder caches elements)
/* target access */
ocsd_err_t accessMemory(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, uint32_t *num_bytes, uint8_t *p_buffer);
ocsd_err_t invalidateMemAccCache();
/* instruction decode */
ocsd_err_t instrDecode(ocsd_instr_info *instr_info);
componentAttachPt<ITrcGenElemIn> m_trace_elem_out;
componentAttachPt<ITargetMemAccess> m_mem_access;
componentAttachPt<IInstrDecode> m_instr_decode;
ocsd_trc_index_t m_index_curr_pkt;
bool m_decode_init_ok;
bool m_config_init_ok;
std::string init_err_msg;
bool m_uses_memaccess;
bool m_uses_idecode;
};
inline TrcPktDecodeI::TrcPktDecodeI(const char *component_name) :
TraceComponent(component_name),
m_index_curr_pkt(0),
m_decode_init_ok(false),
m_config_init_ok(false),
m_uses_memaccess(true),
m_uses_idecode(true)
{
}
inline TrcPktDecodeI::TrcPktDecodeI(const char *component_name, int instIDNum) :
TraceComponent(component_name, instIDNum),
m_index_curr_pkt(0),
m_decode_init_ok(false),
m_config_init_ok(false),
m_uses_memaccess(true),
m_uses_idecode(true)
{
}
inline const bool TrcPktDecodeI::checkInit()
{
if(!m_decode_init_ok)
{
if(!m_config_init_ok)
init_err_msg = "No decoder configuration information";
else if(!m_trace_elem_out.hasAttachedAndEnabled())
init_err_msg = "No element output interface attached and enabled";
else if(m_uses_memaccess && !m_mem_access.hasAttachedAndEnabled())
init_err_msg = "No memory access interface attached and enabled";
else if(m_uses_idecode && !m_instr_decode.hasAttachedAndEnabled())
init_err_msg = "No instruction decoder interface attached and enabled";
else
m_decode_init_ok = true;
if (m_decode_init_ok)
onFirstInitOK();
}
return m_decode_init_ok;
}
inline ocsd_datapath_resp_t TrcPktDecodeI::outputTraceElement(const OcsdTraceElement &elem)
{
return m_trace_elem_out.first()->TraceElemIn(m_index_curr_pkt,getCoreSightTraceID(), elem);
}
inline ocsd_datapath_resp_t TrcPktDecodeI::outputTraceElementIdx(ocsd_trc_index_t idx, const OcsdTraceElement &elem)
{
return m_trace_elem_out.first()->TraceElemIn(idx, getCoreSightTraceID(), elem);
}
inline ocsd_err_t TrcPktDecodeI::instrDecode(ocsd_instr_info *instr_info)
{
if(m_uses_idecode)
return m_instr_decode.first()->DecodeInstruction(instr_info);
return OCSD_ERR_DCD_INTERFACE_UNUSED;
}
inline ocsd_err_t TrcPktDecodeI::accessMemory(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, uint32_t *num_bytes, uint8_t *p_buffer)
{
if(m_uses_memaccess)
return m_mem_access.first()->ReadTargetMemory(address,getCoreSightTraceID(),mem_space, num_bytes,p_buffer);
return OCSD_ERR_DCD_INTERFACE_UNUSED;
}
inline ocsd_err_t TrcPktDecodeI::invalidateMemAccCache()
{
if (!m_uses_memaccess)
return OCSD_ERR_DCD_INTERFACE_UNUSED;
m_mem_access.first()->InvalidateMemAccCache(getCoreSightTraceID());
return OCSD_OK;
}
/**********************************************************************/
template <class P, class Pc>
class TrcPktDecodeBase : public TrcPktDecodeI, public IPktDataIn<P>
{
public:
TrcPktDecodeBase(const char *component_name);
TrcPktDecodeBase(const char *component_name, int instIDNum);
virtual ~TrcPktDecodeBase();
virtual ocsd_datapath_resp_t PacketDataIn( const ocsd_datapath_op_t op,
const ocsd_trc_index_t index_sop,
const P *p_packet_in);
/* protocol configuration */
ocsd_err_t setProtocolConfig(const Pc *config);
const Pc * getProtocolConfig() const { return m_config; };
protected:
void ClearConfigObj();
/* the protocol configuration */
Pc * m_config;
/* the current input packet */
const P * m_curr_packet_in;
};
template <class P, class Pc> TrcPktDecodeBase<P, Pc>::TrcPktDecodeBase(const char *component_name) :
TrcPktDecodeI(component_name),
m_config(0)
{
}
template <class P, class Pc> TrcPktDecodeBase<P, Pc>::TrcPktDecodeBase(const char *component_name, int instIDNum) :
TrcPktDecodeI(component_name,instIDNum),
m_config(0)
{
}
template <class P, class Pc> TrcPktDecodeBase<P, Pc>::~TrcPktDecodeBase()
{
ClearConfigObj();
}
template <class P, class Pc> ocsd_datapath_resp_t TrcPktDecodeBase<P, Pc>::PacketDataIn( const ocsd_datapath_op_t op,
const ocsd_trc_index_t index_sop,
const P *p_packet_in)
{
ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
if(!checkInit())
{
LogError(ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_NOT_INIT,init_err_msg));
return OCSD_RESP_FATAL_NOT_INIT;
}
switch(op)
{
case OCSD_OP_DATA:
if(p_packet_in == 0)
{
LogError(ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_INVALID_PARAM_VAL));
resp = OCSD_RESP_FATAL_INVALID_PARAM;
}
else
{
m_curr_packet_in = p_packet_in;
m_index_curr_pkt = index_sop;
resp = processPacket();
}
break;
case OCSD_OP_EOT:
resp = onEOT();
break;
case OCSD_OP_FLUSH:
resp = onFlush();
break;
case OCSD_OP_RESET:
resp = onReset();
break;
default:
LogError(ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_INVALID_PARAM_VAL));
resp = OCSD_RESP_FATAL_INVALID_OP;
break;
}
return resp;
}
/* protocol configuration */
template <class P, class Pc> ocsd_err_t TrcPktDecodeBase<P, Pc>::setProtocolConfig(const Pc *config)
{
ocsd_err_t err = OCSD_ERR_INVALID_PARAM_VAL;
if(config != 0)
{
ClearConfigObj(); // remove any current config
m_config = new (std::nothrow) Pc(*config); // make a copy of the config - don't rely on the object passed in being valid outside the context of the call.
if(m_config != 0)
{
err = onProtocolConfig();
if(err == OCSD_OK)
m_config_init_ok = true;
}
else
err = OCSD_ERR_MEM;
}
return err;
}
template <class P, class Pc> void TrcPktDecodeBase<P, Pc>::ClearConfigObj()
{
if(m_config)
{
delete m_config;
m_config = 0;
}
}
#endif // ARM_TRC_PKT_DECODE_BASE_H_INCLUDED
/* End of File trc_pkt_decode_base.h */
IPktDataIn::IPktDataIn
IPktDataIn()
Definition trc_pkt_in_i.h:57
OcsdTraceElement
Generic trace element class.
Definition trc_gen_elem.h:50
TraceComponent::TraceComponent
TraceComponent(const std::string &name)
TraceComponent::LogError
void LogError(const ocsdError &Error)
TrcPktDecodeBase::m_config
Pc * m_config
Definition trc_pkt_decode_base.h:214
TrcPktDecodeBase::m_curr_packet_in
const P * m_curr_packet_in
Definition trc_pkt_decode_base.h:216
TrcPktDecodeBase::getProtocolConfig
const Pc * getProtocolConfig() const
Definition trc_pkt_decode_base.h:208
TrcPktDecodeI::m_mem_access
componentAttachPt< ITargetMemAccess > m_mem_access
Definition trc_pkt_decode_base.h:105
TrcPktDecodeI::onFirstInitOK
virtual void onFirstInitOK()
Definition trc_pkt_decode_base.h:91
TrcPktDecodeI::processPacket
virtual ocsd_datapath_resp_t processPacket()=0
TrcPktDecodeI::m_trace_elem_out
componentAttachPt< ITrcGenElemIn > m_trace_elem_out
Definition trc_pkt_decode_base.h:104
TrcPktDecodeI::getMemoryAccessAttachPt
componentAttachPt< ITargetMemAccess > * getMemoryAccessAttachPt()
Definition trc_pkt_decode_base.h:69
TrcPktDecodeI::m_instr_decode
componentAttachPt< IInstrDecode > m_instr_decode
Definition trc_pkt_decode_base.h:106
TrcPktDecodeI::getUsesIDecode
const bool getUsesIDecode() const
Definition trc_pkt_decode_base.h:76
TrcPktDecodeI::m_index_curr_pkt
ocsd_trc_index_t m_index_curr_pkt
Definition trc_pkt_decode_base.h:108
TrcPktDecodeI::m_uses_memaccess
bool m_uses_memaccess
Definition trc_pkt_decode_base.h:115
TrcPktDecodeI::setUsesMemAccess
void setUsesMemAccess(bool bUsesMemaccess)
Definition trc_pkt_decode_base.h:72
TrcPktDecodeI::getUsesMemAccess
const bool getUsesMemAccess() const
Definition trc_pkt_decode_base.h:73
TrcPktDecodeI::~TrcPktDecodeI
virtual ~TrcPktDecodeI()
Definition trc_pkt_decode_base.h:66
TrcPktDecodeI::setUsesIDecode
void setUsesIDecode(bool bUsesIDecode)
Definition trc_pkt_decode_base.h:75
TrcPktDecodeI::getTraceElemOutAttachPt
componentAttachPt< ITrcGenElemIn > * getTraceElemOutAttachPt()
Definition trc_pkt_decode_base.h:68
TrcPktDecodeI::onProtocolConfig
virtual ocsd_err_t onProtocolConfig()=0
TrcPktDecodeI::init_err_msg
std::string init_err_msg
error message for init error
Definition trc_pkt_decode_base.h:113
TrcPktDecodeI::onFlush
virtual ocsd_datapath_resp_t onFlush()=0
TrcPktDecodeI::m_uses_idecode
bool m_uses_idecode
Definition trc_pkt_decode_base.h:116
TrcPktDecodeI::getCoreSightTraceID
virtual const uint8_t getCoreSightTraceID()=0
TrcPktDecodeI::onReset
virtual ocsd_datapath_resp_t onReset()=0
TrcPktDecodeI::m_decode_init_ok
bool m_decode_init_ok
set true if all attachments in place for decode. (remove checks in main throughput paths)
Definition trc_pkt_decode_base.h:110
TrcPktDecodeI::onEOT
virtual ocsd_datapath_resp_t onEOT()=0
TrcPktDecodeI::getInstrDecodeAttachPt
componentAttachPt< IInstrDecode > * getInstrDecodeAttachPt()
Definition trc_pkt_decode_base.h:70
TrcPktDecodeI::m_config_init_ok
bool m_config_init_ok
set true if config set.
Definition trc_pkt_decode_base.h:111
componentAttachPt
Single component interface pointer attachment point.
Definition comp_attach_pt_t.h:61
ocsdError
Definition ocsd_error.h:58
comp_attach_pt_t.h
OpenCSD : Component attachment point interface class.
ocsd_trc_index_t
uint32_t ocsd_trc_index_t
Definition ocsd_if_types.h:59
ocsd_datapath_resp_t
enum _ocsd_datapath_resp_t ocsd_datapath_resp_t
ocsd_mem_space_acc_t
enum _ocsd_mem_space_acc_t ocsd_mem_space_acc_t
ocsd_datapath_op_t
enum _ocsd_datapath_op_t ocsd_datapath_op_t
ocsd_instr_info
struct _ocsd_instr_info ocsd_instr_info
ocsd_err_t
enum _ocsd_err_t ocsd_err_t
ocsd_vaddr_t
uint64_t ocsd_vaddr_t
Definition ocsd_if_types.h:306
OCSD_ERR_DCD_INTERFACE_UNUSED
@ OCSD_ERR_DCD_INTERFACE_UNUSED
Definition ocsd_if_types.h:134
OCSD_OK
@ OCSD_OK
Definition ocsd_if_types.h:80
OCSD_ERR_INVALID_PARAM_VAL
@ OCSD_ERR_INVALID_PARAM_VAL
Definition ocsd_if_types.h:86
OCSD_ERR_NOT_INIT
@ OCSD_ERR_NOT_INIT
Definition ocsd_if_types.h:83
OCSD_ERR_MEM
@ OCSD_ERR_MEM
Definition ocsd_if_types.h:82
OCSD_RESP_CONT
@ OCSD_RESP_CONT
Definition ocsd_if_types.h:187
OCSD_RESP_FATAL_NOT_INIT
@ OCSD_RESP_FATAL_NOT_INIT
Definition ocsd_if_types.h:193
OCSD_RESP_FATAL_INVALID_PARAM
@ OCSD_RESP_FATAL_INVALID_PARAM
Definition ocsd_if_types.h:195
OCSD_RESP_FATAL_INVALID_OP
@ OCSD_RESP_FATAL_INVALID_OP
Definition ocsd_if_types.h:194
OCSD_OP_EOT
@ OCSD_OP_EOT
Definition ocsd_if_types.h:178
OCSD_OP_FLUSH
@ OCSD_OP_FLUSH
Definition ocsd_if_types.h:179
OCSD_OP_DATA
@ OCSD_OP_DATA
Definition ocsd_if_types.h:177
OCSD_OP_RESET
@ OCSD_OP_RESET
Definition ocsd_if_types.h:180
OCSD_ERR_SEV_ERROR
@ OCSD_ERR_SEV_ERROR
Definition ocsd_if_types.h:164
TrcPktDecodeI::accessMemory
ocsd_err_t accessMemory(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, uint32_t *num_bytes, uint8_t *p_buffer)
Definition trc_pkt_decode_base.h:177
TrcPktDecodeBase::TrcPktDecodeBase
TrcPktDecodeBase(const char *component_name)
Definition trc_pkt_decode_base.h:221
TrcPktDecodeBase::PacketDataIn
virtual ocsd_datapath_resp_t PacketDataIn(const ocsd_datapath_op_t op, const ocsd_trc_index_t index_sop, const P *p_packet_in)
Definition trc_pkt_decode_base.h:238
TrcPktDecodeI::TrcPktDecodeI
TrcPktDecodeI(const char *component_name)
Definition trc_pkt_decode_base.h:120
TrcPktDecodeI::outputTraceElement
ocsd_datapath_resp_t outputTraceElement(const OcsdTraceElement &elem)
Definition trc_pkt_decode_base.h:160
TrcPktDecodeBase::ClearConfigObj
void ClearConfigObj()
Definition trc_pkt_decode_base.h:305
TrcPktDecodeI::instrDecode
ocsd_err_t instrDecode(ocsd_instr_info *instr_info)
Definition trc_pkt_decode_base.h:170
TrcPktDecodeBase::setProtocolConfig
ocsd_err_t setProtocolConfig(const Pc *config)
Definition trc_pkt_decode_base.h:286
TrcPktDecodeI::outputTraceElementIdx
ocsd_datapath_resp_t outputTraceElementIdx(ocsd_trc_index_t idx, const OcsdTraceElement &elem)
Definition trc_pkt_decode_base.h:165
TrcPktDecodeI::invalidateMemAccCache
ocsd_err_t invalidateMemAccCache()
Definition trc_pkt_decode_base.h:184
TrcPktDecodeBase::~TrcPktDecodeBase
virtual ~TrcPktDecodeBase()
Definition trc_pkt_decode_base.h:233
TrcPktDecodeI::checkInit
const bool checkInit()
Definition trc_pkt_decode_base.h:140
trc_component.h
OpenCSD : Base trace decode component.
trc_gen_elem_in_i.h
trc_instr_decode_i.h
trc_pkt_in_i.h
trc_tgt_mem_access_i.h