gem5  v22.0.0.1
RubySlicc_Util.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2021 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 /*
43  * These are the functions that exported to slicc from ruby.
44  */
45 
46 #ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
47 #define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
48 
49 #include <cassert>
50 #include <climits>
51 
52 #include "debug/RubyProtocol.hh"
53 #include "debug/RubySlicc.hh"
54 #include "mem/packet.hh"
60 #include "mem/ruby/protocol/RubyRequestType.hh"
61 
62 namespace gem5
63 {
64 
65 namespace ruby
66 {
67 
68 inline Cycles zero_time() { return Cycles(0); }
69 
70 inline Cycles intToCycles(int c) { return Cycles(c); }
71 
72 inline Tick intToTick(int c) { return c; }
73 
74 inline NodeID
75 intToID(int nodenum)
76 {
77  NodeID id = nodenum;
78  return id;
79 }
80 
81 inline int
83 {
84  int nodenum = id;
85  return nodenum;
86 }
87 
88 inline int
90 {
91  assert(!(addr & 0xffffffff00000000));
92  return addr;
93 }
94 
95 inline Addr
97 {
98  assert(!(addr & 0xffffffff00000000));
99  return addr;
100 }
101 
102 inline int
103 mod(int val, int mod)
104 {
105  return val % mod;
106 }
107 
108 inline int max_tokens()
109 {
110  return 1024;
111 }
112 
113 inline bool
114 isWriteRequest(RubyRequestType type)
115 {
116  if ((type == RubyRequestType_ST) ||
117  (type == RubyRequestType_ATOMIC) ||
118  (type == RubyRequestType_RMW_Read) ||
119  (type == RubyRequestType_RMW_Write) ||
120  (type == RubyRequestType_Store_Conditional) ||
121  (type == RubyRequestType_Locked_RMW_Read) ||
122  (type == RubyRequestType_Locked_RMW_Write) ||
123  (type == RubyRequestType_FLUSH)) {
124  return true;
125  } else {
126  return false;
127  }
128 }
129 
130 inline bool
131 isDataReadRequest(RubyRequestType type)
132 {
133  if ((type == RubyRequestType_LD) ||
134  (type == RubyRequestType_Load_Linked)) {
135  return true;
136  } else {
137  return false;
138  }
139 }
140 
141 inline bool
142 isReadRequest(RubyRequestType type)
143 {
144  if (isDataReadRequest(type) ||
145  (type == RubyRequestType_IFETCH)) {
146  return true;
147  } else {
148  return false;
149  }
150 }
151 
152 inline bool
153 isHtmCmdRequest(RubyRequestType type)
154 {
155  if ((type == RubyRequestType_HTM_Start) ||
156  (type == RubyRequestType_HTM_Commit) ||
157  (type == RubyRequestType_HTM_Cancel) ||
158  (type == RubyRequestType_HTM_Abort)) {
159  return true;
160  } else {
161  return false;
162  }
163 }
164 
165 inline bool
166 isTlbiCmdRequest(RubyRequestType type)
167 {
168  if ((type == RubyRequestType_TLBI) ||
169  (type == RubyRequestType_TLBI_SYNC) ||
170  (type == RubyRequestType_TLBI_EXT_SYNC) ||
171  (type == RubyRequestType_TLBI_EXT_SYNC_COMP)) {
172  return true;
173  } else {
174  return false;
175  }
176 }
177 
178 inline RubyRequestType
180 {
181  if (pkt->req->isHTMStart()) {
182  return RubyRequestType_HTM_Start;
183  } else if (pkt->req->isHTMCommit()) {
184  return RubyRequestType_HTM_Commit;
185  } else if (pkt->req->isHTMCancel()) {
186  return RubyRequestType_HTM_Cancel;
187  } else if (pkt->req->isHTMAbort()) {
188  return RubyRequestType_HTM_Abort;
189  }
190  else {
191  panic("invalid ruby packet type\n");
192  }
193 }
194 
195 inline RubyRequestType
197 {
198  if (pkt->req->isTlbi()) {
199  return RubyRequestType_TLBI;
200  } else if (pkt->req->isTlbiSync()) {
201  return RubyRequestType_TLBI_SYNC;
202  } else if (pkt->req->isTlbiExtSync()) {
203  return RubyRequestType_TLBI_EXT_SYNC;
204  } else if (pkt->req->isTlbiExtSyncComp()) {
205  return RubyRequestType_TLBI_EXT_SYNC_COMP;
206  } else {
207  panic("invalid ruby packet type\n");
208  }
209 }
210 
211 inline int
213 {
214  assert(addr >= base);
215  Addr offset = addr - base;
216  // sanity checks if fits in an int
217  assert(offset < INT_MAX);
218  return offset;
219 }
220 
233 inline bool
235 {
236  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
237  Addr lineAddr = makeLineAddress(addr);
238 
239  if (pktLineAddr == lineAddr) {
240  uint8_t *data = pkt->getPtr<uint8_t>();
241  unsigned int size_in_bytes = pkt->getSize();
242  unsigned startByte = pkt->getAddr() - lineAddr;
243 
244  for (unsigned i = 0; i < size_in_bytes; ++i) {
245  data[i] = blk.getByte(i + startByte);
246  }
247  return true;
248  }
249  return false;
250 }
251 
259 inline bool
261 {
262  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
263  Addr lineAddr = makeLineAddress(addr);
264 
265  if (pktLineAddr == lineAddr) {
266  uint8_t *data = pkt->getPtr<uint8_t>();
267  unsigned int size_in_bytes = pkt->getSize();
268  unsigned startByte = pkt->getAddr() - lineAddr;
269  bool was_read = false;
270 
271  for (unsigned i = 0; i < size_in_bytes; ++i) {
272  if (mask.test(i + startByte)) {
273  was_read = true;
274  data[i] = blk.getByte(i + startByte);
275  }
276  }
277  return was_read;
278  }
279  return false;
280 }
281 
288 inline bool
290 {
291  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
292  Addr lineAddr = makeLineAddress(addr);
293 
294  if (pktLineAddr == lineAddr) {
295  const uint8_t *data = pkt->getConstPtr<uint8_t>();
296  unsigned int size_in_bytes = pkt->getSize();
297  unsigned startByte = pkt->getAddr() - lineAddr;
298 
299  for (unsigned i = 0; i < size_in_bytes; ++i) {
300  blk.setByte(i + startByte, data[i]);
301  }
302  return true;
303  }
304  return false;
305 }
306 
307 inline int
309 {
310  int count = 0;
311  for (const bool e: bVec) {
312  if (e) {
313  count++;
314  }
315  }
316  return count;
317 }
318 
319 } // namespace ruby
320 } // namespace gem5
321 
322 #endif //__MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
gem5::ruby::WriteMask
Definition: WriteMask.hh:59
gem5::ruby::intToID
NodeID intToID(int nodenum)
Definition: RubySlicc_Util.hh:75
gem5::ruby::htmCmdToRubyRequestType
RubyRequestType htmCmdToRubyRequestType(const Packet *pkt)
Definition: RubySlicc_Util.hh:179
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::ruby::DataBlock::getByte
uint8_t getByte(int whichByte) const
Definition: DataBlock.hh:111
gem5::Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:374
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:65
gem5::ruby::zero_time
Cycles zero_time()
Definition: RubySlicc_Util.hh:68
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
std::vector< bool >
BoolVec.hh
gem5::X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::ruby::makeLineAddress
Addr makeLineAddress(Addr addr)
Definition: Address.cc:60
gem5::ruby::tlbiCmdToRubyRequestType
RubyRequestType tlbiCmdToRubyRequestType(const Packet *pkt)
Definition: RubySlicc_Util.hh:196
gem5::ruby::intToTick
Tick intToTick(int c)
Definition: RubySlicc_Util.hh:72
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
packet.hh
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::ruby::intToAddress
Addr intToAddress(int addr)
Definition: RubySlicc_Util.hh:96
gem5::VegaISA::c
Bitfield< 2 > c
Definition: pagetable.hh:63
gem5::ruby::isDataReadRequest
bool isDataReadRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:131
gem5::ruby::isReadRequest
bool isReadRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:142
gem5::ruby::intToCycles
Cycles intToCycles(int c)
Definition: RubySlicc_Util.hh:70
gem5::X86ISA::count
count
Definition: misc.hh:703
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:291
gem5::ruby::testAndReadMask
bool testAndReadMask(Addr addr, DataBlock &blk, WriteMask &mask, Packet *pkt)
This function accepts an address, a data block, a write mask and a packet.
Definition: RubySlicc_Util.hh:260
DataBlock.hh
TypeDefines.hh
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
WriteMask.hh
gem5::X86ISA::type
type
Definition: misc.hh:727
gem5::Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1206
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::ruby::isWriteRequest
bool isWriteRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:114
gem5::ruby::DataBlock::setByte
void setByte(int whichByte, uint8_t data)
Definition: DataBlock.hh:117
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::ruby::addressToInt
int addressToInt(Addr addr)
Definition: RubySlicc_Util.hh:89
gem5::ruby::IDToInt
int IDToInt(NodeID id)
Definition: RubySlicc_Util.hh:82
gem5::ruby::testAndRead
bool testAndRead(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Definition: RubySlicc_Util.hh:234
gem5::ruby::isHtmCmdRequest
bool isHtmCmdRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:153
Address.hh
gem5::ruby::isTlbiCmdRequest
bool isTlbiCmdRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:166
gem5::ArmISA::id
Bitfield< 33 > id
Definition: misc_types.hh:251
gem5::ruby::NodeID
unsigned int NodeID
Definition: TypeDefines.hh:42
gem5::ruby::testAndWrite
bool testAndWrite(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Definition: RubySlicc_Util.hh:289
gem5::ruby::countBoolVec
int countBoolVec(BoolVec bVec)
Definition: RubySlicc_Util.hh:308
gem5::ruby::addressOffset
int addressOffset(Addr addr, Addr base)
Definition: RubySlicc_Util.hh:212
gem5::ruby::DataBlock
Definition: DataBlock.hh:60
gem5::ruby::max_tokens
int max_tokens()
Definition: RubySlicc_Util.hh:108
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:790
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::ruby::mod
int mod(int val, int mod)
Definition: RubySlicc_Util.hh:103
gem5::Packet::getSize
unsigned getSize() const
Definition: packet.hh:800
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1197

Generated on Sat Jun 18 2022 08:12:30 for gem5 by doxygen 1.8.17