2 * Copyright (c) 2011-2013 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__
56 #include "base/types.hh"
57 #include "mem/mem_object.hh"
58 #include "params/Bridge.hh"
61 * A bridge is used to interface two different busses (or in general a
62 * memory-mapped master and slave), with buffering for requests and
63 * responses. The bridge has a fixed delay for packets passing through
64 * it and responds to a fixed set of address ranges.
66 * The bridge comprises a slave port and a master port, that buffer
67 * outgoing responses and requests respectively. Buffer space is
68 * reserved when a request arrives, also reserving response space
69 * before forwarding the request. If there is no space present, then
70 * the bridge will delay accepting the packet until space becomes
73 class Bridge : public MemObject
78 * A bridge request state stores packets along with their sender
79 * state and original source. It has enough information to also
80 * restore the response once it comes back to the bridge.
82 class RequestState : public Packet::SenderState
89 RequestState(PortID orig_src) : origSrc(orig_src)
95 * A deferred packet stores a packet along with its scheduled
106 DeferredPacket(PacketPtr _pkt, Tick _tick) : tick(_tick), pkt(_pkt)
110 // Forward declaration to allow the slave port to have a pointer
111 class BridgeMasterPort;
114 * The port on the side that receives requests and sends
115 * responses. The slave port has a set of address ranges that it
116 * is responsible for. The slave port also has a buffer for the
117 * responses not yet sent.
119 class BridgeSlavePort : public SlavePort
124 /** The bridge to which this port belongs. */
128 * Master port on the other side of the bridge (connected to
131 BridgeMasterPort& masterPort;
133 /** Minimum request delay though this bridge. */
136 /** Address ranges to pass through the bridge */
137 const AddrRangeList ranges;
140 * Response packet queue. Response packets are held in this
141 * queue for a specified delay to model the processing delay
142 * of the bridge. We use a deque as we need to iterate over
143 * the items for functional accesses.
145 std::deque<DeferredPacket> transmitList;
147 /** Counter to track the outstanding responses. */
148 unsigned int outstandingResponses;
150 /** If we should send a retry when space becomes available. */
153 /** Max queue size for reserved responses. */
154 unsigned int respQueueLimit;
157 * Is this side blocked from accepting new response packets.
159 * @return true if the reserved space has reached the set limit
161 bool respQueueFull() const;
164 * Handle send event, scheduled when the packet at the head of
165 * the response queue is ready to transmit (for timing
168 void trySendTiming();
170 /** Send event for the response queue. */
171 EventWrapper<BridgeSlavePort,
172 &BridgeSlavePort::trySendTiming> sendEvent;
177 * Constructor for the BridgeSlavePort.
179 * @param _name the port name including the owner
180 * @param _bridge the structural owner
181 * @param _masterPort the master port on the other side of the bridge
182 * @param _delay the delay in cycles from receiving to sending
183 * @param _resp_limit the size of the response queue
184 * @param _ranges a number of address ranges to forward
186 BridgeSlavePort(const std::string& _name, Bridge& _bridge,
187 BridgeMasterPort& _masterPort, Cycles _delay,
188 int _resp_limit, std::vector<AddrRange> _ranges);
191 * Queue a response packet to be sent out later and also schedule
192 * a send if necessary.
194 * @param pkt a response to send out after a delay
195 * @param when tick when response packet should be sent
197 void schedTimingResp(PacketPtr pkt, Tick when);
200 * Retry any stalled request that we have failed to accept at
201 * an earlier point in time. This call will do nothing if no
202 * request is waiting.
204 void retryStalledReq();
208 /** When receiving a timing request from the peer port,
209 pass it to the bridge. */
210 bool recvTimingReq(PacketPtr pkt);
212 /** When receiving a retry request from the peer port,
213 pass it to the bridge. */
216 /** When receiving a Atomic requestfrom the peer port,
217 pass it to the bridge. */
218 Tick recvAtomic(PacketPtr pkt);
220 /** When receiving a Functional request from the peer port,
221 pass it to the bridge. */
222 void recvFunctional(PacketPtr pkt);
224 /** When receiving a address range request the peer port,
225 pass it to the bridge. */
226 AddrRangeList getAddrRanges() const;
231 * Port on the side that forwards requests and receives
232 * responses. The master port has a buffer for the requests not
235 class BridgeMasterPort : public MasterPort
240 /** The bridge to which this port belongs. */
244 * The slave port on the other side of the bridge (connected
247 BridgeSlavePort& slavePort;
249 /** Minimum delay though this bridge. */
253 * Request packet queue. Request packets are held in this
254 * queue for a specified delay to model the processing delay
255 * of the bridge. We use a deque as we need to iterate over
256 * the items for functional accesses.
258 std::deque<DeferredPacket> transmitList;
260 /** Max queue size for request packets */
261 const unsigned int reqQueueLimit;
264 * Handle send event, scheduled when the packet at the head of
265 * the outbound queue is ready to transmit (for timing
268 void trySendTiming();
270 /** Send event for the request queue. */
271 EventWrapper<BridgeMasterPort,
272 &BridgeMasterPort::trySendTiming> sendEvent;
277 * Constructor for the BridgeMasterPort.
279 * @param _name the port name including the owner
280 * @param _bridge the structural owner
281 * @param _slavePort the slave port on the other side of the bridge
282 * @param _delay the delay in cycles from receiving to sending
283 * @param _req_limit the size of the request queue
285 BridgeMasterPort(const std::string& _name, Bridge& _bridge,
286 BridgeSlavePort& _slavePort, Cycles _delay,
290 * Is this side blocked from accepting new request packets.
292 * @return true if the occupied space has reached the set limit
294 bool reqQueueFull() const;
297 * Queue a request packet to be sent out later and also schedule
298 * a send if necessary.
300 * @param pkt a request to send out after a delay
301 * @param when tick when response packet should be sent
303 void schedTimingReq(PacketPtr pkt, Tick when);
306 * Check a functional request against the packets in our
309 * @param pkt packet to check against
311 * @return true if we find a match
313 bool checkFunctional(PacketPtr pkt);
317 /** When receiving a timing request from the peer port,
318 pass it to the bridge. */
319 bool recvTimingResp(PacketPtr pkt);
321 /** When receiving a retry request from the peer port,
322 pass it to the bridge. */
326 /** Slave port of the bridge. */
327 BridgeSlavePort slavePort;
329 /** Master port of the bridge. */
330 BridgeMasterPort masterPort;
334 virtual BaseMasterPort& getMasterPort(const std::string& if_name,
335 PortID idx = InvalidPortID);
336 virtual BaseSlavePort& getSlavePort(const std::string& if_name,
337 PortID idx = InvalidPortID);
341 typedef BridgeParams Params;
346 #endif //__MEM_BUS_HH__