DMASequencer.cc revision 7908
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 297039Snate@binkert.org#include "mem/protocol/SequencerMsg.hh" 307039Snate@binkert.org#include "mem/protocol/SequencerRequestType.hh" 316285Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh" 326285Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 337039Snate@binkert.org#include "mem/ruby/system/DMASequencer.hh" 346285Snate@binkert.org#include "mem/ruby/system/System.hh" 356285Snate@binkert.org 366876Ssteve.reinhardt@amd.comDMASequencer::DMASequencer(const Params *p) 377039Snate@binkert.org : RubyPort(p) 386285Snate@binkert.org{ 396285Snate@binkert.org} 406285Snate@binkert.org 417039Snate@binkert.orgvoid 427039Snate@binkert.orgDMASequencer::init() 436285Snate@binkert.org{ 447039Snate@binkert.org RubyPort::init(); 457039Snate@binkert.org m_is_busy = false; 467039Snate@binkert.org m_data_block_mask = ~ (~0 << RubySystem::getBlockSizeBits()); 476285Snate@binkert.org} 486285Snate@binkert.org 497039Snate@binkert.orgRequestStatus 507039Snate@binkert.orgDMASequencer::makeRequest(const RubyRequest &request) 516285Snate@binkert.org{ 527544SBrad.Beckmann@amd.com if (m_is_busy) { 537544SBrad.Beckmann@amd.com return RequestStatus_BufferFull; 547544SBrad.Beckmann@amd.com } 557544SBrad.Beckmann@amd.com 567039Snate@binkert.org uint64_t paddr = request.paddr; 577039Snate@binkert.org uint8_t* data = request.data; 587039Snate@binkert.org int len = request.len; 597039Snate@binkert.org bool write = false; 607039Snate@binkert.org switch(request.type) { 617039Snate@binkert.org case RubyRequestType_LD: 627039Snate@binkert.org write = false; 637039Snate@binkert.org break; 647039Snate@binkert.org case RubyRequestType_ST: 657039Snate@binkert.org write = true; 667039Snate@binkert.org break; 677039Snate@binkert.org case RubyRequestType_NULL: 687039Snate@binkert.org case RubyRequestType_IFETCH: 697907Shestness@cs.utexas.edu case RubyRequestType_Load_Linked: 707907Shestness@cs.utexas.edu case RubyRequestType_Store_Conditional: 717039Snate@binkert.org case RubyRequestType_RMW_Read: 727039Snate@binkert.org case RubyRequestType_RMW_Write: 737908Shestness@cs.utexas.edu case RubyRequestType_Locked_RMW_Read: 747908Shestness@cs.utexas.edu case RubyRequestType_Locked_RMW_Write: 757039Snate@binkert.org case RubyRequestType_NUM: 767039Snate@binkert.org panic("DMASequencer::makeRequest does not support RubyRequestType"); 777039Snate@binkert.org return RequestStatus_NULL; 787039Snate@binkert.org } 796285Snate@binkert.org 807039Snate@binkert.org assert(!m_is_busy); // only support one outstanding DMA request 817039Snate@binkert.org m_is_busy = true; 826285Snate@binkert.org 837039Snate@binkert.org active_request.start_paddr = paddr; 847039Snate@binkert.org active_request.write = write; 857039Snate@binkert.org active_request.data = data; 867039Snate@binkert.org active_request.len = len; 877039Snate@binkert.org active_request.bytes_completed = 0; 887039Snate@binkert.org active_request.bytes_issued = 0; 897039Snate@binkert.org active_request.pkt = request.pkt; 906285Snate@binkert.org 917453Snate@binkert.org SequencerMsg *msg = new SequencerMsg; 927453Snate@binkert.org msg->getPhysicalAddress() = Address(paddr); 937453Snate@binkert.org msg->getLineAddress() = line_address(msg->getPhysicalAddress()); 947453Snate@binkert.org msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD; 957039Snate@binkert.org int offset = paddr & m_data_block_mask; 966888SBrad.Beckmann@amd.com 977453Snate@binkert.org msg->getLen() = (offset + len) <= RubySystem::getBlockSizeBytes() ? 987039Snate@binkert.org len : RubySystem::getBlockSizeBytes() - offset; 996888SBrad.Beckmann@amd.com 1007039Snate@binkert.org if (write) { 1017453Snate@binkert.org msg->getDataBlk().setData(data, offset, msg->getLen()); 1027039Snate@binkert.org } 1036888SBrad.Beckmann@amd.com 1047039Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 1057039Snate@binkert.org m_mandatory_q_ptr->enqueue(msg); 1067453Snate@binkert.org active_request.bytes_issued += msg->getLen(); 1076285Snate@binkert.org 1087039Snate@binkert.org return RequestStatus_Issued; 1096285Snate@binkert.org} 1106285Snate@binkert.org 1117039Snate@binkert.orgvoid 1127039Snate@binkert.orgDMASequencer::issueNext() 1136285Snate@binkert.org{ 1147039Snate@binkert.org assert(m_is_busy == true); 1157039Snate@binkert.org active_request.bytes_completed = active_request.bytes_issued; 1167039Snate@binkert.org if (active_request.len == active_request.bytes_completed) { 1177544SBrad.Beckmann@amd.com DPRINTF(RubyDma, "DMA request completed\n"); 1187039Snate@binkert.org ruby_hit_callback(active_request.pkt); 1197039Snate@binkert.org m_is_busy = false; 1207039Snate@binkert.org return; 1217039Snate@binkert.org } 1226285Snate@binkert.org 1237453Snate@binkert.org SequencerMsg *msg = new SequencerMsg; 1247453Snate@binkert.org msg->getPhysicalAddress() = Address(active_request.start_paddr + 1257039Snate@binkert.org active_request.bytes_completed); 1266888SBrad.Beckmann@amd.com 1277453Snate@binkert.org assert((msg->getPhysicalAddress().getAddress() & m_data_block_mask) == 0); 1287453Snate@binkert.org msg->getLineAddress() = line_address(msg->getPhysicalAddress()); 1296888SBrad.Beckmann@amd.com 1307453Snate@binkert.org msg->getType() = (active_request.write ? SequencerRequestType_ST : 1317039Snate@binkert.org SequencerRequestType_LD); 1326888SBrad.Beckmann@amd.com 1337453Snate@binkert.org msg->getLen() = 1347039Snate@binkert.org (active_request.len - 1357039Snate@binkert.org active_request.bytes_completed < RubySystem::getBlockSizeBytes() ? 1367039Snate@binkert.org active_request.len - active_request.bytes_completed : 1377039Snate@binkert.org RubySystem::getBlockSizeBytes()); 1386888SBrad.Beckmann@amd.com 1397039Snate@binkert.org if (active_request.write) { 1407453Snate@binkert.org msg->getDataBlk(). 1417039Snate@binkert.org setData(&active_request.data[active_request.bytes_completed], 1427453Snate@binkert.org 0, msg->getLen()); 1437453Snate@binkert.org msg->getType() = SequencerRequestType_ST; 1447039Snate@binkert.org } else { 1457453Snate@binkert.org msg->getType() = SequencerRequestType_LD; 1467039Snate@binkert.org } 1476888SBrad.Beckmann@amd.com 1487039Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 1497039Snate@binkert.org m_mandatory_q_ptr->enqueue(msg); 1507453Snate@binkert.org active_request.bytes_issued += msg->getLen(); 1517544SBrad.Beckmann@amd.com DPRINTF(RubyDma, "Next DMA segment issued to the DMA cntrl\n"); 1526285Snate@binkert.org} 1536285Snate@binkert.org 1547039Snate@binkert.orgvoid 1557039Snate@binkert.orgDMASequencer::dataCallback(const DataBlock & dblk) 1566285Snate@binkert.org{ 1577039Snate@binkert.org assert(m_is_busy == true); 1587039Snate@binkert.org int len = active_request.bytes_issued - active_request.bytes_completed; 1597039Snate@binkert.org int offset = 0; 1607039Snate@binkert.org if (active_request.bytes_completed == 0) 1617039Snate@binkert.org offset = active_request.start_paddr & m_data_block_mask; 1627039Snate@binkert.org assert(active_request.write == false); 1637039Snate@binkert.org memcpy(&active_request.data[active_request.bytes_completed], 1647039Snate@binkert.org dblk.getData(offset, len), len); 1657039Snate@binkert.org issueNext(); 1666285Snate@binkert.org} 1676285Snate@binkert.org 1687039Snate@binkert.orgvoid 1697039Snate@binkert.orgDMASequencer::ackCallback() 1706285Snate@binkert.org{ 1717039Snate@binkert.org issueNext(); 1726285Snate@binkert.org} 1736285Snate@binkert.org 1747039Snate@binkert.orgvoid 1757055Snate@binkert.orgDMASequencer::printConfig(std::ostream & out) 1766285Snate@binkert.org{ 1776285Snate@binkert.org} 1786876Ssteve.reinhardt@amd.com 1796876Ssteve.reinhardt@amd.comDMASequencer * 1806876Ssteve.reinhardt@amd.comDMASequencerParams::create() 1816876Ssteve.reinhardt@amd.com{ 1826876Ssteve.reinhardt@amd.com return new DMASequencer(this); 1836876Ssteve.reinhardt@amd.com} 184