io_device.hh revision 3090
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" 362592SN/A#include "mem/packet_impl.hh" 372489SN/A#include "sim/sim_object.hh" 382914Ssaidi@eecs.umich.edu#include "mem/tport.hh" 39545SN/A 403090Sstever@eecs.umich.educlass Event; 411310SN/Aclass Platform; 422384SN/Aclass PioDevice; 432489SN/Aclass DmaDevice; 442522SN/Aclass System; 45545SN/A 462489SN/A/** 472489SN/A * The PioPort class is a programmed i/o port that all devices that are 482489SN/A * sensitive to an address range use. The port takes all the memory 492489SN/A * access types and roles them into one read() and write() call that the device 502489SN/A * must respond to. The device must also provide the addressRanges() function 513090Sstever@eecs.umich.edu * with which it returns the address ranges it is interested in. 523090Sstever@eecs.umich.edu */ 532914Ssaidi@eecs.umich.educlass PioPort : public SimpleTimingPort 54545SN/A{ 55545SN/A protected: 562489SN/A /** The device that this port serves. */ 572384SN/A PioDevice *device; 582384SN/A 592901Ssaidi@eecs.umich.edu /** The system that device/port are in. This is used to select which mode 602489SN/A * we are currently operating in. */ 612901Ssaidi@eecs.umich.edu System *sys; 622489SN/A 632489SN/A /** The current status of the peer(bus) that we are connected to. */ 642489SN/A Status peerStatus; 652489SN/A 662630SN/A virtual bool recvTiming(Packet *pkt); 672384SN/A 682630SN/A virtual Tick recvAtomic(Packet *pkt); 692384SN/A 702630SN/A virtual void recvFunctional(Packet *pkt) ; 712384SN/A 722489SN/A virtual void recvStatusChange(Status status) 732489SN/A { peerStatus = status; } 742384SN/A 753090Sstever@eecs.umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 763090Sstever@eecs.umich.edu AddrRangeList &snoop); 772384SN/A 782384SN/A public: 792901Ssaidi@eecs.umich.edu PioPort(PioDevice *dev, System *s, std::string pname = "-pioport"); 802901Ssaidi@eecs.umich.edu 812384SN/A}; 822384SN/A 832565SN/A 842384SN/Aclass DmaPort : public Port 852384SN/A{ 862384SN/A protected: 872784Ssaidi@eecs.umich.edu struct DmaReqState : public Packet::SenderState 882784Ssaidi@eecs.umich.edu { 892784Ssaidi@eecs.umich.edu /** Event to call on the device when this transaction (all packets) 902784Ssaidi@eecs.umich.edu * complete. */ 912784Ssaidi@eecs.umich.edu Event *completionEvent; 922784Ssaidi@eecs.umich.edu 932784Ssaidi@eecs.umich.edu /** Where we came from for some sanity checking. */ 942784Ssaidi@eecs.umich.edu Port *outPort; 952784Ssaidi@eecs.umich.edu 962784Ssaidi@eecs.umich.edu /** Total number of bytes that this transaction involves. */ 972784Ssaidi@eecs.umich.edu Addr totBytes; 982784Ssaidi@eecs.umich.edu 992784Ssaidi@eecs.umich.edu /** Number of bytes that have been acked for this transaction. */ 1002784Ssaidi@eecs.umich.edu Addr numBytes; 1012784Ssaidi@eecs.umich.edu 1022784Ssaidi@eecs.umich.edu DmaReqState(Event *ce, Port *p, Addr tb) 1032784Ssaidi@eecs.umich.edu : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0) 1042784Ssaidi@eecs.umich.edu {} 1052784Ssaidi@eecs.umich.edu }; 1062784Ssaidi@eecs.umich.edu 1072565SN/A DmaDevice *device; 1082384SN/A std::list<Packet*> transmitList; 1092384SN/A 1102901Ssaidi@eecs.umich.edu /** The system that device/port are in. This is used to select which mode 1112565SN/A * we are currently operating in. */ 1122901Ssaidi@eecs.umich.edu System *sys; 1132565SN/A 1142565SN/A /** Number of outstanding packets the dma port has. */ 1152565SN/A int pendingCount; 1162384SN/A 1172901Ssaidi@eecs.umich.edu /** If a dmaAction is in progress. */ 1182901Ssaidi@eecs.umich.edu int actionInProgress; 1192901Ssaidi@eecs.umich.edu 1202901Ssaidi@eecs.umich.edu /** If we need to drain, keep the drain event around until we're done 1212901Ssaidi@eecs.umich.edu * here.*/ 1222901Ssaidi@eecs.umich.edu Event *drainEvent; 1232901Ssaidi@eecs.umich.edu 1242630SN/A virtual bool recvTiming(Packet *pkt); 1252630SN/A virtual Tick recvAtomic(Packet *pkt) 1262384SN/A { panic("dma port shouldn't be used for pio access."); } 1272630SN/A virtual void recvFunctional(Packet *pkt) 1282384SN/A { panic("dma port shouldn't be used for pio access."); } 1292384SN/A 1302384SN/A virtual void recvStatusChange(Status status) 1312384SN/A { ; } 1322384SN/A 1332657Ssaidi@eecs.umich.edu virtual void recvRetry() ; 1342384SN/A 1353090Sstever@eecs.umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 1363090Sstever@eecs.umich.edu AddrRangeList &snoop) 1372521SN/A { resp.clear(); snoop.clear(); } 1382384SN/A 1392685Ssaidi@eecs.umich.edu void sendDma(Packet *pkt, bool front = false); 1402489SN/A 1412384SN/A public: 1422901Ssaidi@eecs.umich.edu DmaPort(DmaDevice *dev, System *s); 1432565SN/A 1442641Sstever@eecs.umich.edu void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 1452641Sstever@eecs.umich.edu uint8_t *data = NULL); 1462565SN/A 1472565SN/A bool dmaPending() { return pendingCount > 0; } 1482384SN/A 1492901Ssaidi@eecs.umich.edu unsigned int drain(Event *de); 1502384SN/A}; 1512384SN/A 1522489SN/A/** 1532489SN/A * This device is the base class which all devices senstive to an address range 1542489SN/A * inherit from. There are three pure virtual functions which all devices must 1552489SN/A * implement addressRanges(), read(), and write(). The magic do choose which 1562489SN/A * mode we are in, etc is handled by the PioPort so the device doesn't have to 1572489SN/A * bother. 1582489SN/A */ 1592542SN/Aclass PioDevice : public MemObject 1602384SN/A{ 1612384SN/A protected: 1622384SN/A 1632489SN/A /** The platform we are in. This is used to decide what type of memory 1642489SN/A * transaction we should perform. */ 1651310SN/A Platform *platform; 1662384SN/A 1672901Ssaidi@eecs.umich.edu System *sys; 1682901Ssaidi@eecs.umich.edu 1692489SN/A /** The pioPort that handles the requests for us and provides us requests 1702489SN/A * that it sees. */ 1712384SN/A PioPort *pioPort; 1722384SN/A 1732521SN/A virtual void addressRanges(AddrRangeList &range_list) = 0; 1742384SN/A 1753090Sstever@eecs.umich.edu /** As far as the devices are concerned they only accept atomic 1763090Sstever@eecs.umich.edu * transactions which are converted to either a write or a 1773090Sstever@eecs.umich.edu * read. */ 1782630SN/A Tick recvAtomic(Packet *pkt) 1792641Sstever@eecs.umich.edu { return pkt->isRead() ? this->read(pkt) : this->write(pkt); } 1802384SN/A 1813090Sstever@eecs.umich.edu /** Pure virtual function that the device must implement. Called 1823090Sstever@eecs.umich.edu * when a read command is recieved by the port. 1832523SN/A * @param pkt Packet describing this request 1842523SN/A * @return number of ticks it took to complete 1852523SN/A */ 1862630SN/A virtual Tick read(Packet *pkt) = 0; 1872384SN/A 1882489SN/A /** Pure virtual function that the device must implement. Called when a 1892523SN/A * write command is recieved by the port. 1902523SN/A * @param pkt Packet describing this request 1912523SN/A * @return number of ticks it took to complete 1922523SN/A */ 1932630SN/A virtual Tick write(Packet *pkt) = 0; 194545SN/A 195545SN/A public: 1963090Sstever@eecs.umich.edu /** Params struct which is extended through each device based on 1973090Sstever@eecs.umich.edu * the parameters it needs. Since we are re-writing everything, we 1983090Sstever@eecs.umich.edu * might as well start from the bottom this time. */ 1992512SN/A struct Params 2002512SN/A { 2012512SN/A std::string name; 2022512SN/A Platform *platform; 2032522SN/A System *system; 2042512SN/A }; 2052521SN/A 2062512SN/A protected: 2072512SN/A Params *_params; 2082512SN/A 2092512SN/A public: 2102512SN/A const Params *params() const { return _params; } 2112512SN/A 2122521SN/A PioDevice(Params *p) 2132901Ssaidi@eecs.umich.edu : MemObject(p->name), platform(p->platform), sys(p->system), 2142901Ssaidi@eecs.umich.edu pioPort(NULL), _params(p) 2152512SN/A {} 2162384SN/A 217545SN/A virtual ~PioDevice(); 2182384SN/A 2192541SN/A virtual void init(); 2202541SN/A 2212901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *de); 2222901Ssaidi@eecs.umich.edu 2232738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1) 2242384SN/A { 2252521SN/A if (if_name == "pio") { 2262512SN/A if (pioPort != NULL) 2272512SN/A panic("pio port already connected to."); 2282901Ssaidi@eecs.umich.edu pioPort = new PioPort(this, sys); 2292384SN/A return pioPort; 2302521SN/A } else 2312384SN/A return NULL; 2322384SN/A } 2332489SN/A friend class PioPort; 2342489SN/A 235545SN/A}; 236545SN/A 2372512SN/Aclass BasicPioDevice : public PioDevice 2382512SN/A{ 2392512SN/A public: 2402521SN/A struct Params : public PioDevice::Params 2412512SN/A { 2422512SN/A Addr pio_addr; 2432512SN/A Tick pio_delay; 2442512SN/A }; 2452512SN/A 2462512SN/A protected: 2472512SN/A /** Address that the device listens to. */ 2482512SN/A Addr pioAddr; 2492512SN/A 2502512SN/A /** Size that the device's address range. */ 2512521SN/A Addr pioSize; 2522512SN/A 2532512SN/A /** Delay that the device experinces on an access. */ 2542512SN/A Tick pioDelay; 2552512SN/A 2562512SN/A public: 2572521SN/A BasicPioDevice(Params *p) 2583090Sstever@eecs.umich.edu : PioDevice(p), pioAddr(p->pio_addr), pioSize(0), 2593090Sstever@eecs.umich.edu pioDelay(p->pio_delay) 2602512SN/A {} 2612512SN/A 2622539SN/A /** return the address ranges that this device responds to. 2632982Sstever@eecs.umich.edu * @param range_list range list to populate with ranges 2642539SN/A */ 2652542SN/A void addressRanges(AddrRangeList &range_list); 2662539SN/A 2672512SN/A}; 2682512SN/A 269545SN/Aclass DmaDevice : public PioDevice 270545SN/A{ 271545SN/A protected: 2722384SN/A DmaPort *dmaPort; 273545SN/A 274545SN/A public: 2752521SN/A DmaDevice(Params *p); 276545SN/A virtual ~DmaDevice(); 2772384SN/A 2782565SN/A void dmaWrite(Addr addr, int size, Event *event, uint8_t *data) 2792641Sstever@eecs.umich.edu { dmaPort->dmaAction(Packet::WriteReq, addr, size, event, data) ; } 2802565SN/A 2812565SN/A void dmaRead(Addr addr, int size, Event *event, uint8_t *data = NULL) 2822641Sstever@eecs.umich.edu { dmaPort->dmaAction(Packet::ReadReq, addr, size, event, data); } 2832565SN/A 2842565SN/A bool dmaPending() { return dmaPort->dmaPending(); } 2852565SN/A 2862901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *de); 2872901Ssaidi@eecs.umich.edu 2882738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1) 2892384SN/A { 2902565SN/A if (if_name == "pio") { 2912565SN/A if (pioPort != NULL) 2922565SN/A panic("pio port already connected to."); 2932901Ssaidi@eecs.umich.edu pioPort = new PioPort(this, sys); 2942384SN/A return pioPort; 2952565SN/A } else if (if_name == "dma") { 2962565SN/A if (dmaPort != NULL) 2972565SN/A panic("dma port already connected to."); 2982901Ssaidi@eecs.umich.edu dmaPort = new DmaPort(this, sys); 2992384SN/A return dmaPort; 3002565SN/A } else 3012384SN/A return NULL; 3022384SN/A } 3032489SN/A 3042489SN/A friend class DmaPort; 305545SN/A}; 306545SN/A 3072384SN/A 3081310SN/A#endif // __DEV_IO_DEVICE_HH__ 309