packet.hh revision 8737
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
568737Skoansin.tan@gmail.comclass 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
1118716Snilay@cs.wisc.edu        InvalidationReq,   // request for address to be invalidated from lsq
1124022Sstever@eecs.umich.edu        NUM_MEM_CMDS
1134022Sstever@eecs.umich.edu    };
1144022Sstever@eecs.umich.edu
1154022Sstever@eecs.umich.edu  private:
1165735Snate@binkert.org    /**
1175735Snate@binkert.org     * List of command attributes.
1185735Snate@binkert.org     */
1194022Sstever@eecs.umich.edu    enum Attribute
1204022Sstever@eecs.umich.edu    {
1214626Sstever@eecs.umich.edu        IsRead,         //!< Data flows from responder to requester
1224626Sstever@eecs.umich.edu        IsWrite,        //!< Data flows from requester to responder
1237465Ssteve.reinhardt@amd.com        IsUpgrade,
1244626Sstever@eecs.umich.edu        IsPrefetch,     //!< Not a demand access
1254022Sstever@eecs.umich.edu        IsInvalidate,
1264626Sstever@eecs.umich.edu        NeedsExclusive, //!< Requires exclusive copy to complete in-cache
1274626Sstever@eecs.umich.edu        IsRequest,      //!< Issued by requester
1284626Sstever@eecs.umich.edu        IsResponse,     //!< Issue by responder
1294626Sstever@eecs.umich.edu        NeedsResponse,  //!< Requester needs response from target
1304022Sstever@eecs.umich.edu        IsSWPrefetch,
1314022Sstever@eecs.umich.edu        IsHWPrefetch,
1326076Sgblack@eecs.umich.edu        IsLlsc,         //!< Alpha/MIPS LL or SC access
1334626Sstever@eecs.umich.edu        HasData,        //!< There is an associated payload
1344870Sstever@eecs.umich.edu        IsError,        //!< Error response
1355314Sstever@gmail.com        IsPrint,        //!< Print state matching address (for debugging)
1368184Ssomayeh@cs.wisc.edu        IsFlush,        //!< Flush the address from caches
1374022Sstever@eecs.umich.edu        NUM_COMMAND_ATTRIBUTES
1384022Sstever@eecs.umich.edu    };
1394022Sstever@eecs.umich.edu
1405735Snate@binkert.org    /**
1415735Snate@binkert.org     * Structure that defines attributes and other data associated
1425735Snate@binkert.org     * with a Command.
1435735Snate@binkert.org     */
1445735Snate@binkert.org    struct CommandInfo
1455735Snate@binkert.org    {
1465735Snate@binkert.org        /// Set of attribute flags.
1474022Sstever@eecs.umich.edu        const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
1485735Snate@binkert.org        /// Corresponding response for requests; InvalidCmd if no
1495735Snate@binkert.org        /// response is applicable.
1504022Sstever@eecs.umich.edu        const Command response;
1515735Snate@binkert.org        /// String representation (for printing)
1524022Sstever@eecs.umich.edu        const std::string str;
1534022Sstever@eecs.umich.edu    };
1544022Sstever@eecs.umich.edu
1555735Snate@binkert.org    /// Array to map Command enum to associated info.
1564022Sstever@eecs.umich.edu    static const CommandInfo commandInfo[];
1574022Sstever@eecs.umich.edu
1584022Sstever@eecs.umich.edu  private:
1594022Sstever@eecs.umich.edu
1604022Sstever@eecs.umich.edu    Command cmd;
1614022Sstever@eecs.umich.edu
1625735Snate@binkert.org    bool
1635735Snate@binkert.org    testCmdAttrib(MemCmd::Attribute attrib) const
1645735Snate@binkert.org    {
1654022Sstever@eecs.umich.edu        return commandInfo[cmd].attributes[attrib] != 0;
1664022Sstever@eecs.umich.edu    }
1674022Sstever@eecs.umich.edu
1684022Sstever@eecs.umich.edu  public:
1694022Sstever@eecs.umich.edu
1704022Sstever@eecs.umich.edu    bool isRead() const         { return testCmdAttrib(IsRead); }
1717465Ssteve.reinhardt@amd.com    bool isWrite() const        { return testCmdAttrib(IsWrite); }
1727465Ssteve.reinhardt@amd.com    bool isUpgrade() const      { return testCmdAttrib(IsUpgrade); }
1734022Sstever@eecs.umich.edu    bool isRequest() const      { return testCmdAttrib(IsRequest); }
1744022Sstever@eecs.umich.edu    bool isResponse() const     { return testCmdAttrib(IsResponse); }
1754870Sstever@eecs.umich.edu    bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); }
1764022Sstever@eecs.umich.edu    bool needsResponse() const  { return testCmdAttrib(NeedsResponse); }
1774022Sstever@eecs.umich.edu    bool isInvalidate() const   { return testCmdAttrib(IsInvalidate); }
1784022Sstever@eecs.umich.edu    bool hasData() const        { return testCmdAttrib(HasData); }
1794626Sstever@eecs.umich.edu    bool isReadWrite() const    { return isRead() && isWrite(); }
1806102Sgblack@eecs.umich.edu    bool isLLSC() const         { return testCmdAttrib(IsLlsc); }
1814870Sstever@eecs.umich.edu    bool isError() const        { return testCmdAttrib(IsError); }
1825314Sstever@gmail.com    bool isPrint() const        { return testCmdAttrib(IsPrint); }
1838184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return testCmdAttrib(IsFlush); }
1844022Sstever@eecs.umich.edu
1855735Snate@binkert.org    const Command
1865735Snate@binkert.org    responseCommand() const
1875735Snate@binkert.org    {
1884022Sstever@eecs.umich.edu        return commandInfo[cmd].response;
1894022Sstever@eecs.umich.edu    }
1904022Sstever@eecs.umich.edu
1915735Snate@binkert.org    /// Return the string to a cmd given by idx.
1925735Snate@binkert.org    const std::string &toString() const { return commandInfo[cmd].str; }
1934022Sstever@eecs.umich.edu    int toInt() const { return (int)cmd; }
1944022Sstever@eecs.umich.edu
1955735Snate@binkert.org    MemCmd(Command _cmd) : cmd(_cmd) { }
1965735Snate@binkert.org    MemCmd(int _cmd) : cmd((Command)_cmd) { }
1975735Snate@binkert.org    MemCmd() : cmd(InvalidCmd) { }
1984022Sstever@eecs.umich.edu
1995735Snate@binkert.org    bool operator==(MemCmd c2) const { return (cmd == c2.cmd); }
2005735Snate@binkert.org    bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); }
2014022Sstever@eecs.umich.edu};
2024022Sstever@eecs.umich.edu
2032381SN/A/**
2042662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in
2052662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache).  (In contrast, a
2062662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the
2072662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several
2082662Sstever@eecs.umich.edu * different Packets along the way.)
2092381SN/A */
2105314Sstever@gmail.comclass Packet : public FastAlloc, public Printable
2112381SN/A{
2122813Srdreslin@umich.edu  public:
2135735Snate@binkert.org    typedef uint32_t FlagsType;
2145735Snate@binkert.org    typedef ::Flags<FlagsType> Flags;
2155735Snate@binkert.org    typedef short NodeID;
2164022Sstever@eecs.umich.edu
2175735Snate@binkert.org  private:
2185735Snate@binkert.org    static const FlagsType PUBLIC_FLAGS           = 0x00000000;
2195735Snate@binkert.org    static const FlagsType PRIVATE_FLAGS          = 0x00007F0F;
2205735Snate@binkert.org    static const FlagsType COPY_FLAGS             = 0x0000000F;
2215735Snate@binkert.org
2225735Snate@binkert.org    static const FlagsType SHARED                 = 0x00000001;
2235735Snate@binkert.org    // Special control flags
2245735Snate@binkert.org    /// Special timing-mode atomic snoop for multi-level coherence.
2255735Snate@binkert.org    static const FlagsType EXPRESS_SNOOP          = 0x00000002;
2265735Snate@binkert.org    /// Does supplier have exclusive copy?
2275735Snate@binkert.org    /// Useful for multi-level coherence.
2285735Snate@binkert.org    static const FlagsType SUPPLY_EXCLUSIVE       = 0x00000004;
2295735Snate@binkert.org    // Snoop response flags
2305735Snate@binkert.org    static const FlagsType MEM_INHIBIT            = 0x00000008;
2315735Snate@binkert.org    /// Are the 'addr' and 'size' fields valid?
2325735Snate@binkert.org    static const FlagsType VALID_ADDR             = 0x00000100;
2335735Snate@binkert.org    static const FlagsType VALID_SIZE             = 0x00000200;
2345735Snate@binkert.org    /// Is the 'src' field valid?
2355735Snate@binkert.org    static const FlagsType VALID_SRC              = 0x00000400;
2365735Snate@binkert.org    static const FlagsType VALID_DST              = 0x00000800;
2375735Snate@binkert.org    /// Is the data pointer set to a value that shouldn't be freed
2385735Snate@binkert.org    /// when the packet is destroyed?
2395735Snate@binkert.org    static const FlagsType STATIC_DATA            = 0x00001000;
2405735Snate@binkert.org    /// The data pointer points to a value that should be freed when
2415735Snate@binkert.org    /// the packet is destroyed.
2425735Snate@binkert.org    static const FlagsType DYNAMIC_DATA           = 0x00002000;
2435735Snate@binkert.org    /// the data pointer points to an array (thus delete []) needs to
2445735Snate@binkert.org    /// be called on it rather than simply delete.
2455735Snate@binkert.org    static const FlagsType ARRAY_DATA             = 0x00004000;
2468436SBrad.Beckmann@amd.com    /// suppress the error if this packet encounters a functional
2478436SBrad.Beckmann@amd.com    /// access failure.
2488436SBrad.Beckmann@amd.com    static const FlagsType SUPPRESS_FUNC_ERROR    = 0x00008000;
2495735Snate@binkert.org
2505735Snate@binkert.org    Flags flags;
2515735Snate@binkert.org
2525735Snate@binkert.org  public:
2534022Sstever@eecs.umich.edu    typedef MemCmd::Command Command;
2544022Sstever@eecs.umich.edu
2555735Snate@binkert.org    /// The command field of the packet.
2564870Sstever@eecs.umich.edu    MemCmd cmd;
2574870Sstever@eecs.umich.edu
2585735Snate@binkert.org    /// A pointer to the original request.
2594870Sstever@eecs.umich.edu    RequestPtr req;
2604870Sstever@eecs.umich.edu
2612566SN/A  private:
2625735Snate@binkert.org   /**
2635735Snate@binkert.org    * A pointer to the data being transfered.  It can be differnt
2645735Snate@binkert.org    * sizes at each level of the heirarchy so it belongs in the
2655735Snate@binkert.org    * packet, not request. This may or may not be populated when a
2665735Snate@binkert.org    * responder recieves the packet. If not populated it memory should
2675735Snate@binkert.org    * be allocated.
2682566SN/A    */
2692566SN/A    PacketDataPtr data;
2702566SN/A
2715735Snate@binkert.org    /// The address of the request.  This address could be virtual or
2725735Snate@binkert.org    /// physical, depending on the system configuration.
2732381SN/A    Addr addr;
2742381SN/A
2755735Snate@binkert.org    /// The size of the request or transfer.
2766227Snate@binkert.org    unsigned size;
2772381SN/A
2785735Snate@binkert.org    /**
2795735Snate@binkert.org     * Device address (e.g., bus ID) of the source of the
2805735Snate@binkert.org     * transaction. The source is not responsible for setting this
2815735Snate@binkert.org     * field; it is set implicitly by the interconnect when the packet
2825735Snate@binkert.org     * is first sent.
2835735Snate@binkert.org     */
2845735Snate@binkert.org    NodeID src;
2852381SN/A
2865735Snate@binkert.org    /**
2875735Snate@binkert.org     * Device address (e.g., bus ID) of the destination of the
2885735Snate@binkert.org     * transaction. The special value Broadcast indicates that the
2895735Snate@binkert.org     * packet should be routed based on its address. This field is
2905735Snate@binkert.org     * initialized in the constructor and is thus always valid (unlike
2915735Snate@binkert.org     * addr, size, and src).
2925735Snate@binkert.org     */
2935735Snate@binkert.org    NodeID dest;
2942641Sstever@eecs.umich.edu
2955735Snate@binkert.org    /**
2965735Snate@binkert.org     * The original value of the command field.  Only valid when the
2974870Sstever@eecs.umich.edu     * current command field is an error condition; in that case, the
2984870Sstever@eecs.umich.edu     * previous contents of the command field are copied here.  This
2994870Sstever@eecs.umich.edu     * field is *not* set on non-error responses.
3004870Sstever@eecs.umich.edu     */
3014870Sstever@eecs.umich.edu    MemCmd origCmd;
3024870Sstever@eecs.umich.edu
3038668Sgeoffrey.blake@arm.com    /**
3048668Sgeoffrey.blake@arm.com     * These values specify the range of bytes found that satisfy a
3058668Sgeoffrey.blake@arm.com     * functional read.
3068668Sgeoffrey.blake@arm.com     */
3078668Sgeoffrey.blake@arm.com    uint16_t bytesValidStart;
3088668Sgeoffrey.blake@arm.com    uint16_t bytesValidEnd;
3098668Sgeoffrey.blake@arm.com
3102641Sstever@eecs.umich.edu  public:
3115735Snate@binkert.org    /// Used to calculate latencies for each packet.
3122811Srdreslin@umich.edu    Tick time;
3132811Srdreslin@umich.edu
3145735Snate@binkert.org    /// The time at which the packet will be fully transmitted
3153218Sgblack@eecs.umich.edu    Tick finishTime;
3163218Sgblack@eecs.umich.edu
3175735Snate@binkert.org    /// The time at which the first chunk of the packet will be transmitted
3183218Sgblack@eecs.umich.edu    Tick firstWordTime;
3193218Sgblack@eecs.umich.edu
3205735Snate@binkert.org    /// The special destination address indicating that the packet
3215735Snate@binkert.org    /// should be routed based on its address.
3225735Snate@binkert.org    static const NodeID Broadcast = -1;
3232623SN/A
3245735Snate@binkert.org    /**
3255735Snate@binkert.org     * A virtual base opaque structure used to hold state associated
3265735Snate@binkert.org     * with the packet but specific to the sending device (e.g., an
3275735Snate@binkert.org     * MSHR).  A pointer to this state is returned in the packet's
3285735Snate@binkert.org     * response so that the sender can quickly look up the state
3295735Snate@binkert.org     * needed to process it.  A specific subclass would be derived
3305735Snate@binkert.org     * from this to carry state specific to a particular sending
3315735Snate@binkert.org     * device.
3325735Snate@binkert.org     */
3335735Snate@binkert.org    struct SenderState
3345735Snate@binkert.org    {
3352641Sstever@eecs.umich.edu        virtual ~SenderState() {}
3362641Sstever@eecs.umich.edu    };
3372641Sstever@eecs.umich.edu
3385315Sstever@gmail.com    /**
3395315Sstever@gmail.com     * Object used to maintain state of a PrintReq.  The senderState
3405315Sstever@gmail.com     * field of a PrintReq should always be of this type.
3415315Sstever@gmail.com     */
3425735Snate@binkert.org    class PrintReqState : public SenderState, public FastAlloc
3435735Snate@binkert.org    {
3445735Snate@binkert.org      private:
3455735Snate@binkert.org        /**
3465735Snate@binkert.org         * An entry in the label stack.
3475735Snate@binkert.org         */
3485735Snate@binkert.org        struct LabelStackEntry
3495735Snate@binkert.org        {
3505314Sstever@gmail.com            const std::string label;
3515314Sstever@gmail.com            std::string *prefix;
3525314Sstever@gmail.com            bool labelPrinted;
3535735Snate@binkert.org            LabelStackEntry(const std::string &_label, std::string *_prefix);
3545314Sstever@gmail.com        };
3555314Sstever@gmail.com
3565314Sstever@gmail.com        typedef std::list<LabelStackEntry> LabelStack;
3575314Sstever@gmail.com        LabelStack labelStack;
3585314Sstever@gmail.com
3595314Sstever@gmail.com        std::string *curPrefixPtr;
3605314Sstever@gmail.com
3615314Sstever@gmail.com      public:
3625314Sstever@gmail.com        std::ostream &os;
3635314Sstever@gmail.com        const int verbosity;
3645314Sstever@gmail.com
3655314Sstever@gmail.com        PrintReqState(std::ostream &os, int verbosity = 0);
3665314Sstever@gmail.com        ~PrintReqState();
3675314Sstever@gmail.com
3685735Snate@binkert.org        /**
3695735Snate@binkert.org         * Returns the current line prefix.
3705735Snate@binkert.org         */
3715314Sstever@gmail.com        const std::string &curPrefix() { return *curPrefixPtr; }
3725315Sstever@gmail.com
3735735Snate@binkert.org        /**
3745735Snate@binkert.org         * Push a label onto the label stack, and prepend the given
3755315Sstever@gmail.com         * prefix string onto the current prefix.  Labels will only be
3765735Snate@binkert.org         * printed if an object within the label's scope is printed.
3775735Snate@binkert.org         */
3785314Sstever@gmail.com        void pushLabel(const std::string &lbl,
3795314Sstever@gmail.com                       const std::string &prefix = "  ");
3805735Snate@binkert.org
3815735Snate@binkert.org        /**
3825735Snate@binkert.org         * Pop a label off the label stack.
3835735Snate@binkert.org         */
3845314Sstever@gmail.com        void popLabel();
3855735Snate@binkert.org
3865735Snate@binkert.org        /**
3875735Snate@binkert.org         * Print all of the pending unprinted labels on the
3885315Sstever@gmail.com         * stack. Called by printObj(), so normally not called by
3895735Snate@binkert.org         * users unless bypassing printObj().
3905735Snate@binkert.org         */
3915314Sstever@gmail.com        void printLabels();
3925735Snate@binkert.org
3935735Snate@binkert.org        /**
3945735Snate@binkert.org         * Print a Printable object to os, because it matched the
3955735Snate@binkert.org         * address on a PrintReq.
3965735Snate@binkert.org         */
3975314Sstever@gmail.com        void printObj(Printable *obj);
3985314Sstever@gmail.com    };
3995314Sstever@gmail.com
4005735Snate@binkert.org    /**
4015735Snate@binkert.org     * This packet's sender state.  Devices should use dynamic_cast<>
4025735Snate@binkert.org     * to cast to the state appropriate to the sender.  The intent of
4035735Snate@binkert.org     * this variable is to allow a device to attach extra information
4045735Snate@binkert.org     * to a request.  A response packet must return the sender state
4055735Snate@binkert.org     * that was attached to the original request (even if a new packet
4065735Snate@binkert.org     * is created).
4075735Snate@binkert.org     */
4082662Sstever@eecs.umich.edu    SenderState *senderState;
4092641Sstever@eecs.umich.edu
4105735Snate@binkert.org    /// Return the string name of the cmd field (for debugging and
4115735Snate@binkert.org    /// tracing).
4124022Sstever@eecs.umich.edu    const std::string &cmdString() const { return cmd.toString(); }
4132811Srdreslin@umich.edu
4145735Snate@binkert.org    /// Return the index of this command.
4154022Sstever@eecs.umich.edu    inline int cmdToIndex() const { return cmd.toInt(); }
4162811Srdreslin@umich.edu
4174022Sstever@eecs.umich.edu    bool isRead() const         { return cmd.isRead(); }
4187465Ssteve.reinhardt@amd.com    bool isWrite() const        { return cmd.isWrite(); }
4197465Ssteve.reinhardt@amd.com    bool isUpgrade()  const     { return cmd.isUpgrade(); }
4204022Sstever@eecs.umich.edu    bool isRequest() const      { return cmd.isRequest(); }
4214022Sstever@eecs.umich.edu    bool isResponse() const     { return cmd.isResponse(); }
4224870Sstever@eecs.umich.edu    bool needsExclusive() const { return cmd.needsExclusive(); }
4234022Sstever@eecs.umich.edu    bool needsResponse() const  { return cmd.needsResponse(); }
4244022Sstever@eecs.umich.edu    bool isInvalidate() const   { return cmd.isInvalidate(); }
4254022Sstever@eecs.umich.edu    bool hasData() const        { return cmd.hasData(); }
4264040Ssaidi@eecs.umich.edu    bool isReadWrite() const    { return cmd.isReadWrite(); }
4276102Sgblack@eecs.umich.edu    bool isLLSC() const         { return cmd.isLLSC(); }
4284870Sstever@eecs.umich.edu    bool isError() const        { return cmd.isError(); }
4295314Sstever@gmail.com    bool isPrint() const        { return cmd.isPrint(); }
4308184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return cmd.isFlush(); }
4312812Srdreslin@umich.edu
4324870Sstever@eecs.umich.edu    // Snoop flags
4335735Snate@binkert.org    void assertMemInhibit()     { flags.set(MEM_INHIBIT); }
4345764Snate@binkert.org    bool memInhibitAsserted()   { return flags.isSet(MEM_INHIBIT); }
4355735Snate@binkert.org    void assertShared()         { flags.set(SHARED); }
4365764Snate@binkert.org    bool sharedAsserted()       { return flags.isSet(SHARED); }
4374870Sstever@eecs.umich.edu
4384895Sstever@eecs.umich.edu    // Special control flags
4395735Snate@binkert.org    void setExpressSnoop()      { flags.set(EXPRESS_SNOOP); }
4405764Snate@binkert.org    bool isExpressSnoop()       { return flags.isSet(EXPRESS_SNOOP); }
4415735Snate@binkert.org    void setSupplyExclusive()   { flags.set(SUPPLY_EXCLUSIVE); }
4427687Ssteve.reinhardt@amd.com    void clearSupplyExclusive() { flags.clear(SUPPLY_EXCLUSIVE); }
4435764Snate@binkert.org    bool isSupplyExclusive()    { return flags.isSet(SUPPLY_EXCLUSIVE); }
4448436SBrad.Beckmann@amd.com    void setSuppressFuncError() { flags.set(SUPPRESS_FUNC_ERROR); }
4458436SBrad.Beckmann@amd.com    bool suppressFuncError()    { return flags.isSet(SUPPRESS_FUNC_ERROR); }
4464895Sstever@eecs.umich.edu
4474870Sstever@eecs.umich.edu    // Network error conditions... encapsulate them as methods since
4484870Sstever@eecs.umich.edu    // their encoding keeps changing (from result field to command
4494870Sstever@eecs.umich.edu    // field, etc.)
4505735Snate@binkert.org    void
4515735Snate@binkert.org    setNacked()
4525735Snate@binkert.org    {
4535735Snate@binkert.org        assert(isResponse());
4545735Snate@binkert.org        cmd = MemCmd::NetworkNackError;
4555735Snate@binkert.org    }
4565735Snate@binkert.org
4575735Snate@binkert.org    void
4585735Snate@binkert.org    setBadAddress()
4595735Snate@binkert.org    {
4605735Snate@binkert.org        assert(isResponse());
4615735Snate@binkert.org        cmd = MemCmd::BadAddressError;
4625735Snate@binkert.org    }
4635735Snate@binkert.org
4645735Snate@binkert.org    bool wasNacked() const     { return cmd == MemCmd::NetworkNackError; }
4655735Snate@binkert.org    bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; }
4664986Ssaidi@eecs.umich.edu    void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
4672814Srdreslin@umich.edu
4686768SBrad.Beckmann@amd.com    bool isSrcValid() { return flags.isSet(VALID_SRC); }
4695735Snate@binkert.org    /// Accessor function to get the source index of the packet.
4705764Snate@binkert.org    NodeID getSrc() const    { assert(flags.isSet(VALID_SRC)); return src; }
4715735Snate@binkert.org    /// Accessor function to set the source index of the packet.
4725735Snate@binkert.org    void setSrc(NodeID _src) { src = _src; flags.set(VALID_SRC); }
4735735Snate@binkert.org    /// Reset source field, e.g. to retransmit packet on different bus.
4745735Snate@binkert.org    void clearSrc() { flags.clear(VALID_SRC); }
4752641Sstever@eecs.umich.edu
4766768SBrad.Beckmann@amd.com    bool isDestValid() { return flags.isSet(VALID_DST); }
4775735Snate@binkert.org    /// Accessor function for the destination index of the packet.
4785764Snate@binkert.org    NodeID getDest() const     { assert(flags.isSet(VALID_DST)); return dest; }
4795735Snate@binkert.org    /// Accessor function to set the destination index of the packet.
4805735Snate@binkert.org    void setDest(NodeID _dest) { dest = _dest; flags.set(VALID_DST); }
4812381SN/A
4825764Snate@binkert.org    Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; }
4836227Snate@binkert.org    unsigned getSize() const  { assert(flags.isSet(VALID_SIZE)); return size; }
4845735Snate@binkert.org    Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); }
4852549SN/A
4865735Snate@binkert.org    /**
4877550SBrad.Beckmann@amd.com     * It has been determined that the SC packet should successfully update
4887550SBrad.Beckmann@amd.com     * memory.  Therefore, convert this SC packet to a normal write.
4897550SBrad.Beckmann@amd.com     */
4907550SBrad.Beckmann@amd.com    void
4917550SBrad.Beckmann@amd.com    convertScToWrite()
4927550SBrad.Beckmann@amd.com    {
4937550SBrad.Beckmann@amd.com        assert(isLLSC());
4947550SBrad.Beckmann@amd.com        assert(isWrite());
4957550SBrad.Beckmann@amd.com        cmd = MemCmd::WriteReq;
4967550SBrad.Beckmann@amd.com    }
4977550SBrad.Beckmann@amd.com
4987550SBrad.Beckmann@amd.com    /**
4997550SBrad.Beckmann@amd.com     * When ruby is in use, Ruby will monitor the cache line and thus M5
5007550SBrad.Beckmann@amd.com     * phys memory should treat LL ops as normal reads.
5017550SBrad.Beckmann@amd.com     */
5027550SBrad.Beckmann@amd.com    void
5037550SBrad.Beckmann@amd.com    convertLlToRead()
5047550SBrad.Beckmann@amd.com    {
5057550SBrad.Beckmann@amd.com        assert(isLLSC());
5067550SBrad.Beckmann@amd.com        assert(isRead());
5077550SBrad.Beckmann@amd.com        cmd = MemCmd::ReadReq;
5087550SBrad.Beckmann@amd.com    }
5097550SBrad.Beckmann@amd.com
5107550SBrad.Beckmann@amd.com    /**
5115735Snate@binkert.org     * Constructor.  Note that a Request object must be constructed
5125735Snate@binkert.org     * first, but the Requests's physical address and size fields need
5135735Snate@binkert.org     * not be valid. The command and destination addresses must be
5145735Snate@binkert.org     * supplied.
5155735Snate@binkert.org     */
5165735Snate@binkert.org    Packet(Request *_req, MemCmd _cmd, NodeID _dest)
5175745Snate@binkert.org        :  flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
5188668Sgeoffrey.blake@arm.com           dest(_dest), bytesValidStart(0), bytesValidEnd(0),
5198668Sgeoffrey.blake@arm.com           time(curTick()), senderState(NULL)
5202641Sstever@eecs.umich.edu    {
5216104Ssteve.reinhardt@amd.com        if (req->hasPaddr()) {
5226104Ssteve.reinhardt@amd.com            addr = req->getPaddr();
5236104Ssteve.reinhardt@amd.com            flags.set(VALID_ADDR);
5246104Ssteve.reinhardt@amd.com        }
5256104Ssteve.reinhardt@amd.com        if (req->hasSize()) {
5266104Ssteve.reinhardt@amd.com            size = req->getSize();
5276104Ssteve.reinhardt@amd.com            flags.set(VALID_SIZE);
5286104Ssteve.reinhardt@amd.com        }
5292813Srdreslin@umich.edu    }
5302813Srdreslin@umich.edu
5315735Snate@binkert.org    /**
5325735Snate@binkert.org     * Alternate constructor if you are trying to create a packet with
5335735Snate@binkert.org     * a request that is for a whole block, not the address from the
5345735Snate@binkert.org     * req.  this allows for overriding the size/addr of the req.
5355735Snate@binkert.org     */
5365735Snate@binkert.org    Packet(Request *_req, MemCmd _cmd, NodeID _dest, int _blkSize)
5375745Snate@binkert.org        :  flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
5388668Sgeoffrey.blake@arm.com           dest(_dest), bytesValidStart(0), bytesValidEnd(0),
5398668Sgeoffrey.blake@arm.com           time(curTick()), senderState(NULL)
5402813Srdreslin@umich.edu    {
5416104Ssteve.reinhardt@amd.com        if (req->hasPaddr()) {
5426104Ssteve.reinhardt@amd.com            addr = req->getPaddr() & ~(_blkSize - 1);
5436104Ssteve.reinhardt@amd.com            flags.set(VALID_ADDR);
5446104Ssteve.reinhardt@amd.com        }
5456104Ssteve.reinhardt@amd.com        size = _blkSize;
5466104Ssteve.reinhardt@amd.com        flags.set(VALID_SIZE);
5474626Sstever@eecs.umich.edu    }
5484626Sstever@eecs.umich.edu
5495735Snate@binkert.org    /**
5505735Snate@binkert.org     * Alternate constructor for copying a packet.  Copy all fields
5514887Sstever@eecs.umich.edu     * *except* if the original packet's data was dynamic, don't copy
5524887Sstever@eecs.umich.edu     * that, as we can't guarantee that the new packet's lifetime is
5534887Sstever@eecs.umich.edu     * less than that of the original packet.  In this case the new
5545735Snate@binkert.org     * packet should allocate its own data.
5555735Snate@binkert.org     */
5565735Snate@binkert.org    Packet(Packet *pkt, bool clearFlags = false)
5575735Snate@binkert.org        :  cmd(pkt->cmd), req(pkt->req),
5585764Snate@binkert.org           data(pkt->flags.isSet(STATIC_DATA) ? pkt->data : NULL),
5595735Snate@binkert.org           addr(pkt->addr), size(pkt->size), src(pkt->src), dest(pkt->dest),
5608668Sgeoffrey.blake@arm.com           bytesValidStart(pkt->bytesValidStart), bytesValidEnd(pkt->bytesValidEnd),
5617823Ssteve.reinhardt@amd.com           time(curTick()), senderState(pkt->senderState)
5624626Sstever@eecs.umich.edu    {
5635735Snate@binkert.org        if (!clearFlags)
5645735Snate@binkert.org            flags.set(pkt->flags & COPY_FLAGS);
5655735Snate@binkert.org
5665735Snate@binkert.org        flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE|VALID_SRC|VALID_DST));
5675735Snate@binkert.org        flags.set(pkt->flags & STATIC_DATA);
5688668Sgeoffrey.blake@arm.com
5692641Sstever@eecs.umich.edu    }
5702549SN/A
5715735Snate@binkert.org    /**
5725735Snate@binkert.org     * clean up packet variables
5735735Snate@binkert.org     */
5742566SN/A    ~Packet()
5755387Sstever@gmail.com    {
5765387Sstever@gmail.com        // If this is a request packet for which there's no response,
5775387Sstever@gmail.com        // delete the request object here, since the requester will
5785387Sstever@gmail.com        // never get the chance.
5795387Sstever@gmail.com        if (req && isRequest() && !needsResponse())
5805387Sstever@gmail.com            delete req;
5815735Snate@binkert.org        deleteData();
5825387Sstever@gmail.com    }
5832566SN/A
5845735Snate@binkert.org    /**
5855735Snate@binkert.org     * Reinitialize packet address and size from the associated
5865735Snate@binkert.org     * Request object, and reset other fields that may have been
5875735Snate@binkert.org     * modified by a previous transaction.  Typically called when a
5885735Snate@binkert.org     * statically allocated Request/Packet pair is reused for multiple
5895735Snate@binkert.org     * transactions.
5905735Snate@binkert.org     */
5915735Snate@binkert.org    void
5925735Snate@binkert.org    reinitFromRequest()
5935735Snate@binkert.org    {
5946104Ssteve.reinhardt@amd.com        assert(req->hasPaddr());
5954870Sstever@eecs.umich.edu        flags = 0;
5966104Ssteve.reinhardt@amd.com        addr = req->getPaddr();
5976104Ssteve.reinhardt@amd.com        size = req->getSize();
5986223Snate@binkert.org        time = req->time();
5995735Snate@binkert.org
6005735Snate@binkert.org        flags.set(VALID_ADDR|VALID_SIZE);
6015735Snate@binkert.org        deleteData();
6022662Sstever@eecs.umich.edu    }
6032566SN/A
6044626Sstever@eecs.umich.edu    /**
6054626Sstever@eecs.umich.edu     * Take a request packet and modify it in place to be suitable for
6064626Sstever@eecs.umich.edu     * returning as a response to that request.  The source and
6074626Sstever@eecs.umich.edu     * destination fields are *not* modified, as is appropriate for
6084626Sstever@eecs.umich.edu     * atomic accesses.
6094626Sstever@eecs.umich.edu     */
6105735Snate@binkert.org    void
6115735Snate@binkert.org    makeResponse()
6124626Sstever@eecs.umich.edu    {
6132662Sstever@eecs.umich.edu        assert(needsResponse());
6142855Srdreslin@umich.edu        assert(isRequest());
6154986Ssaidi@eecs.umich.edu        origCmd = cmd;
6164022Sstever@eecs.umich.edu        cmd = cmd.responseCommand();
6175745Snate@binkert.org
6187464Ssteve.reinhardt@amd.com        // responses are never express, even if the snoop that
6197464Ssteve.reinhardt@amd.com        // triggered them was
6207464Ssteve.reinhardt@amd.com        flags.clear(EXPRESS_SNOOP);
6217464Ssteve.reinhardt@amd.com
6225745Snate@binkert.org        dest = src;
6235764Snate@binkert.org        flags.set(VALID_DST, flags.isSet(VALID_SRC));
6245745Snate@binkert.org        flags.clear(VALID_SRC);
6252641Sstever@eecs.umich.edu    }
6262641Sstever@eecs.umich.edu
6275735Snate@binkert.org    void
6285735Snate@binkert.org    makeAtomicResponse()
6294870Sstever@eecs.umich.edu    {
6304870Sstever@eecs.umich.edu        makeResponse();
6314870Sstever@eecs.umich.edu    }
6324870Sstever@eecs.umich.edu
6335735Snate@binkert.org    void
6345735Snate@binkert.org    makeTimingResponse()
6353348Sbinkertn@umich.edu    {
6364870Sstever@eecs.umich.edu        makeResponse();
6373135Srdreslin@umich.edu    }
6383135Srdreslin@umich.edu
6398436SBrad.Beckmann@amd.com    void
6408436SBrad.Beckmann@amd.com    setFunctionalResponseStatus(bool success)
6418436SBrad.Beckmann@amd.com    {
6428436SBrad.Beckmann@amd.com        if (!success) {
6438436SBrad.Beckmann@amd.com            if (isWrite()) {
6448436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalWriteError;
6458436SBrad.Beckmann@amd.com            } else {
6468436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalReadError;
6478436SBrad.Beckmann@amd.com            }
6488436SBrad.Beckmann@amd.com        }
6498436SBrad.Beckmann@amd.com    }
6508436SBrad.Beckmann@amd.com
6513348Sbinkertn@umich.edu    /**
6523348Sbinkertn@umich.edu     * Take a request packet that has been returned as NACKED and
6533348Sbinkertn@umich.edu     * modify it so that it can be sent out again. Only packets that
6543348Sbinkertn@umich.edu     * need a response can be NACKED, so verify that that is true.
6553348Sbinkertn@umich.edu     */
6563348Sbinkertn@umich.edu    void
6573348Sbinkertn@umich.edu    reinitNacked()
6583348Sbinkertn@umich.edu    {
6594870Sstever@eecs.umich.edu        assert(wasNacked());
6604870Sstever@eecs.umich.edu        cmd = origCmd;
6614870Sstever@eecs.umich.edu        assert(needsResponse());
6624870Sstever@eecs.umich.edu        setDest(Broadcast);
6632685Ssaidi@eecs.umich.edu    }
6642685Ssaidi@eecs.umich.edu
6657006Snate@binkert.org    void
6667006Snate@binkert.org    setSize(unsigned size)
6677006Snate@binkert.org    {
6687006Snate@binkert.org        assert(!flags.isSet(VALID_SIZE));
6697006Snate@binkert.org
6707006Snate@binkert.org        this->size = size;
6717006Snate@binkert.org        flags.set(VALID_SIZE);
6727006Snate@binkert.org    }
6737006Snate@binkert.org
6742685Ssaidi@eecs.umich.edu
6753348Sbinkertn@umich.edu    /**
6763348Sbinkertn@umich.edu     * Set the data pointer to the following value that should not be
6773348Sbinkertn@umich.edu     * freed.
6782566SN/A     */
6792566SN/A    template <typename T>
6803348Sbinkertn@umich.edu    void
6813348Sbinkertn@umich.edu    dataStatic(T *p)
6823348Sbinkertn@umich.edu    {
6835764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
6843348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
6855735Snate@binkert.org        flags.set(STATIC_DATA);
6863348Sbinkertn@umich.edu    }
6872566SN/A
6883348Sbinkertn@umich.edu    /**
6893348Sbinkertn@umich.edu     * Set the data pointer to a value that should have delete []
6903348Sbinkertn@umich.edu     * called on it.
6913348Sbinkertn@umich.edu     */
6922566SN/A    template <typename T>
6933348Sbinkertn@umich.edu    void
6943348Sbinkertn@umich.edu    dataDynamicArray(T *p)
6953348Sbinkertn@umich.edu    {
6965764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
6973348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
6985735Snate@binkert.org        flags.set(DYNAMIC_DATA|ARRAY_DATA);
6993348Sbinkertn@umich.edu    }
7003348Sbinkertn@umich.edu
7013348Sbinkertn@umich.edu    /**
7023348Sbinkertn@umich.edu     * set the data pointer to a value that should have delete called
7033348Sbinkertn@umich.edu     * on it.
7043348Sbinkertn@umich.edu     */
7053348Sbinkertn@umich.edu    template <typename T>
7063348Sbinkertn@umich.edu    void
7073348Sbinkertn@umich.edu    dataDynamic(T *p)
7083348Sbinkertn@umich.edu    {
7095764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
7103348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
7115735Snate@binkert.org        flags.set(DYNAMIC_DATA);
7123348Sbinkertn@umich.edu    }
7133348Sbinkertn@umich.edu
7145735Snate@binkert.org    /**
7155735Snate@binkert.org     * get a pointer to the data ptr.
7165735Snate@binkert.org     */
7173348Sbinkertn@umich.edu    template <typename T>
7183348Sbinkertn@umich.edu    T*
7197915SBrad.Beckmann@amd.com    getPtr(bool null_ok = false)
7203348Sbinkertn@umich.edu    {
7217915SBrad.Beckmann@amd.com        assert(null_ok || flags.isSet(STATIC_DATA|DYNAMIC_DATA));
7223348Sbinkertn@umich.edu        return (T*)data;
7233348Sbinkertn@umich.edu    }
7242566SN/A
7255735Snate@binkert.org    /**
7265735Snate@binkert.org     * return the value of what is pointed to in the packet.
7275735Snate@binkert.org     */
7282566SN/A    template <typename T>
7292592SN/A    T get();
7302566SN/A
7315735Snate@binkert.org    /**
7325735Snate@binkert.org     * set the value in the data pointer to v.
7335735Snate@binkert.org     */
7342566SN/A    template <typename T>
7352592SN/A    void set(T v);
7362566SN/A
7373348Sbinkertn@umich.edu    /**
7384626Sstever@eecs.umich.edu     * Copy data into the packet from the provided pointer.
7394626Sstever@eecs.umich.edu     */
7405735Snate@binkert.org    void
7415735Snate@binkert.org    setData(uint8_t *p)
7424626Sstever@eecs.umich.edu    {
7437691SAli.Saidi@ARM.com        if (p != getPtr<uint8_t>())
7447691SAli.Saidi@ARM.com            std::memcpy(getPtr<uint8_t>(), p, getSize());
7454626Sstever@eecs.umich.edu    }
7464626Sstever@eecs.umich.edu
7474626Sstever@eecs.umich.edu    /**
7484626Sstever@eecs.umich.edu     * Copy data into the packet from the provided block pointer,
7494626Sstever@eecs.umich.edu     * which is aligned to the given block size.
7504626Sstever@eecs.umich.edu     */
7515735Snate@binkert.org    void
7525735Snate@binkert.org    setDataFromBlock(uint8_t *blk_data, int blkSize)
7534626Sstever@eecs.umich.edu    {
7544626Sstever@eecs.umich.edu        setData(blk_data + getOffset(blkSize));
7554626Sstever@eecs.umich.edu    }
7564626Sstever@eecs.umich.edu
7574626Sstever@eecs.umich.edu    /**
7584626Sstever@eecs.umich.edu     * Copy data from the packet to the provided block pointer, which
7594626Sstever@eecs.umich.edu     * is aligned to the given block size.
7604626Sstever@eecs.umich.edu     */
7615735Snate@binkert.org    void
7625735Snate@binkert.org    writeData(uint8_t *p)
7634626Sstever@eecs.umich.edu    {
7644626Sstever@eecs.umich.edu        std::memcpy(p, getPtr<uint8_t>(), getSize());
7654626Sstever@eecs.umich.edu    }
7664626Sstever@eecs.umich.edu
7674626Sstever@eecs.umich.edu    /**
7684626Sstever@eecs.umich.edu     * Copy data from the packet to the memory at the provided pointer.
7694626Sstever@eecs.umich.edu     */
7705735Snate@binkert.org    void
7715735Snate@binkert.org    writeDataToBlock(uint8_t *blk_data, int blkSize)
7724626Sstever@eecs.umich.edu    {
7734626Sstever@eecs.umich.edu        writeData(blk_data + getOffset(blkSize));
7744626Sstever@eecs.umich.edu    }
7754626Sstever@eecs.umich.edu
7764626Sstever@eecs.umich.edu    /**
7773348Sbinkertn@umich.edu     * delete the data pointed to in the data pointer. Ok to call to
7783348Sbinkertn@umich.edu     * matter how data was allocted.
7793348Sbinkertn@umich.edu     */
7805735Snate@binkert.org    void
7815735Snate@binkert.org    deleteData()
7825735Snate@binkert.org    {
7835764Snate@binkert.org        if (flags.isSet(ARRAY_DATA))
7845735Snate@binkert.org            delete [] data;
7855764Snate@binkert.org        else if (flags.isSet(DYNAMIC_DATA))
7865735Snate@binkert.org            delete data;
7875735Snate@binkert.org
7885735Snate@binkert.org        flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA);
7895735Snate@binkert.org        data = NULL;
7905735Snate@binkert.org    }
7912566SN/A
7922566SN/A    /** If there isn't data in the packet, allocate some. */
7935735Snate@binkert.org    void
7945735Snate@binkert.org    allocate()
7955735Snate@binkert.org    {
7965735Snate@binkert.org        if (data) {
7975764Snate@binkert.org            assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
7985745Snate@binkert.org            return;
7995735Snate@binkert.org        }
8005745Snate@binkert.org
8015764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
8025745Snate@binkert.org        flags.set(DYNAMIC_DATA|ARRAY_DATA);
8035745Snate@binkert.org        data = new uint8_t[getSize()];
8045735Snate@binkert.org    }
8055735Snate@binkert.org
8064626Sstever@eecs.umich.edu    /**
8074626Sstever@eecs.umich.edu     * Check a functional request against a memory value represented
8084626Sstever@eecs.umich.edu     * by a base/size pair and an associated data array.  If the
8094626Sstever@eecs.umich.edu     * functional request is a read, it may be satisfied by the memory
8104626Sstever@eecs.umich.edu     * value.  If the functional request is a write, it may update the
8114626Sstever@eecs.umich.edu     * memory value.
8124626Sstever@eecs.umich.edu     */
8135314Sstever@gmail.com    bool checkFunctional(Printable *obj, Addr base, int size, uint8_t *data);
8144626Sstever@eecs.umich.edu
8154626Sstever@eecs.umich.edu    /**
8164626Sstever@eecs.umich.edu     * Check a functional request against a memory value stored in
8175315Sstever@gmail.com     * another packet (i.e. an in-transit request or response).
8184626Sstever@eecs.umich.edu     */
8195735Snate@binkert.org    bool
8205735Snate@binkert.org    checkFunctional(PacketPtr other)
8215735Snate@binkert.org    {
8225735Snate@binkert.org        uint8_t *data = other->hasData() ? other->getPtr<uint8_t>() : NULL;
8235735Snate@binkert.org        return checkFunctional(other, other->getAddr(), other->getSize(),
8245735Snate@binkert.org                               data);
8254626Sstever@eecs.umich.edu    }
8265314Sstever@gmail.com
8275315Sstever@gmail.com    /**
8285315Sstever@gmail.com     * Push label for PrintReq (safe to call unconditionally).
8295315Sstever@gmail.com     */
8305735Snate@binkert.org    void
8315735Snate@binkert.org    pushLabel(const std::string &lbl)
8325735Snate@binkert.org    {
8335735Snate@binkert.org        if (isPrint())
8345735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->pushLabel(lbl);
8355314Sstever@gmail.com    }
8365314Sstever@gmail.com
8375315Sstever@gmail.com    /**
8385315Sstever@gmail.com     * Pop label for PrintReq (safe to call unconditionally).
8395315Sstever@gmail.com     */
8405735Snate@binkert.org    void
8415735Snate@binkert.org    popLabel()
8425735Snate@binkert.org    {
8435735Snate@binkert.org        if (isPrint())
8445735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->popLabel();
8455314Sstever@gmail.com    }
8465314Sstever@gmail.com
8475314Sstever@gmail.com    void print(std::ostream &o, int verbosity = 0,
8485314Sstever@gmail.com               const std::string &prefix = "") const;
8492381SN/A};
8502381SN/A
8512381SN/A#endif //__MEM_PACKET_HH
852