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