ruby: added Packet interface to makeRequest and isReady.
[gem5.git] / src / mem / bridge.hh
index 37fb92662e1781d9f5cf1be9ece4987ad74bbfbd..40f033811277e5ac453b4807680045d1d2be0d94 100644 (file)
@@ -30,7 +30,8 @@
  */
 
 /**
- * @file Decleration of a simple bus bridge object with no buffering
+ * @file
+ * Declaration of a simple bus bridge object with no buffering
  */
 
 #ifndef __MEM_BRIDGE_HH__
 #include <inttypes.h>
 #include <queue>
 
+#include "base/fast_alloc.hh"
 #include "mem/mem_object.hh"
 #include "mem/packet.hh"
 #include "mem/port.hh"
+#include "params/Bridge.hh"
 #include "sim/eventq.hh"
 
 class Bridge : public MemObject
 {
   protected:
-    /** Decleration of the buses port type, one will be instantiated for each
+    /** Declaration of the buses port type, one will be instantiated for each
         of the interfaces connecting to the bus. */
     class BridgePort : public Port
     {
@@ -65,25 +68,34 @@ class Bridge : public MemObject
         /** Minimum delay though this bridge. */
         Tick delay;
 
-        class PacketBuffer : public Packet::SenderState {
+        /** Min delay to respond to a nack. */
+        Tick nackDelay;
+
+        /** Pass ranges from one side of the bridge to the other? */
+        std::vector<Range<Addr> > filterRanges;
+
+        class PacketBuffer : public Packet::SenderState, public FastAlloc {
 
           public:
             Tick ready;
-            Packet *pkt;
+            PacketPtr pkt;
+            bool nackedHere;
             Packet::SenderState *origSenderState;
             short origSrc;
             bool expectResponse;
 
-            PacketBuffer(Packet *_pkt, Tick t)
-                : ready(t), pkt(_pkt),
-                  origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
-                  expectResponse(_pkt->needsResponse())
+            PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
+                : ready(t), pkt(_pkt), nackedHere(nack),
+                  origSenderState(_pkt->senderState),
+                  origSrc(nack ? _pkt->getDest() : _pkt->getSrc() ),
+                  expectResponse(_pkt->needsResponse() && !nack)
+
             {
-                if (!pkt->isResponse())
+                if (!pkt->isResponse() && !nack)
                     pkt->senderState = this;
             }
 
-            void fixResponse(Packet *pkt)
+            void fixResponse(PacketPtr pkt)
             {
                 assert(pkt->senderState == this);
                 pkt->setDest(origSrc);
@@ -99,19 +111,29 @@ class Bridge : public MemObject
         std::list<PacketBuffer*> sendQueue;
 
         int outstandingResponses;
+        int queuedRequests;
+
+        /** If we're waiting for a retry to happen.*/
+        bool inRetry;
 
         /** Max queue size for outbound packets */
-        int queueLimit;
+        int reqQueueLimit;
+
+        /** Max queue size for reserved responses. */
+        int respQueueLimit;
 
         /**
          * Is this side blocked from accepting outbound packets?
          */
-        bool queueFull() { return (sendQueue.size() == queueLimit); }
+        bool respQueueFull();
+        bool reqQueueFull();
 
-        bool queueForSendTiming(Packet *pkt);
+        void queueForSendTiming(PacketPtr pkt);
 
         void finishSend(PacketBuffer *buf);
 
+        void nackRequest(PacketPtr pkt);
+
         /**
          * Handle send event, scheduled when the packet at the head of
          * the outbound queue is ready to transmit (for timing
@@ -124,28 +146,25 @@ class Bridge : public MemObject
             BridgePort *port;
 
           public:
-            SendEvent(BridgePort *p)
-                : Event(&mainEventQueue), port(p) {}
-
+            SendEvent(BridgePort *p) : port(p) {}
             virtual void process() { port->trySend(); }
-
-            virtual const char *description() { return "bridge send event"; }
+            virtual const char *description() const { return "bridge send"; }
         };
 
         SendEvent sendEvent;
 
       public:
-
         /** Constructor for the BusPort.*/
-        BridgePort(const std::string &_name,
-                   Bridge *_bridge, BridgePort *_otherPort,
-                   int _delay, int _queueLimit);
+        BridgePort(const std::string &_name, Bridge *_bridge,
+                BridgePort *_otherPort, int _delay, int _nack_delay,
+                int _req_limit, int _resp_limit,
+                std::vector<Range<Addr> > filter_ranges);
 
       protected:
 
         /** When receiving a timing request from the peer port,
             pass it to the bridge. */
-        virtual bool recvTiming(Packet *pkt);
+        virtual bool recvTiming(PacketPtr pkt);
 
         /** When receiving a retry request from the peer port,
             pass it to the bridge. */
@@ -153,11 +172,11 @@ class Bridge : public MemObject
 
         /** When receiving a Atomic requestfrom the peer port,
             pass it to the bridge. */
-        virtual Tick recvAtomic(Packet *pkt);
+        virtual Tick recvAtomic(PacketPtr pkt);
 
         /** When receiving a Functional request from the peer port,
             pass it to the bridge. */
-        virtual void recvFunctional(Packet *pkt);
+        virtual void recvFunctional(PacketPtr pkt);
 
         /** When receiving a status changefrom the peer port,
             pass it to the bridge. */
@@ -166,7 +185,7 @@ class Bridge : public MemObject
         /** When receiving a address range request the peer port,
             pass it to the bridge. */
         virtual void getDeviceAddressRanges(AddrRangeList &resp,
-                                            AddrRangeList &snoop);
+                                            bool &snoop);
     };
 
     BridgePort portA, portB;
@@ -175,13 +194,20 @@ class Bridge : public MemObject
     bool ackWrites;
 
   public:
+    typedef BridgeParams Params;
+
+  protected:
+    Params *_params;
+
+  public:
+    const Params *params() const { return _params; }
 
     /** A function used to return the port associated with this bus object. */
-    virtual Port *getPort(const std::string &if_name);
+    virtual Port *getPort(const std::string &if_name, int idx = -1);
 
     virtual void init();
 
-    Bridge(const std::string &n, int qsa, int qsb, Tick _delay, int write_ack);
+    Bridge(Params *p);
 };
 
 #endif //__MEM_BUS_HH__