]>
Commit | Line | Data |
---|---|---|
420557e8 | 1 | /* |
6f7e9aec | 2 | * QEMU TCX Frame buffer |
5fafdf24 | 3 | * |
6f7e9aec | 4 | * Copyright (c) 2003-2005 Fabrice Bellard |
5fafdf24 | 5 | * |
420557e8 FB |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
f40070c3 | 24 | |
077805fa | 25 | #include "qemu-common.h" |
28ecbaee PB |
26 | #include "ui/console.h" |
27 | #include "ui/pixel_ops.h" | |
83c9f4ca | 28 | #include "hw/sysbus.h" |
420557e8 | 29 | |
420557e8 FB |
30 | #define MAXX 1024 |
31 | #define MAXY 768 | |
6f7e9aec | 32 | #define TCX_DAC_NREGS 16 |
8508b89e BS |
33 | #define TCX_THC_NREGS_8 0x081c |
34 | #define TCX_THC_NREGS_24 0x1000 | |
35 | #define TCX_TEC_NREGS 0x1000 | |
420557e8 | 36 | |
420557e8 | 37 | typedef struct TCXState { |
f40070c3 | 38 | SysBusDevice busdev; |
c78f7137 | 39 | QemuConsole *con; |
8d5f07fa | 40 | uint8_t *vram; |
eee0b836 | 41 | uint32_t *vram24, *cplane; |
d08151bf AK |
42 | MemoryRegion vram_mem; |
43 | MemoryRegion vram_8bit; | |
44 | MemoryRegion vram_24bit; | |
45 | MemoryRegion vram_cplane; | |
46 | MemoryRegion dac; | |
47 | MemoryRegion tec; | |
48 | MemoryRegion thc24; | |
49 | MemoryRegion thc8; | |
50 | ram_addr_t vram24_offset, cplane_offset; | |
ee6847d1 | 51 | uint32_t vram_size; |
21206a10 | 52 | uint32_t palette[256]; |
427a66c3 BS |
53 | uint8_t r[256], g[256], b[256]; |
54 | uint16_t width, height, depth; | |
6f7e9aec | 55 | uint8_t dac_index, dac_state; |
420557e8 FB |
56 | } TCXState; |
57 | ||
d3ffcafe BS |
58 | static void tcx_set_dirty(TCXState *s) |
59 | { | |
fd4aa979 | 60 | memory_region_set_dirty(&s->vram_mem, 0, MAXX * MAXY); |
d3ffcafe BS |
61 | } |
62 | ||
63 | static void tcx24_set_dirty(TCXState *s) | |
64 | { | |
fd4aa979 BS |
65 | memory_region_set_dirty(&s->vram_mem, s->vram24_offset, MAXX * MAXY * 4); |
66 | memory_region_set_dirty(&s->vram_mem, s->cplane_offset, MAXX * MAXY * 4); | |
d3ffcafe | 67 | } |
95219897 | 68 | |
21206a10 FB |
69 | static void update_palette_entries(TCXState *s, int start, int end) |
70 | { | |
c78f7137 | 71 | DisplaySurface *surface = qemu_console_surface(s->con); |
21206a10 | 72 | int i; |
c78f7137 GH |
73 | |
74 | for (i = start; i < end; i++) { | |
75 | switch (surface_bits_per_pixel(surface)) { | |
21206a10 FB |
76 | default: |
77 | case 8: | |
78 | s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]); | |
79 | break; | |
80 | case 15: | |
8927bcfd | 81 | s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]); |
21206a10 FB |
82 | break; |
83 | case 16: | |
8927bcfd | 84 | s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]); |
21206a10 FB |
85 | break; |
86 | case 32: | |
c78f7137 | 87 | if (is_surface_bgr(surface)) { |
7b5d76da | 88 | s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]); |
c78f7137 | 89 | } else { |
7b5d76da | 90 | s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]); |
c78f7137 | 91 | } |
21206a10 FB |
92 | break; |
93 | } | |
94 | } | |
d3ffcafe BS |
95 | if (s->depth == 24) { |
96 | tcx24_set_dirty(s); | |
97 | } else { | |
98 | tcx_set_dirty(s); | |
99 | } | |
21206a10 FB |
100 | } |
101 | ||
5fafdf24 | 102 | static void tcx_draw_line32(TCXState *s1, uint8_t *d, |
f930d07e | 103 | const uint8_t *s, int width) |
420557e8 | 104 | { |
e80cfcfc FB |
105 | int x; |
106 | uint8_t val; | |
8bdc2159 | 107 | uint32_t *p = (uint32_t *)d; |
e80cfcfc FB |
108 | |
109 | for(x = 0; x < width; x++) { | |
f930d07e | 110 | val = *s++; |
8bdc2159 | 111 | *p++ = s1->palette[val]; |
e80cfcfc | 112 | } |
420557e8 FB |
113 | } |
114 | ||
5fafdf24 | 115 | static void tcx_draw_line16(TCXState *s1, uint8_t *d, |
f930d07e | 116 | const uint8_t *s, int width) |
e80cfcfc FB |
117 | { |
118 | int x; | |
119 | uint8_t val; | |
8bdc2159 | 120 | uint16_t *p = (uint16_t *)d; |
8d5f07fa | 121 | |
e80cfcfc | 122 | for(x = 0; x < width; x++) { |
f930d07e | 123 | val = *s++; |
8bdc2159 | 124 | *p++ = s1->palette[val]; |
e80cfcfc FB |
125 | } |
126 | } | |
127 | ||
5fafdf24 | 128 | static void tcx_draw_line8(TCXState *s1, uint8_t *d, |
f930d07e | 129 | const uint8_t *s, int width) |
420557e8 | 130 | { |
e80cfcfc FB |
131 | int x; |
132 | uint8_t val; | |
133 | ||
134 | for(x = 0; x < width; x++) { | |
f930d07e | 135 | val = *s++; |
21206a10 | 136 | *d++ = s1->palette[val]; |
420557e8 | 137 | } |
420557e8 FB |
138 | } |
139 | ||
688ea2eb BS |
140 | /* |
141 | XXX Could be much more optimal: | |
142 | * detect if line/page/whole screen is in 24 bit mode | |
143 | * if destination is also BGR, use memcpy | |
144 | */ | |
eee0b836 BS |
145 | static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d, |
146 | const uint8_t *s, int width, | |
147 | const uint32_t *cplane, | |
148 | const uint32_t *s24) | |
149 | { | |
c78f7137 | 150 | DisplaySurface *surface = qemu_console_surface(s1->con); |
7b5d76da | 151 | int x, bgr, r, g, b; |
688ea2eb | 152 | uint8_t val, *p8; |
eee0b836 BS |
153 | uint32_t *p = (uint32_t *)d; |
154 | uint32_t dval; | |
155 | ||
c78f7137 | 156 | bgr = is_surface_bgr(surface); |
eee0b836 | 157 | for(x = 0; x < width; x++, s++, s24++) { |
688ea2eb BS |
158 | if ((be32_to_cpu(*cplane++) & 0xff000000) == 0x03000000) { |
159 | // 24-bit direct, BGR order | |
160 | p8 = (uint8_t *)s24; | |
161 | p8++; | |
162 | b = *p8++; | |
163 | g = *p8++; | |
f7e683b8 | 164 | r = *p8; |
7b5d76da AL |
165 | if (bgr) |
166 | dval = rgb_to_pixel32bgr(r, g, b); | |
167 | else | |
168 | dval = rgb_to_pixel32(r, g, b); | |
eee0b836 BS |
169 | } else { |
170 | val = *s; | |
171 | dval = s1->palette[val]; | |
172 | } | |
173 | *p++ = dval; | |
174 | } | |
175 | } | |
176 | ||
d08151bf | 177 | static inline int check_dirty(TCXState *s, ram_addr_t page, ram_addr_t page24, |
c227f099 | 178 | ram_addr_t cpage) |
eee0b836 BS |
179 | { |
180 | int ret; | |
eee0b836 | 181 | |
cd7a45c9 BS |
182 | ret = memory_region_get_dirty(&s->vram_mem, page, TARGET_PAGE_SIZE, |
183 | DIRTY_MEMORY_VGA); | |
184 | ret |= memory_region_get_dirty(&s->vram_mem, page24, TARGET_PAGE_SIZE * 4, | |
185 | DIRTY_MEMORY_VGA); | |
186 | ret |= memory_region_get_dirty(&s->vram_mem, cpage, TARGET_PAGE_SIZE * 4, | |
187 | DIRTY_MEMORY_VGA); | |
eee0b836 BS |
188 | return ret; |
189 | } | |
190 | ||
c227f099 AL |
191 | static inline void reset_dirty(TCXState *ts, ram_addr_t page_min, |
192 | ram_addr_t page_max, ram_addr_t page24, | |
193 | ram_addr_t cpage) | |
eee0b836 | 194 | { |
d08151bf | 195 | memory_region_reset_dirty(&ts->vram_mem, |
f10acc8b MCA |
196 | page_min, |
197 | (page_max - page_min) + TARGET_PAGE_SIZE, | |
d08151bf AK |
198 | DIRTY_MEMORY_VGA); |
199 | memory_region_reset_dirty(&ts->vram_mem, | |
200 | page24 + page_min * 4, | |
f10acc8b | 201 | (page_max - page_min) * 4 + TARGET_PAGE_SIZE, |
d08151bf AK |
202 | DIRTY_MEMORY_VGA); |
203 | memory_region_reset_dirty(&ts->vram_mem, | |
204 | cpage + page_min * 4, | |
f10acc8b | 205 | (page_max - page_min) * 4 + TARGET_PAGE_SIZE, |
d08151bf | 206 | DIRTY_MEMORY_VGA); |
eee0b836 BS |
207 | } |
208 | ||
e80cfcfc FB |
209 | /* Fixed line length 1024 allows us to do nice tricks not possible on |
210 | VGA... */ | |
95219897 | 211 | static void tcx_update_display(void *opaque) |
420557e8 | 212 | { |
e80cfcfc | 213 | TCXState *ts = opaque; |
c78f7137 | 214 | DisplaySurface *surface = qemu_console_surface(ts->con); |
c227f099 | 215 | ram_addr_t page, page_min, page_max; |
550be127 | 216 | int y, y_start, dd, ds; |
e80cfcfc | 217 | uint8_t *d, *s; |
b3ceef24 | 218 | void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width); |
e80cfcfc | 219 | |
c78f7137 | 220 | if (surface_bits_per_pixel(surface) == 0) { |
f930d07e | 221 | return; |
c78f7137 GH |
222 | } |
223 | ||
d08151bf | 224 | page = 0; |
e80cfcfc | 225 | y_start = -1; |
c0c440f3 | 226 | page_min = -1; |
550be127 | 227 | page_max = 0; |
c78f7137 | 228 | d = surface_data(surface); |
6f7e9aec | 229 | s = ts->vram; |
c78f7137 | 230 | dd = surface_stride(surface); |
e80cfcfc FB |
231 | ds = 1024; |
232 | ||
c78f7137 | 233 | switch (surface_bits_per_pixel(surface)) { |
e80cfcfc | 234 | case 32: |
f930d07e BS |
235 | f = tcx_draw_line32; |
236 | break; | |
21206a10 FB |
237 | case 15: |
238 | case 16: | |
f930d07e BS |
239 | f = tcx_draw_line16; |
240 | break; | |
e80cfcfc FB |
241 | default: |
242 | case 8: | |
f930d07e BS |
243 | f = tcx_draw_line8; |
244 | break; | |
e80cfcfc | 245 | case 0: |
f930d07e | 246 | return; |
e80cfcfc | 247 | } |
3b46e624 | 248 | |
6f7e9aec | 249 | for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE) { |
cd7a45c9 BS |
250 | if (memory_region_get_dirty(&ts->vram_mem, page, TARGET_PAGE_SIZE, |
251 | DIRTY_MEMORY_VGA)) { | |
f930d07e | 252 | if (y_start < 0) |
e80cfcfc FB |
253 | y_start = y; |
254 | if (page < page_min) | |
255 | page_min = page; | |
256 | if (page > page_max) | |
257 | page_max = page; | |
f930d07e BS |
258 | f(ts, d, s, ts->width); |
259 | d += dd; | |
260 | s += ds; | |
261 | f(ts, d, s, ts->width); | |
262 | d += dd; | |
263 | s += ds; | |
264 | f(ts, d, s, ts->width); | |
265 | d += dd; | |
266 | s += ds; | |
267 | f(ts, d, s, ts->width); | |
268 | d += dd; | |
269 | s += ds; | |
270 | } else { | |
e80cfcfc FB |
271 | if (y_start >= 0) { |
272 | /* flush to display */ | |
c78f7137 | 273 | dpy_gfx_update(ts->con, 0, y_start, |
a93a4a22 | 274 | ts->width, y - y_start); |
e80cfcfc FB |
275 | y_start = -1; |
276 | } | |
f930d07e BS |
277 | d += dd * 4; |
278 | s += ds * 4; | |
279 | } | |
e80cfcfc FB |
280 | } |
281 | if (y_start >= 0) { | |
f930d07e | 282 | /* flush to display */ |
c78f7137 | 283 | dpy_gfx_update(ts->con, 0, y_start, |
a93a4a22 | 284 | ts->width, y - y_start); |
e80cfcfc FB |
285 | } |
286 | /* reset modified pages */ | |
c0c440f3 | 287 | if (page_max >= page_min) { |
d08151bf | 288 | memory_region_reset_dirty(&ts->vram_mem, |
f10acc8b MCA |
289 | page_min, |
290 | (page_max - page_min) + TARGET_PAGE_SIZE, | |
d08151bf | 291 | DIRTY_MEMORY_VGA); |
e80cfcfc | 292 | } |
420557e8 FB |
293 | } |
294 | ||
eee0b836 BS |
295 | static void tcx24_update_display(void *opaque) |
296 | { | |
297 | TCXState *ts = opaque; | |
c78f7137 | 298 | DisplaySurface *surface = qemu_console_surface(ts->con); |
c227f099 | 299 | ram_addr_t page, page_min, page_max, cpage, page24; |
eee0b836 BS |
300 | int y, y_start, dd, ds; |
301 | uint8_t *d, *s; | |
302 | uint32_t *cptr, *s24; | |
303 | ||
c78f7137 | 304 | if (surface_bits_per_pixel(surface) != 32) { |
eee0b836 | 305 | return; |
c78f7137 GH |
306 | } |
307 | ||
d08151bf | 308 | page = 0; |
eee0b836 BS |
309 | page24 = ts->vram24_offset; |
310 | cpage = ts->cplane_offset; | |
311 | y_start = -1; | |
c0c440f3 | 312 | page_min = -1; |
eee0b836 | 313 | page_max = 0; |
c78f7137 | 314 | d = surface_data(surface); |
eee0b836 BS |
315 | s = ts->vram; |
316 | s24 = ts->vram24; | |
317 | cptr = ts->cplane; | |
c78f7137 | 318 | dd = surface_stride(surface); |
eee0b836 BS |
319 | ds = 1024; |
320 | ||
321 | for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE, | |
322 | page24 += TARGET_PAGE_SIZE, cpage += TARGET_PAGE_SIZE) { | |
d08151bf | 323 | if (check_dirty(ts, page, page24, cpage)) { |
eee0b836 BS |
324 | if (y_start < 0) |
325 | y_start = y; | |
326 | if (page < page_min) | |
327 | page_min = page; | |
328 | if (page > page_max) | |
329 | page_max = page; | |
330 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
331 | d += dd; | |
332 | s += ds; | |
333 | cptr += ds; | |
334 | s24 += ds; | |
335 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
336 | d += dd; | |
337 | s += ds; | |
338 | cptr += ds; | |
339 | s24 += ds; | |
340 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
341 | d += dd; | |
342 | s += ds; | |
343 | cptr += ds; | |
344 | s24 += ds; | |
345 | tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | |
346 | d += dd; | |
347 | s += ds; | |
348 | cptr += ds; | |
349 | s24 += ds; | |
350 | } else { | |
351 | if (y_start >= 0) { | |
352 | /* flush to display */ | |
c78f7137 | 353 | dpy_gfx_update(ts->con, 0, y_start, |
a93a4a22 | 354 | ts->width, y - y_start); |
eee0b836 BS |
355 | y_start = -1; |
356 | } | |
357 | d += dd * 4; | |
358 | s += ds * 4; | |
359 | cptr += ds * 4; | |
360 | s24 += ds * 4; | |
361 | } | |
362 | } | |
363 | if (y_start >= 0) { | |
364 | /* flush to display */ | |
c78f7137 | 365 | dpy_gfx_update(ts->con, 0, y_start, |
a93a4a22 | 366 | ts->width, y - y_start); |
eee0b836 BS |
367 | } |
368 | /* reset modified pages */ | |
c0c440f3 | 369 | if (page_max >= page_min) { |
eee0b836 BS |
370 | reset_dirty(ts, page_min, page_max, page24, cpage); |
371 | } | |
372 | } | |
373 | ||
95219897 | 374 | static void tcx_invalidate_display(void *opaque) |
420557e8 | 375 | { |
e80cfcfc | 376 | TCXState *s = opaque; |
e80cfcfc | 377 | |
d3ffcafe | 378 | tcx_set_dirty(s); |
c78f7137 | 379 | qemu_console_resize(s->con, s->width, s->height); |
420557e8 FB |
380 | } |
381 | ||
eee0b836 BS |
382 | static void tcx24_invalidate_display(void *opaque) |
383 | { | |
384 | TCXState *s = opaque; | |
eee0b836 | 385 | |
d3ffcafe BS |
386 | tcx_set_dirty(s); |
387 | tcx24_set_dirty(s); | |
c78f7137 | 388 | qemu_console_resize(s->con, s->width, s->height); |
eee0b836 BS |
389 | } |
390 | ||
e59fb374 | 391 | static int vmstate_tcx_post_load(void *opaque, int version_id) |
420557e8 FB |
392 | { |
393 | TCXState *s = opaque; | |
3b46e624 | 394 | |
21206a10 | 395 | update_palette_entries(s, 0, 256); |
d3ffcafe BS |
396 | if (s->depth == 24) { |
397 | tcx24_set_dirty(s); | |
398 | } else { | |
399 | tcx_set_dirty(s); | |
400 | } | |
5425a216 | 401 | |
e80cfcfc | 402 | return 0; |
420557e8 FB |
403 | } |
404 | ||
c0c41a4b BS |
405 | static const VMStateDescription vmstate_tcx = { |
406 | .name ="tcx", | |
407 | .version_id = 4, | |
408 | .minimum_version_id = 4, | |
409 | .minimum_version_id_old = 4, | |
752ff2fa | 410 | .post_load = vmstate_tcx_post_load, |
c0c41a4b BS |
411 | .fields = (VMStateField []) { |
412 | VMSTATE_UINT16(height, TCXState), | |
413 | VMSTATE_UINT16(width, TCXState), | |
414 | VMSTATE_UINT16(depth, TCXState), | |
415 | VMSTATE_BUFFER(r, TCXState), | |
416 | VMSTATE_BUFFER(g, TCXState), | |
417 | VMSTATE_BUFFER(b, TCXState), | |
418 | VMSTATE_UINT8(dac_index, TCXState), | |
419 | VMSTATE_UINT8(dac_state, TCXState), | |
420 | VMSTATE_END_OF_LIST() | |
421 | } | |
422 | }; | |
423 | ||
7f23f812 | 424 | static void tcx_reset(DeviceState *d) |
420557e8 | 425 | { |
7f23f812 | 426 | TCXState *s = container_of(d, TCXState, busdev.qdev); |
e80cfcfc FB |
427 | |
428 | /* Initialize palette */ | |
429 | memset(s->r, 0, 256); | |
430 | memset(s->g, 0, 256); | |
431 | memset(s->b, 0, 256); | |
432 | s->r[255] = s->g[255] = s->b[255] = 255; | |
21206a10 | 433 | update_palette_entries(s, 0, 256); |
e80cfcfc | 434 | memset(s->vram, 0, MAXX*MAXY); |
d08151bf AK |
435 | memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4), |
436 | DIRTY_MEMORY_VGA); | |
6f7e9aec FB |
437 | s->dac_index = 0; |
438 | s->dac_state = 0; | |
439 | } | |
440 | ||
a8170e5e | 441 | static uint64_t tcx_dac_readl(void *opaque, hwaddr addr, |
d08151bf | 442 | unsigned size) |
6f7e9aec FB |
443 | { |
444 | return 0; | |
445 | } | |
446 | ||
a8170e5e | 447 | static void tcx_dac_writel(void *opaque, hwaddr addr, uint64_t val, |
d08151bf | 448 | unsigned size) |
6f7e9aec FB |
449 | { |
450 | TCXState *s = opaque; | |
6f7e9aec | 451 | |
e64d7d59 | 452 | switch (addr) { |
6f7e9aec | 453 | case 0: |
f930d07e BS |
454 | s->dac_index = val >> 24; |
455 | s->dac_state = 0; | |
456 | break; | |
e64d7d59 | 457 | case 4: |
f930d07e BS |
458 | switch (s->dac_state) { |
459 | case 0: | |
460 | s->r[s->dac_index] = val >> 24; | |
21206a10 | 461 | update_palette_entries(s, s->dac_index, s->dac_index + 1); |
f930d07e BS |
462 | s->dac_state++; |
463 | break; | |
464 | case 1: | |
465 | s->g[s->dac_index] = val >> 24; | |
21206a10 | 466 | update_palette_entries(s, s->dac_index, s->dac_index + 1); |
f930d07e BS |
467 | s->dac_state++; |
468 | break; | |
469 | case 2: | |
470 | s->b[s->dac_index] = val >> 24; | |
21206a10 | 471 | update_palette_entries(s, s->dac_index, s->dac_index + 1); |
5c8cdbf8 | 472 | s->dac_index = (s->dac_index + 1) & 255; // Index autoincrement |
f930d07e BS |
473 | default: |
474 | s->dac_state = 0; | |
475 | break; | |
476 | } | |
477 | break; | |
6f7e9aec | 478 | default: |
f930d07e | 479 | break; |
6f7e9aec | 480 | } |
420557e8 FB |
481 | } |
482 | ||
d08151bf AK |
483 | static const MemoryRegionOps tcx_dac_ops = { |
484 | .read = tcx_dac_readl, | |
485 | .write = tcx_dac_writel, | |
486 | .endianness = DEVICE_NATIVE_ENDIAN, | |
487 | .valid = { | |
488 | .min_access_size = 4, | |
489 | .max_access_size = 4, | |
490 | }, | |
6f7e9aec FB |
491 | }; |
492 | ||
a8170e5e | 493 | static uint64_t dummy_readl(void *opaque, hwaddr addr, |
d08151bf | 494 | unsigned size) |
8508b89e BS |
495 | { |
496 | return 0; | |
497 | } | |
498 | ||
a8170e5e | 499 | static void dummy_writel(void *opaque, hwaddr addr, |
d08151bf | 500 | uint64_t val, unsigned size) |
8508b89e BS |
501 | { |
502 | } | |
503 | ||
d08151bf AK |
504 | static const MemoryRegionOps dummy_ops = { |
505 | .read = dummy_readl, | |
506 | .write = dummy_writel, | |
507 | .endianness = DEVICE_NATIVE_ENDIAN, | |
508 | .valid = { | |
509 | .min_access_size = 4, | |
510 | .max_access_size = 4, | |
511 | }, | |
8508b89e BS |
512 | }; |
513 | ||
380cd056 GH |
514 | static const GraphicHwOps tcx_ops = { |
515 | .invalidate = tcx_invalidate_display, | |
516 | .gfx_update = tcx_update_display, | |
517 | }; | |
518 | ||
519 | static const GraphicHwOps tcx24_ops = { | |
520 | .invalidate = tcx24_invalidate_display, | |
521 | .gfx_update = tcx24_update_display, | |
522 | }; | |
523 | ||
81a322d4 | 524 | static int tcx_init1(SysBusDevice *dev) |
f40070c3 BS |
525 | { |
526 | TCXState *s = FROM_SYSBUS(TCXState, dev); | |
d08151bf | 527 | ram_addr_t vram_offset = 0; |
ee6847d1 | 528 | int size; |
dc828ca1 PB |
529 | uint8_t *vram_base; |
530 | ||
2c9b15ca | 531 | memory_region_init_ram(&s->vram_mem, NULL, "tcx.vram", |
d08151bf | 532 | s->vram_size * (1 + 4 + 4)); |
c5705a77 | 533 | vmstate_register_ram_global(&s->vram_mem); |
d08151bf | 534 | vram_base = memory_region_get_ram_ptr(&s->vram_mem); |
eee0b836 | 535 | |
f40070c3 | 536 | /* 8-bit plane */ |
eee0b836 | 537 | s->vram = vram_base; |
ee6847d1 | 538 | size = s->vram_size; |
2c9b15ca | 539 | memory_region_init_alias(&s->vram_8bit, NULL, "tcx.vram.8bit", |
d08151bf | 540 | &s->vram_mem, vram_offset, size); |
750ecd44 | 541 | sysbus_init_mmio(dev, &s->vram_8bit); |
eee0b836 BS |
542 | vram_offset += size; |
543 | vram_base += size; | |
e80cfcfc | 544 | |
f40070c3 | 545 | /* DAC */ |
2c9b15ca | 546 | memory_region_init_io(&s->dac, NULL, &tcx_dac_ops, s, "tcx.dac", TCX_DAC_NREGS); |
750ecd44 | 547 | sysbus_init_mmio(dev, &s->dac); |
eee0b836 | 548 | |
f40070c3 | 549 | /* TEC (dummy) */ |
2c9b15ca | 550 | memory_region_init_io(&s->tec, NULL, &dummy_ops, s, "tcx.tec", TCX_TEC_NREGS); |
750ecd44 | 551 | sysbus_init_mmio(dev, &s->tec); |
f40070c3 | 552 | /* THC: NetBSD writes here even with 8-bit display: dummy */ |
2c9b15ca | 553 | memory_region_init_io(&s->thc24, NULL, &dummy_ops, s, "tcx.thc24", |
d08151bf | 554 | TCX_THC_NREGS_24); |
750ecd44 | 555 | sysbus_init_mmio(dev, &s->thc24); |
f40070c3 BS |
556 | |
557 | if (s->depth == 24) { | |
558 | /* 24-bit plane */ | |
ee6847d1 | 559 | size = s->vram_size * 4; |
eee0b836 BS |
560 | s->vram24 = (uint32_t *)vram_base; |
561 | s->vram24_offset = vram_offset; | |
2c9b15ca | 562 | memory_region_init_alias(&s->vram_24bit, NULL, "tcx.vram.24bit", |
d08151bf | 563 | &s->vram_mem, vram_offset, size); |
750ecd44 | 564 | sysbus_init_mmio(dev, &s->vram_24bit); |
eee0b836 BS |
565 | vram_offset += size; |
566 | vram_base += size; | |
567 | ||
f40070c3 | 568 | /* Control plane */ |
ee6847d1 | 569 | size = s->vram_size * 4; |
eee0b836 BS |
570 | s->cplane = (uint32_t *)vram_base; |
571 | s->cplane_offset = vram_offset; | |
2c9b15ca | 572 | memory_region_init_alias(&s->vram_cplane, NULL, "tcx.vram.cplane", |
d08151bf | 573 | &s->vram_mem, vram_offset, size); |
750ecd44 | 574 | sysbus_init_mmio(dev, &s->vram_cplane); |
f40070c3 | 575 | |
aa2beaa1 | 576 | s->con = graphic_console_init(DEVICE(dev), &tcx24_ops, s); |
eee0b836 | 577 | } else { |
f40070c3 | 578 | /* THC 8 bit (dummy) */ |
2c9b15ca | 579 | memory_region_init_io(&s->thc8, NULL, &dummy_ops, s, "tcx.thc8", |
d08151bf | 580 | TCX_THC_NREGS_8); |
750ecd44 | 581 | sysbus_init_mmio(dev, &s->thc8); |
f40070c3 | 582 | |
aa2beaa1 | 583 | s->con = graphic_console_init(DEVICE(dev), &tcx_ops, s); |
eee0b836 | 584 | } |
e80cfcfc | 585 | |
c78f7137 | 586 | qemu_console_resize(s->con, s->width, s->height); |
81a322d4 | 587 | return 0; |
420557e8 FB |
588 | } |
589 | ||
999e12bb | 590 | static Property tcx_properties[] = { |
999e12bb AL |
591 | DEFINE_PROP_HEX32("vram_size", TCXState, vram_size, -1), |
592 | DEFINE_PROP_UINT16("width", TCXState, width, -1), | |
593 | DEFINE_PROP_UINT16("height", TCXState, height, -1), | |
594 | DEFINE_PROP_UINT16("depth", TCXState, depth, -1), | |
595 | DEFINE_PROP_END_OF_LIST(), | |
596 | }; | |
597 | ||
598 | static void tcx_class_init(ObjectClass *klass, void *data) | |
599 | { | |
39bffca2 | 600 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb AL |
601 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
602 | ||
603 | k->init = tcx_init1; | |
39bffca2 AL |
604 | dc->reset = tcx_reset; |
605 | dc->vmsd = &vmstate_tcx; | |
606 | dc->props = tcx_properties; | |
999e12bb AL |
607 | } |
608 | ||
8c43a6f0 | 609 | static const TypeInfo tcx_info = { |
39bffca2 AL |
610 | .name = "SUNW,tcx", |
611 | .parent = TYPE_SYS_BUS_DEVICE, | |
612 | .instance_size = sizeof(TCXState), | |
613 | .class_init = tcx_class_init, | |
ee6847d1 GH |
614 | }; |
615 | ||
83f7d43a | 616 | static void tcx_register_types(void) |
f40070c3 | 617 | { |
39bffca2 | 618 | type_register_static(&tcx_info); |
f40070c3 BS |
619 | } |
620 | ||
83f7d43a | 621 | type_init(tcx_register_types) |