2 * Copyright (c) 2012 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 #ifndef __MEM_PACKET_QUEUE_HH__
45 #define __MEM_PACKET_QUEUE_HH__
49 * Declaration of a simple PacketQueue that is associated with
50 * a port on which it attempts to send packets according to the time
51 * stamp given to them at insertion. The packet queue is responsible
52 * for the flow control of the port, but relies on the module
53 * notifying the queue when a transfer ends.
58 #include "mem/port.hh"
59 #include "sim/drain.hh"
60 #include "sim/eventq_impl.hh"
63 * A packet queue is a class that holds deferred packets and later
64 * sends them using the associated slave port or master port.
66 class PacketQueue : public Drainable
69 /** A deferred packet, buffered to transmit later. */
70 class DeferredPacket {
72 Tick tick; ///< The tick when the packet is ready to transmit
73 PacketPtr pkt; ///< Pointer to the packet to transmit
74 bool sendAsSnoop; ///< Should it be sent as a snoop or not
75 DeferredPacket(Tick t, PacketPtr p, bool send_as_snoop)
76 : tick(t), pkt(p), sendAsSnoop(send_as_snoop)
80 typedef std::list<DeferredPacket> DeferredPacketList;
81 typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
83 /** A list of outgoing timing response packets that haven't been
85 DeferredPacketList transmitList;
87 /** The manager which is used for the event queue */
90 /** This function attempts to send deferred packets. Scheduled to
91 * be called in the future via SendEvent. */
92 void processSendEvent();
95 * Event used to call processSendEvent.
97 EventWrapper<PacketQueue, &PacketQueue::processSendEvent> sendEvent;
99 /** If we need to drain, keep the drain manager around until we're done
101 DrainManager *drainManager;
105 /** Label to use for print request packets label stack. */
106 const std::string label;
108 /** Remember whether we're awaiting a retry from the bus. */
111 /** Check whether we have a packet ready to go on the transmit list. */
112 bool deferredPacketReady()
113 { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
115 Tick deferredPacketReadyTime()
116 { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
119 * Attempt to send the packet at the head of the transmit
120 * list. Caller must guarantee that the list is non-empty and that
121 * the head packet is scheduled for curTick() (or earlier). Note
122 * that a subclass of the PacketQueue can override this method and
123 * thus change the behaviour (as done by the cache).
125 virtual void sendDeferredPacket();
128 * Attempt to send the packet at the front of the transmit list,
129 * and set waitingOnRetry accordingly. The packet is temporarily
130 * taken off the list, but put back at the front if not
133 void trySendTiming();
138 virtual bool sendTiming(PacketPtr pkt, bool send_as_snoop) = 0;
141 * Based on the transmit list, or the provided time, schedule a
142 * send event if there are packets to send. If we are idle and
143 * asked to drain then do so.
145 * @param time an alternative time for the next send event
147 void scheduleSend(Tick time = MaxTick);
150 * Simple ports are generally used as slave ports (i.e. the
151 * respond to requests) and thus do not expect to receive any
152 * range changes (as the neighbouring port has a master role and
153 * do not have any address ranges. A subclass can override the
154 * default behaviuor if needed.
156 virtual void recvRangeChange() { }
159 * Create a packet queue, linked to an event manager, and a label
160 * that will be used for functional print request packets.
162 * @param _em Event manager used for scheduling this queue
163 * @param _label Label to push on the label stack for print request packets
165 PacketQueue(EventManager& _em, const std::string& _label);
168 * Virtual desctructor since the class may be used as a base class.
170 virtual ~PacketQueue();
175 * Provide a name to simplify debugging.
177 * @return A complete name, appended to module and port
179 virtual const std::string name() const = 0;
181 /** Check the list of buffered packets against the supplied
182 * functional request. */
183 bool checkFunctional(PacketPtr pkt);
186 * Schedule a send even if not already waiting for a retry. If the
187 * requested time is before an already scheduled send event it
188 * will be rescheduled.
192 void schedSendEvent(Tick when);
195 * Add a packet to the transmit list, and ensure that a
196 * processSendEvent is called in the future.
198 * @param pkt Packet to send
199 * @param when Absolute time (in ticks) to send packet
200 * @param send_as_snoop Send the packet as a snoop or not
202 void schedSendTiming(PacketPtr pkt, Tick when, bool send_as_snoop = false);
205 * Used by a port to notify the queue that a retry was received
206 * and that the queue can proceed and retry sending the packet
207 * that caused the wait.
211 unsigned int drain(DrainManager *dm);
214 class MasterPacketQueue : public PacketQueue
219 MasterPort& masterPort;
224 * Create a master packet queue, linked to an event manager, a
225 * master port, and a label that will be used for functional print
228 * @param _em Event manager used for scheduling this queue
229 * @param _masterPort Master port used to send the packets
230 * @param _label Label to push on the label stack for print request packets
232 MasterPacketQueue(EventManager& _em, MasterPort& _masterPort,
233 const std::string _label = "MasterPacketQueue");
235 virtual ~MasterPacketQueue() { }
237 const std::string name() const
238 { return masterPort.name() + "-" + label; }
240 bool sendTiming(PacketPtr pkt, bool send_as_snoop);
243 class SlavePacketQueue : public PacketQueue
248 SlavePort& slavePort;
253 * Create a slave packet queue, linked to an event manager, a
254 * slave port, and a label that will be used for functional print
257 * @param _em Event manager used for scheduling this queue
258 * @param _slavePort Slave port used to send the packets
259 * @param _label Label to push on the label stack for print request packets
261 SlavePacketQueue(EventManager& _em, SlavePort& _slavePort,
262 const std::string _label = "SlavePacketQueue");
264 virtual ~SlavePacketQueue() { }
266 const std::string name() const
267 { return slavePort.name() + "-" + label; }
269 bool sendTiming(PacketPtr pkt, bool send_as_snoop);
273 #endif // __MEM_PACKET_QUEUE_HH__