gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sc_ext.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, University of Kaiserslautern
3  * Copyright (c) 2016, Dresden University of Technology (TU Dresden)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
25  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
35 
36 #include <optional>
37 
41 
42 using namespace gem5;
43 
44 namespace Gem5SystemC
45 {
46 namespace
47 {
48 
49 struct ControlConversionRegister
50 {
51  ControlConversionRegister()
52  {
54  [] (PacketPtr pkt, tlm::tlm_generic_payload &trans)
55  {
56  ControlExtension *control_ex = nullptr;
57  trans.get_extension(control_ex);
58  if (!control_ex) {
59  return;
60  }
61 
62  if (control_ex->isPrivileged()) {
63  pkt->req->setFlags(Request::PRIVILEGED);
64  } else {
65  pkt->req->clearFlags(Request::PRIVILEGED);
66  }
67 
68  if (control_ex->isSecure()) {
69  pkt->req->setFlags(Request::SECURE);
70  } else {
71  pkt->req->clearFlags(Request::SECURE);
72  }
73 
74  if (control_ex->isInstruction()) {
75  pkt->req->setFlags(Request::INST_FETCH);
76  } else {
77  pkt->req->clearFlags(Request::INST_FETCH);
78  }
79 
80  pkt->qosValue(control_ex->getQos());
81 
82  if (control_ex->hasStreamId()) {
83  pkt->req->setStreamId(control_ex->getStreamId().value());
84  }
85  if (control_ex->hasSubstreamId()) {
86  pkt->req->setSubstreamId(
87  control_ex->getSubstreamId().value());
88  }
89  });
91  [] (PacketPtr pkt, tlm::tlm_generic_payload &trans)
92  {
93  ControlExtension *control_ex = nullptr;
94  trans.get_extension(control_ex);
95  if (!control_ex) {
96  return;
97  }
98 
99  control_ex->setPrivileged(pkt->req->isPriv());
100  control_ex->setSecure(pkt->req->isSecure());
101  control_ex->setInstruction(pkt->req->isInstFetch());
102  control_ex->setQos(pkt->qosValue());
103  if (pkt->req->hasStreamId()) {
104  control_ex->setStreamId(pkt->req->streamId());
105  }
106  if (pkt->req->hasSubstreamId()) {
107  control_ex->setSubstreamId(pkt->req->substreamId());
108  }
109  });
110  }
111 };
112 
113 } // namespace
114 
115 Gem5Extension::Gem5Extension(PacketPtr p) : packet(p)
116 {
117 }
118 
121 {
122  Gem5Extension *result = nullptr;
123  payload->get_extension(result);
124  sc_assert(result != nullptr);
125  return *result;
126 }
127 
130 {
131  return Gem5Extension::getExtension(&payload);
132 }
133 
134 PacketPtr
136 {
137  return packet;
138 }
139 
142 {
143  return new Gem5Extension(packet);
144 }
145 
146 void
148 {
149  const Gem5Extension &from = static_cast<const Gem5Extension &>(ext);
150  packet = from.packet;
151 }
152 
154  std::shared_ptr<gem5::AtomicOpFunctor> o, bool r)
155  : op(o), returnRequired(r)
156 {
157 }
158 
161 {
162  return new AtomicExtension(*this);
163 }
164 
165 void
167 {
168  const AtomicExtension &from = static_cast<const AtomicExtension &>(ext);
169  *this = from;
170 }
171 
174 {
175  return AtomicExtension::getExtension(&payload);
176 }
177 
180 {
181  AtomicExtension *result = nullptr;
182  payload->get_extension(result);
183  sc_assert(result);
184  return *result;
185 }
186 
187 bool
189 {
190  return returnRequired;
191 }
192 
195 {
196  return op.get();
197 }
198 
200  : privileged(false), secure(false), instruction(false), qos(0)
201 {
202  [[maybe_unused]] static ControlConversionRegister *conversion_register =
203  new ControlConversionRegister();
204 }
205 
208 {
209  return new ControlExtension(*this);
210 }
211 
212 void
214 {
215  const ControlExtension &from = static_cast<const ControlExtension &>(ext);
216  *this = from;
217 }
218 
221 {
222  return ControlExtension::getExtension(&payload);
223 }
224 
227 {
228  ControlExtension *result = nullptr;
229  payload->get_extension(result);
230  sc_assert(result);
231  return *result;
232 }
233 
234 bool
236 {
237  return privileged;
238 }
239 
240 void
242 {
243  privileged = p;
244 }
245 
246 bool
248 {
249  return secure;
250 }
251 
252 void
254 {
255  secure = s;
256 }
257 
258 bool
260 {
261  return instruction;
262 }
263 
264 void
266 {
267  instruction = i;
268 }
269 
270 uint8_t
272 {
273  return qos;
274 }
275 
276 void
278 {
279  qos = q;
280 }
281 
282 bool
284 {
285  return stream_id.has_value();
286 }
287 
288 std::optional<uint32_t>
290 {
291  return stream_id;
292 }
293 
294 void
295 ControlExtension::setStreamId(std::optional<uint32_t> s)
296 {
297  stream_id = std::move(s);
298 }
299 
300 bool
302 {
303  return substream_id.has_value();
304 }
305 
306 std::optional<uint32_t>
308 {
309  return substream_id;
310 }
311 
312 void
313 ControlExtension::setSubstreamId(std::optional<uint32_t> s)
314 {
315  substream_id = std::move(s);
316 }
317 
318 } // namespace Gem5SystemC
gem5::VegaISA::s
Bitfield< 1 > s
Definition: pagetable.hh:64
Gem5SystemC::ControlExtension::clone
tlm_extension_base * clone() const override
Definition: sc_ext.cc:207
tlm_to_gem5.hh
gem5::AtomicOpFunctor
Definition: amo.hh:43
Gem5SystemC::ControlExtension::setInstruction
void setInstruction(bool i)
Definition: sc_ext.cc:265
Gem5SystemC::ControlExtension::isInstruction
bool isInstruction() const
Definition: sc_ext.cc:259
Gem5SystemC::ControlExtension::privileged
bool privileged
Definition: sc_ext.hh:129
sc_gem5::addPacketToPayloadConversionStep
void addPacketToPayloadConversionStep(PacketToPayloadConversionStep step)
Notify the Gem5ToTlm bridge that we need an extra step to properly convert a gem5 packet to tlm paylo...
Definition: gem5_to_tlm.cc:119
gem5::Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:377
gem5_to_tlm.hh
Gem5SystemC::Gem5Extension::clone
tlm_extension_base * clone() const override
Definition: sc_ext.cc:141
sc_ext.hh
gem5::Packet::qosValue
uint8_t qosValue() const
QoS Value getter Returns 0 if QoS value was never set (constructor default).
Definition: packet.hh:769
Gem5SystemC::ControlExtension::getStreamId
std::optional< uint32_t > getStreamId() const
Definition: sc_ext.cc:289
Gem5SystemC::ControlExtension
Definition: sc_ext.hh:94
Gem5SystemC::Gem5Extension::Gem5Extension
Gem5Extension(gem5::PacketPtr p)
Definition: sc_ext.cc:115
Gem5SystemC::Gem5Extension::getPacket
gem5::PacketPtr getPacket()
Definition: sc_ext.cc:135
gem5::VegaISA::r
Bitfield< 5 > r
Definition: pagetable.hh:60
Gem5SystemC::ControlExtension::getSubstreamId
std::optional< uint32_t > getSubstreamId() const
Definition: sc_ext.cc:307
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
Gem5SystemC::ControlExtension::ControlExtension
ControlExtension()
Definition: sc_ext.cc:199
Gem5SystemC::ControlExtension::setStreamId
void setStreamId(std::optional< uint32_t > s)
Definition: sc_ext.cc:295
sc_assert
#define sc_assert(expr)
Definition: sc_report_handler.hh:135
Gem5SystemC::AtomicExtension::clone
tlm_extension_base * clone() const override
Definition: sc_ext.cc:160
Gem5SystemC::AtomicExtension::AtomicExtension
AtomicExtension(std::shared_ptr< gem5::AtomicOpFunctor > o, bool r)
Definition: sc_ext.cc:153
gem5::SparcISA::int_reg::o
constexpr RegId o(int index)
Definition: int.hh:147
Gem5SystemC
Definition: sc_ext.cc:44
tlm::tlm_extension_base
Definition: gp.hh:65
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
Gem5SystemC::ControlExtension::stream_id
std::optional< uint32_t > stream_id
Definition: sc_ext.hh:137
Gem5SystemC::ControlExtension::substream_id
std::optional< uint32_t > substream_id
Definition: sc_ext.hh:138
Gem5SystemC::ControlExtension::isPrivileged
bool isPrivileged() const
Definition: sc_ext.cc:235
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Gem5SystemC::ControlExtension::isSecure
bool isSecure() const
Definition: sc_ext.cc:247
Gem5SystemC::ControlExtension::setQos
void setQos(uint8_t q)
Definition: sc_ext.cc:277
Gem5SystemC::ControlExtension::getQos
uint8_t getQos() const
Definition: sc_ext.cc:271
Gem5SystemC::ControlExtension::secure
bool secure
Definition: sc_ext.hh:130
gem5::ArmISA::ext
Bitfield< 12 > ext
Definition: misc_types.hh:485
tlm::tlm_generic_payload::get_extension
void get_extension(T *&ext) const
Definition: gp.hh:381
Gem5SystemC::AtomicExtension::getExtension
static AtomicExtension & getExtension(const tlm::tlm_generic_payload *payload)
Definition: sc_ext.cc:179
sc_gem5::addPayloadToPacketConversionStep
void addPayloadToPacketConversionStep(PayloadToPacketConversionStep step)
Notify the Tlm2Gem5 bridge that we need an extra step to properly convert a tlm payload to gem5 packe...
Definition: tlm_to_gem5.cc:96
Gem5SystemC::AtomicExtension::isReturnRequired
bool isReturnRequired() const
Definition: sc_ext.cc:188
Gem5SystemC::ControlExtension::hasSubstreamId
bool hasSubstreamId() const
Definition: sc_ext.cc:301
sc_report_handler.hh
gem5::ArmISA::q
Bitfield< 27 > q
Definition: misc_types.hh:55
tlm::tlm_generic_payload
Definition: gp.hh:133
Gem5SystemC::Gem5Extension::getExtension
static Gem5Extension & getExtension(const tlm::tlm_generic_payload *payload)
Definition: sc_ext.cc:120
Gem5SystemC::ControlExtension::setPrivileged
void setPrivileged(bool p)
Definition: sc_ext.cc:241
Gem5SystemC::AtomicExtension
Definition: sc_ext.hh:72
Gem5SystemC::ControlExtension::copy_from
void copy_from(const tlm_extension_base &ext) override
Definition: sc_ext.cc:213
Gem5SystemC::ControlExtension::instruction
bool instruction
Definition: sc_ext.hh:131
Gem5SystemC::Gem5Extension
Definition: sc_ext.hh:54
Gem5SystemC::AtomicExtension::returnRequired
bool returnRequired
Definition: sc_ext.hh:91
Gem5SystemC::ControlExtension::hasStreamId
bool hasStreamId() const
Definition: sc_ext.cc:283
Gem5SystemC::AtomicExtension::getAtomicOpFunctor
gem5::AtomicOpFunctor * getAtomicOpFunctor() const
Definition: sc_ext.cc:194
Gem5SystemC::ControlExtension::setSubstreamId
void setSubstreamId(std::optional< uint32_t > s)
Definition: sc_ext.cc:313
Gem5SystemC::ControlExtension::qos
uint8_t qos
Definition: sc_ext.hh:134
Gem5SystemC::AtomicExtension::op
std::shared_ptr< gem5::AtomicOpFunctor > op
Definition: sc_ext.hh:90
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
Gem5SystemC::AtomicExtension::copy_from
void copy_from(const tlm_extension_base &ext) override
Definition: sc_ext.cc:166
Gem5SystemC::Gem5Extension::copy_from
void copy_from(const tlm_extension_base &ext) override
Definition: sc_ext.cc:147
gem5::X86ISA::op
Bitfield< 4 > op
Definition: types.hh:83
Gem5SystemC::ControlExtension::getExtension
static ControlExtension & getExtension(const tlm::tlm_generic_payload *payload)
Definition: sc_ext.cc:226
Gem5SystemC::ControlExtension::setSecure
void setSecure(bool s)
Definition: sc_ext.cc:253
Gem5SystemC::Gem5Extension::packet
gem5::PacketPtr packet
Definition: sc_ext.hh:69

Generated on Sun Jul 30 2023 01:57:03 for gem5 by doxygen 1.8.17