bridge.cc (8922:17f037ad8918) | bridge.cc (8948:e95ee70f876c) |
---|---|
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) 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 148 DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n", 149 pkt->getSrc(), pkt->getDest(), pkt->getAddr()); 150 151 DPRINTF(BusBridge, "Request queue size: %d\n", requestQueue.size()); 152 153 slavePort.queueForSendTiming(pkt); 154 155 return true; 156} 157 158bool 159Bridge::BridgeSlavePort::recvTiming(PacketPtr pkt) 160{ 161 // should only see requests on the slave side 162 assert(pkt->isRequest()); 163 164 DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n", 165 pkt->getSrc(), pkt->getDest(), 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 DPRINTF(BusBridge, "response, new dest %d\n", pkt->getDest()); 281 delete buf; 282 283 Tick readyTime = curTick() + delay; 284 buf = new PacketBuffer(pkt, readyTime); 285 286 // If we're about to put this packet at the head of the queue, we 287 // need to schedule an event to do the transmit. Otherwise there 288 // should already be an event scheduled for sending the head 289 // packet. 290 if (responseQueue.empty()) { 291 bridge->schedule(sendEvent, readyTime); 292 } 293 responseQueue.push_back(buf); 294} 295 296void 297Bridge::BridgeMasterPort::trySend() 298{ 299 assert(!requestQueue.empty()); 300 301 PacketBuffer *buf = requestQueue.front(); 302 303 assert(buf->ready <= curTick()); 304 305 PacketPtr pkt = buf->pkt; 306 307 DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n", 308 buf->origSrc, pkt->getDest(), pkt->getAddr()); 309 310 // If the send was successful, make sure sender state was set to NULL 311 // otherwise we could get a NACK back of a packet that didn't expect a 312 // response and we would try to use freed memory. 313 314 Packet::SenderState *old_sender_state = pkt->senderState; 315 if (!buf->expectResponse) 316 pkt->senderState = NULL; 317 318 if (sendTiming(pkt)) { 319 // send successful 320 requestQueue.pop_front(); 321 // we no longer own packet, so it's not safe to look at it 322 buf->pkt = NULL; 323 324 if (!buf->expectResponse) { 325 // no response expected... deallocate packet buffer now. 326 DPRINTF(BusBridge, " successful: no response expected\n"); 327 delete buf; 328 } 329 330 // If there are more packets to send, schedule event to try again. 331 if (!requestQueue.empty()) { 332 buf = requestQueue.front(); 333 DPRINTF(BusBridge, "Scheduling next send\n"); 334 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1)); 335 } 336 } else { 337 DPRINTF(BusBridge, " unsuccessful\n"); 338 pkt->senderState = old_sender_state; 339 inRetry = true; 340 } 341 342 DPRINTF(BusBridge, "trySend: request queue size: %d\n", 343 requestQueue.size()); 344} 345 346void 347Bridge::BridgeSlavePort::trySend() 348{ 349 assert(!responseQueue.empty()); 350 351 PacketBuffer *buf = responseQueue.front(); 352 353 assert(buf->ready <= curTick()); 354 355 PacketPtr pkt = buf->pkt; 356 357 DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n", 358 buf->origSrc, pkt->getDest(), pkt->getAddr()); 359 360 bool was_nacked_here = buf->nackedHere; 361 362 // no need to worry about the sender state since we are not 363 // modifying it 364 365 if (sendTiming(pkt)) { 366 DPRINTF(BusBridge, " successful\n"); 367 // send successful 368 responseQueue.pop_front(); 369 // this is a response... deallocate packet buffer now. 370 delete buf; 371 372 if (!was_nacked_here) { 373 assert(outstandingResponses != 0); 374 --outstandingResponses; 375 } 376 377 // If there are more packets to send, schedule event to try again. 378 if (!responseQueue.empty()) { 379 buf = responseQueue.front(); 380 DPRINTF(BusBridge, "Scheduling next send\n"); 381 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1)); 382 } 383 } else { 384 DPRINTF(BusBridge, " unsuccessful\n"); 385 inRetry = true; 386 } 387 388 DPRINTF(BusBridge, "trySend: queue size: %d outstanding resp: %d\n", 389 responseQueue.size(), outstandingResponses); 390} 391 392void 393Bridge::BridgeMasterPort::recvRetry() 394{ 395 inRetry = false; 396 Tick nextReady = requestQueue.front()->ready; 397 if (nextReady <= curTick()) 398 trySend(); 399 else 400 bridge->schedule(sendEvent, nextReady); 401} 402 403void 404Bridge::BridgeSlavePort::recvRetry() 405{ 406 inRetry = false; 407 Tick nextReady = responseQueue.front()->ready; 408 if (nextReady <= curTick()) 409 trySend(); 410 else 411 bridge->schedule(sendEvent, nextReady); 412} 413 414Tick | 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) 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 148 DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n", 149 pkt->getSrc(), pkt->getDest(), pkt->getAddr()); 150 151 DPRINTF(BusBridge, "Request queue size: %d\n", requestQueue.size()); 152 153 slavePort.queueForSendTiming(pkt); 154 155 return true; 156} 157 158bool 159Bridge::BridgeSlavePort::recvTiming(PacketPtr pkt) 160{ 161 // should only see requests on the slave side 162 assert(pkt->isRequest()); 163 164 DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n", 165 pkt->getSrc(), pkt->getDest(), 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 DPRINTF(BusBridge, "response, new dest %d\n", pkt->getDest()); 281 delete buf; 282 283 Tick readyTime = curTick() + delay; 284 buf = new PacketBuffer(pkt, readyTime); 285 286 // If we're about to put this packet at the head of the queue, we 287 // need to schedule an event to do the transmit. Otherwise there 288 // should already be an event scheduled for sending the head 289 // packet. 290 if (responseQueue.empty()) { 291 bridge->schedule(sendEvent, readyTime); 292 } 293 responseQueue.push_back(buf); 294} 295 296void 297Bridge::BridgeMasterPort::trySend() 298{ 299 assert(!requestQueue.empty()); 300 301 PacketBuffer *buf = requestQueue.front(); 302 303 assert(buf->ready <= curTick()); 304 305 PacketPtr pkt = buf->pkt; 306 307 DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n", 308 buf->origSrc, pkt->getDest(), pkt->getAddr()); 309 310 // If the send was successful, make sure sender state was set to NULL 311 // otherwise we could get a NACK back of a packet that didn't expect a 312 // response and we would try to use freed memory. 313 314 Packet::SenderState *old_sender_state = pkt->senderState; 315 if (!buf->expectResponse) 316 pkt->senderState = NULL; 317 318 if (sendTiming(pkt)) { 319 // send successful 320 requestQueue.pop_front(); 321 // we no longer own packet, so it's not safe to look at it 322 buf->pkt = NULL; 323 324 if (!buf->expectResponse) { 325 // no response expected... deallocate packet buffer now. 326 DPRINTF(BusBridge, " successful: no response expected\n"); 327 delete buf; 328 } 329 330 // If there are more packets to send, schedule event to try again. 331 if (!requestQueue.empty()) { 332 buf = requestQueue.front(); 333 DPRINTF(BusBridge, "Scheduling next send\n"); 334 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1)); 335 } 336 } else { 337 DPRINTF(BusBridge, " unsuccessful\n"); 338 pkt->senderState = old_sender_state; 339 inRetry = true; 340 } 341 342 DPRINTF(BusBridge, "trySend: request queue size: %d\n", 343 requestQueue.size()); 344} 345 346void 347Bridge::BridgeSlavePort::trySend() 348{ 349 assert(!responseQueue.empty()); 350 351 PacketBuffer *buf = responseQueue.front(); 352 353 assert(buf->ready <= curTick()); 354 355 PacketPtr pkt = buf->pkt; 356 357 DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n", 358 buf->origSrc, pkt->getDest(), pkt->getAddr()); 359 360 bool was_nacked_here = buf->nackedHere; 361 362 // no need to worry about the sender state since we are not 363 // modifying it 364 365 if (sendTiming(pkt)) { 366 DPRINTF(BusBridge, " successful\n"); 367 // send successful 368 responseQueue.pop_front(); 369 // this is a response... deallocate packet buffer now. 370 delete buf; 371 372 if (!was_nacked_here) { 373 assert(outstandingResponses != 0); 374 --outstandingResponses; 375 } 376 377 // If there are more packets to send, schedule event to try again. 378 if (!responseQueue.empty()) { 379 buf = responseQueue.front(); 380 DPRINTF(BusBridge, "Scheduling next send\n"); 381 bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1)); 382 } 383 } else { 384 DPRINTF(BusBridge, " unsuccessful\n"); 385 inRetry = true; 386 } 387 388 DPRINTF(BusBridge, "trySend: queue size: %d outstanding resp: %d\n", 389 responseQueue.size(), outstandingResponses); 390} 391 392void 393Bridge::BridgeMasterPort::recvRetry() 394{ 395 inRetry = false; 396 Tick nextReady = requestQueue.front()->ready; 397 if (nextReady <= curTick()) 398 trySend(); 399 else 400 bridge->schedule(sendEvent, nextReady); 401} 402 403void 404Bridge::BridgeSlavePort::recvRetry() 405{ 406 inRetry = false; 407 Tick nextReady = responseQueue.front()->ready; 408 if (nextReady <= curTick()) 409 trySend(); 410 else 411 bridge->schedule(sendEvent, nextReady); 412} 413 414Tick |
415Bridge::BridgeMasterPort::recvAtomic(PacketPtr pkt) 416{ 417 // master port should never receive any atomic access (panic only 418 // works once the other side, i.e. the busses, respects this) 419 // 420 //panic("Master port on %s got a recvAtomic\n", bridge->name()); 421 return 0; 422} 423 424Tick | |
425Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt) 426{ 427 return delay + masterPort.sendAtomic(pkt); 428} 429 430void | 415Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt) 416{ 417 return delay + masterPort.sendAtomic(pkt); 418} 419 420void |
431Bridge::BridgeMasterPort::recvFunctional(PacketPtr pkt) 432{ 433 // master port should never receive any functional access (panic 434 // only works once the other side, i.e. the busses, respect this) 435 436 // panic("Master port on %s got a recvFunctional\n", bridge->name()); 437} 438 439void | |
440Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt) 441{ 442 std::list<PacketBuffer*>::iterator i; 443 444 pkt->pushLabel(name()); 445 446 // check the response queue 447 for (i = responseQueue.begin(); i != responseQueue.end(); ++i) { 448 if (pkt->checkFunctional((*i)->pkt)) { 449 pkt->makeResponse(); 450 return; 451 } 452 } 453 454 // also check the master port's request queue 455 if (masterPort.checkFunctional(pkt)) { 456 return; 457 } 458 459 pkt->popLabel(); 460 461 // fall through if pkt still not satisfied 462 masterPort.sendFunctional(pkt); 463} 464 465bool 466Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt) 467{ 468 bool found = false; 469 std::list<PacketBuffer*>::iterator i = requestQueue.begin(); 470 471 while(i != requestQueue.end() && !found) { 472 if (pkt->checkFunctional((*i)->pkt)) { 473 pkt->makeResponse(); 474 found = true; 475 } 476 ++i; 477 } 478 479 return found; 480} 481 482AddrRangeList 483Bridge::BridgeSlavePort::getAddrRanges() 484{ 485 return ranges; 486} 487 488Bridge * 489BridgeParams::create() 490{ 491 return new Bridge(this); 492} | 421Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt) 422{ 423 std::list<PacketBuffer*>::iterator i; 424 425 pkt->pushLabel(name()); 426 427 // check the response queue 428 for (i = responseQueue.begin(); i != responseQueue.end(); ++i) { 429 if (pkt->checkFunctional((*i)->pkt)) { 430 pkt->makeResponse(); 431 return; 432 } 433 } 434 435 // also check the master port's request queue 436 if (masterPort.checkFunctional(pkt)) { 437 return; 438 } 439 440 pkt->popLabel(); 441 442 // fall through if pkt still not satisfied 443 masterPort.sendFunctional(pkt); 444} 445 446bool 447Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt) 448{ 449 bool found = false; 450 std::list<PacketBuffer*>::iterator i = requestQueue.begin(); 451 452 while(i != requestQueue.end() && !found) { 453 if (pkt->checkFunctional((*i)->pkt)) { 454 pkt->makeResponse(); 455 found = true; 456 } 457 ++i; 458 } 459 460 return found; 461} 462 463AddrRangeList 464Bridge::BridgeSlavePort::getAddrRanges() 465{ 466 return ranges; 467} 468 469Bridge * 470BridgeParams::create() 471{ 472 return new Bridge(this); 473} |