gem5  v22.1.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)(
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 
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
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:
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)(
214  int id)
215  {
218  }
219 
220  void
222  void (MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64), int id)
223  {
226  }
227 
228  private:
229  class process : public tlm::tlm_bw_transport_if<TYPES>,
231  {
232  public:
233  typedef sync_enum_type (MODULE::*TransportPtr)(
235  typedef void (MODULE::*InvalidateDirectMemPtr)(
237 
238  explicit process(simple_socket_base *owner) :
242  {}
243 
245  void
247  {
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 
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);
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__ */
virtual void bind(IF &i)
Definition: sc_export.hh:75
const char * name() const
Definition: sc_object.cc:44
sync_enum_type nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
void set_invalidate_direct_mem_ptr(MODULE *mod, InvalidateDirectMemPtr p)
sync_enum_type(MODULE::* TransportPtr)(transaction_type &, phase_type &, sc_core::sc_time &)
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
void set_transport_ptr(MODULE *mod, TransportPtr p)
void(MODULE::* InvalidateDirectMemPtr)(sc_dt::uint64, sc_dt::uint64)
tlm::tlm_initiator_socket< BUSWIDTH, TYPES, 1, POL > base_type
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
const sc_core::sc_object * get_socket() const
tlm::tlm_bw_transport_if< TYPES > bw_interface_type
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(sc_dt::uint64, sc_dt::uint64))
simple_initiator_socket_b(const char *n=default_name())
tlm::tlm_fw_transport_if< TYPES > fw_interface_type
simple_initiator_socket_b< MODULE, BUSWIDTH, TYPES, sc_core::SC_ZERO_OR_MORE_BOUND > socket_b
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
void set_invalidate_direct_mem_ptr(MODULE *mod, InvalidateDirectMemPtr p)
void(MODULE::* InvalidateDirectMemPtr)(int, sc_dt::uint64, sc_dt::uint64)
sync_enum_type nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
sync_enum_type(MODULE::* TransportPtr)(int, transaction_type &, phase_type &, sc_core::sc_time &)
simple_initiator_socket_tagged_b(const char *n=default_name())
const sc_core::sc_object * get_socket() const
tlm::tlm_initiator_socket< BUSWIDTH, TYPES, 1, POL > base_type
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(int, transaction_type &, phase_type &, sc_core::sc_time &), int id)
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64), int id)
tlm::tlm_fw_transport_if< TYPES > fw_interface_type
tlm::tlm_bw_transport_if< TYPES > bw_interface_type
simple_initiator_socket_tagged_b< MODULE, BUSWIDTH, TYPES, sc_core::SC_ZERO_OR_MORE_BOUND > socket_b
simple_initiator_socket_tagged_b< MODULE, BUSWIDTH, TYPES > socket_b
simple_initiator_socket_b< MODULE, BUSWIDTH, TYPES > socket_b
Bitfield< 31 > n
Definition: misc_types.hh:462
Bitfield< 33 > id
Definition: misc_types.hh:257
Bitfield< 51 > t
Definition: pagetable.hh:56
Bitfield< 54 > p
Definition: pagetable.hh:70
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
@ TLM_COMPLETED
Definition: fw_bw_ifs.hh:31
#define sc_assert(expr)

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