2010-03-15 04:58:45 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Mark D. Hill and David A. Wood
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-07-07 00:49:47 +02:00
|
|
|
|
2014-10-16 11:49:49 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2014-11-06 07:55:09 +01:00
|
|
|
#include "debug/Config.hh"
|
|
|
|
#include "debug/Drain.hh"
|
2011-04-15 19:44:32 +02:00
|
|
|
#include "debug/RubyDma.hh"
|
2012-07-11 07:51:54 +02:00
|
|
|
#include "debug/RubyStats.hh"
|
2009-08-04 19:52:52 +02:00
|
|
|
#include "mem/protocol/SequencerMsg.hh"
|
2010-03-23 02:43:53 +01:00
|
|
|
#include "mem/ruby/system/DMASequencer.hh"
|
2015-09-16 18:03:03 +02:00
|
|
|
#include "mem/ruby/system/RubySystem.hh"
|
2014-11-06 07:55:09 +01:00
|
|
|
#include "sim/system.hh"
|
2009-07-07 00:49:47 +02:00
|
|
|
|
2010-01-30 05:29:17 +01:00
|
|
|
DMASequencer::DMASequencer(const Params *p)
|
2015-07-10 23:05:23 +02:00
|
|
|
: MemObject(p), m_ruby_system(p->ruby_system), m_version(p->version),
|
|
|
|
m_controller(NULL), m_mandatory_q_ptr(NULL),
|
|
|
|
m_usingRubyTester(p->using_ruby_tester),
|
2015-02-26 16:58:26 +01:00
|
|
|
slave_port(csprintf("%s.slave", name()), this, 0, p->ruby_system,
|
|
|
|
p->ruby_system->getAccessBackingStore()),
|
2015-07-07 10:51:05 +02:00
|
|
|
system(p->system), retry(false)
|
2009-07-07 00:49:47 +02:00
|
|
|
{
|
2014-11-06 07:55:09 +01:00
|
|
|
assert(m_version != -1);
|
2009-07-07 00:49:47 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
DMASequencer::init()
|
2009-07-07 00:49:47 +02:00
|
|
|
{
|
2014-11-06 07:55:09 +01:00
|
|
|
MemObject::init();
|
|
|
|
assert(m_controller != NULL);
|
|
|
|
m_mandatory_q_ptr = m_controller->getMandatoryQueue();
|
2010-03-23 02:43:53 +01:00
|
|
|
m_is_busy = false;
|
|
|
|
m_data_block_mask = ~ (~0 << RubySystem::getBlockSizeBits());
|
2014-11-06 12:41:44 +01:00
|
|
|
|
|
|
|
slave_port.sendRangeChange();
|
2009-07-07 00:49:47 +02:00
|
|
|
}
|
|
|
|
|
2014-11-06 07:55:09 +01:00
|
|
|
BaseSlavePort &
|
|
|
|
DMASequencer::getSlavePort(const std::string &if_name, PortID idx)
|
|
|
|
{
|
|
|
|
// used by the CPUs to connect the caches to the interconnect, and
|
|
|
|
// for the x86 case also the interrupt master
|
|
|
|
if (if_name != "slave") {
|
|
|
|
// pass it along to our super class
|
|
|
|
return MemObject::getSlavePort(if_name, idx);
|
|
|
|
} else {
|
|
|
|
return slave_port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DMASequencer::MemSlavePort::MemSlavePort(const std::string &_name,
|
2015-02-26 16:58:26 +01:00
|
|
|
DMASequencer *_port, PortID id, RubySystem* _ruby_system,
|
|
|
|
bool _access_backing_store)
|
|
|
|
: QueuedSlavePort(_name, _port, queue, id), queue(*_port, *this),
|
2015-07-10 23:05:23 +02:00
|
|
|
m_ruby_system(_ruby_system), access_backing_store(_access_backing_store)
|
2014-11-06 07:55:09 +01:00
|
|
|
{
|
|
|
|
DPRINTF(RubyDma, "Created slave memport on ruby sequencer %s\n", _name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DMASequencer::MemSlavePort::recvTimingReq(PacketPtr pkt)
|
|
|
|
{
|
|
|
|
DPRINTF(RubyDma, "Timing request for address %#x on port %d\n",
|
|
|
|
pkt->getAddr(), id);
|
|
|
|
DMASequencer *seq = static_cast<DMASequencer *>(&owner);
|
|
|
|
|
|
|
|
if (pkt->memInhibitAsserted())
|
|
|
|
panic("DMASequencer should never see an inhibited request\n");
|
|
|
|
|
|
|
|
assert(isPhysMemAddress(pkt->getAddr()));
|
2015-08-14 19:04:51 +02:00
|
|
|
assert(getOffset(pkt->getAddr()) + pkt->getSize() <=
|
2014-11-06 07:55:09 +01:00
|
|
|
RubySystem::getBlockSizeBytes());
|
|
|
|
|
|
|
|
// Submit the ruby request
|
|
|
|
RequestStatus requestStatus = seq->makeRequest(pkt);
|
|
|
|
|
|
|
|
// If the request successfully issued then we should return true.
|
|
|
|
// Otherwise, we need to tell the port to retry at a later point
|
|
|
|
// and return false.
|
|
|
|
if (requestStatus == RequestStatus_Issued) {
|
|
|
|
DPRINTF(RubyDma, "Request %s 0x%x issued\n", pkt->cmdString(),
|
|
|
|
pkt->getAddr());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unless one is using the ruby tester, record the stalled M5 port for
|
|
|
|
// later retry when the sequencer becomes free.
|
|
|
|
if (!seq->m_usingRubyTester) {
|
|
|
|
seq->retry = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(RubyDma, "Request for address %#x did not issued because %s\n",
|
|
|
|
pkt->getAddr(), RequestStatus_to_string(requestStatus));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DMASequencer::ruby_hit_callback(PacketPtr pkt)
|
|
|
|
{
|
|
|
|
DPRINTF(RubyDma, "Hit callback for %s 0x%x\n", pkt->cmdString(),
|
|
|
|
pkt->getAddr());
|
|
|
|
|
|
|
|
// The packet was destined for memory and has not yet been turned
|
|
|
|
// into a response
|
|
|
|
assert(system->isMemAddr(pkt->getAddr()));
|
|
|
|
assert(pkt->isRequest());
|
|
|
|
slave_port.hitCallback(pkt);
|
|
|
|
|
|
|
|
// If we had to stall the slave ports, wake it up because
|
|
|
|
// the sequencer likely has free resources now.
|
|
|
|
if (retry) {
|
|
|
|
retry = false;
|
|
|
|
DPRINTF(RubyDma,"Sequencer may now be free. SendRetry to port %s\n",
|
|
|
|
slave_port.name());
|
2015-03-02 10:00:35 +01:00
|
|
|
slave_port.sendRetryReq();
|
2014-11-06 07:55:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
testDrainComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DMASequencer::testDrainComplete()
|
|
|
|
{
|
|
|
|
//If we weren't able to drain before, we might be able to now.
|
2015-07-07 10:51:05 +02:00
|
|
|
if (drainState() == DrainState::Draining) {
|
2014-11-06 07:55:09 +01:00
|
|
|
unsigned int drainCount = outstandingCount();
|
|
|
|
DPRINTF(Drain, "Drain count: %u\n", drainCount);
|
|
|
|
if (drainCount == 0) {
|
|
|
|
DPRINTF(Drain, "DMASequencer done draining, signaling drain done\n");
|
2015-07-07 10:51:05 +02:00
|
|
|
signalDrainDone();
|
2014-11-06 07:55:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:51:05 +02:00
|
|
|
DrainState
|
|
|
|
DMASequencer::drain()
|
2014-11-06 07:55:09 +01:00
|
|
|
{
|
|
|
|
if (isDeadlockEventScheduled()) {
|
|
|
|
descheduleDeadlockEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the DMASequencer is not empty, then it needs to clear all outstanding
|
2015-07-07 10:51:05 +02:00
|
|
|
// requests before it should call signalDrainDone()
|
2014-11-06 07:55:09 +01:00
|
|
|
DPRINTF(Config, "outstanding count %d\n", outstandingCount());
|
|
|
|
|
|
|
|
// Set status
|
2015-07-07 10:51:05 +02:00
|
|
|
if (outstandingCount() > 0) {
|
2014-11-06 07:55:09 +01:00
|
|
|
DPRINTF(Drain, "DMASequencer not drained\n");
|
2015-07-07 10:51:05 +02:00
|
|
|
return DrainState::Draining;
|
|
|
|
} else {
|
|
|
|
return DrainState::Drained;
|
2014-11-06 07:55:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DMASequencer::MemSlavePort::hitCallback(PacketPtr pkt)
|
|
|
|
{
|
|
|
|
bool needsResponse = pkt->needsResponse();
|
|
|
|
assert(!pkt->isLLSC());
|
|
|
|
assert(!pkt->isFlush());
|
|
|
|
|
|
|
|
DPRINTF(RubyDma, "Hit callback needs response %d\n", needsResponse);
|
|
|
|
|
|
|
|
// turn packet around to go back to requester if response expected
|
2015-02-26 16:58:26 +01:00
|
|
|
|
|
|
|
if (access_backing_store) {
|
2015-07-10 23:05:23 +02:00
|
|
|
m_ruby_system->getPhysMem()->access(pkt);
|
2015-02-26 16:58:26 +01:00
|
|
|
} else if (needsResponse) {
|
2014-11-06 12:41:44 +01:00
|
|
|
pkt->makeResponse();
|
2015-02-26 16:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (needsResponse) {
|
2014-11-06 07:55:09 +01:00
|
|
|
DPRINTF(RubyDma, "Sending packet back over port\n");
|
|
|
|
// send next cycle
|
2015-07-10 23:05:23 +02:00
|
|
|
DMASequencer *seq = static_cast<DMASequencer *>(&owner);
|
|
|
|
RubySystem *rs = seq->m_ruby_system;
|
|
|
|
schedTimingResp(pkt, curTick() + rs->clockPeriod());
|
2014-11-06 07:55:09 +01:00
|
|
|
} else {
|
|
|
|
delete pkt;
|
|
|
|
}
|
2014-11-06 12:41:44 +01:00
|
|
|
|
2014-11-06 07:55:09 +01:00
|
|
|
DPRINTF(RubyDma, "Hit callback done!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DMASequencer::MemSlavePort::isPhysMemAddress(Addr addr) const
|
|
|
|
{
|
|
|
|
DMASequencer *seq = static_cast<DMASequencer *>(&owner);
|
|
|
|
return seq->system->isMemAddr(addr);
|
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
RequestStatus
|
2011-11-15 00:44:35 +01:00
|
|
|
DMASequencer::makeRequest(PacketPtr pkt)
|
2009-07-07 00:49:47 +02:00
|
|
|
{
|
2010-08-20 20:46:12 +02:00
|
|
|
if (m_is_busy) {
|
|
|
|
return RequestStatus_BufferFull;
|
|
|
|
}
|
|
|
|
|
2015-08-14 19:04:51 +02:00
|
|
|
Addr paddr = pkt->getAddr();
|
2014-12-02 12:07:34 +01:00
|
|
|
uint8_t* data = pkt->getPtr<uint8_t>();
|
2011-11-15 00:44:35 +01:00
|
|
|
int len = pkt->getSize();
|
|
|
|
bool write = pkt->isWrite();
|
2010-03-23 02:43:53 +01:00
|
|
|
|
|
|
|
assert(!m_is_busy); // only support one outstanding DMA request
|
|
|
|
m_is_busy = true;
|
|
|
|
|
|
|
|
active_request.start_paddr = paddr;
|
|
|
|
active_request.write = write;
|
|
|
|
active_request.data = data;
|
|
|
|
active_request.len = len;
|
|
|
|
active_request.bytes_completed = 0;
|
|
|
|
active_request.bytes_issued = 0;
|
2011-11-15 00:44:35 +01:00
|
|
|
active_request.pkt = pkt;
|
2010-03-23 02:43:53 +01:00
|
|
|
|
2014-10-16 11:49:49 +02:00
|
|
|
std::shared_ptr<SequencerMsg> msg =
|
|
|
|
std::make_shared<SequencerMsg>(clockEdge());
|
2015-08-14 19:04:51 +02:00
|
|
|
msg->getPhysicalAddress() = paddr;
|
|
|
|
msg->getLineAddress() = makeLineAddress(msg->getPhysicalAddress());
|
2010-06-11 08:17:06 +02:00
|
|
|
msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD;
|
2010-03-23 02:43:53 +01:00
|
|
|
int offset = paddr & m_data_block_mask;
|
|
|
|
|
2010-06-11 08:17:06 +02:00
|
|
|
msg->getLen() = (offset + len) <= RubySystem::getBlockSizeBytes() ?
|
2010-03-23 02:43:53 +01:00
|
|
|
len : RubySystem::getBlockSizeBytes() - offset;
|
|
|
|
|
2011-02-07 07:14:19 +01:00
|
|
|
if (write && (data != NULL)) {
|
|
|
|
if (active_request.data != NULL) {
|
|
|
|
msg->getDataBlk().setData(data, offset, msg->getLen());
|
|
|
|
}
|
2010-03-23 02:43:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(m_mandatory_q_ptr != NULL);
|
2015-09-16 18:59:56 +02:00
|
|
|
m_mandatory_q_ptr->enqueue(msg, clockEdge(), cyclesToTicks(Cycles(1)));
|
2010-06-11 08:17:06 +02:00
|
|
|
active_request.bytes_issued += msg->getLen();
|
2010-03-23 02:43:53 +01:00
|
|
|
|
|
|
|
return RequestStatus_Issued;
|
2009-07-07 00:49:47 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
DMASequencer::issueNext()
|
2009-07-07 00:49:47 +02:00
|
|
|
{
|
2014-06-01 03:00:23 +02:00
|
|
|
assert(m_is_busy);
|
2010-03-23 02:43:53 +01:00
|
|
|
active_request.bytes_completed = active_request.bytes_issued;
|
|
|
|
if (active_request.len == active_request.bytes_completed) {
|
2011-03-19 22:17:48 +01:00
|
|
|
//
|
|
|
|
// Must unset the busy flag before calling back the dma port because
|
|
|
|
// the callback may cause a previously nacked request to be reissued
|
|
|
|
//
|
|
|
|
DPRINTF(RubyDma, "DMA request completed\n");
|
2010-03-23 02:43:53 +01:00
|
|
|
m_is_busy = false;
|
2011-03-19 22:17:48 +01:00
|
|
|
ruby_hit_callback(active_request.pkt);
|
2010-03-23 02:43:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-16 11:49:49 +02:00
|
|
|
std::shared_ptr<SequencerMsg> msg =
|
|
|
|
std::make_shared<SequencerMsg>(clockEdge());
|
2015-08-14 19:04:51 +02:00
|
|
|
msg->getPhysicalAddress() = active_request.start_paddr +
|
|
|
|
active_request.bytes_completed;
|
2010-03-23 02:43:53 +01:00
|
|
|
|
2015-08-14 19:04:51 +02:00
|
|
|
assert((msg->getPhysicalAddress() & m_data_block_mask) == 0);
|
|
|
|
msg->getLineAddress() = makeLineAddress(msg->getPhysicalAddress());
|
2010-03-23 02:43:53 +01:00
|
|
|
|
2010-06-11 08:17:06 +02:00
|
|
|
msg->getType() = (active_request.write ? SequencerRequestType_ST :
|
2010-03-23 02:43:53 +01:00
|
|
|
SequencerRequestType_LD);
|
|
|
|
|
2010-06-11 08:17:06 +02:00
|
|
|
msg->getLen() =
|
2010-03-23 02:43:53 +01:00
|
|
|
(active_request.len -
|
|
|
|
active_request.bytes_completed < RubySystem::getBlockSizeBytes() ?
|
|
|
|
active_request.len - active_request.bytes_completed :
|
|
|
|
RubySystem::getBlockSizeBytes());
|
|
|
|
|
|
|
|
if (active_request.write) {
|
2010-06-11 08:17:06 +02:00
|
|
|
msg->getDataBlk().
|
2010-03-23 02:43:53 +01:00
|
|
|
setData(&active_request.data[active_request.bytes_completed],
|
2010-06-11 08:17:06 +02:00
|
|
|
0, msg->getLen());
|
2010-03-23 02:43:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(m_mandatory_q_ptr != NULL);
|
2015-09-16 18:59:56 +02:00
|
|
|
m_mandatory_q_ptr->enqueue(msg, clockEdge(), cyclesToTicks(Cycles(1)));
|
2010-06-11 08:17:06 +02:00
|
|
|
active_request.bytes_issued += msg->getLen();
|
2015-07-10 23:05:23 +02:00
|
|
|
DPRINTF(RubyDma,
|
2011-03-19 22:17:48 +01:00
|
|
|
"DMA request bytes issued %d, bytes completed %d, total len %d\n",
|
|
|
|
active_request.bytes_issued, active_request.bytes_completed,
|
|
|
|
active_request.len);
|
2009-07-07 00:49:47 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
DMASequencer::dataCallback(const DataBlock & dblk)
|
2009-07-07 00:49:47 +02:00
|
|
|
{
|
2014-06-01 03:00:23 +02:00
|
|
|
assert(m_is_busy);
|
2010-03-23 02:43:53 +01:00
|
|
|
int len = active_request.bytes_issued - active_request.bytes_completed;
|
|
|
|
int offset = 0;
|
|
|
|
if (active_request.bytes_completed == 0)
|
|
|
|
offset = active_request.start_paddr & m_data_block_mask;
|
2014-06-01 03:00:23 +02:00
|
|
|
assert(!active_request.write);
|
2011-02-07 07:14:19 +01:00
|
|
|
if (active_request.data != NULL) {
|
|
|
|
memcpy(&active_request.data[active_request.bytes_completed],
|
|
|
|
dblk.getData(offset, len), len);
|
|
|
|
}
|
2010-03-23 02:43:53 +01:00
|
|
|
issueNext();
|
2009-07-07 00:49:47 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
DMASequencer::ackCallback()
|
2009-07-07 00:49:47 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
issueNext();
|
2009-07-07 00:49:47 +02:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:51:54 +02:00
|
|
|
void
|
2014-11-06 07:55:09 +01:00
|
|
|
DMASequencer::recordRequestType(DMASequencerRequestType requestType)
|
|
|
|
{
|
2012-07-11 07:51:54 +02:00
|
|
|
DPRINTF(RubyStats, "Recorded statistic: %s\n",
|
|
|
|
DMASequencerRequestType_to_string(requestType));
|
|
|
|
}
|
|
|
|
|
2010-01-30 05:29:17 +01:00
|
|
|
DMASequencer *
|
|
|
|
DMASequencerParams::create()
|
|
|
|
{
|
|
|
|
return new DMASequencer(this);
|
|
|
|
}
|