packet.hh revision 11286
12381SN/A/*
210694SMarco.Balboni@ARM.com * Copyright (c) 2012-2015 ARM Limited
38949Sandreas.hansson@arm.com * All rights reserved
48949Sandreas.hansson@arm.com *
58949Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68949Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78949Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88949Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98949Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108949Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118949Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128949Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138949Sandreas.hansson@arm.com *
142592SN/A * Copyright (c) 2006 The Regents of The University of Michigan
1510975Sdavid.hashe@amd.com * Copyright (c) 2010,2015 Advanced Micro Devices, Inc.
162381SN/A * All rights reserved.
172381SN/A *
182381SN/A * Redistribution and use in source and binary forms, with or without
192381SN/A * modification, are permitted provided that the following conditions are
202381SN/A * met: redistributions of source code must retain the above copyright
212381SN/A * notice, this list of conditions and the following disclaimer;
222381SN/A * redistributions in binary form must reproduce the above copyright
232381SN/A * notice, this list of conditions and the following disclaimer in the
242381SN/A * documentation and/or other materials provided with the distribution;
252381SN/A * neither the name of the copyright holders nor the names of its
262381SN/A * contributors may be used to endorse or promote products derived from
272381SN/A * this software without specific prior written permission.
282381SN/A *
292381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402665Ssaidi@eecs.umich.edu *
412665Ssaidi@eecs.umich.edu * Authors: Ron Dreslinski
422665Ssaidi@eecs.umich.edu *          Steve Reinhardt
432665Ssaidi@eecs.umich.edu *          Ali Saidi
449031Sandreas.hansson@arm.com *          Andreas Hansson
452381SN/A */
462381SN/A
472381SN/A/**
482381SN/A * @file
492662Sstever@eecs.umich.edu * Declaration of the Packet class.
502381SN/A */
512381SN/A
522381SN/A#ifndef __MEM_PACKET_HH__
532381SN/A#define __MEM_PACKET_HH__
542381SN/A
558229Snate@binkert.org#include <bitset>
563348Sbinkertn@umich.edu#include <cassert>
573348Sbinkertn@umich.edu#include <list>
583348Sbinkertn@umich.edu
595735Snate@binkert.org#include "base/cast.hh"
604024Sbinkertn@umich.edu#include "base/compiler.hh"
615735Snate@binkert.org#include "base/flags.hh"
623940Ssaidi@eecs.umich.edu#include "base/misc.hh"
635314Sstever@gmail.com#include "base/printable.hh"
646216Snate@binkert.org#include "base/types.hh"
652392SN/A#include "mem/request.hh"
664167Sbinkertn@umich.edu#include "sim/core.hh"
672394SN/A
688737Skoansin.tan@gmail.comclass Packet;
693349Sbinkertn@umich.edutypedef Packet *PacketPtr;
702394SN/Atypedef uint8_t* PacketDataPtr;
712812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList;
722812Srdreslin@umich.edu
734022Sstever@eecs.umich.educlass MemCmd
744022Sstever@eecs.umich.edu{
755735Snate@binkert.org    friend class Packet;
765735Snate@binkert.org
774022Sstever@eecs.umich.edu  public:
785735Snate@binkert.org    /**
795735Snate@binkert.org     * List of all commands associated with a packet.
805735Snate@binkert.org     */
814022Sstever@eecs.umich.edu    enum Command
824022Sstever@eecs.umich.edu    {
834022Sstever@eecs.umich.edu        InvalidCmd,
844022Sstever@eecs.umich.edu        ReadReq,
854473Sstever@eecs.umich.edu        ReadResp,
865319Sstever@gmail.com        ReadRespWithInvalidate,
874022Sstever@eecs.umich.edu        WriteReq,
884022Sstever@eecs.umich.edu        WriteResp,
8911199Sandreas.hansson@arm.com        WritebackDirty,
9011199Sandreas.hansson@arm.com        WritebackClean,
9110883Sali.jafri@arm.com        CleanEvict,
924022Sstever@eecs.umich.edu        SoftPFReq,
934022Sstever@eecs.umich.edu        HardPFReq,
944022Sstever@eecs.umich.edu        SoftPFResp,
954022Sstever@eecs.umich.edu        HardPFResp,
9610886Sandreas.hansson@arm.com        WriteLineReq,
974022Sstever@eecs.umich.edu        UpgradeReq,
987465Ssteve.reinhardt@amd.com        SCUpgradeReq,           // Special "weak" upgrade for StoreCond
994628Sstever@eecs.umich.edu        UpgradeResp,
1007465Ssteve.reinhardt@amd.com        SCUpgradeFailReq,       // Failed SCUpgradeReq in MSHR (never sent)
1017465Ssteve.reinhardt@amd.com        UpgradeFailResp,        // Valid for SCUpgradeReq only
1024022Sstever@eecs.umich.edu        ReadExReq,
1034022Sstever@eecs.umich.edu        ReadExResp,
10410885Sandreas.hansson@arm.com        ReadCleanReq,
10510885Sandreas.hansson@arm.com        ReadSharedReq,
1064626Sstever@eecs.umich.edu        LoadLockedReq,
1074626Sstever@eecs.umich.edu        StoreCondReq,
1087669Ssteve.reinhardt@amd.com        StoreCondFailReq,       // Failed StoreCondReq in MSHR (never sent)
1094626Sstever@eecs.umich.edu        StoreCondResp,
1104040Ssaidi@eecs.umich.edu        SwapReq,
1114040Ssaidi@eecs.umich.edu        SwapResp,
1125650Sgblack@eecs.umich.edu        MessageReq,
1135650Sgblack@eecs.umich.edu        MessageResp,
11411256Santhony.gutierrez@amd.com        MemFenceReq,
11511256Santhony.gutierrez@amd.com        MemFenceResp,
1164870Sstever@eecs.umich.edu        // Error responses
1174870Sstever@eecs.umich.edu        // @TODO these should be classified as responses rather than
1184870Sstever@eecs.umich.edu        // requests; coding them as requests initially for backwards
1194870Sstever@eecs.umich.edu        // compatibility
1204870Sstever@eecs.umich.edu        InvalidDestError,  // packet dest field invalid
1214870Sstever@eecs.umich.edu        BadAddressError,   // memory address invalid
1228436SBrad.Beckmann@amd.com        FunctionalReadError, // unable to fulfill functional read
1238436SBrad.Beckmann@amd.com        FunctionalWriteError, // unable to fulfill functional write
1245314Sstever@gmail.com        // Fake simulator-only commands
1255314Sstever@gmail.com        PrintReq,       // Print state matching address
1268184Ssomayeh@cs.wisc.edu        FlushReq,      //request for a cache flush
12710886Sandreas.hansson@arm.com        InvalidateReq,   // request for address to be invalidated
12810886Sandreas.hansson@arm.com        InvalidateResp,
1294022Sstever@eecs.umich.edu        NUM_MEM_CMDS
1304022Sstever@eecs.umich.edu    };
1314022Sstever@eecs.umich.edu
1324022Sstever@eecs.umich.edu  private:
1335735Snate@binkert.org    /**
1345735Snate@binkert.org     * List of command attributes.
1355735Snate@binkert.org     */
1364022Sstever@eecs.umich.edu    enum Attribute
1374022Sstever@eecs.umich.edu    {
1384626Sstever@eecs.umich.edu        IsRead,         //!< Data flows from responder to requester
1394626Sstever@eecs.umich.edu        IsWrite,        //!< Data flows from requester to responder
1407465Ssteve.reinhardt@amd.com        IsUpgrade,
1414022Sstever@eecs.umich.edu        IsInvalidate,
14211284Sandreas.hansson@arm.com        NeedsWritable,  //!< Requires writable copy to complete in-cache
1434626Sstever@eecs.umich.edu        IsRequest,      //!< Issued by requester
1444626Sstever@eecs.umich.edu        IsResponse,     //!< Issue by responder
1454626Sstever@eecs.umich.edu        NeedsResponse,  //!< Requester needs response from target
14611199Sandreas.hansson@arm.com        IsEviction,
1474022Sstever@eecs.umich.edu        IsSWPrefetch,
1484022Sstever@eecs.umich.edu        IsHWPrefetch,
1496076Sgblack@eecs.umich.edu        IsLlsc,         //!< Alpha/MIPS LL or SC access
1504626Sstever@eecs.umich.edu        HasData,        //!< There is an associated payload
1514870Sstever@eecs.umich.edu        IsError,        //!< Error response
1525314Sstever@gmail.com        IsPrint,        //!< Print state matching address (for debugging)
1538184Ssomayeh@cs.wisc.edu        IsFlush,        //!< Flush the address from caches
1544022Sstever@eecs.umich.edu        NUM_COMMAND_ATTRIBUTES
1554022Sstever@eecs.umich.edu    };
1564022Sstever@eecs.umich.edu
1575735Snate@binkert.org    /**
1585735Snate@binkert.org     * Structure that defines attributes and other data associated
1595735Snate@binkert.org     * with a Command.
1605735Snate@binkert.org     */
1615735Snate@binkert.org    struct CommandInfo
1625735Snate@binkert.org    {
1635735Snate@binkert.org        /// Set of attribute flags.
1644022Sstever@eecs.umich.edu        const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
1655735Snate@binkert.org        /// Corresponding response for requests; InvalidCmd if no
1665735Snate@binkert.org        /// response is applicable.
1674022Sstever@eecs.umich.edu        const Command response;
1685735Snate@binkert.org        /// String representation (for printing)
1694022Sstever@eecs.umich.edu        const std::string str;
1704022Sstever@eecs.umich.edu    };
1714022Sstever@eecs.umich.edu
1725735Snate@binkert.org    /// Array to map Command enum to associated info.
1734022Sstever@eecs.umich.edu    static const CommandInfo commandInfo[];
1744022Sstever@eecs.umich.edu
1754022Sstever@eecs.umich.edu  private:
1764022Sstever@eecs.umich.edu
1774022Sstever@eecs.umich.edu    Command cmd;
1784022Sstever@eecs.umich.edu
1795735Snate@binkert.org    bool
1805735Snate@binkert.org    testCmdAttrib(MemCmd::Attribute attrib) const
1815735Snate@binkert.org    {
1824022Sstever@eecs.umich.edu        return commandInfo[cmd].attributes[attrib] != 0;
1834022Sstever@eecs.umich.edu    }
1844022Sstever@eecs.umich.edu
1854022Sstever@eecs.umich.edu  public:
1864022Sstever@eecs.umich.edu
18710583SCurtis.Dunham@arm.com    bool isRead() const            { return testCmdAttrib(IsRead); }
18810583SCurtis.Dunham@arm.com    bool isWrite() const           { return testCmdAttrib(IsWrite); }
18910583SCurtis.Dunham@arm.com    bool isUpgrade() const         { return testCmdAttrib(IsUpgrade); }
19010583SCurtis.Dunham@arm.com    bool isRequest() const         { return testCmdAttrib(IsRequest); }
19110583SCurtis.Dunham@arm.com    bool isResponse() const        { return testCmdAttrib(IsResponse); }
19211284Sandreas.hansson@arm.com    bool needsWritable() const     { return testCmdAttrib(NeedsWritable); }
19310583SCurtis.Dunham@arm.com    bool needsResponse() const     { return testCmdAttrib(NeedsResponse); }
19410583SCurtis.Dunham@arm.com    bool isInvalidate() const      { return testCmdAttrib(IsInvalidate); }
19511199Sandreas.hansson@arm.com    bool isEviction() const        { return testCmdAttrib(IsEviction); }
19611199Sandreas.hansson@arm.com
19711199Sandreas.hansson@arm.com    /**
19811199Sandreas.hansson@arm.com     * A writeback is an eviction that carries data.
19911199Sandreas.hansson@arm.com     */
20011199Sandreas.hansson@arm.com    bool isWriteback() const       { return testCmdAttrib(IsEviction) &&
20111199Sandreas.hansson@arm.com                                            testCmdAttrib(HasData); }
20210570Sandreas.hansson@arm.com
20310570Sandreas.hansson@arm.com    /**
20410570Sandreas.hansson@arm.com     * Check if this particular packet type carries payload data. Note
20510570Sandreas.hansson@arm.com     * that this does not reflect if the data pointer of the packet is
20610570Sandreas.hansson@arm.com     * valid or not.
20710570Sandreas.hansson@arm.com     */
2084022Sstever@eecs.umich.edu    bool hasData() const        { return testCmdAttrib(HasData); }
2096102Sgblack@eecs.umich.edu    bool isLLSC() const         { return testCmdAttrib(IsLlsc); }
21010343SCurtis.Dunham@arm.com    bool isSWPrefetch() const   { return testCmdAttrib(IsSWPrefetch); }
21110343SCurtis.Dunham@arm.com    bool isHWPrefetch() const   { return testCmdAttrib(IsHWPrefetch); }
21210343SCurtis.Dunham@arm.com    bool isPrefetch() const     { return testCmdAttrib(IsSWPrefetch) ||
21310343SCurtis.Dunham@arm.com                                         testCmdAttrib(IsHWPrefetch); }
2144870Sstever@eecs.umich.edu    bool isError() const        { return testCmdAttrib(IsError); }
2155314Sstever@gmail.com    bool isPrint() const        { return testCmdAttrib(IsPrint); }
2168184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return testCmdAttrib(IsFlush); }
2174022Sstever@eecs.umich.edu
2185735Snate@binkert.org    const Command
2195735Snate@binkert.org    responseCommand() const
2205735Snate@binkert.org    {
2214022Sstever@eecs.umich.edu        return commandInfo[cmd].response;
2224022Sstever@eecs.umich.edu    }
2234022Sstever@eecs.umich.edu
2245735Snate@binkert.org    /// Return the string to a cmd given by idx.
2255735Snate@binkert.org    const std::string &toString() const { return commandInfo[cmd].str; }
2264022Sstever@eecs.umich.edu    int toInt() const { return (int)cmd; }
2274022Sstever@eecs.umich.edu
2285735Snate@binkert.org    MemCmd(Command _cmd) : cmd(_cmd) { }
2295735Snate@binkert.org    MemCmd(int _cmd) : cmd((Command)_cmd) { }
2305735Snate@binkert.org    MemCmd() : cmd(InvalidCmd) { }
2314022Sstever@eecs.umich.edu
2325735Snate@binkert.org    bool operator==(MemCmd c2) const { return (cmd == c2.cmd); }
2335735Snate@binkert.org    bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); }
2344022Sstever@eecs.umich.edu};
2354022Sstever@eecs.umich.edu
2362381SN/A/**
2372662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in
2382662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache).  (In contrast, a
2392662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the
2402662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several
2412662Sstever@eecs.umich.edu * different Packets along the way.)
2422381SN/A */
2439044SAli.Saidi@ARM.comclass Packet : public Printable
2442381SN/A{
2452813Srdreslin@umich.edu  public:
2465735Snate@binkert.org    typedef uint32_t FlagsType;
2475735Snate@binkert.org    typedef ::Flags<FlagsType> Flags;
2484022Sstever@eecs.umich.edu
2495735Snate@binkert.org  private:
2505735Snate@binkert.org
25110938Sandreas.hansson@arm.com    enum : FlagsType {
25210938Sandreas.hansson@arm.com        // Flags to transfer across when copying a packet
25310938Sandreas.hansson@arm.com        COPY_FLAGS             = 0x0000000F,
25410938Sandreas.hansson@arm.com
25511284Sandreas.hansson@arm.com        // Does this packet have sharers (which means it should not be
25611284Sandreas.hansson@arm.com        // considered writable) or not. See setHasSharers below.
25711284Sandreas.hansson@arm.com        HAS_SHARERS            = 0x00000001,
25811284Sandreas.hansson@arm.com
25910938Sandreas.hansson@arm.com        // Special control flags
26010938Sandreas.hansson@arm.com        /// Special timing-mode atomic snoop for multi-level coherence.
26110938Sandreas.hansson@arm.com        EXPRESS_SNOOP          = 0x00000002,
26211284Sandreas.hansson@arm.com
26311284Sandreas.hansson@arm.com        /// Allow a responding cache to inform the cache hierarchy
26411284Sandreas.hansson@arm.com        /// that it had a writable copy before responding. See
26511284Sandreas.hansson@arm.com        /// setResponderHadWritable below.
26611284Sandreas.hansson@arm.com        RESPONDER_HAD_WRITABLE = 0x00000004,
26711284Sandreas.hansson@arm.com
26811284Sandreas.hansson@arm.com        // Snoop co-ordination flag to indicate that a cache is
26911284Sandreas.hansson@arm.com        // responding to a snoop. See setCacheResponding below.
27011284Sandreas.hansson@arm.com        CACHE_RESPONDING       = 0x00000008,
27110938Sandreas.hansson@arm.com
27211057Sandreas.hansson@arm.com        /// Are the 'addr' and 'size' fields valid?
27311057Sandreas.hansson@arm.com        VALID_ADDR             = 0x00000100,
27411057Sandreas.hansson@arm.com        VALID_SIZE             = 0x00000200,
27511057Sandreas.hansson@arm.com
27610938Sandreas.hansson@arm.com        /// Is the data pointer set to a value that shouldn't be freed
27710938Sandreas.hansson@arm.com        /// when the packet is destroyed?
27810938Sandreas.hansson@arm.com        STATIC_DATA            = 0x00001000,
27910938Sandreas.hansson@arm.com        /// The data pointer points to a value that should be freed when
28010938Sandreas.hansson@arm.com        /// the packet is destroyed. The pointer is assumed to be pointing
28110938Sandreas.hansson@arm.com        /// to an array, and delete [] is consequently called
28210938Sandreas.hansson@arm.com        DYNAMIC_DATA           = 0x00002000,
28310938Sandreas.hansson@arm.com
28410938Sandreas.hansson@arm.com        /// suppress the error if this packet encounters a functional
28510938Sandreas.hansson@arm.com        /// access failure.
28610938Sandreas.hansson@arm.com        SUPPRESS_FUNC_ERROR    = 0x00008000,
28710938Sandreas.hansson@arm.com
28810938Sandreas.hansson@arm.com        // Signal block present to squash prefetch and cache evict packets
28910938Sandreas.hansson@arm.com        // through express snoop flag
29010938Sandreas.hansson@arm.com        BLOCK_CACHED          = 0x00010000
29110938Sandreas.hansson@arm.com    };
2925735Snate@binkert.org
2935735Snate@binkert.org    Flags flags;
2945735Snate@binkert.org
2955735Snate@binkert.org  public:
2964022Sstever@eecs.umich.edu    typedef MemCmd::Command Command;
2974022Sstever@eecs.umich.edu
2985735Snate@binkert.org    /// The command field of the packet.
2994870Sstever@eecs.umich.edu    MemCmd cmd;
3004870Sstever@eecs.umich.edu
3015735Snate@binkert.org    /// A pointer to the original request.
30210569Sandreas.hansson@arm.com    const RequestPtr req;
3034870Sstever@eecs.umich.edu
3042566SN/A  private:
3055735Snate@binkert.org   /**
3065735Snate@binkert.org    * A pointer to the data being transfered.  It can be differnt
3075735Snate@binkert.org    * sizes at each level of the heirarchy so it belongs in the
3085735Snate@binkert.org    * packet, not request. This may or may not be populated when a
3095735Snate@binkert.org    * responder recieves the packet. If not populated it memory should
3105735Snate@binkert.org    * be allocated.
3112566SN/A    */
3122566SN/A    PacketDataPtr data;
3132566SN/A
3145735Snate@binkert.org    /// The address of the request.  This address could be virtual or
3155735Snate@binkert.org    /// physical, depending on the system configuration.
3162381SN/A    Addr addr;
3172381SN/A
31810028SGiacomo.Gabrielli@arm.com    /// True if the request targets the secure memory space.
31910028SGiacomo.Gabrielli@arm.com    bool _isSecure;
32010028SGiacomo.Gabrielli@arm.com
3215735Snate@binkert.org    /// The size of the request or transfer.
3226227Snate@binkert.org    unsigned size;
3232381SN/A
3245735Snate@binkert.org    /**
32510723Sandreas.hansson@arm.com     * Track the bytes found that satisfy a functional read.
3268668Sgeoffrey.blake@arm.com     */
32710723Sandreas.hansson@arm.com    std::vector<bool> bytesValid;
3288668Sgeoffrey.blake@arm.com
3292641Sstever@eecs.umich.edu  public:
3302811Srdreslin@umich.edu
3319547Sandreas.hansson@arm.com    /**
33210694SMarco.Balboni@ARM.com     * The extra delay from seeing the packet until the header is
33310405Sandreas.hansson@arm.com     * transmitted. This delay is used to communicate the crossbar
33410405Sandreas.hansson@arm.com     * forwarding latency to the neighbouring object (e.g. a cache)
33510405Sandreas.hansson@arm.com     * that actually makes the packet wait. As the delay is relative,
33610405Sandreas.hansson@arm.com     * a 32-bit unsigned should be sufficient.
3379547Sandreas.hansson@arm.com     */
33810694SMarco.Balboni@ARM.com    uint32_t headerDelay;
3393218Sgblack@eecs.umich.edu
3409547Sandreas.hansson@arm.com    /**
34111127Sandreas.hansson@arm.com     * Keep track of the extra delay incurred by snooping upwards
34211127Sandreas.hansson@arm.com     * before sending a request down the memory system. This is used
34311127Sandreas.hansson@arm.com     * by the coherent crossbar to account for the additional request
34411127Sandreas.hansson@arm.com     * delay.
34511127Sandreas.hansson@arm.com     */
34611127Sandreas.hansson@arm.com    uint32_t snoopDelay;
34711127Sandreas.hansson@arm.com
34811127Sandreas.hansson@arm.com    /**
34910694SMarco.Balboni@ARM.com     * The extra pipelining delay from seeing the packet until the end of
35010694SMarco.Balboni@ARM.com     * payload is transmitted by the component that provided it (if
35110694SMarco.Balboni@ARM.com     * any). This includes the header delay. Similar to the header
35210694SMarco.Balboni@ARM.com     * delay, this is used to make up for the fact that the
35310405Sandreas.hansson@arm.com     * crossbar does not make the packet wait. As the delay is
35410405Sandreas.hansson@arm.com     * relative, a 32-bit unsigned should be sufficient.
3559547Sandreas.hansson@arm.com     */
35610694SMarco.Balboni@ARM.com    uint32_t payloadDelay;
3573218Sgblack@eecs.umich.edu
3585735Snate@binkert.org    /**
3595735Snate@binkert.org     * A virtual base opaque structure used to hold state associated
3609542Sandreas.hansson@arm.com     * with the packet (e.g., an MSHR), specific to a MemObject that
3619542Sandreas.hansson@arm.com     * sees the packet. A pointer to this state is returned in the
3629542Sandreas.hansson@arm.com     * packet's response so that the MemObject in question can quickly
3639542Sandreas.hansson@arm.com     * look up the state needed to process it. A specific subclass
3649542Sandreas.hansson@arm.com     * would be derived from this to carry state specific to a
3659542Sandreas.hansson@arm.com     * particular sending device.
3669542Sandreas.hansson@arm.com     *
3679542Sandreas.hansson@arm.com     * As multiple MemObjects may add their SenderState throughout the
3689542Sandreas.hansson@arm.com     * memory system, the SenderStates create a stack, where a
3699542Sandreas.hansson@arm.com     * MemObject can add a new Senderstate, as long as the
3709542Sandreas.hansson@arm.com     * predecessing SenderState is restored when the response comes
3719542Sandreas.hansson@arm.com     * back. For this reason, the predecessor should always be
3729542Sandreas.hansson@arm.com     * populated with the current SenderState of a packet before
3739542Sandreas.hansson@arm.com     * modifying the senderState field in the request packet.
3745735Snate@binkert.org     */
3755735Snate@binkert.org    struct SenderState
3765735Snate@binkert.org    {
3779542Sandreas.hansson@arm.com        SenderState* predecessor;
3789542Sandreas.hansson@arm.com        SenderState() : predecessor(NULL) {}
3792641Sstever@eecs.umich.edu        virtual ~SenderState() {}
3802641Sstever@eecs.umich.edu    };
3812641Sstever@eecs.umich.edu
3825315Sstever@gmail.com    /**
3835315Sstever@gmail.com     * Object used to maintain state of a PrintReq.  The senderState
3845315Sstever@gmail.com     * field of a PrintReq should always be of this type.
3855315Sstever@gmail.com     */
3869044SAli.Saidi@ARM.com    class PrintReqState : public SenderState
3875735Snate@binkert.org    {
3885735Snate@binkert.org      private:
3895735Snate@binkert.org        /**
3905735Snate@binkert.org         * An entry in the label stack.
3915735Snate@binkert.org         */
3925735Snate@binkert.org        struct LabelStackEntry
3935735Snate@binkert.org        {
3945314Sstever@gmail.com            const std::string label;
3955314Sstever@gmail.com            std::string *prefix;
3965314Sstever@gmail.com            bool labelPrinted;
3975735Snate@binkert.org            LabelStackEntry(const std::string &_label, std::string *_prefix);
3985314Sstever@gmail.com        };
3995314Sstever@gmail.com
4005314Sstever@gmail.com        typedef std::list<LabelStackEntry> LabelStack;
4015314Sstever@gmail.com        LabelStack labelStack;
4025314Sstever@gmail.com
4035314Sstever@gmail.com        std::string *curPrefixPtr;
4045314Sstever@gmail.com
4055314Sstever@gmail.com      public:
4065314Sstever@gmail.com        std::ostream &os;
4075314Sstever@gmail.com        const int verbosity;
4085314Sstever@gmail.com
4095314Sstever@gmail.com        PrintReqState(std::ostream &os, int verbosity = 0);
4105314Sstever@gmail.com        ~PrintReqState();
4115314Sstever@gmail.com
4125735Snate@binkert.org        /**
4135735Snate@binkert.org         * Returns the current line prefix.
4145735Snate@binkert.org         */
4155314Sstever@gmail.com        const std::string &curPrefix() { return *curPrefixPtr; }
4165315Sstever@gmail.com
4175735Snate@binkert.org        /**
4185735Snate@binkert.org         * Push a label onto the label stack, and prepend the given
4195315Sstever@gmail.com         * prefix string onto the current prefix.  Labels will only be
4205735Snate@binkert.org         * printed if an object within the label's scope is printed.
4215735Snate@binkert.org         */
4225314Sstever@gmail.com        void pushLabel(const std::string &lbl,
4235314Sstever@gmail.com                       const std::string &prefix = "  ");
4245735Snate@binkert.org
4255735Snate@binkert.org        /**
4265735Snate@binkert.org         * Pop a label off the label stack.
4275735Snate@binkert.org         */
4285314Sstever@gmail.com        void popLabel();
4295735Snate@binkert.org
4305735Snate@binkert.org        /**
4315735Snate@binkert.org         * Print all of the pending unprinted labels on the
4325315Sstever@gmail.com         * stack. Called by printObj(), so normally not called by
4335735Snate@binkert.org         * users unless bypassing printObj().
4345735Snate@binkert.org         */
4355314Sstever@gmail.com        void printLabels();
4365735Snate@binkert.org
4375735Snate@binkert.org        /**
4385735Snate@binkert.org         * Print a Printable object to os, because it matched the
4395735Snate@binkert.org         * address on a PrintReq.
4405735Snate@binkert.org         */
4415314Sstever@gmail.com        void printObj(Printable *obj);
4425314Sstever@gmail.com    };
4435314Sstever@gmail.com
4445735Snate@binkert.org    /**
4455735Snate@binkert.org     * This packet's sender state.  Devices should use dynamic_cast<>
4465735Snate@binkert.org     * to cast to the state appropriate to the sender.  The intent of
4475735Snate@binkert.org     * this variable is to allow a device to attach extra information
4489542Sandreas.hansson@arm.com     * to a request. A response packet must return the sender state
4495735Snate@binkert.org     * that was attached to the original request (even if a new packet
4505735Snate@binkert.org     * is created).
4515735Snate@binkert.org     */
4522662Sstever@eecs.umich.edu    SenderState *senderState;
4532641Sstever@eecs.umich.edu
4549542Sandreas.hansson@arm.com    /**
4559542Sandreas.hansson@arm.com     * Push a new sender state to the packet and make the current
4569542Sandreas.hansson@arm.com     * sender state the predecessor of the new one. This should be
4579542Sandreas.hansson@arm.com     * prefered over direct manipulation of the senderState member
4589542Sandreas.hansson@arm.com     * variable.
4599542Sandreas.hansson@arm.com     *
4609542Sandreas.hansson@arm.com     * @param sender_state SenderState to push at the top of the stack
4619542Sandreas.hansson@arm.com     */
4629542Sandreas.hansson@arm.com    void pushSenderState(SenderState *sender_state);
4639542Sandreas.hansson@arm.com
4649542Sandreas.hansson@arm.com    /**
4659542Sandreas.hansson@arm.com     * Pop the top of the state stack and return a pointer to it. This
4669542Sandreas.hansson@arm.com     * assumes the current sender state is not NULL. This should be
4679542Sandreas.hansson@arm.com     * preferred over direct manipulation of the senderState member
4689542Sandreas.hansson@arm.com     * variable.
4699542Sandreas.hansson@arm.com     *
4709542Sandreas.hansson@arm.com     * @return The current top of the stack
4719542Sandreas.hansson@arm.com     */
4729542Sandreas.hansson@arm.com    SenderState *popSenderState();
4739542Sandreas.hansson@arm.com
4749543Ssascha.bischoff@arm.com    /**
4759543Ssascha.bischoff@arm.com     * Go through the sender state stack and return the first instance
4769543Ssascha.bischoff@arm.com     * that is of type T (as determined by a dynamic_cast). If there
4779543Ssascha.bischoff@arm.com     * is no sender state of type T, NULL is returned.
4789543Ssascha.bischoff@arm.com     *
4799543Ssascha.bischoff@arm.com     * @return The topmost state of type T
4809543Ssascha.bischoff@arm.com     */
4819543Ssascha.bischoff@arm.com    template <typename T>
4829543Ssascha.bischoff@arm.com    T * findNextSenderState() const
4839543Ssascha.bischoff@arm.com    {
4849543Ssascha.bischoff@arm.com        T *t = NULL;
4859543Ssascha.bischoff@arm.com        SenderState* sender_state = senderState;
4869543Ssascha.bischoff@arm.com        while (t == NULL && sender_state != NULL) {
4879543Ssascha.bischoff@arm.com            t = dynamic_cast<T*>(sender_state);
4889543Ssascha.bischoff@arm.com            sender_state = sender_state->predecessor;
4899543Ssascha.bischoff@arm.com        }
4909543Ssascha.bischoff@arm.com        return t;
4919543Ssascha.bischoff@arm.com    }
4929543Ssascha.bischoff@arm.com
4935735Snate@binkert.org    /// Return the string name of the cmd field (for debugging and
4945735Snate@binkert.org    /// tracing).
4954022Sstever@eecs.umich.edu    const std::string &cmdString() const { return cmd.toString(); }
4962811Srdreslin@umich.edu
4975735Snate@binkert.org    /// Return the index of this command.
4984022Sstever@eecs.umich.edu    inline int cmdToIndex() const { return cmd.toInt(); }
4992811Srdreslin@umich.edu
50010583SCurtis.Dunham@arm.com    bool isRead() const              { return cmd.isRead(); }
50110583SCurtis.Dunham@arm.com    bool isWrite() const             { return cmd.isWrite(); }
50210583SCurtis.Dunham@arm.com    bool isUpgrade()  const          { return cmd.isUpgrade(); }
50310583SCurtis.Dunham@arm.com    bool isRequest() const           { return cmd.isRequest(); }
50410583SCurtis.Dunham@arm.com    bool isResponse() const          { return cmd.isResponse(); }
50511284Sandreas.hansson@arm.com    bool needsWritable() const       { return cmd.needsWritable(); }
50610583SCurtis.Dunham@arm.com    bool needsResponse() const       { return cmd.needsResponse(); }
50710583SCurtis.Dunham@arm.com    bool isInvalidate() const        { return cmd.isInvalidate(); }
50811199Sandreas.hansson@arm.com    bool isEviction() const          { return cmd.isEviction(); }
50911199Sandreas.hansson@arm.com    bool isWriteback() const         { return cmd.isWriteback(); }
51010583SCurtis.Dunham@arm.com    bool hasData() const             { return cmd.hasData(); }
51111286Sandreas.hansson@arm.com    bool hasRespData() const
51211286Sandreas.hansson@arm.com    {
51311286Sandreas.hansson@arm.com        MemCmd resp_cmd = cmd.responseCommand();
51411286Sandreas.hansson@arm.com        return resp_cmd.hasData();
51511286Sandreas.hansson@arm.com    }
51610583SCurtis.Dunham@arm.com    bool isLLSC() const              { return cmd.isLLSC(); }
51710583SCurtis.Dunham@arm.com    bool isError() const             { return cmd.isError(); }
51810583SCurtis.Dunham@arm.com    bool isPrint() const             { return cmd.isPrint(); }
51910583SCurtis.Dunham@arm.com    bool isFlush() const             { return cmd.isFlush(); }
5202812Srdreslin@umich.edu
52111284Sandreas.hansson@arm.com    //@{
52211284Sandreas.hansson@arm.com    /// Snoop flags
52311284Sandreas.hansson@arm.com    /**
52411284Sandreas.hansson@arm.com     * Set the cacheResponding flag. This is used by the caches to
52511284Sandreas.hansson@arm.com     * signal another cache that they are responding to a request. A
52611284Sandreas.hansson@arm.com     * cache will only respond to snoops if it has the line in either
52711284Sandreas.hansson@arm.com     * Modified or Owned state. Note that on snoop hits we always pass
52811284Sandreas.hansson@arm.com     * the line as Modified and never Owned. In the case of an Owned
52911284Sandreas.hansson@arm.com     * line we proceed to invalidate all other copies.
53011284Sandreas.hansson@arm.com     *
53111284Sandreas.hansson@arm.com     * On a cache fill (see Cache::handleFill), we check hasSharers
53211284Sandreas.hansson@arm.com     * first, ignoring the cacheResponding flag if hasSharers is set.
53311284Sandreas.hansson@arm.com     * A line is consequently allocated as:
53411284Sandreas.hansson@arm.com     *
53511284Sandreas.hansson@arm.com     * hasSharers cacheResponding state
53611284Sandreas.hansson@arm.com     * true       false           Shared
53711284Sandreas.hansson@arm.com     * true       true            Shared
53811284Sandreas.hansson@arm.com     * false      false           Exclusive
53911284Sandreas.hansson@arm.com     * false      true            Modified
54011284Sandreas.hansson@arm.com     */
54111284Sandreas.hansson@arm.com    void setCacheResponding()
54210567Sandreas.hansson@arm.com    {
54310567Sandreas.hansson@arm.com        assert(isRequest());
54411284Sandreas.hansson@arm.com        assert(!flags.isSet(CACHE_RESPONDING));
54511284Sandreas.hansson@arm.com        flags.set(CACHE_RESPONDING);
54610567Sandreas.hansson@arm.com    }
54711284Sandreas.hansson@arm.com    bool cacheResponding() const { return flags.isSet(CACHE_RESPONDING); }
54811284Sandreas.hansson@arm.com    /**
54911284Sandreas.hansson@arm.com     * On fills, the hasSharers flag is used by the caches in
55011284Sandreas.hansson@arm.com     * combination with the cacheResponding flag, as clarified
55111284Sandreas.hansson@arm.com     * above. If the hasSharers flag is not set, the packet is passing
55211284Sandreas.hansson@arm.com     * writable. Thus, a response from a memory passes the line as
55311284Sandreas.hansson@arm.com     * writable by default.
55411284Sandreas.hansson@arm.com     *
55511284Sandreas.hansson@arm.com     * The hasSharers flag is also used by upstream caches to inform a
55611284Sandreas.hansson@arm.com     * downstream cache that they have the block (by calling
55711284Sandreas.hansson@arm.com     * setHasSharers on snoop request packets that hit in upstream
55811284Sandreas.hansson@arm.com     * cachs tags or MSHRs). If the snoop packet has sharers, a
55911284Sandreas.hansson@arm.com     * downstream cache is prevented from passing a dirty line upwards
56011284Sandreas.hansson@arm.com     * if it was not explicitly asked for a writable copy. See
56111284Sandreas.hansson@arm.com     * Cache::satisfyCpuSideRequest.
56211284Sandreas.hansson@arm.com     *
56311284Sandreas.hansson@arm.com     * The hasSharers flag is also used on writebacks, in
56411284Sandreas.hansson@arm.com     * combination with the WritbackClean or WritebackDirty commands,
56511284Sandreas.hansson@arm.com     * to allocate the block downstream either as:
56611284Sandreas.hansson@arm.com     *
56711284Sandreas.hansson@arm.com     * command        hasSharers state
56811284Sandreas.hansson@arm.com     * WritebackDirty false      Modified
56911284Sandreas.hansson@arm.com     * WritebackDirty true       Owned
57011284Sandreas.hansson@arm.com     * WritebackClean false      Exclusive
57111284Sandreas.hansson@arm.com     * WritebackClean true       Shared
57211284Sandreas.hansson@arm.com     */
57311284Sandreas.hansson@arm.com    void setHasSharers()    { flags.set(HAS_SHARERS); }
57411284Sandreas.hansson@arm.com    bool hasSharers() const { return flags.isSet(HAS_SHARERS); }
57511284Sandreas.hansson@arm.com    //@}
5764870Sstever@eecs.umich.edu
57711284Sandreas.hansson@arm.com    /**
57811284Sandreas.hansson@arm.com     * The express snoop flag is used for two purposes. Firstly, it is
57911284Sandreas.hansson@arm.com     * used to bypass flow control for normal (non-snoop) requests
58011284Sandreas.hansson@arm.com     * going downstream in the memory system. In cases where a cache
58111284Sandreas.hansson@arm.com     * is responding to a snoop from another cache (it had a dirty
58211284Sandreas.hansson@arm.com     * line), but the line is not writable (and there are possibly
58311284Sandreas.hansson@arm.com     * other copies), the express snoop flag is set by the downstream
58411284Sandreas.hansson@arm.com     * cache to invalidate all other copies in zero time. Secondly,
58511284Sandreas.hansson@arm.com     * the express snoop flag is also set to be able to distinguish
58611284Sandreas.hansson@arm.com     * snoop packets that came from a downstream cache, rather than
58711284Sandreas.hansson@arm.com     * snoop packets from neighbouring caches.
58811284Sandreas.hansson@arm.com     */
58911284Sandreas.hansson@arm.com    void setExpressSnoop()      { flags.set(EXPRESS_SNOOP); }
59011284Sandreas.hansson@arm.com    bool isExpressSnoop() const { return flags.isSet(EXPRESS_SNOOP); }
59111284Sandreas.hansson@arm.com
59211284Sandreas.hansson@arm.com    /**
59311284Sandreas.hansson@arm.com     * On responding to a snoop request (which only happens for
59411284Sandreas.hansson@arm.com     * Modified or Owned lines), make sure that we can transform an
59511284Sandreas.hansson@arm.com     * Owned response to a Modified one. If this flag is not set, the
59611284Sandreas.hansson@arm.com     * responding cache had the line in the Owned state, and there are
59711284Sandreas.hansson@arm.com     * possibly other Shared copies in the memory system. A downstream
59811284Sandreas.hansson@arm.com     * cache helps in orchestrating the invalidation of these copies
59911284Sandreas.hansson@arm.com     * by sending out the appropriate express snoops.
60011284Sandreas.hansson@arm.com     */
60111284Sandreas.hansson@arm.com    void setResponderHadWritable()
60211284Sandreas.hansson@arm.com    {
60311284Sandreas.hansson@arm.com        assert(cacheResponding());
60411284Sandreas.hansson@arm.com        flags.set(RESPONDER_HAD_WRITABLE);
60511284Sandreas.hansson@arm.com    }
60611284Sandreas.hansson@arm.com    bool responderHadWritable() const
60711284Sandreas.hansson@arm.com    { return flags.isSet(RESPONDER_HAD_WRITABLE); }
60811284Sandreas.hansson@arm.com
6099951Sstephan.diestelhorst@arm.com    void setSuppressFuncError()     { flags.set(SUPPRESS_FUNC_ERROR); }
6109951Sstephan.diestelhorst@arm.com    bool suppressFuncError() const  { return flags.isSet(SUPPRESS_FUNC_ERROR); }
61110763Sali.jafri@arm.com    void setBlockCached()          { flags.set(BLOCK_CACHED); }
61210763Sali.jafri@arm.com    bool isBlockCached() const     { return flags.isSet(BLOCK_CACHED); }
61310883Sali.jafri@arm.com    void clearBlockCached()        { flags.clear(BLOCK_CACHED); }
6144895Sstever@eecs.umich.edu
6154870Sstever@eecs.umich.edu    // Network error conditions... encapsulate them as methods since
6164870Sstever@eecs.umich.edu    // their encoding keeps changing (from result field to command
6174870Sstever@eecs.umich.edu    // field, etc.)
6185735Snate@binkert.org    void
6195735Snate@binkert.org    setBadAddress()
6205735Snate@binkert.org    {
6215735Snate@binkert.org        assert(isResponse());
6225735Snate@binkert.org        cmd = MemCmd::BadAddressError;
6235735Snate@binkert.org    }
6245735Snate@binkert.org
6254986Ssaidi@eecs.umich.edu    void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
6262814Srdreslin@umich.edu
62711057Sandreas.hansson@arm.com    Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; }
6289259SAli.Saidi@ARM.com    /**
6299259SAli.Saidi@ARM.com     * Update the address of this packet mid-transaction. This is used
6309259SAli.Saidi@ARM.com     * by the address mapper to change an already set address to a new
6319259SAli.Saidi@ARM.com     * one based on the system configuration. It is intended to remap
6329259SAli.Saidi@ARM.com     * an existing address, so it asserts that the current address is
6339259SAli.Saidi@ARM.com     * valid.
6349259SAli.Saidi@ARM.com     */
63511057Sandreas.hansson@arm.com    void setAddr(Addr _addr) { assert(flags.isSet(VALID_ADDR)); addr = _addr; }
6369259SAli.Saidi@ARM.com
63711057Sandreas.hansson@arm.com    unsigned getSize() const  { assert(flags.isSet(VALID_SIZE)); return size; }
63810938Sandreas.hansson@arm.com
63910938Sandreas.hansson@arm.com    Addr getOffset(unsigned int blk_size) const
64010938Sandreas.hansson@arm.com    {
64110938Sandreas.hansson@arm.com        return getAddr() & Addr(blk_size - 1);
64210938Sandreas.hansson@arm.com    }
64310938Sandreas.hansson@arm.com
64410938Sandreas.hansson@arm.com    Addr getBlockAddr(unsigned int blk_size) const
64510938Sandreas.hansson@arm.com    {
64610938Sandreas.hansson@arm.com        return getAddr() & ~(Addr(blk_size - 1));
64710938Sandreas.hansson@arm.com    }
6482549SN/A
64911057Sandreas.hansson@arm.com    bool isSecure() const
65011057Sandreas.hansson@arm.com    {
65111057Sandreas.hansson@arm.com        assert(flags.isSet(VALID_ADDR));
65211057Sandreas.hansson@arm.com        return _isSecure;
65311057Sandreas.hansson@arm.com    }
65410028SGiacomo.Gabrielli@arm.com
6555735Snate@binkert.org    /**
6567550SBrad.Beckmann@amd.com     * It has been determined that the SC packet should successfully update
65710938Sandreas.hansson@arm.com     * memory. Therefore, convert this SC packet to a normal write.
6587550SBrad.Beckmann@amd.com     */
6597550SBrad.Beckmann@amd.com    void
6607550SBrad.Beckmann@amd.com    convertScToWrite()
6617550SBrad.Beckmann@amd.com    {
6627550SBrad.Beckmann@amd.com        assert(isLLSC());
6637550SBrad.Beckmann@amd.com        assert(isWrite());
6647550SBrad.Beckmann@amd.com        cmd = MemCmd::WriteReq;
6657550SBrad.Beckmann@amd.com    }
6667550SBrad.Beckmann@amd.com
6677550SBrad.Beckmann@amd.com    /**
66810938Sandreas.hansson@arm.com     * When ruby is in use, Ruby will monitor the cache line and the
66910938Sandreas.hansson@arm.com     * phys memory should treat LL ops as normal reads.
6707550SBrad.Beckmann@amd.com     */
6717550SBrad.Beckmann@amd.com    void
6727550SBrad.Beckmann@amd.com    convertLlToRead()
6737550SBrad.Beckmann@amd.com    {
6747550SBrad.Beckmann@amd.com        assert(isLLSC());
6757550SBrad.Beckmann@amd.com        assert(isRead());
6767550SBrad.Beckmann@amd.com        cmd = MemCmd::ReadReq;
6777550SBrad.Beckmann@amd.com    }
6787550SBrad.Beckmann@amd.com
6797550SBrad.Beckmann@amd.com    /**
68010938Sandreas.hansson@arm.com     * Constructor. Note that a Request object must be constructed
68111057Sandreas.hansson@arm.com     * first, but the Requests's physical address and size fields need
68211057Sandreas.hansson@arm.com     * not be valid. The command must be supplied.
6835735Snate@binkert.org     */
68410569Sandreas.hansson@arm.com    Packet(const RequestPtr _req, MemCmd _cmd)
68511057Sandreas.hansson@arm.com        :  cmd(_cmd), req(_req), data(nullptr), addr(0), _isSecure(false),
68611127Sandreas.hansson@arm.com           size(0), headerDelay(0), snoopDelay(0), payloadDelay(0),
68711057Sandreas.hansson@arm.com           senderState(NULL)
68811057Sandreas.hansson@arm.com    {
68911057Sandreas.hansson@arm.com        if (req->hasPaddr()) {
69011057Sandreas.hansson@arm.com            addr = req->getPaddr();
69111057Sandreas.hansson@arm.com            flags.set(VALID_ADDR);
69211057Sandreas.hansson@arm.com            _isSecure = req->isSecure();
69311057Sandreas.hansson@arm.com        }
69411057Sandreas.hansson@arm.com        if (req->hasSize()) {
69511057Sandreas.hansson@arm.com            size = req->getSize();
69611057Sandreas.hansson@arm.com            flags.set(VALID_SIZE);
69711057Sandreas.hansson@arm.com        }
69811057Sandreas.hansson@arm.com    }
69911057Sandreas.hansson@arm.com
70011057Sandreas.hansson@arm.com    /**
70111057Sandreas.hansson@arm.com     * Alternate constructor if you are trying to create a packet with
70211057Sandreas.hansson@arm.com     * a request that is for a whole block, not the address from the
70311057Sandreas.hansson@arm.com     * req.  this allows for overriding the size/addr of the req.
70411057Sandreas.hansson@arm.com     */
70511057Sandreas.hansson@arm.com    Packet(const RequestPtr _req, MemCmd _cmd, int _blkSize)
70611057Sandreas.hansson@arm.com        :  cmd(_cmd), req(_req), data(nullptr), addr(0), _isSecure(false),
70711127Sandreas.hansson@arm.com           headerDelay(0), snoopDelay(0), payloadDelay(0),
7089546Sandreas.hansson@arm.com           senderState(NULL)
70911057Sandreas.hansson@arm.com    {
71011057Sandreas.hansson@arm.com        if (req->hasPaddr()) {
71111057Sandreas.hansson@arm.com            addr = req->getPaddr() & ~(_blkSize - 1);
71211057Sandreas.hansson@arm.com            flags.set(VALID_ADDR);
71311057Sandreas.hansson@arm.com            _isSecure = req->isSecure();
71411057Sandreas.hansson@arm.com        }
71511057Sandreas.hansson@arm.com        size = _blkSize;
71611057Sandreas.hansson@arm.com        flags.set(VALID_SIZE);
71711057Sandreas.hansson@arm.com    }
7184626Sstever@eecs.umich.edu
7195735Snate@binkert.org    /**
7205735Snate@binkert.org     * Alternate constructor for copying a packet.  Copy all fields
7214887Sstever@eecs.umich.edu     * *except* if the original packet's data was dynamic, don't copy
7224887Sstever@eecs.umich.edu     * that, as we can't guarantee that the new packet's lifetime is
7234887Sstever@eecs.umich.edu     * less than that of the original packet.  In this case the new
7245735Snate@binkert.org     * packet should allocate its own data.
7255735Snate@binkert.org     */
72610896Snilay@cs.wisc.edu    Packet(const PacketPtr pkt, bool clear_flags, bool alloc_data)
7275735Snate@binkert.org        :  cmd(pkt->cmd), req(pkt->req),
72810571Sandreas.hansson@arm.com           data(nullptr),
72910028SGiacomo.Gabrielli@arm.com           addr(pkt->addr), _isSecure(pkt->_isSecure), size(pkt->size),
73010723Sandreas.hansson@arm.com           bytesValid(pkt->bytesValid),
73110694SMarco.Balboni@ARM.com           headerDelay(pkt->headerDelay),
73211127Sandreas.hansson@arm.com           snoopDelay(0),
73310694SMarco.Balboni@ARM.com           payloadDelay(pkt->payloadDelay),
7349546Sandreas.hansson@arm.com           senderState(pkt->senderState)
7354626Sstever@eecs.umich.edu    {
73610571Sandreas.hansson@arm.com        if (!clear_flags)
7375735Snate@binkert.org            flags.set(pkt->flags & COPY_FLAGS);
7385735Snate@binkert.org
73911057Sandreas.hansson@arm.com        flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE));
74011057Sandreas.hansson@arm.com
74110571Sandreas.hansson@arm.com        // should we allocate space for data, or not, the express
74210571Sandreas.hansson@arm.com        // snoops do not need to carry any data as they only serve to
74310571Sandreas.hansson@arm.com        // co-ordinate state changes
74410571Sandreas.hansson@arm.com        if (alloc_data) {
74510571Sandreas.hansson@arm.com            // even if asked to allocate data, if the original packet
74610571Sandreas.hansson@arm.com            // holds static data, then the sender will not be doing
74710571Sandreas.hansson@arm.com            // any memcpy on receiving the response, thus we simply
74810571Sandreas.hansson@arm.com            // carry the pointer forward
74910571Sandreas.hansson@arm.com            if (pkt->flags.isSet(STATIC_DATA)) {
75010571Sandreas.hansson@arm.com                data = pkt->data;
75110571Sandreas.hansson@arm.com                flags.set(STATIC_DATA);
75210571Sandreas.hansson@arm.com            } else {
75310571Sandreas.hansson@arm.com                allocate();
75410571Sandreas.hansson@arm.com            }
75510571Sandreas.hansson@arm.com        }
75610342SCurtis.Dunham@arm.com    }
7578668Sgeoffrey.blake@arm.com
75810342SCurtis.Dunham@arm.com    /**
75910739Ssteve.reinhardt@amd.com     * Generate the appropriate read MemCmd based on the Request flags.
76010342SCurtis.Dunham@arm.com     */
76110739Ssteve.reinhardt@amd.com    static MemCmd
76210739Ssteve.reinhardt@amd.com    makeReadCmd(const RequestPtr req)
76310342SCurtis.Dunham@arm.com    {
76410739Ssteve.reinhardt@amd.com        if (req->isLLSC())
76510739Ssteve.reinhardt@amd.com            return MemCmd::LoadLockedReq;
76610739Ssteve.reinhardt@amd.com        else if (req->isPrefetch())
76710739Ssteve.reinhardt@amd.com            return MemCmd::SoftPFReq;
76810739Ssteve.reinhardt@amd.com        else
76910739Ssteve.reinhardt@amd.com            return MemCmd::ReadReq;
77010739Ssteve.reinhardt@amd.com    }
77110739Ssteve.reinhardt@amd.com
77210739Ssteve.reinhardt@amd.com    /**
77310739Ssteve.reinhardt@amd.com     * Generate the appropriate write MemCmd based on the Request flags.
77410739Ssteve.reinhardt@amd.com     */
77510739Ssteve.reinhardt@amd.com    static MemCmd
77610739Ssteve.reinhardt@amd.com    makeWriteCmd(const RequestPtr req)
77710739Ssteve.reinhardt@amd.com    {
77810739Ssteve.reinhardt@amd.com        if (req->isLLSC())
77910739Ssteve.reinhardt@amd.com            return MemCmd::StoreCondReq;
78010739Ssteve.reinhardt@amd.com        else if (req->isSwap())
78110739Ssteve.reinhardt@amd.com            return MemCmd::SwapReq;
78210739Ssteve.reinhardt@amd.com        else
78310739Ssteve.reinhardt@amd.com            return MemCmd::WriteReq;
78410342SCurtis.Dunham@arm.com    }
78510342SCurtis.Dunham@arm.com
78610342SCurtis.Dunham@arm.com    /**
78710342SCurtis.Dunham@arm.com     * Constructor-like methods that return Packets based on Request objects.
78810739Ssteve.reinhardt@amd.com     * Fine-tune the MemCmd type if it's not a vanilla read or write.
78910342SCurtis.Dunham@arm.com     */
79010342SCurtis.Dunham@arm.com    static PacketPtr
79110569Sandreas.hansson@arm.com    createRead(const RequestPtr req)
79210342SCurtis.Dunham@arm.com    {
79310739Ssteve.reinhardt@amd.com        return new Packet(req, makeReadCmd(req));
79410342SCurtis.Dunham@arm.com    }
79510342SCurtis.Dunham@arm.com
79610342SCurtis.Dunham@arm.com    static PacketPtr
79710569Sandreas.hansson@arm.com    createWrite(const RequestPtr req)
79810342SCurtis.Dunham@arm.com    {
79910739Ssteve.reinhardt@amd.com        return new Packet(req, makeWriteCmd(req));
8002641Sstever@eecs.umich.edu    }
8012549SN/A
8025735Snate@binkert.org    /**
8035735Snate@binkert.org     * clean up packet variables
8045735Snate@binkert.org     */
8052566SN/A    ~Packet()
8065387Sstever@gmail.com    {
80710872Sali.jafri@arm.com        // Delete the request object if this is a request packet which
80810872Sali.jafri@arm.com        // does not need a response, because the requester will not get
80910872Sali.jafri@arm.com        // a chance. If the request packet needs a response then the
81010872Sali.jafri@arm.com        // request will be deleted on receipt of the response
81110872Sali.jafri@arm.com        // packet. We also make sure to never delete the request for
81210872Sali.jafri@arm.com        // express snoops, even for cases when responses are not
81310872Sali.jafri@arm.com        // needed (CleanEvict and Writeback), since the snoop packet
81410872Sali.jafri@arm.com        // re-uses the same request.
81510872Sali.jafri@arm.com        if (req && isRequest() && !needsResponse() &&
81610872Sali.jafri@arm.com            !isExpressSnoop()) {
8175387Sstever@gmail.com            delete req;
81810872Sali.jafri@arm.com        }
8195735Snate@binkert.org        deleteData();
8205387Sstever@gmail.com    }
8212566SN/A
8225735Snate@binkert.org    /**
8234626Sstever@eecs.umich.edu     * Take a request packet and modify it in place to be suitable for
82410660Sandreas.hansson@arm.com     * returning as a response to that request.
8254626Sstever@eecs.umich.edu     */
8265735Snate@binkert.org    void
8275735Snate@binkert.org    makeResponse()
8284626Sstever@eecs.umich.edu    {
8292662Sstever@eecs.umich.edu        assert(needsResponse());
8302855Srdreslin@umich.edu        assert(isRequest());
8314022Sstever@eecs.umich.edu        cmd = cmd.responseCommand();
8325745Snate@binkert.org
8337464Ssteve.reinhardt@amd.com        // responses are never express, even if the snoop that
8347464Ssteve.reinhardt@amd.com        // triggered them was
8357464Ssteve.reinhardt@amd.com        flags.clear(EXPRESS_SNOOP);
8362641Sstever@eecs.umich.edu    }
8372641Sstever@eecs.umich.edu
8385735Snate@binkert.org    void
8395735Snate@binkert.org    makeAtomicResponse()
8404870Sstever@eecs.umich.edu    {
8414870Sstever@eecs.umich.edu        makeResponse();
8424870Sstever@eecs.umich.edu    }
8434870Sstever@eecs.umich.edu
8445735Snate@binkert.org    void
8455735Snate@binkert.org    makeTimingResponse()
8463348Sbinkertn@umich.edu    {
8474870Sstever@eecs.umich.edu        makeResponse();
8483135Srdreslin@umich.edu    }
8493135Srdreslin@umich.edu
8508436SBrad.Beckmann@amd.com    void
8518436SBrad.Beckmann@amd.com    setFunctionalResponseStatus(bool success)
8528436SBrad.Beckmann@amd.com    {
8538436SBrad.Beckmann@amd.com        if (!success) {
8548436SBrad.Beckmann@amd.com            if (isWrite()) {
8558436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalWriteError;
8568436SBrad.Beckmann@amd.com            } else {
8578436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalReadError;
8588436SBrad.Beckmann@amd.com            }
8598436SBrad.Beckmann@amd.com        }
8608436SBrad.Beckmann@amd.com    }
8618436SBrad.Beckmann@amd.com
86211057Sandreas.hansson@arm.com    void
86311057Sandreas.hansson@arm.com    setSize(unsigned size)
86411057Sandreas.hansson@arm.com    {
86511057Sandreas.hansson@arm.com        assert(!flags.isSet(VALID_SIZE));
86611057Sandreas.hansson@arm.com
86711057Sandreas.hansson@arm.com        this->size = size;
86811057Sandreas.hansson@arm.com        flags.set(VALID_SIZE);
86911057Sandreas.hansson@arm.com    }
87011057Sandreas.hansson@arm.com
87111057Sandreas.hansson@arm.com
87211013Sandreas.sandberg@arm.com  public:
87311013Sandreas.sandberg@arm.com    /**
87411013Sandreas.sandberg@arm.com     * @{
87511013Sandreas.sandberg@arm.com     * @name Data accessor mehtods
87611013Sandreas.sandberg@arm.com     */
87711013Sandreas.sandberg@arm.com
8783348Sbinkertn@umich.edu    /**
8793348Sbinkertn@umich.edu     * Set the data pointer to the following value that should not be
88010571Sandreas.hansson@arm.com     * freed. Static data allows us to do a single memcpy even if
88110571Sandreas.hansson@arm.com     * multiple packets are required to get from source to destination
88210571Sandreas.hansson@arm.com     * and back. In essence the pointer is set calling dataStatic on
88310571Sandreas.hansson@arm.com     * the original packet, and whenever this packet is copied and
88410571Sandreas.hansson@arm.com     * forwarded the same pointer is passed on. When a packet
88510571Sandreas.hansson@arm.com     * eventually reaches the destination holding the data, it is
88610571Sandreas.hansson@arm.com     * copied once into the location originally set. On the way back
88710571Sandreas.hansson@arm.com     * to the source, no copies are necessary.
8882566SN/A     */
8892566SN/A    template <typename T>
8903348Sbinkertn@umich.edu    void
8913348Sbinkertn@umich.edu    dataStatic(T *p)
8923348Sbinkertn@umich.edu    {
89310566Sandreas.hansson@arm.com        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
8943348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
8955735Snate@binkert.org        flags.set(STATIC_DATA);
8963348Sbinkertn@umich.edu    }
8972566SN/A
8983348Sbinkertn@umich.edu    /**
89910564Sandreas.hansson@arm.com     * Set the data pointer to the following value that should not be
90010564Sandreas.hansson@arm.com     * freed. This version of the function allows the pointer passed
90110564Sandreas.hansson@arm.com     * to us to be const. To avoid issues down the line we cast the
90210564Sandreas.hansson@arm.com     * constness away, the alternative would be to keep both a const
90310564Sandreas.hansson@arm.com     * and non-const data pointer and cleverly choose between
90410564Sandreas.hansson@arm.com     * them. Note that this is only allowed for static data.
90510564Sandreas.hansson@arm.com     */
90610564Sandreas.hansson@arm.com    template <typename T>
90710564Sandreas.hansson@arm.com    void
90810564Sandreas.hansson@arm.com    dataStaticConst(const T *p)
90910564Sandreas.hansson@arm.com    {
91010566Sandreas.hansson@arm.com        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
91110564Sandreas.hansson@arm.com        data = const_cast<PacketDataPtr>(p);
91210564Sandreas.hansson@arm.com        flags.set(STATIC_DATA);
91310564Sandreas.hansson@arm.com    }
91410564Sandreas.hansson@arm.com
91510564Sandreas.hansson@arm.com    /**
9163348Sbinkertn@umich.edu     * Set the data pointer to a value that should have delete []
91710571Sandreas.hansson@arm.com     * called on it. Dynamic data is local to this packet, and as the
91810571Sandreas.hansson@arm.com     * packet travels from source to destination, forwarded packets
91910571Sandreas.hansson@arm.com     * will allocate their own data. When a packet reaches the final
92010571Sandreas.hansson@arm.com     * destination it will populate the dynamic data of that specific
92110571Sandreas.hansson@arm.com     * packet, and on the way back towards the source, memcpy will be
92210571Sandreas.hansson@arm.com     * invoked in every step where a new packet was created e.g. in
92310571Sandreas.hansson@arm.com     * the caches. Ultimately when the response reaches the source a
92410571Sandreas.hansson@arm.com     * final memcpy is needed to extract the data from the packet
92510571Sandreas.hansson@arm.com     * before it is deallocated.
9263348Sbinkertn@umich.edu     */
9272566SN/A    template <typename T>
9283348Sbinkertn@umich.edu    void
9293348Sbinkertn@umich.edu    dataDynamic(T *p)
9303348Sbinkertn@umich.edu    {
93110566Sandreas.hansson@arm.com        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
9323348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
9335735Snate@binkert.org        flags.set(DYNAMIC_DATA);
9343348Sbinkertn@umich.edu    }
9353348Sbinkertn@umich.edu
9365735Snate@binkert.org    /**
9375735Snate@binkert.org     * get a pointer to the data ptr.
9385735Snate@binkert.org     */
9393348Sbinkertn@umich.edu    template <typename T>
9403348Sbinkertn@umich.edu    T*
94110562Sandreas.hansson@arm.com    getPtr()
9423348Sbinkertn@umich.edu    {
94310562Sandreas.hansson@arm.com        assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
9443348Sbinkertn@umich.edu        return (T*)data;
9453348Sbinkertn@umich.edu    }
9462566SN/A
94710563Sandreas.hansson@arm.com    template <typename T>
94810563Sandreas.hansson@arm.com    const T*
94910563Sandreas.hansson@arm.com    getConstPtr() const
95010563Sandreas.hansson@arm.com    {
95110563Sandreas.hansson@arm.com        assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
95210563Sandreas.hansson@arm.com        return (const T*)data;
95310563Sandreas.hansson@arm.com    }
95410563Sandreas.hansson@arm.com
9555735Snate@binkert.org    /**
95611013Sandreas.sandberg@arm.com     * Get the data in the packet byte swapped from big endian to
95711013Sandreas.sandberg@arm.com     * host endian.
95811013Sandreas.sandberg@arm.com     */
95911013Sandreas.sandberg@arm.com    template <typename T>
96011013Sandreas.sandberg@arm.com    T getBE() const;
96111013Sandreas.sandberg@arm.com
96211013Sandreas.sandberg@arm.com    /**
96311013Sandreas.sandberg@arm.com     * Get the data in the packet byte swapped from little endian to
96411013Sandreas.sandberg@arm.com     * host endian.
96511013Sandreas.sandberg@arm.com     */
96611013Sandreas.sandberg@arm.com    template <typename T>
96711013Sandreas.sandberg@arm.com    T getLE() const;
96811013Sandreas.sandberg@arm.com
96911013Sandreas.sandberg@arm.com    /**
97011013Sandreas.sandberg@arm.com     * Get the data in the packet byte swapped from the specified
97111013Sandreas.sandberg@arm.com     * endianness.
97211013Sandreas.sandberg@arm.com     */
97311013Sandreas.sandberg@arm.com    template <typename T>
97411013Sandreas.sandberg@arm.com    T get(ByteOrder endian) const;
97511013Sandreas.sandberg@arm.com
97611013Sandreas.sandberg@arm.com    /**
97711013Sandreas.sandberg@arm.com     * Get the data in the packet byte swapped from guest to host
97811013Sandreas.sandberg@arm.com     * endian.
9795735Snate@binkert.org     */
9802566SN/A    template <typename T>
98110563Sandreas.hansson@arm.com    T get() const;
9822566SN/A
98311013Sandreas.sandberg@arm.com    /** Set the value in the data pointer to v as big endian. */
98411013Sandreas.sandberg@arm.com    template <typename T>
98511013Sandreas.sandberg@arm.com    void setBE(T v);
98611013Sandreas.sandberg@arm.com
98711013Sandreas.sandberg@arm.com    /** Set the value in the data pointer to v as little endian. */
98811013Sandreas.sandberg@arm.com    template <typename T>
98911013Sandreas.sandberg@arm.com    void setLE(T v);
99011013Sandreas.sandberg@arm.com
9915735Snate@binkert.org    /**
99211013Sandreas.sandberg@arm.com     * Set the value in the data pointer to v using the specified
99311013Sandreas.sandberg@arm.com     * endianness.
9945735Snate@binkert.org     */
9952566SN/A    template <typename T>
99611013Sandreas.sandberg@arm.com    void set(T v, ByteOrder endian);
99711013Sandreas.sandberg@arm.com
99811013Sandreas.sandberg@arm.com    /** Set the value in the data pointer to v as guest endian. */
99911013Sandreas.sandberg@arm.com    template <typename T>
10002592SN/A    void set(T v);
10012566SN/A
10023348Sbinkertn@umich.edu    /**
10034626Sstever@eecs.umich.edu     * Copy data into the packet from the provided pointer.
10044626Sstever@eecs.umich.edu     */
10055735Snate@binkert.org    void
100610563Sandreas.hansson@arm.com    setData(const uint8_t *p)
10074626Sstever@eecs.umich.edu    {
100810571Sandreas.hansson@arm.com        // we should never be copying data onto itself, which means we
100910571Sandreas.hansson@arm.com        // must idenfity packets with static data, as they carry the
101010571Sandreas.hansson@arm.com        // same pointer from source to destination and back
101110571Sandreas.hansson@arm.com        assert(p != getPtr<uint8_t>() || flags.isSet(STATIC_DATA));
101210571Sandreas.hansson@arm.com
10137691SAli.Saidi@ARM.com        if (p != getPtr<uint8_t>())
101410571Sandreas.hansson@arm.com            // for packet with allocated dynamic data, we copy data from
101510571Sandreas.hansson@arm.com            // one to the other, e.g. a forwarded response to a response
10167691SAli.Saidi@ARM.com            std::memcpy(getPtr<uint8_t>(), p, getSize());
10174626Sstever@eecs.umich.edu    }
10184626Sstever@eecs.umich.edu
10194626Sstever@eecs.umich.edu    /**
10204626Sstever@eecs.umich.edu     * Copy data into the packet from the provided block pointer,
10214626Sstever@eecs.umich.edu     * which is aligned to the given block size.
10224626Sstever@eecs.umich.edu     */
10235735Snate@binkert.org    void
102410563Sandreas.hansson@arm.com    setDataFromBlock(const uint8_t *blk_data, int blkSize)
10254626Sstever@eecs.umich.edu    {
10264626Sstever@eecs.umich.edu        setData(blk_data + getOffset(blkSize));
10274626Sstever@eecs.umich.edu    }
10284626Sstever@eecs.umich.edu
10294626Sstever@eecs.umich.edu    /**
10304626Sstever@eecs.umich.edu     * Copy data from the packet to the provided block pointer, which
10314626Sstever@eecs.umich.edu     * is aligned to the given block size.
10324626Sstever@eecs.umich.edu     */
10335735Snate@binkert.org    void
103410563Sandreas.hansson@arm.com    writeData(uint8_t *p) const
10354626Sstever@eecs.umich.edu    {
103610563Sandreas.hansson@arm.com        std::memcpy(p, getConstPtr<uint8_t>(), getSize());
10374626Sstever@eecs.umich.edu    }
10384626Sstever@eecs.umich.edu
10394626Sstever@eecs.umich.edu    /**
10404626Sstever@eecs.umich.edu     * Copy data from the packet to the memory at the provided pointer.
10414626Sstever@eecs.umich.edu     */
10425735Snate@binkert.org    void
104310563Sandreas.hansson@arm.com    writeDataToBlock(uint8_t *blk_data, int blkSize) const
10444626Sstever@eecs.umich.edu    {
10454626Sstever@eecs.umich.edu        writeData(blk_data + getOffset(blkSize));
10464626Sstever@eecs.umich.edu    }
10474626Sstever@eecs.umich.edu
10484626Sstever@eecs.umich.edu    /**
10493348Sbinkertn@umich.edu     * delete the data pointed to in the data pointer. Ok to call to
10503348Sbinkertn@umich.edu     * matter how data was allocted.
10513348Sbinkertn@umich.edu     */
10525735Snate@binkert.org    void
10535735Snate@binkert.org    deleteData()
10545735Snate@binkert.org    {
105510566Sandreas.hansson@arm.com        if (flags.isSet(DYNAMIC_DATA))
10565735Snate@binkert.org            delete [] data;
10575735Snate@binkert.org
105810566Sandreas.hansson@arm.com        flags.clear(STATIC_DATA|DYNAMIC_DATA);
10595735Snate@binkert.org        data = NULL;
10605735Snate@binkert.org    }
10612566SN/A
106210565Sandreas.hansson@arm.com    /** Allocate memory for the packet. */
10635735Snate@binkert.org    void
10645735Snate@binkert.org    allocate()
10655735Snate@binkert.org    {
106611286Sandreas.hansson@arm.com        // if either this command or the response command has a data
106711286Sandreas.hansson@arm.com        // payload, actually allocate space
106811286Sandreas.hansson@arm.com        if (hasData() || hasRespData()) {
106911286Sandreas.hansson@arm.com            assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
107011286Sandreas.hansson@arm.com            flags.set(DYNAMIC_DATA);
107111286Sandreas.hansson@arm.com            data = new uint8_t[getSize()];
107211286Sandreas.hansson@arm.com        }
10735735Snate@binkert.org    }
10745735Snate@binkert.org
107511013Sandreas.sandberg@arm.com    /** @} */
107611013Sandreas.sandberg@arm.com
107711013Sandreas.sandberg@arm.com  private: // Private data accessor methods
107811013Sandreas.sandberg@arm.com    /** Get the data in the packet without byte swapping. */
107911013Sandreas.sandberg@arm.com    template <typename T>
108011013Sandreas.sandberg@arm.com    T getRaw() const;
108111013Sandreas.sandberg@arm.com
108211013Sandreas.sandberg@arm.com    /** Set the value in the data pointer to v without byte swapping. */
108311013Sandreas.sandberg@arm.com    template <typename T>
108411013Sandreas.sandberg@arm.com    void setRaw(T v);
108511013Sandreas.sandberg@arm.com
108611013Sandreas.sandberg@arm.com  public:
10874626Sstever@eecs.umich.edu    /**
108810570Sandreas.hansson@arm.com     * Check a functional request against a memory value stored in
108910570Sandreas.hansson@arm.com     * another packet (i.e. an in-transit request or
109010570Sandreas.hansson@arm.com     * response). Returns true if the current packet is a read, and
109110570Sandreas.hansson@arm.com     * the other packet provides the data, which is then copied to the
109210570Sandreas.hansson@arm.com     * current packet. If the current packet is a write, and the other
109310570Sandreas.hansson@arm.com     * packet intersects this one, then we update the data
109410570Sandreas.hansson@arm.com     * accordingly.
109510570Sandreas.hansson@arm.com     */
109610570Sandreas.hansson@arm.com    bool
109710570Sandreas.hansson@arm.com    checkFunctional(PacketPtr other)
109810570Sandreas.hansson@arm.com    {
109910570Sandreas.hansson@arm.com        // all packets that are carrying a payload should have a valid
110010570Sandreas.hansson@arm.com        // data pointer
110110570Sandreas.hansson@arm.com        return checkFunctional(other, other->getAddr(), other->isSecure(),
110210570Sandreas.hansson@arm.com                               other->getSize(),
110310570Sandreas.hansson@arm.com                               other->hasData() ?
110410570Sandreas.hansson@arm.com                               other->getPtr<uint8_t>() : NULL);
110510570Sandreas.hansson@arm.com    }
110610570Sandreas.hansson@arm.com
110710570Sandreas.hansson@arm.com    /**
110810883Sali.jafri@arm.com     * Does the request need to check for cached copies of the same block
110910883Sali.jafri@arm.com     * in the memory hierarchy above.
111010883Sali.jafri@arm.com     **/
111110883Sali.jafri@arm.com    bool
111210883Sali.jafri@arm.com    mustCheckAbove() const
111310883Sali.jafri@arm.com    {
111411199Sandreas.hansson@arm.com        return cmd == MemCmd::HardPFReq || isEviction();
111511199Sandreas.hansson@arm.com    }
111611199Sandreas.hansson@arm.com
111711199Sandreas.hansson@arm.com    /**
111811199Sandreas.hansson@arm.com     * Is this packet a clean eviction, including both actual clean
111911199Sandreas.hansson@arm.com     * evict packets, but also clean writebacks.
112011199Sandreas.hansson@arm.com     */
112111199Sandreas.hansson@arm.com    bool
112211199Sandreas.hansson@arm.com    isCleanEviction() const
112311199Sandreas.hansson@arm.com    {
112411199Sandreas.hansson@arm.com        return cmd == MemCmd::CleanEvict || cmd == MemCmd::WritebackClean;
112510883Sali.jafri@arm.com    }
112610883Sali.jafri@arm.com
112710883Sali.jafri@arm.com    /**
11284626Sstever@eecs.umich.edu     * Check a functional request against a memory value represented
112910570Sandreas.hansson@arm.com     * by a base/size pair and an associated data array. If the
113010570Sandreas.hansson@arm.com     * current packet is a read, it may be satisfied by the memory
113110570Sandreas.hansson@arm.com     * value. If the current packet is a write, it may update the
11324626Sstever@eecs.umich.edu     * memory value.
11334626Sstever@eecs.umich.edu     */
11345735Snate@binkert.org    bool
113510570Sandreas.hansson@arm.com    checkFunctional(Printable *obj, Addr base, bool is_secure, int size,
113610570Sandreas.hansson@arm.com                    uint8_t *_data);
11375314Sstever@gmail.com
11385315Sstever@gmail.com    /**
11395315Sstever@gmail.com     * Push label for PrintReq (safe to call unconditionally).
11405315Sstever@gmail.com     */
11415735Snate@binkert.org    void
11425735Snate@binkert.org    pushLabel(const std::string &lbl)
11435735Snate@binkert.org    {
11445735Snate@binkert.org        if (isPrint())
11455735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->pushLabel(lbl);
11465314Sstever@gmail.com    }
11475314Sstever@gmail.com
11485315Sstever@gmail.com    /**
11495315Sstever@gmail.com     * Pop label for PrintReq (safe to call unconditionally).
11505315Sstever@gmail.com     */
11515735Snate@binkert.org    void
11525735Snate@binkert.org    popLabel()
11535735Snate@binkert.org    {
11545735Snate@binkert.org        if (isPrint())
11555735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->popLabel();
11565314Sstever@gmail.com    }
11575314Sstever@gmail.com
11585314Sstever@gmail.com    void print(std::ostream &o, int verbosity = 0,
11595314Sstever@gmail.com               const std::string &prefix = "") const;
11609663Suri.wiener@arm.com
11619663Suri.wiener@arm.com    /**
11629663Suri.wiener@arm.com     * A no-args wrapper of print(std::ostream...)
11639663Suri.wiener@arm.com     * meant to be invoked from DPRINTFs
11649663Suri.wiener@arm.com     * avoiding string overheads in fast mode
11659663Suri.wiener@arm.com     * @return string with the request's type and start<->end addresses
11669663Suri.wiener@arm.com     */
11679663Suri.wiener@arm.com    std::string print() const;
11682381SN/A};
11692381SN/A
11702381SN/A#endif //__MEM_PACKET_HH
1171