2 * Intel XScale PXA255/270 LCDC emulation.
4 * Copyright (c) 2006 Openedhand Ltd.
5 * Written by Andrzej Zaborowski <balrog@zabor.org>
7 * This code is licensed under the GPLv2.
9 * Contributions after 2012-01-13 are licensed under the terms of the
10 * GNU GPL, version 2 or (at your option) any later version.
13 #include "qemu/osdep.h"
16 #include "migration/vmstate.h"
17 #include "ui/console.h"
18 #include "hw/arm/pxa.h"
19 #include "ui/pixel_ops.h"
20 #include "hw/boards.h"
21 /* FIXME: For graphic_rotate. Should probably be done in common code. */
22 #include "sysemu/sysemu.h"
23 #include "framebuffer.h"
28 uint8_t palette
[1024];
29 uint8_t pbuffer
[1024];
30 void (*redraw
)(PXA2xxLCDState
*s
, hwaddr addr
,
31 int *miny
, int *maxy
);
39 struct PXA2xxLCDState
{
42 MemoryRegionSection fbsection
;
76 struct DMAChannel dma_ch
[7];
82 typedef struct QEMU_PACKED
{
89 #define LCCR0 0x000 /* LCD Controller Control register 0 */
90 #define LCCR1 0x004 /* LCD Controller Control register 1 */
91 #define LCCR2 0x008 /* LCD Controller Control register 2 */
92 #define LCCR3 0x00c /* LCD Controller Control register 3 */
93 #define LCCR4 0x010 /* LCD Controller Control register 4 */
94 #define LCCR5 0x014 /* LCD Controller Control register 5 */
96 #define FBR0 0x020 /* DMA Channel 0 Frame Branch register */
97 #define FBR1 0x024 /* DMA Channel 1 Frame Branch register */
98 #define FBR2 0x028 /* DMA Channel 2 Frame Branch register */
99 #define FBR3 0x02c /* DMA Channel 3 Frame Branch register */
100 #define FBR4 0x030 /* DMA Channel 4 Frame Branch register */
101 #define FBR5 0x110 /* DMA Channel 5 Frame Branch register */
102 #define FBR6 0x114 /* DMA Channel 6 Frame Branch register */
104 #define LCSR1 0x034 /* LCD Controller Status register 1 */
105 #define LCSR0 0x038 /* LCD Controller Status register 0 */
106 #define LIIDR 0x03c /* LCD Controller Interrupt ID register */
108 #define TRGBR 0x040 /* TMED RGB Seed register */
109 #define TCR 0x044 /* TMED Control register */
111 #define OVL1C1 0x050 /* Overlay 1 Control register 1 */
112 #define OVL1C2 0x060 /* Overlay 1 Control register 2 */
113 #define OVL2C1 0x070 /* Overlay 2 Control register 1 */
114 #define OVL2C2 0x080 /* Overlay 2 Control register 2 */
115 #define CCR 0x090 /* Cursor Control register */
117 #define CMDCR 0x100 /* Command Control register */
118 #define PRSR 0x104 /* Panel Read Status register */
120 #define PXA_LCDDMA_CHANS 7
121 #define DMA_FDADR 0x00 /* Frame Descriptor Address register */
122 #define DMA_FSADR 0x04 /* Frame Source Address register */
123 #define DMA_FIDR 0x08 /* Frame ID register */
124 #define DMA_LDCMD 0x0c /* Command register */
126 /* LCD Buffer Strength Control register */
127 #define BSCNTR 0x04000054
130 #define LCCR0_ENB (1 << 0)
131 #define LCCR0_CMS (1 << 1)
132 #define LCCR0_SDS (1 << 2)
133 #define LCCR0_LDM (1 << 3)
134 #define LCCR0_SOFM0 (1 << 4)
135 #define LCCR0_IUM (1 << 5)
136 #define LCCR0_EOFM0 (1 << 6)
137 #define LCCR0_PAS (1 << 7)
138 #define LCCR0_DPD (1 << 9)
139 #define LCCR0_DIS (1 << 10)
140 #define LCCR0_QDM (1 << 11)
141 #define LCCR0_PDD (0xff << 12)
142 #define LCCR0_BSM0 (1 << 20)
143 #define LCCR0_OUM (1 << 21)
144 #define LCCR0_LCDT (1 << 22)
145 #define LCCR0_RDSTM (1 << 23)
146 #define LCCR0_CMDIM (1 << 24)
147 #define LCCR0_OUC (1 << 25)
148 #define LCCR0_LDDALT (1 << 26)
149 #define LCCR1_PPL(x) ((x) & 0x3ff)
150 #define LCCR2_LPP(x) ((x) & 0x3ff)
151 #define LCCR3_API (15 << 16)
152 #define LCCR3_BPP(x) ((((x) >> 24) & 7) | (((x) >> 26) & 8))
153 #define LCCR3_PDFOR(x) (((x) >> 30) & 3)
154 #define LCCR4_K1(x) (((x) >> 0) & 7)
155 #define LCCR4_K2(x) (((x) >> 3) & 7)
156 #define LCCR4_K3(x) (((x) >> 6) & 7)
157 #define LCCR4_PALFOR(x) (((x) >> 15) & 3)
158 #define LCCR5_SOFM(ch) (1 << (ch - 1))
159 #define LCCR5_EOFM(ch) (1 << (ch + 7))
160 #define LCCR5_BSM(ch) (1 << (ch + 15))
161 #define LCCR5_IUM(ch) (1 << (ch + 23))
162 #define OVLC1_EN (1 << 31)
163 #define CCR_CEN (1 << 31)
164 #define FBR_BRA (1 << 0)
165 #define FBR_BINT (1 << 1)
166 #define FBR_SRCADDR (0xfffffff << 4)
167 #define LCSR0_LDD (1 << 0)
168 #define LCSR0_SOF0 (1 << 1)
169 #define LCSR0_BER (1 << 2)
170 #define LCSR0_ABC (1 << 3)
171 #define LCSR0_IU0 (1 << 4)
172 #define LCSR0_IU1 (1 << 5)
173 #define LCSR0_OU (1 << 6)
174 #define LCSR0_QD (1 << 7)
175 #define LCSR0_EOF0 (1 << 8)
176 #define LCSR0_BS0 (1 << 9)
177 #define LCSR0_SINT (1 << 10)
178 #define LCSR0_RDST (1 << 11)
179 #define LCSR0_CMDINT (1 << 12)
180 #define LCSR0_BERCH(x) (((x) & 7) << 28)
181 #define LCSR1_SOF(ch) (1 << (ch - 1))
182 #define LCSR1_EOF(ch) (1 << (ch + 7))
183 #define LCSR1_BS(ch) (1 << (ch + 15))
184 #define LCSR1_IU(ch) (1 << (ch + 23))
185 #define LDCMD_LENGTH(x) ((x) & 0x001ffffc)
186 #define LDCMD_EOFINT (1 << 21)
187 #define LDCMD_SOFINT (1 << 22)
188 #define LDCMD_PAL (1 << 26)
190 /* Size of a pixel in the QEMU UI output surface, in bytes */
191 #define DEST_PIXEL_WIDTH 4
193 /* Line drawing code to handle the various possible guest pixel formats */
195 # define SKIP_PIXEL(to) do { to += deststep; } while (0)
196 # define COPY_PIXEL(to, from) \
198 *(uint32_t *) to = from; \
203 # define SWAP_WORDS 1
206 #define FN_2(x) FN(x + 1) FN(x)
207 #define FN_4(x) FN_2(x + 2) FN_2(x)
209 static void pxa2xx_draw_line2(void *opaque
, uint8_t *dest
, const uint8_t *src
,
210 int width
, int deststep
)
212 uint32_t *palette
= opaque
;
215 data
= *(uint32_t *) src
;
216 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 2)) & 3]);
234 static void pxa2xx_draw_line4(void *opaque
, uint8_t *dest
, const uint8_t *src
,
235 int width
, int deststep
)
237 uint32_t *palette
= opaque
;
240 data
= *(uint32_t *) src
;
241 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 4)) & 0xf]);
259 static void pxa2xx_draw_line8(void *opaque
, uint8_t *dest
, const uint8_t *src
,
260 int width
, int deststep
)
262 uint32_t *palette
= opaque
;
265 data
= *(uint32_t *) src
;
266 #define FN(x) COPY_PIXEL(dest, palette[(data >> (x)) & 0xff]);
284 static void pxa2xx_draw_line16(void *opaque
, uint8_t *dest
, const uint8_t *src
,
285 int width
, int deststep
)
288 unsigned int r
, g
, b
;
290 data
= *(uint32_t *) src
;
292 data
= bswap32(data
);
294 b
= (data
& 0x1f) << 3;
296 g
= (data
& 0x3f) << 2;
298 r
= (data
& 0x1f) << 3;
300 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
301 b
= (data
& 0x1f) << 3;
303 g
= (data
& 0x3f) << 2;
305 r
= (data
& 0x1f) << 3;
306 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
312 static void pxa2xx_draw_line16t(void *opaque
, uint8_t *dest
, const uint8_t *src
,
313 int width
, int deststep
)
316 unsigned int r
, g
, b
;
318 data
= *(uint32_t *) src
;
320 data
= bswap32(data
);
322 b
= (data
& 0x1f) << 3;
324 g
= (data
& 0x1f) << 3;
326 r
= (data
& 0x1f) << 3;
331 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
334 b
= (data
& 0x1f) << 3;
336 g
= (data
& 0x1f) << 3;
338 r
= (data
& 0x1f) << 3;
343 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
350 static void pxa2xx_draw_line18(void *opaque
, uint8_t *dest
, const uint8_t *src
,
351 int width
, int deststep
)
354 unsigned int r
, g
, b
;
356 data
= *(uint32_t *) src
;
358 data
= bswap32(data
);
360 b
= (data
& 0x3f) << 2;
362 g
= (data
& 0x3f) << 2;
364 r
= (data
& 0x3f) << 2;
365 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
371 /* The wicked packed format */
372 static void pxa2xx_draw_line18p(void *opaque
, uint8_t *dest
, const uint8_t *src
,
373 int width
, int deststep
)
376 unsigned int r
, g
, b
;
378 data
[0] = *(uint32_t *) src
;
380 data
[1] = *(uint32_t *) src
;
382 data
[2] = *(uint32_t *) src
;
385 data
[0] = bswap32(data
[0]);
386 data
[1] = bswap32(data
[1]);
387 data
[2] = bswap32(data
[2]);
389 b
= (data
[0] & 0x3f) << 2;
391 g
= (data
[0] & 0x3f) << 2;
393 r
= (data
[0] & 0x3f) << 2;
395 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
396 b
= (data
[0] & 0x3f) << 2;
398 g
= ((data
[1] & 0xf) << 4) | (data
[0] << 2);
400 r
= (data
[1] & 0x3f) << 2;
402 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
403 b
= (data
[1] & 0x3f) << 2;
405 g
= (data
[1] & 0x3f) << 2;
407 r
= ((data
[2] & 0x3) << 6) | (data
[1] << 2);
409 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
410 b
= (data
[2] & 0x3f) << 2;
412 g
= (data
[2] & 0x3f) << 2;
415 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
420 static void pxa2xx_draw_line19(void *opaque
, uint8_t *dest
, const uint8_t *src
,
421 int width
, int deststep
)
424 unsigned int r
, g
, b
;
426 data
= *(uint32_t *) src
;
428 data
= bswap32(data
);
430 b
= (data
& 0x3f) << 2;
432 g
= (data
& 0x3f) << 2;
434 r
= (data
& 0x3f) << 2;
439 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
446 /* The wicked packed format */
447 static void pxa2xx_draw_line19p(void *opaque
, uint8_t *dest
, const uint8_t *src
,
448 int width
, int deststep
)
451 unsigned int r
, g
, b
;
453 data
[0] = *(uint32_t *) src
;
455 data
[1] = *(uint32_t *) src
;
457 data
[2] = *(uint32_t *) src
;
460 data
[0] = bswap32(data
[0]);
461 data
[1] = bswap32(data
[1]);
462 data
[2] = bswap32(data
[2]);
464 b
= (data
[0] & 0x3f) << 2;
466 g
= (data
[0] & 0x3f) << 2;
468 r
= (data
[0] & 0x3f) << 2;
473 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
476 b
= (data
[0] & 0x3f) << 2;
478 g
= ((data
[1] & 0xf) << 4) | (data
[0] << 2);
480 r
= (data
[1] & 0x3f) << 2;
485 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
488 b
= (data
[1] & 0x3f) << 2;
490 g
= (data
[1] & 0x3f) << 2;
492 r
= ((data
[2] & 0x3) << 6) | (data
[1] << 2);
497 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
500 b
= (data
[2] & 0x3f) << 2;
502 g
= (data
[2] & 0x3f) << 2;
509 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
515 static void pxa2xx_draw_line24(void *opaque
, uint8_t *dest
, const uint8_t *src
,
516 int width
, int deststep
)
519 unsigned int r
, g
, b
;
521 data
= *(uint32_t *) src
;
523 data
= bswap32(data
);
530 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
536 static void pxa2xx_draw_line24t(void *opaque
, uint8_t *dest
, const uint8_t *src
,
537 int width
, int deststep
)
540 unsigned int r
, g
, b
;
542 data
= *(uint32_t *) src
;
544 data
= bswap32(data
);
546 b
= (data
& 0x7f) << 1;
555 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
562 static void pxa2xx_draw_line25(void *opaque
, uint8_t *dest
, const uint8_t *src
,
563 int width
, int deststep
)
566 unsigned int r
, g
, b
;
568 data
= *(uint32_t *) src
;
570 data
= bswap32(data
);
581 COPY_PIXEL(dest
, rgb_to_pixel32(r
, g
, b
));
588 /* Overlay planes disabled, no transparency */
589 static drawfn pxa2xx_draw_fn_32
[16] = {
591 [pxa_lcdc_2bpp
] = pxa2xx_draw_line2
,
592 [pxa_lcdc_4bpp
] = pxa2xx_draw_line4
,
593 [pxa_lcdc_8bpp
] = pxa2xx_draw_line8
,
594 [pxa_lcdc_16bpp
] = pxa2xx_draw_line16
,
595 [pxa_lcdc_18bpp
] = pxa2xx_draw_line18
,
596 [pxa_lcdc_18pbpp
] = pxa2xx_draw_line18p
,
597 [pxa_lcdc_24bpp
] = pxa2xx_draw_line24
,
600 /* Overlay planes enabled, transparency used */
601 static drawfn pxa2xx_draw_fn_32t
[16] = {
603 [pxa_lcdc_4bpp
] = pxa2xx_draw_line4
,
604 [pxa_lcdc_8bpp
] = pxa2xx_draw_line8
,
605 [pxa_lcdc_16bpp
] = pxa2xx_draw_line16t
,
606 [pxa_lcdc_19bpp
] = pxa2xx_draw_line19
,
607 [pxa_lcdc_19pbpp
] = pxa2xx_draw_line19p
,
608 [pxa_lcdc_24bpp
] = pxa2xx_draw_line24t
,
609 [pxa_lcdc_25bpp
] = pxa2xx_draw_line25
,
619 /* Route internal interrupt lines to the global IC */
620 static void pxa2xx_lcdc_int_update(PXA2xxLCDState
*s
)
623 level
|= (s
->status
[0] & LCSR0_LDD
) && !(s
->control
[0] & LCCR0_LDM
);
624 level
|= (s
->status
[0] & LCSR0_SOF0
) && !(s
->control
[0] & LCCR0_SOFM0
);
625 level
|= (s
->status
[0] & LCSR0_IU0
) && !(s
->control
[0] & LCCR0_IUM
);
626 level
|= (s
->status
[0] & LCSR0_IU1
) && !(s
->control
[5] & LCCR5_IUM(1));
627 level
|= (s
->status
[0] & LCSR0_OU
) && !(s
->control
[0] & LCCR0_OUM
);
628 level
|= (s
->status
[0] & LCSR0_QD
) && !(s
->control
[0] & LCCR0_QDM
);
629 level
|= (s
->status
[0] & LCSR0_EOF0
) && !(s
->control
[0] & LCCR0_EOFM0
);
630 level
|= (s
->status
[0] & LCSR0_BS0
) && !(s
->control
[0] & LCCR0_BSM0
);
631 level
|= (s
->status
[0] & LCSR0_RDST
) && !(s
->control
[0] & LCCR0_RDSTM
);
632 level
|= (s
->status
[0] & LCSR0_CMDINT
) && !(s
->control
[0] & LCCR0_CMDIM
);
633 level
|= (s
->status
[1] & ~s
->control
[5]);
635 qemu_set_irq(s
->irq
, !!level
);
639 /* Set Branch Status interrupt high and poke associated registers */
640 static inline void pxa2xx_dma_bs_set(PXA2xxLCDState
*s
, int ch
)
644 s
->status
[0] |= LCSR0_BS0
;
645 unmasked
= !(s
->control
[0] & LCCR0_BSM0
);
647 s
->status
[1] |= LCSR1_BS(ch
);
648 unmasked
= !(s
->control
[5] & LCCR5_BSM(ch
));
653 s
->status
[0] |= LCSR0_SINT
;
655 s
->liidr
= s
->dma_ch
[ch
].id
;
659 /* Set Start Of Frame Status interrupt high and poke associated registers */
660 static inline void pxa2xx_dma_sof_set(PXA2xxLCDState
*s
, int ch
)
663 if (!(s
->dma_ch
[ch
].command
& LDCMD_SOFINT
))
667 s
->status
[0] |= LCSR0_SOF0
;
668 unmasked
= !(s
->control
[0] & LCCR0_SOFM0
);
670 s
->status
[1] |= LCSR1_SOF(ch
);
671 unmasked
= !(s
->control
[5] & LCCR5_SOFM(ch
));
676 s
->status
[0] |= LCSR0_SINT
;
678 s
->liidr
= s
->dma_ch
[ch
].id
;
682 /* Set End Of Frame Status interrupt high and poke associated registers */
683 static inline void pxa2xx_dma_eof_set(PXA2xxLCDState
*s
, int ch
)
686 if (!(s
->dma_ch
[ch
].command
& LDCMD_EOFINT
))
690 s
->status
[0] |= LCSR0_EOF0
;
691 unmasked
= !(s
->control
[0] & LCCR0_EOFM0
);
693 s
->status
[1] |= LCSR1_EOF(ch
);
694 unmasked
= !(s
->control
[5] & LCCR5_EOFM(ch
));
699 s
->status
[0] |= LCSR0_SINT
;
701 s
->liidr
= s
->dma_ch
[ch
].id
;
705 /* Set Bus Error Status interrupt high and poke associated registers */
706 static inline void pxa2xx_dma_ber_set(PXA2xxLCDState
*s
, int ch
)
708 s
->status
[0] |= LCSR0_BERCH(ch
) | LCSR0_BER
;
710 s
->status
[0] |= LCSR0_SINT
;
712 s
->liidr
= s
->dma_ch
[ch
].id
;
715 /* Load new Frame Descriptors from DMA */
716 static void pxa2xx_descriptor_load(PXA2xxLCDState
*s
)
718 PXAFrameDescriptor desc
;
722 for (i
= 0; i
< PXA_LCDDMA_CHANS
; i
++) {
723 s
->dma_ch
[i
].source
= 0;
725 if (!s
->dma_ch
[i
].up
)
728 if (s
->dma_ch
[i
].branch
& FBR_BRA
) {
729 descptr
= s
->dma_ch
[i
].branch
& FBR_SRCADDR
;
730 if (s
->dma_ch
[i
].branch
& FBR_BINT
)
731 pxa2xx_dma_bs_set(s
, i
);
732 s
->dma_ch
[i
].branch
&= ~FBR_BRA
;
734 descptr
= s
->dma_ch
[i
].descriptor
;
736 if (!((descptr
>= PXA2XX_SDRAM_BASE
&& descptr
+
737 sizeof(desc
) <= PXA2XX_SDRAM_BASE
+ current_machine
->ram_size
) ||
738 (descptr
>= PXA2XX_INTERNAL_BASE
&& descptr
+ sizeof(desc
) <=
739 PXA2XX_INTERNAL_BASE
+ PXA2XX_INTERNAL_SIZE
))) {
743 cpu_physical_memory_read(descptr
, &desc
, sizeof(desc
));
744 s
->dma_ch
[i
].descriptor
= le32_to_cpu(desc
.fdaddr
);
745 s
->dma_ch
[i
].source
= le32_to_cpu(desc
.fsaddr
);
746 s
->dma_ch
[i
].id
= le32_to_cpu(desc
.fidr
);
747 s
->dma_ch
[i
].command
= le32_to_cpu(desc
.ldcmd
);
751 static uint64_t pxa2xx_lcdc_read(void *opaque
, hwaddr offset
,
754 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
759 return s
->control
[0];
761 return s
->control
[1];
763 return s
->control
[2];
765 return s
->control
[3];
767 return s
->control
[4];
769 return s
->control
[5];
791 case 0x200 ... 0x1000: /* DMA per-channel registers */
792 ch
= (offset
- 0x200) >> 4;
793 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
796 switch (offset
& 0xf) {
798 return s
->dma_ch
[ch
].descriptor
;
800 return s
->dma_ch
[ch
].source
;
802 return s
->dma_ch
[ch
].id
;
804 return s
->dma_ch
[ch
].command
;
810 return s
->dma_ch
[0].branch
;
812 return s
->dma_ch
[1].branch
;
814 return s
->dma_ch
[2].branch
;
816 return s
->dma_ch
[3].branch
;
818 return s
->dma_ch
[4].branch
;
820 return s
->dma_ch
[5].branch
;
822 return s
->dma_ch
[6].branch
;
839 qemu_log_mask(LOG_GUEST_ERROR
, "%s: Bad offset 0x%" HWADDR_PRIX
"\n",
846 static void pxa2xx_lcdc_write(void *opaque
, hwaddr offset
,
847 uint64_t value
, unsigned size
)
849 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
854 /* ACK Quick Disable done */
855 if ((s
->control
[0] & LCCR0_ENB
) && !(value
& LCCR0_ENB
))
856 s
->status
[0] |= LCSR0_QD
;
858 if (!(s
->control
[0] & LCCR0_LCDT
) && (value
& LCCR0_LCDT
)) {
859 qemu_log_mask(LOG_UNIMP
,
860 "%s: internal frame buffer unsupported\n", __func__
);
862 if ((s
->control
[3] & LCCR3_API
) &&
863 (value
& LCCR0_ENB
) && !(value
& LCCR0_LCDT
))
864 s
->status
[0] |= LCSR0_ABC
;
866 s
->control
[0] = value
& 0x07ffffff;
867 pxa2xx_lcdc_int_update(s
);
869 s
->dma_ch
[0].up
= !!(value
& LCCR0_ENB
);
870 s
->dma_ch
[1].up
= (s
->ovl1c
[0] & OVLC1_EN
) || (value
& LCCR0_SDS
);
874 s
->control
[1] = value
;
878 s
->control
[2] = value
;
882 s
->control
[3] = value
& 0xefffffff;
883 s
->bpp
= LCCR3_BPP(value
);
887 s
->control
[4] = value
& 0x83ff81ff;
891 s
->control
[5] = value
& 0x3f3f3f3f;
895 if (!(s
->ovl1c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
)) {
896 qemu_log_mask(LOG_UNIMP
, "%s: Overlay 1 not supported\n", __func__
);
898 s
->ovl1c
[0] = value
& 0x80ffffff;
899 s
->dma_ch
[1].up
= (value
& OVLC1_EN
) || (s
->control
[0] & LCCR0_SDS
);
903 s
->ovl1c
[1] = value
& 0x000fffff;
907 if (!(s
->ovl2c
[0] & OVLC1_EN
) && (value
& OVLC1_EN
)) {
908 qemu_log_mask(LOG_UNIMP
, "%s: Overlay 2 not supported\n", __func__
);
910 s
->ovl2c
[0] = value
& 0x80ffffff;
911 s
->dma_ch
[2].up
= !!(value
& OVLC1_EN
);
912 s
->dma_ch
[3].up
= !!(value
& OVLC1_EN
);
913 s
->dma_ch
[4].up
= !!(value
& OVLC1_EN
);
917 s
->ovl2c
[1] = value
& 0x007fffff;
921 if (!(s
->ccr
& CCR_CEN
) && (value
& CCR_CEN
)) {
922 qemu_log_mask(LOG_UNIMP
,
923 "%s: Hardware cursor unimplemented\n", __func__
);
925 s
->ccr
= value
& 0x81ffffe7;
926 s
->dma_ch
[5].up
= !!(value
& CCR_CEN
);
930 s
->cmdcr
= value
& 0xff;
934 s
->trgbr
= value
& 0x00ffffff;
938 s
->tcr
= value
& 0x7fff;
941 case 0x200 ... 0x1000: /* DMA per-channel registers */
942 ch
= (offset
- 0x200) >> 4;
943 if (!(ch
>= 0 && ch
< PXA_LCDDMA_CHANS
))
946 switch (offset
& 0xf) {
948 s
->dma_ch
[ch
].descriptor
= value
& 0xfffffff0;
957 s
->dma_ch
[0].branch
= value
& 0xfffffff3;
960 s
->dma_ch
[1].branch
= value
& 0xfffffff3;
963 s
->dma_ch
[2].branch
= value
& 0xfffffff3;
966 s
->dma_ch
[3].branch
= value
& 0xfffffff3;
969 s
->dma_ch
[4].branch
= value
& 0xfffffff3;
972 s
->dma_ch
[5].branch
= value
& 0xfffffff3;
975 s
->dma_ch
[6].branch
= value
& 0xfffffff3;
979 s
->bscntr
= value
& 0xf;
986 s
->status
[0] &= ~(value
& 0xfff);
987 if (value
& LCSR0_BER
)
988 s
->status
[0] &= ~LCSR0_BERCH(7);
992 s
->status
[1] &= ~(value
& 0x3e3f3f);
997 qemu_log_mask(LOG_GUEST_ERROR
, "%s: Bad offset 0x%" HWADDR_PRIX
"\n",
1002 static const MemoryRegionOps pxa2xx_lcdc_ops
= {
1003 .read
= pxa2xx_lcdc_read
,
1004 .write
= pxa2xx_lcdc_write
,
1005 .endianness
= DEVICE_NATIVE_ENDIAN
,
1008 /* Load new palette for a given DMA channel, convert to internal format */
1009 static void pxa2xx_palette_parse(PXA2xxLCDState
*s
, int ch
, int bpp
)
1011 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1012 int i
, n
, format
, r
, g
, b
, alpha
;
1015 s
->pal_for
= LCCR4_PALFOR(s
->control
[4]);
1016 format
= s
->pal_for
;
1032 src
= (uint8_t *) s
->dma_ch
[ch
].pbuffer
;
1033 dest
= (uint32_t *) s
->dma_ch
[ch
].palette
;
1034 alpha
= r
= g
= b
= 0;
1036 for (i
= 0; i
< n
; i
++) {
1038 case 0: /* 16 bpp, no transparency */
1040 if (s
->control
[0] & LCCR0_CMS
) {
1041 r
= g
= b
= *(uint16_t *) src
& 0xff;
1044 r
= (*(uint16_t *) src
& 0xf800) >> 8;
1045 g
= (*(uint16_t *) src
& 0x07e0) >> 3;
1046 b
= (*(uint16_t *) src
& 0x001f) << 3;
1050 case 1: /* 16 bpp plus transparency */
1051 alpha
= *(uint32_t *) src
& (1 << 24);
1052 if (s
->control
[0] & LCCR0_CMS
)
1053 r
= g
= b
= *(uint32_t *) src
& 0xff;
1055 r
= (*(uint32_t *) src
& 0xf80000) >> 16;
1056 g
= (*(uint32_t *) src
& 0x00fc00) >> 8;
1057 b
= (*(uint32_t *) src
& 0x0000f8);
1061 case 2: /* 18 bpp plus transparency */
1062 alpha
= *(uint32_t *) src
& (1 << 24);
1063 if (s
->control
[0] & LCCR0_CMS
)
1064 r
= g
= b
= *(uint32_t *) src
& 0xff;
1066 r
= (*(uint32_t *) src
& 0xfc0000) >> 16;
1067 g
= (*(uint32_t *) src
& 0x00fc00) >> 8;
1068 b
= (*(uint32_t *) src
& 0x0000fc);
1072 case 3: /* 24 bpp plus transparency */
1073 alpha
= *(uint32_t *) src
& (1 << 24);
1074 if (s
->control
[0] & LCCR0_CMS
)
1075 r
= g
= b
= *(uint32_t *) src
& 0xff;
1077 r
= (*(uint32_t *) src
& 0xff0000) >> 16;
1078 g
= (*(uint32_t *) src
& 0x00ff00) >> 8;
1079 b
= (*(uint32_t *) src
& 0x0000ff);
1084 switch (surface_bits_per_pixel(surface
)) {
1086 *dest
= rgb_to_pixel8(r
, g
, b
) | alpha
;
1089 *dest
= rgb_to_pixel15(r
, g
, b
) | alpha
;
1092 *dest
= rgb_to_pixel16(r
, g
, b
) | alpha
;
1095 *dest
= rgb_to_pixel24(r
, g
, b
) | alpha
;
1098 *dest
= rgb_to_pixel32(r
, g
, b
) | alpha
;
1105 static inline drawfn
pxa2xx_drawfn(PXA2xxLCDState
*s
)
1108 return pxa2xx_draw_fn_32t
[s
->bpp
];
1110 return pxa2xx_draw_fn_32
[s
->bpp
];
1114 static void pxa2xx_lcdc_dma0_redraw_rot0(PXA2xxLCDState
*s
,
1115 hwaddr addr
, int *miny
, int *maxy
)
1117 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1118 int src_width
, dest_width
;
1119 drawfn fn
= pxa2xx_drawfn(s
);
1123 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
1124 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
1126 else if (s
->bpp
> pxa_lcdc_16bpp
)
1128 else if (s
->bpp
> pxa_lcdc_8bpp
)
1131 dest_width
= s
->xres
* DEST_PIXEL_WIDTH
;
1133 if (s
->invalidated
) {
1134 framebuffer_update_memory_section(&s
->fbsection
, s
->sysmem
,
1135 addr
, s
->yres
, src_width
);
1137 framebuffer_update_display(surface
, &s
->fbsection
, s
->xres
, s
->yres
,
1138 src_width
, dest_width
, DEST_PIXEL_WIDTH
,
1140 fn
, s
->dma_ch
[0].palette
, miny
, maxy
);
1143 static void pxa2xx_lcdc_dma0_redraw_rot90(PXA2xxLCDState
*s
,
1144 hwaddr addr
, int *miny
, int *maxy
)
1146 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1147 int src_width
, dest_width
;
1148 drawfn fn
= pxa2xx_drawfn(s
);
1152 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
1153 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
)
1155 else if (s
->bpp
> pxa_lcdc_16bpp
)
1157 else if (s
->bpp
> pxa_lcdc_8bpp
)
1160 dest_width
= s
->yres
* DEST_PIXEL_WIDTH
;
1162 if (s
->invalidated
) {
1163 framebuffer_update_memory_section(&s
->fbsection
, s
->sysmem
,
1164 addr
, s
->yres
, src_width
);
1166 framebuffer_update_display(surface
, &s
->fbsection
, s
->xres
, s
->yres
,
1167 src_width
, DEST_PIXEL_WIDTH
, -dest_width
,
1169 fn
, s
->dma_ch
[0].palette
,
1173 static void pxa2xx_lcdc_dma0_redraw_rot180(PXA2xxLCDState
*s
,
1174 hwaddr addr
, int *miny
, int *maxy
)
1176 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1177 int src_width
, dest_width
;
1178 drawfn fn
= pxa2xx_drawfn(s
);
1183 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
1184 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
) {
1186 } else if (s
->bpp
> pxa_lcdc_16bpp
) {
1188 } else if (s
->bpp
> pxa_lcdc_8bpp
) {
1192 dest_width
= s
->xres
* DEST_PIXEL_WIDTH
;
1194 if (s
->invalidated
) {
1195 framebuffer_update_memory_section(&s
->fbsection
, s
->sysmem
,
1196 addr
, s
->yres
, src_width
);
1198 framebuffer_update_display(surface
, &s
->fbsection
, s
->xres
, s
->yres
,
1199 src_width
, -dest_width
, -DEST_PIXEL_WIDTH
,
1201 fn
, s
->dma_ch
[0].palette
, miny
, maxy
);
1204 static void pxa2xx_lcdc_dma0_redraw_rot270(PXA2xxLCDState
*s
,
1205 hwaddr addr
, int *miny
, int *maxy
)
1207 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1208 int src_width
, dest_width
;
1209 drawfn fn
= pxa2xx_drawfn(s
);
1214 src_width
= (s
->xres
+ 3) & ~3; /* Pad to a 4 pixels multiple */
1215 if (s
->bpp
== pxa_lcdc_19pbpp
|| s
->bpp
== pxa_lcdc_18pbpp
) {
1217 } else if (s
->bpp
> pxa_lcdc_16bpp
) {
1219 } else if (s
->bpp
> pxa_lcdc_8bpp
) {
1223 dest_width
= s
->yres
* DEST_PIXEL_WIDTH
;
1225 if (s
->invalidated
) {
1226 framebuffer_update_memory_section(&s
->fbsection
, s
->sysmem
,
1227 addr
, s
->yres
, src_width
);
1229 framebuffer_update_display(surface
, &s
->fbsection
, s
->xres
, s
->yres
,
1230 src_width
, -DEST_PIXEL_WIDTH
, dest_width
,
1232 fn
, s
->dma_ch
[0].palette
,
1236 static void pxa2xx_lcdc_resize(PXA2xxLCDState
*s
)
1239 if (!(s
->control
[0] & LCCR0_ENB
))
1242 width
= LCCR1_PPL(s
->control
[1]) + 1;
1243 height
= LCCR2_LPP(s
->control
[2]) + 1;
1245 if (width
!= s
->xres
|| height
!= s
->yres
) {
1246 if (s
->orientation
== 90 || s
->orientation
== 270) {
1247 qemu_console_resize(s
->con
, height
, width
);
1249 qemu_console_resize(s
->con
, width
, height
);
1257 static void pxa2xx_update_display(void *opaque
)
1259 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
1263 if (!(s
->control
[0] & LCCR0_ENB
))
1266 pxa2xx_descriptor_load(s
);
1268 pxa2xx_lcdc_resize(s
);
1271 s
->transp
= s
->dma_ch
[2].up
|| s
->dma_ch
[3].up
;
1272 /* Note: With overlay planes the order depends on LCCR0 bit 25. */
1273 for (ch
= 0; ch
< PXA_LCDDMA_CHANS
; ch
++)
1274 if (s
->dma_ch
[ch
].up
) {
1275 if (!s
->dma_ch
[ch
].source
) {
1276 pxa2xx_dma_ber_set(s
, ch
);
1279 fbptr
= s
->dma_ch
[ch
].source
;
1280 if (!((fbptr
>= PXA2XX_SDRAM_BASE
&&
1281 fbptr
<= PXA2XX_SDRAM_BASE
+ current_machine
->ram_size
) ||
1282 (fbptr
>= PXA2XX_INTERNAL_BASE
&&
1283 fbptr
<= PXA2XX_INTERNAL_BASE
+ PXA2XX_INTERNAL_SIZE
))) {
1284 pxa2xx_dma_ber_set(s
, ch
);
1288 if (s
->dma_ch
[ch
].command
& LDCMD_PAL
) {
1289 cpu_physical_memory_read(fbptr
, s
->dma_ch
[ch
].pbuffer
,
1290 MAX(LDCMD_LENGTH(s
->dma_ch
[ch
].command
),
1291 sizeof(s
->dma_ch
[ch
].pbuffer
)));
1292 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
1294 /* Do we need to reparse palette */
1295 if (LCCR4_PALFOR(s
->control
[4]) != s
->pal_for
)
1296 pxa2xx_palette_parse(s
, ch
, s
->bpp
);
1298 /* ACK frame start */
1299 pxa2xx_dma_sof_set(s
, ch
);
1301 s
->dma_ch
[ch
].redraw(s
, fbptr
, &miny
, &maxy
);
1304 /* ACK frame completed */
1305 pxa2xx_dma_eof_set(s
, ch
);
1309 if (s
->control
[0] & LCCR0_DIS
) {
1310 /* ACK last frame completed */
1311 s
->control
[0] &= ~LCCR0_ENB
;
1312 s
->status
[0] |= LCSR0_LDD
;
1316 switch (s
->orientation
) {
1318 dpy_gfx_update(s
->con
, 0, miny
, s
->xres
, maxy
- miny
+ 1);
1321 dpy_gfx_update(s
->con
, miny
, 0, maxy
- miny
+ 1, s
->xres
);
1324 maxy
= s
->yres
- maxy
- 1;
1325 miny
= s
->yres
- miny
- 1;
1326 dpy_gfx_update(s
->con
, 0, maxy
, s
->xres
, miny
- maxy
+ 1);
1329 maxy
= s
->yres
- maxy
- 1;
1330 miny
= s
->yres
- miny
- 1;
1331 dpy_gfx_update(s
->con
, maxy
, 0, miny
- maxy
+ 1, s
->xres
);
1335 pxa2xx_lcdc_int_update(s
);
1337 qemu_irq_raise(s
->vsync_cb
);
1340 static void pxa2xx_invalidate_display(void *opaque
)
1342 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
1346 static void pxa2xx_lcdc_orientation(void *opaque
, int angle
)
1348 PXA2xxLCDState
*s
= (PXA2xxLCDState
*) opaque
;
1352 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot0
;
1355 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot90
;
1358 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot180
;
1361 s
->dma_ch
[0].redraw
= pxa2xx_lcdc_dma0_redraw_rot270
;
1365 s
->orientation
= angle
;
1366 s
->xres
= s
->yres
= -1;
1367 pxa2xx_lcdc_resize(s
);
1370 static const VMStateDescription vmstate_dma_channel
= {
1371 .name
= "dma_channel",
1373 .minimum_version_id
= 0,
1374 .fields
= (const VMStateField
[]) {
1375 VMSTATE_UINT32(branch
, struct DMAChannel
),
1376 VMSTATE_UINT8(up
, struct DMAChannel
),
1377 VMSTATE_BUFFER(pbuffer
, struct DMAChannel
),
1378 VMSTATE_UINT32(descriptor
, struct DMAChannel
),
1379 VMSTATE_UINT32(source
, struct DMAChannel
),
1380 VMSTATE_UINT32(id
, struct DMAChannel
),
1381 VMSTATE_UINT32(command
, struct DMAChannel
),
1382 VMSTATE_END_OF_LIST()
1386 static int pxa2xx_lcdc_post_load(void *opaque
, int version_id
)
1388 PXA2xxLCDState
*s
= opaque
;
1390 s
->bpp
= LCCR3_BPP(s
->control
[3]);
1391 s
->xres
= s
->yres
= s
->pal_for
= -1;
1396 static const VMStateDescription vmstate_pxa2xx_lcdc
= {
1397 .name
= "pxa2xx_lcdc",
1399 .minimum_version_id
= 0,
1400 .post_load
= pxa2xx_lcdc_post_load
,
1401 .fields
= (const VMStateField
[]) {
1402 VMSTATE_INT32(irqlevel
, PXA2xxLCDState
),
1403 VMSTATE_INT32(transp
, PXA2xxLCDState
),
1404 VMSTATE_UINT32_ARRAY(control
, PXA2xxLCDState
, 6),
1405 VMSTATE_UINT32_ARRAY(status
, PXA2xxLCDState
, 2),
1406 VMSTATE_UINT32_ARRAY(ovl1c
, PXA2xxLCDState
, 2),
1407 VMSTATE_UINT32_ARRAY(ovl2c
, PXA2xxLCDState
, 2),
1408 VMSTATE_UINT32(ccr
, PXA2xxLCDState
),
1409 VMSTATE_UINT32(cmdcr
, PXA2xxLCDState
),
1410 VMSTATE_UINT32(trgbr
, PXA2xxLCDState
),
1411 VMSTATE_UINT32(tcr
, PXA2xxLCDState
),
1412 VMSTATE_UINT32(liidr
, PXA2xxLCDState
),
1413 VMSTATE_UINT8(bscntr
, PXA2xxLCDState
),
1414 VMSTATE_STRUCT_ARRAY(dma_ch
, PXA2xxLCDState
, 7, 0,
1415 vmstate_dma_channel
, struct DMAChannel
),
1416 VMSTATE_END_OF_LIST()
1420 static const GraphicHwOps pxa2xx_ops
= {
1421 .invalidate
= pxa2xx_invalidate_display
,
1422 .gfx_update
= pxa2xx_update_display
,
1425 PXA2xxLCDState
*pxa2xx_lcdc_init(MemoryRegion
*sysmem
,
1426 hwaddr base
, qemu_irq irq
)
1430 s
= g_new0(PXA2xxLCDState
, 1);
1435 pxa2xx_lcdc_orientation(s
, graphic_rotate
);
1437 memory_region_init_io(&s
->iomem
, NULL
, &pxa2xx_lcdc_ops
, s
,
1438 "pxa2xx-lcd-controller", 0x00100000);
1439 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
1441 s
->con
= graphic_console_init(NULL
, 0, &pxa2xx_ops
, s
);
1443 vmstate_register(NULL
, 0, &vmstate_pxa2xx_lcdc
, s
);
1448 void pxa2xx_lcd_vsync_notifier(PXA2xxLCDState
*s
, qemu_irq handler
)
1450 s
->vsync_cb
= handler
;