2 * Copyright (c) 2012 ARM Limited
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.
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
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.
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.
40 * Authors: Ron Dreslinski
47 * Declaration of a request, the overall memory request consisting of
48 the parts of the request that are persistent throughout the transaction.
51 #ifndef __MEM_REQUEST_HH__
52 #define __MEM_REQUEST_HH__
57 #include "base/flags.hh"
58 #include "base/misc.hh"
59 #include "base/types.hh"
60 #include "sim/core.hh"
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.)
70 namespace ContextSwitchTaskId {
72 MaxNormalTaskId = 1021, /* Maximum number of normal tasks */
73 Prefetcher = 1022, /* For cache lines brought in by prefetcher */
74 DMA = 1023, /* Mostly Table Walker */
82 typedef Request* RequestPtr;
83 typedef uint16_t MasterID;
88 typedef uint32_t FlagsType;
89 typedef uint8_t ArchFlagsType;
90 typedef ::Flags<FlagsType> Flags;
93 * Architecture specific flags.
95 * These bits int the flag field are reserved for
96 * architecture-specific code. For example, SPARC uses them to
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;
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
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;
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;
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;
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;
147 /** Request Ids that are statically allocated
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
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;
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;
168 typedef uint8_t PrivateFlagsType;
169 typedef ::Flags<PrivateFlagsType> PrivateFlags;
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;
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;
192 * The physical address of the request. Valid only if validPaddr
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.
204 /** The requestor ID which is unique in the system for all ports
205 * that are capable of issuing a transaction
209 /** Flag structure for the request. */
212 /** Private flags for field validity checking. */
213 PrivateFlags privateFlags;
216 * The time this request was started. Used to calculate
217 * latencies. This field is set to curTick() any time paddr or vaddr
222 /** The address space ID. */
225 /** The virtual address of the request. */
229 * Extra data for the request, such as the return value of
230 * store conditional or the compare value for a CAS. */
233 /** The context ID (for statistics, typically). */
235 /** The thread ID (id within this CPU) */
238 /** program counter of initiating access; for tracing/debugging */
242 /** Minimal constructor. No fields are initialized.
243 * (Note that _flags and privateFlags are cleared by Flags
244 * default constructor.)
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.
254 Request(Addr paddr, int size, Flags flags, MasterID mid)
256 setPhys(paddr, size, flags, mid);
259 Request(Addr paddr, int size, Flags flags, MasterID mid, Tick time)
261 setPhys(paddr, size, flags, mid, time);
264 Request(Addr paddr, int size, Flags flags, MasterID mid, Tick time, Addr pc)
266 setPhys(paddr, size, flags, mid, time);
267 privateFlags.set(VALID_PC);
271 Request(int asid, Addr vaddr, int size, Flags flags, MasterID mid, Addr pc,
272 int cid, ThreadID tid)
274 setVirt(asid, vaddr, size, flags, mid, pc);
275 setThreadContext(cid, tid);
281 * Set up CPU and thread numbers.
284 setThreadContext(int context_id, ThreadID tid)
286 _contextId = context_id;
288 privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
292 * Set up a physical (e.g. device) request in a previously
293 * allocated Request object.
296 setPhys(Addr paddr, int size, Flags flags, MasterID mid, Tick time)
303 _flags.clear(~STICKY_FLAGS);
305 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
306 privateFlags.set(VALID_PADDR|VALID_SIZE);
310 setPhys(Addr paddr, int size, Flags flags, MasterID mid)
312 setPhys(paddr, size, flags, mid, curTick());
316 * Set up a virtual (e.g., CPU) request in a previously
317 * allocated Request object.
320 setVirt(int asid, Addr vaddr, int size, Flags flags, MasterID mid, Addr pc)
330 _flags.clear(~STICKY_FLAGS);
332 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
333 privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
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
347 privateFlags.set(VALID_PADDR);
351 * Generate two requests as if this request had been split into two
352 * pieces. The original request can't have been translated already.
354 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
356 assert(privateFlags.isSet(VALID_VADDR));
357 assert(privateFlags.noneSet(VALID_PADDR));
358 assert(split_addr > _vaddr && split_addr < _vaddr + _size);
363 req1->_size = split_addr - _vaddr;
364 req2->_vaddr = split_addr;
365 req2->_size = _size - req1->_size;
369 * Accessor for paddr.
374 return privateFlags.isSet(VALID_PADDR);
380 assert(privateFlags.isSet(VALID_PADDR));
390 return privateFlags.isSet(VALID_SIZE);
396 assert(privateFlags.isSet(VALID_SIZE));
400 /** Accessor for time. */
404 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
411 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
415 /** Accessor for flags. */
419 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
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(). */
428 setFlags(Flags flags)
430 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
435 setArchFlags(Flags flags)
437 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
438 _flags.set(flags & ARCH_BITS);
441 /** Accessor function for vaddr.*/
445 assert(privateFlags.isSet(VALID_VADDR));
449 /** Accesssor for the requestor id. */
456 /** Accessor function for asid.*/
460 assert(privateFlags.isSet(VALID_VADDR));
464 /** Accessor function for asid.*/
471 /** Accessor function for architecture-specific flags.*/
475 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
476 return _flags & ARCH_BITS;
479 /** Accessor function to check if sc result is valid. */
483 return privateFlags.isSet(VALID_EXTRA_DATA);
486 /** Accessor function for store conditional return value.*/
490 assert(privateFlags.isSet(VALID_EXTRA_DATA));
494 /** Accessor function for store conditional return value.*/
496 setExtraData(uint64_t extraData)
498 _extraData = extraData;
499 privateFlags.set(VALID_EXTRA_DATA);
505 return privateFlags.isSet(VALID_CONTEXT_ID);
508 /** Accessor function for context ID.*/
512 assert(privateFlags.isSet(VALID_CONTEXT_ID));
516 /** Accessor function for thread ID. */
520 assert(privateFlags.isSet(VALID_THREAD_ID));
527 return privateFlags.isSet(VALID_PC);
530 /** Accessor function for pc.*/
534 assert(privateFlags.isSet(VALID_PC));
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); }
552 #endif // __MEM_REQUEST_HH__