packet.hh revision 10938
12381SN/A/* 210694SMarco.Balboni@ARM.com * Copyright (c) 2012-2015 ARM Limited 38949Sandreas.hansson@arm.com * All rights reserved 48949Sandreas.hansson@arm.com * 58949Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68949Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78949Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88949Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98949Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108949Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118949Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128949Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138949Sandreas.hansson@arm.com * 142592SN/A * Copyright (c) 2006 The Regents of The University of Michigan 157636Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc. 162381SN/A * All rights reserved. 172381SN/A * 182381SN/A * Redistribution and use in source and binary forms, with or without 192381SN/A * modification, are permitted provided that the following conditions are 202381SN/A * met: redistributions of source code must retain the above copyright 212381SN/A * notice, this list of conditions and the following disclaimer; 222381SN/A * redistributions in binary form must reproduce the above copyright 232381SN/A * notice, this list of conditions and the following disclaimer in the 242381SN/A * documentation and/or other materials provided with the distribution; 252381SN/A * neither the name of the copyright holders nor the names of its 262381SN/A * contributors may be used to endorse or promote products derived from 272381SN/A * this software without specific prior written permission. 282381SN/A * 292381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu * 412665Ssaidi@eecs.umich.edu * Authors: Ron Dreslinski 422665Ssaidi@eecs.umich.edu * Steve Reinhardt 432665Ssaidi@eecs.umich.edu * Ali Saidi 449031Sandreas.hansson@arm.com * Andreas Hansson 452381SN/A */ 462381SN/A 472381SN/A/** 482381SN/A * @file 492662Sstever@eecs.umich.edu * Declaration of the Packet class. 502381SN/A */ 512381SN/A 522381SN/A#ifndef __MEM_PACKET_HH__ 532381SN/A#define __MEM_PACKET_HH__ 542381SN/A 558229Snate@binkert.org#include <bitset> 563348Sbinkertn@umich.edu#include <cassert> 573348Sbinkertn@umich.edu#include <list> 583348Sbinkertn@umich.edu 595735Snate@binkert.org#include "base/cast.hh" 604024Sbinkertn@umich.edu#include "base/compiler.hh" 615735Snate@binkert.org#include "base/flags.hh" 623940Ssaidi@eecs.umich.edu#include "base/misc.hh" 635314Sstever@gmail.com#include "base/printable.hh" 646216Snate@binkert.org#include "base/types.hh" 652392SN/A#include "mem/request.hh" 664167Sbinkertn@umich.edu#include "sim/core.hh" 672394SN/A 688737Skoansin.tan@gmail.comclass Packet; 693349Sbinkertn@umich.edutypedef Packet *PacketPtr; 702394SN/Atypedef uint8_t* PacketDataPtr; 712812Srdreslin@umich.edutypedef std::list<PacketPtr> PacketList; 722812Srdreslin@umich.edu 734022Sstever@eecs.umich.educlass MemCmd 744022Sstever@eecs.umich.edu{ 755735Snate@binkert.org friend class Packet; 765735Snate@binkert.org 774022Sstever@eecs.umich.edu public: 785735Snate@binkert.org /** 795735Snate@binkert.org * List of all commands associated with a packet. 805735Snate@binkert.org */ 814022Sstever@eecs.umich.edu enum Command 824022Sstever@eecs.umich.edu { 834022Sstever@eecs.umich.edu InvalidCmd, 844022Sstever@eecs.umich.edu ReadReq, 854473Sstever@eecs.umich.edu ReadResp, 865319Sstever@gmail.com ReadRespWithInvalidate, 874022Sstever@eecs.umich.edu WriteReq, 884022Sstever@eecs.umich.edu WriteResp, 894022Sstever@eecs.umich.edu Writeback, 9010883Sali.jafri@arm.com CleanEvict, 914022Sstever@eecs.umich.edu SoftPFReq, 924022Sstever@eecs.umich.edu HardPFReq, 934022Sstever@eecs.umich.edu SoftPFResp, 944022Sstever@eecs.umich.edu HardPFResp, 9510886Sandreas.hansson@arm.com WriteLineReq, 964022Sstever@eecs.umich.edu UpgradeReq, 977465Ssteve.reinhardt@amd.com SCUpgradeReq, // Special "weak" upgrade for StoreCond 984628Sstever@eecs.umich.edu UpgradeResp, 997465Ssteve.reinhardt@amd.com SCUpgradeFailReq, // Failed SCUpgradeReq in MSHR (never sent) 1007465Ssteve.reinhardt@amd.com UpgradeFailResp, // Valid for SCUpgradeReq only 1014022Sstever@eecs.umich.edu ReadExReq, 1024022Sstever@eecs.umich.edu ReadExResp, 10310885Sandreas.hansson@arm.com ReadCleanReq, 10410885Sandreas.hansson@arm.com ReadSharedReq, 1054626Sstever@eecs.umich.edu LoadLockedReq, 1064626Sstever@eecs.umich.edu StoreCondReq, 1077669Ssteve.reinhardt@amd.com StoreCondFailReq, // Failed StoreCondReq in MSHR (never sent) 1084626Sstever@eecs.umich.edu StoreCondResp, 1094040Ssaidi@eecs.umich.edu SwapReq, 1104040Ssaidi@eecs.umich.edu SwapResp, 1115650Sgblack@eecs.umich.edu MessageReq, 1125650Sgblack@eecs.umich.edu MessageResp, 1134870Sstever@eecs.umich.edu // Error responses 1144870Sstever@eecs.umich.edu // @TODO these should be classified as responses rather than 1154870Sstever@eecs.umich.edu // requests; coding them as requests initially for backwards 1164870Sstever@eecs.umich.edu // compatibility 1174870Sstever@eecs.umich.edu InvalidDestError, // packet dest field invalid 1184870Sstever@eecs.umich.edu BadAddressError, // memory address invalid 1198436SBrad.Beckmann@amd.com FunctionalReadError, // unable to fulfill functional read 1208436SBrad.Beckmann@amd.com FunctionalWriteError, // unable to fulfill functional write 1215314Sstever@gmail.com // Fake simulator-only commands 1225314Sstever@gmail.com PrintReq, // Print state matching address 1238184Ssomayeh@cs.wisc.edu FlushReq, //request for a cache flush 12410886Sandreas.hansson@arm.com InvalidateReq, // request for address to be invalidated 12510886Sandreas.hansson@arm.com InvalidateResp, 1264022Sstever@eecs.umich.edu NUM_MEM_CMDS 1274022Sstever@eecs.umich.edu }; 1284022Sstever@eecs.umich.edu 1294022Sstever@eecs.umich.edu private: 1305735Snate@binkert.org /** 1315735Snate@binkert.org * List of command attributes. 1325735Snate@binkert.org */ 1334022Sstever@eecs.umich.edu enum Attribute 1344022Sstever@eecs.umich.edu { 1354626Sstever@eecs.umich.edu IsRead, //!< Data flows from responder to requester 1364626Sstever@eecs.umich.edu IsWrite, //!< Data flows from requester to responder 1377465Ssteve.reinhardt@amd.com IsUpgrade, 1384022Sstever@eecs.umich.edu IsInvalidate, 1394626Sstever@eecs.umich.edu NeedsExclusive, //!< Requires exclusive copy to complete in-cache 1404626Sstever@eecs.umich.edu IsRequest, //!< Issued by requester 1414626Sstever@eecs.umich.edu IsResponse, //!< Issue by responder 1424626Sstever@eecs.umich.edu NeedsResponse, //!< Requester needs response from target 1434022Sstever@eecs.umich.edu IsSWPrefetch, 1444022Sstever@eecs.umich.edu IsHWPrefetch, 1456076Sgblack@eecs.umich.edu IsLlsc, //!< Alpha/MIPS LL or SC access 1464626Sstever@eecs.umich.edu HasData, //!< There is an associated payload 1474870Sstever@eecs.umich.edu IsError, //!< Error response 1485314Sstever@gmail.com IsPrint, //!< Print state matching address (for debugging) 1498184Ssomayeh@cs.wisc.edu IsFlush, //!< Flush the address from caches 1504022Sstever@eecs.umich.edu NUM_COMMAND_ATTRIBUTES 1514022Sstever@eecs.umich.edu }; 1524022Sstever@eecs.umich.edu 1535735Snate@binkert.org /** 1545735Snate@binkert.org * Structure that defines attributes and other data associated 1555735Snate@binkert.org * with a Command. 1565735Snate@binkert.org */ 1575735Snate@binkert.org struct CommandInfo 1585735Snate@binkert.org { 1595735Snate@binkert.org /// Set of attribute flags. 1604022Sstever@eecs.umich.edu const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes; 1615735Snate@binkert.org /// Corresponding response for requests; InvalidCmd if no 1625735Snate@binkert.org /// response is applicable. 1634022Sstever@eecs.umich.edu const Command response; 1645735Snate@binkert.org /// String representation (for printing) 1654022Sstever@eecs.umich.edu const std::string str; 1664022Sstever@eecs.umich.edu }; 1674022Sstever@eecs.umich.edu 1685735Snate@binkert.org /// Array to map Command enum to associated info. 1694022Sstever@eecs.umich.edu static const CommandInfo commandInfo[]; 1704022Sstever@eecs.umich.edu 1714022Sstever@eecs.umich.edu private: 1724022Sstever@eecs.umich.edu 1734022Sstever@eecs.umich.edu Command cmd; 1744022Sstever@eecs.umich.edu 1755735Snate@binkert.org bool 1765735Snate@binkert.org testCmdAttrib(MemCmd::Attribute attrib) const 1775735Snate@binkert.org { 1784022Sstever@eecs.umich.edu return commandInfo[cmd].attributes[attrib] != 0; 1794022Sstever@eecs.umich.edu } 1804022Sstever@eecs.umich.edu 1814022Sstever@eecs.umich.edu public: 1824022Sstever@eecs.umich.edu 18310583SCurtis.Dunham@arm.com bool isRead() const { return testCmdAttrib(IsRead); } 18410583SCurtis.Dunham@arm.com bool isWrite() const { return testCmdAttrib(IsWrite); } 18510583SCurtis.Dunham@arm.com bool isUpgrade() const { return testCmdAttrib(IsUpgrade); } 18610583SCurtis.Dunham@arm.com bool isRequest() const { return testCmdAttrib(IsRequest); } 18710583SCurtis.Dunham@arm.com bool isResponse() const { return testCmdAttrib(IsResponse); } 18810583SCurtis.Dunham@arm.com bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); } 18910583SCurtis.Dunham@arm.com bool needsResponse() const { return testCmdAttrib(NeedsResponse); } 19010583SCurtis.Dunham@arm.com bool isInvalidate() const { return testCmdAttrib(IsInvalidate); } 19110570Sandreas.hansson@arm.com 19210570Sandreas.hansson@arm.com /** 19310570Sandreas.hansson@arm.com * Check if this particular packet type carries payload data. Note 19410570Sandreas.hansson@arm.com * that this does not reflect if the data pointer of the packet is 19510570Sandreas.hansson@arm.com * valid or not. 19610570Sandreas.hansson@arm.com */ 1974022Sstever@eecs.umich.edu bool hasData() const { return testCmdAttrib(HasData); } 1986102Sgblack@eecs.umich.edu bool isLLSC() const { return testCmdAttrib(IsLlsc); } 19910343SCurtis.Dunham@arm.com bool isSWPrefetch() const { return testCmdAttrib(IsSWPrefetch); } 20010343SCurtis.Dunham@arm.com bool isHWPrefetch() const { return testCmdAttrib(IsHWPrefetch); } 20110343SCurtis.Dunham@arm.com bool isPrefetch() const { return testCmdAttrib(IsSWPrefetch) || 20210343SCurtis.Dunham@arm.com testCmdAttrib(IsHWPrefetch); } 2034870Sstever@eecs.umich.edu bool isError() const { return testCmdAttrib(IsError); } 2045314Sstever@gmail.com bool isPrint() const { return testCmdAttrib(IsPrint); } 2058184Ssomayeh@cs.wisc.edu bool isFlush() const { return testCmdAttrib(IsFlush); } 2064022Sstever@eecs.umich.edu 2075735Snate@binkert.org const Command 2085735Snate@binkert.org responseCommand() const 2095735Snate@binkert.org { 2104022Sstever@eecs.umich.edu return commandInfo[cmd].response; 2114022Sstever@eecs.umich.edu } 2124022Sstever@eecs.umich.edu 2135735Snate@binkert.org /// Return the string to a cmd given by idx. 2145735Snate@binkert.org const std::string &toString() const { return commandInfo[cmd].str; } 2154022Sstever@eecs.umich.edu int toInt() const { return (int)cmd; } 2164022Sstever@eecs.umich.edu 2175735Snate@binkert.org MemCmd(Command _cmd) : cmd(_cmd) { } 2185735Snate@binkert.org MemCmd(int _cmd) : cmd((Command)_cmd) { } 2195735Snate@binkert.org MemCmd() : cmd(InvalidCmd) { } 2204022Sstever@eecs.umich.edu 2215735Snate@binkert.org bool operator==(MemCmd c2) const { return (cmd == c2.cmd); } 2225735Snate@binkert.org bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); } 2234022Sstever@eecs.umich.edu}; 2244022Sstever@eecs.umich.edu 2252381SN/A/** 2262662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in 2272662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache). (In contrast, a 2282662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the 2292662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several 2302662Sstever@eecs.umich.edu * different Packets along the way.) 2312381SN/A */ 2329044SAli.Saidi@ARM.comclass Packet : public Printable 2332381SN/A{ 2342813Srdreslin@umich.edu public: 2355735Snate@binkert.org typedef uint32_t FlagsType; 2365735Snate@binkert.org typedef ::Flags<FlagsType> Flags; 2374022Sstever@eecs.umich.edu 2385735Snate@binkert.org private: 2395735Snate@binkert.org 24010938Sandreas.hansson@arm.com enum : FlagsType { 24110938Sandreas.hansson@arm.com // Flags to transfer across when copying a packet 24210938Sandreas.hansson@arm.com COPY_FLAGS = 0x0000000F, 24310938Sandreas.hansson@arm.com 24410938Sandreas.hansson@arm.com SHARED = 0x00000001, 24510938Sandreas.hansson@arm.com // Special control flags 24610938Sandreas.hansson@arm.com /// Special timing-mode atomic snoop for multi-level coherence. 24710938Sandreas.hansson@arm.com EXPRESS_SNOOP = 0x00000002, 24810938Sandreas.hansson@arm.com /// Does supplier have exclusive copy? 24910938Sandreas.hansson@arm.com /// Useful for multi-level coherence. 25010938Sandreas.hansson@arm.com SUPPLY_EXCLUSIVE = 0x00000004, 25110938Sandreas.hansson@arm.com // Snoop response flags 25210938Sandreas.hansson@arm.com MEM_INHIBIT = 0x00000008, 25310938Sandreas.hansson@arm.com 25410938Sandreas.hansson@arm.com /// Are the 'addr' and 'size' fields valid? 25510938Sandreas.hansson@arm.com VALID_ADDR = 0x00000100, 25610938Sandreas.hansson@arm.com VALID_SIZE = 0x00000200, 25710938Sandreas.hansson@arm.com 25810938Sandreas.hansson@arm.com /// Is the data pointer set to a value that shouldn't be freed 25910938Sandreas.hansson@arm.com /// when the packet is destroyed? 26010938Sandreas.hansson@arm.com STATIC_DATA = 0x00001000, 26110938Sandreas.hansson@arm.com /// The data pointer points to a value that should be freed when 26210938Sandreas.hansson@arm.com /// the packet is destroyed. The pointer is assumed to be pointing 26310938Sandreas.hansson@arm.com /// to an array, and delete [] is consequently called 26410938Sandreas.hansson@arm.com DYNAMIC_DATA = 0x00002000, 26510938Sandreas.hansson@arm.com 26610938Sandreas.hansson@arm.com /// suppress the error if this packet encounters a functional 26710938Sandreas.hansson@arm.com /// access failure. 26810938Sandreas.hansson@arm.com SUPPRESS_FUNC_ERROR = 0x00008000, 26910938Sandreas.hansson@arm.com 27010938Sandreas.hansson@arm.com // Signal block present to squash prefetch and cache evict packets 27110938Sandreas.hansson@arm.com // through express snoop flag 27210938Sandreas.hansson@arm.com BLOCK_CACHED = 0x00010000 27310938Sandreas.hansson@arm.com }; 2745735Snate@binkert.org 2755735Snate@binkert.org Flags flags; 2765735Snate@binkert.org 2775735Snate@binkert.org public: 2784022Sstever@eecs.umich.edu typedef MemCmd::Command Command; 2794022Sstever@eecs.umich.edu 2805735Snate@binkert.org /// The command field of the packet. 2814870Sstever@eecs.umich.edu MemCmd cmd; 2824870Sstever@eecs.umich.edu 2835735Snate@binkert.org /// A pointer to the original request. 28410569Sandreas.hansson@arm.com const RequestPtr req; 2854870Sstever@eecs.umich.edu 2862566SN/A private: 2875735Snate@binkert.org /** 2885735Snate@binkert.org * A pointer to the data being transfered. It can be differnt 2895735Snate@binkert.org * sizes at each level of the heirarchy so it belongs in the 2905735Snate@binkert.org * packet, not request. This may or may not be populated when a 2915735Snate@binkert.org * responder recieves the packet. If not populated it memory should 2925735Snate@binkert.org * be allocated. 2932566SN/A */ 2942566SN/A PacketDataPtr data; 2952566SN/A 2965735Snate@binkert.org /// The address of the request. This address could be virtual or 2975735Snate@binkert.org /// physical, depending on the system configuration. 2982381SN/A Addr addr; 2992381SN/A 30010028SGiacomo.Gabrielli@arm.com /// True if the request targets the secure memory space. 30110028SGiacomo.Gabrielli@arm.com bool _isSecure; 30210028SGiacomo.Gabrielli@arm.com 3035735Snate@binkert.org /// The size of the request or transfer. 3046227Snate@binkert.org unsigned size; 3052381SN/A 3065735Snate@binkert.org /** 30710723Sandreas.hansson@arm.com * Track the bytes found that satisfy a functional read. 3088668Sgeoffrey.blake@arm.com */ 30910723Sandreas.hansson@arm.com std::vector<bool> bytesValid; 3108668Sgeoffrey.blake@arm.com 3112641Sstever@eecs.umich.edu public: 3122811Srdreslin@umich.edu 3139547Sandreas.hansson@arm.com /** 31410694SMarco.Balboni@ARM.com * The extra delay from seeing the packet until the header is 31510405Sandreas.hansson@arm.com * transmitted. This delay is used to communicate the crossbar 31610405Sandreas.hansson@arm.com * forwarding latency to the neighbouring object (e.g. a cache) 31710405Sandreas.hansson@arm.com * that actually makes the packet wait. As the delay is relative, 31810405Sandreas.hansson@arm.com * a 32-bit unsigned should be sufficient. 3199547Sandreas.hansson@arm.com */ 32010694SMarco.Balboni@ARM.com uint32_t headerDelay; 3213218Sgblack@eecs.umich.edu 3229547Sandreas.hansson@arm.com /** 32310694SMarco.Balboni@ARM.com * The extra pipelining delay from seeing the packet until the end of 32410694SMarco.Balboni@ARM.com * payload is transmitted by the component that provided it (if 32510694SMarco.Balboni@ARM.com * any). This includes the header delay. Similar to the header 32610694SMarco.Balboni@ARM.com * delay, this is used to make up for the fact that the 32710405Sandreas.hansson@arm.com * crossbar does not make the packet wait. As the delay is 32810405Sandreas.hansson@arm.com * relative, a 32-bit unsigned should be sufficient. 3299547Sandreas.hansson@arm.com */ 33010694SMarco.Balboni@ARM.com uint32_t payloadDelay; 3313218Sgblack@eecs.umich.edu 3325735Snate@binkert.org /** 3335735Snate@binkert.org * A virtual base opaque structure used to hold state associated 3349542Sandreas.hansson@arm.com * with the packet (e.g., an MSHR), specific to a MemObject that 3359542Sandreas.hansson@arm.com * sees the packet. A pointer to this state is returned in the 3369542Sandreas.hansson@arm.com * packet's response so that the MemObject in question can quickly 3379542Sandreas.hansson@arm.com * look up the state needed to process it. A specific subclass 3389542Sandreas.hansson@arm.com * would be derived from this to carry state specific to a 3399542Sandreas.hansson@arm.com * particular sending device. 3409542Sandreas.hansson@arm.com * 3419542Sandreas.hansson@arm.com * As multiple MemObjects may add their SenderState throughout the 3429542Sandreas.hansson@arm.com * memory system, the SenderStates create a stack, where a 3439542Sandreas.hansson@arm.com * MemObject can add a new Senderstate, as long as the 3449542Sandreas.hansson@arm.com * predecessing SenderState is restored when the response comes 3459542Sandreas.hansson@arm.com * back. For this reason, the predecessor should always be 3469542Sandreas.hansson@arm.com * populated with the current SenderState of a packet before 3479542Sandreas.hansson@arm.com * modifying the senderState field in the request packet. 3485735Snate@binkert.org */ 3495735Snate@binkert.org struct SenderState 3505735Snate@binkert.org { 3519542Sandreas.hansson@arm.com SenderState* predecessor; 3529542Sandreas.hansson@arm.com SenderState() : predecessor(NULL) {} 3532641Sstever@eecs.umich.edu virtual ~SenderState() {} 3542641Sstever@eecs.umich.edu }; 3552641Sstever@eecs.umich.edu 3565315Sstever@gmail.com /** 3575315Sstever@gmail.com * Object used to maintain state of a PrintReq. The senderState 3585315Sstever@gmail.com * field of a PrintReq should always be of this type. 3595315Sstever@gmail.com */ 3609044SAli.Saidi@ARM.com class PrintReqState : public SenderState 3615735Snate@binkert.org { 3625735Snate@binkert.org private: 3635735Snate@binkert.org /** 3645735Snate@binkert.org * An entry in the label stack. 3655735Snate@binkert.org */ 3665735Snate@binkert.org struct LabelStackEntry 3675735Snate@binkert.org { 3685314Sstever@gmail.com const std::string label; 3695314Sstever@gmail.com std::string *prefix; 3705314Sstever@gmail.com bool labelPrinted; 3715735Snate@binkert.org LabelStackEntry(const std::string &_label, std::string *_prefix); 3725314Sstever@gmail.com }; 3735314Sstever@gmail.com 3745314Sstever@gmail.com typedef std::list<LabelStackEntry> LabelStack; 3755314Sstever@gmail.com LabelStack labelStack; 3765314Sstever@gmail.com 3775314Sstever@gmail.com std::string *curPrefixPtr; 3785314Sstever@gmail.com 3795314Sstever@gmail.com public: 3805314Sstever@gmail.com std::ostream &os; 3815314Sstever@gmail.com const int verbosity; 3825314Sstever@gmail.com 3835314Sstever@gmail.com PrintReqState(std::ostream &os, int verbosity = 0); 3845314Sstever@gmail.com ~PrintReqState(); 3855314Sstever@gmail.com 3865735Snate@binkert.org /** 3875735Snate@binkert.org * Returns the current line prefix. 3885735Snate@binkert.org */ 3895314Sstever@gmail.com const std::string &curPrefix() { return *curPrefixPtr; } 3905315Sstever@gmail.com 3915735Snate@binkert.org /** 3925735Snate@binkert.org * Push a label onto the label stack, and prepend the given 3935315Sstever@gmail.com * prefix string onto the current prefix. Labels will only be 3945735Snate@binkert.org * printed if an object within the label's scope is printed. 3955735Snate@binkert.org */ 3965314Sstever@gmail.com void pushLabel(const std::string &lbl, 3975314Sstever@gmail.com const std::string &prefix = " "); 3985735Snate@binkert.org 3995735Snate@binkert.org /** 4005735Snate@binkert.org * Pop a label off the label stack. 4015735Snate@binkert.org */ 4025314Sstever@gmail.com void popLabel(); 4035735Snate@binkert.org 4045735Snate@binkert.org /** 4055735Snate@binkert.org * Print all of the pending unprinted labels on the 4065315Sstever@gmail.com * stack. Called by printObj(), so normally not called by 4075735Snate@binkert.org * users unless bypassing printObj(). 4085735Snate@binkert.org */ 4095314Sstever@gmail.com void printLabels(); 4105735Snate@binkert.org 4115735Snate@binkert.org /** 4125735Snate@binkert.org * Print a Printable object to os, because it matched the 4135735Snate@binkert.org * address on a PrintReq. 4145735Snate@binkert.org */ 4155314Sstever@gmail.com void printObj(Printable *obj); 4165314Sstever@gmail.com }; 4175314Sstever@gmail.com 4185735Snate@binkert.org /** 4195735Snate@binkert.org * This packet's sender state. Devices should use dynamic_cast<> 4205735Snate@binkert.org * to cast to the state appropriate to the sender. The intent of 4215735Snate@binkert.org * this variable is to allow a device to attach extra information 4229542Sandreas.hansson@arm.com * to a request. A response packet must return the sender state 4235735Snate@binkert.org * that was attached to the original request (even if a new packet 4245735Snate@binkert.org * is created). 4255735Snate@binkert.org */ 4262662Sstever@eecs.umich.edu SenderState *senderState; 4272641Sstever@eecs.umich.edu 4289542Sandreas.hansson@arm.com /** 4299542Sandreas.hansson@arm.com * Push a new sender state to the packet and make the current 4309542Sandreas.hansson@arm.com * sender state the predecessor of the new one. This should be 4319542Sandreas.hansson@arm.com * prefered over direct manipulation of the senderState member 4329542Sandreas.hansson@arm.com * variable. 4339542Sandreas.hansson@arm.com * 4349542Sandreas.hansson@arm.com * @param sender_state SenderState to push at the top of the stack 4359542Sandreas.hansson@arm.com */ 4369542Sandreas.hansson@arm.com void pushSenderState(SenderState *sender_state); 4379542Sandreas.hansson@arm.com 4389542Sandreas.hansson@arm.com /** 4399542Sandreas.hansson@arm.com * Pop the top of the state stack and return a pointer to it. This 4409542Sandreas.hansson@arm.com * assumes the current sender state is not NULL. This should be 4419542Sandreas.hansson@arm.com * preferred over direct manipulation of the senderState member 4429542Sandreas.hansson@arm.com * variable. 4439542Sandreas.hansson@arm.com * 4449542Sandreas.hansson@arm.com * @return The current top of the stack 4459542Sandreas.hansson@arm.com */ 4469542Sandreas.hansson@arm.com SenderState *popSenderState(); 4479542Sandreas.hansson@arm.com 4489543Ssascha.bischoff@arm.com /** 4499543Ssascha.bischoff@arm.com * Go through the sender state stack and return the first instance 4509543Ssascha.bischoff@arm.com * that is of type T (as determined by a dynamic_cast). If there 4519543Ssascha.bischoff@arm.com * is no sender state of type T, NULL is returned. 4529543Ssascha.bischoff@arm.com * 4539543Ssascha.bischoff@arm.com * @return The topmost state of type T 4549543Ssascha.bischoff@arm.com */ 4559543Ssascha.bischoff@arm.com template <typename T> 4569543Ssascha.bischoff@arm.com T * findNextSenderState() const 4579543Ssascha.bischoff@arm.com { 4589543Ssascha.bischoff@arm.com T *t = NULL; 4599543Ssascha.bischoff@arm.com SenderState* sender_state = senderState; 4609543Ssascha.bischoff@arm.com while (t == NULL && sender_state != NULL) { 4619543Ssascha.bischoff@arm.com t = dynamic_cast<T*>(sender_state); 4629543Ssascha.bischoff@arm.com sender_state = sender_state->predecessor; 4639543Ssascha.bischoff@arm.com } 4649543Ssascha.bischoff@arm.com return t; 4659543Ssascha.bischoff@arm.com } 4669543Ssascha.bischoff@arm.com 4675735Snate@binkert.org /// Return the string name of the cmd field (for debugging and 4685735Snate@binkert.org /// tracing). 4694022Sstever@eecs.umich.edu const std::string &cmdString() const { return cmd.toString(); } 4702811Srdreslin@umich.edu 4715735Snate@binkert.org /// Return the index of this command. 4724022Sstever@eecs.umich.edu inline int cmdToIndex() const { return cmd.toInt(); } 4732811Srdreslin@umich.edu 47410583SCurtis.Dunham@arm.com bool isRead() const { return cmd.isRead(); } 47510583SCurtis.Dunham@arm.com bool isWrite() const { return cmd.isWrite(); } 47610583SCurtis.Dunham@arm.com bool isUpgrade() const { return cmd.isUpgrade(); } 47710583SCurtis.Dunham@arm.com bool isRequest() const { return cmd.isRequest(); } 47810583SCurtis.Dunham@arm.com bool isResponse() const { return cmd.isResponse(); } 47910583SCurtis.Dunham@arm.com bool needsExclusive() const { return cmd.needsExclusive(); } 48010583SCurtis.Dunham@arm.com bool needsResponse() const { return cmd.needsResponse(); } 48110583SCurtis.Dunham@arm.com bool isInvalidate() const { return cmd.isInvalidate(); } 48210583SCurtis.Dunham@arm.com bool hasData() const { return cmd.hasData(); } 48310583SCurtis.Dunham@arm.com bool isLLSC() const { return cmd.isLLSC(); } 48410583SCurtis.Dunham@arm.com bool isError() const { return cmd.isError(); } 48510583SCurtis.Dunham@arm.com bool isPrint() const { return cmd.isPrint(); } 48610583SCurtis.Dunham@arm.com bool isFlush() const { return cmd.isFlush(); } 4872812Srdreslin@umich.edu 4884870Sstever@eecs.umich.edu // Snoop flags 48910567Sandreas.hansson@arm.com void assertMemInhibit() 49010567Sandreas.hansson@arm.com { 49110567Sandreas.hansson@arm.com assert(isRequest()); 49210567Sandreas.hansson@arm.com assert(!flags.isSet(MEM_INHIBIT)); 49310567Sandreas.hansson@arm.com flags.set(MEM_INHIBIT); 49410567Sandreas.hansson@arm.com } 4959951Sstephan.diestelhorst@arm.com bool memInhibitAsserted() const { return flags.isSet(MEM_INHIBIT); } 4969951Sstephan.diestelhorst@arm.com void assertShared() { flags.set(SHARED); } 4979951Sstephan.diestelhorst@arm.com bool sharedAsserted() const { return flags.isSet(SHARED); } 4984870Sstever@eecs.umich.edu 4994895Sstever@eecs.umich.edu // Special control flags 5009951Sstephan.diestelhorst@arm.com void setExpressSnoop() { flags.set(EXPRESS_SNOOP); } 5019951Sstephan.diestelhorst@arm.com bool isExpressSnoop() const { return flags.isSet(EXPRESS_SNOOP); } 5029951Sstephan.diestelhorst@arm.com void setSupplyExclusive() { flags.set(SUPPLY_EXCLUSIVE); } 5039951Sstephan.diestelhorst@arm.com void clearSupplyExclusive() { flags.clear(SUPPLY_EXCLUSIVE); } 5049951Sstephan.diestelhorst@arm.com bool isSupplyExclusive() const { return flags.isSet(SUPPLY_EXCLUSIVE); } 5059951Sstephan.diestelhorst@arm.com void setSuppressFuncError() { flags.set(SUPPRESS_FUNC_ERROR); } 5069951Sstephan.diestelhorst@arm.com bool suppressFuncError() const { return flags.isSet(SUPPRESS_FUNC_ERROR); } 50710763Sali.jafri@arm.com void setBlockCached() { flags.set(BLOCK_CACHED); } 50810763Sali.jafri@arm.com bool isBlockCached() const { return flags.isSet(BLOCK_CACHED); } 50910883Sali.jafri@arm.com void clearBlockCached() { flags.clear(BLOCK_CACHED); } 5104895Sstever@eecs.umich.edu 5114870Sstever@eecs.umich.edu // Network error conditions... encapsulate them as methods since 5124870Sstever@eecs.umich.edu // their encoding keeps changing (from result field to command 5134870Sstever@eecs.umich.edu // field, etc.) 5145735Snate@binkert.org void 5155735Snate@binkert.org setBadAddress() 5165735Snate@binkert.org { 5175735Snate@binkert.org assert(isResponse()); 5185735Snate@binkert.org cmd = MemCmd::BadAddressError; 5195735Snate@binkert.org } 5205735Snate@binkert.org 5214986Ssaidi@eecs.umich.edu void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; } 5222814Srdreslin@umich.edu 5235764Snate@binkert.org Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; } 5249259SAli.Saidi@ARM.com /** 5259259SAli.Saidi@ARM.com * Update the address of this packet mid-transaction. This is used 5269259SAli.Saidi@ARM.com * by the address mapper to change an already set address to a new 5279259SAli.Saidi@ARM.com * one based on the system configuration. It is intended to remap 5289259SAli.Saidi@ARM.com * an existing address, so it asserts that the current address is 5299259SAli.Saidi@ARM.com * valid. 5309259SAli.Saidi@ARM.com */ 5319259SAli.Saidi@ARM.com void setAddr(Addr _addr) { assert(flags.isSet(VALID_ADDR)); addr = _addr; } 5329259SAli.Saidi@ARM.com 5336227Snate@binkert.org unsigned getSize() const { assert(flags.isSet(VALID_SIZE)); return size; } 53410938Sandreas.hansson@arm.com 53510938Sandreas.hansson@arm.com Addr getOffset(unsigned int blk_size) const 53610938Sandreas.hansson@arm.com { 53710938Sandreas.hansson@arm.com return getAddr() & Addr(blk_size - 1); 53810938Sandreas.hansson@arm.com } 53910938Sandreas.hansson@arm.com 54010938Sandreas.hansson@arm.com Addr getBlockAddr(unsigned int blk_size) const 54110938Sandreas.hansson@arm.com { 54210938Sandreas.hansson@arm.com return getAddr() & ~(Addr(blk_size - 1)); 54310938Sandreas.hansson@arm.com } 5442549SN/A 54510028SGiacomo.Gabrielli@arm.com bool isSecure() const 54610028SGiacomo.Gabrielli@arm.com { 54710028SGiacomo.Gabrielli@arm.com assert(flags.isSet(VALID_ADDR)); 54810028SGiacomo.Gabrielli@arm.com return _isSecure; 54910028SGiacomo.Gabrielli@arm.com } 55010028SGiacomo.Gabrielli@arm.com 5515735Snate@binkert.org /** 5527550SBrad.Beckmann@amd.com * It has been determined that the SC packet should successfully update 55310938Sandreas.hansson@arm.com * memory. Therefore, convert this SC packet to a normal write. 5547550SBrad.Beckmann@amd.com */ 5557550SBrad.Beckmann@amd.com void 5567550SBrad.Beckmann@amd.com convertScToWrite() 5577550SBrad.Beckmann@amd.com { 5587550SBrad.Beckmann@amd.com assert(isLLSC()); 5597550SBrad.Beckmann@amd.com assert(isWrite()); 5607550SBrad.Beckmann@amd.com cmd = MemCmd::WriteReq; 5617550SBrad.Beckmann@amd.com } 5627550SBrad.Beckmann@amd.com 5637550SBrad.Beckmann@amd.com /** 56410938Sandreas.hansson@arm.com * When ruby is in use, Ruby will monitor the cache line and the 56510938Sandreas.hansson@arm.com * phys memory should treat LL ops as normal reads. 5667550SBrad.Beckmann@amd.com */ 5677550SBrad.Beckmann@amd.com void 5687550SBrad.Beckmann@amd.com convertLlToRead() 5697550SBrad.Beckmann@amd.com { 5707550SBrad.Beckmann@amd.com assert(isLLSC()); 5717550SBrad.Beckmann@amd.com assert(isRead()); 5727550SBrad.Beckmann@amd.com cmd = MemCmd::ReadReq; 5737550SBrad.Beckmann@amd.com } 5747550SBrad.Beckmann@amd.com 5757550SBrad.Beckmann@amd.com /** 57610938Sandreas.hansson@arm.com * Constructor. Note that a Request object must be constructed 5775735Snate@binkert.org * first, but the Requests's physical address and size fields need 5789030Sandreas.hansson@arm.com * not be valid. The command must be supplied. 5795735Snate@binkert.org */ 58010569Sandreas.hansson@arm.com Packet(const RequestPtr _req, MemCmd _cmd) 58110360Sandreas.hansson@arm.com : cmd(_cmd), req(_req), data(nullptr), addr(0), _isSecure(false), 58210723Sandreas.hansson@arm.com size(0), headerDelay(0), payloadDelay(0), 5839546Sandreas.hansson@arm.com senderState(NULL) 5842641Sstever@eecs.umich.edu { 5856104Ssteve.reinhardt@amd.com if (req->hasPaddr()) { 5866104Ssteve.reinhardt@amd.com addr = req->getPaddr(); 5876104Ssteve.reinhardt@amd.com flags.set(VALID_ADDR); 58810028SGiacomo.Gabrielli@arm.com _isSecure = req->isSecure(); 5896104Ssteve.reinhardt@amd.com } 5906104Ssteve.reinhardt@amd.com if (req->hasSize()) { 5916104Ssteve.reinhardt@amd.com size = req->getSize(); 5926104Ssteve.reinhardt@amd.com flags.set(VALID_SIZE); 5936104Ssteve.reinhardt@amd.com } 5942813Srdreslin@umich.edu } 5952813Srdreslin@umich.edu 5965735Snate@binkert.org /** 5975735Snate@binkert.org * Alternate constructor if you are trying to create a packet with 5985735Snate@binkert.org * a request that is for a whole block, not the address from the 5995735Snate@binkert.org * req. this allows for overriding the size/addr of the req. 6005735Snate@binkert.org */ 60110569Sandreas.hansson@arm.com Packet(const RequestPtr _req, MemCmd _cmd, int _blkSize) 60210360Sandreas.hansson@arm.com : cmd(_cmd), req(_req), data(nullptr), addr(0), _isSecure(false), 60310694SMarco.Balboni@ARM.com headerDelay(0), payloadDelay(0), 6049546Sandreas.hansson@arm.com senderState(NULL) 6052813Srdreslin@umich.edu { 6066104Ssteve.reinhardt@amd.com if (req->hasPaddr()) { 6076104Ssteve.reinhardt@amd.com addr = req->getPaddr() & ~(_blkSize - 1); 6086104Ssteve.reinhardt@amd.com flags.set(VALID_ADDR); 60910028SGiacomo.Gabrielli@arm.com _isSecure = req->isSecure(); 6106104Ssteve.reinhardt@amd.com } 6116104Ssteve.reinhardt@amd.com size = _blkSize; 6126104Ssteve.reinhardt@amd.com flags.set(VALID_SIZE); 6134626Sstever@eecs.umich.edu } 6144626Sstever@eecs.umich.edu 6155735Snate@binkert.org /** 6165735Snate@binkert.org * Alternate constructor for copying a packet. Copy all fields 6174887Sstever@eecs.umich.edu * *except* if the original packet's data was dynamic, don't copy 6184887Sstever@eecs.umich.edu * that, as we can't guarantee that the new packet's lifetime is 6194887Sstever@eecs.umich.edu * less than that of the original packet. In this case the new 6205735Snate@binkert.org * packet should allocate its own data. 6215735Snate@binkert.org */ 62210896Snilay@cs.wisc.edu Packet(const PacketPtr pkt, bool clear_flags, bool alloc_data) 6235735Snate@binkert.org : cmd(pkt->cmd), req(pkt->req), 62410571Sandreas.hansson@arm.com data(nullptr), 62510028SGiacomo.Gabrielli@arm.com addr(pkt->addr), _isSecure(pkt->_isSecure), size(pkt->size), 62610723Sandreas.hansson@arm.com bytesValid(pkt->bytesValid), 62710694SMarco.Balboni@ARM.com headerDelay(pkt->headerDelay), 62810694SMarco.Balboni@ARM.com payloadDelay(pkt->payloadDelay), 6299546Sandreas.hansson@arm.com senderState(pkt->senderState) 6304626Sstever@eecs.umich.edu { 63110571Sandreas.hansson@arm.com if (!clear_flags) 6325735Snate@binkert.org flags.set(pkt->flags & COPY_FLAGS); 6335735Snate@binkert.org 6349031Sandreas.hansson@arm.com flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE)); 63510565Sandreas.hansson@arm.com 63610571Sandreas.hansson@arm.com // should we allocate space for data, or not, the express 63710571Sandreas.hansson@arm.com // snoops do not need to carry any data as they only serve to 63810571Sandreas.hansson@arm.com // co-ordinate state changes 63910571Sandreas.hansson@arm.com if (alloc_data) { 64010571Sandreas.hansson@arm.com // even if asked to allocate data, if the original packet 64110571Sandreas.hansson@arm.com // holds static data, then the sender will not be doing 64210571Sandreas.hansson@arm.com // any memcpy on receiving the response, thus we simply 64310571Sandreas.hansson@arm.com // carry the pointer forward 64410571Sandreas.hansson@arm.com if (pkt->flags.isSet(STATIC_DATA)) { 64510571Sandreas.hansson@arm.com data = pkt->data; 64610571Sandreas.hansson@arm.com flags.set(STATIC_DATA); 64710571Sandreas.hansson@arm.com } else { 64810571Sandreas.hansson@arm.com allocate(); 64910571Sandreas.hansson@arm.com } 65010571Sandreas.hansson@arm.com } 65110342SCurtis.Dunham@arm.com } 6528668Sgeoffrey.blake@arm.com 65310342SCurtis.Dunham@arm.com /** 65410739Ssteve.reinhardt@amd.com * Generate the appropriate read MemCmd based on the Request flags. 65510342SCurtis.Dunham@arm.com */ 65610739Ssteve.reinhardt@amd.com static MemCmd 65710739Ssteve.reinhardt@amd.com makeReadCmd(const RequestPtr req) 65810342SCurtis.Dunham@arm.com { 65910739Ssteve.reinhardt@amd.com if (req->isLLSC()) 66010739Ssteve.reinhardt@amd.com return MemCmd::LoadLockedReq; 66110739Ssteve.reinhardt@amd.com else if (req->isPrefetch()) 66210739Ssteve.reinhardt@amd.com return MemCmd::SoftPFReq; 66310739Ssteve.reinhardt@amd.com else 66410739Ssteve.reinhardt@amd.com return MemCmd::ReadReq; 66510739Ssteve.reinhardt@amd.com } 66610739Ssteve.reinhardt@amd.com 66710739Ssteve.reinhardt@amd.com /** 66810739Ssteve.reinhardt@amd.com * Generate the appropriate write MemCmd based on the Request flags. 66910739Ssteve.reinhardt@amd.com */ 67010739Ssteve.reinhardt@amd.com static MemCmd 67110739Ssteve.reinhardt@amd.com makeWriteCmd(const RequestPtr req) 67210739Ssteve.reinhardt@amd.com { 67310739Ssteve.reinhardt@amd.com if (req->isLLSC()) 67410739Ssteve.reinhardt@amd.com return MemCmd::StoreCondReq; 67510739Ssteve.reinhardt@amd.com else if (req->isSwap()) 67610739Ssteve.reinhardt@amd.com return MemCmd::SwapReq; 67710739Ssteve.reinhardt@amd.com else 67810739Ssteve.reinhardt@amd.com return MemCmd::WriteReq; 67910342SCurtis.Dunham@arm.com } 68010342SCurtis.Dunham@arm.com 68110342SCurtis.Dunham@arm.com /** 68210342SCurtis.Dunham@arm.com * Constructor-like methods that return Packets based on Request objects. 68310739Ssteve.reinhardt@amd.com * Fine-tune the MemCmd type if it's not a vanilla read or write. 68410342SCurtis.Dunham@arm.com */ 68510342SCurtis.Dunham@arm.com static PacketPtr 68610569Sandreas.hansson@arm.com createRead(const RequestPtr req) 68710342SCurtis.Dunham@arm.com { 68810739Ssteve.reinhardt@amd.com return new Packet(req, makeReadCmd(req)); 68910342SCurtis.Dunham@arm.com } 69010342SCurtis.Dunham@arm.com 69110342SCurtis.Dunham@arm.com static PacketPtr 69210569Sandreas.hansson@arm.com createWrite(const RequestPtr req) 69310342SCurtis.Dunham@arm.com { 69410739Ssteve.reinhardt@amd.com return new Packet(req, makeWriteCmd(req)); 6952641Sstever@eecs.umich.edu } 6962549SN/A 6975735Snate@binkert.org /** 6985735Snate@binkert.org * clean up packet variables 6995735Snate@binkert.org */ 7002566SN/A ~Packet() 7015387Sstever@gmail.com { 70210872Sali.jafri@arm.com // Delete the request object if this is a request packet which 70310872Sali.jafri@arm.com // does not need a response, because the requester will not get 70410872Sali.jafri@arm.com // a chance. If the request packet needs a response then the 70510872Sali.jafri@arm.com // request will be deleted on receipt of the response 70610872Sali.jafri@arm.com // packet. We also make sure to never delete the request for 70710872Sali.jafri@arm.com // express snoops, even for cases when responses are not 70810872Sali.jafri@arm.com // needed (CleanEvict and Writeback), since the snoop packet 70910872Sali.jafri@arm.com // re-uses the same request. 71010872Sali.jafri@arm.com if (req && isRequest() && !needsResponse() && 71110872Sali.jafri@arm.com !isExpressSnoop()) { 7125387Sstever@gmail.com delete req; 71310872Sali.jafri@arm.com } 7145735Snate@binkert.org deleteData(); 7155387Sstever@gmail.com } 7162566SN/A 7175735Snate@binkert.org /** 7184626Sstever@eecs.umich.edu * Take a request packet and modify it in place to be suitable for 71910660Sandreas.hansson@arm.com * returning as a response to that request. 7204626Sstever@eecs.umich.edu */ 7215735Snate@binkert.org void 7225735Snate@binkert.org makeResponse() 7234626Sstever@eecs.umich.edu { 7242662Sstever@eecs.umich.edu assert(needsResponse()); 7252855Srdreslin@umich.edu assert(isRequest()); 7264022Sstever@eecs.umich.edu cmd = cmd.responseCommand(); 7275745Snate@binkert.org 7287464Ssteve.reinhardt@amd.com // responses are never express, even if the snoop that 7297464Ssteve.reinhardt@amd.com // triggered them was 7307464Ssteve.reinhardt@amd.com flags.clear(EXPRESS_SNOOP); 7312641Sstever@eecs.umich.edu } 7322641Sstever@eecs.umich.edu 7335735Snate@binkert.org void 7345735Snate@binkert.org makeAtomicResponse() 7354870Sstever@eecs.umich.edu { 7364870Sstever@eecs.umich.edu makeResponse(); 7374870Sstever@eecs.umich.edu } 7384870Sstever@eecs.umich.edu 7395735Snate@binkert.org void 7405735Snate@binkert.org makeTimingResponse() 7413348Sbinkertn@umich.edu { 7424870Sstever@eecs.umich.edu makeResponse(); 7433135Srdreslin@umich.edu } 7443135Srdreslin@umich.edu 7458436SBrad.Beckmann@amd.com void 7468436SBrad.Beckmann@amd.com setFunctionalResponseStatus(bool success) 7478436SBrad.Beckmann@amd.com { 7488436SBrad.Beckmann@amd.com if (!success) { 7498436SBrad.Beckmann@amd.com if (isWrite()) { 7508436SBrad.Beckmann@amd.com cmd = MemCmd::FunctionalWriteError; 7518436SBrad.Beckmann@amd.com } else { 7528436SBrad.Beckmann@amd.com cmd = MemCmd::FunctionalReadError; 7538436SBrad.Beckmann@amd.com } 7548436SBrad.Beckmann@amd.com } 7558436SBrad.Beckmann@amd.com } 7568436SBrad.Beckmann@amd.com 7577006Snate@binkert.org void 7587006Snate@binkert.org setSize(unsigned size) 7597006Snate@binkert.org { 7607006Snate@binkert.org assert(!flags.isSet(VALID_SIZE)); 7617006Snate@binkert.org 7627006Snate@binkert.org this->size = size; 7637006Snate@binkert.org flags.set(VALID_SIZE); 7647006Snate@binkert.org } 7657006Snate@binkert.org 7662685Ssaidi@eecs.umich.edu 7673348Sbinkertn@umich.edu /** 7683348Sbinkertn@umich.edu * Set the data pointer to the following value that should not be 76910571Sandreas.hansson@arm.com * freed. Static data allows us to do a single memcpy even if 77010571Sandreas.hansson@arm.com * multiple packets are required to get from source to destination 77110571Sandreas.hansson@arm.com * and back. In essence the pointer is set calling dataStatic on 77210571Sandreas.hansson@arm.com * the original packet, and whenever this packet is copied and 77310571Sandreas.hansson@arm.com * forwarded the same pointer is passed on. When a packet 77410571Sandreas.hansson@arm.com * eventually reaches the destination holding the data, it is 77510571Sandreas.hansson@arm.com * copied once into the location originally set. On the way back 77610571Sandreas.hansson@arm.com * to the source, no copies are necessary. 7772566SN/A */ 7782566SN/A template <typename T> 7793348Sbinkertn@umich.edu void 7803348Sbinkertn@umich.edu dataStatic(T *p) 7813348Sbinkertn@umich.edu { 78210566Sandreas.hansson@arm.com assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); 7833348Sbinkertn@umich.edu data = (PacketDataPtr)p; 7845735Snate@binkert.org flags.set(STATIC_DATA); 7853348Sbinkertn@umich.edu } 7862566SN/A 7873348Sbinkertn@umich.edu /** 78810564Sandreas.hansson@arm.com * Set the data pointer to the following value that should not be 78910564Sandreas.hansson@arm.com * freed. This version of the function allows the pointer passed 79010564Sandreas.hansson@arm.com * to us to be const. To avoid issues down the line we cast the 79110564Sandreas.hansson@arm.com * constness away, the alternative would be to keep both a const 79210564Sandreas.hansson@arm.com * and non-const data pointer and cleverly choose between 79310564Sandreas.hansson@arm.com * them. Note that this is only allowed for static data. 79410564Sandreas.hansson@arm.com */ 79510564Sandreas.hansson@arm.com template <typename T> 79610564Sandreas.hansson@arm.com void 79710564Sandreas.hansson@arm.com dataStaticConst(const T *p) 79810564Sandreas.hansson@arm.com { 79910566Sandreas.hansson@arm.com assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); 80010564Sandreas.hansson@arm.com data = const_cast<PacketDataPtr>(p); 80110564Sandreas.hansson@arm.com flags.set(STATIC_DATA); 80210564Sandreas.hansson@arm.com } 80310564Sandreas.hansson@arm.com 80410564Sandreas.hansson@arm.com /** 8053348Sbinkertn@umich.edu * Set the data pointer to a value that should have delete [] 80610571Sandreas.hansson@arm.com * called on it. Dynamic data is local to this packet, and as the 80710571Sandreas.hansson@arm.com * packet travels from source to destination, forwarded packets 80810571Sandreas.hansson@arm.com * will allocate their own data. When a packet reaches the final 80910571Sandreas.hansson@arm.com * destination it will populate the dynamic data of that specific 81010571Sandreas.hansson@arm.com * packet, and on the way back towards the source, memcpy will be 81110571Sandreas.hansson@arm.com * invoked in every step where a new packet was created e.g. in 81210571Sandreas.hansson@arm.com * the caches. Ultimately when the response reaches the source a 81310571Sandreas.hansson@arm.com * final memcpy is needed to extract the data from the packet 81410571Sandreas.hansson@arm.com * before it is deallocated. 8153348Sbinkertn@umich.edu */ 8162566SN/A template <typename T> 8173348Sbinkertn@umich.edu void 8183348Sbinkertn@umich.edu dataDynamic(T *p) 8193348Sbinkertn@umich.edu { 82010566Sandreas.hansson@arm.com assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); 8213348Sbinkertn@umich.edu data = (PacketDataPtr)p; 8225735Snate@binkert.org flags.set(DYNAMIC_DATA); 8233348Sbinkertn@umich.edu } 8243348Sbinkertn@umich.edu 8255735Snate@binkert.org /** 8265735Snate@binkert.org * get a pointer to the data ptr. 8275735Snate@binkert.org */ 8283348Sbinkertn@umich.edu template <typename T> 8293348Sbinkertn@umich.edu T* 83010562Sandreas.hansson@arm.com getPtr() 8313348Sbinkertn@umich.edu { 83210562Sandreas.hansson@arm.com assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA)); 8333348Sbinkertn@umich.edu return (T*)data; 8343348Sbinkertn@umich.edu } 8352566SN/A 83610563Sandreas.hansson@arm.com template <typename T> 83710563Sandreas.hansson@arm.com const T* 83810563Sandreas.hansson@arm.com getConstPtr() const 83910563Sandreas.hansson@arm.com { 84010563Sandreas.hansson@arm.com assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA)); 84110563Sandreas.hansson@arm.com return (const T*)data; 84210563Sandreas.hansson@arm.com } 84310563Sandreas.hansson@arm.com 8445735Snate@binkert.org /** 8455735Snate@binkert.org * return the value of what is pointed to in the packet. 8465735Snate@binkert.org */ 8472566SN/A template <typename T> 84810563Sandreas.hansson@arm.com T get() const; 8492566SN/A 8505735Snate@binkert.org /** 8515735Snate@binkert.org * set the value in the data pointer to v. 8525735Snate@binkert.org */ 8532566SN/A template <typename T> 8542592SN/A void set(T v); 8552566SN/A 8563348Sbinkertn@umich.edu /** 8574626Sstever@eecs.umich.edu * Copy data into the packet from the provided pointer. 8584626Sstever@eecs.umich.edu */ 8595735Snate@binkert.org void 86010563Sandreas.hansson@arm.com setData(const uint8_t *p) 8614626Sstever@eecs.umich.edu { 86210571Sandreas.hansson@arm.com // we should never be copying data onto itself, which means we 86310571Sandreas.hansson@arm.com // must idenfity packets with static data, as they carry the 86410571Sandreas.hansson@arm.com // same pointer from source to destination and back 86510571Sandreas.hansson@arm.com assert(p != getPtr<uint8_t>() || flags.isSet(STATIC_DATA)); 86610571Sandreas.hansson@arm.com 8677691SAli.Saidi@ARM.com if (p != getPtr<uint8_t>()) 86810571Sandreas.hansson@arm.com // for packet with allocated dynamic data, we copy data from 86910571Sandreas.hansson@arm.com // one to the other, e.g. a forwarded response to a response 8707691SAli.Saidi@ARM.com std::memcpy(getPtr<uint8_t>(), p, getSize()); 8714626Sstever@eecs.umich.edu } 8724626Sstever@eecs.umich.edu 8734626Sstever@eecs.umich.edu /** 8744626Sstever@eecs.umich.edu * Copy data into the packet from the provided block pointer, 8754626Sstever@eecs.umich.edu * which is aligned to the given block size. 8764626Sstever@eecs.umich.edu */ 8775735Snate@binkert.org void 87810563Sandreas.hansson@arm.com setDataFromBlock(const uint8_t *blk_data, int blkSize) 8794626Sstever@eecs.umich.edu { 8804626Sstever@eecs.umich.edu setData(blk_data + getOffset(blkSize)); 8814626Sstever@eecs.umich.edu } 8824626Sstever@eecs.umich.edu 8834626Sstever@eecs.umich.edu /** 8844626Sstever@eecs.umich.edu * Copy data from the packet to the provided block pointer, which 8854626Sstever@eecs.umich.edu * is aligned to the given block size. 8864626Sstever@eecs.umich.edu */ 8875735Snate@binkert.org void 88810563Sandreas.hansson@arm.com writeData(uint8_t *p) const 8894626Sstever@eecs.umich.edu { 89010563Sandreas.hansson@arm.com std::memcpy(p, getConstPtr<uint8_t>(), getSize()); 8914626Sstever@eecs.umich.edu } 8924626Sstever@eecs.umich.edu 8934626Sstever@eecs.umich.edu /** 8944626Sstever@eecs.umich.edu * Copy data from the packet to the memory at the provided pointer. 8954626Sstever@eecs.umich.edu */ 8965735Snate@binkert.org void 89710563Sandreas.hansson@arm.com writeDataToBlock(uint8_t *blk_data, int blkSize) const 8984626Sstever@eecs.umich.edu { 8994626Sstever@eecs.umich.edu writeData(blk_data + getOffset(blkSize)); 9004626Sstever@eecs.umich.edu } 9014626Sstever@eecs.umich.edu 9024626Sstever@eecs.umich.edu /** 9033348Sbinkertn@umich.edu * delete the data pointed to in the data pointer. Ok to call to 9043348Sbinkertn@umich.edu * matter how data was allocted. 9053348Sbinkertn@umich.edu */ 9065735Snate@binkert.org void 9075735Snate@binkert.org deleteData() 9085735Snate@binkert.org { 90910566Sandreas.hansson@arm.com if (flags.isSet(DYNAMIC_DATA)) 9105735Snate@binkert.org delete [] data; 9115735Snate@binkert.org 91210566Sandreas.hansson@arm.com flags.clear(STATIC_DATA|DYNAMIC_DATA); 9135735Snate@binkert.org data = NULL; 9145735Snate@binkert.org } 9152566SN/A 91610565Sandreas.hansson@arm.com /** Allocate memory for the packet. */ 9175735Snate@binkert.org void 9185735Snate@binkert.org allocate() 9195735Snate@binkert.org { 9205764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); 92110566Sandreas.hansson@arm.com flags.set(DYNAMIC_DATA); 9225745Snate@binkert.org data = new uint8_t[getSize()]; 9235735Snate@binkert.org } 9245735Snate@binkert.org 9254626Sstever@eecs.umich.edu /** 92610570Sandreas.hansson@arm.com * Check a functional request against a memory value stored in 92710570Sandreas.hansson@arm.com * another packet (i.e. an in-transit request or 92810570Sandreas.hansson@arm.com * response). Returns true if the current packet is a read, and 92910570Sandreas.hansson@arm.com * the other packet provides the data, which is then copied to the 93010570Sandreas.hansson@arm.com * current packet. If the current packet is a write, and the other 93110570Sandreas.hansson@arm.com * packet intersects this one, then we update the data 93210570Sandreas.hansson@arm.com * accordingly. 93310570Sandreas.hansson@arm.com */ 93410570Sandreas.hansson@arm.com bool 93510570Sandreas.hansson@arm.com checkFunctional(PacketPtr other) 93610570Sandreas.hansson@arm.com { 93710570Sandreas.hansson@arm.com // all packets that are carrying a payload should have a valid 93810570Sandreas.hansson@arm.com // data pointer 93910570Sandreas.hansson@arm.com return checkFunctional(other, other->getAddr(), other->isSecure(), 94010570Sandreas.hansson@arm.com other->getSize(), 94110570Sandreas.hansson@arm.com other->hasData() ? 94210570Sandreas.hansson@arm.com other->getPtr<uint8_t>() : NULL); 94310570Sandreas.hansson@arm.com } 94410570Sandreas.hansson@arm.com 94510570Sandreas.hansson@arm.com /** 94610883Sali.jafri@arm.com * Is this request notification of a clean or dirty eviction from the cache. 94710883Sali.jafri@arm.com **/ 94810883Sali.jafri@arm.com bool 94910883Sali.jafri@arm.com evictingBlock() const 95010883Sali.jafri@arm.com { 95110883Sali.jafri@arm.com return (cmd == MemCmd::Writeback || 95210883Sali.jafri@arm.com cmd == MemCmd::CleanEvict); 95310883Sali.jafri@arm.com } 95410883Sali.jafri@arm.com 95510883Sali.jafri@arm.com /** 95610883Sali.jafri@arm.com * Does the request need to check for cached copies of the same block 95710883Sali.jafri@arm.com * in the memory hierarchy above. 95810883Sali.jafri@arm.com **/ 95910883Sali.jafri@arm.com bool 96010883Sali.jafri@arm.com mustCheckAbove() const 96110883Sali.jafri@arm.com { 96210883Sali.jafri@arm.com return (cmd == MemCmd::HardPFReq || 96310883Sali.jafri@arm.com evictingBlock()); 96410883Sali.jafri@arm.com } 96510883Sali.jafri@arm.com 96610883Sali.jafri@arm.com /** 9674626Sstever@eecs.umich.edu * Check a functional request against a memory value represented 96810570Sandreas.hansson@arm.com * by a base/size pair and an associated data array. If the 96910570Sandreas.hansson@arm.com * current packet is a read, it may be satisfied by the memory 97010570Sandreas.hansson@arm.com * value. If the current packet is a write, it may update the 9714626Sstever@eecs.umich.edu * memory value. 9724626Sstever@eecs.umich.edu */ 9735735Snate@binkert.org bool 97410570Sandreas.hansson@arm.com checkFunctional(Printable *obj, Addr base, bool is_secure, int size, 97510570Sandreas.hansson@arm.com uint8_t *_data); 9765314Sstever@gmail.com 9775315Sstever@gmail.com /** 9785315Sstever@gmail.com * Push label for PrintReq (safe to call unconditionally). 9795315Sstever@gmail.com */ 9805735Snate@binkert.org void 9815735Snate@binkert.org pushLabel(const std::string &lbl) 9825735Snate@binkert.org { 9835735Snate@binkert.org if (isPrint()) 9845735Snate@binkert.org safe_cast<PrintReqState*>(senderState)->pushLabel(lbl); 9855314Sstever@gmail.com } 9865314Sstever@gmail.com 9875315Sstever@gmail.com /** 9885315Sstever@gmail.com * Pop label for PrintReq (safe to call unconditionally). 9895315Sstever@gmail.com */ 9905735Snate@binkert.org void 9915735Snate@binkert.org popLabel() 9925735Snate@binkert.org { 9935735Snate@binkert.org if (isPrint()) 9945735Snate@binkert.org safe_cast<PrintReqState*>(senderState)->popLabel(); 9955314Sstever@gmail.com } 9965314Sstever@gmail.com 9975314Sstever@gmail.com void print(std::ostream &o, int verbosity = 0, 9985314Sstever@gmail.com const std::string &prefix = "") const; 9999663Suri.wiener@arm.com 10009663Suri.wiener@arm.com /** 10019663Suri.wiener@arm.com * A no-args wrapper of print(std::ostream...) 10029663Suri.wiener@arm.com * meant to be invoked from DPRINTFs 10039663Suri.wiener@arm.com * avoiding string overheads in fast mode 10049663Suri.wiener@arm.com * @return string with the request's type and start<->end addresses 10059663Suri.wiener@arm.com */ 10069663Suri.wiener@arm.com std::string print() const; 10072381SN/A}; 10082381SN/A 10092381SN/A#endif //__MEM_PACKET_HH 1010