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 "sim/host.hh"
48 #include "sim/core.hh"
52 typedef Request* RequestPtr;
54 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 is a Load locked/store conditional. */
65 static const FlagsType LLSC = 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 /** The request should not cause a page fault. */
75 static const FlagsType NO_FAULT = 0x00002000;
76 /** The request should not cause a memory access. */
77 static const FlagsType NO_ACCESS = 0x00004000;
78 /** The request should be prefetched into the exclusive state. */
79 static const FlagsType PF_EXCLUSIVE = 0x00010000;
80 /** The request should be marked as LRU. */
81 static const FlagsType EVICT_NEXT = 0x00020000;
82 /** The request should ignore unaligned access faults */
83 static const FlagsType NO_ALIGN_FAULT = 0x00040000;
84 /** The request was an instruction read. */
85 static const FlagsType INST_READ = 0x00080000;
86 /** This request is for a memory swap. */
87 static const FlagsType MEM_SWAP = 0x00100000;
88 static const FlagsType MEM_SWAP_COND = 0x00200000;
89 /** The request should ignore unaligned access faults */
90 static const FlagsType NO_HALF_WORD_ALIGN_FAULT = 0x00400000;
91 /** This request is to a memory mapped register. */
92 static const FlagsType MMAPED_IPR = 0x00800000;
95 static const FlagsType PUBLIC_FLAGS = 0x00FF3FFF;
96 static const FlagsType PRIVATE_FLAGS = 0xFF000000;
98 /** Whether or not the size is valid. */
99 static const FlagsType VALID_SIZE = 0x01000000;
100 /** Whether or not paddr is valid (has been written yet). */
101 static const FlagsType VALID_PADDR = 0x02000000;
102 /** Whether or not the vaddr & asid are valid. */
103 static const FlagsType VALID_VADDR = 0x04000000;
104 /** Whether or not the pc is valid. */
105 static const FlagsType VALID_PC = 0x10000000;
106 /** Whether or not the context ID is valid. */
107 static const FlagsType VALID_CONTEXT_ID = 0x20000000;
108 static const FlagsType VALID_THREAD_ID = 0x40000000;
109 /** Whether or not the sc result is valid. */
110 static const FlagsType VALID_EXTRA_DATA = 0x80000000;
114 * The physical address of the request. Valid only if validPaddr
120 * The size of the request. This field must be set when vaddr or
121 * paddr is written via setVirt() or setPhys(), so it is always
122 * valid as long as one of the address fields is valid.
126 /** Flag structure for the request. */
130 * The time this request was started. Used to calculate
131 * latencies. This field is set to curTick any time paddr or vaddr
136 /** The address space ID. */
139 /** The virtual address of the request. */
143 * Extra data for the request, such as the return value of
144 * store conditional or the compare value for a CAS. */
147 /** The context ID (for statistics, typically). */
149 /** The thread ID (id within this CPU) */
152 /** program counter of initiating access; for tracing/debugging */
156 /** Minimal constructor. No fields are initialized. */
161 * Constructor for physical (e.g. device) requests. Initializes
162 * just physical address, size, flags, and timestamp (to curTick).
163 * These fields are adequate to perform a request.
165 Request(Addr paddr, int size, Flags flags)
167 setPhys(paddr, size, flags);
170 Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
173 setThreadContext(cid, tid);
174 setVirt(asid, vaddr, size, flags, pc);
177 ~Request() {} // for FastAlloc
180 * Set up CPU and thread numbers.
183 setThreadContext(int context_id, int thread_id)
185 _contextId = context_id;
186 _threadId = thread_id;
187 flags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
191 * Set up a physical (e.g. device) request in a previously
192 * allocated Request object.
195 setPhys(Addr _paddr, int _size, Flags _flags)
202 flags.set(VALID_PADDR|VALID_SIZE);
203 flags.clear(VALID_VADDR|VALID_PC|VALID_EXTRA_DATA|MMAPED_IPR);
204 flags.update(_flags, PUBLIC_FLAGS);
208 * Set up a virtual (e.g., CPU) request in a previously
209 * allocated Request object.
212 setVirt(int _asid, Addr _vaddr, int _size, Flags _flags, Addr _pc)
221 flags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
222 flags.clear(VALID_PADDR|VALID_EXTRA_DATA|MMAPED_IPR);
223 flags.update(_flags, PUBLIC_FLAGS);
227 * Set just the physical address. This should only be used to
228 * record the result of a translation, and thus the vaddr must be
229 * valid before this method is called. Otherwise, use setPhys()
230 * to guarantee that the size and flags are also set.
233 setPaddr(Addr _paddr)
235 assert(flags.isSet(VALID_VADDR));
237 flags.set(VALID_PADDR);
241 * Generate two requests as if this request had been split into two
242 * pieces. The original request can't have been translated already.
244 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
246 assert(flags.isSet(VALID_VADDR));
247 assert(flags.noneSet(VALID_PADDR));
248 assert(split_addr > vaddr && split_addr < vaddr + size);
253 req1->size = split_addr - vaddr;
254 req2->vaddr = split_addr;
255 req2->size = size - req1->size;
259 * Accessor for paddr.
264 assert(flags.isSet(VALID_PADDR));
274 assert(flags.isSet(VALID_SIZE));
278 /** Accessor for time. */
282 assert(flags.isSet(VALID_PADDR|VALID_VADDR));
289 assert(flags.isSet(VALID_PADDR|VALID_VADDR));
293 /** Accessor for flags. */
297 assert(flags.isSet(VALID_PADDR|VALID_VADDR));
298 return flags & PUBLIC_FLAGS;
302 anyFlags(Flags _flags)
304 assert(flags.isSet(VALID_PADDR|VALID_VADDR));
305 assert(_flags.noneSet(~PUBLIC_FLAGS));
306 return flags.isSet(_flags);
310 allFlags(Flags _flags)
312 assert(flags.isSet(VALID_PADDR|VALID_VADDR));
313 assert(_flags.noneSet(~PUBLIC_FLAGS));
314 return flags.allSet(_flags);
317 /** Accessor for flags. */
319 setFlags(Flags _flags)
321 assert(flags.isSet(VALID_PADDR|VALID_VADDR));
322 assert(_flags.noneSet(~PUBLIC_FLAGS));
327 clearFlags(Flags _flags)
329 assert(flags.isSet(VALID_PADDR|VALID_VADDR));
330 assert(_flags.noneSet(~PUBLIC_FLAGS));
337 assert(flags.isSet(VALID_PADDR|VALID_VADDR));
338 flags.clear(PUBLIC_FLAGS);
341 /** Accessor function for vaddr.*/
345 assert(flags.isSet(VALID_VADDR));
349 /** Accessor function for asid.*/
353 assert(flags.isSet(VALID_VADDR));
357 /** Accessor function for asi.*/
361 assert(flags.isSet(VALID_VADDR));
362 return flags & ASI_BITS;
365 /** Accessor function for asi.*/
369 assert(flags.isSet(VALID_VADDR));
370 flags.update(a, ASI_BITS);
373 /** Accessor function for asi.*/
377 assert(flags.isSet(VALID_PADDR));
378 return flags.isSet(MMAPED_IPR);
381 /** Accessor function for asi.*/
386 flags.set(MMAPED_IPR);
389 /** Accessor function to check if sc result is valid. */
393 return flags.isSet(VALID_EXTRA_DATA);
396 /** Accessor function for store conditional return value.*/
400 assert(flags.isSet(VALID_EXTRA_DATA));
404 /** Accessor function for store conditional return value.*/
406 setExtraData(uint64_t _extraData)
408 extraData = _extraData;
409 flags.set(VALID_EXTRA_DATA);
415 return flags.isSet(VALID_CONTEXT_ID);
418 /** Accessor function for context ID.*/
422 assert(flags.isSet(VALID_CONTEXT_ID));
426 /** Accessor function for thread ID. */
430 assert(flags.isSet(VALID_THREAD_ID));
437 return flags.isSet(VALID_PC);
440 /** Accessor function for pc.*/
444 assert(flags.isSet(VALID_PC));
448 /** Accessor Function to Check Cacheability. */
449 bool isUncacheable() const { return flags.isSet(UNCACHEABLE); }
450 bool isInstRead() const { return flags.isSet(INST_READ); }
451 bool isLlsc() const { return flags.isSet(LLSC); }
452 bool isSwap() const { return flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
453 bool isCondSwap() const { return flags.isSet(MEM_SWAP_COND); }
458 if (flags.isSet(NO_ALIGN_FAULT))
464 if (flags.isSet(NO_HALF_WORD_ALIGN_FAULT))
474 #endif // __MEM_REQUEST_HH__