2 * Copyright (c) 2015, University of Kaiserslautern
3 * Copyright (c) 2016, Dresden University of Technology (TU Dresden)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Authors: Matthias Jung
37 #ifndef __SC_SLAVE_PORT_HH__
38 #define __SC_SLAVE_PORT_HH__
40 #include <tlm_utils/simple_initiator_socket.h>
46 #include "mem/external_slave.hh"
48 #include "sc_module.hh"
54 * Test that gem5 is at the same time as SystemC
56 #define CAUGHT_UP do { \
57 assert(curTick() == sc_core::sc_time_stamp().value()); \
61 * This is a gem5 slave port that translates gem5 packets to TLM transactions.
63 * Upon receiving a packet (recvAtomic, recvTiningReq, recvFunctional) the port
64 * creates a new TLM payload and initializes it with information from the gem5
65 * packet. The original packet is added as an extension to the TLM payload.
66 * Then the port issues a TLM transaction in the SystemC world. By storing the
67 * original packet as a payload extension, the packet can be restored and send
68 * back to the gem5 world upon receiving a response from the SystemC world.
70 class SCSlavePort : public tlm::tlm_initiator_socket<>,
71 public tlm::tlm_bw_transport_if<>,
72 public ExternalSlave::Port
77 /** One instance of pe and the related callback needed */
78 //payloadEvent<SCSlavePort> pe;
79 void pec(PayloadEvent<SCSlavePort> * pe,
80 tlm::tlm_generic_payload& trans, const tlm::tlm_phase& phase);
83 * A transaction after BEGIN_REQ has been sent but before END_REQ, which
84 * is blocking the request channel (Exlusion Rule, see IEEE1666)
86 tlm::tlm_generic_payload *blockingRequest;
89 * Did another gem5 request arrive while currently blocked?
90 * This variable is needed when a retry should happen
92 bool needToSendRequestRetry;
95 * A response which has been asked to retry by gem5 and so is blocking
96 * the response channel
98 tlm::tlm_generic_payload *blockingResponse;
101 /** The gem5 Port slave interface */
102 Tick recvAtomic(PacketPtr packet);
103 void recvFunctional(PacketPtr packet);
104 bool recvTimingReq(PacketPtr packet);
105 bool recvTimingSnoopResp(PacketPtr packet);
106 void recvRespRetry();
107 void recvFunctionalSnoop(PacketPtr packet);
109 /** The TLM initiator interface */
110 tlm::tlm_sync_enum nb_transport_bw(tlm::tlm_generic_payload& trans,
111 tlm::tlm_phase& phase,
112 sc_core::sc_time& t);
114 void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
115 sc_dt::uint64 end_range);
118 SCSlavePort(const std::string &name_,
119 const std::string &systemc_name,
120 ExternalSlave &owner_);
122 static void registerPortHandler();
124 friend PayloadEvent<SCSlavePort>;
129 #endif // __SC_SLAVE_PORT_H__