SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
proxy_socket.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2015 Intel Corporation
5
6 This software and the related documents are Intel copyrighted materials, and
7 your use of them is governed by the express license under which they were
8 provided to you ("License"). Unless the License provides otherwise, you may
9 not use, modify, copy, publish, distribute, disclose or transmit this software
10 or the related documents without Intel's prior written permission.
11
12 This software and the related documents are provided as is, with no express or
13 implied warranties, other than those that are expressly stated in the License.
14*/
15
16#ifndef SIMICS_SYSTEMC_AWARENESS_PROXY_SOCKET_H
17#define SIMICS_SYSTEMC_AWARENESS_PROXY_SOCKET_H
18
19#include <tlm>
20#include <tlm_utils/multi_socket_bases.h>
21
22
34#include <deque>
35#include <map>
36#include <string>
37#include <utility>
38#include <vector>
39
40namespace simics {
41namespace systemc {
42namespace awareness {
43
44template <typename TYPES>
46 : public Proxy,
48 public ScExportConnection,
49 public ScPortConnection,
52
53 public:
54 typedef TYPES types;
55
56 explicit ProxySocketBase(simics::ConfObjectRef o)
57 : Proxy(o), ToolController(this), base_socket_(NULL), base_bw_(NULL),
59 multi_initiator_(nullptr), multi_target_(nullptr) {}
60 virtual void init(sc_core::sc_object *obj,
61 SimulationInterface *simulation) {
65 base_socket_ = dynamic_cast<tlm::tlm_base_socket_if *>(obj);
66 assert(base_socket_);
67
69 dynamic_cast<tlm_utils::multi_init_base_if<TYPES> *>(obj);
70 if (multi_initiator_) {
71 binders_bw_ = multi_initiator_->get_binders();
72#ifdef SYSTEMC_2_3_3
73 base_bw_ = &base_socket_->get_export_base();
74#elif defined SYSTEMC_2_3_4 || defined SYSTEMC_3_0_0
75 base_bw_ = const_cast<sc_core::sc_export_base *>(
76 &const_cast<const tlm::tlm_base_socket_if *>(
77 base_socket_)->get_base_export());
78#endif
81 for (auto i : binders_bw_) {
84 }
85 }
86
88 dynamic_cast<tlm_utils::multi_target_base_if<TYPES> *>(obj);
89 if (multi_target_) {
90 binders_fw_ = multi_target_->get_binders();
91#ifdef SYSTEMC_2_3_3
92 base_fw_ = &base_socket_->get_export_base();
93#elif defined SYSTEMC_2_3_4 || defined SYSTEMC_3_0_0
94 base_fw_ = const_cast<sc_core::sc_export_base *>(
95 &const_cast<const tlm::tlm_base_socket_if *>(
96 base_socket_)->get_base_export());
97#endif
100 for (auto i : binders_fw_) {
101 ScExportConnection::keytype key = std::make_pair(i,
103 insertKey(key);
105 }
106 }
107 }
108 virtual void allProxiesInitialized() {
109 for (auto i : binders_bw_) {
110 ScExportConnection *connection =
112 if (connection) {
113 connection->insertKey(std::make_pair(i,
115 }
116 }
117 }
118 virtual void simulationStarted() {
121
122 for (auto b : binders_bw_)
124
125 for (auto f : binders_fw_) {
128 }
129
130 if (multi_initiator_) {
131 std::vector<tlm::tlm_fw_transport_if<TYPES> *> &sockets =
132 multi_initiator_->get_sockets();
133 for (auto s : sockets) {
136 }
137 }
138
139 if (multi_target_) {
140 std::map<unsigned int, tlm::tlm_bw_transport_if<TYPES> *> &binds =
141 multi_target_->get_multi_binds();
142 for (const auto &b : binds) {
144 b.second));
145 }
146 }
147
148 sc_core::sc_object *obj = dynamic_cast<sc_core::sc_object *>(
154 }
155 virtual void simulationEnded() {
156 }
157 virtual bool isTargetSocket() {
158 if (base_socket_) {
159 const sc_core::sc_interface *iface = nullptr;
160#ifdef SYSTEMC_2_3_3
161 iface = base_socket_->get_export_base().get_interface();
162#elif defined SYSTEMC_2_3_4 || defined SYSTEMC_3_0_0
163 iface = const_cast<const tlm::tlm_base_socket_if *>(
164 base_socket_)->get_base_export().get_interface();
165#endif
166 return dynamic_cast<const tlm::tlm_fw_transport_if<TYPES> *>(
167 iface) != nullptr;
168 }
169
170 return false;
171 }
172 virtual void tool_controller_init(ToolController *controller) {
173 for (auto handler : all_handlers_)
174 handler->init(this, controller);
175 }
177 for (auto handler : all_handlers_) {
178 if (state == EMPTY)
179 handler->disable();
180 else
181 handler->enable();
182 }
183 }
185 typename std::vector<tlm_utils::callback_binder_bw<TYPES>* >::
186 iterator i;
187 for (i = binders_bw_.begin(); i != binders_bw_.end(); ++i) {
188 // the implicit cast triggered a segfault, because the object
189 // pointed to has been freed. Cast via void* to circumvent this,
190 // as all we need in the pair is the pointer address
191 ScExportConnection::keytype key = std::make_pair(
192 static_cast<sc_core::sc_interface *>(
193 static_cast<void*>(*i)), base_bw_typename_);
195 }
196 }
197
198 protected:
200 if (handler)
201 all_handlers_.push_back(handler);
202 }
203
204 std::string socket_name_;
205 tlm::tlm_base_socket_if *base_socket_;
206 sc_core::sc_export_base *base_bw_;
207 sc_core::sc_export_base *base_fw_;
208 const char *base_bw_typename_;
209 const char *base_fw_typename_;
210 std::vector<tlm_utils::callback_binder_bw<TYPES>* > binders_bw_;
211 std::vector<tlm_utils::callback_binder_fw<TYPES>* > binders_fw_;
212 std::vector<TlmHandlerInterface *> all_handlers_;
213 tlm_utils::multi_init_base_if<TYPES> *multi_initiator_;
214 tlm_utils::multi_target_base_if<TYPES> *multi_target_;
215};
216
217template <typename TYPES>
219 public tlm::tlm_fw_transport_if<TYPES> {
220 public:
221 typedef typename TYPES::tlm_payload_type transaction_type;
222 typedef typename TYPES::tlm_phase_type phase_type;
223 explicit ProxyInitiatorSocket(simics::ConfObjectRef o)
224 : ProxySocketBase<TYPES>(o) {}
225 virtual tlm::tlm_sync_enum nb_transport_fw(transaction_type &trans, // NOLINT
226 phase_type &phase, // NOLINT
227 sc_core::sc_time &t) { // NOLINT
229 return fw_if()->nb_transport_fw(trans, phase, t);
230 }
231 virtual void b_transport(transaction_type &trans, // NOLINT
232 sc_core::sc_time &t) { // NOLINT
234 invoker_.enqueue(this->base_socket_, &trans, &t);
235 }
236 virtual bool get_direct_mem_ptr(transaction_type &trans, // NOLINT
237 tlm::tlm_dmi &dmi_data) { // NOLINT
239 return fw_if()->get_direct_mem_ptr(trans, dmi_data);
240 }
241 virtual unsigned int transport_dbg(transaction_type &trans) { // NOLINT
242 Kernel(this->simulation()->context());
243 return fw_if()->transport_dbg(trans);
244 }
245 private:
246 tlm::tlm_fw_transport_if<TYPES> *fw_if() {
247#ifdef SYSTEMC_2_3_3
248 tlm::tlm_fw_transport_if<TYPES> *fw_if =
249 dynamic_cast<tlm::tlm_fw_transport_if<TYPES> *>(
250 this->base_socket_->get_port_base().get_interface());
251#elif defined SYSTEMC_2_3_4 || defined SYSTEMC_3_0_0
252 tlm::tlm_fw_transport_if<TYPES> *fw_if =
253 dynamic_cast<tlm::tlm_fw_transport_if<TYPES> *>(
254 const_cast<sc_core::sc_interface *>(
255 const_cast<const tlm::tlm_base_socket_if *>(
256 this->base_socket_)->get_base_port().get_interface()));
257#endif
258 assert(fw_if);
259 return fw_if;
260 }
262};
263
264template <typename TYPES>
265injection::BTransportInvoker<TYPES> ProxyInitiatorSocket<TYPES>::invoker_;
266
267template <typename TYPES>
268class ProxyTargetSocket : public ProxySocketBase<TYPES>,
269 public tlm::tlm_bw_transport_if<TYPES> {
270 public:
271 typedef typename TYPES::tlm_payload_type transaction_type;
272 typedef typename TYPES::tlm_phase_type phase_type;
273 explicit ProxyTargetSocket(simics::ConfObjectRef o)
274 : ProxySocketBase<TYPES>(o) {}
275
276 virtual tlm::tlm_sync_enum nb_transport_bw(transaction_type &trans, // NOLINT
277 phase_type &phase, // NOLINT
278 sc_core::sc_time &t) { // NOLINT
280 return bw_if()->nb_transport_bw(trans, phase, t);
281 }
282 virtual void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
283 sc_dt::uint64 end_range) {
285 bw_if()->invalidate_direct_mem_ptr(start_range, end_range);
286 }
287
288 private:
289 tlm::tlm_bw_transport_if<TYPES> *bw_if() {
290#ifdef SYSTEMC_2_3_3
291 tlm::tlm_bw_transport_if<TYPES> *bw_if =
292 dynamic_cast<tlm::tlm_bw_transport_if<TYPES> *>(
293 this->base_socket_->get_port_base().get_interface());
294#elif defined SYSTEMC_2_3_4 || defined SYSTEMC_3_0_0
295 tlm::tlm_bw_transport_if<TYPES> *bw_if =
296 dynamic_cast<tlm::tlm_bw_transport_if<TYPES> *>(
297 const_cast<sc_core::sc_interface *>(
298 const_cast<const tlm::tlm_base_socket_if *>(
299 this->base_socket_)->get_base_port().get_interface()));
300#endif
301 assert(bw_if);
302 return bw_if;
303 }
304};
305
306} // namespace awareness
307} // namespace systemc
308} // namespace simics
309
310#endif
static const char * get_typename(sc_export_base *object)
Definition: kernel_state_modifier.h:33
Utility class that reset the current context to the previous one upon leaving current scope.
Definition: kernel.h:29
virtual sc_core::sc_simcontext * context() const
Definition: simulation_interface_proxy.h:46
virtual tlm::tlm_sync_enum nb_transport_fw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Definition: proxy_socket.h:225
virtual unsigned int transport_dbg(transaction_type &trans)
Definition: proxy_socket.h:241
virtual bool get_direct_mem_ptr(transaction_type &trans, tlm::tlm_dmi &dmi_data)
Definition: proxy_socket.h:236
virtual void b_transport(transaction_type &trans, sc_core::sc_time &t)
Definition: proxy_socket.h:231
TYPES::tlm_phase_type phase_type
Definition: proxy_socket.h:222
ProxyInitiatorSocket(simics::ConfObjectRef o)
Definition: proxy_socket.h:223
TYPES::tlm_payload_type transaction_type
Definition: proxy_socket.h:221
Definition: proxy_socket.h:51
std::string socket_name_
Definition: proxy_socket.h:204
virtual bool isTargetSocket()
Definition: proxy_socket.h:157
void addHandler(TlmHandlerInterface *handler)
Definition: proxy_socket.h:199
std::vector< tlm_utils::callback_binder_fw< TYPES > * > binders_fw_
Definition: proxy_socket.h:211
sc_core::sc_export_base * base_bw_
Definition: proxy_socket.h:206
virtual void simulationStarted()
Definition: proxy_socket.h:118
virtual void init(sc_core::sc_object *obj, SimulationInterface *simulation)
Definition: proxy_socket.h:60
virtual void simulationEnded()
Definition: proxy_socket.h:155
std::vector< TlmHandlerInterface * > all_handlers_
Definition: proxy_socket.h:212
tlm_utils::multi_target_base_if< TYPES > * multi_target_
Definition: proxy_socket.h:214
ProxySocketBase(simics::ConfObjectRef o)
Definition: proxy_socket.h:56
virtual void tool_controller_init(ToolController *controller)
Definition: proxy_socket.h:172
const char * base_bw_typename_
Definition: proxy_socket.h:208
virtual void allProxiesInitialized()
Definition: proxy_socket.h:108
const char * base_fw_typename_
Definition: proxy_socket.h:209
tlm_utils::multi_init_base_if< TYPES > * multi_initiator_
Definition: proxy_socket.h:213
std::vector< tlm_utils::callback_binder_bw< TYPES > * > binders_bw_
Definition: proxy_socket.h:210
sc_core::sc_export_base * base_fw_
Definition: proxy_socket.h:207
virtual ~ProxySocketBase()
Definition: proxy_socket.h:184
tlm::tlm_base_socket_if * base_socket_
Definition: proxy_socket.h:205
TYPES types
Definition: proxy_socket.h:54
virtual void connection_list_updated(ConnectionListState state)
Definition: proxy_socket.h:176
Definition: proxy_socket_interface.h:23
Definition: proxy_socket.h:269
virtual void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
Definition: proxy_socket.h:282
TYPES::tlm_payload_type transaction_type
Definition: proxy_socket.h:271
TYPES::tlm_phase_type phase_type
Definition: proxy_socket.h:272
virtual tlm::tlm_sync_enum nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Definition: proxy_socket.h:276
ProxyTargetSocket(simics::ConfObjectRef o)
Definition: proxy_socket.h:273
Definition: proxy.h:41
virtual void init(sc_core::sc_object *obj, iface::SimulationInterface *simulation)
virtual iface::SimulationInterface * simulation()
static ProxyInterface * findProxy(sc_core::sc_object *obj)
Definition: sc_export_connection.h:40
static void removeBinderExport(keytype key, sc_core::sc_export_base *obj)
std::pair< sc_core::sc_interface *, std::string > keytype
Definition: sc_export_connection.h:42
static void addBinderExport(const keytype &key, sc_core::sc_export_base *obj)
void init(sc_core::sc_object *object, iface::SimulationInterface *simulation)
Definition: sc_port_connection.h:39
void init(sc_core::sc_object *object, iface::SimulationInterface *simulation)
virtual std::vector< conf_object_t * > port_to_proxies()
static TlmHandlerInterface * targetFwSocketHandler(sc_core::sc_object *obj)
Definition: tlm_base_handler.h:158
static TlmHandlerInterface * mPInitiatorFwSocketHandler(tlm::tlm_fw_transport_if< TYPES > *socket)
Definition: tlm_base_handler.h:199
static TlmHandlerInterface * targetBwSocketHandler(sc_core::sc_object *obj)
Definition: tlm_base_handler.h:178
static TlmHandlerInterface * mPInitiatorBwSocketHandler(tlm_utils::callback_binder_bw< TYPES > *cb)
Definition: tlm_base_handler.h:214
static TlmHandlerInterface * mPtargetBwSocketHandler(tlm::tlm_bw_transport_if< TYPES > *socket)
Definition: tlm_base_handler.h:243
static TlmHandlerInterface * initiatorFwSocketHandler(sc_core::sc_object *obj)
Definition: tlm_base_handler.h:118
static TlmHandlerInterface * mPTargetFwSocketHandler(tlm_utils::callback_binder_fw< TYPES > *cb)
Definition: tlm_base_handler.h:224
static TlmHandlerInterface * mPTargetBwSocketHandler(tlm_utils::callback_binder_fw< TYPES > *cb)
Definition: tlm_base_handler.h:234
static TlmHandlerInterface * mPInitiatorFwMpSocketHandler(tlm::tlm_fw_transport_if< TYPES > *socket)
Definition: tlm_base_handler.h:209
static TlmHandlerInterface * initiatorBwSocketHandler(sc_core::sc_object *obj)
Definition: tlm_base_handler.h:138
Definition: tlm_handler_interface.h:26
Definition: b_transport_invoker.h:31
Definition: tool_controller.h:74
ConnectionListState
Definition: tool_controller.h:76
@ EMPTY
Definition: tool_controller.h:77
Definition: adapter.h:80