packet.hh revision 8668
12381SN/A/*
22592SN/A * Copyright (c) 2006 The Regents of The University of Michigan
37636Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
42381SN/A * All rights reserved.
52381SN/A *
62381SN/A * Redistribution and use in source and binary forms, with or without
72381SN/A * modification, are permitted provided that the following conditions are
82381SN/A * met: redistributions of source code must retain the above copyright
92381SN/A * notice, this list of conditions and the following disclaimer;
102381SN/A * redistributions in binary form must reproduce the above copyright
112381SN/A * notice, this list of conditions and the following disclaimer in the
122381SN/A * documentation and/or other materials provided with the distribution;
132381SN/A * neither the name of the copyright holders nor the names of its
142381SN/A * contributors may be used to endorse or promote products derived from
152381SN/A * this software without specific prior written permission.
162381SN/A *
172381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * Authors: Ron Dreslinski
302665Ssaidi@eecs.umich.edu *          Steve Reinhardt
312665Ssaidi@eecs.umich.edu *          Ali Saidi
322381SN/A */
332381SN/A
342381SN/A/**
352381SN/A * @file
362662Sstever@eecs.umich.edu * Declaration of the Packet class.
372381SN/A */
382381SN/A
392381SN/A#ifndef __MEM_PACKET_HH__
402381SN/A#define __MEM_PACKET_HH__
412381SN/A
428229Snate@binkert.org#include <bitset>
433348Sbinkertn@umich.edu#include <cassert>
443348Sbinkertn@umich.edu#include <list>
453348Sbinkertn@umich.edu
465735Snate@binkert.org#include "base/cast.hh"
474024Sbinkertn@umich.edu#include "base/compiler.hh"
484610Ssaidi@eecs.umich.edu#include "base/fast_alloc.hh"
495735Snate@binkert.org#include "base/flags.hh"
503940Ssaidi@eecs.umich.edu#include "base/misc.hh"
515314Sstever@gmail.com#include "base/printable.hh"
526216Snate@binkert.org#include "base/types.hh"
532392SN/A#include "mem/request.hh"
544167Sbinkertn@umich.edu#include "sim/core.hh"
552394SN/A
562394SN/Astruct Packet;
573349Sbinkertn@umich.edutypedef Packet *PacketPtr;
582394SN/Atypedef uint8_t* PacketDataPtr;
592812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList;
602812Srdreslin@umich.edu
614022Sstever@eecs.umich.educlass MemCmd
624022Sstever@eecs.umich.edu{
635735Snate@binkert.org    friend class Packet;
645735Snate@binkert.org
654022Sstever@eecs.umich.edu  public:
665735Snate@binkert.org    /**
675735Snate@binkert.org     * List of all commands associated with a packet.
685735Snate@binkert.org     */
694022Sstever@eecs.umich.edu    enum Command
704022Sstever@eecs.umich.edu    {
714022Sstever@eecs.umich.edu        InvalidCmd,
724022Sstever@eecs.umich.edu        ReadReq,
734473Sstever@eecs.umich.edu        ReadResp,
745319Sstever@gmail.com        ReadRespWithInvalidate,
754022Sstever@eecs.umich.edu        WriteReq,
764022Sstever@eecs.umich.edu        WriteResp,
774022Sstever@eecs.umich.edu        Writeback,
784022Sstever@eecs.umich.edu        SoftPFReq,
794022Sstever@eecs.umich.edu        HardPFReq,
804022Sstever@eecs.umich.edu        SoftPFResp,
814022Sstever@eecs.umich.edu        HardPFResp,
824022Sstever@eecs.umich.edu        WriteInvalidateReq,
834022Sstever@eecs.umich.edu        WriteInvalidateResp,
844022Sstever@eecs.umich.edu        UpgradeReq,
857465Ssteve.reinhardt@amd.com        SCUpgradeReq,           // Special "weak" upgrade for StoreCond
864628Sstever@eecs.umich.edu        UpgradeResp,
877465Ssteve.reinhardt@amd.com        SCUpgradeFailReq,       // Failed SCUpgradeReq in MSHR (never sent)
887465Ssteve.reinhardt@amd.com        UpgradeFailResp,        // Valid for SCUpgradeReq only
894022Sstever@eecs.umich.edu        ReadExReq,
904022Sstever@eecs.umich.edu        ReadExResp,
914626Sstever@eecs.umich.edu        LoadLockedReq,
924626Sstever@eecs.umich.edu        StoreCondReq,
937669Ssteve.reinhardt@amd.com        StoreCondFailReq,       // Failed StoreCondReq in MSHR (never sent)
944626Sstever@eecs.umich.edu        StoreCondResp,
954040Ssaidi@eecs.umich.edu        SwapReq,
964040Ssaidi@eecs.umich.edu        SwapResp,
975650Sgblack@eecs.umich.edu        MessageReq,
985650Sgblack@eecs.umich.edu        MessageResp,
994870Sstever@eecs.umich.edu        // Error responses
1004870Sstever@eecs.umich.edu        // @TODO these should be classified as responses rather than
1014870Sstever@eecs.umich.edu        // requests; coding them as requests initially for backwards
1024870Sstever@eecs.umich.edu        // compatibility
1034870Sstever@eecs.umich.edu        NetworkNackError,  // nacked at network layer (not by protocol)
1044870Sstever@eecs.umich.edu        InvalidDestError,  // packet dest field invalid
1054870Sstever@eecs.umich.edu        BadAddressError,   // memory address invalid
1068436SBrad.Beckmann@amd.com        FunctionalReadError, // unable to fulfill functional read
1078436SBrad.Beckmann@amd.com        FunctionalWriteError, // unable to fulfill functional write
1085314Sstever@gmail.com        // Fake simulator-only commands
1095314Sstever@gmail.com        PrintReq,       // Print state matching address
1108184Ssomayeh@cs.wisc.edu        FlushReq,      //request for a cache flush
1114022Sstever@eecs.umich.edu        NUM_MEM_CMDS
1124022Sstever@eecs.umich.edu    };
1134022Sstever@eecs.umich.edu
1144022Sstever@eecs.umich.edu  private:
1155735Snate@binkert.org    /**
1165735Snate@binkert.org     * List of command attributes.
1175735Snate@binkert.org     */
1184022Sstever@eecs.umich.edu    enum Attribute
1194022Sstever@eecs.umich.edu    {
1204626Sstever@eecs.umich.edu        IsRead,         //!< Data flows from responder to requester
1214626Sstever@eecs.umich.edu        IsWrite,        //!< Data flows from requester to responder
1227465Ssteve.reinhardt@amd.com        IsUpgrade,
1234626Sstever@eecs.umich.edu        IsPrefetch,     //!< Not a demand access
1244022Sstever@eecs.umich.edu        IsInvalidate,
1254626Sstever@eecs.umich.edu        NeedsExclusive, //!< Requires exclusive copy to complete in-cache
1264626Sstever@eecs.umich.edu        IsRequest,      //!< Issued by requester
1274626Sstever@eecs.umich.edu        IsResponse,     //!< Issue by responder
1284626Sstever@eecs.umich.edu        NeedsResponse,  //!< Requester needs response from target
1294022Sstever@eecs.umich.edu        IsSWPrefetch,
1304022Sstever@eecs.umich.edu        IsHWPrefetch,
1316076Sgblack@eecs.umich.edu        IsLlsc,         //!< Alpha/MIPS LL or SC access
1324626Sstever@eecs.umich.edu        HasData,        //!< There is an associated payload
1334870Sstever@eecs.umich.edu        IsError,        //!< Error response
1345314Sstever@gmail.com        IsPrint,        //!< Print state matching address (for debugging)
1358184Ssomayeh@cs.wisc.edu        IsFlush,        //!< Flush the address from caches
1364022Sstever@eecs.umich.edu        NUM_COMMAND_ATTRIBUTES
1374022Sstever@eecs.umich.edu    };
1384022Sstever@eecs.umich.edu
1395735Snate@binkert.org    /**
1405735Snate@binkert.org     * Structure that defines attributes and other data associated
1415735Snate@binkert.org     * with a Command.
1425735Snate@binkert.org     */
1435735Snate@binkert.org    struct CommandInfo
1445735Snate@binkert.org    {
1455735Snate@binkert.org        /// Set of attribute flags.
1464022Sstever@eecs.umich.edu        const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
1475735Snate@binkert.org        /// Corresponding response for requests; InvalidCmd if no
1485735Snate@binkert.org        /// response is applicable.
1494022Sstever@eecs.umich.edu        const Command response;
1505735Snate@binkert.org        /// String representation (for printing)
1514022Sstever@eecs.umich.edu        const std::string str;
1524022Sstever@eecs.umich.edu    };
1534022Sstever@eecs.umich.edu
1545735Snate@binkert.org    /// Array to map Command enum to associated info.
1554022Sstever@eecs.umich.edu    static const CommandInfo commandInfo[];
1564022Sstever@eecs.umich.edu
1574022Sstever@eecs.umich.edu  private:
1584022Sstever@eecs.umich.edu
1594022Sstever@eecs.umich.edu    Command cmd;
1604022Sstever@eecs.umich.edu
1615735Snate@binkert.org    bool
1625735Snate@binkert.org    testCmdAttrib(MemCmd::Attribute attrib) const
1635735Snate@binkert.org    {
1644022Sstever@eecs.umich.edu        return commandInfo[cmd].attributes[attrib] != 0;
1654022Sstever@eecs.umich.edu    }
1664022Sstever@eecs.umich.edu
1674022Sstever@eecs.umich.edu  public:
1684022Sstever@eecs.umich.edu
1694022Sstever@eecs.umich.edu    bool isRead() const         { return testCmdAttrib(IsRead); }
1707465Ssteve.reinhardt@amd.com    bool isWrite() const        { return testCmdAttrib(IsWrite); }
1717465Ssteve.reinhardt@amd.com    bool isUpgrade() const      { return testCmdAttrib(IsUpgrade); }
1724022Sstever@eecs.umich.edu    bool isRequest() const      { return testCmdAttrib(IsRequest); }
1734022Sstever@eecs.umich.edu    bool isResponse() const     { return testCmdAttrib(IsResponse); }
1744870Sstever@eecs.umich.edu    bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); }
1754022Sstever@eecs.umich.edu    bool needsResponse() const  { return testCmdAttrib(NeedsResponse); }
1764022Sstever@eecs.umich.edu    bool isInvalidate() const   { return testCmdAttrib(IsInvalidate); }
1774022Sstever@eecs.umich.edu    bool hasData() const        { return testCmdAttrib(HasData); }
1784626Sstever@eecs.umich.edu    bool isReadWrite() const    { return isRead() && isWrite(); }
1796102Sgblack@eecs.umich.edu    bool isLLSC() const         { return testCmdAttrib(IsLlsc); }
1804870Sstever@eecs.umich.edu    bool isError() const        { return testCmdAttrib(IsError); }
1815314Sstever@gmail.com    bool isPrint() const        { return testCmdAttrib(IsPrint); }
1828184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return testCmdAttrib(IsFlush); }
1834022Sstever@eecs.umich.edu
1845735Snate@binkert.org    const Command
1855735Snate@binkert.org    responseCommand() const
1865735Snate@binkert.org    {
1874022Sstever@eecs.umich.edu        return commandInfo[cmd].response;
1884022Sstever@eecs.umich.edu    }
1894022Sstever@eecs.umich.edu
1905735Snate@binkert.org    /// Return the string to a cmd given by idx.
1915735Snate@binkert.org    const std::string &toString() const { return commandInfo[cmd].str; }
1924022Sstever@eecs.umich.edu    int toInt() const { return (int)cmd; }
1934022Sstever@eecs.umich.edu
1945735Snate@binkert.org    MemCmd(Command _cmd) : cmd(_cmd) { }
1955735Snate@binkert.org    MemCmd(int _cmd) : cmd((Command)_cmd) { }
1965735Snate@binkert.org    MemCmd() : cmd(InvalidCmd) { }
1974022Sstever@eecs.umich.edu
1985735Snate@binkert.org    bool operator==(MemCmd c2) const { return (cmd == c2.cmd); }
1995735Snate@binkert.org    bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); }
2004022Sstever@eecs.umich.edu};
2014022Sstever@eecs.umich.edu
2022381SN/A/**
2032662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in
2042662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache).  (In contrast, a
2052662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the
2062662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several
2072662Sstever@eecs.umich.edu * different Packets along the way.)
2082381SN/A */
2095314Sstever@gmail.comclass Packet : public FastAlloc, public Printable
2102381SN/A{
2112813Srdreslin@umich.edu  public:
2125735Snate@binkert.org    typedef uint32_t FlagsType;
2135735Snate@binkert.org    typedef ::Flags<FlagsType> Flags;
2145735Snate@binkert.org    typedef short NodeID;
2154022Sstever@eecs.umich.edu
2165735Snate@binkert.org  private:
2175735Snate@binkert.org    static const FlagsType PUBLIC_FLAGS           = 0x00000000;
2185735Snate@binkert.org    static const FlagsType PRIVATE_FLAGS          = 0x00007F0F;
2195735Snate@binkert.org    static const FlagsType COPY_FLAGS             = 0x0000000F;
2205735Snate@binkert.org
2215735Snate@binkert.org    static const FlagsType SHARED                 = 0x00000001;
2225735Snate@binkert.org    // Special control flags
2235735Snate@binkert.org    /// Special timing-mode atomic snoop for multi-level coherence.
2245735Snate@binkert.org    static const FlagsType EXPRESS_SNOOP          = 0x00000002;
2255735Snate@binkert.org    /// Does supplier have exclusive copy?
2265735Snate@binkert.org    /// Useful for multi-level coherence.
2275735Snate@binkert.org    static const FlagsType SUPPLY_EXCLUSIVE       = 0x00000004;
2285735Snate@binkert.org    // Snoop response flags
2295735Snate@binkert.org    static const FlagsType MEM_INHIBIT            = 0x00000008;
2305735Snate@binkert.org    /// Are the 'addr' and 'size' fields valid?
2315735Snate@binkert.org    static const FlagsType VALID_ADDR             = 0x00000100;
2325735Snate@binkert.org    static const FlagsType VALID_SIZE             = 0x00000200;
2335735Snate@binkert.org    /// Is the 'src' field valid?
2345735Snate@binkert.org    static const FlagsType VALID_SRC              = 0x00000400;
2355735Snate@binkert.org    static const FlagsType VALID_DST              = 0x00000800;
2365735Snate@binkert.org    /// Is the data pointer set to a value that shouldn't be freed
2375735Snate@binkert.org    /// when the packet is destroyed?
2385735Snate@binkert.org    static const FlagsType STATIC_DATA            = 0x00001000;
2395735Snate@binkert.org    /// The data pointer points to a value that should be freed when
2405735Snate@binkert.org    /// the packet is destroyed.
2415735Snate@binkert.org    static const FlagsType DYNAMIC_DATA           = 0x00002000;
2425735Snate@binkert.org    /// the data pointer points to an array (thus delete []) needs to
2435735Snate@binkert.org    /// be called on it rather than simply delete.
2445735Snate@binkert.org    static const FlagsType ARRAY_DATA             = 0x00004000;
2458436SBrad.Beckmann@amd.com    /// suppress the error if this packet encounters a functional
2468436SBrad.Beckmann@amd.com    /// access failure.
2478436SBrad.Beckmann@amd.com    static const FlagsType SUPPRESS_FUNC_ERROR    = 0x00008000;
2485735Snate@binkert.org
2495735Snate@binkert.org    Flags flags;
2505735Snate@binkert.org
2515735Snate@binkert.org  public:
2524022Sstever@eecs.umich.edu    typedef MemCmd::Command Command;
2534022Sstever@eecs.umich.edu
2545735Snate@binkert.org    /// The command field of the packet.
2554870Sstever@eecs.umich.edu    MemCmd cmd;
2564870Sstever@eecs.umich.edu
2575735Snate@binkert.org    /// A pointer to the original request.
2584870Sstever@eecs.umich.edu    RequestPtr req;
2594870Sstever@eecs.umich.edu
2602566SN/A  private:
2615735Snate@binkert.org   /**
2625735Snate@binkert.org    * A pointer to the data being transfered.  It can be differnt
2635735Snate@binkert.org    * sizes at each level of the heirarchy so it belongs in the
2645735Snate@binkert.org    * packet, not request. This may or may not be populated when a
2655735Snate@binkert.org    * responder recieves the packet. If not populated it memory should
2665735Snate@binkert.org    * be allocated.
2672566SN/A    */
2682566SN/A    PacketDataPtr data;
2692566SN/A
2705735Snate@binkert.org    /// The address of the request.  This address could be virtual or
2715735Snate@binkert.org    /// physical, depending on the system configuration.
2722381SN/A    Addr addr;
2732381SN/A
2745735Snate@binkert.org    /// The size of the request or transfer.
2756227Snate@binkert.org    unsigned size;
2762381SN/A
2775735Snate@binkert.org    /**
2785735Snate@binkert.org     * Device address (e.g., bus ID) of the source of the
2795735Snate@binkert.org     * transaction. The source is not responsible for setting this
2805735Snate@binkert.org     * field; it is set implicitly by the interconnect when the packet
2815735Snate@binkert.org     * is first sent.
2825735Snate@binkert.org     */
2835735Snate@binkert.org    NodeID src;
2842381SN/A
2855735Snate@binkert.org    /**
2865735Snate@binkert.org     * Device address (e.g., bus ID) of the destination of the
2875735Snate@binkert.org     * transaction. The special value Broadcast indicates that the
2885735Snate@binkert.org     * packet should be routed based on its address. This field is
2895735Snate@binkert.org     * initialized in the constructor and is thus always valid (unlike
2905735Snate@binkert.org     * addr, size, and src).
2915735Snate@binkert.org     */
2925735Snate@binkert.org    NodeID dest;
2932641Sstever@eecs.umich.edu
2945735Snate@binkert.org    /**
2955735Snate@binkert.org     * The original value of the command field.  Only valid when the
2964870Sstever@eecs.umich.edu     * current command field is an error condition; in that case, the
2974870Sstever@eecs.umich.edu     * previous contents of the command field are copied here.  This
2984870Sstever@eecs.umich.edu     * field is *not* set on non-error responses.
2994870Sstever@eecs.umich.edu     */
3004870Sstever@eecs.umich.edu    MemCmd origCmd;
3014870Sstever@eecs.umich.edu
3028668Sgeoffrey.blake@arm.com    /**
3038668Sgeoffrey.blake@arm.com     * These values specify the range of bytes found that satisfy a
3048668Sgeoffrey.blake@arm.com     * functional read.
3058668Sgeoffrey.blake@arm.com     */
3068668Sgeoffrey.blake@arm.com    uint16_t bytesValidStart;
3078668Sgeoffrey.blake@arm.com    uint16_t bytesValidEnd;
3088668Sgeoffrey.blake@arm.com
3092641Sstever@eecs.umich.edu  public:
3105735Snate@binkert.org    /// Used to calculate latencies for each packet.
3112811Srdreslin@umich.edu    Tick time;
3122811Srdreslin@umich.edu
3135735Snate@binkert.org    /// The time at which the packet will be fully transmitted
3143218Sgblack@eecs.umich.edu    Tick finishTime;
3153218Sgblack@eecs.umich.edu
3165735Snate@binkert.org    /// The time at which the first chunk of the packet will be transmitted
3173218Sgblack@eecs.umich.edu    Tick firstWordTime;
3183218Sgblack@eecs.umich.edu
3195735Snate@binkert.org    /// The special destination address indicating that the packet
3205735Snate@binkert.org    /// should be routed based on its address.
3215735Snate@binkert.org    static const NodeID Broadcast = -1;
3222623SN/A
3235735Snate@binkert.org    /**
3245735Snate@binkert.org     * A virtual base opaque structure used to hold state associated
3255735Snate@binkert.org     * with the packet but specific to the sending device (e.g., an
3265735Snate@binkert.org     * MSHR).  A pointer to this state is returned in the packet's
3275735Snate@binkert.org     * response so that the sender can quickly look up the state
3285735Snate@binkert.org     * needed to process it.  A specific subclass would be derived
3295735Snate@binkert.org     * from this to carry state specific to a particular sending
3305735Snate@binkert.org     * device.
3315735Snate@binkert.org     */
3325735Snate@binkert.org    struct SenderState
3335735Snate@binkert.org    {
3342641Sstever@eecs.umich.edu        virtual ~SenderState() {}
3352641Sstever@eecs.umich.edu    };
3362641Sstever@eecs.umich.edu
3375315Sstever@gmail.com    /**
3385315Sstever@gmail.com     * Object used to maintain state of a PrintReq.  The senderState
3395315Sstever@gmail.com     * field of a PrintReq should always be of this type.
3405315Sstever@gmail.com     */
3415735Snate@binkert.org    class PrintReqState : public SenderState, public FastAlloc
3425735Snate@binkert.org    {
3435735Snate@binkert.org      private:
3445735Snate@binkert.org        /**
3455735Snate@binkert.org         * An entry in the label stack.
3465735Snate@binkert.org         */
3475735Snate@binkert.org        struct LabelStackEntry
3485735Snate@binkert.org        {
3495314Sstever@gmail.com            const std::string label;
3505314Sstever@gmail.com            std::string *prefix;
3515314Sstever@gmail.com            bool labelPrinted;
3525735Snate@binkert.org            LabelStackEntry(const std::string &_label, std::string *_prefix);
3535314Sstever@gmail.com        };
3545314Sstever@gmail.com
3555314Sstever@gmail.com        typedef std::list<LabelStackEntry> LabelStack;
3565314Sstever@gmail.com        LabelStack labelStack;
3575314Sstever@gmail.com
3585314Sstever@gmail.com        std::string *curPrefixPtr;
3595314Sstever@gmail.com
3605314Sstever@gmail.com      public:
3615314Sstever@gmail.com        std::ostream &os;
3625314Sstever@gmail.com        const int verbosity;
3635314Sstever@gmail.com
3645314Sstever@gmail.com        PrintReqState(std::ostream &os, int verbosity = 0);
3655314Sstever@gmail.com        ~PrintReqState();
3665314Sstever@gmail.com
3675735Snate@binkert.org        /**
3685735Snate@binkert.org         * Returns the current line prefix.
3695735Snate@binkert.org         */
3705314Sstever@gmail.com        const std::string &curPrefix() { return *curPrefixPtr; }
3715315Sstever@gmail.com
3725735Snate@binkert.org        /**
3735735Snate@binkert.org         * Push a label onto the label stack, and prepend the given
3745315Sstever@gmail.com         * prefix string onto the current prefix.  Labels will only be
3755735Snate@binkert.org         * printed if an object within the label's scope is printed.
3765735Snate@binkert.org         */
3775314Sstever@gmail.com        void pushLabel(const std::string &lbl,
3785314Sstever@gmail.com                       const std::string &prefix = "  ");
3795735Snate@binkert.org
3805735Snate@binkert.org        /**
3815735Snate@binkert.org         * Pop a label off the label stack.
3825735Snate@binkert.org         */
3835314Sstever@gmail.com        void popLabel();
3845735Snate@binkert.org
3855735Snate@binkert.org        /**
3865735Snate@binkert.org         * Print all of the pending unprinted labels on the
3875315Sstever@gmail.com         * stack. Called by printObj(), so normally not called by
3885735Snate@binkert.org         * users unless bypassing printObj().
3895735Snate@binkert.org         */
3905314Sstever@gmail.com        void printLabels();
3915735Snate@binkert.org
3925735Snate@binkert.org        /**
3935735Snate@binkert.org         * Print a Printable object to os, because it matched the
3945735Snate@binkert.org         * address on a PrintReq.
3955735Snate@binkert.org         */
3965314Sstever@gmail.com        void printObj(Printable *obj);
3975314Sstever@gmail.com    };
3985314Sstever@gmail.com
3995735Snate@binkert.org    /**
4005735Snate@binkert.org     * This packet's sender state.  Devices should use dynamic_cast<>
4015735Snate@binkert.org     * to cast to the state appropriate to the sender.  The intent of
4025735Snate@binkert.org     * this variable is to allow a device to attach extra information
4035735Snate@binkert.org     * to a request.  A response packet must return the sender state
4045735Snate@binkert.org     * that was attached to the original request (even if a new packet
4055735Snate@binkert.org     * is created).
4065735Snate@binkert.org     */
4072662Sstever@eecs.umich.edu    SenderState *senderState;
4082641Sstever@eecs.umich.edu
4095735Snate@binkert.org    /// Return the string name of the cmd field (for debugging and
4105735Snate@binkert.org    /// tracing).
4114022Sstever@eecs.umich.edu    const std::string &cmdString() const { return cmd.toString(); }
4122811Srdreslin@umich.edu
4135735Snate@binkert.org    /// Return the index of this command.
4144022Sstever@eecs.umich.edu    inline int cmdToIndex() const { return cmd.toInt(); }
4152811Srdreslin@umich.edu
4164022Sstever@eecs.umich.edu    bool isRead() const         { return cmd.isRead(); }
4177465Ssteve.reinhardt@amd.com    bool isWrite() const        { return cmd.isWrite(); }
4187465Ssteve.reinhardt@amd.com    bool isUpgrade()  const     { return cmd.isUpgrade(); }
4194022Sstever@eecs.umich.edu    bool isRequest() const      { return cmd.isRequest(); }
4204022Sstever@eecs.umich.edu    bool isResponse() const     { return cmd.isResponse(); }
4214870Sstever@eecs.umich.edu    bool needsExclusive() const { return cmd.needsExclusive(); }
4224022Sstever@eecs.umich.edu    bool needsResponse() const  { return cmd.needsResponse(); }
4234022Sstever@eecs.umich.edu    bool isInvalidate() const   { return cmd.isInvalidate(); }
4244022Sstever@eecs.umich.edu    bool hasData() const        { return cmd.hasData(); }
4254040Ssaidi@eecs.umich.edu    bool isReadWrite() const    { return cmd.isReadWrite(); }
4266102Sgblack@eecs.umich.edu    bool isLLSC() const         { return cmd.isLLSC(); }
4274870Sstever@eecs.umich.edu    bool isError() const        { return cmd.isError(); }
4285314Sstever@gmail.com    bool isPrint() const        { return cmd.isPrint(); }
4298184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return cmd.isFlush(); }
4302812Srdreslin@umich.edu
4314870Sstever@eecs.umich.edu    // Snoop flags
4325735Snate@binkert.org    void assertMemInhibit()     { flags.set(MEM_INHIBIT); }
4335764Snate@binkert.org    bool memInhibitAsserted()   { return flags.isSet(MEM_INHIBIT); }
4345735Snate@binkert.org    void assertShared()         { flags.set(SHARED); }
4355764Snate@binkert.org    bool sharedAsserted()       { return flags.isSet(SHARED); }
4364870Sstever@eecs.umich.edu
4374895Sstever@eecs.umich.edu    // Special control flags
4385735Snate@binkert.org    void setExpressSnoop()      { flags.set(EXPRESS_SNOOP); }
4395764Snate@binkert.org    bool isExpressSnoop()       { return flags.isSet(EXPRESS_SNOOP); }
4405735Snate@binkert.org    void setSupplyExclusive()   { flags.set(SUPPLY_EXCLUSIVE); }
4417687Ssteve.reinhardt@amd.com    void clearSupplyExclusive() { flags.clear(SUPPLY_EXCLUSIVE); }
4425764Snate@binkert.org    bool isSupplyExclusive()    { return flags.isSet(SUPPLY_EXCLUSIVE); }
4438436SBrad.Beckmann@amd.com    void setSuppressFuncError() { flags.set(SUPPRESS_FUNC_ERROR); }
4448436SBrad.Beckmann@amd.com    bool suppressFuncError()    { return flags.isSet(SUPPRESS_FUNC_ERROR); }
4454895Sstever@eecs.umich.edu
4464870Sstever@eecs.umich.edu    // Network error conditions... encapsulate them as methods since
4474870Sstever@eecs.umich.edu    // their encoding keeps changing (from result field to command
4484870Sstever@eecs.umich.edu    // field, etc.)
4495735Snate@binkert.org    void
4505735Snate@binkert.org    setNacked()
4515735Snate@binkert.org    {
4525735Snate@binkert.org        assert(isResponse());
4535735Snate@binkert.org        cmd = MemCmd::NetworkNackError;
4545735Snate@binkert.org    }
4555735Snate@binkert.org
4565735Snate@binkert.org    void
4575735Snate@binkert.org    setBadAddress()
4585735Snate@binkert.org    {
4595735Snate@binkert.org        assert(isResponse());
4605735Snate@binkert.org        cmd = MemCmd::BadAddressError;
4615735Snate@binkert.org    }
4625735Snate@binkert.org
4635735Snate@binkert.org    bool wasNacked() const     { return cmd == MemCmd::NetworkNackError; }
4645735Snate@binkert.org    bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; }
4654986Ssaidi@eecs.umich.edu    void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
4662814Srdreslin@umich.edu
4676768SBrad.Beckmann@amd.com    bool isSrcValid() { return flags.isSet(VALID_SRC); }
4685735Snate@binkert.org    /// Accessor function to get the source index of the packet.
4695764Snate@binkert.org    NodeID getSrc() const    { assert(flags.isSet(VALID_SRC)); return src; }
4705735Snate@binkert.org    /// Accessor function to set the source index of the packet.
4715735Snate@binkert.org    void setSrc(NodeID _src) { src = _src; flags.set(VALID_SRC); }
4725735Snate@binkert.org    /// Reset source field, e.g. to retransmit packet on different bus.
4735735Snate@binkert.org    void clearSrc() { flags.clear(VALID_SRC); }
4742641Sstever@eecs.umich.edu
4756768SBrad.Beckmann@amd.com    bool isDestValid() { return flags.isSet(VALID_DST); }
4765735Snate@binkert.org    /// Accessor function for the destination index of the packet.
4775764Snate@binkert.org    NodeID getDest() const     { assert(flags.isSet(VALID_DST)); return dest; }
4785735Snate@binkert.org    /// Accessor function to set the destination index of the packet.
4795735Snate@binkert.org    void setDest(NodeID _dest) { dest = _dest; flags.set(VALID_DST); }
4802381SN/A
4815764Snate@binkert.org    Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; }
4826227Snate@binkert.org    unsigned getSize() const  { assert(flags.isSet(VALID_SIZE)); return size; }
4835735Snate@binkert.org    Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); }
4842549SN/A
4855735Snate@binkert.org    /**
4867550SBrad.Beckmann@amd.com     * It has been determined that the SC packet should successfully update
4877550SBrad.Beckmann@amd.com     * memory.  Therefore, convert this SC packet to a normal write.
4887550SBrad.Beckmann@amd.com     */
4897550SBrad.Beckmann@amd.com    void
4907550SBrad.Beckmann@amd.com    convertScToWrite()
4917550SBrad.Beckmann@amd.com    {
4927550SBrad.Beckmann@amd.com        assert(isLLSC());
4937550SBrad.Beckmann@amd.com        assert(isWrite());
4947550SBrad.Beckmann@amd.com        cmd = MemCmd::WriteReq;
4957550SBrad.Beckmann@amd.com    }
4967550SBrad.Beckmann@amd.com
4977550SBrad.Beckmann@amd.com    /**
4987550SBrad.Beckmann@amd.com     * When ruby is in use, Ruby will monitor the cache line and thus M5
4997550SBrad.Beckmann@amd.com     * phys memory should treat LL ops as normal reads.
5007550SBrad.Beckmann@amd.com     */
5017550SBrad.Beckmann@amd.com    void
5027550SBrad.Beckmann@amd.com    convertLlToRead()
5037550SBrad.Beckmann@amd.com    {
5047550SBrad.Beckmann@amd.com        assert(isLLSC());
5057550SBrad.Beckmann@amd.com        assert(isRead());
5067550SBrad.Beckmann@amd.com        cmd = MemCmd::ReadReq;
5077550SBrad.Beckmann@amd.com    }
5087550SBrad.Beckmann@amd.com
5097550SBrad.Beckmann@amd.com    /**
5105735Snate@binkert.org     * Constructor.  Note that a Request object must be constructed
5115735Snate@binkert.org     * first, but the Requests's physical address and size fields need
5125735Snate@binkert.org     * not be valid. The command and destination addresses must be
5135735Snate@binkert.org     * supplied.
5145735Snate@binkert.org     */
5155735Snate@binkert.org    Packet(Request *_req, MemCmd _cmd, NodeID _dest)
5165745Snate@binkert.org        :  flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
5178668Sgeoffrey.blake@arm.com           dest(_dest), bytesValidStart(0), bytesValidEnd(0),
5188668Sgeoffrey.blake@arm.com           time(curTick()), senderState(NULL)
5192641Sstever@eecs.umich.edu    {
5206104Ssteve.reinhardt@amd.com        if (req->hasPaddr()) {
5216104Ssteve.reinhardt@amd.com            addr = req->getPaddr();
5226104Ssteve.reinhardt@amd.com            flags.set(VALID_ADDR);
5236104Ssteve.reinhardt@amd.com        }
5246104Ssteve.reinhardt@amd.com        if (req->hasSize()) {
5256104Ssteve.reinhardt@amd.com            size = req->getSize();
5266104Ssteve.reinhardt@amd.com            flags.set(VALID_SIZE);
5276104Ssteve.reinhardt@amd.com        }
5282813Srdreslin@umich.edu    }
5292813Srdreslin@umich.edu
5305735Snate@binkert.org    /**
5315735Snate@binkert.org     * Alternate constructor if you are trying to create a packet with
5325735Snate@binkert.org     * a request that is for a whole block, not the address from the
5335735Snate@binkert.org     * req.  this allows for overriding the size/addr of the req.
5345735Snate@binkert.org     */
5355735Snate@binkert.org    Packet(Request *_req, MemCmd _cmd, NodeID _dest, int _blkSize)
5365745Snate@binkert.org        :  flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
5378668Sgeoffrey.blake@arm.com           dest(_dest), bytesValidStart(0), bytesValidEnd(0),
5388668Sgeoffrey.blake@arm.com           time(curTick()), senderState(NULL)
5392813Srdreslin@umich.edu    {
5406104Ssteve.reinhardt@amd.com        if (req->hasPaddr()) {
5416104Ssteve.reinhardt@amd.com            addr = req->getPaddr() & ~(_blkSize - 1);
5426104Ssteve.reinhardt@amd.com            flags.set(VALID_ADDR);
5436104Ssteve.reinhardt@amd.com        }
5446104Ssteve.reinhardt@amd.com        size = _blkSize;
5456104Ssteve.reinhardt@amd.com        flags.set(VALID_SIZE);
5464626Sstever@eecs.umich.edu    }
5474626Sstever@eecs.umich.edu
5485735Snate@binkert.org    /**
5495735Snate@binkert.org     * Alternate constructor for copying a packet.  Copy all fields
5504887Sstever@eecs.umich.edu     * *except* if the original packet's data was dynamic, don't copy
5514887Sstever@eecs.umich.edu     * that, as we can't guarantee that the new packet's lifetime is
5524887Sstever@eecs.umich.edu     * less than that of the original packet.  In this case the new
5535735Snate@binkert.org     * packet should allocate its own data.
5545735Snate@binkert.org     */
5555735Snate@binkert.org    Packet(Packet *pkt, bool clearFlags = false)
5565735Snate@binkert.org        :  cmd(pkt->cmd), req(pkt->req),
5575764Snate@binkert.org           data(pkt->flags.isSet(STATIC_DATA) ? pkt->data : NULL),
5585735Snate@binkert.org           addr(pkt->addr), size(pkt->size), src(pkt->src), dest(pkt->dest),
5598668Sgeoffrey.blake@arm.com           bytesValidStart(pkt->bytesValidStart), bytesValidEnd(pkt->bytesValidEnd),
5607823Ssteve.reinhardt@amd.com           time(curTick()), senderState(pkt->senderState)
5614626Sstever@eecs.umich.edu    {
5625735Snate@binkert.org        if (!clearFlags)
5635735Snate@binkert.org            flags.set(pkt->flags & COPY_FLAGS);
5645735Snate@binkert.org
5655735Snate@binkert.org        flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE|VALID_SRC|VALID_DST));
5665735Snate@binkert.org        flags.set(pkt->flags & STATIC_DATA);
5678668Sgeoffrey.blake@arm.com
5682641Sstever@eecs.umich.edu    }
5692549SN/A
5705735Snate@binkert.org    /**
5715735Snate@binkert.org     * clean up packet variables
5725735Snate@binkert.org     */
5732566SN/A    ~Packet()
5745387Sstever@gmail.com    {
5755387Sstever@gmail.com        // If this is a request packet for which there's no response,
5765387Sstever@gmail.com        // delete the request object here, since the requester will
5775387Sstever@gmail.com        // never get the chance.
5785387Sstever@gmail.com        if (req && isRequest() && !needsResponse())
5795387Sstever@gmail.com            delete req;
5805735Snate@binkert.org        deleteData();
5815387Sstever@gmail.com    }
5822566SN/A
5835735Snate@binkert.org    /**
5845735Snate@binkert.org     * Reinitialize packet address and size from the associated
5855735Snate@binkert.org     * Request object, and reset other fields that may have been
5865735Snate@binkert.org     * modified by a previous transaction.  Typically called when a
5875735Snate@binkert.org     * statically allocated Request/Packet pair is reused for multiple
5885735Snate@binkert.org     * transactions.
5895735Snate@binkert.org     */
5905735Snate@binkert.org    void
5915735Snate@binkert.org    reinitFromRequest()
5925735Snate@binkert.org    {
5936104Ssteve.reinhardt@amd.com        assert(req->hasPaddr());
5944870Sstever@eecs.umich.edu        flags = 0;
5956104Ssteve.reinhardt@amd.com        addr = req->getPaddr();
5966104Ssteve.reinhardt@amd.com        size = req->getSize();
5976223Snate@binkert.org        time = req->time();
5985735Snate@binkert.org
5995735Snate@binkert.org        flags.set(VALID_ADDR|VALID_SIZE);
6005735Snate@binkert.org        deleteData();
6012662Sstever@eecs.umich.edu    }
6022566SN/A
6034626Sstever@eecs.umich.edu    /**
6044626Sstever@eecs.umich.edu     * Take a request packet and modify it in place to be suitable for
6054626Sstever@eecs.umich.edu     * returning as a response to that request.  The source and
6064626Sstever@eecs.umich.edu     * destination fields are *not* modified, as is appropriate for
6074626Sstever@eecs.umich.edu     * atomic accesses.
6084626Sstever@eecs.umich.edu     */
6095735Snate@binkert.org    void
6105735Snate@binkert.org    makeResponse()
6114626Sstever@eecs.umich.edu    {
6122662Sstever@eecs.umich.edu        assert(needsResponse());
6132855Srdreslin@umich.edu        assert(isRequest());
6144986Ssaidi@eecs.umich.edu        origCmd = cmd;
6154022Sstever@eecs.umich.edu        cmd = cmd.responseCommand();
6165745Snate@binkert.org
6177464Ssteve.reinhardt@amd.com        // responses are never express, even if the snoop that
6187464Ssteve.reinhardt@amd.com        // triggered them was
6197464Ssteve.reinhardt@amd.com        flags.clear(EXPRESS_SNOOP);
6207464Ssteve.reinhardt@amd.com
6215745Snate@binkert.org        dest = src;
6225764Snate@binkert.org        flags.set(VALID_DST, flags.isSet(VALID_SRC));
6235745Snate@binkert.org        flags.clear(VALID_SRC);
6242641Sstever@eecs.umich.edu    }
6252641Sstever@eecs.umich.edu
6265735Snate@binkert.org    void
6275735Snate@binkert.org    makeAtomicResponse()
6284870Sstever@eecs.umich.edu    {
6294870Sstever@eecs.umich.edu        makeResponse();
6304870Sstever@eecs.umich.edu    }
6314870Sstever@eecs.umich.edu
6325735Snate@binkert.org    void
6335735Snate@binkert.org    makeTimingResponse()
6343348Sbinkertn@umich.edu    {
6354870Sstever@eecs.umich.edu        makeResponse();
6363135Srdreslin@umich.edu    }
6373135Srdreslin@umich.edu
6388436SBrad.Beckmann@amd.com    void
6398436SBrad.Beckmann@amd.com    setFunctionalResponseStatus(bool success)
6408436SBrad.Beckmann@amd.com    {
6418436SBrad.Beckmann@amd.com        if (!success) {
6428436SBrad.Beckmann@amd.com            if (isWrite()) {
6438436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalWriteError;
6448436SBrad.Beckmann@amd.com            } else {
6458436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalReadError;
6468436SBrad.Beckmann@amd.com            }
6478436SBrad.Beckmann@amd.com        }
6488436SBrad.Beckmann@amd.com    }
6498436SBrad.Beckmann@amd.com
6503348Sbinkertn@umich.edu    /**
6513348Sbinkertn@umich.edu     * Take a request packet that has been returned as NACKED and
6523348Sbinkertn@umich.edu     * modify it so that it can be sent out again. Only packets that
6533348Sbinkertn@umich.edu     * need a response can be NACKED, so verify that that is true.
6543348Sbinkertn@umich.edu     */
6553348Sbinkertn@umich.edu    void
6563348Sbinkertn@umich.edu    reinitNacked()
6573348Sbinkertn@umich.edu    {
6584870Sstever@eecs.umich.edu        assert(wasNacked());
6594870Sstever@eecs.umich.edu        cmd = origCmd;
6604870Sstever@eecs.umich.edu        assert(needsResponse());
6614870Sstever@eecs.umich.edu        setDest(Broadcast);
6622685Ssaidi@eecs.umich.edu    }
6632685Ssaidi@eecs.umich.edu
6647006Snate@binkert.org    void
6657006Snate@binkert.org    setSize(unsigned size)
6667006Snate@binkert.org    {
6677006Snate@binkert.org        assert(!flags.isSet(VALID_SIZE));
6687006Snate@binkert.org
6697006Snate@binkert.org        this->size = size;
6707006Snate@binkert.org        flags.set(VALID_SIZE);
6717006Snate@binkert.org    }
6727006Snate@binkert.org
6732685Ssaidi@eecs.umich.edu
6743348Sbinkertn@umich.edu    /**
6753348Sbinkertn@umich.edu     * Set the data pointer to the following value that should not be
6763348Sbinkertn@umich.edu     * freed.
6772566SN/A     */
6782566SN/A    template <typename T>
6793348Sbinkertn@umich.edu    void
6803348Sbinkertn@umich.edu    dataStatic(T *p)
6813348Sbinkertn@umich.edu    {
6825764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
6833348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
6845735Snate@binkert.org        flags.set(STATIC_DATA);
6853348Sbinkertn@umich.edu    }
6862566SN/A
6873348Sbinkertn@umich.edu    /**
6883348Sbinkertn@umich.edu     * Set the data pointer to a value that should have delete []
6893348Sbinkertn@umich.edu     * called on it.
6903348Sbinkertn@umich.edu     */
6912566SN/A    template <typename T>
6923348Sbinkertn@umich.edu    void
6933348Sbinkertn@umich.edu    dataDynamicArray(T *p)
6943348Sbinkertn@umich.edu    {
6955764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
6963348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
6975735Snate@binkert.org        flags.set(DYNAMIC_DATA|ARRAY_DATA);
6983348Sbinkertn@umich.edu    }
6993348Sbinkertn@umich.edu
7003348Sbinkertn@umich.edu    /**
7013348Sbinkertn@umich.edu     * set the data pointer to a value that should have delete called
7023348Sbinkertn@umich.edu     * on it.
7033348Sbinkertn@umich.edu     */
7043348Sbinkertn@umich.edu    template <typename T>
7053348Sbinkertn@umich.edu    void
7063348Sbinkertn@umich.edu    dataDynamic(T *p)
7073348Sbinkertn@umich.edu    {
7085764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
7093348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
7105735Snate@binkert.org        flags.set(DYNAMIC_DATA);
7113348Sbinkertn@umich.edu    }
7123348Sbinkertn@umich.edu
7135735Snate@binkert.org    /**
7145735Snate@binkert.org     * get a pointer to the data ptr.
7155735Snate@binkert.org     */
7163348Sbinkertn@umich.edu    template <typename T>
7173348Sbinkertn@umich.edu    T*
7187915SBrad.Beckmann@amd.com    getPtr(bool null_ok = false)
7193348Sbinkertn@umich.edu    {
7207915SBrad.Beckmann@amd.com        assert(null_ok || flags.isSet(STATIC_DATA|DYNAMIC_DATA));
7213348Sbinkertn@umich.edu        return (T*)data;
7223348Sbinkertn@umich.edu    }
7232566SN/A
7245735Snate@binkert.org    /**
7255735Snate@binkert.org     * return the value of what is pointed to in the packet.
7265735Snate@binkert.org     */
7272566SN/A    template <typename T>
7282592SN/A    T get();
7292566SN/A
7305735Snate@binkert.org    /**
7315735Snate@binkert.org     * set the value in the data pointer to v.
7325735Snate@binkert.org     */
7332566SN/A    template <typename T>
7342592SN/A    void set(T v);
7352566SN/A
7363348Sbinkertn@umich.edu    /**
7374626Sstever@eecs.umich.edu     * Copy data into the packet from the provided pointer.
7384626Sstever@eecs.umich.edu     */
7395735Snate@binkert.org    void
7405735Snate@binkert.org    setData(uint8_t *p)
7414626Sstever@eecs.umich.edu    {
7427691SAli.Saidi@ARM.com        if (p != getPtr<uint8_t>())
7437691SAli.Saidi@ARM.com            std::memcpy(getPtr<uint8_t>(), p, getSize());
7444626Sstever@eecs.umich.edu    }
7454626Sstever@eecs.umich.edu
7464626Sstever@eecs.umich.edu    /**
7474626Sstever@eecs.umich.edu     * Copy data into the packet from the provided block pointer,
7484626Sstever@eecs.umich.edu     * which is aligned to the given block size.
7494626Sstever@eecs.umich.edu     */
7505735Snate@binkert.org    void
7515735Snate@binkert.org    setDataFromBlock(uint8_t *blk_data, int blkSize)
7524626Sstever@eecs.umich.edu    {
7534626Sstever@eecs.umich.edu        setData(blk_data + getOffset(blkSize));
7544626Sstever@eecs.umich.edu    }
7554626Sstever@eecs.umich.edu
7564626Sstever@eecs.umich.edu    /**
7574626Sstever@eecs.umich.edu     * Copy data from the packet to the provided block pointer, which
7584626Sstever@eecs.umich.edu     * is aligned to the given block size.
7594626Sstever@eecs.umich.edu     */
7605735Snate@binkert.org    void
7615735Snate@binkert.org    writeData(uint8_t *p)
7624626Sstever@eecs.umich.edu    {
7634626Sstever@eecs.umich.edu        std::memcpy(p, getPtr<uint8_t>(), getSize());
7644626Sstever@eecs.umich.edu    }
7654626Sstever@eecs.umich.edu
7664626Sstever@eecs.umich.edu    /**
7674626Sstever@eecs.umich.edu     * Copy data from the packet to the memory at the provided pointer.
7684626Sstever@eecs.umich.edu     */
7695735Snate@binkert.org    void
7705735Snate@binkert.org    writeDataToBlock(uint8_t *blk_data, int blkSize)
7714626Sstever@eecs.umich.edu    {
7724626Sstever@eecs.umich.edu        writeData(blk_data + getOffset(blkSize));
7734626Sstever@eecs.umich.edu    }
7744626Sstever@eecs.umich.edu
7754626Sstever@eecs.umich.edu    /**
7763348Sbinkertn@umich.edu     * delete the data pointed to in the data pointer. Ok to call to
7773348Sbinkertn@umich.edu     * matter how data was allocted.
7783348Sbinkertn@umich.edu     */
7795735Snate@binkert.org    void
7805735Snate@binkert.org    deleteData()
7815735Snate@binkert.org    {
7825764Snate@binkert.org        if (flags.isSet(ARRAY_DATA))
7835735Snate@binkert.org            delete [] data;
7845764Snate@binkert.org        else if (flags.isSet(DYNAMIC_DATA))
7855735Snate@binkert.org            delete data;
7865735Snate@binkert.org
7875735Snate@binkert.org        flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA);
7885735Snate@binkert.org        data = NULL;
7895735Snate@binkert.org    }
7902566SN/A
7912566SN/A    /** If there isn't data in the packet, allocate some. */
7925735Snate@binkert.org    void
7935735Snate@binkert.org    allocate()
7945735Snate@binkert.org    {
7955735Snate@binkert.org        if (data) {
7965764Snate@binkert.org            assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
7975745Snate@binkert.org            return;
7985735Snate@binkert.org        }
7995745Snate@binkert.org
8005764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
8015745Snate@binkert.org        flags.set(DYNAMIC_DATA|ARRAY_DATA);
8025745Snate@binkert.org        data = new uint8_t[getSize()];
8035735Snate@binkert.org    }
8045735Snate@binkert.org
8054626Sstever@eecs.umich.edu    /**
8064626Sstever@eecs.umich.edu     * Check a functional request against a memory value represented
8074626Sstever@eecs.umich.edu     * by a base/size pair and an associated data array.  If the
8084626Sstever@eecs.umich.edu     * functional request is a read, it may be satisfied by the memory
8094626Sstever@eecs.umich.edu     * value.  If the functional request is a write, it may update the
8104626Sstever@eecs.umich.edu     * memory value.
8114626Sstever@eecs.umich.edu     */
8125314Sstever@gmail.com    bool checkFunctional(Printable *obj, Addr base, int size, uint8_t *data);
8134626Sstever@eecs.umich.edu
8144626Sstever@eecs.umich.edu    /**
8154626Sstever@eecs.umich.edu     * Check a functional request against a memory value stored in
8165315Sstever@gmail.com     * another packet (i.e. an in-transit request or response).
8174626Sstever@eecs.umich.edu     */
8185735Snate@binkert.org    bool
8195735Snate@binkert.org    checkFunctional(PacketPtr other)
8205735Snate@binkert.org    {
8215735Snate@binkert.org        uint8_t *data = other->hasData() ? other->getPtr<uint8_t>() : NULL;
8225735Snate@binkert.org        return checkFunctional(other, other->getAddr(), other->getSize(),
8235735Snate@binkert.org                               data);
8244626Sstever@eecs.umich.edu    }
8255314Sstever@gmail.com
8265315Sstever@gmail.com    /**
8275315Sstever@gmail.com     * Push label for PrintReq (safe to call unconditionally).
8285315Sstever@gmail.com     */
8295735Snate@binkert.org    void
8305735Snate@binkert.org    pushLabel(const std::string &lbl)
8315735Snate@binkert.org    {
8325735Snate@binkert.org        if (isPrint())
8335735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->pushLabel(lbl);
8345314Sstever@gmail.com    }
8355314Sstever@gmail.com
8365315Sstever@gmail.com    /**
8375315Sstever@gmail.com     * Pop label for PrintReq (safe to call unconditionally).
8385315Sstever@gmail.com     */
8395735Snate@binkert.org    void
8405735Snate@binkert.org    popLabel()
8415735Snate@binkert.org    {
8425735Snate@binkert.org        if (isPrint())
8435735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->popLabel();
8445314Sstever@gmail.com    }
8455314Sstever@gmail.com
8465314Sstever@gmail.com    void print(std::ostream &o, int verbosity = 0,
8475314Sstever@gmail.com               const std::string &prefix = "") const;
8482381SN/A};
8492381SN/A
8502381SN/A#endif //__MEM_PACKET_HH
851