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