DMASequencer.cc revision 11339
17008Snate@binkert.org/* 27008Snate@binkert.org * Copyright (c) 2008 Mark D. Hill and David A. Wood 37008Snate@binkert.org * All rights reserved. 47008Snate@binkert.org * 57008Snate@binkert.org * Redistribution and use in source and binary forms, with or without 67008Snate@binkert.org * modification, are permitted provided that the following conditions are 77008Snate@binkert.org * met: redistributions of source code must retain the above copyright 87008Snate@binkert.org * notice, this list of conditions and the following disclaimer; 97008Snate@binkert.org * redistributions in binary form must reproduce the above copyright 107008Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 117008Snate@binkert.org * documentation and/or other materials provided with the distribution; 127008Snate@binkert.org * neither the name of the copyright holders nor the names of its 137008Snate@binkert.org * contributors may be used to endorse or promote products derived from 147008Snate@binkert.org * this software without specific prior written permission. 157008Snate@binkert.org * 167008Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177008Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187008Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197008Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207008Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217008Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227008Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237008Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247008Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257008Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267008Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277008Snate@binkert.org */ 286285Snate@binkert.org 2910472Sandreas.hansson@arm.com#include <memory> 3010472Sandreas.hansson@arm.com 318232Snate@binkert.org#include "debug/RubyDma.hh" 329104Shestness@cs.utexas.edu#include "debug/RubyStats.hh" 337039Snate@binkert.org#include "mem/protocol/SequencerMsg.hh" 3411339SMichael.Lebeane@amd.com#include "mem/protocol/SequencerRequestType.hh" 357039Snate@binkert.org#include "mem/ruby/system/DMASequencer.hh" 3611108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh" 376285Snate@binkert.org 386876Ssteve.reinhardt@amd.comDMASequencer::DMASequencer(const Params *p) 3911339SMichael.Lebeane@amd.com : RubyPort(p) 406285Snate@binkert.org{ 416285Snate@binkert.org} 426285Snate@binkert.org 437039Snate@binkert.orgvoid 447039Snate@binkert.orgDMASequencer::init() 456285Snate@binkert.org{ 4611339SMichael.Lebeane@amd.com RubyPort::init(); 477039Snate@binkert.org m_is_busy = false; 487039Snate@binkert.org m_data_block_mask = ~ (~0 << RubySystem::getBlockSizeBits()); 4910518Snilay@cs.wisc.edu} 5010518Snilay@cs.wisc.edu 517039Snate@binkert.orgRequestStatus 528615Snilay@cs.wisc.eduDMASequencer::makeRequest(PacketPtr pkt) 536285Snate@binkert.org{ 547544SBrad.Beckmann@amd.com if (m_is_busy) { 557544SBrad.Beckmann@amd.com return RequestStatus_BufferFull; 567544SBrad.Beckmann@amd.com } 577544SBrad.Beckmann@amd.com 5811025Snilay@cs.wisc.edu Addr paddr = pkt->getAddr(); 5910562Sandreas.hansson@arm.com uint8_t* data = pkt->getPtr<uint8_t>(); 608615Snilay@cs.wisc.edu int len = pkt->getSize(); 618615Snilay@cs.wisc.edu bool write = pkt->isWrite(); 626285Snate@binkert.org 637039Snate@binkert.org assert(!m_is_busy); // only support one outstanding DMA request 647039Snate@binkert.org m_is_busy = true; 656285Snate@binkert.org 667039Snate@binkert.org active_request.start_paddr = paddr; 677039Snate@binkert.org active_request.write = write; 687039Snate@binkert.org active_request.data = data; 697039Snate@binkert.org active_request.len = len; 707039Snate@binkert.org active_request.bytes_completed = 0; 717039Snate@binkert.org active_request.bytes_issued = 0; 728615Snilay@cs.wisc.edu active_request.pkt = pkt; 736285Snate@binkert.org 7410472Sandreas.hansson@arm.com std::shared_ptr<SequencerMsg> msg = 7510472Sandreas.hansson@arm.com std::make_shared<SequencerMsg>(clockEdge()); 7611025Snilay@cs.wisc.edu msg->getPhysicalAddress() = paddr; 7711025Snilay@cs.wisc.edu msg->getLineAddress() = makeLineAddress(msg->getPhysicalAddress()); 787453Snate@binkert.org msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD; 797039Snate@binkert.org int offset = paddr & m_data_block_mask; 806888SBrad.Beckmann@amd.com 817453Snate@binkert.org msg->getLen() = (offset + len) <= RubySystem::getBlockSizeBytes() ? 827039Snate@binkert.org len : RubySystem::getBlockSizeBytes() - offset; 836888SBrad.Beckmann@amd.com 847915SBrad.Beckmann@amd.com if (write && (data != NULL)) { 857915SBrad.Beckmann@amd.com if (active_request.data != NULL) { 867915SBrad.Beckmann@amd.com msg->getDataBlk().setData(data, offset, msg->getLen()); 877915SBrad.Beckmann@amd.com } 887039Snate@binkert.org } 896888SBrad.Beckmann@amd.com 907039Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 9111111Snilay@cs.wisc.edu m_mandatory_q_ptr->enqueue(msg, clockEdge(), cyclesToTicks(Cycles(1))); 927453Snate@binkert.org active_request.bytes_issued += msg->getLen(); 936285Snate@binkert.org 947039Snate@binkert.org return RequestStatus_Issued; 956285Snate@binkert.org} 966285Snate@binkert.org 977039Snate@binkert.orgvoid 987039Snate@binkert.orgDMASequencer::issueNext() 996285Snate@binkert.org{ 10010231Ssteve.reinhardt@amd.com assert(m_is_busy); 1017039Snate@binkert.org active_request.bytes_completed = active_request.bytes_issued; 1027039Snate@binkert.org if (active_request.len == active_request.bytes_completed) { 1038162SBrad.Beckmann@amd.com // 1048162SBrad.Beckmann@amd.com // Must unset the busy flag before calling back the dma port because 1058162SBrad.Beckmann@amd.com // the callback may cause a previously nacked request to be reissued 1068162SBrad.Beckmann@amd.com // 1078162SBrad.Beckmann@amd.com DPRINTF(RubyDma, "DMA request completed\n"); 1088162SBrad.Beckmann@amd.com m_is_busy = false; 1097039Snate@binkert.org ruby_hit_callback(active_request.pkt); 1107039Snate@binkert.org return; 1117039Snate@binkert.org } 1126285Snate@binkert.org 11310472Sandreas.hansson@arm.com std::shared_ptr<SequencerMsg> msg = 11410472Sandreas.hansson@arm.com std::make_shared<SequencerMsg>(clockEdge()); 11511025Snilay@cs.wisc.edu msg->getPhysicalAddress() = active_request.start_paddr + 11611025Snilay@cs.wisc.edu active_request.bytes_completed; 1176888SBrad.Beckmann@amd.com 11811025Snilay@cs.wisc.edu assert((msg->getPhysicalAddress() & m_data_block_mask) == 0); 11911025Snilay@cs.wisc.edu msg->getLineAddress() = makeLineAddress(msg->getPhysicalAddress()); 1206888SBrad.Beckmann@amd.com 1217453Snate@binkert.org msg->getType() = (active_request.write ? SequencerRequestType_ST : 1227039Snate@binkert.org SequencerRequestType_LD); 1236888SBrad.Beckmann@amd.com 1247453Snate@binkert.org msg->getLen() = 1257039Snate@binkert.org (active_request.len - 1267039Snate@binkert.org active_request.bytes_completed < RubySystem::getBlockSizeBytes() ? 1277039Snate@binkert.org active_request.len - active_request.bytes_completed : 1287039Snate@binkert.org RubySystem::getBlockSizeBytes()); 1296888SBrad.Beckmann@amd.com 1307039Snate@binkert.org if (active_request.write) { 1317453Snate@binkert.org msg->getDataBlk(). 1327039Snate@binkert.org setData(&active_request.data[active_request.bytes_completed], 1337453Snate@binkert.org 0, msg->getLen()); 1347039Snate@binkert.org } 1356888SBrad.Beckmann@amd.com 1367039Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 13711111Snilay@cs.wisc.edu m_mandatory_q_ptr->enqueue(msg, clockEdge(), cyclesToTicks(Cycles(1))); 1387453Snate@binkert.org active_request.bytes_issued += msg->getLen(); 13910917Sbrandon.potter@amd.com DPRINTF(RubyDma, 1408160SBrad.Beckmann@amd.com "DMA request bytes issued %d, bytes completed %d, total len %d\n", 1418160SBrad.Beckmann@amd.com active_request.bytes_issued, active_request.bytes_completed, 1428160SBrad.Beckmann@amd.com active_request.len); 1436285Snate@binkert.org} 1446285Snate@binkert.org 1457039Snate@binkert.orgvoid 1467039Snate@binkert.orgDMASequencer::dataCallback(const DataBlock & dblk) 1476285Snate@binkert.org{ 14810231Ssteve.reinhardt@amd.com assert(m_is_busy); 1497039Snate@binkert.org int len = active_request.bytes_issued - active_request.bytes_completed; 1507039Snate@binkert.org int offset = 0; 1517039Snate@binkert.org if (active_request.bytes_completed == 0) 1527039Snate@binkert.org offset = active_request.start_paddr & m_data_block_mask; 15310231Ssteve.reinhardt@amd.com assert(!active_request.write); 1547915SBrad.Beckmann@amd.com if (active_request.data != NULL) { 1557915SBrad.Beckmann@amd.com memcpy(&active_request.data[active_request.bytes_completed], 1567915SBrad.Beckmann@amd.com dblk.getData(offset, len), len); 1577915SBrad.Beckmann@amd.com } 1587039Snate@binkert.org issueNext(); 1596285Snate@binkert.org} 1606285Snate@binkert.org 1617039Snate@binkert.orgvoid 1627039Snate@binkert.orgDMASequencer::ackCallback() 1636285Snate@binkert.org{ 1647039Snate@binkert.org issueNext(); 1656285Snate@binkert.org} 1666285Snate@binkert.org 1677039Snate@binkert.orgvoid 16810518Snilay@cs.wisc.eduDMASequencer::recordRequestType(DMASequencerRequestType requestType) 16910518Snilay@cs.wisc.edu{ 1709104Shestness@cs.utexas.edu DPRINTF(RubyStats, "Recorded statistic: %s\n", 1719104Shestness@cs.utexas.edu DMASequencerRequestType_to_string(requestType)); 1729104Shestness@cs.utexas.edu} 1739104Shestness@cs.utexas.edu 1746876Ssteve.reinhardt@amd.comDMASequencer * 1756876Ssteve.reinhardt@amd.comDMASequencerParams::create() 1766876Ssteve.reinhardt@amd.com{ 1776876Ssteve.reinhardt@amd.com return new DMASequencer(this); 1786876Ssteve.reinhardt@amd.com} 179