gem5  v19.0.0.0
simple_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 
20 #ifndef __SYSTEMC_EXT_TLM_UTILS_SIMPLE_INITIATOR_SOCKET_H__
21 #define __SYSTEMC_EXT_TLM_UTILS_SIMPLE_INITIATOR_SOCKET_H__
22 
23 #include "../core/sc_module.hh"
24 #include "../core/sc_port.hh"
25 #include "../tlm_core/2/generic_payload/gp.hh"
26 #include "../tlm_core/2/interfaces/fw_bw_ifs.hh"
27 #include "../tlm_core/2/sockets/initiator_socket.hh"
28 #include "../tlm_core/2/sockets/target_socket.hh"
29 #include "../utils/sc_report_handler.hh"
31 
32 namespace tlm_utils
33 {
34 
35 template <typename MODULE, unsigned int BUSWIDTH, typename TYPES,
38  public tlm::tlm_initiator_socket<BUSWIDTH, TYPES, 1, POL>,
39  protected simple_socket_base
40 {
41  public:
42  typedef typename TYPES::tlm_payload_type transaction_type;
43  typedef typename TYPES::tlm_phase_type phase_type;
48 
49  public:
50  static const char *
52  {
53  return sc_core::sc_gen_unique_name("simple_initiator_socket");
54  }
55 
56  explicit simple_initiator_socket_b(const char *n=default_name()) :
57  base_type(n), m_process(this)
58  {
59  this->m_export.bind(m_process);
60  }
61 
62  void
64  sync_enum_type (MODULE::*cb)(transaction_type &, phase_type &,
66  {
68  }
69 
70  void
72  void (MODULE::*cb)(sc_dt::uint64, sc_dt::uint64))
73  {
75  }
76 
77  private:
78  class process : public tlm::tlm_bw_transport_if<TYPES>,
80  {
81  public:
82  typedef sync_enum_type (MODULE::*TransportPtr)(
83  transaction_type &, phase_type &, sc_core::sc_time &);
84  typedef void (MODULE::*InvalidateDirectMemPtr)(
86 
87  explicit process(simple_socket_base *owner) :
90  {}
91 
92  void
94  {
95  if (m_transport_ptr) {
96  display_warning("non-blocking callback already registered");
97  return;
98  }
99  sc_assert(!m_mod || m_mod == mod);
100  m_mod = mod;
101  m_transport_ptr = p;
102  }
103 
104  void
106  {
108  display_warning("invalidate DMI callback already registered");
109  return;
110  }
111  sc_assert(!m_mod || m_mod == mod);
112  m_mod = mod;
114  }
115 
116  sync_enum_type
117  nb_transport_bw(transaction_type &trans, phase_type &phase,
119  {
120  if (m_transport_ptr) {
121  // Forward call.
122  sc_assert(m_mod);
123  return (m_mod->*m_transport_ptr)(trans, phase, t);
124  }
125  display_error("no transport callback registered");
126  return tlm::TLM_COMPLETED;
127  }
128 
129  void
130  invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
131  sc_dt::uint64 end_range)
132  {
134  // Forward call.
135  sc_assert(m_mod);
137  start_range, end_range);
138  }
139  }
140 
141  private:
142  MODULE *m_mod;
145  };
146 
147  private:
148  const sc_core::sc_object *get_socket() const { return this; }
149 
150  private:
152 };
153 
154 template <typename MODULE, unsigned int BUSWIDTH=32,
155  typename TYPES=tlm::tlm_base_protocol_types>
157  public simple_initiator_socket_b<MODULE, BUSWIDTH, TYPES>
158 {
160  public:
161  simple_initiator_socket() : socket_b() {}
162  explicit simple_initiator_socket(const char *name) : socket_b(name) {}
163 };
164 
165 template <typename MODULE, unsigned int BUSWIDTH=32,
166  typename TYPES=tlm::tlm_base_protocol_types>
168  public simple_initiator_socket_b<MODULE, BUSWIDTH, TYPES,
169  sc_core::SC_ZERO_OR_MORE_BOUND>
170 {
172  MODULE, BUSWIDTH, TYPES, sc_core::SC_ZERO_OR_MORE_BOUND> socket_b;
173  public:
175  explicit simple_initiator_socket_optional(const char *name) :
176  socket_b(name)
177  {}
178 };
179 
180 
181 // Tagged version
182 
183 template <typename MODULE, unsigned int BUSWIDTH, typename TYPES,
186  public tlm::tlm_initiator_socket<BUSWIDTH, TYPES, 1, POL>,
187  protected simple_socket_base
188 {
189  public:
190  typedef typename TYPES::tlm_payload_type transaction_type;
191  typedef typename TYPES::tlm_phase_type phase_type;
196 
197  public:
198  static const char *
200  {
201  return sc_core::sc_gen_unique_name("simple_initiator_socket_tagged");
202  }
203 
205  base_type(n), m_process(this)
206  {
207  this->m_export.bind(m_process);
208  }
209 
210  void
212  sync_enum_type (MODULE::*cb)(
213  int, transaction_type &, phase_type &, sc_core::sc_time &),
214  int id)
215  {
216  m_process.set_transport_ptr(mod, cb);
217  m_process.set_transport_user_id(id);
218  }
219 
220  void
222  void (MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64), int id)
223  {
225  m_process.set_invalidate_dmi_user_id(id);
226  }
227 
228  private:
229  class process : public tlm::tlm_bw_transport_if<TYPES>,
231  {
232  public:
233  typedef sync_enum_type (MODULE::*TransportPtr)(
234  int, transaction_type &, phase_type &, sc_core::sc_time &);
235  typedef void (MODULE::*InvalidateDirectMemPtr)(
237 
238  explicit process(simple_socket_base *owner) :
241  m_transport_user_id(0), m_invalidate_direct_mem_user_id(0)
242  {}
243 
244  void set_transport_user_id(int id) { m_transport_user_id = id; }
245  void
247  {
248  m_invalidate_direct_mem_user_id = id;
249  }
250 
251  void
253  {
254  if (m_transport_ptr) {
255  display_warning("non-blocking callback already registered");
256  return;
257  }
258  sc_assert(!m_mod || m_mod == mod);
259  m_mod = mod;
260  m_transport_ptr = p;
261  }
262 
263  void
265  {
267  display_warning("invalidate DMI callback already registered");
268  return;
269  }
270  sc_assert(!m_mod || m_mod == mod);
271  m_mod = mod;
273  }
274 
275  sync_enum_type
276  nb_transport_bw(transaction_type &trans, phase_type &phase,
278  {
279  if (m_transport_ptr) {
280  // Forward call.
281  sc_assert(m_mod);
282  return (m_mod->*m_transport_ptr)(
283  m_transport_user_id, trans, phase, t);
284  }
285  display_error("no transport callback registered");
286  return tlm::TLM_COMPLETED;
287  }
288 
289  void
291  sc_dt::uint64 start_range, sc_dt::uint64 end_range)
292  {
294  // Forward call.
295  sc_assert(m_mod);
297  m_invalidate_direct_mem_user_id,
298  start_range, end_range);
299  }
300  }
301 
302  private:
303  MODULE *m_mod;
308  };
309 
310  private:
311  const sc_core::sc_object *get_socket() const { return this; }
312 
313  private:
315 };
316 
317 template <typename MODULE, unsigned int BUSWIDTH=32,
318  typename TYPES=tlm::tlm_base_protocol_types>
320  public simple_initiator_socket_tagged_b<MODULE, BUSWIDTH, TYPES>
321 {
323  MODULE, BUSWIDTH, TYPES> socket_b;
324  public:
326  explicit simple_initiator_socket_tagged(const char *name) :
327  socket_b(name)
328  {}
329 };
330 
331 template <typename MODULE, unsigned int BUSWIDTH=32,
332  typename TYPES=tlm::tlm_base_protocol_types>
334  public simple_initiator_socket_tagged_b<MODULE, BUSWIDTH, TYPES,
335  sc_core::SC_ZERO_OR_MORE_BOUND>
336 {
338  MODULE, BUSWIDTH, TYPES, sc_core::SC_ZERO_OR_MORE_BOUND> socket_b;
339  public:
342  socket_b(name)
343  {}
344 };
345 
346 } // namespace tlm_utils
347 
348 #endif /* __SYSTEMC_EXT_TLM_UTILS_SIMPLE_INITIATOR_SOCKET_H__ */
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(sc_dt::uint64, sc_dt::uint64))
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(int, transaction_type &, phase_type &, sc_core::sc_time &), int id)
void(MODULE::* InvalidateDirectMemPtr)(sc_dt::uint64, sc_dt::uint64)
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:822
simple_initiator_socket_tagged_b< MODULE, BUSWIDTH, TYPES, sc_core::SC_ZERO_OR_MORE_BOUND > socket_b
sync_enum_type(MODULE::* TransportPtr)(transaction_type &, phase_type &, sc_core::sc_time &)
const char * name() const
Definition: sc_object.cc:46
tlm::tlm_initiator_socket< BUSWIDTH, TYPES, 1, POL > base_type
sync_enum_type nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Bitfield< 33 > id
Bitfield< 31 > n
simple_initiator_socket_b< MODULE, BUSWIDTH, TYPES > socket_b
void set_transport_ptr(MODULE *mod, TransportPtr p)
const sc_core::sc_object * get_socket() const
tlm::tlm_fw_transport_if< TYPES > fw_interface_type
int mod(int val, int mod)
simple_initiator_socket_b(const char *n=default_name())
simple_initiator_socket_b< MODULE, BUSWIDTH, TYPES, sc_core::SC_ZERO_OR_MORE_BOUND > socket_b
void set_invalidate_direct_mem_ptr(MODULE *mod, InvalidateDirectMemPtr p)
#define sc_assert(expr)
simple_initiator_socket_tagged_b(const char *n=default_name())
sc_port_policy
Definition: sc_port.hh:69
simple_initiator_socket_tagged_b< MODULE, BUSWIDTH, TYPES > socket_b
uint64_t uint64
Definition: sc_nbdefs.hh:172
tlm::tlm_bw_transport_if< TYPES > bw_interface_type
sync_enum_type nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
tlm_sync_enum
Definition: fw_bw_ifs.hh:31
tlm::tlm_bw_transport_if< TYPES > bw_interface_type
Bitfield< 5 > t
tlm::tlm_fw_transport_if< TYPES > fw_interface_type
tlm::tlm_initiator_socket< BUSWIDTH, TYPES, 1, POL > base_type
void set_invalidate_direct_mem_ptr(MODULE *mod, InvalidateDirectMemPtr p)
Bitfield< 0 > p
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64), int id)
virtual void bind(IF &i)
Definition: sc_export.hh:77
const sc_core::sc_object * get_socket() const

Generated on Fri Feb 28 2020 16:27:04 for gem5 by doxygen 1.8.13