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 "sim/host.hh"
47 #include "sim/core.hh"
51 typedef Request* RequestPtr;
53 class Request : public FastAlloc
56 typedef uint32_t FlagsType;
57 typedef ::Flags<FlagsType> Flags;
59 /** ASI information for this request if it exists. */
60 static const FlagsType ASI_BITS = 0x000000FF;
61 /** The request is a Load locked/store conditional. */
62 static const FlagsType LOCKED = 0x00000100;
63 /** The virtual address is also the physical address. */
64 static const FlagsType PHYSICAL = 0x00000200;
65 /** The request is an ALPHA VPTE pal access (hw_ld). */
66 static const FlagsType VPTE = 0x00000400;
67 /** Use the alternate mode bits in ALPHA. */
68 static const FlagsType ALTMODE = 0x00000800;
69 /** The request is to an uncacheable address. */
70 static const FlagsType UNCACHEABLE = 0x00001000;
71 /** The request should not cause a page fault. */
72 static const FlagsType NO_FAULT = 0x00002000;
73 /** The request should be prefetched into the exclusive state. */
74 static const FlagsType PF_EXCLUSIVE = 0x00010000;
75 /** The request should be marked as LRU. */
76 static const FlagsType EVICT_NEXT = 0x00020000;
77 /** The request should ignore unaligned access faults */
78 static const FlagsType NO_ALIGN_FAULT = 0x00040000;
79 /** The request was an instruction read. */
80 static const FlagsType INST_READ = 0x00080000;
81 /** This request is for a memory swap. */
82 static const FlagsType MEM_SWAP = 0x00100000;
83 static const FlagsType MEM_SWAP_COND = 0x00200000;
84 /** The request should ignore unaligned access faults */
85 static const FlagsType NO_HALF_WORD_ALIGN_FAULT = 0x00400000;
86 /** This request is to a memory mapped register. */
87 static const FlagsType MMAPED_IPR = 0x00800000;
90 static const FlagsType PUBLIC_FLAGS = 0x00FF3FFF;
91 static const FlagsType PRIVATE_FLAGS = 0xFF000000;
93 /** Whether or not the size is valid. */
94 static const FlagsType VALID_SIZE = 0x01000000;
95 /** Whether or not paddr is valid (has been written yet). */
96 static const FlagsType VALID_PADDR = 0x02000000;
97 /** Whether or not the vaddr & asid are valid. */
98 static const FlagsType VALID_VADDR = 0x04000000;
99 /** Whether or not the pc is valid. */
100 static const FlagsType VALID_PC = 0x10000000;
101 /** Whether or not the context ID is valid. */
102 static const FlagsType VALID_CONTEXT_ID = 0x20000000;
103 static const FlagsType VALID_THREAD_ID = 0x40000000;
104 /** Whether or not the sc result is valid. */
105 static const FlagsType VALID_EXTRA_DATA = 0x80000000;
109 * The physical address of the request. Valid only if validPaddr
115 * The size of the request. This field must be set when vaddr or
116 * paddr is written via setVirt() or setPhys(), so it is always
117 * valid as long as one of the address fields is valid.
121 /** Flag structure for the request. */
125 * The time this request was started. Used to calculate
126 * latencies. This field is set to curTick any time paddr or vaddr
131 /** The address space ID. */
134 /** The virtual address of the request. */
138 * Extra data for the request, such as the return value of
139 * store conditional or the compare value for a CAS. */
142 /** The context ID (for statistics, typically). */
144 /** The thread ID (id within this CPU) */
147 /** program counter of initiating access; for tracing/debugging */
151 /** Minimal constructor. No fields are initialized. */
156 * Constructor for physical (e.g. device) requests. Initializes
157 * just physical address, size, flags, and timestamp (to curTick).
158 * These fields are adequate to perform a request.
160 Request(Addr paddr, int size, Flags flags)
162 setPhys(paddr, size, flags);
165 Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
168 setThreadContext(cid, tid);
169 setVirt(asid, vaddr, size, flags, pc);
172 ~Request() {} // for FastAlloc
175 * Set up CPU and thread numbers.
178 setThreadContext(int context_id, int thread_id)
180 _contextId = context_id;
181 _threadId = thread_id;
182 flags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
186 * Set up a physical (e.g. device) request in a previously
187 * allocated Request object.
190 setPhys(Addr _paddr, int _size, Flags _flags)
197 flags.set(VALID_PADDR|VALID_SIZE);
198 flags.clear(VALID_VADDR|VALID_PC|VALID_EXTRA_DATA|MMAPED_IPR);
199 flags.update(_flags, PUBLIC_FLAGS);
203 * Set up a virtual (e.g., CPU) request in a previously
204 * allocated Request object.
207 setVirt(int _asid, Addr _vaddr, int _size, Flags _flags, Addr _pc)
216 flags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
217 flags.clear(VALID_PADDR|VALID_EXTRA_DATA|MMAPED_IPR);
218 flags.update(_flags, PUBLIC_FLAGS);
222 * Set just the physical address. This should only be used to
223 * record the result of a translation, and thus the vaddr must be
224 * valid before this method is called. Otherwise, use setPhys()
225 * to guarantee that the size and flags are also set.
228 setPaddr(Addr _paddr)
230 assert(flags.any(VALID_VADDR));
232 flags.set(VALID_PADDR);
236 * Accessor for paddr.
241 assert(flags.any(VALID_PADDR));
251 assert(flags.any(VALID_SIZE));
255 /** Accessor for time. */
259 assert(flags.any(VALID_PADDR|VALID_VADDR));
266 assert(flags.any(VALID_PADDR|VALID_VADDR));
270 void resetTime() { setTime(curTick); }
272 /** Accessor for flags. */
276 assert(flags.any(VALID_PADDR|VALID_VADDR));
277 return flags & PUBLIC_FLAGS;
281 anyFlags(Flags _flags)
283 assert(flags.any(VALID_PADDR|VALID_VADDR));
284 assert(_flags.none(~PUBLIC_FLAGS));
285 return flags.any(_flags);
289 allFlags(Flags _flags)
291 assert(flags.any(VALID_PADDR|VALID_VADDR));
292 assert(_flags.none(~PUBLIC_FLAGS));
293 return flags.all(_flags);
296 /** Accessor for flags. */
298 setFlags(Flags _flags)
300 assert(flags.any(VALID_PADDR|VALID_VADDR));
301 assert(_flags.none(~PUBLIC_FLAGS));
306 clearFlags(Flags _flags)
308 assert(flags.any(VALID_PADDR|VALID_VADDR));
309 assert(_flags.none(~PUBLIC_FLAGS));
316 assert(flags.any(VALID_PADDR|VALID_VADDR));
317 flags.clear(PUBLIC_FLAGS);
320 /** Accessor function for vaddr.*/
324 assert(flags.any(VALID_VADDR));
328 /** Accessor function for asid.*/
332 assert(flags.any(VALID_VADDR));
336 /** Accessor function for asi.*/
340 assert(flags.any(VALID_VADDR));
341 return flags & ASI_BITS;
344 /** Accessor function for asi.*/
348 assert(flags.any(VALID_VADDR));
349 flags.update(a, ASI_BITS);
352 /** Accessor function for asi.*/
356 assert(flags.any(VALID_PADDR));
357 return flags.any(MMAPED_IPR);
360 /** Accessor function for asi.*/
365 flags.set(MMAPED_IPR);
368 /** Accessor function to check if sc result is valid. */
372 return flags.any(VALID_EXTRA_DATA);
375 /** Accessor function for store conditional return value.*/
379 assert(flags.any(VALID_EXTRA_DATA));
383 /** Accessor function for store conditional return value.*/
385 setExtraData(uint64_t _extraData)
387 extraData = _extraData;
388 flags.set(VALID_EXTRA_DATA);
391 /** Accessor function for context ID.*/
395 assert(flags.any(VALID_CONTEXT_ID));
399 /** Accessor function for thread ID. */
403 assert(flags.any(VALID_THREAD_ID));
407 /** Accessor function for pc.*/
411 assert(flags.any(VALID_PC));
415 /** Accessor Function to Check Cacheability. */
416 bool isUncacheable() const { return flags.any(UNCACHEABLE); }
417 bool isInstRead() const { return flags.any(INST_READ); }
418 bool isLocked() const { return flags.any(LOCKED); }
419 bool isSwap() const { return flags.any(MEM_SWAP|MEM_SWAP_COND); }
420 bool isCondSwap() const { return flags.any(MEM_SWAP_COND); }
425 if (flags.any(NO_ALIGN_FAULT))
431 if (flags.any(NO_HALF_WORD_ALIGN_FAULT))
443 #endif // __MEM_REQUEST_HH__