gem5  v22.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,
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 
58 
59  typedef typename base_type::base_target_socket_type
61 
62  static const char *
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> &
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 
152  {
154  }
155 
156  // Bind against a target socket.
157  virtual void
159  {
160  // Error if this socket is already bound hierarchically.
161  if (m_hierarch_bind) {
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.
192  m_sockets.push_back(&((tlm::tlm_fw_transport_if<TYPES> &)ex_s));
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
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.
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; }
286  {
287  return m_binders;
288  }
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__ */
virtual void bind(IF &i)
Definition: sc_export.hh:75
const char * name() const
Definition: sc_object.cc:44
sc_interface * get_interface()
Definition: sc_port.hh:166
STL vector class.
Definition: stl.hh:37
virtual sc_core::sc_export< BW_IF > & get_base_export()
virtual void bind(base_target_socket_type &s)
invalidate_dmi_functor< TYPES > dmi_func_type
nb_transport_functor< TYPES > nb_func_type
void display_warning(const char *msg) const
void display_error(const char *msg) const
virtual std::vector< callback_binder_bw< TYPES > * > & get_binders()=0
virtual std::vector< tlm::tlm_fw_transport_if< TYPES > * > & get_sockets()=0
virtual multi_init_base * get_hierarch_bind()=0
multi_passthrough_initiator_socket< MODULE, BUSWIDTH, TYPES, N, sc_core::SC_ZERO_OR_MORE_BOUND > socket_b
std::vector< tlm::tlm_fw_transport_if< TYPES > * > m_used_sockets
virtual sc_core::sc_export< tlm::tlm_bw_transport_if< TYPES > > & get_base_export()
tlm::tlm_fw_transport_if< TYPES > * operator[](int i)
std::vector< callback_binder_bw< TYPES > * > m_binders
std::vector< callback_binder_bw< TYPES > * > & get_binders()
virtual const sc_core::sc_export< tlm::tlm_bw_transport_if< TYPES > > & get_base_export() const
std::vector< tlm::tlm_fw_transport_if< TYPES > * > m_sockets
std::vector< tlm::tlm_fw_transport_if< TYPES > * > & get_sockets()
virtual tlm::tlm_bw_transport_if< TYPES > & get_base_interface()
sync_enum_type(MODULE::* nb_cb)(int, transaction_type &, phase_type &, sc_core::sc_time &)
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(int, transaction_type &, phase_type &, sc_core::sc_time &))
multi_init_base< BUSWIDTH, TYPES, N, POL > base_type
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64))
void(MODULE::* dmi_cb)(int, sc_dt::uint64, sc_dt::uint64)
virtual const tlm::tlm_bw_transport_if< TYPES > & get_base_interface() const
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 1 > s
Definition: pagetable.hh:64
sc_port_policy
Definition: sc_port.hh:68
@ SC_ZERO_OR_MORE_BOUND
Definition: sc_port.hh:70
@ SC_ONE_OR_MORE_BOUND
Definition: sc_port.hh:69
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
uint64_t uint64
Definition: sc_nbdefs.hh:172
tlm_sync_enum
Definition: fw_bw_ifs.hh:31
Definition: test.h:38

Generated on Wed Dec 21 2022 10:22:42 for gem5 by doxygen 1.9.1