1/* 2 * Copyright 2018 Google, Inc. 3 * 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. 14 * 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. 26 * 27 * Authors: Gabe Black 28 */ 29 30#ifndef __SYSTEMC_TLM_PORT_WRAPPER_HH__ 31#define __SYSTEMC_TLM_PORT_WRAPPER_HH__ 32 33#include "base/logging.hh" 34#include "sim/port.hh" 35#include "systemc/ext/tlm_core/2/sockets/sockets.hh" 36 37namespace sc_gem5 38{ 39
| 1/* 2 * Copyright 2018 Google, Inc. 3 * 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. 14 * 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. 26 * 27 * Authors: Gabe Black 28 */ 29 30#ifndef __SYSTEMC_TLM_PORT_WRAPPER_HH__ 31#define __SYSTEMC_TLM_PORT_WRAPPER_HH__ 32 33#include "base/logging.hh" 34#include "sim/port.hh" 35#include "systemc/ext/tlm_core/2/sockets/sockets.hh" 36 37namespace sc_gem5 38{ 39
|
40template <unsigned int BUSWIDTH=32, 41 typename TYPES=tlm::tlm_base_protocol_types, int N=1, 42 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 43class TlmInitiatorWrapper;
| 40template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N, 41 sc_core::sc_port_policy POL> 42class TlmInitiatorBaseWrapper;
|
44
| 43
|
45template <unsigned int BUSWIDTH=32, 46 typename TYPES=tlm::tlm_base_protocol_types, int N=1, 47 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 48class TlmTargetWrapper;
| 44template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N, 45 sc_core::sc_port_policy POL> 46class TlmTargetBaseWrapper;
|
49
| 47
|
50template <unsigned int BUSWIDTH, typename TYPES, int N,
| 48template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
|
51 sc_core::sc_port_policy POL>
| 49 sc_core::sc_port_policy POL>
|
52class TlmInitiatorWrapper : public ::Port
| 50class TlmInitiatorBaseWrapper : public ::Port
|
53{ 54 public:
| 51{ 52 public:
|
55 typedef tlm::tlm_base_initiator_socket56 tlm::tlm_fw_transport_if<TYPES>, 57 tlm::tlm_bw_transport_if<TYPES>, N, POL>
| 53 typedef tlm::tlm_base_initiator_socket<BUSWIDTH, FW_IF, BW_IF, N, POL>
|
58 InitiatorSocket; 59 typedef typename InitiatorSocket::base_target_socket_type TargetSocket;
| 54 InitiatorSocket; 55 typedef typename InitiatorSocket::base_target_socket_type TargetSocket;
|
60 typedef TlmTargetWrapper<BUSWIDTH, TYPES, N, POL> TargetWrapper;
| 56 typedef TlmTargetBaseWrapper<BUSWIDTH, FW_IF, BW_IF, N, POL> TargetWrapper;
|
61 62 InitiatorSocket &initiator() { return _initiator; } 63
| 57 58 InitiatorSocket &initiator() { return _initiator; } 59
|
64 TlmInitiatorWrapper(
| 60 TlmInitiatorBaseWrapper(
|
65 InitiatorSocket &i, const std::string &_name, PortID _id) : 66 Port(_name, _id), _initiator(i) 67 {} 68 69 void 70 bind(::Port &peer) override 71 { 72 auto *target = dynamic_cast<TargetWrapper *>(&peer); 73 fatal_if(!target, "Attempt to bind TLM initiator socket %s to " 74 "incompatible port %s.", name(), peer.name()); 75 76 initiator().bind(target->target()); 77 Port::bind(peer); 78 } 79 80 void 81 unbind() override 82 { 83 panic("TLM sockets can't be unbound."); 84 } 85 86 private: 87 InitiatorSocket &_initiator; 88}; 89
| 61 InitiatorSocket &i, const std::string &_name, PortID _id) : 62 Port(_name, _id), _initiator(i) 63 {} 64 65 void 66 bind(::Port &peer) override 67 { 68 auto *target = dynamic_cast<TargetWrapper *>(&peer); 69 fatal_if(!target, "Attempt to bind TLM initiator socket %s to " 70 "incompatible port %s.", name(), peer.name()); 71 72 initiator().bind(target->target()); 73 Port::bind(peer); 74 } 75 76 void 77 unbind() override 78 { 79 panic("TLM sockets can't be unbound."); 80 } 81 82 private: 83 InitiatorSocket &_initiator; 84}; 85
|
90template <unsigned int BUSWIDTH, typename TYPES, int N,
| 86template <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
|
91 sc_core::sc_port_policy POL>
| 87 sc_core::sc_port_policy POL>
|
92class TlmTargetWrapper : public ::Port
| 88class TlmTargetBaseWrapper : public ::Port
|
93{ 94 public:
| 89{ 90 public:
|
95 typedef tlm::tlm_base_target_socket96 tlm::tlm_fw_transport_if<TYPES>, 97 tlm::tlm_bw_transport_if<TYPES>, N, POL>
| 91 typedef tlm::tlm_base_target_socket<BUSWIDTH, FW_IF, BW_IF, N, POL>
|
98 TargetSocket; 99 100 TargetSocket &target() { return _target; } 101
| 92 TargetSocket; 93 94 TargetSocket &target() { return _target; } 95
|
102 TlmTargetWrapper(TargetSocket &t, const std::string &_name, PortID _id) :
| 96 TlmTargetBaseWrapper(TargetSocket &t, const std::string &_name, 97 PortID _id) :
|
103 Port(_name, _id), _target(t) 104 {} 105 106 void 107 bind(::Port &peer) override 108 { 109 // Ignore attempts to bind a target socket. The initiator will 110 // handle it. 111 Port::bind(peer); 112 } 113 114 void 115 unbind() override 116 { 117 panic("TLM sockets can't be unbound."); 118 } 119 120 private: 121 TargetSocket &_target; 122}; 123
| 98 Port(_name, _id), _target(t) 99 {} 100 101 void 102 bind(::Port &peer) override 103 { 104 // Ignore attempts to bind a target socket. The initiator will 105 // handle it. 106 Port::bind(peer); 107 } 108 109 void 110 unbind() override 111 { 112 panic("TLM sockets can't be unbound."); 113 } 114 115 private: 116 TargetSocket &_target; 117}; 118
|
| 119template <unsigned int BUSWIDTH=32, 120 typename TYPES=tlm::tlm_base_protocol_types, int N=1, 121 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 122using TlmInitiatorWrapper = 123 TlmInitiatorBaseWrapper<BUSWIDTH, tlm::tlm_fw_transport_if<TYPES>, 124 tlm::tlm_bw_transport_if<TYPES>, N, POL>; 125 126template <unsigned int BUSWIDTH=32, 127 typename TYPES=tlm::tlm_base_protocol_types, int N=1, 128 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 129using TlmTargetWrapper = 130 TlmTargetBaseWrapper<BUSWIDTH, tlm::tlm_fw_transport_if<TYPES>, 131 tlm::tlm_bw_transport_if<TYPES>, N, POL>; 132
|
124} // namespace sc_gem5 125 126#endif //__SYSTEMC_TLM_PORT_WRAPPER_HH__
| 133} // namespace sc_gem5 134 135#endif //__SYSTEMC_TLM_PORT_WRAPPER_HH__
|