Merge ktlim@zizzer:/bk/newmem
[gem5.git] / src / mem / request.hh
1 /*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Ron Dreslinski
29 * Steve Reinhardt
30 * Ali Saidi
31 */
32
33 /**
34 * @file
35 * Declaration of a request, the overall memory request consisting of
36 the parts of the request that are persistent throughout the transaction.
37 */
38
39 #ifndef __MEM_REQUEST_HH__
40 #define __MEM_REQUEST_HH__
41
42 #include "sim/host.hh"
43 #include "sim/root.hh"
44
45 #include <cassert>
46
47 class Request;
48
49 typedef Request* RequestPtr;
50
51
52 /** The request is a Load locked/store conditional. */
53 const unsigned LOCKED = 0x001;
54 /** The virtual address is also the physical address. */
55 const unsigned PHYSICAL = 0x002;
56 /** The request is an ALPHA VPTE pal access (hw_ld). */
57 const unsigned VPTE = 0x004;
58 /** Use the alternate mode bits in ALPHA. */
59 const unsigned ALTMODE = 0x008;
60 /** The request is to an uncacheable address. */
61 const unsigned UNCACHEABLE = 0x010;
62 /** The request should not cause a page fault. */
63 const unsigned NO_FAULT = 0x020;
64 /** The request should be prefetched into the exclusive state. */
65 const unsigned PF_EXCLUSIVE = 0x100;
66 /** The request should be marked as LRU. */
67 const unsigned EVICT_NEXT = 0x200;
68 /** The request should ignore unaligned access faults */
69 const unsigned NO_ALIGN_FAULT = 0x400;
70 /** The request was an instruction read. */
71 const unsigned INST_READ = 0x800;
72
73 class Request
74 {
75 private:
76 /**
77 * The physical address of the request. Valid only if validPaddr
78 * is set. */
79 Addr paddr;
80
81 /**
82 * The size of the request. This field must be set when vaddr or
83 * paddr is written via setVirt() or setPhys(), so it is always
84 * valid as long as one of the address fields is valid. */
85 int size;
86
87 /** Flag structure for the request. */
88 uint32_t flags;
89
90 /**
91 * The time this request was started. Used to calculate
92 * latencies. This field is set to curTick any time paddr or vaddr
93 * is written. */
94 Tick time;
95
96 /** The address space ID. */
97 int asid;
98 /** The virtual address of the request. */
99 Addr vaddr;
100
101 /** The return value of store conditional. */
102 uint64_t scResult;
103
104 /** The cpu number (for statistics, typically). */
105 int cpuNum;
106 /** The requesting thread id (for statistics, typically). */
107 int threadNum;
108
109 /** program counter of initiating access; for tracing/debugging */
110 Addr pc;
111
112 /** Whether or not paddr is valid (has been written yet). */
113 bool validPaddr;
114 /** Whether or not the asid & vaddr are valid. */
115 bool validAsidVaddr;
116 /** Whether or not the sc result is valid. */
117 bool validScResult;
118 /** Whether or not the cpu number & thread ID are valid. */
119 bool validCpuAndThreadNums;
120 /** Whether or not the pc is valid. */
121 bool validPC;
122
123 public:
124 /** Minimal constructor. No fields are initialized. */
125 Request()
126 : validPaddr(false), validAsidVaddr(false),
127 validScResult(false), validCpuAndThreadNums(false), validPC(false)
128 {}
129
130 /**
131 * Constructor for physical (e.g. device) requests. Initializes
132 * just physical address, size, flags, and timestamp (to curTick).
133 * These fields are adequate to perform a request. */
134 Request(Addr _paddr, int _size, int _flags)
135 : validCpuAndThreadNums(false)
136 { setPhys(_paddr, _size, _flags); }
137
138 Request(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc,
139 int _cpuNum, int _threadNum)
140 {
141 setThreadContext(_cpuNum, _threadNum);
142 setVirt(_asid, _vaddr, _size, _flags, _pc);
143 }
144
145 /**
146 * Set up CPU and thread numbers. */
147 void setThreadContext(int _cpuNum, int _threadNum)
148 {
149 cpuNum = _cpuNum;
150 threadNum = _threadNum;
151 validCpuAndThreadNums = true;
152 }
153
154 /**
155 * Set up a physical (e.g. device) request in a previously
156 * allocated Request object. */
157 void setPhys(Addr _paddr, int _size, int _flags)
158 {
159 paddr = _paddr;
160 size = _size;
161 flags = _flags;
162 time = curTick;
163 validPaddr = true;
164 validAsidVaddr = false;
165 validPC = false;
166 validScResult = false;
167 }
168
169 /**
170 * Set up a virtual (e.g., CPU) request in a previously
171 * allocated Request object. */
172 void setVirt(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc)
173 {
174 asid = _asid;
175 vaddr = _vaddr;
176 size = _size;
177 flags = _flags;
178 pc = _pc;
179 time = curTick;
180 validPaddr = false;
181 validAsidVaddr = true;
182 validPC = true;
183 validScResult = false;
184 }
185
186 /** Set just the physical address. This should only be used to
187 * record the result of a translation, and thus the vaddr must be
188 * valid before this method is called. Otherwise, use setPhys()
189 * to guarantee that the size and flags are also set.
190 */
191 void setPaddr(Addr _paddr)
192 {
193 assert(validAsidVaddr);
194 paddr = _paddr;
195 validPaddr = true;
196 }
197
198 /** Accessor for paddr. */
199 Addr getPaddr() { assert(validPaddr); return paddr; }
200
201 /** Accessor for size. */
202 int getSize() { assert(validPaddr || validAsidVaddr); return size; }
203 /** Accessor for time. */
204 Tick getTime() { assert(validPaddr || validAsidVaddr); return time; }
205
206 /** Accessor for flags. */
207 uint32_t getFlags() { assert(validPaddr || validAsidVaddr); return flags; }
208 /** Accessor for paddr. */
209 void setFlags(uint32_t _flags)
210 { assert(validPaddr || validAsidVaddr); flags = _flags; }
211
212 /** Accessor function for vaddr.*/
213 Addr getVaddr() { assert(validAsidVaddr); return vaddr; }
214
215 /** Accessor function for asid.*/
216 int getAsid() { assert(validAsidVaddr); return asid; }
217
218 /** Accessor function to check if sc result is valid. */
219 bool scResultValid() { return validScResult; }
220 /** Accessor function for store conditional return value.*/
221 uint64_t getScResult() { assert(validScResult); return scResult; }
222 /** Accessor function for store conditional return value.*/
223 void setScResult(uint64_t _scResult)
224 { scResult = _scResult; validScResult = true; }
225
226 /** Accessor function for cpu number.*/
227 int getCpuNum() { assert(validCpuAndThreadNums); return cpuNum; }
228 /** Accessor function for thread number.*/
229 int getThreadNum() { assert(validCpuAndThreadNums); return threadNum; }
230
231 /** Accessor function for pc.*/
232 Addr getPC() { assert(validPC); return pc; }
233
234 /** Accessor Function to Check Cacheability. */
235 bool isUncacheable() { return (getFlags() & UNCACHEABLE) != 0; }
236
237 bool isInstRead() { return (getFlags() & INST_READ) != 0; }
238
239 bool isLocked() { return (getFlags() & LOCKED) != 0; }
240
241 friend class Packet;
242 };
243
244 #endif // __MEM_REQUEST_HH__