io_device.cc revision 2784
1/* 2 * Copyright (c) 2006 The Regents of The University of Michigan 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 * Authors: Ali Saidi 29 * Nathan Binkert 30 */ 31 32#include "base/trace.hh" 33#include "dev/io_device.hh" 34#include "sim/builder.hh" 35 36 37PioPort::PioPort(PioDevice *dev, Platform *p) 38 : Port(dev->name() + "-pioport"), device(dev), platform(p) 39{ } 40 41 42Tick 43PioPort::recvAtomic(Packet *pkt) 44{ 45 return device->recvAtomic(pkt); 46} 47 48void 49PioPort::recvFunctional(Packet *pkt) 50{ 51 device->recvAtomic(pkt); 52} 53 54void 55PioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 56{ 57 snoop.clear(); 58 device->addressRanges(resp); 59} 60 61 62void 63PioPort::recvRetry() 64{ 65 bool result = true; 66 while (result && transmitList.size()) { 67 result = Port::sendTiming(transmitList.front()); 68 if (result) 69 transmitList.pop_front(); 70 } 71} 72 73void 74PioPort::SendEvent::process() 75{ 76 if (port->Port::sendTiming(packet)) 77 return; 78 79 port->transmitList.push_back(packet); 80} 81 82 83 84bool 85PioPort::recvTiming(Packet *pkt) 86{ 87 if (pkt->result == Packet::Nacked) { 88 pkt->reinitNacked(); 89 if (transmitList.size()) { 90 transmitList.push_front(pkt); 91 } else { 92 if (!Port::sendTiming(pkt)) 93 transmitList.push_front(pkt); 94 } 95 } else { 96 Tick latency = device->recvAtomic(pkt); 97 // turn packet around to go back to requester 98 pkt->makeTimingResponse(); 99 sendTiming(pkt, latency); 100 } 101 return true; 102} 103 104PioDevice::~PioDevice() 105{ 106 if (pioPort) 107 delete pioPort; 108} 109 110void 111PioDevice::init() 112{ 113 if (!pioPort) 114 panic("Pio port not connected to anything!"); 115 pioPort->sendStatusChange(Port::RangeChange); 116} 117 118void 119BasicPioDevice::addressRanges(AddrRangeList &range_list) 120{ 121 assert(pioSize != 0); 122 range_list.clear(); 123 range_list.push_back(RangeSize(pioAddr, pioSize)); 124} 125 126 127DmaPort::DmaPort(DmaDevice *dev, Platform *p) 128 : Port(dev->name() + "-dmaport"), device(dev), platform(p), pendingCount(0) 129{ } 130 131bool 132DmaPort::recvTiming(Packet *pkt) 133{ 134 135 136 if (pkt->result == Packet::Nacked) { 137 DPRINTF(DMA, "Received nacked Pkt %#x with State: %#x Addr: %#x\n", 138 pkt, pkt->senderState, pkt->getAddr()); 139 pkt->reinitNacked(); 140 sendDma(pkt, true); 141 } else if (pkt->senderState) { 142 DmaReqState *state; 143 DPRINTF(DMA, "Received response Pkt %#x with State: %#x Addr: %#x\n", 144 pkt, pkt->senderState, pkt->getAddr()); 145 state = dynamic_cast<DmaReqState*>(pkt->senderState); 146 pendingCount--; 147 148 assert(pendingCount >= 0); 149 assert(state); 150 151 state->numBytes += pkt->req->getSize(); 152 if (state->totBytes == state->numBytes) { 153 state->completionEvent->process(); 154 delete state; 155 } 156 delete pkt->req; 157 delete pkt; 158 } else { 159 panic("Got packet without sender state... huh?\n"); 160 } 161 162 return true; 163} 164 165DmaDevice::DmaDevice(Params *p) 166 : PioDevice(p), dmaPort(NULL) 167{ } 168 169void 170DmaPort::recvRetry() 171{ 172 Packet* pkt = transmitList.front(); 173 bool result = true; 174 while (result && transmitList.size()) { 175 DPRINTF(DMA, "Retry on Packet %#x with senderState: %#x\n", 176 pkt, pkt->senderState); 177 result = sendTiming(pkt); 178 if (result) { 179 DPRINTF(DMA, "-- Done\n"); 180 transmitList.pop_front(); 181 } else { 182 DPRINTF(DMA, "-- Failed, queued\n"); 183 } 184 } 185} 186 187 188void 189DmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 190 uint8_t *data) 191{ 192 assert(event); 193 194 DmaReqState *reqState = new DmaReqState(event, this, size); 195 196 for (ChunkGenerator gen(addr, size, peerBlockSize()); 197 !gen.done(); gen.next()) { 198 Request *req = new Request(gen.addr(), gen.size(), 0); 199 Packet *pkt = new Packet(req, cmd, Packet::Broadcast); 200 201 // Increment the data pointer on a write 202 if (data) 203 pkt->dataStatic(data + gen.complete()); 204 205 pkt->senderState = reqState; 206 207 assert(pendingCount >= 0); 208 pendingCount++; 209 sendDma(pkt); 210 } 211} 212 213 214void 215DmaPort::sendDma(Packet *pkt, bool front) 216{ 217 // some kind of selction between access methods 218 // more work is going to have to be done to make 219 // switching actually work 220 /* MemState state = device->platform->system->memState; 221 222 if (state == Timing) { */ 223 DPRINTF(DMA, "Attempting to send Packet %#x with addr: %#x\n", 224 pkt, pkt->getAddr()); 225 if (transmitList.size() || !sendTiming(pkt)) { 226 if (front) 227 transmitList.push_front(pkt); 228 else 229 transmitList.push_back(pkt); 230 DPRINTF(DMA, "-- Failed: queued\n"); 231 } else { 232 DPRINTF(DMA, "-- Done\n"); 233 } 234 /* } else if (state == Atomic) { 235 sendAtomic(pkt); 236 if (pkt->senderState) { 237 DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState); 238 assert(state); 239 state->completionEvent->schedule(curTick + (pkt->time - 240 pkt->req->getTime()) +1); 241 delete state; 242 } 243 pendingCount--; 244 assert(pendingCount >= 0); 245 delete pkt->req; 246 delete pkt; 247 248 } else if (state == Functional) { 249 sendFunctional(pkt); 250 // Is this correct??? 251 completionEvent->schedule(pkt->req->responseTime - pkt->req->requestTime); 252 completionEvent == NULL; 253 } else 254 panic("Unknown memory command state."); 255 */ 256} 257 258DmaDevice::~DmaDevice() 259{ 260 if (dmaPort) 261 delete dmaPort; 262} 263 264 265