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