bridge.cc (9786:03a075377221) bridge.cc (9814:7ad2b0186a32)
1/*
2 * Copyright (c) 2011-2013 ARM Limited
3 * All rights reserved
4 *
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.
13 *
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
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.
27 *
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.
39 *
40 * Authors: Ali Saidi
41 * Steve Reinhardt
42 * Andreas Hansson
43 */
44
45/**
46 * @file
47 * Implementation of a memory-mapped bus bridge that connects a master
48 * and a slave through a request and response queue.
49 */
50
51#include "base/trace.hh"
52#include "debug/Bridge.hh"
53#include "mem/bridge.hh"
54#include "params/Bridge.hh"
55
56Bridge::BridgeSlavePort::BridgeSlavePort(const std::string& _name,
57 Bridge& _bridge,
58 BridgeMasterPort& _masterPort,
59 Cycles _delay, int _resp_limit,
60 std::vector<AddrRange> _ranges)
61 : SlavePort(_name, &_bridge), bridge(_bridge), masterPort(_masterPort),
62 delay(_delay), ranges(_ranges.begin(), _ranges.end()),
63 outstandingResponses(0), retryReq(false),
64 respQueueLimit(_resp_limit), sendEvent(*this)
65{
66}
67
68Bridge::BridgeMasterPort::BridgeMasterPort(const std::string& _name,
69 Bridge& _bridge,
70 BridgeSlavePort& _slavePort,
71 Cycles _delay, int _req_limit)
72 : MasterPort(_name, &_bridge), bridge(_bridge), slavePort(_slavePort),
73 delay(_delay), reqQueueLimit(_req_limit), sendEvent(*this)
74{
75}
76
77Bridge::Bridge(Params *p)
78 : MemObject(p),
79 slavePort(p->name + ".slave", *this, masterPort,
80 ticksToCycles(p->delay), p->resp_size, p->ranges),
81 masterPort(p->name + ".master", *this, slavePort,
82 ticksToCycles(p->delay), p->req_size)
83{
84}
85
86BaseMasterPort&
87Bridge::getMasterPort(const std::string &if_name, PortID idx)
88{
89 if (if_name == "master")
90 return masterPort;
91 else
92 // pass it along to our super class
93 return MemObject::getMasterPort(if_name, idx);
94}
95
96BaseSlavePort&
97Bridge::getSlavePort(const std::string &if_name, PortID idx)
98{
99 if (if_name == "slave")
100 return slavePort;
101 else
102 // pass it along to our super class
103 return MemObject::getSlavePort(if_name, idx);
104}
105
106void
107Bridge::init()
108{
109 // make sure both sides are connected and have the same block size
110 if (!slavePort.isConnected() || !masterPort.isConnected())
111 fatal("Both ports of bus bridge are not connected to a bus.\n");
112
1/*
2 * Copyright (c) 2011-2013 ARM Limited
3 * All rights reserved
4 *
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.
13 *
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
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.
27 *
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.
39 *
40 * Authors: Ali Saidi
41 * Steve Reinhardt
42 * Andreas Hansson
43 */
44
45/**
46 * @file
47 * Implementation of a memory-mapped bus bridge that connects a master
48 * and a slave through a request and response queue.
49 */
50
51#include "base/trace.hh"
52#include "debug/Bridge.hh"
53#include "mem/bridge.hh"
54#include "params/Bridge.hh"
55
56Bridge::BridgeSlavePort::BridgeSlavePort(const std::string& _name,
57 Bridge& _bridge,
58 BridgeMasterPort& _masterPort,
59 Cycles _delay, int _resp_limit,
60 std::vector<AddrRange> _ranges)
61 : SlavePort(_name, &_bridge), bridge(_bridge), masterPort(_masterPort),
62 delay(_delay), ranges(_ranges.begin(), _ranges.end()),
63 outstandingResponses(0), retryReq(false),
64 respQueueLimit(_resp_limit), sendEvent(*this)
65{
66}
67
68Bridge::BridgeMasterPort::BridgeMasterPort(const std::string& _name,
69 Bridge& _bridge,
70 BridgeSlavePort& _slavePort,
71 Cycles _delay, int _req_limit)
72 : MasterPort(_name, &_bridge), bridge(_bridge), slavePort(_slavePort),
73 delay(_delay), reqQueueLimit(_req_limit), sendEvent(*this)
74{
75}
76
77Bridge::Bridge(Params *p)
78 : MemObject(p),
79 slavePort(p->name + ".slave", *this, masterPort,
80 ticksToCycles(p->delay), p->resp_size, p->ranges),
81 masterPort(p->name + ".master", *this, slavePort,
82 ticksToCycles(p->delay), p->req_size)
83{
84}
85
86BaseMasterPort&
87Bridge::getMasterPort(const std::string &if_name, PortID idx)
88{
89 if (if_name == "master")
90 return masterPort;
91 else
92 // pass it along to our super class
93 return MemObject::getMasterPort(if_name, idx);
94}
95
96BaseSlavePort&
97Bridge::getSlavePort(const std::string &if_name, PortID idx)
98{
99 if (if_name == "slave")
100 return slavePort;
101 else
102 // pass it along to our super class
103 return MemObject::getSlavePort(if_name, idx);
104}
105
106void
107Bridge::init()
108{
109 // make sure both sides are connected and have the same block size
110 if (!slavePort.isConnected() || !masterPort.isConnected())
111 fatal("Both ports of bus bridge are not connected to a bus.\n");
112
113 if (slavePort.peerBlockSize() != masterPort.peerBlockSize())
114 fatal("Slave port size %d, master port size %d \n " \
115 "Busses don't have the same block size... Not supported.\n",
116 slavePort.peerBlockSize(), masterPort.peerBlockSize());
117
118 // notify the master side of our address ranges
119 slavePort.sendRangeChange();
120}
121
122bool
123Bridge::BridgeSlavePort::respQueueFull() const
124{
125 return outstandingResponses == respQueueLimit;
126}
127
128bool
129Bridge::BridgeMasterPort::reqQueueFull() const
130{
131 return transmitList.size() == reqQueueLimit;
132}
133
134bool
135Bridge::BridgeMasterPort::recvTimingResp(PacketPtr pkt)
136{
137 // all checks are done when the request is accepted on the slave
138 // side, so we are guaranteed to have space for the response
139 DPRINTF(Bridge, "recvTimingResp: %s addr 0x%x\n",
140 pkt->cmdString(), pkt->getAddr());
141
142 DPRINTF(Bridge, "Request queue size: %d\n", transmitList.size());
143
144 // @todo: We need to pay for this and not just zero it out
145 pkt->busFirstWordDelay = pkt->busLastWordDelay = 0;
146
147 slavePort.schedTimingResp(pkt, bridge.clockEdge(delay));
148
149 return true;
150}
151
152bool
153Bridge::BridgeSlavePort::recvTimingReq(PacketPtr pkt)
154{
155 DPRINTF(Bridge, "recvTimingReq: %s addr 0x%x\n",
156 pkt->cmdString(), pkt->getAddr());
157
158 // we should not see a timing request if we are already in a retry
159 assert(!retryReq);
160
161 DPRINTF(Bridge, "Response queue size: %d outresp: %d\n",
162 transmitList.size(), outstandingResponses);
163
164 // if the request queue is full then there is no hope
165 if (masterPort.reqQueueFull()) {
166 DPRINTF(Bridge, "Request queue full\n");
167 retryReq = true;
168 } else {
169 // look at the response queue if we expect to see a response
170 bool expects_response = pkt->needsResponse() &&
171 !pkt->memInhibitAsserted();
172 if (expects_response) {
173 if (respQueueFull()) {
174 DPRINTF(Bridge, "Response queue full\n");
175 retryReq = true;
176 } else {
177 // ok to send the request with space for the response
178 DPRINTF(Bridge, "Reserving space for response\n");
179 assert(outstandingResponses != respQueueLimit);
180 ++outstandingResponses;
181
182 // no need to set retryReq to false as this is already the
183 // case
184 }
185 }
186
187 if (!retryReq) {
188 // @todo: We need to pay for this and not just zero it out
189 pkt->busFirstWordDelay = pkt->busLastWordDelay = 0;
190
191 masterPort.schedTimingReq(pkt, bridge.clockEdge(delay));
192 }
193 }
194
195 // remember that we are now stalling a packet and that we have to
196 // tell the sending master to retry once space becomes available,
197 // we make no distinction whether the stalling is due to the
198 // request queue or response queue being full
199 return !retryReq;
200}
201
202void
203Bridge::BridgeSlavePort::retryStalledReq()
204{
205 if (retryReq) {
206 DPRINTF(Bridge, "Request waiting for retry, now retrying\n");
207 retryReq = false;
208 sendRetry();
209 }
210}
211
212void
213Bridge::BridgeMasterPort::schedTimingReq(PacketPtr pkt, Tick when)
214{
215 // If we expect to see a response, we need to restore the source
216 // and destination field that is potentially changed by a second
217 // bus
218 if (!pkt->memInhibitAsserted() && pkt->needsResponse()) {
219 // Update the sender state so we can deal with the response
220 // appropriately
221 pkt->pushSenderState(new RequestState(pkt->getSrc()));
222 }
223
224 // If we're about to put this packet at the head of the queue, we
225 // need to schedule an event to do the transmit. Otherwise there
226 // should already be an event scheduled for sending the head
227 // packet.
228 if (transmitList.empty()) {
229 bridge.schedule(sendEvent, when);
230 }
231
232 assert(transmitList.size() != reqQueueLimit);
233
234 transmitList.push_back(DeferredPacket(pkt, when));
235}
236
237
238void
239Bridge::BridgeSlavePort::schedTimingResp(PacketPtr pkt, Tick when)
240{
241 // This is a response for a request we forwarded earlier. The
242 // corresponding request state should be stored in the packet's
243 // senderState field.
244 RequestState *req_state =
245 dynamic_cast<RequestState*>(pkt->popSenderState());
246 assert(req_state != NULL);
247 pkt->setDest(req_state->origSrc);
248 delete req_state;
249
250 // the bridge assumes that at least one bus has set the
251 // destination field of the packet
252 assert(pkt->isDestValid());
253 DPRINTF(Bridge, "response, new dest %d\n", pkt->getDest());
254
255 // If we're about to put this packet at the head of the queue, we
256 // need to schedule an event to do the transmit. Otherwise there
257 // should already be an event scheduled for sending the head
258 // packet.
259 if (transmitList.empty()) {
260 bridge.schedule(sendEvent, when);
261 }
262
263 transmitList.push_back(DeferredPacket(pkt, when));
264}
265
266void
267Bridge::BridgeMasterPort::trySendTiming()
268{
269 assert(!transmitList.empty());
270
271 DeferredPacket req = transmitList.front();
272
273 assert(req.tick <= curTick());
274
275 PacketPtr pkt = req.pkt;
276
277 DPRINTF(Bridge, "trySend request addr 0x%x, queue size %d\n",
278 pkt->getAddr(), transmitList.size());
279
280 if (sendTimingReq(pkt)) {
281 // send successful
282 transmitList.pop_front();
283 DPRINTF(Bridge, "trySend request successful\n");
284
285 // If there are more packets to send, schedule event to try again.
286 if (!transmitList.empty()) {
287 DeferredPacket next_req = transmitList.front();
288 DPRINTF(Bridge, "Scheduling next send\n");
289 bridge.schedule(sendEvent, std::max(next_req.tick,
290 bridge.clockEdge()));
291 }
292
293 // if we have stalled a request due to a full request queue,
294 // then send a retry at this point, also note that if the
295 // request we stalled was waiting for the response queue
296 // rather than the request queue we might stall it again
297 slavePort.retryStalledReq();
298 }
299
300 // if the send failed, then we try again once we receive a retry,
301 // and therefore there is no need to take any action
302}
303
304void
305Bridge::BridgeSlavePort::trySendTiming()
306{
307 assert(!transmitList.empty());
308
309 DeferredPacket resp = transmitList.front();
310
311 assert(resp.tick <= curTick());
312
313 PacketPtr pkt = resp.pkt;
314
315 DPRINTF(Bridge, "trySend response addr 0x%x, outstanding %d\n",
316 pkt->getAddr(), outstandingResponses);
317
318 if (sendTimingResp(pkt)) {
319 // send successful
320 transmitList.pop_front();
321 DPRINTF(Bridge, "trySend response successful\n");
322
323 assert(outstandingResponses != 0);
324 --outstandingResponses;
325
326 // If there are more packets to send, schedule event to try again.
327 if (!transmitList.empty()) {
328 DeferredPacket next_resp = transmitList.front();
329 DPRINTF(Bridge, "Scheduling next send\n");
330 bridge.schedule(sendEvent, std::max(next_resp.tick,
331 bridge.clockEdge()));
332 }
333
334 // if there is space in the request queue and we were stalling
335 // a request, it will definitely be possible to accept it now
336 // since there is guaranteed space in the response queue
337 if (!masterPort.reqQueueFull() && retryReq) {
338 DPRINTF(Bridge, "Request waiting for retry, now retrying\n");
339 retryReq = false;
340 sendRetry();
341 }
342 }
343
344 // if the send failed, then we try again once we receive a retry,
345 // and therefore there is no need to take any action
346}
347
348void
349Bridge::BridgeMasterPort::recvRetry()
350{
351 trySendTiming();
352}
353
354void
355Bridge::BridgeSlavePort::recvRetry()
356{
357 trySendTiming();
358}
359
360Tick
361Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt)
362{
363 return delay * bridge.clockPeriod() + masterPort.sendAtomic(pkt);
364}
365
366void
367Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt)
368{
369 pkt->pushLabel(name());
370
371 // check the response queue
372 for (auto i = transmitList.begin(); i != transmitList.end(); ++i) {
373 if (pkt->checkFunctional((*i).pkt)) {
374 pkt->makeResponse();
375 return;
376 }
377 }
378
379 // also check the master port's request queue
380 if (masterPort.checkFunctional(pkt)) {
381 return;
382 }
383
384 pkt->popLabel();
385
386 // fall through if pkt still not satisfied
387 masterPort.sendFunctional(pkt);
388}
389
390bool
391Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt)
392{
393 bool found = false;
394 auto i = transmitList.begin();
395
396 while(i != transmitList.end() && !found) {
397 if (pkt->checkFunctional((*i).pkt)) {
398 pkt->makeResponse();
399 found = true;
400 }
401 ++i;
402 }
403
404 return found;
405}
406
407AddrRangeList
408Bridge::BridgeSlavePort::getAddrRanges() const
409{
410 return ranges;
411}
412
413Bridge *
414BridgeParams::create()
415{
416 return new Bridge(this);
417}
113 // notify the master side of our address ranges
114 slavePort.sendRangeChange();
115}
116
117bool
118Bridge::BridgeSlavePort::respQueueFull() const
119{
120 return outstandingResponses == respQueueLimit;
121}
122
123bool
124Bridge::BridgeMasterPort::reqQueueFull() const
125{
126 return transmitList.size() == reqQueueLimit;
127}
128
129bool
130Bridge::BridgeMasterPort::recvTimingResp(PacketPtr pkt)
131{
132 // all checks are done when the request is accepted on the slave
133 // side, so we are guaranteed to have space for the response
134 DPRINTF(Bridge, "recvTimingResp: %s addr 0x%x\n",
135 pkt->cmdString(), pkt->getAddr());
136
137 DPRINTF(Bridge, "Request queue size: %d\n", transmitList.size());
138
139 // @todo: We need to pay for this and not just zero it out
140 pkt->busFirstWordDelay = pkt->busLastWordDelay = 0;
141
142 slavePort.schedTimingResp(pkt, bridge.clockEdge(delay));
143
144 return true;
145}
146
147bool
148Bridge::BridgeSlavePort::recvTimingReq(PacketPtr pkt)
149{
150 DPRINTF(Bridge, "recvTimingReq: %s addr 0x%x\n",
151 pkt->cmdString(), pkt->getAddr());
152
153 // we should not see a timing request if we are already in a retry
154 assert(!retryReq);
155
156 DPRINTF(Bridge, "Response queue size: %d outresp: %d\n",
157 transmitList.size(), outstandingResponses);
158
159 // if the request queue is full then there is no hope
160 if (masterPort.reqQueueFull()) {
161 DPRINTF(Bridge, "Request queue full\n");
162 retryReq = true;
163 } else {
164 // look at the response queue if we expect to see a response
165 bool expects_response = pkt->needsResponse() &&
166 !pkt->memInhibitAsserted();
167 if (expects_response) {
168 if (respQueueFull()) {
169 DPRINTF(Bridge, "Response queue full\n");
170 retryReq = true;
171 } else {
172 // ok to send the request with space for the response
173 DPRINTF(Bridge, "Reserving space for response\n");
174 assert(outstandingResponses != respQueueLimit);
175 ++outstandingResponses;
176
177 // no need to set retryReq to false as this is already the
178 // case
179 }
180 }
181
182 if (!retryReq) {
183 // @todo: We need to pay for this and not just zero it out
184 pkt->busFirstWordDelay = pkt->busLastWordDelay = 0;
185
186 masterPort.schedTimingReq(pkt, bridge.clockEdge(delay));
187 }
188 }
189
190 // remember that we are now stalling a packet and that we have to
191 // tell the sending master to retry once space becomes available,
192 // we make no distinction whether the stalling is due to the
193 // request queue or response queue being full
194 return !retryReq;
195}
196
197void
198Bridge::BridgeSlavePort::retryStalledReq()
199{
200 if (retryReq) {
201 DPRINTF(Bridge, "Request waiting for retry, now retrying\n");
202 retryReq = false;
203 sendRetry();
204 }
205}
206
207void
208Bridge::BridgeMasterPort::schedTimingReq(PacketPtr pkt, Tick when)
209{
210 // If we expect to see a response, we need to restore the source
211 // and destination field that is potentially changed by a second
212 // bus
213 if (!pkt->memInhibitAsserted() && pkt->needsResponse()) {
214 // Update the sender state so we can deal with the response
215 // appropriately
216 pkt->pushSenderState(new RequestState(pkt->getSrc()));
217 }
218
219 // If we're about to put this packet at the head of the queue, we
220 // need to schedule an event to do the transmit. Otherwise there
221 // should already be an event scheduled for sending the head
222 // packet.
223 if (transmitList.empty()) {
224 bridge.schedule(sendEvent, when);
225 }
226
227 assert(transmitList.size() != reqQueueLimit);
228
229 transmitList.push_back(DeferredPacket(pkt, when));
230}
231
232
233void
234Bridge::BridgeSlavePort::schedTimingResp(PacketPtr pkt, Tick when)
235{
236 // This is a response for a request we forwarded earlier. The
237 // corresponding request state should be stored in the packet's
238 // senderState field.
239 RequestState *req_state =
240 dynamic_cast<RequestState*>(pkt->popSenderState());
241 assert(req_state != NULL);
242 pkt->setDest(req_state->origSrc);
243 delete req_state;
244
245 // the bridge assumes that at least one bus has set the
246 // destination field of the packet
247 assert(pkt->isDestValid());
248 DPRINTF(Bridge, "response, new dest %d\n", pkt->getDest());
249
250 // If we're about to put this packet at the head of the queue, we
251 // need to schedule an event to do the transmit. Otherwise there
252 // should already be an event scheduled for sending the head
253 // packet.
254 if (transmitList.empty()) {
255 bridge.schedule(sendEvent, when);
256 }
257
258 transmitList.push_back(DeferredPacket(pkt, when));
259}
260
261void
262Bridge::BridgeMasterPort::trySendTiming()
263{
264 assert(!transmitList.empty());
265
266 DeferredPacket req = transmitList.front();
267
268 assert(req.tick <= curTick());
269
270 PacketPtr pkt = req.pkt;
271
272 DPRINTF(Bridge, "trySend request addr 0x%x, queue size %d\n",
273 pkt->getAddr(), transmitList.size());
274
275 if (sendTimingReq(pkt)) {
276 // send successful
277 transmitList.pop_front();
278 DPRINTF(Bridge, "trySend request successful\n");
279
280 // If there are more packets to send, schedule event to try again.
281 if (!transmitList.empty()) {
282 DeferredPacket next_req = transmitList.front();
283 DPRINTF(Bridge, "Scheduling next send\n");
284 bridge.schedule(sendEvent, std::max(next_req.tick,
285 bridge.clockEdge()));
286 }
287
288 // if we have stalled a request due to a full request queue,
289 // then send a retry at this point, also note that if the
290 // request we stalled was waiting for the response queue
291 // rather than the request queue we might stall it again
292 slavePort.retryStalledReq();
293 }
294
295 // if the send failed, then we try again once we receive a retry,
296 // and therefore there is no need to take any action
297}
298
299void
300Bridge::BridgeSlavePort::trySendTiming()
301{
302 assert(!transmitList.empty());
303
304 DeferredPacket resp = transmitList.front();
305
306 assert(resp.tick <= curTick());
307
308 PacketPtr pkt = resp.pkt;
309
310 DPRINTF(Bridge, "trySend response addr 0x%x, outstanding %d\n",
311 pkt->getAddr(), outstandingResponses);
312
313 if (sendTimingResp(pkt)) {
314 // send successful
315 transmitList.pop_front();
316 DPRINTF(Bridge, "trySend response successful\n");
317
318 assert(outstandingResponses != 0);
319 --outstandingResponses;
320
321 // If there are more packets to send, schedule event to try again.
322 if (!transmitList.empty()) {
323 DeferredPacket next_resp = transmitList.front();
324 DPRINTF(Bridge, "Scheduling next send\n");
325 bridge.schedule(sendEvent, std::max(next_resp.tick,
326 bridge.clockEdge()));
327 }
328
329 // if there is space in the request queue and we were stalling
330 // a request, it will definitely be possible to accept it now
331 // since there is guaranteed space in the response queue
332 if (!masterPort.reqQueueFull() && retryReq) {
333 DPRINTF(Bridge, "Request waiting for retry, now retrying\n");
334 retryReq = false;
335 sendRetry();
336 }
337 }
338
339 // if the send failed, then we try again once we receive a retry,
340 // and therefore there is no need to take any action
341}
342
343void
344Bridge::BridgeMasterPort::recvRetry()
345{
346 trySendTiming();
347}
348
349void
350Bridge::BridgeSlavePort::recvRetry()
351{
352 trySendTiming();
353}
354
355Tick
356Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt)
357{
358 return delay * bridge.clockPeriod() + masterPort.sendAtomic(pkt);
359}
360
361void
362Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt)
363{
364 pkt->pushLabel(name());
365
366 // check the response queue
367 for (auto i = transmitList.begin(); i != transmitList.end(); ++i) {
368 if (pkt->checkFunctional((*i).pkt)) {
369 pkt->makeResponse();
370 return;
371 }
372 }
373
374 // also check the master port's request queue
375 if (masterPort.checkFunctional(pkt)) {
376 return;
377 }
378
379 pkt->popLabel();
380
381 // fall through if pkt still not satisfied
382 masterPort.sendFunctional(pkt);
383}
384
385bool
386Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt)
387{
388 bool found = false;
389 auto i = transmitList.begin();
390
391 while(i != transmitList.end() && !found) {
392 if (pkt->checkFunctional((*i).pkt)) {
393 pkt->makeResponse();
394 found = true;
395 }
396 ++i;
397 }
398
399 return found;
400}
401
402AddrRangeList
403Bridge::BridgeSlavePort::getAddrRanges() const
404{
405 return ranges;
406}
407
408Bridge *
409BridgeParams::create()
410{
411 return new Bridge(this);
412}