io_device.hh revision 9090
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
472542SN/A#include "mem/mem_object.hh"
483348Sbinkertn@umich.edu#include "mem/tport.hh"
494762Snate@binkert.org#include "params/BasicPioDevice.hh"
504762Snate@binkert.org#include "params/PioDevice.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 */
842542SN/Aclass PioDevice : public MemObject
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
1262541SN/A    virtual void init();
1272541SN/A
1282901Ssaidi@eecs.umich.edu    virtual unsigned int drain(Event *de);
1292901Ssaidi@eecs.umich.edu
1308922Swilliam.wang@arm.com    virtual SlavePort &getSlavePort(const std::string &if_name, int idx = -1);
1318598Ssteve.reinhardt@amd.com
1322489SN/A    friend class PioPort;
1332489SN/A
134545SN/A};
135545SN/A
1362512SN/Aclass BasicPioDevice : public PioDevice
1372512SN/A{
1382512SN/A  protected:
1392512SN/A    /** Address that the device listens to. */
1402512SN/A    Addr pioAddr;
1412512SN/A
1422512SN/A    /** Size that the device's address range. */
1432521SN/A    Addr pioSize;
1442512SN/A
1452512SN/A    /** Delay that the device experinces on an access. */
1462512SN/A    Tick pioDelay;
1472512SN/A
1482512SN/A  public:
1494762Snate@binkert.org    typedef BasicPioDeviceParams Params;
1504762Snate@binkert.org    BasicPioDevice(const Params *p);
1514762Snate@binkert.org
1524762Snate@binkert.org    const Params *
1534762Snate@binkert.org    params() const
1544762Snate@binkert.org    {
1554762Snate@binkert.org        return dynamic_cast<const Params *>(_params);
1564762Snate@binkert.org    }
1572512SN/A
1588711Sandreas.hansson@arm.com    /**
1598711Sandreas.hansson@arm.com     * Determine the address ranges that this device responds to.
1608711Sandreas.hansson@arm.com     *
1618711Sandreas.hansson@arm.com     * @return a list of non-overlapping address ranges
1622539SN/A     */
1639090Sandreas.hansson@arm.com    virtual AddrRangeList getAddrRanges() const;
1642539SN/A
1652512SN/A};
1662512SN/A
1671310SN/A#endif // __DEV_IO_DEVICE_HH__
168