packet.hh revision 8949
12381SN/A/*
28949Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited
38949Sandreas.hansson@arm.com * All rights reserved
48949Sandreas.hansson@arm.com *
58949Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68949Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78949Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88949Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98949Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108949Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118949Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128949Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138949Sandreas.hansson@arm.com *
142592SN/A * Copyright (c) 2006 The Regents of The University of Michigan
157636Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
162381SN/A * All rights reserved.
172381SN/A *
182381SN/A * Redistribution and use in source and binary forms, with or without
192381SN/A * modification, are permitted provided that the following conditions are
202381SN/A * met: redistributions of source code must retain the above copyright
212381SN/A * notice, this list of conditions and the following disclaimer;
222381SN/A * redistributions in binary form must reproduce the above copyright
232381SN/A * notice, this list of conditions and the following disclaimer in the
242381SN/A * documentation and/or other materials provided with the distribution;
252381SN/A * neither the name of the copyright holders nor the names of its
262381SN/A * contributors may be used to endorse or promote products derived from
272381SN/A * this software without specific prior written permission.
282381SN/A *
292381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402665Ssaidi@eecs.umich.edu *
412665Ssaidi@eecs.umich.edu * Authors: Ron Dreslinski
422665Ssaidi@eecs.umich.edu *          Steve Reinhardt
432665Ssaidi@eecs.umich.edu *          Ali Saidi
442381SN/A */
452381SN/A
462381SN/A/**
472381SN/A * @file
482662Sstever@eecs.umich.edu * Declaration of the Packet class.
492381SN/A */
502381SN/A
512381SN/A#ifndef __MEM_PACKET_HH__
522381SN/A#define __MEM_PACKET_HH__
532381SN/A
548229Snate@binkert.org#include <bitset>
553348Sbinkertn@umich.edu#include <cassert>
563348Sbinkertn@umich.edu#include <list>
573348Sbinkertn@umich.edu
585735Snate@binkert.org#include "base/cast.hh"
594024Sbinkertn@umich.edu#include "base/compiler.hh"
604610Ssaidi@eecs.umich.edu#include "base/fast_alloc.hh"
615735Snate@binkert.org#include "base/flags.hh"
623940Ssaidi@eecs.umich.edu#include "base/misc.hh"
635314Sstever@gmail.com#include "base/printable.hh"
646216Snate@binkert.org#include "base/types.hh"
652392SN/A#include "mem/request.hh"
664167Sbinkertn@umich.edu#include "sim/core.hh"
672394SN/A
688737Skoansin.tan@gmail.comclass Packet;
693349Sbinkertn@umich.edutypedef Packet *PacketPtr;
702394SN/Atypedef uint8_t* PacketDataPtr;
712812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList;
722812Srdreslin@umich.edu
734022Sstever@eecs.umich.educlass MemCmd
744022Sstever@eecs.umich.edu{
755735Snate@binkert.org    friend class Packet;
765735Snate@binkert.org
774022Sstever@eecs.umich.edu  public:
785735Snate@binkert.org    /**
795735Snate@binkert.org     * List of all commands associated with a packet.
805735Snate@binkert.org     */
814022Sstever@eecs.umich.edu    enum Command
824022Sstever@eecs.umich.edu    {
834022Sstever@eecs.umich.edu        InvalidCmd,
844022Sstever@eecs.umich.edu        ReadReq,
854473Sstever@eecs.umich.edu        ReadResp,
865319Sstever@gmail.com        ReadRespWithInvalidate,
874022Sstever@eecs.umich.edu        WriteReq,
884022Sstever@eecs.umich.edu        WriteResp,
894022Sstever@eecs.umich.edu        Writeback,
904022Sstever@eecs.umich.edu        SoftPFReq,
914022Sstever@eecs.umich.edu        HardPFReq,
924022Sstever@eecs.umich.edu        SoftPFResp,
934022Sstever@eecs.umich.edu        HardPFResp,
944022Sstever@eecs.umich.edu        WriteInvalidateReq,
954022Sstever@eecs.umich.edu        WriteInvalidateResp,
964022Sstever@eecs.umich.edu        UpgradeReq,
977465Ssteve.reinhardt@amd.com        SCUpgradeReq,           // Special "weak" upgrade for StoreCond
984628Sstever@eecs.umich.edu        UpgradeResp,
997465Ssteve.reinhardt@amd.com        SCUpgradeFailReq,       // Failed SCUpgradeReq in MSHR (never sent)
1007465Ssteve.reinhardt@amd.com        UpgradeFailResp,        // Valid for SCUpgradeReq only
1014022Sstever@eecs.umich.edu        ReadExReq,
1024022Sstever@eecs.umich.edu        ReadExResp,
1034626Sstever@eecs.umich.edu        LoadLockedReq,
1044626Sstever@eecs.umich.edu        StoreCondReq,
1057669Ssteve.reinhardt@amd.com        StoreCondFailReq,       // Failed StoreCondReq in MSHR (never sent)
1064626Sstever@eecs.umich.edu        StoreCondResp,
1074040Ssaidi@eecs.umich.edu        SwapReq,
1084040Ssaidi@eecs.umich.edu        SwapResp,
1095650Sgblack@eecs.umich.edu        MessageReq,
1105650Sgblack@eecs.umich.edu        MessageResp,
1114870Sstever@eecs.umich.edu        // Error responses
1124870Sstever@eecs.umich.edu        // @TODO these should be classified as responses rather than
1134870Sstever@eecs.umich.edu        // requests; coding them as requests initially for backwards
1144870Sstever@eecs.umich.edu        // compatibility
1154870Sstever@eecs.umich.edu        NetworkNackError,  // nacked at network layer (not by protocol)
1164870Sstever@eecs.umich.edu        InvalidDestError,  // packet dest field invalid
1174870Sstever@eecs.umich.edu        BadAddressError,   // memory address invalid
1188436SBrad.Beckmann@amd.com        FunctionalReadError, // unable to fulfill functional read
1198436SBrad.Beckmann@amd.com        FunctionalWriteError, // unable to fulfill functional write
1205314Sstever@gmail.com        // Fake simulator-only commands
1215314Sstever@gmail.com        PrintReq,       // Print state matching address
1228184Ssomayeh@cs.wisc.edu        FlushReq,      //request for a cache flush
1238716Snilay@cs.wisc.edu        InvalidationReq,   // request for address to be invalidated from lsq
1244022Sstever@eecs.umich.edu        NUM_MEM_CMDS
1254022Sstever@eecs.umich.edu    };
1264022Sstever@eecs.umich.edu
1274022Sstever@eecs.umich.edu  private:
1285735Snate@binkert.org    /**
1295735Snate@binkert.org     * List of command attributes.
1305735Snate@binkert.org     */
1314022Sstever@eecs.umich.edu    enum Attribute
1324022Sstever@eecs.umich.edu    {
1334626Sstever@eecs.umich.edu        IsRead,         //!< Data flows from responder to requester
1344626Sstever@eecs.umich.edu        IsWrite,        //!< Data flows from requester to responder
1357465Ssteve.reinhardt@amd.com        IsUpgrade,
1364626Sstever@eecs.umich.edu        IsPrefetch,     //!< Not a demand access
1374022Sstever@eecs.umich.edu        IsInvalidate,
1384626Sstever@eecs.umich.edu        NeedsExclusive, //!< Requires exclusive copy to complete in-cache
1394626Sstever@eecs.umich.edu        IsRequest,      //!< Issued by requester
1404626Sstever@eecs.umich.edu        IsResponse,     //!< Issue by responder
1414626Sstever@eecs.umich.edu        NeedsResponse,  //!< Requester needs response from target
1424022Sstever@eecs.umich.edu        IsSWPrefetch,
1434022Sstever@eecs.umich.edu        IsHWPrefetch,
1446076Sgblack@eecs.umich.edu        IsLlsc,         //!< Alpha/MIPS LL or SC access
1454626Sstever@eecs.umich.edu        HasData,        //!< There is an associated payload
1464870Sstever@eecs.umich.edu        IsError,        //!< Error response
1475314Sstever@gmail.com        IsPrint,        //!< Print state matching address (for debugging)
1488184Ssomayeh@cs.wisc.edu        IsFlush,        //!< Flush the address from caches
1494022Sstever@eecs.umich.edu        NUM_COMMAND_ATTRIBUTES
1504022Sstever@eecs.umich.edu    };
1514022Sstever@eecs.umich.edu
1525735Snate@binkert.org    /**
1535735Snate@binkert.org     * Structure that defines attributes and other data associated
1545735Snate@binkert.org     * with a Command.
1555735Snate@binkert.org     */
1565735Snate@binkert.org    struct CommandInfo
1575735Snate@binkert.org    {
1585735Snate@binkert.org        /// Set of attribute flags.
1594022Sstever@eecs.umich.edu        const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
1605735Snate@binkert.org        /// Corresponding response for requests; InvalidCmd if no
1615735Snate@binkert.org        /// response is applicable.
1624022Sstever@eecs.umich.edu        const Command response;
1635735Snate@binkert.org        /// String representation (for printing)
1644022Sstever@eecs.umich.edu        const std::string str;
1654022Sstever@eecs.umich.edu    };
1664022Sstever@eecs.umich.edu
1675735Snate@binkert.org    /// Array to map Command enum to associated info.
1684022Sstever@eecs.umich.edu    static const CommandInfo commandInfo[];
1694022Sstever@eecs.umich.edu
1704022Sstever@eecs.umich.edu  private:
1714022Sstever@eecs.umich.edu
1724022Sstever@eecs.umich.edu    Command cmd;
1734022Sstever@eecs.umich.edu
1745735Snate@binkert.org    bool
1755735Snate@binkert.org    testCmdAttrib(MemCmd::Attribute attrib) const
1765735Snate@binkert.org    {
1774022Sstever@eecs.umich.edu        return commandInfo[cmd].attributes[attrib] != 0;
1784022Sstever@eecs.umich.edu    }
1794022Sstever@eecs.umich.edu
1804022Sstever@eecs.umich.edu  public:
1814022Sstever@eecs.umich.edu
1824022Sstever@eecs.umich.edu    bool isRead() const         { return testCmdAttrib(IsRead); }
1837465Ssteve.reinhardt@amd.com    bool isWrite() const        { return testCmdAttrib(IsWrite); }
1847465Ssteve.reinhardt@amd.com    bool isUpgrade() const      { return testCmdAttrib(IsUpgrade); }
1854022Sstever@eecs.umich.edu    bool isRequest() const      { return testCmdAttrib(IsRequest); }
1864022Sstever@eecs.umich.edu    bool isResponse() const     { return testCmdAttrib(IsResponse); }
1874870Sstever@eecs.umich.edu    bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); }
1884022Sstever@eecs.umich.edu    bool needsResponse() const  { return testCmdAttrib(NeedsResponse); }
1894022Sstever@eecs.umich.edu    bool isInvalidate() const   { return testCmdAttrib(IsInvalidate); }
1904022Sstever@eecs.umich.edu    bool hasData() const        { return testCmdAttrib(HasData); }
1914626Sstever@eecs.umich.edu    bool isReadWrite() const    { return isRead() && isWrite(); }
1926102Sgblack@eecs.umich.edu    bool isLLSC() const         { return testCmdAttrib(IsLlsc); }
1934870Sstever@eecs.umich.edu    bool isError() const        { return testCmdAttrib(IsError); }
1945314Sstever@gmail.com    bool isPrint() const        { return testCmdAttrib(IsPrint); }
1958184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return testCmdAttrib(IsFlush); }
1964022Sstever@eecs.umich.edu
1975735Snate@binkert.org    const Command
1985735Snate@binkert.org    responseCommand() const
1995735Snate@binkert.org    {
2004022Sstever@eecs.umich.edu        return commandInfo[cmd].response;
2014022Sstever@eecs.umich.edu    }
2024022Sstever@eecs.umich.edu
2035735Snate@binkert.org    /// Return the string to a cmd given by idx.
2045735Snate@binkert.org    const std::string &toString() const { return commandInfo[cmd].str; }
2054022Sstever@eecs.umich.edu    int toInt() const { return (int)cmd; }
2064022Sstever@eecs.umich.edu
2075735Snate@binkert.org    MemCmd(Command _cmd) : cmd(_cmd) { }
2085735Snate@binkert.org    MemCmd(int _cmd) : cmd((Command)_cmd) { }
2095735Snate@binkert.org    MemCmd() : cmd(InvalidCmd) { }
2104022Sstever@eecs.umich.edu
2115735Snate@binkert.org    bool operator==(MemCmd c2) const { return (cmd == c2.cmd); }
2125735Snate@binkert.org    bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); }
2134022Sstever@eecs.umich.edu};
2144022Sstever@eecs.umich.edu
2152381SN/A/**
2162662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in
2172662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache).  (In contrast, a
2182662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the
2192662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several
2202662Sstever@eecs.umich.edu * different Packets along the way.)
2212381SN/A */
2225314Sstever@gmail.comclass Packet : public FastAlloc, public Printable
2232381SN/A{
2242813Srdreslin@umich.edu  public:
2255735Snate@binkert.org    typedef uint32_t FlagsType;
2265735Snate@binkert.org    typedef ::Flags<FlagsType> Flags;
2275735Snate@binkert.org    typedef short NodeID;
2284022Sstever@eecs.umich.edu
2295735Snate@binkert.org  private:
2305735Snate@binkert.org    static const FlagsType PUBLIC_FLAGS           = 0x00000000;
2315735Snate@binkert.org    static const FlagsType PRIVATE_FLAGS          = 0x00007F0F;
2325735Snate@binkert.org    static const FlagsType COPY_FLAGS             = 0x0000000F;
2335735Snate@binkert.org
2345735Snate@binkert.org    static const FlagsType SHARED                 = 0x00000001;
2355735Snate@binkert.org    // Special control flags
2365735Snate@binkert.org    /// Special timing-mode atomic snoop for multi-level coherence.
2375735Snate@binkert.org    static const FlagsType EXPRESS_SNOOP          = 0x00000002;
2385735Snate@binkert.org    /// Does supplier have exclusive copy?
2395735Snate@binkert.org    /// Useful for multi-level coherence.
2405735Snate@binkert.org    static const FlagsType SUPPLY_EXCLUSIVE       = 0x00000004;
2415735Snate@binkert.org    // Snoop response flags
2425735Snate@binkert.org    static const FlagsType MEM_INHIBIT            = 0x00000008;
2435735Snate@binkert.org    /// Are the 'addr' and 'size' fields valid?
2445735Snate@binkert.org    static const FlagsType VALID_ADDR             = 0x00000100;
2455735Snate@binkert.org    static const FlagsType VALID_SIZE             = 0x00000200;
2465735Snate@binkert.org    /// Is the 'src' field valid?
2475735Snate@binkert.org    static const FlagsType VALID_SRC              = 0x00000400;
2485735Snate@binkert.org    static const FlagsType VALID_DST              = 0x00000800;
2495735Snate@binkert.org    /// Is the data pointer set to a value that shouldn't be freed
2505735Snate@binkert.org    /// when the packet is destroyed?
2515735Snate@binkert.org    static const FlagsType STATIC_DATA            = 0x00001000;
2525735Snate@binkert.org    /// The data pointer points to a value that should be freed when
2535735Snate@binkert.org    /// the packet is destroyed.
2545735Snate@binkert.org    static const FlagsType DYNAMIC_DATA           = 0x00002000;
2555735Snate@binkert.org    /// the data pointer points to an array (thus delete []) needs to
2565735Snate@binkert.org    /// be called on it rather than simply delete.
2575735Snate@binkert.org    static const FlagsType ARRAY_DATA             = 0x00004000;
2588436SBrad.Beckmann@amd.com    /// suppress the error if this packet encounters a functional
2598436SBrad.Beckmann@amd.com    /// access failure.
2608436SBrad.Beckmann@amd.com    static const FlagsType SUPPRESS_FUNC_ERROR    = 0x00008000;
2615735Snate@binkert.org
2625735Snate@binkert.org    Flags flags;
2635735Snate@binkert.org
2645735Snate@binkert.org  public:
2654022Sstever@eecs.umich.edu    typedef MemCmd::Command Command;
2664022Sstever@eecs.umich.edu
2675735Snate@binkert.org    /// The command field of the packet.
2684870Sstever@eecs.umich.edu    MemCmd cmd;
2694870Sstever@eecs.umich.edu
2705735Snate@binkert.org    /// A pointer to the original request.
2714870Sstever@eecs.umich.edu    RequestPtr req;
2724870Sstever@eecs.umich.edu
2732566SN/A  private:
2745735Snate@binkert.org   /**
2755735Snate@binkert.org    * A pointer to the data being transfered.  It can be differnt
2765735Snate@binkert.org    * sizes at each level of the heirarchy so it belongs in the
2775735Snate@binkert.org    * packet, not request. This may or may not be populated when a
2785735Snate@binkert.org    * responder recieves the packet. If not populated it memory should
2795735Snate@binkert.org    * be allocated.
2802566SN/A    */
2812566SN/A    PacketDataPtr data;
2822566SN/A
2835735Snate@binkert.org    /// The address of the request.  This address could be virtual or
2845735Snate@binkert.org    /// physical, depending on the system configuration.
2852381SN/A    Addr addr;
2862381SN/A
2875735Snate@binkert.org    /// The size of the request or transfer.
2886227Snate@binkert.org    unsigned size;
2892381SN/A
2905735Snate@binkert.org    /**
2915735Snate@binkert.org     * Device address (e.g., bus ID) of the source of the
2925735Snate@binkert.org     * transaction. The source is not responsible for setting this
2935735Snate@binkert.org     * field; it is set implicitly by the interconnect when the packet
2945735Snate@binkert.org     * is first sent.
2955735Snate@binkert.org     */
2965735Snate@binkert.org    NodeID src;
2972381SN/A
2985735Snate@binkert.org    /**
2995735Snate@binkert.org     * Device address (e.g., bus ID) of the destination of the
3005735Snate@binkert.org     * transaction. The special value Broadcast indicates that the
3015735Snate@binkert.org     * packet should be routed based on its address. This field is
3025735Snate@binkert.org     * initialized in the constructor and is thus always valid (unlike
3035735Snate@binkert.org     * addr, size, and src).
3045735Snate@binkert.org     */
3055735Snate@binkert.org    NodeID dest;
3062641Sstever@eecs.umich.edu
3075735Snate@binkert.org    /**
3085735Snate@binkert.org     * The original value of the command field.  Only valid when the
3094870Sstever@eecs.umich.edu     * current command field is an error condition; in that case, the
3104870Sstever@eecs.umich.edu     * previous contents of the command field are copied here.  This
3114870Sstever@eecs.umich.edu     * field is *not* set on non-error responses.
3124870Sstever@eecs.umich.edu     */
3134870Sstever@eecs.umich.edu    MemCmd origCmd;
3144870Sstever@eecs.umich.edu
3158668Sgeoffrey.blake@arm.com    /**
3168668Sgeoffrey.blake@arm.com     * These values specify the range of bytes found that satisfy a
3178668Sgeoffrey.blake@arm.com     * functional read.
3188668Sgeoffrey.blake@arm.com     */
3198668Sgeoffrey.blake@arm.com    uint16_t bytesValidStart;
3208668Sgeoffrey.blake@arm.com    uint16_t bytesValidEnd;
3218668Sgeoffrey.blake@arm.com
3222641Sstever@eecs.umich.edu  public:
3235735Snate@binkert.org    /// Used to calculate latencies for each packet.
3242811Srdreslin@umich.edu    Tick time;
3252811Srdreslin@umich.edu
3265735Snate@binkert.org    /// The time at which the packet will be fully transmitted
3273218Sgblack@eecs.umich.edu    Tick finishTime;
3283218Sgblack@eecs.umich.edu
3295735Snate@binkert.org    /// The time at which the first chunk of the packet will be transmitted
3303218Sgblack@eecs.umich.edu    Tick firstWordTime;
3313218Sgblack@eecs.umich.edu
3325735Snate@binkert.org    /**
3335735Snate@binkert.org     * A virtual base opaque structure used to hold state associated
3345735Snate@binkert.org     * with the packet but specific to the sending device (e.g., an
3355735Snate@binkert.org     * MSHR).  A pointer to this state is returned in the packet's
3365735Snate@binkert.org     * response so that the sender can quickly look up the state
3375735Snate@binkert.org     * needed to process it.  A specific subclass would be derived
3385735Snate@binkert.org     * from this to carry state specific to a particular sending
3395735Snate@binkert.org     * device.
3405735Snate@binkert.org     */
3415735Snate@binkert.org    struct SenderState
3425735Snate@binkert.org    {
3432641Sstever@eecs.umich.edu        virtual ~SenderState() {}
3442641Sstever@eecs.umich.edu    };
3452641Sstever@eecs.umich.edu
3465315Sstever@gmail.com    /**
3475315Sstever@gmail.com     * Object used to maintain state of a PrintReq.  The senderState
3485315Sstever@gmail.com     * field of a PrintReq should always be of this type.
3495315Sstever@gmail.com     */
3505735Snate@binkert.org    class PrintReqState : public SenderState, public FastAlloc
3515735Snate@binkert.org    {
3525735Snate@binkert.org      private:
3535735Snate@binkert.org        /**
3545735Snate@binkert.org         * An entry in the label stack.
3555735Snate@binkert.org         */
3565735Snate@binkert.org        struct LabelStackEntry
3575735Snate@binkert.org        {
3585314Sstever@gmail.com            const std::string label;
3595314Sstever@gmail.com            std::string *prefix;
3605314Sstever@gmail.com            bool labelPrinted;
3615735Snate@binkert.org            LabelStackEntry(const std::string &_label, std::string *_prefix);
3625314Sstever@gmail.com        };
3635314Sstever@gmail.com
3645314Sstever@gmail.com        typedef std::list<LabelStackEntry> LabelStack;
3655314Sstever@gmail.com        LabelStack labelStack;
3665314Sstever@gmail.com
3675314Sstever@gmail.com        std::string *curPrefixPtr;
3685314Sstever@gmail.com
3695314Sstever@gmail.com      public:
3705314Sstever@gmail.com        std::ostream &os;
3715314Sstever@gmail.com        const int verbosity;
3725314Sstever@gmail.com
3735314Sstever@gmail.com        PrintReqState(std::ostream &os, int verbosity = 0);
3745314Sstever@gmail.com        ~PrintReqState();
3755314Sstever@gmail.com
3765735Snate@binkert.org        /**
3775735Snate@binkert.org         * Returns the current line prefix.
3785735Snate@binkert.org         */
3795314Sstever@gmail.com        const std::string &curPrefix() { return *curPrefixPtr; }
3805315Sstever@gmail.com
3815735Snate@binkert.org        /**
3825735Snate@binkert.org         * Push a label onto the label stack, and prepend the given
3835315Sstever@gmail.com         * prefix string onto the current prefix.  Labels will only be
3845735Snate@binkert.org         * printed if an object within the label's scope is printed.
3855735Snate@binkert.org         */
3865314Sstever@gmail.com        void pushLabel(const std::string &lbl,
3875314Sstever@gmail.com                       const std::string &prefix = "  ");
3885735Snate@binkert.org
3895735Snate@binkert.org        /**
3905735Snate@binkert.org         * Pop a label off the label stack.
3915735Snate@binkert.org         */
3925314Sstever@gmail.com        void popLabel();
3935735Snate@binkert.org
3945735Snate@binkert.org        /**
3955735Snate@binkert.org         * Print all of the pending unprinted labels on the
3965315Sstever@gmail.com         * stack. Called by printObj(), so normally not called by
3975735Snate@binkert.org         * users unless bypassing printObj().
3985735Snate@binkert.org         */
3995314Sstever@gmail.com        void printLabels();
4005735Snate@binkert.org
4015735Snate@binkert.org        /**
4025735Snate@binkert.org         * Print a Printable object to os, because it matched the
4035735Snate@binkert.org         * address on a PrintReq.
4045735Snate@binkert.org         */
4055314Sstever@gmail.com        void printObj(Printable *obj);
4065314Sstever@gmail.com    };
4075314Sstever@gmail.com
4085735Snate@binkert.org    /**
4095735Snate@binkert.org     * This packet's sender state.  Devices should use dynamic_cast<>
4105735Snate@binkert.org     * to cast to the state appropriate to the sender.  The intent of
4115735Snate@binkert.org     * this variable is to allow a device to attach extra information
4125735Snate@binkert.org     * to a request.  A response packet must return the sender state
4135735Snate@binkert.org     * that was attached to the original request (even if a new packet
4145735Snate@binkert.org     * is created).
4155735Snate@binkert.org     */
4162662Sstever@eecs.umich.edu    SenderState *senderState;
4172641Sstever@eecs.umich.edu
4185735Snate@binkert.org    /// Return the string name of the cmd field (for debugging and
4195735Snate@binkert.org    /// tracing).
4204022Sstever@eecs.umich.edu    const std::string &cmdString() const { return cmd.toString(); }
4212811Srdreslin@umich.edu
4225735Snate@binkert.org    /// Return the index of this command.
4234022Sstever@eecs.umich.edu    inline int cmdToIndex() const { return cmd.toInt(); }
4242811Srdreslin@umich.edu
4254022Sstever@eecs.umich.edu    bool isRead() const         { return cmd.isRead(); }
4267465Ssteve.reinhardt@amd.com    bool isWrite() const        { return cmd.isWrite(); }
4277465Ssteve.reinhardt@amd.com    bool isUpgrade()  const     { return cmd.isUpgrade(); }
4284022Sstever@eecs.umich.edu    bool isRequest() const      { return cmd.isRequest(); }
4294022Sstever@eecs.umich.edu    bool isResponse() const     { return cmd.isResponse(); }
4304870Sstever@eecs.umich.edu    bool needsExclusive() const { return cmd.needsExclusive(); }
4314022Sstever@eecs.umich.edu    bool needsResponse() const  { return cmd.needsResponse(); }
4324022Sstever@eecs.umich.edu    bool isInvalidate() const   { return cmd.isInvalidate(); }
4334022Sstever@eecs.umich.edu    bool hasData() const        { return cmd.hasData(); }
4344040Ssaidi@eecs.umich.edu    bool isReadWrite() const    { return cmd.isReadWrite(); }
4356102Sgblack@eecs.umich.edu    bool isLLSC() const         { return cmd.isLLSC(); }
4364870Sstever@eecs.umich.edu    bool isError() const        { return cmd.isError(); }
4375314Sstever@gmail.com    bool isPrint() const        { return cmd.isPrint(); }
4388184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return cmd.isFlush(); }
4392812Srdreslin@umich.edu
4404870Sstever@eecs.umich.edu    // Snoop flags
4415735Snate@binkert.org    void assertMemInhibit()     { flags.set(MEM_INHIBIT); }
4425764Snate@binkert.org    bool memInhibitAsserted()   { return flags.isSet(MEM_INHIBIT); }
4435735Snate@binkert.org    void assertShared()         { flags.set(SHARED); }
4445764Snate@binkert.org    bool sharedAsserted()       { return flags.isSet(SHARED); }
4454870Sstever@eecs.umich.edu
4464895Sstever@eecs.umich.edu    // Special control flags
4475735Snate@binkert.org    void setExpressSnoop()      { flags.set(EXPRESS_SNOOP); }
4485764Snate@binkert.org    bool isExpressSnoop()       { return flags.isSet(EXPRESS_SNOOP); }
4495735Snate@binkert.org    void setSupplyExclusive()   { flags.set(SUPPLY_EXCLUSIVE); }
4507687Ssteve.reinhardt@amd.com    void clearSupplyExclusive() { flags.clear(SUPPLY_EXCLUSIVE); }
4515764Snate@binkert.org    bool isSupplyExclusive()    { return flags.isSet(SUPPLY_EXCLUSIVE); }
4528436SBrad.Beckmann@amd.com    void setSuppressFuncError() { flags.set(SUPPRESS_FUNC_ERROR); }
4538436SBrad.Beckmann@amd.com    bool suppressFuncError()    { return flags.isSet(SUPPRESS_FUNC_ERROR); }
4544895Sstever@eecs.umich.edu
4554870Sstever@eecs.umich.edu    // Network error conditions... encapsulate them as methods since
4564870Sstever@eecs.umich.edu    // their encoding keeps changing (from result field to command
4574870Sstever@eecs.umich.edu    // field, etc.)
4585735Snate@binkert.org    void
4595735Snate@binkert.org    setNacked()
4605735Snate@binkert.org    {
4615735Snate@binkert.org        assert(isResponse());
4625735Snate@binkert.org        cmd = MemCmd::NetworkNackError;
4635735Snate@binkert.org    }
4645735Snate@binkert.org
4655735Snate@binkert.org    void
4665735Snate@binkert.org    setBadAddress()
4675735Snate@binkert.org    {
4685735Snate@binkert.org        assert(isResponse());
4695735Snate@binkert.org        cmd = MemCmd::BadAddressError;
4705735Snate@binkert.org    }
4715735Snate@binkert.org
4725735Snate@binkert.org    bool wasNacked() const     { return cmd == MemCmd::NetworkNackError; }
4735735Snate@binkert.org    bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; }
4744986Ssaidi@eecs.umich.edu    void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
4752814Srdreslin@umich.edu
4766768SBrad.Beckmann@amd.com    bool isSrcValid() { return flags.isSet(VALID_SRC); }
4775735Snate@binkert.org    /// Accessor function to get the source index of the packet.
4785764Snate@binkert.org    NodeID getSrc() const    { assert(flags.isSet(VALID_SRC)); return src; }
4795735Snate@binkert.org    /// Accessor function to set the source index of the packet.
4805735Snate@binkert.org    void setSrc(NodeID _src) { src = _src; flags.set(VALID_SRC); }
4815735Snate@binkert.org    /// Reset source field, e.g. to retransmit packet on different bus.
4825735Snate@binkert.org    void clearSrc() { flags.clear(VALID_SRC); }
4832641Sstever@eecs.umich.edu
4846768SBrad.Beckmann@amd.com    bool isDestValid() { return flags.isSet(VALID_DST); }
4855735Snate@binkert.org    /// Accessor function for the destination index of the packet.
4865764Snate@binkert.org    NodeID getDest() const     { assert(flags.isSet(VALID_DST)); return dest; }
4875735Snate@binkert.org    /// Accessor function to set the destination index of the packet.
4885735Snate@binkert.org    void setDest(NodeID _dest) { dest = _dest; flags.set(VALID_DST); }
4898949Sandreas.hansson@arm.com    /// Reset destination field, e.g. to turn a response into a request again.
4908949Sandreas.hansson@arm.com    void clearDest() { flags.clear(VALID_DST); }
4912381SN/A
4925764Snate@binkert.org    Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; }
4936227Snate@binkert.org    unsigned getSize() const  { assert(flags.isSet(VALID_SIZE)); return size; }
4945735Snate@binkert.org    Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); }
4952549SN/A
4965735Snate@binkert.org    /**
4977550SBrad.Beckmann@amd.com     * It has been determined that the SC packet should successfully update
4987550SBrad.Beckmann@amd.com     * memory.  Therefore, convert this SC packet to a normal write.
4997550SBrad.Beckmann@amd.com     */
5007550SBrad.Beckmann@amd.com    void
5017550SBrad.Beckmann@amd.com    convertScToWrite()
5027550SBrad.Beckmann@amd.com    {
5037550SBrad.Beckmann@amd.com        assert(isLLSC());
5047550SBrad.Beckmann@amd.com        assert(isWrite());
5057550SBrad.Beckmann@amd.com        cmd = MemCmd::WriteReq;
5067550SBrad.Beckmann@amd.com    }
5077550SBrad.Beckmann@amd.com
5087550SBrad.Beckmann@amd.com    /**
5097550SBrad.Beckmann@amd.com     * When ruby is in use, Ruby will monitor the cache line and thus M5
5107550SBrad.Beckmann@amd.com     * phys memory should treat LL ops as normal reads.
5117550SBrad.Beckmann@amd.com     */
5127550SBrad.Beckmann@amd.com    void
5137550SBrad.Beckmann@amd.com    convertLlToRead()
5147550SBrad.Beckmann@amd.com    {
5157550SBrad.Beckmann@amd.com        assert(isLLSC());
5167550SBrad.Beckmann@amd.com        assert(isRead());
5177550SBrad.Beckmann@amd.com        cmd = MemCmd::ReadReq;
5187550SBrad.Beckmann@amd.com    }
5197550SBrad.Beckmann@amd.com
5207550SBrad.Beckmann@amd.com    /**
5215735Snate@binkert.org     * Constructor.  Note that a Request object must be constructed
5225735Snate@binkert.org     * first, but the Requests's physical address and size fields need
5235735Snate@binkert.org     * not be valid. The command and destination addresses must be
5245735Snate@binkert.org     * supplied.
5255735Snate@binkert.org     */
5268949Sandreas.hansson@arm.com    Packet(Request *_req, MemCmd _cmd)
5278949Sandreas.hansson@arm.com        :  cmd(_cmd), req(_req), data(NULL),
5288949Sandreas.hansson@arm.com           bytesValidStart(0), bytesValidEnd(0),
5298668Sgeoffrey.blake@arm.com           time(curTick()), senderState(NULL)
5302641Sstever@eecs.umich.edu    {
5316104Ssteve.reinhardt@amd.com        if (req->hasPaddr()) {
5326104Ssteve.reinhardt@amd.com            addr = req->getPaddr();
5336104Ssteve.reinhardt@amd.com            flags.set(VALID_ADDR);
5346104Ssteve.reinhardt@amd.com        }
5356104Ssteve.reinhardt@amd.com        if (req->hasSize()) {
5366104Ssteve.reinhardt@amd.com            size = req->getSize();
5376104Ssteve.reinhardt@amd.com            flags.set(VALID_SIZE);
5386104Ssteve.reinhardt@amd.com        }
5392813Srdreslin@umich.edu    }
5402813Srdreslin@umich.edu
5415735Snate@binkert.org    /**
5425735Snate@binkert.org     * Alternate constructor if you are trying to create a packet with
5435735Snate@binkert.org     * a request that is for a whole block, not the address from the
5445735Snate@binkert.org     * req.  this allows for overriding the size/addr of the req.
5455735Snate@binkert.org     */
5468949Sandreas.hansson@arm.com    Packet(Request *_req, MemCmd _cmd, int _blkSize)
5478949Sandreas.hansson@arm.com        :  cmd(_cmd), req(_req), data(NULL),
5488949Sandreas.hansson@arm.com           bytesValidStart(0), bytesValidEnd(0),
5498668Sgeoffrey.blake@arm.com           time(curTick()), senderState(NULL)
5502813Srdreslin@umich.edu    {
5516104Ssteve.reinhardt@amd.com        if (req->hasPaddr()) {
5526104Ssteve.reinhardt@amd.com            addr = req->getPaddr() & ~(_blkSize - 1);
5536104Ssteve.reinhardt@amd.com            flags.set(VALID_ADDR);
5546104Ssteve.reinhardt@amd.com        }
5556104Ssteve.reinhardt@amd.com        size = _blkSize;
5566104Ssteve.reinhardt@amd.com        flags.set(VALID_SIZE);
5574626Sstever@eecs.umich.edu    }
5584626Sstever@eecs.umich.edu
5595735Snate@binkert.org    /**
5605735Snate@binkert.org     * Alternate constructor for copying a packet.  Copy all fields
5614887Sstever@eecs.umich.edu     * *except* if the original packet's data was dynamic, don't copy
5624887Sstever@eecs.umich.edu     * that, as we can't guarantee that the new packet's lifetime is
5634887Sstever@eecs.umich.edu     * less than that of the original packet.  In this case the new
5645735Snate@binkert.org     * packet should allocate its own data.
5655735Snate@binkert.org     */
5665735Snate@binkert.org    Packet(Packet *pkt, bool clearFlags = false)
5675735Snate@binkert.org        :  cmd(pkt->cmd), req(pkt->req),
5685764Snate@binkert.org           data(pkt->flags.isSet(STATIC_DATA) ? pkt->data : NULL),
5695735Snate@binkert.org           addr(pkt->addr), size(pkt->size), src(pkt->src), dest(pkt->dest),
5708668Sgeoffrey.blake@arm.com           bytesValidStart(pkt->bytesValidStart), bytesValidEnd(pkt->bytesValidEnd),
5717823Ssteve.reinhardt@amd.com           time(curTick()), senderState(pkt->senderState)
5724626Sstever@eecs.umich.edu    {
5735735Snate@binkert.org        if (!clearFlags)
5745735Snate@binkert.org            flags.set(pkt->flags & COPY_FLAGS);
5755735Snate@binkert.org
5765735Snate@binkert.org        flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE|VALID_SRC|VALID_DST));
5775735Snate@binkert.org        flags.set(pkt->flags & STATIC_DATA);
5788668Sgeoffrey.blake@arm.com
5792641Sstever@eecs.umich.edu    }
5802549SN/A
5815735Snate@binkert.org    /**
5825735Snate@binkert.org     * clean up packet variables
5835735Snate@binkert.org     */
5842566SN/A    ~Packet()
5855387Sstever@gmail.com    {
5865387Sstever@gmail.com        // If this is a request packet for which there's no response,
5875387Sstever@gmail.com        // delete the request object here, since the requester will
5885387Sstever@gmail.com        // never get the chance.
5895387Sstever@gmail.com        if (req && isRequest() && !needsResponse())
5905387Sstever@gmail.com            delete req;
5915735Snate@binkert.org        deleteData();
5925387Sstever@gmail.com    }
5932566SN/A
5945735Snate@binkert.org    /**
5955735Snate@binkert.org     * Reinitialize packet address and size from the associated
5965735Snate@binkert.org     * Request object, and reset other fields that may have been
5975735Snate@binkert.org     * modified by a previous transaction.  Typically called when a
5985735Snate@binkert.org     * statically allocated Request/Packet pair is reused for multiple
5995735Snate@binkert.org     * transactions.
6005735Snate@binkert.org     */
6015735Snate@binkert.org    void
6025735Snate@binkert.org    reinitFromRequest()
6035735Snate@binkert.org    {
6046104Ssteve.reinhardt@amd.com        assert(req->hasPaddr());
6054870Sstever@eecs.umich.edu        flags = 0;
6066104Ssteve.reinhardt@amd.com        addr = req->getPaddr();
6076104Ssteve.reinhardt@amd.com        size = req->getSize();
6086223Snate@binkert.org        time = req->time();
6095735Snate@binkert.org
6105735Snate@binkert.org        flags.set(VALID_ADDR|VALID_SIZE);
6115735Snate@binkert.org        deleteData();
6122662Sstever@eecs.umich.edu    }
6132566SN/A
6144626Sstever@eecs.umich.edu    /**
6154626Sstever@eecs.umich.edu     * Take a request packet and modify it in place to be suitable for
6164626Sstever@eecs.umich.edu     * returning as a response to that request.  The source and
6174626Sstever@eecs.umich.edu     * destination fields are *not* modified, as is appropriate for
6184626Sstever@eecs.umich.edu     * atomic accesses.
6194626Sstever@eecs.umich.edu     */
6205735Snate@binkert.org    void
6215735Snate@binkert.org    makeResponse()
6224626Sstever@eecs.umich.edu    {
6232662Sstever@eecs.umich.edu        assert(needsResponse());
6242855Srdreslin@umich.edu        assert(isRequest());
6254986Ssaidi@eecs.umich.edu        origCmd = cmd;
6264022Sstever@eecs.umich.edu        cmd = cmd.responseCommand();
6275745Snate@binkert.org
6287464Ssteve.reinhardt@amd.com        // responses are never express, even if the snoop that
6297464Ssteve.reinhardt@amd.com        // triggered them was
6307464Ssteve.reinhardt@amd.com        flags.clear(EXPRESS_SNOOP);
6317464Ssteve.reinhardt@amd.com
6325745Snate@binkert.org        dest = src;
6335764Snate@binkert.org        flags.set(VALID_DST, flags.isSet(VALID_SRC));
6345745Snate@binkert.org        flags.clear(VALID_SRC);
6352641Sstever@eecs.umich.edu    }
6362641Sstever@eecs.umich.edu
6375735Snate@binkert.org    void
6385735Snate@binkert.org    makeAtomicResponse()
6394870Sstever@eecs.umich.edu    {
6404870Sstever@eecs.umich.edu        makeResponse();
6414870Sstever@eecs.umich.edu    }
6424870Sstever@eecs.umich.edu
6435735Snate@binkert.org    void
6445735Snate@binkert.org    makeTimingResponse()
6453348Sbinkertn@umich.edu    {
6464870Sstever@eecs.umich.edu        makeResponse();
6473135Srdreslin@umich.edu    }
6483135Srdreslin@umich.edu
6498436SBrad.Beckmann@amd.com    void
6508436SBrad.Beckmann@amd.com    setFunctionalResponseStatus(bool success)
6518436SBrad.Beckmann@amd.com    {
6528436SBrad.Beckmann@amd.com        if (!success) {
6538436SBrad.Beckmann@amd.com            if (isWrite()) {
6548436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalWriteError;
6558436SBrad.Beckmann@amd.com            } else {
6568436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalReadError;
6578436SBrad.Beckmann@amd.com            }
6588436SBrad.Beckmann@amd.com        }
6598436SBrad.Beckmann@amd.com    }
6608436SBrad.Beckmann@amd.com
6613348Sbinkertn@umich.edu    /**
6623348Sbinkertn@umich.edu     * Take a request packet that has been returned as NACKED and
6633348Sbinkertn@umich.edu     * modify it so that it can be sent out again. Only packets that
6643348Sbinkertn@umich.edu     * need a response can be NACKED, so verify that that is true.
6653348Sbinkertn@umich.edu     */
6663348Sbinkertn@umich.edu    void
6673348Sbinkertn@umich.edu    reinitNacked()
6683348Sbinkertn@umich.edu    {
6694870Sstever@eecs.umich.edu        assert(wasNacked());
6704870Sstever@eecs.umich.edu        cmd = origCmd;
6714870Sstever@eecs.umich.edu        assert(needsResponse());
6728949Sandreas.hansson@arm.com        clearDest();
6732685Ssaidi@eecs.umich.edu    }
6742685Ssaidi@eecs.umich.edu
6757006Snate@binkert.org    void
6767006Snate@binkert.org    setSize(unsigned size)
6777006Snate@binkert.org    {
6787006Snate@binkert.org        assert(!flags.isSet(VALID_SIZE));
6797006Snate@binkert.org
6807006Snate@binkert.org        this->size = size;
6817006Snate@binkert.org        flags.set(VALID_SIZE);
6827006Snate@binkert.org    }
6837006Snate@binkert.org
6842685Ssaidi@eecs.umich.edu
6853348Sbinkertn@umich.edu    /**
6863348Sbinkertn@umich.edu     * Set the data pointer to the following value that should not be
6873348Sbinkertn@umich.edu     * freed.
6882566SN/A     */
6892566SN/A    template <typename T>
6903348Sbinkertn@umich.edu    void
6913348Sbinkertn@umich.edu    dataStatic(T *p)
6923348Sbinkertn@umich.edu    {
6935764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
6943348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
6955735Snate@binkert.org        flags.set(STATIC_DATA);
6963348Sbinkertn@umich.edu    }
6972566SN/A
6983348Sbinkertn@umich.edu    /**
6993348Sbinkertn@umich.edu     * Set the data pointer to a value that should have delete []
7003348Sbinkertn@umich.edu     * called on it.
7013348Sbinkertn@umich.edu     */
7022566SN/A    template <typename T>
7033348Sbinkertn@umich.edu    void
7043348Sbinkertn@umich.edu    dataDynamicArray(T *p)
7053348Sbinkertn@umich.edu    {
7065764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
7073348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
7085735Snate@binkert.org        flags.set(DYNAMIC_DATA|ARRAY_DATA);
7093348Sbinkertn@umich.edu    }
7103348Sbinkertn@umich.edu
7113348Sbinkertn@umich.edu    /**
7123348Sbinkertn@umich.edu     * set the data pointer to a value that should have delete called
7133348Sbinkertn@umich.edu     * on it.
7143348Sbinkertn@umich.edu     */
7153348Sbinkertn@umich.edu    template <typename T>
7163348Sbinkertn@umich.edu    void
7173348Sbinkertn@umich.edu    dataDynamic(T *p)
7183348Sbinkertn@umich.edu    {
7195764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
7203348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
7215735Snate@binkert.org        flags.set(DYNAMIC_DATA);
7223348Sbinkertn@umich.edu    }
7233348Sbinkertn@umich.edu
7245735Snate@binkert.org    /**
7255735Snate@binkert.org     * get a pointer to the data ptr.
7265735Snate@binkert.org     */
7273348Sbinkertn@umich.edu    template <typename T>
7283348Sbinkertn@umich.edu    T*
7297915SBrad.Beckmann@amd.com    getPtr(bool null_ok = false)
7303348Sbinkertn@umich.edu    {
7317915SBrad.Beckmann@amd.com        assert(null_ok || flags.isSet(STATIC_DATA|DYNAMIC_DATA));
7323348Sbinkertn@umich.edu        return (T*)data;
7333348Sbinkertn@umich.edu    }
7342566SN/A
7355735Snate@binkert.org    /**
7365735Snate@binkert.org     * return the value of what is pointed to in the packet.
7375735Snate@binkert.org     */
7382566SN/A    template <typename T>
7392592SN/A    T get();
7402566SN/A
7415735Snate@binkert.org    /**
7425735Snate@binkert.org     * set the value in the data pointer to v.
7435735Snate@binkert.org     */
7442566SN/A    template <typename T>
7452592SN/A    void set(T v);
7462566SN/A
7473348Sbinkertn@umich.edu    /**
7484626Sstever@eecs.umich.edu     * Copy data into the packet from the provided pointer.
7494626Sstever@eecs.umich.edu     */
7505735Snate@binkert.org    void
7515735Snate@binkert.org    setData(uint8_t *p)
7524626Sstever@eecs.umich.edu    {
7537691SAli.Saidi@ARM.com        if (p != getPtr<uint8_t>())
7547691SAli.Saidi@ARM.com            std::memcpy(getPtr<uint8_t>(), p, getSize());
7554626Sstever@eecs.umich.edu    }
7564626Sstever@eecs.umich.edu
7574626Sstever@eecs.umich.edu    /**
7584626Sstever@eecs.umich.edu     * Copy data into the packet from the provided block pointer,
7594626Sstever@eecs.umich.edu     * which is aligned to the given block size.
7604626Sstever@eecs.umich.edu     */
7615735Snate@binkert.org    void
7625735Snate@binkert.org    setDataFromBlock(uint8_t *blk_data, int blkSize)
7634626Sstever@eecs.umich.edu    {
7644626Sstever@eecs.umich.edu        setData(blk_data + getOffset(blkSize));
7654626Sstever@eecs.umich.edu    }
7664626Sstever@eecs.umich.edu
7674626Sstever@eecs.umich.edu    /**
7684626Sstever@eecs.umich.edu     * Copy data from the packet to the provided block pointer, which
7694626Sstever@eecs.umich.edu     * is aligned to the given block size.
7704626Sstever@eecs.umich.edu     */
7715735Snate@binkert.org    void
7725735Snate@binkert.org    writeData(uint8_t *p)
7734626Sstever@eecs.umich.edu    {
7744626Sstever@eecs.umich.edu        std::memcpy(p, getPtr<uint8_t>(), getSize());
7754626Sstever@eecs.umich.edu    }
7764626Sstever@eecs.umich.edu
7774626Sstever@eecs.umich.edu    /**
7784626Sstever@eecs.umich.edu     * Copy data from the packet to the memory at the provided pointer.
7794626Sstever@eecs.umich.edu     */
7805735Snate@binkert.org    void
7815735Snate@binkert.org    writeDataToBlock(uint8_t *blk_data, int blkSize)
7824626Sstever@eecs.umich.edu    {
7834626Sstever@eecs.umich.edu        writeData(blk_data + getOffset(blkSize));
7844626Sstever@eecs.umich.edu    }
7854626Sstever@eecs.umich.edu
7864626Sstever@eecs.umich.edu    /**
7873348Sbinkertn@umich.edu     * delete the data pointed to in the data pointer. Ok to call to
7883348Sbinkertn@umich.edu     * matter how data was allocted.
7893348Sbinkertn@umich.edu     */
7905735Snate@binkert.org    void
7915735Snate@binkert.org    deleteData()
7925735Snate@binkert.org    {
7935764Snate@binkert.org        if (flags.isSet(ARRAY_DATA))
7945735Snate@binkert.org            delete [] data;
7955764Snate@binkert.org        else if (flags.isSet(DYNAMIC_DATA))
7965735Snate@binkert.org            delete data;
7975735Snate@binkert.org
7985735Snate@binkert.org        flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA);
7995735Snate@binkert.org        data = NULL;
8005735Snate@binkert.org    }
8012566SN/A
8022566SN/A    /** If there isn't data in the packet, allocate some. */
8035735Snate@binkert.org    void
8045735Snate@binkert.org    allocate()
8055735Snate@binkert.org    {
8065735Snate@binkert.org        if (data) {
8075764Snate@binkert.org            assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
8085745Snate@binkert.org            return;
8095735Snate@binkert.org        }
8105745Snate@binkert.org
8115764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
8125745Snate@binkert.org        flags.set(DYNAMIC_DATA|ARRAY_DATA);
8135745Snate@binkert.org        data = new uint8_t[getSize()];
8145735Snate@binkert.org    }
8155735Snate@binkert.org
8164626Sstever@eecs.umich.edu    /**
8174626Sstever@eecs.umich.edu     * Check a functional request against a memory value represented
8184626Sstever@eecs.umich.edu     * by a base/size pair and an associated data array.  If the
8194626Sstever@eecs.umich.edu     * functional request is a read, it may be satisfied by the memory
8204626Sstever@eecs.umich.edu     * value.  If the functional request is a write, it may update the
8214626Sstever@eecs.umich.edu     * memory value.
8224626Sstever@eecs.umich.edu     */
8235314Sstever@gmail.com    bool checkFunctional(Printable *obj, Addr base, int size, uint8_t *data);
8244626Sstever@eecs.umich.edu
8254626Sstever@eecs.umich.edu    /**
8264626Sstever@eecs.umich.edu     * Check a functional request against a memory value stored in
8275315Sstever@gmail.com     * another packet (i.e. an in-transit request or response).
8284626Sstever@eecs.umich.edu     */
8295735Snate@binkert.org    bool
8305735Snate@binkert.org    checkFunctional(PacketPtr other)
8315735Snate@binkert.org    {
8325735Snate@binkert.org        uint8_t *data = other->hasData() ? other->getPtr<uint8_t>() : NULL;
8335735Snate@binkert.org        return checkFunctional(other, other->getAddr(), other->getSize(),
8345735Snate@binkert.org                               data);
8354626Sstever@eecs.umich.edu    }
8365314Sstever@gmail.com
8375315Sstever@gmail.com    /**
8385315Sstever@gmail.com     * Push label for PrintReq (safe to call unconditionally).
8395315Sstever@gmail.com     */
8405735Snate@binkert.org    void
8415735Snate@binkert.org    pushLabel(const std::string &lbl)
8425735Snate@binkert.org    {
8435735Snate@binkert.org        if (isPrint())
8445735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->pushLabel(lbl);
8455314Sstever@gmail.com    }
8465314Sstever@gmail.com
8475315Sstever@gmail.com    /**
8485315Sstever@gmail.com     * Pop label for PrintReq (safe to call unconditionally).
8495315Sstever@gmail.com     */
8505735Snate@binkert.org    void
8515735Snate@binkert.org    popLabel()
8525735Snate@binkert.org    {
8535735Snate@binkert.org        if (isPrint())
8545735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->popLabel();
8555314Sstever@gmail.com    }
8565314Sstever@gmail.com
8575314Sstever@gmail.com    void print(std::ostream &o, int verbosity = 0,
8585314Sstever@gmail.com               const std::string &prefix = "") const;
8592381SN/A};
8602381SN/A
8612381SN/A#endif //__MEM_PACKET_HH
862