io_device.hh revision 13892
1545SN/A/* 28948Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited 38948Sandreas.hansson@arm.com * All rights reserved. 48948Sandreas.hansson@arm.com * 58948Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68948Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78948Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88948Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98948Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108948Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118948Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128948Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138948Sandreas.hansson@arm.com * 141762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 15545SN/A * All rights reserved. 16545SN/A * 17545SN/A * Redistribution and use in source and binary forms, with or without 18545SN/A * modification, are permitted provided that the following conditions are 19545SN/A * met: redistributions of source code must retain the above copyright 20545SN/A * notice, this list of conditions and the following disclaimer; 21545SN/A * redistributions in binary form must reproduce the above copyright 22545SN/A * notice, this list of conditions and the following disclaimer in the 23545SN/A * documentation and/or other materials provided with the distribution; 24545SN/A * neither the name of the copyright holders nor the names of its 25545SN/A * contributors may be used to endorse or promote products derived from 26545SN/A * this software without specific prior written permission. 27545SN/A * 28545SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29545SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30545SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31545SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32545SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33545SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34545SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35545SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36545SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37545SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38545SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 412665Ssaidi@eecs.umich.edu * Nathan Binkert 42545SN/A */ 43545SN/A 441310SN/A#ifndef __DEV_IO_DEVICE_HH__ 451310SN/A#define __DEV_IO_DEVICE_HH__ 46545SN/A 473348Sbinkertn@umich.edu#include "mem/tport.hh" 484762Snate@binkert.org#include "params/BasicPioDevice.hh" 494762Snate@binkert.org#include "params/PioDevice.hh" 5013892Sgabeblack@google.com#include "sim/clocked_object.hh" 51545SN/A 522384SN/Aclass PioDevice; 532522SN/Aclass System; 54545SN/A 552489SN/A/** 562489SN/A * The PioPort class is a programmed i/o port that all devices that are 572489SN/A * sensitive to an address range use. The port takes all the memory 582489SN/A * access types and roles them into one read() and write() call that the device 598711Sandreas.hansson@arm.com * must respond to. The device must also provide getAddrRanges() function 603090Sstever@eecs.umich.edu * with which it returns the address ranges it is interested in. 613090Sstever@eecs.umich.edu */ 622914Ssaidi@eecs.umich.educlass PioPort : public SimpleTimingPort 63545SN/A{ 64545SN/A protected: 652489SN/A /** The device that this port serves. */ 662384SN/A PioDevice *device; 672384SN/A 683349Sbinkertn@umich.edu virtual Tick recvAtomic(PacketPtr pkt); 692384SN/A 709090Sandreas.hansson@arm.com virtual AddrRangeList getAddrRanges() const; 712384SN/A 722384SN/A public: 733091Sstever@eecs.umich.edu 748914Sandreas.hansson@arm.com PioPort(PioDevice *dev); 752384SN/A}; 762384SN/A 772489SN/A/** 782489SN/A * This device is the base class which all devices senstive to an address range 792489SN/A * inherit from. There are three pure virtual functions which all devices must 808711Sandreas.hansson@arm.com * implement getAddrRanges(), read(), and write(). The magic do choose which 812489SN/A * mode we are in, etc is handled by the PioPort so the device doesn't have to 822489SN/A * bother. 832489SN/A */ 8413892Sgabeblack@google.comclass PioDevice : public ClockedObject 852384SN/A{ 862384SN/A protected: 872901Ssaidi@eecs.umich.edu System *sys; 882901Ssaidi@eecs.umich.edu 892489SN/A /** The pioPort that handles the requests for us and provides us requests 902489SN/A * that it sees. */ 918851Sandreas.hansson@arm.com PioPort pioPort; 922384SN/A 938711Sandreas.hansson@arm.com /** 948711Sandreas.hansson@arm.com * Every PIO device is obliged to provide an implementation that 958711Sandreas.hansson@arm.com * returns the address ranges the device responds to. 968711Sandreas.hansson@arm.com * 978711Sandreas.hansson@arm.com * @return a list of non-overlapping address ranges 988711Sandreas.hansson@arm.com */ 999090Sandreas.hansson@arm.com virtual AddrRangeList getAddrRanges() const = 0; 1002384SN/A 1013090Sstever@eecs.umich.edu /** Pure virtual function that the device must implement. Called 1023090Sstever@eecs.umich.edu * when a read command is recieved by the port. 1032523SN/A * @param pkt Packet describing this request 1042523SN/A * @return number of ticks it took to complete 1052523SN/A */ 1063349Sbinkertn@umich.edu virtual Tick read(PacketPtr pkt) = 0; 1072384SN/A 1082489SN/A /** Pure virtual function that the device must implement. Called when a 1092523SN/A * write command is recieved by the port. 1102523SN/A * @param pkt Packet describing this request 1112523SN/A * @return number of ticks it took to complete 1122523SN/A */ 1133349Sbinkertn@umich.edu virtual Tick write(PacketPtr pkt) = 0; 114545SN/A 115545SN/A public: 1164762Snate@binkert.org typedef PioDeviceParams Params; 1174762Snate@binkert.org PioDevice(const Params *p); 1184762Snate@binkert.org virtual ~PioDevice(); 1194762Snate@binkert.org 1204762Snate@binkert.org const Params * 1214762Snate@binkert.org params() const 1222512SN/A { 1234762Snate@binkert.org return dynamic_cast<const Params *>(_params); 1244762Snate@binkert.org } 1252384SN/A 12613799SAndrea.Mondelli@ucf.edu void init() override; 1272541SN/A 12813784Sgabeblack@google.com Port &getPort(const std::string &if_name, 12913784Sgabeblack@google.com PortID idx=InvalidPortID) override; 1308598Ssteve.reinhardt@amd.com 1312489SN/A friend class PioPort; 1322489SN/A 133545SN/A}; 134545SN/A 1352512SN/Aclass BasicPioDevice : public PioDevice 1362512SN/A{ 1372512SN/A protected: 1382512SN/A /** Address that the device listens to. */ 1392512SN/A Addr pioAddr; 1402512SN/A 1412512SN/A /** Size that the device's address range. */ 1422521SN/A Addr pioSize; 1432512SN/A 1442512SN/A /** Delay that the device experinces on an access. */ 1452512SN/A Tick pioDelay; 1462512SN/A 1472512SN/A public: 1484762Snate@binkert.org typedef BasicPioDeviceParams Params; 1499808Sstever@gmail.com BasicPioDevice(const Params *p, Addr size); 1504762Snate@binkert.org 1514762Snate@binkert.org const Params * 1524762Snate@binkert.org params() const 1534762Snate@binkert.org { 1544762Snate@binkert.org return dynamic_cast<const Params *>(_params); 1554762Snate@binkert.org } 1562512SN/A 1578711Sandreas.hansson@arm.com /** 1588711Sandreas.hansson@arm.com * Determine the address ranges that this device responds to. 1598711Sandreas.hansson@arm.com * 1608711Sandreas.hansson@arm.com * @return a list of non-overlapping address ranges 1612539SN/A */ 1629090Sandreas.hansson@arm.com virtual AddrRangeList getAddrRanges() const; 1632539SN/A 1642512SN/A}; 1652512SN/A 1661310SN/A#endif // __DEV_IO_DEVICE_HH__ 167