packet.hh revision 4167
12381SN/A/*
22592SN/A * Copyright (c) 2006 The Regents of The University of Michigan
32381SN/A * All rights reserved.
42381SN/A *
52381SN/A * Redistribution and use in source and binary forms, with or without
62381SN/A * modification, are permitted provided that the following conditions are
72381SN/A * met: redistributions of source code must retain the above copyright
82381SN/A * notice, this list of conditions and the following disclaimer;
92381SN/A * redistributions in binary form must reproduce the above copyright
102381SN/A * notice, this list of conditions and the following disclaimer in the
112381SN/A * documentation and/or other materials provided with the distribution;
122381SN/A * neither the name of the copyright holders nor the names of its
132381SN/A * contributors may be used to endorse or promote products derived from
142381SN/A * this software without specific prior written permission.
152381SN/A *
162381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Ron Dreslinski
292665Ssaidi@eecs.umich.edu *          Steve Reinhardt
302665Ssaidi@eecs.umich.edu *          Ali Saidi
312381SN/A */
322381SN/A
332381SN/A/**
342381SN/A * @file
352662Sstever@eecs.umich.edu * Declaration of the Packet class.
362381SN/A */
372381SN/A
382381SN/A#ifndef __MEM_PACKET_HH__
392381SN/A#define __MEM_PACKET_HH__
402381SN/A
413348Sbinkertn@umich.edu#include <cassert>
423348Sbinkertn@umich.edu#include <list>
434022Sstever@eecs.umich.edu#include <bitset>
443348Sbinkertn@umich.edu
454024Sbinkertn@umich.edu#include "base/compiler.hh"
463940Ssaidi@eecs.umich.edu#include "base/misc.hh"
472392SN/A#include "mem/request.hh"
482980Sgblack@eecs.umich.edu#include "sim/host.hh"
494167Sbinkertn@umich.edu#include "sim/core.hh"
502394SN/A
513940Ssaidi@eecs.umich.edu
522394SN/Astruct Packet;
533349Sbinkertn@umich.edutypedef Packet *PacketPtr;
542394SN/Atypedef uint8_t* PacketDataPtr;
552812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList;
562812Srdreslin@umich.edu
572812Srdreslin@umich.edu//Coherence Flags
583366Sstever@eecs.umich.edu#define NACKED_LINE     (1 << 0)
593366Sstever@eecs.umich.edu#define SATISFIED       (1 << 1)
603366Sstever@eecs.umich.edu#define SHARED_LINE     (1 << 2)
613366Sstever@eecs.umich.edu#define CACHE_LINE_FILL (1 << 3)
623366Sstever@eecs.umich.edu#define COMPRESSED      (1 << 4)
633366Sstever@eecs.umich.edu#define NO_ALLOCATE     (1 << 5)
643366Sstever@eecs.umich.edu#define SNOOP_COMMIT    (1 << 6)
652382SN/A
664022Sstever@eecs.umich.edu
674022Sstever@eecs.umich.educlass MemCmd
684022Sstever@eecs.umich.edu{
694022Sstever@eecs.umich.edu  public:
704022Sstever@eecs.umich.edu
714022Sstever@eecs.umich.edu    /** List of all commands associated with a packet. */
724022Sstever@eecs.umich.edu    enum Command
734022Sstever@eecs.umich.edu    {
744022Sstever@eecs.umich.edu        InvalidCmd,
754022Sstever@eecs.umich.edu        ReadReq,
764022Sstever@eecs.umich.edu        WriteReq,
774022Sstever@eecs.umich.edu        WriteReqNoAck,
784022Sstever@eecs.umich.edu        ReadResp,
794022Sstever@eecs.umich.edu        WriteResp,
804022Sstever@eecs.umich.edu        Writeback,
814022Sstever@eecs.umich.edu        SoftPFReq,
824022Sstever@eecs.umich.edu        HardPFReq,
834022Sstever@eecs.umich.edu        SoftPFResp,
844022Sstever@eecs.umich.edu        HardPFResp,
854022Sstever@eecs.umich.edu        InvalidateReq,
864022Sstever@eecs.umich.edu        WriteInvalidateReq,
874022Sstever@eecs.umich.edu        WriteInvalidateResp,
884022Sstever@eecs.umich.edu        UpgradeReq,
894022Sstever@eecs.umich.edu        ReadExReq,
904022Sstever@eecs.umich.edu        ReadExResp,
914040Ssaidi@eecs.umich.edu        SwapReq,
924040Ssaidi@eecs.umich.edu        SwapResp,
934022Sstever@eecs.umich.edu        NUM_MEM_CMDS
944022Sstever@eecs.umich.edu    };
954022Sstever@eecs.umich.edu
964022Sstever@eecs.umich.edu  private:
974022Sstever@eecs.umich.edu    /** List of command attributes. */
984022Sstever@eecs.umich.edu    enum Attribute
994022Sstever@eecs.umich.edu    {
1004022Sstever@eecs.umich.edu        IsRead,
1014022Sstever@eecs.umich.edu        IsWrite,
1024022Sstever@eecs.umich.edu        IsPrefetch,
1034022Sstever@eecs.umich.edu        IsInvalidate,
1044022Sstever@eecs.umich.edu        IsRequest,
1054022Sstever@eecs.umich.edu        IsResponse,
1064022Sstever@eecs.umich.edu        NeedsResponse,
1074022Sstever@eecs.umich.edu        IsSWPrefetch,
1084022Sstever@eecs.umich.edu        IsHWPrefetch,
1094022Sstever@eecs.umich.edu        IsUpgrade,
1104022Sstever@eecs.umich.edu        HasData,
1114040Ssaidi@eecs.umich.edu        IsReadWrite,
1124022Sstever@eecs.umich.edu        NUM_COMMAND_ATTRIBUTES
1134022Sstever@eecs.umich.edu    };
1144022Sstever@eecs.umich.edu
1154022Sstever@eecs.umich.edu    /** Structure that defines attributes and other data associated
1164022Sstever@eecs.umich.edu     * with a Command. */
1174022Sstever@eecs.umich.edu    struct CommandInfo {
1184022Sstever@eecs.umich.edu        /** Set of attribute flags. */
1194022Sstever@eecs.umich.edu        const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
1204022Sstever@eecs.umich.edu        /** Corresponding response for requests; InvalidCmd if no
1214022Sstever@eecs.umich.edu         * response is applicable. */
1224022Sstever@eecs.umich.edu        const Command response;
1234022Sstever@eecs.umich.edu        /** String representation (for printing) */
1244022Sstever@eecs.umich.edu        const std::string str;
1254022Sstever@eecs.umich.edu    };
1264022Sstever@eecs.umich.edu
1274022Sstever@eecs.umich.edu    /** Array to map Command enum to associated info. */
1284022Sstever@eecs.umich.edu    static const CommandInfo commandInfo[];
1294022Sstever@eecs.umich.edu
1304022Sstever@eecs.umich.edu  private:
1314022Sstever@eecs.umich.edu
1324022Sstever@eecs.umich.edu    Command cmd;
1334022Sstever@eecs.umich.edu
1344022Sstever@eecs.umich.edu    bool testCmdAttrib(MemCmd::Attribute attrib) const {
1354022Sstever@eecs.umich.edu        return commandInfo[cmd].attributes[attrib] != 0;
1364022Sstever@eecs.umich.edu    }
1374022Sstever@eecs.umich.edu
1384022Sstever@eecs.umich.edu  public:
1394022Sstever@eecs.umich.edu
1404022Sstever@eecs.umich.edu    bool isRead() const         { return testCmdAttrib(IsRead); }
1414022Sstever@eecs.umich.edu    bool isWrite()  const       { return testCmdAttrib(IsWrite); }
1424022Sstever@eecs.umich.edu    bool isRequest() const      { return testCmdAttrib(IsRequest); }
1434022Sstever@eecs.umich.edu    bool isResponse() const     { return testCmdAttrib(IsResponse); }
1444022Sstever@eecs.umich.edu    bool needsResponse() const  { return testCmdAttrib(NeedsResponse); }
1454022Sstever@eecs.umich.edu    bool isInvalidate() const   { return testCmdAttrib(IsInvalidate); }
1464022Sstever@eecs.umich.edu    bool hasData() const        { return testCmdAttrib(HasData); }
1474040Ssaidi@eecs.umich.edu    bool isReadWrite() const    { return testCmdAttrib(IsReadWrite); }
1484022Sstever@eecs.umich.edu
1494022Sstever@eecs.umich.edu    const Command responseCommand() const {
1504022Sstever@eecs.umich.edu        return commandInfo[cmd].response;
1514022Sstever@eecs.umich.edu    }
1524022Sstever@eecs.umich.edu
1534022Sstever@eecs.umich.edu    /** Return the string to a cmd given by idx. */
1544022Sstever@eecs.umich.edu    const std::string &toString() const {
1554022Sstever@eecs.umich.edu        return commandInfo[cmd].str;
1564022Sstever@eecs.umich.edu    }
1574022Sstever@eecs.umich.edu
1584022Sstever@eecs.umich.edu    int toInt() const { return (int)cmd; }
1594022Sstever@eecs.umich.edu
1604022Sstever@eecs.umich.edu    MemCmd(Command _cmd)
1614022Sstever@eecs.umich.edu        : cmd(_cmd)
1624022Sstever@eecs.umich.edu    { }
1634022Sstever@eecs.umich.edu
1644022Sstever@eecs.umich.edu    MemCmd(int _cmd)
1654022Sstever@eecs.umich.edu        : cmd((Command)_cmd)
1664022Sstever@eecs.umich.edu    { }
1674022Sstever@eecs.umich.edu
1684022Sstever@eecs.umich.edu    MemCmd()
1694022Sstever@eecs.umich.edu        : cmd(InvalidCmd)
1704022Sstever@eecs.umich.edu    { }
1714022Sstever@eecs.umich.edu
1724022Sstever@eecs.umich.edu    bool operator==(MemCmd c2) { return (cmd == c2.cmd); }
1734022Sstever@eecs.umich.edu    bool operator!=(MemCmd c2) { return (cmd != c2.cmd); }
1744022Sstever@eecs.umich.edu
1754022Sstever@eecs.umich.edu    friend class Packet;
1764022Sstever@eecs.umich.edu};
1774022Sstever@eecs.umich.edu
1782381SN/A/**
1792662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in
1802662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache).  (In contrast, a
1812662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the
1822662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several
1832662Sstever@eecs.umich.edu * different Packets along the way.)
1842381SN/A */
1852641Sstever@eecs.umich.educlass Packet
1862381SN/A{
1872813Srdreslin@umich.edu  public:
1884022Sstever@eecs.umich.edu
1894022Sstever@eecs.umich.edu    typedef MemCmd::Command Command;
1904022Sstever@eecs.umich.edu
1912813Srdreslin@umich.edu    /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */
1922813Srdreslin@umich.edu    uint64_t flags;
1932813Srdreslin@umich.edu
1942566SN/A  private:
1952662Sstever@eecs.umich.edu   /** A pointer to the data being transfered.  It can be differnt
1962662Sstever@eecs.umich.edu    *    sizes at each level of the heirarchy so it belongs in the
1972662Sstever@eecs.umich.edu    *    packet, not request. This may or may not be populated when a
1982662Sstever@eecs.umich.edu    *    responder recieves the packet. If not populated it memory
1992662Sstever@eecs.umich.edu    *    should be allocated.
2002566SN/A    */
2012566SN/A    PacketDataPtr data;
2022566SN/A
2032662Sstever@eecs.umich.edu    /** Is the data pointer set to a value that shouldn't be freed
2042662Sstever@eecs.umich.edu     *   when the packet is destroyed? */
2052566SN/A    bool staticData;
2062662Sstever@eecs.umich.edu    /** The data pointer points to a value that should be freed when
2072662Sstever@eecs.umich.edu     *   the packet is destroyed. */
2082566SN/A    bool dynamicData;
2092662Sstever@eecs.umich.edu    /** the data pointer points to an array (thus delete [] ) needs to
2102662Sstever@eecs.umich.edu     *   be called on it rather than simply delete.*/
2112566SN/A    bool arrayData;
2122566SN/A
2132662Sstever@eecs.umich.edu    /** The address of the request.  This address could be virtual or
2142662Sstever@eecs.umich.edu     *   physical, depending on the system configuration. */
2152381SN/A    Addr addr;
2162381SN/A
2172662Sstever@eecs.umich.edu     /** The size of the request or transfer. */
2182381SN/A    int size;
2192381SN/A
2202662Sstever@eecs.umich.edu    /** Device address (e.g., bus ID) of the source of the
2212662Sstever@eecs.umich.edu     *   transaction. The source is not responsible for setting this
2222662Sstever@eecs.umich.edu     *   field; it is set implicitly by the interconnect when the
2233349Sbinkertn@umich.edu     *   packet is first sent.  */
2242381SN/A    short src;
2252381SN/A
2262662Sstever@eecs.umich.edu    /** Device address (e.g., bus ID) of the destination of the
2272662Sstever@eecs.umich.edu     *   transaction. The special value Broadcast indicates that the
2282662Sstever@eecs.umich.edu     *   packet should be routed based on its address. This field is
2292662Sstever@eecs.umich.edu     *   initialized in the constructor and is thus always valid
2302662Sstever@eecs.umich.edu     *   (unlike * addr, size, and src). */
2312641Sstever@eecs.umich.edu    short dest;
2322641Sstever@eecs.umich.edu
2332663Sstever@eecs.umich.edu    /** Are the 'addr' and 'size' fields valid? */
2342663Sstever@eecs.umich.edu    bool addrSizeValid;
2352662Sstever@eecs.umich.edu    /** Is the 'src' field valid? */
2362641Sstever@eecs.umich.edu    bool srcValid;
2372813Srdreslin@umich.edu
2382641Sstever@eecs.umich.edu
2392641Sstever@eecs.umich.edu  public:
2402641Sstever@eecs.umich.edu
2412811Srdreslin@umich.edu    /** Used to calculate latencies for each packet.*/
2422811Srdreslin@umich.edu    Tick time;
2432811Srdreslin@umich.edu
2443218Sgblack@eecs.umich.edu    /** The time at which the packet will be fully transmitted */
2453218Sgblack@eecs.umich.edu    Tick finishTime;
2463218Sgblack@eecs.umich.edu
2473218Sgblack@eecs.umich.edu    /** The time at which the first chunk of the packet will be transmitted */
2483218Sgblack@eecs.umich.edu    Tick firstWordTime;
2493218Sgblack@eecs.umich.edu
2502662Sstever@eecs.umich.edu    /** The special destination address indicating that the packet
2512662Sstever@eecs.umich.edu     *   should be routed based on its address. */
2522623SN/A    static const short Broadcast = -1;
2532623SN/A
2542662Sstever@eecs.umich.edu    /** A pointer to the original request. */
2552641Sstever@eecs.umich.edu    RequestPtr req;
2562641Sstever@eecs.umich.edu
2572662Sstever@eecs.umich.edu    /** A virtual base opaque structure used to hold coherence-related
2582662Sstever@eecs.umich.edu     *    state.  A specific subclass would be derived from this to
2592662Sstever@eecs.umich.edu     *    carry state specific to a particular coherence protocol.  */
2602641Sstever@eecs.umich.edu    class CoherenceState {
2612641Sstever@eecs.umich.edu      public:
2622641Sstever@eecs.umich.edu        virtual ~CoherenceState() {}
2632641Sstever@eecs.umich.edu    };
2642641Sstever@eecs.umich.edu
2652662Sstever@eecs.umich.edu    /** This packet's coherence state.  Caches should use
2662662Sstever@eecs.umich.edu     *   dynamic_cast<> to cast to the state appropriate for the
2672662Sstever@eecs.umich.edu     *   system's coherence protocol.  */
2682662Sstever@eecs.umich.edu    CoherenceState *coherence;
2692641Sstever@eecs.umich.edu
2702662Sstever@eecs.umich.edu    /** A virtual base opaque structure used to hold state associated
2712662Sstever@eecs.umich.edu     *    with the packet but specific to the sending device (e.g., an
2722662Sstever@eecs.umich.edu     *    MSHR).  A pointer to this state is returned in the packet's
2732662Sstever@eecs.umich.edu     *    response so that the sender can quickly look up the state
2742662Sstever@eecs.umich.edu     *    needed to process it.  A specific subclass would be derived
2752662Sstever@eecs.umich.edu     *    from this to carry state specific to a particular sending
2762662Sstever@eecs.umich.edu     *    device.  */
2772641Sstever@eecs.umich.edu    class SenderState {
2782641Sstever@eecs.umich.edu      public:
2792641Sstever@eecs.umich.edu        virtual ~SenderState() {}
2802641Sstever@eecs.umich.edu    };
2812641Sstever@eecs.umich.edu
2822662Sstever@eecs.umich.edu    /** This packet's sender state.  Devices should use dynamic_cast<>
2832662Sstever@eecs.umich.edu     *   to cast to the state appropriate to the sender. */
2842662Sstever@eecs.umich.edu    SenderState *senderState;
2852641Sstever@eecs.umich.edu
2864022Sstever@eecs.umich.edu  public:
2872641Sstever@eecs.umich.edu
2884022Sstever@eecs.umich.edu    /** The command field of the packet. */
2894022Sstever@eecs.umich.edu    MemCmd cmd;
2902641Sstever@eecs.umich.edu
2912662Sstever@eecs.umich.edu    /** Return the string name of the cmd field (for debugging and
2922662Sstever@eecs.umich.edu     *   tracing). */
2934022Sstever@eecs.umich.edu    const std::string &cmdString() const { return cmd.toString(); }
2942811Srdreslin@umich.edu
2952811Srdreslin@umich.edu    /** Return the index of this command. */
2964022Sstever@eecs.umich.edu    inline int cmdToIndex() const { return cmd.toInt(); }
2972811Srdreslin@umich.edu
2984022Sstever@eecs.umich.edu  public:
2992381SN/A
3004022Sstever@eecs.umich.edu    bool isRead() const         { return cmd.isRead(); }
3014022Sstever@eecs.umich.edu    bool isWrite()  const       { return cmd.isWrite(); }
3024022Sstever@eecs.umich.edu    bool isRequest() const      { return cmd.isRequest(); }
3034022Sstever@eecs.umich.edu    bool isResponse() const     { return cmd.isResponse(); }
3044022Sstever@eecs.umich.edu    bool needsResponse() const  { return cmd.needsResponse(); }
3054022Sstever@eecs.umich.edu    bool isInvalidate() const   { return cmd.isInvalidate(); }
3064022Sstever@eecs.umich.edu    bool hasData() const        { return cmd.hasData(); }
3074040Ssaidi@eecs.umich.edu    bool isReadWrite() const    { return cmd.isReadWrite(); }
3082812Srdreslin@umich.edu
3093260Ssaidi@eecs.umich.edu    bool isCacheFill() const    { return (flags & CACHE_LINE_FILL) != 0; }
3103260Ssaidi@eecs.umich.edu    bool isNoAllocate() const   { return (flags & NO_ALLOCATE) != 0; }
3113260Ssaidi@eecs.umich.edu    bool isCompressed() const   { return (flags & COMPRESSED) != 0; }
3122814Srdreslin@umich.edu
3133940Ssaidi@eecs.umich.edu    bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN }
3142641Sstever@eecs.umich.edu
3152662Sstever@eecs.umich.edu    /** Possible results of a packet's request. */
3162641Sstever@eecs.umich.edu    enum Result
3172641Sstever@eecs.umich.edu    {
3182641Sstever@eecs.umich.edu        Success,
3192641Sstever@eecs.umich.edu        BadAddress,
3202685Ssaidi@eecs.umich.edu        Nacked,
3212641Sstever@eecs.umich.edu        Unknown
3222641Sstever@eecs.umich.edu    };
3232641Sstever@eecs.umich.edu
3242662Sstever@eecs.umich.edu    /** The result of this packet's request. */
3252641Sstever@eecs.umich.edu    Result result;
3262381SN/A
3272381SN/A    /** Accessor function that returns the source index of the packet. */
3282641Sstever@eecs.umich.edu    short getSrc() const { assert(srcValid); return src; }
3292641Sstever@eecs.umich.edu    void setSrc(short _src) { src = _src; srcValid = true; }
3302381SN/A
3312381SN/A    /** Accessor function that returns the destination index of
3322381SN/A        the packet. */
3332381SN/A    short getDest() const { return dest; }
3342641Sstever@eecs.umich.edu    void setDest(short _dest) { dest = _dest; }
3352549SN/A
3362663Sstever@eecs.umich.edu    Addr getAddr() const { assert(addrSizeValid); return addr; }
3372663Sstever@eecs.umich.edu    int getSize() const { assert(addrSizeValid); return size; }
3382883Srdreslin@umich.edu    Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); }
3392813Srdreslin@umich.edu
3402813Srdreslin@umich.edu    void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; }
3414022Sstever@eecs.umich.edu    void cmdOverride(MemCmd newCmd) { cmd = newCmd; }
3422641Sstever@eecs.umich.edu
3432662Sstever@eecs.umich.edu    /** Constructor.  Note that a Request object must be constructed
3442662Sstever@eecs.umich.edu     *   first, but the Requests's physical address and size fields
3452662Sstever@eecs.umich.edu     *   need not be valid. The command and destination addresses
3462662Sstever@eecs.umich.edu     *   must be supplied.  */
3474022Sstever@eecs.umich.edu    Packet(Request *_req, MemCmd _cmd, short _dest)
3482566SN/A        :  data(NULL), staticData(false), dynamicData(false), arrayData(false),
3492641Sstever@eecs.umich.edu           addr(_req->paddr), size(_req->size), dest(_dest),
3502663Sstever@eecs.umich.edu           addrSizeValid(_req->validPaddr),
3512814Srdreslin@umich.edu           srcValid(false),
3522641Sstever@eecs.umich.edu           req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
3532662Sstever@eecs.umich.edu           result(Unknown)
3542641Sstever@eecs.umich.edu    {
3552813Srdreslin@umich.edu        flags = 0;
3563018Srdreslin@umich.edu        time = curTick;
3572813Srdreslin@umich.edu    }
3582813Srdreslin@umich.edu
3592813Srdreslin@umich.edu    /** Alternate constructor if you are trying to create a packet with
3602813Srdreslin@umich.edu     *  a request that is for a whole block, not the address from the req.
3612813Srdreslin@umich.edu     *  this allows for overriding the size/addr of the req.*/
3624022Sstever@eecs.umich.edu    Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize)
3632813Srdreslin@umich.edu        :  data(NULL), staticData(false), dynamicData(false), arrayData(false),
3642813Srdreslin@umich.edu           addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize),
3652814Srdreslin@umich.edu           dest(_dest),
3662814Srdreslin@umich.edu           addrSizeValid(_req->validPaddr), srcValid(false),
3672813Srdreslin@umich.edu           req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
3682813Srdreslin@umich.edu           result(Unknown)
3692813Srdreslin@umich.edu    {
3702813Srdreslin@umich.edu        flags = 0;
3713018Srdreslin@umich.edu        time = curTick;
3722641Sstever@eecs.umich.edu    }
3732549SN/A
3742662Sstever@eecs.umich.edu    /** Destructor. */
3752566SN/A    ~Packet()
3763665Srdreslin@umich.edu    { if (staticData || dynamicData) deleteData(); }
3772566SN/A
3782662Sstever@eecs.umich.edu    /** Reinitialize packet address and size from the associated
3792662Sstever@eecs.umich.edu     *   Request object, and reset other fields that may have been
3802662Sstever@eecs.umich.edu     *   modified by a previous transaction.  Typically called when a
3812662Sstever@eecs.umich.edu     *   statically allocated Request/Packet pair is reused for
3822662Sstever@eecs.umich.edu     *   multiple transactions. */
3832662Sstever@eecs.umich.edu    void reinitFromRequest() {
3842662Sstever@eecs.umich.edu        assert(req->validPaddr);
3853369Sstever@eecs.umich.edu        flags = 0;
3862663Sstever@eecs.umich.edu        addr = req->paddr;
3872663Sstever@eecs.umich.edu        size = req->size;
3883018Srdreslin@umich.edu        time = req->time;
3892663Sstever@eecs.umich.edu        addrSizeValid = true;
3902662Sstever@eecs.umich.edu        result = Unknown;
3912662Sstever@eecs.umich.edu        if (dynamicData) {
3922662Sstever@eecs.umich.edu            deleteData();
3932662Sstever@eecs.umich.edu            dynamicData = false;
3942662Sstever@eecs.umich.edu            arrayData = false;
3952662Sstever@eecs.umich.edu        }
3962662Sstever@eecs.umich.edu    }
3972566SN/A
3982662Sstever@eecs.umich.edu    /** Take a request packet and modify it in place to be suitable
3992662Sstever@eecs.umich.edu     *   for returning as a response to that request.  Used for timing
4002662Sstever@eecs.umich.edu     *   accesses only.  For atomic and functional accesses, the
4012662Sstever@eecs.umich.edu     *   request packet is always implicitly passed back *without*
4023135Srdreslin@umich.edu     *   modifying the destination fields, so this function
4032662Sstever@eecs.umich.edu     *   should not be called. */
4042662Sstever@eecs.umich.edu    void makeTimingResponse() {
4052662Sstever@eecs.umich.edu        assert(needsResponse());
4062855Srdreslin@umich.edu        assert(isRequest());
4074022Sstever@eecs.umich.edu        cmd = cmd.responseCommand();
4082662Sstever@eecs.umich.edu        dest = src;
4092662Sstever@eecs.umich.edu        srcValid = false;
4102641Sstever@eecs.umich.edu    }
4112641Sstever@eecs.umich.edu
4123348Sbinkertn@umich.edu    /**
4133348Sbinkertn@umich.edu     * Take a request packet and modify it in place to be suitable for
4143348Sbinkertn@umich.edu     * returning as a response to that request.
4153135Srdreslin@umich.edu     */
4163348Sbinkertn@umich.edu    void makeAtomicResponse()
4173348Sbinkertn@umich.edu    {
4183135Srdreslin@umich.edu        assert(needsResponse());
4193135Srdreslin@umich.edu        assert(isRequest());
4204022Sstever@eecs.umich.edu        cmd = cmd.responseCommand();
4213135Srdreslin@umich.edu    }
4223135Srdreslin@umich.edu
4233348Sbinkertn@umich.edu    /**
4243348Sbinkertn@umich.edu     * Take a request packet that has been returned as NACKED and
4253348Sbinkertn@umich.edu     * modify it so that it can be sent out again. Only packets that
4263348Sbinkertn@umich.edu     * need a response can be NACKED, so verify that that is true.
4273348Sbinkertn@umich.edu     */
4283348Sbinkertn@umich.edu    void
4293348Sbinkertn@umich.edu    reinitNacked()
4303348Sbinkertn@umich.edu    {
4312685Ssaidi@eecs.umich.edu        assert(needsResponse() && result == Nacked);
4322685Ssaidi@eecs.umich.edu        dest =  Broadcast;
4332685Ssaidi@eecs.umich.edu        result = Unknown;
4342685Ssaidi@eecs.umich.edu    }
4352685Ssaidi@eecs.umich.edu
4362685Ssaidi@eecs.umich.edu
4373348Sbinkertn@umich.edu    /**
4383348Sbinkertn@umich.edu     * Set the data pointer to the following value that should not be
4393348Sbinkertn@umich.edu     * freed.
4402566SN/A     */
4412566SN/A    template <typename T>
4423348Sbinkertn@umich.edu    void
4433348Sbinkertn@umich.edu    dataStatic(T *p)
4443348Sbinkertn@umich.edu    {
4453348Sbinkertn@umich.edu        if(dynamicData)
4463348Sbinkertn@umich.edu            dynamicData = false;
4473348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
4483348Sbinkertn@umich.edu        staticData = true;
4493348Sbinkertn@umich.edu    }
4502566SN/A
4513348Sbinkertn@umich.edu    /**
4523348Sbinkertn@umich.edu     * Set the data pointer to a value that should have delete []
4533348Sbinkertn@umich.edu     * called on it.
4543348Sbinkertn@umich.edu     */
4552566SN/A    template <typename T>
4563348Sbinkertn@umich.edu    void
4573348Sbinkertn@umich.edu    dataDynamicArray(T *p)
4583348Sbinkertn@umich.edu    {
4593348Sbinkertn@umich.edu        assert(!staticData && !dynamicData);
4603348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
4613348Sbinkertn@umich.edu        dynamicData = true;
4623348Sbinkertn@umich.edu        arrayData = true;
4633348Sbinkertn@umich.edu    }
4643348Sbinkertn@umich.edu
4653348Sbinkertn@umich.edu    /**
4663348Sbinkertn@umich.edu     * set the data pointer to a value that should have delete called
4673348Sbinkertn@umich.edu     * on it.
4683348Sbinkertn@umich.edu     */
4693348Sbinkertn@umich.edu    template <typename T>
4703348Sbinkertn@umich.edu    void
4713348Sbinkertn@umich.edu    dataDynamic(T *p)
4723348Sbinkertn@umich.edu    {
4733348Sbinkertn@umich.edu        assert(!staticData && !dynamicData);
4743348Sbinkertn@umich.edu        data = (PacketDataPtr)p;
4753348Sbinkertn@umich.edu        dynamicData = true;
4763348Sbinkertn@umich.edu        arrayData = false;
4773348Sbinkertn@umich.edu    }
4783348Sbinkertn@umich.edu
4793348Sbinkertn@umich.edu    /** get a pointer to the data ptr. */
4803348Sbinkertn@umich.edu    template <typename T>
4813348Sbinkertn@umich.edu    T*
4823348Sbinkertn@umich.edu    getPtr()
4833348Sbinkertn@umich.edu    {
4843348Sbinkertn@umich.edu        assert(staticData || dynamicData);
4853348Sbinkertn@umich.edu        return (T*)data;
4863348Sbinkertn@umich.edu    }
4872566SN/A
4882566SN/A    /** return the value of what is pointed to in the packet. */
4892566SN/A    template <typename T>
4902592SN/A    T get();
4912566SN/A
4922566SN/A    /** set the value in the data pointer to v. */
4932566SN/A    template <typename T>
4942592SN/A    void set(T v);
4952566SN/A
4963348Sbinkertn@umich.edu    /**
4973348Sbinkertn@umich.edu     * delete the data pointed to in the data pointer. Ok to call to
4983348Sbinkertn@umich.edu     * matter how data was allocted.
4993348Sbinkertn@umich.edu     */
5002592SN/A    void deleteData();
5012566SN/A
5022566SN/A    /** If there isn't data in the packet, allocate some. */
5032592SN/A    void allocate();
5042568SN/A
5052568SN/A    /** Do the packet modify the same addresses. */
5063349Sbinkertn@umich.edu    bool intersect(PacketPtr p);
5072381SN/A};
5082381SN/A
5093260Ssaidi@eecs.umich.edu/** This function given a functional packet and a timing packet either satisfies
5103260Ssaidi@eecs.umich.edu * the timing packet, or updates the timing packet to reflect the updated state
5113260Ssaidi@eecs.umich.edu * in the timing packet. It returns if the functional packet should continue to
5123260Ssaidi@eecs.umich.edu * traverse the memory hierarchy or not.
5133260Ssaidi@eecs.umich.edu */
5143349Sbinkertn@umich.edubool fixPacket(PacketPtr func, PacketPtr timing);
5153260Ssaidi@eecs.umich.edu
5163607Srdreslin@umich.edu/** This function is a wrapper for the fixPacket field that toggles the hasData bit
5173607Srdreslin@umich.edu * it is used when a response is waiting in the caches, but hasn't been marked as a
5183607Srdreslin@umich.edu * response yet (so the fixPacket needs to get the correct value for the hasData)
5193607Srdreslin@umich.edu */
5203607Srdreslin@umich.edubool fixDelayedResponsePacket(PacketPtr func, PacketPtr timing);
5213607Srdreslin@umich.edu
5223260Ssaidi@eecs.umich.edustd::ostream & operator<<(std::ostream &o, const Packet &p);
5233260Ssaidi@eecs.umich.edu
5242381SN/A#endif //__MEM_PACKET_HH
525