/*
- * Copyright (c) 2011 ARM Limited
+ * Copyright (c) 2011-2012 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
*/
#include "base/trace.hh"
-#include "debug/BusBridge.hh"
+#include "debug/Bridge.hh"
#include "mem/bridge.hh"
#include "params/Bridge.hh"
-Bridge::BridgeSlavePort::BridgeSlavePort(const std::string &_name,
- Bridge* _bridge,
+Bridge::BridgeSlavePort::BridgeSlavePort(const std::string& _name,
+ Bridge& _bridge,
BridgeMasterPort& _masterPort,
- int _delay, int _nack_delay,
- int _resp_limit,
- std::vector<Range<Addr> > _ranges)
- : Port(_name, _bridge), bridge(_bridge), masterPort(_masterPort),
- delay(_delay), nackDelay(_nack_delay),
- ranges(_ranges.begin(), _ranges.end()),
- outstandingResponses(0), inRetry(false),
+ Cycles _delay, int _resp_limit,
+ std::vector<AddrRange> _ranges)
+ : SlavePort(_name, &_bridge), bridge(_bridge), masterPort(_masterPort),
+ delay(_delay), ranges(_ranges.begin(), _ranges.end()),
+ outstandingResponses(0), retryReq(false),
respQueueLimit(_resp_limit), sendEvent(*this)
{
}
-Bridge::BridgeMasterPort::BridgeMasterPort(const std::string &_name,
- Bridge* _bridge,
+Bridge::BridgeMasterPort::BridgeMasterPort(const std::string& _name,
+ Bridge& _bridge,
BridgeSlavePort& _slavePort,
- int _delay, int _req_limit)
- : Port(_name, _bridge), bridge(_bridge), slavePort(_slavePort),
- delay(_delay), inRetry(false), reqQueueLimit(_req_limit),
- sendEvent(*this)
+ Cycles _delay, int _req_limit)
+ : MasterPort(_name, &_bridge), bridge(_bridge), slavePort(_slavePort),
+ delay(_delay), reqQueueLimit(_req_limit), sendEvent(*this)
{
}
Bridge::Bridge(Params *p)
: MemObject(p),
- slavePort(p->name + "-slave", this, masterPort, p->delay,
- p->nack_delay, p->resp_size, p->ranges),
- masterPort(p->name + "-master", this, slavePort, p->delay, p->req_size),
- ackWrites(p->write_ack), _params(p)
+ slavePort(p->name + ".slave", *this, masterPort,
+ ticksToCycles(p->delay), p->resp_size, p->ranges),
+ masterPort(p->name + ".master", *this, slavePort,
+ ticksToCycles(p->delay), p->req_size)
{
- if (ackWrites)
- panic("No support for acknowledging writes\n");
}
-Port*
-Bridge::getPort(const std::string &if_name, int idx)
+BaseMasterPort&
+Bridge::getMasterPort(const std::string &if_name, PortID idx)
{
- if (if_name == "slave")
- return &slavePort;
- else if (if_name == "master")
- return &masterPort;
- else {
- panic("Bridge %s has no port named %s\n", name(), if_name);
- return NULL;
- }
+ if (if_name == "master")
+ return masterPort;
+ else
+ // pass it along to our super class
+ return MemObject::getMasterPort(if_name, idx);
}
+BaseSlavePort&
+Bridge::getSlavePort(const std::string &if_name, PortID idx)
+{
+ if (if_name == "slave")
+ return slavePort;
+ else
+ // pass it along to our super class
+ return MemObject::getSlavePort(if_name, idx);
+}
void
Bridge::init()
bool
Bridge::BridgeMasterPort::reqQueueFull()
{
- return requestQueue.size() == reqQueueLimit;
+ return transmitList.size() == reqQueueLimit;
}
bool
-Bridge::BridgeMasterPort::recvTiming(PacketPtr pkt)
+Bridge::BridgeMasterPort::recvTimingResp(PacketPtr pkt)
{
- // should only see responses on the master side
- assert(pkt->isResponse());
-
// all checks are done when the request is accepted on the slave
// side, so we are guaranteed to have space for the response
+ DPRINTF(Bridge, "recvTimingResp: %s addr 0x%x\n",
+ pkt->cmdString(), pkt->getAddr());
- DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n",
- pkt->getSrc(), pkt->getDest(), pkt->getAddr());
-
- DPRINTF(BusBridge, "Request queue size: %d\n", requestQueue.size());
+ DPRINTF(Bridge, "Request queue size: %d\n", transmitList.size());
- slavePort.queueForSendTiming(pkt);
+ slavePort.schedTimingResp(pkt, bridge.clockEdge(delay));
return true;
}
bool
-Bridge::BridgeSlavePort::recvTiming(PacketPtr pkt)
+Bridge::BridgeSlavePort::recvTimingReq(PacketPtr pkt)
{
- // should only see requests on the slave side
- assert(pkt->isRequest());
+ DPRINTF(Bridge, "recvTimingReq: %s addr 0x%x\n",
+ pkt->cmdString(), pkt->getAddr());
- DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n",
- pkt->getSrc(), pkt->getDest(), pkt->getAddr());
+ // ensure we do not have something waiting to retry
+ if(retryReq)
+ return false;
- DPRINTF(BusBridge, "Response queue size: %d outresp: %d\n",
- responseQueue.size(), outstandingResponses);
+ DPRINTF(Bridge, "Response queue size: %d outresp: %d\n",
+ transmitList.size(), outstandingResponses);
if (masterPort.reqQueueFull()) {
- DPRINTF(BusBridge, "Request queue full, nacking\n");
- nackRequest(pkt);
- return true;
- }
-
- if (pkt->needsResponse()) {
+ DPRINTF(Bridge, "Request queue full\n");
+ retryReq = true;
+ } else if (pkt->needsResponse()) {
if (respQueueFull()) {
- DPRINTF(BusBridge,
- "Response queue full, no space for response, nacking\n");
- DPRINTF(BusBridge,
- "queue size: %d outstanding resp: %d\n",
- responseQueue.size(), outstandingResponses);
- nackRequest(pkt);
- return true;
+ DPRINTF(Bridge, "Response queue full\n");
+ retryReq = true;
} else {
- DPRINTF(BusBridge, "Request Needs response, reserving space\n");
+ DPRINTF(Bridge, "Reserving space for response\n");
assert(outstandingResponses != respQueueLimit);
++outstandingResponses;
+ retryReq = false;
+ masterPort.schedTimingReq(pkt, bridge.clockEdge(delay));
}
}
- masterPort.queueForSendTiming(pkt);
-
- return true;
+ // remember that we are now stalling a packet and that we have to
+ // tell the sending master to retry once space becomes available,
+ // we make no distinction whether the stalling is due to the
+ // request queue or response queue being full
+ return !retryReq;
}
void
-Bridge::BridgeSlavePort::nackRequest(PacketPtr pkt)
+Bridge::BridgeSlavePort::retryStalledReq()
{
- // Nack the packet
- pkt->makeTimingResponse();
- pkt->setNacked();
-
- // The Nack packets are stored in the response queue just like any
- // other response, but they do not occupy any space as this is
- // tracked by the outstandingResponses, this guarantees space for
- // the Nack packets, but implicitly means we have an (unrealistic)
- // unbounded Nack queue.
-
- // put it on the list to send
- Tick readyTime = curTick() + nackDelay;
- PacketBuffer *buf = new PacketBuffer(pkt, readyTime, true);
-
- // nothing on the list, add it and we're done
- if (responseQueue.empty()) {
- assert(!sendEvent.scheduled());
- bridge->schedule(sendEvent, readyTime);
- responseQueue.push_back(buf);
- return;
- }
-
- assert(sendEvent.scheduled() || inRetry);
-
- // does it go at the end?
- if (readyTime >= responseQueue.back()->ready) {
- responseQueue.push_back(buf);
- return;
- }
-
- // ok, somewhere in the middle, fun
- std::list<PacketBuffer*>::iterator i = responseQueue.begin();
- std::list<PacketBuffer*>::iterator end = responseQueue.end();
- std::list<PacketBuffer*>::iterator begin = responseQueue.begin();
- bool done = false;
-
- while (i != end && !done) {
- if (readyTime < (*i)->ready) {
- if (i == begin)
- bridge->reschedule(sendEvent, readyTime);
- responseQueue.insert(i,buf);
- done = true;
- }
- i++;
+ if (retryReq) {
+ DPRINTF(Bridge, "Request waiting for retry, now retrying\n");
+ retryReq = false;
+ sendRetry();
}
- assert(done);
}
void
-Bridge::BridgeMasterPort::queueForSendTiming(PacketPtr pkt)
+Bridge::BridgeMasterPort::schedTimingReq(PacketPtr pkt, Tick when)
{
- Tick readyTime = curTick() + delay;
- PacketBuffer *buf = new PacketBuffer(pkt, readyTime);
+ // If we expect to see a response, we need to restore the source
+ // and destination field that is potentially changed by a second
+ // bus
+ if (!pkt->memInhibitAsserted() && pkt->needsResponse()) {
+ // Update the sender state so we can deal with the response
+ // appropriately
+ RequestState *req_state = new RequestState(pkt);
+ pkt->senderState = req_state;
+ }
// If we're about to put this packet at the head of the queue, we
// need to schedule an event to do the transmit. Otherwise there
// should already be an event scheduled for sending the head
// packet.
- if (requestQueue.empty()) {
- bridge->schedule(sendEvent, readyTime);
+ if (transmitList.empty()) {
+ bridge.schedule(sendEvent, when);
}
- assert(requestQueue.size() != reqQueueLimit);
+ assert(transmitList.size() != reqQueueLimit);
- requestQueue.push_back(buf);
+ transmitList.push_back(DeferredPacket(pkt, when));
}
void
-Bridge::BridgeSlavePort::queueForSendTiming(PacketPtr pkt)
+Bridge::BridgeSlavePort::schedTimingResp(PacketPtr pkt, Tick when)
{
// This is a response for a request we forwarded earlier. The
- // corresponding PacketBuffer should be stored in the packet's
+ // corresponding request state should be stored in the packet's
// senderState field.
- PacketBuffer *buf = dynamic_cast<PacketBuffer*>(pkt->senderState);
- assert(buf != NULL);
+ RequestState *req_state = dynamic_cast<RequestState*>(pkt->senderState);
+ assert(req_state != NULL);
// set up new packet dest & senderState based on values saved
// from original request
- buf->fixResponse(pkt);
+ req_state->fixResponse(pkt);
+ delete req_state;
- DPRINTF(BusBridge, "response, new dest %d\n", pkt->getDest());
- delete buf;
-
- Tick readyTime = curTick() + delay;
- buf = new PacketBuffer(pkt, readyTime);
+ // the bridge assumes that at least one bus has set the
+ // destination field of the packet
+ assert(pkt->isDestValid());
+ DPRINTF(Bridge, "response, new dest %d\n", pkt->getDest());
// If we're about to put this packet at the head of the queue, we
// need to schedule an event to do the transmit. Otherwise there
// should already be an event scheduled for sending the head
// packet.
- if (responseQueue.empty()) {
- bridge->schedule(sendEvent, readyTime);
+ if (transmitList.empty()) {
+ bridge.schedule(sendEvent, when);
}
- responseQueue.push_back(buf);
+
+ transmitList.push_back(DeferredPacket(pkt, when));
}
void
-Bridge::BridgeMasterPort::trySend()
+Bridge::BridgeMasterPort::trySendTiming()
{
- assert(!requestQueue.empty());
-
- PacketBuffer *buf = requestQueue.front();
+ assert(!transmitList.empty());
- assert(buf->ready <= curTick());
+ DeferredPacket req = transmitList.front();
- PacketPtr pkt = buf->pkt;
+ assert(req.tick <= curTick());
- DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n",
- buf->origSrc, pkt->getDest(), pkt->getAddr());
+ PacketPtr pkt = req.pkt;
- // If the send was successful, make sure sender state was set to NULL
- // otherwise we could get a NACK back of a packet that didn't expect a
- // response and we would try to use freed memory.
+ DPRINTF(Bridge, "trySend request addr 0x%x, queue size %d\n",
+ pkt->getAddr(), transmitList.size());
- Packet::SenderState *old_sender_state = pkt->senderState;
- if (!buf->expectResponse)
- pkt->senderState = NULL;
-
- if (sendTiming(pkt)) {
+ if (sendTimingReq(pkt)) {
// send successful
- requestQueue.pop_front();
- // we no longer own packet, so it's not safe to look at it
- buf->pkt = NULL;
-
- if (!buf->expectResponse) {
- // no response expected... deallocate packet buffer now.
- DPRINTF(BusBridge, " successful: no response expected\n");
- delete buf;
- }
+ transmitList.pop_front();
+ DPRINTF(Bridge, "trySend request successful\n");
// If there are more packets to send, schedule event to try again.
- if (!requestQueue.empty()) {
- buf = requestQueue.front();
- DPRINTF(BusBridge, "Scheduling next send\n");
- bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1));
+ if (!transmitList.empty()) {
+ req = transmitList.front();
+ DPRINTF(Bridge, "Scheduling next send\n");
+ bridge.schedule(sendEvent, std::max(req.tick,
+ bridge.nextCycle()));
}
- } else {
- DPRINTF(BusBridge, " unsuccessful\n");
- pkt->senderState = old_sender_state;
- inRetry = true;
+
+ // if we have stalled a request due to a full request queue,
+ // then send a retry at this point, also note that if the
+ // request we stalled was waiting for the response queue
+ // rather than the request queue we might stall it again
+ slavePort.retryStalledReq();
}
- DPRINTF(BusBridge, "trySend: request queue size: %d\n",
- requestQueue.size());
+ // if the send failed, then we try again once we receive a retry,
+ // and therefore there is no need to take any action
}
void
-Bridge::BridgeSlavePort::trySend()
+Bridge::BridgeSlavePort::trySendTiming()
{
- assert(!responseQueue.empty());
-
- PacketBuffer *buf = responseQueue.front();
+ assert(!transmitList.empty());
- assert(buf->ready <= curTick());
+ DeferredPacket resp = transmitList.front();
- PacketPtr pkt = buf->pkt;
+ assert(resp.tick <= curTick());
- DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n",
- buf->origSrc, pkt->getDest(), pkt->getAddr());
+ PacketPtr pkt = resp.pkt;
- bool was_nacked_here = buf->nackedHere;
+ DPRINTF(Bridge, "trySend response addr 0x%x, outstanding %d\n",
+ pkt->getAddr(), outstandingResponses);
- // no need to worry about the sender state since we are not
- // modifying it
-
- if (sendTiming(pkt)) {
- DPRINTF(BusBridge, " successful\n");
+ if (sendTimingResp(pkt)) {
// send successful
- responseQueue.pop_front();
- // this is a response... deallocate packet buffer now.
- delete buf;
+ transmitList.pop_front();
+ DPRINTF(Bridge, "trySend response successful\n");
- if (!was_nacked_here) {
- assert(outstandingResponses != 0);
- --outstandingResponses;
- }
+ assert(outstandingResponses != 0);
+ --outstandingResponses;
// If there are more packets to send, schedule event to try again.
- if (!responseQueue.empty()) {
- buf = responseQueue.front();
- DPRINTF(BusBridge, "Scheduling next send\n");
- bridge->schedule(sendEvent, std::max(buf->ready, curTick() + 1));
+ if (!transmitList.empty()) {
+ resp = transmitList.front();
+ DPRINTF(Bridge, "Scheduling next send\n");
+ bridge.schedule(sendEvent, std::max(resp.tick,
+ bridge.nextCycle()));
+ }
+
+ // if there is space in the request queue and we were stalling
+ // a request, it will definitely be possible to accept it now
+ // since there is guaranteed space in the response queue
+ if (!masterPort.reqQueueFull() && retryReq) {
+ DPRINTF(Bridge, "Request waiting for retry, now retrying\n");
+ retryReq = false;
+ sendRetry();
}
- } else {
- DPRINTF(BusBridge, " unsuccessful\n");
- inRetry = true;
}
- DPRINTF(BusBridge, "trySend: queue size: %d outstanding resp: %d\n",
- responseQueue.size(), outstandingResponses);
+ // if the send failed, then we try again once we receive a retry,
+ // and therefore there is no need to take any action
}
void
Bridge::BridgeMasterPort::recvRetry()
{
- inRetry = false;
- Tick nextReady = requestQueue.front()->ready;
+ Tick nextReady = transmitList.front().tick;
if (nextReady <= curTick())
- trySend();
+ trySendTiming();
else
- bridge->schedule(sendEvent, nextReady);
+ bridge.schedule(sendEvent, nextReady);
}
void
Bridge::BridgeSlavePort::recvRetry()
{
- inRetry = false;
- Tick nextReady = responseQueue.front()->ready;
+ Tick nextReady = transmitList.front().tick;
if (nextReady <= curTick())
- trySend();
+ trySendTiming();
else
- bridge->schedule(sendEvent, nextReady);
-}
-
-Tick
-Bridge::BridgeMasterPort::recvAtomic(PacketPtr pkt)
-{
- // master port should never receive any atomic access (panic only
- // works once the other side, i.e. the busses, respects this)
- //
- //panic("Master port on %s got a recvAtomic\n", bridge->name());
- return 0;
+ bridge.schedule(sendEvent, nextReady);
}
Tick
Bridge::BridgeSlavePort::recvAtomic(PacketPtr pkt)
{
- return delay + masterPort.sendAtomic(pkt);
-}
-
-void
-Bridge::BridgeMasterPort::recvFunctional(PacketPtr pkt)
-{
- // master port should never receive any functional access (panic
- // only works once the other side, i.e. the busses, respect this)
-
- // panic("Master port on %s got a recvFunctional\n", bridge->name());
+ return delay * bridge.clockPeriod() + masterPort.sendAtomic(pkt);
}
void
Bridge::BridgeSlavePort::recvFunctional(PacketPtr pkt)
{
- std::list<PacketBuffer*>::iterator i;
+ std::list<DeferredPacket>::iterator i;
pkt->pushLabel(name());
// check the response queue
- for (i = responseQueue.begin(); i != responseQueue.end(); ++i) {
- if (pkt->checkFunctional((*i)->pkt)) {
+ for (i = transmitList.begin(); i != transmitList.end(); ++i) {
+ if (pkt->checkFunctional((*i).pkt)) {
pkt->makeResponse();
return;
}
Bridge::BridgeMasterPort::checkFunctional(PacketPtr pkt)
{
bool found = false;
- std::list<PacketBuffer*>::iterator i = requestQueue.begin();
+ std::list<DeferredPacket>::iterator i = transmitList.begin();
- while(i != requestQueue.end() && !found) {
- if (pkt->checkFunctional((*i)->pkt)) {
+ while(i != transmitList.end() && !found) {
+ if (pkt->checkFunctional((*i).pkt)) {
pkt->makeResponse();
found = true;
}
return found;
}
-/** Function called by the port when the bridge is receiving a range change.*/
-void
-Bridge::BridgeMasterPort::recvRangeChange()
-{
- // no need to forward as the bridge has a fixed set of ranges
-}
-
-void
-Bridge::BridgeSlavePort::recvRangeChange()
-{
- // is a slave port so do nothing
-}
-
AddrRangeList
-Bridge::BridgeSlavePort::getAddrRanges()
+Bridge::BridgeSlavePort::getAddrRanges() const
{
return ranges;
}