io_device.cc revision 2665
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" 35545SN/A 362489SN/A 372497SN/APioPort::PioPort(PioDevice *dev, Platform *p) 382640Sstever@eecs.umich.edu : Port(dev->name() + "-pioport"), device(dev), platform(p) 392489SN/A{ } 402489SN/A 412489SN/A 422489SN/ATick 432630SN/APioPort::recvAtomic(Packet *pkt) 442489SN/A{ 452489SN/A return device->recvAtomic(pkt); 462489SN/A} 472489SN/A 482489SN/Avoid 492630SN/APioPort::recvFunctional(Packet *pkt) 502489SN/A{ 512489SN/A device->recvAtomic(pkt); 522489SN/A} 532489SN/A 542489SN/Avoid 552521SN/APioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 562489SN/A{ 572521SN/A snoop.clear(); 582521SN/A device->addressRanges(resp); 592489SN/A} 602489SN/A 612489SN/A 622657Ssaidi@eecs.umich.eduvoid 632489SN/APioPort::recvRetry() 642489SN/A{ 652489SN/A Packet* pkt = transmitList.front(); 662657Ssaidi@eecs.umich.edu if (Port::sendTiming(pkt)) { 672657Ssaidi@eecs.umich.edu transmitList.pop_front(); 682657Ssaidi@eecs.umich.edu } 692489SN/A} 702489SN/A 712489SN/A 722384SN/Avoid 732384SN/APioPort::SendEvent::process() 742384SN/A{ 752641Sstever@eecs.umich.edu if (port->Port::sendTiming(packet)) 762384SN/A return; 772384SN/A 782630SN/A port->transmitList.push_back(packet); 792384SN/A} 802384SN/A 812384SN/A 822657Ssaidi@eecs.umich.edu 832384SN/Abool 842630SN/APioPort::recvTiming(Packet *pkt) 852384SN/A{ 862662Sstever@eecs.umich.edu Tick latency = device->recvAtomic(pkt); 872639Sstever@eecs.umich.edu // turn packet around to go back to requester 882641Sstever@eecs.umich.edu pkt->makeTimingResponse(); 892662Sstever@eecs.umich.edu sendTiming(pkt, latency); 902641Sstever@eecs.umich.edu return true; 912384SN/A} 92545SN/A 93545SN/APioDevice::~PioDevice() 94545SN/A{ 952384SN/A if (pioPort) 962489SN/A delete pioPort; 97545SN/A} 98545SN/A 992542SN/Avoid 1002541SN/APioDevice::init() 1012541SN/A{ 1022541SN/A if (!pioPort) 1032541SN/A panic("Pio port not connected to anything!"); 1042541SN/A pioPort->sendStatusChange(Port::RangeChange); 1052541SN/A} 1062541SN/A 1072539SN/Avoid 1082539SN/ABasicPioDevice::addressRanges(AddrRangeList &range_list) 1092539SN/A{ 1102539SN/A assert(pioSize != 0); 1112539SN/A range_list.clear(); 1122539SN/A range_list.push_back(RangeSize(pioAddr, pioSize)); 1132539SN/A} 1142539SN/A 1152489SN/A 1162565SN/ADmaPort::DmaPort(DmaDevice *dev, Platform *p) 1172640Sstever@eecs.umich.edu : Port(dev->name() + "-dmaport"), device(dev), platform(p), pendingCount(0) 1182489SN/A{ } 1192489SN/A 1202489SN/Abool 1212630SN/ADmaPort::recvTiming(Packet *pkt) 1222384SN/A{ 1232630SN/A if (pkt->senderState) { 1242565SN/A DmaReqState *state; 1252657Ssaidi@eecs.umich.edu DPRINTF(DMA, "Received response Packet %#x with senderState: %#x\n", 1262657Ssaidi@eecs.umich.edu pkt, pkt->senderState); 1272641Sstever@eecs.umich.edu state = dynamic_cast<DmaReqState*>(pkt->senderState); 1282657Ssaidi@eecs.umich.edu assert(state); 1292657Ssaidi@eecs.umich.edu state->completionEvent->process(); 1302630SN/A delete pkt->req; 1312630SN/A delete pkt; 1322569SN/A } else { 1332657Ssaidi@eecs.umich.edu DPRINTF(DMA, "Received response Packet %#x with no senderState\n", pkt); 1342630SN/A delete pkt->req; 1352630SN/A delete pkt; 1362565SN/A } 1372569SN/A 1382657Ssaidi@eecs.umich.edu return true; 1392384SN/A} 140679SN/A 1412521SN/ADmaDevice::DmaDevice(Params *p) 1422565SN/A : PioDevice(p), dmaPort(NULL) 1432565SN/A{ } 1442384SN/A 1452384SN/Avoid 1462489SN/ADmaPort::recvRetry() 1472489SN/A{ 1482489SN/A Packet* pkt = transmitList.front(); 1492659Ssaidi@eecs.umich.edu bool result = true; 1502659Ssaidi@eecs.umich.edu while (result && transmitList.size()) { 1512659Ssaidi@eecs.umich.edu DPRINTF(DMA, "Retry on Packet %#x with senderState: %#x\n", 1522659Ssaidi@eecs.umich.edu pkt, pkt->senderState); 1532659Ssaidi@eecs.umich.edu result = sendTiming(pkt); 1542659Ssaidi@eecs.umich.edu if (result) { 1552659Ssaidi@eecs.umich.edu DPRINTF(DMA, "-- Done\n"); 1562659Ssaidi@eecs.umich.edu transmitList.pop_front(); 1572659Ssaidi@eecs.umich.edu pendingCount--; 1582659Ssaidi@eecs.umich.edu assert(pendingCount >= 0); 1592659Ssaidi@eecs.umich.edu } else { 1602659Ssaidi@eecs.umich.edu DPRINTF(DMA, "-- Failed, queued\n"); 1612659Ssaidi@eecs.umich.edu } 1622657Ssaidi@eecs.umich.edu } 1632489SN/A} 1642641Sstever@eecs.umich.edu 1652641Sstever@eecs.umich.edu 1662489SN/Avoid 1672641Sstever@eecs.umich.eduDmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 1682641Sstever@eecs.umich.edu uint8_t *data) 1692384SN/A{ 1702384SN/A assert(event); 1712384SN/A 1722384SN/A int prevSize = 0; 1732384SN/A 1742406SN/A for (ChunkGenerator gen(addr, size, peerBlockSize()); 1752406SN/A !gen.done(); gen.next()) { 1762663Sstever@eecs.umich.edu Request *req = new Request(gen.addr(), gen.size(), 0); 1772641Sstever@eecs.umich.edu Packet *pkt = new Packet(req, cmd, Packet::Broadcast); 1782641Sstever@eecs.umich.edu 1792384SN/A // Increment the data pointer on a write 1802566SN/A if (data) 1812663Sstever@eecs.umich.edu pkt->dataStatic(data + prevSize); 1822641Sstever@eecs.umich.edu 1832641Sstever@eecs.umich.edu prevSize += gen.size(); 1842641Sstever@eecs.umich.edu 1852565SN/A // Set the last bit of the dma as the final packet for this dma 1862565SN/A // and set it's completion event. 1872565SN/A if (prevSize == size) { 1882641Sstever@eecs.umich.edu pkt->senderState = new DmaReqState(event, true); 1892565SN/A } 1902565SN/A assert(pendingCount >= 0); 1912565SN/A pendingCount++; 1922566SN/A sendDma(pkt); 1932384SN/A } 1942384SN/A} 1952384SN/A 1962384SN/A 1972384SN/Avoid 1982566SN/ADmaPort::sendDma(Packet *pkt) 1992384SN/A{ 2002384SN/A // some kind of selction between access methods 2012384SN/A // more work is going to have to be done to make 2022384SN/A // switching actually work 2032489SN/A /* MemState state = device->platform->system->memState; 2042384SN/A 2052657Ssaidi@eecs.umich.edu if (state == Timing) { */ 2062657Ssaidi@eecs.umich.edu DPRINTF(DMA, "Attempting to send Packet %#x with senderState: %#x\n", 2072657Ssaidi@eecs.umich.edu pkt, pkt->senderState); 2082659Ssaidi@eecs.umich.edu if (transmitList.size() || !sendTiming(pkt)) { 2092657Ssaidi@eecs.umich.edu transmitList.push_back(pkt); 2102657Ssaidi@eecs.umich.edu DPRINTF(DMA, "-- Failed: queued\n"); 2112657Ssaidi@eecs.umich.edu } else { 2122657Ssaidi@eecs.umich.edu DPRINTF(DMA, "-- Done\n"); 2132657Ssaidi@eecs.umich.edu pendingCount--; 2142657Ssaidi@eecs.umich.edu assert(pendingCount >= 0); 2152657Ssaidi@eecs.umich.edu } 2162657Ssaidi@eecs.umich.edu /* } else if (state == Atomic) { 2172630SN/A sendAtomic(pkt); 2182566SN/A if (pkt->senderState) { 2192641Sstever@eecs.umich.edu DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState); 2202657Ssaidi@eecs.umich.edu assert(state); 2212566SN/A state->completionEvent->schedule(curTick + (pkt->time - pkt->req->getTime()) +1); 2222565SN/A } 2232566SN/A pendingCount--; 2242566SN/A assert(pendingCount >= 0); 2252566SN/A delete pkt->req; 2262566SN/A delete pkt; 2272566SN/A 2282657Ssaidi@eecs.umich.edu } else if (state == Functional) { 2292384SN/A sendFunctional(pkt); 2302384SN/A // Is this correct??? 2312630SN/A completionEvent->schedule(pkt->req->responseTime - pkt->req->requestTime); 2322384SN/A completionEvent == NULL; 2332384SN/A } else 2342384SN/A panic("Unknown memory command state."); 2352489SN/A */ 2362384SN/A} 237545SN/A 238545SN/ADmaDevice::~DmaDevice() 239545SN/A{ 2402489SN/A if (dmaPort) 2412489SN/A delete dmaPort; 242545SN/A} 243545SN/A 244679SN/A 245