tlm_to_gem5.hh revision 13846
113821Sgabeblack@google.com/* 213821Sgabeblack@google.com * Copyright 2019 Google, Inc. 313821Sgabeblack@google.com * 413821Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 513821Sgabeblack@google.com * modification, are permitted provided that the following conditions are 613821Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 713821Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 813821Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 913821Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1013821Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1113821Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1213821Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1313821Sgabeblack@google.com * this software without specific prior written permission. 1413821Sgabeblack@google.com * 1513821Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1613821Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1713821Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1813821Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1913821Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2013821Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2113821Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2213821Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2313821Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2413821Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2513821Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2613821Sgabeblack@google.com * 2713821Sgabeblack@google.com * Copyright (c) 2016, Dresden University of Technology (TU Dresden) 2813821Sgabeblack@google.com * All rights reserved. 2913821Sgabeblack@google.com * 3013821Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 3113821Sgabeblack@google.com * modification, are permitted provided that the following conditions are 3213821Sgabeblack@google.com * met: 3313821Sgabeblack@google.com * 3413821Sgabeblack@google.com * 1. Redistributions of source code must retain the above copyright notice, 3513821Sgabeblack@google.com * this list of conditions and the following disclaimer. 3613821Sgabeblack@google.com * 3713821Sgabeblack@google.com * 2. Redistributions in binary form must reproduce the above copyright 3813821Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 3913821Sgabeblack@google.com * documentation and/or other materials provided with the distribution. 4013821Sgabeblack@google.com * 4113821Sgabeblack@google.com * 3. Neither the name of the copyright holder nor the names of its 4213821Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 4313821Sgabeblack@google.com * this software without specific prior written permission. 4413821Sgabeblack@google.com * 4513821Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4613821Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 4713821Sgabeblack@google.com * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4813821Sgabeblack@google.com * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 4913821Sgabeblack@google.com * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 5013821Sgabeblack@google.com * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 5113821Sgabeblack@google.com * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 5213821Sgabeblack@google.com * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 5313821Sgabeblack@google.com * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 5413821Sgabeblack@google.com * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 5513821Sgabeblack@google.com * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5613821Sgabeblack@google.com * 5713821Sgabeblack@google.com * Authors: Gabe Black 5813821Sgabeblack@google.com * Christian Menard 5913821Sgabeblack@google.com */ 6013821Sgabeblack@google.com 6113821Sgabeblack@google.com#ifndef __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 6213821Sgabeblack@google.com#define __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 6313821Sgabeblack@google.com 6413821Sgabeblack@google.com#include "mem/port.hh" 6513823Sgabeblack@google.com#include "params/TlmToGem5BridgeBase.hh" 6613821Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 6713821Sgabeblack@google.com#include "systemc/ext/core/sc_module_name.hh" 6813821Sgabeblack@google.com#include "systemc/ext/tlm_core/2/generic_payload/gp.hh" 6913821Sgabeblack@google.com#include "systemc/ext/tlm_utils/peq_with_cb_and_phase.h" 7013821Sgabeblack@google.com#include "systemc/ext/tlm_utils/simple_target_socket.h" 7113821Sgabeblack@google.com#include "systemc/tlm_bridge/sc_ext.hh" 7213821Sgabeblack@google.com#include "systemc/tlm_port_wrapper.hh" 7313821Sgabeblack@google.com 7413821Sgabeblack@google.comnamespace sc_gem5 7513821Sgabeblack@google.com{ 7613821Sgabeblack@google.com 7713823Sgabeblack@google.comclass TlmToGem5BridgeBase : public sc_core::sc_module 7813823Sgabeblack@google.com{ 7913823Sgabeblack@google.com protected: 8013823Sgabeblack@google.com using sc_core::sc_module::sc_module; 8113823Sgabeblack@google.com}; 8213823Sgabeblack@google.com 8313823Sgabeblack@google.comtemplate <unsigned int BITWIDTH> 8413823Sgabeblack@google.comclass TlmToGem5Bridge : public TlmToGem5BridgeBase 8513821Sgabeblack@google.com{ 8613821Sgabeblack@google.com private: 8713821Sgabeblack@google.com struct TlmSenderState : public Packet::SenderState 8813821Sgabeblack@google.com { 8913821Sgabeblack@google.com tlm::tlm_generic_payload &trans; 9013821Sgabeblack@google.com TlmSenderState(tlm::tlm_generic_payload &trans) : trans(trans) {} 9113821Sgabeblack@google.com }; 9213821Sgabeblack@google.com 9313821Sgabeblack@google.com class BridgeMasterPort : public MasterPort 9413821Sgabeblack@google.com { 9513821Sgabeblack@google.com protected: 9613823Sgabeblack@google.com TlmToGem5Bridge<BITWIDTH> &bridge; 9713821Sgabeblack@google.com 9813821Sgabeblack@google.com bool 9913821Sgabeblack@google.com recvTimingResp(PacketPtr pkt) override 10013821Sgabeblack@google.com { 10113821Sgabeblack@google.com return bridge.recvTimingResp(pkt); 10213821Sgabeblack@google.com } 10313821Sgabeblack@google.com void recvReqRetry() override { bridge.recvReqRetry(); } 10413821Sgabeblack@google.com void recvRangeChange() override { bridge.recvRangeChange(); } 10513821Sgabeblack@google.com 10613821Sgabeblack@google.com public: 10713823Sgabeblack@google.com BridgeMasterPort(const std::string &name_, 10813823Sgabeblack@google.com TlmToGem5Bridge<BITWIDTH> &bridge_) : 10913821Sgabeblack@google.com MasterPort(name_, nullptr), bridge(bridge_) 11013821Sgabeblack@google.com {} 11113821Sgabeblack@google.com }; 11213821Sgabeblack@google.com 11313823Sgabeblack@google.com tlm_utils::peq_with_cb_and_phase<TlmToGem5Bridge<BITWIDTH>> peq; 11413821Sgabeblack@google.com 11513821Sgabeblack@google.com bool waitForRetry; 11613821Sgabeblack@google.com tlm::tlm_generic_payload *pendingRequest; 11713821Sgabeblack@google.com PacketPtr pendingPacket; 11813821Sgabeblack@google.com 11913821Sgabeblack@google.com bool needToSendRetry; 12013821Sgabeblack@google.com 12113821Sgabeblack@google.com bool responseInProgress; 12213821Sgabeblack@google.com 12313821Sgabeblack@google.com BridgeMasterPort bmp; 12413823Sgabeblack@google.com tlm_utils::simple_target_socket< 12513823Sgabeblack@google.com TlmToGem5Bridge<BITWIDTH>, BITWIDTH> socket; 12613823Sgabeblack@google.com sc_gem5::TlmTargetWrapper<BITWIDTH> wrapper; 12713821Sgabeblack@google.com 12813821Sgabeblack@google.com System *system; 12913821Sgabeblack@google.com 13013821Sgabeblack@google.com void sendEndReq(tlm::tlm_generic_payload &trans); 13113821Sgabeblack@google.com void sendBeginResp(tlm::tlm_generic_payload &trans, 13213821Sgabeblack@google.com sc_core::sc_time &delay); 13313821Sgabeblack@google.com 13413821Sgabeblack@google.com void handleBeginReq(tlm::tlm_generic_payload &trans); 13513821Sgabeblack@google.com void handleEndResp(tlm::tlm_generic_payload &trans); 13613821Sgabeblack@google.com 13713821Sgabeblack@google.com PacketPtr generatePacket(tlm::tlm_generic_payload &trans); 13813821Sgabeblack@google.com void destroyPacket(PacketPtr pkt); 13913821Sgabeblack@google.com 14013821Sgabeblack@google.com void checkTransaction(tlm::tlm_generic_payload &trans); 14113821Sgabeblack@google.com 14213846Sgabeblack@google.com void invalidateDmi(const ::MemBackdoor &backdoor); 14313846Sgabeblack@google.com 14413821Sgabeblack@google.com protected: 14513821Sgabeblack@google.com // payload event call back 14613821Sgabeblack@google.com void peq_cb(tlm::tlm_generic_payload &trans, const tlm::tlm_phase &phase); 14713821Sgabeblack@google.com 14813821Sgabeblack@google.com // The TLM target interface 14913821Sgabeblack@google.com tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload &trans, 15013821Sgabeblack@google.com tlm::tlm_phase &phase, 15113821Sgabeblack@google.com sc_core::sc_time &t); 15213821Sgabeblack@google.com void b_transport(tlm::tlm_generic_payload &trans, sc_core::sc_time &t); 15313821Sgabeblack@google.com unsigned int transport_dbg(tlm::tlm_generic_payload &trans); 15413821Sgabeblack@google.com bool get_direct_mem_ptr(tlm::tlm_generic_payload &trans, 15513821Sgabeblack@google.com tlm::tlm_dmi &dmi_data); 15613821Sgabeblack@google.com 15713821Sgabeblack@google.com // Gem5 port interface. 15813821Sgabeblack@google.com bool recvTimingResp(PacketPtr pkt); 15913821Sgabeblack@google.com void recvReqRetry(); 16013821Sgabeblack@google.com void recvRangeChange(); 16113821Sgabeblack@google.com 16213821Sgabeblack@google.com public: 16313821Sgabeblack@google.com ::Port &gem5_getPort(const std::string &if_name, int idx=-1) override; 16413821Sgabeblack@google.com 16513823Sgabeblack@google.com typedef TlmToGem5BridgeBaseParams Params; 16613821Sgabeblack@google.com TlmToGem5Bridge(Params *p, const sc_core::sc_module_name &mn); 16713821Sgabeblack@google.com 16813823Sgabeblack@google.com tlm_utils::simple_target_socket<TlmToGem5Bridge<BITWIDTH>, BITWIDTH> & 16913821Sgabeblack@google.com getSocket() 17013821Sgabeblack@google.com { 17113821Sgabeblack@google.com return socket; 17213821Sgabeblack@google.com } 17313821Sgabeblack@google.com 17413821Sgabeblack@google.com void before_end_of_elaboration() override; 17513821Sgabeblack@google.com 17613821Sgabeblack@google.com const MasterID masterId; 17713821Sgabeblack@google.com}; 17813821Sgabeblack@google.com 17913821Sgabeblack@google.com} // namespace sc_gem5 18013821Sgabeblack@google.com 18113821Sgabeblack@google.com#endif // __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 182