DMASequencer.cc revision 8174:e21f6e70169e
1/* 2 * Copyright (c) 2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include "mem/protocol/SequencerMsg.hh" 30#include "mem/protocol/SequencerRequestType.hh" 31#include "mem/ruby/buffers/MessageBuffer.hh" 32#include "mem/ruby/slicc_interface/AbstractController.hh" 33#include "mem/ruby/system/DMASequencer.hh" 34#include "mem/ruby/system/System.hh" 35 36DMASequencer::DMASequencer(const Params *p) 37 : RubyPort(p) 38{ 39} 40 41void 42DMASequencer::init() 43{ 44 RubyPort::init(); 45 m_is_busy = false; 46 m_data_block_mask = ~ (~0 << RubySystem::getBlockSizeBits()); 47} 48 49RequestStatus 50DMASequencer::makeRequest(const RubyRequest &request) 51{ 52 if (m_is_busy) { 53 return RequestStatus_BufferFull; 54 } 55 56 uint64_t paddr = request.m_PhysicalAddress.getAddress(); 57 uint8_t* data = request.data; 58 int len = request.m_Size; 59 bool write = false; 60 switch(request.m_Type) { 61 case RubyRequestType_LD: 62 write = false; 63 break; 64 case RubyRequestType_ST: 65 write = true; 66 break; 67 default: 68 panic("DMASequencer::makeRequest does not support RubyRequestType"); 69 return RequestStatus_NULL; 70 } 71 72 assert(!m_is_busy); // only support one outstanding DMA request 73 m_is_busy = true; 74 75 active_request.start_paddr = paddr; 76 active_request.write = write; 77 active_request.data = data; 78 active_request.len = len; 79 active_request.bytes_completed = 0; 80 active_request.bytes_issued = 0; 81 active_request.pkt = request.pkt; 82 83 SequencerMsg *msg = new SequencerMsg; 84 msg->getPhysicalAddress() = Address(paddr); 85 msg->getLineAddress() = line_address(msg->getPhysicalAddress()); 86 msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD; 87 int offset = paddr & m_data_block_mask; 88 89 msg->getLen() = (offset + len) <= RubySystem::getBlockSizeBytes() ? 90 len : RubySystem::getBlockSizeBytes() - offset; 91 92 if (write && (data != NULL)) { 93 if (active_request.data != NULL) { 94 msg->getDataBlk().setData(data, offset, msg->getLen()); 95 } 96 } 97 98 assert(m_mandatory_q_ptr != NULL); 99 m_mandatory_q_ptr->enqueue(msg); 100 active_request.bytes_issued += msg->getLen(); 101 102 return RequestStatus_Issued; 103} 104 105void 106DMASequencer::issueNext() 107{ 108 assert(m_is_busy == true); 109 active_request.bytes_completed = active_request.bytes_issued; 110 if (active_request.len == active_request.bytes_completed) { 111 // 112 // Must unset the busy flag before calling back the dma port because 113 // the callback may cause a previously nacked request to be reissued 114 // 115 DPRINTF(RubyDma, "DMA request completed\n"); 116 m_is_busy = false; 117 ruby_hit_callback(active_request.pkt); 118 return; 119 } 120 121 SequencerMsg *msg = new SequencerMsg; 122 msg->getPhysicalAddress() = Address(active_request.start_paddr + 123 active_request.bytes_completed); 124 125 assert((msg->getPhysicalAddress().getAddress() & m_data_block_mask) == 0); 126 msg->getLineAddress() = line_address(msg->getPhysicalAddress()); 127 128 msg->getType() = (active_request.write ? SequencerRequestType_ST : 129 SequencerRequestType_LD); 130 131 msg->getLen() = 132 (active_request.len - 133 active_request.bytes_completed < RubySystem::getBlockSizeBytes() ? 134 active_request.len - active_request.bytes_completed : 135 RubySystem::getBlockSizeBytes()); 136 137 if (active_request.write) { 138 msg->getDataBlk(). 139 setData(&active_request.data[active_request.bytes_completed], 140 0, msg->getLen()); 141 msg->getType() = SequencerRequestType_ST; 142 } else { 143 msg->getType() = SequencerRequestType_LD; 144 } 145 146 assert(m_mandatory_q_ptr != NULL); 147 m_mandatory_q_ptr->enqueue(msg); 148 active_request.bytes_issued += msg->getLen(); 149 DPRINTF(RubyDma, 150 "DMA request bytes issued %d, bytes completed %d, total len %d\n", 151 active_request.bytes_issued, active_request.bytes_completed, 152 active_request.len); 153} 154 155void 156DMASequencer::dataCallback(const DataBlock & dblk) 157{ 158 assert(m_is_busy == true); 159 int len = active_request.bytes_issued - active_request.bytes_completed; 160 int offset = 0; 161 if (active_request.bytes_completed == 0) 162 offset = active_request.start_paddr & m_data_block_mask; 163 assert(active_request.write == false); 164 if (active_request.data != NULL) { 165 memcpy(&active_request.data[active_request.bytes_completed], 166 dblk.getData(offset, len), len); 167 } 168 issueNext(); 169} 170 171void 172DMASequencer::ackCallback() 173{ 174 issueNext(); 175} 176 177void 178DMASequencer::printConfig(std::ostream & out) 179{ 180} 181 182DMASequencer * 183DMASequencerParams::create() 184{ 185 return new DMASequencer(this); 186} 187