2 * Copyright (c) 2010-2013 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: Chris Emmons
42 * Implementiation of the ARM HDLcd controller.
44 * This implementation aims to have sufficient detail such that underrun
45 * conditions are reasonable / behave similar to reality. There are two
46 * 'engines' going at once. First, the DMA engine running at LCD clock
47 * frequency is responsible for filling the controller's internal buffer.
48 * The second engine runs at the pixel clock frequency and reads the pixels
49 * out of the internal buffer. The pixel rendering engine uses front / back
50 * porch and sync delays between lines and frames.
52 * If the pixel rendering engine does not have a pixel to display, it will
53 * cause an underrun event. The HDLcd controller, per spec, will stop
54 * issuing DMA requests for the rest of the frame and resume normal behavior
55 * on the subsequent frame. What pixels are rendered upon an underrun
56 * condition is different than the real hardware; while the user will see
57 * artifacts (previous frame mixed with current frame), it is not the same
58 * behavior as real hardware which repeats the last pixel value for the rest
59 * of the current frame. This compromise was made to save on memory and
60 * complexity and assumes that it is not important to accurately model the
61 * content of an underrun frame.
64 * 1. The default kernel driver used in testing sets the line count to one
65 * less than the expected 768. However, it also sets the v_count to 767.
66 * The controller specifies that 1 should be added to v_count but does not
67 * specify adding 1 to the line count. The driver is probably wrong.
68 * However, to sync these two numbers up, this model uses fb_line_count and
69 * fb_line_length rather than using v_data or h_data values to determine the
70 * width and height of the frame; those values are ignored.
71 * 2. The HDLcd is implemented here as an AmbaDmaDevice, but it doesn't have
72 * an AMBA ID as far as I know. That is the only bit of the AmbaDmaDevice
73 * interface that is irrelevant to it, so a fake AMBA ID is used for now.
74 * I didn't think inserting an extra layer of hierachy between AmbaDmaDevice
75 * and DmaDevice would be helpful to anyone else, but that may be the right
77 * 3. The internal buffer size is either 1 or 2 KB depending on which
78 * specification is referenced for the different Versatile Express tiles.
79 * This implementation uses the larger 2 KB buffer by default.
82 #ifndef __DEV_ARM_HDLCD_HH__
83 #define __DEV_ARM_HDLCD_HH__
87 #include "dev/arm/amba_device.hh"
88 #include "params/HDLcd.hh"
89 #include "sim/serialize.hh"
94 class HDLcd: public AmbaDmaDevice
97 /** fake AMBA ID -- unused */
98 static const uint64_t AMBA_ID = ULL(0xb105f00d00141000);
100 /** ARM HDLcd register offsets */
101 enum RegisterOffset {
103 Int_RawStat = 0x0010,
108 Fb_Line_Length = 0x0104,
109 Fb_Line_Count = 0x0108,
110 Fb_Line_Pitch = 0x010C,
111 Bus_Options = 0x0110,
113 V_Back_Porch = 0x0204,
115 V_Front_Porch = 0x020C,
117 H_Back_Porch = 0x0214,
119 H_Front_Porch = 0x021C,
122 Pixel_Format = 0x0240,
124 Green_Select = 0x0248,
125 Blue_Select = 0x024C };
127 /** Reset value for Bus_Options register */
128 static const size_t BUS_OPTIONS_RESETV = 0x408;
130 /** Reset value for Version register */
131 static const size_t VERSION_RESETV = 0x1CDC0000;
133 /** max number of outstanding DMA requests possible */
134 static const size_t MAX_OUTSTANDING_DMA_REQ_CAPACITY = 16;
136 /** max number of beats delivered in one dma burst */
137 static const size_t MAX_BURST_LEN = 16;
139 /** size of internal buffer in bytes */
140 static const size_t PIXEL_BUFFER_CAPACITY = 2048;
142 /** AXI port width in bytes */
143 static const size_t AXI_PORT_WIDTH = 8;
146 * @name RegisterFieldLayouts
147 * Bit layout declarations for multi-field registers.
150 BitUnion32(VersionReg)
151 Bitfield<7,0> version_minor;
152 Bitfield<15,8> version_major;
153 Bitfield<31,16> product_id;
154 EndBitUnion(VersionReg)
156 BitUnion32(InterruptReg)
158 Bitfield<1> bus_error;
160 Bitfield<3> underrun;
161 EndBitUnion(InterruptReg)
163 BitUnion32(FbLineCountReg)
164 Bitfield<11,0> fb_line_count;
165 Bitfield<31,12> reserved_31_12;
166 EndBitUnion(FbLineCountReg)
168 BitUnion32(BusOptsReg)
169 Bitfield<4,0> burst_len;
170 Bitfield<7,5> reserved_7_5;
171 Bitfield<11,8> max_outstanding;
172 Bitfield<31,12> reserved_31_12;
173 EndBitUnion(BusOptsReg)
175 BitUnion32(TimingReg)
177 Bitfield<31,12> reserved_31_12;
178 EndBitUnion(TimingReg)
180 BitUnion32(PolaritiesReg)
181 Bitfield<0> vsync_polarity;
182 Bitfield<1> hsync_polarity;
183 Bitfield<2> dataen_polarity;
184 Bitfield<3> data_polarity;
185 Bitfield<4> pxlclk_polarity;
186 Bitfield<31,5> reserved_31_5;
187 EndBitUnion(PolaritiesReg)
189 BitUnion32(CommandReg)
191 Bitfield<31,1> reserved_31_1;
192 EndBitUnion(CommandReg)
194 BitUnion32(PixelFormatReg)
195 Bitfield<2,0> reserved_2_0;
196 Bitfield<4,3> bytes_per_pixel;
197 Bitfield<30,5> reserved_30_5;
198 Bitfield<31> big_endian;
199 EndBitUnion(PixelFormatReg)
201 BitUnion32(ColorSelectReg)
202 Bitfield<4,0> offset;
203 Bitfield<7,5> reserved_7_5;
205 Bitfield<15,12> reserved_15_12;
206 Bitfield<23,16> default_color;
207 Bitfield<31,24> reserved_31_24;
208 EndBitUnion(ColorSelectReg)
212 * @name HDLCDRegisters
213 * HDLCD register contents.
216 VersionReg version; /**< Version register */
217 InterruptReg int_rawstat; /**< Interrupt raw status register */
218 InterruptReg int_clear; /**< Interrupt clear register */
219 InterruptReg int_mask; /**< Interrupt mask register */
220 InterruptReg int_status; /**< Interrupt status register */
221 uint32_t fb_base; /**< Frame buffer base address register */
222 uint32_t fb_line_length; /**< Frame buffer Line length register */
223 FbLineCountReg fb_line_count; /**< Frame buffer Line count register */
224 uint32_t fb_line_pitch; /**< Frame buffer Line pitch register */
225 BusOptsReg bus_options; /**< Bus options register */
226 TimingReg v_sync; /**< Vertical sync width register */
227 TimingReg v_back_porch; /**< Vertical back porch width register */
228 TimingReg v_data; /**< Vertical data width register */
229 TimingReg v_front_porch; /**< Vertical front porch width register */
230 TimingReg h_sync; /**< Horizontal sync width register */
231 TimingReg h_back_porch; /**< Horizontal back porch width register */
232 TimingReg h_data; /**< Horizontal data width register */
233 TimingReg h_front_porch; /**< Horizontal front porch width reg */
234 PolaritiesReg polarities; /**< Polarities register */
235 CommandReg command; /**< Command register */
236 PixelFormatReg pixel_format; /**< Pixel format register */
237 ColorSelectReg red_select; /**< Red color select register */
238 ColorSelectReg green_select; /**< Green color select register */
239 ColorSelectReg blue_select; /**< Blue color select register */
242 /** Pixel clock period */
243 const Tick pixelClock;
248 /** Helper to write out bitmaps */
251 /** Picture of what the current frame buffer looks like */
255 * Event wrapper for dmaDone()
257 * This event call pushes its this pointer onto the freeDoneEvent vector
258 * and calls dmaDone() when triggered. While most of the time the burst
259 * length of a transaction will be the max burst length set by the driver,
260 * any trailing bytes must be handled with smaller lengths thus requiring
261 * the configurable burst length option.
263 class DmaDoneEvent : public Event
266 /** Reference to HDLCD that issued the corresponding DMA transaction */
269 /** Transaction size */
276 * @param _obj HDLCD that issued the corresponding DMA transaction
278 DmaDoneEvent(HDLcd *_obj)
279 : Event(), obj(*_obj), transSize(0) {}
282 * Sets the size of this transaction.
284 * @param len size of the transaction in bytes
286 void setTransactionSize(size_t len) {
291 * Gets the size of this transaction.
293 * @return size of this transaction in bytes
295 size_t getTransactionSize() const {
303 const std::string name() const {
304 return obj.name() + ".DmaDoneEvent";
308 /** Start time for frame buffer dma read */
309 Tick frameReadStartTime;
311 /** Starting address for the current frame */
314 /** Next address the dma should read from */
317 /** One byte past the address of the last byte the dma should read
321 /** Number of pending dma reads */
322 size_t dmaPendingNum;
324 /** Flag indicating whether current frame has underrun */
327 /** HDLcd virtual display buffer */
328 uint8_t *virtualDisplayBuffer;
330 /** Size of the pixel buffer */
331 size_t pixelBufferSize;
333 /** Index of the next pixel to render */
336 /** Flag indicating whether video parameters need updating */
339 /** Flag indicating whether a frame read / display is in progress */
343 * Number of bytes in flight from DMA that have not reached the pixel
346 uint32_t dmaBytesInFlight;
349 * Gets the number of oustanding DMA transactions allowed on the bus at a
352 * @return gets the driver-specified number of outstanding DMA transactions
353 * from the hdlcd controller that are allowed on the bus at a time
355 inline uint16_t maxOutstandingDma() const {
356 return bus_options.max_outstanding;
360 * Gets the number of bytes free in the pixel buffer.
362 * @return number of bytes free in the internal pixel buffer
364 inline uint32_t bytesFreeInPixelBuffer() const {
365 return PIXEL_BUFFER_CAPACITY - (pixelBufferSize + dmaBytesInFlight);
369 * Gets the number of beats-per-burst for bus transactions.
371 * @return number of beats-per-burst per HDLcd DMA transaction
373 inline size_t dmaBurstLength() const {
374 assert(bus_options.burst_len <= MAX_BURST_LEN);
375 return bus_options.burst_len;
379 * Gets the number of bytes per pixel.
381 * @return bytes per pixel
383 inline size_t bytesPerPixel() const {
384 return pixel_format.bytes_per_pixel + 1;
388 * Gets frame buffer width.
390 * @return frame buffer width (pixels per line)
392 inline size_t width() const {
393 return fb_line_length / bytesPerPixel();
397 * Gets frame buffer height.
399 * @return frame buffer height (lines per panel)
401 inline size_t height() const {
402 return fb_line_count.fb_line_count;
406 * Gets the total number of pixel clocks per display line.
408 * @return number of pixel clocks per display line including porch delays
409 * and horizontal sync time
411 inline uint64_t PClksPerLine() const {
412 return h_back_porch.val + 1 +
414 h_front_porch.val + 1 +
418 /** Send updated parameters to the vnc server */
419 void updateVideoParams(bool unserializing);
421 /** Generates an interrupt */
422 void generateInterrupt();
424 /** Start reading the next frame */
427 /** End of frame reached */
430 /** Generate DMA read requests from frame buffer into pixel buffer */
431 void fillPixelBuffer();
433 /** DMA done event */
434 void dmaDone(DmaDoneEvent *event);
436 /** Called when it is time to render a pixel */
439 /** Start of frame event */
440 EventWrapper<HDLcd, &HDLcd::startFrame> startFrameEvent;
442 /** End of frame event */
443 EventWrapper<HDLcd, &HDLcd::endFrame> endFrameEvent;
445 /** Pixel render event */
446 EventWrapper<HDLcd, &HDLcd::renderPixel> renderPixelEvent;
449 EventWrapper<HDLcd, &HDLcd::fillPixelBuffer> fillPixelBufferEvent;
451 /** Wrapper to create an event out of the interrupt */
452 EventWrapper<HDLcd, &HDLcd::generateInterrupt> intEvent;
456 * All pre-allocated DMA done events
458 * The HDLCD model preallocates maxOutstandingDma() number of
459 * DmaDoneEvents to avoid having to heap allocate every single
460 * event when it is needed. In order to keep track of which events
461 * are in flight and which are ready to be used, we use two
462 * different vectors. dmaDoneEventAll contains <i>all</i>
463 * DmaDoneEvents that the object may use, while dmaDoneEventFree
464 * contains a list of currently <i>unused</i> events. When an
465 * event needs to be scheduled, the last element of the
466 * dmaDoneEventFree is used and removed from the list. When an
467 * event fires, it is added to the end of the
468 * dmaEventFreeList. dmaDoneEventAll is never used except for in
469 * initialization and serialization.
471 std::vector<DmaDoneEvent> dmaDoneEventAll;
473 /** Unused DMA done events that are ready to be scheduled */
474 std::vector<DmaDoneEvent *> dmaDoneEventFree;
480 typedef HDLcdParams Params;
485 return dynamic_cast<const Params *>(_params);
487 HDLcd(const Params *p);
490 virtual Tick read(PacketPtr pkt);
491 virtual Tick write(PacketPtr pkt);
493 virtual void serialize(std::ostream &os);
494 virtual void unserialize(Checkpoint *cp, const std::string §ion);
497 * Determine the address ranges that this device responds to.
499 * @return a list of non-overlapping address ranges
501 AddrRangeList getAddrRanges() const;