request.hh (6899:f8057af86bf7) request.hh (7612:917946898102)
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ron Dreslinski
29 * Steve Reinhardt
30 * Ali Saidi
31 */
32
33/**
34 * @file
35 * Declaration of a request, the overall memory request consisting of
36 the parts of the request that are persistent throughout the transaction.
37 */
38
39#ifndef __MEM_REQUEST_HH__
40#define __MEM_REQUEST_HH__
41
42#include <cassert>
43
44#include "base/fast_alloc.hh"
45#include "base/flags.hh"
46#include "base/misc.hh"
47#include "base/types.hh"
48#include "sim/core.hh"
49
50class Request;
51
52typedef Request* RequestPtr;
53
54class Request : public FastAlloc
55{
56 public:
57 typedef uint32_t FlagsType;
58 typedef ::Flags<FlagsType> Flags;
59
60 /** ASI information for this request if it exists. */
61 static const FlagsType ASI_BITS = 0x000000FF;
62 /** The request was an instruction fetch. */
63 static const FlagsType INST_FETCH = 0x00000100;
64 /** The virtual address is also the physical address. */
65 static const FlagsType PHYSICAL = 0x00000200;
66 /** The request is an ALPHA VPTE pal access (hw_ld). */
67 static const FlagsType VPTE = 0x00000400;
68 /** Use the alternate mode bits in ALPHA. */
69 static const FlagsType ALTMODE = 0x00000800;
70 /** The request is to an uncacheable address. */
71 static const FlagsType UNCACHEABLE = 0x00001000;
72 /** This request is to a memory mapped register. */
73 static const FlagsType MMAPED_IPR = 0x00002000;
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ron Dreslinski
29 * Steve Reinhardt
30 * Ali Saidi
31 */
32
33/**
34 * @file
35 * Declaration of a request, the overall memory request consisting of
36 the parts of the request that are persistent throughout the transaction.
37 */
38
39#ifndef __MEM_REQUEST_HH__
40#define __MEM_REQUEST_HH__
41
42#include <cassert>
43
44#include "base/fast_alloc.hh"
45#include "base/flags.hh"
46#include "base/misc.hh"
47#include "base/types.hh"
48#include "sim/core.hh"
49
50class Request;
51
52typedef Request* RequestPtr;
53
54class Request : public FastAlloc
55{
56 public:
57 typedef uint32_t FlagsType;
58 typedef ::Flags<FlagsType> Flags;
59
60 /** ASI information for this request if it exists. */
61 static const FlagsType ASI_BITS = 0x000000FF;
62 /** The request was an instruction fetch. */
63 static const FlagsType INST_FETCH = 0x00000100;
64 /** The virtual address is also the physical address. */
65 static const FlagsType PHYSICAL = 0x00000200;
66 /** The request is an ALPHA VPTE pal access (hw_ld). */
67 static const FlagsType VPTE = 0x00000400;
68 /** Use the alternate mode bits in ALPHA. */
69 static const FlagsType ALTMODE = 0x00000800;
70 /** The request is to an uncacheable address. */
71 static const FlagsType UNCACHEABLE = 0x00001000;
72 /** This request is to a memory mapped register. */
73 static const FlagsType MMAPED_IPR = 0x00002000;
74 /** This request is a clear exclusive. */
75 static const FlagsType CLREX = 0x00004000;
74
75 /** The request should ignore unaligned access faults */
76 static const FlagsType NO_ALIGN_FAULT = 0x00020000;
77 /** The request should ignore unaligned access faults */
78 static const FlagsType NO_HALF_WORD_ALIGN_FAULT = 0x00040000;
79 /** The request should not cause a memory access. */
80 static const FlagsType NO_ACCESS = 0x00080000;
81 /** This request will lock or unlock the accessed memory. When used with
82 * a load, the access locks the particular chunk of memory. When used
83 * with a store, it unlocks. The rule is that locked accesses have to be
84 * made up of a locked load, some operation on the data, and then a locked
85 * store.
86 */
87 static const FlagsType LOCKED = 0x00100000;
88 /** The request is a Load locked/store conditional. */
89 static const FlagsType LLSC = 0x00200000;
90 /** This request is for a memory swap. */
91 static const FlagsType MEM_SWAP = 0x00400000;
92 static const FlagsType MEM_SWAP_COND = 0x00800000;
93
94 /** The request is a prefetch. */
95 static const FlagsType PREFETCH = 0x01000000;
96 /** The request should be prefetched into the exclusive state. */
97 static const FlagsType PF_EXCLUSIVE = 0x02000000;
98 /** The request should be marked as LRU. */
99 static const FlagsType EVICT_NEXT = 0x04000000;
100
101 /** These flags are *not* cleared when a Request object is reused
102 (assigned a new address). */
103 static const FlagsType STICKY_FLAGS = INST_FETCH;
104
105 private:
106 typedef uint8_t PrivateFlagsType;
107 typedef ::Flags<PrivateFlagsType> PrivateFlags;
108
109 /** Whether or not the size is valid. */
110 static const PrivateFlagsType VALID_SIZE = 0x00000001;
111 /** Whether or not paddr is valid (has been written yet). */
112 static const PrivateFlagsType VALID_PADDR = 0x00000002;
113 /** Whether or not the vaddr & asid are valid. */
114 static const PrivateFlagsType VALID_VADDR = 0x00000004;
115 /** Whether or not the pc is valid. */
116 static const PrivateFlagsType VALID_PC = 0x00000010;
117 /** Whether or not the context ID is valid. */
118 static const PrivateFlagsType VALID_CONTEXT_ID = 0x00000020;
119 static const PrivateFlagsType VALID_THREAD_ID = 0x00000040;
120 /** Whether or not the sc result is valid. */
121 static const PrivateFlagsType VALID_EXTRA_DATA = 0x00000080;
122
123 /** These flags are *not* cleared when a Request object is reused
124 (assigned a new address). */
125 static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
126 VALID_CONTEXT_ID | VALID_THREAD_ID;
127
128 private:
129 /**
130 * The physical address of the request. Valid only if validPaddr
131 * is set.
132 */
133 Addr _paddr;
134
135 /**
136 * The size of the request. This field must be set when vaddr or
137 * paddr is written via setVirt() or setPhys(), so it is always
138 * valid as long as one of the address fields is valid.
139 */
140 int _size;
141
142 /** Flag structure for the request. */
143 Flags _flags;
144
145 /** Private flags for field validity checking. */
146 PrivateFlags privateFlags;
147
148 /**
149 * The time this request was started. Used to calculate
150 * latencies. This field is set to curTick any time paddr or vaddr
151 * is written.
152 */
153 Tick _time;
154
155 /** The address space ID. */
156 int _asid;
157
158 /** The virtual address of the request. */
159 Addr _vaddr;
160
161 /**
162 * Extra data for the request, such as the return value of
163 * store conditional or the compare value for a CAS. */
164 uint64_t _extraData;
165
166 /** The context ID (for statistics, typically). */
167 int _contextId;
168 /** The thread ID (id within this CPU) */
169 int _threadId;
170
171 /** program counter of initiating access; for tracing/debugging */
172 Addr _pc;
173
174 public:
175 /** Minimal constructor. No fields are initialized.
176 * (Note that _flags and privateFlags are cleared by Flags
177 * default constructor.)
178 */
179 Request()
180 {}
181
182 /**
183 * Constructor for physical (e.g. device) requests. Initializes
184 * just physical address, size, flags, and timestamp (to curTick).
185 * These fields are adequate to perform a request.
186 */
187 Request(Addr paddr, int size, Flags flags)
188 {
189 setPhys(paddr, size, flags);
190 }
191
192 Request(Addr paddr, int size, Flags flags, Tick time)
193 {
194 setPhys(paddr, size, flags, time);
195 }
196
197 Request(Addr paddr, int size, Flags flags, Tick time, Addr pc)
198 {
199 setPhys(paddr, size, flags, time);
200 privateFlags.set(VALID_PC);
201 _pc = pc;
202 }
203
204 Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
205 int cid, ThreadID tid)
206 {
207 setVirt(asid, vaddr, size, flags, pc);
208 setThreadContext(cid, tid);
209 }
210
211 ~Request() {} // for FastAlloc
212
213 /**
214 * Set up CPU and thread numbers.
215 */
216 void
217 setThreadContext(int context_id, ThreadID tid)
218 {
219 _contextId = context_id;
220 _threadId = tid;
221 privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
222 }
223
224 /**
225 * Set up a physical (e.g. device) request in a previously
226 * allocated Request object.
227 */
228 void
229 setPhys(Addr paddr, int size, Flags flags, Tick time)
230 {
231 assert(size >= 0);
232 _paddr = paddr;
233 _size = size;
234 _time = time;
235
236 _flags.clear(~STICKY_FLAGS);
237 _flags.set(flags);
238 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
239 privateFlags.set(VALID_PADDR|VALID_SIZE);
240 }
241
242 void
243 setPhys(Addr paddr, int size, Flags flags)
244 {
245 setPhys(paddr, size, flags, curTick);
246 }
247
248 /**
249 * Set up a virtual (e.g., CPU) request in a previously
250 * allocated Request object.
251 */
252 void
253 setVirt(int asid, Addr vaddr, int size, Flags flags, Addr pc)
254 {
255 assert(size >= 0);
256 _asid = asid;
257 _vaddr = vaddr;
258 _size = size;
259 _pc = pc;
260 _time = curTick;
261
262 _flags.clear(~STICKY_FLAGS);
263 _flags.set(flags);
264 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
265 privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
266 }
267
268 /**
269 * Set just the physical address. This should only be used to
270 * record the result of a translation, and thus the vaddr must be
271 * valid before this method is called. Otherwise, use setPhys()
272 * to guarantee that the size and flags are also set.
273 */
274 void
275 setPaddr(Addr paddr)
276 {
277 assert(privateFlags.isSet(VALID_VADDR));
278 _paddr = paddr;
279 privateFlags.set(VALID_PADDR);
280 }
281
282 /**
283 * Generate two requests as if this request had been split into two
284 * pieces. The original request can't have been translated already.
285 */
286 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
287 {
288 assert(privateFlags.isSet(VALID_VADDR));
289 assert(privateFlags.noneSet(VALID_PADDR));
290 assert(split_addr > _vaddr && split_addr < _vaddr + _size);
291 req1 = new Request;
292 *req1 = *this;
293 req2 = new Request;
294 *req2 = *this;
295 req1->_size = split_addr - _vaddr;
296 req2->_vaddr = split_addr;
297 req2->_size = _size - req1->_size;
298 }
299
300 /**
301 * Accessor for paddr.
302 */
303 bool
304 hasPaddr()
305 {
306 return privateFlags.isSet(VALID_PADDR);
307 }
308
309 Addr
310 getPaddr()
311 {
312 assert(privateFlags.isSet(VALID_PADDR));
313 return _paddr;
314 }
315
316 /**
317 * Accessor for size.
318 */
319 bool
320 hasSize()
321 {
322 return privateFlags.isSet(VALID_SIZE);
323 }
324
325 int
326 getSize()
327 {
328 assert(privateFlags.isSet(VALID_SIZE));
329 return _size;
330 }
331
332 /** Accessor for time. */
333 Tick
334 time() const
335 {
336 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
337 return _time;
338 }
339
340 void
341 time(Tick time)
342 {
343 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
344 _time = time;
345 }
346
347 /** Accessor for flags. */
348 Flags
349 getFlags()
350 {
351 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
352 return _flags;
353 }
354
355 /** Note that unlike other accessors, this function sets *specific
356 flags* (ORs them in); it does not assign its argument to the
357 _flags field. Thus this method should rightly be called
358 setFlags() and not just flags(). */
359 void
360 setFlags(Flags flags)
361 {
362 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
363 _flags.set(flags);
364 }
365
366 /** Accessor function for vaddr.*/
367 Addr
368 getVaddr()
369 {
370 assert(privateFlags.isSet(VALID_VADDR));
371 return _vaddr;
372 }
373
374 /** Accessor function for asid.*/
375 int
376 getAsid()
377 {
378 assert(privateFlags.isSet(VALID_VADDR));
379 return _asid;
380 }
381
382 /** Accessor function for asi.*/
383 uint8_t
384 getAsi()
385 {
386 assert(privateFlags.isSet(VALID_VADDR));
387 return _flags & ASI_BITS;
388 }
389
390 /** Accessor function to check if sc result is valid. */
391 bool
392 extraDataValid()
393 {
394 return privateFlags.isSet(VALID_EXTRA_DATA);
395 }
396
397 /** Accessor function for store conditional return value.*/
398 uint64_t
399 getExtraData() const
400 {
401 assert(privateFlags.isSet(VALID_EXTRA_DATA));
402 return _extraData;
403 }
404
405 /** Accessor function for store conditional return value.*/
406 void
407 setExtraData(uint64_t extraData)
408 {
409 _extraData = extraData;
410 privateFlags.set(VALID_EXTRA_DATA);
411 }
412
413 bool
414 hasContextId() const
415 {
416 return privateFlags.isSet(VALID_CONTEXT_ID);
417 }
418
419 /** Accessor function for context ID.*/
420 int
421 contextId() const
422 {
423 assert(privateFlags.isSet(VALID_CONTEXT_ID));
424 return _contextId;
425 }
426
427 /** Accessor function for thread ID. */
428 int
429 threadId() const
430 {
431 assert(privateFlags.isSet(VALID_THREAD_ID));
432 return _threadId;
433 }
434
435 bool
436 hasPC() const
437 {
438 return privateFlags.isSet(VALID_PC);
439 }
440
441 /** Accessor function for pc.*/
442 Addr
443 getPC() const
444 {
445 assert(privateFlags.isSet(VALID_PC));
446 return _pc;
447 }
448
449 /** Accessor functions for flags. Note that these are for testing
450 only; setting flags should be done via setFlags(). */
451 bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
452 bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
453 bool isPrefetch() const { return _flags.isSet(PREFETCH); }
454 bool isLLSC() const { return _flags.isSet(LLSC); }
455 bool isLocked() const { return _flags.isSet(LOCKED); }
456 bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
457 bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
458 bool isMmapedIpr() const { return _flags.isSet(MMAPED_IPR); }
76
77 /** The request should ignore unaligned access faults */
78 static const FlagsType NO_ALIGN_FAULT = 0x00020000;
79 /** The request should ignore unaligned access faults */
80 static const FlagsType NO_HALF_WORD_ALIGN_FAULT = 0x00040000;
81 /** The request should not cause a memory access. */
82 static const FlagsType NO_ACCESS = 0x00080000;
83 /** This request will lock or unlock the accessed memory. When used with
84 * a load, the access locks the particular chunk of memory. When used
85 * with a store, it unlocks. The rule is that locked accesses have to be
86 * made up of a locked load, some operation on the data, and then a locked
87 * store.
88 */
89 static const FlagsType LOCKED = 0x00100000;
90 /** The request is a Load locked/store conditional. */
91 static const FlagsType LLSC = 0x00200000;
92 /** This request is for a memory swap. */
93 static const FlagsType MEM_SWAP = 0x00400000;
94 static const FlagsType MEM_SWAP_COND = 0x00800000;
95
96 /** The request is a prefetch. */
97 static const FlagsType PREFETCH = 0x01000000;
98 /** The request should be prefetched into the exclusive state. */
99 static const FlagsType PF_EXCLUSIVE = 0x02000000;
100 /** The request should be marked as LRU. */
101 static const FlagsType EVICT_NEXT = 0x04000000;
102
103 /** These flags are *not* cleared when a Request object is reused
104 (assigned a new address). */
105 static const FlagsType STICKY_FLAGS = INST_FETCH;
106
107 private:
108 typedef uint8_t PrivateFlagsType;
109 typedef ::Flags<PrivateFlagsType> PrivateFlags;
110
111 /** Whether or not the size is valid. */
112 static const PrivateFlagsType VALID_SIZE = 0x00000001;
113 /** Whether or not paddr is valid (has been written yet). */
114 static const PrivateFlagsType VALID_PADDR = 0x00000002;
115 /** Whether or not the vaddr & asid are valid. */
116 static const PrivateFlagsType VALID_VADDR = 0x00000004;
117 /** Whether or not the pc is valid. */
118 static const PrivateFlagsType VALID_PC = 0x00000010;
119 /** Whether or not the context ID is valid. */
120 static const PrivateFlagsType VALID_CONTEXT_ID = 0x00000020;
121 static const PrivateFlagsType VALID_THREAD_ID = 0x00000040;
122 /** Whether or not the sc result is valid. */
123 static const PrivateFlagsType VALID_EXTRA_DATA = 0x00000080;
124
125 /** These flags are *not* cleared when a Request object is reused
126 (assigned a new address). */
127 static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
128 VALID_CONTEXT_ID | VALID_THREAD_ID;
129
130 private:
131 /**
132 * The physical address of the request. Valid only if validPaddr
133 * is set.
134 */
135 Addr _paddr;
136
137 /**
138 * The size of the request. This field must be set when vaddr or
139 * paddr is written via setVirt() or setPhys(), so it is always
140 * valid as long as one of the address fields is valid.
141 */
142 int _size;
143
144 /** Flag structure for the request. */
145 Flags _flags;
146
147 /** Private flags for field validity checking. */
148 PrivateFlags privateFlags;
149
150 /**
151 * The time this request was started. Used to calculate
152 * latencies. This field is set to curTick any time paddr or vaddr
153 * is written.
154 */
155 Tick _time;
156
157 /** The address space ID. */
158 int _asid;
159
160 /** The virtual address of the request. */
161 Addr _vaddr;
162
163 /**
164 * Extra data for the request, such as the return value of
165 * store conditional or the compare value for a CAS. */
166 uint64_t _extraData;
167
168 /** The context ID (for statistics, typically). */
169 int _contextId;
170 /** The thread ID (id within this CPU) */
171 int _threadId;
172
173 /** program counter of initiating access; for tracing/debugging */
174 Addr _pc;
175
176 public:
177 /** Minimal constructor. No fields are initialized.
178 * (Note that _flags and privateFlags are cleared by Flags
179 * default constructor.)
180 */
181 Request()
182 {}
183
184 /**
185 * Constructor for physical (e.g. device) requests. Initializes
186 * just physical address, size, flags, and timestamp (to curTick).
187 * These fields are adequate to perform a request.
188 */
189 Request(Addr paddr, int size, Flags flags)
190 {
191 setPhys(paddr, size, flags);
192 }
193
194 Request(Addr paddr, int size, Flags flags, Tick time)
195 {
196 setPhys(paddr, size, flags, time);
197 }
198
199 Request(Addr paddr, int size, Flags flags, Tick time, Addr pc)
200 {
201 setPhys(paddr, size, flags, time);
202 privateFlags.set(VALID_PC);
203 _pc = pc;
204 }
205
206 Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
207 int cid, ThreadID tid)
208 {
209 setVirt(asid, vaddr, size, flags, pc);
210 setThreadContext(cid, tid);
211 }
212
213 ~Request() {} // for FastAlloc
214
215 /**
216 * Set up CPU and thread numbers.
217 */
218 void
219 setThreadContext(int context_id, ThreadID tid)
220 {
221 _contextId = context_id;
222 _threadId = tid;
223 privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
224 }
225
226 /**
227 * Set up a physical (e.g. device) request in a previously
228 * allocated Request object.
229 */
230 void
231 setPhys(Addr paddr, int size, Flags flags, Tick time)
232 {
233 assert(size >= 0);
234 _paddr = paddr;
235 _size = size;
236 _time = time;
237
238 _flags.clear(~STICKY_FLAGS);
239 _flags.set(flags);
240 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
241 privateFlags.set(VALID_PADDR|VALID_SIZE);
242 }
243
244 void
245 setPhys(Addr paddr, int size, Flags flags)
246 {
247 setPhys(paddr, size, flags, curTick);
248 }
249
250 /**
251 * Set up a virtual (e.g., CPU) request in a previously
252 * allocated Request object.
253 */
254 void
255 setVirt(int asid, Addr vaddr, int size, Flags flags, Addr pc)
256 {
257 assert(size >= 0);
258 _asid = asid;
259 _vaddr = vaddr;
260 _size = size;
261 _pc = pc;
262 _time = curTick;
263
264 _flags.clear(~STICKY_FLAGS);
265 _flags.set(flags);
266 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
267 privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
268 }
269
270 /**
271 * Set just the physical address. This should only be used to
272 * record the result of a translation, and thus the vaddr must be
273 * valid before this method is called. Otherwise, use setPhys()
274 * to guarantee that the size and flags are also set.
275 */
276 void
277 setPaddr(Addr paddr)
278 {
279 assert(privateFlags.isSet(VALID_VADDR));
280 _paddr = paddr;
281 privateFlags.set(VALID_PADDR);
282 }
283
284 /**
285 * Generate two requests as if this request had been split into two
286 * pieces. The original request can't have been translated already.
287 */
288 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
289 {
290 assert(privateFlags.isSet(VALID_VADDR));
291 assert(privateFlags.noneSet(VALID_PADDR));
292 assert(split_addr > _vaddr && split_addr < _vaddr + _size);
293 req1 = new Request;
294 *req1 = *this;
295 req2 = new Request;
296 *req2 = *this;
297 req1->_size = split_addr - _vaddr;
298 req2->_vaddr = split_addr;
299 req2->_size = _size - req1->_size;
300 }
301
302 /**
303 * Accessor for paddr.
304 */
305 bool
306 hasPaddr()
307 {
308 return privateFlags.isSet(VALID_PADDR);
309 }
310
311 Addr
312 getPaddr()
313 {
314 assert(privateFlags.isSet(VALID_PADDR));
315 return _paddr;
316 }
317
318 /**
319 * Accessor for size.
320 */
321 bool
322 hasSize()
323 {
324 return privateFlags.isSet(VALID_SIZE);
325 }
326
327 int
328 getSize()
329 {
330 assert(privateFlags.isSet(VALID_SIZE));
331 return _size;
332 }
333
334 /** Accessor for time. */
335 Tick
336 time() const
337 {
338 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
339 return _time;
340 }
341
342 void
343 time(Tick time)
344 {
345 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
346 _time = time;
347 }
348
349 /** Accessor for flags. */
350 Flags
351 getFlags()
352 {
353 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
354 return _flags;
355 }
356
357 /** Note that unlike other accessors, this function sets *specific
358 flags* (ORs them in); it does not assign its argument to the
359 _flags field. Thus this method should rightly be called
360 setFlags() and not just flags(). */
361 void
362 setFlags(Flags flags)
363 {
364 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
365 _flags.set(flags);
366 }
367
368 /** Accessor function for vaddr.*/
369 Addr
370 getVaddr()
371 {
372 assert(privateFlags.isSet(VALID_VADDR));
373 return _vaddr;
374 }
375
376 /** Accessor function for asid.*/
377 int
378 getAsid()
379 {
380 assert(privateFlags.isSet(VALID_VADDR));
381 return _asid;
382 }
383
384 /** Accessor function for asi.*/
385 uint8_t
386 getAsi()
387 {
388 assert(privateFlags.isSet(VALID_VADDR));
389 return _flags & ASI_BITS;
390 }
391
392 /** Accessor function to check if sc result is valid. */
393 bool
394 extraDataValid()
395 {
396 return privateFlags.isSet(VALID_EXTRA_DATA);
397 }
398
399 /** Accessor function for store conditional return value.*/
400 uint64_t
401 getExtraData() const
402 {
403 assert(privateFlags.isSet(VALID_EXTRA_DATA));
404 return _extraData;
405 }
406
407 /** Accessor function for store conditional return value.*/
408 void
409 setExtraData(uint64_t extraData)
410 {
411 _extraData = extraData;
412 privateFlags.set(VALID_EXTRA_DATA);
413 }
414
415 bool
416 hasContextId() const
417 {
418 return privateFlags.isSet(VALID_CONTEXT_ID);
419 }
420
421 /** Accessor function for context ID.*/
422 int
423 contextId() const
424 {
425 assert(privateFlags.isSet(VALID_CONTEXT_ID));
426 return _contextId;
427 }
428
429 /** Accessor function for thread ID. */
430 int
431 threadId() const
432 {
433 assert(privateFlags.isSet(VALID_THREAD_ID));
434 return _threadId;
435 }
436
437 bool
438 hasPC() const
439 {
440 return privateFlags.isSet(VALID_PC);
441 }
442
443 /** Accessor function for pc.*/
444 Addr
445 getPC() const
446 {
447 assert(privateFlags.isSet(VALID_PC));
448 return _pc;
449 }
450
451 /** Accessor functions for flags. Note that these are for testing
452 only; setting flags should be done via setFlags(). */
453 bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
454 bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
455 bool isPrefetch() const { return _flags.isSet(PREFETCH); }
456 bool isLLSC() const { return _flags.isSet(LLSC); }
457 bool isLocked() const { return _flags.isSet(LOCKED); }
458 bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
459 bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
460 bool isMmapedIpr() const { return _flags.isSet(MMAPED_IPR); }
461 bool isClrex() const { return _flags.isSet(CLREX); }
459
460 bool
461 isMisaligned() const
462 {
463 if (_flags.isSet(NO_ALIGN_FAULT))
464 return false;
465
466 if ((_vaddr & 0x1))
467 return true;
468
469 if (_flags.isSet(NO_HALF_WORD_ALIGN_FAULT))
470 return false;
471
472 if ((_vaddr & 0x2))
473 return true;
474
475 return false;
476 }
477};
478
479#endif // __MEM_REQUEST_HH__
462
463 bool
464 isMisaligned() const
465 {
466 if (_flags.isSet(NO_ALIGN_FAULT))
467 return false;
468
469 if ((_vaddr & 0x1))
470 return true;
471
472 if (_flags.isSet(NO_HALF_WORD_ALIGN_FAULT))
473 return false;
474
475 if ((_vaddr & 0x2))
476 return true;
477
478 return false;
479 }
480};
481
482#endif // __MEM_REQUEST_HH__