/*
+ * Copyright (c) 2012-2013 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
* Copyright (c) 2006 The Regents of The University of Michigan
* Copyright (c) 2010 Advanced Micro Devices, Inc.
* All rights reserved.
* Authors: Ron Dreslinski
* Steve Reinhardt
* Ali Saidi
+ * Andreas Hansson
*/
/**
#include "base/cast.hh"
#include "base/compiler.hh"
-#include "base/fast_alloc.hh"
#include "base/flags.hh"
#include "base/misc.hh"
#include "base/printable.hh"
HardPFReq,
SoftPFResp,
HardPFResp,
+ // WriteInvalidateReq transactions used to be generated by the
+ // DMA ports when writing full blocks to memory, however, it
+ // is not used anymore since we put the I/O cache in place to
+ // deal with partial block writes. Hence, WriteInvalidateReq
+ // and WriteInvalidateResp are currently unused. The
+ // implication is that the I/O cache does read-exclusive
+ // operations on every full-cache-block DMA, and ultimately
+ // this needs to be fixed.
WriteInvalidateReq,
WriteInvalidateResp,
UpgradeReq,
// @TODO these should be classified as responses rather than
// requests; coding them as requests initially for backwards
// compatibility
- NetworkNackError, // nacked at network layer (not by protocol)
InvalidDestError, // packet dest field invalid
BadAddressError, // memory address invalid
FunctionalReadError, // unable to fulfill functional read
IsRead, //!< Data flows from responder to requester
IsWrite, //!< Data flows from requester to responder
IsUpgrade,
- IsPrefetch, //!< Not a demand access
IsInvalidate,
NeedsExclusive, //!< Requires exclusive copy to complete in-cache
IsRequest, //!< Issued by requester
* ultimate destination and back, possibly being conveyed by several
* different Packets along the way.)
*/
-class Packet : public FastAlloc, public Printable
+class Packet : public Printable
{
public:
typedef uint32_t FlagsType;
typedef ::Flags<FlagsType> Flags;
- typedef short NodeID;
private:
static const FlagsType PUBLIC_FLAGS = 0x00000000;
/// Are the 'addr' and 'size' fields valid?
static const FlagsType VALID_ADDR = 0x00000100;
static const FlagsType VALID_SIZE = 0x00000200;
- /// Is the 'src' field valid?
- static const FlagsType VALID_SRC = 0x00000400;
- static const FlagsType VALID_DST = 0x00000800;
/// Is the data pointer set to a value that shouldn't be freed
/// when the packet is destroyed?
static const FlagsType STATIC_DATA = 0x00001000;
unsigned size;
/**
- * Device address (e.g., bus ID) of the source of the
- * transaction. The source is not responsible for setting this
- * field; it is set implicitly by the interconnect when the packet
- * is first sent.
+ * Source port identifier set on a request packet to enable
+ * appropriate routing of the responses. The source port
+ * identifier is set by any multiplexing component, e.g. a bus, as
+ * the timing responses need this information to be routed back to
+ * the appropriate port at a later point in time. The field can be
+ * updated (over-written) as the request packet passes through
+ * additional multiplexing components, and it is their
+ * responsibility to remember the original source port identifier,
+ * for example by using an appropriate sender state. The latter is
+ * done in the cache and bridge.
*/
- NodeID src;
+ PortID src;
/**
- * Device address (e.g., bus ID) of the destination of the
- * transaction. The special value Broadcast indicates that the
- * packet should be routed based on its address. This field is
- * initialized in the constructor and is thus always valid (unlike
- * addr, size, and src).
+ * Destination port identifier that is present on all response
+ * packets that passed through a multiplexing component as a
+ * request packet. The source port identifier is turned into a
+ * destination port identifier when the packet is turned into a
+ * response, and the destination is used, e.g. by the bus, to
+ * select the appropriate path through the interconnect.
*/
- NodeID dest;
+ PortID dest;
/**
* The original value of the command field. Only valid when the
/// The time at which the first chunk of the packet will be transmitted
Tick firstWordTime;
- /// The special destination address indicating that the packet
- /// should be routed based on its address.
- static const NodeID Broadcast = -1;
-
/**
* A virtual base opaque structure used to hold state associated
- * with the packet but specific to the sending device (e.g., an
- * MSHR). A pointer to this state is returned in the packet's
- * response so that the sender can quickly look up the state
- * needed to process it. A specific subclass would be derived
- * from this to carry state specific to a particular sending
- * device.
+ * with the packet (e.g., an MSHR), specific to a MemObject that
+ * sees the packet. A pointer to this state is returned in the
+ * packet's response so that the MemObject in question can quickly
+ * look up the state needed to process it. A specific subclass
+ * would be derived from this to carry state specific to a
+ * particular sending device.
+ *
+ * As multiple MemObjects may add their SenderState throughout the
+ * memory system, the SenderStates create a stack, where a
+ * MemObject can add a new Senderstate, as long as the
+ * predecessing SenderState is restored when the response comes
+ * back. For this reason, the predecessor should always be
+ * populated with the current SenderState of a packet before
+ * modifying the senderState field in the request packet.
*/
struct SenderState
{
+ SenderState* predecessor;
+ SenderState() : predecessor(NULL) {}
virtual ~SenderState() {}
};
* Object used to maintain state of a PrintReq. The senderState
* field of a PrintReq should always be of this type.
*/
- class PrintReqState : public SenderState, public FastAlloc
+ class PrintReqState : public SenderState
{
private:
/**
* This packet's sender state. Devices should use dynamic_cast<>
* to cast to the state appropriate to the sender. The intent of
* this variable is to allow a device to attach extra information
- * to a request. A response packet must return the sender state
+ * to a request. A response packet must return the sender state
* that was attached to the original request (even if a new packet
* is created).
*/
SenderState *senderState;
+ /**
+ * Push a new sender state to the packet and make the current
+ * sender state the predecessor of the new one. This should be
+ * prefered over direct manipulation of the senderState member
+ * variable.
+ *
+ * @param sender_state SenderState to push at the top of the stack
+ */
+ void pushSenderState(SenderState *sender_state);
+
+ /**
+ * Pop the top of the state stack and return a pointer to it. This
+ * assumes the current sender state is not NULL. This should be
+ * preferred over direct manipulation of the senderState member
+ * variable.
+ *
+ * @return The current top of the stack
+ */
+ SenderState *popSenderState();
+
/// Return the string name of the cmd field (for debugging and
/// tracing).
const std::string &cmdString() const { return cmd.toString(); }
// Network error conditions... encapsulate them as methods since
// their encoding keeps changing (from result field to command
// field, etc.)
- void
- setNacked()
- {
- assert(isResponse());
- cmd = MemCmd::NetworkNackError;
- }
-
void
setBadAddress()
{
cmd = MemCmd::BadAddressError;
}
- bool wasNacked() const { return cmd == MemCmd::NetworkNackError; }
bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; }
void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
- bool isSrcValid() { return flags.isSet(VALID_SRC); }
+ bool isSrcValid() const { return src != InvalidPortID; }
/// Accessor function to get the source index of the packet.
- NodeID getSrc() const { assert(flags.isSet(VALID_SRC)); return src; }
+ PortID getSrc() const { assert(isSrcValid()); return src; }
/// Accessor function to set the source index of the packet.
- void setSrc(NodeID _src) { src = _src; flags.set(VALID_SRC); }
+ void setSrc(PortID _src) { src = _src; }
/// Reset source field, e.g. to retransmit packet on different bus.
- void clearSrc() { flags.clear(VALID_SRC); }
+ void clearSrc() { src = InvalidPortID; }
- bool isDestValid() { return flags.isSet(VALID_DST); }
+ bool isDestValid() const { return dest != InvalidPortID; }
/// Accessor function for the destination index of the packet.
- NodeID getDest() const { assert(flags.isSet(VALID_DST)); return dest; }
+ PortID getDest() const { assert(isDestValid()); return dest; }
/// Accessor function to set the destination index of the packet.
- void setDest(NodeID _dest) { dest = _dest; flags.set(VALID_DST); }
+ void setDest(PortID _dest) { dest = _dest; }
+ /// Reset destination field, e.g. to turn a response into a request again.
+ void clearDest() { dest = InvalidPortID; }
Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; }
+ /**
+ * Update the address of this packet mid-transaction. This is used
+ * by the address mapper to change an already set address to a new
+ * one based on the system configuration. It is intended to remap
+ * an existing address, so it asserts that the current address is
+ * valid.
+ */
+ void setAddr(Addr _addr) { assert(flags.isSet(VALID_ADDR)); addr = _addr; }
+
unsigned getSize() const { assert(flags.isSet(VALID_SIZE)); return size; }
Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); }
/**
* Constructor. Note that a Request object must be constructed
* first, but the Requests's physical address and size fields need
- * not be valid. The command and destination addresses must be
- * supplied.
+ * not be valid. The command must be supplied.
*/
- Packet(Request *_req, MemCmd _cmd, NodeID _dest)
- : flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
- dest(_dest), bytesValidStart(0), bytesValidEnd(0),
+ Packet(Request *_req, MemCmd _cmd)
+ : cmd(_cmd), req(_req), data(NULL),
+ src(InvalidPortID), dest(InvalidPortID),
+ bytesValidStart(0), bytesValidEnd(0),
time(curTick()), senderState(NULL)
{
if (req->hasPaddr()) {
* a request that is for a whole block, not the address from the
* req. this allows for overriding the size/addr of the req.
*/
- Packet(Request *_req, MemCmd _cmd, NodeID _dest, int _blkSize)
- : flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
- dest(_dest), bytesValidStart(0), bytesValidEnd(0),
+ Packet(Request *_req, MemCmd _cmd, int _blkSize)
+ : cmd(_cmd), req(_req), data(NULL),
+ src(InvalidPortID), dest(InvalidPortID),
+ bytesValidStart(0), bytesValidEnd(0),
time(curTick()), senderState(NULL)
{
if (req->hasPaddr()) {
if (!clearFlags)
flags.set(pkt->flags & COPY_FLAGS);
- flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE|VALID_SRC|VALID_DST));
+ flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE));
flags.set(pkt->flags & STATIC_DATA);
}
/**
* Take a request packet and modify it in place to be suitable for
- * returning as a response to that request. The source and
- * destination fields are *not* modified, as is appropriate for
- * atomic accesses.
+ * returning as a response to that request. The source field is
+ * turned into the destination, and subsequently cleared. Note
+ * that the latter is not necessary for atomic requests, but
+ * causes no harm as neither field is valid.
*/
void
makeResponse()
flags.clear(EXPRESS_SNOOP);
dest = src;
- flags.set(VALID_DST, flags.isSet(VALID_SRC));
- flags.clear(VALID_SRC);
+ clearSrc();
}
void
}
}
- /**
- * Take a request packet that has been returned as NACKED and
- * modify it so that it can be sent out again. Only packets that
- * need a response can be NACKED, so verify that that is true.
- */
- void
- reinitNacked()
- {
- assert(wasNacked());
- cmd = origCmd;
- assert(needsResponse());
- setDest(Broadcast);
- }
-
void
setSize(unsigned size)
{