packet.hh revision 9044
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
449031Sandreas.hansson@arm.com *          Andreas Hansson
452381SN/A */
462381SN/A
472381SN/A/**
482381SN/A * @file
492662Sstever@eecs.umich.edu * Declaration of the Packet class.
502381SN/A */
512381SN/A
522381SN/A#ifndef __MEM_PACKET_HH__
532381SN/A#define __MEM_PACKET_HH__
542381SN/A
558229Snate@binkert.org#include <bitset>
563348Sbinkertn@umich.edu#include <cassert>
573348Sbinkertn@umich.edu#include <list>
583348Sbinkertn@umich.edu
595735Snate@binkert.org#include "base/cast.hh"
604024Sbinkertn@umich.edu#include "base/compiler.hh"
615735Snate@binkert.org#include "base/flags.hh"
623940Ssaidi@eecs.umich.edu#include "base/misc.hh"
635314Sstever@gmail.com#include "base/printable.hh"
646216Snate@binkert.org#include "base/types.hh"
652392SN/A#include "mem/request.hh"
664167Sbinkertn@umich.edu#include "sim/core.hh"
672394SN/A
688737Skoansin.tan@gmail.comclass Packet;
693349Sbinkertn@umich.edutypedef Packet *PacketPtr;
702394SN/Atypedef uint8_t* PacketDataPtr;
712812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList;
722812Srdreslin@umich.edu
734022Sstever@eecs.umich.educlass MemCmd
744022Sstever@eecs.umich.edu{
755735Snate@binkert.org    friend class Packet;
765735Snate@binkert.org
774022Sstever@eecs.umich.edu  public:
785735Snate@binkert.org    /**
795735Snate@binkert.org     * List of all commands associated with a packet.
805735Snate@binkert.org     */
814022Sstever@eecs.umich.edu    enum Command
824022Sstever@eecs.umich.edu    {
834022Sstever@eecs.umich.edu        InvalidCmd,
844022Sstever@eecs.umich.edu        ReadReq,
854473Sstever@eecs.umich.edu        ReadResp,
865319Sstever@gmail.com        ReadRespWithInvalidate,
874022Sstever@eecs.umich.edu        WriteReq,
884022Sstever@eecs.umich.edu        WriteResp,
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,
949018Sandreas.hansson@arm.com        // WriteInvalidateReq transactions used to be generated by the
959018Sandreas.hansson@arm.com        // DMA ports when writing full blocks to memory, however, it
969018Sandreas.hansson@arm.com        // is not used anymore since we put the I/O cache in place to
979018Sandreas.hansson@arm.com        // deal with partial block writes. Hence, WriteInvalidateReq
989018Sandreas.hansson@arm.com        // and WriteInvalidateResp are currently unused. The
999018Sandreas.hansson@arm.com        // implication is that the I/O cache does read-exclusive
1009018Sandreas.hansson@arm.com        // operations on every full-cache-block DMA, and ultimately
1019018Sandreas.hansson@arm.com        // this needs to be fixed.
1024022Sstever@eecs.umich.edu        WriteInvalidateReq,
1034022Sstever@eecs.umich.edu        WriteInvalidateResp,
1044022Sstever@eecs.umich.edu        UpgradeReq,
1057465Ssteve.reinhardt@amd.com        SCUpgradeReq,           // Special "weak" upgrade for StoreCond
1064628Sstever@eecs.umich.edu        UpgradeResp,
1077465Ssteve.reinhardt@amd.com        SCUpgradeFailReq,       // Failed SCUpgradeReq in MSHR (never sent)
1087465Ssteve.reinhardt@amd.com        UpgradeFailResp,        // Valid for SCUpgradeReq only
1094022Sstever@eecs.umich.edu        ReadExReq,
1104022Sstever@eecs.umich.edu        ReadExResp,
1114626Sstever@eecs.umich.edu        LoadLockedReq,
1124626Sstever@eecs.umich.edu        StoreCondReq,
1137669Ssteve.reinhardt@amd.com        StoreCondFailReq,       // Failed StoreCondReq in MSHR (never sent)
1144626Sstever@eecs.umich.edu        StoreCondResp,
1154040Ssaidi@eecs.umich.edu        SwapReq,
1164040Ssaidi@eecs.umich.edu        SwapResp,
1175650Sgblack@eecs.umich.edu        MessageReq,
1185650Sgblack@eecs.umich.edu        MessageResp,
1194870Sstever@eecs.umich.edu        // Error responses
1204870Sstever@eecs.umich.edu        // @TODO these should be classified as responses rather than
1214870Sstever@eecs.umich.edu        // requests; coding them as requests initially for backwards
1224870Sstever@eecs.umich.edu        // compatibility
1234870Sstever@eecs.umich.edu        NetworkNackError,  // nacked at network layer (not by protocol)
1244870Sstever@eecs.umich.edu        InvalidDestError,  // packet dest field invalid
1254870Sstever@eecs.umich.edu        BadAddressError,   // memory address invalid
1268436SBrad.Beckmann@amd.com        FunctionalReadError, // unable to fulfill functional read
1278436SBrad.Beckmann@amd.com        FunctionalWriteError, // unable to fulfill functional write
1285314Sstever@gmail.com        // Fake simulator-only commands
1295314Sstever@gmail.com        PrintReq,       // Print state matching address
1308184Ssomayeh@cs.wisc.edu        FlushReq,      //request for a cache flush
1318716Snilay@cs.wisc.edu        InvalidationReq,   // request for address to be invalidated from lsq
1324022Sstever@eecs.umich.edu        NUM_MEM_CMDS
1334022Sstever@eecs.umich.edu    };
1344022Sstever@eecs.umich.edu
1354022Sstever@eecs.umich.edu  private:
1365735Snate@binkert.org    /**
1375735Snate@binkert.org     * List of command attributes.
1385735Snate@binkert.org     */
1394022Sstever@eecs.umich.edu    enum Attribute
1404022Sstever@eecs.umich.edu    {
1414626Sstever@eecs.umich.edu        IsRead,         //!< Data flows from responder to requester
1424626Sstever@eecs.umich.edu        IsWrite,        //!< Data flows from requester to responder
1437465Ssteve.reinhardt@amd.com        IsUpgrade,
1444022Sstever@eecs.umich.edu        IsInvalidate,
1454626Sstever@eecs.umich.edu        NeedsExclusive, //!< Requires exclusive copy to complete in-cache
1464626Sstever@eecs.umich.edu        IsRequest,      //!< Issued by requester
1474626Sstever@eecs.umich.edu        IsResponse,     //!< Issue by responder
1484626Sstever@eecs.umich.edu        NeedsResponse,  //!< Requester needs response from target
1494022Sstever@eecs.umich.edu        IsSWPrefetch,
1504022Sstever@eecs.umich.edu        IsHWPrefetch,
1516076Sgblack@eecs.umich.edu        IsLlsc,         //!< Alpha/MIPS LL or SC access
1524626Sstever@eecs.umich.edu        HasData,        //!< There is an associated payload
1534870Sstever@eecs.umich.edu        IsError,        //!< Error response
1545314Sstever@gmail.com        IsPrint,        //!< Print state matching address (for debugging)
1558184Ssomayeh@cs.wisc.edu        IsFlush,        //!< Flush the address from caches
1564022Sstever@eecs.umich.edu        NUM_COMMAND_ATTRIBUTES
1574022Sstever@eecs.umich.edu    };
1584022Sstever@eecs.umich.edu
1595735Snate@binkert.org    /**
1605735Snate@binkert.org     * Structure that defines attributes and other data associated
1615735Snate@binkert.org     * with a Command.
1625735Snate@binkert.org     */
1635735Snate@binkert.org    struct CommandInfo
1645735Snate@binkert.org    {
1655735Snate@binkert.org        /// Set of attribute flags.
1664022Sstever@eecs.umich.edu        const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
1675735Snate@binkert.org        /// Corresponding response for requests; InvalidCmd if no
1685735Snate@binkert.org        /// response is applicable.
1694022Sstever@eecs.umich.edu        const Command response;
1705735Snate@binkert.org        /// String representation (for printing)
1714022Sstever@eecs.umich.edu        const std::string str;
1724022Sstever@eecs.umich.edu    };
1734022Sstever@eecs.umich.edu
1745735Snate@binkert.org    /// Array to map Command enum to associated info.
1754022Sstever@eecs.umich.edu    static const CommandInfo commandInfo[];
1764022Sstever@eecs.umich.edu
1774022Sstever@eecs.umich.edu  private:
1784022Sstever@eecs.umich.edu
1794022Sstever@eecs.umich.edu    Command cmd;
1804022Sstever@eecs.umich.edu
1815735Snate@binkert.org    bool
1825735Snate@binkert.org    testCmdAttrib(MemCmd::Attribute attrib) const
1835735Snate@binkert.org    {
1844022Sstever@eecs.umich.edu        return commandInfo[cmd].attributes[attrib] != 0;
1854022Sstever@eecs.umich.edu    }
1864022Sstever@eecs.umich.edu
1874022Sstever@eecs.umich.edu  public:
1884022Sstever@eecs.umich.edu
1894022Sstever@eecs.umich.edu    bool isRead() const         { return testCmdAttrib(IsRead); }
1907465Ssteve.reinhardt@amd.com    bool isWrite() const        { return testCmdAttrib(IsWrite); }
1917465Ssteve.reinhardt@amd.com    bool isUpgrade() const      { return testCmdAttrib(IsUpgrade); }
1924022Sstever@eecs.umich.edu    bool isRequest() const      { return testCmdAttrib(IsRequest); }
1934022Sstever@eecs.umich.edu    bool isResponse() const     { return testCmdAttrib(IsResponse); }
1944870Sstever@eecs.umich.edu    bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); }
1954022Sstever@eecs.umich.edu    bool needsResponse() const  { return testCmdAttrib(NeedsResponse); }
1964022Sstever@eecs.umich.edu    bool isInvalidate() const   { return testCmdAttrib(IsInvalidate); }
1974022Sstever@eecs.umich.edu    bool hasData() const        { return testCmdAttrib(HasData); }
1984626Sstever@eecs.umich.edu    bool isReadWrite() const    { return isRead() && isWrite(); }
1996102Sgblack@eecs.umich.edu    bool isLLSC() const         { return testCmdAttrib(IsLlsc); }
2004870Sstever@eecs.umich.edu    bool isError() const        { return testCmdAttrib(IsError); }
2015314Sstever@gmail.com    bool isPrint() const        { return testCmdAttrib(IsPrint); }
2028184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return testCmdAttrib(IsFlush); }
2034022Sstever@eecs.umich.edu
2045735Snate@binkert.org    const Command
2055735Snate@binkert.org    responseCommand() const
2065735Snate@binkert.org    {
2074022Sstever@eecs.umich.edu        return commandInfo[cmd].response;
2084022Sstever@eecs.umich.edu    }
2094022Sstever@eecs.umich.edu
2105735Snate@binkert.org    /// Return the string to a cmd given by idx.
2115735Snate@binkert.org    const std::string &toString() const { return commandInfo[cmd].str; }
2124022Sstever@eecs.umich.edu    int toInt() const { return (int)cmd; }
2134022Sstever@eecs.umich.edu
2145735Snate@binkert.org    MemCmd(Command _cmd) : cmd(_cmd) { }
2155735Snate@binkert.org    MemCmd(int _cmd) : cmd((Command)_cmd) { }
2165735Snate@binkert.org    MemCmd() : cmd(InvalidCmd) { }
2174022Sstever@eecs.umich.edu
2185735Snate@binkert.org    bool operator==(MemCmd c2) const { return (cmd == c2.cmd); }
2195735Snate@binkert.org    bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); }
2204022Sstever@eecs.umich.edu};
2214022Sstever@eecs.umich.edu
2222381SN/A/**
2232662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in
2242662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache).  (In contrast, a
2252662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the
2262662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several
2272662Sstever@eecs.umich.edu * different Packets along the way.)
2282381SN/A */
2299044SAli.Saidi@ARM.comclass Packet : public Printable
2302381SN/A{
2312813Srdreslin@umich.edu  public:
2325735Snate@binkert.org    typedef uint32_t FlagsType;
2335735Snate@binkert.org    typedef ::Flags<FlagsType> Flags;
2344022Sstever@eecs.umich.edu
2355735Snate@binkert.org  private:
2365735Snate@binkert.org    static const FlagsType PUBLIC_FLAGS           = 0x00000000;
2375735Snate@binkert.org    static const FlagsType PRIVATE_FLAGS          = 0x00007F0F;
2385735Snate@binkert.org    static const FlagsType COPY_FLAGS             = 0x0000000F;
2395735Snate@binkert.org
2405735Snate@binkert.org    static const FlagsType SHARED                 = 0x00000001;
2415735Snate@binkert.org    // Special control flags
2425735Snate@binkert.org    /// Special timing-mode atomic snoop for multi-level coherence.
2435735Snate@binkert.org    static const FlagsType EXPRESS_SNOOP          = 0x00000002;
2445735Snate@binkert.org    /// Does supplier have exclusive copy?
2455735Snate@binkert.org    /// Useful for multi-level coherence.
2465735Snate@binkert.org    static const FlagsType SUPPLY_EXCLUSIVE       = 0x00000004;
2475735Snate@binkert.org    // Snoop response flags
2485735Snate@binkert.org    static const FlagsType MEM_INHIBIT            = 0x00000008;
2495735Snate@binkert.org    /// Are the 'addr' and 'size' fields valid?
2505735Snate@binkert.org    static const FlagsType VALID_ADDR             = 0x00000100;
2515735Snate@binkert.org    static const FlagsType VALID_SIZE             = 0x00000200;
2525735Snate@binkert.org    /// Is the data pointer set to a value that shouldn't be freed
2535735Snate@binkert.org    /// when the packet is destroyed?
2545735Snate@binkert.org    static const FlagsType STATIC_DATA            = 0x00001000;
2555735Snate@binkert.org    /// The data pointer points to a value that should be freed when
2565735Snate@binkert.org    /// the packet is destroyed.
2575735Snate@binkert.org    static const FlagsType DYNAMIC_DATA           = 0x00002000;
2585735Snate@binkert.org    /// the data pointer points to an array (thus delete []) needs to
2595735Snate@binkert.org    /// be called on it rather than simply delete.
2605735Snate@binkert.org    static const FlagsType ARRAY_DATA             = 0x00004000;
2618436SBrad.Beckmann@amd.com    /// suppress the error if this packet encounters a functional
2628436SBrad.Beckmann@amd.com    /// access failure.
2638436SBrad.Beckmann@amd.com    static const FlagsType SUPPRESS_FUNC_ERROR    = 0x00008000;
2645735Snate@binkert.org
2655735Snate@binkert.org    Flags flags;
2665735Snate@binkert.org
2675735Snate@binkert.org  public:
2684022Sstever@eecs.umich.edu    typedef MemCmd::Command Command;
2694022Sstever@eecs.umich.edu
2705735Snate@binkert.org    /// The command field of the packet.
2714870Sstever@eecs.umich.edu    MemCmd cmd;
2724870Sstever@eecs.umich.edu
2735735Snate@binkert.org    /// A pointer to the original request.
2744870Sstever@eecs.umich.edu    RequestPtr req;
2754870Sstever@eecs.umich.edu
2762566SN/A  private:
2775735Snate@binkert.org   /**
2785735Snate@binkert.org    * A pointer to the data being transfered.  It can be differnt
2795735Snate@binkert.org    * sizes at each level of the heirarchy so it belongs in the
2805735Snate@binkert.org    * packet, not request. This may or may not be populated when a
2815735Snate@binkert.org    * responder recieves the packet. If not populated it memory should
2825735Snate@binkert.org    * be allocated.
2832566SN/A    */
2842566SN/A    PacketDataPtr data;
2852566SN/A
2865735Snate@binkert.org    /// The address of the request.  This address could be virtual or
2875735Snate@binkert.org    /// physical, depending on the system configuration.
2882381SN/A    Addr addr;
2892381SN/A
2905735Snate@binkert.org    /// The size of the request or transfer.
2916227Snate@binkert.org    unsigned size;
2922381SN/A
2935735Snate@binkert.org    /**
2949030Sandreas.hansson@arm.com     * Source port identifier set on a request packet to enable
2959030Sandreas.hansson@arm.com     * appropriate routing of the responses. The source port
2969030Sandreas.hansson@arm.com     * identifier is set by any multiplexing component, e.g. a bus, as
2979030Sandreas.hansson@arm.com     * the timing responses need this information to be routed back to
2989030Sandreas.hansson@arm.com     * the appropriate port at a later point in time. The field can be
2999030Sandreas.hansson@arm.com     * updated (over-written) as the request packet passes through
3009030Sandreas.hansson@arm.com     * additional multiplexing components, and it is their
3019030Sandreas.hansson@arm.com     * responsibility to remember the original source port identifier,
3029030Sandreas.hansson@arm.com     * for example by using an appropriate sender state. The latter is
3039030Sandreas.hansson@arm.com     * done in the cache and bridge.
3045735Snate@binkert.org     */
3059031Sandreas.hansson@arm.com    PortID src;
3062381SN/A
3075735Snate@binkert.org    /**
3089030Sandreas.hansson@arm.com     * Destination port identifier that is present on all response
3099030Sandreas.hansson@arm.com     * packets that passed through a multiplexing component as a
3109030Sandreas.hansson@arm.com     * request packet. The source port identifier is turned into a
3119030Sandreas.hansson@arm.com     * destination port identifier when the packet is turned into a
3129030Sandreas.hansson@arm.com     * response, and the destination is used, e.g. by the bus, to
3139030Sandreas.hansson@arm.com     * select the appropriate path through the interconnect.
3145735Snate@binkert.org     */
3159031Sandreas.hansson@arm.com    PortID dest;
3162641Sstever@eecs.umich.edu
3175735Snate@binkert.org    /**
3185735Snate@binkert.org     * The original value of the command field.  Only valid when the
3194870Sstever@eecs.umich.edu     * current command field is an error condition; in that case, the
3204870Sstever@eecs.umich.edu     * previous contents of the command field are copied here.  This
3214870Sstever@eecs.umich.edu     * field is *not* set on non-error responses.
3224870Sstever@eecs.umich.edu     */
3234870Sstever@eecs.umich.edu    MemCmd origCmd;
3244870Sstever@eecs.umich.edu
3258668Sgeoffrey.blake@arm.com    /**
3268668Sgeoffrey.blake@arm.com     * These values specify the range of bytes found that satisfy a
3278668Sgeoffrey.blake@arm.com     * functional read.
3288668Sgeoffrey.blake@arm.com     */
3298668Sgeoffrey.blake@arm.com    uint16_t bytesValidStart;
3308668Sgeoffrey.blake@arm.com    uint16_t bytesValidEnd;
3318668Sgeoffrey.blake@arm.com
3322641Sstever@eecs.umich.edu  public:
3335735Snate@binkert.org    /// Used to calculate latencies for each packet.
3342811Srdreslin@umich.edu    Tick time;
3352811Srdreslin@umich.edu
3365735Snate@binkert.org    /// The time at which the packet will be fully transmitted
3373218Sgblack@eecs.umich.edu    Tick finishTime;
3383218Sgblack@eecs.umich.edu
3395735Snate@binkert.org    /// The time at which the first chunk of the packet will be transmitted
3403218Sgblack@eecs.umich.edu    Tick firstWordTime;
3413218Sgblack@eecs.umich.edu
3425735Snate@binkert.org    /**
3435735Snate@binkert.org     * A virtual base opaque structure used to hold state associated
3445735Snate@binkert.org     * with the packet but specific to the sending device (e.g., an
3455735Snate@binkert.org     * MSHR).  A pointer to this state is returned in the packet's
3465735Snate@binkert.org     * response so that the sender can quickly look up the state
3475735Snate@binkert.org     * needed to process it.  A specific subclass would be derived
3485735Snate@binkert.org     * from this to carry state specific to a particular sending
3495735Snate@binkert.org     * device.
3505735Snate@binkert.org     */
3515735Snate@binkert.org    struct SenderState
3525735Snate@binkert.org    {
3532641Sstever@eecs.umich.edu        virtual ~SenderState() {}
3542641Sstever@eecs.umich.edu    };
3552641Sstever@eecs.umich.edu
3565315Sstever@gmail.com    /**
3575315Sstever@gmail.com     * Object used to maintain state of a PrintReq.  The senderState
3585315Sstever@gmail.com     * field of a PrintReq should always be of this type.
3595315Sstever@gmail.com     */
3609044SAli.Saidi@ARM.com    class PrintReqState : public SenderState
3615735Snate@binkert.org    {
3625735Snate@binkert.org      private:
3635735Snate@binkert.org        /**
3645735Snate@binkert.org         * An entry in the label stack.
3655735Snate@binkert.org         */
3665735Snate@binkert.org        struct LabelStackEntry
3675735Snate@binkert.org        {
3685314Sstever@gmail.com            const std::string label;
3695314Sstever@gmail.com            std::string *prefix;
3705314Sstever@gmail.com            bool labelPrinted;
3715735Snate@binkert.org            LabelStackEntry(const std::string &_label, std::string *_prefix);
3725314Sstever@gmail.com        };
3735314Sstever@gmail.com
3745314Sstever@gmail.com        typedef std::list<LabelStackEntry> LabelStack;
3755314Sstever@gmail.com        LabelStack labelStack;
3765314Sstever@gmail.com
3775314Sstever@gmail.com        std::string *curPrefixPtr;
3785314Sstever@gmail.com
3795314Sstever@gmail.com      public:
3805314Sstever@gmail.com        std::ostream &os;
3815314Sstever@gmail.com        const int verbosity;
3825314Sstever@gmail.com
3835314Sstever@gmail.com        PrintReqState(std::ostream &os, int verbosity = 0);
3845314Sstever@gmail.com        ~PrintReqState();
3855314Sstever@gmail.com
3865735Snate@binkert.org        /**
3875735Snate@binkert.org         * Returns the current line prefix.
3885735Snate@binkert.org         */
3895314Sstever@gmail.com        const std::string &curPrefix() { return *curPrefixPtr; }
3905315Sstever@gmail.com
3915735Snate@binkert.org        /**
3925735Snate@binkert.org         * Push a label onto the label stack, and prepend the given
3935315Sstever@gmail.com         * prefix string onto the current prefix.  Labels will only be
3945735Snate@binkert.org         * printed if an object within the label's scope is printed.
3955735Snate@binkert.org         */
3965314Sstever@gmail.com        void pushLabel(const std::string &lbl,
3975314Sstever@gmail.com                       const std::string &prefix = "  ");
3985735Snate@binkert.org
3995735Snate@binkert.org        /**
4005735Snate@binkert.org         * Pop a label off the label stack.
4015735Snate@binkert.org         */
4025314Sstever@gmail.com        void popLabel();
4035735Snate@binkert.org
4045735Snate@binkert.org        /**
4055735Snate@binkert.org         * Print all of the pending unprinted labels on the
4065315Sstever@gmail.com         * stack. Called by printObj(), so normally not called by
4075735Snate@binkert.org         * users unless bypassing printObj().
4085735Snate@binkert.org         */
4095314Sstever@gmail.com        void printLabels();
4105735Snate@binkert.org
4115735Snate@binkert.org        /**
4125735Snate@binkert.org         * Print a Printable object to os, because it matched the
4135735Snate@binkert.org         * address on a PrintReq.
4145735Snate@binkert.org         */
4155314Sstever@gmail.com        void printObj(Printable *obj);
4165314Sstever@gmail.com    };
4175314Sstever@gmail.com
4185735Snate@binkert.org    /**
4195735Snate@binkert.org     * This packet's sender state.  Devices should use dynamic_cast<>
4205735Snate@binkert.org     * to cast to the state appropriate to the sender.  The intent of
4215735Snate@binkert.org     * this variable is to allow a device to attach extra information
4225735Snate@binkert.org     * to a request.  A response packet must return the sender state
4235735Snate@binkert.org     * that was attached to the original request (even if a new packet
4245735Snate@binkert.org     * is created).
4255735Snate@binkert.org     */
4262662Sstever@eecs.umich.edu    SenderState *senderState;
4272641Sstever@eecs.umich.edu
4285735Snate@binkert.org    /// Return the string name of the cmd field (for debugging and
4295735Snate@binkert.org    /// tracing).
4304022Sstever@eecs.umich.edu    const std::string &cmdString() const { return cmd.toString(); }
4312811Srdreslin@umich.edu
4325735Snate@binkert.org    /// Return the index of this command.
4334022Sstever@eecs.umich.edu    inline int cmdToIndex() const { return cmd.toInt(); }
4342811Srdreslin@umich.edu
4354022Sstever@eecs.umich.edu    bool isRead() const         { return cmd.isRead(); }
4367465Ssteve.reinhardt@amd.com    bool isWrite() const        { return cmd.isWrite(); }
4377465Ssteve.reinhardt@amd.com    bool isUpgrade()  const     { return cmd.isUpgrade(); }
4384022Sstever@eecs.umich.edu    bool isRequest() const      { return cmd.isRequest(); }
4394022Sstever@eecs.umich.edu    bool isResponse() const     { return cmd.isResponse(); }
4404870Sstever@eecs.umich.edu    bool needsExclusive() const { return cmd.needsExclusive(); }
4414022Sstever@eecs.umich.edu    bool needsResponse() const  { return cmd.needsResponse(); }
4424022Sstever@eecs.umich.edu    bool isInvalidate() const   { return cmd.isInvalidate(); }
4434022Sstever@eecs.umich.edu    bool hasData() const        { return cmd.hasData(); }
4444040Ssaidi@eecs.umich.edu    bool isReadWrite() const    { return cmd.isReadWrite(); }
4456102Sgblack@eecs.umich.edu    bool isLLSC() const         { return cmd.isLLSC(); }
4464870Sstever@eecs.umich.edu    bool isError() const        { return cmd.isError(); }
4475314Sstever@gmail.com    bool isPrint() const        { return cmd.isPrint(); }
4488184Ssomayeh@cs.wisc.edu    bool isFlush() const        { return cmd.isFlush(); }
4492812Srdreslin@umich.edu
4504870Sstever@eecs.umich.edu    // Snoop flags
4515735Snate@binkert.org    void assertMemInhibit()     { flags.set(MEM_INHIBIT); }
4525764Snate@binkert.org    bool memInhibitAsserted()   { return flags.isSet(MEM_INHIBIT); }
4535735Snate@binkert.org    void assertShared()         { flags.set(SHARED); }
4545764Snate@binkert.org    bool sharedAsserted()       { return flags.isSet(SHARED); }
4554870Sstever@eecs.umich.edu
4564895Sstever@eecs.umich.edu    // Special control flags
4575735Snate@binkert.org    void setExpressSnoop()      { flags.set(EXPRESS_SNOOP); }
4585764Snate@binkert.org    bool isExpressSnoop()       { return flags.isSet(EXPRESS_SNOOP); }
4595735Snate@binkert.org    void setSupplyExclusive()   { flags.set(SUPPLY_EXCLUSIVE); }
4607687Ssteve.reinhardt@amd.com    void clearSupplyExclusive() { flags.clear(SUPPLY_EXCLUSIVE); }
4615764Snate@binkert.org    bool isSupplyExclusive()    { return flags.isSet(SUPPLY_EXCLUSIVE); }
4628436SBrad.Beckmann@amd.com    void setSuppressFuncError() { flags.set(SUPPRESS_FUNC_ERROR); }
4638436SBrad.Beckmann@amd.com    bool suppressFuncError()    { return flags.isSet(SUPPRESS_FUNC_ERROR); }
4644895Sstever@eecs.umich.edu
4654870Sstever@eecs.umich.edu    // Network error conditions... encapsulate them as methods since
4664870Sstever@eecs.umich.edu    // their encoding keeps changing (from result field to command
4674870Sstever@eecs.umich.edu    // field, etc.)
4685735Snate@binkert.org    void
4695735Snate@binkert.org    setNacked()
4705735Snate@binkert.org    {
4715735Snate@binkert.org        assert(isResponse());
4725735Snate@binkert.org        cmd = MemCmd::NetworkNackError;
4735735Snate@binkert.org    }
4745735Snate@binkert.org
4755735Snate@binkert.org    void
4765735Snate@binkert.org    setBadAddress()
4775735Snate@binkert.org    {
4785735Snate@binkert.org        assert(isResponse());
4795735Snate@binkert.org        cmd = MemCmd::BadAddressError;
4805735Snate@binkert.org    }
4815735Snate@binkert.org
4825735Snate@binkert.org    bool wasNacked() const     { return cmd == MemCmd::NetworkNackError; }
4835735Snate@binkert.org    bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; }
4844986Ssaidi@eecs.umich.edu    void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
4852814Srdreslin@umich.edu
4869031Sandreas.hansson@arm.com    bool isSrcValid() const { return src != InvalidPortID; }
4875735Snate@binkert.org    /// Accessor function to get the source index of the packet.
4889031Sandreas.hansson@arm.com    PortID getSrc() const { assert(isSrcValid()); return src; }
4895735Snate@binkert.org    /// Accessor function to set the source index of the packet.
4909031Sandreas.hansson@arm.com    void setSrc(PortID _src) { src = _src; }
4915735Snate@binkert.org    /// Reset source field, e.g. to retransmit packet on different bus.
4929031Sandreas.hansson@arm.com    void clearSrc() { src = InvalidPortID; }
4932641Sstever@eecs.umich.edu
4949031Sandreas.hansson@arm.com    bool isDestValid() const { return dest != InvalidPortID; }
4955735Snate@binkert.org    /// Accessor function for the destination index of the packet.
4969031Sandreas.hansson@arm.com    PortID getDest() const { assert(isDestValid()); return dest; }
4975735Snate@binkert.org    /// Accessor function to set the destination index of the packet.
4989031Sandreas.hansson@arm.com    void setDest(PortID _dest) { dest = _dest; }
4998949Sandreas.hansson@arm.com    /// Reset destination field, e.g. to turn a response into a request again.
5009031Sandreas.hansson@arm.com    void clearDest() { dest = InvalidPortID; }
5012381SN/A
5025764Snate@binkert.org    Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; }
5036227Snate@binkert.org    unsigned getSize() const  { assert(flags.isSet(VALID_SIZE)); return size; }
5045735Snate@binkert.org    Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); }
5052549SN/A
5065735Snate@binkert.org    /**
5077550SBrad.Beckmann@amd.com     * It has been determined that the SC packet should successfully update
5087550SBrad.Beckmann@amd.com     * memory.  Therefore, convert this SC packet to a normal write.
5097550SBrad.Beckmann@amd.com     */
5107550SBrad.Beckmann@amd.com    void
5117550SBrad.Beckmann@amd.com    convertScToWrite()
5127550SBrad.Beckmann@amd.com    {
5137550SBrad.Beckmann@amd.com        assert(isLLSC());
5147550SBrad.Beckmann@amd.com        assert(isWrite());
5157550SBrad.Beckmann@amd.com        cmd = MemCmd::WriteReq;
5167550SBrad.Beckmann@amd.com    }
5177550SBrad.Beckmann@amd.com
5187550SBrad.Beckmann@amd.com    /**
5197550SBrad.Beckmann@amd.com     * When ruby is in use, Ruby will monitor the cache line and thus M5
5207550SBrad.Beckmann@amd.com     * phys memory should treat LL ops as normal reads.
5217550SBrad.Beckmann@amd.com     */
5227550SBrad.Beckmann@amd.com    void
5237550SBrad.Beckmann@amd.com    convertLlToRead()
5247550SBrad.Beckmann@amd.com    {
5257550SBrad.Beckmann@amd.com        assert(isLLSC());
5267550SBrad.Beckmann@amd.com        assert(isRead());
5277550SBrad.Beckmann@amd.com        cmd = MemCmd::ReadReq;
5287550SBrad.Beckmann@amd.com    }
5297550SBrad.Beckmann@amd.com
5307550SBrad.Beckmann@amd.com    /**
5315735Snate@binkert.org     * Constructor.  Note that a Request object must be constructed
5325735Snate@binkert.org     * first, but the Requests's physical address and size fields need
5339030Sandreas.hansson@arm.com     * not be valid. The command must be supplied.
5345735Snate@binkert.org     */
5358949Sandreas.hansson@arm.com    Packet(Request *_req, MemCmd _cmd)
5368949Sandreas.hansson@arm.com        :  cmd(_cmd), req(_req), data(NULL),
5379031Sandreas.hansson@arm.com           src(InvalidPortID), dest(InvalidPortID),
5388949Sandreas.hansson@arm.com           bytesValidStart(0), bytesValidEnd(0),
5398668Sgeoffrey.blake@arm.com           time(curTick()), senderState(NULL)
5402641Sstever@eecs.umich.edu    {
5416104Ssteve.reinhardt@amd.com        if (req->hasPaddr()) {
5426104Ssteve.reinhardt@amd.com            addr = req->getPaddr();
5436104Ssteve.reinhardt@amd.com            flags.set(VALID_ADDR);
5446104Ssteve.reinhardt@amd.com        }
5456104Ssteve.reinhardt@amd.com        if (req->hasSize()) {
5466104Ssteve.reinhardt@amd.com            size = req->getSize();
5476104Ssteve.reinhardt@amd.com            flags.set(VALID_SIZE);
5486104Ssteve.reinhardt@amd.com        }
5492813Srdreslin@umich.edu    }
5502813Srdreslin@umich.edu
5515735Snate@binkert.org    /**
5525735Snate@binkert.org     * Alternate constructor if you are trying to create a packet with
5535735Snate@binkert.org     * a request that is for a whole block, not the address from the
5545735Snate@binkert.org     * req.  this allows for overriding the size/addr of the req.
5555735Snate@binkert.org     */
5568949Sandreas.hansson@arm.com    Packet(Request *_req, MemCmd _cmd, int _blkSize)
5578949Sandreas.hansson@arm.com        :  cmd(_cmd), req(_req), data(NULL),
5589031Sandreas.hansson@arm.com           src(InvalidPortID), dest(InvalidPortID),
5598949Sandreas.hansson@arm.com           bytesValidStart(0), bytesValidEnd(0),
5608668Sgeoffrey.blake@arm.com           time(curTick()), senderState(NULL)
5612813Srdreslin@umich.edu    {
5626104Ssteve.reinhardt@amd.com        if (req->hasPaddr()) {
5636104Ssteve.reinhardt@amd.com            addr = req->getPaddr() & ~(_blkSize - 1);
5646104Ssteve.reinhardt@amd.com            flags.set(VALID_ADDR);
5656104Ssteve.reinhardt@amd.com        }
5666104Ssteve.reinhardt@amd.com        size = _blkSize;
5676104Ssteve.reinhardt@amd.com        flags.set(VALID_SIZE);
5684626Sstever@eecs.umich.edu    }
5694626Sstever@eecs.umich.edu
5705735Snate@binkert.org    /**
5715735Snate@binkert.org     * Alternate constructor for copying a packet.  Copy all fields
5724887Sstever@eecs.umich.edu     * *except* if the original packet's data was dynamic, don't copy
5734887Sstever@eecs.umich.edu     * that, as we can't guarantee that the new packet's lifetime is
5744887Sstever@eecs.umich.edu     * less than that of the original packet.  In this case the new
5755735Snate@binkert.org     * packet should allocate its own data.
5765735Snate@binkert.org     */
5775735Snate@binkert.org    Packet(Packet *pkt, bool clearFlags = false)
5785735Snate@binkert.org        :  cmd(pkt->cmd), req(pkt->req),
5795764Snate@binkert.org           data(pkt->flags.isSet(STATIC_DATA) ? pkt->data : NULL),
5805735Snate@binkert.org           addr(pkt->addr), size(pkt->size), src(pkt->src), dest(pkt->dest),
5818668Sgeoffrey.blake@arm.com           bytesValidStart(pkt->bytesValidStart), bytesValidEnd(pkt->bytesValidEnd),
5827823Ssteve.reinhardt@amd.com           time(curTick()), senderState(pkt->senderState)
5834626Sstever@eecs.umich.edu    {
5845735Snate@binkert.org        if (!clearFlags)
5855735Snate@binkert.org            flags.set(pkt->flags & COPY_FLAGS);
5865735Snate@binkert.org
5879031Sandreas.hansson@arm.com        flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE));
5885735Snate@binkert.org        flags.set(pkt->flags & STATIC_DATA);
5898668Sgeoffrey.blake@arm.com
5902641Sstever@eecs.umich.edu    }
5912549SN/A
5925735Snate@binkert.org    /**
5935735Snate@binkert.org     * clean up packet variables
5945735Snate@binkert.org     */
5952566SN/A    ~Packet()
5965387Sstever@gmail.com    {
5975387Sstever@gmail.com        // If this is a request packet for which there's no response,
5985387Sstever@gmail.com        // delete the request object here, since the requester will
5995387Sstever@gmail.com        // never get the chance.
6005387Sstever@gmail.com        if (req && isRequest() && !needsResponse())
6015387Sstever@gmail.com            delete req;
6025735Snate@binkert.org        deleteData();
6035387Sstever@gmail.com    }
6042566SN/A
6055735Snate@binkert.org    /**
6065735Snate@binkert.org     * Reinitialize packet address and size from the associated
6075735Snate@binkert.org     * Request object, and reset other fields that may have been
6085735Snate@binkert.org     * modified by a previous transaction.  Typically called when a
6095735Snate@binkert.org     * statically allocated Request/Packet pair is reused for multiple
6105735Snate@binkert.org     * transactions.
6115735Snate@binkert.org     */
6125735Snate@binkert.org    void
6135735Snate@binkert.org    reinitFromRequest()
6145735Snate@binkert.org    {
6156104Ssteve.reinhardt@amd.com        assert(req->hasPaddr());
6164870Sstever@eecs.umich.edu        flags = 0;
6176104Ssteve.reinhardt@amd.com        addr = req->getPaddr();
6186104Ssteve.reinhardt@amd.com        size = req->getSize();
6196223Snate@binkert.org        time = req->time();
6205735Snate@binkert.org
6215735Snate@binkert.org        flags.set(VALID_ADDR|VALID_SIZE);
6225735Snate@binkert.org        deleteData();
6232662Sstever@eecs.umich.edu    }
6242566SN/A
6254626Sstever@eecs.umich.edu    /**
6264626Sstever@eecs.umich.edu     * Take a request packet and modify it in place to be suitable for
6279030Sandreas.hansson@arm.com     * returning as a response to that request. The source field is
6289030Sandreas.hansson@arm.com     * turned into the destination, and subsequently cleared. Note
6299030Sandreas.hansson@arm.com     * that the latter is not necessary for atomic requests, but
6309030Sandreas.hansson@arm.com     * causes no harm as neither field is valid.
6314626Sstever@eecs.umich.edu     */
6325735Snate@binkert.org    void
6335735Snate@binkert.org    makeResponse()
6344626Sstever@eecs.umich.edu    {
6352662Sstever@eecs.umich.edu        assert(needsResponse());
6362855Srdreslin@umich.edu        assert(isRequest());
6374986Ssaidi@eecs.umich.edu        origCmd = cmd;
6384022Sstever@eecs.umich.edu        cmd = cmd.responseCommand();
6395745Snate@binkert.org
6407464Ssteve.reinhardt@amd.com        // responses are never express, even if the snoop that
6417464Ssteve.reinhardt@amd.com        // triggered them was
6427464Ssteve.reinhardt@amd.com        flags.clear(EXPRESS_SNOOP);
6437464Ssteve.reinhardt@amd.com
6445745Snate@binkert.org        dest = src;
6459031Sandreas.hansson@arm.com        clearSrc();
6462641Sstever@eecs.umich.edu    }
6472641Sstever@eecs.umich.edu
6485735Snate@binkert.org    void
6495735Snate@binkert.org    makeAtomicResponse()
6504870Sstever@eecs.umich.edu    {
6514870Sstever@eecs.umich.edu        makeResponse();
6524870Sstever@eecs.umich.edu    }
6534870Sstever@eecs.umich.edu
6545735Snate@binkert.org    void
6555735Snate@binkert.org    makeTimingResponse()
6563348Sbinkertn@umich.edu    {
6574870Sstever@eecs.umich.edu        makeResponse();
6583135Srdreslin@umich.edu    }
6593135Srdreslin@umich.edu
6608436SBrad.Beckmann@amd.com    void
6618436SBrad.Beckmann@amd.com    setFunctionalResponseStatus(bool success)
6628436SBrad.Beckmann@amd.com    {
6638436SBrad.Beckmann@amd.com        if (!success) {
6648436SBrad.Beckmann@amd.com            if (isWrite()) {
6658436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalWriteError;
6668436SBrad.Beckmann@amd.com            } else {
6678436SBrad.Beckmann@amd.com                cmd = MemCmd::FunctionalReadError;
6688436SBrad.Beckmann@amd.com            }
6698436SBrad.Beckmann@amd.com        }
6708436SBrad.Beckmann@amd.com    }
6718436SBrad.Beckmann@amd.com
6723348Sbinkertn@umich.edu    /**
6733348Sbinkertn@umich.edu     * Take a request packet that has been returned as NACKED and
6743348Sbinkertn@umich.edu     * modify it so that it can be sent out again. Only packets that
6753348Sbinkertn@umich.edu     * need a response can be NACKED, so verify that that is true.
6763348Sbinkertn@umich.edu     */
6773348Sbinkertn@umich.edu    void
6783348Sbinkertn@umich.edu    reinitNacked()
6793348Sbinkertn@umich.edu    {
6804870Sstever@eecs.umich.edu        assert(wasNacked());
6814870Sstever@eecs.umich.edu        cmd = origCmd;
6824870Sstever@eecs.umich.edu        assert(needsResponse());
6838949Sandreas.hansson@arm.com        clearDest();
6842685Ssaidi@eecs.umich.edu    }
6852685Ssaidi@eecs.umich.edu
6867006Snate@binkert.org    void
6877006Snate@binkert.org    setSize(unsigned size)
6887006Snate@binkert.org    {
6897006Snate@binkert.org        assert(!flags.isSet(VALID_SIZE));
6907006Snate@binkert.org
6917006Snate@binkert.org        this->size = size;
6927006Snate@binkert.org        flags.set(VALID_SIZE);
6937006Snate@binkert.org    }
6947006Snate@binkert.org
6952685Ssaidi@eecs.umich.edu
6963348Sbinkertn@umich.edu    /**
6973348Sbinkertn@umich.edu     * Set the data pointer to the following value that should not be
6983348Sbinkertn@umich.edu     * freed.
6992566SN/A     */
7002566SN/A    template <typename T>
7013348Sbinkertn@umich.edu    void
7023348Sbinkertn@umich.edu    dataStatic(T *p)
7033348Sbinkertn@umich.edu    {
7045764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
7053348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
7065735Snate@binkert.org        flags.set(STATIC_DATA);
7073348Sbinkertn@umich.edu    }
7082566SN/A
7093348Sbinkertn@umich.edu    /**
7103348Sbinkertn@umich.edu     * Set the data pointer to a value that should have delete []
7113348Sbinkertn@umich.edu     * called on it.
7123348Sbinkertn@umich.edu     */
7132566SN/A    template <typename T>
7143348Sbinkertn@umich.edu    void
7153348Sbinkertn@umich.edu    dataDynamicArray(T *p)
7163348Sbinkertn@umich.edu    {
7175764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
7183348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
7195735Snate@binkert.org        flags.set(DYNAMIC_DATA|ARRAY_DATA);
7203348Sbinkertn@umich.edu    }
7213348Sbinkertn@umich.edu
7223348Sbinkertn@umich.edu    /**
7233348Sbinkertn@umich.edu     * set the data pointer to a value that should have delete called
7243348Sbinkertn@umich.edu     * on it.
7253348Sbinkertn@umich.edu     */
7263348Sbinkertn@umich.edu    template <typename T>
7273348Sbinkertn@umich.edu    void
7283348Sbinkertn@umich.edu    dataDynamic(T *p)
7293348Sbinkertn@umich.edu    {
7305764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
7313348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
7325735Snate@binkert.org        flags.set(DYNAMIC_DATA);
7333348Sbinkertn@umich.edu    }
7343348Sbinkertn@umich.edu
7355735Snate@binkert.org    /**
7365735Snate@binkert.org     * get a pointer to the data ptr.
7375735Snate@binkert.org     */
7383348Sbinkertn@umich.edu    template <typename T>
7393348Sbinkertn@umich.edu    T*
7407915SBrad.Beckmann@amd.com    getPtr(bool null_ok = false)
7413348Sbinkertn@umich.edu    {
7427915SBrad.Beckmann@amd.com        assert(null_ok || flags.isSet(STATIC_DATA|DYNAMIC_DATA));
7433348Sbinkertn@umich.edu        return (T*)data;
7443348Sbinkertn@umich.edu    }
7452566SN/A
7465735Snate@binkert.org    /**
7475735Snate@binkert.org     * return the value of what is pointed to in the packet.
7485735Snate@binkert.org     */
7492566SN/A    template <typename T>
7502592SN/A    T get();
7512566SN/A
7525735Snate@binkert.org    /**
7535735Snate@binkert.org     * set the value in the data pointer to v.
7545735Snate@binkert.org     */
7552566SN/A    template <typename T>
7562592SN/A    void set(T v);
7572566SN/A
7583348Sbinkertn@umich.edu    /**
7594626Sstever@eecs.umich.edu     * Copy data into the packet from the provided pointer.
7604626Sstever@eecs.umich.edu     */
7615735Snate@binkert.org    void
7625735Snate@binkert.org    setData(uint8_t *p)
7634626Sstever@eecs.umich.edu    {
7647691SAli.Saidi@ARM.com        if (p != getPtr<uint8_t>())
7657691SAli.Saidi@ARM.com            std::memcpy(getPtr<uint8_t>(), p, getSize());
7664626Sstever@eecs.umich.edu    }
7674626Sstever@eecs.umich.edu
7684626Sstever@eecs.umich.edu    /**
7694626Sstever@eecs.umich.edu     * Copy data into the packet from the provided block pointer,
7704626Sstever@eecs.umich.edu     * which is aligned to the given block size.
7714626Sstever@eecs.umich.edu     */
7725735Snate@binkert.org    void
7735735Snate@binkert.org    setDataFromBlock(uint8_t *blk_data, int blkSize)
7744626Sstever@eecs.umich.edu    {
7754626Sstever@eecs.umich.edu        setData(blk_data + getOffset(blkSize));
7764626Sstever@eecs.umich.edu    }
7774626Sstever@eecs.umich.edu
7784626Sstever@eecs.umich.edu    /**
7794626Sstever@eecs.umich.edu     * Copy data from the packet to the provided block pointer, which
7804626Sstever@eecs.umich.edu     * is aligned to the given block size.
7814626Sstever@eecs.umich.edu     */
7825735Snate@binkert.org    void
7835735Snate@binkert.org    writeData(uint8_t *p)
7844626Sstever@eecs.umich.edu    {
7854626Sstever@eecs.umich.edu        std::memcpy(p, getPtr<uint8_t>(), getSize());
7864626Sstever@eecs.umich.edu    }
7874626Sstever@eecs.umich.edu
7884626Sstever@eecs.umich.edu    /**
7894626Sstever@eecs.umich.edu     * Copy data from the packet to the memory at the provided pointer.
7904626Sstever@eecs.umich.edu     */
7915735Snate@binkert.org    void
7925735Snate@binkert.org    writeDataToBlock(uint8_t *blk_data, int blkSize)
7934626Sstever@eecs.umich.edu    {
7944626Sstever@eecs.umich.edu        writeData(blk_data + getOffset(blkSize));
7954626Sstever@eecs.umich.edu    }
7964626Sstever@eecs.umich.edu
7974626Sstever@eecs.umich.edu    /**
7983348Sbinkertn@umich.edu     * delete the data pointed to in the data pointer. Ok to call to
7993348Sbinkertn@umich.edu     * matter how data was allocted.
8003348Sbinkertn@umich.edu     */
8015735Snate@binkert.org    void
8025735Snate@binkert.org    deleteData()
8035735Snate@binkert.org    {
8045764Snate@binkert.org        if (flags.isSet(ARRAY_DATA))
8055735Snate@binkert.org            delete [] data;
8065764Snate@binkert.org        else if (flags.isSet(DYNAMIC_DATA))
8075735Snate@binkert.org            delete data;
8085735Snate@binkert.org
8095735Snate@binkert.org        flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA);
8105735Snate@binkert.org        data = NULL;
8115735Snate@binkert.org    }
8122566SN/A
8132566SN/A    /** If there isn't data in the packet, allocate some. */
8145735Snate@binkert.org    void
8155735Snate@binkert.org    allocate()
8165735Snate@binkert.org    {
8175735Snate@binkert.org        if (data) {
8185764Snate@binkert.org            assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
8195745Snate@binkert.org            return;
8205735Snate@binkert.org        }
8215745Snate@binkert.org
8225764Snate@binkert.org        assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
8235745Snate@binkert.org        flags.set(DYNAMIC_DATA|ARRAY_DATA);
8245745Snate@binkert.org        data = new uint8_t[getSize()];
8255735Snate@binkert.org    }
8265735Snate@binkert.org
8274626Sstever@eecs.umich.edu    /**
8284626Sstever@eecs.umich.edu     * Check a functional request against a memory value represented
8294626Sstever@eecs.umich.edu     * by a base/size pair and an associated data array.  If the
8304626Sstever@eecs.umich.edu     * functional request is a read, it may be satisfied by the memory
8314626Sstever@eecs.umich.edu     * value.  If the functional request is a write, it may update the
8324626Sstever@eecs.umich.edu     * memory value.
8334626Sstever@eecs.umich.edu     */
8345314Sstever@gmail.com    bool checkFunctional(Printable *obj, Addr base, int size, uint8_t *data);
8354626Sstever@eecs.umich.edu
8364626Sstever@eecs.umich.edu    /**
8374626Sstever@eecs.umich.edu     * Check a functional request against a memory value stored in
8385315Sstever@gmail.com     * another packet (i.e. an in-transit request or response).
8394626Sstever@eecs.umich.edu     */
8405735Snate@binkert.org    bool
8415735Snate@binkert.org    checkFunctional(PacketPtr other)
8425735Snate@binkert.org    {
8435735Snate@binkert.org        uint8_t *data = other->hasData() ? other->getPtr<uint8_t>() : NULL;
8445735Snate@binkert.org        return checkFunctional(other, other->getAddr(), other->getSize(),
8455735Snate@binkert.org                               data);
8464626Sstever@eecs.umich.edu    }
8475314Sstever@gmail.com
8485315Sstever@gmail.com    /**
8495315Sstever@gmail.com     * Push label for PrintReq (safe to call unconditionally).
8505315Sstever@gmail.com     */
8515735Snate@binkert.org    void
8525735Snate@binkert.org    pushLabel(const std::string &lbl)
8535735Snate@binkert.org    {
8545735Snate@binkert.org        if (isPrint())
8555735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->pushLabel(lbl);
8565314Sstever@gmail.com    }
8575314Sstever@gmail.com
8585315Sstever@gmail.com    /**
8595315Sstever@gmail.com     * Pop label for PrintReq (safe to call unconditionally).
8605315Sstever@gmail.com     */
8615735Snate@binkert.org    void
8625735Snate@binkert.org    popLabel()
8635735Snate@binkert.org    {
8645735Snate@binkert.org        if (isPrint())
8655735Snate@binkert.org            safe_cast<PrintReqState*>(senderState)->popLabel();
8665314Sstever@gmail.com    }
8675314Sstever@gmail.com
8685314Sstever@gmail.com    void print(std::ostream &o, int verbosity = 0,
8695314Sstever@gmail.com               const std::string &prefix = "") const;
8702381SN/A};
8712381SN/A
8722381SN/A#endif //__MEM_PACKET_HH
873