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 <cassert>
43
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"
49
50class Request;
51
52typedef Request* RequestPtr;
53
54class Request : public FastAlloc
55{
56 public:
57 typedef uint32_t FlagsType;
58 typedef ::Flags<FlagsType> Flags;
59
60 /** ASI information for this request if it exists. */
61 static const FlagsType ASI_BITS = 0x000000FF;
62 /** The request is a Load locked/store conditional. */
63 static const FlagsType LOCKED = 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 /** The request should not cause a page fault. */
73 static const FlagsType NO_FAULT = 0x00002000;
74 /** The request should be prefetched into the exclusive state. */
75 static const FlagsType PF_EXCLUSIVE = 0x00010000;
76 /** The request should be marked as LRU. */
77 static const FlagsType EVICT_NEXT = 0x00020000;
78 /** The request should ignore unaligned access faults */
79 static const FlagsType NO_ALIGN_FAULT = 0x00040000;
80 /** The request was an instruction read. */
81 static const FlagsType INST_READ = 0x00080000;
82 /** This request is for a memory swap. */
83 static const FlagsType MEM_SWAP = 0x00100000;
84 static const FlagsType MEM_SWAP_COND = 0x00200000;
85 /** The request should ignore unaligned access faults */
86 static const FlagsType NO_HALF_WORD_ALIGN_FAULT = 0x00400000;
87 /** This request is to a memory mapped register. */
88 static const FlagsType MMAPED_IPR = 0x00800000;
89
90 private:
91 static const FlagsType PUBLIC_FLAGS = 0x00FF3FFF;
92 static const FlagsType PRIVATE_FLAGS = 0xFF000000;
93
94 /** Whether or not the size is valid. */
95 static const FlagsType VALID_SIZE = 0x01000000;
96 /** Whether or not paddr is valid (has been written yet). */
97 static const FlagsType VALID_PADDR = 0x02000000;
98 /** Whether or not the vaddr & asid are valid. */
99 static const FlagsType VALID_VADDR = 0x04000000;
100 /** Whether or not the pc is valid. */
101 static const FlagsType VALID_PC = 0x10000000;
102 /** Whether or not the context ID is valid. */
103 static const FlagsType VALID_CONTEXT_ID = 0x20000000;
104 static const FlagsType VALID_THREAD_ID = 0x40000000;
105 /** Whether or not the sc result is valid. */
106 static const FlagsType VALID_EXTRA_DATA = 0x80000000;
107
108 private:
109 /**
110 * The physical address of the request. Valid only if validPaddr
111 * is set.
112 */
113 Addr paddr;
114
115 /**
116 * The size of the request. This field must be set when vaddr or
117 * paddr is written via setVirt() or setPhys(), so it is always
118 * valid as long as one of the address fields is valid.
119 */
120 int size;
121
122 /** Flag structure for the request. */
123 Flags flags;
124
125 /**
126 * The time this request was started. Used to calculate
127 * latencies. This field is set to curTick any time paddr or vaddr
128 * is written.
129 */
130 Tick time;
131
132 /** The address space ID. */
133 int asid;
134
135 /** The virtual address of the request. */
136 Addr vaddr;
137
138 /**
139 * Extra data for the request, such as the return value of
140 * store conditional or the compare value for a CAS. */
141 uint64_t extraData;
142
143 /** The context ID (for statistics, typically). */
144 int _contextId;
145 /** The thread ID (id within this CPU) */
146 int _threadId;
147
148 /** program counter of initiating access; for tracing/debugging */
149 Addr pc;
150
151 public:
152 /** Minimal constructor. No fields are initialized. */
153 Request()
154 {}
155
156 /**
157 * Constructor for physical (e.g. device) requests. Initializes
158 * just physical address, size, flags, and timestamp (to curTick).
159 * These fields are adequate to perform a request.
160 */
161 Request(Addr paddr, int size, Flags flags)
162 {
163 setPhys(paddr, size, flags);
164 }
165
166 Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
167 int cid, int tid)
168 {
169 setThreadContext(cid, tid);
170 setVirt(asid, vaddr, size, flags, pc);
171 }
172
173 ~Request() {} // for FastAlloc
174
175 /**
176 * Set up CPU and thread numbers.
177 */
178 void
179 setThreadContext(int context_id, int thread_id)
180 {
181 _contextId = context_id;
182 _threadId = thread_id;
183 flags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
184 }
185
186 /**
187 * Set up a physical (e.g. device) request in a previously
188 * allocated Request object.
189 */
190 void
191 setPhys(Addr _paddr, int _size, Flags _flags)
192 {
193 assert(_size >= 0);
194 paddr = _paddr;
195 size = _size;
196 time = curTick;
197
198 flags.set(VALID_PADDR|VALID_SIZE);
199 flags.clear(VALID_VADDR|VALID_PC|VALID_EXTRA_DATA|MMAPED_IPR);
200 flags.update(_flags, PUBLIC_FLAGS);
201 }
202
203 /**
204 * Set up a virtual (e.g., CPU) request in a previously
205 * allocated Request object.
206 */
207 void
208 setVirt(int _asid, Addr _vaddr, int _size, Flags _flags, Addr _pc)
209 {
210 assert(_size >= 0);
211 asid = _asid;
212 vaddr = _vaddr;
213 size = _size;
214 pc = _pc;
215 time = curTick;
216
217 flags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
218 flags.clear(VALID_PADDR|VALID_EXTRA_DATA|MMAPED_IPR);
219 flags.update(_flags, PUBLIC_FLAGS);
220 }
221
222 /**
223 * Set just the physical address. This should only be used to
224 * record the result of a translation, and thus the vaddr must be
225 * valid before this method is called. Otherwise, use setPhys()
226 * to guarantee that the size and flags are also set.
227 */
228 void
229 setPaddr(Addr _paddr)
230 {
231 assert(flags.any(VALID_VADDR));
232 paddr = _paddr;
233 flags.set(VALID_PADDR);
234 }
235
236 /**
237 * Generate two requests as if this request had been split into two
238 * pieces. The original request can't have been translated already.
239 */
240 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
241 {
242 assert(flags.any(VALID_VADDR));
243 assert(flags.none(VALID_PADDR));
244 assert(split_addr > vaddr && split_addr < vaddr + size);
245 req1 = new Request;
246 *req1 = *this;
247 req2 = new Request;
248 *req2 = *this;
249 req1->size = split_addr - vaddr;
250 req2->vaddr = split_addr;
251 req2->size = size - req1->size;
252 }
253
254 /**
255 * Accessor for paddr.
256 */
257 Addr
258 getPaddr()
259 {
260 assert(flags.any(VALID_PADDR));
261 return paddr;
262 }
263
264 /**
265 * Accessor for size.
266 */
267 int
268 getSize()
269 {
270 assert(flags.any(VALID_SIZE));
271 return size;
272 }
273
274 /** Accessor for time. */
275 Tick
276 getTime()
277 {
278 assert(flags.any(VALID_PADDR|VALID_VADDR));
279 return time;
280 }
281
282 void
283 setTime(Tick when)
284 {
285 assert(flags.any(VALID_PADDR|VALID_VADDR));
286 time = when;
287 }
288
289 void resetTime() { setTime(curTick); }
290
291 /** Accessor for flags. */
292 Flags
293 getFlags()
294 {
295 assert(flags.any(VALID_PADDR|VALID_VADDR));
296 return flags & PUBLIC_FLAGS;
297 }
298
299 Flags
300 anyFlags(Flags _flags)
301 {
302 assert(flags.any(VALID_PADDR|VALID_VADDR));
303 assert(_flags.none(~PUBLIC_FLAGS));
304 return flags.any(_flags);
305 }
306
307 Flags
308 allFlags(Flags _flags)
309 {
310 assert(flags.any(VALID_PADDR|VALID_VADDR));
311 assert(_flags.none(~PUBLIC_FLAGS));
312 return flags.all(_flags);
313 }
314
315 /** Accessor for flags. */
316 void
317 setFlags(Flags _flags)
318 {
319 assert(flags.any(VALID_PADDR|VALID_VADDR));
320 assert(_flags.none(~PUBLIC_FLAGS));
321 flags.set(_flags);
322 }
323
324 void
325 clearFlags(Flags _flags)
326 {
327 assert(flags.any(VALID_PADDR|VALID_VADDR));
328 assert(_flags.none(~PUBLIC_FLAGS));
329 flags.clear(_flags);
330 }
331
332 void
333 clearFlags()
334 {
335 assert(flags.any(VALID_PADDR|VALID_VADDR));
336 flags.clear(PUBLIC_FLAGS);
337 }
338
339 /** Accessor function for vaddr.*/
340 Addr
341 getVaddr()
342 {
343 assert(flags.any(VALID_VADDR));
344 return vaddr;
345 }
346
347 /** Accessor function for asid.*/
348 int
349 getAsid()
350 {
351 assert(flags.any(VALID_VADDR));
352 return asid;
353 }
354
355 /** Accessor function for asi.*/
356 uint8_t
357 getAsi()
358 {
359 assert(flags.any(VALID_VADDR));
360 return flags & ASI_BITS;
361 }
362
363 /** Accessor function for asi.*/
364 void
365 setAsi(uint8_t a)
366 {
367 assert(flags.any(VALID_VADDR));
368 flags.update(a, ASI_BITS);
369 }
370
371 /** Accessor function for asi.*/
372 bool
373 isMmapedIpr()
374 {
375 assert(flags.any(VALID_PADDR));
376 return flags.any(MMAPED_IPR);
377 }
378
379 /** Accessor function for asi.*/
380 void
381 setMmapedIpr(bool r)
382 {
383 assert(VALID_VADDR);
384 flags.set(MMAPED_IPR);
385 }
386
387 /** Accessor function to check if sc result is valid. */
388 bool
389 extraDataValid()
390 {
391 return flags.any(VALID_EXTRA_DATA);
392 }
393
394 /** Accessor function for store conditional return value.*/
395 uint64_t
396 getExtraData() const
397 {
398 assert(flags.any(VALID_EXTRA_DATA));
399 return extraData;
400 }
401
402 /** Accessor function for store conditional return value.*/
403 void
404 setExtraData(uint64_t _extraData)
405 {
406 extraData = _extraData;
407 flags.set(VALID_EXTRA_DATA);
408 }
409
410 /** Accessor function for context ID.*/
411 int
412 contextId() const
413 {
414 assert(flags.any(VALID_CONTEXT_ID));
415 return _contextId;
416 }
417
418 /** Accessor function for thread ID. */
419 int
420 threadId() const
421 {
422 assert(flags.any(VALID_THREAD_ID));
423 return _threadId;
424 }
425
426 /** Accessor function for pc.*/
427 Addr
428 getPC() const
429 {
430 assert(flags.any(VALID_PC));
431 return pc;
432 }
433
434 /** Accessor Function to Check Cacheability. */
435 bool isUncacheable() const { return flags.any(UNCACHEABLE); }
436 bool isInstRead() const { return flags.any(INST_READ); }
437 bool isLocked() const { return flags.any(LOCKED); }
438 bool isSwap() const { return flags.any(MEM_SWAP|MEM_SWAP_COND); }
439 bool isCondSwap() const { return flags.any(MEM_SWAP_COND); }
440
441 bool
442 isMisaligned() const
443 {
444 if (flags.any(NO_ALIGN_FAULT))
445 return false;
446
447 if ((vaddr & 0x1))
448 return true;
449
450 if (flags.any(NO_HALF_WORD_ALIGN_FAULT))
451 return false;
452
453 if ((vaddr & 0x2))
454 return true;
455
456 return false;
457 }
458
459 friend class Packet;
460};
461
462#endif // __MEM_REQUEST_HH__