2 * Copyright 2018 Google, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef __SYSTEMC_TLM_PORT_WRAPPER_HH__
29 #define __SYSTEMC_TLM_PORT_WRAPPER_HH__
31 #include "base/logging.hh"
32 #include "sim/port.hh"
33 #include "systemc/ext/tlm_core/2/sockets/sockets.hh"
38 template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
39 sc_core::sc_port_policy POL>
40 class TlmInitiatorBaseWrapper;
42 template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
43 sc_core::sc_port_policy POL>
44 class TlmTargetBaseWrapper;
46 template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
47 sc_core::sc_port_policy POL>
48 class TlmInitiatorBaseWrapper : public ::Port
51 typedef tlm::tlm_base_initiator_socket<BUSWIDTH, FW_IF, BW_IF, N, POL>
53 typedef typename InitiatorSocket::base_target_socket_type TargetSocket;
54 typedef TlmTargetBaseWrapper<BUSWIDTH, FW_IF, BW_IF, N, POL> TargetWrapper;
56 InitiatorSocket &initiator() { return _initiator; }
58 TlmInitiatorBaseWrapper(
59 InitiatorSocket &i, const std::string &_name, PortID _id) :
60 Port(_name, _id), _initiator(i)
64 bind(::Port &peer) override
66 auto *target = dynamic_cast<TargetWrapper *>(&peer);
67 fatal_if(!target, "Attempt to bind TLM initiator socket %s to "
68 "incompatible port %s.", name(), peer.name());
70 initiator().bind(target->target());
77 panic("TLM sockets can't be unbound.");
81 InitiatorSocket &_initiator;
84 template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
85 sc_core::sc_port_policy POL>
86 class TlmTargetBaseWrapper : public ::Port
89 typedef tlm::tlm_base_target_socket<BUSWIDTH, FW_IF, BW_IF, N, POL>
92 TargetSocket &target() { return _target; }
94 TlmTargetBaseWrapper(TargetSocket &t, const std::string &_name,
96 Port(_name, _id), _target(t)
100 bind(::Port &peer) override
102 // Ignore attempts to bind a target socket. The initiator will
110 panic("TLM sockets can't be unbound.");
114 TargetSocket &_target;
117 template <unsigned int BUSWIDTH=32,
118 typename TYPES=tlm::tlm_base_protocol_types, int N=1,
119 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
120 using TlmInitiatorWrapper =
121 TlmInitiatorBaseWrapper<BUSWIDTH, tlm::tlm_fw_transport_if<TYPES>,
122 tlm::tlm_bw_transport_if<TYPES>, N, POL>;
124 template <unsigned int BUSWIDTH=32,
125 typename TYPES=tlm::tlm_base_protocol_types, int N=1,
126 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
127 using TlmTargetWrapper =
128 TlmTargetBaseWrapper<BUSWIDTH, tlm::tlm_fw_transport_if<TYPES>,
129 tlm::tlm_bw_transport_if<TYPES>, N, POL>;
131 } // namespace sc_gem5
133 #endif //__SYSTEMC_TLM_PORT_WRAPPER_HH__