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/chunk_generator.hh" 33#include "base/trace.hh" 34#include "dev/io_device.hh" 35#include "sim/builder.hh" 36#include "sim/system.hh" 37 38 39PioPort::PioPort(PioDevice *dev, System *s, std::string pname) 40 : SimpleTimingPort(dev->name() + pname, dev), device(dev) 41{ } 42 43 44Tick 45PioPort::recvAtomic(PacketPtr pkt) 46{ 47 return pkt->isRead() ? device->read(pkt) : device->write(pkt); 48} 49 50void 51PioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 52{ 53 snoop.clear(); 54 device->addressRanges(resp); 55} 56 57 58PioDevice::~PioDevice() 59{ 60 if (pioPort) 61 delete pioPort; 62} 63 64void 65PioDevice::init() 66{ 67 if (!pioPort) 68 panic("Pio port not connected to anything!"); 69 pioPort->sendStatusChange(Port::RangeChange); 70} 71 72 73unsigned int 74PioDevice::drain(Event *de) 75{ 76 unsigned int count; 77 count = pioPort->drain(de); 78 if (count) 79 changeState(Draining); 80 else 81 changeState(Drained); 82 return count; 83} 84 85void 86BasicPioDevice::addressRanges(AddrRangeList &range_list) 87{ 88 assert(pioSize != 0); 89 range_list.clear(); 90 range_list.push_back(RangeSize(pioAddr, pioSize)); 91} 92 93 94DmaPort::DmaPort(DmaDevice *dev, System *s) 95 : Port(dev->name() + "-dmaport", dev), device(dev), sys(s), 96 pendingCount(0), actionInProgress(0), drainEvent(NULL), 97 backoffTime(0), inRetry(false), backoffEvent(this) 98{ } 99 100bool 101DmaPort::recvTiming(PacketPtr pkt) 102{ 103 104 105 if (pkt->result == Packet::Nacked) { 106 DPRINTF(DMA, "Received nacked Pkt %#x with State: %#x Addr: %#x\n", 107 pkt, pkt->senderState, pkt->getAddr()); 108 109 if (backoffTime < device->minBackoffDelay) 110 backoffTime = device->minBackoffDelay; 111 else if (backoffTime < device->maxBackoffDelay) 112 backoffTime <<= 1; 113
| 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/chunk_generator.hh" 33#include "base/trace.hh" 34#include "dev/io_device.hh" 35#include "sim/builder.hh" 36#include "sim/system.hh" 37 38 39PioPort::PioPort(PioDevice *dev, System *s, std::string pname) 40 : SimpleTimingPort(dev->name() + pname, dev), device(dev) 41{ } 42 43 44Tick 45PioPort::recvAtomic(PacketPtr pkt) 46{ 47 return pkt->isRead() ? device->read(pkt) : device->write(pkt); 48} 49 50void 51PioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 52{ 53 snoop.clear(); 54 device->addressRanges(resp); 55} 56 57 58PioDevice::~PioDevice() 59{ 60 if (pioPort) 61 delete pioPort; 62} 63 64void 65PioDevice::init() 66{ 67 if (!pioPort) 68 panic("Pio port not connected to anything!"); 69 pioPort->sendStatusChange(Port::RangeChange); 70} 71 72 73unsigned int 74PioDevice::drain(Event *de) 75{ 76 unsigned int count; 77 count = pioPort->drain(de); 78 if (count) 79 changeState(Draining); 80 else 81 changeState(Drained); 82 return count; 83} 84 85void 86BasicPioDevice::addressRanges(AddrRangeList &range_list) 87{ 88 assert(pioSize != 0); 89 range_list.clear(); 90 range_list.push_back(RangeSize(pioAddr, pioSize)); 91} 92 93 94DmaPort::DmaPort(DmaDevice *dev, System *s) 95 : Port(dev->name() + "-dmaport", dev), device(dev), sys(s), 96 pendingCount(0), actionInProgress(0), drainEvent(NULL), 97 backoffTime(0), inRetry(false), backoffEvent(this) 98{ } 99 100bool 101DmaPort::recvTiming(PacketPtr pkt) 102{ 103 104 105 if (pkt->result == Packet::Nacked) { 106 DPRINTF(DMA, "Received nacked Pkt %#x with State: %#x Addr: %#x\n", 107 pkt, pkt->senderState, pkt->getAddr()); 108 109 if (backoffTime < device->minBackoffDelay) 110 backoffTime = device->minBackoffDelay; 111 else if (backoffTime < device->maxBackoffDelay) 112 backoffTime <<= 1; 113
|
118 119 DPRINTF(DMA, "Backoff time set to %d ticks\n", backoffTime); 120 121 pkt->reinitNacked(); 122 queueDma(pkt, true); 123 } else if (pkt->senderState) { 124 DmaReqState *state; 125 backoffTime >>= 2; 126 127 DPRINTF(DMA, "Received response Pkt %#x with State: %#x Addr: %#x size: %#x\n", 128 pkt, pkt->senderState, pkt->getAddr(), pkt->req->getSize()); 129 state = dynamic_cast<DmaReqState*>(pkt->senderState); 130 pendingCount--; 131 132 assert(pendingCount >= 0); 133 assert(state); 134 135 state->numBytes += pkt->req->getSize(); 136 assert(state->totBytes >= state->numBytes); 137 if (state->totBytes == state->numBytes) { 138 state->completionEvent->process(); 139 delete state; 140 } 141 delete pkt->req; 142 delete pkt; 143 144 if (pendingCount == 0 && drainEvent) { 145 drainEvent->process(); 146 drainEvent = NULL; 147 } 148 } else { 149 panic("Got packet without sender state... huh?\n"); 150 } 151 152 return true; 153} 154 155DmaDevice::DmaDevice(Params *p) 156 : PioDevice(p), dmaPort(NULL), minBackoffDelay(p->min_backoff_delay), 157 maxBackoffDelay(p->max_backoff_delay) 158{ } 159 160 161unsigned int 162DmaDevice::drain(Event *de) 163{ 164 unsigned int count; 165 count = pioPort->drain(de) + dmaPort->drain(de); 166 if (count) 167 changeState(Draining); 168 else 169 changeState(Drained); 170 return count; 171} 172 173unsigned int 174DmaPort::drain(Event *de) 175{ 176 if (pendingCount == 0) 177 return 0; 178 drainEvent = de; 179 return 1; 180} 181 182 183void 184DmaPort::recvRetry() 185{ 186 assert(transmitList.size()); 187 PacketPtr pkt = transmitList.front(); 188 bool result = true; 189 do { 190 DPRINTF(DMA, "Retry on Packet %#x with senderState: %#x\n", 191 pkt, pkt->senderState); 192 result = sendTiming(pkt); 193 if (result) { 194 DPRINTF(DMA, "-- Done\n"); 195 transmitList.pop_front(); 196 inRetry = false; 197 } else { 198 inRetry = true; 199 DPRINTF(DMA, "-- Failed, queued\n"); 200 } 201 } while (!backoffTime && result && transmitList.size()); 202 203 if (transmitList.size() && backoffTime && !inRetry) { 204 DPRINTF(DMA, "Scheduling backoff for %d\n", curTick+backoffTime); 205 if (!backoffEvent.scheduled()) 206 backoffEvent.schedule(backoffTime+curTick); 207 } 208 DPRINTF(DMA, "TransmitList: %d, backoffTime: %d inRetry: %d es: %d\n", 209 transmitList.size(), backoffTime, inRetry, 210 backoffEvent.scheduled()); 211} 212 213 214void 215DmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 216 uint8_t *data) 217{ 218 assert(event); 219 220 assert(device->getState() == SimObject::Running); 221 222 DmaReqState *reqState = new DmaReqState(event, this, size); 223 224 for (ChunkGenerator gen(addr, size, peerBlockSize()); 225 !gen.done(); gen.next()) { 226 Request *req = new Request(gen.addr(), gen.size(), 0); 227 PacketPtr pkt = new Packet(req, cmd, Packet::Broadcast); 228 229 // Increment the data pointer on a write 230 if (data) 231 pkt->dataStatic(data + gen.complete()); 232 233 pkt->senderState = reqState; 234 235 assert(pendingCount >= 0); 236 pendingCount++; 237 queueDma(pkt); 238 } 239 240} 241 242void 243DmaPort::queueDma(PacketPtr pkt, bool front) 244{ 245 246 if (front) 247 transmitList.push_front(pkt); 248 else 249 transmitList.push_back(pkt); 250 sendDma(); 251} 252 253 254void 255DmaPort::sendDma() 256{ 257 // some kind of selction between access methods 258 // more work is going to have to be done to make 259 // switching actually work 260 assert(transmitList.size()); 261 PacketPtr pkt = transmitList.front(); 262 263 System::MemoryMode state = sys->getMemoryMode(); 264 if (state == System::Timing) { 265 if (backoffEvent.scheduled() || inRetry) { 266 DPRINTF(DMA, "Can't send immediately, waiting for retry or backoff timer\n"); 267 return; 268 } 269 270 DPRINTF(DMA, "Attempting to send Packet %#x with addr: %#x\n", 271 pkt, pkt->getAddr()); 272 273 bool result; 274 do { 275 result = sendTiming(pkt); 276 if (result) { 277 transmitList.pop_front(); 278 DPRINTF(DMA, "-- Done\n"); 279 } else { 280 inRetry = true; 281 DPRINTF(DMA, "-- Failed: queued\n"); 282 } 283 } while (result && !backoffTime && transmitList.size()); 284 285 if (transmitList.size() && backoffTime && !inRetry && 286 !backoffEvent.scheduled()) { 287 backoffEvent.schedule(backoffTime+curTick); 288 } 289 } else if (state == System::Atomic) { 290 transmitList.pop_front(); 291 292 Tick lat; 293 lat = sendAtomic(pkt); 294 assert(pkt->senderState); 295 DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState); 296 assert(state); 297 298 state->numBytes += pkt->req->getSize(); 299 if (state->totBytes == state->numBytes) { 300 state->completionEvent->schedule(curTick + lat); 301 delete state; 302 delete pkt->req; 303 } 304 pendingCount--; 305 assert(pendingCount >= 0); 306 delete pkt; 307 308 if (pendingCount == 0 && drainEvent) { 309 drainEvent->process(); 310 drainEvent = NULL; 311 } 312 313 } else 314 panic("Unknown memory command state."); 315} 316 317DmaDevice::~DmaDevice() 318{ 319 if (dmaPort) 320 delete dmaPort; 321} 322 323
| 115 116 DPRINTF(DMA, "Backoff time set to %d ticks\n", backoffTime); 117 118 pkt->reinitNacked(); 119 queueDma(pkt, true); 120 } else if (pkt->senderState) { 121 DmaReqState *state; 122 backoffTime >>= 2; 123 124 DPRINTF(DMA, "Received response Pkt %#x with State: %#x Addr: %#x size: %#x\n", 125 pkt, pkt->senderState, pkt->getAddr(), pkt->req->getSize()); 126 state = dynamic_cast<DmaReqState*>(pkt->senderState); 127 pendingCount--; 128 129 assert(pendingCount >= 0); 130 assert(state); 131 132 state->numBytes += pkt->req->getSize(); 133 assert(state->totBytes >= state->numBytes); 134 if (state->totBytes == state->numBytes) { 135 state->completionEvent->process(); 136 delete state; 137 } 138 delete pkt->req; 139 delete pkt; 140 141 if (pendingCount == 0 && drainEvent) { 142 drainEvent->process(); 143 drainEvent = NULL; 144 } 145 } else { 146 panic("Got packet without sender state... huh?\n"); 147 } 148 149 return true; 150} 151 152DmaDevice::DmaDevice(Params *p) 153 : PioDevice(p), dmaPort(NULL), minBackoffDelay(p->min_backoff_delay), 154 maxBackoffDelay(p->max_backoff_delay) 155{ } 156 157 158unsigned int 159DmaDevice::drain(Event *de) 160{ 161 unsigned int count; 162 count = pioPort->drain(de) + dmaPort->drain(de); 163 if (count) 164 changeState(Draining); 165 else 166 changeState(Drained); 167 return count; 168} 169 170unsigned int 171DmaPort::drain(Event *de) 172{ 173 if (pendingCount == 0) 174 return 0; 175 drainEvent = de; 176 return 1; 177} 178 179 180void 181DmaPort::recvRetry() 182{ 183 assert(transmitList.size()); 184 PacketPtr pkt = transmitList.front(); 185 bool result = true; 186 do { 187 DPRINTF(DMA, "Retry on Packet %#x with senderState: %#x\n", 188 pkt, pkt->senderState); 189 result = sendTiming(pkt); 190 if (result) { 191 DPRINTF(DMA, "-- Done\n"); 192 transmitList.pop_front(); 193 inRetry = false; 194 } else { 195 inRetry = true; 196 DPRINTF(DMA, "-- Failed, queued\n"); 197 } 198 } while (!backoffTime && result && transmitList.size()); 199 200 if (transmitList.size() && backoffTime && !inRetry) { 201 DPRINTF(DMA, "Scheduling backoff for %d\n", curTick+backoffTime); 202 if (!backoffEvent.scheduled()) 203 backoffEvent.schedule(backoffTime+curTick); 204 } 205 DPRINTF(DMA, "TransmitList: %d, backoffTime: %d inRetry: %d es: %d\n", 206 transmitList.size(), backoffTime, inRetry, 207 backoffEvent.scheduled()); 208} 209 210 211void 212DmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 213 uint8_t *data) 214{ 215 assert(event); 216 217 assert(device->getState() == SimObject::Running); 218 219 DmaReqState *reqState = new DmaReqState(event, this, size); 220 221 for (ChunkGenerator gen(addr, size, peerBlockSize()); 222 !gen.done(); gen.next()) { 223 Request *req = new Request(gen.addr(), gen.size(), 0); 224 PacketPtr pkt = new Packet(req, cmd, Packet::Broadcast); 225 226 // Increment the data pointer on a write 227 if (data) 228 pkt->dataStatic(data + gen.complete()); 229 230 pkt->senderState = reqState; 231 232 assert(pendingCount >= 0); 233 pendingCount++; 234 queueDma(pkt); 235 } 236 237} 238 239void 240DmaPort::queueDma(PacketPtr pkt, bool front) 241{ 242 243 if (front) 244 transmitList.push_front(pkt); 245 else 246 transmitList.push_back(pkt); 247 sendDma(); 248} 249 250 251void 252DmaPort::sendDma() 253{ 254 // some kind of selction between access methods 255 // more work is going to have to be done to make 256 // switching actually work 257 assert(transmitList.size()); 258 PacketPtr pkt = transmitList.front(); 259 260 System::MemoryMode state = sys->getMemoryMode(); 261 if (state == System::Timing) { 262 if (backoffEvent.scheduled() || inRetry) { 263 DPRINTF(DMA, "Can't send immediately, waiting for retry or backoff timer\n"); 264 return; 265 } 266 267 DPRINTF(DMA, "Attempting to send Packet %#x with addr: %#x\n", 268 pkt, pkt->getAddr()); 269 270 bool result; 271 do { 272 result = sendTiming(pkt); 273 if (result) { 274 transmitList.pop_front(); 275 DPRINTF(DMA, "-- Done\n"); 276 } else { 277 inRetry = true; 278 DPRINTF(DMA, "-- Failed: queued\n"); 279 } 280 } while (result && !backoffTime && transmitList.size()); 281 282 if (transmitList.size() && backoffTime && !inRetry && 283 !backoffEvent.scheduled()) { 284 backoffEvent.schedule(backoffTime+curTick); 285 } 286 } else if (state == System::Atomic) { 287 transmitList.pop_front(); 288 289 Tick lat; 290 lat = sendAtomic(pkt); 291 assert(pkt->senderState); 292 DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState); 293 assert(state); 294 295 state->numBytes += pkt->req->getSize(); 296 if (state->totBytes == state->numBytes) { 297 state->completionEvent->schedule(curTick + lat); 298 delete state; 299 delete pkt->req; 300 } 301 pendingCount--; 302 assert(pendingCount >= 0); 303 delete pkt; 304 305 if (pendingCount == 0 && drainEvent) { 306 drainEvent->process(); 307 drainEvent = NULL; 308 } 309 310 } else 311 panic("Unknown memory command state."); 312} 313 314DmaDevice::~DmaDevice() 315{ 316 if (dmaPort) 317 delete dmaPort; 318} 319 320
|