packet.hh revision 4024
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> 433348Sbinkertn@umich.edu 444024Sbinkertn@umich.edu#include "base/compiler.hh" 453940Ssaidi@eecs.umich.edu#include "base/misc.hh" 462392SN/A#include "mem/request.hh" 472980Sgblack@eecs.umich.edu#include "sim/host.hh" 482394SN/A#include "sim/root.hh" 492394SN/A 503940Ssaidi@eecs.umich.edu 512394SN/Astruct Packet; 523349Sbinkertn@umich.edutypedef Packet *PacketPtr; 532394SN/Atypedef uint8_t* PacketDataPtr; 542812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList; 552812Srdreslin@umich.edu 562812Srdreslin@umich.edu//Coherence Flags 573366Sstever@eecs.umich.edu#define NACKED_LINE (1 << 0) 583366Sstever@eecs.umich.edu#define SATISFIED (1 << 1) 593366Sstever@eecs.umich.edu#define SHARED_LINE (1 << 2) 603366Sstever@eecs.umich.edu#define CACHE_LINE_FILL (1 << 3) 613366Sstever@eecs.umich.edu#define COMPRESSED (1 << 4) 623366Sstever@eecs.umich.edu#define NO_ALLOCATE (1 << 5) 633366Sstever@eecs.umich.edu#define SNOOP_COMMIT (1 << 6) 642382SN/A 653208Srdreslin@umich.edu//for now. @todo fix later 663366Sstever@eecs.umich.edu#define NUM_MEM_CMDS (1 << 11) 672381SN/A/** 682662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in 692662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache). (In contrast, a 702662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the 712662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several 722662Sstever@eecs.umich.edu * different Packets along the way.) 732381SN/A */ 742641Sstever@eecs.umich.educlass Packet 752381SN/A{ 762813Srdreslin@umich.edu public: 772813Srdreslin@umich.edu /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */ 782813Srdreslin@umich.edu uint64_t flags; 792813Srdreslin@umich.edu 802566SN/A private: 812662Sstever@eecs.umich.edu /** A pointer to the data being transfered. It can be differnt 822662Sstever@eecs.umich.edu * sizes at each level of the heirarchy so it belongs in the 832662Sstever@eecs.umich.edu * packet, not request. This may or may not be populated when a 842662Sstever@eecs.umich.edu * responder recieves the packet. If not populated it memory 852662Sstever@eecs.umich.edu * should be allocated. 862566SN/A */ 872566SN/A PacketDataPtr data; 882566SN/A 892662Sstever@eecs.umich.edu /** Is the data pointer set to a value that shouldn't be freed 902662Sstever@eecs.umich.edu * when the packet is destroyed? */ 912566SN/A bool staticData; 922662Sstever@eecs.umich.edu /** The data pointer points to a value that should be freed when 932662Sstever@eecs.umich.edu * the packet is destroyed. */ 942566SN/A bool dynamicData; 952662Sstever@eecs.umich.edu /** the data pointer points to an array (thus delete [] ) needs to 962662Sstever@eecs.umich.edu * be called on it rather than simply delete.*/ 972566SN/A bool arrayData; 982566SN/A 992662Sstever@eecs.umich.edu /** The address of the request. This address could be virtual or 1002662Sstever@eecs.umich.edu * physical, depending on the system configuration. */ 1012381SN/A Addr addr; 1022381SN/A 1032662Sstever@eecs.umich.edu /** The size of the request or transfer. */ 1042381SN/A int size; 1052381SN/A 1062662Sstever@eecs.umich.edu /** Device address (e.g., bus ID) of the source of the 1072662Sstever@eecs.umich.edu * transaction. The source is not responsible for setting this 1082662Sstever@eecs.umich.edu * field; it is set implicitly by the interconnect when the 1093349Sbinkertn@umich.edu * packet is first sent. */ 1102381SN/A short src; 1112381SN/A 1122662Sstever@eecs.umich.edu /** Device address (e.g., bus ID) of the destination of the 1132662Sstever@eecs.umich.edu * transaction. The special value Broadcast indicates that the 1142662Sstever@eecs.umich.edu * packet should be routed based on its address. This field is 1152662Sstever@eecs.umich.edu * initialized in the constructor and is thus always valid 1162662Sstever@eecs.umich.edu * (unlike * addr, size, and src). */ 1172641Sstever@eecs.umich.edu short dest; 1182641Sstever@eecs.umich.edu 1192663Sstever@eecs.umich.edu /** Are the 'addr' and 'size' fields valid? */ 1202663Sstever@eecs.umich.edu bool addrSizeValid; 1212662Sstever@eecs.umich.edu /** Is the 'src' field valid? */ 1222641Sstever@eecs.umich.edu bool srcValid; 1232813Srdreslin@umich.edu 1242641Sstever@eecs.umich.edu 1252641Sstever@eecs.umich.edu public: 1262641Sstever@eecs.umich.edu 1272811Srdreslin@umich.edu /** Used to calculate latencies for each packet.*/ 1282811Srdreslin@umich.edu Tick time; 1292811Srdreslin@umich.edu 1303218Sgblack@eecs.umich.edu /** The time at which the packet will be fully transmitted */ 1313218Sgblack@eecs.umich.edu Tick finishTime; 1323218Sgblack@eecs.umich.edu 1333218Sgblack@eecs.umich.edu /** The time at which the first chunk of the packet will be transmitted */ 1343218Sgblack@eecs.umich.edu Tick firstWordTime; 1353218Sgblack@eecs.umich.edu 1362662Sstever@eecs.umich.edu /** The special destination address indicating that the packet 1372662Sstever@eecs.umich.edu * should be routed based on its address. */ 1382623SN/A static const short Broadcast = -1; 1392623SN/A 1402662Sstever@eecs.umich.edu /** A pointer to the original request. */ 1412641Sstever@eecs.umich.edu RequestPtr req; 1422641Sstever@eecs.umich.edu 1432662Sstever@eecs.umich.edu /** A virtual base opaque structure used to hold coherence-related 1442662Sstever@eecs.umich.edu * state. A specific subclass would be derived from this to 1452662Sstever@eecs.umich.edu * carry state specific to a particular coherence protocol. */ 1462641Sstever@eecs.umich.edu class CoherenceState { 1472641Sstever@eecs.umich.edu public: 1482641Sstever@eecs.umich.edu virtual ~CoherenceState() {} 1492641Sstever@eecs.umich.edu }; 1502641Sstever@eecs.umich.edu 1512662Sstever@eecs.umich.edu /** This packet's coherence state. Caches should use 1522662Sstever@eecs.umich.edu * dynamic_cast<> to cast to the state appropriate for the 1532662Sstever@eecs.umich.edu * system's coherence protocol. */ 1542662Sstever@eecs.umich.edu CoherenceState *coherence; 1552641Sstever@eecs.umich.edu 1562662Sstever@eecs.umich.edu /** A virtual base opaque structure used to hold state associated 1572662Sstever@eecs.umich.edu * with the packet but specific to the sending device (e.g., an 1582662Sstever@eecs.umich.edu * MSHR). A pointer to this state is returned in the packet's 1592662Sstever@eecs.umich.edu * response so that the sender can quickly look up the state 1602662Sstever@eecs.umich.edu * needed to process it. A specific subclass would be derived 1612662Sstever@eecs.umich.edu * from this to carry state specific to a particular sending 1622662Sstever@eecs.umich.edu * device. */ 1632641Sstever@eecs.umich.edu class SenderState { 1642641Sstever@eecs.umich.edu public: 1652641Sstever@eecs.umich.edu virtual ~SenderState() {} 1662641Sstever@eecs.umich.edu }; 1672641Sstever@eecs.umich.edu 1682662Sstever@eecs.umich.edu /** This packet's sender state. Devices should use dynamic_cast<> 1692662Sstever@eecs.umich.edu * to cast to the state appropriate to the sender. */ 1702662Sstever@eecs.umich.edu SenderState *senderState; 1712641Sstever@eecs.umich.edu 1722641Sstever@eecs.umich.edu private: 1732641Sstever@eecs.umich.edu /** List of command attributes. */ 1743158Sgblack@eecs.umich.edu // If you add a new CommandAttribute, make sure to increase NUM_MEM_CMDS 1753158Sgblack@eecs.umich.edu // as well. 1762641Sstever@eecs.umich.edu enum CommandAttribute 1772641Sstever@eecs.umich.edu { 1783366Sstever@eecs.umich.edu IsRead = 1 << 0, 1793366Sstever@eecs.umich.edu IsWrite = 1 << 1, 1803366Sstever@eecs.umich.edu IsPrefetch = 1 << 2, 1813366Sstever@eecs.umich.edu IsInvalidate = 1 << 3, 1823366Sstever@eecs.umich.edu IsRequest = 1 << 4, 1833366Sstever@eecs.umich.edu IsResponse = 1 << 5, 1843366Sstever@eecs.umich.edu NeedsResponse = 1 << 6, 1852811Srdreslin@umich.edu IsSWPrefetch = 1 << 7, 1863156Sgblack@eecs.umich.edu IsHWPrefetch = 1 << 8, 1873214Srdreslin@umich.edu IsUpgrade = 1 << 9, 1883366Sstever@eecs.umich.edu HasData = 1 << 10 1892641Sstever@eecs.umich.edu }; 1902641Sstever@eecs.umich.edu 1912641Sstever@eecs.umich.edu public: 1922641Sstever@eecs.umich.edu /** List of all commands associated with a packet. */ 1932641Sstever@eecs.umich.edu enum Command 1942641Sstever@eecs.umich.edu { 1952813Srdreslin@umich.edu InvalidCmd = 0, 1963366Sstever@eecs.umich.edu ReadReq = IsRead | IsRequest | NeedsResponse, 1973260Ssaidi@eecs.umich.edu WriteReq = IsWrite | IsRequest | NeedsResponse | HasData, 1983366Sstever@eecs.umich.edu WriteReqNoAck = IsWrite | IsRequest | HasData, 1993260Ssaidi@eecs.umich.edu ReadResp = IsRead | IsResponse | NeedsResponse | HasData, 2003366Sstever@eecs.umich.edu WriteResp = IsWrite | IsResponse | NeedsResponse, 2013158Sgblack@eecs.umich.edu Writeback = IsWrite | IsRequest | HasData, 2022811Srdreslin@umich.edu SoftPFReq = IsRead | IsRequest | IsSWPrefetch | NeedsResponse, 2032811Srdreslin@umich.edu HardPFReq = IsRead | IsRequest | IsHWPrefetch | NeedsResponse, 2043156Sgblack@eecs.umich.edu SoftPFResp = IsRead | IsResponse | IsSWPrefetch 2053366Sstever@eecs.umich.edu | NeedsResponse | HasData, 2063156Sgblack@eecs.umich.edu HardPFResp = IsRead | IsResponse | IsHWPrefetch 2073366Sstever@eecs.umich.edu | NeedsResponse | HasData, 2082812Srdreslin@umich.edu InvalidateReq = IsInvalidate | IsRequest, 2093366Sstever@eecs.umich.edu WriteInvalidateReq = IsWrite | IsInvalidate | IsRequest 2103366Sstever@eecs.umich.edu | HasData | NeedsResponse, 2113366Sstever@eecs.umich.edu WriteInvalidateResp = IsWrite | IsInvalidate | IsRequest 2123366Sstever@eecs.umich.edu | NeedsResponse | IsResponse, 2133207Srdreslin@umich.edu UpgradeReq = IsInvalidate | IsRequest | IsUpgrade, 2142855Srdreslin@umich.edu ReadExReq = IsRead | IsInvalidate | IsRequest | NeedsResponse, 2153156Sgblack@eecs.umich.edu ReadExResp = IsRead | IsInvalidate | IsResponse 2163366Sstever@eecs.umich.edu | NeedsResponse | HasData 2172641Sstever@eecs.umich.edu }; 2182641Sstever@eecs.umich.edu 2192662Sstever@eecs.umich.edu /** Return the string name of the cmd field (for debugging and 2202662Sstever@eecs.umich.edu * tracing). */ 2212641Sstever@eecs.umich.edu const std::string &cmdString() const; 2222381SN/A 2232811Srdreslin@umich.edu /** Reutrn the string to a cmd given by idx. */ 2242811Srdreslin@umich.edu const std::string &cmdIdxToString(Command idx); 2252811Srdreslin@umich.edu 2262811Srdreslin@umich.edu /** Return the index of this command. */ 2272811Srdreslin@umich.edu inline int cmdToIndex() const { return (int) cmd; } 2282811Srdreslin@umich.edu 2292662Sstever@eecs.umich.edu /** The command field of the packet. */ 2302381SN/A Command cmd; 2312381SN/A 2323260Ssaidi@eecs.umich.edu bool isRead() const { return (cmd & IsRead) != 0; } 2333260Ssaidi@eecs.umich.edu bool isWrite() const { return (cmd & IsWrite) != 0; } 2343260Ssaidi@eecs.umich.edu bool isRequest() const { return (cmd & IsRequest) != 0; } 2353260Ssaidi@eecs.umich.edu bool isResponse() const { return (cmd & IsResponse) != 0; } 2363260Ssaidi@eecs.umich.edu bool needsResponse() const { return (cmd & NeedsResponse) != 0; } 2373260Ssaidi@eecs.umich.edu bool isInvalidate() const { return (cmd & IsInvalidate) != 0; } 2383260Ssaidi@eecs.umich.edu bool hasData() const { return (cmd & HasData) != 0; } 2392812Srdreslin@umich.edu 2403260Ssaidi@eecs.umich.edu bool isCacheFill() const { return (flags & CACHE_LINE_FILL) != 0; } 2413260Ssaidi@eecs.umich.edu bool isNoAllocate() const { return (flags & NO_ALLOCATE) != 0; } 2423260Ssaidi@eecs.umich.edu bool isCompressed() const { return (flags & COMPRESSED) != 0; } 2432814Srdreslin@umich.edu 2443940Ssaidi@eecs.umich.edu bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN } 2452641Sstever@eecs.umich.edu 2462662Sstever@eecs.umich.edu /** Possible results of a packet's request. */ 2472641Sstever@eecs.umich.edu enum Result 2482641Sstever@eecs.umich.edu { 2492641Sstever@eecs.umich.edu Success, 2502641Sstever@eecs.umich.edu BadAddress, 2512685Ssaidi@eecs.umich.edu Nacked, 2522641Sstever@eecs.umich.edu Unknown 2532641Sstever@eecs.umich.edu }; 2542641Sstever@eecs.umich.edu 2552662Sstever@eecs.umich.edu /** The result of this packet's request. */ 2562641Sstever@eecs.umich.edu Result result; 2572381SN/A 2582381SN/A /** Accessor function that returns the source index of the packet. */ 2592641Sstever@eecs.umich.edu short getSrc() const { assert(srcValid); return src; } 2602641Sstever@eecs.umich.edu void setSrc(short _src) { src = _src; srcValid = true; } 2612381SN/A 2622381SN/A /** Accessor function that returns the destination index of 2632381SN/A the packet. */ 2642381SN/A short getDest() const { return dest; } 2652641Sstever@eecs.umich.edu void setDest(short _dest) { dest = _dest; } 2662549SN/A 2672663Sstever@eecs.umich.edu Addr getAddr() const { assert(addrSizeValid); return addr; } 2682663Sstever@eecs.umich.edu int getSize() const { assert(addrSizeValid); return size; } 2692883Srdreslin@umich.edu Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 2702813Srdreslin@umich.edu 2712813Srdreslin@umich.edu void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; } 2722813Srdreslin@umich.edu void cmdOverride(Command newCmd) { cmd = newCmd; } 2732641Sstever@eecs.umich.edu 2742662Sstever@eecs.umich.edu /** Constructor. Note that a Request object must be constructed 2752662Sstever@eecs.umich.edu * first, but the Requests's physical address and size fields 2762662Sstever@eecs.umich.edu * need not be valid. The command and destination addresses 2772662Sstever@eecs.umich.edu * must be supplied. */ 2782641Sstever@eecs.umich.edu Packet(Request *_req, Command _cmd, short _dest) 2792566SN/A : data(NULL), staticData(false), dynamicData(false), arrayData(false), 2802641Sstever@eecs.umich.edu addr(_req->paddr), size(_req->size), dest(_dest), 2812663Sstever@eecs.umich.edu addrSizeValid(_req->validPaddr), 2822814Srdreslin@umich.edu srcValid(false), 2832641Sstever@eecs.umich.edu req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 2842662Sstever@eecs.umich.edu result(Unknown) 2852641Sstever@eecs.umich.edu { 2862813Srdreslin@umich.edu flags = 0; 2873018Srdreslin@umich.edu time = curTick; 2882813Srdreslin@umich.edu } 2892813Srdreslin@umich.edu 2902813Srdreslin@umich.edu /** Alternate constructor if you are trying to create a packet with 2912813Srdreslin@umich.edu * a request that is for a whole block, not the address from the req. 2922813Srdreslin@umich.edu * this allows for overriding the size/addr of the req.*/ 2932813Srdreslin@umich.edu Packet(Request *_req, Command _cmd, short _dest, int _blkSize) 2942813Srdreslin@umich.edu : data(NULL), staticData(false), dynamicData(false), arrayData(false), 2952813Srdreslin@umich.edu addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), 2962814Srdreslin@umich.edu dest(_dest), 2972814Srdreslin@umich.edu addrSizeValid(_req->validPaddr), srcValid(false), 2982813Srdreslin@umich.edu req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 2992813Srdreslin@umich.edu result(Unknown) 3002813Srdreslin@umich.edu { 3012813Srdreslin@umich.edu flags = 0; 3023018Srdreslin@umich.edu time = curTick; 3032641Sstever@eecs.umich.edu } 3042549SN/A 3052662Sstever@eecs.umich.edu /** Destructor. */ 3062566SN/A ~Packet() 3073665Srdreslin@umich.edu { if (staticData || dynamicData) deleteData(); } 3082566SN/A 3092662Sstever@eecs.umich.edu /** Reinitialize packet address and size from the associated 3102662Sstever@eecs.umich.edu * Request object, and reset other fields that may have been 3112662Sstever@eecs.umich.edu * modified by a previous transaction. Typically called when a 3122662Sstever@eecs.umich.edu * statically allocated Request/Packet pair is reused for 3132662Sstever@eecs.umich.edu * multiple transactions. */ 3142662Sstever@eecs.umich.edu void reinitFromRequest() { 3152662Sstever@eecs.umich.edu assert(req->validPaddr); 3163369Sstever@eecs.umich.edu flags = 0; 3172663Sstever@eecs.umich.edu addr = req->paddr; 3182663Sstever@eecs.umich.edu size = req->size; 3193018Srdreslin@umich.edu time = req->time; 3202663Sstever@eecs.umich.edu addrSizeValid = true; 3212662Sstever@eecs.umich.edu result = Unknown; 3222662Sstever@eecs.umich.edu if (dynamicData) { 3232662Sstever@eecs.umich.edu deleteData(); 3242662Sstever@eecs.umich.edu dynamicData = false; 3252662Sstever@eecs.umich.edu arrayData = false; 3262662Sstever@eecs.umich.edu } 3272662Sstever@eecs.umich.edu } 3282566SN/A 3292662Sstever@eecs.umich.edu /** Take a request packet and modify it in place to be suitable 3302662Sstever@eecs.umich.edu * for returning as a response to that request. Used for timing 3312662Sstever@eecs.umich.edu * accesses only. For atomic and functional accesses, the 3322662Sstever@eecs.umich.edu * request packet is always implicitly passed back *without* 3333135Srdreslin@umich.edu * modifying the destination fields, so this function 3342662Sstever@eecs.umich.edu * should not be called. */ 3352662Sstever@eecs.umich.edu void makeTimingResponse() { 3362662Sstever@eecs.umich.edu assert(needsResponse()); 3372855Srdreslin@umich.edu assert(isRequest()); 3382662Sstever@eecs.umich.edu int icmd = (int)cmd; 3392855Srdreslin@umich.edu icmd &= ~(IsRequest); 3402662Sstever@eecs.umich.edu icmd |= IsResponse; 3413216Srdreslin@umich.edu if (isRead()) 3423216Srdreslin@umich.edu icmd |= HasData; 3433217Srdreslin@umich.edu if (isWrite()) 3443217Srdreslin@umich.edu icmd &= ~HasData; 3452662Sstever@eecs.umich.edu cmd = (Command)icmd; 3462662Sstever@eecs.umich.edu dest = src; 3472662Sstever@eecs.umich.edu srcValid = false; 3482641Sstever@eecs.umich.edu } 3492641Sstever@eecs.umich.edu 3503607Srdreslin@umich.edu 3513607Srdreslin@umich.edu void toggleData() { 3523607Srdreslin@umich.edu int icmd = (int)cmd; 3533607Srdreslin@umich.edu icmd ^= HasData; 3543607Srdreslin@umich.edu cmd = (Command)icmd; 3553607Srdreslin@umich.edu } 3563607Srdreslin@umich.edu 3573348Sbinkertn@umich.edu /** 3583348Sbinkertn@umich.edu * Take a request packet and modify it in place to be suitable for 3593348Sbinkertn@umich.edu * returning as a response to that request. 3603135Srdreslin@umich.edu */ 3613348Sbinkertn@umich.edu void makeAtomicResponse() 3623348Sbinkertn@umich.edu { 3633135Srdreslin@umich.edu assert(needsResponse()); 3643135Srdreslin@umich.edu assert(isRequest()); 3653135Srdreslin@umich.edu int icmd = (int)cmd; 3663135Srdreslin@umich.edu icmd &= ~(IsRequest); 3673135Srdreslin@umich.edu icmd |= IsResponse; 3683261Srdreslin@umich.edu if (isRead()) 3693261Srdreslin@umich.edu icmd |= HasData; 3703261Srdreslin@umich.edu if (isWrite()) 3713261Srdreslin@umich.edu icmd &= ~HasData; 3723135Srdreslin@umich.edu cmd = (Command)icmd; 3733135Srdreslin@umich.edu } 3743135Srdreslin@umich.edu 3753348Sbinkertn@umich.edu /** 3763348Sbinkertn@umich.edu * Take a request packet that has been returned as NACKED and 3773348Sbinkertn@umich.edu * modify it so that it can be sent out again. Only packets that 3783348Sbinkertn@umich.edu * need a response can be NACKED, so verify that that is true. 3793348Sbinkertn@umich.edu */ 3803348Sbinkertn@umich.edu void 3813348Sbinkertn@umich.edu reinitNacked() 3823348Sbinkertn@umich.edu { 3832685Ssaidi@eecs.umich.edu assert(needsResponse() && result == Nacked); 3842685Ssaidi@eecs.umich.edu dest = Broadcast; 3852685Ssaidi@eecs.umich.edu result = Unknown; 3862685Ssaidi@eecs.umich.edu } 3872685Ssaidi@eecs.umich.edu 3882685Ssaidi@eecs.umich.edu 3893348Sbinkertn@umich.edu /** 3903348Sbinkertn@umich.edu * Set the data pointer to the following value that should not be 3913348Sbinkertn@umich.edu * freed. 3922566SN/A */ 3932566SN/A template <typename T> 3943348Sbinkertn@umich.edu void 3953348Sbinkertn@umich.edu dataStatic(T *p) 3963348Sbinkertn@umich.edu { 3973348Sbinkertn@umich.edu if(dynamicData) 3983348Sbinkertn@umich.edu dynamicData = false; 3993348Sbinkertn@umich.edu data = (PacketDataPtr)p; 4003348Sbinkertn@umich.edu staticData = true; 4013348Sbinkertn@umich.edu } 4022566SN/A 4033348Sbinkertn@umich.edu /** 4043348Sbinkertn@umich.edu * Set the data pointer to a value that should have delete [] 4053348Sbinkertn@umich.edu * called on it. 4063348Sbinkertn@umich.edu */ 4072566SN/A template <typename T> 4083348Sbinkertn@umich.edu void 4093348Sbinkertn@umich.edu dataDynamicArray(T *p) 4103348Sbinkertn@umich.edu { 4113348Sbinkertn@umich.edu assert(!staticData && !dynamicData); 4123348Sbinkertn@umich.edu data = (PacketDataPtr)p; 4133348Sbinkertn@umich.edu dynamicData = true; 4143348Sbinkertn@umich.edu arrayData = true; 4153348Sbinkertn@umich.edu } 4163348Sbinkertn@umich.edu 4173348Sbinkertn@umich.edu /** 4183348Sbinkertn@umich.edu * set the data pointer to a value that should have delete called 4193348Sbinkertn@umich.edu * on it. 4203348Sbinkertn@umich.edu */ 4213348Sbinkertn@umich.edu template <typename T> 4223348Sbinkertn@umich.edu void 4233348Sbinkertn@umich.edu dataDynamic(T *p) 4243348Sbinkertn@umich.edu { 4253348Sbinkertn@umich.edu assert(!staticData && !dynamicData); 4263348Sbinkertn@umich.edu data = (PacketDataPtr)p; 4273348Sbinkertn@umich.edu dynamicData = true; 4283348Sbinkertn@umich.edu arrayData = false; 4293348Sbinkertn@umich.edu } 4303348Sbinkertn@umich.edu 4313348Sbinkertn@umich.edu /** get a pointer to the data ptr. */ 4323348Sbinkertn@umich.edu template <typename T> 4333348Sbinkertn@umich.edu T* 4343348Sbinkertn@umich.edu getPtr() 4353348Sbinkertn@umich.edu { 4363348Sbinkertn@umich.edu assert(staticData || dynamicData); 4373348Sbinkertn@umich.edu return (T*)data; 4383348Sbinkertn@umich.edu } 4392566SN/A 4402566SN/A /** return the value of what is pointed to in the packet. */ 4412566SN/A template <typename T> 4422592SN/A T get(); 4432566SN/A 4442566SN/A /** set the value in the data pointer to v. */ 4452566SN/A template <typename T> 4462592SN/A void set(T v); 4472566SN/A 4483348Sbinkertn@umich.edu /** 4493348Sbinkertn@umich.edu * delete the data pointed to in the data pointer. Ok to call to 4503348Sbinkertn@umich.edu * matter how data was allocted. 4513348Sbinkertn@umich.edu */ 4522592SN/A void deleteData(); 4532566SN/A 4542566SN/A /** If there isn't data in the packet, allocate some. */ 4552592SN/A void allocate(); 4562568SN/A 4572568SN/A /** Do the packet modify the same addresses. */ 4583349Sbinkertn@umich.edu bool intersect(PacketPtr p); 4592381SN/A}; 4602381SN/A 4613260Ssaidi@eecs.umich.edu/** This function given a functional packet and a timing packet either satisfies 4623260Ssaidi@eecs.umich.edu * the timing packet, or updates the timing packet to reflect the updated state 4633260Ssaidi@eecs.umich.edu * in the timing packet. It returns if the functional packet should continue to 4643260Ssaidi@eecs.umich.edu * traverse the memory hierarchy or not. 4653260Ssaidi@eecs.umich.edu */ 4663349Sbinkertn@umich.edubool fixPacket(PacketPtr func, PacketPtr timing); 4673260Ssaidi@eecs.umich.edu 4683607Srdreslin@umich.edu/** This function is a wrapper for the fixPacket field that toggles the hasData bit 4693607Srdreslin@umich.edu * it is used when a response is waiting in the caches, but hasn't been marked as a 4703607Srdreslin@umich.edu * response yet (so the fixPacket needs to get the correct value for the hasData) 4713607Srdreslin@umich.edu */ 4723607Srdreslin@umich.edubool fixDelayedResponsePacket(PacketPtr func, PacketPtr timing); 4733607Srdreslin@umich.edu 4743260Ssaidi@eecs.umich.edustd::ostream & operator<<(std::ostream &o, const Packet &p); 4753260Ssaidi@eecs.umich.edu 4762381SN/A#endif //__MEM_PACKET_HH 477