]> git.proxmox.com Git - qemu.git/blame - hw/pl110_template.h
esp: cancel current request only if some request is in flight
[qemu.git] / hw / pl110_template.h
CommitLineData
5fafdf24 1/*
bdd5003a
PB
2 * Arm PrimeCell PL110 Color LCD Controller
3 *
4 * Copyright (c) 2005 CodeSourcery, LLC.
5 * Written by Paul Brook
6 *
7 * This code is licenced under the GNU LGPL
8 *
9 * Framebuffer format conversion routines.
10 */
11
12#ifndef ORDER
13
14#if BITS == 8
15#define COPY_PIXEL(to, from) *(to++) = from
16#elif BITS == 15 || BITS == 16
17#define COPY_PIXEL(to, from) *(uint16_t *)to = from; to += 2;
5fafdf24 18#elif BITS == 24
bdd5003a
PB
19#define COPY_PIXEL(to, from) \
20 *(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16
21#elif BITS == 32
22#define COPY_PIXEL(to, from) *(uint32_t *)to = from; to += 4;
23#else
24#error unknown bit depth
25#endif
26
e9c05b42
AZ
27#undef RGB
28#define BORDER bgr
bdd5003a
PB
29#define ORDER 0
30#include "pl110_template.h"
31#define ORDER 1
32#include "pl110_template.h"
33#define ORDER 2
34#include "pl110_template.h"
e9c05b42
AZ
35#undef BORDER
36#define RGB
37#define BORDER rgb
38#define ORDER 0
39#include "pl110_template.h"
40#define ORDER 1
41#include "pl110_template.h"
42#define ORDER 2
43#include "pl110_template.h"
44#undef BORDER
bdd5003a 45
e9c05b42 46static drawfn glue(pl110_draw_fn_,BITS)[36] =
bdd5003a 47{
e9c05b42
AZ
48 glue(pl110_draw_line1_lblp_bgr,BITS),
49 glue(pl110_draw_line2_lblp_bgr,BITS),
50 glue(pl110_draw_line4_lblp_bgr,BITS),
51 glue(pl110_draw_line8_lblp_bgr,BITS),
52 glue(pl110_draw_line16_lblp_bgr,BITS),
53 glue(pl110_draw_line32_lblp_bgr,BITS),
54
55 glue(pl110_draw_line1_bbbp_bgr,BITS),
56 glue(pl110_draw_line2_bbbp_bgr,BITS),
57 glue(pl110_draw_line4_bbbp_bgr,BITS),
58 glue(pl110_draw_line8_bbbp_bgr,BITS),
59 glue(pl110_draw_line16_bbbp_bgr,BITS),
60 glue(pl110_draw_line32_bbbp_bgr,BITS),
61
62 glue(pl110_draw_line1_lbbp_bgr,BITS),
63 glue(pl110_draw_line2_lbbp_bgr,BITS),
64 glue(pl110_draw_line4_lbbp_bgr,BITS),
65 glue(pl110_draw_line8_lbbp_bgr,BITS),
66 glue(pl110_draw_line16_lbbp_bgr,BITS),
67 glue(pl110_draw_line32_lbbp_bgr,BITS),
68
69 glue(pl110_draw_line1_lblp_rgb,BITS),
70 glue(pl110_draw_line2_lblp_rgb,BITS),
71 glue(pl110_draw_line4_lblp_rgb,BITS),
72 glue(pl110_draw_line8_lblp_rgb,BITS),
73 glue(pl110_draw_line16_lblp_rgb,BITS),
74 glue(pl110_draw_line32_lblp_rgb,BITS),
75
76 glue(pl110_draw_line1_bbbp_rgb,BITS),
77 glue(pl110_draw_line2_bbbp_rgb,BITS),
78 glue(pl110_draw_line4_bbbp_rgb,BITS),
79 glue(pl110_draw_line8_bbbp_rgb,BITS),
80 glue(pl110_draw_line16_bbbp_rgb,BITS),
81 glue(pl110_draw_line32_bbbp_rgb,BITS),
82
83 glue(pl110_draw_line1_lbbp_rgb,BITS),
84 glue(pl110_draw_line2_lbbp_rgb,BITS),
85 glue(pl110_draw_line4_lbbp_rgb,BITS),
86 glue(pl110_draw_line8_lbbp_rgb,BITS),
87 glue(pl110_draw_line16_lbbp_rgb,BITS),
88 glue(pl110_draw_line32_lbbp_rgb,BITS),
bdd5003a
PB
89};
90
91#undef BITS
92#undef COPY_PIXEL
93
94#else
95
96#if ORDER == 0
e9c05b42 97#define NAME glue(glue(lblp_, BORDER), BITS)
e2542fe2 98#ifdef HOST_WORDS_BIGENDIAN
bdd5003a
PB
99#define SWAP_WORDS 1
100#endif
101#elif ORDER == 1
e9c05b42 102#define NAME glue(glue(bbbp_, BORDER), BITS)
e2542fe2 103#ifndef HOST_WORDS_BIGENDIAN
bdd5003a
PB
104#define SWAP_WORDS 1
105#endif
106#else
107#define SWAP_PIXELS 1
e9c05b42 108#define NAME glue(glue(lbbp_, BORDER), BITS)
e2542fe2 109#ifdef HOST_WORDS_BIGENDIAN
bdd5003a
PB
110#define SWAP_WORDS 1
111#endif
112#endif
113
114#define FN_2(x, y) FN(x, y) FN(x+1, y)
1f9519c9 115#define FN_4(x, y) FN_2(x, y) FN_2(x+2, y)
bdd5003a
PB
116#define FN_8(y) FN_4(0, y) FN_4(4, y)
117
714fa308 118static void glue(pl110_draw_line1_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
bdd5003a 119{
714fa308 120 uint32_t *pallette = opaque;
bdd5003a
PB
121 uint32_t data;
122 while (width > 0) {
123 data = *(uint32_t *)src;
124#ifdef SWAP_PIXELS
125#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 7 - (x))) & 1]);
126#else
127#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x) + y)) & 1]);
128#endif
be9d3657 129#ifdef SWAP_WORDS
bdd5003a
PB
130 FN_8(24)
131 FN_8(16)
132 FN_8(8)
133 FN_8(0)
134#else
135 FN_8(0)
136 FN_8(8)
137 FN_8(16)
138 FN_8(24)
139#endif
140#undef FN
141 width -= 32;
142 src += 4;
143 }
144}
145
714fa308 146static void glue(pl110_draw_line2_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
bdd5003a 147{
714fa308 148 uint32_t *pallette = opaque;
bdd5003a
PB
149 uint32_t data;
150 while (width > 0) {
151 data = *(uint32_t *)src;
152#ifdef SWAP_PIXELS
153#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 6 - (x)*2)) & 3]);
154#else
155#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*2 + y)) & 3]);
156#endif
be9d3657 157#ifdef SWAP_WORDS
bdd5003a
PB
158 FN_4(0, 24)
159 FN_4(0, 16)
160 FN_4(0, 8)
161 FN_4(0, 0)
162#else
163 FN_4(0, 0)
164 FN_4(0, 8)
165 FN_4(0, 16)
166 FN_4(0, 24)
167#endif
168#undef FN
169 width -= 16;
170 src += 4;
171 }
172}
173
714fa308 174static void glue(pl110_draw_line4_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
bdd5003a 175{
714fa308 176 uint32_t *pallette = opaque;
bdd5003a
PB
177 uint32_t data;
178 while (width > 0) {
179 data = *(uint32_t *)src;
180#ifdef SWAP_PIXELS
181#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 4 - (x)*4)) & 0xf]);
182#else
183#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*4 + y)) & 0xf]);
184#endif
be9d3657 185#ifdef SWAP_WORDS
bdd5003a
PB
186 FN_2(0, 24)
187 FN_2(0, 16)
188 FN_2(0, 8)
189 FN_2(0, 0)
190#else
191 FN_2(0, 0)
192 FN_2(0, 8)
193 FN_2(0, 16)
194 FN_2(0, 24)
195#endif
196#undef FN
197 width -= 8;
198 src += 4;
199 }
200}
201
714fa308 202static void glue(pl110_draw_line8_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
bdd5003a 203{
714fa308 204 uint32_t *pallette = opaque;
bdd5003a
PB
205 uint32_t data;
206 while (width > 0) {
207 data = *(uint32_t *)src;
208#define FN(x) COPY_PIXEL(d, pallette[(data >> (x)) & 0xff]);
be9d3657 209#ifdef SWAP_WORDS
bdd5003a
PB
210 FN(24)
211 FN(16)
212 FN(8)
213 FN(0)
214#else
215 FN(0)
216 FN(8)
217 FN(16)
218 FN(24)
219#endif
220#undef FN
221 width -= 4;
222 src += 4;
223 }
224}
225
714fa308 226static void glue(pl110_draw_line16_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
bdd5003a
PB
227{
228 uint32_t data;
229 unsigned int r, g, b;
230 while (width > 0) {
231 data = *(uint32_t *)src;
be9d3657 232#ifdef SWAP_WORDS
bdd5003a
PB
233 data = bswap32(data);
234#endif
e9c05b42
AZ
235#ifdef RGB
236#define LSB r
237#define MSB b
238#else
239#define LSB b
240#define MSB r
241#endif
bdd5003a 242#if 0
e9c05b42 243 LSB = data & 0x1f;
bdd5003a
PB
244 data >>= 5;
245 g = data & 0x3f;
246 data >>= 6;
e9c05b42 247 MSB = data & 0x1f;
bdd5003a
PB
248 data >>= 5;
249#else
e9c05b42 250 LSB = (data & 0x1f) << 3;
bdd5003a
PB
251 data >>= 5;
252 g = (data & 0x3f) << 2;
253 data >>= 6;
e9c05b42 254 MSB = (data & 0x1f) << 3;
bdd5003a
PB
255 data >>= 5;
256#endif
257 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
e9c05b42 258 LSB = (data & 0x1f) << 3;
bdd5003a
PB
259 data >>= 5;
260 g = (data & 0x3f) << 2;
261 data >>= 6;
e9c05b42 262 MSB = (data & 0x1f) << 3;
bdd5003a
PB
263 data >>= 5;
264 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
e9c05b42
AZ
265#undef MSB
266#undef LSB
bdd5003a
PB
267 width -= 2;
268 src += 4;
269 }
270}
271
714fa308 272static void glue(pl110_draw_line32_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
bdd5003a
PB
273{
274 uint32_t data;
275 unsigned int r, g, b;
276 while (width > 0) {
277 data = *(uint32_t *)src;
e9c05b42
AZ
278#ifdef RGB
279#define LSB r
280#define MSB b
281#else
282#define LSB b
283#define MSB r
284#endif
399a4e21 285#ifndef SWAP_WORDS
e9c05b42 286 LSB = data & 0xff;
bdd5003a 287 g = (data >> 8) & 0xff;
e9c05b42 288 MSB = (data >> 16) & 0xff;
bdd5003a 289#else
e9c05b42 290 LSB = (data >> 24) & 0xff;
bdd5003a 291 g = (data >> 16) & 0xff;
e9c05b42 292 MSB = (data >> 8) & 0xff;
bdd5003a
PB
293#endif
294 COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
e9c05b42
AZ
295#undef MSB
296#undef LSB
bdd5003a
PB
297 width--;
298 src += 4;
299 }
300}
301
302#undef SWAP_PIXELS
303#undef NAME
304#undef SWAP_WORDS
305#undef ORDER
306
307#endif