tlm_to_gem5.hh revision 13821
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" 6513821Sgabeblack@google.com#include "params/TlmToGem5Bridge.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 7713821Sgabeblack@google.comclass TlmToGem5Bridge : public sc_core::sc_module 7813821Sgabeblack@google.com{ 7913821Sgabeblack@google.com private: 8013821Sgabeblack@google.com struct TlmSenderState : public Packet::SenderState 8113821Sgabeblack@google.com { 8213821Sgabeblack@google.com tlm::tlm_generic_payload &trans; 8313821Sgabeblack@google.com TlmSenderState(tlm::tlm_generic_payload &trans) : trans(trans) {} 8413821Sgabeblack@google.com }; 8513821Sgabeblack@google.com 8613821Sgabeblack@google.com class BridgeMasterPort : public MasterPort 8713821Sgabeblack@google.com { 8813821Sgabeblack@google.com protected: 8913821Sgabeblack@google.com TlmToGem5Bridge &bridge; 9013821Sgabeblack@google.com 9113821Sgabeblack@google.com bool 9213821Sgabeblack@google.com recvTimingResp(PacketPtr pkt) override 9313821Sgabeblack@google.com { 9413821Sgabeblack@google.com return bridge.recvTimingResp(pkt); 9513821Sgabeblack@google.com } 9613821Sgabeblack@google.com void recvReqRetry() override { bridge.recvReqRetry(); } 9713821Sgabeblack@google.com void recvRangeChange() override { bridge.recvRangeChange(); } 9813821Sgabeblack@google.com 9913821Sgabeblack@google.com public: 10013821Sgabeblack@google.com BridgeMasterPort(const std::string &name_, TlmToGem5Bridge &bridge_) : 10113821Sgabeblack@google.com MasterPort(name_, nullptr), bridge(bridge_) 10213821Sgabeblack@google.com {} 10313821Sgabeblack@google.com }; 10413821Sgabeblack@google.com 10513821Sgabeblack@google.com tlm_utils::peq_with_cb_and_phase<TlmToGem5Bridge> peq; 10613821Sgabeblack@google.com 10713821Sgabeblack@google.com bool waitForRetry; 10813821Sgabeblack@google.com tlm::tlm_generic_payload *pendingRequest; 10913821Sgabeblack@google.com PacketPtr pendingPacket; 11013821Sgabeblack@google.com 11113821Sgabeblack@google.com bool needToSendRetry; 11213821Sgabeblack@google.com 11313821Sgabeblack@google.com bool responseInProgress; 11413821Sgabeblack@google.com 11513821Sgabeblack@google.com BridgeMasterPort bmp; 11613821Sgabeblack@google.com tlm_utils::simple_target_socket<TlmToGem5Bridge, 64> socket; 11713821Sgabeblack@google.com sc_gem5::TlmTargetWrapper<64> wrapper; 11813821Sgabeblack@google.com 11913821Sgabeblack@google.com System *system; 12013821Sgabeblack@google.com 12113821Sgabeblack@google.com void sendEndReq(tlm::tlm_generic_payload &trans); 12213821Sgabeblack@google.com void sendBeginResp(tlm::tlm_generic_payload &trans, 12313821Sgabeblack@google.com sc_core::sc_time &delay); 12413821Sgabeblack@google.com 12513821Sgabeblack@google.com void handleBeginReq(tlm::tlm_generic_payload &trans); 12613821Sgabeblack@google.com void handleEndResp(tlm::tlm_generic_payload &trans); 12713821Sgabeblack@google.com 12813821Sgabeblack@google.com PacketPtr generatePacket(tlm::tlm_generic_payload &trans); 12913821Sgabeblack@google.com void destroyPacket(PacketPtr pkt); 13013821Sgabeblack@google.com 13113821Sgabeblack@google.com void checkTransaction(tlm::tlm_generic_payload &trans); 13213821Sgabeblack@google.com 13313821Sgabeblack@google.com protected: 13413821Sgabeblack@google.com // payload event call back 13513821Sgabeblack@google.com void peq_cb(tlm::tlm_generic_payload &trans, const tlm::tlm_phase &phase); 13613821Sgabeblack@google.com 13713821Sgabeblack@google.com // The TLM target interface 13813821Sgabeblack@google.com tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload &trans, 13913821Sgabeblack@google.com tlm::tlm_phase &phase, 14013821Sgabeblack@google.com sc_core::sc_time &t); 14113821Sgabeblack@google.com void b_transport(tlm::tlm_generic_payload &trans, sc_core::sc_time &t); 14213821Sgabeblack@google.com unsigned int transport_dbg(tlm::tlm_generic_payload &trans); 14313821Sgabeblack@google.com bool get_direct_mem_ptr(tlm::tlm_generic_payload &trans, 14413821Sgabeblack@google.com tlm::tlm_dmi &dmi_data); 14513821Sgabeblack@google.com 14613821Sgabeblack@google.com // Gem5 port interface. 14713821Sgabeblack@google.com bool recvTimingResp(PacketPtr pkt); 14813821Sgabeblack@google.com void recvReqRetry(); 14913821Sgabeblack@google.com void recvRangeChange(); 15013821Sgabeblack@google.com 15113821Sgabeblack@google.com public: 15213821Sgabeblack@google.com ::Port &gem5_getPort(const std::string &if_name, int idx=-1) override; 15313821Sgabeblack@google.com 15413821Sgabeblack@google.com typedef TlmToGem5BridgeParams Params; 15513821Sgabeblack@google.com TlmToGem5Bridge(Params *p, const sc_core::sc_module_name &mn); 15613821Sgabeblack@google.com 15713821Sgabeblack@google.com tlm_utils::simple_target_socket<TlmToGem5Bridge, 64> & 15813821Sgabeblack@google.com getSocket() 15913821Sgabeblack@google.com { 16013821Sgabeblack@google.com return socket; 16113821Sgabeblack@google.com } 16213821Sgabeblack@google.com 16313821Sgabeblack@google.com void before_end_of_elaboration() override; 16413821Sgabeblack@google.com 16513821Sgabeblack@google.com const MasterID masterId; 16613821Sgabeblack@google.com}; 16713821Sgabeblack@google.com 16813821Sgabeblack@google.com} // namespace sc_gem5 16913821Sgabeblack@google.com 17013821Sgabeblack@google.com#endif // __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 171