2 * Copyright (c) 2011 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.
47 * Declaration of a memory-mapped bus bridge that connects a master
48 * and a slave through a request and response queue.
51 #ifndef __MEM_BRIDGE_HH__
52 #define __MEM_BRIDGE_HH__
58 #include "base/fast_alloc.hh"
59 #include "base/types.hh"
60 #include "mem/mem_object.hh"
61 #include "mem/packet.hh"
62 #include "mem/port.hh"
63 #include "params/Bridge.hh"
64 #include "sim/eventq.hh"
67 * A bridge is used to interface two different busses (or in general a
68 * memory-mapped master and slave), with buffering for requests and
69 * responses. The bridge has a fixed delay for packets passing through
70 * it and responds to a fixed set of address ranges.
72 * The bridge comprises a slave port and a master port, that buffer
73 * outgoing responses and requests respectively. Buffer space is
74 * reserved when a request arrives, also reserving response space
75 * before forwarding the request. An incoming request is always
76 * accepted (recvTiming returns true), but is potentially NACKed if
77 * there is no request space or response space.
79 class Bridge : public MemObject
84 * A packet buffer stores packets along with their sender state
85 * and scheduled time for transmission.
87 class PacketBuffer : public Packet::SenderState, public FastAlloc {
93 Packet::SenderState *origSenderState;
97 PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
98 : ready(t), pkt(_pkt), nackedHere(nack),
99 origSenderState(_pkt->senderState),
100 origSrc(nack ? _pkt->getDest() : _pkt->getSrc() ),
101 expectResponse(_pkt->needsResponse() && !nack)
104 if (!pkt->isResponse() && !nack)
105 pkt->senderState = this;
108 void fixResponse(PacketPtr pkt)
110 assert(pkt->senderState == this);
111 pkt->setDest(origSrc);
112 pkt->senderState = origSenderState;
116 // Forward declaration to allow the slave port to have a pointer
117 class BridgeMasterPort;
120 * The port on the side that receives requests and sends
121 * responses. The slave port has a set of address ranges that it
122 * is responsible for. The slave port also has a buffer for the
123 * responses not yet sent.
125 class BridgeSlavePort : public Port
130 /** A pointer to the bridge to which this port belongs. */
134 * Pointer to the master port on the other side of the bridge
135 * (connected to the other bus).
137 BridgeMasterPort* masterPort;
139 /** Minimum request delay though this bridge. */
142 /** Min delay to respond with a nack. */
145 /** Address ranges to pass through the bridge */
146 AddrRangeList ranges;
149 * Response packet queue. Response packets are held in this
150 * queue for a specified delay to model the processing delay
153 std::list<PacketBuffer*> responseQueue;
155 /** Counter to track the outstanding responses. */
156 unsigned int outstandingResponses;
158 /** If we're waiting for a retry to happen. */
161 /** Max queue size for reserved responses. */
162 unsigned int respQueueLimit;
165 * Is this side blocked from accepting new response packets.
167 * @return true if the reserved space has reached the set limit
169 bool respQueueFull();
172 * Turn the request packet into a NACK response and put it in
173 * the response queue and schedule its transmission.
175 * @param pkt the request packet to NACK
177 void nackRequest(PacketPtr pkt);
180 * Handle send event, scheduled when the packet at the head of
181 * the response queue is ready to transmit (for timing
187 * Private class for scheduling sending of responses from the
190 class SendEvent : public Event
192 BridgeSlavePort *port;
195 SendEvent(BridgeSlavePort *p) : port(p) {}
196 virtual void process() { port->trySend(); }
197 virtual const char *description() const { return "bridge send"; }
200 /** Send event for the response queue. */
206 * Constructor for the BridgeSlavePort.
208 * @param _name the port name including the owner
209 * @param _bridge the structural owner
210 * @param _masterPort the master port on the other side of the bridge
211 * @param _delay the delay from seeing a response to sending it
212 * @param _nack_delay the delay from a NACK to sending the response
213 * @param _resp_limit the size of the response queue
214 * @param _ranges a number of address ranges to forward
216 BridgeSlavePort(const std::string &_name, Bridge *_bridge,
217 BridgeMasterPort* _masterPort, int _delay,
218 int _nack_delay, int _resp_limit,
219 std::vector<Range<Addr> > _ranges);
222 * Queue a response packet to be sent out later and also schedule
223 * a send if necessary.
225 * @param pkt a response to send out after a delay
227 void queueForSendTiming(PacketPtr pkt);
231 /** When receiving a timing request from the peer port,
232 pass it to the bridge. */
233 virtual bool recvTiming(PacketPtr pkt);
235 /** When receiving a retry request from the peer port,
236 pass it to the bridge. */
237 virtual void recvRetry();
239 /** When receiving a Atomic requestfrom the peer port,
240 pass it to the bridge. */
241 virtual Tick recvAtomic(PacketPtr pkt);
243 /** When receiving a Functional request from the peer port,
244 pass it to the bridge. */
245 virtual void recvFunctional(PacketPtr pkt);
248 * When receiving a range change on the slave side do nothing.
250 virtual void recvRangeChange();
252 /** When receiving a address range request the peer port,
253 pass it to the bridge. */
254 virtual AddrRangeList getAddrRanges();
259 * Port on the side that forwards requests and receives
260 * responses. The master port has a buffer for the requests not
263 class BridgeMasterPort : public Port
268 /** A pointer to the bridge to which this port belongs. */
272 * Pointer to the slave port on the other side of the bridge
273 * (connected to the other bus).
275 BridgeSlavePort* slavePort;
277 /** Minimum delay though this bridge. */
281 * Request packet queue. Request packets are held in this
282 * queue for a specified delay to model the processing delay
285 std::list<PacketBuffer*> requestQueue;
287 /** If we're waiting for a retry to happen. */
290 /** Max queue size for request packets */
291 unsigned int reqQueueLimit;
294 * Handle send event, scheduled when the packet at the head of
295 * the outbound queue is ready to transmit (for timing
301 * Private class for scheduling sending of requests from the
304 class SendEvent : public Event
306 BridgeMasterPort *port;
309 SendEvent(BridgeMasterPort *p) : port(p) {}
310 virtual void process() { port->trySend(); }
311 virtual const char *description() const { return "bridge send"; }
314 /** Send event for the request queue. */
320 * Constructor for the BridgeMasterPort.
322 * @param _name the port name including the owner
323 * @param _bridge the structural owner
324 * @param _slavePort the slave port on the other side of the bridge
325 * @param _delay the delay from seeing a request to sending it
326 * @param _req_limit the size of the request queue
328 BridgeMasterPort(const std::string &_name, Bridge *_bridge,
329 BridgeSlavePort* _slavePort, int _delay,
333 * Is this side blocked from accepting new request packets.
335 * @return true if the occupied space has reached the set limit
340 * Queue a request packet to be sent out later and also schedule
341 * a send if necessary.
343 * @param pkt a request to send out after a delay
345 void queueForSendTiming(PacketPtr pkt);
348 * Check a functional request against the packets in our
351 * @param pkt packet to check against
353 * @return true if we find a match
355 bool checkFunctional(PacketPtr pkt);
359 /** When receiving a timing request from the peer port,
360 pass it to the bridge. */
361 virtual bool recvTiming(PacketPtr pkt);
363 /** When receiving a retry request from the peer port,
364 pass it to the bridge. */
365 virtual void recvRetry();
367 /** When receiving a Atomic requestfrom the peer port,
368 pass it to the bridge. */
369 virtual Tick recvAtomic(PacketPtr pkt);
371 /** When receiving a Functional request from the peer port,
372 pass it to the bridge. */
373 virtual void recvFunctional(PacketPtr pkt);
376 * When receiving a range change, pass it through the bridge.
378 virtual void recvRangeChange();
381 /** Slave port of the bridge. */
382 BridgeSlavePort slavePort;
384 /** Master port of the bridge. */
385 BridgeMasterPort masterPort;
387 /** If this bridge should acknowledge writes. */
391 typedef BridgeParams Params;
397 const Params *params() const { return _params; }
399 /** A function used to return the port associated with this bus object. */
400 virtual Port *getPort(const std::string &if_name, int idx = -1);
407 #endif //__MEM_BUS_HH__