2 * QEMU TCX Frame buffer
4 * Copyright (c) 2003-2005 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 #include "qemu/osdep.h"
26 #include "qapi/error.h"
27 #include "qemu-common.h"
28 #include "cpu.h" /* FIXME shouldn't use TARGET_PAGE_SIZE */
29 #include "ui/console.h"
30 #include "ui/pixel_ops.h"
31 #include "hw/loader.h"
32 #include "hw/sysbus.h"
33 #include "qemu/error-report.h"
35 #define TCX_ROM_FILE "QEMU,tcx.bin"
36 #define FCODE_MAX_ROM_SIZE 0x10000
40 #define TCX_DAC_NREGS 16
41 #define TCX_THC_NREGS 0x1000
42 #define TCX_DHC_NREGS 0x4000
43 #define TCX_TEC_NREGS 0x1000
44 #define TCX_ALT_NREGS 0x8000
45 #define TCX_STIP_NREGS 0x800000
46 #define TCX_BLIT_NREGS 0x800000
47 #define TCX_RSTIP_NREGS 0x800000
48 #define TCX_RBLIT_NREGS 0x800000
50 #define TCX_THC_MISC 0x818
51 #define TCX_THC_CURSXY 0x8fc
52 #define TCX_THC_CURSMASK 0x900
53 #define TCX_THC_CURSBITS 0x980
55 #define TYPE_TCX "SUNW,tcx"
56 #define TCX(obj) OBJECT_CHECK(TCXState, (obj), TYPE_TCX)
58 typedef struct TCXState
{
59 SysBusDevice parent_obj
;
64 uint32_t *vram24
, *cplane
;
67 MemoryRegion vram_mem
;
68 MemoryRegion vram_8bit
;
69 MemoryRegion vram_24bit
;
72 MemoryRegion vram_cplane
;
82 ram_addr_t vram24_offset
, cplane_offset
;
85 uint32_t palette
[260];
86 uint8_t r
[260], g
[260], b
[260];
87 uint16_t width
, height
, depth
;
88 uint8_t dac_index
, dac_state
;
90 uint32_t cursmask
[32];
91 uint32_t cursbits
[32];
96 static void tcx_set_dirty(TCXState
*s
, ram_addr_t addr
, int len
)
98 memory_region_set_dirty(&s
->vram_mem
, addr
, len
);
100 if (s
->depth
== 24) {
101 memory_region_set_dirty(&s
->vram_mem
, s
->vram24_offset
+ addr
* 4,
103 memory_region_set_dirty(&s
->vram_mem
, s
->cplane_offset
+ addr
* 4,
108 static int tcx_check_dirty(TCXState
*s
, ram_addr_t addr
, int len
)
112 ret
= memory_region_get_dirty(&s
->vram_mem
, addr
, len
, DIRTY_MEMORY_VGA
);
114 if (s
->depth
== 24) {
115 ret
|= memory_region_get_dirty(&s
->vram_mem
,
116 s
->vram24_offset
+ addr
* 4, len
* 4,
118 ret
|= memory_region_get_dirty(&s
->vram_mem
,
119 s
->cplane_offset
+ addr
* 4, len
* 4,
126 static void tcx_reset_dirty(TCXState
*s
, ram_addr_t addr
, int len
)
128 memory_region_reset_dirty(&s
->vram_mem
, addr
, len
, DIRTY_MEMORY_VGA
);
130 if (s
->depth
== 24) {
131 memory_region_reset_dirty(&s
->vram_mem
, s
->vram24_offset
+ addr
* 4,
132 len
* 4, DIRTY_MEMORY_VGA
);
133 memory_region_reset_dirty(&s
->vram_mem
, s
->cplane_offset
+ addr
* 4,
134 len
* 4, DIRTY_MEMORY_VGA
);
138 static void update_palette_entries(TCXState
*s
, int start
, int end
)
140 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
143 for (i
= start
; i
< end
; i
++) {
144 switch (surface_bits_per_pixel(surface
)) {
147 s
->palette
[i
] = rgb_to_pixel8(s
->r
[i
], s
->g
[i
], s
->b
[i
]);
150 s
->palette
[i
] = rgb_to_pixel15(s
->r
[i
], s
->g
[i
], s
->b
[i
]);
153 s
->palette
[i
] = rgb_to_pixel16(s
->r
[i
], s
->g
[i
], s
->b
[i
]);
156 if (is_surface_bgr(surface
)) {
157 s
->palette
[i
] = rgb_to_pixel32bgr(s
->r
[i
], s
->g
[i
], s
->b
[i
]);
159 s
->palette
[i
] = rgb_to_pixel32(s
->r
[i
], s
->g
[i
], s
->b
[i
]);
164 tcx_set_dirty(s
, 0, memory_region_size(&s
->vram_mem
));
167 static void tcx_draw_line32(TCXState
*s1
, uint8_t *d
,
168 const uint8_t *s
, int width
)
172 uint32_t *p
= (uint32_t *)d
;
174 for (x
= 0; x
< width
; x
++) {
176 *p
++ = s1
->palette
[val
];
180 static void tcx_draw_line16(TCXState
*s1
, uint8_t *d
,
181 const uint8_t *s
, int width
)
185 uint16_t *p
= (uint16_t *)d
;
187 for (x
= 0; x
< width
; x
++) {
189 *p
++ = s1
->palette
[val
];
193 static void tcx_draw_line8(TCXState
*s1
, uint8_t *d
,
194 const uint8_t *s
, int width
)
199 for(x
= 0; x
< width
; x
++) {
201 *d
++ = s1
->palette
[val
];
205 static void tcx_draw_cursor32(TCXState
*s1
, uint8_t *d
,
210 uint32_t *p
= (uint32_t *)d
;
213 mask
= s1
->cursmask
[y
];
214 bits
= s1
->cursbits
[y
];
215 len
= MIN(width
- s1
->cursx
, 32);
217 for (x
= 0; x
< len
; x
++) {
218 if (mask
& 0x80000000) {
219 if (bits
& 0x80000000) {
220 *p
= s1
->palette
[259];
222 *p
= s1
->palette
[258];
231 static void tcx_draw_cursor16(TCXState
*s1
, uint8_t *d
,
236 uint16_t *p
= (uint16_t *)d
;
239 mask
= s1
->cursmask
[y
];
240 bits
= s1
->cursbits
[y
];
241 len
= MIN(width
- s1
->cursx
, 32);
243 for (x
= 0; x
< len
; x
++) {
244 if (mask
& 0x80000000) {
245 if (bits
& 0x80000000) {
246 *p
= s1
->palette
[259];
248 *p
= s1
->palette
[258];
257 static void tcx_draw_cursor8(TCXState
*s1
, uint8_t *d
,
264 mask
= s1
->cursmask
[y
];
265 bits
= s1
->cursbits
[y
];
266 len
= MIN(width
- s1
->cursx
, 32);
268 for (x
= 0; x
< len
; x
++) {
269 if (mask
& 0x80000000) {
270 if (bits
& 0x80000000) {
271 *d
= s1
->palette
[259];
273 *d
= s1
->palette
[258];
283 XXX Could be much more optimal:
284 * detect if line/page/whole screen is in 24 bit mode
285 * if destination is also BGR, use memcpy
287 static inline void tcx24_draw_line32(TCXState
*s1
, uint8_t *d
,
288 const uint8_t *s
, int width
,
289 const uint32_t *cplane
,
292 DisplaySurface
*surface
= qemu_console_surface(s1
->con
);
295 uint32_t *p
= (uint32_t *)d
;
297 bgr
= is_surface_bgr(surface
);
298 for(x
= 0; x
< width
; x
++, s
++, s24
++) {
299 if (be32_to_cpu(*cplane
) & 0x03000000) {
300 /* 24-bit direct, BGR order */
307 dval
= rgb_to_pixel32bgr(r
, g
, b
);
309 dval
= rgb_to_pixel32(r
, g
, b
);
311 /* 8-bit pseudocolor */
313 dval
= s1
->palette
[val
];
320 /* Fixed line length 1024 allows us to do nice tricks not possible on
323 static void tcx_update_display(void *opaque
)
325 TCXState
*ts
= opaque
;
326 DisplaySurface
*surface
= qemu_console_surface(ts
->con
);
327 ram_addr_t page
, page_min
, page_max
;
328 int y
, y_start
, dd
, ds
;
330 void (*f
)(TCXState
*s1
, uint8_t *dst
, const uint8_t *src
, int width
);
331 void (*fc
)(TCXState
*s1
, uint8_t *dst
, int y
, int width
);
333 if (surface_bits_per_pixel(surface
) == 0) {
341 d
= surface_data(surface
);
343 dd
= surface_stride(surface
);
346 switch (surface_bits_per_pixel(surface
)) {
349 fc
= tcx_draw_cursor32
;
354 fc
= tcx_draw_cursor16
;
359 fc
= tcx_draw_cursor8
;
365 memory_region_sync_dirty_bitmap(&ts
->vram_mem
);
366 for (y
= 0; y
< ts
->height
; page
+= TARGET_PAGE_SIZE
) {
367 if (tcx_check_dirty(ts
, page
, TARGET_PAGE_SIZE
)) {
375 f(ts
, d
, s
, ts
->width
);
376 if (y
>= ts
->cursy
&& y
< ts
->cursy
+ 32 && ts
->cursx
< ts
->width
) {
377 fc(ts
, d
, y
, ts
->width
);
383 f(ts
, d
, s
, ts
->width
);
384 if (y
>= ts
->cursy
&& y
< ts
->cursy
+ 32 && ts
->cursx
< ts
->width
) {
385 fc(ts
, d
, y
, ts
->width
);
391 f(ts
, d
, s
, ts
->width
);
392 if (y
>= ts
->cursy
&& y
< ts
->cursy
+ 32 && ts
->cursx
< ts
->width
) {
393 fc(ts
, d
, y
, ts
->width
);
399 f(ts
, d
, s
, ts
->width
);
400 if (y
>= ts
->cursy
&& y
< ts
->cursy
+ 32 && ts
->cursx
< ts
->width
) {
401 fc(ts
, d
, y
, ts
->width
);
408 /* flush to display */
409 dpy_gfx_update(ts
->con
, 0, y_start
,
410 ts
->width
, y
- y_start
);
419 /* flush to display */
420 dpy_gfx_update(ts
->con
, 0, y_start
,
421 ts
->width
, y
- y_start
);
423 /* reset modified pages */
424 if (page_max
>= page_min
) {
425 tcx_reset_dirty(ts
, page_min
, page_max
- page_min
);
429 static void tcx24_update_display(void *opaque
)
431 TCXState
*ts
= opaque
;
432 DisplaySurface
*surface
= qemu_console_surface(ts
->con
);
433 ram_addr_t page
, page_min
, page_max
;
434 int y
, y_start
, dd
, ds
;
436 uint32_t *cptr
, *s24
;
438 if (surface_bits_per_pixel(surface
) != 32) {
446 d
= surface_data(surface
);
450 dd
= surface_stride(surface
);
453 memory_region_sync_dirty_bitmap(&ts
->vram_mem
);
454 for (y
= 0; y
< ts
->height
; page
+= TARGET_PAGE_SIZE
) {
455 if (tcx_check_dirty(ts
, page
, TARGET_PAGE_SIZE
)) {
462 tcx24_draw_line32(ts
, d
, s
, ts
->width
, cptr
, s24
);
463 if (y
>= ts
->cursy
&& y
< ts
->cursy
+32 && ts
->cursx
< ts
->width
) {
464 tcx_draw_cursor32(ts
, d
, y
, ts
->width
);
471 tcx24_draw_line32(ts
, d
, s
, ts
->width
, cptr
, s24
);
472 if (y
>= ts
->cursy
&& y
< ts
->cursy
+32 && ts
->cursx
< ts
->width
) {
473 tcx_draw_cursor32(ts
, d
, y
, ts
->width
);
480 tcx24_draw_line32(ts
, d
, s
, ts
->width
, cptr
, s24
);
481 if (y
>= ts
->cursy
&& y
< ts
->cursy
+32 && ts
->cursx
< ts
->width
) {
482 tcx_draw_cursor32(ts
, d
, y
, ts
->width
);
489 tcx24_draw_line32(ts
, d
, s
, ts
->width
, cptr
, s24
);
490 if (y
>= ts
->cursy
&& y
< ts
->cursy
+32 && ts
->cursx
< ts
->width
) {
491 tcx_draw_cursor32(ts
, d
, y
, ts
->width
);
500 /* flush to display */
501 dpy_gfx_update(ts
->con
, 0, y_start
,
502 ts
->width
, y
- y_start
);
513 /* flush to display */
514 dpy_gfx_update(ts
->con
, 0, y_start
,
515 ts
->width
, y
- y_start
);
517 /* reset modified pages */
518 if (page_max
>= page_min
) {
519 tcx_reset_dirty(ts
, page_min
, page_max
- page_min
);
523 static void tcx_invalidate_display(void *opaque
)
525 TCXState
*s
= opaque
;
527 tcx_set_dirty(s
, 0, memory_region_size(&s
->vram_mem
));
528 qemu_console_resize(s
->con
, s
->width
, s
->height
);
531 static void tcx24_invalidate_display(void *opaque
)
533 TCXState
*s
= opaque
;
535 tcx_set_dirty(s
, 0, memory_region_size(&s
->vram_mem
));
536 qemu_console_resize(s
->con
, s
->width
, s
->height
);
539 static int vmstate_tcx_post_load(void *opaque
, int version_id
)
541 TCXState
*s
= opaque
;
543 update_palette_entries(s
, 0, 256);
544 tcx_set_dirty(s
, 0, memory_region_size(&s
->vram_mem
));
548 static const VMStateDescription vmstate_tcx
= {
551 .minimum_version_id
= 4,
552 .post_load
= vmstate_tcx_post_load
,
553 .fields
= (VMStateField
[]) {
554 VMSTATE_UINT16(height
, TCXState
),
555 VMSTATE_UINT16(width
, TCXState
),
556 VMSTATE_UINT16(depth
, TCXState
),
557 VMSTATE_BUFFER(r
, TCXState
),
558 VMSTATE_BUFFER(g
, TCXState
),
559 VMSTATE_BUFFER(b
, TCXState
),
560 VMSTATE_UINT8(dac_index
, TCXState
),
561 VMSTATE_UINT8(dac_state
, TCXState
),
562 VMSTATE_END_OF_LIST()
566 static void tcx_reset(DeviceState
*d
)
568 TCXState
*s
= TCX(d
);
570 /* Initialize palette */
571 memset(s
->r
, 0, 260);
572 memset(s
->g
, 0, 260);
573 memset(s
->b
, 0, 260);
574 s
->r
[255] = s
->g
[255] = s
->b
[255] = 255;
575 s
->r
[256] = s
->g
[256] = s
->b
[256] = 255;
576 s
->r
[258] = s
->g
[258] = s
->b
[258] = 255;
577 update_palette_entries(s
, 0, 260);
578 memset(s
->vram
, 0, MAXX
*MAXY
);
579 memory_region_reset_dirty(&s
->vram_mem
, 0, MAXX
* MAXY
* (1 + 4 + 4),
583 s
->cursx
= 0xf000; /* Put cursor off screen */
587 static uint64_t tcx_dac_readl(void *opaque
, hwaddr addr
,
590 TCXState
*s
= opaque
;
593 switch (s
->dac_state
) {
595 val
= s
->r
[s
->dac_index
] << 24;
599 val
= s
->g
[s
->dac_index
] << 24;
603 val
= s
->b
[s
->dac_index
] << 24;
604 s
->dac_index
= (s
->dac_index
+ 1) & 0xff; /* Index autoincrement */
613 static void tcx_dac_writel(void *opaque
, hwaddr addr
, uint64_t val
,
616 TCXState
*s
= opaque
;
620 case 0: /* Address */
621 s
->dac_index
= val
>> 24;
624 case 4: /* Pixel colours */
625 case 12: /* Overlay (cursor) colours */
627 index
= (s
->dac_index
& 3) + 256;
629 index
= s
->dac_index
;
631 switch (s
->dac_state
) {
633 s
->r
[index
] = val
>> 24;
634 update_palette_entries(s
, index
, index
+ 1);
638 s
->g
[index
] = val
>> 24;
639 update_palette_entries(s
, index
, index
+ 1);
643 s
->b
[index
] = val
>> 24;
644 update_palette_entries(s
, index
, index
+ 1);
645 s
->dac_index
= (s
->dac_index
+ 1) & 0xff; /* Index autoincrement */
651 default: /* Control registers */
656 static const MemoryRegionOps tcx_dac_ops
= {
657 .read
= tcx_dac_readl
,
658 .write
= tcx_dac_writel
,
659 .endianness
= DEVICE_NATIVE_ENDIAN
,
661 .min_access_size
= 4,
662 .max_access_size
= 4,
666 static uint64_t tcx_stip_readl(void *opaque
, hwaddr addr
,
672 static void tcx_stip_writel(void *opaque
, hwaddr addr
,
673 uint64_t val
, unsigned size
)
675 TCXState
*s
= opaque
;
682 addr
= (addr
>> 3) & 0xfffff;
683 col
= cpu_to_be32(s
->tmpblit
);
684 if (s
->depth
== 24) {
685 for (i
= 0; i
< 32; i
++) {
686 if (val
& 0x80000000) {
687 s
->vram
[addr
+ i
] = s
->tmpblit
;
688 s
->vram24
[addr
+ i
] = col
;
693 for (i
= 0; i
< 32; i
++) {
694 if (val
& 0x80000000) {
695 s
->vram
[addr
+ i
] = s
->tmpblit
;
700 memory_region_set_dirty(&s
->vram_mem
, addr
, 32);
704 static void tcx_rstip_writel(void *opaque
, hwaddr addr
,
705 uint64_t val
, unsigned size
)
707 TCXState
*s
= opaque
;
714 addr
= (addr
>> 3) & 0xfffff;
715 col
= cpu_to_be32(s
->tmpblit
);
716 if (s
->depth
== 24) {
717 for (i
= 0; i
< 32; i
++) {
718 if (val
& 0x80000000) {
719 s
->vram
[addr
+ i
] = s
->tmpblit
;
720 s
->vram24
[addr
+ i
] = col
;
721 s
->cplane
[addr
+ i
] = col
;
726 for (i
= 0; i
< 32; i
++) {
727 if (val
& 0x80000000) {
728 s
->vram
[addr
+ i
] = s
->tmpblit
;
733 memory_region_set_dirty(&s
->vram_mem
, addr
, 32);
737 static const MemoryRegionOps tcx_stip_ops
= {
738 .read
= tcx_stip_readl
,
739 .write
= tcx_stip_writel
,
740 .endianness
= DEVICE_NATIVE_ENDIAN
,
742 .min_access_size
= 4,
743 .max_access_size
= 4,
747 static const MemoryRegionOps tcx_rstip_ops
= {
748 .read
= tcx_stip_readl
,
749 .write
= tcx_rstip_writel
,
750 .endianness
= DEVICE_NATIVE_ENDIAN
,
752 .min_access_size
= 4,
753 .max_access_size
= 4,
757 static uint64_t tcx_blit_readl(void *opaque
, hwaddr addr
,
763 static void tcx_blit_writel(void *opaque
, hwaddr addr
,
764 uint64_t val
, unsigned size
)
766 TCXState
*s
= opaque
;
773 addr
= (addr
>> 3) & 0xfffff;
774 adsr
= val
& 0xffffff;
775 len
= ((val
>> 24) & 0x1f) + 1;
776 if (adsr
== 0xffffff) {
777 memset(&s
->vram
[addr
], s
->tmpblit
, len
);
778 if (s
->depth
== 24) {
779 val
= s
->tmpblit
& 0xffffff;
780 val
= cpu_to_be32(val
);
781 for (i
= 0; i
< len
; i
++) {
782 s
->vram24
[addr
+ i
] = val
;
786 memcpy(&s
->vram
[addr
], &s
->vram
[adsr
], len
);
787 if (s
->depth
== 24) {
788 memcpy(&s
->vram24
[addr
], &s
->vram24
[adsr
], len
* 4);
791 memory_region_set_dirty(&s
->vram_mem
, addr
, len
);
795 static void tcx_rblit_writel(void *opaque
, hwaddr addr
,
796 uint64_t val
, unsigned size
)
798 TCXState
*s
= opaque
;
805 addr
= (addr
>> 3) & 0xfffff;
806 adsr
= val
& 0xffffff;
807 len
= ((val
>> 24) & 0x1f) + 1;
808 if (adsr
== 0xffffff) {
809 memset(&s
->vram
[addr
], s
->tmpblit
, len
);
810 if (s
->depth
== 24) {
811 val
= s
->tmpblit
& 0xffffff;
812 val
= cpu_to_be32(val
);
813 for (i
= 0; i
< len
; i
++) {
814 s
->vram24
[addr
+ i
] = val
;
815 s
->cplane
[addr
+ i
] = val
;
819 memcpy(&s
->vram
[addr
], &s
->vram
[adsr
], len
);
820 if (s
->depth
== 24) {
821 memcpy(&s
->vram24
[addr
], &s
->vram24
[adsr
], len
* 4);
822 memcpy(&s
->cplane
[addr
], &s
->cplane
[adsr
], len
* 4);
825 memory_region_set_dirty(&s
->vram_mem
, addr
, len
);
829 static const MemoryRegionOps tcx_blit_ops
= {
830 .read
= tcx_blit_readl
,
831 .write
= tcx_blit_writel
,
832 .endianness
= DEVICE_NATIVE_ENDIAN
,
834 .min_access_size
= 4,
835 .max_access_size
= 4,
839 static const MemoryRegionOps tcx_rblit_ops
= {
840 .read
= tcx_blit_readl
,
841 .write
= tcx_rblit_writel
,
842 .endianness
= DEVICE_NATIVE_ENDIAN
,
844 .min_access_size
= 4,
845 .max_access_size
= 4,
849 static void tcx_invalidate_cursor_position(TCXState
*s
)
851 int ymin
, ymax
, start
, end
;
853 /* invalidate only near the cursor */
855 if (ymin
>= s
->height
) {
858 ymax
= MIN(s
->height
, ymin
+ 32);
862 memory_region_set_dirty(&s
->vram_mem
, start
, end
-start
);
865 static uint64_t tcx_thc_readl(void *opaque
, hwaddr addr
,
868 TCXState
*s
= opaque
;
871 if (addr
== TCX_THC_MISC
) {
872 val
= s
->thcmisc
| 0x02000000;
879 static void tcx_thc_writel(void *opaque
, hwaddr addr
,
880 uint64_t val
, unsigned size
)
882 TCXState
*s
= opaque
;
884 if (addr
== TCX_THC_CURSXY
) {
885 tcx_invalidate_cursor_position(s
);
886 s
->cursx
= val
>> 16;
888 tcx_invalidate_cursor_position(s
);
889 } else if (addr
>= TCX_THC_CURSMASK
&& addr
< TCX_THC_CURSMASK
+ 128) {
890 s
->cursmask
[(addr
- TCX_THC_CURSMASK
) >> 2] = val
;
891 tcx_invalidate_cursor_position(s
);
892 } else if (addr
>= TCX_THC_CURSBITS
&& addr
< TCX_THC_CURSBITS
+ 128) {
893 s
->cursbits
[(addr
- TCX_THC_CURSBITS
) >> 2] = val
;
894 tcx_invalidate_cursor_position(s
);
895 } else if (addr
== TCX_THC_MISC
) {
901 static const MemoryRegionOps tcx_thc_ops
= {
902 .read
= tcx_thc_readl
,
903 .write
= tcx_thc_writel
,
904 .endianness
= DEVICE_NATIVE_ENDIAN
,
906 .min_access_size
= 4,
907 .max_access_size
= 4,
911 static uint64_t tcx_dummy_readl(void *opaque
, hwaddr addr
,
917 static void tcx_dummy_writel(void *opaque
, hwaddr addr
,
918 uint64_t val
, unsigned size
)
923 static const MemoryRegionOps tcx_dummy_ops
= {
924 .read
= tcx_dummy_readl
,
925 .write
= tcx_dummy_writel
,
926 .endianness
= DEVICE_NATIVE_ENDIAN
,
928 .min_access_size
= 4,
929 .max_access_size
= 4,
933 static const GraphicHwOps tcx_ops
= {
934 .invalidate
= tcx_invalidate_display
,
935 .gfx_update
= tcx_update_display
,
938 static const GraphicHwOps tcx24_ops
= {
939 .invalidate
= tcx24_invalidate_display
,
940 .gfx_update
= tcx24_update_display
,
943 static void tcx_initfn(Object
*obj
)
945 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
946 TCXState
*s
= TCX(obj
);
948 memory_region_init_ram(&s
->rom
, obj
, "tcx.prom", FCODE_MAX_ROM_SIZE
,
950 memory_region_set_readonly(&s
->rom
, true);
951 sysbus_init_mmio(sbd
, &s
->rom
);
953 /* 2/STIP : Stippler */
954 memory_region_init_io(&s
->stip
, obj
, &tcx_stip_ops
, s
, "tcx.stip",
956 sysbus_init_mmio(sbd
, &s
->stip
);
958 /* 3/BLIT : Blitter */
959 memory_region_init_io(&s
->blit
, obj
, &tcx_blit_ops
, s
, "tcx.blit",
961 sysbus_init_mmio(sbd
, &s
->blit
);
963 /* 5/RSTIP : Raw Stippler */
964 memory_region_init_io(&s
->rstip
, obj
, &tcx_rstip_ops
, s
, "tcx.rstip",
966 sysbus_init_mmio(sbd
, &s
->rstip
);
968 /* 6/RBLIT : Raw Blitter */
969 memory_region_init_io(&s
->rblit
, obj
, &tcx_rblit_ops
, s
, "tcx.rblit",
971 sysbus_init_mmio(sbd
, &s
->rblit
);
974 memory_region_init_io(&s
->tec
, obj
, &tcx_dummy_ops
, s
, "tcx.tec",
976 sysbus_init_mmio(sbd
, &s
->tec
);
979 memory_region_init_io(&s
->dac
, obj
, &tcx_dac_ops
, s
, "tcx.dac",
981 sysbus_init_mmio(sbd
, &s
->dac
);
984 memory_region_init_io(&s
->thc
, obj
, &tcx_thc_ops
, s
, "tcx.thc",
986 sysbus_init_mmio(sbd
, &s
->thc
);
989 memory_region_init_io(&s
->dhc
, obj
, &tcx_dummy_ops
, s
, "tcx.dhc",
991 sysbus_init_mmio(sbd
, &s
->dhc
);
994 memory_region_init_io(&s
->alt
, obj
, &tcx_dummy_ops
, s
, "tcx.alt",
996 sysbus_init_mmio(sbd
, &s
->alt
);
999 static void tcx_realizefn(DeviceState
*dev
, Error
**errp
)
1001 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
1002 TCXState
*s
= TCX(dev
);
1003 ram_addr_t vram_offset
= 0;
1006 char *fcode_filename
;
1008 memory_region_init_ram(&s
->vram_mem
, OBJECT(s
), "tcx.vram",
1009 s
->vram_size
* (1 + 4 + 4), &error_fatal
);
1010 vmstate_register_ram_global(&s
->vram_mem
);
1011 memory_region_set_log(&s
->vram_mem
, true, DIRTY_MEMORY_VGA
);
1012 vram_base
= memory_region_get_ram_ptr(&s
->vram_mem
);
1014 /* 10/ROM : FCode ROM */
1015 vmstate_register_ram_global(&s
->rom
);
1016 fcode_filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, TCX_ROM_FILE
);
1017 if (fcode_filename
) {
1018 ret
= load_image_targphys(fcode_filename
, s
->prom_addr
,
1019 FCODE_MAX_ROM_SIZE
);
1020 g_free(fcode_filename
);
1021 if (ret
< 0 || ret
> FCODE_MAX_ROM_SIZE
) {
1022 error_report("tcx: could not load prom '%s'", TCX_ROM_FILE
);
1026 /* 0/DFB8 : 8-bit plane */
1027 s
->vram
= vram_base
;
1028 size
= s
->vram_size
;
1029 memory_region_init_alias(&s
->vram_8bit
, OBJECT(s
), "tcx.vram.8bit",
1030 &s
->vram_mem
, vram_offset
, size
);
1031 sysbus_init_mmio(sbd
, &s
->vram_8bit
);
1032 vram_offset
+= size
;
1035 /* 1/DFB24 : 24bit plane */
1036 size
= s
->vram_size
* 4;
1037 s
->vram24
= (uint32_t *)vram_base
;
1038 s
->vram24_offset
= vram_offset
;
1039 memory_region_init_alias(&s
->vram_24bit
, OBJECT(s
), "tcx.vram.24bit",
1040 &s
->vram_mem
, vram_offset
, size
);
1041 sysbus_init_mmio(sbd
, &s
->vram_24bit
);
1042 vram_offset
+= size
;
1045 /* 4/RDFB32 : Raw Framebuffer */
1046 size
= s
->vram_size
* 4;
1047 s
->cplane
= (uint32_t *)vram_base
;
1048 s
->cplane_offset
= vram_offset
;
1049 memory_region_init_alias(&s
->vram_cplane
, OBJECT(s
), "tcx.vram.cplane",
1050 &s
->vram_mem
, vram_offset
, size
);
1051 sysbus_init_mmio(sbd
, &s
->vram_cplane
);
1053 /* 9/THC24bits : NetBSD writes here even with 8-bit display: dummy */
1054 if (s
->depth
== 8) {
1055 memory_region_init_io(&s
->thc24
, OBJECT(s
), &tcx_dummy_ops
, s
,
1056 "tcx.thc24", TCX_THC_NREGS
);
1057 sysbus_init_mmio(sbd
, &s
->thc24
);
1060 sysbus_init_irq(sbd
, &s
->irq
);
1062 if (s
->depth
== 8) {
1063 s
->con
= graphic_console_init(DEVICE(dev
), 0, &tcx_ops
, s
);
1065 s
->con
= graphic_console_init(DEVICE(dev
), 0, &tcx24_ops
, s
);
1069 qemu_console_resize(s
->con
, s
->width
, s
->height
);
1072 static Property tcx_properties
[] = {
1073 DEFINE_PROP_UINT32("vram_size", TCXState
, vram_size
, -1),
1074 DEFINE_PROP_UINT16("width", TCXState
, width
, -1),
1075 DEFINE_PROP_UINT16("height", TCXState
, height
, -1),
1076 DEFINE_PROP_UINT16("depth", TCXState
, depth
, -1),
1077 DEFINE_PROP_UINT64("prom_addr", TCXState
, prom_addr
, -1),
1078 DEFINE_PROP_END_OF_LIST(),
1081 static void tcx_class_init(ObjectClass
*klass
, void *data
)
1083 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1085 dc
->realize
= tcx_realizefn
;
1086 dc
->reset
= tcx_reset
;
1087 dc
->vmsd
= &vmstate_tcx
;
1088 dc
->props
= tcx_properties
;
1091 static const TypeInfo tcx_info
= {
1093 .parent
= TYPE_SYS_BUS_DEVICE
,
1094 .instance_size
= sizeof(TCXState
),
1095 .instance_init
= tcx_initfn
,
1096 .class_init
= tcx_class_init
,
1099 static void tcx_register_types(void)
1101 type_register_static(&tcx_info
);
1104 type_init(tcx_register_types
)