TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
simple_initiator_socket.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 #ifndef __SIMPLE_INITIATOR_SOCKET_H__
19 #define __SIMPLE_INITIATOR_SOCKET_H__
20 
21 #include <tlm>
22 #include <sstream>
23 
24 namespace tlm_utils {
25 
26 template <typename MODULE,
27  unsigned int BUSWIDTH = 32,
28  typename TYPES = tlm::tlm_base_protocol_types>
30  public tlm::tlm_initiator_socket<BUSWIDTH, TYPES>
31 {
32 public:
33  typedef typename TYPES::tlm_payload_type transaction_type;
34  typedef typename TYPES::tlm_phase_type phase_type;
39 
40 public:
42  base_type(sc_core::sc_gen_unique_name("simple_initiator_socket")),
43  m_process(this->name())
44  {
45  this->m_export.bind(m_process);
46  }
47 
48  explicit simple_initiator_socket(const char* n) :
49  base_type(n),
50  m_process(this->name())
51  {
52  this->m_export.bind(m_process);
53  }
54 
55  void register_nb_transport_bw(MODULE* mod,
56  sync_enum_type (MODULE::*cb)(transaction_type&,
57  phase_type&,
59  {
60  m_process.set_transport_ptr(mod, cb);
61  }
62 
64  void (MODULE::*cb)(sc_dt::uint64, sc_dt::uint64))
65  {
66  m_process.set_invalidate_direct_mem_ptr(mod, cb);
67  }
68 
69 private:
70  class process : public tlm::tlm_bw_transport_if<TYPES>
71  {
72  public:
73  typedef sync_enum_type (MODULE::*TransportPtr)(transaction_type&,
74  phase_type&,
76  typedef void (MODULE::*InvalidateDirectMemPtr)(sc_dt::uint64,
78 
79  process(const std::string& name) :
80  m_name(name),
81  m_mod(0),
82  m_transport_ptr(0),
83  m_invalidate_direct_mem_ptr(0)
84  {
85  }
86 
87  void set_transport_ptr(MODULE* mod, TransportPtr p)
88  {
89  if (m_transport_ptr) {
90  std::stringstream s;
91  s << m_name << ": non-blocking callback allready registered";
92  SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket",s.str().c_str());
93  } else {
94  assert(!m_mod || m_mod == mod);
95  m_mod = mod;
96  m_transport_ptr = p;
97  }
98  }
99 
100  void set_invalidate_direct_mem_ptr(MODULE* mod, InvalidateDirectMemPtr p)
101  {
102  if (m_invalidate_direct_mem_ptr) {
103  std::stringstream s;
104  s << m_name << ": invalidate DMI callback allready registered";
105  SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket",s.str().c_str());
106  } else {
107  assert(!m_mod || m_mod == mod);
108  m_mod = mod;
109  m_invalidate_direct_mem_ptr = p;
110  }
111  }
112 
113  sync_enum_type nb_transport_bw(transaction_type& trans, phase_type& phase, sc_core::sc_time& t)
114  {
115  if (m_transport_ptr) {
116  // forward call
117  assert(m_mod);
118  return (m_mod->*m_transport_ptr)(trans, phase, t);
119 
120  } else {
121  std::stringstream s;
122  s << m_name << ": no transport callback registered";
123  SC_REPORT_ERROR("/OSCI_TLM-2/simple_socket",s.str().c_str());
124  }
125  return tlm::TLM_ACCEPTED;
126  }
127 
128  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
129  sc_dt::uint64 end_range)
130  {
131  if (m_invalidate_direct_mem_ptr) {
132  // forward call
133  assert(m_mod);
134  (m_mod->*m_invalidate_direct_mem_ptr)(start_range, end_range);
135  }
136  }
137 
138  private:
139  const std::string m_name;
140  MODULE* m_mod;
141  TransportPtr m_transport_ptr;
142  InvalidateDirectMemPtr m_invalidate_direct_mem_ptr;
143  };
144 
145 private:
146  process m_process;
147 };
148 
149 // Tagged version
150 
151 template <typename MODULE,
152  unsigned int BUSWIDTH = 32,
153  typename TYPES = tlm::tlm_base_protocol_types>
155  public tlm::tlm_initiator_socket<BUSWIDTH, TYPES>
156 {
157 public:
158  typedef typename TYPES::tlm_payload_type transaction_type;
159  typedef typename TYPES::tlm_phase_type phase_type;
164 
165 public:
167  base_type(sc_core::sc_gen_unique_name("simple_initiator_socket_tagged")),
168  m_process(this->name())
169  {
170  this->m_export.bind(m_process);
171  }
172 
173  explicit simple_initiator_socket_tagged(const char* n) :
174  base_type(n),
175  m_process(this->name())
176  {
177  this->m_export.bind(m_process);
178  }
179 
180  void register_nb_transport_bw(MODULE* mod,
181  sync_enum_type (MODULE::*cb)(int,
183  phase_type&,
185  int id)
186  {
187  m_process.set_transport_ptr(mod, cb);
188  m_process.set_transport_user_id(id);
189  }
190 
192  void (MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64),
193  int id)
194  {
195  m_process.set_invalidate_direct_mem_ptr(mod, cb);
196  m_process.set_invalidate_dmi_user_id(id);
197  }
198 
199 private:
200  class process : public tlm::tlm_bw_transport_if<TYPES>
201  {
202  public:
203  typedef sync_enum_type (MODULE::*TransportPtr)(int,
205  phase_type&,
207  typedef void (MODULE::*InvalidateDirectMemPtr)(int,
209  sc_dt::uint64);
210 
211  process(const std::string& name) :
212  m_name(name),
213  m_mod(0),
214  m_transport_ptr(0),
215  m_invalidate_direct_mem_ptr(0),
216  m_transport_user_id(0),
217  m_invalidate_direct_mem_user_id(0)
218  {
219  }
220 
221  void set_transport_user_id(int id) { m_transport_user_id = id; }
222  void set_invalidate_dmi_user_id(int id) { m_invalidate_direct_mem_user_id = id; }
223 
224  void set_transport_ptr(MODULE* mod, TransportPtr p)
225  {
226  if (m_transport_ptr) {
227  std::stringstream s;
228  s << m_name << ": non-blocking callback allready registered";
229  SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket",s.str().c_str());
230  } else {
231  assert(!m_mod || m_mod == mod);
232  m_mod = mod;
233  m_transport_ptr = p;
234  }
235  }
236 
237  void set_invalidate_direct_mem_ptr(MODULE* mod, InvalidateDirectMemPtr p)
238  {
239  if (m_invalidate_direct_mem_ptr) {
240  std::stringstream s;
241  s << m_name << ": invalidate DMI callback allready registered";
242  SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket",s.str().c_str());
243  } else {
244  assert(!m_mod || m_mod == mod);
245  m_mod = mod;
246  m_invalidate_direct_mem_ptr = p;
247  }
248  }
249 
250  sync_enum_type nb_transport_bw(transaction_type& trans, phase_type& phase, sc_core::sc_time& t)
251  {
252  if (m_transport_ptr) {
253  // forward call
254  assert(m_mod);
255  return (m_mod->*m_transport_ptr)(m_transport_user_id, trans, phase, t);
256 
257  } else {
258  std::stringstream s;
259  s << m_name << ": no transport callback registered";
260  SC_REPORT_ERROR("/OSCI_TLM-2/simple_socket",s.str().c_str());
261  }
262  return tlm::TLM_ACCEPTED;
263  }
264 
265  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
266  sc_dt::uint64 end_range)
267  {
268  if (m_invalidate_direct_mem_ptr) {
269  // forward call
270  assert(m_mod);
271  (m_mod->*m_invalidate_direct_mem_ptr)(m_invalidate_direct_mem_user_id, start_range, end_range);
272  }
273  }
274 
275  private:
276  const std::string m_name;
277  MODULE* m_mod;
278  TransportPtr m_transport_ptr;
279  InvalidateDirectMemPtr m_invalidate_direct_mem_ptr;
280  int m_transport_user_id;
281  int m_invalidate_direct_mem_user_id;
282  };
283 
284 private:
285  process m_process;
286 };
287 
288 }
289 
290 #endif
tlm::tlm_initiator_socket< BUSWIDTH, TYPES > base_type
uint64_t uint64
#define SC_REPORT_WARNING(msg_type, msg)
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(int, transaction_type &, phase_type &, sc_core::sc_time &), int id)
tlm::tlm_initiator_socket< BUSWIDTH, TYPES > base_type
const char * sc_gen_unique_name(const char *, bool preserve_first)
tlm::tlm_bw_transport_if< TYPES > bw_interface_type
tlm_sync_enum
Definition: tlm_fw_bw_ifs.h:27
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
#define SC_REPORT_ERROR(msg_type, msg)
SC_VIRTUAL_ void bind(IF &interface_)
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(sc_dt::uint64, sc_dt::uint64))
tlm::tlm_fw_transport_if< TYPES > fw_interface_type
tlm::tlm_bw_transport_if< TYPES > bw_interface_type