bridge.cc (8949:3fa1ee293096) bridge.cc (8975:7f36d4436074)
1/*
2 * Copyright (c) 2011-2012 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/BusBridge.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 int _delay, int _nack_delay,
60 int _resp_limit,
61 std::vector<Range<Addr> > _ranges)
62 : SlavePort(_name, _bridge), bridge(_bridge), masterPort(_masterPort),
63 delay(_delay), nackDelay(_nack_delay),
64 ranges(_ranges.begin(), _ranges.end()),
65 outstandingResponses(0), inRetry(false),
66 respQueueLimit(_resp_limit), sendEvent(*this)
67{
68}
69
70Bridge::BridgeMasterPort::BridgeMasterPort(const std::string &_name,
71 Bridge* _bridge,
72 BridgeSlavePort& _slavePort,
73 int _delay, int _req_limit)
74 : MasterPort(_name, _bridge), bridge(_bridge), slavePort(_slavePort),
75 delay(_delay), inRetry(false), reqQueueLimit(_req_limit),
76 sendEvent(*this)
77{
78}
79
80Bridge::Bridge(Params *p)
81 : MemObject(p),
82 slavePort(p->name + "-slave", this, masterPort, p->delay,
83 p->nack_delay, p->resp_size, p->ranges),
84 masterPort(p->name + "-master", this, slavePort, p->delay, p->req_size),
85 ackWrites(p->write_ack), _params(p)
86{
87 if (ackWrites)
88 panic("No support for acknowledging writes\n");
89}
90
91MasterPort&
92Bridge::getMasterPort(const std::string &if_name, int idx)
93{
94 if (if_name == "master")
95 return masterPort;
96 else
97 // pass it along to our super class
98 return MemObject::getMasterPort(if_name, idx);
99}
100
101SlavePort&
102Bridge::getSlavePort(const std::string &if_name, int idx)
103{
104 if (if_name == "slave")
105 return slavePort;
106 else
107 // pass it along to our super class
108 return MemObject::getSlavePort(if_name, idx);
109}
110
111void
112Bridge::init()
113{
114 // make sure both sides are connected and have the same block size
115 if (!slavePort.isConnected() || !masterPort.isConnected())
116 fatal("Both ports of bus bridge are not connected to a bus.\n");
117
118 if (slavePort.peerBlockSize() != masterPort.peerBlockSize())
119 fatal("Slave port size %d, master port size %d \n " \
120 "Busses don't have the same block size... Not supported.\n",
121 slavePort.peerBlockSize(), masterPort.peerBlockSize());
122
123 // notify the master side of our address ranges
124 slavePort.sendRangeChange();
125}
126
127bool
128Bridge::BridgeSlavePort::respQueueFull()
129{
130 return outstandingResponses == respQueueLimit;
131}
132
133bool
134Bridge::BridgeMasterPort::reqQueueFull()
135{
136 return requestQueue.size() == reqQueueLimit;
137}
138
139bool
1/*
2 * Copyright (c) 2011-2012 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/BusBridge.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 int _delay, int _nack_delay,
60 int _resp_limit,
61 std::vector<Range<Addr> > _ranges)
62 : SlavePort(_name, _bridge), bridge(_bridge), masterPort(_masterPort),
63 delay(_delay), nackDelay(_nack_delay),
64 ranges(_ranges.begin(), _ranges.end()),
65 outstandingResponses(0), inRetry(false),
66 respQueueLimit(_resp_limit), sendEvent(*this)
67{
68}
69
70Bridge::BridgeMasterPort::BridgeMasterPort(const std::string &_name,
71 Bridge* _bridge,
72 BridgeSlavePort& _slavePort,
73 int _delay, int _req_limit)
74 : MasterPort(_name, _bridge), bridge(_bridge), slavePort(_slavePort),
75 delay(_delay), inRetry(false), reqQueueLimit(_req_limit),
76 sendEvent(*this)
77{
78}
79
80Bridge::Bridge(Params *p)
81 : MemObject(p),
82 slavePort(p->name + "-slave", this, masterPort, p->delay,
83 p->nack_delay, p->resp_size, p->ranges),
84 masterPort(p->name + "-master", this, slavePort, p->delay, p->req_size),
85 ackWrites(p->write_ack), _params(p)
86{
87 if (ackWrites)
88 panic("No support for acknowledging writes\n");
89}
90
91MasterPort&
92Bridge::getMasterPort(const std::string &if_name, int idx)
93{
94 if (if_name == "master")
95 return masterPort;
96 else
97 // pass it along to our super class
98 return MemObject::getMasterPort(if_name, idx);
99}
100
101SlavePort&
102Bridge::getSlavePort(const std::string &if_name, int idx)
103{
104 if (if_name == "slave")
105 return slavePort;
106 else
107 // pass it along to our super class
108 return MemObject::getSlavePort(if_name, idx);
109}
110
111void
112Bridge::init()
113{
114 // make sure both sides are connected and have the same block size
115 if (!slavePort.isConnected() || !masterPort.isConnected())
116 fatal("Both ports of bus bridge are not connected to a bus.\n");
117
118 if (slavePort.peerBlockSize() != masterPort.peerBlockSize())
119 fatal("Slave port size %d, master port size %d \n " \
120 "Busses don't have the same block size... Not supported.\n",
121 slavePort.peerBlockSize(), masterPort.peerBlockSize());
122
123 // notify the master side of our address ranges
124 slavePort.sendRangeChange();
125}
126
127bool
128Bridge::BridgeSlavePort::respQueueFull()
129{
130 return outstandingResponses == respQueueLimit;
131}
132
133bool
134Bridge::BridgeMasterPort::reqQueueFull()
135{
136 return requestQueue.size() == reqQueueLimit;
137}
138
139bool
140Bridge::BridgeMasterPort::recvTiming(PacketPtr pkt)
140Bridge::BridgeMasterPort::recvTimingResp(PacketPtr pkt)
141{
141{
142 // should only see responses on the master side
143 assert(pkt->isResponse());
144
145 // all checks are done when the request is accepted on the slave
146 // side, so we are guaranteed to have space for the response
147 DPRINTF(BusBridge, "recvTiming: response %s addr 0x%x\n",
148 pkt->cmdString(), pkt->getAddr());
149
150 DPRINTF(BusBridge, "Request queue size: %d\n", requestQueue.size());
151
152 slavePort.queueForSendTiming(pkt);
153
154 return true;
155}
156
157bool
142 // all checks are done when the request is accepted on the slave
143 // side, so we are guaranteed to have space for the response
144 DPRINTF(BusBridge, "recvTiming: response %s addr 0x%x\n",
145 pkt->cmdString(), pkt->getAddr());
146
147 DPRINTF(BusBridge, "Request queue size: %d\n", requestQueue.size());
148
149 slavePort.queueForSendTiming(pkt);
150
151 return true;
152}
153
154bool
158Bridge::BridgeSlavePort::recvTiming(PacketPtr pkt)
155Bridge::BridgeSlavePort::recvTimingReq(PacketPtr pkt)
159{
156{
160 // should only see requests on the slave side
161 assert(pkt->isRequest());
162
163
164 DPRINTF(BusBridge, "recvTiming: request %s addr 0x%x\n",
165 pkt->cmdString(), pkt->getAddr());
166
167 DPRINTF(BusBridge, "Response queue size: %d outresp: %d\n",
168 responseQueue.size(), outstandingResponses);
169
170 if (masterPort.reqQueueFull()) {
171 DPRINTF(BusBridge, "Request queue full, nacking\n");
172 nackRequest(pkt);
173 return true;
174 }
175
176 if (pkt->needsResponse()) {
177 if (respQueueFull()) {
178 DPRINTF(BusBridge,
179 "Response queue full, no space for response, nacking\n");
180 DPRINTF(BusBridge,
181 "queue size: %d outstanding resp: %d\n",
182 responseQueue.size(), outstandingResponses);
183 nackRequest(pkt);
184 return true;
185 } else {
186 DPRINTF(BusBridge, "Request Needs response, reserving space\n");
187 assert(outstandingResponses != respQueueLimit);
188 ++outstandingResponses;
189 }
190 }
191
192 masterPort.queueForSendTiming(pkt);
193
194 return true;
195}
196
197void
198Bridge::BridgeSlavePort::nackRequest(PacketPtr pkt)
199{
200 // Nack the packet
201 pkt->makeTimingResponse();
202 pkt->setNacked();
203
204 // The Nack packets are stored in the response queue just like any
205 // other response, but they do not occupy any space as this is
206 // tracked by the outstandingResponses, this guarantees space for
207 // the Nack packets, but implicitly means we have an (unrealistic)
208 // unbounded Nack queue.
209
210 // put it on the list to send
211 Tick readyTime = curTick() + nackDelay;
212 PacketBuffer *buf = new PacketBuffer(pkt, readyTime, true);
213
214 // nothing on the list, add it and we're done
215 if (responseQueue.empty()) {
216 assert(!sendEvent.scheduled());
217 bridge->schedule(sendEvent, readyTime);
218 responseQueue.push_back(buf);
219 return;
220 }
221
222 assert(sendEvent.scheduled() || inRetry);
223
224 // does it go at the end?
225 if (readyTime >= responseQueue.back()->ready) {
226 responseQueue.push_back(buf);
227 return;
228 }
229
230 // ok, somewhere in the middle, fun
231 std::list<PacketBuffer*>::iterator i = responseQueue.begin();
232 std::list<PacketBuffer*>::iterator end = responseQueue.end();
233 std::list<PacketBuffer*>::iterator begin = responseQueue.begin();
234 bool done = false;
235
236 while (i != end && !done) {
237 if (readyTime < (*i)->ready) {
238 if (i == begin)
239 bridge->reschedule(sendEvent, readyTime);
240 responseQueue.insert(i,buf);
241 done = true;
242 }
243 i++;
244 }
245 assert(done);
246}
247
248void
249Bridge::BridgeMasterPort::queueForSendTiming(PacketPtr pkt)
250{
251 Tick readyTime = curTick() + delay;
252 PacketBuffer *buf = new PacketBuffer(pkt, readyTime);
253
254 // If we're about to put this packet at the head of the queue, we
255 // need to schedule an event to do the transmit. Otherwise there
256 // should already be an event scheduled for sending the head
257 // packet.
258 if (requestQueue.empty()) {
259 bridge->schedule(sendEvent, readyTime);
260 }
261
262 assert(requestQueue.size() != reqQueueLimit);
263
264 requestQueue.push_back(buf);
265}
266
267
268void
269Bridge::BridgeSlavePort::queueForSendTiming(PacketPtr pkt)
270{
271 // This is a response for a request we forwarded earlier. The
272 // corresponding PacketBuffer should be stored in the packet's
273 // senderState field.
274 PacketBuffer *buf = dynamic_cast<PacketBuffer*>(pkt->senderState);
275 assert(buf != NULL);
276 // set up new packet dest & senderState based on values saved
277 // from original request
278 buf->fixResponse(pkt);
279
280 // the bridge assumes that at least one bus has set the
281 // destination field of the packet
282 assert(pkt->isDestValid());
283 DPRINTF(BusBridge, "response, new dest %d\n", pkt->getDest());
284 delete buf;
285
286 Tick readyTime = curTick() + delay;
287 buf = new PacketBuffer(pkt, readyTime);
288
289 // If we're about to put this packet at the head of the queue, we
290 // need to schedule an event to do the transmit. Otherwise there
291 // should already be an event scheduled for sending the head
292 // packet.
293 if (responseQueue.empty()) {
294 bridge->schedule(sendEvent, readyTime);
295 }
296 responseQueue.push_back(buf);
297}
298
299void
300Bridge::BridgeMasterPort::trySend()
301{
302 assert(!requestQueue.empty());
303
304 PacketBuffer *buf = requestQueue.front();
305
306 assert(buf->ready <= curTick());
307
308 PacketPtr pkt = buf->pkt;
309
310 DPRINTF(BusBridge, "trySend: origSrc %d addr 0x%x\n",
311 buf->origSrc, pkt->getAddr());
312
313 // If the send was successful, make sure sender state was set to NULL
314 // otherwise we could get a NACK back of a packet that didn't expect a
315 // response and we would try to use freed memory.
316
317 Packet::SenderState *old_sender_state = pkt->senderState;
318 if (!buf->expectResponse)
319 pkt->senderState = NULL;
320
157 DPRINTF(BusBridge, "recvTiming: request %s addr 0x%x\n",
158 pkt->cmdString(), pkt->getAddr());
159
160 DPRINTF(BusBridge, "Response queue size: %d outresp: %d\n",
161 responseQueue.size(), outstandingResponses);
162
163 if (masterPort.reqQueueFull()) {
164 DPRINTF(BusBridge, "Request queue full, nacking\n");
165 nackRequest(pkt);
166 return true;
167 }
168
169 if (pkt->needsResponse()) {
170 if (respQueueFull()) {
171 DPRINTF(BusBridge,
172 "Response queue full, no space for response, nacking\n");
173 DPRINTF(BusBridge,
174 "queue size: %d outstanding resp: %d\n",
175 responseQueue.size(), outstandingResponses);
176 nackRequest(pkt);
177 return true;
178 } else {
179 DPRINTF(BusBridge, "Request Needs response, reserving space\n");
180 assert(outstandingResponses != respQueueLimit);
181 ++outstandingResponses;
182 }
183 }
184
185 masterPort.queueForSendTiming(pkt);
186
187 return true;
188}
189
190void
191Bridge::BridgeSlavePort::nackRequest(PacketPtr pkt)
192{
193 // Nack the packet
194 pkt->makeTimingResponse();
195 pkt->setNacked();
196
197 // The Nack packets are stored in the response queue just like any
198 // other response, but they do not occupy any space as this is
199 // tracked by the outstandingResponses, this guarantees space for
200 // the Nack packets, but implicitly means we have an (unrealistic)
201 // unbounded Nack queue.
202
203 // put it on the list to send
204 Tick readyTime = curTick() + nackDelay;
205 PacketBuffer *buf = new PacketBuffer(pkt, readyTime, true);
206
207 // nothing on the list, add it and we're done
208 if (responseQueue.empty()) {
209 assert(!sendEvent.scheduled());
210 bridge->schedule(sendEvent, readyTime);
211 responseQueue.push_back(buf);
212 return;
213 }
214
215 assert(sendEvent.scheduled() || inRetry);
216
217 // does it go at the end?
218 if (readyTime >= responseQueue.back()->ready) {
219 responseQueue.push_back(buf);
220 return;
221 }
222
223 // ok, somewhere in the middle, fun
224 std::list<PacketBuffer*>::iterator i = responseQueue.begin();
225 std::list<PacketBuffer*>::iterator end = responseQueue.end();
226 std::list<PacketBuffer*>::iterator begin = responseQueue.begin();
227 bool done = false;
228
229 while (i != end && !done) {
230 if (readyTime < (*i)->ready) {
231 if (i == begin)
232 bridge->reschedule(sendEvent, readyTime);
233 responseQueue.insert(i,buf);
234 done = true;
235 }
236 i++;
237 }
238 assert(done);
239}
240
241void
242Bridge::BridgeMasterPort::queueForSendTiming(PacketPtr pkt)
243{
244 Tick readyTime = curTick() + delay;
245 PacketBuffer *buf = new PacketBuffer(pkt, readyTime);
246
247 // If we're about to put this packet at the head of the queue, we
248 // need to schedule an event to do the transmit. Otherwise there
249 // should already be an event scheduled for sending the head
250 // packet.
251 if (requestQueue.empty()) {
252 bridge->schedule(sendEvent, readyTime);
253 }
254
255 assert(requestQueue.size() != reqQueueLimit);
256
257 requestQueue.push_back(buf);
258}
259
260
261void
262Bridge::BridgeSlavePort::queueForSendTiming(PacketPtr pkt)
263{
264 // This is a response for a request we forwarded earlier. The
265 // corresponding PacketBuffer should be stored in the packet's
266 // senderState field.
267 PacketBuffer *buf = dynamic_cast<PacketBuffer*>(pkt->senderState);
268 assert(buf != NULL);
269 // set up new packet dest & senderState based on values saved
270 // from original request
271 buf->fixResponse(pkt);
272
273 // the bridge assumes that at least one bus has set the
274 // destination field of the packet
275 assert(pkt->isDestValid());
276 DPRINTF(BusBridge, "response, new dest %d\n", pkt->getDest());
277 delete buf;
278
279 Tick readyTime = curTick() + delay;
280 buf = new PacketBuffer(pkt, readyTime);
281
282 // If we're about to put this packet at the head of the queue, we
283 // need to schedule an event to do the transmit. Otherwise there
284 // should already be an event scheduled for sending the head
285 // packet.
286 if (responseQueue.empty()) {
287 bridge->schedule(sendEvent, readyTime);
288 }
289 responseQueue.push_back(buf);
290}
291
292void
293Bridge::BridgeMasterPort::trySend()
294{
295 assert(!requestQueue.empty());
296
297 PacketBuffer *buf = requestQueue.front();
298
299 assert(buf->ready <= curTick());
300
301 PacketPtr pkt = buf->pkt;
302
303 DPRINTF(BusBridge, "trySend: origSrc %d addr 0x%x\n",
304 buf->origSrc, pkt->getAddr());
305
306 // If the send was successful, make sure sender state was set to NULL
307 // otherwise we could get a NACK back of a packet that didn't expect a
308 // response and we would try to use freed memory.
309
310 Packet::SenderState *old_sender_state = pkt->senderState;
311 if (!buf->expectResponse)
312 pkt->senderState = NULL;
313
321 if (sendTiming(pkt)) {
314 if (sendTimingReq(pkt)) {
322 // send successful
323 requestQueue.pop_front();
324 // we no longer own packet, so it's not safe to look at it
325 buf->pkt = NULL;
326
327 if (!buf->expectResponse) {
328 // no response expected... deallocate packet buffer now.
329 DPRINTF(BusBridge, " successful: no response expected\n");
330 delete buf;
331 }
332
333 // If there are more packets to send, schedule event to try again.
334 if (!requestQueue.empty()) {
335 buf = requestQueue.front();
336 DPRINTF(BusBridge, "Scheduling next send\n");
337 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1));
338 }
339 } else {
340 DPRINTF(BusBridge, " unsuccessful\n");
341 pkt->senderState = old_sender_state;
342 inRetry = true;
343 }
344
345 DPRINTF(BusBridge, "trySend: request queue size: %d\n",
346 requestQueue.size());
347}
348
349void
350Bridge::BridgeSlavePort::trySend()
351{
352 assert(!responseQueue.empty());
353
354 PacketBuffer *buf = responseQueue.front();
355
356 assert(buf->ready <= curTick());
357
358 PacketPtr pkt = buf->pkt;
359
360 DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n",
361 buf->origSrc, pkt->getDest(), pkt->getAddr());
362
363 bool was_nacked_here = buf->nackedHere;
364
365 // no need to worry about the sender state since we are not
366 // modifying it
367
315 // send successful
316 requestQueue.pop_front();
317 // we no longer own packet, so it's not safe to look at it
318 buf->pkt = NULL;
319
320 if (!buf->expectResponse) {
321 // no response expected... deallocate packet buffer now.
322 DPRINTF(BusBridge, " successful: no response expected\n");
323 delete buf;
324 }
325
326 // If there are more packets to send, schedule event to try again.
327 if (!requestQueue.empty()) {
328 buf = requestQueue.front();
329 DPRINTF(BusBridge, "Scheduling next send\n");
330 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1));
331 }
332 } else {
333 DPRINTF(BusBridge, " unsuccessful\n");
334 pkt->senderState = old_sender_state;
335 inRetry = true;
336 }
337
338 DPRINTF(BusBridge, "trySend: request queue size: %d\n",
339 requestQueue.size());
340}
341
342void
343Bridge::BridgeSlavePort::trySend()
344{
345 assert(!responseQueue.empty());
346
347 PacketBuffer *buf = responseQueue.front();
348
349 assert(buf->ready <= curTick());
350
351 PacketPtr pkt = buf->pkt;
352
353 DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n",
354 buf->origSrc, pkt->getDest(), pkt->getAddr());
355
356 bool was_nacked_here = buf->nackedHere;
357
358 // no need to worry about the sender state since we are not
359 // modifying it
360
368 if (sendTiming(pkt)) {
361 if (sendTimingResp(pkt)) {
369 DPRINTF(BusBridge, " successful\n");
370 // send successful
371 responseQueue.pop_front();
372 // this is a response... deallocate packet buffer now.
373 delete buf;
374
375 if (!was_nacked_here) {
376 assert(outstandingResponses != 0);
377 --outstandingResponses;
378 }
379
380 // If there are more packets to send, schedule event to try again.
381 if (!responseQueue.empty()) {
382 buf = responseQueue.front();
383 DPRINTF(BusBridge, "Scheduling next send\n");
384 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1));
385 }
386 } else {
387 DPRINTF(BusBridge, " unsuccessful\n");
388 inRetry = true;
389 }
390
391 DPRINTF(BusBridge, "trySend: queue size: %d outstanding resp: %d\n",
392 responseQueue.size(), outstandingResponses);
393}
394
395void
396Bridge::BridgeMasterPort::recvRetry()
397{
398 inRetry = false;
399 Tick nextReady = requestQueue.front()->ready;
400 if (nextReady <= curTick())
401 trySend();
402 else
403 bridge->schedule(sendEvent, nextReady);
404}
405
406void
407Bridge::BridgeSlavePort::recvRetry()
408{
409 inRetry = false;
410 Tick nextReady = responseQueue.front()->ready;
411 if (nextReady <= curTick())
412 trySend();
413 else
414 bridge->schedule(sendEvent, nextReady);
415}
416
417Tick
418Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt)
419{
420 return delay + masterPort.sendAtomic(pkt);
421}
422
423void
424Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt)
425{
426 std::list<PacketBuffer*>::iterator i;
427
428 pkt->pushLabel(name());
429
430 // check the response queue
431 for (i = responseQueue.begin(); i != responseQueue.end(); ++i) {
432 if (pkt->checkFunctional((*i)->pkt)) {
433 pkt->makeResponse();
434 return;
435 }
436 }
437
438 // also check the master port's request queue
439 if (masterPort.checkFunctional(pkt)) {
440 return;
441 }
442
443 pkt->popLabel();
444
445 // fall through if pkt still not satisfied
446 masterPort.sendFunctional(pkt);
447}
448
449bool
450Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt)
451{
452 bool found = false;
453 std::list<PacketBuffer*>::iterator i = requestQueue.begin();
454
455 while(i != requestQueue.end() && !found) {
456 if (pkt->checkFunctional((*i)->pkt)) {
457 pkt->makeResponse();
458 found = true;
459 }
460 ++i;
461 }
462
463 return found;
464}
465
466AddrRangeList
467Bridge::BridgeSlavePort::getAddrRanges()
468{
469 return ranges;
470}
471
472Bridge *
473BridgeParams::create()
474{
475 return new Bridge(this);
476}
362 DPRINTF(BusBridge, " successful\n");
363 // send successful
364 responseQueue.pop_front();
365 // this is a response... deallocate packet buffer now.
366 delete buf;
367
368 if (!was_nacked_here) {
369 assert(outstandingResponses != 0);
370 --outstandingResponses;
371 }
372
373 // If there are more packets to send, schedule event to try again.
374 if (!responseQueue.empty()) {
375 buf = responseQueue.front();
376 DPRINTF(BusBridge, "Scheduling next send\n");
377 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1));
378 }
379 } else {
380 DPRINTF(BusBridge, " unsuccessful\n");
381 inRetry = true;
382 }
383
384 DPRINTF(BusBridge, "trySend: queue size: %d outstanding resp: %d\n",
385 responseQueue.size(), outstandingResponses);
386}
387
388void
389Bridge::BridgeMasterPort::recvRetry()
390{
391 inRetry = false;
392 Tick nextReady = requestQueue.front()->ready;
393 if (nextReady <= curTick())
394 trySend();
395 else
396 bridge->schedule(sendEvent, nextReady);
397}
398
399void
400Bridge::BridgeSlavePort::recvRetry()
401{
402 inRetry = false;
403 Tick nextReady = responseQueue.front()->ready;
404 if (nextReady <= curTick())
405 trySend();
406 else
407 bridge->schedule(sendEvent, nextReady);
408}
409
410Tick
411Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt)
412{
413 return delay + masterPort.sendAtomic(pkt);
414}
415
416void
417Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt)
418{
419 std::list<PacketBuffer*>::iterator i;
420
421 pkt->pushLabel(name());
422
423 // check the response queue
424 for (i = responseQueue.begin(); i != responseQueue.end(); ++i) {
425 if (pkt->checkFunctional((*i)->pkt)) {
426 pkt->makeResponse();
427 return;
428 }
429 }
430
431 // also check the master port's request queue
432 if (masterPort.checkFunctional(pkt)) {
433 return;
434 }
435
436 pkt->popLabel();
437
438 // fall through if pkt still not satisfied
439 masterPort.sendFunctional(pkt);
440}
441
442bool
443Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt)
444{
445 bool found = false;
446 std::list<PacketBuffer*>::iterator i = requestQueue.begin();
447
448 while(i != requestQueue.end() && !found) {
449 if (pkt->checkFunctional((*i)->pkt)) {
450 pkt->makeResponse();
451 found = true;
452 }
453 ++i;
454 }
455
456 return found;
457}
458
459AddrRangeList
460Bridge::BridgeSlavePort::getAddrRanges()
461{
462 return ranges;
463}
464
465Bridge *
466BridgeParams::create()
467{
468 return new Bridge(this);
469}