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 base_bw_ = &base_socket_->get_export_base();
75 for (auto i : binders_bw_) {
78 }
79 }
80
82 dynamic_cast<tlm_utils::multi_target_base_if<TYPES> *>(obj);
83 if (multi_target_) {
84 binders_fw_ = multi_target_->get_binders();
85 base_fw_ = &base_socket_->get_export_base();
88 for (auto i : binders_fw_) {
89 ScExportConnection::keytype key = std::make_pair(i,
91 insertKey(key);
93 }
94 }
95 }
96 virtual void allProxiesInitialized() {
97 for (auto i : binders_bw_) {
98 ScExportConnection *connection =
100 if (connection) {
101 connection->insertKey(std::make_pair(i,
103 }
104 }
105 }
106 virtual void simulationStarted() {
109
110 for (auto b : binders_bw_)
112
113 for (auto f : binders_fw_) {
116 }
117
118 if (multi_initiator_) {
119 std::vector<tlm::tlm_fw_transport_if<TYPES> *> &sockets =
120 multi_initiator_->get_sockets();
121 for (auto s : sockets) {
124 }
125 }
126
127 if (multi_target_) {
128 std::map<unsigned int, tlm::tlm_bw_transport_if<TYPES> *> &binds =
129 multi_target_->get_multi_binds();
130 for (const auto &b : binds) {
132 b.second));
133 }
134 }
135
136 sc_core::sc_object *obj = dynamic_cast<sc_core::sc_object *>(
142 }
143 virtual void simulationEnded() {
144 }
145 virtual bool isTargetSocket() {
146 if (base_socket_) {
147 return dynamic_cast<tlm::tlm_fw_transport_if<TYPES> *>(
148 base_socket_->get_export_base().get_interface()) != NULL;
149 }
150
151 return false;
152 }
153 virtual void tool_controller_init(ToolController *controller) {
154 for (auto handler : all_handlers_)
155 handler->init(this, controller);
156 }
158 for (auto handler : all_handlers_) {
159 if (state == EMPTY)
160 handler->disable();
161 else
162 handler->enable();
163 }
164 }
166 typename std::vector<tlm_utils::callback_binder_bw<TYPES>* >::
167 iterator i;
168 for (i = binders_bw_.begin(); i != binders_bw_.end(); ++i) {
169 // the implicit cast triggered a segfault, because the object
170 // pointed to has been freed. Cast via void* to circumvent this,
171 // as all we need in the pair is the pointer address
172 ScExportConnection::keytype key = std::make_pair(
173 static_cast<sc_core::sc_interface *>(
174 static_cast<void*>(*i)), base_bw_typename_);
176 }
177 }
178
179 protected:
181 if (handler)
182 all_handlers_.push_back(handler);
183 }
184
185 std::string socket_name_;
186 tlm::tlm_base_socket_if *base_socket_;
187 sc_core::sc_export_base *base_bw_;
188 sc_core::sc_export_base *base_fw_;
189 const char *base_bw_typename_;
190 const char *base_fw_typename_;
191 std::vector<tlm_utils::callback_binder_bw<TYPES>* > binders_bw_;
192 std::vector<tlm_utils::callback_binder_fw<TYPES>* > binders_fw_;
193 std::vector<TlmHandlerInterface *> all_handlers_;
194 tlm_utils::multi_init_base_if<TYPES> *multi_initiator_;
195 tlm_utils::multi_target_base_if<TYPES> *multi_target_;
196};
197
198template <typename TYPES>
200 public tlm::tlm_fw_transport_if<TYPES> {
201 public:
202 typedef typename TYPES::tlm_payload_type transaction_type;
203 typedef typename TYPES::tlm_phase_type phase_type;
204 explicit ProxyInitiatorSocket(simics::ConfObjectRef o)
205 : ProxySocketBase<TYPES>(o) {}
206 virtual tlm::tlm_sync_enum nb_transport_fw(transaction_type &trans, // NOLINT
207 phase_type &phase, // NOLINT
208 sc_core::sc_time &t) { // NOLINT
210 return fw_if()->nb_transport_fw(trans, phase, t);
211 }
212 virtual void b_transport(transaction_type &trans, // NOLINT
213 sc_core::sc_time &t) { // NOLINT
215 invoker_.enqueue(this->base_socket_, &trans, &t);
216 }
217 virtual bool get_direct_mem_ptr(transaction_type &trans, // NOLINT
218 tlm::tlm_dmi &dmi_data) { // NOLINT
220 return fw_if()->get_direct_mem_ptr(trans, dmi_data);
221 }
222 virtual unsigned int transport_dbg(transaction_type &trans) { // NOLINT
223 Kernel(this->simulation()->context());
224 return fw_if()->transport_dbg(trans);
225 }
226 private:
227 tlm::tlm_fw_transport_if<TYPES> *fw_if() {
228 tlm::tlm_fw_transport_if<TYPES> *fw_if =
229 dynamic_cast<tlm::tlm_fw_transport_if<TYPES> *>(
230 this->base_socket_->get_port_base().get_interface());
231 assert(fw_if);
232 return fw_if;
233 }
235};
236
237template <typename TYPES>
238injection::BTransportInvoker<TYPES> ProxyInitiatorSocket<TYPES>::invoker_;
239
240template <typename TYPES>
241class ProxyTargetSocket : public ProxySocketBase<TYPES>,
242 public tlm::tlm_bw_transport_if<TYPES> {
243 public:
244 typedef typename TYPES::tlm_payload_type transaction_type;
245 typedef typename TYPES::tlm_phase_type phase_type;
246 explicit ProxyTargetSocket(simics::ConfObjectRef o)
247 : ProxySocketBase<TYPES>(o) {}
248
249 virtual tlm::tlm_sync_enum nb_transport_bw(transaction_type &trans, // NOLINT
250 phase_type &phase, // NOLINT
251 sc_core::sc_time &t) { // NOLINT
253 return bw_if()->nb_transport_bw(trans, phase, t);
254 }
255 virtual void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
256 sc_dt::uint64 end_range) {
258 bw_if()->invalidate_direct_mem_ptr(start_range, end_range);
259 }
260
261 private:
262 tlm::tlm_bw_transport_if<TYPES> *bw_if() {
263 tlm::tlm_bw_transport_if<TYPES> *bw_if =
264 dynamic_cast<tlm::tlm_bw_transport_if<TYPES> *>(
265 this->base_socket_->get_port_base().get_interface());
266 assert(bw_if);
267 return bw_if;
268 }
269};
270
271} // namespace awareness
272} // namespace systemc
273} // namespace simics
274
275#endif
static const char * get_typename(sc_export_base *object)
Definition: kernel_state_modifier.h:30
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:206
virtual unsigned int transport_dbg(transaction_type &trans)
Definition: proxy_socket.h:222
virtual bool get_direct_mem_ptr(transaction_type &trans, tlm::tlm_dmi &dmi_data)
Definition: proxy_socket.h:217
virtual void b_transport(transaction_type &trans, sc_core::sc_time &t)
Definition: proxy_socket.h:212
TYPES::tlm_phase_type phase_type
Definition: proxy_socket.h:203
ProxyInitiatorSocket(simics::ConfObjectRef o)
Definition: proxy_socket.h:204
TYPES::tlm_payload_type transaction_type
Definition: proxy_socket.h:202
Definition: proxy_socket.h:51
std::string socket_name_
Definition: proxy_socket.h:185
virtual bool isTargetSocket()
Definition: proxy_socket.h:145
void addHandler(TlmHandlerInterface *handler)
Definition: proxy_socket.h:180
std::vector< tlm_utils::callback_binder_fw< TYPES > * > binders_fw_
Definition: proxy_socket.h:192
sc_core::sc_export_base * base_bw_
Definition: proxy_socket.h:187
virtual void simulationStarted()
Definition: proxy_socket.h:106
virtual void init(sc_core::sc_object *obj, SimulationInterface *simulation)
Definition: proxy_socket.h:60
virtual void simulationEnded()
Definition: proxy_socket.h:143
std::vector< TlmHandlerInterface * > all_handlers_
Definition: proxy_socket.h:193
tlm_utils::multi_target_base_if< TYPES > * multi_target_
Definition: proxy_socket.h:195
ProxySocketBase(simics::ConfObjectRef o)
Definition: proxy_socket.h:56
virtual void tool_controller_init(ToolController *controller)
Definition: proxy_socket.h:153
const char * base_bw_typename_
Definition: proxy_socket.h:189
virtual void allProxiesInitialized()
Definition: proxy_socket.h:96
const char * base_fw_typename_
Definition: proxy_socket.h:190
tlm_utils::multi_init_base_if< TYPES > * multi_initiator_
Definition: proxy_socket.h:194
std::vector< tlm_utils::callback_binder_bw< TYPES > * > binders_bw_
Definition: proxy_socket.h:191
sc_core::sc_export_base * base_fw_
Definition: proxy_socket.h:188
virtual ~ProxySocketBase()
Definition: proxy_socket.h:165
tlm::tlm_base_socket_if * base_socket_
Definition: proxy_socket.h:186
TYPES types
Definition: proxy_socket.h:54
virtual void connection_list_updated(ConnectionListState state)
Definition: proxy_socket.h:157
Definition: proxy_socket_interface.h:23
Definition: proxy_socket.h:242
virtual void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
Definition: proxy_socket.h:255
TYPES::tlm_payload_type transaction_type
Definition: proxy_socket.h:244
TYPES::tlm_phase_type phase_type
Definition: proxy_socket.h:245
virtual tlm::tlm_sync_enum nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Definition: proxy_socket.h:249
ProxyTargetSocket(simics::ConfObjectRef o)
Definition: proxy_socket.h:246
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
void init(sc_core::sc_object *object, iface::SimulationInterface *simulation)
static void addBinderExport(keytype key, sc_core::sc_export_base *obj)
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:140
static TlmHandlerInterface * mPInitiatorFwSocketHandler(tlm::tlm_fw_transport_if< TYPES > *socket)
Definition: tlm_base_handler.h:169
static TlmHandlerInterface * targetBwSocketHandler(sc_core::sc_object *obj)
Definition: tlm_base_handler.h:154
static TlmHandlerInterface * mPInitiatorBwSocketHandler(tlm_utils::callback_binder_bw< TYPES > *cb)
Definition: tlm_base_handler.h:184
static TlmHandlerInterface * mPtargetBwSocketHandler(tlm::tlm_bw_transport_if< TYPES > *socket)
Definition: tlm_base_handler.h:213
static TlmHandlerInterface * initiatorFwSocketHandler(sc_core::sc_object *obj)
Definition: tlm_base_handler.h:112
static TlmHandlerInterface * mPTargetFwSocketHandler(tlm_utils::callback_binder_fw< TYPES > *cb)
Definition: tlm_base_handler.h:194
static TlmHandlerInterface * mPTargetBwSocketHandler(tlm_utils::callback_binder_fw< TYPES > *cb)
Definition: tlm_base_handler.h:204
static TlmHandlerInterface * mPInitiatorFwMpSocketHandler(tlm::tlm_fw_transport_if< TYPES > *socket)
Definition: tlm_base_handler.h:179
static TlmHandlerInterface * initiatorBwSocketHandler(sc_core::sc_object *obj)
Definition: tlm_base_handler.h:126
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: pci_bus_interface.h:24