DMASequencer.cc revision 7008
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 296285Snate@binkert.org#include "mem/ruby/system/DMASequencer.hh" 306285Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh" 316285Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 326285Snate@binkert.org 336285Snate@binkert.org/* SLICC generated types */ 346467Sdrh5@cs.wisc.edu#include "mem/protocol/SequencerMsg.hh" 356467Sdrh5@cs.wisc.edu#include "mem/protocol/SequencerRequestType.hh" 366285Snate@binkert.org#include "mem/ruby/system/System.hh" 376285Snate@binkert.org 386888SBrad.Beckmann@amd.com// 396888SBrad.Beckmann@amd.com// Fix me: This code needs comments! 406888SBrad.Beckmann@amd.com// 416888SBrad.Beckmann@amd.com 426876Ssteve.reinhardt@amd.comDMASequencer::DMASequencer(const Params *p) 436876Ssteve.reinhardt@amd.com : RubyPort(p) 446285Snate@binkert.org{ 456285Snate@binkert.org} 466285Snate@binkert.org 476876Ssteve.reinhardt@amd.comvoid DMASequencer::init() 486285Snate@binkert.org{ 496888SBrad.Beckmann@amd.com RubyPort::init(); 506285Snate@binkert.org m_is_busy = false; 516368Sdrh5@cs.wisc.edu m_data_block_mask = ~ (~0 << RubySystem::getBlockSizeBits()); 526285Snate@binkert.org} 536285Snate@binkert.org 546922SBrad.Beckmann@amd.comRequestStatus DMASequencer::makeRequest(const RubyRequest & request) 556285Snate@binkert.org{ 566285Snate@binkert.org uint64_t paddr = request.paddr; 576285Snate@binkert.org uint8_t* data = request.data; 586285Snate@binkert.org int len = request.len; 596285Snate@binkert.org bool write = false; 606285Snate@binkert.org switch(request.type) { 616285Snate@binkert.org case RubyRequestType_LD: 626285Snate@binkert.org write = false; 636285Snate@binkert.org break; 646285Snate@binkert.org case RubyRequestType_ST: 656285Snate@binkert.org write = true; 666285Snate@binkert.org break; 676285Snate@binkert.org case RubyRequestType_NULL: 686285Snate@binkert.org case RubyRequestType_IFETCH: 696350Spdudnik@gmail.com case RubyRequestType_Locked_Read: 706350Spdudnik@gmail.com case RubyRequestType_Locked_Write: 716355Spdudnik@gmail.com case RubyRequestType_RMW_Read: 726355Spdudnik@gmail.com case RubyRequestType_RMW_Write: 736433Sdrh5@cs.wisc.edu case RubyRequestType_NUM: 746922SBrad.Beckmann@amd.com panic("DMASequencer::makeRequest does not support the RubyRequestType"); 756922SBrad.Beckmann@amd.com return RequestStatus_NULL; 766285Snate@binkert.org } 776285Snate@binkert.org 786368Sdrh5@cs.wisc.edu assert(!m_is_busy); // only support one outstanding DMA request 796285Snate@binkert.org m_is_busy = true; 806285Snate@binkert.org 816285Snate@binkert.org active_request.start_paddr = paddr; 826285Snate@binkert.org active_request.write = write; 836285Snate@binkert.org active_request.data = data; 846285Snate@binkert.org active_request.len = len; 856285Snate@binkert.org active_request.bytes_completed = 0; 866285Snate@binkert.org active_request.bytes_issued = 0; 876922SBrad.Beckmann@amd.com active_request.pkt = request.pkt; 886285Snate@binkert.org 896467Sdrh5@cs.wisc.edu SequencerMsg msg; 906285Snate@binkert.org msg.getPhysicalAddress() = Address(paddr); 916368Sdrh5@cs.wisc.edu msg.getLineAddress() = line_address(msg.getPhysicalAddress()); 926467Sdrh5@cs.wisc.edu msg.getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD; 936467Sdrh5@cs.wisc.edu int offset = paddr & m_data_block_mask; 946888SBrad.Beckmann@amd.com 956467Sdrh5@cs.wisc.edu msg.getLen() = (offset + len) <= RubySystem::getBlockSizeBytes() ? 966368Sdrh5@cs.wisc.edu len : 976467Sdrh5@cs.wisc.edu RubySystem::getBlockSizeBytes() - offset; 986888SBrad.Beckmann@amd.com 996888SBrad.Beckmann@amd.com if (write) { 1006467Sdrh5@cs.wisc.edu msg.getDataBlk().setData(data, offset, msg.getLen()); 1016888SBrad.Beckmann@amd.com } 1026888SBrad.Beckmann@amd.com 1036888SBrad.Beckmann@amd.com assert(m_mandatory_q_ptr != NULL); 1046285Snate@binkert.org m_mandatory_q_ptr->enqueue(msg); 1056285Snate@binkert.org active_request.bytes_issued += msg.getLen(); 1066285Snate@binkert.org 1076922SBrad.Beckmann@amd.com return RequestStatus_Issued; 1086285Snate@binkert.org} 1096285Snate@binkert.org 1106285Snate@binkert.orgvoid DMASequencer::issueNext() 1116285Snate@binkert.org{ 1126285Snate@binkert.org assert(m_is_busy == true); 1136285Snate@binkert.org active_request.bytes_completed = active_request.bytes_issued; 1146285Snate@binkert.org if (active_request.len == active_request.bytes_completed) { 1156922SBrad.Beckmann@amd.com ruby_hit_callback(active_request.pkt); 1166285Snate@binkert.org m_is_busy = false; 1176285Snate@binkert.org return; 1186285Snate@binkert.org } 1196285Snate@binkert.org 1206467Sdrh5@cs.wisc.edu SequencerMsg msg; 1216368Sdrh5@cs.wisc.edu msg.getPhysicalAddress() = Address(active_request.start_paddr + 1226922SBrad.Beckmann@amd.com active_request.bytes_completed); 1236888SBrad.Beckmann@amd.com 1246368Sdrh5@cs.wisc.edu assert((msg.getPhysicalAddress().getAddress() & m_data_block_mask) == 0); 1256368Sdrh5@cs.wisc.edu msg.getLineAddress() = line_address(msg.getPhysicalAddress()); 1266888SBrad.Beckmann@amd.com 1276467Sdrh5@cs.wisc.edu msg.getType() = (active_request.write ? SequencerRequestType_ST : 1286467Sdrh5@cs.wisc.edu SequencerRequestType_LD); 1296888SBrad.Beckmann@amd.com 1306368Sdrh5@cs.wisc.edu msg.getLen() = (active_request.len - 1316368Sdrh5@cs.wisc.edu active_request.bytes_completed < RubySystem::getBlockSizeBytes() ? 1326368Sdrh5@cs.wisc.edu active_request.len - active_request.bytes_completed : 1336368Sdrh5@cs.wisc.edu RubySystem::getBlockSizeBytes()); 1346888SBrad.Beckmann@amd.com 1356285Snate@binkert.org if (active_request.write) { 1366368Sdrh5@cs.wisc.edu msg.getDataBlk().setData(&active_request.data[active_request.bytes_completed], 1376368Sdrh5@cs.wisc.edu 0, msg.getLen()); 1386467Sdrh5@cs.wisc.edu msg.getType() = SequencerRequestType_ST; 1396285Snate@binkert.org } else { 1406467Sdrh5@cs.wisc.edu msg.getType() = SequencerRequestType_LD; 1416285Snate@binkert.org } 1426888SBrad.Beckmann@amd.com 1436888SBrad.Beckmann@amd.com assert(m_mandatory_q_ptr != NULL); 1446285Snate@binkert.org m_mandatory_q_ptr->enqueue(msg); 1456285Snate@binkert.org active_request.bytes_issued += msg.getLen(); 1466285Snate@binkert.org} 1476285Snate@binkert.org 1486285Snate@binkert.orgvoid DMASequencer::dataCallback(const DataBlock & dblk) 1496285Snate@binkert.org{ 1506285Snate@binkert.org assert(m_is_busy == true); 1516285Snate@binkert.org int len = active_request.bytes_issued - active_request.bytes_completed; 1526285Snate@binkert.org int offset = 0; 1536285Snate@binkert.org if (active_request.bytes_completed == 0) 1546368Sdrh5@cs.wisc.edu offset = active_request.start_paddr & m_data_block_mask; 1556368Sdrh5@cs.wisc.edu assert( active_request.write == false ); 1566368Sdrh5@cs.wisc.edu memcpy(&active_request.data[active_request.bytes_completed], 1576368Sdrh5@cs.wisc.edu dblk.getData(offset, len), len); 1586285Snate@binkert.org issueNext(); 1596285Snate@binkert.org} 1606285Snate@binkert.org 1616285Snate@binkert.orgvoid DMASequencer::ackCallback() 1626285Snate@binkert.org{ 1636285Snate@binkert.org issueNext(); 1646285Snate@binkert.org} 1656285Snate@binkert.org 1666285Snate@binkert.orgvoid DMASequencer::printConfig(ostream & out) 1676285Snate@binkert.org{ 1686285Snate@binkert.org 1696285Snate@binkert.org} 1706876Ssteve.reinhardt@amd.com 1716876Ssteve.reinhardt@amd.com 1726876Ssteve.reinhardt@amd.comDMASequencer * 1736876Ssteve.reinhardt@amd.comDMASequencerParams::create() 1746876Ssteve.reinhardt@amd.com{ 1756876Ssteve.reinhardt@amd.com return new DMASequencer(this); 1766876Ssteve.reinhardt@amd.com} 177