gem5_to_tlm.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) 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"
6913821Sgabeblack@google.com#include "params/Gem5ToTlmBridge.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
8113821Sgabeblack@google.comclass Gem5ToTlmBridge : public sc_core::sc_module
8213821Sgabeblack@google.com{
8313821Sgabeblack@google.com  private:
8413821Sgabeblack@google.com    class BridgeSlavePort : public SlavePort
8513821Sgabeblack@google.com    {
8613821Sgabeblack@google.com      protected:
8713821Sgabeblack@google.com        Gem5ToTlmBridge &bridge;
8813821Sgabeblack@google.com
8913821Sgabeblack@google.com        AddrRangeList
9013821Sgabeblack@google.com        getAddrRanges() const override
9113821Sgabeblack@google.com        {
9213821Sgabeblack@google.com            return bridge.getAddrRanges();
9313821Sgabeblack@google.com        }
9413821Sgabeblack@google.com        Tick
9513821Sgabeblack@google.com        recvAtomic(PacketPtr pkt) override
9613821Sgabeblack@google.com        {
9713821Sgabeblack@google.com            return bridge.recvAtomic(pkt);
9813821Sgabeblack@google.com        }
9913821Sgabeblack@google.com        void
10013821Sgabeblack@google.com        recvFunctional(PacketPtr pkt) override
10113821Sgabeblack@google.com        {
10213821Sgabeblack@google.com            return bridge.recvFunctional(pkt);
10313821Sgabeblack@google.com        }
10413821Sgabeblack@google.com        bool
10513821Sgabeblack@google.com        recvTimingReq(PacketPtr pkt) override
10613821Sgabeblack@google.com        {
10713821Sgabeblack@google.com            return bridge.recvTimingReq(pkt);
10813821Sgabeblack@google.com        }
10913821Sgabeblack@google.com        bool
11013821Sgabeblack@google.com        tryTiming(PacketPtr pkt) override
11113821Sgabeblack@google.com        {
11213821Sgabeblack@google.com            return bridge.tryTiming(pkt);
11313821Sgabeblack@google.com        }
11413821Sgabeblack@google.com        bool
11513821Sgabeblack@google.com        recvTimingSnoopResp(PacketPtr pkt) override
11613821Sgabeblack@google.com        {
11713821Sgabeblack@google.com            return bridge.recvTimingSnoopResp(pkt);
11813821Sgabeblack@google.com        }
11913821Sgabeblack@google.com        void recvRespRetry() override { bridge.recvRespRetry(); }
12013821Sgabeblack@google.com
12113821Sgabeblack@google.com      public:
12213821Sgabeblack@google.com        BridgeSlavePort(const std::string &name_, Gem5ToTlmBridge &bridge_) :
12313821Sgabeblack@google.com            SlavePort(name_, nullptr), bridge(bridge_)
12413821Sgabeblack@google.com        {}
12513821Sgabeblack@google.com    };
12613821Sgabeblack@google.com
12713821Sgabeblack@google.com    BridgeSlavePort bsp;
12813821Sgabeblack@google.com    tlm_utils::simple_initiator_socket<Gem5ToTlmBridge, 64> socket;
12913821Sgabeblack@google.com    sc_gem5::TlmInitiatorWrapper<64> wrapper;
13013821Sgabeblack@google.com
13113821Sgabeblack@google.com    System *system;
13213821Sgabeblack@google.com
13313821Sgabeblack@google.com    /**
13413821Sgabeblack@google.com     * A transaction after BEGIN_REQ has been sent but before END_REQ, which
13513821Sgabeblack@google.com     * is blocking the request channel (Exlusion Rule, see IEEE1666)
13613821Sgabeblack@google.com     */
13713821Sgabeblack@google.com    tlm::tlm_generic_payload *blockingRequest;
13813821Sgabeblack@google.com
13913821Sgabeblack@google.com    /**
14013821Sgabeblack@google.com     * Did another gem5 request arrive while currently blocked?
14113821Sgabeblack@google.com     * This variable is needed when a retry should happen
14213821Sgabeblack@google.com     */
14313821Sgabeblack@google.com    bool needToSendRequestRetry;
14413821Sgabeblack@google.com
14513821Sgabeblack@google.com    /**
14613821Sgabeblack@google.com     * A response which has been asked to retry by gem5 and so is blocking
14713821Sgabeblack@google.com     * the response channel
14813821Sgabeblack@google.com     */
14913821Sgabeblack@google.com    tlm::tlm_generic_payload *blockingResponse;
15013821Sgabeblack@google.com
15113821Sgabeblack@google.com    AddrRangeList addrRanges;
15213821Sgabeblack@google.com
15313821Sgabeblack@google.com  protected:
15413821Sgabeblack@google.com    void pec(Gem5SystemC::PayloadEvent<Gem5ToTlmBridge> *pe,
15513821Sgabeblack@google.com             tlm::tlm_generic_payload &trans, const tlm::tlm_phase &phase);
15613821Sgabeblack@google.com
15713821Sgabeblack@google.com    // The gem5 port interface.
15813821Sgabeblack@google.com    Tick recvAtomic(PacketPtr packet);
15913821Sgabeblack@google.com    void recvFunctional(PacketPtr packet);
16013821Sgabeblack@google.com    bool recvTimingReq(PacketPtr packet);
16113821Sgabeblack@google.com    bool tryTiming(PacketPtr packet);
16213821Sgabeblack@google.com    bool recvTimingSnoopResp(PacketPtr packet);
16313821Sgabeblack@google.com    void recvRespRetry();
16413821Sgabeblack@google.com    void recvFunctionalSnoop(PacketPtr packet);
16513821Sgabeblack@google.com    AddrRangeList getAddrRanges() const { return addrRanges; }
16613821Sgabeblack@google.com
16713821Sgabeblack@google.com    // The TLM initiator interface.
16813821Sgabeblack@google.com    tlm::tlm_sync_enum nb_transport_bw(tlm::tlm_generic_payload &trans,
16913821Sgabeblack@google.com                                       tlm::tlm_phase &phase,
17013821Sgabeblack@google.com                                       sc_core::sc_time &t);
17113821Sgabeblack@google.com
17213821Sgabeblack@google.com  public:
17313821Sgabeblack@google.com    ::Port &gem5_getPort(const std::string &if_name, int idx=-1) override;
17413821Sgabeblack@google.com
17513821Sgabeblack@google.com    typedef Gem5ToTlmBridgeParams Params;
17613821Sgabeblack@google.com    Gem5ToTlmBridge(Params *p, const sc_core::sc_module_name &mn);
17713821Sgabeblack@google.com
17813821Sgabeblack@google.com    tlm_utils::simple_initiator_socket<Gem5ToTlmBridge, 64> &
17913821Sgabeblack@google.com    getSocket()
18013821Sgabeblack@google.com    {
18113821Sgabeblack@google.com        return socket;
18213821Sgabeblack@google.com    }
18313821Sgabeblack@google.com
18413821Sgabeblack@google.com    void before_end_of_elaboration() override;
18513821Sgabeblack@google.com};
18613821Sgabeblack@google.com
18713821Sgabeblack@google.com} // namespace sc_gem5
18813821Sgabeblack@google.com
18913821Sgabeblack@google.com#endif // __SYSTEMC_TLM_BRIDGE_GEM5_TO_TLM_HH__
190