gem5  v20.1.0.0
multi_passthrough_initiator_socket.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 #ifndef __SYSTEMC_EXT_TLM_UTILS_MULTI_PASSTHROUGH_INITIATOR_SOCKET_H__
20 #define __SYSTEMC_EXT_TLM_UTILS_MULTI_PASSTHROUGH_INITIATOR_SOCKET_H__
21 
22 #include "tlm_utils/multi_socket_bases.h"
23 
24 namespace tlm_utils
25 {
26 
27 /*
28 This class implements a trivial multi initiator socket.
29 The triviality refers to the fact that the socket does not
30 do blocking to non-blocking or non-blocking to blocking conversions.
31 
32 It allows to connect multiple targets to this socket.
33 The user has to register callbacks for the bw interface methods
34 he likes to use. The callbacks are basically equal to the bw interface
35 methods but carry an additional integer that indicates to which
36 index of this socket the calling target is connected.
37 */
38 template <typename MODULE, unsigned int BUSWIDTH=32,
39  typename TYPES=tlm::tlm_base_protocol_types, unsigned int N=0,
41 class multi_passthrough_initiator_socket :
42  public multi_init_base< BUSWIDTH, TYPES, N, POL>
43 {
44  public:
45 
46  //typedefs
47  // tlm 2.0 types for nb_transport
48  typedef typename TYPES::tlm_payload_type transaction_type;
49  typedef typename TYPES::tlm_phase_type phase_type;
51 
52  // typedefs to keep the fn ptr notations short
53  typedef sync_enum_type (MODULE::*nb_cb)(
55  typedef void (MODULE::*dmi_cb)(int, sc_dt::uint64, sc_dt::uint64);
56 
57  typedef multi_init_base<BUSWIDTH, TYPES, N, POL> base_type;
58 
59  typedef typename base_type::base_target_socket_type
61 
62  static const char *
63  default_name()
64  {
66  "multi_passthrough_initiator_socket");
67  }
68 
70  const char *name=default_name()) :
71  base_type(name), m_hierarch_bind(nullptr), m_beoe_disabled(false),
72  m_dummy(this, 42)
73  {}
74 
76  {
77  // Clean up everything allocated by 'new'.
78  for (unsigned int i = 0; i < m_binders.size(); i++)
79  delete m_binders[i];
80  }
81 
82  // Register callback for nb transport of bw interface.
83  void
86  {
87  // Warn if there already is a callback.
88  if (m_nb_f.is_valid()) {
89  display_warning("NBTransport_bw callback already registered.");
90  return;
91  }
92 
93  // Set the functor.
94  m_nb_f.set_function(mod, cb);
95  }
96 
97  // Register callback for dmi function of bw interface.
98  void
99  register_invalidate_direct_mem_ptr(MODULE *mod, void (MODULE::*cb)(
101  {
102  // Warn if there already is a callback.
103  if (m_dmi_f.is_valid()) {
104  display_warning("InvalidateDMI callback already registered.");
105  return;
106  }
107 
108  // Set the functor.
109  m_dmi_f.set_function(mod, cb);
110  }
111 
112  // Override virtual functions of the tlm_initiator_socket:
113  // this function is called whenever an sc_port (as part of a target socket)
114  // wants to bind to the export of the underlying tlm_initiator_socket.
115  // At this time a callback binder is created an returned to the sc_port
116  // of the target socket, so that it binds to the callback binder.
119  {
120  m_binders.push_back(
121  new callback_binder_bw<TYPES>(this, m_binders.size()));
122  return *m_binders[m_binders.size() - 1];
123  }
124 
125  // Const overload not allowed for multi-sockets.
126  virtual const tlm::tlm_bw_transport_if<TYPES> &
127  get_base_interface() const
128  {
129  display_error("'get_base_interface()'"
130  " const not allowed for multi-sockets.");
132  }
133 
134  // Override virtual functions of the tlm_initiator_socket:
135  // This function is called whenever an sc_export (as part of a initiator
136  // socket) wants to bind to the export of the underlying
137  // tlm_initiator_socket, i.e. a hierarchical bind takes place.
140  {
141  if (!m_beoe_disabled) { // We are not bound hierarchically.
142  // So we bind the dummy to avoid a SystemC error.
144  }
145  // and then return our own export so that the hierarchical
146  // binding is set up properly.
148  }
149 
151  get_base_export() const
152  {
154  }
155 
156  // Bind against a target socket.
157  virtual void
159  {
160  // Error if this socket is already bound hierarchically.
162  display_error("Already hierarchically bound.");
163  return;
164  }
165 
166  // Satisfy systemC, leads to a call to get_base_interface().
168 
169  // Try to cast the target socket into a fw interface.
171  dynamic_cast<sc_core::sc_export<
173  if (!p_ex_s) {
174  display_error("Multi socket not bound to tlm_socket.");
175  return;
176  }
177 
178  // Try a cast into a multi sockets.
180  dynamic_cast<multi_to_multi_bind_base<TYPES> *>(p_ex_s);
181  if (test) {
182  // Did we just do a multi-multi bind??
183  // If that is the case the multi target socket must have just
184  // created a callback binder which we want to get from it.
185  // Moreover, we also just created one, which we will pass to it.
186  m_sockets.push_back(test->get_last_binder(
187  m_binders[m_binders.size() - 1]));
188  } else { // If not just bind normally,
190  *p_ex_s;
191  // Store the interface we are bound against.
193  }
194  }
195 
196  // Operator notation for direct bind.
198 
199  // SystemC standard callback before end of elaboration.
200  void
202  {
203  // If our export hasn't been bound yet (due to a hierarch binding)
204  // we bind it now to avoid a SystemC error. We must do that because it
205  // is legal not to register a callback on this socket as the user
206  // might only use b_transport.
209  }
210 
211  // 'break' here if the socket was told not to do callback binding.
212  if (m_beoe_disabled)
213  return;
214 
215  // Get the callback binders of the top of the hierachical bind chain.
216  // NOTE: this could be the same socket if there is no hierachical bind.
219 
220  // Get the interfaces bound to the top of the hierachical bind chain.
221  // NOTE: this could be the same socket if there is no hierachical bind.
223 
224  // Register the callbacks of this socket with the callback binders
225  // we just got from the top of the hierachical bind chain.
226  for (unsigned int i = 0; i < binders.size(); i++) {
227  binders[i]->set_callbacks(m_nb_f, m_dmi_f);
228  }
229  }
230 
231  //
232  // Bind multi initiator socket to multi initiator socket (hierarchical
233  // bind).
234  //
235  virtual void
236  bind(base_type& s)
237  {
238  if (m_binders.size()) {
239  // A multi socket is either bound hierarchically or directly.
240  display_error("Socket already directly bound.");
241  return;
242  }
243  if (m_hierarch_bind) {
244  display_warning("Socket already bound hierarchically. "
245  "Bind attempt ignored.");
246  return;
247  }
248 
249  // Remember to which socket we are hierarchically bound and disable it,
250  // so that it won't try to register callbacks itself.
251  s.disable_cb_bind();
252  m_hierarch_bind = &s;
253  base_type::bind(s); // Satisfy SystemC.
254  }
255 
256  // Operator notation for hierarchical bind.
257  void operator() (base_type &s) { bind(s); }
258 
259  // Get access to sub port.
261  operator [] (int i)
262  {
263  return m_used_sockets[i];
264  }
265 
266  // Get the number of bound targets.
267  // NOTE: This is only valid at end of elaboration!
268  unsigned int size() { return get_hierarch_bind()->get_sockets().size(); }
269 
270  protected:
273 
274  // Implementation of base class interface.
275  base_type *
277  {
278  if (m_hierarch_bind)
280  else
281  return this;
282  }
283  void disable_cb_bind() { m_beoe_disabled = true; }
285  get_binders()
286  {
287  return m_binders;
288  }
290  get_sockets()
291  {
292  return m_sockets;
293  }
294  // Vector of connected sockets.
297  // Vector of binders that convert untagged interface into tagged interface.
299 
300  base_type *m_hierarch_bind; // Pointer to hierarchical bound multi port.
301  // bool that remembers whether this socket shall bind callbacks or not.
303  // A callback binder that is bound to the underlying export
304  // in case there was no real bind.
306 
307  //callbacks as functors
308  // (allows to pass the callback to another socket that does not know the
309  // type of the module that owns the callbacks).
312 };
313 
314 template <typename MODULE, unsigned int BUSWIDTH=32,
315  typename TYPES=tlm::tlm_base_protocol_types, unsigned int N=0>
318  MODULE, BUSWIDTH, TYPES, N, sc_core::SC_ZERO_OR_MORE_BOUND>
319 {
321  MODULE, BUSWIDTH, TYPES, N, sc_core::SC_ZERO_OR_MORE_BOUND> socket_b;
322  public:
325  socket_b(name)
326  {}
327 };
328 
329 } // namespace tlm_utils
330 
331 #endif /* __SYSTEMC_EXT_TLM_UTILS_MULTI_PASSTHROUGH_INITIATOR_SOCKET_H__ */
tlm::tlm_bw_transport_if
Definition: fw_bw_ifs.hh:231
tlm_utils::multi_passthrough_initiator_socket::register_nb_transport_bw
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(int, transaction_type &, phase_type &, sc_core::sc_time &))
Definition: multi_passthrough_initiator_socket.h:118
sc_core::SC_ONE_OR_MORE_BOUND
@ SC_ONE_OR_MORE_BOUND
Definition: sc_port.hh:69
tlm_utils::multi_passthrough_initiator_socket::base_type
multi_init_base< BUSWIDTH, TYPES, N, POL > base_type
Definition: multi_passthrough_initiator_socket.h:91
tlm_utils::multi_passthrough_initiator_socket::get_hierarch_bind
base_type * get_hierarch_bind()
Definition: multi_passthrough_initiator_socket.h:310
tlm_utils::callback_binder_bw::nb_func_type
nb_transport_functor< TYPES > nb_func_type
Definition: multi_socket_bases.h:313
tlm_utils::multi_passthrough_initiator_socket::dmi_cb
void(MODULE::* dmi_cb)(int, sc_dt::uint64, sc_dt::uint64)
Definition: multi_passthrough_initiator_socket.h:89
tlm_utils::multi_passthrough_initiator_socket::m_sockets
std::vector< tlm::tlm_fw_transport_if< TYPES > * > m_sockets
Definition: multi_passthrough_initiator_socket.h:329
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
test
Definition: test.h:38
tlm_utils::callback_binder_bw
Definition: multi_socket_bases.h:303
mod
int mod(int val, int mod)
Definition: RubySlicc_Util.hh:90
tlm_utils::callback_binder_bw::dmi_func_type
invalidate_dmi_functor< TYPES > dmi_func_type
Definition: multi_socket_bases.h:314
tlm_utils::multi_passthrough_initiator_socket::get_sockets
std::vector< tlm::tlm_fw_transport_if< TYPES > * > & get_sockets()
Definition: multi_passthrough_initiator_socket.h:324
tlm_utils::multi_passthrough_initiator_socket_optional::multi_passthrough_initiator_socket_optional
multi_passthrough_initiator_socket_optional()
Definition: multi_passthrough_initiator_socket.h:340
tlm::tlm_base_initiator_socket< BUSWIDTH, tlm_fw_transport_if< tlm::tlm_base_protocol_types >, tlm_bw_transport_if< tlm::tlm_base_protocol_types >, N, POL >::get_base_interface
virtual tlm_bw_transport_if< tlm::tlm_base_protocol_types > & get_base_interface()
Definition: initiator_socket.hh:181
std::vector
STL vector class.
Definition: stl.hh:37
tlm_utils::convenience_socket_base::display_warning
void display_warning(const char *msg) const
Definition: convenience_socket_bases.cc:49
tlm::tlm_base_initiator_socket< BUSWIDTH, tlm_fw_transport_if< tlm::tlm_base_protocol_types >, tlm_bw_transport_if< tlm::tlm_base_protocol_types >, N, POL >::m_export
export_type m_export
Definition: initiator_socket.hh:192
tlm_utils::multi_passthrough_initiator_socket::get_binders
std::vector< callback_binder_bw< TYPES > * > & get_binders()
Definition: multi_passthrough_initiator_socket.h:319
tlm_utils::multi_passthrough_initiator_socket::m_nb_f
callback_binder_bw< TYPES >::nb_func_type m_nb_f
Definition: multi_passthrough_initiator_socket.h:344
tlm_utils::multi_passthrough_initiator_socket::m_dmi_f
callback_binder_bw< TYPES >::dmi_func_type m_dmi_f
Definition: multi_passthrough_initiator_socket.h:345
tlm_utils::multi_passthrough_initiator_socket::m_beoe_disabled
bool m_beoe_disabled
Definition: multi_passthrough_initiator_socket.h:336
tlm_utils::multi_passthrough_initiator_socket::register_invalidate_direct_mem_ptr
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64))
Definition: multi_passthrough_initiator_socket.h:133
tlm_utils::multi_passthrough_initiator_socket::m_hierarch_bind
base_type * m_hierarch_bind
Definition: multi_passthrough_initiator_socket.h:334
tlm::tlm_fw_transport_if
Definition: fw_bw_ifs.hh:221
tlm::tlm_base_initiator_socket_b
Definition: initiator_socket.hh:51
tlm_utils::multi_to_multi_bind_base
Definition: multi_socket_bases.h:494
tlm_utils::multi_passthrough_initiator_socket::default_name
static const char * default_name()
Definition: multi_passthrough_initiator_socket.h:97
tlm_utils::multi_passthrough_initiator_socket::operator[]
tlm::tlm_fw_transport_if< TYPES > * operator[](int i)
Definition: multi_passthrough_initiator_socket.h:295
sc_core::SC_ZERO_OR_MORE_BOUND
@ SC_ZERO_OR_MORE_BOUND
Definition: sc_port.hh:70
tlm_utils::multi_passthrough_initiator_socket::before_end_of_elaboration
void before_end_of_elaboration()
Definition: multi_passthrough_initiator_socket.h:235
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
tlm::tlm_base_initiator_socket< BUSWIDTH, tlm_fw_transport_if< tlm::tlm_base_protocol_types >, tlm_bw_transport_if< tlm::tlm_base_protocol_types >, N, POL >::get_base_export
virtual sc_core::sc_export< tlm_bw_transport_if< tlm::tlm_base_protocol_types > > & get_base_export()
Definition: initiator_socket.hh:184
tlm_utils::multi_passthrough_initiator_socket_optional::socket_b
multi_passthrough_initiator_socket< MODULE, BUSWIDTH, TYPES, N, sc_core::SC_ZERO_OR_MORE_BOUND > socket_b
Definition: multi_passthrough_initiator_socket.h:338
tlm_utils::multi_passthrough_initiator_socket::nb_cb
sync_enum_type(MODULE::* nb_cb)(int, transaction_type &, phase_type &, sc_core::sc_time &)
Definition: multi_passthrough_initiator_socket.h:87
tlm_utils::multi_passthrough_initiator_socket::transaction_type
TYPES::tlm_payload_type transaction_type
Definition: multi_passthrough_initiator_socket.h:82
sc_core::sc_time
Definition: sc_time.hh:49
tlm_utils::convenience_socket_base::display_error
void display_error(const char *msg) const
Definition: convenience_socket_bases.cc:57
tlm_utils::multi_passthrough_initiator_socket
Definition: multi_passthrough_initiator_socket.h:58
sc_core::sc_gen_unique_name
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
sc_core::sc_port_policy
sc_port_policy
Definition: sc_port.hh:67
tlm_utils::multi_init_base_if::get_sockets
virtual std::vector< tlm::tlm_fw_transport_if< TYPES > * > & get_sockets()=0
tlm_utils::multi_passthrough_initiator_socket::bind
virtual void bind(base_target_socket_type &s)
Definition: multi_passthrough_initiator_socket.h:192
tlm_utils::multi_passthrough_initiator_socket::base_target_socket_type
base_type::base_target_socket_type base_target_socket_type
Definition: multi_passthrough_initiator_socket.h:94
tlm_utils
Definition: convenience_socket_bases.h:29
tlm_utils::multi_passthrough_initiator_socket::m_used_sockets
std::vector< tlm::tlm_fw_transport_if< TYPES > * > m_used_sockets
Definition: multi_passthrough_initiator_socket.h:330
tlm_utils::multi_passthrough_initiator_socket::sync_enum_type
tlm::tlm_sync_enum sync_enum_type
Definition: multi_passthrough_initiator_socket.h:84
tlm::tlm_base_target_socket_b
Definition: initiator_socket.hh:65
sc_core::sc_export::bind
virtual void bind(IF &i)
Definition: sc_export.hh:75
tlm_utils::multi_passthrough_initiator_socket::size
unsigned int size()
Definition: multi_passthrough_initiator_socket.h:302
tlm_utils::multi_passthrough_initiator_socket::m_binders
std::vector< callback_binder_bw< TYPES > * > m_binders
Definition: multi_passthrough_initiator_socket.h:332
tlm_utils::multi_init_base::get_hierarch_bind
virtual multi_init_base * get_hierarch_bind()=0
tlm::tlm_base_initiator_socket< BUSWIDTH, tlm_fw_transport_if< tlm::tlm_base_protocol_types >, tlm_bw_transport_if< tlm::tlm_base_protocol_types >, N, POL >::bind
virtual void bind(base_target_socket_type &s)
Definition: initiator_socket.hh:121
tlm_utils::multi_passthrough_initiator_socket::phase_type
TYPES::tlm_phase_type phase_type
Definition: multi_passthrough_initiator_socket.h:83
tlm::tlm_base_protocol_types
Definition: fw_bw_ifs.hh:213
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
tlm_utils::multi_passthrough_initiator_socket_optional
Definition: multi_passthrough_initiator_socket.h:333
tlm::tlm_sync_enum
tlm_sync_enum
Definition: fw_bw_ifs.hh:48
tlm_utils::multi_passthrough_initiator_socket::m_dummy
callback_binder_bw< TYPES > m_dummy
Definition: multi_passthrough_initiator_socket.h:339
tlm_utils::multi_passthrough_initiator_socket::disable_cb_bind
void disable_cb_bind()
Definition: multi_passthrough_initiator_socket.h:317
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
tlm_utils::multi_passthrough_initiator_socket::get_base_interface
virtual tlm::tlm_bw_transport_if< TYPES > & get_base_interface()
Definition: multi_passthrough_initiator_socket.h:152
tlm_utils::multi_passthrough_initiator_socket::get_base_export
virtual sc_core::sc_export< tlm::tlm_bw_transport_if< TYPES > > & get_base_export()
Definition: multi_passthrough_initiator_socket.h:173
tlm_utils::multi_passthrough_initiator_socket::operator()
void operator()(base_target_socket_type &s)
Definition: multi_passthrough_initiator_socket.h:231
sc_core::sc_export
Definition: sc_export.hh:60
tlm_utils::multi_init_base_if::get_binders
virtual std::vector< callback_binder_bw< TYPES > * > & get_binders()=0
tlm_utils::multi_passthrough_initiator_socket::~multi_passthrough_initiator_socket
~multi_passthrough_initiator_socket()
Definition: multi_passthrough_initiator_socket.h:109
sc_core::sc_port_b< tlm_fw_transport_if< tlm::tlm_base_protocol_types > >::get_interface
sc_interface * get_interface()
Definition: sc_port.hh:166
tlm_utils::multi_passthrough_initiator_socket::multi_passthrough_initiator_socket
multi_passthrough_initiator_socket(const char *name=default_name())
Definition: multi_passthrough_initiator_socket.h:103

Generated on Wed Sep 30 2020 14:02:16 for gem5 by doxygen 1.8.17