io_device.hh revision 14218
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 */ 6214218Sgabeblack@google.comtemplate <class Device> 632914Ssaidi@eecs.umich.educlass PioPort : public SimpleTimingPort 64545SN/A{ 65545SN/A protected: 662489SN/A /** The device that this port serves. */ 6714218Sgabeblack@google.com Device *device; 682384SN/A 6914218Sgabeblack@google.com Tick 7014218Sgabeblack@google.com recvAtomic(PacketPtr pkt) override 7114218Sgabeblack@google.com { 7214218Sgabeblack@google.com // Technically the packet only reaches us after the header delay, 7314218Sgabeblack@google.com // and typically we also need to deserialise any payload. 7414218Sgabeblack@google.com Tick receive_delay = pkt->headerDelay + pkt->payloadDelay; 7514218Sgabeblack@google.com pkt->headerDelay = pkt->payloadDelay = 0; 762384SN/A 7714218Sgabeblack@google.com const Tick delay = 7814218Sgabeblack@google.com pkt->isRead() ? device->read(pkt) : device->write(pkt); 7914218Sgabeblack@google.com assert(pkt->isResponse() || pkt->isError()); 8014218Sgabeblack@google.com return delay + receive_delay; 8114218Sgabeblack@google.com } 8214218Sgabeblack@google.com 8314218Sgabeblack@google.com AddrRangeList 8414218Sgabeblack@google.com getAddrRanges() const override 8514218Sgabeblack@google.com { 8614218Sgabeblack@google.com return device->getAddrRanges(); 8714218Sgabeblack@google.com } 882384SN/A 892384SN/A public: 9014218Sgabeblack@google.com PioPort(Device *dev) : 9114218Sgabeblack@google.com SimpleTimingPort(dev->name() + ".pio", dev), device(dev) 9214218Sgabeblack@google.com {} 932384SN/A}; 942384SN/A 952489SN/A/** 962489SN/A * This device is the base class which all devices senstive to an address range 972489SN/A * inherit from. There are three pure virtual functions which all devices must 988711Sandreas.hansson@arm.com * implement getAddrRanges(), read(), and write(). The magic do choose which 992489SN/A * mode we are in, etc is handled by the PioPort so the device doesn't have to 1002489SN/A * bother. 1012489SN/A */ 10213892Sgabeblack@google.comclass PioDevice : public ClockedObject 1032384SN/A{ 1042384SN/A protected: 1052901Ssaidi@eecs.umich.edu System *sys; 1062901Ssaidi@eecs.umich.edu 1072489SN/A /** The pioPort that handles the requests for us and provides us requests 1082489SN/A * that it sees. */ 10914218Sgabeblack@google.com PioPort<PioDevice> pioPort; 1102384SN/A 1118711Sandreas.hansson@arm.com /** 1128711Sandreas.hansson@arm.com * Every PIO device is obliged to provide an implementation that 1138711Sandreas.hansson@arm.com * returns the address ranges the device responds to. 1148711Sandreas.hansson@arm.com * 1158711Sandreas.hansson@arm.com * @return a list of non-overlapping address ranges 1168711Sandreas.hansson@arm.com */ 1179090Sandreas.hansson@arm.com virtual AddrRangeList getAddrRanges() const = 0; 1182384SN/A 1193090Sstever@eecs.umich.edu /** Pure virtual function that the device must implement. Called 1203090Sstever@eecs.umich.edu * when a read command is recieved by the port. 1212523SN/A * @param pkt Packet describing this request 1222523SN/A * @return number of ticks it took to complete 1232523SN/A */ 1243349Sbinkertn@umich.edu virtual Tick read(PacketPtr pkt) = 0; 1252384SN/A 1262489SN/A /** Pure virtual function that the device must implement. Called when a 1272523SN/A * write command is recieved by the port. 1282523SN/A * @param pkt Packet describing this request 1292523SN/A * @return number of ticks it took to complete 1302523SN/A */ 1313349Sbinkertn@umich.edu virtual Tick write(PacketPtr pkt) = 0; 132545SN/A 133545SN/A public: 1344762Snate@binkert.org typedef PioDeviceParams Params; 1354762Snate@binkert.org PioDevice(const Params *p); 1364762Snate@binkert.org virtual ~PioDevice(); 1374762Snate@binkert.org 1384762Snate@binkert.org const Params * 1394762Snate@binkert.org params() const 1402512SN/A { 1414762Snate@binkert.org return dynamic_cast<const Params *>(_params); 1424762Snate@binkert.org } 1432384SN/A 14413799SAndrea.Mondelli@ucf.edu void init() override; 1452541SN/A 14613784Sgabeblack@google.com Port &getPort(const std::string &if_name, 14713784Sgabeblack@google.com PortID idx=InvalidPortID) override; 1488598Ssteve.reinhardt@amd.com 14914218Sgabeblack@google.com friend class PioPort<PioDevice>; 1502489SN/A 151545SN/A}; 152545SN/A 1532512SN/Aclass BasicPioDevice : public PioDevice 1542512SN/A{ 1552512SN/A protected: 1562512SN/A /** Address that the device listens to. */ 1572512SN/A Addr pioAddr; 1582512SN/A 1592512SN/A /** Size that the device's address range. */ 1602521SN/A Addr pioSize; 1612512SN/A 1622512SN/A /** Delay that the device experinces on an access. */ 1632512SN/A Tick pioDelay; 1642512SN/A 1652512SN/A public: 1664762Snate@binkert.org typedef BasicPioDeviceParams Params; 1679808Sstever@gmail.com BasicPioDevice(const Params *p, Addr size); 1684762Snate@binkert.org 1694762Snate@binkert.org const Params * 1704762Snate@binkert.org params() const 1714762Snate@binkert.org { 1724762Snate@binkert.org return dynamic_cast<const Params *>(_params); 1734762Snate@binkert.org } 1742512SN/A 1758711Sandreas.hansson@arm.com /** 1768711Sandreas.hansson@arm.com * Determine the address ranges that this device responds to. 1778711Sandreas.hansson@arm.com * 1788711Sandreas.hansson@arm.com * @return a list of non-overlapping address ranges 1792539SN/A */ 18014218Sgabeblack@google.com AddrRangeList getAddrRanges() const override; 1812512SN/A}; 1822512SN/A 1831310SN/A#endif // __DEV_IO_DEVICE_HH__ 184