io_device.hh revision 13784
12SN/A/* 21762SN/A * Copyright (c) 2012 ARM Limited 32SN/A * All rights reserved. 42SN/A * 52SN/A * The license below extends only to copyright in the software and shall 62SN/A * not be construed as granting a license to any other intellectual 72SN/A * property including but not limited to intellectual property relating 82SN/A * to a hardware implementation of the functionality of the software 92SN/A * licensed hereunder. You may use the software subject to the license 102SN/A * terms below provided that you ensure that this notice is replicated 112SN/A * unmodified and in its entirety in all distributions of the software, 122SN/A * modified or unmodified, in source code or in binary form. 132SN/A * 142SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 152SN/A * All rights reserved. 162SN/A * 172SN/A * Redistribution and use in source and binary forms, with or without 182SN/A * modification, are permitted provided that the following conditions are 192SN/A * met: redistributions of source code must retain the above copyright 202SN/A * notice, this list of conditions and the following disclaimer; 212SN/A * redistributions in binary form must reproduce the above copyright 222SN/A * notice, this list of conditions and the following disclaimer in the 232SN/A * documentation and/or other materials provided with the distribution; 242SN/A * neither the name of the copyright holders nor the names of its 252SN/A * contributors may be used to endorse or promote products derived from 262SN/A * this software without specific prior written permission. 272665Ssaidi@eecs.umich.edu * 282760Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292760Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302665Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34363SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35363SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361354SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392SN/A * 402SN/A * Authors: Ali Saidi 412SN/A * Nathan Binkert 422SN/A */ 43363SN/A 4456SN/A#ifndef __DEV_IO_DEVICE_HH__ 451388SN/A#define __DEV_IO_DEVICE_HH__ 46217SN/A 47363SN/A#include "mem/mem_object.hh" 4856SN/A#include "mem/tport.hh" 4956SN/A#include "params/BasicPioDevice.hh" 5056SN/A#include "params/PioDevice.hh" 511638SN/A 5256SN/Aclass PioDevice; 532SN/Aclass System; 542356SN/A 552356SN/A/** 562356SN/A * The PioPort class is a programmed i/o port that all devices that are 572SN/A * sensitive to an address range use. The port takes all the memory 582SN/A * access types and roles them into one read() and write() call that the device 594000Ssaidi@eecs.umich.edu * must respond to. The device must also provide getAddrRanges() function 604000Ssaidi@eecs.umich.edu * with which it returns the address ranges it is interested in. 614762Snate@binkert.org */ 624762Snate@binkert.orgclass PioPort : public SimpleTimingPort 634762Snate@binkert.org{ 644762Snate@binkert.org protected: 654762Snate@binkert.org /** The device that this port serves. */ 664762Snate@binkert.org PioDevice *device; 674762Snate@binkert.org 684762Snate@binkert.org virtual Tick recvAtomic(PacketPtr pkt); 694762Snate@binkert.org 704762Snate@binkert.org virtual AddrRangeList getAddrRanges() const; 714762Snate@binkert.org 724762Snate@binkert.org public: 734762Snate@binkert.org 744762Snate@binkert.org PioPort(PioDevice *dev); 754762Snate@binkert.org}; 764762Snate@binkert.org 774762Snate@binkert.org/** 784762Snate@binkert.org * This device is the base class which all devices senstive to an address range 794762Snate@binkert.org * inherit from. There are three pure virtual functions which all devices must 804762Snate@binkert.org * implement getAddrRanges(), read(), and write(). The magic do choose which 814762Snate@binkert.org * mode we are in, etc is handled by the PioPort so the device doesn't have to 824762Snate@binkert.org * bother. 834762Snate@binkert.org */ 844762Snate@binkert.orgclass PioDevice : public MemObject 854762Snate@binkert.org{ 864762Snate@binkert.org protected: 874762Snate@binkert.org System *sys; 884762Snate@binkert.org 894762Snate@binkert.org /** The pioPort that handles the requests for us and provides us requests 904762Snate@binkert.org * that it sees. */ 914762Snate@binkert.org PioPort pioPort; 924762Snate@binkert.org 934762Snate@binkert.org /** 944762Snate@binkert.org * Every PIO device is obliged to provide an implementation that 954762Snate@binkert.org * returns the address ranges the device responds to. 964762Snate@binkert.org * 974762Snate@binkert.org * @return a list of non-overlapping address ranges 984762Snate@binkert.org */ 994762Snate@binkert.org virtual AddrRangeList getAddrRanges() const = 0; 1004762Snate@binkert.org 1014762Snate@binkert.org /** Pure virtual function that the device must implement. Called 1024762Snate@binkert.org * when a read command is recieved by the port. 1034762Snate@binkert.org * @param pkt Packet describing this request 1044762Snate@binkert.org * @return number of ticks it took to complete 1054762Snate@binkert.org */ 1064762Snate@binkert.org virtual Tick read(PacketPtr pkt) = 0; 1074762Snate@binkert.org 1084762Snate@binkert.org /** Pure virtual function that the device must implement. Called when a 1094762Snate@binkert.org * write command is recieved by the port. 1104762Snate@binkert.org * @param pkt Packet describing this request 1114762Snate@binkert.org * @return number of ticks it took to complete 1124762Snate@binkert.org */ 1134762Snate@binkert.org virtual Tick write(PacketPtr pkt) = 0; 1144762Snate@binkert.org 1154762Snate@binkert.org 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 1224762Snate@binkert.org { 1234762Snate@binkert.org return dynamic_cast<const Params *>(_params); 1244762Snate@binkert.org } 1254762Snate@binkert.org 1264762Snate@binkert.org virtual void init(); 1274762Snate@binkert.org 1284762Snate@binkert.org Port &getPort(const std::string &if_name, 1294762Snate@binkert.org PortID idx=InvalidPortID) override; 1304762Snate@binkert.org 1314762Snate@binkert.org friend class PioPort; 1324762Snate@binkert.org 1334762Snate@binkert.org}; 1344762Snate@binkert.org 1354762Snate@binkert.orgclass BasicPioDevice : public PioDevice 1364762Snate@binkert.org{ 1374762Snate@binkert.org protected: 1384762Snate@binkert.org /** Address that the device listens to. */ 1394762Snate@binkert.org Addr pioAddr; 1404762Snate@binkert.org 1414762Snate@binkert.org /** Size that the device's address range. */ 1424762Snate@binkert.org Addr pioSize; 1434762Snate@binkert.org 1444762Snate@binkert.org /** Delay that the device experinces on an access. */ 1454762Snate@binkert.org Tick pioDelay; 1464762Snate@binkert.org 1474762Snate@binkert.org public: 1484762Snate@binkert.org typedef BasicPioDeviceParams Params; 1494762Snate@binkert.org 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 } 1562287SN/A 1572287SN/A /** 1582287SN/A * Determine the address ranges that this device responds to. 1591637SN/A * 1602SN/A * @return a list of non-overlapping address ranges 161395SN/A */ 1622SN/A virtual AddrRangeList getAddrRanges() const; 163217SN/A 1642SN/A}; 1652SN/A 1662SN/A#endif // __DEV_IO_DEVICE_HH__ 167395SN/A