DMASequencer.cc revision 7055
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
296145Snate@binkert.org#include "mem/protocol/SequencerMsg.hh"
306145Snate@binkert.org#include "mem/protocol/SequencerRequestType.hh"
316145Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh"
326145Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh"
336145Snate@binkert.org#include "mem/ruby/system/DMASequencer.hh"
346145Snate@binkert.org#include "mem/ruby/system/System.hh"
356145Snate@binkert.org
366145Snate@binkert.orgDMASequencer::DMASequencer(const Params *p)
376145Snate@binkert.org    : RubyPort(p)
386145Snate@binkert.org{
396145Snate@binkert.org}
406154Snate@binkert.org
416154Snate@binkert.orgvoid
426154Snate@binkert.orgDMASequencer::init()
436154Snate@binkert.org{
446154Snate@binkert.org    RubyPort::init();
456154Snate@binkert.org    m_is_busy = false;
466154Snate@binkert.org    m_data_block_mask = ~ (~0 << RubySystem::getBlockSizeBits());
476154Snate@binkert.org}
486154Snate@binkert.org
496145Snate@binkert.orgRequestStatus
506145Snate@binkert.orgDMASequencer::makeRequest(const RubyRequest &request)
516145Snate@binkert.org{
526145Snate@binkert.org    uint64_t paddr = request.paddr;
536145Snate@binkert.org    uint8_t* data = request.data;
546145Snate@binkert.org    int len = request.len;
556145Snate@binkert.org    bool write = false;
566145Snate@binkert.org    switch(request.type) {
576145Snate@binkert.org      case RubyRequestType_LD:
586145Snate@binkert.org        write = false;
596145Snate@binkert.org        break;
606145Snate@binkert.org      case RubyRequestType_ST:
616145Snate@binkert.org        write = true;
626145Snate@binkert.org        break;
636145Snate@binkert.org      case RubyRequestType_NULL:
646145Snate@binkert.org      case RubyRequestType_IFETCH:
656145Snate@binkert.org      case RubyRequestType_Locked_Read:
666145Snate@binkert.org      case RubyRequestType_Locked_Write:
676145Snate@binkert.org      case RubyRequestType_RMW_Read:
686145Snate@binkert.org      case RubyRequestType_RMW_Write:
696145Snate@binkert.org      case RubyRequestType_NUM:
706145Snate@binkert.org        panic("DMASequencer::makeRequest does not support RubyRequestType");
716145Snate@binkert.org        return RequestStatus_NULL;
726145Snate@binkert.org    }
736145Snate@binkert.org
746145Snate@binkert.org    assert(!m_is_busy);  // only support one outstanding DMA request
756145Snate@binkert.org    m_is_busy = true;
766145Snate@binkert.org
776145Snate@binkert.org    active_request.start_paddr = paddr;
786145Snate@binkert.org    active_request.write = write;
796145Snate@binkert.org    active_request.data = data;
806145Snate@binkert.org    active_request.len = len;
816145Snate@binkert.org    active_request.bytes_completed = 0;
826145Snate@binkert.org    active_request.bytes_issued = 0;
836145Snate@binkert.org    active_request.pkt = request.pkt;
846145Snate@binkert.org
856145Snate@binkert.org    SequencerMsg msg;
866145Snate@binkert.org    msg.getPhysicalAddress() = Address(paddr);
876145Snate@binkert.org    msg.getLineAddress() = line_address(msg.getPhysicalAddress());
886145Snate@binkert.org    msg.getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD;
896145Snate@binkert.org    int offset = paddr & m_data_block_mask;
906145Snate@binkert.org
916145Snate@binkert.org    msg.getLen() = (offset + len) <= RubySystem::getBlockSizeBytes() ?
926145Snate@binkert.org        len : RubySystem::getBlockSizeBytes() - offset;
936145Snate@binkert.org
946145Snate@binkert.org    if (write) {
956145Snate@binkert.org        msg.getDataBlk().setData(data, offset, msg.getLen());
966145Snate@binkert.org    }
976145Snate@binkert.org
986145Snate@binkert.org    assert(m_mandatory_q_ptr != NULL);
996145Snate@binkert.org    m_mandatory_q_ptr->enqueue(msg);
1006145Snate@binkert.org    active_request.bytes_issued += msg.getLen();
1016145Snate@binkert.org
1026145Snate@binkert.org    return RequestStatus_Issued;
1036145Snate@binkert.org}
1046145Snate@binkert.org
1056145Snate@binkert.orgvoid
1066151Sdrh5@cs.wisc.eduDMASequencer::issueNext()
1076151Sdrh5@cs.wisc.edu{
1086145Snate@binkert.org    assert(m_is_busy == true);
1096145Snate@binkert.org    active_request.bytes_completed = active_request.bytes_issued;
1106151Sdrh5@cs.wisc.edu    if (active_request.len == active_request.bytes_completed) {
1116151Sdrh5@cs.wisc.edu        ruby_hit_callback(active_request.pkt);
1126145Snate@binkert.org        m_is_busy = false;
1136145Snate@binkert.org        return;
1146145Snate@binkert.org    }
1156145Snate@binkert.org
1166145Snate@binkert.org    SequencerMsg msg;
1176145Snate@binkert.org    msg.getPhysicalAddress() = Address(active_request.start_paddr +
1186145Snate@binkert.org                                       active_request.bytes_completed);
1196145Snate@binkert.org
1206145Snate@binkert.org    assert((msg.getPhysicalAddress().getAddress() & m_data_block_mask) == 0);
1216145Snate@binkert.org    msg.getLineAddress() = line_address(msg.getPhysicalAddress());
1226145Snate@binkert.org
1236145Snate@binkert.org    msg.getType() = (active_request.write ? SequencerRequestType_ST :
1246145Snate@binkert.org                     SequencerRequestType_LD);
1256145Snate@binkert.org
1266145Snate@binkert.org    msg.getLen() =
1276145Snate@binkert.org        (active_request.len -
1286152Sdrh5@cs.wisc.edu         active_request.bytes_completed < RubySystem::getBlockSizeBytes() ?
1296145Snate@binkert.org         active_request.len - active_request.bytes_completed :
1306145Snate@binkert.org         RubySystem::getBlockSizeBytes());
1316145Snate@binkert.org
1326145Snate@binkert.org    if (active_request.write) {
1336145Snate@binkert.org        msg.getDataBlk().
1346145Snate@binkert.org            setData(&active_request.data[active_request.bytes_completed],
1356145Snate@binkert.org                    0, msg.getLen());
1366145Snate@binkert.org        msg.getType() = SequencerRequestType_ST;
1376145Snate@binkert.org    } else {
1386145Snate@binkert.org        msg.getType() = SequencerRequestType_LD;
1396145Snate@binkert.org    }
1406145Snate@binkert.org
1416145Snate@binkert.org    assert(m_mandatory_q_ptr != NULL);
1426145Snate@binkert.org    m_mandatory_q_ptr->enqueue(msg);
1436145Snate@binkert.org    active_request.bytes_issued += msg.getLen();
1446145Snate@binkert.org}
1456145Snate@binkert.org
1466145Snate@binkert.orgvoid
1476145Snate@binkert.orgDMASequencer::dataCallback(const DataBlock & dblk)
1486145Snate@binkert.org{
1496145Snate@binkert.org    assert(m_is_busy == true);
1506145Snate@binkert.org    int len = active_request.bytes_issued - active_request.bytes_completed;
1516145Snate@binkert.org    int offset = 0;
1526145Snate@binkert.org    if (active_request.bytes_completed == 0)
1536145Snate@binkert.org        offset = active_request.start_paddr & m_data_block_mask;
1546145Snate@binkert.org    assert(active_request.write == false);
1556145Snate@binkert.org    memcpy(&active_request.data[active_request.bytes_completed],
1566145Snate@binkert.org           dblk.getData(offset, len), len);
1576145Snate@binkert.org    issueNext();
1586145Snate@binkert.org}
1596145Snate@binkert.org
1606145Snate@binkert.orgvoid
1616145Snate@binkert.orgDMASequencer::ackCallback()
1626145Snate@binkert.org{
1636145Snate@binkert.org    issueNext();
1646145Snate@binkert.org}
1656145Snate@binkert.org
1666145Snate@binkert.orgvoid
1676145Snate@binkert.orgDMASequencer::printConfig(std::ostream & out)
168{
169}
170
171DMASequencer *
172DMASequencerParams::create()
173{
174    return new DMASequencer(this);
175}
176