2 * Copyright (c) 2010-2012, 2015 ARM Limited
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.
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.
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.
37 * Authors: William Wang
43 * Implementiation of a PL111 CLCD controller
46 #ifndef __DEV_ARM_PL111_HH__
47 #define __DEV_ARM_PL111_HH__
52 #include "base/bmpwriter.hh"
53 #include "base/framebuffer.hh"
54 #include "base/output.hh"
55 #include "dev/arm/amba_device.hh"
56 #include "params/Pl111.hh"
57 #include "sim/serialize.hh"
61 class Pl111: public AmbaDmaDevice
64 static const uint64_t AMBA_ID = ULL(0xb105f00d00141111);
65 /** ARM PL111 register map*/
66 static const int LcdTiming0 = 0x000;
67 static const int LcdTiming1 = 0x004;
68 static const int LcdTiming2 = 0x008;
69 static const int LcdTiming3 = 0x00C;
70 static const int LcdUpBase = 0x010;
71 static const int LcdLpBase = 0x014;
72 static const int LcdControl = 0x018;
73 static const int LcdImsc = 0x01C;
74 static const int LcdRis = 0x020;
75 static const int LcdMis = 0x024;
76 static const int LcdIcr = 0x028;
77 static const int LcdUpCurr = 0x02C;
78 static const int LcdLpCurr = 0x030;
79 static const int LcdPalette = 0x200;
80 static const int CrsrImage = 0x800;
81 static const int ClcdCrsrCtrl = 0xC00;
82 static const int ClcdCrsrConfig = 0xC04;
83 static const int ClcdCrsrPalette0 = 0xC08;
84 static const int ClcdCrsrPalette1 = 0xC0C;
85 static const int ClcdCrsrXY = 0xC10;
86 static const int ClcdCrsrClip = 0xC14;
87 static const int ClcdCrsrImsc = 0xC20;
88 static const int ClcdCrsrIcr = 0xC24;
89 static const int ClcdCrsrRis = 0xC28;
90 static const int ClcdCrsrMis = 0xC2C;
92 static const int LcdPaletteSize = 128;
93 static const int CrsrImageSize = 256;
95 static const int LcdMaxWidth = 1024; // pixels per line
96 static const int LcdMaxHeight = 768; // lines per panel
98 static const int dmaSize = 8; // 64 bits
99 static const int maxOutstandingDma = 16; // 16 deep FIFO of 64 bits
101 static const int buffer_size = LcdMaxWidth * LcdMaxHeight * sizeof(uint32_t);
114 BitUnion8(InterruptReg)
115 Bitfield<1> underflow;
116 Bitfield<2> baseaddr;
118 Bitfield<4> ahbmaster;
119 EndBitUnion(InterruptReg)
121 BitUnion32(TimingReg0)
126 EndBitUnion(TimingReg0)
128 BitUnion32(TimingReg1)
133 EndBitUnion(TimingReg1)
135 BitUnion32(TimingReg2)
145 Bitfield<31,27> pcdhi;
146 EndBitUnion(TimingReg2)
148 BitUnion32(TimingReg3)
151 EndBitUnion(TimingReg3)
153 BitUnion32(ControlReg)
155 Bitfield<3,1> lcdbpp;
158 Bitfield<6> lcdmono8;
164 Bitfield<13,12> lcdvcomp;
165 Bitfield<16> watermark;
166 EndBitUnion(ControlReg)
169 * Event wrapper for dmaDone()
171 * This event calls pushes its this pointer onto the freeDoneEvent
172 * vector and calls dmaDone() when triggered.
174 class DmaDoneEvent : public Event
180 DmaDoneEvent(Pl111 *_obj)
181 : Event(), obj(*_obj) {}
184 obj.dmaDoneEventFree.push_back(this);
188 const std::string name() const {
189 return obj.name() + ".DmaDoneEvent";
193 /** Horizontal axis panel control register */
194 TimingReg0 lcdTiming0;
196 /** Vertical axis panel control register */
197 TimingReg1 lcdTiming1;
199 /** Clock and signal polarity control register */
200 TimingReg2 lcdTiming2;
202 /** Line end control register */
203 TimingReg3 lcdTiming3;
205 /** Upper panel frame base address register */
208 /** Lower panel frame base address register */
211 /** Control register */
212 ControlReg lcdControl;
214 /** Interrupt mask set/clear register */
215 InterruptReg lcdImsc;
217 /** Raw interrupt status register - const */
220 /** Masked interrupt status register */
223 /** 256x16-bit color palette registers
224 * 256 palette entries organized as 128 locations of two entries per word */
225 uint32_t lcdPalette[LcdPaletteSize];
227 /** Cursor image RAM register
228 * 256-word wide values defining images overlaid by the hw cursor mechanism */
229 uint32_t cursorImage[CrsrImageSize];
231 /** Cursor control register */
232 uint32_t clcdCrsrCtrl;
234 /** Cursor configuration register */
235 uint32_t clcdCrsrConfig;
237 /** Cursor palette registers */
238 uint32_t clcdCrsrPalette0;
239 uint32_t clcdCrsrPalette1;
241 /** Cursor XY position register */
244 /** Cursor clip position register */
245 uint32_t clcdCrsrClip;
247 /** Cursor interrupt mask set/clear register */
248 InterruptReg clcdCrsrImsc;
250 /** Cursor interrupt clear register */
251 InterruptReg clcdCrsrIcr;
253 /** Cursor raw interrupt status register - const */
254 InterruptReg clcdCrsrRis;
256 /** Cursor masked interrupt status register - const */
257 InterruptReg clcdCrsrMis;
262 PixelConverter converter;
268 /** Helper to write out bitmaps */
271 /** Picture of what the current frame buffer looks like */
274 /** Frame buffer width - pixels per line */
277 /** Frame buffer height - lines per panel */
280 /** Bytes per pixel */
281 uint8_t bytesPerPixel;
283 /** CLCDC supports up to 1024x768 */
286 /** Start time for frame buffer dma read */
289 /** Frame buffer base address */
292 /** Frame buffer max address */
295 /** Frame buffer current address */
298 /** DMA FIFO watermark */
301 /** Number of pending dma reads */
302 uint32_t dmaPendingNum;
304 PixelConverter pixelConverter() const;
306 /** Send updated parameters to the vnc server */
307 void updateVideoParams();
309 /** DMA framebuffer read */
310 void readFramebuffer();
312 /** Generate dma framebuffer read event */
313 void generateReadEvent();
315 /** Function to generate interrupt */
316 void generateInterrupt();
318 /** fillFIFO event */
321 /** start the dmas off after power is enabled */
324 /** DMA done event */
327 /** DMA framebuffer read event */
328 EventFunctionWrapper readEvent;
331 EventFunctionWrapper fillFifoEvent;
335 * All pre-allocated DMA done events
337 * The PL111 model preallocates maxOutstandingDma number of
338 * DmaDoneEvents to avoid having to heap allocate every single
339 * event when it is needed. In order to keep track of which events
340 * are in flight and which are ready to be used, we use two
341 * different vectors. dmaDoneEventAll contains <i>all</i>
342 * DmaDoneEvents that the object may use, while dmaDoneEventFree
343 * contains a list of currently <i>unused</i> events. When an
344 * event needs to be scheduled, the last element of the
345 * dmaDoneEventFree is used and removed from the list. When an
346 * event fires, it is added to the end of the
347 * dmaEventFreeList. dmaDoneEventAll is never used except for in
348 * initialization and serialization.
350 std::vector<DmaDoneEvent> dmaDoneEventAll;
352 /** Unused DMA done events that are ready to be scheduled */
353 std::vector<DmaDoneEvent *> dmaDoneEventFree;
356 /** Wrapper to create an event out of the interrupt */
357 EventFunctionWrapper intEvent;
362 typedef Pl111Params Params;
367 return dynamic_cast<const Params *>(_params);
369 Pl111(const Params *p);
372 Tick read(PacketPtr pkt) override;
373 Tick write(PacketPtr pkt) override;
375 void serialize(CheckpointOut &cp) const override;
376 void unserialize(CheckpointIn &cp) override;
379 * Determine the address ranges that this device responds to.
381 * @return a list of non-overlapping address ranges
383 AddrRangeList getAddrRanges() const override;