packet.hh revision 10562
12381SN/A/* 210342SCurtis.Dunham@arm.com * Copyright (c) 2012-2014 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, 904022Sstever@eecs.umich.edu SoftPFReq, 914022Sstever@eecs.umich.edu HardPFReq, 924022Sstever@eecs.umich.edu SoftPFResp, 934022Sstever@eecs.umich.edu HardPFResp, 944022Sstever@eecs.umich.edu WriteInvalidateReq, 954022Sstever@eecs.umich.edu WriteInvalidateResp, 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, 1034626Sstever@eecs.umich.edu LoadLockedReq, 1044626Sstever@eecs.umich.edu StoreCondReq, 1057669Ssteve.reinhardt@amd.com StoreCondFailReq, // Failed StoreCondReq in MSHR (never sent) 1064626Sstever@eecs.umich.edu StoreCondResp, 1074040Ssaidi@eecs.umich.edu SwapReq, 1084040Ssaidi@eecs.umich.edu SwapResp, 1095650Sgblack@eecs.umich.edu MessageReq, 1105650Sgblack@eecs.umich.edu MessageResp, 1114870Sstever@eecs.umich.edu // Error responses 1124870Sstever@eecs.umich.edu // @TODO these should be classified as responses rather than 1134870Sstever@eecs.umich.edu // requests; coding them as requests initially for backwards 1144870Sstever@eecs.umich.edu // compatibility 1154870Sstever@eecs.umich.edu InvalidDestError, // packet dest field invalid 1164870Sstever@eecs.umich.edu BadAddressError, // memory address invalid 1178436SBrad.Beckmann@amd.com FunctionalReadError, // unable to fulfill functional read 1188436SBrad.Beckmann@amd.com FunctionalWriteError, // unable to fulfill functional write 1195314Sstever@gmail.com // Fake simulator-only commands 1205314Sstever@gmail.com PrintReq, // Print state matching address 1218184Ssomayeh@cs.wisc.edu FlushReq, //request for a cache flush 1228716Snilay@cs.wisc.edu InvalidationReq, // request for address to be invalidated from lsq 1234022Sstever@eecs.umich.edu NUM_MEM_CMDS 1244022Sstever@eecs.umich.edu }; 1254022Sstever@eecs.umich.edu 1264022Sstever@eecs.umich.edu private: 1275735Snate@binkert.org /** 1285735Snate@binkert.org * List of command attributes. 1295735Snate@binkert.org */ 1304022Sstever@eecs.umich.edu enum Attribute 1314022Sstever@eecs.umich.edu { 1324626Sstever@eecs.umich.edu IsRead, //!< Data flows from responder to requester 1334626Sstever@eecs.umich.edu IsWrite, //!< Data flows from requester to responder 1347465Ssteve.reinhardt@amd.com IsUpgrade, 1354022Sstever@eecs.umich.edu IsInvalidate, 1364626Sstever@eecs.umich.edu NeedsExclusive, //!< Requires exclusive copy to complete in-cache 1374626Sstever@eecs.umich.edu IsRequest, //!< Issued by requester 1384626Sstever@eecs.umich.edu IsResponse, //!< Issue by responder 1394626Sstever@eecs.umich.edu NeedsResponse, //!< Requester needs response from target 1404022Sstever@eecs.umich.edu IsSWPrefetch, 1414022Sstever@eecs.umich.edu IsHWPrefetch, 1426076Sgblack@eecs.umich.edu IsLlsc, //!< Alpha/MIPS LL or SC access 1434626Sstever@eecs.umich.edu HasData, //!< There is an associated payload 1444870Sstever@eecs.umich.edu IsError, //!< Error response 1455314Sstever@gmail.com IsPrint, //!< Print state matching address (for debugging) 1468184Ssomayeh@cs.wisc.edu IsFlush, //!< Flush the address from caches 1474022Sstever@eecs.umich.edu NUM_COMMAND_ATTRIBUTES 1484022Sstever@eecs.umich.edu }; 1494022Sstever@eecs.umich.edu 1505735Snate@binkert.org /** 1515735Snate@binkert.org * Structure that defines attributes and other data associated 1525735Snate@binkert.org * with a Command. 1535735Snate@binkert.org */ 1545735Snate@binkert.org struct CommandInfo 1555735Snate@binkert.org { 1565735Snate@binkert.org /// Set of attribute flags. 1574022Sstever@eecs.umich.edu const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes; 1585735Snate@binkert.org /// Corresponding response for requests; InvalidCmd if no 1595735Snate@binkert.org /// response is applicable. 1604022Sstever@eecs.umich.edu const Command response; 1615735Snate@binkert.org /// String representation (for printing) 1624022Sstever@eecs.umich.edu const std::string str; 1634022Sstever@eecs.umich.edu }; 1644022Sstever@eecs.umich.edu 1655735Snate@binkert.org /// Array to map Command enum to associated info. 1664022Sstever@eecs.umich.edu static const CommandInfo commandInfo[]; 1674022Sstever@eecs.umich.edu 1684022Sstever@eecs.umich.edu private: 1694022Sstever@eecs.umich.edu 1704022Sstever@eecs.umich.edu Command cmd; 1714022Sstever@eecs.umich.edu 1725735Snate@binkert.org bool 1735735Snate@binkert.org testCmdAttrib(MemCmd::Attribute attrib) const 1745735Snate@binkert.org { 1754022Sstever@eecs.umich.edu return commandInfo[cmd].attributes[attrib] != 0; 1764022Sstever@eecs.umich.edu } 1774022Sstever@eecs.umich.edu 1784022Sstever@eecs.umich.edu public: 1794022Sstever@eecs.umich.edu 1804022Sstever@eecs.umich.edu bool isRead() const { return testCmdAttrib(IsRead); } 1817465Ssteve.reinhardt@amd.com bool isWrite() const { return testCmdAttrib(IsWrite); } 1827465Ssteve.reinhardt@amd.com bool isUpgrade() const { return testCmdAttrib(IsUpgrade); } 1834022Sstever@eecs.umich.edu bool isRequest() const { return testCmdAttrib(IsRequest); } 1844022Sstever@eecs.umich.edu bool isResponse() const { return testCmdAttrib(IsResponse); } 1854870Sstever@eecs.umich.edu bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); } 1864022Sstever@eecs.umich.edu bool needsResponse() const { return testCmdAttrib(NeedsResponse); } 1874022Sstever@eecs.umich.edu bool isInvalidate() const { return testCmdAttrib(IsInvalidate); } 1884022Sstever@eecs.umich.edu bool hasData() const { return testCmdAttrib(HasData); } 1894626Sstever@eecs.umich.edu bool isReadWrite() const { return isRead() && isWrite(); } 1906102Sgblack@eecs.umich.edu bool isLLSC() const { return testCmdAttrib(IsLlsc); } 19110343SCurtis.Dunham@arm.com bool isSWPrefetch() const { return testCmdAttrib(IsSWPrefetch); } 19210343SCurtis.Dunham@arm.com bool isHWPrefetch() const { return testCmdAttrib(IsHWPrefetch); } 19310343SCurtis.Dunham@arm.com bool isPrefetch() const { return testCmdAttrib(IsSWPrefetch) || 19410343SCurtis.Dunham@arm.com testCmdAttrib(IsHWPrefetch); } 1954870Sstever@eecs.umich.edu bool isError() const { return testCmdAttrib(IsError); } 1965314Sstever@gmail.com bool isPrint() const { return testCmdAttrib(IsPrint); } 1978184Ssomayeh@cs.wisc.edu bool isFlush() const { return testCmdAttrib(IsFlush); } 1984022Sstever@eecs.umich.edu 1995735Snate@binkert.org const Command 2005735Snate@binkert.org responseCommand() const 2015735Snate@binkert.org { 2024022Sstever@eecs.umich.edu return commandInfo[cmd].response; 2034022Sstever@eecs.umich.edu } 2044022Sstever@eecs.umich.edu 2055735Snate@binkert.org /// Return the string to a cmd given by idx. 2065735Snate@binkert.org const std::string &toString() const { return commandInfo[cmd].str; } 2074022Sstever@eecs.umich.edu int toInt() const { return (int)cmd; } 2084022Sstever@eecs.umich.edu 2095735Snate@binkert.org MemCmd(Command _cmd) : cmd(_cmd) { } 2105735Snate@binkert.org MemCmd(int _cmd) : cmd((Command)_cmd) { } 2115735Snate@binkert.org MemCmd() : cmd(InvalidCmd) { } 2124022Sstever@eecs.umich.edu 2135735Snate@binkert.org bool operator==(MemCmd c2) const { return (cmd == c2.cmd); } 2145735Snate@binkert.org bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); } 2154022Sstever@eecs.umich.edu}; 2164022Sstever@eecs.umich.edu 2172381SN/A/** 2182662Sstever@eecs.umich.edu * A Packet is used to encapsulate a transfer between two objects in 2192662Sstever@eecs.umich.edu * the memory system (e.g., the L1 and L2 cache). (In contrast, a 2202662Sstever@eecs.umich.edu * single Request travels all the way from the requester to the 2212662Sstever@eecs.umich.edu * ultimate destination and back, possibly being conveyed by several 2222662Sstever@eecs.umich.edu * different Packets along the way.) 2232381SN/A */ 2249044SAli.Saidi@ARM.comclass Packet : public Printable 2252381SN/A{ 2262813Srdreslin@umich.edu public: 2275735Snate@binkert.org typedef uint32_t FlagsType; 2285735Snate@binkert.org typedef ::Flags<FlagsType> Flags; 2294022Sstever@eecs.umich.edu 2305735Snate@binkert.org private: 2315735Snate@binkert.org static const FlagsType PUBLIC_FLAGS = 0x00000000; 2325735Snate@binkert.org static const FlagsType PRIVATE_FLAGS = 0x00007F0F; 2335735Snate@binkert.org static const FlagsType COPY_FLAGS = 0x0000000F; 2345735Snate@binkert.org 2355735Snate@binkert.org static const FlagsType SHARED = 0x00000001; 2365735Snate@binkert.org // Special control flags 2375735Snate@binkert.org /// Special timing-mode atomic snoop for multi-level coherence. 2385735Snate@binkert.org static const FlagsType EXPRESS_SNOOP = 0x00000002; 2395735Snate@binkert.org /// Does supplier have exclusive copy? 2405735Snate@binkert.org /// Useful for multi-level coherence. 2415735Snate@binkert.org static const FlagsType SUPPLY_EXCLUSIVE = 0x00000004; 2425735Snate@binkert.org // Snoop response flags 2435735Snate@binkert.org static const FlagsType MEM_INHIBIT = 0x00000008; 2445735Snate@binkert.org /// Are the 'addr' and 'size' fields valid? 2455735Snate@binkert.org static const FlagsType VALID_ADDR = 0x00000100; 2465735Snate@binkert.org static const FlagsType VALID_SIZE = 0x00000200; 2475735Snate@binkert.org /// Is the data pointer set to a value that shouldn't be freed 2485735Snate@binkert.org /// when the packet is destroyed? 2495735Snate@binkert.org static const FlagsType STATIC_DATA = 0x00001000; 2505735Snate@binkert.org /// The data pointer points to a value that should be freed when 2515735Snate@binkert.org /// the packet is destroyed. 2525735Snate@binkert.org static const FlagsType DYNAMIC_DATA = 0x00002000; 2535735Snate@binkert.org /// the data pointer points to an array (thus delete []) needs to 2545735Snate@binkert.org /// be called on it rather than simply delete. 2555735Snate@binkert.org static const FlagsType ARRAY_DATA = 0x00004000; 2568436SBrad.Beckmann@amd.com /// suppress the error if this packet encounters a functional 2578436SBrad.Beckmann@amd.com /// access failure. 2588436SBrad.Beckmann@amd.com static const FlagsType SUPPRESS_FUNC_ERROR = 0x00008000; 25910192Smitch.hayenga@arm.com // Signal prefetch squash through express snoop flag 26010192Smitch.hayenga@arm.com static const FlagsType PREFETCH_SNOOP_SQUASH = 0x00010000; 2615735Snate@binkert.org 2625735Snate@binkert.org Flags flags; 2635735Snate@binkert.org 2645735Snate@binkert.org public: 2654022Sstever@eecs.umich.edu typedef MemCmd::Command Command; 2664022Sstever@eecs.umich.edu 2675735Snate@binkert.org /// The command field of the packet. 2684870Sstever@eecs.umich.edu MemCmd cmd; 2694870Sstever@eecs.umich.edu 2705735Snate@binkert.org /// A pointer to the original request. 2714870Sstever@eecs.umich.edu RequestPtr req; 2724870Sstever@eecs.umich.edu 2732566SN/A private: 2745735Snate@binkert.org /** 2755735Snate@binkert.org * A pointer to the data being transfered. It can be differnt 2765735Snate@binkert.org * sizes at each level of the heirarchy so it belongs in the 2775735Snate@binkert.org * packet, not request. This may or may not be populated when a 2785735Snate@binkert.org * responder recieves the packet. If not populated it memory should 2795735Snate@binkert.org * be allocated. 2802566SN/A */ 2812566SN/A PacketDataPtr data; 2822566SN/A 2835735Snate@binkert.org /// The address of the request. This address could be virtual or 2845735Snate@binkert.org /// physical, depending on the system configuration. 2852381SN/A Addr addr; 2862381SN/A 28710028SGiacomo.Gabrielli@arm.com /// True if the request targets the secure memory space. 28810028SGiacomo.Gabrielli@arm.com bool _isSecure; 28910028SGiacomo.Gabrielli@arm.com 2905735Snate@binkert.org /// The size of the request or transfer. 2916227Snate@binkert.org unsigned size; 2922381SN/A 2935735Snate@binkert.org /** 2949030Sandreas.hansson@arm.com * Source port identifier set on a request packet to enable 2959030Sandreas.hansson@arm.com * appropriate routing of the responses. The source port 29610405Sandreas.hansson@arm.com * identifier is set by any multiplexing component, e.g. a 29710405Sandreas.hansson@arm.com * crossbar, as the timing responses need this information to be 29810405Sandreas.hansson@arm.com * routed back to the appropriate port at a later point in 29910405Sandreas.hansson@arm.com * time. The field can be updated (over-written) as the request 30010405Sandreas.hansson@arm.com * packet passes through additional multiplexing components, and 30110405Sandreas.hansson@arm.com * it is their responsibility to remember the original source port 30210405Sandreas.hansson@arm.com * identifier, for example by using an appropriate sender 30310405Sandreas.hansson@arm.com * state. The latter is done in the cache and bridge. 3045735Snate@binkert.org */ 3059031Sandreas.hansson@arm.com PortID src; 3062381SN/A 3075735Snate@binkert.org /** 3089030Sandreas.hansson@arm.com * Destination port identifier that is present on all response 3099030Sandreas.hansson@arm.com * packets that passed through a multiplexing component as a 3109030Sandreas.hansson@arm.com * request packet. The source port identifier is turned into a 3119030Sandreas.hansson@arm.com * destination port identifier when the packet is turned into a 31210405Sandreas.hansson@arm.com * response, and the destination is used, e.g. by the crossbar, to 3139030Sandreas.hansson@arm.com * select the appropriate path through the interconnect. 3145735Snate@binkert.org */ 3159031Sandreas.hansson@arm.com PortID dest; 3162641Sstever@eecs.umich.edu 3175735Snate@binkert.org /** 3185735Snate@binkert.org * The original value of the command field. Only valid when the 3194870Sstever@eecs.umich.edu * current command field is an error condition; in that case, the 3204870Sstever@eecs.umich.edu * previous contents of the command field are copied here. This 3214870Sstever@eecs.umich.edu * field is *not* set on non-error responses. 3224870Sstever@eecs.umich.edu */ 3234870Sstever@eecs.umich.edu MemCmd origCmd; 3244870Sstever@eecs.umich.edu 3258668Sgeoffrey.blake@arm.com /** 3268668Sgeoffrey.blake@arm.com * These values specify the range of bytes found that satisfy a 3278668Sgeoffrey.blake@arm.com * functional read. 3288668Sgeoffrey.blake@arm.com */ 3298668Sgeoffrey.blake@arm.com uint16_t bytesValidStart; 3308668Sgeoffrey.blake@arm.com uint16_t bytesValidEnd; 3318668Sgeoffrey.blake@arm.com 3322641Sstever@eecs.umich.edu public: 3332811Srdreslin@umich.edu 3349547Sandreas.hansson@arm.com /** 3359547Sandreas.hansson@arm.com * The extra delay from seeing the packet until the first word is 33610405Sandreas.hansson@arm.com * transmitted. This delay is used to communicate the crossbar 33710405Sandreas.hansson@arm.com * forwarding latency to the neighbouring object (e.g. a cache) 33810405Sandreas.hansson@arm.com * that actually makes the packet wait. As the delay is relative, 33910405Sandreas.hansson@arm.com * a 32-bit unsigned should be sufficient. 3409547Sandreas.hansson@arm.com */ 34110405Sandreas.hansson@arm.com uint32_t firstWordDelay; 3423218Sgblack@eecs.umich.edu 3439547Sandreas.hansson@arm.com /** 34410405Sandreas.hansson@arm.com * The extra pipelining delay from seeing the packet until the 34510405Sandreas.hansson@arm.com * last word is transmitted by the component that provided it (if 34610405Sandreas.hansson@arm.com * any). This includes the first word delay. Similar to the first 34710405Sandreas.hansson@arm.com * word delay, this is used to make up for the fact that the 34810405Sandreas.hansson@arm.com * crossbar does not make the packet wait. As the delay is 34910405Sandreas.hansson@arm.com * relative, a 32-bit unsigned should be sufficient. 3509547Sandreas.hansson@arm.com */ 35110405Sandreas.hansson@arm.com uint32_t lastWordDelay; 3523218Sgblack@eecs.umich.edu 3535735Snate@binkert.org /** 3545735Snate@binkert.org * A virtual base opaque structure used to hold state associated 3559542Sandreas.hansson@arm.com * with the packet (e.g., an MSHR), specific to a MemObject that 3569542Sandreas.hansson@arm.com * sees the packet. A pointer to this state is returned in the 3579542Sandreas.hansson@arm.com * packet's response so that the MemObject in question can quickly 3589542Sandreas.hansson@arm.com * look up the state needed to process it. A specific subclass 3599542Sandreas.hansson@arm.com * would be derived from this to carry state specific to a 3609542Sandreas.hansson@arm.com * particular sending device. 3619542Sandreas.hansson@arm.com * 3629542Sandreas.hansson@arm.com * As multiple MemObjects may add their SenderState throughout the 3639542Sandreas.hansson@arm.com * memory system, the SenderStates create a stack, where a 3649542Sandreas.hansson@arm.com * MemObject can add a new Senderstate, as long as the 3659542Sandreas.hansson@arm.com * predecessing SenderState is restored when the response comes 3669542Sandreas.hansson@arm.com * back. For this reason, the predecessor should always be 3679542Sandreas.hansson@arm.com * populated with the current SenderState of a packet before 3689542Sandreas.hansson@arm.com * modifying the senderState field in the request packet. 3695735Snate@binkert.org */ 3705735Snate@binkert.org struct SenderState 3715735Snate@binkert.org { 3729542Sandreas.hansson@arm.com SenderState* predecessor; 3739542Sandreas.hansson@arm.com SenderState() : predecessor(NULL) {} 3742641Sstever@eecs.umich.edu virtual ~SenderState() {} 3752641Sstever@eecs.umich.edu }; 3762641Sstever@eecs.umich.edu 3775315Sstever@gmail.com /** 3785315Sstever@gmail.com * Object used to maintain state of a PrintReq. The senderState 3795315Sstever@gmail.com * field of a PrintReq should always be of this type. 3805315Sstever@gmail.com */ 3819044SAli.Saidi@ARM.com class PrintReqState : public SenderState 3825735Snate@binkert.org { 3835735Snate@binkert.org private: 3845735Snate@binkert.org /** 3855735Snate@binkert.org * An entry in the label stack. 3865735Snate@binkert.org */ 3875735Snate@binkert.org struct LabelStackEntry 3885735Snate@binkert.org { 3895314Sstever@gmail.com const std::string label; 3905314Sstever@gmail.com std::string *prefix; 3915314Sstever@gmail.com bool labelPrinted; 3925735Snate@binkert.org LabelStackEntry(const std::string &_label, std::string *_prefix); 3935314Sstever@gmail.com }; 3945314Sstever@gmail.com 3955314Sstever@gmail.com typedef std::list<LabelStackEntry> LabelStack; 3965314Sstever@gmail.com LabelStack labelStack; 3975314Sstever@gmail.com 3985314Sstever@gmail.com std::string *curPrefixPtr; 3995314Sstever@gmail.com 4005314Sstever@gmail.com public: 4015314Sstever@gmail.com std::ostream &os; 4025314Sstever@gmail.com const int verbosity; 4035314Sstever@gmail.com 4045314Sstever@gmail.com PrintReqState(std::ostream &os, int verbosity = 0); 4055314Sstever@gmail.com ~PrintReqState(); 4065314Sstever@gmail.com 4075735Snate@binkert.org /** 4085735Snate@binkert.org * Returns the current line prefix. 4095735Snate@binkert.org */ 4105314Sstever@gmail.com const std::string &curPrefix() { return *curPrefixPtr; } 4115315Sstever@gmail.com 4125735Snate@binkert.org /** 4135735Snate@binkert.org * Push a label onto the label stack, and prepend the given 4145315Sstever@gmail.com * prefix string onto the current prefix. Labels will only be 4155735Snate@binkert.org * printed if an object within the label's scope is printed. 4165735Snate@binkert.org */ 4175314Sstever@gmail.com void pushLabel(const std::string &lbl, 4185314Sstever@gmail.com const std::string &prefix = " "); 4195735Snate@binkert.org 4205735Snate@binkert.org /** 4215735Snate@binkert.org * Pop a label off the label stack. 4225735Snate@binkert.org */ 4235314Sstever@gmail.com void popLabel(); 4245735Snate@binkert.org 4255735Snate@binkert.org /** 4265735Snate@binkert.org * Print all of the pending unprinted labels on the 4275315Sstever@gmail.com * stack. Called by printObj(), so normally not called by 4285735Snate@binkert.org * users unless bypassing printObj(). 4295735Snate@binkert.org */ 4305314Sstever@gmail.com void printLabels(); 4315735Snate@binkert.org 4325735Snate@binkert.org /** 4335735Snate@binkert.org * Print a Printable object to os, because it matched the 4345735Snate@binkert.org * address on a PrintReq. 4355735Snate@binkert.org */ 4365314Sstever@gmail.com void printObj(Printable *obj); 4375314Sstever@gmail.com }; 4385314Sstever@gmail.com 4395735Snate@binkert.org /** 4405735Snate@binkert.org * This packet's sender state. Devices should use dynamic_cast<> 4415735Snate@binkert.org * to cast to the state appropriate to the sender. The intent of 4425735Snate@binkert.org * this variable is to allow a device to attach extra information 4439542Sandreas.hansson@arm.com * to a request. A response packet must return the sender state 4445735Snate@binkert.org * that was attached to the original request (even if a new packet 4455735Snate@binkert.org * is created). 4465735Snate@binkert.org */ 4472662Sstever@eecs.umich.edu SenderState *senderState; 4482641Sstever@eecs.umich.edu 4499542Sandreas.hansson@arm.com /** 4509542Sandreas.hansson@arm.com * Push a new sender state to the packet and make the current 4519542Sandreas.hansson@arm.com * sender state the predecessor of the new one. This should be 4529542Sandreas.hansson@arm.com * prefered over direct manipulation of the senderState member 4539542Sandreas.hansson@arm.com * variable. 4549542Sandreas.hansson@arm.com * 4559542Sandreas.hansson@arm.com * @param sender_state SenderState to push at the top of the stack 4569542Sandreas.hansson@arm.com */ 4579542Sandreas.hansson@arm.com void pushSenderState(SenderState *sender_state); 4589542Sandreas.hansson@arm.com 4599542Sandreas.hansson@arm.com /** 4609542Sandreas.hansson@arm.com * Pop the top of the state stack and return a pointer to it. This 4619542Sandreas.hansson@arm.com * assumes the current sender state is not NULL. This should be 4629542Sandreas.hansson@arm.com * preferred over direct manipulation of the senderState member 4639542Sandreas.hansson@arm.com * variable. 4649542Sandreas.hansson@arm.com * 4659542Sandreas.hansson@arm.com * @return The current top of the stack 4669542Sandreas.hansson@arm.com */ 4679542Sandreas.hansson@arm.com SenderState *popSenderState(); 4689542Sandreas.hansson@arm.com 4699543Ssascha.bischoff@arm.com /** 4709543Ssascha.bischoff@arm.com * Go through the sender state stack and return the first instance 4719543Ssascha.bischoff@arm.com * that is of type T (as determined by a dynamic_cast). If there 4729543Ssascha.bischoff@arm.com * is no sender state of type T, NULL is returned. 4739543Ssascha.bischoff@arm.com * 4749543Ssascha.bischoff@arm.com * @return The topmost state of type T 4759543Ssascha.bischoff@arm.com */ 4769543Ssascha.bischoff@arm.com template <typename T> 4779543Ssascha.bischoff@arm.com T * findNextSenderState() const 4789543Ssascha.bischoff@arm.com { 4799543Ssascha.bischoff@arm.com T *t = NULL; 4809543Ssascha.bischoff@arm.com SenderState* sender_state = senderState; 4819543Ssascha.bischoff@arm.com while (t == NULL && sender_state != NULL) { 4829543Ssascha.bischoff@arm.com t = dynamic_cast<T*>(sender_state); 4839543Ssascha.bischoff@arm.com sender_state = sender_state->predecessor; 4849543Ssascha.bischoff@arm.com } 4859543Ssascha.bischoff@arm.com return t; 4869543Ssascha.bischoff@arm.com } 4879543Ssascha.bischoff@arm.com 4885735Snate@binkert.org /// Return the string name of the cmd field (for debugging and 4895735Snate@binkert.org /// tracing). 4904022Sstever@eecs.umich.edu const std::string &cmdString() const { return cmd.toString(); } 4912811Srdreslin@umich.edu 4925735Snate@binkert.org /// Return the index of this command. 4934022Sstever@eecs.umich.edu inline int cmdToIndex() const { return cmd.toInt(); } 4942811Srdreslin@umich.edu 4954022Sstever@eecs.umich.edu bool isRead() const { return cmd.isRead(); } 4967465Ssteve.reinhardt@amd.com bool isWrite() const { return cmd.isWrite(); } 4977465Ssteve.reinhardt@amd.com bool isUpgrade() const { return cmd.isUpgrade(); } 4984022Sstever@eecs.umich.edu bool isRequest() const { return cmd.isRequest(); } 4994022Sstever@eecs.umich.edu bool isResponse() const { return cmd.isResponse(); } 5004870Sstever@eecs.umich.edu bool needsExclusive() const { return cmd.needsExclusive(); } 5014022Sstever@eecs.umich.edu bool needsResponse() const { return cmd.needsResponse(); } 5024022Sstever@eecs.umich.edu bool isInvalidate() const { return cmd.isInvalidate(); } 5034022Sstever@eecs.umich.edu bool hasData() const { return cmd.hasData(); } 5044040Ssaidi@eecs.umich.edu bool isReadWrite() const { return cmd.isReadWrite(); } 5056102Sgblack@eecs.umich.edu bool isLLSC() const { return cmd.isLLSC(); } 5064870Sstever@eecs.umich.edu bool isError() const { return cmd.isError(); } 5075314Sstever@gmail.com bool isPrint() const { return cmd.isPrint(); } 5088184Ssomayeh@cs.wisc.edu bool isFlush() const { return cmd.isFlush(); } 5092812Srdreslin@umich.edu 5104870Sstever@eecs.umich.edu // Snoop flags 5119951Sstephan.diestelhorst@arm.com void assertMemInhibit() { flags.set(MEM_INHIBIT); } 5129951Sstephan.diestelhorst@arm.com bool memInhibitAsserted() const { return flags.isSet(MEM_INHIBIT); } 5139951Sstephan.diestelhorst@arm.com void assertShared() { flags.set(SHARED); } 5149951Sstephan.diestelhorst@arm.com bool sharedAsserted() const { return flags.isSet(SHARED); } 5154870Sstever@eecs.umich.edu 5164895Sstever@eecs.umich.edu // Special control flags 5179951Sstephan.diestelhorst@arm.com void setExpressSnoop() { flags.set(EXPRESS_SNOOP); } 5189951Sstephan.diestelhorst@arm.com bool isExpressSnoop() const { return flags.isSet(EXPRESS_SNOOP); } 5199951Sstephan.diestelhorst@arm.com void setSupplyExclusive() { flags.set(SUPPLY_EXCLUSIVE); } 5209951Sstephan.diestelhorst@arm.com void clearSupplyExclusive() { flags.clear(SUPPLY_EXCLUSIVE); } 5219951Sstephan.diestelhorst@arm.com bool isSupplyExclusive() const { return flags.isSet(SUPPLY_EXCLUSIVE); } 5229951Sstephan.diestelhorst@arm.com void setSuppressFuncError() { flags.set(SUPPRESS_FUNC_ERROR); } 5239951Sstephan.diestelhorst@arm.com bool suppressFuncError() const { return flags.isSet(SUPPRESS_FUNC_ERROR); } 52410192Smitch.hayenga@arm.com void setPrefetchSquashed() { flags.set(PREFETCH_SNOOP_SQUASH); } 52510192Smitch.hayenga@arm.com bool prefetchSquashed() const { return flags.isSet(PREFETCH_SNOOP_SQUASH); } 5264895Sstever@eecs.umich.edu 5274870Sstever@eecs.umich.edu // Network error conditions... encapsulate them as methods since 5284870Sstever@eecs.umich.edu // their encoding keeps changing (from result field to command 5294870Sstever@eecs.umich.edu // field, etc.) 5305735Snate@binkert.org void 5315735Snate@binkert.org setBadAddress() 5325735Snate@binkert.org { 5335735Snate@binkert.org assert(isResponse()); 5345735Snate@binkert.org cmd = MemCmd::BadAddressError; 5355735Snate@binkert.org } 5365735Snate@binkert.org 5375735Snate@binkert.org bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; } 5384986Ssaidi@eecs.umich.edu void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; } 5392814Srdreslin@umich.edu 5409031Sandreas.hansson@arm.com bool isSrcValid() const { return src != InvalidPortID; } 5415735Snate@binkert.org /// Accessor function to get the source index of the packet. 5429031Sandreas.hansson@arm.com PortID getSrc() const { assert(isSrcValid()); return src; } 5435735Snate@binkert.org /// Accessor function to set the source index of the packet. 5449031Sandreas.hansson@arm.com void setSrc(PortID _src) { src = _src; } 5452641Sstever@eecs.umich.edu 5469031Sandreas.hansson@arm.com bool isDestValid() const { return dest != InvalidPortID; } 5475735Snate@binkert.org /// Accessor function for the destination index of the packet. 5489031Sandreas.hansson@arm.com PortID getDest() const { assert(isDestValid()); return dest; } 5495735Snate@binkert.org /// Accessor function to set the destination index of the packet. 5509031Sandreas.hansson@arm.com void setDest(PortID _dest) { dest = _dest; } 5518949Sandreas.hansson@arm.com /// Reset destination field, e.g. to turn a response into a request again. 5529031Sandreas.hansson@arm.com void clearDest() { dest = InvalidPortID; } 5532381SN/A 5545764Snate@binkert.org Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; } 5559259SAli.Saidi@ARM.com /** 5569259SAli.Saidi@ARM.com * Update the address of this packet mid-transaction. This is used 5579259SAli.Saidi@ARM.com * by the address mapper to change an already set address to a new 5589259SAli.Saidi@ARM.com * one based on the system configuration. It is intended to remap 5599259SAli.Saidi@ARM.com * an existing address, so it asserts that the current address is 5609259SAli.Saidi@ARM.com * valid. 5619259SAli.Saidi@ARM.com */ 5629259SAli.Saidi@ARM.com void setAddr(Addr _addr) { assert(flags.isSet(VALID_ADDR)); addr = _addr; } 5639259SAli.Saidi@ARM.com 5646227Snate@binkert.org unsigned getSize() const { assert(flags.isSet(VALID_SIZE)); return size; } 5655735Snate@binkert.org Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); } 5662549SN/A 56710028SGiacomo.Gabrielli@arm.com bool isSecure() const 56810028SGiacomo.Gabrielli@arm.com { 56910028SGiacomo.Gabrielli@arm.com assert(flags.isSet(VALID_ADDR)); 57010028SGiacomo.Gabrielli@arm.com return _isSecure; 57110028SGiacomo.Gabrielli@arm.com } 57210028SGiacomo.Gabrielli@arm.com 5735735Snate@binkert.org /** 5747550SBrad.Beckmann@amd.com * It has been determined that the SC packet should successfully update 5757550SBrad.Beckmann@amd.com * memory. Therefore, convert this SC packet to a normal write. 5767550SBrad.Beckmann@amd.com */ 5777550SBrad.Beckmann@amd.com void 5787550SBrad.Beckmann@amd.com convertScToWrite() 5797550SBrad.Beckmann@amd.com { 5807550SBrad.Beckmann@amd.com assert(isLLSC()); 5817550SBrad.Beckmann@amd.com assert(isWrite()); 5827550SBrad.Beckmann@amd.com cmd = MemCmd::WriteReq; 5837550SBrad.Beckmann@amd.com } 5847550SBrad.Beckmann@amd.com 5857550SBrad.Beckmann@amd.com /** 5867550SBrad.Beckmann@amd.com * When ruby is in use, Ruby will monitor the cache line and thus M5 5877550SBrad.Beckmann@amd.com * phys memory should treat LL ops as normal reads. 5887550SBrad.Beckmann@amd.com */ 5897550SBrad.Beckmann@amd.com void 5907550SBrad.Beckmann@amd.com convertLlToRead() 5917550SBrad.Beckmann@amd.com { 5927550SBrad.Beckmann@amd.com assert(isLLSC()); 5937550SBrad.Beckmann@amd.com assert(isRead()); 5947550SBrad.Beckmann@amd.com cmd = MemCmd::ReadReq; 5957550SBrad.Beckmann@amd.com } 5967550SBrad.Beckmann@amd.com 5977550SBrad.Beckmann@amd.com /** 5985735Snate@binkert.org * Constructor. Note that a Request object must be constructed 5995735Snate@binkert.org * first, but the Requests's physical address and size fields need 6009030Sandreas.hansson@arm.com * not be valid. The command must be supplied. 6015735Snate@binkert.org */ 6028949Sandreas.hansson@arm.com Packet(Request *_req, MemCmd _cmd) 60310360Sandreas.hansson@arm.com : cmd(_cmd), req(_req), data(nullptr), addr(0), _isSecure(false), 60410412Sandreas.hansson@arm.com size(0), src(InvalidPortID), dest(InvalidPortID), 6058949Sandreas.hansson@arm.com bytesValidStart(0), bytesValidEnd(0), 60610405Sandreas.hansson@arm.com firstWordDelay(0), lastWordDelay(0), 6079546Sandreas.hansson@arm.com senderState(NULL) 6082641Sstever@eecs.umich.edu { 6096104Ssteve.reinhardt@amd.com if (req->hasPaddr()) { 6106104Ssteve.reinhardt@amd.com addr = req->getPaddr(); 6116104Ssteve.reinhardt@amd.com flags.set(VALID_ADDR); 61210028SGiacomo.Gabrielli@arm.com _isSecure = req->isSecure(); 6136104Ssteve.reinhardt@amd.com } 6146104Ssteve.reinhardt@amd.com if (req->hasSize()) { 6156104Ssteve.reinhardt@amd.com size = req->getSize(); 6166104Ssteve.reinhardt@amd.com flags.set(VALID_SIZE); 6176104Ssteve.reinhardt@amd.com } 6182813Srdreslin@umich.edu } 6192813Srdreslin@umich.edu 6205735Snate@binkert.org /** 6215735Snate@binkert.org * Alternate constructor if you are trying to create a packet with 6225735Snate@binkert.org * a request that is for a whole block, not the address from the 6235735Snate@binkert.org * req. this allows for overriding the size/addr of the req. 6245735Snate@binkert.org */ 6258949Sandreas.hansson@arm.com Packet(Request *_req, MemCmd _cmd, int _blkSize) 62610360Sandreas.hansson@arm.com : cmd(_cmd), req(_req), data(nullptr), addr(0), _isSecure(false), 6279031Sandreas.hansson@arm.com src(InvalidPortID), dest(InvalidPortID), 6288949Sandreas.hansson@arm.com bytesValidStart(0), bytesValidEnd(0), 62910405Sandreas.hansson@arm.com firstWordDelay(0), lastWordDelay(0), 6309546Sandreas.hansson@arm.com senderState(NULL) 6312813Srdreslin@umich.edu { 6326104Ssteve.reinhardt@amd.com if (req->hasPaddr()) { 6336104Ssteve.reinhardt@amd.com addr = req->getPaddr() & ~(_blkSize - 1); 6346104Ssteve.reinhardt@amd.com flags.set(VALID_ADDR); 63510028SGiacomo.Gabrielli@arm.com _isSecure = req->isSecure(); 6366104Ssteve.reinhardt@amd.com } 6376104Ssteve.reinhardt@amd.com size = _blkSize; 6386104Ssteve.reinhardt@amd.com flags.set(VALID_SIZE); 6394626Sstever@eecs.umich.edu } 6404626Sstever@eecs.umich.edu 6415735Snate@binkert.org /** 6425735Snate@binkert.org * Alternate constructor for copying a packet. Copy all fields 6434887Sstever@eecs.umich.edu * *except* if the original packet's data was dynamic, don't copy 6444887Sstever@eecs.umich.edu * that, as we can't guarantee that the new packet's lifetime is 6454887Sstever@eecs.umich.edu * less than that of the original packet. In this case the new 6465735Snate@binkert.org * packet should allocate its own data. 6475735Snate@binkert.org */ 6485735Snate@binkert.org Packet(Packet *pkt, bool clearFlags = false) 6495735Snate@binkert.org : cmd(pkt->cmd), req(pkt->req), 6505764Snate@binkert.org data(pkt->flags.isSet(STATIC_DATA) ? pkt->data : NULL), 65110028SGiacomo.Gabrielli@arm.com addr(pkt->addr), _isSecure(pkt->_isSecure), size(pkt->size), 65210028SGiacomo.Gabrielli@arm.com src(pkt->src), dest(pkt->dest), 6539547Sandreas.hansson@arm.com bytesValidStart(pkt->bytesValidStart), 6549547Sandreas.hansson@arm.com bytesValidEnd(pkt->bytesValidEnd), 65510405Sandreas.hansson@arm.com firstWordDelay(pkt->firstWordDelay), 65610405Sandreas.hansson@arm.com lastWordDelay(pkt->lastWordDelay), 6579546Sandreas.hansson@arm.com senderState(pkt->senderState) 6584626Sstever@eecs.umich.edu { 6595735Snate@binkert.org if (!clearFlags) 6605735Snate@binkert.org flags.set(pkt->flags & COPY_FLAGS); 6615735Snate@binkert.org 6629031Sandreas.hansson@arm.com flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE)); 6635735Snate@binkert.org flags.set(pkt->flags & STATIC_DATA); 66410342SCurtis.Dunham@arm.com } 6658668Sgeoffrey.blake@arm.com 66610342SCurtis.Dunham@arm.com /** 66710342SCurtis.Dunham@arm.com * Change the packet type based on request type. 66810342SCurtis.Dunham@arm.com */ 66910342SCurtis.Dunham@arm.com void 67010342SCurtis.Dunham@arm.com refineCommand() 67110342SCurtis.Dunham@arm.com { 67210342SCurtis.Dunham@arm.com if (cmd == MemCmd::ReadReq) { 67310342SCurtis.Dunham@arm.com if (req->isLLSC()) { 67410342SCurtis.Dunham@arm.com cmd = MemCmd::LoadLockedReq; 67510343SCurtis.Dunham@arm.com } else if (req->isPrefetch()) { 67610343SCurtis.Dunham@arm.com cmd = MemCmd::SoftPFReq; 67710342SCurtis.Dunham@arm.com } 67810342SCurtis.Dunham@arm.com } else if (cmd == MemCmd::WriteReq) { 67910342SCurtis.Dunham@arm.com if (req->isLLSC()) { 68010342SCurtis.Dunham@arm.com cmd = MemCmd::StoreCondReq; 68110342SCurtis.Dunham@arm.com } else if (req->isSwap()) { 68210342SCurtis.Dunham@arm.com cmd = MemCmd::SwapReq; 68310342SCurtis.Dunham@arm.com } 68410342SCurtis.Dunham@arm.com } 68510342SCurtis.Dunham@arm.com } 68610342SCurtis.Dunham@arm.com 68710342SCurtis.Dunham@arm.com /** 68810342SCurtis.Dunham@arm.com * Constructor-like methods that return Packets based on Request objects. 68910342SCurtis.Dunham@arm.com * Will call refineCommand() to fine-tune the Packet type if it's not a 69010342SCurtis.Dunham@arm.com * vanilla read or write. 69110342SCurtis.Dunham@arm.com */ 69210342SCurtis.Dunham@arm.com static PacketPtr 69310342SCurtis.Dunham@arm.com createRead(Request *req) 69410342SCurtis.Dunham@arm.com { 69510342SCurtis.Dunham@arm.com PacketPtr pkt = new Packet(req, MemCmd::ReadReq); 69610342SCurtis.Dunham@arm.com pkt->refineCommand(); 69710342SCurtis.Dunham@arm.com return pkt; 69810342SCurtis.Dunham@arm.com } 69910342SCurtis.Dunham@arm.com 70010342SCurtis.Dunham@arm.com static PacketPtr 70110342SCurtis.Dunham@arm.com createWrite(Request *req) 70210342SCurtis.Dunham@arm.com { 70310342SCurtis.Dunham@arm.com PacketPtr pkt = new Packet(req, MemCmd::WriteReq); 70410342SCurtis.Dunham@arm.com pkt->refineCommand(); 70510342SCurtis.Dunham@arm.com return pkt; 7062641Sstever@eecs.umich.edu } 7072549SN/A 7085735Snate@binkert.org /** 7095735Snate@binkert.org * clean up packet variables 7105735Snate@binkert.org */ 7112566SN/A ~Packet() 7125387Sstever@gmail.com { 7135387Sstever@gmail.com // If this is a request packet for which there's no response, 7145387Sstever@gmail.com // delete the request object here, since the requester will 7155387Sstever@gmail.com // never get the chance. 7165387Sstever@gmail.com if (req && isRequest() && !needsResponse()) 7175387Sstever@gmail.com delete req; 7185735Snate@binkert.org deleteData(); 7195387Sstever@gmail.com } 7202566SN/A 7215735Snate@binkert.org /** 7225735Snate@binkert.org * Reinitialize packet address and size from the associated 7235735Snate@binkert.org * Request object, and reset other fields that may have been 7245735Snate@binkert.org * modified by a previous transaction. Typically called when a 7255735Snate@binkert.org * statically allocated Request/Packet pair is reused for multiple 7265735Snate@binkert.org * transactions. 7275735Snate@binkert.org */ 7285735Snate@binkert.org void 7295735Snate@binkert.org reinitFromRequest() 7305735Snate@binkert.org { 7316104Ssteve.reinhardt@amd.com assert(req->hasPaddr()); 7324870Sstever@eecs.umich.edu flags = 0; 7336104Ssteve.reinhardt@amd.com addr = req->getPaddr(); 73410028SGiacomo.Gabrielli@arm.com _isSecure = req->isSecure(); 7356104Ssteve.reinhardt@amd.com size = req->getSize(); 7365735Snate@binkert.org 7379547Sandreas.hansson@arm.com src = InvalidPortID; 7389547Sandreas.hansson@arm.com dest = InvalidPortID; 7399547Sandreas.hansson@arm.com bytesValidStart = 0; 7409547Sandreas.hansson@arm.com bytesValidEnd = 0; 74110405Sandreas.hansson@arm.com firstWordDelay = 0; 74210405Sandreas.hansson@arm.com lastWordDelay = 0; 7439547Sandreas.hansson@arm.com 7445735Snate@binkert.org flags.set(VALID_ADDR|VALID_SIZE); 7455735Snate@binkert.org deleteData(); 7462662Sstever@eecs.umich.edu } 7472566SN/A 7484626Sstever@eecs.umich.edu /** 7494626Sstever@eecs.umich.edu * Take a request packet and modify it in place to be suitable for 7509030Sandreas.hansson@arm.com * returning as a response to that request. The source field is 7519030Sandreas.hansson@arm.com * turned into the destination, and subsequently cleared. Note 7529030Sandreas.hansson@arm.com * that the latter is not necessary for atomic requests, but 7539030Sandreas.hansson@arm.com * causes no harm as neither field is valid. 7544626Sstever@eecs.umich.edu */ 7555735Snate@binkert.org void 7565735Snate@binkert.org makeResponse() 7574626Sstever@eecs.umich.edu { 7582662Sstever@eecs.umich.edu assert(needsResponse()); 7592855Srdreslin@umich.edu assert(isRequest()); 7604986Ssaidi@eecs.umich.edu origCmd = cmd; 7614022Sstever@eecs.umich.edu cmd = cmd.responseCommand(); 7625745Snate@binkert.org 7637464Ssteve.reinhardt@amd.com // responses are never express, even if the snoop that 7647464Ssteve.reinhardt@amd.com // triggered them was 7657464Ssteve.reinhardt@amd.com flags.clear(EXPRESS_SNOOP); 7667464Ssteve.reinhardt@amd.com 7675745Snate@binkert.org dest = src; 76810405Sandreas.hansson@arm.com src = InvalidPortID; 7692641Sstever@eecs.umich.edu } 7702641Sstever@eecs.umich.edu 7715735Snate@binkert.org void 7725735Snate@binkert.org makeAtomicResponse() 7734870Sstever@eecs.umich.edu { 7744870Sstever@eecs.umich.edu makeResponse(); 7754870Sstever@eecs.umich.edu } 7764870Sstever@eecs.umich.edu 7775735Snate@binkert.org void 7785735Snate@binkert.org makeTimingResponse() 7793348Sbinkertn@umich.edu { 7804870Sstever@eecs.umich.edu makeResponse(); 7813135Srdreslin@umich.edu } 7823135Srdreslin@umich.edu 7838436SBrad.Beckmann@amd.com void 7848436SBrad.Beckmann@amd.com setFunctionalResponseStatus(bool success) 7858436SBrad.Beckmann@amd.com { 7868436SBrad.Beckmann@amd.com if (!success) { 7878436SBrad.Beckmann@amd.com if (isWrite()) { 7888436SBrad.Beckmann@amd.com cmd = MemCmd::FunctionalWriteError; 7898436SBrad.Beckmann@amd.com } else { 7908436SBrad.Beckmann@amd.com cmd = MemCmd::FunctionalReadError; 7918436SBrad.Beckmann@amd.com } 7928436SBrad.Beckmann@amd.com } 7938436SBrad.Beckmann@amd.com } 7948436SBrad.Beckmann@amd.com 7957006Snate@binkert.org void 7967006Snate@binkert.org setSize(unsigned size) 7977006Snate@binkert.org { 7987006Snate@binkert.org assert(!flags.isSet(VALID_SIZE)); 7997006Snate@binkert.org 8007006Snate@binkert.org this->size = size; 8017006Snate@binkert.org flags.set(VALID_SIZE); 8027006Snate@binkert.org } 8037006Snate@binkert.org 8042685Ssaidi@eecs.umich.edu 8053348Sbinkertn@umich.edu /** 8063348Sbinkertn@umich.edu * Set the data pointer to the following value that should not be 8073348Sbinkertn@umich.edu * freed. 8082566SN/A */ 8092566SN/A template <typename T> 8103348Sbinkertn@umich.edu void 8113348Sbinkertn@umich.edu dataStatic(T *p) 8123348Sbinkertn@umich.edu { 8135764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); 8143348Sbinkertn@umich.edu data = (PacketDataPtr)p; 8155735Snate@binkert.org flags.set(STATIC_DATA); 8163348Sbinkertn@umich.edu } 8172566SN/A 8183348Sbinkertn@umich.edu /** 8193348Sbinkertn@umich.edu * Set the data pointer to a value that should have delete [] 8203348Sbinkertn@umich.edu * called on it. 8213348Sbinkertn@umich.edu */ 8222566SN/A template <typename T> 8233348Sbinkertn@umich.edu void 8243348Sbinkertn@umich.edu dataDynamicArray(T *p) 8253348Sbinkertn@umich.edu { 8265764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); 8273348Sbinkertn@umich.edu data = (PacketDataPtr)p; 8285735Snate@binkert.org flags.set(DYNAMIC_DATA|ARRAY_DATA); 8293348Sbinkertn@umich.edu } 8303348Sbinkertn@umich.edu 8313348Sbinkertn@umich.edu /** 8323348Sbinkertn@umich.edu * set the data pointer to a value that should have delete called 8333348Sbinkertn@umich.edu * on it. 8343348Sbinkertn@umich.edu */ 8353348Sbinkertn@umich.edu template <typename T> 8363348Sbinkertn@umich.edu void 8373348Sbinkertn@umich.edu dataDynamic(T *p) 8383348Sbinkertn@umich.edu { 8395764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); 8403348Sbinkertn@umich.edu data = (PacketDataPtr)p; 8415735Snate@binkert.org flags.set(DYNAMIC_DATA); 8423348Sbinkertn@umich.edu } 8433348Sbinkertn@umich.edu 8445735Snate@binkert.org /** 8455735Snate@binkert.org * get a pointer to the data ptr. 8465735Snate@binkert.org */ 8473348Sbinkertn@umich.edu template <typename T> 8483348Sbinkertn@umich.edu T* 84910562Sandreas.hansson@arm.com getPtr() 8503348Sbinkertn@umich.edu { 85110562Sandreas.hansson@arm.com assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA)); 8523348Sbinkertn@umich.edu return (T*)data; 8533348Sbinkertn@umich.edu } 8542566SN/A 8555735Snate@binkert.org /** 8565735Snate@binkert.org * return the value of what is pointed to in the packet. 8575735Snate@binkert.org */ 8582566SN/A template <typename T> 8592592SN/A T get(); 8602566SN/A 8615735Snate@binkert.org /** 8625735Snate@binkert.org * set the value in the data pointer to v. 8635735Snate@binkert.org */ 8642566SN/A template <typename T> 8652592SN/A void set(T v); 8662566SN/A 8673348Sbinkertn@umich.edu /** 8684626Sstever@eecs.umich.edu * Copy data into the packet from the provided pointer. 8694626Sstever@eecs.umich.edu */ 8705735Snate@binkert.org void 8715735Snate@binkert.org setData(uint8_t *p) 8724626Sstever@eecs.umich.edu { 8737691SAli.Saidi@ARM.com if (p != getPtr<uint8_t>()) 8747691SAli.Saidi@ARM.com std::memcpy(getPtr<uint8_t>(), p, getSize()); 8754626Sstever@eecs.umich.edu } 8764626Sstever@eecs.umich.edu 8774626Sstever@eecs.umich.edu /** 8784626Sstever@eecs.umich.edu * Copy data into the packet from the provided block pointer, 8794626Sstever@eecs.umich.edu * which is aligned to the given block size. 8804626Sstever@eecs.umich.edu */ 8815735Snate@binkert.org void 8825735Snate@binkert.org setDataFromBlock(uint8_t *blk_data, int blkSize) 8834626Sstever@eecs.umich.edu { 8844626Sstever@eecs.umich.edu setData(blk_data + getOffset(blkSize)); 8854626Sstever@eecs.umich.edu } 8864626Sstever@eecs.umich.edu 8874626Sstever@eecs.umich.edu /** 8884626Sstever@eecs.umich.edu * Copy data from the packet to the provided block pointer, which 8894626Sstever@eecs.umich.edu * is aligned to the given block size. 8904626Sstever@eecs.umich.edu */ 8915735Snate@binkert.org void 8925735Snate@binkert.org writeData(uint8_t *p) 8934626Sstever@eecs.umich.edu { 8944626Sstever@eecs.umich.edu std::memcpy(p, getPtr<uint8_t>(), getSize()); 8954626Sstever@eecs.umich.edu } 8964626Sstever@eecs.umich.edu 8974626Sstever@eecs.umich.edu /** 8984626Sstever@eecs.umich.edu * Copy data from the packet to the memory at the provided pointer. 8994626Sstever@eecs.umich.edu */ 9005735Snate@binkert.org void 9015735Snate@binkert.org writeDataToBlock(uint8_t *blk_data, int blkSize) 9024626Sstever@eecs.umich.edu { 9034626Sstever@eecs.umich.edu writeData(blk_data + getOffset(blkSize)); 9044626Sstever@eecs.umich.edu } 9054626Sstever@eecs.umich.edu 9064626Sstever@eecs.umich.edu /** 9073348Sbinkertn@umich.edu * delete the data pointed to in the data pointer. Ok to call to 9083348Sbinkertn@umich.edu * matter how data was allocted. 9093348Sbinkertn@umich.edu */ 9105735Snate@binkert.org void 9115735Snate@binkert.org deleteData() 9125735Snate@binkert.org { 9135764Snate@binkert.org if (flags.isSet(ARRAY_DATA)) 9145735Snate@binkert.org delete [] data; 9155764Snate@binkert.org else if (flags.isSet(DYNAMIC_DATA)) 9165735Snate@binkert.org delete data; 9175735Snate@binkert.org 9185735Snate@binkert.org flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA); 9195735Snate@binkert.org data = NULL; 9205735Snate@binkert.org } 9212566SN/A 9222566SN/A /** If there isn't data in the packet, allocate some. */ 9235735Snate@binkert.org void 9245735Snate@binkert.org allocate() 9255735Snate@binkert.org { 9265735Snate@binkert.org if (data) { 9275764Snate@binkert.org assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA)); 9285745Snate@binkert.org return; 9295735Snate@binkert.org } 9305745Snate@binkert.org 9315764Snate@binkert.org assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); 9325745Snate@binkert.org flags.set(DYNAMIC_DATA|ARRAY_DATA); 9335745Snate@binkert.org data = new uint8_t[getSize()]; 9345735Snate@binkert.org } 9355735Snate@binkert.org 9364626Sstever@eecs.umich.edu /** 9374626Sstever@eecs.umich.edu * Check a functional request against a memory value represented 9384626Sstever@eecs.umich.edu * by a base/size pair and an associated data array. If the 9394626Sstever@eecs.umich.edu * functional request is a read, it may be satisfied by the memory 9404626Sstever@eecs.umich.edu * value. If the functional request is a write, it may update the 9414626Sstever@eecs.umich.edu * memory value. 9424626Sstever@eecs.umich.edu */ 94310028SGiacomo.Gabrielli@arm.com bool checkFunctional(Printable *obj, Addr base, bool is_secure, int size, 94410028SGiacomo.Gabrielli@arm.com uint8_t *data); 9454626Sstever@eecs.umich.edu 9464626Sstever@eecs.umich.edu /** 9474626Sstever@eecs.umich.edu * Check a functional request against a memory value stored in 9485315Sstever@gmail.com * another packet (i.e. an in-transit request or response). 9494626Sstever@eecs.umich.edu */ 9505735Snate@binkert.org bool 9515735Snate@binkert.org checkFunctional(PacketPtr other) 9525735Snate@binkert.org { 9535735Snate@binkert.org uint8_t *data = other->hasData() ? other->getPtr<uint8_t>() : NULL; 95410028SGiacomo.Gabrielli@arm.com return checkFunctional(other, other->getAddr(), other->isSecure(), 95510028SGiacomo.Gabrielli@arm.com other->getSize(), data); 9564626Sstever@eecs.umich.edu } 9575314Sstever@gmail.com 9585315Sstever@gmail.com /** 9595315Sstever@gmail.com * Push label for PrintReq (safe to call unconditionally). 9605315Sstever@gmail.com */ 9615735Snate@binkert.org void 9625735Snate@binkert.org pushLabel(const std::string &lbl) 9635735Snate@binkert.org { 9645735Snate@binkert.org if (isPrint()) 9655735Snate@binkert.org safe_cast<PrintReqState*>(senderState)->pushLabel(lbl); 9665314Sstever@gmail.com } 9675314Sstever@gmail.com 9685315Sstever@gmail.com /** 9695315Sstever@gmail.com * Pop label for PrintReq (safe to call unconditionally). 9705315Sstever@gmail.com */ 9715735Snate@binkert.org void 9725735Snate@binkert.org popLabel() 9735735Snate@binkert.org { 9745735Snate@binkert.org if (isPrint()) 9755735Snate@binkert.org safe_cast<PrintReqState*>(senderState)->popLabel(); 9765314Sstever@gmail.com } 9775314Sstever@gmail.com 9785314Sstever@gmail.com void print(std::ostream &o, int verbosity = 0, 9795314Sstever@gmail.com const std::string &prefix = "") const; 9809663Suri.wiener@arm.com 9819663Suri.wiener@arm.com /** 9829663Suri.wiener@arm.com * A no-args wrapper of print(std::ostream...) 9839663Suri.wiener@arm.com * meant to be invoked from DPRINTFs 9849663Suri.wiener@arm.com * avoiding string overheads in fast mode 9859663Suri.wiener@arm.com * @return string with the request's type and start<->end addresses 9869663Suri.wiener@arm.com */ 9879663Suri.wiener@arm.com std::string print() const; 9882381SN/A}; 9892381SN/A 9902381SN/A#endif //__MEM_PACKET_HH 991