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__
44 #include "base/fast_alloc.hh"
45 #include "base/flags.hh"
46 #include "base/misc.hh"
47 #include "base/types.hh"
48 #include "sim/core.hh"
52 typedef Request* RequestPtr;
54 class Request : public FastAlloc
57 typedef uint32_t FlagsType;
58 typedef ::Flags<FlagsType> Flags;
60 /** ASI information for this request if it exists. */
61 static const FlagsType ASI_BITS = 0x000000FF;
62 /** The request was an instruction fetch. */
63 static const FlagsType INST_FETCH = 0x00000100;
64 /** The virtual address is also the physical address. */
65 static const FlagsType PHYSICAL = 0x00000200;
66 /** The request is an ALPHA VPTE pal access (hw_ld). */
67 static const FlagsType VPTE = 0x00000400;
68 /** Use the alternate mode bits in ALPHA. */
69 static const FlagsType ALTMODE = 0x00000800;
70 /** The request is to an uncacheable address. */
71 static const FlagsType UNCACHEABLE = 0x00001000;
72 /** This request is to a memory mapped register. */
73 static const FlagsType MMAPPED_IPR = 0x00002000;
74 /** This request is a clear exclusive. */
75 static const FlagsType CLEAR_LL = 0x00004000;
77 /** The request should not cause a memory access. */
78 static const FlagsType NO_ACCESS = 0x00080000;
79 /** This request will lock or unlock the accessed memory. When used with
80 * a load, the access locks the particular chunk of memory. When used
81 * with a store, it unlocks. The rule is that locked accesses have to be
82 * made up of a locked load, some operation on the data, and then a locked
85 static const FlagsType LOCKED = 0x00100000;
86 /** The request is a Load locked/store conditional. */
87 static const FlagsType LLSC = 0x00200000;
88 /** This request is for a memory swap. */
89 static const FlagsType MEM_SWAP = 0x00400000;
90 static const FlagsType MEM_SWAP_COND = 0x00800000;
92 /** The request is a prefetch. */
93 static const FlagsType PREFETCH = 0x01000000;
94 /** The request should be prefetched into the exclusive state. */
95 static const FlagsType PF_EXCLUSIVE = 0x02000000;
96 /** The request should be marked as LRU. */
97 static const FlagsType EVICT_NEXT = 0x04000000;
99 /** These flags are *not* cleared when a Request object is reused
100 (assigned a new address). */
101 static const FlagsType STICKY_FLAGS = INST_FETCH;
104 typedef uint8_t PrivateFlagsType;
105 typedef ::Flags<PrivateFlagsType> PrivateFlags;
107 /** Whether or not the size is valid. */
108 static const PrivateFlagsType VALID_SIZE = 0x00000001;
109 /** Whether or not paddr is valid (has been written yet). */
110 static const PrivateFlagsType VALID_PADDR = 0x00000002;
111 /** Whether or not the vaddr & asid are valid. */
112 static const PrivateFlagsType VALID_VADDR = 0x00000004;
113 /** Whether or not the pc is valid. */
114 static const PrivateFlagsType VALID_PC = 0x00000010;
115 /** Whether or not the context ID is valid. */
116 static const PrivateFlagsType VALID_CONTEXT_ID = 0x00000020;
117 static const PrivateFlagsType VALID_THREAD_ID = 0x00000040;
118 /** Whether or not the sc result is valid. */
119 static const PrivateFlagsType VALID_EXTRA_DATA = 0x00000080;
121 /** These flags are *not* cleared when a Request object is reused
122 (assigned a new address). */
123 static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
124 VALID_CONTEXT_ID | VALID_THREAD_ID;
128 * The physical address of the request. Valid only if validPaddr
134 * The size of the request. This field must be set when vaddr or
135 * paddr is written via setVirt() or setPhys(), so it is always
136 * valid as long as one of the address fields is valid.
140 /** Flag structure for the request. */
143 /** Private flags for field validity checking. */
144 PrivateFlags privateFlags;
147 * The time this request was started. Used to calculate
148 * latencies. This field is set to curTick() any time paddr or vaddr
153 /** The address space ID. */
156 /** The virtual address of the request. */
160 * Extra data for the request, such as the return value of
161 * store conditional or the compare value for a CAS. */
164 /** The context ID (for statistics, typically). */
166 /** The thread ID (id within this CPU) */
169 /** program counter of initiating access; for tracing/debugging */
173 /** Minimal constructor. No fields are initialized.
174 * (Note that _flags and privateFlags are cleared by Flags
175 * default constructor.)
181 * Constructor for physical (e.g. device) requests. Initializes
182 * just physical address, size, flags, and timestamp (to curTick()).
183 * These fields are adequate to perform a request.
185 Request(Addr paddr, int size, Flags flags)
187 setPhys(paddr, size, flags);
190 Request(Addr paddr, int size, Flags flags, Tick time)
192 setPhys(paddr, size, flags, time);
195 Request(Addr paddr, int size, Flags flags, Tick time, Addr pc)
197 setPhys(paddr, size, flags, time);
198 privateFlags.set(VALID_PC);
202 Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
203 int cid, ThreadID tid)
205 setVirt(asid, vaddr, size, flags, pc);
206 setThreadContext(cid, tid);
209 ~Request() {} // for FastAlloc
212 * Set up CPU and thread numbers.
215 setThreadContext(int context_id, ThreadID tid)
217 _contextId = context_id;
219 privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
223 * Set up a physical (e.g. device) request in a previously
224 * allocated Request object.
227 setPhys(Addr paddr, int size, Flags flags, Tick time)
234 _flags.clear(~STICKY_FLAGS);
236 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
237 privateFlags.set(VALID_PADDR|VALID_SIZE);
241 setPhys(Addr paddr, int size, Flags flags)
243 setPhys(paddr, size, flags, curTick());
247 * Set up a virtual (e.g., CPU) request in a previously
248 * allocated Request object.
251 setVirt(int asid, Addr vaddr, int size, Flags flags, Addr pc)
260 _flags.clear(~STICKY_FLAGS);
262 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
263 privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
267 * Set just the physical address. This should only be used to
268 * record the result of a translation, and thus the vaddr must be
269 * valid before this method is called. Otherwise, use setPhys()
270 * to guarantee that the size and flags are also set.
275 assert(privateFlags.isSet(VALID_VADDR));
277 privateFlags.set(VALID_PADDR);
281 * Generate two requests as if this request had been split into two
282 * pieces. The original request can't have been translated already.
284 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
286 assert(privateFlags.isSet(VALID_VADDR));
287 assert(privateFlags.noneSet(VALID_PADDR));
288 assert(split_addr > _vaddr && split_addr < _vaddr + _size);
293 req1->_size = split_addr - _vaddr;
294 req2->_vaddr = split_addr;
295 req2->_size = _size - req1->_size;
299 * Accessor for paddr.
304 return privateFlags.isSet(VALID_PADDR);
310 assert(privateFlags.isSet(VALID_PADDR));
320 return privateFlags.isSet(VALID_SIZE);
326 assert(privateFlags.isSet(VALID_SIZE));
330 /** Accessor for time. */
334 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
341 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
345 /** Accessor for flags. */
349 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
353 /** Note that unlike other accessors, this function sets *specific
354 flags* (ORs them in); it does not assign its argument to the
355 _flags field. Thus this method should rightly be called
356 setFlags() and not just flags(). */
358 setFlags(Flags flags)
360 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
364 /** Accessor function for vaddr.*/
368 assert(privateFlags.isSet(VALID_VADDR));
372 /** Accessor function for asid.*/
376 assert(privateFlags.isSet(VALID_VADDR));
380 /** Accessor function for asi.*/
384 assert(privateFlags.isSet(VALID_VADDR));
385 return _flags & ASI_BITS;
388 /** Accessor function to check if sc result is valid. */
392 return privateFlags.isSet(VALID_EXTRA_DATA);
395 /** Accessor function for store conditional return value.*/
399 assert(privateFlags.isSet(VALID_EXTRA_DATA));
403 /** Accessor function for store conditional return value.*/
405 setExtraData(uint64_t extraData)
407 _extraData = extraData;
408 privateFlags.set(VALID_EXTRA_DATA);
414 return privateFlags.isSet(VALID_CONTEXT_ID);
417 /** Accessor function for context ID.*/
421 assert(privateFlags.isSet(VALID_CONTEXT_ID));
425 /** Accessor function for thread ID. */
429 assert(privateFlags.isSet(VALID_THREAD_ID));
436 return privateFlags.isSet(VALID_PC);
439 /** Accessor function for pc.*/
443 assert(privateFlags.isSet(VALID_PC));
447 /** Accessor functions for flags. Note that these are for testing
448 only; setting flags should be done via setFlags(). */
449 bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
450 bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
451 bool isPrefetch() const { return _flags.isSet(PREFETCH); }
452 bool isLLSC() const { return _flags.isSet(LLSC); }
453 bool isLocked() const { return _flags.isSet(LOCKED); }
454 bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
455 bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
456 bool isMmappedIpr() const { return _flags.isSet(MMAPPED_IPR); }
457 bool isClearLL() const { return _flags.isSet(CLEAR_LL); }
460 #endif // __MEM_REQUEST_HH__