- /** Constructor for the BusPort.*/
- BusPort(const std::string &_name, Bus *_bus, int _id)
- : Port(_name, _bus), _onRetryList(false), bus(_bus), id(_id)
- { }
-
- bool onRetryList()
- { return _onRetryList; }
-
- void onRetryList(bool newVal)
- { _onRetryList = newVal; }
-
- int getId() { return id; }
-
- protected:
-
- /** When reciving a timing request from the peer port (at id),
- pass it to the bus. */
- virtual bool recvTiming(PacketPtr pkt)
- { pkt->setSrc(id); return bus->recvTiming(pkt); }
-
- /** When reciving a Atomic requestfrom the peer port (at id),
- pass it to the bus. */
- virtual Tick recvAtomic(PacketPtr pkt)
- { pkt->setSrc(id); return bus->recvAtomic(pkt); }
-
- /** When reciving a Functional requestfrom the peer port (at id),
- pass it to the bus. */
- virtual void recvFunctional(PacketPtr pkt)
- { pkt->setSrc(id); bus->recvFunctional(pkt); }
-
- /** When reciving a status changefrom the peer port (at id),
- pass it to the bus. */
- virtual void recvStatusChange(Status status)
- { bus->recvStatusChange(status, id); }
-
- /** When reciving a retry from the peer port (at id),
- pass it to the bus. */
- virtual void recvRetry()
- { bus->recvRetry(id); }
-
- // This should return all the 'owned' addresses that are
- // downstream from this bus, yes? That is, the union of all
- // the 'owned' address ranges of all the other interfaces on
- // this bus...
- virtual void getDeviceAddressRanges(AddrRangeList &resp,
- bool &snoop)
- { bus->addressRanges(resp, snoop, id); }
-
- // Ask the bus to ask everyone on the bus what their block size is and
- // take the max of it. This might need to be changed a bit if we ever
- // support multiple block sizes.
- virtual int deviceBlockSize()
- { return bus->findBlockSize(id); }
+ /**
+ * Create a bus layer and give it a name. The bus layer uses
+ * the bus an event manager.
+ *
+ * @param _bus the bus this layer belongs to
+ * @param _name the layer's name
+ */
+ Layer(BaseBus& _bus, const std::string& _name);
+
+ /**
+ * Drain according to the normal semantics, so that the bus
+ * can tell the layer to drain, and pass an event to signal
+ * back when drained.
+ *
+ * @param de drain event to call once drained
+ *
+ * @return 1 if busy or waiting to retry, or 0 if idle
+ */
+ unsigned int drain(DrainManager *dm);
+
+ /**
+ * Get the bus layer's name
+ */
+ const std::string name() const { return bus.name() + _name; }
+
+
+ /**
+ * Determine if the bus layer accepts a packet from a specific
+ * port. If not, the port in question is also added to the
+ * retry list. In either case the state of the layer is updated
+ * accordingly.
+ *
+ * @param port Source port resenting the packet
+ *
+ * @return True if the bus layer accepts the packet
+ */
+ bool tryTiming(PortClass* port);
+
+ /**
+ * Deal with a destination port accepting a packet by potentially
+ * removing the source port from the retry list (if retrying) and
+ * occupying the bus layer accordingly.
+ *
+ * @param busy_time Time to spend as a result of a successful send
+ */
+ void succeededTiming(Tick busy_time);
+
+ /**
+ * Deal with a destination port not accepting a packet by
+ * potentially adding the source port to the retry list (if
+ * not already at the front) and occupying the bus layer
+ * accordingly.
+ *
+ * @param busy_time Time to spend as a result of a failed send
+ */
+ void failedTiming(PortClass* port, Tick busy_time);
+
+ /** Occupy the bus layer until until */
+ void occupyLayer(Tick until);
+
+ /**
+ * Send a retry to the port at the head of the retryList. The
+ * caller must ensure that the list is not empty.
+ */
+ void retryWaiting();
+
+ /**
+ * Handler a retry from a neighbouring module. Eventually this
+ * should be all encapsulated in the bus. This wraps
+ * retryWaiting by verifying that there are ports waiting
+ * before calling retryWaiting.
+ */
+ void recvRetry();
+
+ private:
+
+ /** The bus this layer is a part of. */
+ BaseBus& bus;
+
+ /** A name for this layer. */
+ std::string _name;
+
+ /**
+ * We declare an enum to track the state of the bus layer. The
+ * starting point is an idle state where the bus layer is
+ * waiting for a packet to arrive. Upon arrival, the bus layer
+ * transitions to the busy state, where it remains either
+ * until the packet transfer is done, or the header time is
+ * spent. Once the bus layer leaves the busy state, it can
+ * either go back to idle, if no packets have arrived while it
+ * was busy, or the bus layer goes on to retry the first port
+ * on the retryList. A similar transition takes place from
+ * idle to retry if the bus layer receives a retry from one of
+ * its connected ports. The retry state lasts until the port
+ * in questions calls sendTiming and returns control to the
+ * bus layer, or goes to a busy state if the port does not
+ * immediately react to the retry by calling sendTiming.
+ */
+ enum State { IDLE, BUSY, RETRY };
+
+ /** track the state of the bus layer */
+ State state;
+
+ /** manager to signal when drained */
+ DrainManager *drainManager;
+
+ /**
+ * An array of ports that retry should be called
+ * on because the original send failed for whatever reason.
+ */
+ std::deque<PortClass*> retryList;
+
+ /**
+ * Release the bus layer after being occupied and return to an
+ * idle state where we proceed to send a retry to any
+ * potential waiting port, or drain if asked to do so.
+ */
+ void releaseLayer();
+
+ /** event used to schedule a release of the layer */
+ EventWrapper<Layer, &Layer::releaseLayer> releaseEvent;