SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
gasket_factory.h
Go to the documentation of this file.
1/*
2 © 2013 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_TLM2SIMICS_GASKET_FACTORY_H
15#define SIMICS_SYSTEMC_TLM2SIMICS_GASKET_FACTORY_H
16
17
18#include <tlm_utils/multi_passthrough_initiator_socket.h>
19
23
24#include <algorithm>
25#include <string>
26
27namespace simics {
28namespace systemc {
29namespace tlm2simics {
30
31namespace internal {
32
33template<unsigned int BUSWIDTH, typename TYPES>
34static Gasket<BUSWIDTH, TYPES> *createGasket(
35 const std::string& socket_name,
36 const simics::ConfObjectRef &simics_obj) {
37 std::string name = "gasket_" + socket_name;
38 std::replace(name.begin(), name.end(), '.', '_');
39
40 const char* char_name = name.c_str();
41 if (sc_core::sc_find_object(char_name))
42 char_name = sc_core::sc_gen_unique_name(char_name);
43
44 // The raw pointer is eventually managed by shared_ptr
45 return new Gasket<BUSWIDTH, TYPES>(char_name, simics_obj);
46}
47} // namespace internal
48
51
53template<unsigned int BUSWIDTH, typename TYPES,
54 int N, sc_core::sc_port_policy POL>
55static GasketInterface::Ptr createGasket(
56 tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL> *target_socket,
57 const simics::ConfObjectRef &simics_obj) {
58 FATAL_ERROR_IF(target_socket->name() == NULL,
59 "target socket not fully initialized, name missing");
60 auto gasket = internal::createGasket<BUSWIDTH, TYPES>(
61 target_socket->name(), simics_obj);
62 gasket->bind(*target_socket);
63 return GasketInterface::Ptr(gasket);
64}
65
67template<unsigned int BUSWIDTH, typename TYPES,
68 int N, sc_core::sc_port_policy POL>
69static GasketInterface::Ptr createGasket(
70 tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL> *initiator_socket,
71 const simics::ConfObjectRef &simics_obj) {
72 FATAL_ERROR_IF(initiator_socket->name() == NULL,
73 "initiator socket not fully initialized, name missing");
74 auto gasket = internal::createGasket<BUSWIDTH, TYPES>(
75 initiator_socket->name(), simics_obj);
76 gasket->bind(*initiator_socket);
77 return GasketInterface::Ptr(gasket);
78}
79
82template<unsigned int BUSWIDTH, typename TYPES,
83 int N, sc_core::sc_port_policy POL>
84static GasketInterface::Ptr createMultiGasket(
85 tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL> *initiator_socket,
86 const simics::ConfObjectRef &simics_obj) {
87 FATAL_ERROR_IF(initiator_socket->name() == NULL,
88 "initiator socket not fully initialized, name missing");
89 std::string name = "gasket_";
90 name += initiator_socket->name();
91 std::replace(name.begin(), name.end(), '.', '_');
92
93 const char* char_name = name.c_str();
94 if (sc_core::sc_find_object(char_name))
95 char_name = sc_core::sc_gen_unique_name(char_name);
96
98 initiator_socket, char_name, simics_obj);
99}
100
103template<typename MODULE, unsigned int BUSWIDTH, typename TYPES,
104 unsigned int N, sc_core::sc_port_policy POL>
105static GasketInterface::Ptr createGasket(
106 tlm_utils::multi_passthrough_initiator_socket<
107 MODULE, BUSWIDTH, TYPES, N, POL> *initiator_socket,
108 const simics::ConfObjectRef &simics_obj) {
109 FATAL_ERROR_IF(initiator_socket->name() == NULL,
110 "initiator socket not fully initialized, name missing");
111 auto gasket = internal::createGasket<BUSWIDTH, TYPES>(
112 initiator_socket->name(), simics_obj);
113 gasket->bind(*initiator_socket);
114 return GasketInterface::Ptr(gasket);
115}
116
118 const simics::ConfObjectRef &simics_obj);
119
121 public:
123 virtual GasketInterface::Ptr create(sc_core::sc_object *object,
124 const ConfObjectRef &simics_obj) = 0;
125};
126
127template <unsigned int BUSWIDTH, typename TYPES, int N = 1,
128 sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
129class GasketFactory : public Registrant<GasketFactoryInterface> {
130 public:
131 typedef tlm::tlm_base_initiator_socket<BUSWIDTH,
132 tlm::tlm_fw_transport_if<TYPES>,
133 tlm::tlm_bw_transport_if<TYPES>,
134 N, POL> Socket;
135
136 GasketInterface::Ptr create(sc_core::sc_object *object,
137 const ConfObjectRef &simics_obj) override {
138 Socket *socket = dynamic_cast<Socket *>(object);
139 if (!socket)
140 return NULL;
141
142 auto gasket = internal::createGasket<BUSWIDTH, TYPES>(
143 socket->name(), simics_obj);
144 gasket->bind(*socket);
145 return GasketInterface::Ptr(gasket);
146 }
147};
148
150
151} // namespace tlm2simics
152} // namespace systemc
153} // namespace simics
154
155#endif
Definition: registry.h:86
static GasketInterface::Ptr bind(tlm::tlm_initiator_socket< BUSWIDTH, TYPES, N, POL > *socket, const char *name, const simics::ConfObjectRef &simics_obj)
Definition: gasket_dispatcher.h:73
virtual ~GasketFactoryInterface()
Definition: gasket_factory.h:122
virtual GasketInterface::Ptr create(sc_core::sc_object *object, const ConfObjectRef &simics_obj)=0
Definition: gasket_factory.h:129
GasketInterface::Ptr create(sc_core::sc_object *object, const ConfObjectRef &simics_obj) override
Definition: gasket_factory.h:136
tlm::tlm_base_initiator_socket< BUSWIDTH, tlm::tlm_fw_transport_if< TYPES >, tlm::tlm_bw_transport_if< TYPES >, N, POL > Socket
Definition: gasket_factory.h:134
std::shared_ptr< GasketInterface > Ptr
Definition: gasket_interface.h:30
Implements core functionality for receiving a TLM2 transaction over a socket.
Definition: gasket.h:45
GasketInterface::Ptr createGasketByName(std::string socket_name, const simics::ConfObjectRef &simics_obj)
Definition: adapter.h:79