packet.hh revision 4610
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" 482392SN/A#include "mem/request.hh" 492980Sgblack@eecs.umich.edu#include "sim/host.hh" 504167Sbinkertn@umich.edu#include "sim/core.hh" 512394SN/A 523940Ssaidi@eecs.umich.edu 532394SN/Astruct Packet; 543349Sbinkertn@umich.edutypedef Packet *PacketPtr; 552394SN/Atypedef uint8_t* PacketDataPtr; 562812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList; 572812Srdreslin@umich.edu 582812Srdreslin@umich.edu//Coherence Flags 593366Sstever@eecs.umich.edu#define NACKED_LINE (1 << 0) 603366Sstever@eecs.umich.edu#define SATISFIED (1 << 1) 613366Sstever@eecs.umich.edu#define SHARED_LINE (1 << 2) 623366Sstever@eecs.umich.edu#define CACHE_LINE_FILL (1 << 3) 633366Sstever@eecs.umich.edu#define COMPRESSED (1 << 4) 643366Sstever@eecs.umich.edu#define NO_ALLOCATE (1 << 5) 653366Sstever@eecs.umich.edu#define SNOOP_COMMIT (1 << 6) 662382SN/A 674022Sstever@eecs.umich.edu 684022Sstever@eecs.umich.educlass MemCmd 694022Sstever@eecs.umich.edu{ 704022Sstever@eecs.umich.edu public: 714022Sstever@eecs.umich.edu 724022Sstever@eecs.umich.edu /** List of all commands associated with a packet. */ 734022Sstever@eecs.umich.edu enum Command 744022Sstever@eecs.umich.edu { 754022Sstever@eecs.umich.edu InvalidCmd, 764022Sstever@eecs.umich.edu ReadReq, 774022Sstever@eecs.umich.edu WriteReq, 784022Sstever@eecs.umich.edu WriteReqNoAck, 794022Sstever@eecs.umich.edu ReadResp, 804022Sstever@eecs.umich.edu WriteResp, 814022Sstever@eecs.umich.edu Writeback, 824022Sstever@eecs.umich.edu SoftPFReq, 834022Sstever@eecs.umich.edu HardPFReq, 844022Sstever@eecs.umich.edu SoftPFResp, 854022Sstever@eecs.umich.edu HardPFResp, 864022Sstever@eecs.umich.edu InvalidateReq, 874022Sstever@eecs.umich.edu WriteInvalidateReq, 884022Sstever@eecs.umich.edu WriteInvalidateResp, 894022Sstever@eecs.umich.edu UpgradeReq, 904022Sstever@eecs.umich.edu ReadExReq, 914022Sstever@eecs.umich.edu ReadExResp, 924040Ssaidi@eecs.umich.edu SwapReq, 934040Ssaidi@eecs.umich.edu SwapResp, 944022Sstever@eecs.umich.edu NUM_MEM_CMDS 954022Sstever@eecs.umich.edu }; 964022Sstever@eecs.umich.edu 974022Sstever@eecs.umich.edu private: 984022Sstever@eecs.umich.edu /** List of command attributes. */ 994022Sstever@eecs.umich.edu enum Attribute 1004022Sstever@eecs.umich.edu { 1014022Sstever@eecs.umich.edu IsRead, 1024022Sstever@eecs.umich.edu IsWrite, 1034022Sstever@eecs.umich.edu IsPrefetch, 1044022Sstever@eecs.umich.edu IsInvalidate, 1054022Sstever@eecs.umich.edu IsRequest, 1064022Sstever@eecs.umich.edu IsResponse, 1074022Sstever@eecs.umich.edu NeedsResponse, 1084022Sstever@eecs.umich.edu IsSWPrefetch, 1094022Sstever@eecs.umich.edu IsHWPrefetch, 1104022Sstever@eecs.umich.edu IsUpgrade, 1114022Sstever@eecs.umich.edu HasData, 1124040Ssaidi@eecs.umich.edu IsReadWrite, 1134022Sstever@eecs.umich.edu NUM_COMMAND_ATTRIBUTES 1144022Sstever@eecs.umich.edu }; 1154022Sstever@eecs.umich.edu 1164022Sstever@eecs.umich.edu /** Structure that defines attributes and other data associated 1174022Sstever@eecs.umich.edu * with a Command. */ 1184022Sstever@eecs.umich.edu struct CommandInfo { 1194022Sstever@eecs.umich.edu /** Set of attribute flags. */ 1204022Sstever@eecs.umich.edu const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes; 1214022Sstever@eecs.umich.edu /** Corresponding response for requests; InvalidCmd if no 1224022Sstever@eecs.umich.edu * response is applicable. */ 1234022Sstever@eecs.umich.edu const Command response; 1244022Sstever@eecs.umich.edu /** String representation (for printing) */ 1254022Sstever@eecs.umich.edu const std::string str; 1264022Sstever@eecs.umich.edu }; 1274022Sstever@eecs.umich.edu 1284022Sstever@eecs.umich.edu /** Array to map Command enum to associated info. */ 1294022Sstever@eecs.umich.edu static const CommandInfo commandInfo[]; 1304022Sstever@eecs.umich.edu 1314022Sstever@eecs.umich.edu private: 1324022Sstever@eecs.umich.edu 1334022Sstever@eecs.umich.edu Command cmd; 1344022Sstever@eecs.umich.edu 1354022Sstever@eecs.umich.edu bool testCmdAttrib(MemCmd::Attribute attrib) const { 1364022Sstever@eecs.umich.edu return commandInfo[cmd].attributes[attrib] != 0; 1374022Sstever@eecs.umich.edu } 1384022Sstever@eecs.umich.edu 1394022Sstever@eecs.umich.edu public: 1404022Sstever@eecs.umich.edu 1414022Sstever@eecs.umich.edu bool isRead() const { return testCmdAttrib(IsRead); } 1424022Sstever@eecs.umich.edu bool isWrite() const { return testCmdAttrib(IsWrite); } 1434022Sstever@eecs.umich.edu bool isRequest() const { return testCmdAttrib(IsRequest); } 1444022Sstever@eecs.umich.edu bool isResponse() const { return testCmdAttrib(IsResponse); } 1454022Sstever@eecs.umich.edu bool needsResponse() const { return testCmdAttrib(NeedsResponse); } 1464022Sstever@eecs.umich.edu bool isInvalidate() const { return testCmdAttrib(IsInvalidate); } 1474022Sstever@eecs.umich.edu bool hasData() const { return testCmdAttrib(HasData); } 1484040Ssaidi@eecs.umich.edu bool isReadWrite() const { return testCmdAttrib(IsReadWrite); } 1494022Sstever@eecs.umich.edu 1504022Sstever@eecs.umich.edu const Command responseCommand() const { 1514022Sstever@eecs.umich.edu return commandInfo[cmd].response; 1524022Sstever@eecs.umich.edu } 1534022Sstever@eecs.umich.edu 1544022Sstever@eecs.umich.edu /** Return the string to a cmd given by idx. */ 1554022Sstever@eecs.umich.edu const std::string &toString() const { 1564022Sstever@eecs.umich.edu return commandInfo[cmd].str; 1574022Sstever@eecs.umich.edu } 1584022Sstever@eecs.umich.edu 1594022Sstever@eecs.umich.edu int toInt() const { return (int)cmd; } 1604022Sstever@eecs.umich.edu 1614022Sstever@eecs.umich.edu MemCmd(Command _cmd) 1624022Sstever@eecs.umich.edu : cmd(_cmd) 1634022Sstever@eecs.umich.edu { } 1644022Sstever@eecs.umich.edu 1654022Sstever@eecs.umich.edu MemCmd(int _cmd) 1664022Sstever@eecs.umich.edu : cmd((Command)_cmd) 1674022Sstever@eecs.umich.edu { } 1684022Sstever@eecs.umich.edu 1694022Sstever@eecs.umich.edu MemCmd() 1704022Sstever@eecs.umich.edu : cmd(InvalidCmd) 1714022Sstever@eecs.umich.edu { } 1724022Sstever@eecs.umich.edu 1734022Sstever@eecs.umich.edu bool operator==(MemCmd c2) { return (cmd == c2.cmd); } 1744022Sstever@eecs.umich.edu bool operator!=(MemCmd c2) { return (cmd != c2.cmd); } 1754022Sstever@eecs.umich.edu 1764022Sstever@eecs.umich.edu friend class Packet; 1774022Sstever@eecs.umich.edu}; 1784022Sstever@eecs.umich.edu 1792381SN/A/** 1802662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in 1812662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache). (In contrast, a 1822662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the 1832662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several 1842662Sstever@eecs.umich.edu * different Packets along the way.) 1852381SN/A */ 1864610Ssaidi@eecs.umich.educlass Packet : public FastAlloc 1872381SN/A{ 1882813Srdreslin@umich.edu public: 1894022Sstever@eecs.umich.edu 1904022Sstever@eecs.umich.edu typedef MemCmd::Command Command; 1914022Sstever@eecs.umich.edu 1922813Srdreslin@umich.edu /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */ 1932813Srdreslin@umich.edu uint64_t flags; 1942813Srdreslin@umich.edu 1952566SN/A private: 1962662Sstever@eecs.umich.edu /** A pointer to the data being transfered. It can be differnt 1972662Sstever@eecs.umich.edu * sizes at each level of the heirarchy so it belongs in the 1982662Sstever@eecs.umich.edu * packet, not request. This may or may not be populated when a 1992662Sstever@eecs.umich.edu * responder recieves the packet. If not populated it memory 2002662Sstever@eecs.umich.edu * should be allocated. 2012566SN/A */ 2022566SN/A PacketDataPtr data; 2032566SN/A 2042662Sstever@eecs.umich.edu /** Is the data pointer set to a value that shouldn't be freed 2052662Sstever@eecs.umich.edu * when the packet is destroyed? */ 2062566SN/A bool staticData; 2072662Sstever@eecs.umich.edu /** The data pointer points to a value that should be freed when 2082662Sstever@eecs.umich.edu * the packet is destroyed. */ 2092566SN/A bool dynamicData; 2102662Sstever@eecs.umich.edu /** the data pointer points to an array (thus delete [] ) needs to 2112662Sstever@eecs.umich.edu * be called on it rather than simply delete.*/ 2122566SN/A bool arrayData; 2132566SN/A 2142662Sstever@eecs.umich.edu /** The address of the request. This address could be virtual or 2152662Sstever@eecs.umich.edu * physical, depending on the system configuration. */ 2162381SN/A Addr addr; 2172381SN/A 2182662Sstever@eecs.umich.edu /** The size of the request or transfer. */ 2192381SN/A int size; 2202381SN/A 2212662Sstever@eecs.umich.edu /** Device address (e.g., bus ID) of the source of the 2222662Sstever@eecs.umich.edu * transaction. The source is not responsible for setting this 2232662Sstever@eecs.umich.edu * field; it is set implicitly by the interconnect when the 2243349Sbinkertn@umich.edu * packet is first sent. */ 2252381SN/A short src; 2262381SN/A 2272662Sstever@eecs.umich.edu /** Device address (e.g., bus ID) of the destination of the 2282662Sstever@eecs.umich.edu * transaction. The special value Broadcast indicates that the 2292662Sstever@eecs.umich.edu * packet should be routed based on its address. This field is 2302662Sstever@eecs.umich.edu * initialized in the constructor and is thus always valid 2312662Sstever@eecs.umich.edu * (unlike * addr, size, and src). */ 2322641Sstever@eecs.umich.edu short dest; 2332641Sstever@eecs.umich.edu 2342663Sstever@eecs.umich.edu /** Are the 'addr' and 'size' fields valid? */ 2352663Sstever@eecs.umich.edu bool addrSizeValid; 2362662Sstever@eecs.umich.edu /** Is the 'src' field valid? */ 2372641Sstever@eecs.umich.edu bool srcValid; 2382813Srdreslin@umich.edu 2392641Sstever@eecs.umich.edu 2402641Sstever@eecs.umich.edu public: 2412641Sstever@eecs.umich.edu 2422811Srdreslin@umich.edu /** Used to calculate latencies for each packet.*/ 2432811Srdreslin@umich.edu Tick time; 2442811Srdreslin@umich.edu 2453218Sgblack@eecs.umich.edu /** The time at which the packet will be fully transmitted */ 2463218Sgblack@eecs.umich.edu Tick finishTime; 2473218Sgblack@eecs.umich.edu 2483218Sgblack@eecs.umich.edu /** The time at which the first chunk of the packet will be transmitted */ 2493218Sgblack@eecs.umich.edu Tick firstWordTime; 2503218Sgblack@eecs.umich.edu 2512662Sstever@eecs.umich.edu /** The special destination address indicating that the packet 2522662Sstever@eecs.umich.edu * should be routed based on its address. */ 2532623SN/A static const short Broadcast = -1; 2542623SN/A 2552662Sstever@eecs.umich.edu /** A pointer to the original request. */ 2562641Sstever@eecs.umich.edu RequestPtr req; 2572641Sstever@eecs.umich.edu 2582662Sstever@eecs.umich.edu /** A virtual base opaque structure used to hold coherence-related 2592662Sstever@eecs.umich.edu * state. A specific subclass would be derived from this to 2602662Sstever@eecs.umich.edu * carry state specific to a particular coherence protocol. */ 2614610Ssaidi@eecs.umich.edu class CoherenceState : public FastAlloc { 2622641Sstever@eecs.umich.edu public: 2632641Sstever@eecs.umich.edu virtual ~CoherenceState() {} 2642641Sstever@eecs.umich.edu }; 2652641Sstever@eecs.umich.edu 2662662Sstever@eecs.umich.edu /** This packet's coherence state. Caches should use 2672662Sstever@eecs.umich.edu * dynamic_cast<> to cast to the state appropriate for the 2682662Sstever@eecs.umich.edu * system's coherence protocol. */ 2692662Sstever@eecs.umich.edu CoherenceState *coherence; 2702641Sstever@eecs.umich.edu 2712662Sstever@eecs.umich.edu /** A virtual base opaque structure used to hold state associated 2722662Sstever@eecs.umich.edu * with the packet but specific to the sending device (e.g., an 2732662Sstever@eecs.umich.edu * MSHR). A pointer to this state is returned in the packet's 2742662Sstever@eecs.umich.edu * response so that the sender can quickly look up the state 2752662Sstever@eecs.umich.edu * needed to process it. A specific subclass would be derived 2762662Sstever@eecs.umich.edu * from this to carry state specific to a particular sending 2772662Sstever@eecs.umich.edu * device. */ 2784610Ssaidi@eecs.umich.edu class SenderState : public FastAlloc { 2792641Sstever@eecs.umich.edu public: 2802641Sstever@eecs.umich.edu virtual ~SenderState() {} 2812641Sstever@eecs.umich.edu }; 2822641Sstever@eecs.umich.edu 2832662Sstever@eecs.umich.edu /** This packet's sender state. Devices should use dynamic_cast<> 2842662Sstever@eecs.umich.edu * to cast to the state appropriate to the sender. */ 2852662Sstever@eecs.umich.edu SenderState *senderState; 2862641Sstever@eecs.umich.edu 2874022Sstever@eecs.umich.edu public: 2882641Sstever@eecs.umich.edu 2894022Sstever@eecs.umich.edu /** The command field of the packet. */ 2904022Sstever@eecs.umich.edu MemCmd cmd; 2912641Sstever@eecs.umich.edu 2922662Sstever@eecs.umich.edu /** Return the string name of the cmd field (for debugging and 2932662Sstever@eecs.umich.edu * tracing). */ 2944022Sstever@eecs.umich.edu const std::string &cmdString() const { return cmd.toString(); } 2952811Srdreslin@umich.edu 2962811Srdreslin@umich.edu /** Return the index of this command. */ 2974022Sstever@eecs.umich.edu inline int cmdToIndex() const { return cmd.toInt(); } 2982811Srdreslin@umich.edu 2994022Sstever@eecs.umich.edu public: 3002381SN/A 3014022Sstever@eecs.umich.edu bool isRead() const { return cmd.isRead(); } 3024022Sstever@eecs.umich.edu bool isWrite() const { return cmd.isWrite(); } 3034022Sstever@eecs.umich.edu bool isRequest() const { return cmd.isRequest(); } 3044022Sstever@eecs.umich.edu bool isResponse() const { return cmd.isResponse(); } 3054022Sstever@eecs.umich.edu bool needsResponse() const { return cmd.needsResponse(); } 3064022Sstever@eecs.umich.edu bool isInvalidate() const { return cmd.isInvalidate(); } 3074022Sstever@eecs.umich.edu bool hasData() const { return cmd.hasData(); } 3084040Ssaidi@eecs.umich.edu bool isReadWrite() const { return cmd.isReadWrite(); } 3092812Srdreslin@umich.edu 3103260Ssaidi@eecs.umich.edu bool isCacheFill() const { return (flags & CACHE_LINE_FILL) != 0; } 3113260Ssaidi@eecs.umich.edu bool isNoAllocate() const { return (flags & NO_ALLOCATE) != 0; } 3123260Ssaidi@eecs.umich.edu bool isCompressed() const { return (flags & COMPRESSED) != 0; } 3132814Srdreslin@umich.edu 3143940Ssaidi@eecs.umich.edu bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN } 3152641Sstever@eecs.umich.edu 3162662Sstever@eecs.umich.edu /** Possible results of a packet's request. */ 3172641Sstever@eecs.umich.edu enum Result 3182641Sstever@eecs.umich.edu { 3192641Sstever@eecs.umich.edu Success, 3202641Sstever@eecs.umich.edu BadAddress, 3212685Ssaidi@eecs.umich.edu Nacked, 3222641Sstever@eecs.umich.edu Unknown 3232641Sstever@eecs.umich.edu }; 3242641Sstever@eecs.umich.edu 3252662Sstever@eecs.umich.edu /** The result of this packet's request. */ 3262641Sstever@eecs.umich.edu Result result; 3272381SN/A 3282381SN/A /** Accessor function that returns the source index of the packet. */ 3292641Sstever@eecs.umich.edu short getSrc() const { assert(srcValid); return src; } 3302641Sstever@eecs.umich.edu void setSrc(short _src) { src = _src; srcValid = true; } 3312381SN/A 3322381SN/A /** Accessor function that returns the destination index of 3332381SN/A the packet. */ 3342381SN/A short getDest() const { return dest; } 3352641Sstever@eecs.umich.edu void setDest(short _dest) { dest = _dest; } 3362549SN/A 3372663Sstever@eecs.umich.edu Addr getAddr() const { assert(addrSizeValid); return addr; } 3382663Sstever@eecs.umich.edu int getSize() const { assert(addrSizeValid); return size; } 3392883Srdreslin@umich.edu Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 3402813Srdreslin@umich.edu 3412813Srdreslin@umich.edu void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; } 3424022Sstever@eecs.umich.edu void cmdOverride(MemCmd newCmd) { cmd = newCmd; } 3432641Sstever@eecs.umich.edu 3442662Sstever@eecs.umich.edu /** Constructor. Note that a Request object must be constructed 3452662Sstever@eecs.umich.edu * first, but the Requests's physical address and size fields 3462662Sstever@eecs.umich.edu * need not be valid. The command and destination addresses 3472662Sstever@eecs.umich.edu * must be supplied. */ 3484022Sstever@eecs.umich.edu Packet(Request *_req, MemCmd _cmd, short _dest) 3492566SN/A : data(NULL), staticData(false), dynamicData(false), arrayData(false), 3502641Sstever@eecs.umich.edu addr(_req->paddr), size(_req->size), dest(_dest), 3512663Sstever@eecs.umich.edu addrSizeValid(_req->validPaddr), 3522814Srdreslin@umich.edu srcValid(false), 3532641Sstever@eecs.umich.edu req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 3542662Sstever@eecs.umich.edu result(Unknown) 3552641Sstever@eecs.umich.edu { 3562813Srdreslin@umich.edu flags = 0; 3573018Srdreslin@umich.edu time = curTick; 3582813Srdreslin@umich.edu } 3592813Srdreslin@umich.edu 3602813Srdreslin@umich.edu /** Alternate constructor if you are trying to create a packet with 3612813Srdreslin@umich.edu * a request that is for a whole block, not the address from the req. 3622813Srdreslin@umich.edu * this allows for overriding the size/addr of the req.*/ 3634022Sstever@eecs.umich.edu Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize) 3642813Srdreslin@umich.edu : data(NULL), staticData(false), dynamicData(false), arrayData(false), 3652813Srdreslin@umich.edu addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), 3662814Srdreslin@umich.edu dest(_dest), 3672814Srdreslin@umich.edu addrSizeValid(_req->validPaddr), srcValid(false), 3682813Srdreslin@umich.edu req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 3692813Srdreslin@umich.edu result(Unknown) 3702813Srdreslin@umich.edu { 3712813Srdreslin@umich.edu flags = 0; 3723018Srdreslin@umich.edu time = curTick; 3732641Sstever@eecs.umich.edu } 3742549SN/A 3752662Sstever@eecs.umich.edu /** Destructor. */ 3762566SN/A ~Packet() 3773665Srdreslin@umich.edu { if (staticData || dynamicData) deleteData(); } 3782566SN/A 3792662Sstever@eecs.umich.edu /** Reinitialize packet address and size from the associated 3802662Sstever@eecs.umich.edu * Request object, and reset other fields that may have been 3812662Sstever@eecs.umich.edu * modified by a previous transaction. Typically called when a 3822662Sstever@eecs.umich.edu * statically allocated Request/Packet pair is reused for 3832662Sstever@eecs.umich.edu * multiple transactions. */ 3842662Sstever@eecs.umich.edu void reinitFromRequest() { 3852662Sstever@eecs.umich.edu assert(req->validPaddr); 3863369Sstever@eecs.umich.edu flags = 0; 3872663Sstever@eecs.umich.edu addr = req->paddr; 3882663Sstever@eecs.umich.edu size = req->size; 3893018Srdreslin@umich.edu time = req->time; 3902663Sstever@eecs.umich.edu addrSizeValid = true; 3912662Sstever@eecs.umich.edu result = Unknown; 3922662Sstever@eecs.umich.edu if (dynamicData) { 3932662Sstever@eecs.umich.edu deleteData(); 3942662Sstever@eecs.umich.edu dynamicData = false; 3952662Sstever@eecs.umich.edu arrayData = false; 3962662Sstever@eecs.umich.edu } 3972662Sstever@eecs.umich.edu } 3982566SN/A 3992662Sstever@eecs.umich.edu /** Take a request packet and modify it in place to be suitable 4002662Sstever@eecs.umich.edu * for returning as a response to that request. Used for timing 4012662Sstever@eecs.umich.edu * accesses only. For atomic and functional accesses, the 4022662Sstever@eecs.umich.edu * request packet is always implicitly passed back *without* 4033135Srdreslin@umich.edu * modifying the destination fields, so this function 4042662Sstever@eecs.umich.edu * should not be called. */ 4052662Sstever@eecs.umich.edu void makeTimingResponse() { 4062662Sstever@eecs.umich.edu assert(needsResponse()); 4072855Srdreslin@umich.edu assert(isRequest()); 4084022Sstever@eecs.umich.edu cmd = cmd.responseCommand(); 4092662Sstever@eecs.umich.edu dest = src; 4102662Sstever@eecs.umich.edu srcValid = false; 4112641Sstever@eecs.umich.edu } 4122641Sstever@eecs.umich.edu 4133348Sbinkertn@umich.edu /** 4143348Sbinkertn@umich.edu * Take a request packet and modify it in place to be suitable for 4153348Sbinkertn@umich.edu * returning as a response to that request. 4163135Srdreslin@umich.edu */ 4173348Sbinkertn@umich.edu void makeAtomicResponse() 4183348Sbinkertn@umich.edu { 4193135Srdreslin@umich.edu assert(needsResponse()); 4203135Srdreslin@umich.edu assert(isRequest()); 4214022Sstever@eecs.umich.edu cmd = cmd.responseCommand(); 4223135Srdreslin@umich.edu } 4233135Srdreslin@umich.edu 4243348Sbinkertn@umich.edu /** 4253348Sbinkertn@umich.edu * Take a request packet that has been returned as NACKED and 4263348Sbinkertn@umich.edu * modify it so that it can be sent out again. Only packets that 4273348Sbinkertn@umich.edu * need a response can be NACKED, so verify that that is true. 4283348Sbinkertn@umich.edu */ 4293348Sbinkertn@umich.edu void 4303348Sbinkertn@umich.edu reinitNacked() 4313348Sbinkertn@umich.edu { 4322685Ssaidi@eecs.umich.edu assert(needsResponse() && result == Nacked); 4332685Ssaidi@eecs.umich.edu dest = Broadcast; 4342685Ssaidi@eecs.umich.edu result = Unknown; 4352685Ssaidi@eecs.umich.edu } 4362685Ssaidi@eecs.umich.edu 4372685Ssaidi@eecs.umich.edu 4383348Sbinkertn@umich.edu /** 4393348Sbinkertn@umich.edu * Set the data pointer to the following value that should not be 4403348Sbinkertn@umich.edu * freed. 4412566SN/A */ 4422566SN/A template <typename T> 4433348Sbinkertn@umich.edu void 4443348Sbinkertn@umich.edu dataStatic(T *p) 4453348Sbinkertn@umich.edu { 4463348Sbinkertn@umich.edu if(dynamicData) 4473348Sbinkertn@umich.edu dynamicData = false; 4483348Sbinkertn@umich.edu data = (PacketDataPtr)p; 4493348Sbinkertn@umich.edu staticData = true; 4503348Sbinkertn@umich.edu } 4512566SN/A 4523348Sbinkertn@umich.edu /** 4533348Sbinkertn@umich.edu * Set the data pointer to a value that should have delete [] 4543348Sbinkertn@umich.edu * called on it. 4553348Sbinkertn@umich.edu */ 4562566SN/A template <typename T> 4573348Sbinkertn@umich.edu void 4583348Sbinkertn@umich.edu dataDynamicArray(T *p) 4593348Sbinkertn@umich.edu { 4603348Sbinkertn@umich.edu assert(!staticData && !dynamicData); 4613348Sbinkertn@umich.edu data = (PacketDataPtr)p; 4623348Sbinkertn@umich.edu dynamicData = true; 4633348Sbinkertn@umich.edu arrayData = true; 4643348Sbinkertn@umich.edu } 4653348Sbinkertn@umich.edu 4663348Sbinkertn@umich.edu /** 4673348Sbinkertn@umich.edu * set the data pointer to a value that should have delete called 4683348Sbinkertn@umich.edu * on it. 4693348Sbinkertn@umich.edu */ 4703348Sbinkertn@umich.edu template <typename T> 4713348Sbinkertn@umich.edu void 4723348Sbinkertn@umich.edu dataDynamic(T *p) 4733348Sbinkertn@umich.edu { 4743348Sbinkertn@umich.edu assert(!staticData && !dynamicData); 4753348Sbinkertn@umich.edu data = (PacketDataPtr)p; 4763348Sbinkertn@umich.edu dynamicData = true; 4773348Sbinkertn@umich.edu arrayData = false; 4783348Sbinkertn@umich.edu } 4793348Sbinkertn@umich.edu 4803348Sbinkertn@umich.edu /** get a pointer to the data ptr. */ 4813348Sbinkertn@umich.edu template <typename T> 4823348Sbinkertn@umich.edu T* 4833348Sbinkertn@umich.edu getPtr() 4843348Sbinkertn@umich.edu { 4853348Sbinkertn@umich.edu assert(staticData || dynamicData); 4863348Sbinkertn@umich.edu return (T*)data; 4873348Sbinkertn@umich.edu } 4882566SN/A 4892566SN/A /** return the value of what is pointed to in the packet. */ 4902566SN/A template <typename T> 4912592SN/A T get(); 4922566SN/A 4932566SN/A /** set the value in the data pointer to v. */ 4942566SN/A template <typename T> 4952592SN/A void set(T v); 4962566SN/A 4973348Sbinkertn@umich.edu /** 4983348Sbinkertn@umich.edu * delete the data pointed to in the data pointer. Ok to call to 4993348Sbinkertn@umich.edu * matter how data was allocted. 5003348Sbinkertn@umich.edu */ 5012592SN/A void deleteData(); 5022566SN/A 5032566SN/A /** If there isn't data in the packet, allocate some. */ 5042592SN/A void allocate(); 5052568SN/A 5062568SN/A /** Do the packet modify the same addresses. */ 5073349Sbinkertn@umich.edu bool intersect(PacketPtr p); 5082381SN/A}; 5092381SN/A 5104489Sstever@eecs.umich.edu/** This function given a functional packet and a timing packet either 5114489Sstever@eecs.umich.edu * satisfies the timing packet, or updates the timing packet to 5124489Sstever@eecs.umich.edu * reflect the updated state in the timing packet. It returns if the 5134489Sstever@eecs.umich.edu * functional packet should continue to traverse the memory hierarchy 5144489Sstever@eecs.umich.edu * or not. 5153260Ssaidi@eecs.umich.edu */ 5163349Sbinkertn@umich.edubool fixPacket(PacketPtr func, PacketPtr timing); 5173260Ssaidi@eecs.umich.edu 5184489Sstever@eecs.umich.edu/** This function is a wrapper for the fixPacket field that toggles 5194489Sstever@eecs.umich.edu * the hasData bit it is used when a response is waiting in the 5204489Sstever@eecs.umich.edu * caches, but hasn't been marked as a response yet (so the fixPacket 5214489Sstever@eecs.umich.edu * needs to get the correct value for the hasData) 5223607Srdreslin@umich.edu */ 5233607Srdreslin@umich.edubool fixDelayedResponsePacket(PacketPtr func, PacketPtr timing); 5243607Srdreslin@umich.edu 5253260Ssaidi@eecs.umich.edustd::ostream & operator<<(std::ostream &o, const Packet &p); 5263260Ssaidi@eecs.umich.edu 5272381SN/A#endif //__MEM_PACKET_HH 528