tlm_to_gem5.hh revision 13823:040971e0f728
17375Sgblack@eecs.umich.edu/* 27375Sgblack@eecs.umich.edu * Copyright 2019 Google, Inc. 37375Sgblack@eecs.umich.edu * 47375Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 57375Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 67375Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 77375Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 87375Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 97375Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 107375Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 117375Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 127375Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 137375Sgblack@eecs.umich.edu * this software without specific prior written permission. 147375Sgblack@eecs.umich.edu * 157375Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 167375Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 177375Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 187375Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 197375Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 207375Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 217375Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 227375Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 237375Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 247375Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 257375Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 267375Sgblack@eecs.umich.edu * 277375Sgblack@eecs.umich.edu * Copyright (c) 2016, Dresden University of Technology (TU Dresden) 287375Sgblack@eecs.umich.edu * All rights reserved. 297375Sgblack@eecs.umich.edu * 307375Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 317375Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 327375Sgblack@eecs.umich.edu * met: 337375Sgblack@eecs.umich.edu * 347375Sgblack@eecs.umich.edu * 1. Redistributions of source code must retain the above copyright notice, 357375Sgblack@eecs.umich.edu * this list of conditions and the following disclaimer. 367375Sgblack@eecs.umich.edu * 377375Sgblack@eecs.umich.edu * 2. Redistributions in binary form must reproduce the above copyright 387375Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 397375Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution. 407375Sgblack@eecs.umich.edu * 417375Sgblack@eecs.umich.edu * 3. Neither the name of the copyright holder nor the names of its 427375Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 437375Sgblack@eecs.umich.edu * this software without specific prior written permission. 447378Sgblack@eecs.umich.edu * 457378Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 467382Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 477375Sgblack@eecs.umich.edu * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 487384Sgblack@eecs.umich.edu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 497384Sgblack@eecs.umich.edu * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 507384Sgblack@eecs.umich.edu * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 517375Sgblack@eecs.umich.edu * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 527375Sgblack@eecs.umich.edu * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 537375Sgblack@eecs.umich.edu * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 547375Sgblack@eecs.umich.edu * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 557375Sgblack@eecs.umich.edu * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 567375Sgblack@eecs.umich.edu * 577375Sgblack@eecs.umich.edu * Authors: Gabe Black 587375Sgblack@eecs.umich.edu * Christian Menard 597375Sgblack@eecs.umich.edu */ 607375Sgblack@eecs.umich.edu 617375Sgblack@eecs.umich.edu#ifndef __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 627375Sgblack@eecs.umich.edu#define __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 637375Sgblack@eecs.umich.edu 647375Sgblack@eecs.umich.edu#include "mem/port.hh" 657375Sgblack@eecs.umich.edu#include "params/TlmToGem5BridgeBase.hh" 667375Sgblack@eecs.umich.edu#include "systemc/ext/core/sc_module.hh" 677375Sgblack@eecs.umich.edu#include "systemc/ext/core/sc_module_name.hh" 687375Sgblack@eecs.umich.edu#include "systemc/ext/tlm_core/2/generic_payload/gp.hh" 697375Sgblack@eecs.umich.edu#include "systemc/ext/tlm_utils/peq_with_cb_and_phase.h" 707375Sgblack@eecs.umich.edu#include "systemc/ext/tlm_utils/simple_target_socket.h" 717375Sgblack@eecs.umich.edu#include "systemc/tlm_bridge/sc_ext.hh" 727375Sgblack@eecs.umich.edu#include "systemc/tlm_port_wrapper.hh" 737375Sgblack@eecs.umich.edu 747375Sgblack@eecs.umich.edunamespace sc_gem5 757375Sgblack@eecs.umich.edu{ 767375Sgblack@eecs.umich.edu 777376Sgblack@eecs.umich.educlass TlmToGem5BridgeBase : public sc_core::sc_module 787376Sgblack@eecs.umich.edu{ 797376Sgblack@eecs.umich.edu protected: 807375Sgblack@eecs.umich.edu using sc_core::sc_module::sc_module; 817375Sgblack@eecs.umich.edu}; 827378Sgblack@eecs.umich.edu 837378Sgblack@eecs.umich.edutemplate <unsigned int BITWIDTH> 847378Sgblack@eecs.umich.educlass TlmToGem5Bridge : public TlmToGem5BridgeBase 857378Sgblack@eecs.umich.edu{ 867378Sgblack@eecs.umich.edu private: 877378Sgblack@eecs.umich.edu struct TlmSenderState : public Packet::SenderState 887378Sgblack@eecs.umich.edu { 897378Sgblack@eecs.umich.edu tlm::tlm_generic_payload &trans; 907378Sgblack@eecs.umich.edu TlmSenderState(tlm::tlm_generic_payload &trans) : trans(trans) {} 917378Sgblack@eecs.umich.edu }; 927378Sgblack@eecs.umich.edu 937378Sgblack@eecs.umich.edu class BridgeMasterPort : public MasterPort 947378Sgblack@eecs.umich.edu { 957378Sgblack@eecs.umich.edu protected: 967378Sgblack@eecs.umich.edu TlmToGem5Bridge<BITWIDTH> &bridge; 977378Sgblack@eecs.umich.edu 987378Sgblack@eecs.umich.edu bool 997378Sgblack@eecs.umich.edu recvTimingResp(PacketPtr pkt) override 1007378Sgblack@eecs.umich.edu { 1017378Sgblack@eecs.umich.edu return bridge.recvTimingResp(pkt); 1027378Sgblack@eecs.umich.edu } 1037378Sgblack@eecs.umich.edu void recvReqRetry() override { bridge.recvReqRetry(); } 1047378Sgblack@eecs.umich.edu void recvRangeChange() override { bridge.recvRangeChange(); } 1057378Sgblack@eecs.umich.edu 1067378Sgblack@eecs.umich.edu public: 1077378Sgblack@eecs.umich.edu BridgeMasterPort(const std::string &name_, 1087382Sgblack@eecs.umich.edu TlmToGem5Bridge<BITWIDTH> &bridge_) : 1097382Sgblack@eecs.umich.edu MasterPort(name_, nullptr), bridge(bridge_) 1107382Sgblack@eecs.umich.edu {} 1117382Sgblack@eecs.umich.edu }; 1127382Sgblack@eecs.umich.edu 1137396Sgblack@eecs.umich.edu tlm_utils::peq_with_cb_and_phase<TlmToGem5Bridge<BITWIDTH>> peq; 1147382Sgblack@eecs.umich.edu 1157382Sgblack@eecs.umich.edu bool waitForRetry; 1167396Sgblack@eecs.umich.edu tlm::tlm_generic_payload *pendingRequest; 1177396Sgblack@eecs.umich.edu PacketPtr pendingPacket; 1187382Sgblack@eecs.umich.edu 1197382Sgblack@eecs.umich.edu bool needToSendRetry; 1207382Sgblack@eecs.umich.edu 1217382Sgblack@eecs.umich.edu bool responseInProgress; 1227382Sgblack@eecs.umich.edu 1237382Sgblack@eecs.umich.edu BridgeMasterPort bmp; 1247382Sgblack@eecs.umich.edu tlm_utils::simple_target_socket< 1257382Sgblack@eecs.umich.edu TlmToGem5Bridge<BITWIDTH>, BITWIDTH> socket; 1267382Sgblack@eecs.umich.edu sc_gem5::TlmTargetWrapper<BITWIDTH> wrapper; 1277382Sgblack@eecs.umich.edu 1287382Sgblack@eecs.umich.edu System *system; 1297382Sgblack@eecs.umich.edu 1307396Sgblack@eecs.umich.edu void sendEndReq(tlm::tlm_generic_payload &trans); 1317396Sgblack@eecs.umich.edu void sendBeginResp(tlm::tlm_generic_payload &trans, 1327396Sgblack@eecs.umich.edu sc_core::sc_time &delay); 1337396Sgblack@eecs.umich.edu 1347396Sgblack@eecs.umich.edu void handleBeginReq(tlm::tlm_generic_payload &trans); 1357396Sgblack@eecs.umich.edu void handleEndResp(tlm::tlm_generic_payload &trans); 1367396Sgblack@eecs.umich.edu 1377396Sgblack@eecs.umich.edu PacketPtr generatePacket(tlm::tlm_generic_payload &trans); 1387396Sgblack@eecs.umich.edu void destroyPacket(PacketPtr pkt); 1397396Sgblack@eecs.umich.edu 1407396Sgblack@eecs.umich.edu void checkTransaction(tlm::tlm_generic_payload &trans); 1417396Sgblack@eecs.umich.edu 1427396Sgblack@eecs.umich.edu protected: 1437396Sgblack@eecs.umich.edu // payload event call back 1447396Sgblack@eecs.umich.edu void peq_cb(tlm::tlm_generic_payload &trans, const tlm::tlm_phase &phase); 1457396Sgblack@eecs.umich.edu 1467396Sgblack@eecs.umich.edu // The TLM target interface 1477396Sgblack@eecs.umich.edu tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload &trans, 1487396Sgblack@eecs.umich.edu tlm::tlm_phase &phase, 1497396Sgblack@eecs.umich.edu sc_core::sc_time &t); 1507396Sgblack@eecs.umich.edu void b_transport(tlm::tlm_generic_payload &trans, sc_core::sc_time &t); 1517396Sgblack@eecs.umich.edu unsigned int transport_dbg(tlm::tlm_generic_payload &trans); 1527384Sgblack@eecs.umich.edu bool get_direct_mem_ptr(tlm::tlm_generic_payload &trans, 1537384Sgblack@eecs.umich.edu tlm::tlm_dmi &dmi_data); 1547384Sgblack@eecs.umich.edu 1557384Sgblack@eecs.umich.edu // Gem5 port interface. 1567384Sgblack@eecs.umich.edu bool recvTimingResp(PacketPtr pkt); 1577384Sgblack@eecs.umich.edu void recvReqRetry(); 1587384Sgblack@eecs.umich.edu void recvRangeChange(); 1597384Sgblack@eecs.umich.edu 1607384Sgblack@eecs.umich.edu public: 1617384Sgblack@eecs.umich.edu ::Port &gem5_getPort(const std::string &if_name, int idx=-1) override; 1627384Sgblack@eecs.umich.edu 1637384Sgblack@eecs.umich.edu typedef TlmToGem5BridgeBaseParams Params; 1647384Sgblack@eecs.umich.edu TlmToGem5Bridge(Params *p, const sc_core::sc_module_name &mn); 1657384Sgblack@eecs.umich.edu 1667384Sgblack@eecs.umich.edu tlm_utils::simple_target_socket<TlmToGem5Bridge<BITWIDTH>, BITWIDTH> & 1677384Sgblack@eecs.umich.edu getSocket() 1687384Sgblack@eecs.umich.edu { 1697384Sgblack@eecs.umich.edu return socket; 1707384Sgblack@eecs.umich.edu } 1717384Sgblack@eecs.umich.edu 1727384Sgblack@eecs.umich.edu void before_end_of_elaboration() override; 1737384Sgblack@eecs.umich.edu 1747384Sgblack@eecs.umich.edu const MasterID masterId; 1757384Sgblack@eecs.umich.edu}; 1767384Sgblack@eecs.umich.edu 1777384Sgblack@eecs.umich.edu} // namespace sc_gem5 1787384Sgblack@eecs.umich.edu 1797384Sgblack@eecs.umich.edu#endif // __SYSTEMC_TLM_BRIDGE_TLM_TO_GEM5_HH__ 1807384Sgblack@eecs.umich.edu