2006-03-26 00:31:20 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Ali Saidi
|
2006-03-26 00:31:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2006-08-15 01:25:07 +02:00
|
|
|
* @file
|
|
|
|
* Definition of a bus object.
|
2006-03-26 00:31:20 +01:00
|
|
|
*/
|
|
|
|
|
2007-06-18 02:27:53 +02:00
|
|
|
#include <algorithm>
|
2007-03-09 00:57:15 +01:00
|
|
|
#include <limits>
|
|
|
|
|
2006-07-06 20:41:01 +02:00
|
|
|
#include "base/misc.hh"
|
2006-04-12 01:35:30 +02:00
|
|
|
#include "base/trace.hh"
|
2011-04-15 19:44:32 +02:00
|
|
|
#include "debug/Bus.hh"
|
|
|
|
#include "debug/BusAddrRanges.hh"
|
|
|
|
#include "debug/MMU.hh"
|
2006-04-12 01:35:30 +02:00
|
|
|
#include "mem/bus.hh"
|
2006-03-26 00:31:20 +01:00
|
|
|
|
2010-08-17 14:06:21 +02:00
|
|
|
Bus::Bus(const BusParams *p)
|
|
|
|
: MemObject(p), busId(p->bus_id), clock(p->clock),
|
|
|
|
headerCycles(p->header_cycles), width(p->width), tickNextIdle(0),
|
|
|
|
drainEvent(NULL), busIdle(this), inRetry(false), maxId(0),
|
|
|
|
defaultPort(NULL), funcPort(NULL), funcPortId(-4),
|
|
|
|
useDefaultRange(p->use_default_range), defaultBlockSize(p->block_size),
|
|
|
|
cachedBlockSize(0), cachedBlockSizeValid(false)
|
|
|
|
{
|
|
|
|
//width, clock period, and header cycles must be positive
|
|
|
|
if (width <= 0)
|
|
|
|
fatal("Bus width must be positive\n");
|
|
|
|
if (clock <= 0)
|
|
|
|
fatal("Bus clock period must be positive\n");
|
|
|
|
if (headerCycles <= 0)
|
|
|
|
fatal("Number of header cycles must be positive\n");
|
|
|
|
clearBusCache();
|
|
|
|
clearPortCache();
|
|
|
|
}
|
|
|
|
|
2006-05-26 19:48:35 +02:00
|
|
|
Port *
|
2006-06-14 05:19:28 +02:00
|
|
|
Bus::getPort(const std::string &if_name, int idx)
|
2006-05-26 19:48:35 +02:00
|
|
|
{
|
2006-11-02 21:20:37 +01:00
|
|
|
if (if_name == "default") {
|
2006-07-06 20:41:01 +02:00
|
|
|
if (defaultPort == NULL) {
|
|
|
|
defaultPort = new BusPort(csprintf("%s-default",name()), this,
|
2006-11-02 21:20:37 +01:00
|
|
|
defaultId);
|
2007-05-07 20:42:03 +02:00
|
|
|
cachedBlockSizeValid = false;
|
2006-07-06 20:41:01 +02:00
|
|
|
return defaultPort;
|
|
|
|
} else
|
|
|
|
fatal("Default port already set\n");
|
2006-11-02 21:20:37 +01:00
|
|
|
}
|
2007-04-04 19:56:38 +02:00
|
|
|
int id;
|
|
|
|
if (if_name == "functional") {
|
|
|
|
if (!funcPort) {
|
|
|
|
id = maxId++;
|
|
|
|
funcPort = new BusPort(csprintf("%s-p%d-func", name(), id), this, id);
|
|
|
|
funcPortId = id;
|
|
|
|
interfaces[id] = funcPort;
|
|
|
|
}
|
|
|
|
return funcPort;
|
|
|
|
}
|
2006-07-06 20:41:01 +02:00
|
|
|
|
2006-05-26 19:48:35 +02:00
|
|
|
// if_name ignored? forced to be empty?
|
2007-04-04 19:56:38 +02:00
|
|
|
id = maxId++;
|
2007-03-09 00:57:15 +01:00
|
|
|
assert(maxId < std::numeric_limits<typeof(maxId)>::max());
|
2006-05-26 19:48:35 +02:00
|
|
|
BusPort *bp = new BusPort(csprintf("%s-p%d", name(), id), this, id);
|
2007-03-09 00:57:15 +01:00
|
|
|
interfaces[id] = bp;
|
2007-05-07 20:42:03 +02:00
|
|
|
cachedBlockSizeValid = false;
|
2006-05-26 19:48:35 +02:00
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
2008-06-28 19:19:38 +02:00
|
|
|
void
|
|
|
|
Bus::deletePortRefs(Port *p)
|
2007-03-09 00:57:15 +01:00
|
|
|
{
|
2007-04-04 19:56:38 +02:00
|
|
|
|
2007-03-09 00:57:15 +01:00
|
|
|
BusPort *bp = dynamic_cast<BusPort*>(p);
|
|
|
|
if (bp == NULL)
|
|
|
|
panic("Couldn't convert Port* to BusPort*\n");
|
2007-04-04 19:56:38 +02:00
|
|
|
// If this is our one functional port
|
|
|
|
if (funcPort == bp)
|
2008-06-28 19:19:38 +02:00
|
|
|
return;
|
2007-03-09 00:57:15 +01:00
|
|
|
interfaces.erase(bp->getId());
|
2007-08-04 22:05:55 +02:00
|
|
|
clearBusCache();
|
2007-04-04 19:56:38 +02:00
|
|
|
delete bp;
|
2007-03-09 00:57:15 +01:00
|
|
|
}
|
|
|
|
|
2006-07-06 20:41:01 +02:00
|
|
|
/** Get the ranges of anyone other buses that we are connected to. */
|
2006-04-28 21:37:48 +02:00
|
|
|
void
|
|
|
|
Bus::init()
|
|
|
|
{
|
2007-03-09 00:57:15 +01:00
|
|
|
m5::hash_map<short,BusPort*>::iterator intIter;
|
2006-07-06 20:41:01 +02:00
|
|
|
|
2006-04-28 21:37:48 +02:00
|
|
|
for (intIter = interfaces.begin(); intIter != interfaces.end(); intIter++)
|
2007-03-09 00:57:15 +01:00
|
|
|
intIter->second->sendStatusChange(Port::RangeChange);
|
2006-04-28 21:37:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 13:58:24 +02:00
|
|
|
Bus::BusFreeEvent::BusFreeEvent(Bus *_bus)
|
|
|
|
: bus(_bus)
|
2006-10-10 23:24:03 +02:00
|
|
|
{}
|
2006-10-08 20:08:58 +02:00
|
|
|
|
2008-10-09 13:58:24 +02:00
|
|
|
void
|
|
|
|
Bus::BusFreeEvent::process()
|
2006-10-08 20:08:58 +02:00
|
|
|
{
|
2006-10-10 23:24:03 +02:00
|
|
|
bus->recvRetry(-1);
|
2006-10-08 20:08:58 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 13:58:24 +02:00
|
|
|
const char *
|
|
|
|
Bus::BusFreeEvent::description() const
|
2006-10-08 20:08:58 +02:00
|
|
|
{
|
|
|
|
return "bus became available";
|
|
|
|
}
|
|
|
|
|
2008-10-09 13:58:24 +02:00
|
|
|
Tick
|
|
|
|
Bus::calcPacketTiming(PacketPtr pkt)
|
2006-03-26 00:31:20 +01:00
|
|
|
{
|
2008-03-17 08:07:38 +01:00
|
|
|
// Bring tickNextIdle up to the present tick.
|
|
|
|
// There is some potential ambiguity where a cycle starts, which
|
|
|
|
// might make a difference when devices are acting right around a
|
|
|
|
// cycle boundary. Using a < allows things which happen exactly on
|
|
|
|
// a cycle boundary to take up only the following cycle. Anything
|
|
|
|
// that happens later will have to "wait" for the end of that
|
|
|
|
// cycle, and then start using the bus after that.
|
2011-01-08 06:50:29 +01:00
|
|
|
if (tickNextIdle < curTick()) {
|
|
|
|
tickNextIdle = curTick();
|
2007-06-20 20:54:17 +02:00
|
|
|
if (tickNextIdle % clock != 0)
|
2011-01-08 06:50:29 +01:00
|
|
|
tickNextIdle = curTick() - (curTick() % clock) + clock;
|
2007-06-20 20:54:17 +02:00
|
|
|
}
|
2006-10-10 05:24:21 +02:00
|
|
|
|
2008-03-17 08:07:38 +01:00
|
|
|
Tick headerTime = tickNextIdle + headerCycles * clock;
|
2008-02-26 08:20:08 +01:00
|
|
|
|
2006-10-10 05:24:21 +02:00
|
|
|
// The packet will be sent. Figure out how long it occupies the bus, and
|
|
|
|
// how much of that time is for the first "word", aka bus width.
|
2006-10-10 00:12:45 +02:00
|
|
|
int numCycles = 0;
|
2008-02-26 08:20:08 +01:00
|
|
|
if (pkt->hasData()) {
|
2006-10-10 00:12:45 +02:00
|
|
|
// If a packet has data, it needs ceil(size/width) cycles to send it
|
2008-02-26 08:20:08 +01:00
|
|
|
int dataSize = pkt->getSize();
|
|
|
|
numCycles += dataSize/width;
|
|
|
|
if (dataSize % width)
|
2006-10-10 00:12:45 +02:00
|
|
|
numCycles++;
|
|
|
|
}
|
|
|
|
|
2006-10-10 05:24:21 +02:00
|
|
|
// The first word will be delivered after the current tick, the delivery
|
|
|
|
// of the address if any, and one bus cycle to deliver the data
|
2008-02-26 08:20:08 +01:00
|
|
|
pkt->firstWordTime = headerTime + clock;
|
|
|
|
|
|
|
|
pkt->finishTime = headerTime + numCycles * clock;
|
2008-03-17 08:07:38 +01:00
|
|
|
|
|
|
|
return headerTime;
|
2008-02-26 08:20:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Bus::occupyBus(Tick until)
|
|
|
|
{
|
2008-03-17 08:07:38 +01:00
|
|
|
if (until == 0) {
|
|
|
|
// shortcut for express snoop packets
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-26 08:20:08 +01:00
|
|
|
tickNextIdle = until;
|
2008-10-09 13:58:24 +02:00
|
|
|
reschedule(busIdle, tickNextIdle, true);
|
2006-10-10 05:24:21 +02:00
|
|
|
|
|
|
|
DPRINTF(Bus, "The bus is now occupied from tick %d to %d\n",
|
2011-01-08 06:50:29 +01:00
|
|
|
curTick(), tickNextIdle);
|
2006-10-11 05:28:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Function called by the port when the bus is receiving a Timing
|
|
|
|
* transaction.*/
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
Bus::recvTiming(PacketPtr pkt)
|
2006-10-11 05:28:33 +02:00
|
|
|
{
|
2007-07-25 07:37:41 +02:00
|
|
|
short src = pkt->getSrc();
|
2006-10-11 05:28:33 +02:00
|
|
|
|
2007-08-04 22:05:55 +02:00
|
|
|
BusPort *src_port;
|
|
|
|
if (src == defaultId)
|
|
|
|
src_port = defaultPort;
|
|
|
|
else {
|
|
|
|
src_port = checkBusCache(src);
|
|
|
|
if (src_port == NULL) {
|
|
|
|
src_port = interfaces[src];
|
|
|
|
updateBusCache(src, src_port);
|
|
|
|
}
|
|
|
|
}
|
2006-10-11 05:28:33 +02:00
|
|
|
|
|
|
|
// If the bus is busy, or other devices are in line ahead of the current
|
|
|
|
// one, put this device on the retry list.
|
2007-07-29 22:24:48 +02:00
|
|
|
if (!pkt->isExpressSnoop() &&
|
2011-01-08 06:50:29 +01:00
|
|
|
(tickNextIdle > curTick() ||
|
2007-07-25 07:37:41 +02:00
|
|
|
(retryList.size() && (!inRetry || src_port != retryList.front()))))
|
2007-05-19 07:35:04 +02:00
|
|
|
{
|
2007-07-25 07:37:41 +02:00
|
|
|
addToRetryList(src_port);
|
2007-09-17 01:46:38 +02:00
|
|
|
DPRINTF(Bus, "recvTiming: src %d dst %d %s 0x%x BUSY\n",
|
|
|
|
src, pkt->getDest(), pkt->cmdString(), pkt->getAddr());
|
2006-10-11 05:28:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-09-17 01:46:38 +02:00
|
|
|
DPRINTF(Bus, "recvTiming: src %d dst %d %s 0x%x\n",
|
|
|
|
src, pkt->getDest(), pkt->cmdString(), pkt->getAddr());
|
|
|
|
|
2008-03-17 08:07:38 +01:00
|
|
|
Tick headerFinishTime = pkt->isExpressSnoop() ? 0 : calcPacketTiming(pkt);
|
|
|
|
Tick packetFinishTime = pkt->isExpressSnoop() ? 0 : pkt->finishTime;
|
2007-07-25 07:37:41 +02:00
|
|
|
|
2006-10-11 05:28:33 +02:00
|
|
|
short dest = pkt->getDest();
|
2007-07-25 07:37:41 +02:00
|
|
|
int dest_port_id;
|
|
|
|
Port *dest_port;
|
2007-03-23 18:09:37 +01:00
|
|
|
|
2006-10-11 05:28:33 +02:00
|
|
|
if (dest == Packet::Broadcast) {
|
2007-07-25 07:37:41 +02:00
|
|
|
dest_port_id = findPort(pkt->getAddr());
|
2007-07-27 02:04:12 +02:00
|
|
|
dest_port = (dest_port_id == defaultId) ?
|
|
|
|
defaultPort : interfaces[dest_port_id];
|
2007-08-10 22:14:01 +02:00
|
|
|
SnoopIter s_end = snoopPorts.end();
|
|
|
|
for (SnoopIter s_iter = snoopPorts.begin(); s_iter != s_end; s_iter++) {
|
2007-07-25 07:37:41 +02:00
|
|
|
BusPort *p = *s_iter;
|
|
|
|
if (p != dest_port && p != src_port) {
|
|
|
|
// cache is not allowed to refuse snoop
|
2007-08-10 22:14:01 +02:00
|
|
|
bool success M5_VAR_USED = p->sendTiming(pkt);
|
2007-07-25 07:37:41 +02:00
|
|
|
assert(success);
|
2006-10-11 05:28:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2008-07-16 20:10:33 +02:00
|
|
|
assert(dest < maxId);
|
2007-07-25 07:37:41 +02:00
|
|
|
assert(dest != src); // catch infinite loops
|
|
|
|
dest_port_id = dest;
|
2007-08-04 22:05:55 +02:00
|
|
|
if (dest_port_id == defaultId)
|
|
|
|
dest_port = defaultPort;
|
|
|
|
else {
|
|
|
|
dest_port = checkBusCache(dest);
|
|
|
|
if (dest_port == NULL) {
|
|
|
|
dest_port = interfaces[dest_port_id];
|
|
|
|
// updateBusCache(dest_port_id, dest_port);
|
|
|
|
}
|
|
|
|
}
|
2007-07-27 02:04:12 +02:00
|
|
|
dest_port = (dest_port_id == defaultId) ?
|
|
|
|
defaultPort : interfaces[dest_port_id];
|
2006-10-11 05:28:33 +02:00
|
|
|
}
|
|
|
|
|
2007-07-25 07:37:41 +02:00
|
|
|
if (dest_port_id == src) {
|
|
|
|
// Must be forwarded snoop up from below...
|
|
|
|
assert(dest == Packet::Broadcast);
|
|
|
|
} else {
|
|
|
|
// send to actual target
|
|
|
|
if (!dest_port->sendTiming(pkt)) {
|
|
|
|
// Packet not successfully sent. Leave or put it on the retry list.
|
|
|
|
// illegal to block responses... can lead to deadlock
|
|
|
|
assert(!pkt->isResponse());
|
2009-10-04 03:07:39 +02:00
|
|
|
// It's also illegal to force a transaction to retry after
|
|
|
|
// someone else has committed to respond.
|
|
|
|
assert(!pkt->memInhibitAsserted());
|
2007-09-17 01:46:38 +02:00
|
|
|
DPRINTF(Bus, "recvTiming: src %d dst %d %s 0x%x TGT RETRY\n",
|
|
|
|
src, pkt->getDest(), pkt->cmdString(), pkt->getAddr());
|
2007-07-25 07:37:41 +02:00
|
|
|
addToRetryList(src_port);
|
2008-03-17 08:07:38 +01:00
|
|
|
occupyBus(headerFinishTime);
|
2007-07-25 07:37:41 +02:00
|
|
|
return false;
|
2006-10-09 00:44:49 +02:00
|
|
|
}
|
2008-03-17 08:07:38 +01:00
|
|
|
// send OK, fall through... pkt may have been deleted by
|
|
|
|
// target at this point, so it should *not* be referenced
|
|
|
|
// again. We'll set it to NULL here just to be safe.
|
|
|
|
pkt = NULL;
|
2006-11-14 23:15:05 +01:00
|
|
|
}
|
2007-07-25 07:37:41 +02:00
|
|
|
|
2008-03-17 08:07:38 +01:00
|
|
|
occupyBus(packetFinishTime);
|
2008-02-26 08:20:08 +01:00
|
|
|
|
2007-07-25 07:37:41 +02:00
|
|
|
// Packet was successfully sent.
|
|
|
|
// Also take care of retries
|
|
|
|
if (inRetry) {
|
|
|
|
DPRINTF(Bus, "Remove retry from list %d\n", src);
|
|
|
|
retryList.front()->onRetryList(false);
|
|
|
|
retryList.pop_front();
|
|
|
|
inRetry = false;
|
2006-05-31 00:57:42 +02:00
|
|
|
}
|
2007-07-25 07:37:41 +02:00
|
|
|
return true;
|
2006-03-26 00:31:20 +01:00
|
|
|
}
|
|
|
|
|
2006-05-31 00:57:42 +02:00
|
|
|
void
|
|
|
|
Bus::recvRetry(int id)
|
|
|
|
{
|
2006-10-11 06:54:47 +02:00
|
|
|
// If there's anything waiting, and the bus isn't busy...
|
2011-01-08 06:50:29 +01:00
|
|
|
if (retryList.size() && curTick() >= tickNextIdle) {
|
2006-10-10 23:24:03 +02:00
|
|
|
//retryingPort = retryList.front();
|
|
|
|
inRetry = true;
|
2007-05-07 20:42:03 +02:00
|
|
|
DPRINTF(Bus, "Sending a retry to %s\n", retryList.front()->getPeer()->name());
|
2006-10-10 23:24:03 +02:00
|
|
|
retryList.front()->sendRetry();
|
|
|
|
// If inRetry is still true, sendTiming wasn't called
|
|
|
|
if (inRetry)
|
2006-10-11 06:26:21 +02:00
|
|
|
{
|
|
|
|
retryList.front()->onRetryList(false);
|
|
|
|
retryList.pop_front();
|
|
|
|
inRetry = false;
|
|
|
|
|
2007-05-10 04:23:01 +02:00
|
|
|
//Bring tickNextIdle up to the present
|
2011-01-08 06:50:29 +01:00
|
|
|
while (tickNextIdle < curTick())
|
2007-05-07 20:42:03 +02:00
|
|
|
tickNextIdle += clock;
|
2006-10-11 06:26:21 +02:00
|
|
|
|
2007-05-10 04:23:01 +02:00
|
|
|
//Burn a cycle for the missed grant.
|
|
|
|
tickNextIdle += clock;
|
|
|
|
|
2008-10-09 13:58:24 +02:00
|
|
|
reschedule(busIdle, tickNextIdle, true);
|
2006-10-11 06:26:21 +02:00
|
|
|
}
|
2006-05-31 00:57:42 +02:00
|
|
|
}
|
2006-11-07 20:25:54 +01:00
|
|
|
//If we weren't able to drain before, we might be able to now.
|
2011-01-08 06:50:29 +01:00
|
|
|
if (drainEvent && retryList.size() == 0 && curTick() >= tickNextIdle) {
|
2006-11-07 20:25:54 +01:00
|
|
|
drainEvent->process();
|
2006-11-09 17:33:44 +01:00
|
|
|
// Clear the drain event once we're done with it.
|
|
|
|
drainEvent = NULL;
|
|
|
|
}
|
2006-05-31 00:57:42 +02:00
|
|
|
}
|
|
|
|
|
2007-07-16 05:09:03 +02:00
|
|
|
int
|
|
|
|
Bus::findPort(Addr addr)
|
2006-03-26 00:31:20 +01:00
|
|
|
{
|
|
|
|
/* An interval tree would be a better way to do this. --ali. */
|
2010-08-17 14:06:21 +02:00
|
|
|
int dest_id;
|
2006-03-26 00:31:20 +01:00
|
|
|
|
2007-08-04 22:05:55 +02:00
|
|
|
dest_id = checkPortCache(addr);
|
2010-08-17 14:06:21 +02:00
|
|
|
if (dest_id != -1)
|
|
|
|
return dest_id;
|
|
|
|
|
|
|
|
// Check normal port ranges
|
|
|
|
PortIter i = portMap.find(RangeSize(addr,1));
|
|
|
|
if (i != portMap.end()) {
|
|
|
|
dest_id = i->second;
|
|
|
|
updatePortCache(dest_id, i->first.start, i->first.end);
|
|
|
|
return dest_id;
|
2007-08-04 22:05:55 +02:00
|
|
|
}
|
2006-07-06 20:41:01 +02:00
|
|
|
|
|
|
|
// Check if this matches the default range
|
2010-08-17 14:06:21 +02:00
|
|
|
if (useDefaultRange) {
|
2007-08-10 22:14:01 +02:00
|
|
|
AddrRangeIter a_end = defaultRange.end();
|
|
|
|
for (AddrRangeIter i = defaultRange.begin(); i != a_end; i++) {
|
|
|
|
if (*i == addr) {
|
2006-08-28 18:55:13 +02:00
|
|
|
DPRINTF(Bus, " found addr %#llx on default\n", addr);
|
2007-07-16 05:09:03 +02:00
|
|
|
return defaultId;
|
2006-07-06 20:41:01 +02:00
|
|
|
}
|
|
|
|
}
|
2006-11-02 21:20:37 +01:00
|
|
|
|
2010-08-17 14:06:21 +02:00
|
|
|
panic("Unable to find destination for addr %#llx\n", addr);
|
2006-07-06 20:41:01 +02:00
|
|
|
}
|
|
|
|
|
2010-08-17 14:06:21 +02:00
|
|
|
DPRINTF(Bus, "Unable to find destination for addr %#llx, "
|
|
|
|
"will use default port\n", addr);
|
|
|
|
return defaultId;
|
2006-03-26 00:31:20 +01:00
|
|
|
}
|
|
|
|
|
2006-10-09 00:48:03 +02:00
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
/** Function called by the port when the bus is receiving a Atomic
|
2006-03-26 00:31:20 +01:00
|
|
|
* transaction.*/
|
|
|
|
Tick
|
2006-10-20 09:10:12 +02:00
|
|
|
Bus::recvAtomic(PacketPtr pkt)
|
2006-03-26 00:31:20 +01:00
|
|
|
{
|
2006-05-26 20:17:33 +02:00
|
|
|
DPRINTF(Bus, "recvAtomic: packet src %d dest %d addr 0x%x cmd %s\n",
|
|
|
|
pkt->getSrc(), pkt->getDest(), pkt->getAddr(), pkt->cmdString());
|
|
|
|
assert(pkt->getDest() == Packet::Broadcast);
|
2007-06-30 19:16:18 +02:00
|
|
|
assert(pkt->isRequest());
|
2006-11-09 17:37:26 +01:00
|
|
|
|
2007-06-18 02:27:53 +02:00
|
|
|
// Variables for recording original command and snoop response (if
|
|
|
|
// any)... if a snooper respondes, we will need to restore
|
|
|
|
// original command so that additional snoops can take place
|
|
|
|
// properly
|
|
|
|
MemCmd orig_cmd = pkt->cmd;
|
2007-07-02 10:02:35 +02:00
|
|
|
MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
|
|
|
|
Tick snoop_response_latency = 0;
|
2007-06-30 19:16:18 +02:00
|
|
|
int orig_src = pkt->getSrc();
|
2006-11-14 07:12:52 +01:00
|
|
|
|
2007-07-16 05:09:03 +02:00
|
|
|
int target_port_id = findPort(pkt->getAddr());
|
2007-08-04 22:05:55 +02:00
|
|
|
BusPort *target_port;
|
|
|
|
if (target_port_id == defaultId)
|
|
|
|
target_port = defaultPort;
|
|
|
|
else {
|
|
|
|
target_port = checkBusCache(target_port_id);
|
|
|
|
if (target_port == NULL) {
|
|
|
|
target_port = interfaces[target_port_id];
|
|
|
|
updateBusCache(target_port_id, target_port);
|
|
|
|
}
|
|
|
|
}
|
2006-11-14 07:12:52 +01:00
|
|
|
|
2007-06-18 02:27:53 +02:00
|
|
|
SnoopIter s_end = snoopPorts.end();
|
|
|
|
for (SnoopIter s_iter = snoopPorts.begin(); s_iter != s_end; s_iter++) {
|
|
|
|
BusPort *p = *s_iter;
|
|
|
|
// same port should not have both target addresses and snooping
|
|
|
|
assert(p != target_port);
|
|
|
|
if (p->getId() != pkt->getSrc()) {
|
2007-07-02 10:02:35 +02:00
|
|
|
Tick latency = p->sendAtomic(pkt);
|
2007-06-30 19:16:18 +02:00
|
|
|
if (pkt->isResponse()) {
|
2007-06-18 02:27:53 +02:00
|
|
|
// response from snoop agent
|
|
|
|
assert(pkt->cmd != orig_cmd);
|
|
|
|
assert(pkt->memInhibitAsserted());
|
|
|
|
// should only happen once
|
2007-07-02 10:02:35 +02:00
|
|
|
assert(snoop_response_cmd == MemCmd::InvalidCmd);
|
2007-06-18 02:27:53 +02:00
|
|
|
// save response state
|
2007-07-02 10:02:35 +02:00
|
|
|
snoop_response_cmd = pkt->cmd;
|
|
|
|
snoop_response_latency = latency;
|
2007-06-18 02:27:53 +02:00
|
|
|
// restore original packet state for remaining snoopers
|
|
|
|
pkt->cmd = orig_cmd;
|
2007-06-30 19:16:18 +02:00
|
|
|
pkt->setSrc(orig_src);
|
|
|
|
pkt->setDest(Packet::Broadcast);
|
2007-06-18 02:27:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-16 05:09:03 +02:00
|
|
|
Tick response_latency = 0;
|
|
|
|
|
|
|
|
// we can get requests sent up from the memory side of the bus for
|
|
|
|
// snooping... don't send them back down!
|
|
|
|
if (target_port_id != pkt->getSrc()) {
|
|
|
|
response_latency = target_port->sendAtomic(pkt);
|
|
|
|
}
|
2007-06-18 02:27:53 +02:00
|
|
|
|
|
|
|
// if we got a response from a snooper, restore it here
|
2007-07-02 10:02:35 +02:00
|
|
|
if (snoop_response_cmd != MemCmd::InvalidCmd) {
|
2007-06-18 02:27:53 +02:00
|
|
|
// no one else should have responded
|
2007-06-30 19:16:18 +02:00
|
|
|
assert(!pkt->isResponse());
|
2007-06-18 02:27:53 +02:00
|
|
|
assert(pkt->cmd == orig_cmd);
|
2007-07-02 10:02:35 +02:00
|
|
|
pkt->cmd = snoop_response_cmd;
|
|
|
|
response_latency = snoop_response_latency;
|
2007-06-18 02:27:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// why do we have this packet field and the return value both???
|
2011-01-08 06:50:29 +01:00
|
|
|
pkt->finishTime = curTick() + response_latency;
|
2007-07-02 10:02:35 +02:00
|
|
|
return response_latency;
|
2006-03-26 00:31:20 +01:00
|
|
|
}
|
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
/** Function called by the port when the bus is receiving a Functional
|
2006-03-26 00:31:20 +01:00
|
|
|
* transaction.*/
|
|
|
|
void
|
2006-10-20 09:10:12 +02:00
|
|
|
Bus::recvFunctional(PacketPtr pkt)
|
2006-03-26 00:31:20 +01:00
|
|
|
{
|
2008-01-02 23:42:24 +01:00
|
|
|
if (!pkt->isPrint()) {
|
|
|
|
// don't do DPRINTFs on PrintReq as it clutters up the output
|
|
|
|
DPRINTF(Bus,
|
|
|
|
"recvFunctional: packet src %d dest %d addr 0x%x cmd %s\n",
|
|
|
|
pkt->getSrc(), pkt->getDest(), pkt->getAddr(),
|
|
|
|
pkt->cmdString());
|
|
|
|
}
|
2006-05-26 20:17:33 +02:00
|
|
|
assert(pkt->getDest() == Packet::Broadcast);
|
2006-11-14 07:12:52 +01:00
|
|
|
|
2007-07-16 05:09:03 +02:00
|
|
|
int port_id = findPort(pkt->getAddr());
|
2007-07-27 02:04:12 +02:00
|
|
|
Port *port = (port_id == defaultId) ? defaultPort : interfaces[port_id];
|
2007-07-25 07:37:41 +02:00
|
|
|
// The packet may be changed by another bus on snoops, restore the
|
|
|
|
// id after each
|
|
|
|
int src_id = pkt->getSrc();
|
|
|
|
|
|
|
|
assert(pkt->isRequest()); // hasn't already been satisfied
|
|
|
|
|
2007-08-10 22:14:01 +02:00
|
|
|
SnoopIter s_end = snoopPorts.end();
|
|
|
|
for (SnoopIter s_iter = snoopPorts.begin(); s_iter != s_end; s_iter++) {
|
2007-07-25 07:37:41 +02:00
|
|
|
BusPort *p = *s_iter;
|
|
|
|
if (p != port && p->getId() != src_id) {
|
|
|
|
p->sendFunctional(pkt);
|
|
|
|
}
|
|
|
|
if (pkt->isResponse()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pkt->setSrc(src_id);
|
|
|
|
}
|
2006-10-12 21:02:25 +02:00
|
|
|
|
2007-06-30 19:16:18 +02:00
|
|
|
// If the snooping hasn't found what we were looking for, keep going.
|
2007-07-16 05:09:03 +02:00
|
|
|
if (!pkt->isResponse() && port_id != pkt->getSrc()) {
|
2006-11-14 07:38:42 +01:00
|
|
|
port->sendFunctional(pkt);
|
2006-11-14 01:56:34 +01:00
|
|
|
}
|
2006-03-26 00:31:20 +01:00
|
|
|
}
|
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
/** Function called by the port when the bus is receiving a status change.*/
|
2006-03-26 00:31:20 +01:00
|
|
|
void
|
|
|
|
Bus::recvStatusChange(Port::Status status, int id)
|
|
|
|
{
|
2006-07-06 20:41:01 +02:00
|
|
|
AddrRangeList ranges;
|
2007-05-22 08:36:09 +02:00
|
|
|
bool snoops;
|
2006-07-06 20:41:01 +02:00
|
|
|
AddrRangeIter iter;
|
|
|
|
|
2007-08-10 22:14:01 +02:00
|
|
|
if (inRecvStatusChange.count(id))
|
|
|
|
return;
|
|
|
|
inRecvStatusChange.insert(id);
|
|
|
|
|
2006-04-07 22:26:22 +02:00
|
|
|
assert(status == Port::RangeChange &&
|
2006-03-26 00:31:20 +01:00
|
|
|
"The other statuses need to be implemented.");
|
2006-04-07 22:26:22 +02:00
|
|
|
|
2006-05-26 20:24:46 +02:00
|
|
|
DPRINTF(BusAddrRanges, "received RangeChange from device id %d\n", id);
|
2006-05-26 20:17:33 +02:00
|
|
|
|
2007-08-04 22:05:55 +02:00
|
|
|
clearPortCache();
|
2006-07-06 20:41:01 +02:00
|
|
|
if (id == defaultId) {
|
|
|
|
defaultRange.clear();
|
2006-11-02 21:20:37 +01:00
|
|
|
// Only try to update these ranges if the user set a default responder.
|
2010-08-17 14:06:21 +02:00
|
|
|
if (useDefaultRange) {
|
2006-11-02 21:20:37 +01:00
|
|
|
defaultPort->getPeerAddressRanges(ranges, snoops);
|
2007-05-22 08:36:09 +02:00
|
|
|
assert(snoops == false);
|
2006-11-02 21:20:37 +01:00
|
|
|
for(iter = ranges.begin(); iter != ranges.end(); iter++) {
|
|
|
|
defaultRange.push_back(*iter);
|
|
|
|
DPRINTF(BusAddrRanges, "Adding range %#llx - %#llx for default range\n",
|
|
|
|
iter->start, iter->end);
|
|
|
|
}
|
2006-07-06 20:41:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
2006-04-20 23:14:30 +02:00
|
|
|
|
2007-03-09 00:57:15 +01:00
|
|
|
assert((id < maxId && id >= 0) || id == defaultId);
|
2007-05-22 08:36:09 +02:00
|
|
|
BusPort *port = interfaces[id];
|
2006-07-06 20:41:01 +02:00
|
|
|
|
|
|
|
// Clean out any previously existent ids
|
2007-05-22 08:36:09 +02:00
|
|
|
for (PortIter portIter = portMap.begin();
|
|
|
|
portIter != portMap.end(); ) {
|
2006-12-15 07:49:41 +01:00
|
|
|
if (portIter->second == id)
|
|
|
|
portMap.erase(portIter++);
|
2006-07-06 20:41:01 +02:00
|
|
|
else
|
|
|
|
portIter++;
|
|
|
|
}
|
2006-04-06 06:51:46 +02:00
|
|
|
|
2007-05-22 08:36:09 +02:00
|
|
|
for (SnoopIter s_iter = snoopPorts.begin();
|
|
|
|
s_iter != snoopPorts.end(); ) {
|
|
|
|
if ((*s_iter)->getId() == id)
|
|
|
|
s_iter = snoopPorts.erase(s_iter);
|
2006-08-22 22:08:18 +02:00
|
|
|
else
|
2007-05-22 08:36:09 +02:00
|
|
|
s_iter++;
|
2006-08-22 22:08:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-06 20:41:01 +02:00
|
|
|
port->getPeerAddressRanges(ranges, snoops);
|
2006-03-26 00:31:20 +01:00
|
|
|
|
2007-05-22 08:36:09 +02:00
|
|
|
if (snoops) {
|
|
|
|
DPRINTF(BusAddrRanges, "Adding id %d to snoop list\n", id);
|
|
|
|
snoopPorts.push_back(port);
|
2006-08-22 22:08:18 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 08:36:09 +02:00
|
|
|
for (iter = ranges.begin(); iter != ranges.end(); iter++) {
|
2006-08-28 18:55:13 +02:00
|
|
|
DPRINTF(BusAddrRanges, "Adding range %#llx - %#llx for id %d\n",
|
2006-12-15 07:49:41 +01:00
|
|
|
iter->start, iter->end, id);
|
2008-06-21 07:06:27 +02:00
|
|
|
if (portMap.insert(*iter, id) == portMap.end()) {
|
|
|
|
int conflict_id = portMap.find(*iter)->second;
|
|
|
|
fatal("%s has two ports with same range:\n\t%s\n\t%s\n",
|
|
|
|
name(), interfaces[id]->getPeer()->name(),
|
|
|
|
interfaces[conflict_id]->getPeer()->name());
|
|
|
|
}
|
2006-07-06 20:41:01 +02:00
|
|
|
}
|
2006-04-20 23:14:30 +02:00
|
|
|
}
|
2006-12-15 07:49:41 +01:00
|
|
|
DPRINTF(MMU, "port list has %d entries\n", portMap.size());
|
2006-04-28 21:37:48 +02:00
|
|
|
|
|
|
|
// tell all our peers that our address range has changed.
|
|
|
|
// Don't tell the device that caused this change, it already knows
|
2007-03-09 00:57:15 +01:00
|
|
|
m5::hash_map<short,BusPort*>::iterator intIter;
|
|
|
|
|
|
|
|
for (intIter = interfaces.begin(); intIter != interfaces.end(); intIter++)
|
2007-04-04 19:56:38 +02:00
|
|
|
if (intIter->first != id && intIter->first != funcPortId)
|
2007-03-09 00:57:15 +01:00
|
|
|
intIter->second->sendStatusChange(Port::RangeChange);
|
2006-07-06 20:41:01 +02:00
|
|
|
|
|
|
|
if (id != defaultId && defaultPort)
|
|
|
|
defaultPort->sendStatusChange(Port::RangeChange);
|
2007-08-10 22:14:01 +02:00
|
|
|
inRecvStatusChange.erase(id);
|
2006-03-26 00:31:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-05-22 08:36:09 +02:00
|
|
|
Bus::addressRanges(AddrRangeList &resp, bool &snoop, int id)
|
2006-03-26 00:31:20 +01:00
|
|
|
{
|
2006-04-28 21:37:48 +02:00
|
|
|
resp.clear();
|
2007-05-22 08:36:09 +02:00
|
|
|
snoop = false;
|
2006-04-28 21:37:48 +02:00
|
|
|
|
2006-05-26 20:24:46 +02:00
|
|
|
DPRINTF(BusAddrRanges, "received address range request, returning:\n");
|
2006-07-06 20:41:01 +02:00
|
|
|
|
2007-05-22 08:36:09 +02:00
|
|
|
for (AddrRangeIter dflt_iter = defaultRange.begin();
|
|
|
|
dflt_iter != defaultRange.end(); dflt_iter++) {
|
2006-07-06 20:41:01 +02:00
|
|
|
resp.push_back(*dflt_iter);
|
2006-11-14 01:56:34 +01:00
|
|
|
DPRINTF(BusAddrRanges, " -- Dflt: %#llx : %#llx\n",dflt_iter->start,
|
2006-07-06 20:41:01 +02:00
|
|
|
dflt_iter->end);
|
|
|
|
}
|
2007-05-22 08:36:09 +02:00
|
|
|
for (PortIter portIter = portMap.begin();
|
|
|
|
portIter != portMap.end(); portIter++) {
|
|
|
|
bool subset = false;
|
|
|
|
for (AddrRangeIter dflt_iter = defaultRange.begin();
|
|
|
|
dflt_iter != defaultRange.end(); dflt_iter++) {
|
2006-12-15 07:49:41 +01:00
|
|
|
if ((portIter->first.start < dflt_iter->start &&
|
|
|
|
portIter->first.end >= dflt_iter->start) ||
|
|
|
|
(portIter->first.start < dflt_iter->end &&
|
|
|
|
portIter->first.end >= dflt_iter->end))
|
2006-07-06 20:41:01 +02:00
|
|
|
fatal("Devices can not set ranges that itersect the default set\
|
|
|
|
but are not a subset of the default set.\n");
|
2006-12-15 07:49:41 +01:00
|
|
|
if (portIter->first.start >= dflt_iter->start &&
|
|
|
|
portIter->first.end <= dflt_iter->end) {
|
2006-07-06 20:41:01 +02:00
|
|
|
subset = true;
|
2006-08-28 18:55:13 +02:00
|
|
|
DPRINTF(BusAddrRanges, " -- %#llx : %#llx is a SUBSET\n",
|
2006-12-15 07:49:41 +01:00
|
|
|
portIter->first.start, portIter->first.end);
|
2006-07-06 20:41:01 +02:00
|
|
|
}
|
|
|
|
}
|
2006-12-15 07:49:41 +01:00
|
|
|
if (portIter->second != id && !subset) {
|
|
|
|
resp.push_back(portIter->first);
|
2006-08-28 18:55:13 +02:00
|
|
|
DPRINTF(BusAddrRanges, " -- %#llx : %#llx\n",
|
2006-12-15 07:49:41 +01:00
|
|
|
portIter->first.start, portIter->first.end);
|
2006-11-14 01:56:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-22 08:36:09 +02:00
|
|
|
for (SnoopIter s_iter = snoopPorts.begin(); s_iter != snoopPorts.end();
|
|
|
|
s_iter++) {
|
|
|
|
if ((*s_iter)->getId() != id) {
|
|
|
|
snoop = true;
|
|
|
|
break;
|
2006-04-28 21:37:48 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-26 00:31:20 +01:00
|
|
|
}
|
|
|
|
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned
|
2007-05-07 20:42:03 +02:00
|
|
|
Bus::findBlockSize(int id)
|
|
|
|
{
|
|
|
|
if (cachedBlockSizeValid)
|
|
|
|
return cachedBlockSize;
|
|
|
|
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned max_bs = 0;
|
2007-05-22 08:36:09 +02:00
|
|
|
|
2007-08-10 22:14:01 +02:00
|
|
|
PortIter p_end = portMap.end();
|
|
|
|
for (PortIter p_iter = portMap.begin(); p_iter != p_end; p_iter++) {
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned tmp_bs = interfaces[p_iter->second]->peerBlockSize();
|
2007-05-07 20:42:03 +02:00
|
|
|
if (tmp_bs > max_bs)
|
|
|
|
max_bs = tmp_bs;
|
|
|
|
}
|
2007-08-10 22:14:01 +02:00
|
|
|
SnoopIter s_end = snoopPorts.end();
|
|
|
|
for (SnoopIter s_iter = snoopPorts.begin(); s_iter != s_end; s_iter++) {
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned tmp_bs = (*s_iter)->peerBlockSize();
|
2007-05-07 20:42:03 +02:00
|
|
|
if (tmp_bs > max_bs)
|
|
|
|
max_bs = tmp_bs;
|
|
|
|
}
|
2009-06-05 08:21:12 +02:00
|
|
|
if (max_bs == 0)
|
2007-05-07 20:42:03 +02:00
|
|
|
max_bs = defaultBlockSize;
|
|
|
|
|
|
|
|
if (max_bs != 64)
|
|
|
|
warn_once("Blocksize found to not be 64... hmm... probably not.\n");
|
|
|
|
cachedBlockSize = max_bs;
|
|
|
|
cachedBlockSizeValid = true;
|
|
|
|
return max_bs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-02 01:00:49 +01:00
|
|
|
unsigned int
|
|
|
|
Bus::drain(Event * de)
|
|
|
|
{
|
|
|
|
//We should check that we're not "doing" anything, and that noone is
|
|
|
|
//waiting. We might be idle but have someone waiting if the device we
|
|
|
|
//contacted for a retry didn't actually retry.
|
2011-01-08 06:50:29 +01:00
|
|
|
if (retryList.size() || (curTick() < tickNextIdle && busIdle.scheduled())) {
|
2006-11-02 01:00:49 +01:00
|
|
|
drainEvent = de;
|
|
|
|
return 1;
|
|
|
|
}
|
2007-09-05 23:12:41 +02:00
|
|
|
return 0;
|
2006-11-02 01:00:49 +01:00
|
|
|
}
|
|
|
|
|
2007-06-10 08:01:47 +02:00
|
|
|
void
|
|
|
|
Bus::startup()
|
|
|
|
{
|
2011-01-08 06:50:29 +01:00
|
|
|
if (tickNextIdle < curTick())
|
|
|
|
tickNextIdle = (curTick() / clock) * clock + clock;
|
2007-06-10 08:01:47 +02:00
|
|
|
}
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
Bus *
|
|
|
|
BusParams::create()
|
2006-03-26 00:31:20 +01:00
|
|
|
{
|
2007-08-30 21:16:59 +02:00
|
|
|
return new Bus(this);
|
2006-03-26 00:31:20 +01:00
|
|
|
}
|