2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Ron Dreslinski
35 * Declaration of a request, the overall memory request consisting of
36 the parts of the request that are persistent throughout the transaction.
39 #ifndef __MEM_REQUEST_HH__
40 #define __MEM_REQUEST_HH__
45 #include "base/fast_alloc.hh"
46 #include "base/flags.hh"
47 #include "base/misc.hh"
48 #include "base/types.hh"
49 #include "sim/core.hh"
53 typedef Request* RequestPtr;
54 typedef uint16_t MasterID;
56 class Request : public FastAlloc
59 typedef uint32_t FlagsType;
60 typedef ::Flags<FlagsType> Flags;
62 /** ASI information for this request if it exists. */
63 static const FlagsType ASI_BITS = 0x000000FF;
64 /** The request was an instruction fetch. */
65 static const FlagsType INST_FETCH = 0x00000100;
66 /** The virtual address is also the physical address. */
67 static const FlagsType PHYSICAL = 0x00000200;
68 /** The request is an ALPHA VPTE pal access (hw_ld). */
69 static const FlagsType VPTE = 0x00000400;
70 /** Use the alternate mode bits in ALPHA. */
71 static const FlagsType ALTMODE = 0x00000800;
72 /** The request is to an uncacheable address. */
73 static const FlagsType UNCACHEABLE = 0x00001000;
74 /** This request is to a memory mapped register. */
75 static const FlagsType MMAPPED_IPR = 0x00002000;
76 /** This request is a clear exclusive. */
77 static const FlagsType CLEAR_LL = 0x00004000;
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
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;
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;
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;
105 /** Request Ids that are statically allocated
107 /** This request id is used for writeback requests by the caches */
108 static const MasterID wbMasterId = 0;
109 /** This request id is used for functional requests that don't come from a
112 static const MasterID funcMasterId = 1;
113 /** This request id is used for message signaled interrupts */
114 static const MasterID intMasterId = 2;
115 /** Invalid request id for assertion checking only. It is invalid behavior
116 * to ever send this id as part of a request.
117 * @todo C++1x replace with numeric_limits when constexpr is added */
118 static const MasterID invldMasterId = USHRT_MAX;
122 typedef uint8_t PrivateFlagsType;
123 typedef ::Flags<PrivateFlagsType> PrivateFlags;
125 /** Whether or not the size is valid. */
126 static const PrivateFlagsType VALID_SIZE = 0x00000001;
127 /** Whether or not paddr is valid (has been written yet). */
128 static const PrivateFlagsType VALID_PADDR = 0x00000002;
129 /** Whether or not the vaddr & asid are valid. */
130 static const PrivateFlagsType VALID_VADDR = 0x00000004;
131 /** Whether or not the pc is valid. */
132 static const PrivateFlagsType VALID_PC = 0x00000010;
133 /** Whether or not the context ID is valid. */
134 static const PrivateFlagsType VALID_CONTEXT_ID = 0x00000020;
135 static const PrivateFlagsType VALID_THREAD_ID = 0x00000040;
136 /** Whether or not the sc result is valid. */
137 static const PrivateFlagsType VALID_EXTRA_DATA = 0x00000080;
139 /** These flags are *not* cleared when a Request object is reused
140 (assigned a new address). */
141 static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
142 VALID_CONTEXT_ID | VALID_THREAD_ID;
146 * The physical address of the request. Valid only if validPaddr
152 * The size of the request. This field must be set when vaddr or
153 * paddr is written via setVirt() or setPhys(), so it is always
154 * valid as long as one of the address fields is valid.
158 /** The requestor ID which is unique in the system for all ports
159 * that are capable of issuing a transaction
163 /** Flag structure for the request. */
166 /** Private flags for field validity checking. */
167 PrivateFlags privateFlags;
170 * The time this request was started. Used to calculate
171 * latencies. This field is set to curTick() any time paddr or vaddr
176 /** The address space ID. */
179 /** The virtual address of the request. */
183 * Extra data for the request, such as the return value of
184 * store conditional or the compare value for a CAS. */
187 /** The context ID (for statistics, typically). */
189 /** The thread ID (id within this CPU) */
192 /** program counter of initiating access; for tracing/debugging */
196 /** Minimal constructor. No fields are initialized.
197 * (Note that _flags and privateFlags are cleared by Flags
198 * default constructor.)
204 * Constructor for physical (e.g. device) requests. Initializes
205 * just physical address, size, flags, and timestamp (to curTick()).
206 * These fields are adequate to perform a request.
208 Request(Addr paddr, int size, Flags flags, MasterID mid)
210 setPhys(paddr, size, flags, mid);
213 Request(Addr paddr, int size, Flags flags, MasterID mid, Tick time)
215 setPhys(paddr, size, flags, mid, time);
218 Request(Addr paddr, int size, Flags flags, MasterID mid, Tick time, Addr pc)
220 setPhys(paddr, size, flags, mid, time);
221 privateFlags.set(VALID_PC);
225 Request(int asid, Addr vaddr, int size, Flags flags, MasterID mid, Addr pc,
226 int cid, ThreadID tid)
228 setVirt(asid, vaddr, size, flags, mid, pc);
229 setThreadContext(cid, tid);
232 ~Request() {} // for FastAlloc
235 * Set up CPU and thread numbers.
238 setThreadContext(int context_id, ThreadID tid)
240 _contextId = context_id;
242 privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
246 * Set up a physical (e.g. device) request in a previously
247 * allocated Request object.
250 setPhys(Addr paddr, int size, Flags flags, MasterID mid, Tick time)
257 _flags.clear(~STICKY_FLAGS);
259 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
260 privateFlags.set(VALID_PADDR|VALID_SIZE);
264 setPhys(Addr paddr, int size, Flags flags, MasterID mid)
266 setPhys(paddr, size, flags, mid, curTick());
270 * Set up a virtual (e.g., CPU) request in a previously
271 * allocated Request object.
274 setVirt(int asid, Addr vaddr, int size, Flags flags, MasterID mid, Addr pc)
284 _flags.clear(~STICKY_FLAGS);
286 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
287 privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
291 * Set just the physical address. This should only be used to
292 * record the result of a translation, and thus the vaddr must be
293 * valid before this method is called. Otherwise, use setPhys()
294 * to guarantee that the size and flags are also set.
299 assert(privateFlags.isSet(VALID_VADDR));
301 privateFlags.set(VALID_PADDR);
305 * Generate two requests as if this request had been split into two
306 * pieces. The original request can't have been translated already.
308 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
310 assert(privateFlags.isSet(VALID_VADDR));
311 assert(privateFlags.noneSet(VALID_PADDR));
312 assert(split_addr > _vaddr && split_addr < _vaddr + _size);
317 req1->_size = split_addr - _vaddr;
318 req2->_vaddr = split_addr;
319 req2->_size = _size - req1->_size;
323 * Accessor for paddr.
328 return privateFlags.isSet(VALID_PADDR);
334 assert(privateFlags.isSet(VALID_PADDR));
344 return privateFlags.isSet(VALID_SIZE);
350 assert(privateFlags.isSet(VALID_SIZE));
354 /** Accessor for time. */
358 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
365 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
369 /** Accessor for flags. */
373 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
377 /** Note that unlike other accessors, this function sets *specific
378 flags* (ORs them in); it does not assign its argument to the
379 _flags field. Thus this method should rightly be called
380 setFlags() and not just flags(). */
382 setFlags(Flags flags)
384 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
388 /** Accessor function for vaddr.*/
392 assert(privateFlags.isSet(VALID_VADDR));
396 /** Accesssor for the requestor id. */
403 /** Accessor function for asid.*/
407 assert(privateFlags.isSet(VALID_VADDR));
411 /** Accessor function for asid.*/
418 /** Accessor function for asi.*/
422 assert(privateFlags.isSet(VALID_VADDR));
423 return _flags & ASI_BITS;
426 /** Accessor function to check if sc result is valid. */
430 return privateFlags.isSet(VALID_EXTRA_DATA);
433 /** Accessor function for store conditional return value.*/
437 assert(privateFlags.isSet(VALID_EXTRA_DATA));
441 /** Accessor function for store conditional return value.*/
443 setExtraData(uint64_t extraData)
445 _extraData = extraData;
446 privateFlags.set(VALID_EXTRA_DATA);
452 return privateFlags.isSet(VALID_CONTEXT_ID);
455 /** Accessor function for context ID.*/
459 assert(privateFlags.isSet(VALID_CONTEXT_ID));
463 /** Accessor function for thread ID. */
467 assert(privateFlags.isSet(VALID_THREAD_ID));
474 return privateFlags.isSet(VALID_PC);
477 /** Accessor function for pc.*/
481 assert(privateFlags.isSet(VALID_PC));
485 /** Accessor functions for flags. Note that these are for testing
486 only; setting flags should be done via setFlags(). */
487 bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
488 bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
489 bool isPrefetch() const { return _flags.isSet(PREFETCH); }
490 bool isLLSC() const { return _flags.isSet(LLSC); }
491 bool isLocked() const { return _flags.isSet(LOCKED); }
492 bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
493 bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
494 bool isMmappedIpr() const { return _flags.isSet(MMAPPED_IPR); }
495 bool isClearLL() const { return _flags.isSet(CLEAR_LL); }
498 #endif // __MEM_REQUEST_HH__