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