packet.hh revision 5650
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" 464610Ssaidi@eecs.umich.edu#include "base/fast_alloc.hh" 473940Ssaidi@eecs.umich.edu#include "base/misc.hh" 485314Sstever@gmail.com#include "base/printable.hh" 492392SN/A#include "mem/request.hh" 502980Sgblack@eecs.umich.edu#include "sim/host.hh" 514167Sbinkertn@umich.edu#include "sim/core.hh" 522394SN/A 533940Ssaidi@eecs.umich.edu 542394SN/Astruct Packet; 553349Sbinkertn@umich.edutypedef Packet *PacketPtr; 562394SN/Atypedef uint8_t* PacketDataPtr; 572812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList; 582812Srdreslin@umich.edu 594022Sstever@eecs.umich.educlass MemCmd 604022Sstever@eecs.umich.edu{ 614022Sstever@eecs.umich.edu public: 624022Sstever@eecs.umich.edu 634022Sstever@eecs.umich.edu /** List of all commands associated with a packet. */ 644022Sstever@eecs.umich.edu enum Command 654022Sstever@eecs.umich.edu { 664022Sstever@eecs.umich.edu InvalidCmd, 674022Sstever@eecs.umich.edu ReadReq, 684473Sstever@eecs.umich.edu ReadResp, 695319Sstever@gmail.com ReadRespWithInvalidate, 704022Sstever@eecs.umich.edu WriteReq, 714022Sstever@eecs.umich.edu WriteResp, 724022Sstever@eecs.umich.edu Writeback, 734022Sstever@eecs.umich.edu SoftPFReq, 744022Sstever@eecs.umich.edu HardPFReq, 754022Sstever@eecs.umich.edu SoftPFResp, 764022Sstever@eecs.umich.edu HardPFResp, 774022Sstever@eecs.umich.edu WriteInvalidateReq, 784022Sstever@eecs.umich.edu WriteInvalidateResp, 794022Sstever@eecs.umich.edu UpgradeReq, 804628Sstever@eecs.umich.edu UpgradeResp, 814022Sstever@eecs.umich.edu ReadExReq, 824022Sstever@eecs.umich.edu ReadExResp, 834626Sstever@eecs.umich.edu LoadLockedReq, 844626Sstever@eecs.umich.edu StoreCondReq, 854626Sstever@eecs.umich.edu StoreCondResp, 864040Ssaidi@eecs.umich.edu SwapReq, 874040Ssaidi@eecs.umich.edu SwapResp, 885650Sgblack@eecs.umich.edu MessageReq, 895650Sgblack@eecs.umich.edu MessageResp, 904870Sstever@eecs.umich.edu // Error responses 914870Sstever@eecs.umich.edu // @TODO these should be classified as responses rather than 924870Sstever@eecs.umich.edu // requests; coding them as requests initially for backwards 934870Sstever@eecs.umich.edu // compatibility 944870Sstever@eecs.umich.edu NetworkNackError, // nacked at network layer (not by protocol) 954870Sstever@eecs.umich.edu InvalidDestError, // packet dest field invalid 964870Sstever@eecs.umich.edu BadAddressError, // memory address invalid 975314Sstever@gmail.com // Fake simulator-only commands 985314Sstever@gmail.com PrintReq, // Print state matching address 994022Sstever@eecs.umich.edu NUM_MEM_CMDS 1004022Sstever@eecs.umich.edu }; 1014022Sstever@eecs.umich.edu 1024022Sstever@eecs.umich.edu private: 1034022Sstever@eecs.umich.edu /** List of command attributes. */ 1044022Sstever@eecs.umich.edu enum Attribute 1054022Sstever@eecs.umich.edu { 1064626Sstever@eecs.umich.edu IsRead, //!< Data flows from responder to requester 1074626Sstever@eecs.umich.edu IsWrite, //!< Data flows from requester to responder 1084626Sstever@eecs.umich.edu IsPrefetch, //!< Not a demand access 1094022Sstever@eecs.umich.edu IsInvalidate, 1104626Sstever@eecs.umich.edu NeedsExclusive, //!< Requires exclusive copy to complete in-cache 1114626Sstever@eecs.umich.edu IsRequest, //!< Issued by requester 1124626Sstever@eecs.umich.edu IsResponse, //!< Issue by responder 1134626Sstever@eecs.umich.edu NeedsResponse, //!< Requester needs response from target 1144022Sstever@eecs.umich.edu IsSWPrefetch, 1154022Sstever@eecs.umich.edu IsHWPrefetch, 1164626Sstever@eecs.umich.edu IsLocked, //!< Alpha/MIPS LL or SC access 1174626Sstever@eecs.umich.edu HasData, //!< There is an associated payload 1184870Sstever@eecs.umich.edu IsError, //!< Error response 1195314Sstever@gmail.com IsPrint, //!< Print state matching address (for debugging) 1204022Sstever@eecs.umich.edu NUM_COMMAND_ATTRIBUTES 1214022Sstever@eecs.umich.edu }; 1224022Sstever@eecs.umich.edu 1234022Sstever@eecs.umich.edu /** Structure that defines attributes and other data associated 1244022Sstever@eecs.umich.edu * with a Command. */ 1254022Sstever@eecs.umich.edu struct CommandInfo { 1264022Sstever@eecs.umich.edu /** Set of attribute flags. */ 1274022Sstever@eecs.umich.edu const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes; 1284022Sstever@eecs.umich.edu /** Corresponding response for requests; InvalidCmd if no 1294022Sstever@eecs.umich.edu * response is applicable. */ 1304022Sstever@eecs.umich.edu const Command response; 1314022Sstever@eecs.umich.edu /** String representation (for printing) */ 1324022Sstever@eecs.umich.edu const std::string str; 1334022Sstever@eecs.umich.edu }; 1344022Sstever@eecs.umich.edu 1354022Sstever@eecs.umich.edu /** Array to map Command enum to associated info. */ 1364022Sstever@eecs.umich.edu static const CommandInfo commandInfo[]; 1374022Sstever@eecs.umich.edu 1384022Sstever@eecs.umich.edu private: 1394022Sstever@eecs.umich.edu 1404022Sstever@eecs.umich.edu Command cmd; 1414022Sstever@eecs.umich.edu 1424022Sstever@eecs.umich.edu bool testCmdAttrib(MemCmd::Attribute attrib) const { 1434022Sstever@eecs.umich.edu return commandInfo[cmd].attributes[attrib] != 0; 1444022Sstever@eecs.umich.edu } 1454022Sstever@eecs.umich.edu 1464022Sstever@eecs.umich.edu public: 1474022Sstever@eecs.umich.edu 1484022Sstever@eecs.umich.edu bool isRead() const { return testCmdAttrib(IsRead); } 1494022Sstever@eecs.umich.edu bool isWrite() const { return testCmdAttrib(IsWrite); } 1504022Sstever@eecs.umich.edu bool isRequest() const { return testCmdAttrib(IsRequest); } 1514022Sstever@eecs.umich.edu bool isResponse() const { return testCmdAttrib(IsResponse); } 1524870Sstever@eecs.umich.edu bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); } 1534022Sstever@eecs.umich.edu bool needsResponse() const { return testCmdAttrib(NeedsResponse); } 1544022Sstever@eecs.umich.edu bool isInvalidate() const { return testCmdAttrib(IsInvalidate); } 1554022Sstever@eecs.umich.edu bool hasData() const { return testCmdAttrib(HasData); } 1564626Sstever@eecs.umich.edu bool isReadWrite() const { return isRead() && isWrite(); } 1574626Sstever@eecs.umich.edu bool isLocked() const { return testCmdAttrib(IsLocked); } 1584870Sstever@eecs.umich.edu bool isError() const { return testCmdAttrib(IsError); } 1595314Sstever@gmail.com bool isPrint() const { return testCmdAttrib(IsPrint); } 1604022Sstever@eecs.umich.edu 1614022Sstever@eecs.umich.edu const Command responseCommand() const { 1624022Sstever@eecs.umich.edu return commandInfo[cmd].response; 1634022Sstever@eecs.umich.edu } 1644022Sstever@eecs.umich.edu 1654022Sstever@eecs.umich.edu /** Return the string to a cmd given by idx. */ 1664022Sstever@eecs.umich.edu const std::string &toString() const { 1674022Sstever@eecs.umich.edu return commandInfo[cmd].str; 1684022Sstever@eecs.umich.edu } 1694022Sstever@eecs.umich.edu 1704022Sstever@eecs.umich.edu int toInt() const { return (int)cmd; } 1714022Sstever@eecs.umich.edu 1724022Sstever@eecs.umich.edu MemCmd(Command _cmd) 1734022Sstever@eecs.umich.edu : cmd(_cmd) 1744022Sstever@eecs.umich.edu { } 1754022Sstever@eecs.umich.edu 1764022Sstever@eecs.umich.edu MemCmd(int _cmd) 1774022Sstever@eecs.umich.edu : cmd((Command)_cmd) 1784022Sstever@eecs.umich.edu { } 1794022Sstever@eecs.umich.edu 1804022Sstever@eecs.umich.edu MemCmd() 1814022Sstever@eecs.umich.edu : cmd(InvalidCmd) 1824022Sstever@eecs.umich.edu { } 1834022Sstever@eecs.umich.edu 1844022Sstever@eecs.umich.edu bool operator==(MemCmd c2) { return (cmd == c2.cmd); } 1854022Sstever@eecs.umich.edu bool operator!=(MemCmd c2) { return (cmd != c2.cmd); } 1864022Sstever@eecs.umich.edu 1874022Sstever@eecs.umich.edu friend class Packet; 1884022Sstever@eecs.umich.edu}; 1894022Sstever@eecs.umich.edu 1902381SN/A/** 1912662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in 1922662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache). (In contrast, a 1932662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the 1942662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several 1952662Sstever@eecs.umich.edu * different Packets along the way.) 1962381SN/A */ 1975314Sstever@gmail.comclass Packet : public FastAlloc, public Printable 1982381SN/A{ 1992813Srdreslin@umich.edu public: 2004022Sstever@eecs.umich.edu 2014022Sstever@eecs.umich.edu typedef MemCmd::Command Command; 2024022Sstever@eecs.umich.edu 2034870Sstever@eecs.umich.edu /** The command field of the packet. */ 2044870Sstever@eecs.umich.edu MemCmd cmd; 2054870Sstever@eecs.umich.edu 2064870Sstever@eecs.umich.edu /** A pointer to the original request. */ 2074870Sstever@eecs.umich.edu RequestPtr req; 2084870Sstever@eecs.umich.edu 2092566SN/A private: 2102662Sstever@eecs.umich.edu /** A pointer to the data being transfered. It can be differnt 2112662Sstever@eecs.umich.edu * sizes at each level of the heirarchy so it belongs in the 2122662Sstever@eecs.umich.edu * packet, not request. This may or may not be populated when a 2132662Sstever@eecs.umich.edu * responder recieves the packet. If not populated it memory 2142662Sstever@eecs.umich.edu * should be allocated. 2152566SN/A */ 2162566SN/A PacketDataPtr data; 2172566SN/A 2182662Sstever@eecs.umich.edu /** Is the data pointer set to a value that shouldn't be freed 2192662Sstever@eecs.umich.edu * when the packet is destroyed? */ 2202566SN/A bool staticData; 2212662Sstever@eecs.umich.edu /** The data pointer points to a value that should be freed when 2222662Sstever@eecs.umich.edu * the packet is destroyed. */ 2232566SN/A bool dynamicData; 2242662Sstever@eecs.umich.edu /** the data pointer points to an array (thus delete [] ) needs to 2252662Sstever@eecs.umich.edu * be called on it rather than simply delete.*/ 2262566SN/A bool arrayData; 2272566SN/A 2282662Sstever@eecs.umich.edu /** The address of the request. This address could be virtual or 2292662Sstever@eecs.umich.edu * physical, depending on the system configuration. */ 2302381SN/A Addr addr; 2312381SN/A 2322662Sstever@eecs.umich.edu /** The size of the request or transfer. */ 2332381SN/A int size; 2342381SN/A 2352662Sstever@eecs.umich.edu /** Device address (e.g., bus ID) of the source of the 2362662Sstever@eecs.umich.edu * transaction. The source is not responsible for setting this 2372662Sstever@eecs.umich.edu * field; it is set implicitly by the interconnect when the 2383349Sbinkertn@umich.edu * packet is first sent. */ 2392381SN/A short src; 2402381SN/A 2412662Sstever@eecs.umich.edu /** Device address (e.g., bus ID) of the destination of the 2422662Sstever@eecs.umich.edu * transaction. The special value Broadcast indicates that the 2432662Sstever@eecs.umich.edu * packet should be routed based on its address. This field is 2442662Sstever@eecs.umich.edu * initialized in the constructor and is thus always valid 2452662Sstever@eecs.umich.edu * (unlike * addr, size, and src). */ 2462641Sstever@eecs.umich.edu short dest; 2472641Sstever@eecs.umich.edu 2484870Sstever@eecs.umich.edu /** The original value of the command field. Only valid when the 2494870Sstever@eecs.umich.edu * current command field is an error condition; in that case, the 2504870Sstever@eecs.umich.edu * previous contents of the command field are copied here. This 2514870Sstever@eecs.umich.edu * field is *not* set on non-error responses. 2524870Sstever@eecs.umich.edu */ 2534870Sstever@eecs.umich.edu MemCmd origCmd; 2544870Sstever@eecs.umich.edu 2552663Sstever@eecs.umich.edu /** Are the 'addr' and 'size' fields valid? */ 2562663Sstever@eecs.umich.edu bool addrSizeValid; 2572662Sstever@eecs.umich.edu /** Is the 'src' field valid? */ 2582641Sstever@eecs.umich.edu bool srcValid; 2594870Sstever@eecs.umich.edu bool destValid; 2602813Srdreslin@umich.edu 2614870Sstever@eecs.umich.edu enum Flag { 2624895Sstever@eecs.umich.edu // Snoop response flags 2634626Sstever@eecs.umich.edu MemInhibit, 2644626Sstever@eecs.umich.edu Shared, 2654895Sstever@eecs.umich.edu // Special control flags 2664916Sstever@eecs.umich.edu /// Special timing-mode atomic snoop for multi-level coherence. 2674895Sstever@eecs.umich.edu ExpressSnoop, 2684916Sstever@eecs.umich.edu /// Does supplier have exclusive copy? 2694916Sstever@eecs.umich.edu /// Useful for multi-level coherence. 2704916Sstever@eecs.umich.edu SupplyExclusive, 2714870Sstever@eecs.umich.edu NUM_PACKET_FLAGS 2724626Sstever@eecs.umich.edu }; 2734626Sstever@eecs.umich.edu 2744870Sstever@eecs.umich.edu /** Status flags */ 2754870Sstever@eecs.umich.edu std::bitset<NUM_PACKET_FLAGS> flags; 2762641Sstever@eecs.umich.edu 2772641Sstever@eecs.umich.edu public: 2782641Sstever@eecs.umich.edu 2792811Srdreslin@umich.edu /** Used to calculate latencies for each packet.*/ 2802811Srdreslin@umich.edu Tick time; 2812811Srdreslin@umich.edu 2823218Sgblack@eecs.umich.edu /** The time at which the packet will be fully transmitted */ 2833218Sgblack@eecs.umich.edu Tick finishTime; 2843218Sgblack@eecs.umich.edu 2853218Sgblack@eecs.umich.edu /** The time at which the first chunk of the packet will be transmitted */ 2863218Sgblack@eecs.umich.edu Tick firstWordTime; 2873218Sgblack@eecs.umich.edu 2882662Sstever@eecs.umich.edu /** The special destination address indicating that the packet 2892662Sstever@eecs.umich.edu * should be routed based on its address. */ 2902623SN/A static const short Broadcast = -1; 2912623SN/A 2922662Sstever@eecs.umich.edu /** A virtual base opaque structure used to hold state associated 2932662Sstever@eecs.umich.edu * with the packet but specific to the sending device (e.g., an 2942662Sstever@eecs.umich.edu * MSHR). A pointer to this state is returned in the packet's 2952662Sstever@eecs.umich.edu * response so that the sender can quickly look up the state 2962662Sstever@eecs.umich.edu * needed to process it. A specific subclass would be derived 2972662Sstever@eecs.umich.edu * from this to carry state specific to a particular sending 2982662Sstever@eecs.umich.edu * device. */ 2995386Sstever@gmail.com class SenderState { 3002641Sstever@eecs.umich.edu public: 3012641Sstever@eecs.umich.edu virtual ~SenderState() {} 3022641Sstever@eecs.umich.edu }; 3032641Sstever@eecs.umich.edu 3045315Sstever@gmail.com /** 3055315Sstever@gmail.com * Object used to maintain state of a PrintReq. The senderState 3065315Sstever@gmail.com * field of a PrintReq should always be of this type. 3075315Sstever@gmail.com */ 3085386Sstever@gmail.com class PrintReqState : public SenderState, public FastAlloc { 3095315Sstever@gmail.com /** An entry in the label stack. */ 3105314Sstever@gmail.com class LabelStackEntry { 3115314Sstever@gmail.com public: 3125314Sstever@gmail.com const std::string label; 3135314Sstever@gmail.com std::string *prefix; 3145314Sstever@gmail.com bool labelPrinted; 3155314Sstever@gmail.com LabelStackEntry(const std::string &_label, 3165314Sstever@gmail.com std::string *_prefix); 3175314Sstever@gmail.com }; 3185314Sstever@gmail.com 3195314Sstever@gmail.com typedef std::list<LabelStackEntry> LabelStack; 3205314Sstever@gmail.com LabelStack labelStack; 3215314Sstever@gmail.com 3225314Sstever@gmail.com std::string *curPrefixPtr; 3235314Sstever@gmail.com 3245314Sstever@gmail.com public: 3255314Sstever@gmail.com std::ostream &os; 3265314Sstever@gmail.com const int verbosity; 3275314Sstever@gmail.com 3285314Sstever@gmail.com PrintReqState(std::ostream &os, int verbosity = 0); 3295314Sstever@gmail.com ~PrintReqState(); 3305314Sstever@gmail.com 3315315Sstever@gmail.com /** Returns the current line prefix. */ 3325314Sstever@gmail.com const std::string &curPrefix() { return *curPrefixPtr; } 3335315Sstever@gmail.com 3345315Sstever@gmail.com /** Push a label onto the label stack, and prepend the given 3355315Sstever@gmail.com * prefix string onto the current prefix. Labels will only be 3365315Sstever@gmail.com * printed if an object within the label's scope is 3375315Sstever@gmail.com * printed. */ 3385314Sstever@gmail.com void pushLabel(const std::string &lbl, 3395314Sstever@gmail.com const std::string &prefix = " "); 3405315Sstever@gmail.com /** Pop a label off the label stack. */ 3415314Sstever@gmail.com void popLabel(); 3425315Sstever@gmail.com /** Print all of the pending unprinted labels on the 3435315Sstever@gmail.com * stack. Called by printObj(), so normally not called by 3445315Sstever@gmail.com * users unless bypassing printObj(). */ 3455314Sstever@gmail.com void printLabels(); 3465315Sstever@gmail.com /** Print a Printable object to os, because it matched the 3475315Sstever@gmail.com * address on a PrintReq. */ 3485314Sstever@gmail.com void printObj(Printable *obj); 3495314Sstever@gmail.com }; 3505314Sstever@gmail.com 3512662Sstever@eecs.umich.edu /** This packet's sender state. Devices should use dynamic_cast<> 3522662Sstever@eecs.umich.edu * to cast to the state appropriate to the sender. */ 3532662Sstever@eecs.umich.edu SenderState *senderState; 3542641Sstever@eecs.umich.edu 3552662Sstever@eecs.umich.edu /** Return the string name of the cmd field (for debugging and 3562662Sstever@eecs.umich.edu * tracing). */ 3574022Sstever@eecs.umich.edu const std::string &cmdString() const { return cmd.toString(); } 3582811Srdreslin@umich.edu 3592811Srdreslin@umich.edu /** Return the index of this command. */ 3604022Sstever@eecs.umich.edu inline int cmdToIndex() const { return cmd.toInt(); } 3612811Srdreslin@umich.edu 3624022Sstever@eecs.umich.edu bool isRead() const { return cmd.isRead(); } 3634022Sstever@eecs.umich.edu bool isWrite() const { return cmd.isWrite(); } 3644022Sstever@eecs.umich.edu bool isRequest() const { return cmd.isRequest(); } 3654022Sstever@eecs.umich.edu bool isResponse() const { return cmd.isResponse(); } 3664870Sstever@eecs.umich.edu bool needsExclusive() const { return cmd.needsExclusive(); } 3674022Sstever@eecs.umich.edu bool needsResponse() const { return cmd.needsResponse(); } 3684022Sstever@eecs.umich.edu bool isInvalidate() const { return cmd.isInvalidate(); } 3694022Sstever@eecs.umich.edu bool hasData() const { return cmd.hasData(); } 3704040Ssaidi@eecs.umich.edu bool isReadWrite() const { return cmd.isReadWrite(); } 3714626Sstever@eecs.umich.edu bool isLocked() const { return cmd.isLocked(); } 3724870Sstever@eecs.umich.edu bool isError() const { return cmd.isError(); } 3735314Sstever@gmail.com bool isPrint() const { return cmd.isPrint(); } 3742812Srdreslin@umich.edu 3754870Sstever@eecs.umich.edu // Snoop flags 3764870Sstever@eecs.umich.edu void assertMemInhibit() { flags[MemInhibit] = true; } 3774916Sstever@eecs.umich.edu bool memInhibitAsserted() { return flags[MemInhibit]; } 3784870Sstever@eecs.umich.edu void assertShared() { flags[Shared] = true; } 3794870Sstever@eecs.umich.edu bool sharedAsserted() { return flags[Shared]; } 3804870Sstever@eecs.umich.edu 3814895Sstever@eecs.umich.edu // Special control flags 3824895Sstever@eecs.umich.edu void setExpressSnoop() { flags[ExpressSnoop] = true; } 3834895Sstever@eecs.umich.edu bool isExpressSnoop() { return flags[ExpressSnoop]; } 3844916Sstever@eecs.umich.edu void setSupplyExclusive() { flags[SupplyExclusive] = true; } 3854916Sstever@eecs.umich.edu bool isSupplyExclusive() { return flags[SupplyExclusive]; } 3864895Sstever@eecs.umich.edu 3874870Sstever@eecs.umich.edu // Network error conditions... encapsulate them as methods since 3884870Sstever@eecs.umich.edu // their encoding keeps changing (from result field to command 3894870Sstever@eecs.umich.edu // field, etc.) 3904986Ssaidi@eecs.umich.edu void setNacked() { assert(isResponse()); cmd = MemCmd::NetworkNackError; } 3914986Ssaidi@eecs.umich.edu void setBadAddress() { assert(isResponse()); cmd = MemCmd::BadAddressError; } 3924870Sstever@eecs.umich.edu bool wasNacked() { return cmd == MemCmd::NetworkNackError; } 3934870Sstever@eecs.umich.edu bool hadBadAddress() { return cmd == MemCmd::BadAddressError; } 3944986Ssaidi@eecs.umich.edu void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; } 3952814Srdreslin@umich.edu 3963940Ssaidi@eecs.umich.edu bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN } 3972641Sstever@eecs.umich.edu 3982381SN/A /** Accessor function that returns the source index of the packet. */ 3994870Sstever@eecs.umich.edu short getSrc() const { assert(srcValid); return src; } 4002641Sstever@eecs.umich.edu void setSrc(short _src) { src = _src; srcValid = true; } 4014626Sstever@eecs.umich.edu /** Reset source field, e.g. to retransmit packet on different bus. */ 4024626Sstever@eecs.umich.edu void clearSrc() { srcValid = false; } 4032381SN/A 4042381SN/A /** Accessor function that returns the destination index of 4052381SN/A the packet. */ 4064870Sstever@eecs.umich.edu short getDest() const { assert(destValid); return dest; } 4074870Sstever@eecs.umich.edu void setDest(short _dest) { dest = _dest; destValid = true; } 4082549SN/A 4092663Sstever@eecs.umich.edu Addr getAddr() const { assert(addrSizeValid); return addr; } 4104870Sstever@eecs.umich.edu int getSize() const { assert(addrSizeValid); return size; } 4112883Srdreslin@umich.edu Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 4122813Srdreslin@umich.edu 4132662Sstever@eecs.umich.edu /** Constructor. Note that a Request object must be constructed 4142662Sstever@eecs.umich.edu * first, but the Requests's physical address and size fields 4152662Sstever@eecs.umich.edu * need not be valid. The command and destination addresses 4162662Sstever@eecs.umich.edu * must be supplied. */ 4174022Sstever@eecs.umich.edu Packet(Request *_req, MemCmd _cmd, short _dest) 4184870Sstever@eecs.umich.edu : cmd(_cmd), req(_req), 4194870Sstever@eecs.umich.edu data(NULL), staticData(false), dynamicData(false), arrayData(false), 4202641Sstever@eecs.umich.edu addr(_req->paddr), size(_req->size), dest(_dest), 4214870Sstever@eecs.umich.edu addrSizeValid(_req->validPaddr), srcValid(false), destValid(true), 4224870Sstever@eecs.umich.edu flags(0), time(curTick), senderState(NULL) 4232641Sstever@eecs.umich.edu { 4242813Srdreslin@umich.edu } 4252813Srdreslin@umich.edu 4262813Srdreslin@umich.edu /** Alternate constructor if you are trying to create a packet with 4272813Srdreslin@umich.edu * a request that is for a whole block, not the address from the req. 4282813Srdreslin@umich.edu * this allows for overriding the size/addr of the req.*/ 4294022Sstever@eecs.umich.edu Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize) 4304870Sstever@eecs.umich.edu : cmd(_cmd), req(_req), 4314870Sstever@eecs.umich.edu data(NULL), staticData(false), dynamicData(false), arrayData(false), 4324626Sstever@eecs.umich.edu addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), dest(_dest), 4334870Sstever@eecs.umich.edu addrSizeValid(_req->validPaddr), srcValid(false), destValid(true), 4344870Sstever@eecs.umich.edu flags(0), time(curTick), senderState(NULL) 4352813Srdreslin@umich.edu { 4364626Sstever@eecs.umich.edu } 4374626Sstever@eecs.umich.edu 4384626Sstever@eecs.umich.edu /** Alternate constructor for copying a packet. Copy all fields 4394887Sstever@eecs.umich.edu * *except* if the original packet's data was dynamic, don't copy 4404887Sstever@eecs.umich.edu * that, as we can't guarantee that the new packet's lifetime is 4414887Sstever@eecs.umich.edu * less than that of the original packet. In this case the new 4424887Sstever@eecs.umich.edu * packet should allocate its own data. */ 4434895Sstever@eecs.umich.edu Packet(Packet *origPkt, bool clearFlags = false) 4444870Sstever@eecs.umich.edu : cmd(origPkt->cmd), req(origPkt->req), 4454887Sstever@eecs.umich.edu data(origPkt->staticData ? origPkt->data : NULL), 4464887Sstever@eecs.umich.edu staticData(origPkt->staticData), 4474887Sstever@eecs.umich.edu dynamicData(false), arrayData(false), 4484626Sstever@eecs.umich.edu addr(origPkt->addr), size(origPkt->size), 4494660Sstever@eecs.umich.edu src(origPkt->src), dest(origPkt->dest), 4504870Sstever@eecs.umich.edu addrSizeValid(origPkt->addrSizeValid), 4514870Sstever@eecs.umich.edu srcValid(origPkt->srcValid), destValid(origPkt->destValid), 4524895Sstever@eecs.umich.edu flags(clearFlags ? 0 : origPkt->flags), 4534870Sstever@eecs.umich.edu time(curTick), senderState(origPkt->senderState) 4544626Sstever@eecs.umich.edu { 4552641Sstever@eecs.umich.edu } 4562549SN/A 4572662Sstever@eecs.umich.edu /** Destructor. */ 4582566SN/A ~Packet() 4595387Sstever@gmail.com { 4605387Sstever@gmail.com // If this is a request packet for which there's no response, 4615387Sstever@gmail.com // delete the request object here, since the requester will 4625387Sstever@gmail.com // never get the chance. 4635387Sstever@gmail.com if (req && isRequest() && !needsResponse()) 4645387Sstever@gmail.com delete req; 4655387Sstever@gmail.com if (staticData || dynamicData) 4665387Sstever@gmail.com deleteData(); 4675387Sstever@gmail.com } 4682566SN/A 4692662Sstever@eecs.umich.edu /** Reinitialize packet address and size from the associated 4702662Sstever@eecs.umich.edu * Request object, and reset other fields that may have been 4712662Sstever@eecs.umich.edu * modified by a previous transaction. Typically called when a 4722662Sstever@eecs.umich.edu * statically allocated Request/Packet pair is reused for 4732662Sstever@eecs.umich.edu * multiple transactions. */ 4742662Sstever@eecs.umich.edu void reinitFromRequest() { 4752662Sstever@eecs.umich.edu assert(req->validPaddr); 4764870Sstever@eecs.umich.edu flags = 0; 4772663Sstever@eecs.umich.edu addr = req->paddr; 4782663Sstever@eecs.umich.edu size = req->size; 4793018Srdreslin@umich.edu time = req->time; 4802663Sstever@eecs.umich.edu addrSizeValid = true; 4812662Sstever@eecs.umich.edu if (dynamicData) { 4822662Sstever@eecs.umich.edu deleteData(); 4832662Sstever@eecs.umich.edu dynamicData = false; 4842662Sstever@eecs.umich.edu arrayData = false; 4852662Sstever@eecs.umich.edu } 4862662Sstever@eecs.umich.edu } 4872566SN/A 4884626Sstever@eecs.umich.edu /** 4894626Sstever@eecs.umich.edu * Take a request packet and modify it in place to be suitable for 4904626Sstever@eecs.umich.edu * returning as a response to that request. The source and 4914626Sstever@eecs.umich.edu * destination fields are *not* modified, as is appropriate for 4924626Sstever@eecs.umich.edu * atomic accesses. 4934626Sstever@eecs.umich.edu */ 4944870Sstever@eecs.umich.edu void makeResponse() 4954626Sstever@eecs.umich.edu { 4962662Sstever@eecs.umich.edu assert(needsResponse()); 4972855Srdreslin@umich.edu assert(isRequest()); 4984986Ssaidi@eecs.umich.edu origCmd = cmd; 4994022Sstever@eecs.umich.edu cmd = cmd.responseCommand(); 5004870Sstever@eecs.umich.edu dest = src; 5014870Sstever@eecs.umich.edu destValid = srcValid; 5022662Sstever@eecs.umich.edu srcValid = false; 5032641Sstever@eecs.umich.edu } 5042641Sstever@eecs.umich.edu 5054870Sstever@eecs.umich.edu void makeAtomicResponse() 5064870Sstever@eecs.umich.edu { 5074870Sstever@eecs.umich.edu makeResponse(); 5084870Sstever@eecs.umich.edu } 5094870Sstever@eecs.umich.edu 5104626Sstever@eecs.umich.edu void makeTimingResponse() 5113348Sbinkertn@umich.edu { 5124870Sstever@eecs.umich.edu makeResponse(); 5133135Srdreslin@umich.edu } 5143135Srdreslin@umich.edu 5153348Sbinkertn@umich.edu /** 5163348Sbinkertn@umich.edu * Take a request packet that has been returned as NACKED and 5173348Sbinkertn@umich.edu * modify it so that it can be sent out again. Only packets that 5183348Sbinkertn@umich.edu * need a response can be NACKED, so verify that that is true. 5193348Sbinkertn@umich.edu */ 5203348Sbinkertn@umich.edu void 5213348Sbinkertn@umich.edu reinitNacked() 5223348Sbinkertn@umich.edu { 5234870Sstever@eecs.umich.edu assert(wasNacked()); 5244870Sstever@eecs.umich.edu cmd = origCmd; 5254870Sstever@eecs.umich.edu assert(needsResponse()); 5264870Sstever@eecs.umich.edu setDest(Broadcast); 5272685Ssaidi@eecs.umich.edu } 5282685Ssaidi@eecs.umich.edu 5292685Ssaidi@eecs.umich.edu 5303348Sbinkertn@umich.edu /** 5313348Sbinkertn@umich.edu * Set the data pointer to the following value that should not be 5323348Sbinkertn@umich.edu * freed. 5332566SN/A */ 5342566SN/A template <typename T> 5353348Sbinkertn@umich.edu void 5363348Sbinkertn@umich.edu dataStatic(T *p) 5373348Sbinkertn@umich.edu { 5383348Sbinkertn@umich.edu if(dynamicData) 5393348Sbinkertn@umich.edu dynamicData = false; 5403348Sbinkertn@umich.edu data = (PacketDataPtr)p; 5413348Sbinkertn@umich.edu staticData = true; 5423348Sbinkertn@umich.edu } 5432566SN/A 5443348Sbinkertn@umich.edu /** 5453348Sbinkertn@umich.edu * Set the data pointer to a value that should have delete [] 5463348Sbinkertn@umich.edu * called on it. 5473348Sbinkertn@umich.edu */ 5482566SN/A template <typename T> 5493348Sbinkertn@umich.edu void 5503348Sbinkertn@umich.edu dataDynamicArray(T *p) 5513348Sbinkertn@umich.edu { 5523348Sbinkertn@umich.edu assert(!staticData && !dynamicData); 5533348Sbinkertn@umich.edu data = (PacketDataPtr)p; 5543348Sbinkertn@umich.edu dynamicData = true; 5553348Sbinkertn@umich.edu arrayData = true; 5563348Sbinkertn@umich.edu } 5573348Sbinkertn@umich.edu 5583348Sbinkertn@umich.edu /** 5593348Sbinkertn@umich.edu * set the data pointer to a value that should have delete called 5603348Sbinkertn@umich.edu * on it. 5613348Sbinkertn@umich.edu */ 5623348Sbinkertn@umich.edu template <typename T> 5633348Sbinkertn@umich.edu void 5643348Sbinkertn@umich.edu dataDynamic(T *p) 5653348Sbinkertn@umich.edu { 5663348Sbinkertn@umich.edu assert(!staticData && !dynamicData); 5673348Sbinkertn@umich.edu data = (PacketDataPtr)p; 5683348Sbinkertn@umich.edu dynamicData = true; 5693348Sbinkertn@umich.edu arrayData = false; 5703348Sbinkertn@umich.edu } 5713348Sbinkertn@umich.edu 5723348Sbinkertn@umich.edu /** get a pointer to the data ptr. */ 5733348Sbinkertn@umich.edu template <typename T> 5743348Sbinkertn@umich.edu T* 5753348Sbinkertn@umich.edu getPtr() 5763348Sbinkertn@umich.edu { 5773348Sbinkertn@umich.edu assert(staticData || dynamicData); 5783348Sbinkertn@umich.edu return (T*)data; 5793348Sbinkertn@umich.edu } 5802566SN/A 5812566SN/A /** return the value of what is pointed to in the packet. */ 5822566SN/A template <typename T> 5832592SN/A T get(); 5842566SN/A 5852566SN/A /** set the value in the data pointer to v. */ 5862566SN/A template <typename T> 5872592SN/A void set(T v); 5882566SN/A 5893348Sbinkertn@umich.edu /** 5904626Sstever@eecs.umich.edu * Copy data into the packet from the provided pointer. 5914626Sstever@eecs.umich.edu */ 5924626Sstever@eecs.umich.edu void setData(uint8_t *p) 5934626Sstever@eecs.umich.edu { 5944626Sstever@eecs.umich.edu std::memcpy(getPtr<uint8_t>(), p, getSize()); 5954626Sstever@eecs.umich.edu } 5964626Sstever@eecs.umich.edu 5974626Sstever@eecs.umich.edu /** 5984626Sstever@eecs.umich.edu * Copy data into the packet from the provided block pointer, 5994626Sstever@eecs.umich.edu * which is aligned to the given block size. 6004626Sstever@eecs.umich.edu */ 6014626Sstever@eecs.umich.edu void setDataFromBlock(uint8_t *blk_data, int blkSize) 6024626Sstever@eecs.umich.edu { 6034626Sstever@eecs.umich.edu setData(blk_data + getOffset(blkSize)); 6044626Sstever@eecs.umich.edu } 6054626Sstever@eecs.umich.edu 6064626Sstever@eecs.umich.edu /** 6074626Sstever@eecs.umich.edu * Copy data from the packet to the provided block pointer, which 6084626Sstever@eecs.umich.edu * is aligned to the given block size. 6094626Sstever@eecs.umich.edu */ 6104626Sstever@eecs.umich.edu void writeData(uint8_t *p) 6114626Sstever@eecs.umich.edu { 6124626Sstever@eecs.umich.edu std::memcpy(p, getPtr<uint8_t>(), getSize()); 6134626Sstever@eecs.umich.edu } 6144626Sstever@eecs.umich.edu 6154626Sstever@eecs.umich.edu /** 6164626Sstever@eecs.umich.edu * Copy data from the packet to the memory at the provided pointer. 6174626Sstever@eecs.umich.edu */ 6184626Sstever@eecs.umich.edu void writeDataToBlock(uint8_t *blk_data, int blkSize) 6194626Sstever@eecs.umich.edu { 6204626Sstever@eecs.umich.edu writeData(blk_data + getOffset(blkSize)); 6214626Sstever@eecs.umich.edu } 6224626Sstever@eecs.umich.edu 6234626Sstever@eecs.umich.edu /** 6243348Sbinkertn@umich.edu * delete the data pointed to in the data pointer. Ok to call to 6253348Sbinkertn@umich.edu * matter how data was allocted. 6263348Sbinkertn@umich.edu */ 6272592SN/A void deleteData(); 6282566SN/A 6292566SN/A /** If there isn't data in the packet, allocate some. */ 6302592SN/A void allocate(); 6312568SN/A 6324626Sstever@eecs.umich.edu /** 6334626Sstever@eecs.umich.edu * Check a functional request against a memory value represented 6344626Sstever@eecs.umich.edu * by a base/size pair and an associated data array. If the 6354626Sstever@eecs.umich.edu * functional request is a read, it may be satisfied by the memory 6364626Sstever@eecs.umich.edu * value. If the functional request is a write, it may update the 6374626Sstever@eecs.umich.edu * memory value. 6384626Sstever@eecs.umich.edu */ 6395314Sstever@gmail.com bool checkFunctional(Printable *obj, Addr base, int size, uint8_t *data); 6404626Sstever@eecs.umich.edu 6414626Sstever@eecs.umich.edu /** 6424626Sstever@eecs.umich.edu * Check a functional request against a memory value stored in 6435315Sstever@gmail.com * another packet (i.e. an in-transit request or response). 6444626Sstever@eecs.umich.edu */ 6454626Sstever@eecs.umich.edu bool checkFunctional(PacketPtr otherPkt) { 6465314Sstever@gmail.com return checkFunctional(otherPkt, 6475314Sstever@gmail.com otherPkt->getAddr(), otherPkt->getSize(), 6485314Sstever@gmail.com otherPkt->hasData() ? 6495314Sstever@gmail.com otherPkt->getPtr<uint8_t>() : NULL); 6504626Sstever@eecs.umich.edu } 6515314Sstever@gmail.com 6525315Sstever@gmail.com /** 6535315Sstever@gmail.com * Push label for PrintReq (safe to call unconditionally). 6545315Sstever@gmail.com */ 6555314Sstever@gmail.com void pushLabel(const std::string &lbl) { 6565314Sstever@gmail.com if (isPrint()) { 6575314Sstever@gmail.com dynamic_cast<PrintReqState*>(senderState)->pushLabel(lbl); 6585314Sstever@gmail.com } 6595314Sstever@gmail.com } 6605314Sstever@gmail.com 6615315Sstever@gmail.com /** 6625315Sstever@gmail.com * Pop label for PrintReq (safe to call unconditionally). 6635315Sstever@gmail.com */ 6645314Sstever@gmail.com void popLabel() { 6655314Sstever@gmail.com if (isPrint()) { 6665314Sstever@gmail.com dynamic_cast<PrintReqState*>(senderState)->popLabel(); 6675314Sstever@gmail.com } 6685314Sstever@gmail.com } 6695314Sstever@gmail.com 6705314Sstever@gmail.com void print(std::ostream &o, int verbosity = 0, 6715314Sstever@gmail.com const std::string &prefix = "") const; 6722381SN/A}; 6732381SN/A 6742381SN/A#endif //__MEM_PACKET_HH 675