request.hh revision 3806:65ae5388c059
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
47class Request;
48
49typedef Request* RequestPtr;
50
51
52/** ASI information for this request if it exsits. */
53const uint32_t ASI_BITS         = 0x000FF;
54/** The request is a Load locked/store conditional. */
55const uint32_t LOCKED		= 0x00100;
56/** The virtual address is also the physical address. */
57const uint32_t PHYSICAL		= 0x00200;
58/** The request is an ALPHA VPTE pal access (hw_ld). */
59const uint32_t VPTE		= 0x00400;
60/** Use the alternate mode bits in ALPHA. */
61const uint32_t ALTMODE		= 0x00800;
62/** The request is to an uncacheable address. */
63const uint32_t UNCACHEABLE	= 0x01000;
64/** The request should not cause a page fault. */
65const uint32_t NO_FAULT         = 0x02000;
66/** The request should be prefetched into the exclusive state. */
67const uint32_t PF_EXCLUSIVE	= 0x10000;
68/** The request should be marked as LRU. */
69const uint32_t EVICT_NEXT	= 0x20000;
70/** The request should ignore unaligned access faults */
71const uint32_t NO_ALIGN_FAULT   = 0x40000;
72/** The request was an instruction read. */
73const uint32_t INST_READ        = 0x80000;
74
75class Request
76{
77  private:
78    /**
79     * The physical address of the request. Valid only if validPaddr
80     * is set. */
81    Addr paddr;
82
83    /**
84     * The size of the request. This field must be set when vaddr or
85     * paddr is written via setVirt() or setPhys(), so it is always
86     * valid as long as one of the address fields is valid.  */
87    int size;
88
89    /** Flag structure for the request. */
90    uint32_t flags;
91
92    /**
93     * The time this request was started. Used to calculate
94     * latencies. This field is set to curTick any time paddr or vaddr
95     * is written.  */
96    Tick time;
97
98    /** The address space ID. */
99    int asid;
100
101    /** This request is to a memory mapped register. */
102    bool mmapedIpr;
103
104    /** The virtual address of the request. */
105    Addr vaddr;
106
107    /** The return value of store conditional. */
108    uint64_t scResult;
109
110    /** The cpu number (for statistics, typically). */
111    int cpuNum;
112    /** The requesting thread id (for statistics, typically). */
113    int  threadNum;
114
115    /** program counter of initiating access; for tracing/debugging */
116    Addr pc;
117
118    /** Whether or not paddr is valid (has been written yet). */
119    bool validPaddr;
120    /** Whether or not the asid & vaddr are valid. */
121    bool validAsidVaddr;
122    /** Whether or not the sc result is valid. */
123    bool validScResult;
124    /** Whether or not the cpu number & thread ID are valid. */
125    bool validCpuAndThreadNums;
126    /** Whether or not the pc is valid. */
127    bool validPC;
128
129  public:
130    /** Minimal constructor.  No fields are initialized. */
131    Request()
132        : validPaddr(false), validAsidVaddr(false),
133          validScResult(false), validCpuAndThreadNums(false), validPC(false)
134    {}
135
136    /**
137     * Constructor for physical (e.g. device) requests.  Initializes
138     * just physical address, size, flags, and timestamp (to curTick).
139     * These fields are adequate to perform a request.  */
140    Request(Addr _paddr, int _size, int _flags)
141        : validCpuAndThreadNums(false)
142    { setPhys(_paddr, _size, _flags); }
143
144    Request(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc,
145            int _cpuNum, int _threadNum)
146    {
147        setThreadContext(_cpuNum, _threadNum);
148        setVirt(_asid, _vaddr, _size, _flags, _pc);
149    }
150
151    /**
152     * Set up CPU and thread numbers. */
153    void setThreadContext(int _cpuNum, int _threadNum)
154    {
155        cpuNum = _cpuNum;
156        threadNum = _threadNum;
157        validCpuAndThreadNums = true;
158    }
159
160    /**
161     * Set up a physical (e.g. device) request in a previously
162     * allocated Request object. */
163    void setPhys(Addr _paddr, int _size, int _flags)
164    {
165        paddr = _paddr;
166        size = _size;
167        flags = _flags;
168        time = curTick;
169        validPaddr = true;
170        validAsidVaddr = false;
171        validPC = false;
172        validScResult = false;
173        mmapedIpr = false;
174    }
175
176    /**
177     * Set up a virtual (e.g., CPU) request in a previously
178     * allocated Request object. */
179    void setVirt(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc)
180    {
181        asid = _asid;
182        vaddr = _vaddr;
183        size = _size;
184        flags = _flags;
185        pc = _pc;
186        time = curTick;
187        validPaddr = false;
188        validAsidVaddr = true;
189        validPC = true;
190        validScResult = false;
191        mmapedIpr = false;
192    }
193
194    /** Set just the physical address.  This should only be used to
195     * record the result of a translation, and thus the vaddr must be
196     * valid before this method is called.  Otherwise, use setPhys()
197     * to guarantee that the size and flags are also set.
198     */
199    void setPaddr(Addr _paddr)
200    {
201        assert(validAsidVaddr);
202        paddr = _paddr;
203        validPaddr = true;
204    }
205
206    /** Accessor for paddr. */
207    Addr getPaddr() { assert(validPaddr); return paddr; }
208
209    /** Accessor for size. */
210    int getSize() { assert(validPaddr || validAsidVaddr); return size; }
211    /** Accessor for time. */
212    Tick getTime() { assert(validPaddr || validAsidVaddr); return time; }
213
214    /** Accessor for flags. */
215    uint32_t getFlags() { assert(validPaddr || validAsidVaddr); return flags; }
216    /** Accessor for paddr. */
217    void setFlags(uint32_t _flags)
218    { assert(validPaddr || validAsidVaddr); flags = _flags; }
219
220    /** Accessor function for vaddr.*/
221    Addr getVaddr() { assert(validAsidVaddr); return vaddr; }
222
223    /** Accessor function for asid.*/
224    int getAsid() { assert(validAsidVaddr); return asid; }
225
226    /** Accessor function for asi.*/
227    uint8_t getAsi() { assert(validAsidVaddr); return flags & ASI_BITS; }
228
229    /** Accessor function for asi.*/
230    void setAsi(uint8_t a)
231    { assert(validAsidVaddr); flags = (flags & ~ASI_BITS) | a; }
232
233    /** Accessor function for asi.*/
234    bool isMmapedIpr() { assert(validPaddr); return mmapedIpr; }
235
236    /** Accessor function for asi.*/
237    void setMmapedIpr(bool r) { assert(validPaddr); mmapedIpr = r; }
238
239    /** Accessor function to check if sc result is valid. */
240    bool scResultValid() { return validScResult; }
241    /** Accessor function for store conditional return value.*/
242    uint64_t getScResult() { assert(validScResult); return scResult; }
243    /** Accessor function for store conditional return value.*/
244    void setScResult(uint64_t _scResult)
245    { scResult = _scResult; validScResult = true; }
246
247    /** Accessor function for cpu number.*/
248    int getCpuNum() { assert(validCpuAndThreadNums); return cpuNum; }
249    /** Accessor function for thread number.*/
250    int getThreadNum()  { assert(validCpuAndThreadNums); return threadNum; }
251
252    /** Accessor function for pc.*/
253    Addr getPC() { assert(validPC); return pc; }
254
255    /** Accessor Function to Check Cacheability. */
256    bool isUncacheable() { return (getFlags() & UNCACHEABLE) != 0; }
257
258    bool isInstRead() { return (getFlags() & INST_READ) != 0; }
259
260    bool isLocked() { return (getFlags() & LOCKED) != 0; }
261
262    friend class Packet;
263};
264
265#endif // __MEM_REQUEST_HH__
266