io_device.cc revision 2902
1545SN/A/* 22512SN/A * Copyright (c) 2006 The Regents of The University of Michigan 3545SN/A * All rights reserved. 4545SN/A * 5545SN/A * Redistribution and use in source and binary forms, with or without 6545SN/A * modification, are permitted provided that the following conditions are 7545SN/A * met: redistributions of source code must retain the above copyright 8545SN/A * notice, this list of conditions and the following disclaimer; 9545SN/A * redistributions in binary form must reproduce the above copyright 10545SN/A * notice, this list of conditions and the following disclaimer in the 11545SN/A * documentation and/or other materials provided with the distribution; 12545SN/A * neither the name of the copyright holders nor the names of its 13545SN/A * contributors may be used to endorse or promote products derived from 14545SN/A * this software without specific prior written permission. 15545SN/A * 16545SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17545SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18545SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19545SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20545SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21545SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22545SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23545SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24545SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25545SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26545SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 292665Ssaidi@eecs.umich.edu * Nathan Binkert 30545SN/A */ 31545SN/A 322657Ssaidi@eecs.umich.edu#include "base/trace.hh" 33545SN/A#include "dev/io_device.hh" 34679SN/A#include "sim/builder.hh" 352901Ssaidi@eecs.umich.edu#include "sim/system.hh" 36545SN/A 372489SN/A 382901Ssaidi@eecs.umich.eduPioPort::PioPort(PioDevice *dev, System *s, std::string pname) 392901Ssaidi@eecs.umich.edu : Port(dev->name() + pname), device(dev), sys(s), 402901Ssaidi@eecs.umich.edu outTiming(0), drainEvent(NULL) 412489SN/A{ } 422489SN/A 432489SN/A 442489SN/ATick 452630SN/APioPort::recvAtomic(Packet *pkt) 462489SN/A{ 472489SN/A return device->recvAtomic(pkt); 482489SN/A} 492489SN/A 502489SN/Avoid 512630SN/APioPort::recvFunctional(Packet *pkt) 522489SN/A{ 532489SN/A device->recvAtomic(pkt); 542489SN/A} 552489SN/A 562489SN/Avoid 572521SN/APioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 582489SN/A{ 592521SN/A snoop.clear(); 602521SN/A device->addressRanges(resp); 612489SN/A} 622489SN/A 632489SN/A 642657Ssaidi@eecs.umich.eduvoid 652489SN/APioPort::recvRetry() 662489SN/A{ 672784Ssaidi@eecs.umich.edu bool result = true; 682784Ssaidi@eecs.umich.edu while (result && transmitList.size()) { 692784Ssaidi@eecs.umich.edu result = Port::sendTiming(transmitList.front()); 702784Ssaidi@eecs.umich.edu if (result) 712784Ssaidi@eecs.umich.edu transmitList.pop_front(); 722657Ssaidi@eecs.umich.edu } 732901Ssaidi@eecs.umich.edu if (transmitList.size() == 0 && drainEvent) { 742901Ssaidi@eecs.umich.edu drainEvent->process(); 752901Ssaidi@eecs.umich.edu drainEvent = NULL; 762901Ssaidi@eecs.umich.edu } 772489SN/A} 782489SN/A 792384SN/Avoid 802384SN/APioPort::SendEvent::process() 812384SN/A{ 822901Ssaidi@eecs.umich.edu port->outTiming--; 832901Ssaidi@eecs.umich.edu assert(port->outTiming >= 0); 842641Sstever@eecs.umich.edu if (port->Port::sendTiming(packet)) 852901Ssaidi@eecs.umich.edu if (port->transmitList.size() == 0 && port->drainEvent) { 862901Ssaidi@eecs.umich.edu port->drainEvent->process(); 872901Ssaidi@eecs.umich.edu port->drainEvent = NULL; 882901Ssaidi@eecs.umich.edu } 892901Ssaidi@eecs.umich.edu return; 902384SN/A 912630SN/A port->transmitList.push_back(packet); 922384SN/A} 932384SN/A 942846Ssaidi@eecs.umich.eduvoid 952846Ssaidi@eecs.umich.eduPioPort::resendNacked(Packet *pkt) { 962846Ssaidi@eecs.umich.edu pkt->reinitNacked(); 972846Ssaidi@eecs.umich.edu if (transmitList.size()) { 982846Ssaidi@eecs.umich.edu transmitList.push_front(pkt); 992846Ssaidi@eecs.umich.edu } else { 1002846Ssaidi@eecs.umich.edu if (!Port::sendTiming(pkt)) 1012846Ssaidi@eecs.umich.edu transmitList.push_front(pkt); 1022846Ssaidi@eecs.umich.edu } 1032846Ssaidi@eecs.umich.edu}; 1042384SN/A 1052657Ssaidi@eecs.umich.edu 1062384SN/Abool 1072630SN/APioPort::recvTiming(Packet *pkt) 1082384SN/A{ 1092784Ssaidi@eecs.umich.edu if (pkt->result == Packet::Nacked) { 1102846Ssaidi@eecs.umich.edu resendNacked(pkt); 1112784Ssaidi@eecs.umich.edu } else { 1122784Ssaidi@eecs.umich.edu Tick latency = device->recvAtomic(pkt); 1132784Ssaidi@eecs.umich.edu // turn packet around to go back to requester 1142784Ssaidi@eecs.umich.edu pkt->makeTimingResponse(); 1152784Ssaidi@eecs.umich.edu sendTiming(pkt, latency); 1162784Ssaidi@eecs.umich.edu } 1172641Sstever@eecs.umich.edu return true; 1182384SN/A} 119545SN/A 1202901Ssaidi@eecs.umich.eduunsigned int 1212901Ssaidi@eecs.umich.eduPioPort::drain(Event *de) 1222901Ssaidi@eecs.umich.edu{ 1232901Ssaidi@eecs.umich.edu if (outTiming == 0 && transmitList.size() == 0) 1242901Ssaidi@eecs.umich.edu return 0; 1252901Ssaidi@eecs.umich.edu drainEvent = de; 1262901Ssaidi@eecs.umich.edu return 1; 1272901Ssaidi@eecs.umich.edu} 1282901Ssaidi@eecs.umich.edu 129545SN/APioDevice::~PioDevice() 130545SN/A{ 1312384SN/A if (pioPort) 1322489SN/A delete pioPort; 133545SN/A} 134545SN/A 1352542SN/Avoid 1362541SN/APioDevice::init() 1372541SN/A{ 1382541SN/A if (!pioPort) 1392541SN/A panic("Pio port not connected to anything!"); 1402541SN/A pioPort->sendStatusChange(Port::RangeChange); 1412541SN/A} 1422541SN/A 1432901Ssaidi@eecs.umich.edu 1442901Ssaidi@eecs.umich.eduunsigned int 1452901Ssaidi@eecs.umich.eduPioDevice::drain(Event *de) 1462901Ssaidi@eecs.umich.edu{ 1472901Ssaidi@eecs.umich.edu unsigned int count; 1482901Ssaidi@eecs.umich.edu count = pioPort->drain(de); 1492901Ssaidi@eecs.umich.edu if (count) 1502901Ssaidi@eecs.umich.edu changeState(Draining); 1512901Ssaidi@eecs.umich.edu else 1522901Ssaidi@eecs.umich.edu changeState(Drained); 1532901Ssaidi@eecs.umich.edu return count; 1542901Ssaidi@eecs.umich.edu} 1552901Ssaidi@eecs.umich.edu 1562539SN/Avoid 1572539SN/ABasicPioDevice::addressRanges(AddrRangeList &range_list) 1582539SN/A{ 1592539SN/A assert(pioSize != 0); 1602539SN/A range_list.clear(); 1612539SN/A range_list.push_back(RangeSize(pioAddr, pioSize)); 1622539SN/A} 1632539SN/A 1642489SN/A 1652901Ssaidi@eecs.umich.eduDmaPort::DmaPort(DmaDevice *dev, System *s) 1662901Ssaidi@eecs.umich.edu : Port(dev->name() + "-dmaport"), device(dev), sys(s), pendingCount(0), 1672901Ssaidi@eecs.umich.edu actionInProgress(0), drainEvent(NULL) 1682489SN/A{ } 1692489SN/A 1702489SN/Abool 1712630SN/ADmaPort::recvTiming(Packet *pkt) 1722384SN/A{ 1732685Ssaidi@eecs.umich.edu 1742685Ssaidi@eecs.umich.edu 1752685Ssaidi@eecs.umich.edu if (pkt->result == Packet::Nacked) { 1762685Ssaidi@eecs.umich.edu DPRINTF(DMA, "Received nacked Pkt %#x with State: %#x Addr: %#x\n", 1772685Ssaidi@eecs.umich.edu pkt, pkt->senderState, pkt->getAddr()); 1782685Ssaidi@eecs.umich.edu pkt->reinitNacked(); 1792685Ssaidi@eecs.umich.edu sendDma(pkt, true); 1802685Ssaidi@eecs.umich.edu } else if (pkt->senderState) { 1812565SN/A DmaReqState *state; 1822685Ssaidi@eecs.umich.edu DPRINTF(DMA, "Received response Pkt %#x with State: %#x Addr: %#x\n", 1832685Ssaidi@eecs.umich.edu pkt, pkt->senderState, pkt->getAddr()); 1842641Sstever@eecs.umich.edu state = dynamic_cast<DmaReqState*>(pkt->senderState); 1852685Ssaidi@eecs.umich.edu pendingCount--; 1862685Ssaidi@eecs.umich.edu 1872685Ssaidi@eecs.umich.edu assert(pendingCount >= 0); 1882657Ssaidi@eecs.umich.edu assert(state); 1892685Ssaidi@eecs.umich.edu 1902685Ssaidi@eecs.umich.edu state->numBytes += pkt->req->getSize(); 1912685Ssaidi@eecs.umich.edu if (state->totBytes == state->numBytes) { 1922685Ssaidi@eecs.umich.edu state->completionEvent->process(); 1932685Ssaidi@eecs.umich.edu delete state; 1942685Ssaidi@eecs.umich.edu } 1952630SN/A delete pkt->req; 1962630SN/A delete pkt; 1972901Ssaidi@eecs.umich.edu 1982901Ssaidi@eecs.umich.edu if (pendingCount == 0 && drainEvent) { 1992901Ssaidi@eecs.umich.edu drainEvent->process(); 2002901Ssaidi@eecs.umich.edu drainEvent = NULL; 2012901Ssaidi@eecs.umich.edu } 2022569SN/A } else { 2032685Ssaidi@eecs.umich.edu panic("Got packet without sender state... huh?\n"); 2042565SN/A } 2052569SN/A 2062657Ssaidi@eecs.umich.edu return true; 2072384SN/A} 208679SN/A 2092521SN/ADmaDevice::DmaDevice(Params *p) 2102565SN/A : PioDevice(p), dmaPort(NULL) 2112565SN/A{ } 2122384SN/A 2132901Ssaidi@eecs.umich.edu 2142901Ssaidi@eecs.umich.eduunsigned int 2152901Ssaidi@eecs.umich.eduDmaDevice::drain(Event *de) 2162901Ssaidi@eecs.umich.edu{ 2172901Ssaidi@eecs.umich.edu unsigned int count; 2182901Ssaidi@eecs.umich.edu count = pioPort->drain(de) + dmaPort->drain(de); 2192901Ssaidi@eecs.umich.edu if (count) 2202901Ssaidi@eecs.umich.edu changeState(Draining); 2212901Ssaidi@eecs.umich.edu else 2222901Ssaidi@eecs.umich.edu changeState(Drained); 2232901Ssaidi@eecs.umich.edu return count; 2242901Ssaidi@eecs.umich.edu} 2252901Ssaidi@eecs.umich.edu 2262901Ssaidi@eecs.umich.eduunsigned int 2272901Ssaidi@eecs.umich.eduDmaPort::drain(Event *de) 2282901Ssaidi@eecs.umich.edu{ 2292901Ssaidi@eecs.umich.edu if (pendingCount == 0) 2302901Ssaidi@eecs.umich.edu return 0; 2312901Ssaidi@eecs.umich.edu drainEvent = de; 2322901Ssaidi@eecs.umich.edu return 1; 2332901Ssaidi@eecs.umich.edu} 2342901Ssaidi@eecs.umich.edu 2352901Ssaidi@eecs.umich.edu 2362384SN/Avoid 2372489SN/ADmaPort::recvRetry() 2382489SN/A{ 2392489SN/A Packet* pkt = transmitList.front(); 2402659Ssaidi@eecs.umich.edu bool result = true; 2412659Ssaidi@eecs.umich.edu while (result && transmitList.size()) { 2422659Ssaidi@eecs.umich.edu DPRINTF(DMA, "Retry on Packet %#x with senderState: %#x\n", 2432659Ssaidi@eecs.umich.edu pkt, pkt->senderState); 2442659Ssaidi@eecs.umich.edu result = sendTiming(pkt); 2452659Ssaidi@eecs.umich.edu if (result) { 2462659Ssaidi@eecs.umich.edu DPRINTF(DMA, "-- Done\n"); 2472659Ssaidi@eecs.umich.edu transmitList.pop_front(); 2482659Ssaidi@eecs.umich.edu } else { 2492659Ssaidi@eecs.umich.edu DPRINTF(DMA, "-- Failed, queued\n"); 2502659Ssaidi@eecs.umich.edu } 2512657Ssaidi@eecs.umich.edu } 2522489SN/A} 2532641Sstever@eecs.umich.edu 2542641Sstever@eecs.umich.edu 2552489SN/Avoid 2562641Sstever@eecs.umich.eduDmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 2572641Sstever@eecs.umich.edu uint8_t *data) 2582384SN/A{ 2592384SN/A assert(event); 2602384SN/A 2612901Ssaidi@eecs.umich.edu assert(device->getState() == SimObject::Running); 2622901Ssaidi@eecs.umich.edu 2632685Ssaidi@eecs.umich.edu DmaReqState *reqState = new DmaReqState(event, this, size); 2642384SN/A 2652406SN/A for (ChunkGenerator gen(addr, size, peerBlockSize()); 2662406SN/A !gen.done(); gen.next()) { 2672663Sstever@eecs.umich.edu Request *req = new Request(gen.addr(), gen.size(), 0); 2682641Sstever@eecs.umich.edu Packet *pkt = new Packet(req, cmd, Packet::Broadcast); 2692641Sstever@eecs.umich.edu 2702384SN/A // Increment the data pointer on a write 2712566SN/A if (data) 2722685Ssaidi@eecs.umich.edu pkt->dataStatic(data + gen.complete()); 2732641Sstever@eecs.umich.edu 2742685Ssaidi@eecs.umich.edu pkt->senderState = reqState; 2752641Sstever@eecs.umich.edu 2762565SN/A assert(pendingCount >= 0); 2772565SN/A pendingCount++; 2782566SN/A sendDma(pkt); 2792384SN/A } 2802901Ssaidi@eecs.umich.edu 2812384SN/A} 2822384SN/A 2832384SN/A 2842384SN/Avoid 2852685Ssaidi@eecs.umich.eduDmaPort::sendDma(Packet *pkt, bool front) 2862384SN/A{ 2872901Ssaidi@eecs.umich.edu // some kind of selction between access methods 2882901Ssaidi@eecs.umich.edu // more work is going to have to be done to make 2892901Ssaidi@eecs.umich.edu // switching actually work 2902902Ssaidi@eecs.umich.edu 2912901Ssaidi@eecs.umich.edu System::MemoryMode state = sys->getMemoryMode(); 2922901Ssaidi@eecs.umich.edu if (state == System::Timing) { 2932901Ssaidi@eecs.umich.edu DPRINTF(DMA, "Attempting to send Packet %#x with addr: %#x\n", 2942901Ssaidi@eecs.umich.edu pkt, pkt->getAddr()); 2952901Ssaidi@eecs.umich.edu if (transmitList.size() || !sendTiming(pkt)) { 2962901Ssaidi@eecs.umich.edu if (front) 2972901Ssaidi@eecs.umich.edu transmitList.push_front(pkt); 2982901Ssaidi@eecs.umich.edu else 2992901Ssaidi@eecs.umich.edu transmitList.push_back(pkt); 3002901Ssaidi@eecs.umich.edu DPRINTF(DMA, "-- Failed: queued\n"); 3012901Ssaidi@eecs.umich.edu } else { 3022901Ssaidi@eecs.umich.edu DPRINTF(DMA, "-- Done\n"); 3032901Ssaidi@eecs.umich.edu } 3042901Ssaidi@eecs.umich.edu } else if (state == System::Atomic) { 3052902Ssaidi@eecs.umich.edu Tick lat; 3062902Ssaidi@eecs.umich.edu lat = sendAtomic(pkt); 3072901Ssaidi@eecs.umich.edu assert(pkt->senderState); 3082901Ssaidi@eecs.umich.edu DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState); 3092901Ssaidi@eecs.umich.edu assert(state); 3102384SN/A 3112901Ssaidi@eecs.umich.edu state->numBytes += pkt->req->getSize(); 3122901Ssaidi@eecs.umich.edu if (state->totBytes == state->numBytes) { 3132902Ssaidi@eecs.umich.edu state->completionEvent->schedule(curTick + lat); 3142901Ssaidi@eecs.umich.edu delete state; 3152901Ssaidi@eecs.umich.edu delete pkt->req; 3162901Ssaidi@eecs.umich.edu } 3172901Ssaidi@eecs.umich.edu pendingCount--; 3182901Ssaidi@eecs.umich.edu assert(pendingCount >= 0); 3192901Ssaidi@eecs.umich.edu delete pkt; 3202566SN/A 3212901Ssaidi@eecs.umich.edu if (pendingCount == 0 && drainEvent) { 3222901Ssaidi@eecs.umich.edu drainEvent->process(); 3232901Ssaidi@eecs.umich.edu drainEvent = NULL; 3242901Ssaidi@eecs.umich.edu } 3252901Ssaidi@eecs.umich.edu 3262384SN/A } else 3272384SN/A panic("Unknown memory command state."); 3282384SN/A} 329545SN/A 330545SN/ADmaDevice::~DmaDevice() 331545SN/A{ 3322489SN/A if (dmaPort) 3332489SN/A delete dmaPort; 334545SN/A} 335545SN/A 336679SN/A 337