gem5  v19.0.0.0
extension_adaptors.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 __EXTENSIONS_ADAPTORS_H__
21 #define __EXTENSIONS_ADAPTORS_H__
22 
23 #include "tlm.h"
24 #include "my_extension.h"
25 
26 #include "tlm_utils/simple_initiator_socket.h"
27 #include "tlm_utils/simple_target_socket.h"
28 
29 template <unsigned int BUSWIDTH = 32>
31 {
32  public:
39 
40  target_socket_type target_socket;
41  initiator_socket_type initiator_socket;
42 
43  SC_HAS_PROCESS(adapt_ext2gp);
45  : sc_core::sc_module(name_)
46  {
50 
53  }
54 
56  // NB transport
58 
59  // Forward direction: The initiator calls this method with an extended
60  // payload. We leave the extension class in the vector, and it will be
61  // ignored by the GP target.
62  tlm::tlm_sync_enum forward_nb_transport(initiator_payload_type& trans,
63  tlm::tlm_phase& phase,
65  {
66  return initiator_socket->nb_transport_fw(trans, phase, t);
67  }
68  // Backward direction: we can assume here that the payload we get
69  // as parameter is the same one that the initiator sent out. Thus, the
70  // extension vector is known to be present.
71  tlm::tlm_sync_enum backward_nb_transport(target_payload_type& trans,
72  tlm::tlm_phase& phase,
74  {
75  return target_socket->nb_transport_bw(trans, phase, t);
76  }
77 
78  bool get_dmi_pointer(target_payload_type& trans,
79  tlm::tlm_dmi& dmi_data)
80  {
81  bool tmp_ret = initiator_socket->get_direct_mem_ptr(trans,
82  dmi_data);
83  return tmp_ret;
84  }
85 
87  // simple call forwarders:
89  unsigned int transport_debug(target_payload_type& trans)
90  {
91  return initiator_socket->transport_dbg(trans);
92  }
94  sc_dt::uint64 end_range)
95  {
96  target_socket->invalidate_direct_mem_ptr(start_range,
97  end_range);
98  }
99 };
100 
101 template <unsigned int BUSWIDTH = 32>
103 {
104  public:
109  typedef tlm_utils::simple_target_socket<adapt_gp2ext, BUSWIDTH,
111 
112  target_socket_type target_socket;
113  initiator_socket_type initiator_socket;
114 
115  SC_HAS_PROCESS(adapt_gp2ext);
117  : sc_core::sc_module(name_)
118  {
119  // Optionally, we can initialize our private extension class
120  // here, if required.
121 
125 
128 
129  m_ext.m_data = 13;
130  }
131 
133  // NB transport
135 
136  // Forward direction: We extend the payload on the fly (if needed).
137  tlm::tlm_sync_enum forward_nb_transport(initiator_payload_type& trans,
138  tlm::tlm_phase& phase,
140  {
141  // If the mandatory extension is not there, we need to add it and
142  // store it so that we can re-construc the original state.
143  // Otherwise we don't touch the extension, so that we don't overwrite
144  // it in e.g. a nonGP->GP->nonGP (initiator->interconnect->target)
145  // setup.
146  // Note, however, that there might be situations where we might need to
147  // re-initialize the extension, e.g. for mutable data fields in
148  // different system setups.
149  trans.get_extension(m_initiator_ext);
150  if (!m_initiator_ext)
151  {
152  m_initiator_ext = trans.set_extension(&m_ext);
153  }
154  tlm::tlm_sync_enum tmp =
155  initiator_socket->nb_transport_fw(trans, phase, t);
156  if (tmp == tlm::TLM_COMPLETED)
157  {
158  m_initiator_ext = trans.set_extension(m_initiator_ext);
159  }
160  return tmp;
161  }
162  // Backward direction: only restore of original extension and static_cast.
163  tlm::tlm_sync_enum backward_nb_transport(target_payload_type& trans,
164  tlm::tlm_phase& phase,
166  {
167  m_initiator_ext = trans.set_extension(m_initiator_ext);
168  return target_socket->nb_transport_bw(trans, phase, t);
169  }
170 
171  bool get_dmi_pointer(target_payload_type& trans,
172  tlm::tlm_dmi& dmi_data)
173  {
174  // If the mandatory extension is not there, we need to add it and
175  // store it so that we can re-construc the original state.
176  // Otherwise we don't touch the extension, so that we don't overwrite
177  // it in e.g. a nonGP->GP->nonGP (initiator->interconnect->target)
178  // setup.
179  my_extension* tmp_ext;
180  trans.get_extension(tmp_ext);
181  if (!tmp_ext)
182  {
183  trans.set_extension(&m_ext);
184  }
185  bool tmp_ret = initiator_socket->get_direct_mem_ptr(trans,
186  dmi_data);
187  if(!tmp_ext)
188  {
189  trans.clear_extension(tmp_ext);
190  }
191  return tmp_ret;
192  }
194  // simple call forwarders:
196  unsigned int transport_debug(target_payload_type& trans)
197  {
198  return initiator_socket->transport_dbg(trans);
199  }
201  sc_dt::uint64 end_range)
202  {
203  target_socket->invalidate_direct_mem_ptr(start_range,
204  end_range);
205  }
206 
207 private:
210 };
211 
212 #endif
tlm::tlm_generic_payload initiator_payload_type
void register_invalidate_direct_mem_ptr(MODULE *mod, void(MODULE::*cb)(sc_dt::uint64, sc_dt::uint64))
void get_extension(T *&ext) const
Definition: gp.hh:364
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
adapt_gp2ext(sc_core::sc_module_name name_)
target_socket_type target_socket
my_extension * m_initiator_ext
void invalidate_dmi_pointers(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
adapt_ext2gp(sc_core::sc_module_name name_)
initiator_socket_type initiator_socket
tlm::tlm_generic_payload initiator_payload_type
unsigned int transport_debug(target_payload_type &trans)
tlm::tlm_sync_enum backward_nb_transport(target_payload_type &trans, tlm::tlm_phase &phase, sc_core::sc_time &t)
tlm::tlm_sync_enum backward_nb_transport(target_payload_type &trans, tlm::tlm_phase &phase, sc_core::sc_time &t)
void clear_extension(const T *ext)
Definition: gp.hh:379
tlm::tlm_sync_enum forward_nb_transport(initiator_payload_type &trans, tlm::tlm_phase &phase, sc_core::sc_time &t)
tlm::tlm_generic_payload target_payload_type
tlm_utils::simple_target_socket< adapt_gp2ext, BUSWIDTH, tlm::tlm_base_protocol_types > target_socket_type
tlm::tlm_generic_payload target_payload_type
tlm::tlm_sync_enum forward_nb_transport(initiator_payload_type &trans, tlm::tlm_phase &phase, sc_core::sc_time &t)
void invalidate_dmi_pointers(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
void register_get_direct_mem_ptr(MODULE *mod, bool(MODULE::*cb)(transaction_type &, tlm::tlm_dmi &))
target_socket_type target_socket
T * set_extension(T *ext)
Definition: gp.hh:340
SC_HAS_PROCESS(adapt_ext2gp)
void register_transport_dbg(MODULE *mod, unsigned int(MODULE::*cb)(transaction_type &))
uint64_t uint64
Definition: sc_nbdefs.hh:172
tlm_utils::simple_initiator_socket< adapt_gp2ext, BUSWIDTH, my_extended_payload_types > initiator_socket_type
void register_nb_transport_fw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
tlm_utils::simple_target_socket< adapt_ext2gp, BUSWIDTH, my_extended_payload_types > target_socket_type
initiator_socket_type initiator_socket
tlm_utils::simple_initiator_socket< adapt_ext2gp, BUSWIDTH, tlm::tlm_base_protocol_types > initiator_socket_type
tlm_sync_enum
Definition: fw_bw_ifs.hh:31
Bitfield< 5 > t
bool get_dmi_pointer(target_payload_type &trans, tlm::tlm_dmi &dmi_data)
bool get_dmi_pointer(target_payload_type &trans, tlm::tlm_dmi &dmi_data)
unsigned int transport_debug(target_payload_type &trans)
my_extension m_ext

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