gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
36namespace gem5
37{
38
39namespace {
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.
47uint8_t dummy_buffer[64] = {};
48
49struct 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
71namespace fastmodel
72{
73
74AmbaToTlmBridge64::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
92Port &
93AmbaToTlmBridge64::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
103void
104AmbaToTlmBridge64::bTransport(amba_pv::amba_pv_transaction &trans,
106{
109 return initiatorProxy->b_transport(trans, t);
110}
111
112bool
113AmbaToTlmBridge64::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
119unsigned int
120AmbaToTlmBridge64::transportDbg(amba_pv::amba_pv_transaction &trans)
121{
122 return initiatorProxy->transport_dbg(trans);
123}
124
125void
127 sc_dt::uint64 end_range)
128{
129 targetProxy->invalidate_direct_mem_ptr(start_range, end_range);
130}
131
132void
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
174void
175AmbaToTlmBridge64::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
far_atomic::FarAtomic * fa
void setStreamId(std::optional< uint32_t > s)
Definition sc_ext.cc:295
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
AmbaToTlmBridge64(const AmbaToTlmBridge64Params &params, const sc_core::sc_module_name &name)
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)
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:236
Bitfield< 5 > t
Definition misc_types.hh:71
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t uint64
Definition sc_nbdefs.hh:172
Overload hash function for BasicBlockRange type.
Definition binary32.hh:81
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:23:55 for gem5 by doxygen 1.11.0