hdlcd.cc revision 9648:f10eb34e3e38
1/*
2 * Copyright (c) 2010-2013 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: Chris Emmons
38 */
39
40#include "base/vnc/vncinput.hh"
41#include "base/bitmap.hh"
42#include "base/output.hh"
43#include "base/trace.hh"
44#include "debug/HDLcd.hh"
45#include "debug/Uart.hh"
46#include "dev/arm/amba_device.hh"
47#include "dev/arm/base_gic.hh"
48#include "dev/arm/hdlcd.hh"
49#include "mem/packet.hh"
50#include "mem/packet_access.hh"
51#include "sim/system.hh"
52
53using std::vector;
54
55
56// initialize hdlcd registers
57HDLcd::HDLcd(const Params *p)
58    : AmbaDmaDevice(p), version(VERSION_RESETV),
59      int_rawstat(0), int_clear(0), int_mask(0), int_status(0),
60      fb_base(0), fb_line_length(0), fb_line_count(0), fb_line_pitch(0),
61      bus_options(BUS_OPTIONS_RESETV),
62      v_sync(0), v_back_porch(0), v_data(0), v_front_porch(0),
63      h_sync(0), h_back_porch(0), h_data(0), h_front_porch(0),
64      polarities(0), command(0), pixel_format(0),
65      red_select(0), green_select(0), blue_select(0),
66      pixelClock(p->pixel_clock), vnc(p->vnc), bmp(NULL), pic(NULL),
67      frameReadStartTime(0),
68      dmaStartAddr(0), dmaCurAddr(0), dmaMaxAddr(0), dmaPendingNum(0),
69      frameUnderrun(false), virtualDisplayBuffer(NULL), pixelBufferSize(0),
70      pixelIndex(0), doUpdateParams(false), frameUnderway(false),
71      dmaBytesInFlight(0),
72      startFrameEvent(this), endFrameEvent(this), renderPixelEvent(this),
73      fillPixelBufferEvent(this), intEvent(this),
74      dmaDoneEventAll(MAX_OUTSTANDING_DMA_REQ_CAPACITY, this),
75      dmaDoneEventFree(MAX_OUTSTANDING_DMA_REQ_CAPACITY)
76{
77    pioSize = 0xFFFF;
78
79    for (int i = 0; i < MAX_OUTSTANDING_DMA_REQ_CAPACITY; ++i)
80        dmaDoneEventFree[i] = &dmaDoneEventAll[i];
81
82    if (vnc)
83        vnc->setFramebufferAddr(NULL);
84}
85
86HDLcd::~HDLcd()
87{
88    if (virtualDisplayBuffer)
89        delete [] virtualDisplayBuffer;
90}
91
92// read registers and frame buffer
93Tick
94HDLcd::read(PacketPtr pkt)
95{
96    uint32_t data = 0;
97    const Addr daddr = pkt->getAddr() - pioAddr;
98
99    DPRINTF(HDLcd, "read register BASE+0x%04x size=%d\n", daddr,
100            pkt->getSize());
101
102    assert(pkt->getAddr() >= pioAddr &&
103            pkt->getAddr() < pioAddr + pioSize &&
104            pkt->getSize() == 4);
105
106    pkt->allocate();
107
108    switch (daddr) {
109      case Version:
110        data = version;
111        break;
112      case Int_RawStat:
113        data = int_rawstat;
114        break;
115      case Int_Clear:
116        panic("HDLCD INT_CLEAR register is Write-Only\n");
117        break;
118      case Int_Mask:
119        data = int_mask;
120        break;
121      case Int_Status:
122        data = int_status;
123        break;
124      case Fb_Base:
125        data = fb_base;
126        break;
127      case Fb_Line_Length:
128        data = fb_line_length;
129        break;
130      case Fb_Line_Count:
131        data = fb_line_count;
132        break;
133      case Fb_Line_Pitch:
134        data = fb_line_pitch;
135        break;
136      case Bus_Options:
137        data = bus_options;
138        break;
139      case V_Sync:
140        data = v_sync;
141        break;
142      case V_Back_Porch:
143        data = v_back_porch;
144        break;
145      case V_Data:
146        data = v_data;
147        break;
148      case V_Front_Porch:
149        data = v_front_porch;
150        break;
151      case H_Sync:
152        data = h_sync;
153        break;
154      case H_Back_Porch:
155        data = h_back_porch;
156        break;
157      case H_Data:
158        data = h_data;
159        break;
160      case H_Front_Porch:
161        data = h_front_porch;
162        break;
163      case Polarities:
164        data = polarities;
165        break;
166      case Command:
167        data = command;
168        break;
169      case Pixel_Format:
170        data = pixel_format;
171        break;
172      case Red_Select:
173        data = red_select;
174        break;
175      case Green_Select:
176        data = green_select;
177        break;
178      case Blue_Select:
179        data = blue_select;
180        break;
181      default:
182        panic("Tried to read HDLCD register that doesn't  exist\n", daddr);
183        break;
184    }
185
186    pkt->set<uint32_t>(data);
187    pkt->makeAtomicResponse();
188    return pioDelay;
189}
190
191// write registers and frame buffer
192Tick
193HDLcd::write(PacketPtr pkt)
194{
195    assert(pkt->getAddr() >= pioAddr &&
196           pkt->getAddr() < pioAddr + pioSize &&
197           pkt->getSize() == 4);
198
199    const uint32_t data = pkt->get<uint32_t>();
200    const Addr daddr = pkt->getAddr() - pioAddr;
201
202    DPRINTF(HDLcd, "write register BASE+%0x04x <= 0x%08x\n", daddr,
203            pkt->get<uint32_t>());
204
205    switch (daddr) {
206      case Version:
207        panic("HDLCD VERSION register is read-Only\n");
208        break;
209      case Int_RawStat:
210        int_rawstat = data;
211        break;
212      case Int_Clear:
213        int_clear = data;
214        break;
215      case Int_Mask:
216        int_mask = data;
217        break;
218      case Int_Status:
219        panic("HDLCD INT_STATUS register is read-Only\n");
220        break;
221      case Fb_Base:
222        fb_base = data;
223        DPRINTF(HDLcd, "HDLCD Frame Buffer located at addr 0x%08x\n", fb_base);
224        break;
225      case Fb_Line_Length:
226        fb_line_length = data;
227        DPRINTF(HDLcd, "HDLCD res = %d x %d\n", width(), height());
228        break;
229      case Fb_Line_Count:
230        fb_line_count = data;
231        DPRINTF(HDLcd, "HDLCD res = %d x %d\n", width(), height());
232        break;
233      case Fb_Line_Pitch:
234        fb_line_pitch = data;
235        break;
236      case Bus_Options: {
237        BusOptsReg old_bus_options;
238        old_bus_options = bus_options;
239        bus_options = data;
240        if (bus_options.max_outstanding != old_bus_options.max_outstanding)
241            DPRINTF(HDLcd,
242                "Changing HDLcd outstanding dma transactions from %d to %d\n",
243                old_bus_options.max_outstanding, bus_options.max_outstanding);
244        if (bus_options.burst_len != old_bus_options.burst_len)
245            DPRINTF(HDLcd,
246                "Changing HDLcd dma burst length from %d bytes to %d bytes\n",
247                old_bus_options.burst_len, bus_options.burst_len); }
248        break;
249      case V_Sync:
250        v_sync = data;
251        break;
252      case V_Back_Porch:
253        v_back_porch = data;
254        break;
255      case V_Data:
256        v_data = data;
257        break;
258      case V_Front_Porch:
259        v_front_porch = data;
260        break;
261      case H_Sync:
262        h_sync = data;
263        break;
264      case H_Back_Porch:
265        h_back_porch = data;
266        break;
267      case H_Data:
268        h_data = data;
269        break;
270      case H_Front_Porch:
271        h_front_porch = data;
272        break;
273      case Polarities:
274        polarities = data;
275        break;
276      case Command: {
277        CommandReg new_command;
278        new_command = data;
279        if (new_command.enable != command.enable) {
280            DPRINTF(HDLcd, "HDLCD switched %s\n",
281                    new_command.enable==0 ? "off" : "on");
282            if (new_command.enable) {
283                doUpdateParams = true;
284                if (!frameUnderway) {
285                    schedule(startFrameEvent, clockEdge());
286                }
287            }
288        }
289        command = new_command; }
290        break;
291      case Pixel_Format:
292        pixel_format = data;
293        DPRINTF(HDLcd, "HDLCD res = %d x %d\n", width(), height());
294        DPRINTF(HDLcd, "HDLCD bytes per pixel = %d\n", bytesPerPixel());
295        DPRINTF(HDLcd, "HDLCD endianness = %s\n",
296                pixel_format.big_endian ? "big" : "little");
297        break;
298      case Red_Select:
299        red_select = data;
300        break;
301      case Green_Select:
302        green_select = data;
303        break;
304      case Blue_Select:
305        blue_select = data;
306        break;
307      default:
308        panic("Tried to write HDLCD register that doesn't exist\n", daddr);
309        break;
310    }
311
312    pkt->makeAtomicResponse();
313    return pioDelay;
314}
315
316void
317HDLcd::updateVideoParams(bool unserializing = false)
318{
319    const uint16_t bpp = bytesPerPixel() << 3;
320    const size_t buffer_size = bytesPerPixel() * width() * height();
321
322    // updating these parameters while LCD is enabled is not supported
323    if (frameUnderway && !unserializing)
324        panic("Attempting to change some HDLCD parameters while the controller"
325                " is active is not allowed");
326
327    // resize the virtualDisplayBuffer unless we are unserializing - it may
328    //   have changed size
329    // there must be no outstanding DMA transactions for this to work
330    if (!unserializing) {
331        assert(dmaPendingNum == 0);
332        if (virtualDisplayBuffer)
333            delete [] virtualDisplayBuffer;
334        virtualDisplayBuffer = new uint8_t[buffer_size];
335        memset(virtualDisplayBuffer, 0, buffer_size);
336    }
337
338    assert(virtualDisplayBuffer);
339    if (vnc)
340        vnc->setFramebufferAddr(virtualDisplayBuffer);
341
342    if (bmp)
343        delete bmp;
344
345    DPRINTF(HDLcd, "bpp = %d\n", bpp);
346    DPRINTF(HDLcd, "display size = %d x %d\n", width(), height());
347#if TRACING_ON
348    const size_t totalLinesPerFrame = v_back_porch.val + 1 +
349                                      v_data.val + 1 +
350                                      v_front_porch.val + 1 +
351                                      v_sync.val + 1;
352    const double fps = (double)SimClock::Frequency /
353            (double)(PClksPerLine() * totalLinesPerFrame * pixelClock);
354#endif
355    DPRINTF(HDLcd, "simulated refresh rate ~ %.1ffps generating ~ %.1fMB/s "
356            "traffic ([%.1fMHz, T=%d sim clocks] pclk, %d bpp => %.1fMB/s peak requirement)\n",
357            fps,
358            fps * buffer_size / 1024 / 1024,
359            (double)SimClock::Frequency / pixelClock / 1000000.0,
360            pixelClock,
361            bpp,
362            (double)(SimClock::Frequency / pixelClock * (bpp / 8)) / 1024 / 1024);
363
364    if (pixel_format.big_endian)
365        panic("Big Endian pixel format not implemented by HDLcd controller");
366
367    if (vnc) {
368        if ((bpp == 24) &&
369                (red_select.size == 8) &&
370                (blue_select.size == 8) &&
371                (green_select.size == 8) &&
372                (green_select.offset == 8)) {
373            if ((blue_select.offset == 0) &&
374                    (red_select.offset == 16)) {
375                vnc->setFrameBufferParams(VideoConvert::rgb8888, width(),
376                        height());
377                bmp = new Bitmap(VideoConvert::rgb8888, width(), height(),
378                        virtualDisplayBuffer);
379                DPRINTF(HDLcd, "color mode:  rgb888\n");
380            } else if ((red_select.offset == 0) &&
381                    (blue_select.offset == 16)) {
382                vnc->setFrameBufferParams(VideoConvert::bgr8888, width(),
383                        height());
384                bmp = new Bitmap(VideoConvert::bgr8888, width(), height(),
385                        virtualDisplayBuffer);
386                DPRINTF(HDLcd, "color mode:  bgr888\n");
387            }
388        } else if ((bpp == 16) &&
389                (red_select.size == 5) &&
390                (blue_select.size == 5) &&
391                (green_select.size == 6) &&
392                (green_select.offset == 5)) {
393            if ((blue_select.offset == 0) &&
394                    (red_select.offset == 11)) {
395                vnc->setFrameBufferParams(VideoConvert::rgb565, width(),
396                        height());
397                bmp = new Bitmap(VideoConvert::rgb565, width(), height(),
398                        virtualDisplayBuffer);
399                DPRINTF(HDLcd, "color mode:  rgb565\n");
400            } else if ((red_select.offset == 0) &&
401                    (blue_select.offset == 11)) {
402                vnc->setFrameBufferParams(VideoConvert::bgr565, width(),
403                        height());
404                bmp = new Bitmap(VideoConvert::bgr565, width(), height(),
405                        virtualDisplayBuffer);
406                DPRINTF(HDLcd, "color mode:  bgr565\n");
407            }
408        } else {
409            DPRINTF(HDLcd, "color mode:  undefined\n");
410            panic("Unimplemented video mode\n");
411        }
412    }
413}
414
415void
416HDLcd::startFrame()
417{
418    // 0. Check that we are in the appropriate state
419    assert(!frameUnderway);
420    if (!command.enable)
421        return;
422    DPRINTF(HDLcd, "Frame read started\n");
423    if (doUpdateParams) {
424        updateVideoParams();
425        doUpdateParams = false;
426    }
427    frameUnderway = true;
428    assert(virtualDisplayBuffer);
429    assert(pixelBufferSize == 0);
430    assert(dmaBytesInFlight == 0);
431    assert(dmaPendingNum == 0);
432    assert(dmaDoneEventFree.size() == dmaDoneEventAll.size());
433    assert(!renderPixelEvent.scheduled());
434    // currently only support positive line pitches equal to the line length
435    assert(width() * bytesPerPixel() == fb_line_pitch);
436
437    // 1. Start DMA'ing the frame; subsequent transactions created as we go
438    dmaCurAddr = dmaStartAddr = fb_base;
439    dmaMaxAddr = static_cast<Addr>(width() * height() * bytesPerPixel()) +
440                    dmaCurAddr;
441    frameReadStartTime = curTick();
442    pixelIndex = 0;
443    frameUnderrun = false;
444    fillPixelBuffer();
445
446    // 2. Schedule first pixelclock read; subsequent reads generated as we go
447    Tick firstPixelReadTick = curTick() + pixelClock * (
448                                  PClksPerLine() * (v_sync.val + 1 +
449                                                    v_back_porch.val + 1) +
450                                  h_sync.val + 1 +
451                                  h_back_porch.val + 1);
452    schedule(renderPixelEvent, firstPixelReadTick);
453}
454
455void
456HDLcd::fillPixelBuffer()
457{
458    // - am I under the LCD dma transaction total?
459    // - do I have more data to transfer?
460    // - have I not yet underrun for this frame?
461    // - is there room to put the data in the pixel buffer including any
462    //   outstanding dma transfers in flight?
463    while ((dmaPendingNum < maxOutstandingDma()) &&
464           (dmaMaxAddr > dmaCurAddr) &&
465           !frameUnderrun &&
466           bytesFreeInPixelBuffer() > dmaBurstLength() * AXI_PORT_WIDTH) {
467        // try largest transaction size allowed first but switch to smaller
468        // sizes for trailing bytes
469        size_t transaction_size = dmaBurstLength() * AXI_PORT_WIDTH;
470        while (transaction_size > (dmaMaxAddr - dmaCurAddr))
471            transaction_size >>= 1;
472        assert(transaction_size > 0);
473
474        // concurrent dma reads need different dma done events
475        // due to assertion in scheduling state
476        ++dmaPendingNum;
477
478        assert(!dmaDoneEventFree.empty());
479        DmaDoneEvent *event(dmaDoneEventFree.back());
480        dmaDoneEventFree.pop_back();
481        assert(event);
482        assert(!event->scheduled());
483
484        // We use a uncachable request here because the requests from the CPU
485        // will be uncacheable as well. If we have uncacheable and cacheable
486        // requests in the memory system for the same address it won't be
487        // pleased
488        event->setTransactionSize(transaction_size);
489        dmaPort.dmaAction(MemCmd::ReadReq, dmaCurAddr, transaction_size, event,
490                          virtualDisplayBuffer + dmaCurAddr - dmaStartAddr,
491                          0, Request::UNCACHEABLE);
492        dmaCurAddr += transaction_size;
493        dmaBytesInFlight += transaction_size;
494    }
495}
496
497void
498HDLcd::renderPixel()
499{
500    // try to handle multiple pixels at a time; doing so reduces the accuracy
501    //   of the underrun detection but lowers simulation overhead
502    const size_t count = 32;
503    assert(width() % count == 0); // not set up to handle trailing pixels
504
505    // have we underrun on this frame anytime before?
506    if (frameUnderrun) {
507        // the LCD controller gives up on a frame if an underrun occurs and
508        //   resumes regular operation on the next frame
509        pixelBufferSize = 0;
510    } else {
511        // did we underrun on this set of pixels?
512        if (pixelBufferSize < bytesPerPixel() * count) {
513            warn("HDLcd controller buffer underrun\n");
514            frameUnderrun = true;
515            int_rawstat.underrun = 1;
516            if (!intEvent.scheduled())
517                schedule(intEvent, clockEdge());
518        } else {
519            // emulate the pixel read from the internal buffer
520            pixelBufferSize -= bytesPerPixel() * count;
521        }
522    }
523
524    // the DMA may have previously stalled due to the buffer being full;
525    //   give it a kick; it knows not to fill if at end of frame, underrun, etc
526    if (!fillPixelBufferEvent.scheduled())
527        schedule(fillPixelBufferEvent, clockEdge());
528
529    // schedule the next pixel read according to where it is in the frame
530    pixelIndex += count;
531    assert(pixelIndex <= width() * height());
532    size_t x = pixelIndex % width();
533    Tick nextEventTick = curTick();
534    if (x == 0) {
535        // start of new line
536        nextEventTick += pixelClock * ((h_front_porch.val + 1) +
537                                       (h_back_porch.val + 1) +
538                                       (h_sync.val + 1));
539        if (pixelIndex == width() * height()) {
540            // end of frame
541            nextEventTick += PClksPerLine() * (v_front_porch.val + 1) *
542                             pixelClock;
543            schedule(endFrameEvent, nextEventTick);
544            return;
545        }
546    } else {
547        nextEventTick += pixelClock * count;
548    }
549
550    schedule(renderPixelEvent, nextEventTick);
551}
552
553void
554HDLcd::endFrame() {
555    assert(pixelBufferSize == 0);
556    assert(dmaPendingNum == 0);
557    assert(dmaBytesInFlight == 0);
558    assert(dmaDoneEventFree.size() == dmaDoneEventAll.size());
559
560    if (vnc)
561        vnc->setDirty();
562
563    if (!pic)
564        pic = simout.create(csprintf("%s.framebuffer.bmp", sys->name()), true);
565
566    assert(bmp);
567    assert(pic);
568    pic->seekp(0);
569    bmp->write(pic);
570
571    // start the next frame
572    frameUnderway = false;
573    startFrame();
574}
575
576void
577HDLcd::dmaDone(DmaDoneEvent *event)
578{
579    const size_t transactionLength = event->getTransactionSize();
580    assert(pixelBufferSize + transactionLength < PIXEL_BUFFER_CAPACITY);
581    assert(dmaCurAddr <= dmaMaxAddr);
582
583    dmaDoneEventFree.push_back(event);
584    --dmaPendingNum;
585    assert(MAX_OUTSTANDING_DMA_REQ_CAPACITY - dmaDoneEventFree.size() ==
586            dmaPendingNum);
587
588    // add the data to the pixel buffer
589    dmaBytesInFlight -= transactionLength;
590    pixelBufferSize += transactionLength;
591
592    // schedule another dma transaction if:
593    // - we're not done reading the frame
594    // - there is sufficient room in the pixel buffer for another transaction
595    // - another fillPixelBufferEvent is not already scheduled
596    const size_t targetTransSize = dmaBurstLength() * AXI_PORT_WIDTH;
597    if ((dmaCurAddr < dmaMaxAddr) &&
598        (bytesFreeInPixelBuffer() + targetTransSize < PIXEL_BUFFER_CAPACITY) &&
599        !fillPixelBufferEvent.scheduled()) {
600        schedule(fillPixelBufferEvent, clockEdge());
601    }
602}
603
604void
605HDLcd::serialize(std::ostream &os)
606{
607    DPRINTF(HDLcd, "Serializing ARM HDLCD\n");
608
609    const uint32_t version_serial = version;
610    SERIALIZE_SCALAR(version_serial);
611    const uint32_t int_rawstat_serial = int_rawstat;
612    SERIALIZE_SCALAR(int_rawstat_serial);
613    const uint32_t int_clear_serial = int_clear;
614    SERIALIZE_SCALAR(int_clear_serial);
615    const uint32_t int_mask_serial = int_mask;
616    SERIALIZE_SCALAR(int_mask_serial);
617    const uint32_t int_status_serial = int_status;
618    SERIALIZE_SCALAR(int_status_serial);
619
620    SERIALIZE_SCALAR(fb_base);
621    SERIALIZE_SCALAR(fb_line_length);
622
623    const uint32_t fb_line_count_serial = fb_line_count;
624    SERIALIZE_SCALAR(fb_line_count_serial);
625
626    SERIALIZE_SCALAR(fb_line_pitch);
627
628    const uint32_t bus_options_serial = bus_options;
629    SERIALIZE_SCALAR(bus_options_serial);
630    const uint32_t v_sync_serial = v_sync;
631    SERIALIZE_SCALAR(v_sync_serial);
632    const uint32_t v_back_porch_serial = v_back_porch;
633    SERIALIZE_SCALAR(v_back_porch_serial);
634    const uint32_t v_data_serial = v_data;
635    SERIALIZE_SCALAR(v_data_serial);
636    const uint32_t v_front_porch_serial = v_front_porch;
637    SERIALIZE_SCALAR(v_front_porch_serial);
638    const uint32_t h_sync_serial = h_sync;
639    SERIALIZE_SCALAR(h_sync_serial);
640    const uint32_t h_back_porch_serial = h_back_porch;
641    SERIALIZE_SCALAR(h_back_porch_serial);
642    const uint32_t h_data_serial = h_data;
643    SERIALIZE_SCALAR(h_data_serial);
644    const uint32_t h_front_porch_serial = h_front_porch;
645    SERIALIZE_SCALAR(h_front_porch_serial);
646    const uint32_t polarities_serial = polarities;
647    SERIALIZE_SCALAR(polarities_serial);
648    const uint32_t command_serial = command;
649    SERIALIZE_SCALAR(command_serial);
650    const uint32_t pixel_format_serial = pixel_format;
651    SERIALIZE_SCALAR(pixel_format_serial);
652    const uint32_t red_select_serial = red_select;
653    SERIALIZE_SCALAR(red_select_serial);
654    const uint32_t green_select_serial = green_select;
655    SERIALIZE_SCALAR(green_select_serial);
656    const uint32_t blue_select_serial = blue_select;
657    SERIALIZE_SCALAR(blue_select_serial);
658
659    SERIALIZE_SCALAR(frameReadStartTime);
660    SERIALIZE_SCALAR(dmaStartAddr);
661    SERIALIZE_SCALAR(dmaCurAddr);
662    SERIALIZE_SCALAR(dmaMaxAddr);
663    SERIALIZE_SCALAR(dmaPendingNum);
664    SERIALIZE_SCALAR(frameUnderrun);
665
666    const size_t buffer_size = bytesPerPixel() * width() * height();
667    SERIALIZE_ARRAY(virtualDisplayBuffer, buffer_size);
668
669    SERIALIZE_SCALAR(pixelBufferSize);
670    SERIALIZE_SCALAR(pixelIndex);
671    SERIALIZE_SCALAR(doUpdateParams);
672    SERIALIZE_SCALAR(frameUnderway);
673    SERIALIZE_SCALAR(dmaBytesInFlight);
674
675    Tick start_event_time = 0;
676    Tick end_event_time = 0;
677    Tick render_pixel_event_time = 0;
678    Tick fill_pixel_buffer_event_time = 0;
679    Tick int_event_time = 0;
680    if (startFrameEvent.scheduled())
681        start_event_time = startFrameEvent.when();
682    if (endFrameEvent.scheduled())
683        end_event_time = endFrameEvent.when();
684    if (renderPixelEvent.scheduled())
685        render_pixel_event_time = renderPixelEvent.when();
686    if (fillPixelBufferEvent.scheduled())
687        fill_pixel_buffer_event_time = fillPixelBufferEvent.when();
688    if (intEvent.scheduled())
689        int_event_time = intEvent.when();
690    SERIALIZE_SCALAR(start_event_time);
691    SERIALIZE_SCALAR(end_event_time);
692    SERIALIZE_SCALAR(render_pixel_event_time);
693    SERIALIZE_SCALAR(fill_pixel_buffer_event_time);
694    SERIALIZE_SCALAR(int_event_time);
695
696    vector<Tick> dma_done_event_tick(MAX_OUTSTANDING_DMA_REQ_CAPACITY);
697    vector<size_t> dma_done_event_burst_len(MAX_OUTSTANDING_DMA_REQ_CAPACITY);
698    for (int x = 0; x < MAX_OUTSTANDING_DMA_REQ_CAPACITY; ++x) {
699        dma_done_event_tick[x] = dmaDoneEventAll[x].scheduled() ?
700            dmaDoneEventAll[x].when() : 0;
701        dma_done_event_burst_len[x] = dmaDoneEventAll[x].scheduled() ?
702            dmaDoneEventAll[x].getTransactionSize() : 0;
703    }
704    arrayParamOut(os, "dma_done_event_tick", dma_done_event_tick);
705    arrayParamOut(os, "dma_done_event_burst_length", dma_done_event_burst_len);
706}
707
708void
709HDLcd::unserialize(Checkpoint *cp, const std::string &section)
710{
711    uint32_t version_serial, int_rawstat_serial, int_clear_serial,
712            int_mask_serial, int_status_serial, fb_line_count_serial,
713            bus_options_serial, v_sync_serial, v_back_porch_serial,
714            v_data_serial, v_front_porch_serial, h_sync_serial,
715            h_back_porch_serial, h_data_serial, h_front_porch_serial,
716            polarities_serial, command_serial, pixel_format_serial,
717            red_select_serial, green_select_serial, blue_select_serial;
718
719    DPRINTF(HDLcd, "Unserializing ARM HDLCD\n");
720
721    UNSERIALIZE_SCALAR(version_serial);
722    version = version_serial;
723    UNSERIALIZE_SCALAR(int_rawstat_serial);
724    int_rawstat = int_rawstat_serial;
725    UNSERIALIZE_SCALAR(int_clear_serial);
726    int_clear = int_clear_serial;
727    UNSERIALIZE_SCALAR(int_mask_serial);
728    int_mask = int_mask_serial;
729    UNSERIALIZE_SCALAR(int_status_serial);
730    int_status = int_status_serial;
731
732    UNSERIALIZE_SCALAR(fb_base);
733    UNSERIALIZE_SCALAR(fb_line_length);
734
735    UNSERIALIZE_SCALAR(fb_line_count_serial);
736    fb_line_count = fb_line_count_serial;
737
738    UNSERIALIZE_SCALAR(fb_line_pitch);
739
740    UNSERIALIZE_SCALAR(bus_options_serial);
741    bus_options = bus_options_serial;
742    UNSERIALIZE_SCALAR(v_sync_serial);
743    v_sync = v_sync_serial;
744    UNSERIALIZE_SCALAR(v_back_porch_serial);
745    v_back_porch = v_back_porch_serial;
746    UNSERIALIZE_SCALAR(v_data_serial);
747    v_data = v_data_serial;
748    UNSERIALIZE_SCALAR(v_front_porch_serial);
749    v_front_porch = v_front_porch_serial;
750    UNSERIALIZE_SCALAR(h_sync_serial);
751    h_sync = h_sync_serial;
752    UNSERIALIZE_SCALAR(h_back_porch_serial);
753    h_back_porch = h_back_porch_serial;
754    UNSERIALIZE_SCALAR(h_data_serial);
755    h_data = h_data_serial;
756    UNSERIALIZE_SCALAR(h_front_porch_serial);
757    h_front_porch = h_front_porch_serial;
758    UNSERIALIZE_SCALAR(polarities_serial);
759    polarities = polarities_serial;
760    UNSERIALIZE_SCALAR(command_serial);
761    command = command_serial;
762    UNSERIALIZE_SCALAR(pixel_format_serial);
763    pixel_format = pixel_format_serial;
764    UNSERIALIZE_SCALAR(red_select_serial);
765    red_select = red_select_serial;
766    UNSERIALIZE_SCALAR(green_select_serial);
767    green_select = green_select_serial;
768    UNSERIALIZE_SCALAR(blue_select_serial);
769    blue_select = blue_select_serial;
770
771    UNSERIALIZE_SCALAR(frameReadStartTime);
772    UNSERIALIZE_SCALAR(dmaStartAddr);
773    UNSERIALIZE_SCALAR(dmaCurAddr);
774    UNSERIALIZE_SCALAR(dmaMaxAddr);
775    UNSERIALIZE_SCALAR(dmaPendingNum);
776    UNSERIALIZE_SCALAR(frameUnderrun);
777    UNSERIALIZE_SCALAR(dmaBytesInFlight);
778
779    const size_t buffer_size = bytesPerPixel() * width() * height();
780    virtualDisplayBuffer = new uint8_t[buffer_size];
781    UNSERIALIZE_ARRAY(virtualDisplayBuffer, buffer_size);
782
783    UNSERIALIZE_SCALAR(pixelBufferSize);
784    UNSERIALIZE_SCALAR(pixelIndex);
785    UNSERIALIZE_SCALAR(doUpdateParams);
786    UNSERIALIZE_SCALAR(frameUnderway);
787
788    Tick start_event_time = 0;
789    Tick end_event_time = 0;
790    Tick render_pixel_event_time = 0;
791    Tick fill_pixel_buffer_event_time = 0;
792    Tick int_event_time = 0;
793    UNSERIALIZE_SCALAR(start_event_time);
794    UNSERIALIZE_SCALAR(end_event_time);
795    UNSERIALIZE_SCALAR(render_pixel_event_time);
796    UNSERIALIZE_SCALAR(fill_pixel_buffer_event_time);
797    UNSERIALIZE_SCALAR(int_event_time);
798    if (start_event_time)
799        schedule(startFrameEvent, start_event_time);
800    if (end_event_time)
801        schedule(endFrameEvent, end_event_time);
802    if (render_pixel_event_time)
803        schedule(renderPixelEvent, render_pixel_event_time);
804    if (fill_pixel_buffer_event_time)
805        schedule(fillPixelBufferEvent, fill_pixel_buffer_event_time);
806    if (int_event_time)
807        schedule(intEvent, int_event_time);
808
809    vector<Tick> dma_done_event_tick(MAX_OUTSTANDING_DMA_REQ_CAPACITY);
810    vector<Tick> dma_done_event_burst_len(MAX_OUTSTANDING_DMA_REQ_CAPACITY);
811    arrayParamIn(cp, section, "dma_done_event_tick", dma_done_event_tick);
812    arrayParamIn(cp, section, "dma_done_event_burst_length", dma_done_event_burst_len);
813    dmaDoneEventFree.clear();
814    for (int x = 0; x < MAX_OUTSTANDING_DMA_REQ_CAPACITY; ++x) {
815        if (dma_done_event_tick[x]) {
816            dmaDoneEventAll[x].setTransactionSize(dma_done_event_burst_len[x]);
817            schedule(dmaDoneEventAll[x], dma_done_event_tick[x]);
818        } else
819            dmaDoneEventFree.push_back(&dmaDoneEventAll[x]);
820    }
821    assert(MAX_OUTSTANDING_DMA_REQ_CAPACITY - dmaDoneEventFree.size() == dmaPendingNum);
822
823    if (frameUnderway) {
824        updateVideoParams(true);
825        if (vnc)
826            vnc->setDirty();
827    }
828}
829
830void
831HDLcd::generateInterrupt()
832{
833    int_status = int_rawstat & int_mask;
834    DPRINTF(HDLcd, "Generate Interrupt: int_rawstat=0x%08x int_mask=0x%08x "
835            "int_status=0x%08x\n",
836            (uint32_t)int_rawstat, (uint32_t)int_mask, (uint32_t)int_status);
837
838    if (int_status != 0) {
839        gic->sendInt(intNum);
840        DPRINTF(HDLcd, " -- Generated\n");
841    }
842}
843
844AddrRangeList
845HDLcd::getAddrRanges() const
846{
847    AddrRangeList ranges;
848    ranges.push_back(RangeSize(pioAddr, pioSize));
849    return ranges;
850}
851
852HDLcd *
853HDLcdParams::create()
854{
855    return new HDLcd(this);
856}
857