DMASequencer.cc revision 11339:c45bfadcd51b
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 297832Snate@binkert.org#include <memory> 307547SBrad.Beckmann@amd.com 317547SBrad.Beckmann@amd.com#include "debug/RubyDma.hh" 328645Snilay@cs.wisc.edu#include "debug/RubyStats.hh" 337454Snate@binkert.org#include "mem/protocol/SequencerMsg.hh" 347054Snate@binkert.org#include "mem/protocol/SequencerRequestType.hh" 357054Snate@binkert.org#include "mem/ruby/system/DMASequencer.hh" 368257SBrad.Beckmann@amd.com#include "mem/ruby/system/RubySystem.hh" 378258SBrad.Beckmann@amd.com 386154Snate@binkert.orgDMASequencer::DMASequencer(const Params *p) 397054Snate@binkert.org : RubyPort(p) 407547SBrad.Beckmann@amd.com{ 418255SBrad.Beckmann@amd.com} 426154Snate@binkert.org 436154Snate@binkert.orgvoid 446145Snate@binkert.orgDMASequencer::init() 457055Snate@binkert.org{ 467454Snate@binkert.org RubyPort::init(); 477055Snate@binkert.org m_is_busy = false; 486876Ssteve.reinhardt@amd.com m_data_block_mask = ~ (~0 << RubySystem::getBlockSizeBits()); 496876Ssteve.reinhardt@amd.com} 506285Snate@binkert.org 518259SBrad.Beckmann@amd.comRequestStatus 528259SBrad.Beckmann@amd.comDMASequencer::makeRequest(PacketPtr pkt) 538259SBrad.Beckmann@amd.com{ 548259SBrad.Beckmann@amd.com if (m_is_busy) { 557054Snate@binkert.org return RequestStatus_BufferFull; 567054Snate@binkert.org } 577054Snate@binkert.org 586285Snate@binkert.org Addr paddr = pkt->getAddr(); 597454Snate@binkert.org uint8_t* data = pkt->getPtr<uint8_t>(); 606285Snate@binkert.org int len = pkt->getSize(); 617454Snate@binkert.org bool write = pkt->isWrite(); 627454Snate@binkert.org 637054Snate@binkert.org assert(!m_is_busy); // only support one outstanding DMA request 647054Snate@binkert.org m_is_busy = true; 657054Snate@binkert.org 666285Snate@binkert.org active_request.start_paddr = paddr; 677054Snate@binkert.org active_request.write = write; 687054Snate@binkert.org active_request.data = data; 697454Snate@binkert.org active_request.len = len; 707454Snate@binkert.org active_request.bytes_completed = 0; 717054Snate@binkert.org active_request.bytes_issued = 0; 727454Snate@binkert.org active_request.pkt = pkt; 737454Snate@binkert.org 747054Snate@binkert.org std::shared_ptr<SequencerMsg> msg = 757056Snate@binkert.org std::make_shared<SequencerMsg>(clockEdge()); 767056Snate@binkert.org msg->getPhysicalAddress() = paddr; 777056Snate@binkert.org msg->getLineAddress() = makeLineAddress(msg->getPhysicalAddress()); 787056Snate@binkert.org msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD; 797054Snate@binkert.org int offset = paddr & m_data_block_mask; 807054Snate@binkert.org 819274Snilay@cs.wisc.edu msg->getLen() = (offset + len) <= RubySystem::getBlockSizeBytes() ? 829274Snilay@cs.wisc.edu len : RubySystem::getBlockSizeBytes() - offset; 839593Snilay@cs.wisc.edu 849593Snilay@cs.wisc.edu if (write && (data != NULL)) { 859274Snilay@cs.wisc.edu if (active_request.data != NULL) { 869274Snilay@cs.wisc.edu msg->getDataBlk().setData(data, offset, msg->getLen()); 879274Snilay@cs.wisc.edu } 889274Snilay@cs.wisc.edu } 896881SBrad.Beckmann@amd.com 906285Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 917054Snate@binkert.org m_mandatory_q_ptr->enqueue(msg, clockEdge(), cyclesToTicks(Cycles(1))); 927054Snate@binkert.org active_request.bytes_issued += msg->getLen(); 936881SBrad.Beckmann@amd.com 947054Snate@binkert.org return RequestStatus_Issued; 956881SBrad.Beckmann@amd.com} 967054Snate@binkert.org 977054Snate@binkert.orgvoid 987054Snate@binkert.orgDMASequencer::issueNext() 997054Snate@binkert.org{ 1007054Snate@binkert.org assert(m_is_busy); 1016285Snate@binkert.org active_request.bytes_completed = active_request.bytes_issued; 1026145Snate@binkert.org if (active_request.len == active_request.bytes_completed) { 1037054Snate@binkert.org // 1047054Snate@binkert.org // Must unset the busy flag before calling back the dma port because 1056145Snate@binkert.org // the callback may cause a previously nacked request to be reissued 1067054Snate@binkert.org // 1077054Snate@binkert.org DPRINTF(RubyDma, "DMA request completed\n"); 1087054Snate@binkert.org m_is_busy = false; 1097054Snate@binkert.org ruby_hit_callback(active_request.pkt); 1107054Snate@binkert.org return; 1116145Snate@binkert.org } 1126145Snate@binkert.org 1137054Snate@binkert.org std::shared_ptr<SequencerMsg> msg = 1147054Snate@binkert.org std::make_shared<SequencerMsg>(clockEdge()); 1157054Snate@binkert.org msg->getPhysicalAddress() = active_request.start_paddr + 1166145Snate@binkert.org active_request.bytes_completed; 1176145Snate@binkert.org 1186145Snate@binkert.org assert((msg->getPhysicalAddress() & m_data_block_mask) == 0); 1196145Snate@binkert.org msg->getLineAddress() = makeLineAddress(msg->getPhysicalAddress()); 1207054Snate@binkert.org 1217454Snate@binkert.org msg->getType() = (active_request.write ? SequencerRequestType_ST : 1227454Snate@binkert.org SequencerRequestType_LD); 1237054Snate@binkert.org 1247454Snate@binkert.org msg->getLen() = 1257454Snate@binkert.org (active_request.len - 1267054Snate@binkert.org active_request.bytes_completed < RubySystem::getBlockSizeBytes() ? 1276145Snate@binkert.org active_request.len - active_request.bytes_completed : 1286145Snate@binkert.org RubySystem::getBlockSizeBytes()); 1296145Snate@binkert.org 1307054Snate@binkert.org if (active_request.write) { 1318257SBrad.Beckmann@amd.com msg->getDataBlk(). 1328257SBrad.Beckmann@amd.com setData(&active_request.data[active_request.bytes_completed], 1338257SBrad.Beckmann@amd.com 0, msg->getLen()); 1348257SBrad.Beckmann@amd.com } 1356145Snate@binkert.org 1367054Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 1377054Snate@binkert.org m_mandatory_q_ptr->enqueue(msg, clockEdge(), cyclesToTicks(Cycles(1))); 1387054Snate@binkert.org active_request.bytes_issued += msg->getLen(); 1397054Snate@binkert.org DPRINTF(RubyDma, 1407054Snate@binkert.org "DMA request bytes issued %d, bytes completed %d, total len %d\n", 1417054Snate@binkert.org active_request.bytes_issued, active_request.bytes_completed, 1427054Snate@binkert.org active_request.len); 1437054Snate@binkert.org} 1447054Snate@binkert.org 1458258SBrad.Beckmann@amd.comvoid 1468258SBrad.Beckmann@amd.comDMASequencer::dataCallback(const DataBlock & dblk) 1477054Snate@binkert.org{ 1488257SBrad.Beckmann@amd.com assert(m_is_busy); 1498258SBrad.Beckmann@amd.com int len = active_request.bytes_issued - active_request.bytes_completed; 1508258SBrad.Beckmann@amd.com int offset = 0; 1518257SBrad.Beckmann@amd.com if (active_request.bytes_completed == 0) 1526145Snate@binkert.org offset = active_request.start_paddr & m_data_block_mask; 1536145Snate@binkert.org assert(!active_request.write); 1546145Snate@binkert.org if (active_request.data != NULL) { 1556145Snate@binkert.org memcpy(&active_request.data[active_request.bytes_completed], 1567054Snate@binkert.org dblk.getData(offset, len), len); 1578257SBrad.Beckmann@amd.com } 1588257SBrad.Beckmann@amd.com issueNext(); 1598257SBrad.Beckmann@amd.com} 1608257SBrad.Beckmann@amd.com 1616145Snate@binkert.orgvoid 1627054Snate@binkert.orgDMASequencer::ackCallback() 1637054Snate@binkert.org{ 1647054Snate@binkert.org issueNext(); 1657054Snate@binkert.org} 1667054Snate@binkert.org 1677054Snate@binkert.orgvoid 1686145Snate@binkert.orgDMASequencer::recordRequestType(DMASequencerRequestType requestType) 1696145Snate@binkert.org{ 1706145Snate@binkert.org DPRINTF(RubyStats, "Recorded statistic: %s\n", 1716145Snate@binkert.org DMASequencerRequestType_to_string(requestType)); 1727054Snate@binkert.org} 1738257SBrad.Beckmann@amd.com 1748257SBrad.Beckmann@amd.comDMASequencer * 1758257SBrad.Beckmann@amd.comDMASequencerParams::create() 1768257SBrad.Beckmann@amd.com{ 1776145Snate@binkert.org return new DMASequencer(this); 1787054Snate@binkert.org} 1797054Snate@binkert.org