io_device.hh revision 4762
1545SN/A/* 21762SN/A * Copyright (c) 2004-2005 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 321310SN/A#ifndef __DEV_IO_DEVICE_HH__ 331310SN/A#define __DEV_IO_DEVICE_HH__ 34545SN/A 352542SN/A#include "mem/mem_object.hh" 363348Sbinkertn@umich.edu#include "mem/packet.hh" 373348Sbinkertn@umich.edu#include "mem/tport.hh" 384762Snate@binkert.org#include "params/BasicPioDevice.hh" 394762Snate@binkert.org#include "params/DmaDevice.hh" 404762Snate@binkert.org#include "params/PioDevice.hh" 412489SN/A#include "sim/sim_object.hh" 42545SN/A 433090Sstever@eecs.umich.educlass Event; 441310SN/Aclass Platform; 452384SN/Aclass PioDevice; 462489SN/Aclass DmaDevice; 472522SN/Aclass System; 48545SN/A 492489SN/A/** 502489SN/A * The PioPort class is a programmed i/o port that all devices that are 512489SN/A * sensitive to an address range use. The port takes all the memory 522489SN/A * access types and roles them into one read() and write() call that the device 532489SN/A * must respond to. The device must also provide the addressRanges() function 543090Sstever@eecs.umich.edu * with which it returns the address ranges it is interested in. 553090Sstever@eecs.umich.edu */ 562914Ssaidi@eecs.umich.educlass PioPort : public SimpleTimingPort 57545SN/A{ 58545SN/A protected: 592489SN/A /** The device that this port serves. */ 602384SN/A PioDevice *device; 612384SN/A 623349Sbinkertn@umich.edu virtual Tick recvAtomic(PacketPtr pkt); 632384SN/A 643090Sstever@eecs.umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 654475Sstever@eecs.umich.edu bool &snoop); 662384SN/A 672384SN/A public: 683091Sstever@eecs.umich.edu 692901Ssaidi@eecs.umich.edu PioPort(PioDevice *dev, System *s, std::string pname = "-pioport"); 702384SN/A}; 712384SN/A 722565SN/A 732384SN/Aclass DmaPort : public Port 742384SN/A{ 752384SN/A protected: 762784Ssaidi@eecs.umich.edu struct DmaReqState : public Packet::SenderState 772784Ssaidi@eecs.umich.edu { 782784Ssaidi@eecs.umich.edu /** Event to call on the device when this transaction (all packets) 792784Ssaidi@eecs.umich.edu * complete. */ 802784Ssaidi@eecs.umich.edu Event *completionEvent; 812784Ssaidi@eecs.umich.edu 822784Ssaidi@eecs.umich.edu /** Where we came from for some sanity checking. */ 832784Ssaidi@eecs.umich.edu Port *outPort; 842784Ssaidi@eecs.umich.edu 852784Ssaidi@eecs.umich.edu /** Total number of bytes that this transaction involves. */ 862784Ssaidi@eecs.umich.edu Addr totBytes; 872784Ssaidi@eecs.umich.edu 882784Ssaidi@eecs.umich.edu /** Number of bytes that have been acked for this transaction. */ 892784Ssaidi@eecs.umich.edu Addr numBytes; 902784Ssaidi@eecs.umich.edu 912784Ssaidi@eecs.umich.edu DmaReqState(Event *ce, Port *p, Addr tb) 922784Ssaidi@eecs.umich.edu : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0) 932784Ssaidi@eecs.umich.edu {} 942784Ssaidi@eecs.umich.edu }; 952784Ssaidi@eecs.umich.edu 962565SN/A DmaDevice *device; 973349Sbinkertn@umich.edu std::list<PacketPtr> transmitList; 982384SN/A 992901Ssaidi@eecs.umich.edu /** The system that device/port are in. This is used to select which mode 1002565SN/A * we are currently operating in. */ 1012901Ssaidi@eecs.umich.edu System *sys; 1022565SN/A 1032565SN/A /** Number of outstanding packets the dma port has. */ 1042565SN/A int pendingCount; 1052384SN/A 1062901Ssaidi@eecs.umich.edu /** If a dmaAction is in progress. */ 1072901Ssaidi@eecs.umich.edu int actionInProgress; 1082901Ssaidi@eecs.umich.edu 1092901Ssaidi@eecs.umich.edu /** If we need to drain, keep the drain event around until we're done 1102901Ssaidi@eecs.umich.edu * here.*/ 1112901Ssaidi@eecs.umich.edu Event *drainEvent; 1122901Ssaidi@eecs.umich.edu 1134435Ssaidi@eecs.umich.edu /** time to wait between sending another packet, increases as NACKs are 1144435Ssaidi@eecs.umich.edu * recived, decreases as responses are recived. */ 1154435Ssaidi@eecs.umich.edu Tick backoffTime; 1164435Ssaidi@eecs.umich.edu 1174435Ssaidi@eecs.umich.edu /** If the port is currently waiting for a retry before it can send whatever 1184435Ssaidi@eecs.umich.edu * it is that it's sending. */ 1194435Ssaidi@eecs.umich.edu bool inRetry; 1204435Ssaidi@eecs.umich.edu 1213349Sbinkertn@umich.edu virtual bool recvTiming(PacketPtr pkt); 1223349Sbinkertn@umich.edu virtual Tick recvAtomic(PacketPtr pkt) 1233918Ssaidi@eecs.umich.edu { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN } 1243349Sbinkertn@umich.edu virtual void recvFunctional(PacketPtr pkt) 1252384SN/A { panic("dma port shouldn't be used for pio access."); } 1262384SN/A 1272384SN/A virtual void recvStatusChange(Status status) 1282384SN/A { ; } 1292384SN/A 1302657Ssaidi@eecs.umich.edu virtual void recvRetry() ; 1312384SN/A 1323090Sstever@eecs.umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 1334475Sstever@eecs.umich.edu bool &snoop) 1344475Sstever@eecs.umich.edu { resp.clear(); snoop = false; } 1352384SN/A 1364435Ssaidi@eecs.umich.edu void queueDma(PacketPtr pkt, bool front = false); 1374435Ssaidi@eecs.umich.edu void sendDma(); 1384435Ssaidi@eecs.umich.edu 1394435Ssaidi@eecs.umich.edu /** event to give us a kick every time we backoff time is reached. */ 1404435Ssaidi@eecs.umich.edu EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent; 1412489SN/A 1422384SN/A public: 1432901Ssaidi@eecs.umich.edu DmaPort(DmaDevice *dev, System *s); 1442565SN/A 1452641Sstever@eecs.umich.edu void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 1462641Sstever@eecs.umich.edu uint8_t *data = NULL); 1472565SN/A 1482565SN/A bool dmaPending() { return pendingCount > 0; } 1492384SN/A 1504263Ssaidi@eecs.umich.edu int cacheBlockSize() { return peerBlockSize(); } 1512901Ssaidi@eecs.umich.edu unsigned int drain(Event *de); 1522384SN/A}; 1532384SN/A 1542489SN/A/** 1552489SN/A * This device is the base class which all devices senstive to an address range 1562489SN/A * inherit from. There are three pure virtual functions which all devices must 1572489SN/A * implement addressRanges(), read(), and write(). The magic do choose which 1582489SN/A * mode we are in, etc is handled by the PioPort so the device doesn't have to 1592489SN/A * bother. 1602489SN/A */ 1612542SN/Aclass PioDevice : public MemObject 1622384SN/A{ 1632384SN/A protected: 1642384SN/A 1652489SN/A /** The platform we are in. This is used to decide what type of memory 1662489SN/A * transaction we should perform. */ 1671310SN/A Platform *platform; 1682384SN/A 1692901Ssaidi@eecs.umich.edu System *sys; 1702901Ssaidi@eecs.umich.edu 1712489SN/A /** The pioPort that handles the requests for us and provides us requests 1722489SN/A * that it sees. */ 1732384SN/A PioPort *pioPort; 1742384SN/A 1752521SN/A virtual void addressRanges(AddrRangeList &range_list) = 0; 1762384SN/A 1773090Sstever@eecs.umich.edu /** Pure virtual function that the device must implement. Called 1783090Sstever@eecs.umich.edu * when a read command is recieved by the port. 1792523SN/A * @param pkt Packet describing this request 1802523SN/A * @return number of ticks it took to complete 1812523SN/A */ 1823349Sbinkertn@umich.edu virtual Tick read(PacketPtr pkt) = 0; 1832384SN/A 1842489SN/A /** Pure virtual function that the device must implement. Called when a 1852523SN/A * write command is recieved by the port. 1862523SN/A * @param pkt Packet describing this request 1872523SN/A * @return number of ticks it took to complete 1882523SN/A */ 1893349Sbinkertn@umich.edu virtual Tick write(PacketPtr pkt) = 0; 190545SN/A 191545SN/A public: 1924762Snate@binkert.org typedef PioDeviceParams Params; 1934762Snate@binkert.org PioDevice(const Params *p); 1944762Snate@binkert.org virtual ~PioDevice(); 1954762Snate@binkert.org 1964762Snate@binkert.org const Params * 1974762Snate@binkert.org params() const 1982512SN/A { 1994762Snate@binkert.org return dynamic_cast<const Params *>(_params); 2004762Snate@binkert.org } 2012384SN/A 2022541SN/A virtual void init(); 2032541SN/A 2042901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *de); 2052901Ssaidi@eecs.umich.edu 2062738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1) 2072384SN/A { 2082521SN/A if (if_name == "pio") { 2092512SN/A if (pioPort != NULL) 2102512SN/A panic("pio port already connected to."); 2112901Ssaidi@eecs.umich.edu pioPort = new PioPort(this, sys); 2122384SN/A return pioPort; 2132521SN/A } else 2142384SN/A return NULL; 2152384SN/A } 2162489SN/A friend class PioPort; 2172489SN/A 218545SN/A}; 219545SN/A 2202512SN/Aclass BasicPioDevice : public PioDevice 2212512SN/A{ 2222512SN/A protected: 2232512SN/A /** Address that the device listens to. */ 2242512SN/A Addr pioAddr; 2252512SN/A 2262512SN/A /** Size that the device's address range. */ 2272521SN/A Addr pioSize; 2282512SN/A 2292512SN/A /** Delay that the device experinces on an access. */ 2302512SN/A Tick pioDelay; 2312512SN/A 2322512SN/A public: 2334762Snate@binkert.org typedef BasicPioDeviceParams Params; 2344762Snate@binkert.org BasicPioDevice(const Params *p); 2354762Snate@binkert.org 2364762Snate@binkert.org const Params * 2374762Snate@binkert.org params() const 2384762Snate@binkert.org { 2394762Snate@binkert.org return dynamic_cast<const Params *>(_params); 2404762Snate@binkert.org } 2412512SN/A 2422539SN/A /** return the address ranges that this device responds to. 2432982Sstever@eecs.umich.edu * @param range_list range list to populate with ranges 2442539SN/A */ 2452542SN/A void addressRanges(AddrRangeList &range_list); 2462539SN/A 2472512SN/A}; 2482512SN/A 249545SN/Aclass DmaDevice : public PioDevice 250545SN/A{ 2514435Ssaidi@eecs.umich.edu protected: 2522384SN/A DmaPort *dmaPort; 2534435Ssaidi@eecs.umich.edu Tick minBackoffDelay; 2544435Ssaidi@eecs.umich.edu Tick maxBackoffDelay; 255545SN/A 256545SN/A public: 2574762Snate@binkert.org typedef DmaDeviceParams Params; 2584762Snate@binkert.org DmaDevice(const Params *p); 259545SN/A virtual ~DmaDevice(); 2602384SN/A 2614762Snate@binkert.org const Params * 2624762Snate@binkert.org params() const 2634762Snate@binkert.org { 2644762Snate@binkert.org return dynamic_cast<const Params *>(_params); 2654762Snate@binkert.org } 2664762Snate@binkert.org 2672565SN/A void dmaWrite(Addr addr, int size, Event *event, uint8_t *data) 2684022Sstever@eecs.umich.edu { 2694022Sstever@eecs.umich.edu dmaPort->dmaAction(MemCmd::WriteInvalidateReq, 2704022Sstever@eecs.umich.edu addr, size, event, data); 2714022Sstever@eecs.umich.edu } 2722565SN/A 2734263Ssaidi@eecs.umich.edu void dmaRead(Addr addr, int size, Event *event, uint8_t *data) 2744263Ssaidi@eecs.umich.edu { 2754263Ssaidi@eecs.umich.edu dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data); 2764263Ssaidi@eecs.umich.edu } 2772565SN/A 2782565SN/A bool dmaPending() { return dmaPort->dmaPending(); } 2792565SN/A 2802901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *de); 2812901Ssaidi@eecs.umich.edu 2824263Ssaidi@eecs.umich.edu int cacheBlockSize() { return dmaPort->cacheBlockSize(); } 2834263Ssaidi@eecs.umich.edu 2842738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1) 2852384SN/A { 2862565SN/A if (if_name == "pio") { 2872565SN/A if (pioPort != NULL) 2882565SN/A panic("pio port already connected to."); 2892901Ssaidi@eecs.umich.edu pioPort = new PioPort(this, sys); 2902384SN/A return pioPort; 2912565SN/A } else if (if_name == "dma") { 2922565SN/A if (dmaPort != NULL) 2932565SN/A panic("dma port already connected to."); 2942901Ssaidi@eecs.umich.edu dmaPort = new DmaPort(this, sys); 2952384SN/A return dmaPort; 2962565SN/A } else 2972384SN/A return NULL; 2982384SN/A } 2992489SN/A 3002489SN/A friend class DmaPort; 301545SN/A}; 302545SN/A 3032384SN/A 3041310SN/A#endif // __DEV_IO_DEVICE_HH__ 305