2 * Copyright (c) 2011-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.
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 AddrRangeList ranges;
140 * Response packet queue. Response packets are held in this
141 * queue for a specified delay to model the processing delay
144 std::list<DeferredPacket> transmitList;
146 /** Counter to track the outstanding responses. */
147 unsigned int outstandingResponses;
149 /** If we should send a retry when space becomes available. */
152 /** Max queue size for reserved responses. */
153 unsigned int respQueueLimit;
156 * Is this side blocked from accepting new response packets.
158 * @return true if the reserved space has reached the set limit
160 bool respQueueFull();
163 * Handle send event, scheduled when the packet at the head of
164 * the response queue is ready to transmit (for timing
167 void trySendTiming();
169 /** Send event for the response queue. */
170 EventWrapper<BridgeSlavePort,
171 &BridgeSlavePort::trySendTiming> sendEvent;
176 * Constructor for the BridgeSlavePort.
178 * @param _name the port name including the owner
179 * @param _bridge the structural owner
180 * @param _masterPort the master port on the other side of the bridge
181 * @param _delay the delay in cycles from receiving to sending
182 * @param _resp_limit the size of the response queue
183 * @param _ranges a number of address ranges to forward
185 BridgeSlavePort(const std::string& _name, Bridge& _bridge,
186 BridgeMasterPort& _masterPort, Cycles _delay,
187 int _resp_limit, std::vector<AddrRange> _ranges);
190 * Queue a response packet to be sent out later and also schedule
191 * a send if necessary.
193 * @param pkt a response to send out after a delay
194 * @param when tick when response packet should be sent
196 void schedTimingResp(PacketPtr pkt, Tick when);
199 * Retry any stalled request that we have failed to accept at
200 * an earlier point in time. This call will do nothing if no
201 * request is waiting.
203 void retryStalledReq();
207 /** When receiving a timing request from the peer port,
208 pass it to the bridge. */
209 bool recvTimingReq(PacketPtr pkt);
211 /** When receiving a retry request from the peer port,
212 pass it to the bridge. */
215 /** When receiving a Atomic requestfrom the peer port,
216 pass it to the bridge. */
217 Tick recvAtomic(PacketPtr pkt);
219 /** When receiving a Functional request from the peer port,
220 pass it to the bridge. */
221 void recvFunctional(PacketPtr pkt);
223 /** When receiving a address range request the peer port,
224 pass it to the bridge. */
225 AddrRangeList getAddrRanges() const;
230 * Port on the side that forwards requests and receives
231 * responses. The master port has a buffer for the requests not
234 class BridgeMasterPort : public MasterPort
239 /** The bridge to which this port belongs. */
243 * The slave port on the other side of the bridge (connected
246 BridgeSlavePort& slavePort;
248 /** Minimum delay though this bridge. */
252 * Request packet queue. Request packets are held in this
253 * queue for a specified delay to model the processing delay
256 std::list<DeferredPacket> transmitList;
258 /** Max queue size for request packets */
259 unsigned int reqQueueLimit;
262 * Handle send event, scheduled when the packet at the head of
263 * the outbound queue is ready to transmit (for timing
266 void trySendTiming();
268 /** Send event for the request queue. */
269 EventWrapper<BridgeMasterPort,
270 &BridgeMasterPort::trySendTiming> sendEvent;
275 * Constructor for the BridgeMasterPort.
277 * @param _name the port name including the owner
278 * @param _bridge the structural owner
279 * @param _slavePort the slave port on the other side of the bridge
280 * @param _delay the delay in cycles from receiving to sending
281 * @param _req_limit the size of the request queue
283 BridgeMasterPort(const std::string& _name, Bridge& _bridge,
284 BridgeSlavePort& _slavePort, Cycles _delay,
288 * Is this side blocked from accepting new request packets.
290 * @return true if the occupied space has reached the set limit
295 * Queue a request packet to be sent out later and also schedule
296 * a send if necessary.
298 * @param pkt a request to send out after a delay
299 * @param when tick when response packet should be sent
301 void schedTimingReq(PacketPtr pkt, Tick when);
304 * Check a functional request against the packets in our
307 * @param pkt packet to check against
309 * @return true if we find a match
311 bool checkFunctional(PacketPtr pkt);
315 /** When receiving a timing request from the peer port,
316 pass it to the bridge. */
317 bool recvTimingResp(PacketPtr pkt);
319 /** When receiving a retry request from the peer port,
320 pass it to the bridge. */
324 /** Slave port of the bridge. */
325 BridgeSlavePort slavePort;
327 /** Master port of the bridge. */
328 BridgeMasterPort masterPort;
332 virtual BaseMasterPort& getMasterPort(const std::string& if_name,
333 PortID idx = InvalidPortID);
334 virtual BaseSlavePort& getSlavePort(const std::string& if_name,
335 PortID idx = InvalidPortID);
339 typedef BridgeParams Params;
344 #endif //__MEM_BUS_HH__