gem5  v22.1.0.0
amba_to_tlm_bridge.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
29 
30 #include "base/amo.hh"
31 #include "params/AmbaToTlmBridge64.hh"
32 #include "pv/FarAtomicService.h"
33 #include "pv_userpayload_extension.h"
35 
36 namespace gem5
37 {
38 
39 namespace {
40 
41 // According to AbstractMemory::access in mem/abstract_mem.cc, the gem5 memory
42 // model would set original data into the packet buffer. However, the TLM
43 // request with atomic operation doesn't carry a valid buffer because the
44 // resource is all allocated in atomic extension. Preventing from segmentation
45 // fault, we allocate a random buffer and share it with all atomic transactions
46 // since we don't really care about the content of it.
47 uint8_t dummy_buffer[64] = {};
48 
49 struct FarAtomicOpFunctor : public AtomicOpFunctor
50 {
51  FarAtomicOpFunctor(far_atomic::FarAtomic *_fa) : fa(_fa) {}
52 
53  void
54  operator() (uint8_t *p) override
55  {
56  fa->serviceWasFound();
57  fa->doAtomicOperation(p);
58  }
59 
60  AtomicOpFunctor *
61  clone() override
62  {
63  return new FarAtomicOpFunctor(*this);
64  }
65 
66  far_atomic::FarAtomic *fa;
67 };
68 
69 }
70 
71 GEM5_DEPRECATED_NAMESPACE(FastModel, fastmodel);
72 namespace fastmodel
73 {
74 
76  amba_pv::amba_pv_to_tlm_bridge<64>(name),
77  targetProxy("target_proxy"),
78  initiatorProxy("initiator_proxy"),
79  tlmWrapper(initiatorProxy, std::string(name) + ".tlm", -1),
80  ambaWrapper(amba_pv_s, std::string(name) + ".amba", -1)
81 {
82  targetProxy.register_b_transport(this, &AmbaToTlmBridge64::bTransport);
83  targetProxy.register_get_direct_mem_ptr(
85  targetProxy.register_transport_dbg(this, &AmbaToTlmBridge64::transportDbg);
86  initiatorProxy.register_invalidate_direct_mem_ptr(
88  tlm_m(targetProxy);
89 }
90 
91 Port &
92 AmbaToTlmBridge64::gem5_getPort(const std::string &if_name, int idx)
93 {
94  if (if_name == "tlm")
95  return tlmWrapper;
96  else if (if_name == "amba")
97  return ambaWrapper;
98  else
99  return amba_pv::amba_pv_to_tlm_bridge<64>::gem5_getPort(if_name, idx);
100 }
101 
102 void
103 AmbaToTlmBridge64::bTransport(amba_pv::amba_pv_transaction &trans,
105 {
107  setupControlExtension(trans);
108  return initiatorProxy->b_transport(trans, t);
109 }
110 
111 bool
112 AmbaToTlmBridge64::getDirectMemPtr(amba_pv::amba_pv_transaction &trans,
113  tlm::tlm_dmi &dmi_data)
114 {
115  return initiatorProxy->get_direct_mem_ptr(trans, dmi_data);
116 }
117 
118 unsigned int
119 AmbaToTlmBridge64::transportDbg(amba_pv::amba_pv_transaction &trans)
120 {
121  return initiatorProxy->transport_dbg(trans);
122 }
123 
124 void
126  sc_dt::uint64 end_range)
127 {
128  targetProxy->invalidate_direct_mem_ptr(start_range, end_range);
129 }
130 
131 void
133  amba_pv::amba_pv_transaction &trans)
134 {
135  Gem5SystemC::AtomicExtension *atomic_ex = nullptr;
136  trans.get_extension(atomic_ex);
137  if (atomic_ex)
138  return;
139 
140  pv_userpayload_extension *user_ex = nullptr;
141  trans.get_extension(user_ex);
142  if (!user_ex)
143  return;
144 
145  pv::UserPayloadBase *upb = user_ex->get_user_payload();
146  uint32_t appid = upb->get_appID();
147  if (appid != pv::UserPayloadBase::SERVICE_REQUEST)
148  return;
149 
150  std::pair<void *, std::size_t> u_data = user_ex->get_user_data();
151  far_atomic::FarAtomic *fa = static_cast<far_atomic::FarAtomic *>(
152  u_data.first);
153 
154  // Correct the request size manually and give it a dummy buffer preventing
155  // from segmentation fault.
156  fatal_if(
157  fa->getDataValueSizeInBytes() > sizeof(dummy_buffer),
158  "atomic operation(%d) is larger than dummy buffer(%d)",
159  fa->getDataValueSizeInBytes(), sizeof(dummy_buffer));
160  trans.set_data_length(fa->getDataValueSizeInBytes());
161  trans.set_data_ptr(dummy_buffer);
162 
163  // The return value would store in the extension. We don't need to specify
164  // returnRequired here.
165  atomic_ex = new Gem5SystemC::AtomicExtension(
166  std::make_shared<FarAtomicOpFunctor>(fa), false);
167  if (trans.has_mm())
168  trans.set_auto_extension(atomic_ex);
169  else
170  trans.set_extension(atomic_ex);
171 }
172 
173 void
174 AmbaToTlmBridge64::setupControlExtension(amba_pv::amba_pv_transaction &trans)
175 {
176  Gem5SystemC::ControlExtension *control_ex = nullptr;
177  trans.get_extension(control_ex);
178  if (control_ex) {
179  return;
180  }
181 
182  amba_pv::amba_pv_extension *amba_ex = nullptr;
183  trans.get_extension(amba_ex);
184  if (!amba_ex) {
185  return;
186  }
187 
188  control_ex = new Gem5SystemC::ControlExtension();
189 
190  control_ex->setPrivileged(amba_ex->is_privileged());
191  control_ex->setSecure(!amba_ex->is_non_secure());
192  control_ex->setInstruction(amba_ex->is_instruction());
193 
194  if (trans.has_mm()) {
195  trans.set_auto_extension(control_ex);
196  } else {
197  trans.set_extension(control_ex);
198  }
199 }
200 
201 } // namespace fastmodel
202 
204 AmbaToTlmBridge64Params::create() const
205 {
206  return new fastmodel::AmbaToTlmBridge64(name.c_str());
207 }
208 
209 } // namespace gem5
far_atomic::FarAtomic * fa
void setPrivileged(bool p)
Definition: sc_ext.cc:225
void setInstruction(bool i)
Definition: sc_ext.cc:249
Ports are used to interface objects to each other.
Definition: port.hh:62
tlm_utils::simple_target_socket< AmbaToTlmBridge64, 64, tlm::tlm_base_protocol_types > targetProxy
void setupControlExtension(amba_pv::amba_pv_transaction &trans)
gem5::Port & gem5_getPort(const std::string &if_name, int idx=-1) override
tlm_utils::simple_initiator_socket< AmbaToTlmBridge64, 64, tlm::tlm_base_protocol_types > initiatorProxy
unsigned int transportDbg(amba_pv::amba_pv_transaction &trans)
sc_gem5::TlmInitiatorWrapper< 64 > tlmWrapper
void bTransport(amba_pv::amba_pv_transaction &trans, sc_core::sc_time &t)
void maybeSetupAtomicExtension(amba_pv::amba_pv_transaction &trans)
bool getDirectMemPtr(amba_pv::amba_pv_transaction &trans, tlm::tlm_dmi &dmi_data)
AmbaToTlmBridge64(const sc_core::sc_module_name &name)
void invalidateDirectMemPtr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
STL pair class.
Definition: stl.hh:58
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
Bitfield< 51 > t
Definition: pagetable.hh:56
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
uint64_t uint64
Definition: sc_nbdefs.hh:172
Overload hash function for BasicBlockRange type.
Definition: misc.hh:2826
const std::string & name()
Definition: trace.cc:49

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