gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 namespace fastmodel
72 {
73 
74 AmbaToTlmBridge64::AmbaToTlmBridge64(const AmbaToTlmBridge64Params &params,
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  setStreamId(params.set_stream_id)
82 {
83  targetProxy.register_b_transport(this, &AmbaToTlmBridge64::bTransport);
84  targetProxy.register_get_direct_mem_ptr(
86  targetProxy.register_transport_dbg(this, &AmbaToTlmBridge64::transportDbg);
87  initiatorProxy.register_invalidate_direct_mem_ptr(
89  tlm_m(targetProxy);
90 }
91 
92 Port &
93 AmbaToTlmBridge64::gem5_getPort(const std::string &if_name, int idx)
94 {
95  if (if_name == "tlm")
96  return tlmWrapper;
97  else if (if_name == "amba")
98  return ambaWrapper;
99  else
100  return amba_pv::amba_pv_to_tlm_bridge<64>::gem5_getPort(if_name, idx);
101 }
102 
103 void
104 AmbaToTlmBridge64::bTransport(amba_pv::amba_pv_transaction &trans,
106 {
108  setupControlExtension(trans);
109  return initiatorProxy->b_transport(trans, t);
110 }
111 
112 bool
113 AmbaToTlmBridge64::getDirectMemPtr(amba_pv::amba_pv_transaction &trans,
114  tlm::tlm_dmi &dmi_data)
115 {
116  return initiatorProxy->get_direct_mem_ptr(trans, dmi_data);
117 }
118 
119 unsigned int
120 AmbaToTlmBridge64::transportDbg(amba_pv::amba_pv_transaction &trans)
121 {
122  return initiatorProxy->transport_dbg(trans);
123 }
124 
125 void
127  sc_dt::uint64 end_range)
128 {
129  targetProxy->invalidate_direct_mem_ptr(start_range, end_range);
130 }
131 
132 void
134  amba_pv::amba_pv_transaction &trans)
135 {
136  Gem5SystemC::AtomicExtension *atomic_ex = nullptr;
137  trans.get_extension(atomic_ex);
138  if (atomic_ex)
139  return;
140 
141  pv_userpayload_extension *user_ex = nullptr;
142  trans.get_extension(user_ex);
143  if (!user_ex)
144  return;
145 
146  pv::UserPayloadBase *upb = user_ex->get_user_payload();
147  uint32_t appid = upb->get_appID();
148  if (appid != pv::UserPayloadBase::SERVICE_REQUEST)
149  return;
150 
151  std::pair<void *, std::size_t> u_data = user_ex->get_user_data();
152  far_atomic::FarAtomic *fa = static_cast<far_atomic::FarAtomic *>(
153  u_data.first);
154 
155  // Correct the request size manually and give it a dummy buffer preventing
156  // from segmentation fault.
157  fatal_if(
158  fa->getDataValueSizeInBytes() > sizeof(dummy_buffer),
159  "atomic operation(%d) is larger than dummy buffer(%d)",
160  fa->getDataValueSizeInBytes(), sizeof(dummy_buffer));
161  trans.set_data_length(fa->getDataValueSizeInBytes());
162  trans.set_data_ptr(dummy_buffer);
163 
164  // The return value would store in the extension. We don't need to specify
165  // returnRequired here.
166  atomic_ex = new Gem5SystemC::AtomicExtension(
167  std::make_shared<FarAtomicOpFunctor>(fa), false);
168  if (trans.has_mm())
169  trans.set_auto_extension(atomic_ex);
170  else
171  trans.set_extension(atomic_ex);
172 }
173 
174 void
175 AmbaToTlmBridge64::setupControlExtension(amba_pv::amba_pv_transaction &trans)
176 {
177  Gem5SystemC::ControlExtension *control_ex = nullptr;
178  trans.get_extension(control_ex);
179  if (control_ex) {
180  return;
181  }
182 
183  amba_pv::amba_pv_extension *amba_ex = nullptr;
184  trans.get_extension(amba_ex);
185  if (!amba_ex) {
186  return;
187  }
188 
189  control_ex = new Gem5SystemC::ControlExtension();
190 
191  control_ex->setPrivileged(amba_ex->is_privileged());
192  control_ex->setSecure(!amba_ex->is_non_secure());
193  control_ex->setInstruction(amba_ex->is_instruction());
194 
195  if (setStreamId) {
196  control_ex->setStreamId(amba_ex->get_id());
197  }
198 
199  if (trans.has_mm()) {
200  trans.set_auto_extension(control_ex);
201  } else {
202  trans.set_extension(control_ex);
203  }
204 }
205 
206 } // namespace fastmodel
207 } // namespace gem5
gem5::fastmodel::AmbaToTlmBridge64::setStreamId
bool setStreamId
Definition: amba_to_tlm_bridge.hh:74
gem5::fastmodel::AmbaToTlmBridge64::invalidateDirectMemPtr
void invalidateDirectMemPtr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
Definition: amba_to_tlm_bridge.cc:126
amo.hh
Gem5SystemC::ControlExtension::setInstruction
void setInstruction(bool i)
Definition: sc_ext.cc:265
amba_to_tlm_bridge.hh
tlm::tlm_dmi
Definition: dmi.hh:46
sc_ext.hh
gem5::fastmodel::AmbaToTlmBridge64::setupControlExtension
void setupControlExtension(amba_pv::amba_pv_transaction &trans)
Definition: amba_to_tlm_bridge.cc:175
Gem5SystemC::ControlExtension
Definition: sc_ext.hh:94
gem5::fastmodel::AmbaToTlmBridge64::getDirectMemPtr
bool getDirectMemPtr(amba_pv::amba_pv_transaction &trans, tlm::tlm_dmi &dmi_data)
Definition: amba_to_tlm_bridge.cc:113
Gem5SystemC::ControlExtension::setStreamId
void setStreamId(std::optional< uint32_t > s)
Definition: sc_ext.cc:295
gem5::VegaISA::t
Bitfield< 51 > t
Definition: pagetable.hh:56
gem5::fastmodel::AmbaToTlmBridge64::gem5_getPort
gem5::Port & gem5_getPort(const std::string &if_name, int idx=-1) override
Definition: amba_to_tlm_bridge.cc:93
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
sc_core::sc_time
Definition: sc_time.hh:49
gem5::fastmodel::AmbaToTlmBridge64::maybeSetupAtomicExtension
void maybeSetupAtomicExtension(amba_pv::amba_pv_transaction &trans)
Definition: amba_to_tlm_bridge.cc:133
gem5::fastmodel::AmbaToTlmBridge64::ambaWrapper
AmbaTarget ambaWrapper
Definition: amba_to_tlm_bridge.hh:73
sc_core::sc_module_name
Definition: sc_module_name.hh:41
gem5::fastmodel::AmbaToTlmBridge64::targetProxy
tlm_utils::simple_target_socket< AmbaToTlmBridge64, 64, tlm::tlm_base_protocol_types > targetProxy
Definition: amba_to_tlm_bridge.hh:69
gem5::fastmodel::AmbaToTlmBridge64::AmbaToTlmBridge64
AmbaToTlmBridge64(const AmbaToTlmBridge64Params &params, const sc_core::sc_module_name &name)
Definition: amba_to_tlm_bridge.cc:74
gem5::fastmodel::AmbaToTlmBridge64::tlmWrapper
sc_gem5::TlmInitiatorWrapper< 64 > tlmWrapper
Definition: amba_to_tlm_bridge.hh:72
std::pair
STL pair class.
Definition: stl.hh:58
name
const std::string & name()
Definition: trace.cc:48
gem5::fastmodel::AmbaToTlmBridge64::initiatorProxy
tlm_utils::simple_initiator_socket< AmbaToTlmBridge64, 64, tlm::tlm_base_protocol_types > initiatorProxy
Definition: amba_to_tlm_bridge.hh:71
gem5::fastmodel::AmbaToTlmBridge64::transportDbg
unsigned int transportDbg(amba_pv::amba_pv_transaction &trans)
Definition: amba_to_tlm_bridge.cc:120
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
std
Overload hash function for BasicBlockRange type.
Definition: misc.hh:2909
Gem5SystemC::ControlExtension::setPrivileged
void setPrivileged(bool p)
Definition: sc_ext.cc:241
Gem5SystemC::AtomicExtension
Definition: sc_ext.hh:72
gem5::fastmodel::AmbaToTlmBridge64::bTransport
void bTransport(amba_pv::amba_pv_transaction &trans, sc_core::sc_time &t)
Definition: amba_to_tlm_bridge.cc:104
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:236
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
Gem5SystemC::ControlExtension::setSecure
void setSecure(bool s)
Definition: sc_ext.cc:253
fa
far_atomic::FarAtomic * fa
Definition: amba_to_tlm_bridge.cc:66

Generated on Sun Jul 30 2023 01:56:47 for gem5 by doxygen 1.8.17