tlm_to_gem5.hh revision 13823
12SN/A/* 21762SN/A * Copyright 2019 Google, Inc. 32SN/A * 42SN/A * Redistribution and use in source and binary forms, with or without 52SN/A * modification, are permitted provided that the following conditions are 62SN/A * met: redistributions of source code must retain the above copyright 72SN/A * notice, this list of conditions and the following disclaimer; 82SN/A * redistributions in binary form must reproduce the above copyright 92SN/A * notice, this list of conditions and the following disclaimer in the 102SN/A * documentation and/or other materials provided with the distribution; 112SN/A * neither the name of the copyright holders nor the names of its 122SN/A * contributors may be used to endorse or promote products derived from 132SN/A * this software without specific prior written permission. 142SN/A * 152SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262SN/A * 272665Ssaidi@eecs.umich.edu * Copyright (c) 2016, Dresden University of Technology (TU Dresden) 282665Ssaidi@eecs.umich.edu * All rights reserved. 292665Ssaidi@eecs.umich.edu * 302SN/A * Redistribution and use in source and binary forms, with or without 312SN/A * modification, are permitted provided that the following conditions are 321112SN/A * met: 331112SN/A * 342SN/A * 1. Redistributions of source code must retain the above copyright notice, 353386Sgblack@eecs.umich.edu * this list of conditions and the following disclaimer. 362SN/A * 372SN/A * 2. Redistributions in binary form must reproduce the above copyright 382SN/A * notice, this list of conditions and the following disclaimer in the 392SN/A * documentation and/or other materials provided with the distribution. 402SN/A * 412SN/A * 3. Neither the name of the copyright holder nor the names of its 422SN/A * contributors may be used to endorse or promote products derived from 432SN/A * this software without specific prior written permission. 442SN/A * 452SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 462SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 472SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 482SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 492SN/A * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 502SN/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 512SN/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 522SN/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 532SN/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 542SN/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 552SN/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 562SN/A * 572SN/A * Authors: Gabe Black 582SN/A * Christian Menard 592SN/A */ 602SN/A 612SN/A#ifndef __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 622SN/A#define __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 632SN/A 642SN/A#include "mem/port.hh" 652SN/A#include "params/TlmToGem5BridgeBase.hh" 662SN/A#include "systemc/ext/core/sc_module.hh" 672SN/A#include "systemc/ext/core/sc_module_name.hh" 682SN/A#include "systemc/ext/tlm_core/2/generic_payload/gp.hh" 692SN/A#include "systemc/ext/tlm_utils/peq_with_cb_and_phase.h" 702SN/A#include "systemc/ext/tlm_utils/simple_target_socket.h" 712SN/A#include "systemc/tlm_bridge/sc_ext.hh" 723422Sgblack@eecs.umich.edu#include "systemc/tlm_port_wrapper.hh" 733422Sgblack@eecs.umich.edu 743422Sgblack@eecs.umich.edunamespace sc_gem5 753422Sgblack@eecs.umich.edu{ 763422Sgblack@eecs.umich.edu 773422Sgblack@eecs.umich.educlass TlmToGem5BridgeBase : public sc_core::sc_module 783422Sgblack@eecs.umich.edu{ 793422Sgblack@eecs.umich.edu protected: 803422Sgblack@eecs.umich.edu using sc_core::sc_module::sc_module; 813422Sgblack@eecs.umich.edu}; 823422Sgblack@eecs.umich.edu 833422Sgblack@eecs.umich.edutemplate <unsigned int BITWIDTH> 843422Sgblack@eecs.umich.educlass TlmToGem5Bridge : public TlmToGem5BridgeBase 853422Sgblack@eecs.umich.edu{ 863422Sgblack@eecs.umich.edu private: 873422Sgblack@eecs.umich.edu struct TlmSenderState : public Packet::SenderState 883422Sgblack@eecs.umich.edu { 893422Sgblack@eecs.umich.edu tlm::tlm_generic_payload &trans; 903422Sgblack@eecs.umich.edu TlmSenderState(tlm::tlm_generic_payload &trans) : trans(trans) {} 913422Sgblack@eecs.umich.edu }; 923422Sgblack@eecs.umich.edu 933422Sgblack@eecs.umich.edu class BridgeMasterPort : public MasterPort 943422Sgblack@eecs.umich.edu { 953422Sgblack@eecs.umich.edu protected: 961112SN/A TlmToGem5Bridge<BITWIDTH> &bridge; 97 98 bool 99 recvTimingResp(PacketPtr pkt) override 100 { 101 return bridge.recvTimingResp(pkt); 102 } 103 void recvReqRetry() override { bridge.recvReqRetry(); } 104 void recvRangeChange() override { bridge.recvRangeChange(); } 105 106 public: 107 BridgeMasterPort(const std::string &name_, 108 TlmToGem5Bridge<BITWIDTH> &bridge_) : 109 MasterPort(name_, nullptr), bridge(bridge_) 110 {} 111 }; 112 113 tlm_utils::peq_with_cb_and_phase<TlmToGem5Bridge<BITWIDTH>> peq; 114 115 bool waitForRetry; 116 tlm::tlm_generic_payload *pendingRequest; 117 PacketPtr pendingPacket; 118 119 bool needToSendRetry; 120 121 bool responseInProgress; 122 123 BridgeMasterPort bmp; 124 tlm_utils::simple_target_socket< 125 TlmToGem5Bridge<BITWIDTH>, BITWIDTH> socket; 126 sc_gem5::TlmTargetWrapper<BITWIDTH> wrapper; 127 128 System *system; 129 130 void sendEndReq(tlm::tlm_generic_payload &trans); 131 void sendBeginResp(tlm::tlm_generic_payload &trans, 132 sc_core::sc_time &delay); 133 134 void handleBeginReq(tlm::tlm_generic_payload &trans); 135 void handleEndResp(tlm::tlm_generic_payload &trans); 136 137 PacketPtr generatePacket(tlm::tlm_generic_payload &trans); 138 void destroyPacket(PacketPtr pkt); 139 140 void checkTransaction(tlm::tlm_generic_payload &trans); 141 142 protected: 143 // payload event call back 144 void peq_cb(tlm::tlm_generic_payload &trans, const tlm::tlm_phase &phase); 145 146 // The TLM target interface 147 tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload &trans, 148 tlm::tlm_phase &phase, 149 sc_core::sc_time &t); 150 void b_transport(tlm::tlm_generic_payload &trans, sc_core::sc_time &t); 151 unsigned int transport_dbg(tlm::tlm_generic_payload &trans); 152 bool get_direct_mem_ptr(tlm::tlm_generic_payload &trans, 153 tlm::tlm_dmi &dmi_data); 154 155 // Gem5 port interface. 156 bool recvTimingResp(PacketPtr pkt); 157 void recvReqRetry(); 158 void recvRangeChange(); 159 160 public: 161 ::Port &gem5_getPort(const std::string &if_name, int idx=-1) override; 162 163 typedef TlmToGem5BridgeBaseParams Params; 164 TlmToGem5Bridge(Params *p, const sc_core::sc_module_name &mn); 165 166 tlm_utils::simple_target_socket<TlmToGem5Bridge<BITWIDTH>, BITWIDTH> & 167 getSocket() 168 { 169 return socket; 170 } 171 172 void before_end_of_elaboration() override; 173 174 const MasterID masterId; 175}; 176 177} // namespace sc_gem5 178 179#endif // __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 180