mem: Rename the ASI_BITS flag field in Request
[gem5.git] / src / mem / request.hh
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
70 namespace 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
80 class Request;
81
82 typedef Request* RequestPtr;
83 typedef uint16_t MasterID;
84
85 class Request
86 {
87 public:
88 typedef uint32_t FlagsType;
89 typedef uint8_t ArchFlagsType;
90 typedef ::Flags<FlagsType> Flags;
91
92 /**
93 * Architecture specific flags.
94 *
95 * These bits int the flag field are reserved for
96 * architecture-specific code. For example, SPARC uses them to
97 * represent ASIs.
98 */
99 static const FlagsType ARCH_BITS = 0x000000FF;
100 /** The request was an instruction fetch. */
101 static const FlagsType INST_FETCH = 0x00000100;
102 /** The virtual address is also the physical address. */
103 static const FlagsType PHYSICAL = 0x00000200;
104 /** The request is an ALPHA VPTE pal access (hw_ld). */
105 static const FlagsType VPTE = 0x00000400;
106 /** Use the alternate mode bits in ALPHA. */
107 static const FlagsType ALTMODE = 0x00000800;
108 /** The request is to an uncacheable address. */
109 static const FlagsType UNCACHEABLE = 0x00001000;
110 /** This request is to a memory mapped register. */
111 static const FlagsType MMAPPED_IPR = 0x00002000;
112 /** This request is a clear exclusive. */
113 static const FlagsType CLEAR_LL = 0x00004000;
114
115 /** The request should not cause a memory access. */
116 static const FlagsType NO_ACCESS = 0x00080000;
117 /** This request will lock or unlock the accessed memory. When used with
118 * a load, the access locks the particular chunk of memory. When used
119 * with a store, it unlocks. The rule is that locked accesses have to be
120 * made up of a locked load, some operation on the data, and then a locked
121 * store.
122 */
123 static const FlagsType LOCKED = 0x00100000;
124 /** The request is a Load locked/store conditional. */
125 static const FlagsType LLSC = 0x00200000;
126 /** This request is for a memory swap. */
127 static const FlagsType MEM_SWAP = 0x00400000;
128 static const FlagsType MEM_SWAP_COND = 0x00800000;
129
130 /** The request is a prefetch. */
131 static const FlagsType PREFETCH = 0x01000000;
132 /** The request should be prefetched into the exclusive state. */
133 static const FlagsType PF_EXCLUSIVE = 0x02000000;
134 /** The request should be marked as LRU. */
135 static const FlagsType EVICT_NEXT = 0x04000000;
136
137 /** The request should be handled by the generic IPR code (only
138 * valid together with MMAPPED_IPR) */
139 static const FlagsType GENERIC_IPR = 0x08000000;
140
141 /** These flags are *not* cleared when a Request object is reused
142 (assigned a new address). */
143 static const FlagsType STICKY_FLAGS = INST_FETCH;
144
145 /** Request Ids that are statically allocated
146 * @{*/
147 /** This request id is used for writeback requests by the caches */
148 static const MasterID wbMasterId = 0;
149 /** This request id is used for functional requests that don't come from a
150 * particular device
151 */
152 static const MasterID funcMasterId = 1;
153 /** This request id is used for message signaled interrupts */
154 static const MasterID intMasterId = 2;
155 /** Invalid request id for assertion checking only. It is invalid behavior
156 * to ever send this id as part of a request.
157 * @todo C++1x replace with numeric_limits when constexpr is added */
158 static const MasterID invldMasterId = USHRT_MAX;
159 /** @} */
160
161 /** Invalid or unknown Pid. Possible when operating system is not present
162 * or has not assigned a pid yet */
163 static const uint32_t invldPid = UINT_MAX;
164
165 private:
166 typedef uint8_t PrivateFlagsType;
167 typedef ::Flags<PrivateFlagsType> PrivateFlags;
168
169 /** Whether or not the size is valid. */
170 static const PrivateFlagsType VALID_SIZE = 0x00000001;
171 /** Whether or not paddr is valid (has been written yet). */
172 static const PrivateFlagsType VALID_PADDR = 0x00000002;
173 /** Whether or not the vaddr & asid are valid. */
174 static const PrivateFlagsType VALID_VADDR = 0x00000004;
175 /** Whether or not the pc is valid. */
176 static const PrivateFlagsType VALID_PC = 0x00000010;
177 /** Whether or not the context ID is valid. */
178 static const PrivateFlagsType VALID_CONTEXT_ID = 0x00000020;
179 static const PrivateFlagsType VALID_THREAD_ID = 0x00000040;
180 /** Whether or not the sc result is valid. */
181 static const PrivateFlagsType VALID_EXTRA_DATA = 0x00000080;
182
183 /** These flags are *not* cleared when a Request object is reused
184 (assigned a new address). */
185 static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
186 VALID_CONTEXT_ID | VALID_THREAD_ID;
187
188 private:
189 /**
190 * The physical address of the request. Valid only if validPaddr
191 * is set.
192 */
193 Addr _paddr;
194
195 /**
196 * The size of the request. This field must be set when vaddr or
197 * paddr is written via setVirt() or setPhys(), so it is always
198 * valid as long as one of the address fields is valid.
199 */
200 int _size;
201
202 /** The requestor ID which is unique in the system for all ports
203 * that are capable of issuing a transaction
204 */
205 MasterID _masterId;
206
207 /** Flag structure for the request. */
208 Flags _flags;
209
210 /** Private flags for field validity checking. */
211 PrivateFlags privateFlags;
212
213 /**
214 * The time this request was started. Used to calculate
215 * latencies. This field is set to curTick() any time paddr or vaddr
216 * is written.
217 */
218 Tick _time;
219
220 /** The address space ID. */
221 int _asid;
222
223 /** The virtual address of the request. */
224 Addr _vaddr;
225
226 /**
227 * Extra data for the request, such as the return value of
228 * store conditional or the compare value for a CAS. */
229 uint64_t _extraData;
230
231 /** The context ID (for statistics, typically). */
232 int _contextId;
233 /** The thread ID (id within this CPU) */
234 int _threadId;
235
236 /** program counter of initiating access; for tracing/debugging */
237 Addr _pc;
238
239 public:
240 /** Minimal constructor. No fields are initialized.
241 * (Note that _flags and privateFlags are cleared by Flags
242 * default constructor.)
243 */
244 Request()
245 {}
246
247 /**
248 * Constructor for physical (e.g. device) requests. Initializes
249 * just physical address, size, flags, and timestamp (to curTick()).
250 * These fields are adequate to perform a request.
251 */
252 Request(Addr paddr, int size, Flags flags, MasterID mid)
253 {
254 setPhys(paddr, size, flags, mid);
255 }
256
257 Request(Addr paddr, int size, Flags flags, MasterID mid, Tick time)
258 {
259 setPhys(paddr, size, flags, mid, time);
260 }
261
262 Request(Addr paddr, int size, Flags flags, MasterID mid, Tick time, Addr pc)
263 {
264 setPhys(paddr, size, flags, mid, time);
265 privateFlags.set(VALID_PC);
266 _pc = pc;
267 }
268
269 Request(int asid, Addr vaddr, int size, Flags flags, MasterID mid, Addr pc,
270 int cid, ThreadID tid)
271 {
272 setVirt(asid, vaddr, size, flags, mid, pc);
273 setThreadContext(cid, tid);
274 }
275
276 ~Request() {}
277
278 /**
279 * Set up CPU and thread numbers.
280 */
281 void
282 setThreadContext(int context_id, ThreadID tid)
283 {
284 _contextId = context_id;
285 _threadId = tid;
286 privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
287 }
288
289 /**
290 * Set up a physical (e.g. device) request in a previously
291 * allocated Request object.
292 */
293 void
294 setPhys(Addr paddr, int size, Flags flags, MasterID mid, Tick time)
295 {
296 assert(size >= 0);
297 _paddr = paddr;
298 _size = size;
299 _time = time;
300 _masterId = mid;
301 _flags.clear(~STICKY_FLAGS);
302 _flags.set(flags);
303 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
304 privateFlags.set(VALID_PADDR|VALID_SIZE);
305 }
306
307 void
308 setPhys(Addr paddr, int size, Flags flags, MasterID mid)
309 {
310 setPhys(paddr, size, flags, mid, curTick());
311 }
312
313 /**
314 * Set up a virtual (e.g., CPU) request in a previously
315 * allocated Request object.
316 */
317 void
318 setVirt(int asid, Addr vaddr, int size, Flags flags, MasterID mid, Addr pc)
319 {
320 assert(size >= 0);
321 _asid = asid;
322 _vaddr = vaddr;
323 _size = size;
324 _masterId = mid;
325 _pc = pc;
326 _time = curTick();
327
328 _flags.clear(~STICKY_FLAGS);
329 _flags.set(flags);
330 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
331 privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
332 }
333
334 /**
335 * Set just the physical address. This usually used to record the
336 * result of a translation. However, when using virtualized CPUs
337 * setPhys() is sometimes called to finalize a physical address
338 * without a virtual address, so we can't check if the virtual
339 * address is valid.
340 */
341 void
342 setPaddr(Addr paddr)
343 {
344 _paddr = paddr;
345 privateFlags.set(VALID_PADDR);
346 }
347
348 /**
349 * Generate two requests as if this request had been split into two
350 * pieces. The original request can't have been translated already.
351 */
352 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
353 {
354 assert(privateFlags.isSet(VALID_VADDR));
355 assert(privateFlags.noneSet(VALID_PADDR));
356 assert(split_addr > _vaddr && split_addr < _vaddr + _size);
357 req1 = new Request;
358 *req1 = *this;
359 req2 = new Request;
360 *req2 = *this;
361 req1->_size = split_addr - _vaddr;
362 req2->_vaddr = split_addr;
363 req2->_size = _size - req1->_size;
364 }
365
366 /**
367 * Accessor for paddr.
368 */
369 bool
370 hasPaddr()
371 {
372 return privateFlags.isSet(VALID_PADDR);
373 }
374
375 Addr
376 getPaddr()
377 {
378 assert(privateFlags.isSet(VALID_PADDR));
379 return _paddr;
380 }
381
382 /**
383 * Accessor for size.
384 */
385 bool
386 hasSize()
387 {
388 return privateFlags.isSet(VALID_SIZE);
389 }
390
391 int
392 getSize()
393 {
394 assert(privateFlags.isSet(VALID_SIZE));
395 return _size;
396 }
397
398 /** Accessor for time. */
399 Tick
400 time() const
401 {
402 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
403 return _time;
404 }
405
406 void
407 time(Tick time)
408 {
409 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
410 _time = time;
411 }
412
413 /** Accessor for flags. */
414 Flags
415 getFlags()
416 {
417 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
418 return _flags;
419 }
420
421 /** Note that unlike other accessors, this function sets *specific
422 flags* (ORs them in); it does not assign its argument to the
423 _flags field. Thus this method should rightly be called
424 setFlags() and not just flags(). */
425 void
426 setFlags(Flags flags)
427 {
428 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
429 _flags.set(flags);
430 }
431
432 void
433 setArchFlags(Flags flags)
434 {
435 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
436 _flags.set(flags & ARCH_BITS);
437 }
438
439 /** Accessor function for vaddr.*/
440 Addr
441 getVaddr()
442 {
443 assert(privateFlags.isSet(VALID_VADDR));
444 return _vaddr;
445 }
446
447 /** Accesssor for the requestor id. */
448 MasterID
449 masterId()
450 {
451 return _masterId;
452 }
453
454 /** Accessor function for asid.*/
455 int
456 getAsid()
457 {
458 assert(privateFlags.isSet(VALID_VADDR));
459 return _asid;
460 }
461
462 /** Accessor function for asid.*/
463 void
464 setAsid(int asid)
465 {
466 _asid = asid;
467 }
468
469 /** Accessor function for architecture-specific flags.*/
470 ArchFlagsType
471 getArchFlags()
472 {
473 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
474 return _flags & ARCH_BITS;
475 }
476
477 /** Accessor function to check if sc result is valid. */
478 bool
479 extraDataValid()
480 {
481 return privateFlags.isSet(VALID_EXTRA_DATA);
482 }
483
484 /** Accessor function for store conditional return value.*/
485 uint64_t
486 getExtraData() const
487 {
488 assert(privateFlags.isSet(VALID_EXTRA_DATA));
489 return _extraData;
490 }
491
492 /** Accessor function for store conditional return value.*/
493 void
494 setExtraData(uint64_t extraData)
495 {
496 _extraData = extraData;
497 privateFlags.set(VALID_EXTRA_DATA);
498 }
499
500 bool
501 hasContextId() const
502 {
503 return privateFlags.isSet(VALID_CONTEXT_ID);
504 }
505
506 /** Accessor function for context ID.*/
507 int
508 contextId() const
509 {
510 assert(privateFlags.isSet(VALID_CONTEXT_ID));
511 return _contextId;
512 }
513
514 /** Accessor function for thread ID. */
515 int
516 threadId() const
517 {
518 assert(privateFlags.isSet(VALID_THREAD_ID));
519 return _threadId;
520 }
521
522 bool
523 hasPC() const
524 {
525 return privateFlags.isSet(VALID_PC);
526 }
527
528 /** Accessor function for pc.*/
529 Addr
530 getPC() const
531 {
532 assert(privateFlags.isSet(VALID_PC));
533 return _pc;
534 }
535
536 /** Accessor functions for flags. Note that these are for testing
537 only; setting flags should be done via setFlags(). */
538 bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
539 bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
540 bool isPrefetch() const { return _flags.isSet(PREFETCH); }
541 bool isLLSC() const { return _flags.isSet(LLSC); }
542 bool isLocked() const { return _flags.isSet(LOCKED); }
543 bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
544 bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
545 bool isMmappedIpr() const { return _flags.isSet(MMAPPED_IPR); }
546 bool isClearLL() const { return _flags.isSet(CLEAR_LL); }
547 };
548
549 #endif // __MEM_REQUEST_HH__