pl111.hh revision 7753
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder.  You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: William Wang
38 */
39
40
41/** @file
42 * Implementiation of a PL111 CLCD controller
43 */
44
45#ifndef __DEV_ARM_PL111_HH__
46#define __DEV_ARM_PL111_HH__
47
48#include <fstream>
49
50#include "base/range.hh"
51#include "dev/arm/amba_device.hh"
52#include "params/Pl111.hh"
53#include "sim/serialize.hh"
54
55using namespace std;
56
57class Gic;
58
59class Pl111: public AmbaDmaDevice
60{
61  protected:
62    static const uint64_t AMBA_ID       = ULL(0xb105f00d00141111);
63    /** ARM PL111 register map*/
64    static const int LcdTiming0       = 0x000;
65    static const int LcdTiming1       = 0x004;
66    static const int LcdTiming2       = 0x008;
67    static const int LcdTiming3       = 0x00C;
68    static const int LcdUpBase        = 0x010;
69    static const int LcdLpBase        = 0x014;
70    static const int LcdControl       = 0x018;
71    static const int LcdImsc          = 0x01C;
72    static const int LcdRis           = 0x020;
73    static const int LcdMis           = 0x024;
74    static const int LcdIcr           = 0x028;
75    static const int LcdUpCurr        = 0x02C;
76    static const int LcdLpCurr        = 0x030;
77    static const int LcdPalette       = 0x200;
78    static const int CrsrImage        = 0x800;
79    static const int ClcdCrsrCtrl     = 0xC00;
80    static const int ClcdCrsrConfig   = 0xC04;
81    static const int ClcdCrsrPalette0 = 0xC08;
82    static const int ClcdCrsrPalette1 = 0xC0C;
83    static const int ClcdCrsrXY       = 0xC10;
84    static const int ClcdCrsrClip     = 0xC14;
85    static const int ClcdCrsrImsc     = 0xC20;
86    static const int ClcdCrsrIcr      = 0xC24;
87    static const int ClcdCrsrRis      = 0xC28;
88    static const int ClcdCrsrMis      = 0xC2C;
89
90    static const int LcdPaletteSize   = 128;
91    static const int CrsrImageSize    = 256;
92
93    static const int LcdMaxWidth      = 1024; // pixels per line
94    static const int LcdMaxHeight     = 768;  // lines per panel
95
96    static const int dmaSize            = 8;    // 64 bits
97    static const int maxOutstandingDma  = 16;   // 16 deep FIFO of 64 bits
98
99    BitUnion8(InterruptReg)
100    Bitfield<1> ffufie;
101    Bitfield<2> nbupie;
102    Bitfield<3> vtcpie;
103    Bitfield<4> ahmeie;
104    EndBitUnion(InterruptReg)
105
106    BitUnion32(TimingReg0)
107    Bitfield<7,2> ppl;
108    Bitfield<15,8> hsw;
109    Bitfield<23,16> hfp;
110    Bitfield<31,24> hbp;
111    EndBitUnion(TimingReg0)
112
113    BitUnion32(TimingReg1)
114    Bitfield<9,0> lpp;
115    Bitfield<15,10> vsw;
116    Bitfield<23,16> vfp;
117    Bitfield<31,24> vbp;
118    EndBitUnion(TimingReg1)
119
120    BitUnion32(TimingReg2)
121    Bitfield<4,0> pcdlo;
122    Bitfield<5> clksel;
123    Bitfield<10,6> acb;
124    Bitfield<11> avs;
125    Bitfield<12> ihs;
126    Bitfield<13> ipc;
127    Bitfield<14> ioe;
128    Bitfield<25,16> cpl;
129    Bitfield<26> bcd;
130    Bitfield<31,27> pcdhi;
131    EndBitUnion(TimingReg2)
132
133    BitUnion32(TimingReg3)
134    Bitfield<6,0> led;
135    Bitfield<16> lee;
136    EndBitUnion(TimingReg3)
137
138    BitUnion32(ControlReg)
139    Bitfield<0> lcden;
140    Bitfield<3,1> lcdbpp;
141    Bitfield<4> lcdbw;
142    Bitfield<5> lcdtft;
143    Bitfield<6> lcdmono8;
144    Bitfield<7> lcddual;
145    Bitfield<8> bgr;
146    Bitfield<9> bebo;
147    Bitfield<10> bepo;
148    Bitfield<11> lcdpwr;
149    Bitfield<13,12> lcdvcomp;
150    Bitfield<16> watermark;
151    EndBitUnion(ControlReg)
152
153    /** Horizontal axis panel control register */
154    TimingReg0 lcdTiming0;
155
156    /** Vertical axis panel control register */
157    TimingReg1 lcdTiming1;
158
159    /** Clock and signal polarity control register */
160    TimingReg2 lcdTiming2;
161
162    /** Line end control register */
163    TimingReg3 lcdTiming3;
164
165    /** Upper panel frame base address register */
166    int lcdUpbase;
167
168    /** Lower panel frame base address register */
169    int lcdLpbase;
170
171    /** Control register */
172    ControlReg lcdControl;
173
174    /** Interrupt mask set/clear register */
175    InterruptReg lcdImsc;
176
177    /** Raw interrupt status register - const */
178    InterruptReg lcdRis;
179
180    /** Masked interrupt status register */
181    InterruptReg lcdMis;
182
183    /** Interrupt clear register */
184    InterruptReg lcdIcr;
185
186    /** Upper panel current address value register - ro */
187    int lcdUpcurr;
188
189    /** Lower panel current address value register - ro */
190    int lcdLpcurr;
191
192    /** 256x16-bit color palette registers
193     * 256 palette entries organized as 128 locations of two entries per word */
194    int lcdPalette[LcdPaletteSize];
195
196    /** Cursor image RAM register
197     * 256-word wide values defining images overlaid by the hw cursor mechanism */
198    int cursorImage[CrsrImageSize];
199
200    /** Cursor control register */
201    int clcdCrsrCtrl;
202
203    /** Cursor configuration register */
204    int clcdCrsrConfig;
205
206    /** Cursor palette registers */
207    int clcdCrsrPalette0;
208    int clcdCrsrPalette1;
209
210    /** Cursor XY position register */
211    int clcdCrsrXY;
212
213    /** Cursor clip position register */
214    int clcdCrsrClip;
215
216    /** Cursor interrupt mask set/clear register */
217    InterruptReg clcdCrsrImsc;
218
219    /** Cursor interrupt clear register */
220    InterruptReg clcdCrsrIcr;
221
222    /** Cursor raw interrupt status register - const */
223    InterruptReg clcdCrsrRis;
224
225    /** Cursor masked interrupt status register - const */
226    InterruptReg clcdCrsrMis;
227
228    /** Clock speed */
229    Tick clock;
230
231    /** Frame buffer height - lines per panel */
232    uint16_t height;
233
234    /** Frame buffer width - pixels per line */
235    uint16_t width;
236
237    /** CLCDC supports up to 1024x768 */
238    uint8_t dmaBuffer[LcdMaxWidth * LcdMaxHeight * sizeof(uint32_t)];
239
240    /** Double buffering */
241    uint32_t frameBuffer[LcdMaxWidth * LcdMaxHeight];
242
243    /** Start time for frame buffer dma read */
244    Tick startTime;
245
246    /** Frame buffer base address */
247    Addr startAddr;
248
249    /** Frame buffer max address */
250    Addr maxAddr;
251
252    /** Frame buffer current address */
253    Addr curAddr;
254
255    /** DMA FIFO watermark */
256    int waterMark;
257
258    /** Number of pending dma reads */
259    int dmaPendingNum;
260
261    /** DMA framebuffer read */
262    void readFramebuffer();
263
264    /** Write framebuffer to a bmp file */
265    void writeBMP(uint32_t*);
266
267    /** Generate dma framebuffer read event */
268    void generateReadEvent();
269
270    /** Function to generate interrupt */
271    void generateInterrupt();
272
273    /** fillFIFO event */
274    void fillFifo();
275
276    /** DMA done event */
277    void dmaDone();
278
279    /** Next cycle event */
280    Tick nextCycle();
281    Tick nextCycle(Tick beginTick);
282
283    /** DMA framebuffer read event */
284    EventWrapper<Pl111, &Pl111::readFramebuffer> readEvent;
285
286    /** Fill fifo */
287    EventWrapper<Pl111, &Pl111::fillFifo> fillFifoEvent;
288
289    /** DMA done event */
290    vector<EventWrapper<Pl111, &Pl111::dmaDone> > dmaDoneEvent;
291
292    /** Wrapper to create an event out of the thing */
293    EventWrapper<Pl111, &Pl111::generateInterrupt> intEvent;
294
295  public:
296    typedef Pl111Params Params;
297
298    const Params *
299    params() const
300    {
301        return dynamic_cast<const Params *>(_params);
302    }
303    Pl111(const Params *p);
304
305    virtual Tick read(PacketPtr pkt);
306    virtual Tick write(PacketPtr pkt);
307
308    virtual void serialize(std::ostream &os);
309    virtual void unserialize(Checkpoint *cp, const std::string &section);
310
311    /** return the address ranges that this device responds to.
312     * @param range_list range list to populate with ranges
313     */
314    void addressRanges(AddrRangeList &range_list);
315
316    /**
317     * Return if we have an interrupt pending
318     * @return interrupt status
319     * @todo fix me when implementation improves
320     */
321    virtual bool intStatus() { return false; }
322};
323
324// write frame buffer into a bitmap picture
325class  Bitmap
326{
327  public:
328    Bitmap(std::fstream& bmp, uint16_t h, uint16_t w);
329
330  private:
331    struct Magic
332    {
333        unsigned char magic_number[2];
334    } magic;
335
336    struct Header
337    {
338        uint32_t size;
339        uint16_t reserved1;
340        uint16_t reserved2;
341        uint32_t offset;
342    } header;
343
344    struct Info
345    {
346        uint32_t Size;
347        uint32_t Width;
348        uint32_t Height;
349        uint16_t Planes;
350        uint16_t BitCount;
351        uint32_t Compression;
352        uint32_t SizeImage;
353        uint32_t XPelsPerMeter;
354        uint32_t YPelsPerMeter;
355        uint32_t ClrUsed;
356        uint32_t ClrImportant;
357    } info;
358
359    struct Color
360    {
361        unsigned char b;
362        unsigned char g;
363        unsigned char r;
364        unsigned char a;
365    } color;
366};
367
368#endif
369