gem5  v22.1.0.0
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__
const char data[]
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1212
Addr getAddr() const
Definition: packet.hh:805
RequestPtr req
A pointer to the original request.
Definition: packet.hh:376
unsigned getSize() const
Definition: packet.hh:815
const T * getConstPtr() const
Definition: packet.hh:1221
uint8_t getByte(int whichByte) const
Definition: DataBlock.hh:111
void setByte(int whichByte, uint8_t data)
Definition: DataBlock.hh:117
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 9 > e
Definition: misc_types.hh:65
Bitfield< 33 > id
Definition: misc_types.hh:257
Bitfield< 2 > c
Definition: pagetable.hh:63
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 3 > addr
Definition: types.hh:84
NodeID intToID(int nodenum)
bool testAndRead(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Cycles intToCycles(int c)
int countBoolVec(BoolVec bVec)
bool testAndWrite(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
bool isWriteRequest(RubyRequestType type)
bool isReadRequest(RubyRequestType type)
RubyRequestType tlbiCmdToRubyRequestType(const Packet *pkt)
Addr intToAddress(int addr)
bool isTlbiCmdRequest(RubyRequestType type)
Cycles zero_time()
Tick intToTick(int c)
unsigned int NodeID
Definition: TypeDefines.hh:42
Addr makeLineAddress(Addr addr)
Definition: Address.cc:60
int addressToInt(Addr addr)
RubyRequestType htmCmdToRubyRequestType(const Packet *pkt)
int IDToInt(NodeID id)
bool testAndReadMask(Addr addr, DataBlock &blk, WriteMask &mask, Packet *pkt)
This function accepts an address, a data block, a write mask and a packet.
bool isDataReadRequest(RubyRequestType type)
int addressOffset(Addr addr, Addr base)
int mod(int val, int mod)
bool isHtmCmdRequest(RubyRequestType type)
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint64_t Tick
Tick count type.
Definition: types.hh:58
Declaration of the Packet class.

Generated on Wed Dec 21 2022 10:22:38 for gem5 by doxygen 1.9.1