a42532cad9c5bc30571b8467a163095bebf6937a
[gem5.git] / util / tlm / sc_slave_port.hh
1 /*
2 * Copyright (c) 2015, University of Kaiserslautern
3 * Copyright (c) 2016, Dresden University of Technology (TU Dresden)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
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.
16 *
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.
20 *
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.
32 *
33 * Authors: Matthias Jung
34 * Christian Menard
35 */
36
37 #ifndef __SC_SLAVE_PORT_HH__
38 #define __SC_SLAVE_PORT_HH__
39
40 #include <tlm_utils/simple_initiator_socket.h>
41
42 #include <map>
43 #include <systemc>
44 #include <tlm>
45
46 #include "mem/external_slave.hh"
47 #include "sc_mm.hh"
48 #include "sc_module.hh"
49 #include "sc_peq.hh"
50
51 namespace Gem5SystemC
52 {
53 /**
54 * Test that gem5 is at the same time as SystemC
55 */
56 #define CAUGHT_UP do { \
57 assert(curTick() == sc_core::sc_time_stamp().value()); \
58 } while (0)
59
60 /**
61 * This is a gem5 slave port that translates gem5 packets to TLM transactions.
62 *
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.
69 */
70 class SCSlavePort : public tlm::tlm_initiator_socket<>,
71 public tlm::tlm_bw_transport_if<>,
72 public ExternalSlave::Port
73 {
74 public:
75 SCSlavePort &iSocket;
76
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);
81
82 /**
83 * A transaction after BEGIN_REQ has been sent but before END_REQ, which
84 * is blocking the request channel (Exlusion Rule, see IEEE1666)
85 */
86 tlm::tlm_generic_payload *blockingRequest;
87
88 /**
89 * Did another gem5 request arrive while currently blocked?
90 * This variable is needed when a retry should happen
91 */
92 bool needToSendRequestRetry;
93
94 /**
95 * A response which has been asked to retry by gem5 and so is blocking
96 * the response channel
97 */
98 tlm::tlm_generic_payload *blockingResponse;
99
100 protected:
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);
108
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);
113
114 void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
115 sc_dt::uint64 end_range);
116
117 public:
118 SCSlavePort(const std::string &name_,
119 const std::string &systemc_name,
120 ExternalSlave &owner_);
121
122 static void registerPortHandler();
123
124 friend PayloadEvent<SCSlavePort>;
125 };
126
127 }
128
129 #endif // __SC_SLAVE_PORT_H__