gem5  v21.1.0.2
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,
37 class simple_initiator_socket_b :
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 *
51  default_name()
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);
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) :
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 *
199  default_name()
200  {
201  return sc_core::sc_gen_unique_name("simple_initiator_socket_tagged");
202  }
203 
204  explicit simple_initiator_socket_tagged_b(const char *n=default_name()) :
205  base_type(n), m_process(this)
206  {
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 
244  void set_transport_user_id(int id) { m_transport_user_id = id; }
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.
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:
314  process m_process;
315 };
316 
317 template <typename MODULE, unsigned int BUSWIDTH=32,
318  typename TYPES=tlm::tlm_base_protocol_types>
319 class simple_initiator_socket_tagged :
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:
341  explicit simple_initiator_socket_tagged_optional(const char *name) :
343  {}
344 };
345 
346 } // namespace tlm_utils
347 
348 #endif /* __SYSTEMC_EXT_TLM_UTILS_SIMPLE_INITIATOR_SOCKET_H__ */
tlm_utils::simple_initiator_socket_tagged_b::phase_type
TYPES::tlm_phase_type phase_type
Definition: simple_initiator_socket.h:208
tlm_utils::simple_initiator_socket_tagged_b::m_process
process m_process
Definition: simple_initiator_socket.h:331
tlm_utils::simple_initiator_socket_tagged_b::process::set_transport_user_id
void set_transport_user_id(int id)
Definition: simple_initiator_socket.h:261
tlm_utils::simple_initiator_socket_tagged_b::process::nb_transport_bw
sync_enum_type nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Definition: simple_initiator_socket.h:293
tlm_utils::simple_initiator_socket_tagged_b::process::TransportPtr
sync_enum_type(MODULE::* TransportPtr)(int, transaction_type &, phase_type &, sc_core::sc_time &)
Definition: simple_initiator_socket.h:250
tlm::tlm_bw_transport_if
Definition: fw_bw_ifs.hh:231
tlm_utils::simple_initiator_socket_tagged_b::process::m_transport_ptr
TransportPtr m_transport_ptr
Definition: simple_initiator_socket.h:321
tlm_utils::simple_initiator_socket_tagged_b::process::m_invalidate_direct_mem_user_id
int m_invalidate_direct_mem_user_id
Definition: simple_initiator_socket.h:324
tlm_utils::simple_initiator_socket_b::fw_interface_type
tlm::tlm_fw_transport_if< TYPES > fw_interface_type
Definition: simple_initiator_socket.h:79
tlm_utils::simple_initiator_socket_b::process::InvalidateDirectMemPtr
void(MODULE::* InvalidateDirectMemPtr)(sc_dt::uint64, sc_dt::uint64)
Definition: simple_initiator_socket.h:118
sc_core::SC_ONE_OR_MORE_BOUND
@ SC_ONE_OR_MORE_BOUND
Definition: sc_port.hh:69
tlm_utils::simple_initiator_socket_optional
Definition: simple_initiator_socket.h:184
tlm_utils::simple_initiator_socket_tagged_b::process::m_invalidate_direct_mem_ptr
InvalidateDirectMemPtr m_invalidate_direct_mem_ptr
Definition: simple_initiator_socket.h:322
tlm_utils::simple_initiator_socket_tagged_b::register_invalidate_direct_mem_ptr
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64), int id)
Definition: simple_initiator_socket.h:238
tlm_utils::simple_initiator_socket_tagged_optional
Definition: simple_initiator_socket.h:350
tlm_utils::simple_initiator_socket_b::process::TransportPtr
sync_enum_type(MODULE::* TransportPtr)(transaction_type &, phase_type &, sc_core::sc_time &)
Definition: simple_initiator_socket.h:116
tlm_utils::simple_initiator_socket_tagged_b::sync_enum_type
tlm::tlm_sync_enum sync_enum_type
Definition: simple_initiator_socket.h:209
tlm_utils::simple_initiator_socket_tagged_b::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 &), int id)
Definition: simple_initiator_socket.h:228
tlm_utils::simple_initiator_socket_b::register_nb_transport_bw
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
Definition: simple_initiator_socket.h:97
tlm_utils::simple_initiator_socket_tagged_b::process::set_transport_ptr
void set_transport_ptr(MODULE *mod, TransportPtr p)
Definition: simple_initiator_socket.h:269
tlm_utils::simple_initiator_socket_b::process::invalidate_direct_mem_ptr
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
Definition: simple_initiator_socket.h:164
tlm::TLM_COMPLETED
@ TLM_COMPLETED
Definition: fw_bw_ifs.hh:65
gem5::X86ISA::mod
mod
Definition: types.hh:91
tlm::tlm_initiator_socket
Definition: initiator_socket.hh:202
tlm_utils::simple_initiator_socket_b::process::m_transport_ptr
TransportPtr m_transport_ptr
Definition: simple_initiator_socket.h:177
tlm_utils::simple_initiator_socket_b::process::nb_transport_bw
sync_enum_type nb_transport_bw(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Definition: simple_initiator_socket.h:151
tlm_utils::simple_initiator_socket::simple_initiator_socket
simple_initiator_socket()
Definition: simple_initiator_socket.h:178
tlm_utils::simple_initiator_socket_b::sync_enum_type
tlm::tlm_sync_enum sync_enum_type
Definition: simple_initiator_socket.h:78
tlm_utils::convenience_socket_cb_holder::display_error
void display_error(const char *msg) const
Definition: convenience_socket_bases.cc:73
tlm_utils::simple_initiator_socket_tagged::simple_initiator_socket_tagged
simple_initiator_socket_tagged()
Definition: simple_initiator_socket.h:342
tlm_utils::simple_initiator_socket_b::process::set_transport_ptr
void set_transport_ptr(MODULE *mod, TransportPtr p)
Definition: simple_initiator_socket.h:127
tlm::tlm_base_initiator_socket< BUSWIDTH, tlm_fw_transport_if< TYPES >, tlm_bw_transport_if< TYPES >, N, POL >::m_export
export_type m_export
Definition: initiator_socket.hh:192
sc_assert
#define sc_assert(expr)
Definition: sc_report_handler.hh:135
tlm_utils::simple_initiator_socket_tagged_b
Definition: simple_initiator_socket.h:202
tlm_utils::simple_initiator_socket_b::register_invalidate_direct_mem_ptr
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(sc_dt::uint64, sc_dt::uint64))
Definition: simple_initiator_socket.h:105
tlm::tlm_fw_transport_if
Definition: fw_bw_ifs.hh:221
tlm_utils::simple_initiator_socket_b::m_process
process m_process
Definition: simple_initiator_socket.h:185
tlm_utils::simple_initiator_socket_tagged_b::process::set_invalidate_direct_mem_ptr
void set_invalidate_direct_mem_ptr(MODULE *mod, InvalidateDirectMemPtr p)
Definition: simple_initiator_socket.h:281
sc_core::SC_ZERO_OR_MORE_BOUND
@ SC_ZERO_OR_MORE_BOUND
Definition: sc_port.hh:70
tlm_utils::simple_initiator_socket_b::process::m_invalidate_direct_mem_ptr
InvalidateDirectMemPtr m_invalidate_direct_mem_ptr
Definition: simple_initiator_socket.h:178
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
tlm_utils::simple_initiator_socket_b::transaction_type
TYPES::tlm_payload_type transaction_type
Definition: simple_initiator_socket.h:76
tlm_utils::simple_initiator_socket_optional::socket_b
simple_initiator_socket_b< MODULE, BUSWIDTH, TYPES, sc_core::SC_ZERO_OR_MORE_BOUND > socket_b
Definition: simple_initiator_socket.h:189
tlm_utils::simple_initiator_socket_tagged_b::simple_initiator_socket_tagged_b
simple_initiator_socket_tagged_b(const char *n=default_name())
Definition: simple_initiator_socket.h:221
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
sc_core::sc_time
Definition: sc_time.hh:49
tlm_utils::simple_initiator_socket
Definition: simple_initiator_socket.h:173
tlm_utils::simple_initiator_socket_tagged::socket_b
simple_initiator_socket_tagged_b< MODULE, BUSWIDTH, TYPES > socket_b
Definition: simple_initiator_socket.h:340
tlm_utils::simple_initiator_socket_b::process::process
process(simple_socket_base *owner)
Definition: simple_initiator_socket.h:121
tlm_utils::simple_initiator_socket_tagged_b::get_socket
const sc_core::sc_object * get_socket() const
Definition: simple_initiator_socket.h:328
tlm_utils::simple_initiator_socket_b::process
Definition: simple_initiator_socket.h:112
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
gem5::ArmISA::t
Bitfield< 5 > t
Definition: misc_types.hh:70
tlm_utils::simple_initiator_socket_b::default_name
static const char * default_name()
Definition: simple_initiator_socket.h:85
tlm_utils::simple_initiator_socket_tagged_b::transaction_type
TYPES::tlm_payload_type transaction_type
Definition: simple_initiator_socket.h:207
sc_core::sc_object
Definition: sc_object.hh:50
tlm_utils::simple_initiator_socket_tagged_b::process::m_transport_user_id
int m_transport_user_id
Definition: simple_initiator_socket.h:323
tlm_utils::simple_initiator_socket_b::phase_type
TYPES::tlm_phase_type phase_type
Definition: simple_initiator_socket.h:77
tlm_utils::simple_initiator_socket_tagged_b::fw_interface_type
tlm::tlm_fw_transport_if< TYPES > fw_interface_type
Definition: simple_initiator_socket.h:210
tlm_utils
Definition: convenience_socket_bases.h:29
sc_core::sc_export::bind
virtual void bind(IF &i)
Definition: sc_export.hh:75
tlm_utils::simple_initiator_socket_b::process::m_mod
MODULE * m_mod
Definition: simple_initiator_socket.h:176
tlm_utils::convenience_socket_cb_holder::display_warning
void display_warning(const char *msg) const
Definition: convenience_socket_bases.cc:67
tlm_utils::simple_initiator_socket_tagged_optional::socket_b
simple_initiator_socket_tagged_b< MODULE, BUSWIDTH, TYPES, sc_core::SC_ZERO_OR_MORE_BOUND > socket_b
Definition: simple_initiator_socket.h:355
tlm_utils::simple_initiator_socket_b::get_socket
const sc_core::sc_object * get_socket() const
Definition: simple_initiator_socket.h:182
gem5::ArmISA::n
Bitfield< 31 > n
Definition: misc_types.hh:455
tlm::tlm_base_protocol_types
Definition: fw_bw_ifs.hh:213
tlm_utils::simple_initiator_socket_tagged_b::default_name
static const char * default_name()
Definition: simple_initiator_socket.h:216
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
tlm_utils::simple_initiator_socket_b::process::set_invalidate_direct_mem_ptr
void set_invalidate_direct_mem_ptr(MODULE *mod, InvalidateDirectMemPtr p)
Definition: simple_initiator_socket.h:139
tlm_utils::simple_initiator_socket_tagged_b::process::process
process(simple_socket_base *owner)
Definition: simple_initiator_socket.h:255
tlm_utils::simple_socket_base
Definition: convenience_socket_bases.h:48
tlm_utils::simple_initiator_socket_tagged_b::process::invalidate_direct_mem_ptr
void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
Definition: simple_initiator_socket.h:307
tlm_utils::simple_initiator_socket_optional::simple_initiator_socket_optional
simple_initiator_socket_optional()
Definition: simple_initiator_socket.h:191
tlm::tlm_sync_enum
tlm_sync_enum
Definition: fw_bw_ifs.hh:48
gem5::ArmISA::id
Bitfield< 33 > id
Definition: misc_types.hh:250
tlm_utils::simple_initiator_socket_b::bw_interface_type
tlm::tlm_bw_transport_if< TYPES > bw_interface_type
Definition: simple_initiator_socket.h:80
tlm_utils::simple_initiator_socket_tagged_b::bw_interface_type
tlm::tlm_bw_transport_if< TYPES > bw_interface_type
Definition: simple_initiator_socket.h:211
tlm_utils::simple_initiator_socket_tagged_b::process::set_invalidate_dmi_user_id
void set_invalidate_dmi_user_id(int id)
Definition: simple_initiator_socket.h:263
tlm_utils::simple_initiator_socket_b::base_type
tlm::tlm_initiator_socket< BUSWIDTH, TYPES, 1, POL > base_type
Definition: simple_initiator_socket.h:81
tlm_utils::simple_initiator_socket::socket_b
simple_initiator_socket_b< MODULE, BUSWIDTH, TYPES > socket_b
Definition: simple_initiator_socket.h:176
tlm_utils::simple_initiator_socket_b
Definition: simple_initiator_socket.h:54
tlm_utils::simple_initiator_socket_tagged_optional::simple_initiator_socket_tagged_optional
simple_initiator_socket_tagged_optional()
Definition: simple_initiator_socket.h:357
tlm_utils::convenience_socket_cb_holder
Definition: convenience_socket_bases.h:69
tlm_utils::simple_initiator_socket_tagged_b::base_type
tlm::tlm_initiator_socket< BUSWIDTH, TYPES, 1, POL > base_type
Definition: simple_initiator_socket.h:212
tlm_utils::simple_initiator_socket_tagged_b::process::m_mod
MODULE * m_mod
Definition: simple_initiator_socket.h:320
convenience_socket_bases.h
tlm_utils::simple_initiator_socket_tagged_b::process::InvalidateDirectMemPtr
void(MODULE::* InvalidateDirectMemPtr)(int, sc_dt::uint64, sc_dt::uint64)
Definition: simple_initiator_socket.h:252
tlm_utils::simple_initiator_socket_b::simple_initiator_socket_b
simple_initiator_socket_b(const char *n=default_name())
Definition: simple_initiator_socket.h:90

Generated on Tue Sep 21 2021 12:25:56 for gem5 by doxygen 1.8.17