2004-02-11 22:07:55 +01:00
|
|
|
/*
|
2006-03-30 00:37:25 +02:00
|
|
|
* Copyright (c) 2006 The Regents of The University of Michigan
|
2004-02-11 22:07:55 +01:00
|
|
|
* 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
|
|
|
|
* Nathan Binkert
|
2004-02-11 22:07:55 +01:00
|
|
|
*/
|
|
|
|
|
2006-08-30 18:57:46 +02:00
|
|
|
#include "base/chunk_generator.hh"
|
2006-05-31 00:57:42 +02:00
|
|
|
#include "base/trace.hh"
|
2004-02-11 22:07:55 +01:00
|
|
|
#include "dev/io_device.hh"
|
2006-07-13 02:22:07 +02:00
|
|
|
#include "sim/system.hh"
|
2004-02-11 22:07:55 +01:00
|
|
|
|
2006-03-21 21:45:31 +01:00
|
|
|
|
2006-07-13 02:22:07 +02:00
|
|
|
PioPort::PioPort(PioDevice *dev, System *s, std::string pname)
|
2006-10-31 19:59:30 +01:00
|
|
|
: SimpleTimingPort(dev->name() + pname, dev), device(dev)
|
2006-03-21 21:45:31 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
Tick
|
2006-10-20 09:10:12 +02:00
|
|
|
PioPort::recvAtomic(PacketPtr pkt)
|
2006-03-21 21:45:31 +01:00
|
|
|
{
|
2006-08-31 01:24:26 +02:00
|
|
|
return pkt->isRead() ? device->read(pkt) : device->write(pkt);
|
2006-03-21 21:45:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-05-22 08:36:09 +02:00
|
|
|
PioPort::getDeviceAddressRanges(AddrRangeList &resp, bool &snoop)
|
2006-03-21 21:45:31 +01:00
|
|
|
{
|
2007-05-22 08:36:09 +02:00
|
|
|
snoop = false;
|
2006-04-06 06:51:46 +02:00
|
|
|
device->addressRanges(resp);
|
2006-03-21 21:45:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
PioDevice::PioDevice(const Params *p)
|
|
|
|
: MemObject(p), platform(p->platform), sys(p->system), pioPort(NULL)
|
|
|
|
{}
|
|
|
|
|
2004-02-11 22:07:55 +01:00
|
|
|
PioDevice::~PioDevice()
|
|
|
|
{
|
2006-01-31 20:20:39 +01:00
|
|
|
if (pioPort)
|
2006-03-21 21:45:31 +01:00
|
|
|
delete pioPort;
|
2004-02-11 22:07:55 +01:00
|
|
|
}
|
|
|
|
|
2006-04-11 19:42:47 +02:00
|
|
|
void
|
2006-04-10 20:40:22 +02:00
|
|
|
PioDevice::init()
|
|
|
|
{
|
|
|
|
if (!pioPort)
|
|
|
|
panic("Pio port not connected to anything!");
|
|
|
|
pioPort->sendStatusChange(Port::RangeChange);
|
|
|
|
}
|
|
|
|
|
2006-07-13 02:22:07 +02:00
|
|
|
|
|
|
|
unsigned int
|
|
|
|
PioDevice::drain(Event *de)
|
|
|
|
{
|
|
|
|
unsigned int count;
|
|
|
|
count = pioPort->drain(de);
|
|
|
|
if (count)
|
|
|
|
changeState(Draining);
|
|
|
|
else
|
|
|
|
changeState(Drained);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
BasicPioDevice::BasicPioDevice(const Params *p)
|
|
|
|
: PioDevice(p), pioAddr(p->pio_addr), pioSize(0),
|
|
|
|
pioDelay(p->pio_latency)
|
|
|
|
{}
|
|
|
|
|
2006-04-10 20:14:06 +02:00
|
|
|
void
|
|
|
|
BasicPioDevice::addressRanges(AddrRangeList &range_list)
|
|
|
|
{
|
|
|
|
assert(pioSize != 0);
|
|
|
|
range_list.clear();
|
|
|
|
range_list.push_back(RangeSize(pioAddr, pioSize));
|
|
|
|
}
|
|
|
|
|
2006-03-21 21:45:31 +01:00
|
|
|
|
2006-07-13 02:22:07 +02:00
|
|
|
DmaPort::DmaPort(DmaDevice *dev, System *s)
|
2006-10-31 19:59:30 +01:00
|
|
|
: Port(dev->name() + "-dmaport", dev), device(dev), sys(s),
|
2007-05-10 00:20:24 +02:00
|
|
|
pendingCount(0), actionInProgress(0), drainEvent(NULL),
|
|
|
|
backoffTime(0), inRetry(false), backoffEvent(this)
|
2006-03-21 21:45:31 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
DmaPort::recvTiming(PacketPtr pkt)
|
2006-01-31 20:20:39 +01:00
|
|
|
{
|
2007-06-30 19:16:18 +02:00
|
|
|
if (pkt->wasNacked()) {
|
2007-07-14 20:48:30 +02:00
|
|
|
DPRINTF(DMA, "Received nacked %s addr %#x\n",
|
|
|
|
pkt->cmdString(), pkt->getAddr());
|
2007-05-10 00:20:24 +02:00
|
|
|
|
|
|
|
if (backoffTime < device->minBackoffDelay)
|
|
|
|
backoffTime = device->minBackoffDelay;
|
|
|
|
else if (backoffTime < device->maxBackoffDelay)
|
|
|
|
backoffTime <<= 1;
|
|
|
|
|
2008-10-09 13:58:24 +02:00
|
|
|
reschedule(backoffEvent, curTick + backoffTime, true);
|
2007-05-10 00:20:24 +02:00
|
|
|
|
|
|
|
DPRINTF(DMA, "Backoff time set to %d ticks\n", backoffTime);
|
|
|
|
|
2006-06-09 01:43:50 +02:00
|
|
|
pkt->reinitNacked();
|
2007-05-10 00:20:24 +02:00
|
|
|
queueDma(pkt, true);
|
2006-06-09 01:43:50 +02:00
|
|
|
} else if (pkt->senderState) {
|
2006-04-20 23:14:30 +02:00
|
|
|
DmaReqState *state;
|
2007-05-10 00:20:24 +02:00
|
|
|
backoffTime >>= 2;
|
|
|
|
|
2007-07-14 20:48:30 +02:00
|
|
|
DPRINTF(DMA, "Received response %s addr %#x size %#x\n",
|
|
|
|
pkt->cmdString(), pkt->getAddr(), pkt->req->getSize());
|
2006-05-26 20:17:33 +02:00
|
|
|
state = dynamic_cast<DmaReqState*>(pkt->senderState);
|
2006-06-09 01:43:50 +02:00
|
|
|
pendingCount--;
|
|
|
|
|
|
|
|
assert(pendingCount >= 0);
|
2006-05-31 00:57:42 +02:00
|
|
|
assert(state);
|
2006-06-09 01:43:50 +02:00
|
|
|
|
|
|
|
state->numBytes += pkt->req->getSize();
|
2007-05-10 00:20:24 +02:00
|
|
|
assert(state->totBytes >= state->numBytes);
|
2006-06-09 01:43:50 +02:00
|
|
|
if (state->totBytes == state->numBytes) {
|
2008-08-13 23:41:56 +02:00
|
|
|
if (state->delay)
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(state->completionEvent, curTick + state->delay);
|
2008-08-13 23:41:56 +02:00
|
|
|
else
|
|
|
|
state->completionEvent->process();
|
2006-06-09 01:43:50 +02:00
|
|
|
delete state;
|
|
|
|
}
|
2006-05-19 04:32:21 +02:00
|
|
|
delete pkt->req;
|
|
|
|
delete pkt;
|
2006-07-13 02:22:07 +02:00
|
|
|
|
|
|
|
if (pendingCount == 0 && drainEvent) {
|
|
|
|
drainEvent->process();
|
|
|
|
drainEvent = NULL;
|
|
|
|
}
|
2006-04-28 21:38:43 +02:00
|
|
|
} else {
|
2006-06-09 01:43:50 +02:00
|
|
|
panic("Got packet without sender state... huh?\n");
|
2006-04-20 23:14:30 +02:00
|
|
|
}
|
2006-04-28 21:38:43 +02:00
|
|
|
|
2006-05-31 00:57:42 +02:00
|
|
|
return true;
|
2006-01-31 20:20:39 +01:00
|
|
|
}
|
2004-04-06 19:02:00 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
DmaDevice::DmaDevice(const Params *p)
|
2007-05-10 00:20:24 +02:00
|
|
|
: PioDevice(p), dmaPort(NULL), minBackoffDelay(p->min_backoff_delay),
|
|
|
|
maxBackoffDelay(p->max_backoff_delay)
|
2006-04-20 23:14:30 +02:00
|
|
|
{ }
|
2006-01-31 20:20:39 +01:00
|
|
|
|
2006-07-13 02:22:07 +02:00
|
|
|
|
|
|
|
unsigned int
|
|
|
|
DmaDevice::drain(Event *de)
|
|
|
|
{
|
|
|
|
unsigned int count;
|
|
|
|
count = pioPort->drain(de) + dmaPort->drain(de);
|
|
|
|
if (count)
|
|
|
|
changeState(Draining);
|
|
|
|
else
|
|
|
|
changeState(Drained);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
DmaPort::drain(Event *de)
|
|
|
|
{
|
|
|
|
if (pendingCount == 0)
|
|
|
|
return 0;
|
|
|
|
drainEvent = de;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-31 20:20:39 +01:00
|
|
|
void
|
2006-03-21 21:45:31 +01:00
|
|
|
DmaPort::recvRetry()
|
|
|
|
{
|
2007-05-10 00:20:24 +02:00
|
|
|
assert(transmitList.size());
|
2006-05-31 19:45:37 +02:00
|
|
|
bool result = true;
|
2007-05-10 00:20:24 +02:00
|
|
|
do {
|
2008-08-26 08:37:26 +02:00
|
|
|
PacketPtr pkt = transmitList.front();
|
2007-07-14 20:48:30 +02:00
|
|
|
DPRINTF(DMA, "Retry on %s addr %#x\n",
|
|
|
|
pkt->cmdString(), pkt->getAddr());
|
2006-05-31 19:45:37 +02:00
|
|
|
result = sendTiming(pkt);
|
|
|
|
if (result) {
|
|
|
|
DPRINTF(DMA, "-- Done\n");
|
|
|
|
transmitList.pop_front();
|
2007-05-10 00:20:24 +02:00
|
|
|
inRetry = false;
|
2006-05-31 19:45:37 +02:00
|
|
|
} else {
|
2007-05-10 00:20:24 +02:00
|
|
|
inRetry = true;
|
2006-05-31 19:45:37 +02:00
|
|
|
DPRINTF(DMA, "-- Failed, queued\n");
|
|
|
|
}
|
2007-05-10 00:20:24 +02:00
|
|
|
} while (!backoffTime && result && transmitList.size());
|
|
|
|
|
|
|
|
if (transmitList.size() && backoffTime && !inRetry) {
|
|
|
|
DPRINTF(DMA, "Scheduling backoff for %d\n", curTick+backoffTime);
|
|
|
|
if (!backoffEvent.scheduled())
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(backoffEvent, backoffTime + curTick);
|
2006-05-31 00:57:42 +02:00
|
|
|
}
|
2007-05-10 00:20:24 +02:00
|
|
|
DPRINTF(DMA, "TransmitList: %d, backoffTime: %d inRetry: %d es: %d\n",
|
|
|
|
transmitList.size(), backoffTime, inRetry,
|
|
|
|
backoffEvent.scheduled());
|
2006-03-21 21:45:31 +01:00
|
|
|
}
|
2006-05-26 20:17:33 +02:00
|
|
|
|
|
|
|
|
2006-03-21 21:45:31 +01:00
|
|
|
void
|
2006-05-26 20:17:33 +02:00
|
|
|
DmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
|
2008-08-13 23:41:56 +02:00
|
|
|
uint8_t *data, Tick delay)
|
2006-01-31 20:20:39 +01:00
|
|
|
{
|
|
|
|
assert(event);
|
|
|
|
|
2006-07-13 02:22:07 +02:00
|
|
|
assert(device->getState() == SimObject::Running);
|
|
|
|
|
2008-08-13 23:41:56 +02:00
|
|
|
DmaReqState *reqState = new DmaReqState(event, this, size, delay);
|
2006-01-31 20:20:39 +01:00
|
|
|
|
2007-05-14 22:14:59 +02:00
|
|
|
|
|
|
|
DPRINTF(DMA, "Starting DMA for addr: %#x size: %d sched: %d\n", addr, size,
|
|
|
|
event->scheduled());
|
2006-02-21 18:20:02 +01:00
|
|
|
for (ChunkGenerator gen(addr, size, peerBlockSize());
|
|
|
|
!gen.done(); gen.next()) {
|
2006-05-31 06:12:29 +02:00
|
|
|
Request *req = new Request(gen.addr(), gen.size(), 0);
|
2006-10-20 09:10:12 +02:00
|
|
|
PacketPtr pkt = new Packet(req, cmd, Packet::Broadcast);
|
2006-05-26 20:17:33 +02:00
|
|
|
|
2006-01-31 20:20:39 +01:00
|
|
|
// Increment the data pointer on a write
|
2006-04-25 01:31:50 +02:00
|
|
|
if (data)
|
2006-06-09 01:43:50 +02:00
|
|
|
pkt->dataStatic(data + gen.complete());
|
2006-05-26 20:17:33 +02:00
|
|
|
|
2006-06-09 01:43:50 +02:00
|
|
|
pkt->senderState = reqState;
|
2006-05-26 20:17:33 +02:00
|
|
|
|
2006-04-20 23:14:30 +02:00
|
|
|
assert(pendingCount >= 0);
|
|
|
|
pendingCount++;
|
2007-05-14 22:14:59 +02:00
|
|
|
DPRINTF(DMA, "--Queuing DMA for addr: %#x size: %d\n", gen.addr(),
|
|
|
|
gen.size());
|
2007-05-10 00:20:24 +02:00
|
|
|
queueDma(pkt);
|
2006-01-31 20:20:39 +01:00
|
|
|
}
|
2006-07-13 02:22:07 +02:00
|
|
|
|
2006-01-31 20:20:39 +01:00
|
|
|
}
|
|
|
|
|
2007-05-10 00:20:24 +02:00
|
|
|
void
|
|
|
|
DmaPort::queueDma(PacketPtr pkt, bool front)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (front)
|
|
|
|
transmitList.push_front(pkt);
|
|
|
|
else
|
|
|
|
transmitList.push_back(pkt);
|
|
|
|
sendDma();
|
|
|
|
}
|
|
|
|
|
2006-01-31 20:20:39 +01:00
|
|
|
|
|
|
|
void
|
2007-05-10 00:20:24 +02:00
|
|
|
DmaPort::sendDma()
|
2006-01-31 20:20:39 +01:00
|
|
|
{
|
2006-07-13 02:22:07 +02:00
|
|
|
// some kind of selction between access methods
|
|
|
|
// more work is going to have to be done to make
|
|
|
|
// switching actually work
|
2007-05-10 00:20:24 +02:00
|
|
|
assert(transmitList.size());
|
|
|
|
PacketPtr pkt = transmitList.front();
|
2006-07-13 21:48:17 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
Enums::MemoryMode state = sys->getMemoryMode();
|
|
|
|
if (state == Enums::timing) {
|
2007-05-10 00:20:24 +02:00
|
|
|
if (backoffEvent.scheduled() || inRetry) {
|
|
|
|
DPRINTF(DMA, "Can't send immediately, waiting for retry or backoff timer\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-14 20:48:30 +02:00
|
|
|
DPRINTF(DMA, "Attempting to send %s addr %#x\n",
|
|
|
|
pkt->cmdString(), pkt->getAddr());
|
2007-05-10 00:20:24 +02:00
|
|
|
|
|
|
|
bool result;
|
|
|
|
do {
|
|
|
|
result = sendTiming(pkt);
|
|
|
|
if (result) {
|
|
|
|
transmitList.pop_front();
|
|
|
|
DPRINTF(DMA, "-- Done\n");
|
|
|
|
} else {
|
|
|
|
inRetry = true;
|
|
|
|
DPRINTF(DMA, "-- Failed: queued\n");
|
|
|
|
}
|
|
|
|
} while (result && !backoffTime && transmitList.size());
|
|
|
|
|
|
|
|
if (transmitList.size() && backoffTime && !inRetry &&
|
|
|
|
!backoffEvent.scheduled()) {
|
2007-05-14 22:14:59 +02:00
|
|
|
DPRINTF(DMA, "-- Scheduling backoff timer for %d\n",
|
|
|
|
backoffTime+curTick);
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(backoffEvent, backoffTime + curTick);
|
2006-07-13 02:22:07 +02:00
|
|
|
}
|
2007-07-24 06:51:38 +02:00
|
|
|
} else if (state == Enums::atomic) {
|
2007-05-10 00:20:24 +02:00
|
|
|
transmitList.pop_front();
|
|
|
|
|
2006-07-13 21:48:17 +02:00
|
|
|
Tick lat;
|
2007-05-14 22:14:59 +02:00
|
|
|
DPRINTF(DMA, "--Sending DMA for addr: %#x size: %d\n",
|
|
|
|
pkt->req->getPaddr(), pkt->req->getSize());
|
2006-07-13 21:48:17 +02:00
|
|
|
lat = sendAtomic(pkt);
|
2006-07-13 02:22:07 +02:00
|
|
|
assert(pkt->senderState);
|
|
|
|
DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState);
|
|
|
|
assert(state);
|
|
|
|
state->numBytes += pkt->req->getSize();
|
2007-05-14 22:14:59 +02:00
|
|
|
|
|
|
|
DPRINTF(DMA, "--Received response for DMA for addr: %#x size: %d nb: %d, tot: %d sched %d\n",
|
|
|
|
pkt->req->getPaddr(), pkt->req->getSize(), state->numBytes,
|
|
|
|
state->totBytes, state->completionEvent->scheduled());
|
|
|
|
|
2006-07-13 02:22:07 +02:00
|
|
|
if (state->totBytes == state->numBytes) {
|
2007-05-14 22:14:59 +02:00
|
|
|
assert(!state->completionEvent->scheduled());
|
2008-10-09 13:58:24 +02:00
|
|
|
schedule(state->completionEvent, curTick + lat + state->delay);
|
2006-07-13 02:22:07 +02:00
|
|
|
delete state;
|
|
|
|
delete pkt->req;
|
|
|
|
}
|
|
|
|
pendingCount--;
|
|
|
|
assert(pendingCount >= 0);
|
|
|
|
delete pkt;
|
|
|
|
|
|
|
|
if (pendingCount == 0 && drainEvent) {
|
|
|
|
drainEvent->process();
|
|
|
|
drainEvent = NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-31 20:20:39 +01:00
|
|
|
} else
|
|
|
|
panic("Unknown memory command state.");
|
|
|
|
}
|
2004-02-11 22:07:55 +01:00
|
|
|
|
|
|
|
DmaDevice::~DmaDevice()
|
|
|
|
{
|
2006-03-21 21:45:31 +01:00
|
|
|
if (dmaPort)
|
|
|
|
delete dmaPort;
|
2004-02-11 22:07:55 +01:00
|
|
|
}
|