io_device.cc revision 2569
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 29#include "dev/io_device.hh" 30#include "sim/builder.hh" 31 32 33PioPort::PioPort(PioDevice *dev, Platform *p) 34 : device(dev), platform(p) 35{ } 36 37 38Tick 39PioPort::recvAtomic(Packet &pkt) 40{ 41 return device->recvAtomic(pkt); 42} 43 44void 45PioPort::recvFunctional(Packet &pkt) 46{ 47 device->recvAtomic(pkt); 48} 49 50void 51PioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 52{ 53 snoop.clear(); 54 device->addressRanges(resp); 55} 56 57 58Packet * 59PioPort::recvRetry() 60{ 61 Packet* pkt = transmitList.front(); 62 transmitList.pop_front(); 63 return pkt; 64} 65 66 67void 68PioPort::SendEvent::process() 69{ 70 if (port->Port::sendTiming(packet) == Success) 71 return; 72 73 port->transmitList.push_back(&packet); 74} 75 76 77bool 78PioPort::recvTiming(Packet &pkt) 79{ 80 device->recvAtomic(pkt); 81 sendTiming(pkt, pkt.time-pkt.req->getTime()); 82 return Success; 83} 84 85PioDevice::~PioDevice() 86{ 87 if (pioPort) 88 delete pioPort; 89} 90 91void 92PioDevice::init() 93{ 94 if (!pioPort) 95 panic("Pio port not connected to anything!"); 96 pioPort->sendStatusChange(Port::RangeChange); 97} 98 99void 100BasicPioDevice::addressRanges(AddrRangeList &range_list) 101{ 102 assert(pioSize != 0); 103 range_list.clear(); 104 range_list.push_back(RangeSize(pioAddr, pioSize)); 105} 106 107 108DmaPort::DmaPort(DmaDevice *dev, Platform *p) 109 : device(dev), platform(p), pendingCount(0) 110{ } 111 112bool 113DmaPort::recvTiming(Packet &pkt) 114{ 115 if (pkt.senderState) { 116 DmaReqState *state; 117 state = (DmaReqState*)pkt.senderState; 118 state->completionEvent->schedule(pkt.time - pkt.req->getTime()); 119 delete pkt.req; 120 delete &pkt; 121 } else { 122 delete pkt.req; 123 delete &pkt; 124 } 125 126 return Success; 127} 128 129DmaDevice::DmaDevice(Params *p) 130 : PioDevice(p), dmaPort(NULL) 131{ } 132 133void 134DmaPort::SendEvent::process() 135{ 136 if (port->Port::sendTiming(packet) == Success) 137 return; 138 139 port->transmitList.push_back(&packet); 140} 141 142Packet * 143DmaPort::recvRetry() 144{ 145 Packet* pkt = transmitList.front(); 146 transmitList.pop_front(); 147 return pkt; 148} 149void 150DmaPort::dmaAction(Command cmd, Addr addr, int size, Event *event, 151 uint8_t *data) 152{ 153 154 assert(event); 155 156 int prevSize = 0; 157 Packet basePkt; 158 Request baseReq(false); 159 160 basePkt.flags = 0; 161 basePkt.coherence = NULL; 162 basePkt.senderState = NULL; 163 basePkt.src = 0; 164 basePkt.dest = 0; 165 basePkt.cmd = cmd; 166 basePkt.result = Unknown; 167 basePkt.req = NULL; 168// baseReq.nicReq = true; 169 baseReq.setTime(curTick); 170 171 for (ChunkGenerator gen(addr, size, peerBlockSize()); 172 !gen.done(); gen.next()) { 173 Packet *pkt = new Packet(basePkt); 174 Request *req = new Request(baseReq); 175 pkt->addr = gen.addr(); 176 pkt->size = gen.size(); 177 pkt->req = req; 178 pkt->req->setPaddr(pkt->addr); 179 pkt->req->setSize(pkt->size); 180 // Increment the data pointer on a write 181 if (data) 182 pkt->dataStatic(data + prevSize) ; 183 prevSize += pkt->size; 184 // Set the last bit of the dma as the final packet for this dma 185 // and set it's completion event. 186 if (prevSize == size) { 187 DmaReqState *state = new DmaReqState(event, true); 188 189 pkt->senderState = (void*)state; 190 } 191 assert(pendingCount >= 0); 192 pendingCount++; 193 sendDma(pkt); 194 } 195 // since this isn't getting used and we want a check to make sure that all 196 // packets had data in them at some point. 197 basePkt.dataStatic((uint8_t*)NULL); 198} 199 200 201void 202DmaPort::sendDma(Packet *pkt) 203{ 204 // some kind of selction between access methods 205 // more work is going to have to be done to make 206 // switching actually work 207 /* MemState state = device->platform->system->memState; 208 209 if (state == Timing) { 210 if (sendTiming(pkt) == Failure) 211 transmitList.push_back(&packet); 212 } else if (state == Atomic) {*/ 213 sendAtomic(*pkt); 214 if (pkt->senderState) { 215 DmaReqState *state = (DmaReqState*)pkt->senderState; 216 state->completionEvent->schedule(curTick + (pkt->time - pkt->req->getTime()) +1); 217 } 218 pendingCount--; 219 assert(pendingCount >= 0); 220 delete pkt->req; 221 delete pkt; 222 223/* } else if (state == Functional) { 224 sendFunctional(pkt); 225 // Is this correct??? 226 completionEvent->schedule(pkt.req->responseTime - pkt.req->requestTime); 227 completionEvent == NULL; 228 } else 229 panic("Unknown memory command state."); 230 */ 231} 232 233DmaDevice::~DmaDevice() 234{ 235 if (dmaPort) 236 delete dmaPort; 237} 238 239 240