3 * Copyright (c) 2006 The Regents of The University of Michigan
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * Definition of a simple bus bridge without buffering.
40 #include "base/range_ops.hh"
41 #include "base/trace.hh"
42 #include "mem/bridge.hh"
43 #include "params/Bridge.hh"
45 Bridge::BridgePort::BridgePort(const std::string
&_name
,
46 Bridge
*_bridge
, BridgePort
*_otherPort
,
47 int _delay
, int _nack_delay
, int _req_limit
,
49 std::vector
<Range
<Addr
> > filter_ranges
)
50 : Port(_name
), bridge(_bridge
), otherPort(_otherPort
),
51 delay(_delay
), nackDelay(_nack_delay
), filterRanges(filter_ranges
),
52 outstandingResponses(0), queuedRequests(0), inRetry(false),
53 reqQueueLimit(_req_limit
), respQueueLimit(_resp_limit
), sendEvent(this)
57 Bridge::Bridge(Params
*p
)
59 portA(p
->name
+ "-portA", this, &portB
, p
->delay
, p
->nack_delay
,
60 p
->req_size_a
, p
->resp_size_a
, p
->filter_ranges_a
),
61 portB(p
->name
+ "-portB", this, &portA
, p
->delay
, p
->nack_delay
,
62 p
->req_size_b
, p
->resp_size_b
, p
->filter_ranges_b
),
63 ackWrites(p
->write_ack
), _params(p
)
66 panic("No support for acknowledging writes\n");
70 Bridge::getPort(const std::string
&if_name
, int idx
)
74 if (if_name
== "side_a")
76 else if (if_name
== "side_b")
81 if (port
->getPeer() != NULL
)
82 panic("bridge side %s already connected to.", if_name
);
90 // Make sure that both sides are connected to.
91 if (portA
.getPeer() == NULL
|| portB
.getPeer() == NULL
)
92 fatal("Both ports of bus bridge are not connected to a bus.\n");
94 if (portA
.peerBlockSize() != portB
.peerBlockSize())
95 fatal("Busses don't have the same block size... Not supported.\n");
99 Bridge::BridgePort::respQueueFull()
101 assert(outstandingResponses
>= 0 && outstandingResponses
<= respQueueLimit
);
102 return outstandingResponses
>= respQueueLimit
;
106 Bridge::BridgePort::reqQueueFull()
108 assert(queuedRequests
>= 0 && queuedRequests
<= reqQueueLimit
);
109 return queuedRequests
>= reqQueueLimit
;
112 /** Function called by the port when the bus is receiving a Timing
115 Bridge::BridgePort::recvTiming(PacketPtr pkt
)
117 DPRINTF(BusBridge
, "recvTiming: src %d dest %d addr 0x%x\n",
118 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr());
120 DPRINTF(BusBridge
, "Local queue size: %d outreq: %d outresp: %d\n",
121 sendQueue
.size(), queuedRequests
, outstandingResponses
);
122 DPRINTF(BusBridge
, "Remove queue size: %d outreq: %d outresp: %d\n",
123 otherPort
->sendQueue
.size(), otherPort
->queuedRequests
,
124 otherPort
->outstandingResponses
);
126 if (pkt
->isRequest() && otherPort
->reqQueueFull() && !pkt
->wasNacked()) {
127 DPRINTF(BusBridge
, "Remote queue full, nacking\n");
132 if (pkt
->needsResponse() && !pkt
->wasNacked())
133 if (respQueueFull()) {
134 DPRINTF(BusBridge
, "Local queue full, no space for response, nacking\n");
135 DPRINTF(BusBridge
, "queue size: %d outreq: %d outstanding resp: %d\n",
136 sendQueue
.size(), queuedRequests
, outstandingResponses
);
140 DPRINTF(BusBridge
, "Request Needs response, reserving space\n");
141 ++outstandingResponses
;
144 otherPort
->queueForSendTiming(pkt
);
150 Bridge::BridgePort::nackRequest(PacketPtr pkt
)
154 pkt
->setDest(pkt
->getSrc());
156 //put it on the list to send
157 Tick readyTime
= curTick
+ nackDelay
;
158 PacketBuffer
*buf
= new PacketBuffer(pkt
, readyTime
, true);
160 // nothing on the list, add it and we're done
161 if (sendQueue
.empty()) {
162 assert(!sendEvent
.scheduled());
163 sendEvent
.schedule(readyTime
);
164 sendQueue
.push_back(buf
);
168 assert(sendEvent
.scheduled() || inRetry
);
170 // does it go at the end?
171 if (readyTime
>= sendQueue
.back()->ready
) {
172 sendQueue
.push_back(buf
);
176 // ok, somewhere in the middle, fun
177 std::list
<PacketBuffer
*>::iterator i
= sendQueue
.begin();
178 std::list
<PacketBuffer
*>::iterator end
= sendQueue
.end();
179 std::list
<PacketBuffer
*>::iterator begin
= sendQueue
.begin();
182 while (i
!= end
&& !done
) {
183 if (readyTime
< (*i
)->ready
) {
185 sendEvent
.reschedule(readyTime
);
186 sendQueue
.insert(i
,buf
);
196 Bridge::BridgePort::queueForSendTiming(PacketPtr pkt
)
198 if (pkt
->isResponse() || pkt
->wasNacked()) {
199 // This is a response for a request we forwarded earlier. The
200 // corresponding PacketBuffer should be stored in the packet's
201 // senderState field.
202 PacketBuffer
*buf
= dynamic_cast<PacketBuffer
*>(pkt
->senderState
);
204 // set up new packet dest & senderState based on values saved
205 // from original request
206 buf
->fixResponse(pkt
);
208 // Check if this packet was expecting a response and it's a nacked
209 // packet, in which case we will never being seeing it
210 if (buf
->expectResponse
&& pkt
->wasNacked())
211 --outstandingResponses
;
213 DPRINTF(BusBridge
, "response, new dest %d\n", pkt
->getDest());
218 if (pkt
->isRequest() && !pkt
->wasNacked()) {
224 Tick readyTime
= curTick
+ delay
;
225 PacketBuffer
*buf
= new PacketBuffer(pkt
, readyTime
);
227 // If we're about to put this packet at the head of the queue, we
228 // need to schedule an event to do the transmit. Otherwise there
229 // should already be an event scheduled for sending the head
231 if (sendQueue
.empty()) {
232 sendEvent
.schedule(readyTime
);
234 sendQueue
.push_back(buf
);
238 Bridge::BridgePort::trySend()
240 assert(!sendQueue
.empty());
242 PacketBuffer
*buf
= sendQueue
.front();
244 assert(buf
->ready
<= curTick
);
246 PacketPtr pkt
= buf
->pkt
;
248 DPRINTF(BusBridge
, "trySend: origSrc %d dest %d addr 0x%x\n",
249 buf
->origSrc
, pkt
->getDest(), pkt
->getAddr());
251 bool wasReq
= pkt
->isRequest();
252 bool wasNacked
= pkt
->wasNacked();
254 if (sendTiming(pkt
)) {
256 sendQueue
.pop_front();
257 buf
->pkt
= NULL
; // we no longer own packet, so it's not safe to look at it
259 if (buf
->expectResponse
) {
260 // Must wait for response
261 DPRINTF(BusBridge
, " successful: awaiting response (%d)\n",
262 outstandingResponses
);
264 // no response expected... deallocate packet buffer now.
265 DPRINTF(BusBridge
, " successful: no response expected\n");
273 --outstandingResponses
;
276 // If there are more packets to send, schedule event to try again.
277 if (!sendQueue
.empty()) {
278 buf
= sendQueue
.front();
279 DPRINTF(BusBridge
, "Scheduling next send\n");
280 sendEvent
.schedule(std::max(buf
->ready
, curTick
+ 1));
283 DPRINTF(BusBridge
, " unsuccessful\n");
286 DPRINTF(BusBridge
, "trySend: queue size: %d outreq: %d outstanding resp: %d\n",
287 sendQueue
.size(), queuedRequests
, outstandingResponses
);
292 Bridge::BridgePort::recvRetry()
295 Tick nextReady
= sendQueue
.front()->ready
;
296 if (nextReady
<= curTick
)
299 sendEvent
.schedule(nextReady
);
302 /** Function called by the port when the bus is receiving a Atomic
305 Bridge::BridgePort::recvAtomic(PacketPtr pkt
)
307 return delay
+ otherPort
->sendAtomic(pkt
);
310 /** Function called by the port when the bus is receiving a Functional
313 Bridge::BridgePort::recvFunctional(PacketPtr pkt
)
315 std::list
<PacketBuffer
*>::iterator i
;
317 for (i
= sendQueue
.begin(); i
!= sendQueue
.end(); ++i
) {
318 if (pkt
->checkFunctional((*i
)->pkt
))
322 // fall through if pkt still not satisfied
323 otherPort
->sendFunctional(pkt
);
326 /** Function called by the port when the bus is receiving a status change.*/
328 Bridge::BridgePort::recvStatusChange(Port::Status status
)
330 otherPort
->sendStatusChange(status
);
334 Bridge::BridgePort::getDeviceAddressRanges(AddrRangeList
&resp
,
337 otherPort
->getPeerAddressRanges(resp
, snoop
);
338 FilterRangeList(filterRanges
, resp
);
339 // we don't allow snooping across bridges
344 BridgeParams::create()
346 return new Bridge(this);