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