packet.hh revision 8436
12381SN/A/* 22592SN/A * Copyright (c) 2006 The Regents of The University of Michigan 37636Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc. 42381SN/A * All rights reserved. 52381SN/A * 62381SN/A * Redistribution and use in source and binary forms, with or without 72381SN/A * modification, are permitted provided that the following conditions are 82381SN/A * met: redistributions of source code must retain the above copyright 92381SN/A * notice, this list of conditions and the following disclaimer; 102381SN/A * redistributions in binary form must reproduce the above copyright 112381SN/A * notice, this list of conditions and the following disclaimer in the 122381SN/A * documentation and/or other materials provided with the distribution; 132381SN/A * neither the name of the copyright holders nor the names of its 142381SN/A * contributors may be used to endorse or promote products derived from 152381SN/A * this software without specific prior written permission. 162381SN/A * 172381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu * 292665Ssaidi@eecs.umich.edu * Authors: Ron Dreslinski 302665Ssaidi@eecs.umich.edu * Steve Reinhardt 312665Ssaidi@eecs.umich.edu * Ali Saidi 322381SN/A */ 332381SN/A 342381SN/A/** 352381SN/A * @file 362662Sstever@eecs.umich.edu * Declaration of the Packet class. 372381SN/A */ 382381SN/A 392381SN/A#ifndef __MEM_PACKET_HH__ 402381SN/A#define __MEM_PACKET_HH__ 412381SN/A 428229Snate@binkert.org#include <bitset> 433348Sbinkertn@umich.edu#include <cassert> 443348Sbinkertn@umich.edu#include <list> 453348Sbinkertn@umich.edu 465735Snate@binkert.org#include "base/cast.hh" 474024Sbinkertn@umich.edu#include "base/compiler.hh" 484610Ssaidi@eecs.umich.edu#include "base/fast_alloc.hh" 495735Snate@binkert.org#include "base/flags.hh" 503940Ssaidi@eecs.umich.edu#include "base/misc.hh" 515314Sstever@gmail.com#include "base/printable.hh" 526216Snate@binkert.org#include "base/types.hh" 532392SN/A#include "mem/request.hh" 544167Sbinkertn@umich.edu#include "sim/core.hh" 552394SN/A 562394SN/Astruct Packet; 573349Sbinkertn@umich.edutypedef Packet *PacketPtr; 582394SN/Atypedef uint8_t* PacketDataPtr; 592812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList; 602812Srdreslin@umich.edu 614022Sstever@eecs.umich.educlass MemCmd 624022Sstever@eecs.umich.edu{ 635735Snate@binkert.org friend class Packet; 645735Snate@binkert.org 654022Sstever@eecs.umich.edu public: 665735Snate@binkert.org /** 675735Snate@binkert.org * List of all commands associated with a packet. 685735Snate@binkert.org */ 694022Sstever@eecs.umich.edu enum Command 704022Sstever@eecs.umich.edu { 714022Sstever@eecs.umich.edu InvalidCmd, 724022Sstever@eecs.umich.edu ReadReq, 734473Sstever@eecs.umich.edu ReadResp, 745319Sstever@gmail.com ReadRespWithInvalidate, 754022Sstever@eecs.umich.edu WriteReq, 764022Sstever@eecs.umich.edu WriteResp, 774022Sstever@eecs.umich.edu Writeback, 784022Sstever@eecs.umich.edu SoftPFReq, 794022Sstever@eecs.umich.edu HardPFReq, 804022Sstever@eecs.umich.edu SoftPFResp, 814022Sstever@eecs.umich.edu HardPFResp, 824022Sstever@eecs.umich.edu WriteInvalidateReq, 834022Sstever@eecs.umich.edu WriteInvalidateResp, 844022Sstever@eecs.umich.edu UpgradeReq, 857465Ssteve.reinhardt@amd.com SCUpgradeReq, // Special "weak" upgrade for StoreCond 864628Sstever@eecs.umich.edu UpgradeResp, 877465Ssteve.reinhardt@amd.com SCUpgradeFailReq, // Failed SCUpgradeReq in MSHR (never sent) 887465Ssteve.reinhardt@amd.com UpgradeFailResp, // Valid for SCUpgradeReq only 894022Sstever@eecs.umich.edu ReadExReq, 904022Sstever@eecs.umich.edu ReadExResp, 914626Sstever@eecs.umich.edu LoadLockedReq, 924626Sstever@eecs.umich.edu StoreCondReq, 937669Ssteve.reinhardt@amd.com StoreCondFailReq, // Failed StoreCondReq in MSHR (never sent) 944626Sstever@eecs.umich.edu StoreCondResp, 954040Ssaidi@eecs.umich.edu SwapReq, 964040Ssaidi@eecs.umich.edu SwapResp, 975650Sgblack@eecs.umich.edu MessageReq, 985650Sgblack@eecs.umich.edu MessageResp, 994870Sstever@eecs.umich.edu // Error responses 1004870Sstever@eecs.umich.edu // @TODO these should be classified as responses rather than 1014870Sstever@eecs.umich.edu // requests; coding them as requests initially for backwards 1024870Sstever@eecs.umich.edu // compatibility 1034870Sstever@eecs.umich.edu NetworkNackError, // nacked at network layer (not by protocol) 1044870Sstever@eecs.umich.edu InvalidDestError, // packet dest field invalid 1054870Sstever@eecs.umich.edu BadAddressError, // memory address invalid 1068436SBrad.Beckmann@amd.com FunctionalReadError, // unable to fulfill functional read 1078436SBrad.Beckmann@amd.com FunctionalWriteError, // unable to fulfill functional write 1085314Sstever@gmail.com // Fake simulator-only commands 1095314Sstever@gmail.com PrintReq, // Print state matching address 1108184Ssomayeh@cs.wisc.edu FlushReq, //request for a cache flush 1114022Sstever@eecs.umich.edu NUM_MEM_CMDS 1124022Sstever@eecs.umich.edu }; 1134022Sstever@eecs.umich.edu 1144022Sstever@eecs.umich.edu private: 1155735Snate@binkert.org /** 1165735Snate@binkert.org * List of command attributes. 1175735Snate@binkert.org */ 1184022Sstever@eecs.umich.edu enum Attribute 1194022Sstever@eecs.umich.edu { 1204626Sstever@eecs.umich.edu IsRead, //!< Data flows from responder to requester 1214626Sstever@eecs.umich.edu IsWrite, //!< Data flows from requester to responder 1227465Ssteve.reinhardt@amd.com IsUpgrade, 1234626Sstever@eecs.umich.edu IsPrefetch, //!< Not a demand access 1244022Sstever@eecs.umich.edu IsInvalidate, 1254626Sstever@eecs.umich.edu NeedsExclusive, //!< Requires exclusive copy to complete in-cache 1264626Sstever@eecs.umich.edu IsRequest, //!< Issued by requester 1274626Sstever@eecs.umich.edu IsResponse, //!< Issue by responder 1284626Sstever@eecs.umich.edu NeedsResponse, //!< Requester needs response from target 1294022Sstever@eecs.umich.edu IsSWPrefetch, 1304022Sstever@eecs.umich.edu IsHWPrefetch, 1316076Sgblack@eecs.umich.edu IsLlsc, //!< Alpha/MIPS LL or SC access 1324626Sstever@eecs.umich.edu HasData, //!< There is an associated payload 1334870Sstever@eecs.umich.edu IsError, //!< Error response 1345314Sstever@gmail.com IsPrint, //!< Print state matching address (for debugging) 1358184Ssomayeh@cs.wisc.edu IsFlush, //!< Flush the address from caches 1364022Sstever@eecs.umich.edu NUM_COMMAND_ATTRIBUTES 1374022Sstever@eecs.umich.edu }; 1384022Sstever@eecs.umich.edu 1395735Snate@binkert.org /** 1405735Snate@binkert.org * Structure that defines attributes and other data associated 1415735Snate@binkert.org * with a Command. 1425735Snate@binkert.org */ 1435735Snate@binkert.org struct CommandInfo 1445735Snate@binkert.org { 1455735Snate@binkert.org /// Set of attribute flags. 1464022Sstever@eecs.umich.edu const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes; 1475735Snate@binkert.org /// Corresponding response for requests; InvalidCmd if no 1485735Snate@binkert.org /// response is applicable. 1494022Sstever@eecs.umich.edu const Command response; 1505735Snate@binkert.org /// String representation (for printing) 1514022Sstever@eecs.umich.edu const std::string str; 1524022Sstever@eecs.umich.edu }; 1534022Sstever@eecs.umich.edu 1545735Snate@binkert.org /// Array to map Command enum to associated info. 1554022Sstever@eecs.umich.edu static const CommandInfo commandInfo[]; 1564022Sstever@eecs.umich.edu 1574022Sstever@eecs.umich.edu private: 1584022Sstever@eecs.umich.edu 1594022Sstever@eecs.umich.edu Command cmd; 1604022Sstever@eecs.umich.edu 1615735Snate@binkert.org bool 1625735Snate@binkert.org testCmdAttrib(MemCmd::Attribute attrib) const 1635735Snate@binkert.org { 1644022Sstever@eecs.umich.edu return commandInfo[cmd].attributes[attrib] != 0; 1654022Sstever@eecs.umich.edu } 1664022Sstever@eecs.umich.edu 1674022Sstever@eecs.umich.edu public: 1684022Sstever@eecs.umich.edu 1694022Sstever@eecs.umich.edu bool isRead() const { return testCmdAttrib(IsRead); } 1707465Ssteve.reinhardt@amd.com bool isWrite() const { return testCmdAttrib(IsWrite); } 1717465Ssteve.reinhardt@amd.com bool isUpgrade() const { return testCmdAttrib(IsUpgrade); } 1724022Sstever@eecs.umich.edu bool isRequest() const { return testCmdAttrib(IsRequest); } 1734022Sstever@eecs.umich.edu bool isResponse() const { return testCmdAttrib(IsResponse); } 1744870Sstever@eecs.umich.edu bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); } 1754022Sstever@eecs.umich.edu bool needsResponse() const { return testCmdAttrib(NeedsResponse); } 1764022Sstever@eecs.umich.edu bool isInvalidate() const { return testCmdAttrib(IsInvalidate); } 1774022Sstever@eecs.umich.edu bool hasData() const { return testCmdAttrib(HasData); } 1784626Sstever@eecs.umich.edu bool isReadWrite() const { return isRead() && isWrite(); } 1796102Sgblack@eecs.umich.edu bool isLLSC() const { return testCmdAttrib(IsLlsc); } 1804870Sstever@eecs.umich.edu bool isError() const { return testCmdAttrib(IsError); } 1815314Sstever@gmail.com bool isPrint() const { return testCmdAttrib(IsPrint); } 1828184Ssomayeh@cs.wisc.edu bool isFlush() const { return testCmdAttrib(IsFlush); } 1834022Sstever@eecs.umich.edu 1845735Snate@binkert.org const Command 1855735Snate@binkert.org responseCommand() const 1865735Snate@binkert.org { 1874022Sstever@eecs.umich.edu return commandInfo[cmd].response; 1884022Sstever@eecs.umich.edu } 1894022Sstever@eecs.umich.edu 1905735Snate@binkert.org /// Return the string to a cmd given by idx. 1915735Snate@binkert.org const std::string &toString() const { return commandInfo[cmd].str; } 1924022Sstever@eecs.umich.edu int toInt() const { return (int)cmd; } 1934022Sstever@eecs.umich.edu 1945735Snate@binkert.org MemCmd(Command _cmd) : cmd(_cmd) { } 1955735Snate@binkert.org MemCmd(int _cmd) : cmd((Command)_cmd) { } 1965735Snate@binkert.org MemCmd() : cmd(InvalidCmd) { } 1974022Sstever@eecs.umich.edu 1985735Snate@binkert.org bool operator==(MemCmd c2) const { return (cmd == c2.cmd); } 1995735Snate@binkert.org bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); } 2004022Sstever@eecs.umich.edu}; 2014022Sstever@eecs.umich.edu 2022381SN/A/** 2032662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in 2042662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache). (In contrast, a 2052662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the 2062662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several 2072662Sstever@eecs.umich.edu * different Packets along the way.) 2082381SN/A */ 2095314Sstever@gmail.comclass Packet : public FastAlloc, public Printable 2102381SN/A{ 2112813Srdreslin@umich.edu public: 2125735Snate@binkert.org typedef uint32_t FlagsType; 2135735Snate@binkert.org typedef ::Flags<FlagsType> Flags; 2145735Snate@binkert.org typedef short NodeID; 2154022Sstever@eecs.umich.edu 2165735Snate@binkert.org private: 2175735Snate@binkert.org static const FlagsType PUBLIC_FLAGS = 0x00000000; 2185735Snate@binkert.org static const FlagsType PRIVATE_FLAGS = 0x00007F0F; 2195735Snate@binkert.org static const FlagsType COPY_FLAGS = 0x0000000F; 2205735Snate@binkert.org 2215735Snate@binkert.org static const FlagsType SHARED = 0x00000001; 2225735Snate@binkert.org // Special control flags 2235735Snate@binkert.org /// Special timing-mode atomic snoop for multi-level coherence. 2245735Snate@binkert.org static const FlagsType EXPRESS_SNOOP = 0x00000002; 2255735Snate@binkert.org /// Does supplier have exclusive copy? 2265735Snate@binkert.org /// Useful for multi-level coherence. 2275735Snate@binkert.org static const FlagsType SUPPLY_EXCLUSIVE = 0x00000004; 2285735Snate@binkert.org // Snoop response flags 2295735Snate@binkert.org static const FlagsType MEM_INHIBIT = 0x00000008; 2305735Snate@binkert.org /// Are the 'addr' and 'size' fields valid? 2315735Snate@binkert.org static const FlagsType VALID_ADDR = 0x00000100; 2325735Snate@binkert.org static const FlagsType VALID_SIZE = 0x00000200; 2335735Snate@binkert.org /// Is the 'src' field valid? 2345735Snate@binkert.org static const FlagsType VALID_SRC = 0x00000400; 2355735Snate@binkert.org static const FlagsType VALID_DST = 0x00000800; 2365735Snate@binkert.org /// Is the data pointer set to a value that shouldn't be freed 2375735Snate@binkert.org /// when the packet is destroyed? 2385735Snate@binkert.org static const FlagsType STATIC_DATA = 0x00001000; 2395735Snate@binkert.org /// The data pointer points to a value that should be freed when 2405735Snate@binkert.org /// the packet is destroyed. 2415735Snate@binkert.org static const FlagsType DYNAMIC_DATA = 0x00002000; 2425735Snate@binkert.org /// the data pointer points to an array (thus delete []) needs to 2435735Snate@binkert.org /// be called on it rather than simply delete. 2445735Snate@binkert.org static const FlagsType ARRAY_DATA = 0x00004000; 2458436SBrad.Beckmann@amd.com /// suppress the error if this packet encounters a functional 2468436SBrad.Beckmann@amd.com /// access failure. 2478436SBrad.Beckmann@amd.com static const FlagsType SUPPRESS_FUNC_ERROR = 0x00008000; 2485735Snate@binkert.org 2495735Snate@binkert.org Flags flags; 2505735Snate@binkert.org 2515735Snate@binkert.org public: 2524022Sstever@eecs.umich.edu typedef MemCmd::Command Command; 2534022Sstever@eecs.umich.edu 2545735Snate@binkert.org /// The command field of the packet. 2554870Sstever@eecs.umich.edu MemCmd cmd; 2564870Sstever@eecs.umich.edu 2575735Snate@binkert.org /// A pointer to the original request. 2584870Sstever@eecs.umich.edu RequestPtr req; 2594870Sstever@eecs.umich.edu 2602566SN/A private: 2615735Snate@binkert.org /** 2625735Snate@binkert.org * A pointer to the data being transfered. It can be differnt 2635735Snate@binkert.org * sizes at each level of the heirarchy so it belongs in the 2645735Snate@binkert.org * packet, not request. This may or may not be populated when a 2655735Snate@binkert.org * responder recieves the packet. If not populated it memory should 2665735Snate@binkert.org * be allocated. 2672566SN/A */ 2682566SN/A PacketDataPtr data; 2692566SN/A 2705735Snate@binkert.org /// The address of the request. This address could be virtual or 2715735Snate@binkert.org /// physical, depending on the system configuration. 2722381SN/A Addr addr; 2732381SN/A 2745735Snate@binkert.org /// The size of the request or transfer. 2756227Snate@binkert.org unsigned size; 2762381SN/A 2775735Snate@binkert.org /** 2785735Snate@binkert.org * Device address (e.g., bus ID) of the source of the 2795735Snate@binkert.org * transaction. The source is not responsible for setting this 2805735Snate@binkert.org * field; it is set implicitly by the interconnect when the packet 2815735Snate@binkert.org * is first sent. 2825735Snate@binkert.org */ 2835735Snate@binkert.org NodeID src; 2842381SN/A 2855735Snate@binkert.org /** 2865735Snate@binkert.org * Device address (e.g., bus ID) of the destination of the 2875735Snate@binkert.org * transaction. The special value Broadcast indicates that the 2885735Snate@binkert.org * packet should be routed based on its address. This field is 2895735Snate@binkert.org * initialized in the constructor and is thus always valid (unlike 2905735Snate@binkert.org * addr, size, and src). 2915735Snate@binkert.org */ 2925735Snate@binkert.org NodeID dest; 2932641Sstever@eecs.umich.edu 2945735Snate@binkert.org /** 2955735Snate@binkert.org * The original value of the command field. Only valid when the 2964870Sstever@eecs.umich.edu * current command field is an error condition; in that case, the 2974870Sstever@eecs.umich.edu * previous contents of the command field are copied here. This 2984870Sstever@eecs.umich.edu * field is *not* set on non-error responses. 2994870Sstever@eecs.umich.edu */ 3004870Sstever@eecs.umich.edu MemCmd origCmd; 3014870Sstever@eecs.umich.edu 3022641Sstever@eecs.umich.edu public: 3035735Snate@binkert.org /// Used to calculate latencies for each packet. 3042811Srdreslin@umich.edu Tick time; 3052811Srdreslin@umich.edu 3065735Snate@binkert.org /// The time at which the packet will be fully transmitted 3073218Sgblack@eecs.umich.edu Tick finishTime; 3083218Sgblack@eecs.umich.edu 3095735Snate@binkert.org /// The time at which the first chunk of the packet will be transmitted 3103218Sgblack@eecs.umich.edu Tick firstWordTime; 3113218Sgblack@eecs.umich.edu 3125735Snate@binkert.org /// The special destination address indicating that the packet 3135735Snate@binkert.org /// should be routed based on its address. 3145735Snate@binkert.org static const NodeID Broadcast = -1; 3152623SN/A 3165735Snate@binkert.org /** 3175735Snate@binkert.org * A virtual base opaque structure used to hold state associated 3185735Snate@binkert.org * with the packet but specific to the sending device (e.g., an 3195735Snate@binkert.org * MSHR). A pointer to this state is returned in the packet's 3205735Snate@binkert.org * response so that the sender can quickly look up the state 3215735Snate@binkert.org * needed to process it. A specific subclass would be derived 3225735Snate@binkert.org * from this to carry state specific to a particular sending 3235735Snate@binkert.org * device. 3245735Snate@binkert.org */ 3255735Snate@binkert.org struct SenderState 3265735Snate@binkert.org { 3272641Sstever@eecs.umich.edu virtual ~SenderState() {} 3282641Sstever@eecs.umich.edu }; 3292641Sstever@eecs.umich.edu 3305315Sstever@gmail.com /** 3315315Sstever@gmail.com * Object used to maintain state of a PrintReq. The senderState 3325315Sstever@gmail.com * field of a PrintReq should always be of this type. 3335315Sstever@gmail.com */ 3345735Snate@binkert.org class PrintReqState : public SenderState, public FastAlloc 3355735Snate@binkert.org { 3365735Snate@binkert.org private: 3375735Snate@binkert.org /** 3385735Snate@binkert.org * An entry in the label stack. 3395735Snate@binkert.org */ 3405735Snate@binkert.org struct LabelStackEntry 3415735Snate@binkert.org { 3425314Sstever@gmail.com const std::string label; 3435314Sstever@gmail.com std::string *prefix; 3445314Sstever@gmail.com bool labelPrinted; 3455735Snate@binkert.org LabelStackEntry(const std::string &_label, std::string *_prefix); 3465314Sstever@gmail.com }; 3475314Sstever@gmail.com 3485314Sstever@gmail.com typedef std::list<LabelStackEntry> LabelStack; 3495314Sstever@gmail.com LabelStack labelStack; 3505314Sstever@gmail.com 3515314Sstever@gmail.com std::string *curPrefixPtr; 3525314Sstever@gmail.com 3535314Sstever@gmail.com public: 3545314Sstever@gmail.com std::ostream &os; 3555314Sstever@gmail.com const int verbosity; 3565314Sstever@gmail.com 3575314Sstever@gmail.com PrintReqState(std::ostream &os, int verbosity = 0); 3585314Sstever@gmail.com ~PrintReqState(); 3595314Sstever@gmail.com 3605735Snate@binkert.org /** 3615735Snate@binkert.org * Returns the current line prefix. 3625735Snate@binkert.org */ 3635314Sstever@gmail.com const std::string &curPrefix() { return *curPrefixPtr; } 3645315Sstever@gmail.com 3655735Snate@binkert.org /** 3665735Snate@binkert.org * Push a label onto the label stack, and prepend the given 3675315Sstever@gmail.com * prefix string onto the current prefix. Labels will only be 3685735Snate@binkert.org * printed if an object within the label's scope is printed. 3695735Snate@binkert.org */ 3705314Sstever@gmail.com void pushLabel(const std::string &lbl, 3715314Sstever@gmail.com const std::string &prefix = " "); 3725735Snate@binkert.org 3735735Snate@binkert.org /** 3745735Snate@binkert.org * Pop a label off the label stack. 3755735Snate@binkert.org */ 3765314Sstever@gmail.com void popLabel(); 3775735Snate@binkert.org 3785735Snate@binkert.org /** 3795735Snate@binkert.org * Print all of the pending unprinted labels on the 3805315Sstever@gmail.com * stack. Called by printObj(), so normally not called by 3815735Snate@binkert.org * users unless bypassing printObj(). 3825735Snate@binkert.org */ 3835314Sstever@gmail.com void printLabels(); 3845735Snate@binkert.org 3855735Snate@binkert.org /** 3865735Snate@binkert.org * Print a Printable object to os, because it matched the 3875735Snate@binkert.org * address on a PrintReq. 3885735Snate@binkert.org */ 3895314Sstever@gmail.com void printObj(Printable *obj); 3905314Sstever@gmail.com }; 3915314Sstever@gmail.com 3925735Snate@binkert.org /** 3935735Snate@binkert.org * This packet's sender state. Devices should use dynamic_cast<> 3945735Snate@binkert.org * to cast to the state appropriate to the sender. The intent of 3955735Snate@binkert.org * this variable is to allow a device to attach extra information 3965735Snate@binkert.org * to a request. A response packet must return the sender state 3975735Snate@binkert.org * that was attached to the original request (even if a new packet 3985735Snate@binkert.org * is created). 3995735Snate@binkert.org */ 4002662Sstever@eecs.umich.edu SenderState *senderState; 4012641Sstever@eecs.umich.edu 4025735Snate@binkert.org /// Return the string name of the cmd field (for debugging and 4035735Snate@binkert.org /// tracing). 4044022Sstever@eecs.umich.edu const std::string &cmdString() const { return cmd.toString(); } 4052811Srdreslin@umich.edu 4065735Snate@binkert.org /// Return the index of this command. 4074022Sstever@eecs.umich.edu inline int cmdToIndex() const { return cmd.toInt(); } 4082811Srdreslin@umich.edu 4094022Sstever@eecs.umich.edu bool isRead() const { return cmd.isRead(); } 4107465Ssteve.reinhardt@amd.com bool isWrite() const { return cmd.isWrite(); } 4117465Ssteve.reinhardt@amd.com bool isUpgrade() const { return cmd.isUpgrade(); } 4124022Sstever@eecs.umich.edu bool isRequest() const { return cmd.isRequest(); } 4134022Sstever@eecs.umich.edu bool isResponse() const { return cmd.isResponse(); } 4144870Sstever@eecs.umich.edu bool needsExclusive() const { return cmd.needsExclusive(); } 4154022Sstever@eecs.umich.edu bool needsResponse() const { return cmd.needsResponse(); } 4164022Sstever@eecs.umich.edu bool isInvalidate() const { return cmd.isInvalidate(); } 4174022Sstever@eecs.umich.edu bool hasData() const { return cmd.hasData(); } 4184040Ssaidi@eecs.umich.edu bool isReadWrite() const { return cmd.isReadWrite(); } 4196102Sgblack@eecs.umich.edu bool isLLSC() const { return cmd.isLLSC(); } 4204870Sstever@eecs.umich.edu bool isError() const { return cmd.isError(); } 4215314Sstever@gmail.com bool isPrint() const { return cmd.isPrint(); } 4228184Ssomayeh@cs.wisc.edu bool isFlush() const { return cmd.isFlush(); } 4232812Srdreslin@umich.edu 4244870Sstever@eecs.umich.edu // Snoop flags 4255735Snate@binkert.org void assertMemInhibit() { flags.set(MEM_INHIBIT); } 4265764Snate@binkert.org bool memInhibitAsserted() { return flags.isSet(MEM_INHIBIT); } 4275735Snate@binkert.org void assertShared() { flags.set(SHARED); } 4285764Snate@binkert.org bool sharedAsserted() { return flags.isSet(SHARED); } 4294870Sstever@eecs.umich.edu 4304895Sstever@eecs.umich.edu // Special control flags 4315735Snate@binkert.org void setExpressSnoop() { flags.set(EXPRESS_SNOOP); } 4325764Snate@binkert.org bool isExpressSnoop() { return flags.isSet(EXPRESS_SNOOP); } 4335735Snate@binkert.org void setSupplyExclusive() { flags.set(SUPPLY_EXCLUSIVE); } 4347687Ssteve.reinhardt@amd.com void clearSupplyExclusive() { flags.clear(SUPPLY_EXCLUSIVE); } 4355764Snate@binkert.org bool isSupplyExclusive() { return flags.isSet(SUPPLY_EXCLUSIVE); } 4368436SBrad.Beckmann@amd.com void setSuppressFuncError() { flags.set(SUPPRESS_FUNC_ERROR); } 4378436SBrad.Beckmann@amd.com bool suppressFuncError() { return flags.isSet(SUPPRESS_FUNC_ERROR); } 4384895Sstever@eecs.umich.edu 4394870Sstever@eecs.umich.edu // Network error conditions... encapsulate them as methods since 4404870Sstever@eecs.umich.edu // their encoding keeps changing (from result field to command 4414870Sstever@eecs.umich.edu // field, etc.) 4425735Snate@binkert.org void 4435735Snate@binkert.org setNacked() 4445735Snate@binkert.org { 4455735Snate@binkert.org assert(isResponse()); 4465735Snate@binkert.org cmd = MemCmd::NetworkNackError; 4475735Snate@binkert.org } 4485735Snate@binkert.org 4495735Snate@binkert.org void 4505735Snate@binkert.org setBadAddress() 4515735Snate@binkert.org { 4525735Snate@binkert.org assert(isResponse()); 4535735Snate@binkert.org cmd = MemCmd::BadAddressError; 4545735Snate@binkert.org } 4555735Snate@binkert.org 4565735Snate@binkert.org bool wasNacked() const { return cmd == MemCmd::NetworkNackError; } 4575735Snate@binkert.org bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; } 4584986Ssaidi@eecs.umich.edu void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; } 4592814Srdreslin@umich.edu 4606768SBrad.Beckmann@amd.com bool isSrcValid() { return flags.isSet(VALID_SRC); } 4615735Snate@binkert.org /// Accessor function to get the source index of the packet. 4625764Snate@binkert.org NodeID getSrc() const { assert(flags.isSet(VALID_SRC)); return src; } 4635735Snate@binkert.org /// Accessor function to set the source index of the packet. 4645735Snate@binkert.org void setSrc(NodeID _src) { src = _src; flags.set(VALID_SRC); } 4655735Snate@binkert.org /// Reset source field, e.g. to retransmit packet on different bus. 4665735Snate@binkert.org void clearSrc() { flags.clear(VALID_SRC); } 4672641Sstever@eecs.umich.edu 4686768SBrad.Beckmann@amd.com bool isDestValid() { return flags.isSet(VALID_DST); } 4695735Snate@binkert.org /// Accessor function for the destination index of the packet. 4705764Snate@binkert.org NodeID getDest() const { assert(flags.isSet(VALID_DST)); return dest; } 4715735Snate@binkert.org /// Accessor function to set the destination index of the packet. 4725735Snate@binkert.org void setDest(NodeID _dest) { dest = _dest; flags.set(VALID_DST); } 4732381SN/A 4745764Snate@binkert.org Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; } 4756227Snate@binkert.org unsigned getSize() const { assert(flags.isSet(VALID_SIZE)); return size; } 4765735Snate@binkert.org Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); } 4772549SN/A 4785735Snate@binkert.org /** 4797550SBrad.Beckmann@amd.com * It has been determined that the SC packet should successfully update 4807550SBrad.Beckmann@amd.com * memory. Therefore, convert this SC packet to a normal write. 4817550SBrad.Beckmann@amd.com */ 4827550SBrad.Beckmann@amd.com void 4837550SBrad.Beckmann@amd.com convertScToWrite() 4847550SBrad.Beckmann@amd.com { 4857550SBrad.Beckmann@amd.com assert(isLLSC()); 4867550SBrad.Beckmann@amd.com assert(isWrite()); 4877550SBrad.Beckmann@amd.com cmd = MemCmd::WriteReq; 4887550SBrad.Beckmann@amd.com } 4897550SBrad.Beckmann@amd.com 4907550SBrad.Beckmann@amd.com /** 4917550SBrad.Beckmann@amd.com * When ruby is in use, Ruby will monitor the cache line and thus M5 4927550SBrad.Beckmann@amd.com * phys memory should treat LL ops as normal reads. 4937550SBrad.Beckmann@amd.com */ 4947550SBrad.Beckmann@amd.com void 4957550SBrad.Beckmann@amd.com convertLlToRead() 4967550SBrad.Beckmann@amd.com { 4977550SBrad.Beckmann@amd.com assert(isLLSC()); 4987550SBrad.Beckmann@amd.com assert(isRead()); 4997550SBrad.Beckmann@amd.com cmd = MemCmd::ReadReq; 5007550SBrad.Beckmann@amd.com } 5017550SBrad.Beckmann@amd.com 5027550SBrad.Beckmann@amd.com /** 5035735Snate@binkert.org * Constructor. Note that a Request object must be constructed 5045735Snate@binkert.org * first, but the Requests's physical address and size fields need 5055735Snate@binkert.org * not be valid. The command and destination addresses must be 5065735Snate@binkert.org * supplied. 5075735Snate@binkert.org */ 5085735Snate@binkert.org Packet(Request *_req, MemCmd _cmd, NodeID _dest) 5095745Snate@binkert.org : flags(VALID_DST), cmd(_cmd), req(_req), data(NULL), 5107823Ssteve.reinhardt@amd.com dest(_dest), time(curTick()), senderState(NULL) 5112641Sstever@eecs.umich.edu { 5126104Ssteve.reinhardt@amd.com if (req->hasPaddr()) { 5136104Ssteve.reinhardt@amd.com addr = req->getPaddr(); 5146104Ssteve.reinhardt@amd.com flags.set(VALID_ADDR); 5156104Ssteve.reinhardt@amd.com } 5166104Ssteve.reinhardt@amd.com if (req->hasSize()) { 5176104Ssteve.reinhardt@amd.com size = req->getSize(); 5186104Ssteve.reinhardt@amd.com flags.set(VALID_SIZE); 5196104Ssteve.reinhardt@amd.com } 5202813Srdreslin@umich.edu } 5212813Srdreslin@umich.edu 5225735Snate@binkert.org /** 5235735Snate@binkert.org * Alternate constructor if you are trying to create a packet with 5245735Snate@binkert.org * a request that is for a whole block, not the address from the 5255735Snate@binkert.org * req. this allows for overriding the size/addr of the req. 5265735Snate@binkert.org */ 5275735Snate@binkert.org Packet(Request *_req, MemCmd _cmd, NodeID _dest, int _blkSize) 5285745Snate@binkert.org : flags(VALID_DST), cmd(_cmd), req(_req), data(NULL), 5297823Ssteve.reinhardt@amd.com dest(_dest), time(curTick()), senderState(NULL) 5302813Srdreslin@umich.edu { 5316104Ssteve.reinhardt@amd.com if (req->hasPaddr()) { 5326104Ssteve.reinhardt@amd.com addr = req->getPaddr() & ~(_blkSize - 1); 5336104Ssteve.reinhardt@amd.com flags.set(VALID_ADDR); 5346104Ssteve.reinhardt@amd.com } 5356104Ssteve.reinhardt@amd.com size = _blkSize; 5366104Ssteve.reinhardt@amd.com flags.set(VALID_SIZE); 5374626Sstever@eecs.umich.edu } 5384626Sstever@eecs.umich.edu 5395735Snate@binkert.org /** 5405735Snate@binkert.org * Alternate constructor for copying a packet. Copy all fields 5414887Sstever@eecs.umich.edu * *except* if the original packet's data was dynamic, don't copy 5424887Sstever@eecs.umich.edu * that, as we can't guarantee that the new packet's lifetime is 5434887Sstever@eecs.umich.edu * less than that of the original packet. In this case the new 5445735Snate@binkert.org * packet should allocate its own data. 5455735Snate@binkert.org */ 5465735Snate@binkert.org Packet(Packet *pkt, bool clearFlags = false) 5475735Snate@binkert.org : cmd(pkt->cmd), req(pkt->req), 5485764Snate@binkert.org data(pkt->flags.isSet(STATIC_DATA) ? pkt->data : NULL), 5495735Snate@binkert.org addr(pkt->addr), size(pkt->size), src(pkt->src), dest(pkt->dest), 5507823Ssteve.reinhardt@amd.com time(curTick()), senderState(pkt->senderState) 5514626Sstever@eecs.umich.edu { 5525735Snate@binkert.org if (!clearFlags) 5535735Snate@binkert.org flags.set(pkt->flags & COPY_FLAGS); 5545735Snate@binkert.org 5555735Snate@binkert.org flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE|VALID_SRC|VALID_DST)); 5565735Snate@binkert.org flags.set(pkt->flags & STATIC_DATA); 5572641Sstever@eecs.umich.edu } 5582549SN/A 5595735Snate@binkert.org /** 5605735Snate@binkert.org * clean up packet variables 5615735Snate@binkert.org */ 5622566SN/A ~Packet() 5635387Sstever@gmail.com { 5645387Sstever@gmail.com // If this is a request packet for which there's no response, 5655387Sstever@gmail.com // delete the request object here, since the requester will 5665387Sstever@gmail.com // never get the chance. 5675387Sstever@gmail.com if (req && isRequest() && !needsResponse()) 5685387Sstever@gmail.com delete req; 5695735Snate@binkert.org deleteData(); 5705387Sstever@gmail.com } 5712566SN/A 5725735Snate@binkert.org /** 5735735Snate@binkert.org * Reinitialize packet address and size from the associated 5745735Snate@binkert.org * Request object, and reset other fields that may have been 5755735Snate@binkert.org * modified by a previous transaction. Typically called when a 5765735Snate@binkert.org * statically allocated Request/Packet pair is reused for multiple 5775735Snate@binkert.org * transactions. 5785735Snate@binkert.org */ 5795735Snate@binkert.org void 5805735Snate@binkert.org reinitFromRequest() 5815735Snate@binkert.org { 5826104Ssteve.reinhardt@amd.com assert(req->hasPaddr()); 5834870Sstever@eecs.umich.edu flags = 0; 5846104Ssteve.reinhardt@amd.com addr = req->getPaddr(); 5856104Ssteve.reinhardt@amd.com size = req->getSize(); 5866223Snate@binkert.org time = req->time(); 5875735Snate@binkert.org 5885735Snate@binkert.org flags.set(VALID_ADDR|VALID_SIZE); 5895735Snate@binkert.org deleteData(); 5902662Sstever@eecs.umich.edu } 5912566SN/A 5924626Sstever@eecs.umich.edu /** 5934626Sstever@eecs.umich.edu * Take a request packet and modify it in place to be suitable for 5944626Sstever@eecs.umich.edu * returning as a response to that request. The source and 5954626Sstever@eecs.umich.edu * destination fields are *not* modified, as is appropriate for 5964626Sstever@eecs.umich.edu * atomic accesses. 5974626Sstever@eecs.umich.edu */ 5985735Snate@binkert.org void 5995735Snate@binkert.org makeResponse() 6004626Sstever@eecs.umich.edu { 6012662Sstever@eecs.umich.edu assert(needsResponse()); 6022855Srdreslin@umich.edu assert(isRequest()); 6034986Ssaidi@eecs.umich.edu origCmd = cmd; 6044022Sstever@eecs.umich.edu cmd = cmd.responseCommand(); 6055745Snate@binkert.org 6067464Ssteve.reinhardt@amd.com // responses are never express, even if the snoop that 6077464Ssteve.reinhardt@amd.com // triggered them was 6087464Ssteve.reinhardt@amd.com flags.clear(EXPRESS_SNOOP); 6097464Ssteve.reinhardt@amd.com 6105745Snate@binkert.org dest = src; 6115764Snate@binkert.org flags.set(VALID_DST, flags.isSet(VALID_SRC)); 6125745Snate@binkert.org flags.clear(VALID_SRC); 6132641Sstever@eecs.umich.edu } 6142641Sstever@eecs.umich.edu 6155735Snate@binkert.org void 6165735Snate@binkert.org makeAtomicResponse() 6174870Sstever@eecs.umich.edu { 6184870Sstever@eecs.umich.edu makeResponse(); 6194870Sstever@eecs.umich.edu } 6204870Sstever@eecs.umich.edu 6215735Snate@binkert.org void 6225735Snate@binkert.org makeTimingResponse() 6233348Sbinkertn@umich.edu { 6244870Sstever@eecs.umich.edu makeResponse(); 6253135Srdreslin@umich.edu } 6263135Srdreslin@umich.edu 6278436SBrad.Beckmann@amd.com void 6288436SBrad.Beckmann@amd.com setFunctionalResponseStatus(bool success) 6298436SBrad.Beckmann@amd.com { 6308436SBrad.Beckmann@amd.com if (!success) { 6318436SBrad.Beckmann@amd.com if (isWrite()) { 6328436SBrad.Beckmann@amd.com cmd = MemCmd::FunctionalWriteError; 6338436SBrad.Beckmann@amd.com } else { 6348436SBrad.Beckmann@amd.com cmd = MemCmd::FunctionalReadError; 6358436SBrad.Beckmann@amd.com } 6368436SBrad.Beckmann@amd.com } 6378436SBrad.Beckmann@amd.com } 6388436SBrad.Beckmann@amd.com 6393348Sbinkertn@umich.edu /** 6403348Sbinkertn@umich.edu * Take a request packet that has been returned as NACKED and 6413348Sbinkertn@umich.edu * modify it so that it can be sent out again. Only packets that 6423348Sbinkertn@umich.edu * need a response can be NACKED, so verify that that is true. 6433348Sbinkertn@umich.edu */ 6443348Sbinkertn@umich.edu void 6453348Sbinkertn@umich.edu reinitNacked() 6463348Sbinkertn@umich.edu { 6474870Sstever@eecs.umich.edu assert(wasNacked()); 6484870Sstever@eecs.umich.edu cmd = origCmd; 6494870Sstever@eecs.umich.edu assert(needsResponse()); 6504870Sstever@eecs.umich.edu setDest(Broadcast); 6512685Ssaidi@eecs.umich.edu } 6522685Ssaidi@eecs.umich.edu 6537006Snate@binkert.org void 6547006Snate@binkert.org setSize(unsigned size) 6557006Snate@binkert.org { 6567006Snate@binkert.org assert(!flags.isSet(VALID_SIZE)); 6577006Snate@binkert.org 6587006Snate@binkert.org this->size = size; 6597006Snate@binkert.org flags.set(VALID_SIZE); 6607006Snate@binkert.org } 6617006Snate@binkert.org 6622685Ssaidi@eecs.umich.edu 6633348Sbinkertn@umich.edu /** 6643348Sbinkertn@umich.edu * Set the data pointer to the following value that should not be 6653348Sbinkertn@umich.edu * freed. 6662566SN/A */ 6672566SN/A template <typename T> 6683348Sbinkertn@umich.edu void 6693348Sbinkertn@umich.edu dataStatic(T *p) 6703348Sbinkertn@umich.edu { 6715764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); 6723348Sbinkertn@umich.edu data = (PacketDataPtr)p; 6735735Snate@binkert.org flags.set(STATIC_DATA); 6743348Sbinkertn@umich.edu } 6752566SN/A 6763348Sbinkertn@umich.edu /** 6773348Sbinkertn@umich.edu * Set the data pointer to a value that should have delete [] 6783348Sbinkertn@umich.edu * called on it. 6793348Sbinkertn@umich.edu */ 6802566SN/A template <typename T> 6813348Sbinkertn@umich.edu void 6823348Sbinkertn@umich.edu dataDynamicArray(T *p) 6833348Sbinkertn@umich.edu { 6845764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); 6853348Sbinkertn@umich.edu data = (PacketDataPtr)p; 6865735Snate@binkert.org flags.set(DYNAMIC_DATA|ARRAY_DATA); 6873348Sbinkertn@umich.edu } 6883348Sbinkertn@umich.edu 6893348Sbinkertn@umich.edu /** 6903348Sbinkertn@umich.edu * set the data pointer to a value that should have delete called 6913348Sbinkertn@umich.edu * on it. 6923348Sbinkertn@umich.edu */ 6933348Sbinkertn@umich.edu template <typename T> 6943348Sbinkertn@umich.edu void 6953348Sbinkertn@umich.edu dataDynamic(T *p) 6963348Sbinkertn@umich.edu { 6975764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); 6983348Sbinkertn@umich.edu data = (PacketDataPtr)p; 6995735Snate@binkert.org flags.set(DYNAMIC_DATA); 7003348Sbinkertn@umich.edu } 7013348Sbinkertn@umich.edu 7025735Snate@binkert.org /** 7035735Snate@binkert.org * get a pointer to the data ptr. 7045735Snate@binkert.org */ 7053348Sbinkertn@umich.edu template <typename T> 7063348Sbinkertn@umich.edu T* 7077915SBrad.Beckmann@amd.com getPtr(bool null_ok = false) 7083348Sbinkertn@umich.edu { 7097915SBrad.Beckmann@amd.com assert(null_ok || flags.isSet(STATIC_DATA|DYNAMIC_DATA)); 7103348Sbinkertn@umich.edu return (T*)data; 7113348Sbinkertn@umich.edu } 7122566SN/A 7135735Snate@binkert.org /** 7145735Snate@binkert.org * return the value of what is pointed to in the packet. 7155735Snate@binkert.org */ 7162566SN/A template <typename T> 7172592SN/A T get(); 7182566SN/A 7195735Snate@binkert.org /** 7205735Snate@binkert.org * set the value in the data pointer to v. 7215735Snate@binkert.org */ 7222566SN/A template <typename T> 7232592SN/A void set(T v); 7242566SN/A 7253348Sbinkertn@umich.edu /** 7264626Sstever@eecs.umich.edu * Copy data into the packet from the provided pointer. 7274626Sstever@eecs.umich.edu */ 7285735Snate@binkert.org void 7295735Snate@binkert.org setData(uint8_t *p) 7304626Sstever@eecs.umich.edu { 7317691SAli.Saidi@ARM.com if (p != getPtr<uint8_t>()) 7327691SAli.Saidi@ARM.com std::memcpy(getPtr<uint8_t>(), p, getSize()); 7334626Sstever@eecs.umich.edu } 7344626Sstever@eecs.umich.edu 7354626Sstever@eecs.umich.edu /** 7364626Sstever@eecs.umich.edu * Copy data into the packet from the provided block pointer, 7374626Sstever@eecs.umich.edu * which is aligned to the given block size. 7384626Sstever@eecs.umich.edu */ 7395735Snate@binkert.org void 7405735Snate@binkert.org setDataFromBlock(uint8_t *blk_data, int blkSize) 7414626Sstever@eecs.umich.edu { 7424626Sstever@eecs.umich.edu setData(blk_data + getOffset(blkSize)); 7434626Sstever@eecs.umich.edu } 7444626Sstever@eecs.umich.edu 7454626Sstever@eecs.umich.edu /** 7464626Sstever@eecs.umich.edu * Copy data from the packet to the provided block pointer, which 7474626Sstever@eecs.umich.edu * is aligned to the given block size. 7484626Sstever@eecs.umich.edu */ 7495735Snate@binkert.org void 7505735Snate@binkert.org writeData(uint8_t *p) 7514626Sstever@eecs.umich.edu { 7524626Sstever@eecs.umich.edu std::memcpy(p, getPtr<uint8_t>(), getSize()); 7534626Sstever@eecs.umich.edu } 7544626Sstever@eecs.umich.edu 7554626Sstever@eecs.umich.edu /** 7564626Sstever@eecs.umich.edu * Copy data from the packet to the memory at the provided pointer. 7574626Sstever@eecs.umich.edu */ 7585735Snate@binkert.org void 7595735Snate@binkert.org writeDataToBlock(uint8_t *blk_data, int blkSize) 7604626Sstever@eecs.umich.edu { 7614626Sstever@eecs.umich.edu writeData(blk_data + getOffset(blkSize)); 7624626Sstever@eecs.umich.edu } 7634626Sstever@eecs.umich.edu 7644626Sstever@eecs.umich.edu /** 7653348Sbinkertn@umich.edu * delete the data pointed to in the data pointer. Ok to call to 7663348Sbinkertn@umich.edu * matter how data was allocted. 7673348Sbinkertn@umich.edu */ 7685735Snate@binkert.org void 7695735Snate@binkert.org deleteData() 7705735Snate@binkert.org { 7715764Snate@binkert.org if (flags.isSet(ARRAY_DATA)) 7725735Snate@binkert.org delete [] data; 7735764Snate@binkert.org else if (flags.isSet(DYNAMIC_DATA)) 7745735Snate@binkert.org delete data; 7755735Snate@binkert.org 7765735Snate@binkert.org flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA); 7775735Snate@binkert.org data = NULL; 7785735Snate@binkert.org } 7792566SN/A 7802566SN/A /** If there isn't data in the packet, allocate some. */ 7815735Snate@binkert.org void 7825735Snate@binkert.org allocate() 7835735Snate@binkert.org { 7845735Snate@binkert.org if (data) { 7855764Snate@binkert.org assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA)); 7865745Snate@binkert.org return; 7875735Snate@binkert.org } 7885745Snate@binkert.org 7895764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); 7905745Snate@binkert.org flags.set(DYNAMIC_DATA|ARRAY_DATA); 7915745Snate@binkert.org data = new uint8_t[getSize()]; 7925735Snate@binkert.org } 7935735Snate@binkert.org 7944626Sstever@eecs.umich.edu /** 7954626Sstever@eecs.umich.edu * Check a functional request against a memory value represented 7964626Sstever@eecs.umich.edu * by a base/size pair and an associated data array. If the 7974626Sstever@eecs.umich.edu * functional request is a read, it may be satisfied by the memory 7984626Sstever@eecs.umich.edu * value. If the functional request is a write, it may update the 7994626Sstever@eecs.umich.edu * memory value. 8004626Sstever@eecs.umich.edu */ 8015314Sstever@gmail.com bool checkFunctional(Printable *obj, Addr base, int size, uint8_t *data); 8024626Sstever@eecs.umich.edu 8034626Sstever@eecs.umich.edu /** 8044626Sstever@eecs.umich.edu * Check a functional request against a memory value stored in 8055315Sstever@gmail.com * another packet (i.e. an in-transit request or response). 8064626Sstever@eecs.umich.edu */ 8075735Snate@binkert.org bool 8085735Snate@binkert.org checkFunctional(PacketPtr other) 8095735Snate@binkert.org { 8105735Snate@binkert.org uint8_t *data = other->hasData() ? other->getPtr<uint8_t>() : NULL; 8115735Snate@binkert.org return checkFunctional(other, other->getAddr(), other->getSize(), 8125735Snate@binkert.org data); 8134626Sstever@eecs.umich.edu } 8145314Sstever@gmail.com 8155315Sstever@gmail.com /** 8165315Sstever@gmail.com * Push label for PrintReq (safe to call unconditionally). 8175315Sstever@gmail.com */ 8185735Snate@binkert.org void 8195735Snate@binkert.org pushLabel(const std::string &lbl) 8205735Snate@binkert.org { 8215735Snate@binkert.org if (isPrint()) 8225735Snate@binkert.org safe_cast<PrintReqState*>(senderState)->pushLabel(lbl); 8235314Sstever@gmail.com } 8245314Sstever@gmail.com 8255315Sstever@gmail.com /** 8265315Sstever@gmail.com * Pop label for PrintReq (safe to call unconditionally). 8275315Sstever@gmail.com */ 8285735Snate@binkert.org void 8295735Snate@binkert.org popLabel() 8305735Snate@binkert.org { 8315735Snate@binkert.org if (isPrint()) 8325735Snate@binkert.org safe_cast<PrintReqState*>(senderState)->popLabel(); 8335314Sstever@gmail.com } 8345314Sstever@gmail.com 8355314Sstever@gmail.com void print(std::ostream &o, int verbosity = 0, 8365314Sstever@gmail.com const std::string &prefix = "") const; 8372381SN/A}; 8382381SN/A 8392381SN/A#endif //__MEM_PACKET_HH 840