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