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