mem: Fix guest corruption when caches handle uncacheable accesses
[gem5.git] / src / mem / packet.hh
index 50a6f3d5a35076bfdfa6118608570b34c5b3ffd6..fbcf185ccb7e35230fac333b155ae58e72151047 100644 (file)
@@ -41,6 +41,7 @@
  * Authors: Ron Dreslinski
  *          Steve Reinhardt
  *          Ali Saidi
+ *          Andreas Hansson
  */
 
 /**
@@ -57,7 +58,6 @@
 
 #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"
@@ -120,7 +120,6 @@ class MemCmd
         // @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
@@ -226,12 +225,11 @@ class MemCmd
  * 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;
@@ -250,9 +248,6 @@ class Packet : public FastAlloc, public Printable
     /// 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;
@@ -306,7 +301,7 @@ class Packet : public FastAlloc, public Printable
      * for example by using an appropriate sender state. The latter is
      * done in the cache and bridge.
      */
-    NodeID src;
+    PortID src;
 
     /**
      * Destination port identifier that is present on all response
@@ -316,7 +311,7 @@ class Packet : public FastAlloc, public Printable
      * 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
@@ -361,7 +356,7 @@ class Packet : public FastAlloc, public Printable
      * 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:
         /**
@@ -469,13 +464,6 @@ class Packet : public FastAlloc, public Printable
     // 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()
     {
@@ -483,27 +471,35 @@ class Packet : public FastAlloc, public Printable
         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() { flags.clear(VALID_DST); }
+    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); }
 
@@ -538,6 +534,7 @@ class Packet : public FastAlloc, public Printable
      */
     Packet(Request *_req, MemCmd _cmd)
         :  cmd(_cmd), req(_req), data(NULL),
+           src(InvalidPortID), dest(InvalidPortID),
            bytesValidStart(0), bytesValidEnd(0),
            time(curTick()), senderState(NULL)
     {
@@ -558,6 +555,7 @@ class Packet : public FastAlloc, public Printable
      */
     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)
     {
@@ -586,7 +584,7 @@ class Packet : public FastAlloc, public Printable
         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);
 
     }
@@ -644,8 +642,7 @@ class Packet : public FastAlloc, public Printable
         flags.clear(EXPRESS_SNOOP);
 
         dest = src;
-        flags.set(VALID_DST, flags.isSet(VALID_SRC));
-        flags.clear(VALID_SRC);
+        clearSrc();
     }
 
     void
@@ -672,20 +669,6 @@ class Packet : public FastAlloc, public Printable
         }
     }
 
-    /**
-     * 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());
-        clearDest();
-    }
-
     void
     setSize(unsigned size)
     {