pl011.hh revision 9806:3f262c18ad5d
112268Sradhika.jagtap@arm.com/*
212268Sradhika.jagtap@arm.com * Copyright (c) 2010 ARM Limited
312268Sradhika.jagtap@arm.com * All rights reserved
412268Sradhika.jagtap@arm.com *
512268Sradhika.jagtap@arm.com * The license below extends only to copyright in the software and shall
612268Sradhika.jagtap@arm.com * not be construed as granting a license to any other intellectual
712268Sradhika.jagtap@arm.com * property including but not limited to intellectual property relating
812268Sradhika.jagtap@arm.com * to a hardware implementation of the functionality of the software
912268Sradhika.jagtap@arm.com * licensed hereunder.  You may use the software subject to the license
1012268Sradhika.jagtap@arm.com * terms below provided that you ensure that this notice is replicated
1112268Sradhika.jagtap@arm.com * unmodified and in its entirety in all distributions of the software,
1212268Sradhika.jagtap@arm.com * modified or unmodified, in source code or in binary form.
1312268Sradhika.jagtap@arm.com *
1412268Sradhika.jagtap@arm.com * Copyright (c) 2005 The Regents of The University of Michigan
1512268Sradhika.jagtap@arm.com * All rights reserved.
1612268Sradhika.jagtap@arm.com *
1712268Sradhika.jagtap@arm.com * Redistribution and use in source and binary forms, with or without
1812268Sradhika.jagtap@arm.com * modification, are permitted provided that the following conditions are
1912268Sradhika.jagtap@arm.com * met: redistributions of source code must retain the above copyright
2012268Sradhika.jagtap@arm.com * notice, this list of conditions and the following disclaimer;
2112268Sradhika.jagtap@arm.com * redistributions in binary form must reproduce the above copyright
2212268Sradhika.jagtap@arm.com * notice, this list of conditions and the following disclaimer in the
2312268Sradhika.jagtap@arm.com * documentation and/or other materials provided with the distribution;
2412268Sradhika.jagtap@arm.com * neither the name of the copyright holders nor the names of its
2512268Sradhika.jagtap@arm.com * contributors may be used to endorse or promote products derived from
2612268Sradhika.jagtap@arm.com * this software without specific prior written permission.
2712268Sradhika.jagtap@arm.com *
2812268Sradhika.jagtap@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2912268Sradhika.jagtap@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3012268Sradhika.jagtap@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3112268Sradhika.jagtap@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3212268Sradhika.jagtap@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3312268Sradhika.jagtap@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3412268Sradhika.jagtap@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3512268Sradhika.jagtap@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3612268Sradhika.jagtap@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3712268Sradhika.jagtap@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3812268Sradhika.jagtap@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3912268Sradhika.jagtap@arm.com *
4012268Sradhika.jagtap@arm.com * Authors: Ali Saidi
4112268Sradhika.jagtap@arm.com */
4212268Sradhika.jagtap@arm.com
4312268Sradhika.jagtap@arm.com
4412268Sradhika.jagtap@arm.com/** @file
4512268Sradhika.jagtap@arm.com * Implementiation of a PL011 UART
4612268Sradhika.jagtap@arm.com */
4712268Sradhika.jagtap@arm.com
4812268Sradhika.jagtap@arm.com#ifndef __DEV_ARM_PL011_H__
4912268Sradhika.jagtap@arm.com#define __DEV_ARM_PL011_H__
5012268Sradhika.jagtap@arm.com
5112268Sradhika.jagtap@arm.com#include "base/bitfield.hh"
5212268Sradhika.jagtap@arm.com#include "base/bitunion.hh"
5312268Sradhika.jagtap@arm.com#include "dev/arm/amba_device.hh"
5412268Sradhika.jagtap@arm.com#include "dev/io_device.hh"
5512268Sradhika.jagtap@arm.com#include "dev/uart.hh"
5612268Sradhika.jagtap@arm.com#include "params/Pl011.hh"
5712268Sradhika.jagtap@arm.com
5812268Sradhika.jagtap@arm.comclass BaseGic;
5912268Sradhika.jagtap@arm.com
6012268Sradhika.jagtap@arm.comclass Pl011 : public Uart, public AmbaDevice
6112268Sradhika.jagtap@arm.com{
6212268Sradhika.jagtap@arm.com  protected:
6312268Sradhika.jagtap@arm.com    static const uint64_t AMBA_ID = ULL(0xb105f00d00341011);
6412268Sradhika.jagtap@arm.com    static const int UART_DR = 0x000;
6512268Sradhika.jagtap@arm.com    static const int UART_FR = 0x018;
6612268Sradhika.jagtap@arm.com    static const int UART_FR_CTS  = 0x001;
6712268Sradhika.jagtap@arm.com    static const int UART_FR_TXFE = 0x080;
6812268Sradhika.jagtap@arm.com    static const int UART_FR_RXFE = 0x010;
69    static const int UART_IBRD = 0x024;
70    static const int UART_FBRD = 0x028;
71    static const int UART_LCRH = 0x02C;
72    static const int UART_CR   = 0x030;
73    static const int UART_IFLS = 0x034;
74    static const int UART_IMSC = 0x038;
75    static const int UART_RIS  = 0x03C;
76    static const int UART_MIS  = 0x040;
77    static const int UART_ICR  = 0x044;
78
79    uint16_t control;
80
81    /** fractional baud rate divisor. Not used for anything but reporting
82     * written value */
83    uint16_t fbrd;
84
85    /** integer baud rate divisor. Not used for anything but reporting
86     * written value */
87    uint16_t ibrd;
88
89    /** Line control register. Not used for anything but reporting
90     * written value */
91    uint16_t lcrh;
92
93    /** interrupt fifo level register. Not used for anything but reporting
94     * written value */
95    uint16_t ifls;
96
97    BitUnion16(INTREG)
98        Bitfield<0> rimim;
99        Bitfield<1> ctsmim;
100        Bitfield<2> dcdmim;
101        Bitfield<3> dsrmim;
102        Bitfield<4> rxim;
103        Bitfield<5> txim;
104        Bitfield<6> rtim;
105        Bitfield<7> feim;
106        Bitfield<8> peim;
107        Bitfield<9> beim;
108        Bitfield<10> oeim;
109        Bitfield<15,11> rsvd;
110    EndBitUnion(INTREG)
111
112    /** interrupt mask register. */
113    INTREG imsc;
114
115    /** raw interrupt status register */
116    INTREG rawInt;
117
118    /** Masked interrupt status register */
119    INTREG maskInt;
120
121    /** Interrupt number to generate */
122    int intNum;
123
124    /** Gic to use for interrupting */
125    BaseGic *gic;
126
127    /** Should the simulation end on an EOT */
128    bool endOnEOT;
129
130    /** Delay before interrupting */
131    Tick intDelay;
132
133    /** Function to generate interrupt */
134    void generateInterrupt();
135
136    /** Wrapper to create an event out of the thing */
137    EventWrapper<Pl011, &Pl011::generateInterrupt> intEvent;
138
139  public:
140   typedef Pl011Params Params;
141   const Params *
142    params() const
143    {
144        return dynamic_cast<const Params *>(_params);
145    }
146    Pl011(const Params *p);
147
148    virtual Tick read(PacketPtr pkt);
149    virtual Tick write(PacketPtr pkt);
150
151    /**
152     * Inform the uart that there is data available.
153     */
154    virtual void dataAvailable();
155
156
157    /**
158     * Return if we have an interrupt pending
159     * @return interrupt status
160     * @todo fix me when implementation improves
161     */
162    virtual bool intStatus() { return false; }
163
164    virtual void serialize(std::ostream &os);
165    virtual void unserialize(Checkpoint *cp, const std::string &section);
166
167};
168
169#endif //__DEV_ARM_PL011_H__
170