gem5_to_tlm.hh revision 13823
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) 2015, University of Kaiserslautern 2813821Sgabeblack@google.com * Copyright (c) 2016, Dresden University of Technology (TU Dresden) 2913821Sgabeblack@google.com * All rights reserved. 3013821Sgabeblack@google.com * 3113821Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 3213821Sgabeblack@google.com * modification, are permitted provided that the following conditions are 3313821Sgabeblack@google.com * met: 3413821Sgabeblack@google.com * 3513821Sgabeblack@google.com * 1. Redistributions of source code must retain the above copyright notice, 3613821Sgabeblack@google.com * this list of conditions and the following disclaimer. 3713821Sgabeblack@google.com * 3813821Sgabeblack@google.com * 2. Redistributions in binary form must reproduce the above copyright 3913821Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 4013821Sgabeblack@google.com * documentation and/or other materials provided with the distribution. 4113821Sgabeblack@google.com * 4213821Sgabeblack@google.com * 3. Neither the name of the copyright holder nor the names of its 4313821Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 4413821Sgabeblack@google.com * this software without specific prior written permission. 4513821Sgabeblack@google.com * 4613821Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4713821Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 4813821Sgabeblack@google.com * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4913821Sgabeblack@google.com * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 5013821Sgabeblack@google.com * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 5113821Sgabeblack@google.com * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 5213821Sgabeblack@google.com * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 5313821Sgabeblack@google.com * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 5413821Sgabeblack@google.com * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 5513821Sgabeblack@google.com * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 5613821Sgabeblack@google.com * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5713821Sgabeblack@google.com * 5813821Sgabeblack@google.com * Authors: Gabe Black 5913821Sgabeblack@google.com * Matthias Jung 6013821Sgabeblack@google.com * Christian Menard 6113821Sgabeblack@google.com */ 6213821Sgabeblack@google.com 6313821Sgabeblack@google.com#ifndef __SYSTEMC_TLM_BRIDGE_GEM5_TO_TLM_HH__ 6413821Sgabeblack@google.com#define __SYSTEMC_TLM_BRIDGE_GEM5_TO_TLM_HH__ 6513821Sgabeblack@google.com 6613821Sgabeblack@google.com#include <string> 6713821Sgabeblack@google.com 6813821Sgabeblack@google.com#include "mem/port.hh" 6913823Sgabeblack@google.com#include "params/Gem5ToTlmBridgeBase.hh" 7013821Sgabeblack@google.com#include "sim/system.hh" 7113821Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 7213821Sgabeblack@google.com#include "systemc/ext/core/sc_module_name.hh" 7313821Sgabeblack@google.com#include "systemc/ext/tlm_core/2/generic_payload/gp.hh" 7413821Sgabeblack@google.com#include "systemc/ext/tlm_utils/simple_initiator_socket.h" 7513821Sgabeblack@google.com#include "systemc/tlm_bridge/sc_peq.hh" 7613821Sgabeblack@google.com#include "systemc/tlm_port_wrapper.hh" 7713821Sgabeblack@google.com 7813821Sgabeblack@google.comnamespace sc_gem5 7913821Sgabeblack@google.com{ 8013821Sgabeblack@google.com 8113823Sgabeblack@google.comclass Gem5ToTlmBridgeBase : public sc_core::sc_module 8213823Sgabeblack@google.com{ 8313823Sgabeblack@google.com protected: 8413823Sgabeblack@google.com using sc_core::sc_module::sc_module; 8513823Sgabeblack@google.com}; 8613823Sgabeblack@google.com 8713823Sgabeblack@google.comtemplate <unsigned int BITWIDTH> 8813823Sgabeblack@google.comclass Gem5ToTlmBridge : public Gem5ToTlmBridgeBase 8913821Sgabeblack@google.com{ 9013821Sgabeblack@google.com private: 9113821Sgabeblack@google.com class BridgeSlavePort : public SlavePort 9213821Sgabeblack@google.com { 9313821Sgabeblack@google.com protected: 9413823Sgabeblack@google.com Gem5ToTlmBridge<BITWIDTH> &bridge; 9513821Sgabeblack@google.com 9613821Sgabeblack@google.com AddrRangeList 9713821Sgabeblack@google.com getAddrRanges() const override 9813821Sgabeblack@google.com { 9913821Sgabeblack@google.com return bridge.getAddrRanges(); 10013821Sgabeblack@google.com } 10113821Sgabeblack@google.com Tick 10213821Sgabeblack@google.com recvAtomic(PacketPtr pkt) override 10313821Sgabeblack@google.com { 10413821Sgabeblack@google.com return bridge.recvAtomic(pkt); 10513821Sgabeblack@google.com } 10613821Sgabeblack@google.com void 10713821Sgabeblack@google.com recvFunctional(PacketPtr pkt) override 10813821Sgabeblack@google.com { 10913821Sgabeblack@google.com return bridge.recvFunctional(pkt); 11013821Sgabeblack@google.com } 11113821Sgabeblack@google.com bool 11213821Sgabeblack@google.com recvTimingReq(PacketPtr pkt) override 11313821Sgabeblack@google.com { 11413821Sgabeblack@google.com return bridge.recvTimingReq(pkt); 11513821Sgabeblack@google.com } 11613821Sgabeblack@google.com bool 11713821Sgabeblack@google.com tryTiming(PacketPtr pkt) override 11813821Sgabeblack@google.com { 11913821Sgabeblack@google.com return bridge.tryTiming(pkt); 12013821Sgabeblack@google.com } 12113821Sgabeblack@google.com bool 12213821Sgabeblack@google.com recvTimingSnoopResp(PacketPtr pkt) override 12313821Sgabeblack@google.com { 12413821Sgabeblack@google.com return bridge.recvTimingSnoopResp(pkt); 12513821Sgabeblack@google.com } 12613821Sgabeblack@google.com void recvRespRetry() override { bridge.recvRespRetry(); } 12713821Sgabeblack@google.com 12813821Sgabeblack@google.com public: 12913823Sgabeblack@google.com BridgeSlavePort(const std::string &name_, 13013823Sgabeblack@google.com Gem5ToTlmBridge<BITWIDTH> &bridge_) : 13113821Sgabeblack@google.com SlavePort(name_, nullptr), bridge(bridge_) 13213821Sgabeblack@google.com {} 13313821Sgabeblack@google.com }; 13413821Sgabeblack@google.com 13513821Sgabeblack@google.com BridgeSlavePort bsp; 13613823Sgabeblack@google.com tlm_utils::simple_initiator_socket< 13713823Sgabeblack@google.com Gem5ToTlmBridge<BITWIDTH>, BITWIDTH> socket; 13813823Sgabeblack@google.com sc_gem5::TlmInitiatorWrapper<BITWIDTH> wrapper; 13913821Sgabeblack@google.com 14013821Sgabeblack@google.com System *system; 14113821Sgabeblack@google.com 14213821Sgabeblack@google.com /** 14313821Sgabeblack@google.com * A transaction after BEGIN_REQ has been sent but before END_REQ, which 14413821Sgabeblack@google.com * is blocking the request channel (Exlusion Rule, see IEEE1666) 14513821Sgabeblack@google.com */ 14613821Sgabeblack@google.com tlm::tlm_generic_payload *blockingRequest; 14713821Sgabeblack@google.com 14813821Sgabeblack@google.com /** 14913821Sgabeblack@google.com * Did another gem5 request arrive while currently blocked? 15013821Sgabeblack@google.com * This variable is needed when a retry should happen 15113821Sgabeblack@google.com */ 15213821Sgabeblack@google.com bool needToSendRequestRetry; 15313821Sgabeblack@google.com 15413821Sgabeblack@google.com /** 15513821Sgabeblack@google.com * A response which has been asked to retry by gem5 and so is blocking 15613821Sgabeblack@google.com * the response channel 15713821Sgabeblack@google.com */ 15813821Sgabeblack@google.com tlm::tlm_generic_payload *blockingResponse; 15913821Sgabeblack@google.com 16013821Sgabeblack@google.com AddrRangeList addrRanges; 16113821Sgabeblack@google.com 16213821Sgabeblack@google.com protected: 16313823Sgabeblack@google.com void pec(Gem5SystemC::PayloadEvent<Gem5ToTlmBridge<BITWIDTH>> *pe, 16413821Sgabeblack@google.com tlm::tlm_generic_payload &trans, const tlm::tlm_phase &phase); 16513821Sgabeblack@google.com 16613821Sgabeblack@google.com // The gem5 port interface. 16713821Sgabeblack@google.com Tick recvAtomic(PacketPtr packet); 16813821Sgabeblack@google.com void recvFunctional(PacketPtr packet); 16913821Sgabeblack@google.com bool recvTimingReq(PacketPtr packet); 17013821Sgabeblack@google.com bool tryTiming(PacketPtr packet); 17113821Sgabeblack@google.com bool recvTimingSnoopResp(PacketPtr packet); 17213821Sgabeblack@google.com void recvRespRetry(); 17313821Sgabeblack@google.com void recvFunctionalSnoop(PacketPtr packet); 17413821Sgabeblack@google.com AddrRangeList getAddrRanges() const { return addrRanges; } 17513821Sgabeblack@google.com 17613821Sgabeblack@google.com // The TLM initiator interface. 17713821Sgabeblack@google.com tlm::tlm_sync_enum nb_transport_bw(tlm::tlm_generic_payload &trans, 17813821Sgabeblack@google.com tlm::tlm_phase &phase, 17913821Sgabeblack@google.com sc_core::sc_time &t); 18013821Sgabeblack@google.com 18113821Sgabeblack@google.com public: 18213821Sgabeblack@google.com ::Port &gem5_getPort(const std::string &if_name, int idx=-1) override; 18313821Sgabeblack@google.com 18413823Sgabeblack@google.com typedef Gem5ToTlmBridgeBaseParams Params; 18513821Sgabeblack@google.com Gem5ToTlmBridge(Params *p, const sc_core::sc_module_name &mn); 18613821Sgabeblack@google.com 18713823Sgabeblack@google.com tlm_utils::simple_initiator_socket<Gem5ToTlmBridge<BITWIDTH>, BITWIDTH> & 18813821Sgabeblack@google.com getSocket() 18913821Sgabeblack@google.com { 19013821Sgabeblack@google.com return socket; 19113821Sgabeblack@google.com } 19213821Sgabeblack@google.com 19313821Sgabeblack@google.com void before_end_of_elaboration() override; 19413821Sgabeblack@google.com}; 19513821Sgabeblack@google.com 19613821Sgabeblack@google.com} // namespace sc_gem5 19713821Sgabeblack@google.com 19813821Sgabeblack@google.com#endif // __SYSTEMC_TLM_BRIDGE_GEM5_TO_TLM_HH__ 199