request.hh revision 6427:50125d42559c
14202Sbinkertn@umich.edu/*
24202Sbinkertn@umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
34202Sbinkertn@umich.edu * All rights reserved.
44202Sbinkertn@umich.edu *
54202Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without
64202Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are
74202Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright
84202Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer;
94202Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright
104202Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the
114202Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution;
124202Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its
134202Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from
144202Sbinkertn@umich.edu * this software without specific prior written permission.
154202Sbinkertn@umich.edu *
164202Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174202Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184202Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194202Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204202Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214202Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224202Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234202Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244202Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254202Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264202Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274202Sbinkertn@umich.edu *
284202Sbinkertn@umich.edu * Authors: Ron Dreslinski
294202Sbinkertn@umich.edu *          Steve Reinhardt
304202Sbinkertn@umich.edu *          Ali Saidi
314202Sbinkertn@umich.edu */
324202Sbinkertn@umich.edu
334486Sbinkertn@umich.edu/**
344486Sbinkertn@umich.edu * @file
358981Sandreas.hansson@arm.com * Declaration of a request, the overall memory request consisting of
366165Ssanchezd@stanford.edu the parts of the request that are persistent throughout the transaction.
376168Snate@binkert.org */
384202Sbinkertn@umich.edu
394202Sbinkertn@umich.edu#ifndef __MEM_REQUEST_HH__
409036Sandreas.hansson@arm.com#define __MEM_REQUEST_HH__
418981Sandreas.hansson@arm.com
424202Sbinkertn@umich.edu#include <cassert>
438761Sgblack@eecs.umich.edu
449036Sandreas.hansson@arm.com#include "base/fast_alloc.hh"
454202Sbinkertn@umich.edu#include "base/flags.hh"
464202Sbinkertn@umich.edu#include "base/misc.hh"
478914Sandreas.hansson@arm.com#include "base/types.hh"
484202Sbinkertn@umich.edu#include "sim/core.hh"
498853Sandreas.hansson@arm.com
508799Sgblack@eecs.umich.educlass Request;
518799Sgblack@eecs.umich.edu
526168Snate@binkert.orgtypedef Request* RequestPtr;
537768SAli.Saidi@ARM.com
548931Sandreas.hansson@arm.comclass Request : public FastAlloc
558931Sandreas.hansson@arm.com{
568931Sandreas.hansson@arm.com  public:
578931Sandreas.hansson@arm.com    typedef uint32_t FlagsType;
588763Sgblack@eecs.umich.edu    typedef ::Flags<FlagsType> Flags;
597768SAli.Saidi@ARM.com
607768SAli.Saidi@ARM.com    /** ASI information for this request if it exists. */
619036Sandreas.hansson@arm.com    static const FlagsType ASI_BITS                    = 0x000000FF;
628335Snate@binkert.org    /** The request was an instruction fetch. */
639036Sandreas.hansson@arm.com    static const FlagsType INST_FETCH                  = 0x00000100;
649036Sandreas.hansson@arm.com    /** The virtual address is also the physical address. */
659036Sandreas.hansson@arm.com    static const FlagsType PHYSICAL                    = 0x00000200;
669036Sandreas.hansson@arm.com    /** The request is an ALPHA VPTE pal access (hw_ld). */
679036Sandreas.hansson@arm.com    static const FlagsType VPTE                        = 0x00000400;
688335Snate@binkert.org    /** Use the alternate mode bits in ALPHA. */
698981Sandreas.hansson@arm.com    static const FlagsType ALTMODE                     = 0x00000800;
708335Snate@binkert.org    /** The request is to an uncacheable address. */
718335Snate@binkert.org    static const FlagsType UNCACHEABLE                 = 0x00001000;
728335Snate@binkert.org    /** This request is to a memory mapped register. */
738914Sandreas.hansson@arm.com    static const FlagsType MMAPED_IPR                  = 0x00002000;
747780Snilay@cs.wisc.edu
758335Snate@binkert.org    /** The request should not cause a page fault. */
768335Snate@binkert.org    static const FlagsType NO_FAULT                    = 0x00010000;
778683Snilay@cs.wisc.edu    /** The request should ignore unaligned access faults */
788335Snate@binkert.org    static const FlagsType NO_ALIGN_FAULT              = 0x00020000;
798335Snate@binkert.org    /** The request should ignore unaligned access faults */
808335Snate@binkert.org    static const FlagsType NO_HALF_WORD_ALIGN_FAULT    = 0x00040000;
818335Snate@binkert.org    /** The request should not cause a memory access. */
828335Snate@binkert.org    static const FlagsType NO_ACCESS                   = 0x00080000;
838335Snate@binkert.org    /** This request will lock or unlock the accessed memory. When used with
848615Snilay@cs.wisc.edu     * a load, the access locks the particular chunk of memory. When used
858335Snate@binkert.org     * with a store, it unlocks. The rule is that locked accesses have to be
868687Snilay@cs.wisc.edu     * made up of a locked load, some operation on the data, and then a locked
878335Snate@binkert.org     * store.
889104Shestness@cs.utexas.edu     */
897780Snilay@cs.wisc.edu    static const FlagsType LOCKED                      = 0x00100000;
907780Snilay@cs.wisc.edu    /** The request is a Load locked/store conditional. */
918687Snilay@cs.wisc.edu    static const FlagsType LLSC                        = 0x00200000;
928683Snilay@cs.wisc.edu    /** This request is for a memory swap. */
93    static const FlagsType MEM_SWAP                    = 0x00400000;
94    static const FlagsType MEM_SWAP_COND               = 0x00800000;
95
96    /** The request is a prefetch. */
97    static const FlagsType PREFETCH                    = 0x01000000;
98    /** The request should be prefetched into the exclusive state. */
99    static const FlagsType PF_EXCLUSIVE                = 0x02000000;
100    /** The request should be marked as LRU. */
101    static const FlagsType EVICT_NEXT                  = 0x04000000;
102
103    /** These flags are *not* cleared when a Request object is reused
104       (assigned a new address). */
105    static const FlagsType STICKY_FLAGS = INST_FETCH;
106
107  private:
108    typedef uint8_t PrivateFlagsType;
109    typedef ::Flags<PrivateFlagsType> PrivateFlags;
110
111    /** Whether or not the size is valid. */
112    static const PrivateFlagsType VALID_SIZE           = 0x00000001;
113    /** Whether or not paddr is valid (has been written yet). */
114    static const PrivateFlagsType VALID_PADDR          = 0x00000002;
115    /** Whether or not the vaddr & asid are valid. */
116    static const PrivateFlagsType VALID_VADDR          = 0x00000004;
117    /** Whether or not the pc is valid. */
118    static const PrivateFlagsType VALID_PC             = 0x00000010;
119    /** Whether or not the context ID is valid. */
120    static const PrivateFlagsType VALID_CONTEXT_ID     = 0x00000020;
121    static const PrivateFlagsType VALID_THREAD_ID      = 0x00000040;
122    /** Whether or not the sc result is valid. */
123    static const PrivateFlagsType VALID_EXTRA_DATA     = 0x00000080;
124
125    /** These flags are *not* cleared when a Request object is reused
126       (assigned a new address). */
127    static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
128        VALID_CONTEXT_ID | VALID_THREAD_ID;
129
130  private:
131    /**
132     * The physical address of the request. Valid only if validPaddr
133     * is set.
134     */
135    Addr _paddr;
136
137    /**
138     * The size of the request. This field must be set when vaddr or
139     * paddr is written via setVirt() or setPhys(), so it is always
140     * valid as long as one of the address fields is valid.
141     */
142    int _size;
143
144    /** Flag structure for the request. */
145    Flags _flags;
146
147    /** Private flags for field validity checking. */
148    PrivateFlags privateFlags;
149
150    /**
151     * The time this request was started. Used to calculate
152     * latencies. This field is set to curTick any time paddr or vaddr
153     * is written.
154     */
155    Tick _time;
156
157    /** The address space ID. */
158    int _asid;
159
160    /** The virtual address of the request. */
161    Addr _vaddr;
162
163    /**
164     * Extra data for the request, such as the return value of
165     * store conditional or the compare value for a CAS. */
166    uint64_t _extraData;
167
168    /** The context ID (for statistics, typically). */
169    int _contextId;
170    /** The thread ID (id within this CPU) */
171    int _threadId;
172
173    /** program counter of initiating access; for tracing/debugging */
174    Addr _pc;
175
176  public:
177    /** Minimal constructor.  No fields are initialized.
178     *  (Note that _flags and privateFlags are cleared by Flags
179     *  default constructor.)
180     */
181    Request()
182    {}
183
184    /**
185     * Constructor for physical (e.g. device) requests.  Initializes
186     * just physical address, size, flags, and timestamp (to curTick).
187     * These fields are adequate to perform a request.
188     */
189    Request(Addr paddr, int size, Flags flags)
190    {
191        setPhys(paddr, size, flags);
192    }
193
194    Request(Addr paddr, int size, Flags flags, Tick time)
195    {
196        setPhys(paddr, size, flags, time);
197    }
198
199    Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
200            int cid, ThreadID tid)
201    {
202        setVirt(asid, vaddr, size, flags, pc);
203        setThreadContext(cid, tid);
204    }
205
206    ~Request() {}  // for FastAlloc
207
208    /**
209     * Set up CPU and thread numbers.
210     */
211    void
212    setThreadContext(int context_id, ThreadID tid)
213    {
214        _contextId = context_id;
215        _threadId = tid;
216        privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
217    }
218
219    /**
220     * Set up a physical (e.g. device) request in a previously
221     * allocated Request object.
222     */
223    void
224    setPhys(Addr paddr, int size, Flags flags, Tick time)
225    {
226        assert(size >= 0);
227        _paddr = paddr;
228        _size = size;
229        _time = time;
230
231        _flags.clear(~STICKY_FLAGS);
232        _flags.set(flags);
233        privateFlags.clear(~STICKY_PRIVATE_FLAGS);
234        privateFlags.set(VALID_PADDR|VALID_SIZE);
235    }
236
237    void
238    setPhys(Addr paddr, int size, Flags flags)
239    {
240        setPhys(paddr, size, flags, curTick);
241    }
242
243    /**
244     * Set up a virtual (e.g., CPU) request in a previously
245     * allocated Request object.
246     */
247    void
248    setVirt(int asid, Addr vaddr, int size, Flags flags, Addr pc)
249    {
250        assert(size >= 0);
251        _asid = asid;
252        _vaddr = vaddr;
253        _size = size;
254        _pc = pc;
255        _time = curTick;
256
257        _flags.clear(~STICKY_FLAGS);
258        _flags.set(flags);
259        privateFlags.clear(~STICKY_PRIVATE_FLAGS);
260        privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
261    }
262
263    /**
264     * Set just the physical address.  This should only be used to
265     * record the result of a translation, and thus the vaddr must be
266     * valid before this method is called.  Otherwise, use setPhys()
267     * to guarantee that the size and flags are also set.
268     */
269    void
270    setPaddr(Addr paddr)
271    {
272        assert(privateFlags.isSet(VALID_VADDR));
273        _paddr = paddr;
274        privateFlags.set(VALID_PADDR);
275    }
276
277    /**
278     * Generate two requests as if this request had been split into two
279     * pieces. The original request can't have been translated already.
280     */
281    void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
282    {
283        assert(privateFlags.isSet(VALID_VADDR));
284        assert(privateFlags.noneSet(VALID_PADDR));
285        assert(split_addr > _vaddr && split_addr < _vaddr + _size);
286        req1 = new Request;
287        *req1 = *this;
288        req2 = new Request;
289        *req2 = *this;
290        req1->_size = split_addr - _vaddr;
291        req2->_vaddr = split_addr;
292        req2->_size = _size - req1->_size;
293    }
294
295    /**
296     * Accessor for paddr.
297     */
298    bool
299    hasPaddr()
300    {
301        return privateFlags.isSet(VALID_PADDR);
302    }
303
304    Addr
305    getPaddr()
306    {
307        assert(privateFlags.isSet(VALID_PADDR));
308        return _paddr;
309    }
310
311    /**
312     *  Accessor for size.
313     */
314    bool
315    hasSize()
316    {
317        return privateFlags.isSet(VALID_SIZE);
318    }
319
320    int
321    getSize()
322    {
323        assert(privateFlags.isSet(VALID_SIZE));
324        return _size;
325    }
326
327    /** Accessor for time. */
328    Tick
329    time() const
330    {
331        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
332        return _time;
333    }
334
335    void
336    time(Tick time)
337    {
338        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
339        _time = time;
340    }
341
342    /** Accessor for flags. */
343    Flags
344    getFlags()
345    {
346        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
347        return _flags;
348    }
349
350    void
351    setFlags(Flags flags)
352    {
353        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
354        _flags.set(flags);
355    }
356
357    /** Accessor function for vaddr.*/
358    Addr
359    getVaddr()
360    {
361        assert(privateFlags.isSet(VALID_VADDR));
362        return _vaddr;
363    }
364
365    /** Accessor function for asid.*/
366    int
367    getAsid()
368    {
369        assert(privateFlags.isSet(VALID_VADDR));
370        return _asid;
371    }
372
373    /** Accessor function for asi.*/
374    uint8_t
375    getAsi()
376    {
377        assert(privateFlags.isSet(VALID_VADDR));
378        return _flags & ASI_BITS;
379    }
380
381    /** Accessor function for MMAPED_IPR flag. */
382    bool
383    isMmapedIpr()
384    {
385        assert(privateFlags.isSet(VALID_PADDR));
386        return _flags.isSet(MMAPED_IPR);
387    }
388
389    void
390    setMmapedIpr(bool r)
391    {
392        assert(VALID_VADDR);
393        _flags.set(MMAPED_IPR);
394    }
395
396    /** Accessor function to check if sc result is valid. */
397    bool
398    extraDataValid()
399    {
400        return privateFlags.isSet(VALID_EXTRA_DATA);
401    }
402
403    /** Accessor function for store conditional return value.*/
404    uint64_t
405    getExtraData() const
406    {
407        assert(privateFlags.isSet(VALID_EXTRA_DATA));
408        return _extraData;
409    }
410
411    /** Accessor function for store conditional return value.*/
412    void
413    setExtraData(uint64_t extraData)
414    {
415        _extraData = extraData;
416        privateFlags.set(VALID_EXTRA_DATA);
417    }
418
419    bool
420    hasContextId() const
421    {
422        return privateFlags.isSet(VALID_CONTEXT_ID);
423    }
424
425    /** Accessor function for context ID.*/
426    int
427    contextId() const
428    {
429        assert(privateFlags.isSet(VALID_CONTEXT_ID));
430        return _contextId;
431    }
432
433    /** Accessor function for thread ID. */
434    int
435    threadId() const
436    {
437        assert(privateFlags.isSet(VALID_THREAD_ID));
438        return _threadId;
439    }
440
441    bool
442    hasPC() const
443    {
444        return privateFlags.isSet(VALID_PC);
445    }
446
447    /** Accessor function for pc.*/
448    Addr
449    getPC() const
450    {
451        assert(privateFlags.isSet(VALID_PC));
452        return _pc;
453    }
454
455    /** Accessor Function to Check Cacheability. */
456    bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
457    bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
458    bool isPrefetch() const { return _flags.isSet(PREFETCH); }
459    bool isLLSC() const { return _flags.isSet(LLSC); }
460    bool isLocked() const { return _flags.isSet(LOCKED); }
461    bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
462    bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
463
464    bool
465    isMisaligned() const
466    {
467        if (_flags.isSet(NO_ALIGN_FAULT))
468            return false;
469
470        if ((_vaddr & 0x1))
471            return true;
472
473        if (_flags.isSet(NO_HALF_WORD_ALIGN_FAULT))
474            return false;
475
476        if ((_vaddr & 0x2))
477            return true;
478
479        return false;
480    }
481};
482
483#endif // __MEM_REQUEST_HH__
484