request.hh revision 10824
111317Sm.alian1369@gmail.com/*
211317Sm.alian1369@gmail.com * Copyright (c) 2012-2013 ARM Limited
311317Sm.alian1369@gmail.com * All rights reserved
411317Sm.alian1369@gmail.com *
511317Sm.alian1369@gmail.com * The license below extends only to copyright in the software and shall
611317Sm.alian1369@gmail.com * not be construed as granting a license to any other intellectual
711317Sm.alian1369@gmail.com * property including but not limited to intellectual property relating
811317Sm.alian1369@gmail.com * to a hardware implementation of the functionality of the software
911317Sm.alian1369@gmail.com * licensed hereunder.  You may use the software subject to the license
1011317Sm.alian1369@gmail.com * terms below provided that you ensure that this notice is replicated
1111317Sm.alian1369@gmail.com * unmodified and in its entirety in all distributions of the software,
1211317Sm.alian1369@gmail.com * modified or unmodified, in source code or in binary form.
1311317Sm.alian1369@gmail.com *
1411317Sm.alian1369@gmail.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
1511317Sm.alian1369@gmail.com * All rights reserved.
1611317Sm.alian1369@gmail.com *
1711317Sm.alian1369@gmail.com * Redistribution and use in source and binary forms, with or without
1811317Sm.alian1369@gmail.com * modification, are permitted provided that the following conditions are
1911317Sm.alian1369@gmail.com * met: redistributions of source code must retain the above copyright
2011317Sm.alian1369@gmail.com * notice, this list of conditions and the following disclaimer;
2111317Sm.alian1369@gmail.com * redistributions in binary form must reproduce the above copyright
2211317Sm.alian1369@gmail.com * notice, this list of conditions and the following disclaimer in the
2311317Sm.alian1369@gmail.com * documentation and/or other materials provided with the distribution;
2411317Sm.alian1369@gmail.com * neither the name of the copyright holders nor the names of its
2511317Sm.alian1369@gmail.com * contributors may be used to endorse or promote products derived from
2611317Sm.alian1369@gmail.com * this software without specific prior written permission.
2711317Sm.alian1369@gmail.com *
2811317Sm.alian1369@gmail.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2911317Sm.alian1369@gmail.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3011317Sm.alian1369@gmail.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3111317Sm.alian1369@gmail.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3211317Sm.alian1369@gmail.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3311317Sm.alian1369@gmail.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3411317Sm.alian1369@gmail.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3511317Sm.alian1369@gmail.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3611317Sm.alian1369@gmail.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3711317Sm.alian1369@gmail.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3811317Sm.alian1369@gmail.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3911800Sbrandon.potter@amd.com *
4011317Sm.alian1369@gmail.com * Authors: Ron Dreslinski
4111800Sbrandon.potter@amd.com *          Steve Reinhardt
4211317Sm.alian1369@gmail.com *          Ali Saidi
4311317Sm.alian1369@gmail.com */
4411317Sm.alian1369@gmail.com
4511317Sm.alian1369@gmail.com/**
4613766Sgabeblack@google.com * @file
4711317Sm.alian1369@gmail.com * Declaration of a request, the overall memory request consisting of
4811317Sm.alian1369@gmail.com the parts of the request that are persistent throughout the transaction.
4911317Sm.alian1369@gmail.com */
5011317Sm.alian1369@gmail.com
5111317Sm.alian1369@gmail.com#ifndef __MEM_REQUEST_HH__
5211533Sm.alian1369@gmail.com#define __MEM_REQUEST_HH__
5311317Sm.alian1369@gmail.com
5411317Sm.alian1369@gmail.com#include <cassert>
5511317Sm.alian1369@gmail.com#include <climits>
5611317Sm.alian1369@gmail.com
5711317Sm.alian1369@gmail.com#include "base/flags.hh"
5811317Sm.alian1369@gmail.com#include "base/misc.hh"
5911317Sm.alian1369@gmail.com#include "base/types.hh"
6011317Sm.alian1369@gmail.com#include "sim/core.hh"
6111317Sm.alian1369@gmail.com
6211317Sm.alian1369@gmail.com/**
6311317Sm.alian1369@gmail.com * Special TaskIds that are used for per-context-switch stats dumps
6411317Sm.alian1369@gmail.com * and Cache Occupancy. Having too many tasks seems to be a problem
6511317Sm.alian1369@gmail.com * with vector stats. 1024 seems to be a reasonable number that
6611317Sm.alian1369@gmail.com * doesn't cause a problem with stats and is large enough to realistic
6711317Sm.alian1369@gmail.com * benchmarks (Linux/Android boot, BBench, etc.)
6811317Sm.alian1369@gmail.com */
6911317Sm.alian1369@gmail.com
7011317Sm.alian1369@gmail.comnamespace ContextSwitchTaskId {
7111317Sm.alian1369@gmail.com    enum TaskId {
7211317Sm.alian1369@gmail.com        MaxNormalTaskId = 1021, /* Maximum number of normal tasks */
7311317Sm.alian1369@gmail.com        Prefetcher = 1022, /* For cache lines brought in by prefetcher */
7411317Sm.alian1369@gmail.com        DMA = 1023, /* Mostly Table Walker */
7511317Sm.alian1369@gmail.com        Unknown = 1024,
7611317Sm.alian1369@gmail.com        NumTaskId
7711533Sm.alian1369@gmail.com    };
7811533Sm.alian1369@gmail.com}
7911533Sm.alian1369@gmail.com
8011533Sm.alian1369@gmail.comclass Request;
8111533Sm.alian1369@gmail.com
8211533Sm.alian1369@gmail.comtypedef Request* RequestPtr;
8311533Sm.alian1369@gmail.comtypedef uint16_t MasterID;
8411533Sm.alian1369@gmail.com
8511533Sm.alian1369@gmail.comclass Request
8611533Sm.alian1369@gmail.com{
8711533Sm.alian1369@gmail.com  public:
8811533Sm.alian1369@gmail.com    typedef uint32_t FlagsType;
8911533Sm.alian1369@gmail.com    typedef uint8_t ArchFlagsType;
9011533Sm.alian1369@gmail.com    typedef ::Flags<FlagsType> Flags;
9111533Sm.alian1369@gmail.com
9211533Sm.alian1369@gmail.com    /**
9311533Sm.alian1369@gmail.com     * Architecture specific flags.
9411533Sm.alian1369@gmail.com     *
9511533Sm.alian1369@gmail.com     * These bits int the flag field are reserved for
9611533Sm.alian1369@gmail.com     * architecture-specific code. For example, SPARC uses them to
9711533Sm.alian1369@gmail.com     * represent ASIs.
9811533Sm.alian1369@gmail.com     */
9911533Sm.alian1369@gmail.com    static const FlagsType ARCH_BITS                   = 0x000000FF;
10011533Sm.alian1369@gmail.com    /** The request was an instruction fetch. */
10111533Sm.alian1369@gmail.com    static const FlagsType INST_FETCH                  = 0x00000100;
10211533Sm.alian1369@gmail.com    /** The virtual address is also the physical address. */
10311533Sm.alian1369@gmail.com    static const FlagsType PHYSICAL                    = 0x00000200;
10411533Sm.alian1369@gmail.com    /**
10511533Sm.alian1369@gmail.com     * The request is to an uncacheable address.
10611533Sm.alian1369@gmail.com     *
10711533Sm.alian1369@gmail.com     * @note Uncacheable accesses may be reordered by CPU models. The
10811533Sm.alian1369@gmail.com     * STRICT_ORDER flag should be set if such reordering is
10911533Sm.alian1369@gmail.com     * undesirable.
11011533Sm.alian1369@gmail.com     */
11111533Sm.alian1369@gmail.com    static const FlagsType UNCACHEABLE                = 0x00000400;
11211533Sm.alian1369@gmail.com    /**
11311533Sm.alian1369@gmail.com     * The request is required to be strictly ordered by <i>CPU
11411533Sm.alian1369@gmail.com     * models</i> and is non-speculative.
11511533Sm.alian1369@gmail.com     *
11611533Sm.alian1369@gmail.com     * A strictly ordered request is guaranteed to never be re-ordered
11711533Sm.alian1369@gmail.com     * or executed speculatively by a CPU model. The memory system may
11811533Sm.alian1369@gmail.com     * still reorder requests in caches unless the UNCACHEABLE flag is
11911533Sm.alian1369@gmail.com     * set as well.
12011533Sm.alian1369@gmail.com     */
12111533Sm.alian1369@gmail.com    static const FlagsType STRICT_ORDER                = 0x00000800;
12211533Sm.alian1369@gmail.com    /** This request is to a memory mapped register. */
12311533Sm.alian1369@gmail.com    static const FlagsType MMAPPED_IPR                 = 0x00002000;
12411533Sm.alian1369@gmail.com    /** This request is a clear exclusive. */
12511533Sm.alian1369@gmail.com    static const FlagsType CLEAR_LL                    = 0x00004000;
12611533Sm.alian1369@gmail.com    /** This request is made in privileged mode. */
12711533Sm.alian1369@gmail.com    static const FlagsType PRIVILEGED                  = 0x00008000;
12811317Sm.alian1369@gmail.com
12911317Sm.alian1369@gmail.com    /** This is a write that is targeted and zeroing an entire cache block.
13011317Sm.alian1369@gmail.com     * There is no need for a read/modify/write
13111533Sm.alian1369@gmail.com     */
13211317Sm.alian1369@gmail.com    static const FlagsType CACHE_BLOCK_ZERO            = 0x00010000;
13311533Sm.alian1369@gmail.com
13412087Sspwilson2@wisc.edu    /** The request should not cause a memory access. */
13512087Sspwilson2@wisc.edu    static const FlagsType NO_ACCESS                   = 0x00080000;
13611317Sm.alian1369@gmail.com    /** This request will lock or unlock the accessed memory. When used with
13711317Sm.alian1369@gmail.com     * a load, the access locks the particular chunk of memory. When used
13811317Sm.alian1369@gmail.com     * with a store, it unlocks. The rule is that locked accesses have to be
13911317Sm.alian1369@gmail.com     * made up of a locked load, some operation on the data, and then a locked
14011317Sm.alian1369@gmail.com     * store.
14111317Sm.alian1369@gmail.com     */
14211317Sm.alian1369@gmail.com    static const FlagsType LOCKED_RMW                  = 0x00100000;
14311317Sm.alian1369@gmail.com    /** The request is a Load locked/store conditional. */
14411317Sm.alian1369@gmail.com    static const FlagsType LLSC                        = 0x00200000;
14511317Sm.alian1369@gmail.com    /** This request is for a memory swap. */
14611317Sm.alian1369@gmail.com    static const FlagsType MEM_SWAP                    = 0x00400000;
14711317Sm.alian1369@gmail.com    static const FlagsType MEM_SWAP_COND               = 0x00800000;
14811317Sm.alian1369@gmail.com
14911317Sm.alian1369@gmail.com    /** The request is a prefetch. */
15011317Sm.alian1369@gmail.com    static const FlagsType PREFETCH                    = 0x01000000;
15111533Sm.alian1369@gmail.com    /** The request should be prefetched into the exclusive state. */
15211317Sm.alian1369@gmail.com    static const FlagsType PF_EXCLUSIVE                = 0x02000000;
15311317Sm.alian1369@gmail.com    /** The request should be marked as LRU. */
15411317Sm.alian1369@gmail.com    static const FlagsType EVICT_NEXT                  = 0x04000000;
15511317Sm.alian1369@gmail.com
15611317Sm.alian1369@gmail.com    /** The request should be handled by the generic IPR code (only
15711533Sm.alian1369@gmail.com     * valid together with MMAPPED_IPR) */
15811317Sm.alian1369@gmail.com    static const FlagsType GENERIC_IPR                 = 0x08000000;
15911317Sm.alian1369@gmail.com
16011317Sm.alian1369@gmail.com    /** The request targets the secure memory space. */
16111317Sm.alian1369@gmail.com    static const FlagsType SECURE                      = 0x10000000;
16211317Sm.alian1369@gmail.com    /** The request is a page table walk */
16311317Sm.alian1369@gmail.com    static const FlagsType PT_WALK                     = 0x20000000;
16411317Sm.alian1369@gmail.com
16511317Sm.alian1369@gmail.com    /** These flags are *not* cleared when a Request object is reused
16611317Sm.alian1369@gmail.com       (assigned a new address). */
16711533Sm.alian1369@gmail.com    static const FlagsType STICKY_FLAGS = INST_FETCH;
16811317Sm.alian1369@gmail.com
16911317Sm.alian1369@gmail.com    /** Request Ids that are statically allocated
17011533Sm.alian1369@gmail.com     * @{*/
17111533Sm.alian1369@gmail.com    /** This request id is used for writeback requests by the caches */
17211533Sm.alian1369@gmail.com    static const MasterID wbMasterId = 0;
17311533Sm.alian1369@gmail.com    /** This request id is used for functional requests that don't come from a
17411533Sm.alian1369@gmail.com     * particular device
17511533Sm.alian1369@gmail.com     */
17611317Sm.alian1369@gmail.com    static const MasterID funcMasterId = 1;
17711533Sm.alian1369@gmail.com    /** This request id is used for message signaled interrupts */
17811562Sm.alian1369@gmail.com    static const MasterID intMasterId = 2;
17911317Sm.alian1369@gmail.com    /** Invalid request id for assertion checking only. It is invalid behavior
18011317Sm.alian1369@gmail.com     * to ever send this id as part of a request.
18111317Sm.alian1369@gmail.com     * @todo C++1x replace with numeric_limits when constexpr is added  */
18211317Sm.alian1369@gmail.com    static const MasterID invldMasterId = std::numeric_limits<MasterID>::max();
18311317Sm.alian1369@gmail.com    /** @} */
18411317Sm.alian1369@gmail.com
18511317Sm.alian1369@gmail.com    /** Invalid or unknown Pid. Possible when operating system is not present
18611317Sm.alian1369@gmail.com     *  or has not assigned a pid yet */
18711317Sm.alian1369@gmail.com    static const uint32_t invldPid = std::numeric_limits<uint32_t>::max();
18811317Sm.alian1369@gmail.com
18911317Sm.alian1369@gmail.com  private:
19011317Sm.alian1369@gmail.com    typedef uint8_t PrivateFlagsType;
19111317Sm.alian1369@gmail.com    typedef ::Flags<PrivateFlagsType> PrivateFlags;
19211317Sm.alian1369@gmail.com
19311317Sm.alian1369@gmail.com    /** Whether or not the size is valid. */
19411317Sm.alian1369@gmail.com    static const PrivateFlagsType VALID_SIZE           = 0x00000001;
19511317Sm.alian1369@gmail.com    /** Whether or not paddr is valid (has been written yet). */
19611317Sm.alian1369@gmail.com    static const PrivateFlagsType VALID_PADDR          = 0x00000002;
19711317Sm.alian1369@gmail.com    /** Whether or not the vaddr & asid are valid. */
19811317Sm.alian1369@gmail.com    static const PrivateFlagsType VALID_VADDR          = 0x00000004;
19911317Sm.alian1369@gmail.com    /** Whether or not the pc is valid. */
20011317Sm.alian1369@gmail.com    static const PrivateFlagsType VALID_PC             = 0x00000010;
20111317Sm.alian1369@gmail.com    /** Whether or not the context ID is valid. */
20211317Sm.alian1369@gmail.com    static const PrivateFlagsType VALID_CONTEXT_ID     = 0x00000020;
20311317Sm.alian1369@gmail.com    static const PrivateFlagsType VALID_THREAD_ID      = 0x00000040;
20411317Sm.alian1369@gmail.com    /** Whether or not the sc result is valid. */
20511317Sm.alian1369@gmail.com    static const PrivateFlagsType VALID_EXTRA_DATA     = 0x00000080;
20611701Smichael.lebeane@amd.com
20711317Sm.alian1369@gmail.com    /** These flags are *not* cleared when a Request object is reused
20811317Sm.alian1369@gmail.com       (assigned a new address). */
20911317Sm.alian1369@gmail.com    static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
21011317Sm.alian1369@gmail.com        VALID_CONTEXT_ID | VALID_THREAD_ID;
21111317Sm.alian1369@gmail.com
21211317Sm.alian1369@gmail.com  private:
21311317Sm.alian1369@gmail.com
21411317Sm.alian1369@gmail.com    /**
21511317Sm.alian1369@gmail.com     * Set up a physical (e.g. device) request in a previously
21611317Sm.alian1369@gmail.com     * allocated Request object.
21711317Sm.alian1369@gmail.com     */
21811317Sm.alian1369@gmail.com    void
21911317Sm.alian1369@gmail.com    setPhys(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time)
22011317Sm.alian1369@gmail.com    {
22111317Sm.alian1369@gmail.com        assert(size >= 0);
22211317Sm.alian1369@gmail.com        _paddr = paddr;
22311317Sm.alian1369@gmail.com        _size = size;
22411317Sm.alian1369@gmail.com        _time = time;
22511317Sm.alian1369@gmail.com        _masterId = mid;
22611317Sm.alian1369@gmail.com        _flags.clear(~STICKY_FLAGS);
22711317Sm.alian1369@gmail.com        _flags.set(flags);
22811317Sm.alian1369@gmail.com        privateFlags.clear(~STICKY_PRIVATE_FLAGS);
22911317Sm.alian1369@gmail.com        privateFlags.set(VALID_PADDR|VALID_SIZE);
23011317Sm.alian1369@gmail.com        depth = 0;
23111317Sm.alian1369@gmail.com        accessDelta = 0;
23211317Sm.alian1369@gmail.com        //translateDelta = 0;
23311317Sm.alian1369@gmail.com    }
23411317Sm.alian1369@gmail.com
23511317Sm.alian1369@gmail.com    /**
23611317Sm.alian1369@gmail.com     * The physical address of the request. Valid only if validPaddr
23711317Sm.alian1369@gmail.com     * is set.
23811317Sm.alian1369@gmail.com     */
23911317Sm.alian1369@gmail.com    Addr _paddr;
24011317Sm.alian1369@gmail.com
24111317Sm.alian1369@gmail.com    /**
24211317Sm.alian1369@gmail.com     * The size of the request. This field must be set when vaddr or
24311317Sm.alian1369@gmail.com     * paddr is written via setVirt() or setPhys(), so it is always
24411317Sm.alian1369@gmail.com     * valid as long as one of the address fields is valid.
24511317Sm.alian1369@gmail.com     */
24611317Sm.alian1369@gmail.com    unsigned _size;
24711317Sm.alian1369@gmail.com
24811317Sm.alian1369@gmail.com    /** The requestor ID which is unique in the system for all ports
24911317Sm.alian1369@gmail.com     * that are capable of issuing a transaction
25011317Sm.alian1369@gmail.com     */
25111317Sm.alian1369@gmail.com    MasterID _masterId;
25211317Sm.alian1369@gmail.com
25311317Sm.alian1369@gmail.com    /** Flag structure for the request. */
25411317Sm.alian1369@gmail.com    Flags _flags;
25511317Sm.alian1369@gmail.com
25611317Sm.alian1369@gmail.com    /** Private flags for field validity checking. */
25711317Sm.alian1369@gmail.com    PrivateFlags privateFlags;
25811317Sm.alian1369@gmail.com
25911317Sm.alian1369@gmail.com    /**
26011317Sm.alian1369@gmail.com     * The time this request was started. Used to calculate
26111317Sm.alian1369@gmail.com     * latencies. This field is set to curTick() any time paddr or vaddr
26211317Sm.alian1369@gmail.com     * is written.
26311317Sm.alian1369@gmail.com     */
26411317Sm.alian1369@gmail.com    Tick _time;
26511533Sm.alian1369@gmail.com
26611533Sm.alian1369@gmail.com    /**
26711317Sm.alian1369@gmail.com     * The task id associated with this request
26811317Sm.alian1369@gmail.com     */
26911317Sm.alian1369@gmail.com    uint32_t _taskId;
27011317Sm.alian1369@gmail.com
27111317Sm.alian1369@gmail.com    /** The address space ID. */
27211317Sm.alian1369@gmail.com    int _asid;
27311533Sm.alian1369@gmail.com
27411533Sm.alian1369@gmail.com    /** The virtual address of the request. */
27511317Sm.alian1369@gmail.com    Addr _vaddr;
27611317Sm.alian1369@gmail.com
27711317Sm.alian1369@gmail.com    /**
27811533Sm.alian1369@gmail.com     * Extra data for the request, such as the return value of
27911317Sm.alian1369@gmail.com     * store conditional or the compare value for a CAS. */
28011317Sm.alian1369@gmail.com    uint64_t _extraData;
28111533Sm.alian1369@gmail.com
28211533Sm.alian1369@gmail.com    /** The context ID (for statistics, typically). */
28311317Sm.alian1369@gmail.com    int _contextId;
28411317Sm.alian1369@gmail.com    /** The thread ID (id within this CPU) */
28511533Sm.alian1369@gmail.com    ThreadID _threadId;
28611317Sm.alian1369@gmail.com
28711533Sm.alian1369@gmail.com    /** program counter of initiating access; for tracing/debugging */
28811317Sm.alian1369@gmail.com    Addr _pc;
28911317Sm.alian1369@gmail.com
29011317Sm.alian1369@gmail.com  public:
29111533Sm.alian1369@gmail.com
29211317Sm.alian1369@gmail.com    /**
29311317Sm.alian1369@gmail.com     * Minimal constructor. No fields are initialized. (Note that
29411533Sm.alian1369@gmail.com     *  _flags and privateFlags are cleared by Flags default
29511533Sm.alian1369@gmail.com     *  constructor.)
29611317Sm.alian1369@gmail.com     */
29711317Sm.alian1369@gmail.com    Request()
29811533Sm.alian1369@gmail.com        : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
29911317Sm.alian1369@gmail.com          _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
30011317Sm.alian1369@gmail.com          _extraData(0), _contextId(0), _threadId(0), _pc(0),
30111533Sm.alian1369@gmail.com          translateDelta(0), accessDelta(0), depth(0)
30211533Sm.alian1369@gmail.com    {}
30311317Sm.alian1369@gmail.com
30411533Sm.alian1369@gmail.com    /**
30511533Sm.alian1369@gmail.com     * Constructor for physical (e.g. device) requests.  Initializes
30611533Sm.alian1369@gmail.com     * just physical address, size, flags, and timestamp (to curTick()).
30711533Sm.alian1369@gmail.com     * These fields are adequate to perform a request.
30811533Sm.alian1369@gmail.com     */
30911533Sm.alian1369@gmail.com    Request(Addr paddr, unsigned size, Flags flags, MasterID mid)
31011533Sm.alian1369@gmail.com        : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
31111533Sm.alian1369@gmail.com          _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
31211533Sm.alian1369@gmail.com          _extraData(0), _contextId(0), _threadId(0), _pc(0),
31311533Sm.alian1369@gmail.com          translateDelta(0), accessDelta(0), depth(0)
31411533Sm.alian1369@gmail.com    {
31511533Sm.alian1369@gmail.com        setPhys(paddr, size, flags, mid, curTick());
31611533Sm.alian1369@gmail.com    }
31711533Sm.alian1369@gmail.com
31811533Sm.alian1369@gmail.com    Request(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time)
31911533Sm.alian1369@gmail.com        : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
32011533Sm.alian1369@gmail.com          _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
32111533Sm.alian1369@gmail.com          _extraData(0), _contextId(0), _threadId(0), _pc(0),
32211533Sm.alian1369@gmail.com          translateDelta(0), accessDelta(0), depth(0)
32311533Sm.alian1369@gmail.com    {
32411533Sm.alian1369@gmail.com        setPhys(paddr, size, flags, mid, time);
32511533Sm.alian1369@gmail.com    }
32611533Sm.alian1369@gmail.com
32711533Sm.alian1369@gmail.com    Request(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time,
32811533Sm.alian1369@gmail.com            Addr pc)
32911533Sm.alian1369@gmail.com        : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
33011533Sm.alian1369@gmail.com          _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
33111533Sm.alian1369@gmail.com          _extraData(0), _contextId(0), _threadId(0), _pc(0),
33211533Sm.alian1369@gmail.com          translateDelta(0), accessDelta(0), depth(0)
33311533Sm.alian1369@gmail.com    {
33411533Sm.alian1369@gmail.com        setPhys(paddr, size, flags, mid, time);
33511533Sm.alian1369@gmail.com        privateFlags.set(VALID_PC);
33611533Sm.alian1369@gmail.com        _pc = pc;
33711533Sm.alian1369@gmail.com    }
33811533Sm.alian1369@gmail.com
33911533Sm.alian1369@gmail.com    Request(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid,
34011533Sm.alian1369@gmail.com            Addr pc, int cid, ThreadID tid)
34111533Sm.alian1369@gmail.com        : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
34211533Sm.alian1369@gmail.com          _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
34311533Sm.alian1369@gmail.com          _extraData(0), _contextId(0), _threadId(0), _pc(0),
34411533Sm.alian1369@gmail.com          translateDelta(0), accessDelta(0), depth(0)
34511533Sm.alian1369@gmail.com    {
34611533Sm.alian1369@gmail.com        setVirt(asid, vaddr, size, flags, mid, pc);
34711533Sm.alian1369@gmail.com        setThreadContext(cid, tid);
34811533Sm.alian1369@gmail.com    }
34911533Sm.alian1369@gmail.com
35011533Sm.alian1369@gmail.com    ~Request() {}
35111317Sm.alian1369@gmail.com
35211317Sm.alian1369@gmail.com    /**
35311317Sm.alian1369@gmail.com     * Set up CPU and thread numbers.
35411317Sm.alian1369@gmail.com     */
35511317Sm.alian1369@gmail.com    void
35611317Sm.alian1369@gmail.com    setThreadContext(int context_id, ThreadID tid)
35711317Sm.alian1369@gmail.com    {
358        _contextId = context_id;
359        _threadId = tid;
360        privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
361    }
362
363    /**
364     * Set up a virtual (e.g., CPU) request in a previously
365     * allocated Request object.
366     */
367    void
368    setVirt(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid,
369            Addr pc)
370    {
371        _asid = asid;
372        _vaddr = vaddr;
373        _size = size;
374        _masterId = mid;
375        _pc = pc;
376        _time = curTick();
377
378        _flags.clear(~STICKY_FLAGS);
379        _flags.set(flags);
380        privateFlags.clear(~STICKY_PRIVATE_FLAGS);
381        privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
382        depth = 0;
383        accessDelta = 0;
384        translateDelta = 0;
385    }
386
387    /**
388     * Set just the physical address.  This usually used to record the
389     * result of a translation. However, when using virtualized CPUs
390     * setPhys() is sometimes called to finalize a physical address
391     * without a virtual address, so we can't check if the virtual
392     * address is valid.
393     */
394    void
395    setPaddr(Addr paddr)
396    {
397        _paddr = paddr;
398        privateFlags.set(VALID_PADDR);
399    }
400
401    /**
402     * Generate two requests as if this request had been split into two
403     * pieces. The original request can't have been translated already.
404     */
405    void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
406    {
407        assert(privateFlags.isSet(VALID_VADDR));
408        assert(privateFlags.noneSet(VALID_PADDR));
409        assert(split_addr > _vaddr && split_addr < _vaddr + _size);
410        req1 = new Request(*this);
411        req2 = new Request(*this);
412        req1->_size = split_addr - _vaddr;
413        req2->_vaddr = split_addr;
414        req2->_size = _size - req1->_size;
415    }
416
417    /**
418     * Accessor for paddr.
419     */
420    bool
421    hasPaddr() const
422    {
423        return privateFlags.isSet(VALID_PADDR);
424    }
425
426    Addr
427    getPaddr() const
428    {
429        assert(privateFlags.isSet(VALID_PADDR));
430        return _paddr;
431    }
432
433    /**
434     * Time for the TLB/table walker to successfully translate this request.
435     */
436    Tick translateDelta;
437
438    /**
439     * Access latency to complete this memory transaction not including
440     * translation time.
441     */
442    Tick accessDelta;
443
444    /**
445     * Level of the cache hierachy where this request was responded to
446     * (e.g. 0 = L1; 1 = L2).
447     */
448    mutable int depth;
449
450    /**
451     *  Accessor for size.
452     */
453    bool
454    hasSize() const
455    {
456        return privateFlags.isSet(VALID_SIZE);
457    }
458
459    unsigned
460    getSize() const
461    {
462        assert(privateFlags.isSet(VALID_SIZE));
463        return _size;
464    }
465
466    /** Accessor for time. */
467    Tick
468    time() const
469    {
470        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
471        return _time;
472    }
473
474    /** Accessor for flags. */
475    Flags
476    getFlags()
477    {
478        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
479        return _flags;
480    }
481
482    /** Note that unlike other accessors, this function sets *specific
483       flags* (ORs them in); it does not assign its argument to the
484       _flags field.  Thus this method should rightly be called
485       setFlags() and not just flags(). */
486    void
487    setFlags(Flags flags)
488    {
489        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
490        _flags.set(flags);
491    }
492
493    /** Accessor function for vaddr.*/
494    bool
495    hasVaddr() const
496    {
497        return privateFlags.isSet(VALID_VADDR);
498    }
499
500    Addr
501    getVaddr() const
502    {
503        assert(privateFlags.isSet(VALID_VADDR));
504        return _vaddr;
505    }
506
507    /** Accesssor for the requestor id. */
508    MasterID
509    masterId() const
510    {
511        return _masterId;
512    }
513
514    uint32_t
515    taskId() const
516    {
517        return _taskId;
518    }
519
520    void
521    taskId(uint32_t id) {
522        _taskId = id;
523    }
524
525    /** Accessor function for asid.*/
526    int
527    getAsid() const
528    {
529        assert(privateFlags.isSet(VALID_VADDR));
530        return _asid;
531    }
532
533    /** Accessor function for asid.*/
534    void
535    setAsid(int asid)
536    {
537        _asid = asid;
538    }
539
540    /** Accessor function for architecture-specific flags.*/
541    ArchFlagsType
542    getArchFlags() const
543    {
544        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
545        return _flags & ARCH_BITS;
546    }
547
548    /** Accessor function to check if sc result is valid. */
549    bool
550    extraDataValid() const
551    {
552        return privateFlags.isSet(VALID_EXTRA_DATA);
553    }
554
555    /** Accessor function for store conditional return value.*/
556    uint64_t
557    getExtraData() const
558    {
559        assert(privateFlags.isSet(VALID_EXTRA_DATA));
560        return _extraData;
561    }
562
563    /** Accessor function for store conditional return value.*/
564    void
565    setExtraData(uint64_t extraData)
566    {
567        _extraData = extraData;
568        privateFlags.set(VALID_EXTRA_DATA);
569    }
570
571    bool
572    hasContextId() const
573    {
574        return privateFlags.isSet(VALID_CONTEXT_ID);
575    }
576
577    /** Accessor function for context ID.*/
578    int
579    contextId() const
580    {
581        assert(privateFlags.isSet(VALID_CONTEXT_ID));
582        return _contextId;
583    }
584
585    /** Accessor function for thread ID. */
586    ThreadID
587    threadId() const
588    {
589        assert(privateFlags.isSet(VALID_THREAD_ID));
590        return _threadId;
591    }
592
593    void
594    setPC(Addr pc)
595    {
596        privateFlags.set(VALID_PC);
597        _pc = pc;
598    }
599
600    bool
601    hasPC() const
602    {
603        return privateFlags.isSet(VALID_PC);
604    }
605
606    /** Accessor function for pc.*/
607    Addr
608    getPC() const
609    {
610        assert(privateFlags.isSet(VALID_PC));
611        return _pc;
612    }
613
614    /**
615     * Increment/Get the depth at which this request is responded to.
616     * This currently happens when the request misses in any cache level.
617     */
618    void incAccessDepth() const { depth++; }
619    int getAccessDepth() const { return depth; }
620
621    /**
622     * Set/Get the time taken for this request to be successfully translated.
623     */
624    void setTranslateLatency() { translateDelta = curTick() - _time; }
625    Tick getTranslateLatency() const { return translateDelta; }
626
627    /**
628     * Set/Get the time taken to complete this request's access, not including
629     *  the time to successfully translate the request.
630     */
631    void setAccessLatency() { accessDelta = curTick() - _time - translateDelta; }
632    Tick getAccessLatency() const { return accessDelta; }
633
634    /** Accessor functions for flags.  Note that these are for testing
635       only; setting flags should be done via setFlags(). */
636    bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
637    bool isStrictlyOrdered() const { return _flags.isSet(STRICT_ORDER); }
638    bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
639    bool isPrefetch() const { return _flags.isSet(PREFETCH); }
640    bool isLLSC() const { return _flags.isSet(LLSC); }
641    bool isPriv() const { return _flags.isSet(PRIVILEGED); }
642    bool isLockedRMW() const { return _flags.isSet(LOCKED_RMW); }
643    bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
644    bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
645    bool isMmappedIpr() const { return _flags.isSet(MMAPPED_IPR); }
646    bool isClearLL() const { return _flags.isSet(CLEAR_LL); }
647    bool isSecure() const { return _flags.isSet(SECURE); }
648    bool isPTWalk() const { return _flags.isSet(PT_WALK); }
649};
650
651#endif // __MEM_REQUEST_HH__
652