io_device.hh revision 4263
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" 382489SN/A#include "sim/sim_object.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 593349Sbinkertn@umich.edu virtual Tick recvAtomic(PacketPtr pkt); 602384SN/A 613090Sstever@eecs.umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 623090Sstever@eecs.umich.edu AddrRangeList &snoop); 632384SN/A 642384SN/A public: 653091Sstever@eecs.umich.edu 662901Ssaidi@eecs.umich.edu PioPort(PioDevice *dev, System *s, std::string pname = "-pioport"); 672384SN/A}; 682384SN/A 692565SN/A 702384SN/Aclass DmaPort : public Port 712384SN/A{ 722384SN/A protected: 732784Ssaidi@eecs.umich.edu struct DmaReqState : public Packet::SenderState 742784Ssaidi@eecs.umich.edu { 752784Ssaidi@eecs.umich.edu /** Event to call on the device when this transaction (all packets) 762784Ssaidi@eecs.umich.edu * complete. */ 772784Ssaidi@eecs.umich.edu Event *completionEvent; 782784Ssaidi@eecs.umich.edu 792784Ssaidi@eecs.umich.edu /** Where we came from for some sanity checking. */ 802784Ssaidi@eecs.umich.edu Port *outPort; 812784Ssaidi@eecs.umich.edu 822784Ssaidi@eecs.umich.edu /** Total number of bytes that this transaction involves. */ 832784Ssaidi@eecs.umich.edu Addr totBytes; 842784Ssaidi@eecs.umich.edu 852784Ssaidi@eecs.umich.edu /** Number of bytes that have been acked for this transaction. */ 862784Ssaidi@eecs.umich.edu Addr numBytes; 872784Ssaidi@eecs.umich.edu 882784Ssaidi@eecs.umich.edu DmaReqState(Event *ce, Port *p, Addr tb) 892784Ssaidi@eecs.umich.edu : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0) 902784Ssaidi@eecs.umich.edu {} 912784Ssaidi@eecs.umich.edu }; 922784Ssaidi@eecs.umich.edu 932565SN/A DmaDevice *device; 943349Sbinkertn@umich.edu std::list<PacketPtr> transmitList; 952384SN/A 962901Ssaidi@eecs.umich.edu /** The system that device/port are in. This is used to select which mode 972565SN/A * we are currently operating in. */ 982901Ssaidi@eecs.umich.edu System *sys; 992565SN/A 1002565SN/A /** Number of outstanding packets the dma port has. */ 1012565SN/A int pendingCount; 1022384SN/A 1032901Ssaidi@eecs.umich.edu /** If a dmaAction is in progress. */ 1042901Ssaidi@eecs.umich.edu int actionInProgress; 1052901Ssaidi@eecs.umich.edu 1062901Ssaidi@eecs.umich.edu /** If we need to drain, keep the drain event around until we're done 1072901Ssaidi@eecs.umich.edu * here.*/ 1082901Ssaidi@eecs.umich.edu Event *drainEvent; 1092901Ssaidi@eecs.umich.edu 1103349Sbinkertn@umich.edu virtual bool recvTiming(PacketPtr pkt); 1113349Sbinkertn@umich.edu virtual Tick recvAtomic(PacketPtr pkt) 1123918Ssaidi@eecs.umich.edu { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN } 1133349Sbinkertn@umich.edu virtual void recvFunctional(PacketPtr pkt) 1142384SN/A { panic("dma port shouldn't be used for pio access."); } 1152384SN/A 1162384SN/A virtual void recvStatusChange(Status status) 1172384SN/A { ; } 1182384SN/A 1192657Ssaidi@eecs.umich.edu virtual void recvRetry() ; 1202384SN/A 1213090Sstever@eecs.umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 1223090Sstever@eecs.umich.edu AddrRangeList &snoop) 1232521SN/A { resp.clear(); snoop.clear(); } 1242384SN/A 1253349Sbinkertn@umich.edu void sendDma(PacketPtr pkt, bool front = false); 1262489SN/A 1272384SN/A public: 1282901Ssaidi@eecs.umich.edu DmaPort(DmaDevice *dev, System *s); 1292565SN/A 1302641Sstever@eecs.umich.edu void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 1312641Sstever@eecs.umich.edu uint8_t *data = NULL); 1322565SN/A 1332565SN/A bool dmaPending() { return pendingCount > 0; } 1342384SN/A 1354263Ssaidi@eecs.umich.edu int cacheBlockSize() { return peerBlockSize(); } 1362901Ssaidi@eecs.umich.edu unsigned int drain(Event *de); 1372384SN/A}; 1382384SN/A 1392489SN/A/** 1402489SN/A * This device is the base class which all devices senstive to an address range 1412489SN/A * inherit from. There are three pure virtual functions which all devices must 1422489SN/A * implement addressRanges(), read(), and write(). The magic do choose which 1432489SN/A * mode we are in, etc is handled by the PioPort so the device doesn't have to 1442489SN/A * bother. 1452489SN/A */ 1462542SN/Aclass PioDevice : public MemObject 1472384SN/A{ 1482384SN/A protected: 1492384SN/A 1502489SN/A /** The platform we are in. This is used to decide what type of memory 1512489SN/A * transaction we should perform. */ 1521310SN/A Platform *platform; 1532384SN/A 1542901Ssaidi@eecs.umich.edu System *sys; 1552901Ssaidi@eecs.umich.edu 1562489SN/A /** The pioPort that handles the requests for us and provides us requests 1572489SN/A * that it sees. */ 1582384SN/A PioPort *pioPort; 1592384SN/A 1602521SN/A virtual void addressRanges(AddrRangeList &range_list) = 0; 1612384SN/A 1623090Sstever@eecs.umich.edu /** Pure virtual function that the device must implement. Called 1633090Sstever@eecs.umich.edu * when a read command is recieved by the port. 1642523SN/A * @param pkt Packet describing this request 1652523SN/A * @return number of ticks it took to complete 1662523SN/A */ 1673349Sbinkertn@umich.edu virtual Tick read(PacketPtr pkt) = 0; 1682384SN/A 1692489SN/A /** Pure virtual function that the device must implement. Called when a 1702523SN/A * write command is recieved by the port. 1712523SN/A * @param pkt Packet describing this request 1722523SN/A * @return number of ticks it took to complete 1732523SN/A */ 1743349Sbinkertn@umich.edu virtual Tick write(PacketPtr pkt) = 0; 175545SN/A 176545SN/A public: 1773090Sstever@eecs.umich.edu /** Params struct which is extended through each device based on 1783090Sstever@eecs.umich.edu * the parameters it needs. Since we are re-writing everything, we 1793090Sstever@eecs.umich.edu * might as well start from the bottom this time. */ 1802512SN/A struct Params 1812512SN/A { 1822512SN/A std::string name; 1832512SN/A Platform *platform; 1842522SN/A System *system; 1852512SN/A }; 1862521SN/A 1872512SN/A protected: 1882512SN/A Params *_params; 1892512SN/A 1902512SN/A public: 1912512SN/A const Params *params() const { return _params; } 1922512SN/A 1932521SN/A PioDevice(Params *p) 1942901Ssaidi@eecs.umich.edu : MemObject(p->name), platform(p->platform), sys(p->system), 1952901Ssaidi@eecs.umich.edu pioPort(NULL), _params(p) 1962512SN/A {} 1972384SN/A 198545SN/A virtual ~PioDevice(); 1992384SN/A 2002541SN/A virtual void init(); 2012541SN/A 2022901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *de); 2032901Ssaidi@eecs.umich.edu 2042738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1) 2052384SN/A { 2062521SN/A if (if_name == "pio") { 2072512SN/A if (pioPort != NULL) 2082512SN/A panic("pio port already connected to."); 2092901Ssaidi@eecs.umich.edu pioPort = new PioPort(this, sys); 2102384SN/A return pioPort; 2112521SN/A } else 2122384SN/A return NULL; 2132384SN/A } 2142489SN/A friend class PioPort; 2152489SN/A 216545SN/A}; 217545SN/A 2182512SN/Aclass BasicPioDevice : public PioDevice 2192512SN/A{ 2202512SN/A public: 2212521SN/A struct Params : public PioDevice::Params 2222512SN/A { 2232512SN/A Addr pio_addr; 2242512SN/A Tick pio_delay; 2252512SN/A }; 2262512SN/A 2272512SN/A protected: 2282512SN/A /** Address that the device listens to. */ 2292512SN/A Addr pioAddr; 2302512SN/A 2312512SN/A /** Size that the device's address range. */ 2322521SN/A Addr pioSize; 2332512SN/A 2342512SN/A /** Delay that the device experinces on an access. */ 2352512SN/A Tick pioDelay; 2362512SN/A 2372512SN/A public: 2382521SN/A BasicPioDevice(Params *p) 2393090Sstever@eecs.umich.edu : PioDevice(p), pioAddr(p->pio_addr), pioSize(0), 2403090Sstever@eecs.umich.edu pioDelay(p->pio_delay) 2412512SN/A {} 2422512SN/A 2432539SN/A /** return the address ranges that this device responds to. 2442982Sstever@eecs.umich.edu * @param range_list range list to populate with ranges 2452539SN/A */ 2462542SN/A void addressRanges(AddrRangeList &range_list); 2472539SN/A 2482512SN/A}; 2492512SN/A 250545SN/Aclass DmaDevice : public PioDevice 251545SN/A{ 252545SN/A protected: 2532384SN/A DmaPort *dmaPort; 254545SN/A 255545SN/A public: 2562521SN/A DmaDevice(Params *p); 257545SN/A virtual ~DmaDevice(); 2582384SN/A 2592565SN/A void dmaWrite(Addr addr, int size, Event *event, uint8_t *data) 2604022Sstever@eecs.umich.edu { 2614022Sstever@eecs.umich.edu dmaPort->dmaAction(MemCmd::WriteInvalidateReq, 2624022Sstever@eecs.umich.edu addr, size, event, data); 2634022Sstever@eecs.umich.edu } 2642565SN/A 2654263Ssaidi@eecs.umich.edu void dmaRead(Addr addr, int size, Event *event, uint8_t *data) 2664263Ssaidi@eecs.umich.edu { 2674263Ssaidi@eecs.umich.edu dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data); 2684263Ssaidi@eecs.umich.edu } 2692565SN/A 2702565SN/A bool dmaPending() { return dmaPort->dmaPending(); } 2712565SN/A 2722901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *de); 2732901Ssaidi@eecs.umich.edu 2744263Ssaidi@eecs.umich.edu int cacheBlockSize() { return dmaPort->cacheBlockSize(); } 2754263Ssaidi@eecs.umich.edu 2762738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1) 2772384SN/A { 2782565SN/A if (if_name == "pio") { 2792565SN/A if (pioPort != NULL) 2802565SN/A panic("pio port already connected to."); 2812901Ssaidi@eecs.umich.edu pioPort = new PioPort(this, sys); 2822384SN/A return pioPort; 2832565SN/A } else if (if_name == "dma") { 2842565SN/A if (dmaPort != NULL) 2852565SN/A panic("dma port already connected to."); 2862901Ssaidi@eecs.umich.edu dmaPort = new DmaPort(this, sys); 2872384SN/A return dmaPort; 2882565SN/A } else 2892384SN/A return NULL; 2902384SN/A } 2912489SN/A 2922489SN/A friend class DmaPort; 293545SN/A}; 294545SN/A 2952384SN/A 2961310SN/A#endif // __DEV_IO_DEVICE_HH__ 297