gem5  v21.1.0.2
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 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  return initiatorProxy->b_transport(trans, t);
108 }
109 
110 bool
111 AmbaToTlmBridge64::getDirectMemPtr(amba_pv::amba_pv_transaction &trans,
112  tlm::tlm_dmi &dmi_data)
113 {
114  return initiatorProxy->get_direct_mem_ptr(trans, dmi_data);
115 }
116 
117 unsigned int
118 AmbaToTlmBridge64::transportDbg(amba_pv::amba_pv_transaction &trans)
119 {
120  return initiatorProxy->transport_dbg(trans);
121 }
122 
123 void
125  sc_dt::uint64 end_range)
126 {
127  targetProxy->invalidate_direct_mem_ptr(start_range, end_range);
128 }
129 
130 void
132  amba_pv::amba_pv_transaction &trans)
133 {
134  Gem5SystemC::AtomicExtension *atomic_ex = nullptr;
135  trans.get_extension(atomic_ex);
136  if (atomic_ex)
137  return;
138 
139  pv_userpayload_extension *user_ex = nullptr;
140  trans.get_extension(user_ex);
141  if (!user_ex)
142  return;
143 
144  pv::UserPayloadBase *upb = user_ex->get_user_payload();
145  uint32_t appid = upb->get_appID();
146  if (appid != pv::UserPayloadBase::SERVICE_REQUEST)
147  return;
148 
149  std::pair<void *, std::size_t> u_data = user_ex->get_user_data();
150  far_atomic::FarAtomic *fa = static_cast<far_atomic::FarAtomic *>(
151  u_data.first);
152 
153  // Correct the request size manually and give it a dummy buffer preventing
154  // from segmentation fault.
155  fatal_if(
156  fa->getDataValueSizeInBytes() > sizeof(dummy_buffer),
157  "atomic operation(%d) is larger than dummy buffer(%d)",
158  fa->getDataValueSizeInBytes(), sizeof(dummy_buffer));
159  trans.set_data_length(fa->getDataValueSizeInBytes());
160  trans.set_data_ptr(dummy_buffer);
161 
162  // The return value would store in the extension. We don't need to specify
163  // need_return here.
164  atomic_ex = new Gem5SystemC::AtomicExtension(
165  std::make_shared<FarAtomicOpFunctor>(fa), false);
166  if (trans.has_mm())
167  trans.set_auto_extension(atomic_ex);
168  else
169  trans.set_extension(atomic_ex);
170 }
171 
172 } // namespace fastmodel
173 
175 AmbaToTlmBridge64Params::create() const
176 {
177  return new fastmodel::AmbaToTlmBridge64(name.c_str());
178 }
179 
180 } // namespace gem5
gem5::fastmodel::AmbaToTlmBridge64::invalidateDirectMemPtr
void invalidateDirectMemPtr(sc_dt::uint64 start_range, sc_dt::uint64 end_range)
Definition: amba_to_tlm_bridge.cc:124
amo.hh
amba_to_tlm_bridge.hh
tlm::tlm_dmi
Definition: dmi.hh:46
sc_ext.hh
gem5::fastmodel::AmbaToTlmBridge64::getDirectMemPtr
bool getDirectMemPtr(amba_pv::amba_pv_transaction &trans, tlm::tlm_dmi &dmi_data)
Definition: amba_to_tlm_bridge.cc:111
gem5::fastmodel::AmbaToTlmBridge64::gem5_getPort
gem5::Port & gem5_getPort(const std::string &if_name, int idx=-1) override
Definition: amba_to_tlm_bridge.cc:92
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
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:131
gem5::fastmodel::AmbaToTlmBridge64::ambaWrapper
AmbaTarget ambaWrapper
Definition: amba_to_tlm_bridge.hh:68
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:64
gem5::fastmodel::AmbaToTlmBridge64::tlmWrapper
sc_gem5::TlmInitiatorWrapper< 64 > tlmWrapper
Definition: amba_to_tlm_bridge.hh:67
gem5::fastmodel::AmbaToTlmBridge64::AmbaToTlmBridge64
AmbaToTlmBridge64(const sc_core::sc_module_name &name)
Definition: amba_to_tlm_bridge.cc:75
gem5::ArmISA::t
Bitfield< 5 > t
Definition: misc_types.hh:70
std::pair
STL pair class.
Definition: stl.hh:58
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
name
const std::string & name()
Definition: trace.cc:49
gem5::fastmodel::AmbaToTlmBridge64::initiatorProxy
tlm_utils::simple_initiator_socket< AmbaToTlmBridge64, 64, tlm::tlm_base_protocol_types > initiatorProxy
Definition: amba_to_tlm_bridge.hh:66
gem5::fastmodel::AmbaToTlmBridge64::transportDbg
unsigned int transportDbg(amba_pv::amba_pv_transaction &trans)
Definition: amba_to_tlm_bridge.cc:118
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
std
Overload hash function for BasicBlockRange type.
Definition: types.hh:111
Gem5SystemC::AtomicExtension
Definition: sc_ext.hh:64
gem5::fastmodel::AmbaToTlmBridge64::bTransport
void bTransport(amba_pv::amba_pv_transaction &trans, sc_core::sc_time &t)
Definition: amba_to_tlm_bridge.cc:103
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:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::fastmodel::AmbaToTlmBridge64
Definition: amba_to_tlm_bridge.hh:47
fa
far_atomic::FarAtomic * fa
Definition: amba_to_tlm_bridge.cc:66

Generated on Tue Sep 21 2021 12:24:22 for gem5 by doxygen 1.8.17