io_device.hh revision 13799
111986Sandreas.sandberg@arm.com/*
211986Sandreas.sandberg@arm.com * Copyright (c) 2012 ARM Limited
311986Sandreas.sandberg@arm.com * All rights reserved.
411986Sandreas.sandberg@arm.com *
511986Sandreas.sandberg@arm.com * The license below extends only to copyright in the software and shall
611986Sandreas.sandberg@arm.com * not be construed as granting a license to any other intellectual
711986Sandreas.sandberg@arm.com * property including but not limited to intellectual property relating
811986Sandreas.sandberg@arm.com * to a hardware implementation of the functionality of the software
911986Sandreas.sandberg@arm.com * licensed hereunder.  You may use the software subject to the license
1011986Sandreas.sandberg@arm.com * terms below provided that you ensure that this notice is replicated
1111986Sandreas.sandberg@arm.com * unmodified and in its entirety in all distributions of the software,
1211986Sandreas.sandberg@arm.com * modified or unmodified, in source code or in binary form.
1311986Sandreas.sandberg@arm.com *
1411986Sandreas.sandberg@arm.com * Copyright (c) 2004-2005 The Regents of The University of Michigan
1511986Sandreas.sandberg@arm.com * All rights reserved.
1611986Sandreas.sandberg@arm.com *
1711986Sandreas.sandberg@arm.com * Redistribution and use in source and binary forms, with or without
1811986Sandreas.sandberg@arm.com * modification, are permitted provided that the following conditions are
1911986Sandreas.sandberg@arm.com * met: redistributions of source code must retain the above copyright
2011986Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer;
2111986Sandreas.sandberg@arm.com * redistributions in binary form must reproduce the above copyright
2211986Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer in the
2311986Sandreas.sandberg@arm.com * documentation and/or other materials provided with the distribution;
2411986Sandreas.sandberg@arm.com * neither the name of the copyright holders nor the names of its
2511986Sandreas.sandberg@arm.com * contributors may be used to endorse or promote products derived from
2611986Sandreas.sandberg@arm.com * this software without specific prior written permission.
2711986Sandreas.sandberg@arm.com *
2811986Sandreas.sandberg@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2911986Sandreas.sandberg@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3011986Sandreas.sandberg@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3111986Sandreas.sandberg@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3211986Sandreas.sandberg@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3311986Sandreas.sandberg@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3411986Sandreas.sandberg@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3511986Sandreas.sandberg@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3611986Sandreas.sandberg@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3711986Sandreas.sandberg@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3811986Sandreas.sandberg@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3911986Sandreas.sandberg@arm.com *
4011986Sandreas.sandberg@arm.com * Authors: Ali Saidi
4111986Sandreas.sandberg@arm.com *          Nathan Binkert
4211986Sandreas.sandberg@arm.com */
4311986Sandreas.sandberg@arm.com
4411986Sandreas.sandberg@arm.com#ifndef __DEV_IO_DEVICE_HH__
4511986Sandreas.sandberg@arm.com#define __DEV_IO_DEVICE_HH__
4611986Sandreas.sandberg@arm.com
4711986Sandreas.sandberg@arm.com#include "mem/mem_object.hh"
4811986Sandreas.sandberg@arm.com#include "mem/tport.hh"
4911986Sandreas.sandberg@arm.com#include "params/BasicPioDevice.hh"
5011986Sandreas.sandberg@arm.com#include "params/PioDevice.hh"
5111986Sandreas.sandberg@arm.com
5211986Sandreas.sandberg@arm.comclass PioDevice;
5311986Sandreas.sandberg@arm.comclass System;
5411986Sandreas.sandberg@arm.com
5511986Sandreas.sandberg@arm.com/**
5611986Sandreas.sandberg@arm.com * The PioPort class is a programmed i/o port that all devices that are
5711986Sandreas.sandberg@arm.com * sensitive to an address range use. The port takes all the memory
5811986Sandreas.sandberg@arm.com * access types and roles them into one read() and write() call that the device
5911986Sandreas.sandberg@arm.com * must respond to. The device must also provide getAddrRanges() function
6011986Sandreas.sandberg@arm.com * with which it returns the address ranges it is interested in.
6111986Sandreas.sandberg@arm.com */
6211986Sandreas.sandberg@arm.comclass PioPort : public SimpleTimingPort
6311986Sandreas.sandberg@arm.com{
6411986Sandreas.sandberg@arm.com  protected:
6511986Sandreas.sandberg@arm.com    /** The device that this port serves. */
6611986Sandreas.sandberg@arm.com    PioDevice *device;
6711986Sandreas.sandberg@arm.com
6811986Sandreas.sandberg@arm.com    virtual Tick recvAtomic(PacketPtr pkt);
6911986Sandreas.sandberg@arm.com
7011986Sandreas.sandberg@arm.com    virtual AddrRangeList getAddrRanges() const;
7111986Sandreas.sandberg@arm.com
7211986Sandreas.sandberg@arm.com  public:
7311986Sandreas.sandberg@arm.com
7411986Sandreas.sandberg@arm.com    PioPort(PioDevice *dev);
7511986Sandreas.sandberg@arm.com};
7611986Sandreas.sandberg@arm.com
7711986Sandreas.sandberg@arm.com/**
7811986Sandreas.sandberg@arm.com * This device is the base class which all devices senstive to an address range
7911986Sandreas.sandberg@arm.com * inherit from. There are three pure virtual functions which all devices must
8011986Sandreas.sandberg@arm.com * implement getAddrRanges(), read(), and write(). The magic do choose which
8111986Sandreas.sandberg@arm.com * mode we are in, etc is handled by the PioPort so the device doesn't have to
82 * bother.
83 */
84class PioDevice : public MemObject
85{
86  protected:
87    System *sys;
88
89    /** The pioPort that handles the requests for us and provides us requests
90     * that it sees. */
91    PioPort pioPort;
92
93    /**
94     * Every PIO device is obliged to provide an implementation that
95     * returns the address ranges the device responds to.
96     *
97     * @return a list of non-overlapping address ranges
98     */
99    virtual AddrRangeList getAddrRanges() const = 0;
100
101    /** Pure virtual function that the device must implement. Called
102     * when a read command is recieved by the port.
103     * @param pkt Packet describing this request
104     * @return number of ticks it took to complete
105     */
106    virtual Tick read(PacketPtr pkt) = 0;
107
108    /** Pure virtual function that the device must implement. Called when a
109     * write command is recieved by the port.
110     * @param pkt Packet describing this request
111     * @return number of ticks it took to complete
112     */
113    virtual Tick write(PacketPtr pkt) = 0;
114
115  public:
116    typedef PioDeviceParams Params;
117    PioDevice(const Params *p);
118    virtual ~PioDevice();
119
120    const Params *
121    params() const
122    {
123        return dynamic_cast<const Params *>(_params);
124    }
125
126    void init() override;
127
128    Port &getPort(const std::string &if_name,
129            PortID idx=InvalidPortID) override;
130
131    friend class PioPort;
132
133};
134
135class BasicPioDevice : public PioDevice
136{
137  protected:
138    /** Address that the device listens to. */
139    Addr pioAddr;
140
141    /** Size that the device's address range. */
142    Addr pioSize;
143
144    /** Delay that the device experinces on an access. */
145    Tick pioDelay;
146
147  public:
148    typedef BasicPioDeviceParams Params;
149    BasicPioDevice(const Params *p, Addr size);
150
151    const Params *
152    params() const
153    {
154        return dynamic_cast<const Params *>(_params);
155    }
156
157    /**
158     * Determine the address ranges that this device responds to.
159     *
160     * @return a list of non-overlapping address ranges
161     */
162    virtual AddrRangeList getAddrRanges() const;
163
164};
165
166#endif // __DEV_IO_DEVICE_HH__
167