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