bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1 | /* |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 2 | * QEMU Cirrus CLGD 54xx VGA Emulator. |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 4 | * Copyright (c) 2004 Fabrice Bellard |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 5 | * Copyright (c) 2004 Makoto Suzuki (suzu) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6 | * |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | * of this software and associated documentation files (the "Software"), to deal |
| 9 | * in the Software without restriction, including without limitation the rights |
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | * copies of the Software, and to permit persons to whom the Software is |
| 12 | * furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included in |
| 15 | * all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | * THE SOFTWARE. |
| 24 | */ |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 25 | /* |
Philippe Mathieu-Daudé | 2958546 | 2019-05-04 14:16:50 +0200 | [diff] [blame] | 26 | * Reference: Finn Thogersons' VGADOC4b: |
| 27 | * |
| 28 | * http://web.archive.org/web/20021019054927/http://home.worldonline.dk/finth/ |
| 29 | * |
| 30 | * VGADOC4b.ZIP content available at: |
| 31 | * |
| 32 | * https://pdos.csail.mit.edu/6.828/2005/readings/hardware/vgadoc |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 33 | */ |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 34 | |
Peter Maydell | 47df515 | 2016-01-26 18:17:13 +0000 | [diff] [blame] | 35 | #include "qemu/osdep.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 36 | #include "qemu/module.h" |
Philippe Mathieu-Daudé | f0353b0 | 2018-06-25 09:42:06 -0300 | [diff] [blame] | 37 | #include "qemu/units.h" |
Philippe Mathieu-Daudé | bb6e9e9 | 2020-05-26 08:22:42 +0200 | [diff] [blame] | 38 | #include "qemu/log.h" |
Markus Armbruster | 71e8a91 | 2019-08-12 07:23:38 +0200 | [diff] [blame] | 39 | #include "sysemu/reset.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 40 | #include "qapi/error.h" |
Gerd Hoffmann | ec87f20 | 2017-02-08 14:51:33 +0100 | [diff] [blame] | 41 | #include "trace.h" |
Markus Armbruster | edf5ca5 | 2022-12-22 11:03:28 +0100 | [diff] [blame] | 42 | #include "hw/pci/pci_device.h" |
Markus Armbruster | a27bd6c | 2019-08-12 07:23:51 +0200 | [diff] [blame] | 43 | #include "hw/qdev-properties.h" |
Markus Armbruster | d645427 | 2019-08-12 07:23:45 +0200 | [diff] [blame] | 44 | #include "migration/vmstate.h" |
Benjamin Herrenschmidt | d3c2343 | 2014-06-22 11:00:50 +1000 | [diff] [blame] | 45 | #include "ui/pixel_ops.h" |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 46 | #include "vga_regs.h" |
Thomas Huth | ce3cf70 | 2018-10-12 12:11:46 +0200 | [diff] [blame] | 47 | #include "cirrus_vga_internal.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 48 | #include "qom/object.h" |
Michael S. Tsirkin | 28cf396 | 2022-11-09 17:21:23 -0500 | [diff] [blame] | 49 | #include "ui/console.h" |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 50 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 51 | /* |
| 52 | * TODO: |
bellard | ad81218 | 2005-04-26 20:49:17 +0000 | [diff] [blame] | 53 | * - destination write mask support not complete (bits 5..7) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 54 | * - optimize linear mappings |
| 55 | * - optimize bitblt functions |
| 56 | */ |
| 57 | |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 58 | //#define DEBUG_CIRRUS |
| 59 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 60 | /*************************************** |
| 61 | * |
| 62 | * definitions |
| 63 | * |
| 64 | ***************************************/ |
| 65 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 66 | // sequencer 0x07 |
| 67 | #define CIRRUS_SR7_BPP_VGA 0x00 |
| 68 | #define CIRRUS_SR7_BPP_SVGA 0x01 |
| 69 | #define CIRRUS_SR7_BPP_MASK 0x0e |
| 70 | #define CIRRUS_SR7_BPP_8 0x00 |
| 71 | #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02 |
| 72 | #define CIRRUS_SR7_BPP_24 0x04 |
| 73 | #define CIRRUS_SR7_BPP_16 0x06 |
| 74 | #define CIRRUS_SR7_BPP_32 0x08 |
| 75 | #define CIRRUS_SR7_ISAADDR_MASK 0xe0 |
| 76 | |
| 77 | // sequencer 0x0f |
| 78 | #define CIRRUS_MEMSIZE_512k 0x08 |
| 79 | #define CIRRUS_MEMSIZE_1M 0x10 |
| 80 | #define CIRRUS_MEMSIZE_2M 0x18 |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 81 | #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled. |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 82 | |
| 83 | // sequencer 0x12 |
| 84 | #define CIRRUS_CURSOR_SHOW 0x01 |
| 85 | #define CIRRUS_CURSOR_HIDDENPEL 0x02 |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 86 | #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 87 | |
| 88 | // sequencer 0x17 |
| 89 | #define CIRRUS_BUSTYPE_VLBFAST 0x10 |
| 90 | #define CIRRUS_BUSTYPE_PCI 0x20 |
| 91 | #define CIRRUS_BUSTYPE_VLBSLOW 0x30 |
| 92 | #define CIRRUS_BUSTYPE_ISA 0x38 |
| 93 | #define CIRRUS_MMIO_ENABLE 0x04 |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 94 | #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared. |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 95 | #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80 |
| 96 | |
| 97 | // control 0x0b |
| 98 | #define CIRRUS_BANKING_DUAL 0x01 |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 99 | #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 100 | |
| 101 | // control 0x30 |
| 102 | #define CIRRUS_BLTMODE_BACKWARDS 0x01 |
| 103 | #define CIRRUS_BLTMODE_MEMSYSDEST 0x02 |
| 104 | #define CIRRUS_BLTMODE_MEMSYSSRC 0x04 |
| 105 | #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08 |
| 106 | #define CIRRUS_BLTMODE_PATTERNCOPY 0x40 |
| 107 | #define CIRRUS_BLTMODE_COLOREXPAND 0x80 |
| 108 | #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30 |
| 109 | #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00 |
| 110 | #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10 |
| 111 | #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20 |
| 112 | #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30 |
| 113 | |
| 114 | // control 0x31 |
| 115 | #define CIRRUS_BLT_BUSY 0x01 |
| 116 | #define CIRRUS_BLT_START 0x02 |
| 117 | #define CIRRUS_BLT_RESET 0x04 |
| 118 | #define CIRRUS_BLT_FIFOUSED 0x10 |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 119 | #define CIRRUS_BLT_AUTOSTART 0x80 |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 120 | |
| 121 | // control 0x32 |
| 122 | #define CIRRUS_ROP_0 0x00 |
| 123 | #define CIRRUS_ROP_SRC_AND_DST 0x05 |
| 124 | #define CIRRUS_ROP_NOP 0x06 |
| 125 | #define CIRRUS_ROP_SRC_AND_NOTDST 0x09 |
| 126 | #define CIRRUS_ROP_NOTDST 0x0b |
| 127 | #define CIRRUS_ROP_SRC 0x0d |
| 128 | #define CIRRUS_ROP_1 0x0e |
| 129 | #define CIRRUS_ROP_NOTSRC_AND_DST 0x50 |
| 130 | #define CIRRUS_ROP_SRC_XOR_DST 0x59 |
| 131 | #define CIRRUS_ROP_SRC_OR_DST 0x6d |
| 132 | #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90 |
| 133 | #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95 |
| 134 | #define CIRRUS_ROP_SRC_OR_NOTDST 0xad |
| 135 | #define CIRRUS_ROP_NOTSRC 0xd0 |
| 136 | #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6 |
| 137 | #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda |
| 138 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 139 | #define CIRRUS_ROP_NOP_INDEX 2 |
| 140 | #define CIRRUS_ROP_SRC_INDEX 5 |
| 141 | |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 142 | // control 0x33 |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 143 | #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04 |
bellard | 4c8732d | 2004-06-07 19:46:45 +0000 | [diff] [blame] | 144 | #define CIRRUS_BLTMODEEXT_COLOREXPINV 0x02 |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 145 | #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01 |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 146 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 147 | // memory-mapped IO |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 148 | #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword |
| 149 | #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword |
| 150 | #define CIRRUS_MMIO_BLTWIDTH 0x08 // word |
| 151 | #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word |
| 152 | #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word |
| 153 | #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word |
| 154 | #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword |
| 155 | #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword |
| 156 | #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte |
| 157 | #define CIRRUS_MMIO_BLTMODE 0x18 // byte |
| 158 | #define CIRRUS_MMIO_BLTROP 0x1a // byte |
| 159 | #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte |
| 160 | #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word? |
| 161 | #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word? |
| 162 | #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word |
| 163 | #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word |
| 164 | #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word |
| 165 | #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word |
| 166 | #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte |
| 167 | #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte |
| 168 | #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte |
| 169 | #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte |
| 170 | #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word |
| 171 | #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word |
| 172 | #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word |
| 173 | #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word |
| 174 | #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte |
| 175 | #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte |
| 176 | #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 177 | |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 178 | #define CIRRUS_PNPMMIO_SIZE 0x1000 |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 179 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 180 | typedef void (*cirrus_fill_t)(struct CirrusVGAState *s, |
Gerd Hoffmann | 026aeff | 2017-03-15 11:47:52 +0100 | [diff] [blame] | 181 | uint32_t dstaddr, int dst_pitch, |
| 182 | int width, int height); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 183 | |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 184 | struct PCICirrusVGAState { |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 185 | PCIDevice dev; |
| 186 | CirrusVGAState cirrus_vga; |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 187 | }; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 188 | |
Gonglei | d338bae | 2015-05-12 17:27:09 +0800 | [diff] [blame] | 189 | #define TYPE_PCI_CIRRUS_VGA "cirrus-vga" |
Eduardo Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 190 | OBJECT_DECLARE_SIMPLE_TYPE(PCICirrusVGAState, PCI_CIRRUS_VGA) |
Gonglei | d338bae | 2015-05-12 17:27:09 +0800 | [diff] [blame] | 191 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 192 | static uint8_t rop_to_index[256]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 193 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 194 | /*************************************** |
| 195 | * |
| 196 | * prototypes. |
| 197 | * |
| 198 | ***************************************/ |
| 199 | |
| 200 | |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 201 | static void cirrus_bitblt_reset(CirrusVGAState *s); |
| 202 | static void cirrus_update_memory_access(CirrusVGAState *s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 203 | |
| 204 | /*************************************** |
| 205 | * |
| 206 | * raster operations |
| 207 | * |
| 208 | ***************************************/ |
| 209 | |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 210 | static bool blit_region_is_unsafe(struct CirrusVGAState *s, |
| 211 | int32_t pitch, int32_t addr) |
| 212 | { |
Gerd Hoffmann | 12e97ec | 2017-02-09 14:02:21 +0100 | [diff] [blame] | 213 | if (!pitch) { |
| 214 | return true; |
| 215 | } |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 216 | if (pitch < 0) { |
| 217 | int64_t min = addr |
Li Qiang | 62d4c6b | 2017-02-01 09:35:01 +0100 | [diff] [blame] | 218 | + ((int64_t)s->cirrus_blt_height - 1) * pitch |
| 219 | - s->cirrus_blt_width; |
| 220 | if (min < -1 || addr >= s->vga.vram_size) { |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 221 | return true; |
| 222 | } |
| 223 | } else { |
| 224 | int64_t max = addr |
| 225 | + ((int64_t)s->cirrus_blt_height-1) * pitch |
| 226 | + s->cirrus_blt_width; |
Paolo Bonzini | d2ba7ec | 2016-02-10 17:17:39 +0100 | [diff] [blame] | 227 | if (max > s->vga.vram_size) { |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 228 | return true; |
| 229 | } |
| 230 | } |
| 231 | return false; |
| 232 | } |
| 233 | |
Gerd Hoffmann | 12e97ec | 2017-02-09 14:02:21 +0100 | [diff] [blame] | 234 | static bool blit_is_unsafe(struct CirrusVGAState *s, bool dst_only) |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 235 | { |
| 236 | /* should be the case, see cirrus_bitblt_start */ |
| 237 | assert(s->cirrus_blt_width > 0); |
| 238 | assert(s->cirrus_blt_height > 0); |
| 239 | |
Gerd Hoffmann | bf25983 | 2014-11-19 13:27:28 +0100 | [diff] [blame] | 240 | if (s->cirrus_blt_width > CIRRUS_BLTBUFSIZE) { |
| 241 | return true; |
| 242 | } |
| 243 | |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 244 | if (blit_region_is_unsafe(s, s->cirrus_blt_dstpitch, |
Gerd Hoffmann | 60cd23e | 2017-01-25 11:09:56 +0100 | [diff] [blame] | 245 | s->cirrus_blt_dstaddr)) { |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 246 | return true; |
| 247 | } |
Bruce Rogers | 913a878 | 2017-01-09 13:35:20 -0700 | [diff] [blame] | 248 | if (dst_only) { |
| 249 | return false; |
| 250 | } |
Gerd Hoffmann | 12e97ec | 2017-02-09 14:02:21 +0100 | [diff] [blame] | 251 | if (blit_region_is_unsafe(s, s->cirrus_blt_srcpitch, |
Gerd Hoffmann | 60cd23e | 2017-01-25 11:09:56 +0100 | [diff] [blame] | 252 | s->cirrus_blt_srcaddr)) { |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | |
| 256 | return false; |
| 257 | } |
| 258 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 259 | static void cirrus_bitblt_rop_nop(CirrusVGAState *s, |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 260 | uint32_t dstaddr, uint32_t srcaddr, |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 261 | int dstpitch,int srcpitch, |
| 262 | int bltwidth,int bltheight) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 263 | { |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 264 | } |
| 265 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 266 | static void cirrus_bitblt_fill_nop(CirrusVGAState *s, |
Gerd Hoffmann | 026aeff | 2017-03-15 11:47:52 +0100 | [diff] [blame] | 267 | uint32_t dstaddr, |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 268 | int dstpitch, int bltwidth,int bltheight) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 269 | { |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 272 | static inline uint8_t cirrus_src(CirrusVGAState *s, uint32_t srcaddr) |
| 273 | { |
| 274 | if (s->cirrus_srccounter) { |
| 275 | /* cputovideo */ |
| 276 | return s->cirrus_bltbuf[srcaddr & (CIRRUS_BLTBUFSIZE - 1)]; |
| 277 | } else { |
| 278 | /* videotovideo */ |
| 279 | return s->vga.vram_ptr[srcaddr & s->cirrus_addr_mask]; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | static inline uint16_t cirrus_src16(CirrusVGAState *s, uint32_t srcaddr) |
| 284 | { |
| 285 | uint16_t *src; |
| 286 | |
| 287 | if (s->cirrus_srccounter) { |
| 288 | /* cputovideo */ |
| 289 | src = (void *)&s->cirrus_bltbuf[srcaddr & (CIRRUS_BLTBUFSIZE - 1) & ~1]; |
| 290 | } else { |
| 291 | /* videotovideo */ |
| 292 | src = (void *)&s->vga.vram_ptr[srcaddr & s->cirrus_addr_mask & ~1]; |
| 293 | } |
| 294 | return *src; |
| 295 | } |
| 296 | |
| 297 | static inline uint32_t cirrus_src32(CirrusVGAState *s, uint32_t srcaddr) |
| 298 | { |
| 299 | uint32_t *src; |
| 300 | |
| 301 | if (s->cirrus_srccounter) { |
| 302 | /* cputovideo */ |
| 303 | src = (void *)&s->cirrus_bltbuf[srcaddr & (CIRRUS_BLTBUFSIZE - 1) & ~3]; |
| 304 | } else { |
| 305 | /* videotovideo */ |
| 306 | src = (void *)&s->vga.vram_ptr[srcaddr & s->cirrus_addr_mask & ~3]; |
| 307 | } |
| 308 | return *src; |
| 309 | } |
| 310 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 311 | #define ROP_NAME 0 |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 312 | #define ROP_FN(d, s) 0 |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 313 | #include "cirrus_vga_rop.h" |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 314 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 315 | #define ROP_NAME src_and_dst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 316 | #define ROP_FN(d, s) (s) & (d) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 317 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 318 | |
| 319 | #define ROP_NAME src_and_notdst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 320 | #define ROP_FN(d, s) (s) & (~(d)) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 321 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 322 | |
| 323 | #define ROP_NAME notdst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 324 | #define ROP_FN(d, s) ~(d) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 325 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 326 | |
| 327 | #define ROP_NAME src |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 328 | #define ROP_FN(d, s) s |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 329 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 330 | |
| 331 | #define ROP_NAME 1 |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 332 | #define ROP_FN(d, s) ~0 |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 333 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 334 | |
| 335 | #define ROP_NAME notsrc_and_dst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 336 | #define ROP_FN(d, s) (~(s)) & (d) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 337 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 338 | |
| 339 | #define ROP_NAME src_xor_dst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 340 | #define ROP_FN(d, s) (s) ^ (d) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 341 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 342 | |
| 343 | #define ROP_NAME src_or_dst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 344 | #define ROP_FN(d, s) (s) | (d) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 345 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 346 | |
| 347 | #define ROP_NAME notsrc_or_notdst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 348 | #define ROP_FN(d, s) (~(s)) | (~(d)) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 349 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 350 | |
| 351 | #define ROP_NAME src_notxor_dst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 352 | #define ROP_FN(d, s) ~((s) ^ (d)) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 353 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 354 | |
| 355 | #define ROP_NAME src_or_notdst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 356 | #define ROP_FN(d, s) (s) | (~(d)) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 357 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 358 | |
| 359 | #define ROP_NAME notsrc |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 360 | #define ROP_FN(d, s) (~(s)) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 361 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 362 | |
| 363 | #define ROP_NAME notsrc_or_dst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 364 | #define ROP_FN(d, s) (~(s)) | (d) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 365 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 366 | |
| 367 | #define ROP_NAME notsrc_and_notdst |
Blue Swirl | 8c78881 | 2010-10-13 18:38:07 +0000 | [diff] [blame] | 368 | #define ROP_FN(d, s) (~(s)) & (~(d)) |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 369 | #include "cirrus_vga_rop.h" |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 370 | |
| 371 | static const cirrus_bitblt_rop_t cirrus_fwd_rop[16] = { |
| 372 | cirrus_bitblt_rop_fwd_0, |
| 373 | cirrus_bitblt_rop_fwd_src_and_dst, |
| 374 | cirrus_bitblt_rop_nop, |
| 375 | cirrus_bitblt_rop_fwd_src_and_notdst, |
| 376 | cirrus_bitblt_rop_fwd_notdst, |
| 377 | cirrus_bitblt_rop_fwd_src, |
| 378 | cirrus_bitblt_rop_fwd_1, |
| 379 | cirrus_bitblt_rop_fwd_notsrc_and_dst, |
| 380 | cirrus_bitblt_rop_fwd_src_xor_dst, |
| 381 | cirrus_bitblt_rop_fwd_src_or_dst, |
| 382 | cirrus_bitblt_rop_fwd_notsrc_or_notdst, |
| 383 | cirrus_bitblt_rop_fwd_src_notxor_dst, |
| 384 | cirrus_bitblt_rop_fwd_src_or_notdst, |
| 385 | cirrus_bitblt_rop_fwd_notsrc, |
| 386 | cirrus_bitblt_rop_fwd_notsrc_or_dst, |
| 387 | cirrus_bitblt_rop_fwd_notsrc_and_notdst, |
| 388 | }; |
| 389 | |
| 390 | static const cirrus_bitblt_rop_t cirrus_bkwd_rop[16] = { |
| 391 | cirrus_bitblt_rop_bkwd_0, |
| 392 | cirrus_bitblt_rop_bkwd_src_and_dst, |
| 393 | cirrus_bitblt_rop_nop, |
| 394 | cirrus_bitblt_rop_bkwd_src_and_notdst, |
| 395 | cirrus_bitblt_rop_bkwd_notdst, |
| 396 | cirrus_bitblt_rop_bkwd_src, |
| 397 | cirrus_bitblt_rop_bkwd_1, |
| 398 | cirrus_bitblt_rop_bkwd_notsrc_and_dst, |
| 399 | cirrus_bitblt_rop_bkwd_src_xor_dst, |
| 400 | cirrus_bitblt_rop_bkwd_src_or_dst, |
| 401 | cirrus_bitblt_rop_bkwd_notsrc_or_notdst, |
| 402 | cirrus_bitblt_rop_bkwd_src_notxor_dst, |
| 403 | cirrus_bitblt_rop_bkwd_src_or_notdst, |
| 404 | cirrus_bitblt_rop_bkwd_notsrc, |
| 405 | cirrus_bitblt_rop_bkwd_notsrc_or_dst, |
| 406 | cirrus_bitblt_rop_bkwd_notsrc_and_notdst, |
| 407 | }; |
ths | 96cf2df | 2007-07-31 23:26:00 +0000 | [diff] [blame] | 408 | |
| 409 | #define TRANSP_ROP(name) {\ |
| 410 | name ## _8,\ |
| 411 | name ## _16,\ |
| 412 | } |
| 413 | #define TRANSP_NOP(func) {\ |
| 414 | func,\ |
| 415 | func,\ |
| 416 | } |
| 417 | |
| 418 | static const cirrus_bitblt_rop_t cirrus_fwd_transp_rop[16][2] = { |
| 419 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_0), |
| 420 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_dst), |
| 421 | TRANSP_NOP(cirrus_bitblt_rop_nop), |
| 422 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_notdst), |
| 423 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notdst), |
| 424 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src), |
| 425 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_1), |
| 426 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_dst), |
| 427 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_xor_dst), |
| 428 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_dst), |
| 429 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_notdst), |
| 430 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_notxor_dst), |
| 431 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_notdst), |
| 432 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc), |
| 433 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_dst), |
| 434 | TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_notdst), |
| 435 | }; |
| 436 | |
| 437 | static const cirrus_bitblt_rop_t cirrus_bkwd_transp_rop[16][2] = { |
| 438 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_0), |
| 439 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_dst), |
| 440 | TRANSP_NOP(cirrus_bitblt_rop_nop), |
| 441 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_notdst), |
| 442 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notdst), |
| 443 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src), |
| 444 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_1), |
| 445 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_dst), |
| 446 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_xor_dst), |
| 447 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_dst), |
| 448 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_notdst), |
| 449 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_notxor_dst), |
| 450 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_notdst), |
| 451 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc), |
| 452 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_dst), |
| 453 | TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_notdst), |
| 454 | }; |
| 455 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 456 | #define ROP2(name) {\ |
| 457 | name ## _8,\ |
| 458 | name ## _16,\ |
| 459 | name ## _24,\ |
| 460 | name ## _32,\ |
| 461 | } |
| 462 | |
| 463 | #define ROP_NOP2(func) {\ |
| 464 | func,\ |
| 465 | func,\ |
| 466 | func,\ |
| 467 | func,\ |
| 468 | } |
| 469 | |
bellard | e69390c | 2004-06-09 23:12:09 +0000 | [diff] [blame] | 470 | static const cirrus_bitblt_rop_t cirrus_patternfill[16][4] = { |
| 471 | ROP2(cirrus_patternfill_0), |
| 472 | ROP2(cirrus_patternfill_src_and_dst), |
| 473 | ROP_NOP2(cirrus_bitblt_rop_nop), |
| 474 | ROP2(cirrus_patternfill_src_and_notdst), |
| 475 | ROP2(cirrus_patternfill_notdst), |
| 476 | ROP2(cirrus_patternfill_src), |
| 477 | ROP2(cirrus_patternfill_1), |
| 478 | ROP2(cirrus_patternfill_notsrc_and_dst), |
| 479 | ROP2(cirrus_patternfill_src_xor_dst), |
| 480 | ROP2(cirrus_patternfill_src_or_dst), |
| 481 | ROP2(cirrus_patternfill_notsrc_or_notdst), |
| 482 | ROP2(cirrus_patternfill_src_notxor_dst), |
| 483 | ROP2(cirrus_patternfill_src_or_notdst), |
| 484 | ROP2(cirrus_patternfill_notsrc), |
| 485 | ROP2(cirrus_patternfill_notsrc_or_dst), |
| 486 | ROP2(cirrus_patternfill_notsrc_and_notdst), |
| 487 | }; |
| 488 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 489 | static const cirrus_bitblt_rop_t cirrus_colorexpand_transp[16][4] = { |
| 490 | ROP2(cirrus_colorexpand_transp_0), |
| 491 | ROP2(cirrus_colorexpand_transp_src_and_dst), |
| 492 | ROP_NOP2(cirrus_bitblt_rop_nop), |
| 493 | ROP2(cirrus_colorexpand_transp_src_and_notdst), |
| 494 | ROP2(cirrus_colorexpand_transp_notdst), |
| 495 | ROP2(cirrus_colorexpand_transp_src), |
| 496 | ROP2(cirrus_colorexpand_transp_1), |
| 497 | ROP2(cirrus_colorexpand_transp_notsrc_and_dst), |
| 498 | ROP2(cirrus_colorexpand_transp_src_xor_dst), |
| 499 | ROP2(cirrus_colorexpand_transp_src_or_dst), |
| 500 | ROP2(cirrus_colorexpand_transp_notsrc_or_notdst), |
| 501 | ROP2(cirrus_colorexpand_transp_src_notxor_dst), |
| 502 | ROP2(cirrus_colorexpand_transp_src_or_notdst), |
| 503 | ROP2(cirrus_colorexpand_transp_notsrc), |
| 504 | ROP2(cirrus_colorexpand_transp_notsrc_or_dst), |
| 505 | ROP2(cirrus_colorexpand_transp_notsrc_and_notdst), |
| 506 | }; |
| 507 | |
| 508 | static const cirrus_bitblt_rop_t cirrus_colorexpand[16][4] = { |
| 509 | ROP2(cirrus_colorexpand_0), |
| 510 | ROP2(cirrus_colorexpand_src_and_dst), |
| 511 | ROP_NOP2(cirrus_bitblt_rop_nop), |
| 512 | ROP2(cirrus_colorexpand_src_and_notdst), |
| 513 | ROP2(cirrus_colorexpand_notdst), |
| 514 | ROP2(cirrus_colorexpand_src), |
| 515 | ROP2(cirrus_colorexpand_1), |
| 516 | ROP2(cirrus_colorexpand_notsrc_and_dst), |
| 517 | ROP2(cirrus_colorexpand_src_xor_dst), |
| 518 | ROP2(cirrus_colorexpand_src_or_dst), |
| 519 | ROP2(cirrus_colorexpand_notsrc_or_notdst), |
| 520 | ROP2(cirrus_colorexpand_src_notxor_dst), |
| 521 | ROP2(cirrus_colorexpand_src_or_notdst), |
| 522 | ROP2(cirrus_colorexpand_notsrc), |
| 523 | ROP2(cirrus_colorexpand_notsrc_or_dst), |
| 524 | ROP2(cirrus_colorexpand_notsrc_and_notdst), |
| 525 | }; |
| 526 | |
bellard | b30d460 | 2004-07-06 01:50:49 +0000 | [diff] [blame] | 527 | static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp[16][4] = { |
| 528 | ROP2(cirrus_colorexpand_pattern_transp_0), |
| 529 | ROP2(cirrus_colorexpand_pattern_transp_src_and_dst), |
| 530 | ROP_NOP2(cirrus_bitblt_rop_nop), |
| 531 | ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst), |
| 532 | ROP2(cirrus_colorexpand_pattern_transp_notdst), |
| 533 | ROP2(cirrus_colorexpand_pattern_transp_src), |
| 534 | ROP2(cirrus_colorexpand_pattern_transp_1), |
| 535 | ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst), |
| 536 | ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst), |
| 537 | ROP2(cirrus_colorexpand_pattern_transp_src_or_dst), |
| 538 | ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst), |
| 539 | ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst), |
| 540 | ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst), |
| 541 | ROP2(cirrus_colorexpand_pattern_transp_notsrc), |
| 542 | ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst), |
| 543 | ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst), |
| 544 | }; |
| 545 | |
| 546 | static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern[16][4] = { |
| 547 | ROP2(cirrus_colorexpand_pattern_0), |
| 548 | ROP2(cirrus_colorexpand_pattern_src_and_dst), |
| 549 | ROP_NOP2(cirrus_bitblt_rop_nop), |
| 550 | ROP2(cirrus_colorexpand_pattern_src_and_notdst), |
| 551 | ROP2(cirrus_colorexpand_pattern_notdst), |
| 552 | ROP2(cirrus_colorexpand_pattern_src), |
| 553 | ROP2(cirrus_colorexpand_pattern_1), |
| 554 | ROP2(cirrus_colorexpand_pattern_notsrc_and_dst), |
| 555 | ROP2(cirrus_colorexpand_pattern_src_xor_dst), |
| 556 | ROP2(cirrus_colorexpand_pattern_src_or_dst), |
| 557 | ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst), |
| 558 | ROP2(cirrus_colorexpand_pattern_src_notxor_dst), |
| 559 | ROP2(cirrus_colorexpand_pattern_src_or_notdst), |
| 560 | ROP2(cirrus_colorexpand_pattern_notsrc), |
| 561 | ROP2(cirrus_colorexpand_pattern_notsrc_or_dst), |
| 562 | ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst), |
| 563 | }; |
| 564 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 565 | static const cirrus_fill_t cirrus_fill[16][4] = { |
| 566 | ROP2(cirrus_fill_0), |
| 567 | ROP2(cirrus_fill_src_and_dst), |
| 568 | ROP_NOP2(cirrus_bitblt_fill_nop), |
| 569 | ROP2(cirrus_fill_src_and_notdst), |
| 570 | ROP2(cirrus_fill_notdst), |
| 571 | ROP2(cirrus_fill_src), |
| 572 | ROP2(cirrus_fill_1), |
| 573 | ROP2(cirrus_fill_notsrc_and_dst), |
| 574 | ROP2(cirrus_fill_src_xor_dst), |
| 575 | ROP2(cirrus_fill_src_or_dst), |
| 576 | ROP2(cirrus_fill_notsrc_or_notdst), |
| 577 | ROP2(cirrus_fill_src_notxor_dst), |
| 578 | ROP2(cirrus_fill_src_or_notdst), |
| 579 | ROP2(cirrus_fill_notsrc), |
| 580 | ROP2(cirrus_fill_notsrc_or_dst), |
| 581 | ROP2(cirrus_fill_notsrc_and_notdst), |
| 582 | }; |
| 583 | |
| 584 | static inline void cirrus_bitblt_fgcol(CirrusVGAState *s) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 585 | { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 586 | unsigned int color; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 587 | switch (s->cirrus_blt_pixelwidth) { |
| 588 | case 1: |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 589 | s->cirrus_blt_fgcol = s->cirrus_shadow_gr1; |
| 590 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 591 | case 2: |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 592 | color = s->cirrus_shadow_gr1 | (s->vga.gr[0x11] << 8); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 593 | s->cirrus_blt_fgcol = le16_to_cpu(color); |
| 594 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 595 | case 3: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 596 | s->cirrus_blt_fgcol = s->cirrus_shadow_gr1 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 597 | (s->vga.gr[0x11] << 8) | (s->vga.gr[0x13] << 16); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 598 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 599 | default: |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 600 | case 4: |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 601 | color = s->cirrus_shadow_gr1 | (s->vga.gr[0x11] << 8) | |
| 602 | (s->vga.gr[0x13] << 16) | (s->vga.gr[0x15] << 24); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 603 | s->cirrus_blt_fgcol = le32_to_cpu(color); |
| 604 | break; |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | static inline void cirrus_bitblt_bgcol(CirrusVGAState *s) |
| 609 | { |
| 610 | unsigned int color; |
| 611 | switch (s->cirrus_blt_pixelwidth) { |
| 612 | case 1: |
| 613 | s->cirrus_blt_bgcol = s->cirrus_shadow_gr0; |
| 614 | break; |
| 615 | case 2: |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 616 | color = s->cirrus_shadow_gr0 | (s->vga.gr[0x10] << 8); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 617 | s->cirrus_blt_bgcol = le16_to_cpu(color); |
| 618 | break; |
| 619 | case 3: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 620 | s->cirrus_blt_bgcol = s->cirrus_shadow_gr0 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 621 | (s->vga.gr[0x10] << 8) | (s->vga.gr[0x12] << 16); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 622 | break; |
| 623 | default: |
| 624 | case 4: |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 625 | color = s->cirrus_shadow_gr0 | (s->vga.gr[0x10] << 8) | |
| 626 | (s->vga.gr[0x12] << 16) | (s->vga.gr[0x14] << 24); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 627 | s->cirrus_blt_bgcol = le32_to_cpu(color); |
| 628 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
| 632 | static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 633 | int off_pitch, int bytesperline, |
| 634 | int lines) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 635 | { |
| 636 | int y; |
| 637 | int off_cur; |
| 638 | int off_cur_end; |
| 639 | |
Wolfgang Bumiller | f153b56 | 2017-01-25 14:48:57 +0100 | [diff] [blame] | 640 | if (off_pitch < 0) { |
| 641 | off_begin -= bytesperline - 1; |
| 642 | } |
| 643 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 644 | for (y = 0; y < lines; y++) { |
Gerd Hoffmann | 5fcf787 | 2020-09-01 16:09:44 +0200 | [diff] [blame] | 645 | off_cur = off_begin & s->cirrus_addr_mask; |
Gerd Hoffmann | e048dac | 2017-03-15 13:06:46 +0100 | [diff] [blame] | 646 | off_cur_end = ((off_cur + bytesperline - 1) & s->cirrus_addr_mask) + 1; |
Gerd Hoffmann | 5fcf787 | 2020-09-01 16:09:44 +0200 | [diff] [blame] | 647 | if (off_cur_end >= off_cur) { |
| 648 | memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); |
| 649 | } else { |
| 650 | /* wraparound */ |
| 651 | memory_region_set_dirty(&s->vga.vram, off_cur, |
| 652 | s->cirrus_addr_mask + 1 - off_cur); |
| 653 | memory_region_set_dirty(&s->vga.vram, 0, off_cur_end); |
| 654 | } |
Gerd Hoffmann | e048dac | 2017-03-15 13:06:46 +0100 | [diff] [blame] | 655 | off_begin += off_pitch; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 659 | static int cirrus_bitblt_common_patterncopy(CirrusVGAState *s) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 660 | { |
Gerd Hoffmann | 95280c3 | 2017-02-09 14:02:20 +0100 | [diff] [blame] | 661 | uint32_t patternsize; |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 662 | bool videosrc = !s->cirrus_srccounter; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 663 | |
Gerd Hoffmann | 95280c3 | 2017-02-09 14:02:20 +0100 | [diff] [blame] | 664 | if (videosrc) { |
| 665 | switch (s->vga.get_bpp(&s->vga)) { |
| 666 | case 8: |
| 667 | patternsize = 64; |
| 668 | break; |
| 669 | case 15: |
| 670 | case 16: |
| 671 | patternsize = 128; |
| 672 | break; |
| 673 | case 24: |
| 674 | case 32: |
| 675 | default: |
| 676 | patternsize = 256; |
| 677 | break; |
| 678 | } |
| 679 | s->cirrus_blt_srcaddr &= ~(patternsize - 1); |
| 680 | if (s->cirrus_blt_srcaddr + patternsize > s->vga.vram_size) { |
| 681 | return 0; |
| 682 | } |
Gerd Hoffmann | 95280c3 | 2017-02-09 14:02:20 +0100 | [diff] [blame] | 683 | } |
| 684 | |
Gerd Hoffmann | 12e97ec | 2017-02-09 14:02:21 +0100 | [diff] [blame] | 685 | if (blit_is_unsafe(s, true)) { |
aurel32 | b2eb849 | 2008-05-05 21:26:31 +0000 | [diff] [blame] | 686 | return 0; |
Wolfgang Bumiller | 5858dd1 | 2017-01-24 16:35:38 +0100 | [diff] [blame] | 687 | } |
aurel32 | b2eb849 | 2008-05-05 21:26:31 +0000 | [diff] [blame] | 688 | |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 689 | (*s->cirrus_rop) (s, s->cirrus_blt_dstaddr, |
| 690 | videosrc ? s->cirrus_blt_srcaddr : 0, |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 691 | s->cirrus_blt_dstpitch, 0, |
bellard | e69390c | 2004-06-09 23:12:09 +0000 | [diff] [blame] | 692 | s->cirrus_blt_width, s->cirrus_blt_height); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 693 | cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, |
bellard | e69390c | 2004-06-09 23:12:09 +0000 | [diff] [blame] | 694 | s->cirrus_blt_dstpitch, s->cirrus_blt_width, |
| 695 | s->cirrus_blt_height); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 696 | return 1; |
| 697 | } |
| 698 | |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 699 | /* fill */ |
| 700 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 701 | static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop) |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 702 | { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 703 | cirrus_fill_t rop_func; |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 704 | |
Gerd Hoffmann | 12e97ec | 2017-02-09 14:02:21 +0100 | [diff] [blame] | 705 | if (blit_is_unsafe(s, true)) { |
aurel32 | b2eb849 | 2008-05-05 21:26:31 +0000 | [diff] [blame] | 706 | return 0; |
Gerd Hoffmann | d3532a0 | 2014-11-19 11:37:42 +0100 | [diff] [blame] | 707 | } |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 708 | rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; |
Gerd Hoffmann | 026aeff | 2017-03-15 11:47:52 +0100 | [diff] [blame] | 709 | rop_func(s, s->cirrus_blt_dstaddr, |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 710 | s->cirrus_blt_dstpitch, |
| 711 | s->cirrus_blt_width, s->cirrus_blt_height); |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 712 | cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 713 | s->cirrus_blt_dstpitch, s->cirrus_blt_width, |
| 714 | s->cirrus_blt_height); |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 715 | cirrus_bitblt_reset(s); |
| 716 | return 1; |
| 717 | } |
| 718 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 719 | /*************************************** |
| 720 | * |
| 721 | * bitblt (video-to-video) |
| 722 | * |
| 723 | ***************************************/ |
| 724 | |
| 725 | static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState * s) |
| 726 | { |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 727 | return cirrus_bitblt_common_patterncopy(s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Prasad J Pandit | 4299b90 | 2016-10-18 13:15:17 +0530 | [diff] [blame] | 730 | static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 731 | { |
Aurelien Jarno | 78935c4 | 2011-01-06 22:28:33 +0100 | [diff] [blame] | 732 | int sx = 0, sy = 0; |
| 733 | int dx = 0, dy = 0; |
| 734 | int depth = 0; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 735 | int notify = 0; |
| 736 | |
Aurelien Jarno | 92d675d | 2011-01-04 21:58:24 +0100 | [diff] [blame] | 737 | /* make sure to only copy if it's a plain copy ROP */ |
| 738 | if (*s->cirrus_rop == cirrus_bitblt_rop_fwd_src || |
| 739 | *s->cirrus_rop == cirrus_bitblt_rop_bkwd_src) { |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 740 | |
Aurelien Jarno | 92d675d | 2011-01-04 21:58:24 +0100 | [diff] [blame] | 741 | int width, height; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 742 | |
Aurelien Jarno | 92d675d | 2011-01-04 21:58:24 +0100 | [diff] [blame] | 743 | depth = s->vga.get_bpp(&s->vga) / 8; |
Prasad J Pandit | 4299b90 | 2016-10-18 13:15:17 +0530 | [diff] [blame] | 744 | if (!depth) { |
| 745 | return 0; |
| 746 | } |
Aurelien Jarno | 92d675d | 2011-01-04 21:58:24 +0100 | [diff] [blame] | 747 | s->vga.get_resolution(&s->vga, &width, &height); |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 748 | |
Aurelien Jarno | 92d675d | 2011-01-04 21:58:24 +0100 | [diff] [blame] | 749 | /* extra x, y */ |
| 750 | sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth; |
| 751 | sy = (src / ABS(s->cirrus_blt_srcpitch)); |
| 752 | dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth; |
| 753 | dy = (dst / ABS(s->cirrus_blt_dstpitch)); |
| 754 | |
| 755 | /* normalize width */ |
| 756 | w /= depth; |
| 757 | |
| 758 | /* if we're doing a backward copy, we have to adjust |
| 759 | our x/y to be the upper left corner (instead of the lower |
| 760 | right corner) */ |
| 761 | if (s->cirrus_blt_dstpitch < 0) { |
| 762 | sx -= (s->cirrus_blt_width / depth) - 1; |
| 763 | dx -= (s->cirrus_blt_width / depth) - 1; |
| 764 | sy -= s->cirrus_blt_height - 1; |
| 765 | dy -= s->cirrus_blt_height - 1; |
| 766 | } |
| 767 | |
| 768 | /* are we in the visible portion of memory? */ |
| 769 | if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 && |
| 770 | (sx + w) <= width && (sy + h) <= height && |
| 771 | (dx + w) <= width && (dy + h) <= height) { |
| 772 | notify = 1; |
| 773 | } |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Gerd Hoffmann | 026aeff | 2017-03-15 11:47:52 +0100 | [diff] [blame] | 776 | (*s->cirrus_rop) (s, s->cirrus_blt_dstaddr, |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 777 | s->cirrus_blt_srcaddr, |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 778 | s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch, |
| 779 | s->cirrus_blt_width, s->cirrus_blt_height); |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 780 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 781 | if (notify) { |
Gerd Hoffmann | 50628d3 | 2017-03-14 13:26:59 +0100 | [diff] [blame] | 782 | dpy_gfx_update(s->vga.con, dx, dy, |
| 783 | s->cirrus_blt_width / depth, |
| 784 | s->cirrus_blt_height); |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 785 | } |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 786 | |
| 787 | /* we don't have to notify the display that this portion has |
balrog | 38334f7 | 2008-09-24 02:21:24 +0000 | [diff] [blame] | 788 | changed since qemu_console_copy implies this */ |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 789 | |
aliguori | 31c0550 | 2009-02-27 19:53:57 +0000 | [diff] [blame] | 790 | cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 791 | s->cirrus_blt_dstpitch, s->cirrus_blt_width, |
| 792 | s->cirrus_blt_height); |
Prasad J Pandit | 4299b90 | 2016-10-18 13:15:17 +0530 | [diff] [blame] | 793 | |
| 794 | return 1; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s) |
| 798 | { |
Gerd Hoffmann | 12e97ec | 2017-02-09 14:02:21 +0100 | [diff] [blame] | 799 | if (blit_is_unsafe(s, false)) |
aurel32 | 65d35a0 | 2008-11-01 00:53:39 +0000 | [diff] [blame] | 800 | return 0; |
| 801 | |
Paolo Bonzini | f9b925f | 2015-01-09 10:47:33 +0100 | [diff] [blame] | 802 | return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.params.start_addr, |
| 803 | s->cirrus_blt_srcaddr - s->vga.params.start_addr, |
| 804 | s->cirrus_blt_width, s->cirrus_blt_height); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | /*************************************** |
| 808 | * |
| 809 | * bitblt (cpu-to-video) |
| 810 | * |
| 811 | ***************************************/ |
| 812 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 813 | static void cirrus_bitblt_cputovideo_next(CirrusVGAState * s) |
| 814 | { |
| 815 | int copy_count; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 816 | uint8_t *end_ptr; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 817 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 818 | if (s->cirrus_srccounter > 0) { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 819 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) { |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 820 | cirrus_bitblt_common_patterncopy(s); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 821 | the_end: |
| 822 | s->cirrus_srccounter = 0; |
| 823 | cirrus_bitblt_reset(s); |
| 824 | } else { |
| 825 | /* at least one scan line */ |
| 826 | do { |
Gerd Hoffmann | 026aeff | 2017-03-15 11:47:52 +0100 | [diff] [blame] | 827 | (*s->cirrus_rop)(s, s->cirrus_blt_dstaddr, |
Gerd Hoffmann | ffaf857 | 2017-03-15 14:28:07 +0100 | [diff] [blame] | 828 | 0, 0, 0, s->cirrus_blt_width, 1); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 829 | cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, 0, |
| 830 | s->cirrus_blt_width, 1); |
| 831 | s->cirrus_blt_dstaddr += s->cirrus_blt_dstpitch; |
| 832 | s->cirrus_srccounter -= s->cirrus_blt_srcpitch; |
| 833 | if (s->cirrus_srccounter <= 0) |
| 834 | goto the_end; |
Dong Xu Wang | 66a0a2c | 2011-11-29 16:52:39 +0800 | [diff] [blame] | 835 | /* more bytes than needed can be transferred because of |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 836 | word alignment, so we keep them for the next line */ |
| 837 | /* XXX: keep alignment to speed up transfer */ |
| 838 | end_ptr = s->cirrus_bltbuf + s->cirrus_blt_srcpitch; |
lu zhipeng | 2fba4e9 | 2022-09-29 20:23:52 +0800 | [diff] [blame] | 839 | copy_count = MIN(s->cirrus_srcptr_end - end_ptr, CIRRUS_BLTBUFSIZE); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 840 | memmove(s->cirrus_bltbuf, end_ptr, copy_count); |
| 841 | s->cirrus_srcptr = s->cirrus_bltbuf + copy_count; |
| 842 | s->cirrus_srcptr_end = s->cirrus_bltbuf + s->cirrus_blt_srcpitch; |
| 843 | } while (s->cirrus_srcptr >= s->cirrus_srcptr_end); |
| 844 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | |
| 848 | /*************************************** |
| 849 | * |
| 850 | * bitblt wrapper |
| 851 | * |
| 852 | ***************************************/ |
| 853 | |
| 854 | static void cirrus_bitblt_reset(CirrusVGAState * s) |
| 855 | { |
aliguori | f8b237a | 2009-01-21 18:31:26 +0000 | [diff] [blame] | 856 | int need_update; |
| 857 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 858 | s->vga.gr[0x31] &= |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 859 | ~(CIRRUS_BLT_START | CIRRUS_BLT_BUSY | CIRRUS_BLT_FIFOUSED); |
aliguori | f8b237a | 2009-01-21 18:31:26 +0000 | [diff] [blame] | 860 | need_update = s->cirrus_srcptr != &s->cirrus_bltbuf[0] |
| 861 | || s->cirrus_srcptr_end != &s->cirrus_bltbuf[0]; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 862 | s->cirrus_srcptr = &s->cirrus_bltbuf[0]; |
| 863 | s->cirrus_srcptr_end = &s->cirrus_bltbuf[0]; |
| 864 | s->cirrus_srccounter = 0; |
aliguori | f8b237a | 2009-01-21 18:31:26 +0000 | [diff] [blame] | 865 | if (!need_update) |
| 866 | return; |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 867 | cirrus_update_memory_access(s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | static int cirrus_bitblt_cputovideo(CirrusVGAState * s) |
| 871 | { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 872 | int w; |
| 873 | |
Gerd Hoffmann | 92f2b88 | 2017-02-08 11:18:36 +0100 | [diff] [blame] | 874 | if (blit_is_unsafe(s, true)) { |
| 875 | return 0; |
| 876 | } |
| 877 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 878 | s->cirrus_blt_mode &= ~CIRRUS_BLTMODE_MEMSYSSRC; |
| 879 | s->cirrus_srcptr = &s->cirrus_bltbuf[0]; |
| 880 | s->cirrus_srcptr_end = &s->cirrus_bltbuf[0]; |
| 881 | |
| 882 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 883 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_COLOREXPAND) { |
| 884 | s->cirrus_blt_srcpitch = 8; |
| 885 | } else { |
bellard | b30d460 | 2004-07-06 01:50:49 +0000 | [diff] [blame] | 886 | /* XXX: check for 24 bpp */ |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 887 | s->cirrus_blt_srcpitch = 8 * 8 * s->cirrus_blt_pixelwidth; |
| 888 | } |
| 889 | s->cirrus_srccounter = s->cirrus_blt_srcpitch; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 890 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 891 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_COLOREXPAND) { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 892 | w = s->cirrus_blt_width / s->cirrus_blt_pixelwidth; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 893 | if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_DWORDGRANULARITY) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 894 | s->cirrus_blt_srcpitch = ((w + 31) >> 5); |
| 895 | else |
| 896 | s->cirrus_blt_srcpitch = ((w + 7) >> 3); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 897 | } else { |
bellard | c9c0eae | 2004-11-15 21:43:57 +0000 | [diff] [blame] | 898 | /* always align input size to 32 bits */ |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 899 | s->cirrus_blt_srcpitch = (s->cirrus_blt_width + 3) & ~3; |
| 900 | } |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 901 | s->cirrus_srccounter = s->cirrus_blt_srcpitch * s->cirrus_blt_height; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 902 | } |
Gerd Hoffmann | 92f2b88 | 2017-02-08 11:18:36 +0100 | [diff] [blame] | 903 | |
| 904 | /* the blit_is_unsafe call above should catch this */ |
| 905 | assert(s->cirrus_blt_srcpitch <= CIRRUS_BLTBUFSIZE); |
| 906 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 907 | s->cirrus_srcptr = s->cirrus_bltbuf; |
| 908 | s->cirrus_srcptr_end = s->cirrus_bltbuf + s->cirrus_blt_srcpitch; |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 909 | cirrus_update_memory_access(s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 910 | return 1; |
| 911 | } |
| 912 | |
| 913 | static int cirrus_bitblt_videotocpu(CirrusVGAState * s) |
| 914 | { |
| 915 | /* XXX */ |
Philippe Mathieu-Daudé | bb6e9e9 | 2020-05-26 08:22:42 +0200 | [diff] [blame] | 916 | qemu_log_mask(LOG_UNIMP, |
| 917 | "cirrus: bitblt (video to cpu) is not implemented\n"); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static int cirrus_bitblt_videotovideo(CirrusVGAState * s) |
| 922 | { |
| 923 | int ret; |
| 924 | |
| 925 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 926 | ret = cirrus_bitblt_videotovideo_patterncopy(s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 927 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 928 | ret = cirrus_bitblt_videotovideo_copy(s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 929 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 930 | if (ret) |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 931 | cirrus_bitblt_reset(s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 932 | return ret; |
| 933 | } |
| 934 | |
| 935 | static void cirrus_bitblt_start(CirrusVGAState * s) |
| 936 | { |
| 937 | uint8_t blt_rop; |
| 938 | |
Gerd Hoffmann | 827bd51 | 2017-03-14 13:29:00 +0100 | [diff] [blame] | 939 | if (!s->enable_blitter) { |
| 940 | goto bitblt_ignore; |
| 941 | } |
| 942 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 943 | s->vga.gr[0x31] |= CIRRUS_BLT_BUSY; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 944 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 945 | s->cirrus_blt_width = (s->vga.gr[0x20] | (s->vga.gr[0x21] << 8)) + 1; |
| 946 | s->cirrus_blt_height = (s->vga.gr[0x22] | (s->vga.gr[0x23] << 8)) + 1; |
| 947 | s->cirrus_blt_dstpitch = (s->vga.gr[0x24] | (s->vga.gr[0x25] << 8)); |
| 948 | s->cirrus_blt_srcpitch = (s->vga.gr[0x26] | (s->vga.gr[0x27] << 8)); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 949 | s->cirrus_blt_dstaddr = |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 950 | (s->vga.gr[0x28] | (s->vga.gr[0x29] << 8) | (s->vga.gr[0x2a] << 16)); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 951 | s->cirrus_blt_srcaddr = |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 952 | (s->vga.gr[0x2c] | (s->vga.gr[0x2d] << 8) | (s->vga.gr[0x2e] << 16)); |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 953 | s->cirrus_blt_mode = s->vga.gr[0x30]; |
| 954 | s->cirrus_blt_modeext = s->vga.gr[0x33]; |
| 955 | blt_rop = s->vga.gr[0x32]; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 956 | |
Gerd Hoffmann | 60cd23e | 2017-01-25 11:09:56 +0100 | [diff] [blame] | 957 | s->cirrus_blt_dstaddr &= s->cirrus_addr_mask; |
| 958 | s->cirrus_blt_srcaddr &= s->cirrus_addr_mask; |
| 959 | |
Philippe Mathieu-Daudé | 6152772 | 2020-05-26 08:22:44 +0200 | [diff] [blame] | 960 | trace_vga_cirrus_bitblt_start(blt_rop, |
| 961 | s->cirrus_blt_mode, |
| 962 | s->cirrus_blt_modeext, |
| 963 | s->cirrus_blt_width, |
| 964 | s->cirrus_blt_height, |
| 965 | s->cirrus_blt_dstpitch, |
| 966 | s->cirrus_blt_srcpitch, |
| 967 | s->cirrus_blt_dstaddr, |
| 968 | s->cirrus_blt_srcaddr, |
| 969 | s->vga.gr[0x2f]); |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 970 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 971 | switch (s->cirrus_blt_mode & CIRRUS_BLTMODE_PIXELWIDTHMASK) { |
| 972 | case CIRRUS_BLTMODE_PIXELWIDTH8: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 973 | s->cirrus_blt_pixelwidth = 1; |
| 974 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 975 | case CIRRUS_BLTMODE_PIXELWIDTH16: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 976 | s->cirrus_blt_pixelwidth = 2; |
| 977 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 978 | case CIRRUS_BLTMODE_PIXELWIDTH24: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 979 | s->cirrus_blt_pixelwidth = 3; |
| 980 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 981 | case CIRRUS_BLTMODE_PIXELWIDTH32: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 982 | s->cirrus_blt_pixelwidth = 4; |
| 983 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 984 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 985 | qemu_log_mask(LOG_GUEST_ERROR, |
| 986 | "cirrus: bitblt - pixel width is unknown\n"); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 987 | goto bitblt_ignore; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 988 | } |
| 989 | s->cirrus_blt_mode &= ~CIRRUS_BLTMODE_PIXELWIDTHMASK; |
| 990 | |
| 991 | if ((s-> |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 992 | cirrus_blt_mode & (CIRRUS_BLTMODE_MEMSYSSRC | |
| 993 | CIRRUS_BLTMODE_MEMSYSDEST)) |
| 994 | == (CIRRUS_BLTMODE_MEMSYSSRC | CIRRUS_BLTMODE_MEMSYSDEST)) { |
Philippe Mathieu-Daudé | bb6e9e9 | 2020-05-26 08:22:42 +0200 | [diff] [blame] | 995 | qemu_log_mask(LOG_UNIMP, |
| 996 | "cirrus: bitblt - memory-to-memory copy requested\n"); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 997 | goto bitblt_ignore; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 998 | } |
| 999 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 1000 | if ((s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_SOLIDFILL) && |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1001 | (s->cirrus_blt_mode & (CIRRUS_BLTMODE_MEMSYSDEST | |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 1002 | CIRRUS_BLTMODE_TRANSPARENTCOMP | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1003 | CIRRUS_BLTMODE_PATTERNCOPY | |
| 1004 | CIRRUS_BLTMODE_COLOREXPAND)) == |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 1005 | (CIRRUS_BLTMODE_PATTERNCOPY | CIRRUS_BLTMODE_COLOREXPAND)) { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 1006 | cirrus_bitblt_fgcol(s); |
| 1007 | cirrus_bitblt_solidfill(s, blt_rop); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1008 | } else { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1009 | if ((s->cirrus_blt_mode & (CIRRUS_BLTMODE_COLOREXPAND | |
| 1010 | CIRRUS_BLTMODE_PATTERNCOPY)) == |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 1011 | CIRRUS_BLTMODE_COLOREXPAND) { |
| 1012 | |
| 1013 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_TRANSPARENTCOMP) { |
bellard | b30d460 | 2004-07-06 01:50:49 +0000 | [diff] [blame] | 1014 | if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) |
bellard | 4c8732d | 2004-06-07 19:46:45 +0000 | [diff] [blame] | 1015 | cirrus_bitblt_bgcol(s); |
bellard | b30d460 | 2004-07-06 01:50:49 +0000 | [diff] [blame] | 1016 | else |
bellard | 4c8732d | 2004-06-07 19:46:45 +0000 | [diff] [blame] | 1017 | cirrus_bitblt_fgcol(s); |
bellard | b30d460 | 2004-07-06 01:50:49 +0000 | [diff] [blame] | 1018 | s->cirrus_rop = cirrus_colorexpand_transp[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 1019 | } else { |
| 1020 | cirrus_bitblt_fgcol(s); |
| 1021 | cirrus_bitblt_bgcol(s); |
| 1022 | s->cirrus_rop = cirrus_colorexpand[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; |
| 1023 | } |
bellard | e69390c | 2004-06-09 23:12:09 +0000 | [diff] [blame] | 1024 | } else if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) { |
bellard | b30d460 | 2004-07-06 01:50:49 +0000 | [diff] [blame] | 1025 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_COLOREXPAND) { |
| 1026 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_TRANSPARENTCOMP) { |
| 1027 | if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) |
| 1028 | cirrus_bitblt_bgcol(s); |
| 1029 | else |
| 1030 | cirrus_bitblt_fgcol(s); |
| 1031 | s->cirrus_rop = cirrus_colorexpand_pattern_transp[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; |
| 1032 | } else { |
| 1033 | cirrus_bitblt_fgcol(s); |
| 1034 | cirrus_bitblt_bgcol(s); |
| 1035 | s->cirrus_rop = cirrus_colorexpand_pattern[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; |
| 1036 | } |
| 1037 | } else { |
| 1038 | s->cirrus_rop = cirrus_patternfill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; |
| 1039 | } |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 1040 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1041 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_TRANSPARENTCOMP) { |
| 1042 | if (s->cirrus_blt_pixelwidth > 2) { |
Philippe Mathieu-Daudé | ae3887e | 2020-05-29 18:54:36 +0200 | [diff] [blame] | 1043 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1044 | "cirrus: src transparent without colorexpand " |
| 1045 | "must be 8bpp or 16bpp\n"); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1046 | goto bitblt_ignore; |
| 1047 | } |
| 1048 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_BACKWARDS) { |
| 1049 | s->cirrus_blt_dstpitch = -s->cirrus_blt_dstpitch; |
| 1050 | s->cirrus_blt_srcpitch = -s->cirrus_blt_srcpitch; |
| 1051 | s->cirrus_rop = cirrus_bkwd_transp_rop[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; |
| 1052 | } else { |
| 1053 | s->cirrus_rop = cirrus_fwd_transp_rop[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; |
| 1054 | } |
| 1055 | } else { |
| 1056 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_BACKWARDS) { |
| 1057 | s->cirrus_blt_dstpitch = -s->cirrus_blt_dstpitch; |
| 1058 | s->cirrus_blt_srcpitch = -s->cirrus_blt_srcpitch; |
| 1059 | s->cirrus_rop = cirrus_bkwd_rop[rop_to_index[blt_rop]]; |
| 1060 | } else { |
| 1061 | s->cirrus_rop = cirrus_fwd_rop[rop_to_index[blt_rop]]; |
| 1062 | } |
| 1063 | } |
| 1064 | } |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 1065 | // setup bitblt engine. |
| 1066 | if (s->cirrus_blt_mode & CIRRUS_BLTMODE_MEMSYSSRC) { |
| 1067 | if (!cirrus_bitblt_cputovideo(s)) |
| 1068 | goto bitblt_ignore; |
| 1069 | } else if (s->cirrus_blt_mode & CIRRUS_BLTMODE_MEMSYSDEST) { |
| 1070 | if (!cirrus_bitblt_videotocpu(s)) |
| 1071 | goto bitblt_ignore; |
| 1072 | } else { |
| 1073 | if (!cirrus_bitblt_videotovideo(s)) |
| 1074 | goto bitblt_ignore; |
| 1075 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1076 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1077 | return; |
| 1078 | bitblt_ignore:; |
| 1079 | cirrus_bitblt_reset(s); |
| 1080 | } |
| 1081 | |
| 1082 | static void cirrus_write_bitblt(CirrusVGAState * s, unsigned reg_value) |
| 1083 | { |
| 1084 | unsigned old_value; |
| 1085 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1086 | old_value = s->vga.gr[0x31]; |
| 1087 | s->vga.gr[0x31] = reg_value; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1088 | |
| 1089 | if (((old_value & CIRRUS_BLT_RESET) != 0) && |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1090 | ((reg_value & CIRRUS_BLT_RESET) == 0)) { |
| 1091 | cirrus_bitblt_reset(s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1092 | } else if (((old_value & CIRRUS_BLT_START) == 0) && |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1093 | ((reg_value & CIRRUS_BLT_START) != 0)) { |
| 1094 | cirrus_bitblt_start(s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | /*************************************** |
| 1100 | * |
| 1101 | * basic parameters |
| 1102 | * |
| 1103 | ***************************************/ |
| 1104 | |
Paolo Bonzini | f9b925f | 2015-01-09 10:47:33 +0100 | [diff] [blame] | 1105 | static void cirrus_get_params(VGACommonState *s1, |
| 1106 | VGADisplayParams *params) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1107 | { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1108 | CirrusVGAState * s = container_of(s1, CirrusVGAState, vga); |
Paolo Bonzini | f9b925f | 2015-01-09 10:47:33 +0100 | [diff] [blame] | 1109 | uint32_t line_offset; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1110 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1111 | line_offset = s->vga.cr[0x13] |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1112 | | ((s->vga.cr[0x1b] & 0x10) << 4); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1113 | line_offset <<= 3; |
Paolo Bonzini | f9b925f | 2015-01-09 10:47:33 +0100 | [diff] [blame] | 1114 | params->line_offset = line_offset; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1115 | |
Paolo Bonzini | f9b925f | 2015-01-09 10:47:33 +0100 | [diff] [blame] | 1116 | params->start_addr = (s->vga.cr[0x0c] << 8) |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1117 | | s->vga.cr[0x0d] |
| 1118 | | ((s->vga.cr[0x1b] & 0x01) << 16) |
| 1119 | | ((s->vga.cr[0x1b] & 0x0c) << 15) |
| 1120 | | ((s->vga.cr[0x1d] & 0x80) << 12); |
bellard | 83acc96 | 2006-08-18 09:32:04 +0000 | [diff] [blame] | 1121 | |
Paolo Bonzini | f9b925f | 2015-01-09 10:47:33 +0100 | [diff] [blame] | 1122 | params->line_compare = s->vga.cr[0x18] | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1123 | ((s->vga.cr[0x07] & 0x10) << 4) | |
| 1124 | ((s->vga.cr[0x09] & 0x40) << 3); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 1125 | |
| 1126 | params->hpel = s->vga.ar[VGA_ATC_PEL]; |
| 1127 | params->hpel_split = s->vga.ar[VGA_ATC_MODE] & 0x20; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | static uint32_t cirrus_get_bpp16_depth(CirrusVGAState * s) |
| 1131 | { |
| 1132 | uint32_t ret = 16; |
| 1133 | |
| 1134 | switch (s->cirrus_hidden_dac_data & 0xf) { |
| 1135 | case 0: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1136 | ret = 15; |
| 1137 | break; /* Sierra HiColor */ |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1138 | case 1: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1139 | ret = 16; |
| 1140 | break; /* XGA HiColor */ |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1141 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1142 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1143 | "cirrus: invalid DAC value 0x%x in 16bpp\n", |
| 1144 | (s->cirrus_hidden_dac_data & 0xf)); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1145 | ret = 15; /* XXX */ |
| 1146 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1147 | } |
| 1148 | return ret; |
| 1149 | } |
| 1150 | |
Juan Quintela | a4a2f59 | 2009-08-24 18:42:47 +0200 | [diff] [blame] | 1151 | static int cirrus_get_bpp(VGACommonState *s1) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1152 | { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1153 | CirrusVGAState * s = container_of(s1, CirrusVGAState, vga); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1154 | uint32_t ret = 8; |
| 1155 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1156 | if ((s->vga.sr[0x07] & 0x01) != 0) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1157 | /* Cirrus SVGA */ |
| 1158 | switch (s->vga.sr[0x07] & CIRRUS_SR7_BPP_MASK) { |
| 1159 | case CIRRUS_SR7_BPP_8: |
| 1160 | ret = 8; |
| 1161 | break; |
| 1162 | case CIRRUS_SR7_BPP_16_DOUBLEVCLK: |
| 1163 | ret = cirrus_get_bpp16_depth(s); |
| 1164 | break; |
| 1165 | case CIRRUS_SR7_BPP_24: |
| 1166 | ret = 24; |
| 1167 | break; |
| 1168 | case CIRRUS_SR7_BPP_16: |
| 1169 | ret = cirrus_get_bpp16_depth(s); |
| 1170 | break; |
| 1171 | case CIRRUS_SR7_BPP_32: |
| 1172 | ret = 32; |
| 1173 | break; |
| 1174 | default: |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1175 | #ifdef DEBUG_CIRRUS |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1176 | printf("cirrus: unknown bpp - sr7=%x\n", s->vga.sr[0x7]); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1177 | #endif |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1178 | ret = 8; |
| 1179 | break; |
| 1180 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1181 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1182 | /* VGA */ |
| 1183 | ret = 0; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | return ret; |
| 1187 | } |
| 1188 | |
Juan Quintela | a4a2f59 | 2009-08-24 18:42:47 +0200 | [diff] [blame] | 1189 | static void cirrus_get_resolution(VGACommonState *s, int *pwidth, int *pheight) |
bellard | 78e127e | 2004-06-08 00:58:26 +0000 | [diff] [blame] | 1190 | { |
| 1191 | int width, height; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1192 | |
bellard | 78e127e | 2004-06-08 00:58:26 +0000 | [diff] [blame] | 1193 | width = (s->cr[0x01] + 1) * 8; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1194 | height = s->cr[0x12] | |
| 1195 | ((s->cr[0x07] & 0x02) << 7) | |
bellard | 78e127e | 2004-06-08 00:58:26 +0000 | [diff] [blame] | 1196 | ((s->cr[0x07] & 0x40) << 3); |
| 1197 | height = (height + 1); |
| 1198 | /* interlace support */ |
| 1199 | if (s->cr[0x1a] & 0x01) |
| 1200 | height = height * 2; |
| 1201 | *pwidth = width; |
| 1202 | *pheight = height; |
| 1203 | } |
| 1204 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1205 | /*************************************** |
| 1206 | * |
| 1207 | * bank memory |
| 1208 | * |
| 1209 | ***************************************/ |
| 1210 | |
| 1211 | static void cirrus_update_bank_ptr(CirrusVGAState * s, unsigned bank_index) |
| 1212 | { |
| 1213 | unsigned offset; |
| 1214 | unsigned limit; |
| 1215 | |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1216 | if ((s->vga.gr[0x0b] & 0x01) != 0) /* dual bank */ |
| 1217 | offset = s->vga.gr[0x09 + bank_index]; |
| 1218 | else /* single bank */ |
| 1219 | offset = s->vga.gr[0x09]; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1220 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1221 | if ((s->vga.gr[0x0b] & 0x20) != 0) |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1222 | offset <<= 14; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1223 | else |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1224 | offset <<= 12; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1225 | |
bellard | e3a4e4b | 2005-04-17 17:56:18 +0000 | [diff] [blame] | 1226 | if (s->real_vram_size <= offset) |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1227 | limit = 0; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1228 | else |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1229 | limit = s->real_vram_size - offset; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1230 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1231 | if (((s->vga.gr[0x0b] & 0x01) == 0) && (bank_index != 0)) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1232 | if (limit > 0x8000) { |
| 1233 | offset += 0x8000; |
| 1234 | limit -= 0x8000; |
| 1235 | } else { |
| 1236 | limit = 0; |
| 1237 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | if (limit > 0) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1241 | s->cirrus_bank_base[bank_index] = offset; |
| 1242 | s->cirrus_bank_limit[bank_index] = limit; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1243 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1244 | s->cirrus_bank_base[bank_index] = 0; |
| 1245 | s->cirrus_bank_limit[bank_index] = 0; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | /*************************************** |
| 1250 | * |
| 1251 | * I/O access between 0x3c4-0x3c5 |
| 1252 | * |
| 1253 | ***************************************/ |
| 1254 | |
Juan Quintela | 8a82c32 | 2009-08-31 16:07:25 +0200 | [diff] [blame] | 1255 | static int cirrus_vga_read_sr(CirrusVGAState * s) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1256 | { |
Juan Quintela | 8a82c32 | 2009-08-31 16:07:25 +0200 | [diff] [blame] | 1257 | switch (s->vga.sr_index) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1258 | case 0x00: // Standard VGA |
| 1259 | case 0x01: // Standard VGA |
| 1260 | case 0x02: // Standard VGA |
| 1261 | case 0x03: // Standard VGA |
| 1262 | case 0x04: // Standard VGA |
| 1263 | return s->vga.sr[s->vga.sr_index]; |
| 1264 | case 0x06: // Unlock Cirrus extensions |
| 1265 | return s->vga.sr[s->vga.sr_index]; |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 1266 | case 0x10: |
| 1267 | case 0x30: |
| 1268 | case 0x50: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1269 | case 0x70: // Graphics Cursor X |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 1270 | case 0x90: |
| 1271 | case 0xb0: |
| 1272 | case 0xd0: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1273 | case 0xf0: // Graphics Cursor X |
| 1274 | return s->vga.sr[0x10]; |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 1275 | case 0x11: |
| 1276 | case 0x31: |
| 1277 | case 0x51: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1278 | case 0x71: // Graphics Cursor Y |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 1279 | case 0x91: |
| 1280 | case 0xb1: |
| 1281 | case 0xd1: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1282 | case 0xf1: // Graphics Cursor Y |
| 1283 | return s->vga.sr[0x11]; |
| 1284 | case 0x05: // ??? |
| 1285 | case 0x07: // Extended Sequencer Mode |
| 1286 | case 0x08: // EEPROM Control |
| 1287 | case 0x09: // Scratch Register 0 |
| 1288 | case 0x0a: // Scratch Register 1 |
| 1289 | case 0x0b: // VCLK 0 |
| 1290 | case 0x0c: // VCLK 1 |
| 1291 | case 0x0d: // VCLK 2 |
| 1292 | case 0x0e: // VCLK 3 |
| 1293 | case 0x0f: // DRAM Control |
| 1294 | case 0x12: // Graphics Cursor Attribute |
| 1295 | case 0x13: // Graphics Cursor Pattern Address |
| 1296 | case 0x14: // Scratch Register 2 |
| 1297 | case 0x15: // Scratch Register 3 |
| 1298 | case 0x16: // Performance Tuning Register |
| 1299 | case 0x17: // Configuration Readback and Extended Control |
| 1300 | case 0x18: // Signature Generator Control |
| 1301 | case 0x19: // Signal Generator Result |
| 1302 | case 0x1a: // Signal Generator Result |
| 1303 | case 0x1b: // VCLK 0 Denominator & Post |
| 1304 | case 0x1c: // VCLK 1 Denominator & Post |
| 1305 | case 0x1d: // VCLK 2 Denominator & Post |
| 1306 | case 0x1e: // VCLK 3 Denominator & Post |
| 1307 | case 0x1f: // BIOS Write Enable and MCLK select |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1308 | #ifdef DEBUG_CIRRUS |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1309 | printf("cirrus: handled inport sr_index %02x\n", s->vga.sr_index); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1310 | #endif |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1311 | return s->vga.sr[s->vga.sr_index]; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1312 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1313 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1314 | "cirrus: inport sr_index 0x%02x\n", s->vga.sr_index); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1315 | return 0xff; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1316 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
Juan Quintela | 31c6320 | 2009-08-31 16:07:26 +0200 | [diff] [blame] | 1319 | static void cirrus_vga_write_sr(CirrusVGAState * s, uint32_t val) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1320 | { |
Juan Quintela | 31c6320 | 2009-08-31 16:07:26 +0200 | [diff] [blame] | 1321 | switch (s->vga.sr_index) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1322 | case 0x00: // Standard VGA |
| 1323 | case 0x01: // Standard VGA |
| 1324 | case 0x02: // Standard VGA |
| 1325 | case 0x03: // Standard VGA |
| 1326 | case 0x04: // Standard VGA |
| 1327 | s->vga.sr[s->vga.sr_index] = val & sr_mask[s->vga.sr_index]; |
| 1328 | if (s->vga.sr_index == 1) |
Juan Quintela | 31c6320 | 2009-08-31 16:07:26 +0200 | [diff] [blame] | 1329 | s->vga.update_retrace_info(&s->vga); |
| 1330 | break; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1331 | case 0x06: // Unlock Cirrus extensions |
| 1332 | val &= 0x17; |
| 1333 | if (val == 0x12) { |
| 1334 | s->vga.sr[s->vga.sr_index] = 0x12; |
| 1335 | } else { |
| 1336 | s->vga.sr[s->vga.sr_index] = 0x0f; |
| 1337 | } |
| 1338 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1339 | case 0x10: |
| 1340 | case 0x30: |
| 1341 | case 0x50: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1342 | case 0x70: // Graphics Cursor X |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1343 | case 0x90: |
| 1344 | case 0xb0: |
| 1345 | case 0xd0: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1346 | case 0xf0: // Graphics Cursor X |
| 1347 | s->vga.sr[0x10] = val; |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 1348 | s->vga.hw_cursor_x = (val << 3) | (s->vga.sr_index >> 5); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1349 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1350 | case 0x11: |
| 1351 | case 0x31: |
| 1352 | case 0x51: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1353 | case 0x71: // Graphics Cursor Y |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1354 | case 0x91: |
| 1355 | case 0xb1: |
| 1356 | case 0xd1: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1357 | case 0xf1: // Graphics Cursor Y |
| 1358 | s->vga.sr[0x11] = val; |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 1359 | s->vga.hw_cursor_y = (val << 3) | (s->vga.sr_index >> 5); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1360 | break; |
| 1361 | case 0x07: // Extended Sequencer Mode |
Paolo Bonzini | edd7541 | 2018-08-01 17:14:09 +0200 | [diff] [blame] | 1362 | cirrus_update_memory_access(s); |
| 1363 | /* fall through */ |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1364 | case 0x08: // EEPROM Control |
| 1365 | case 0x09: // Scratch Register 0 |
| 1366 | case 0x0a: // Scratch Register 1 |
| 1367 | case 0x0b: // VCLK 0 |
| 1368 | case 0x0c: // VCLK 1 |
| 1369 | case 0x0d: // VCLK 2 |
| 1370 | case 0x0e: // VCLK 3 |
| 1371 | case 0x0f: // DRAM Control |
| 1372 | case 0x13: // Graphics Cursor Pattern Address |
| 1373 | case 0x14: // Scratch Register 2 |
| 1374 | case 0x15: // Scratch Register 3 |
| 1375 | case 0x16: // Performance Tuning Register |
| 1376 | case 0x18: // Signature Generator Control |
| 1377 | case 0x19: // Signature Generator Result |
| 1378 | case 0x1a: // Signature Generator Result |
| 1379 | case 0x1b: // VCLK 0 Denominator & Post |
| 1380 | case 0x1c: // VCLK 1 Denominator & Post |
| 1381 | case 0x1d: // VCLK 2 Denominator & Post |
| 1382 | case 0x1e: // VCLK 3 Denominator & Post |
| 1383 | case 0x1f: // BIOS Write Enable and MCLK select |
| 1384 | s->vga.sr[s->vga.sr_index] = val; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1385 | #ifdef DEBUG_CIRRUS |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1386 | printf("cirrus: handled outport sr_index %02x, sr_value %02x\n", |
| 1387 | s->vga.sr_index, val); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1388 | #endif |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1389 | break; |
| 1390 | case 0x12: // Graphics Cursor Attribute |
| 1391 | s->vga.sr[0x12] = val; |
Benjamin Herrenschmidt | b9fd11b | 2014-07-07 10:28:39 +1000 | [diff] [blame] | 1392 | s->vga.force_shadow = !!(val & CIRRUS_CURSOR_SHOW); |
| 1393 | #ifdef DEBUG_CIRRUS |
| 1394 | printf("cirrus: cursor ctl SR12=%02x (force shadow: %d)\n", |
| 1395 | val, s->vga.force_shadow); |
| 1396 | #endif |
| 1397 | break; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1398 | case 0x17: // Configuration Readback and Extended Control |
| 1399 | s->vga.sr[s->vga.sr_index] = (s->vga.sr[s->vga.sr_index] & 0x38) |
Juan Quintela | 31c6320 | 2009-08-31 16:07:26 +0200 | [diff] [blame] | 1400 | | (val & 0xc7); |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 1401 | cirrus_update_memory_access(s); |
| 1402 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1403 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1404 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1405 | "cirrus: outport sr_index 0x%02x, sr_value 0x%02x\n", |
| 1406 | s->vga.sr_index, val); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1407 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1408 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | /*************************************** |
| 1412 | * |
| 1413 | * I/O access at 0x3c6 |
| 1414 | * |
| 1415 | ***************************************/ |
| 1416 | |
Juan Quintela | 957c9db | 2009-08-31 16:07:22 +0200 | [diff] [blame] | 1417 | static int cirrus_read_hidden_dac(CirrusVGAState * s) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1418 | { |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 1419 | if (++s->cirrus_hidden_dac_lockindex == 5) { |
Juan Quintela | 957c9db | 2009-08-31 16:07:22 +0200 | [diff] [blame] | 1420 | s->cirrus_hidden_dac_lockindex = 0; |
| 1421 | return s->cirrus_hidden_dac_data; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1422 | } |
Juan Quintela | 957c9db | 2009-08-31 16:07:22 +0200 | [diff] [blame] | 1423 | return 0xff; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | static void cirrus_write_hidden_dac(CirrusVGAState * s, int reg_value) |
| 1427 | { |
| 1428 | if (s->cirrus_hidden_dac_lockindex == 4) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1429 | s->cirrus_hidden_dac_data = reg_value; |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 1430 | #if defined(DEBUG_CIRRUS) |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1431 | printf("cirrus: outport hidden DAC, value %02x\n", reg_value); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1432 | #endif |
| 1433 | } |
| 1434 | s->cirrus_hidden_dac_lockindex = 0; |
| 1435 | } |
| 1436 | |
| 1437 | /*************************************** |
| 1438 | * |
| 1439 | * I/O access at 0x3c9 |
| 1440 | * |
| 1441 | ***************************************/ |
| 1442 | |
Juan Quintela | 5deaeee | 2009-08-31 16:07:27 +0200 | [diff] [blame] | 1443 | static int cirrus_vga_read_palette(CirrusVGAState * s) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1444 | { |
Juan Quintela | 5deaeee | 2009-08-31 16:07:27 +0200 | [diff] [blame] | 1445 | int val; |
| 1446 | |
| 1447 | if ((s->vga.sr[0x12] & CIRRUS_CURSOR_HIDDENPEL)) { |
| 1448 | val = s->cirrus_hidden_palette[(s->vga.dac_read_index & 0x0f) * 3 + |
| 1449 | s->vga.dac_sub_index]; |
| 1450 | } else { |
| 1451 | val = s->vga.palette[s->vga.dac_read_index * 3 + s->vga.dac_sub_index]; |
| 1452 | } |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1453 | if (++s->vga.dac_sub_index == 3) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1454 | s->vga.dac_sub_index = 0; |
| 1455 | s->vga.dac_read_index++; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1456 | } |
Juan Quintela | 5deaeee | 2009-08-31 16:07:27 +0200 | [diff] [blame] | 1457 | return val; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Juan Quintela | 86948bb | 2009-08-31 16:07:28 +0200 | [diff] [blame] | 1460 | static void cirrus_vga_write_palette(CirrusVGAState * s, int reg_value) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1461 | { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1462 | s->vga.dac_cache[s->vga.dac_sub_index] = reg_value; |
| 1463 | if (++s->vga.dac_sub_index == 3) { |
Juan Quintela | 86948bb | 2009-08-31 16:07:28 +0200 | [diff] [blame] | 1464 | if ((s->vga.sr[0x12] & CIRRUS_CURSOR_HIDDENPEL)) { |
| 1465 | memcpy(&s->cirrus_hidden_palette[(s->vga.dac_write_index & 0x0f) * 3], |
| 1466 | s->vga.dac_cache, 3); |
| 1467 | } else { |
| 1468 | memcpy(&s->vga.palette[s->vga.dac_write_index * 3], s->vga.dac_cache, 3); |
| 1469 | } |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 1470 | /* XXX update cursor */ |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1471 | s->vga.dac_sub_index = 0; |
| 1472 | s->vga.dac_write_index++; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1473 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | /*************************************** |
| 1477 | * |
| 1478 | * I/O access between 0x3ce-0x3cf |
| 1479 | * |
| 1480 | ***************************************/ |
| 1481 | |
Juan Quintela | f705db9 | 2009-08-31 16:07:29 +0200 | [diff] [blame] | 1482 | static int cirrus_vga_read_gr(CirrusVGAState * s, unsigned reg_index) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1483 | { |
| 1484 | switch (reg_index) { |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 1485 | case 0x00: // Standard VGA, BGCOLOR 0x000000ff |
Juan Quintela | f705db9 | 2009-08-31 16:07:29 +0200 | [diff] [blame] | 1486 | return s->cirrus_shadow_gr0; |
bellard | aeb3c85 | 2004-06-05 14:26:11 +0000 | [diff] [blame] | 1487 | case 0x01: // Standard VGA, FGCOLOR 0x000000ff |
Juan Quintela | f705db9 | 2009-08-31 16:07:29 +0200 | [diff] [blame] | 1488 | return s->cirrus_shadow_gr1; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1489 | case 0x02: // Standard VGA |
| 1490 | case 0x03: // Standard VGA |
| 1491 | case 0x04: // Standard VGA |
| 1492 | case 0x06: // Standard VGA |
| 1493 | case 0x07: // Standard VGA |
| 1494 | case 0x08: // Standard VGA |
Juan Quintela | f705db9 | 2009-08-31 16:07:29 +0200 | [diff] [blame] | 1495 | return s->vga.gr[s->vga.gr_index]; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1496 | case 0x05: // Standard VGA, Cirrus extended mode |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1497 | default: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1498 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | if (reg_index < 0x3a) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1502 | return s->vga.gr[reg_index]; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1503 | } else { |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1504 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1505 | "cirrus: inport gr_index 0x%02x\n", reg_index); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1506 | return 0xff; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1507 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Juan Quintela | 22286bc | 2009-08-31 16:07:30 +0200 | [diff] [blame] | 1510 | static void |
| 1511 | cirrus_vga_write_gr(CirrusVGAState * s, unsigned reg_index, int reg_value) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1512 | { |
Philippe Mathieu-Daudé | bee61ca | 2020-05-26 08:22:41 +0200 | [diff] [blame] | 1513 | trace_vga_cirrus_write_gr(reg_index, reg_value); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1514 | switch (reg_index) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1515 | case 0x00: // Standard VGA, BGCOLOR 0x000000ff |
| 1516 | s->vga.gr[reg_index] = reg_value & gr_mask[reg_index]; |
| 1517 | s->cirrus_shadow_gr0 = reg_value; |
Juan Quintela | 22286bc | 2009-08-31 16:07:30 +0200 | [diff] [blame] | 1518 | break; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1519 | case 0x01: // Standard VGA, FGCOLOR 0x000000ff |
| 1520 | s->vga.gr[reg_index] = reg_value & gr_mask[reg_index]; |
| 1521 | s->cirrus_shadow_gr1 = reg_value; |
| 1522 | break; |
| 1523 | case 0x02: // Standard VGA |
| 1524 | case 0x03: // Standard VGA |
| 1525 | case 0x04: // Standard VGA |
| 1526 | case 0x06: // Standard VGA |
| 1527 | case 0x07: // Standard VGA |
| 1528 | case 0x08: // Standard VGA |
| 1529 | s->vga.gr[reg_index] = reg_value & gr_mask[reg_index]; |
| 1530 | break; |
| 1531 | case 0x05: // Standard VGA, Cirrus extended mode |
| 1532 | s->vga.gr[reg_index] = reg_value & 0x7f; |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 1533 | cirrus_update_memory_access(s); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1534 | break; |
| 1535 | case 0x09: // bank offset #0 |
| 1536 | case 0x0A: // bank offset #1 |
| 1537 | s->vga.gr[reg_index] = reg_value; |
| 1538 | cirrus_update_bank_ptr(s, 0); |
| 1539 | cirrus_update_bank_ptr(s, 1); |
aliguori | 2bec46d | 2008-11-24 20:21:41 +0000 | [diff] [blame] | 1540 | cirrus_update_memory_access(s); |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 1541 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1542 | case 0x0B: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1543 | s->vga.gr[reg_index] = reg_value; |
| 1544 | cirrus_update_bank_ptr(s, 0); |
| 1545 | cirrus_update_bank_ptr(s, 1); |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 1546 | cirrus_update_memory_access(s); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1547 | break; |
| 1548 | case 0x10: // BGCOLOR 0x0000ff00 |
| 1549 | case 0x11: // FGCOLOR 0x0000ff00 |
| 1550 | case 0x12: // BGCOLOR 0x00ff0000 |
| 1551 | case 0x13: // FGCOLOR 0x00ff0000 |
| 1552 | case 0x14: // BGCOLOR 0xff000000 |
| 1553 | case 0x15: // FGCOLOR 0xff000000 |
| 1554 | case 0x20: // BLT WIDTH 0x0000ff |
| 1555 | case 0x22: // BLT HEIGHT 0x0000ff |
| 1556 | case 0x24: // BLT DEST PITCH 0x0000ff |
| 1557 | case 0x26: // BLT SRC PITCH 0x0000ff |
| 1558 | case 0x28: // BLT DEST ADDR 0x0000ff |
| 1559 | case 0x29: // BLT DEST ADDR 0x00ff00 |
| 1560 | case 0x2c: // BLT SRC ADDR 0x0000ff |
| 1561 | case 0x2d: // BLT SRC ADDR 0x00ff00 |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 1562 | case 0x2f: // BLT WRITEMASK |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1563 | case 0x30: // BLT MODE |
| 1564 | case 0x32: // RASTER OP |
| 1565 | case 0x33: // BLT MODEEXT |
| 1566 | case 0x34: // BLT TRANSPARENT COLOR 0x00ff |
| 1567 | case 0x35: // BLT TRANSPARENT COLOR 0xff00 |
| 1568 | case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff |
| 1569 | case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00 |
| 1570 | s->vga.gr[reg_index] = reg_value; |
| 1571 | break; |
| 1572 | case 0x21: // BLT WIDTH 0x001f00 |
| 1573 | case 0x23: // BLT HEIGHT 0x001f00 |
| 1574 | case 0x25: // BLT DEST PITCH 0x001f00 |
| 1575 | case 0x27: // BLT SRC PITCH 0x001f00 |
| 1576 | s->vga.gr[reg_index] = reg_value & 0x1f; |
| 1577 | break; |
| 1578 | case 0x2a: // BLT DEST ADDR 0x3f0000 |
| 1579 | s->vga.gr[reg_index] = reg_value & 0x3f; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 1580 | /* if auto start mode, starts bit blt now */ |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 1581 | if (s->vga.gr[0x31] & CIRRUS_BLT_AUTOSTART) { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 1582 | cirrus_bitblt_start(s); |
| 1583 | } |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1584 | break; |
| 1585 | case 0x2e: // BLT SRC ADDR 0x3f0000 |
| 1586 | s->vga.gr[reg_index] = reg_value & 0x3f; |
| 1587 | break; |
| 1588 | case 0x31: // BLT STATUS/START |
| 1589 | cirrus_write_bitblt(s, reg_value); |
| 1590 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1591 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1592 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1593 | "cirrus: outport gr_index 0x%02x, gr_value 0x%02x\n", |
| 1594 | reg_index, reg_value); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1595 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1596 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /*************************************** |
| 1600 | * |
| 1601 | * I/O access between 0x3d4-0x3d5 |
| 1602 | * |
| 1603 | ***************************************/ |
| 1604 | |
Juan Quintela | b863d51 | 2009-08-31 16:07:31 +0200 | [diff] [blame] | 1605 | static int cirrus_vga_read_cr(CirrusVGAState * s, unsigned reg_index) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1606 | { |
| 1607 | switch (reg_index) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1608 | case 0x00: // Standard VGA |
| 1609 | case 0x01: // Standard VGA |
| 1610 | case 0x02: // Standard VGA |
| 1611 | case 0x03: // Standard VGA |
| 1612 | case 0x04: // Standard VGA |
| 1613 | case 0x05: // Standard VGA |
| 1614 | case 0x06: // Standard VGA |
| 1615 | case 0x07: // Standard VGA |
| 1616 | case 0x08: // Standard VGA |
| 1617 | case 0x09: // Standard VGA |
| 1618 | case 0x0a: // Standard VGA |
| 1619 | case 0x0b: // Standard VGA |
| 1620 | case 0x0c: // Standard VGA |
| 1621 | case 0x0d: // Standard VGA |
| 1622 | case 0x0e: // Standard VGA |
| 1623 | case 0x0f: // Standard VGA |
| 1624 | case 0x10: // Standard VGA |
| 1625 | case 0x11: // Standard VGA |
| 1626 | case 0x12: // Standard VGA |
| 1627 | case 0x13: // Standard VGA |
| 1628 | case 0x14: // Standard VGA |
| 1629 | case 0x15: // Standard VGA |
| 1630 | case 0x16: // Standard VGA |
| 1631 | case 0x17: // Standard VGA |
| 1632 | case 0x18: // Standard VGA |
| 1633 | return s->vga.cr[s->vga.cr_index]; |
| 1634 | case 0x24: // Attribute Controller Toggle Readback (R) |
Juan Quintela | b863d51 | 2009-08-31 16:07:31 +0200 | [diff] [blame] | 1635 | return (s->vga.ar_flip_flop << 7); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1636 | case 0x19: // Interlace End |
| 1637 | case 0x1a: // Miscellaneous Control |
| 1638 | case 0x1b: // Extended Display Control |
| 1639 | case 0x1c: // Sync Adjust and Genlock |
| 1640 | case 0x1d: // Overlay Extended Control |
| 1641 | case 0x22: // Graphics Data Latches Readback (R) |
| 1642 | case 0x25: // Part Status |
| 1643 | case 0x27: // Part ID (R) |
| 1644 | return s->vga.cr[s->vga.cr_index]; |
| 1645 | case 0x26: // Attribute Controller Index Readback (R) |
| 1646 | return s->vga.ar_index & 0x3f; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1647 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1648 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1649 | "cirrus: inport cr_index 0x%02x\n", reg_index); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1650 | return 0xff; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1651 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
Juan Quintela | 4ec1ce0 | 2009-08-31 16:07:32 +0200 | [diff] [blame] | 1654 | static void cirrus_vga_write_cr(CirrusVGAState * s, int reg_value) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1655 | { |
Juan Quintela | 4ec1ce0 | 2009-08-31 16:07:32 +0200 | [diff] [blame] | 1656 | switch (s->vga.cr_index) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1657 | case 0x00: // Standard VGA |
| 1658 | case 0x01: // Standard VGA |
| 1659 | case 0x02: // Standard VGA |
| 1660 | case 0x03: // Standard VGA |
| 1661 | case 0x04: // Standard VGA |
| 1662 | case 0x05: // Standard VGA |
| 1663 | case 0x06: // Standard VGA |
| 1664 | case 0x07: // Standard VGA |
| 1665 | case 0x08: // Standard VGA |
| 1666 | case 0x09: // Standard VGA |
| 1667 | case 0x0a: // Standard VGA |
| 1668 | case 0x0b: // Standard VGA |
| 1669 | case 0x0c: // Standard VGA |
| 1670 | case 0x0d: // Standard VGA |
| 1671 | case 0x0e: // Standard VGA |
| 1672 | case 0x0f: // Standard VGA |
| 1673 | case 0x10: // Standard VGA |
| 1674 | case 0x11: // Standard VGA |
| 1675 | case 0x12: // Standard VGA |
| 1676 | case 0x13: // Standard VGA |
| 1677 | case 0x14: // Standard VGA |
| 1678 | case 0x15: // Standard VGA |
| 1679 | case 0x16: // Standard VGA |
| 1680 | case 0x17: // Standard VGA |
| 1681 | case 0x18: // Standard VGA |
| 1682 | /* handle CR0-7 protection */ |
| 1683 | if ((s->vga.cr[0x11] & 0x80) && s->vga.cr_index <= 7) { |
| 1684 | /* can always write bit 4 of CR7 */ |
| 1685 | if (s->vga.cr_index == 7) |
| 1686 | s->vga.cr[7] = (s->vga.cr[7] & ~0x10) | (reg_value & 0x10); |
| 1687 | return; |
| 1688 | } |
| 1689 | s->vga.cr[s->vga.cr_index] = reg_value; |
| 1690 | switch(s->vga.cr_index) { |
| 1691 | case 0x00: |
| 1692 | case 0x04: |
| 1693 | case 0x05: |
| 1694 | case 0x06: |
| 1695 | case 0x07: |
| 1696 | case 0x11: |
| 1697 | case 0x17: |
| 1698 | s->vga.update_retrace_info(&s->vga); |
| 1699 | break; |
| 1700 | } |
Juan Quintela | 4ec1ce0 | 2009-08-31 16:07:32 +0200 | [diff] [blame] | 1701 | break; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1702 | case 0x19: // Interlace End |
| 1703 | case 0x1a: // Miscellaneous Control |
| 1704 | case 0x1b: // Extended Display Control |
| 1705 | case 0x1c: // Sync Adjust and Genlock |
| 1706 | case 0x1d: // Overlay Extended Control |
| 1707 | s->vga.cr[s->vga.cr_index] = reg_value; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1708 | #ifdef DEBUG_CIRRUS |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1709 | printf("cirrus: handled outport cr_index %02x, cr_value %02x\n", |
| 1710 | s->vga.cr_index, reg_value); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1711 | #endif |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1712 | break; |
| 1713 | case 0x22: // Graphics Data Latches Readback (R) |
| 1714 | case 0x24: // Attribute Controller Toggle Readback (R) |
| 1715 | case 0x26: // Attribute Controller Index Readback (R) |
| 1716 | case 0x27: // Part ID (R) |
| 1717 | break; |
| 1718 | case 0x25: // Part Status |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1719 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1720 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1721 | "cirrus: outport cr_index 0x%02x, cr_value 0x%02x\n", |
| 1722 | s->vga.cr_index, reg_value); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1723 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1724 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | /*************************************** |
| 1728 | * |
| 1729 | * memory-mapped I/O (bitblt) |
| 1730 | * |
| 1731 | ***************************************/ |
| 1732 | |
| 1733 | static uint8_t cirrus_mmio_blt_read(CirrusVGAState * s, unsigned address) |
| 1734 | { |
| 1735 | int value = 0xff; |
| 1736 | |
| 1737 | switch (address) { |
| 1738 | case (CIRRUS_MMIO_BLTBGCOLOR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1739 | value = cirrus_vga_read_gr(s, 0x00); |
| 1740 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1741 | case (CIRRUS_MMIO_BLTBGCOLOR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1742 | value = cirrus_vga_read_gr(s, 0x10); |
| 1743 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1744 | case (CIRRUS_MMIO_BLTBGCOLOR + 2): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1745 | value = cirrus_vga_read_gr(s, 0x12); |
| 1746 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1747 | case (CIRRUS_MMIO_BLTBGCOLOR + 3): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1748 | value = cirrus_vga_read_gr(s, 0x14); |
| 1749 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1750 | case (CIRRUS_MMIO_BLTFGCOLOR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1751 | value = cirrus_vga_read_gr(s, 0x01); |
| 1752 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1753 | case (CIRRUS_MMIO_BLTFGCOLOR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1754 | value = cirrus_vga_read_gr(s, 0x11); |
| 1755 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1756 | case (CIRRUS_MMIO_BLTFGCOLOR + 2): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1757 | value = cirrus_vga_read_gr(s, 0x13); |
| 1758 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1759 | case (CIRRUS_MMIO_BLTFGCOLOR + 3): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1760 | value = cirrus_vga_read_gr(s, 0x15); |
| 1761 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1762 | case (CIRRUS_MMIO_BLTWIDTH + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1763 | value = cirrus_vga_read_gr(s, 0x20); |
| 1764 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1765 | case (CIRRUS_MMIO_BLTWIDTH + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1766 | value = cirrus_vga_read_gr(s, 0x21); |
| 1767 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1768 | case (CIRRUS_MMIO_BLTHEIGHT + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1769 | value = cirrus_vga_read_gr(s, 0x22); |
| 1770 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1771 | case (CIRRUS_MMIO_BLTHEIGHT + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1772 | value = cirrus_vga_read_gr(s, 0x23); |
| 1773 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1774 | case (CIRRUS_MMIO_BLTDESTPITCH + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1775 | value = cirrus_vga_read_gr(s, 0x24); |
| 1776 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1777 | case (CIRRUS_MMIO_BLTDESTPITCH + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1778 | value = cirrus_vga_read_gr(s, 0x25); |
| 1779 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1780 | case (CIRRUS_MMIO_BLTSRCPITCH + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1781 | value = cirrus_vga_read_gr(s, 0x26); |
| 1782 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1783 | case (CIRRUS_MMIO_BLTSRCPITCH + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1784 | value = cirrus_vga_read_gr(s, 0x27); |
| 1785 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1786 | case (CIRRUS_MMIO_BLTDESTADDR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1787 | value = cirrus_vga_read_gr(s, 0x28); |
| 1788 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1789 | case (CIRRUS_MMIO_BLTDESTADDR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1790 | value = cirrus_vga_read_gr(s, 0x29); |
| 1791 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1792 | case (CIRRUS_MMIO_BLTDESTADDR + 2): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1793 | value = cirrus_vga_read_gr(s, 0x2a); |
| 1794 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1795 | case (CIRRUS_MMIO_BLTSRCADDR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1796 | value = cirrus_vga_read_gr(s, 0x2c); |
| 1797 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1798 | case (CIRRUS_MMIO_BLTSRCADDR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1799 | value = cirrus_vga_read_gr(s, 0x2d); |
| 1800 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1801 | case (CIRRUS_MMIO_BLTSRCADDR + 2): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1802 | value = cirrus_vga_read_gr(s, 0x2e); |
| 1803 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1804 | case CIRRUS_MMIO_BLTWRITEMASK: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1805 | value = cirrus_vga_read_gr(s, 0x2f); |
| 1806 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1807 | case CIRRUS_MMIO_BLTMODE: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1808 | value = cirrus_vga_read_gr(s, 0x30); |
| 1809 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1810 | case CIRRUS_MMIO_BLTROP: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1811 | value = cirrus_vga_read_gr(s, 0x32); |
| 1812 | break; |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 1813 | case CIRRUS_MMIO_BLTMODEEXT: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1814 | value = cirrus_vga_read_gr(s, 0x33); |
| 1815 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1816 | case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1817 | value = cirrus_vga_read_gr(s, 0x34); |
| 1818 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1819 | case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1820 | value = cirrus_vga_read_gr(s, 0x35); |
| 1821 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1822 | case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1823 | value = cirrus_vga_read_gr(s, 0x38); |
| 1824 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1825 | case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1826 | value = cirrus_vga_read_gr(s, 0x39); |
| 1827 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1828 | case CIRRUS_MMIO_BLTSTATUS: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1829 | value = cirrus_vga_read_gr(s, 0x31); |
| 1830 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1831 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1832 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1833 | "cirrus: mmio read - address 0x%04x\n", address); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1834 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Gerd Hoffmann | ec87f20 | 2017-02-08 14:51:33 +0100 | [diff] [blame] | 1837 | trace_vga_cirrus_write_blt(address, value); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1838 | return (uint8_t) value; |
| 1839 | } |
| 1840 | |
| 1841 | static void cirrus_mmio_blt_write(CirrusVGAState * s, unsigned address, |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1842 | uint8_t value) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1843 | { |
Gerd Hoffmann | ec87f20 | 2017-02-08 14:51:33 +0100 | [diff] [blame] | 1844 | trace_vga_cirrus_write_blt(address, value); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1845 | switch (address) { |
| 1846 | case (CIRRUS_MMIO_BLTBGCOLOR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1847 | cirrus_vga_write_gr(s, 0x00, value); |
| 1848 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1849 | case (CIRRUS_MMIO_BLTBGCOLOR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1850 | cirrus_vga_write_gr(s, 0x10, value); |
| 1851 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1852 | case (CIRRUS_MMIO_BLTBGCOLOR + 2): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1853 | cirrus_vga_write_gr(s, 0x12, value); |
| 1854 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1855 | case (CIRRUS_MMIO_BLTBGCOLOR + 3): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1856 | cirrus_vga_write_gr(s, 0x14, value); |
| 1857 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1858 | case (CIRRUS_MMIO_BLTFGCOLOR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1859 | cirrus_vga_write_gr(s, 0x01, value); |
| 1860 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1861 | case (CIRRUS_MMIO_BLTFGCOLOR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1862 | cirrus_vga_write_gr(s, 0x11, value); |
| 1863 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1864 | case (CIRRUS_MMIO_BLTFGCOLOR + 2): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1865 | cirrus_vga_write_gr(s, 0x13, value); |
| 1866 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1867 | case (CIRRUS_MMIO_BLTFGCOLOR + 3): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1868 | cirrus_vga_write_gr(s, 0x15, value); |
| 1869 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1870 | case (CIRRUS_MMIO_BLTWIDTH + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1871 | cirrus_vga_write_gr(s, 0x20, value); |
| 1872 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1873 | case (CIRRUS_MMIO_BLTWIDTH + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1874 | cirrus_vga_write_gr(s, 0x21, value); |
| 1875 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1876 | case (CIRRUS_MMIO_BLTHEIGHT + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1877 | cirrus_vga_write_gr(s, 0x22, value); |
| 1878 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1879 | case (CIRRUS_MMIO_BLTHEIGHT + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1880 | cirrus_vga_write_gr(s, 0x23, value); |
| 1881 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1882 | case (CIRRUS_MMIO_BLTDESTPITCH + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1883 | cirrus_vga_write_gr(s, 0x24, value); |
| 1884 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1885 | case (CIRRUS_MMIO_BLTDESTPITCH + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1886 | cirrus_vga_write_gr(s, 0x25, value); |
| 1887 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1888 | case (CIRRUS_MMIO_BLTSRCPITCH + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1889 | cirrus_vga_write_gr(s, 0x26, value); |
| 1890 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1891 | case (CIRRUS_MMIO_BLTSRCPITCH + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1892 | cirrus_vga_write_gr(s, 0x27, value); |
| 1893 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1894 | case (CIRRUS_MMIO_BLTDESTADDR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1895 | cirrus_vga_write_gr(s, 0x28, value); |
| 1896 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1897 | case (CIRRUS_MMIO_BLTDESTADDR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1898 | cirrus_vga_write_gr(s, 0x29, value); |
| 1899 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1900 | case (CIRRUS_MMIO_BLTDESTADDR + 2): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1901 | cirrus_vga_write_gr(s, 0x2a, value); |
| 1902 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1903 | case (CIRRUS_MMIO_BLTDESTADDR + 3): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1904 | /* ignored */ |
| 1905 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1906 | case (CIRRUS_MMIO_BLTSRCADDR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1907 | cirrus_vga_write_gr(s, 0x2c, value); |
| 1908 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1909 | case (CIRRUS_MMIO_BLTSRCADDR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1910 | cirrus_vga_write_gr(s, 0x2d, value); |
| 1911 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1912 | case (CIRRUS_MMIO_BLTSRCADDR + 2): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1913 | cirrus_vga_write_gr(s, 0x2e, value); |
| 1914 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1915 | case CIRRUS_MMIO_BLTWRITEMASK: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1916 | cirrus_vga_write_gr(s, 0x2f, value); |
| 1917 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1918 | case CIRRUS_MMIO_BLTMODE: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1919 | cirrus_vga_write_gr(s, 0x30, value); |
| 1920 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1921 | case CIRRUS_MMIO_BLTROP: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1922 | cirrus_vga_write_gr(s, 0x32, value); |
| 1923 | break; |
bellard | a21ae81 | 2004-06-05 17:59:37 +0000 | [diff] [blame] | 1924 | case CIRRUS_MMIO_BLTMODEEXT: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1925 | cirrus_vga_write_gr(s, 0x33, value); |
| 1926 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1927 | case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1928 | cirrus_vga_write_gr(s, 0x34, value); |
| 1929 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1930 | case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1931 | cirrus_vga_write_gr(s, 0x35, value); |
| 1932 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1933 | case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK + 0): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1934 | cirrus_vga_write_gr(s, 0x38, value); |
| 1935 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1936 | case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK + 1): |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1937 | cirrus_vga_write_gr(s, 0x39, value); |
| 1938 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1939 | case CIRRUS_MMIO_BLTSTATUS: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1940 | cirrus_vga_write_gr(s, 0x31, value); |
| 1941 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1942 | default: |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 1943 | qemu_log_mask(LOG_GUEST_ERROR, |
| 1944 | "cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n", |
| 1945 | address, value); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1946 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1947 | } |
| 1948 | } |
| 1949 | |
| 1950 | /*************************************** |
| 1951 | * |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1952 | * write mode 4/5 |
| 1953 | * |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1954 | ***************************************/ |
| 1955 | |
| 1956 | static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState * s, |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1957 | unsigned mode, |
| 1958 | unsigned offset, |
| 1959 | uint32_t mem_value) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1960 | { |
| 1961 | int x; |
| 1962 | unsigned val = mem_value; |
| 1963 | uint8_t *dst; |
| 1964 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1965 | for (x = 0; x < 8; x++) { |
Gerd Hoffmann | eb38e1b | 2017-10-11 10:43:14 +0200 | [diff] [blame] | 1966 | dst = s->vga.vram_ptr + ((offset + x) & s->cirrus_addr_mask); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1967 | if (val & 0x80) { |
| 1968 | *dst = s->cirrus_shadow_gr1; |
| 1969 | } else if (mode == 5) { |
| 1970 | *dst = s->cirrus_shadow_gr0; |
| 1971 | } |
| 1972 | val <<= 1; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1973 | } |
Blue Swirl | fd4aa97 | 2011-10-16 16:04:59 +0000 | [diff] [blame] | 1974 | memory_region_set_dirty(&s->vga.vram, offset, 8); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState * s, |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1978 | unsigned mode, |
| 1979 | unsigned offset, |
| 1980 | uint32_t mem_value) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1981 | { |
| 1982 | int x; |
| 1983 | unsigned val = mem_value; |
| 1984 | uint8_t *dst; |
| 1985 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1986 | for (x = 0; x < 8; x++) { |
Gerd Hoffmann | eb38e1b | 2017-10-11 10:43:14 +0200 | [diff] [blame] | 1987 | dst = s->vga.vram_ptr + ((offset + 2 * x) & s->cirrus_addr_mask & ~1); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 1988 | if (val & 0x80) { |
| 1989 | *dst = s->cirrus_shadow_gr1; |
| 1990 | *(dst + 1) = s->vga.gr[0x11]; |
| 1991 | } else if (mode == 5) { |
| 1992 | *dst = s->cirrus_shadow_gr0; |
| 1993 | *(dst + 1) = s->vga.gr[0x10]; |
| 1994 | } |
| 1995 | val <<= 1; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1996 | } |
Blue Swirl | fd4aa97 | 2011-10-16 16:04:59 +0000 | [diff] [blame] | 1997 | memory_region_set_dirty(&s->vga.vram, offset, 16); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | /*************************************** |
| 2001 | * |
| 2002 | * memory access between 0xa0000-0xbffff |
| 2003 | * |
| 2004 | ***************************************/ |
| 2005 | |
Avi Kivity | a815b16 | 2011-08-08 16:09:00 +0300 | [diff] [blame] | 2006 | static uint64_t cirrus_vga_mem_read(void *opaque, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 2007 | hwaddr addr, |
Avi Kivity | a815b16 | 2011-08-08 16:09:00 +0300 | [diff] [blame] | 2008 | uint32_t size) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2009 | { |
| 2010 | CirrusVGAState *s = opaque; |
| 2011 | unsigned bank_index; |
| 2012 | unsigned bank_offset; |
| 2013 | uint32_t val; |
| 2014 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2015 | if ((s->vga.sr[0x07] & 0x01) == 0) { |
Avi Kivity | b2a5e76 | 2011-08-08 16:09:01 +0300 | [diff] [blame] | 2016 | return vga_mem_readb(&s->vga, addr); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | if (addr < 0x10000) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2020 | /* XXX handle bitblt */ |
| 2021 | /* video memory */ |
| 2022 | bank_index = addr >> 15; |
| 2023 | bank_offset = addr & 0x7fff; |
| 2024 | if (bank_offset < s->cirrus_bank_limit[bank_index]) { |
| 2025 | bank_offset += s->cirrus_bank_base[bank_index]; |
| 2026 | if ((s->vga.gr[0x0B] & 0x14) == 0x14) { |
| 2027 | bank_offset <<= 4; |
| 2028 | } else if (s->vga.gr[0x0B] & 0x02) { |
| 2029 | bank_offset <<= 3; |
| 2030 | } |
| 2031 | bank_offset &= s->cirrus_addr_mask; |
| 2032 | val = *(s->vga.vram_ptr + bank_offset); |
| 2033 | } else |
| 2034 | val = 0xff; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2035 | } else if (addr >= 0x18000 && addr < 0x18100) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2036 | /* memory-mapped I/O */ |
| 2037 | val = 0xff; |
| 2038 | if ((s->vga.sr[0x17] & 0x44) == 0x04) { |
| 2039 | val = cirrus_mmio_blt_read(s, addr & 0xff); |
| 2040 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2041 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2042 | val = 0xff; |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 2043 | qemu_log_mask(LOG_GUEST_ERROR, |
Philippe Mathieu-Daudé | 883f2c5 | 2023-01-10 22:29:47 +0100 | [diff] [blame] | 2044 | "cirrus: mem_readb 0x" HWADDR_FMT_plx "\n", addr); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2045 | } |
| 2046 | return val; |
| 2047 | } |
| 2048 | |
Avi Kivity | a815b16 | 2011-08-08 16:09:00 +0300 | [diff] [blame] | 2049 | static void cirrus_vga_mem_write(void *opaque, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 2050 | hwaddr addr, |
Avi Kivity | a815b16 | 2011-08-08 16:09:00 +0300 | [diff] [blame] | 2051 | uint64_t mem_value, |
| 2052 | uint32_t size) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2053 | { |
| 2054 | CirrusVGAState *s = opaque; |
| 2055 | unsigned bank_index; |
| 2056 | unsigned bank_offset; |
| 2057 | unsigned mode; |
| 2058 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2059 | if ((s->vga.sr[0x07] & 0x01) == 0) { |
Avi Kivity | b2a5e76 | 2011-08-08 16:09:01 +0300 | [diff] [blame] | 2060 | vga_mem_writeb(&s->vga, addr, mem_value); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2061 | return; |
| 2062 | } |
| 2063 | |
| 2064 | if (addr < 0x10000) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2065 | if (s->cirrus_srcptr != s->cirrus_srcptr_end) { |
| 2066 | /* bitblt */ |
| 2067 | *s->cirrus_srcptr++ = (uint8_t) mem_value; |
| 2068 | if (s->cirrus_srcptr >= s->cirrus_srcptr_end) { |
| 2069 | cirrus_bitblt_cputovideo_next(s); |
| 2070 | } |
| 2071 | } else { |
| 2072 | /* video memory */ |
| 2073 | bank_index = addr >> 15; |
| 2074 | bank_offset = addr & 0x7fff; |
| 2075 | if (bank_offset < s->cirrus_bank_limit[bank_index]) { |
| 2076 | bank_offset += s->cirrus_bank_base[bank_index]; |
| 2077 | if ((s->vga.gr[0x0B] & 0x14) == 0x14) { |
| 2078 | bank_offset <<= 4; |
| 2079 | } else if (s->vga.gr[0x0B] & 0x02) { |
| 2080 | bank_offset <<= 3; |
| 2081 | } |
| 2082 | bank_offset &= s->cirrus_addr_mask; |
| 2083 | mode = s->vga.gr[0x05] & 0x7; |
| 2084 | if (mode < 4 || mode > 5 || ((s->vga.gr[0x0B] & 0x4) == 0)) { |
| 2085 | *(s->vga.vram_ptr + bank_offset) = mem_value; |
Blue Swirl | fd4aa97 | 2011-10-16 16:04:59 +0000 | [diff] [blame] | 2086 | memory_region_set_dirty(&s->vga.vram, bank_offset, |
| 2087 | sizeof(mem_value)); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2088 | } else { |
| 2089 | if ((s->vga.gr[0x0B] & 0x14) != 0x14) { |
| 2090 | cirrus_mem_writeb_mode4and5_8bpp(s, mode, |
| 2091 | bank_offset, |
| 2092 | mem_value); |
| 2093 | } else { |
| 2094 | cirrus_mem_writeb_mode4and5_16bpp(s, mode, |
| 2095 | bank_offset, |
| 2096 | mem_value); |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2101 | } else if (addr >= 0x18000 && addr < 0x18100) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2102 | /* memory-mapped I/O */ |
| 2103 | if ((s->vga.sr[0x17] & 0x44) == 0x04) { |
| 2104 | cirrus_mmio_blt_write(s, addr & 0xff, mem_value); |
| 2105 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2106 | } else { |
Philippe Mathieu-Daudé | 2b55f4d | 2020-05-26 08:22:43 +0200 | [diff] [blame] | 2107 | qemu_log_mask(LOG_GUEST_ERROR, |
Philippe Mathieu-Daudé | 883f2c5 | 2023-01-10 22:29:47 +0100 | [diff] [blame] | 2108 | "cirrus: mem_writeb 0x" HWADDR_FMT_plx " " |
Philippe Mathieu-Daudé | e016a84 | 2020-11-03 12:25:56 +0100 | [diff] [blame] | 2109 | "value 0x%02" PRIx64 "\n", addr, mem_value); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2113 | static const MemoryRegionOps cirrus_vga_mem_ops = { |
| 2114 | .read = cirrus_vga_mem_read, |
| 2115 | .write = cirrus_vga_mem_write, |
| 2116 | .endianness = DEVICE_LITTLE_ENDIAN, |
Avi Kivity | a815b16 | 2011-08-08 16:09:00 +0300 | [diff] [blame] | 2117 | .impl = { |
| 2118 | .min_access_size = 1, |
| 2119 | .max_access_size = 1, |
| 2120 | }, |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2121 | }; |
| 2122 | |
| 2123 | /*************************************** |
| 2124 | * |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2125 | * hardware cursor |
| 2126 | * |
| 2127 | ***************************************/ |
| 2128 | |
| 2129 | static inline void invalidate_cursor1(CirrusVGAState *s) |
| 2130 | { |
| 2131 | if (s->last_hw_cursor_size) { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2132 | vga_invalidate_scanlines(&s->vga, |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2133 | s->last_hw_cursor_y + s->last_hw_cursor_y_start, |
| 2134 | s->last_hw_cursor_y + s->last_hw_cursor_y_end); |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | static inline void cirrus_cursor_compute_yrange(CirrusVGAState *s) |
| 2139 | { |
| 2140 | const uint8_t *src; |
| 2141 | uint32_t content; |
| 2142 | int y, y_min, y_max; |
| 2143 | |
Philippe Mathieu-Daudé | f0353b0 | 2018-06-25 09:42:06 -0300 | [diff] [blame] | 2144 | src = s->vga.vram_ptr + s->real_vram_size - 16 * KiB; |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2145 | if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) { |
| 2146 | src += (s->vga.sr[0x13] & 0x3c) * 256; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2147 | y_min = 64; |
| 2148 | y_max = -1; |
| 2149 | for(y = 0; y < 64; y++) { |
| 2150 | content = ((uint32_t *)src)[0] | |
| 2151 | ((uint32_t *)src)[1] | |
| 2152 | ((uint32_t *)src)[2] | |
| 2153 | ((uint32_t *)src)[3]; |
| 2154 | if (content) { |
| 2155 | if (y < y_min) |
| 2156 | y_min = y; |
| 2157 | if (y > y_max) |
| 2158 | y_max = y; |
| 2159 | } |
| 2160 | src += 16; |
| 2161 | } |
| 2162 | } else { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2163 | src += (s->vga.sr[0x13] & 0x3f) * 256; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2164 | y_min = 32; |
| 2165 | y_max = -1; |
| 2166 | for(y = 0; y < 32; y++) { |
| 2167 | content = ((uint32_t *)src)[0] | |
| 2168 | ((uint32_t *)(src + 128))[0]; |
| 2169 | if (content) { |
| 2170 | if (y < y_min) |
| 2171 | y_min = y; |
| 2172 | if (y > y_max) |
| 2173 | y_max = y; |
| 2174 | } |
| 2175 | src += 4; |
| 2176 | } |
| 2177 | } |
| 2178 | if (y_min > y_max) { |
| 2179 | s->last_hw_cursor_y_start = 0; |
| 2180 | s->last_hw_cursor_y_end = 0; |
| 2181 | } else { |
| 2182 | s->last_hw_cursor_y_start = y_min; |
| 2183 | s->last_hw_cursor_y_end = y_max + 1; |
| 2184 | } |
| 2185 | } |
| 2186 | |
| 2187 | /* NOTE: we do not currently handle the cursor bitmap change, so we |
| 2188 | update the cursor only if it moves. */ |
Juan Quintela | a4a2f59 | 2009-08-24 18:42:47 +0200 | [diff] [blame] | 2189 | static void cirrus_cursor_invalidate(VGACommonState *s1) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2190 | { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2191 | CirrusVGAState *s = container_of(s1, CirrusVGAState, vga); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2192 | int size; |
| 2193 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2194 | if (!(s->vga.sr[0x12] & CIRRUS_CURSOR_SHOW)) { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2195 | size = 0; |
| 2196 | } else { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2197 | if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2198 | size = 64; |
| 2199 | else |
| 2200 | size = 32; |
| 2201 | } |
| 2202 | /* invalidate last cursor and new cursor if any change */ |
| 2203 | if (s->last_hw_cursor_size != size || |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2204 | s->last_hw_cursor_x != s->vga.hw_cursor_x || |
| 2205 | s->last_hw_cursor_y != s->vga.hw_cursor_y) { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2206 | |
| 2207 | invalidate_cursor1(s); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2208 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2209 | s->last_hw_cursor_size = size; |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2210 | s->last_hw_cursor_x = s->vga.hw_cursor_x; |
| 2211 | s->last_hw_cursor_y = s->vga.hw_cursor_y; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2212 | /* compute the real cursor min and max y */ |
| 2213 | cirrus_cursor_compute_yrange(s); |
| 2214 | invalidate_cursor1(s); |
| 2215 | } |
| 2216 | } |
| 2217 | |
Benjamin Herrenschmidt | 70a041f | 2014-06-22 11:04:24 +1000 | [diff] [blame] | 2218 | static void vga_draw_cursor_line(uint8_t *d1, |
| 2219 | const uint8_t *src1, |
| 2220 | int poffset, int w, |
| 2221 | unsigned int color0, |
| 2222 | unsigned int color1, |
| 2223 | unsigned int color_xor) |
| 2224 | { |
| 2225 | const uint8_t *plane0, *plane1; |
| 2226 | int x, b0, b1; |
| 2227 | uint8_t *d; |
Blue Swirl | 94d7b48 | 2012-01-25 16:10:44 +0000 | [diff] [blame] | 2228 | |
Benjamin Herrenschmidt | 70a041f | 2014-06-22 11:04:24 +1000 | [diff] [blame] | 2229 | d = d1; |
| 2230 | plane0 = src1; |
| 2231 | plane1 = src1 + poffset; |
| 2232 | for (x = 0; x < w; x++) { |
| 2233 | b0 = (plane0[x >> 3] >> (7 - (x & 7))) & 1; |
| 2234 | b1 = (plane1[x >> 3] >> (7 - (x & 7))) & 1; |
| 2235 | switch (b0 | (b1 << 1)) { |
| 2236 | case 0: |
| 2237 | break; |
| 2238 | case 1: |
| 2239 | ((uint32_t *)d)[0] ^= color_xor; |
| 2240 | break; |
| 2241 | case 2: |
| 2242 | ((uint32_t *)d)[0] = color0; |
| 2243 | break; |
| 2244 | case 3: |
| 2245 | ((uint32_t *)d)[0] = color1; |
| 2246 | break; |
| 2247 | } |
| 2248 | d += 4; |
| 2249 | } |
| 2250 | } |
Blue Swirl | 94d7b48 | 2012-01-25 16:10:44 +0000 | [diff] [blame] | 2251 | |
Juan Quintela | a4a2f59 | 2009-08-24 18:42:47 +0200 | [diff] [blame] | 2252 | static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2253 | { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2254 | CirrusVGAState *s = container_of(s1, CirrusVGAState, vga); |
Benjamin Herrenschmidt | 70a041f | 2014-06-22 11:04:24 +1000 | [diff] [blame] | 2255 | int w, h, x1, x2, poffset; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2256 | unsigned int color0, color1; |
| 2257 | const uint8_t *palette, *src; |
| 2258 | uint32_t content; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2259 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2260 | if (!(s->vga.sr[0x12] & CIRRUS_CURSOR_SHOW)) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2261 | return; |
| 2262 | /* fast test to see if the cursor intersects with the scan line */ |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2263 | if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2264 | h = 64; |
| 2265 | } else { |
| 2266 | h = 32; |
| 2267 | } |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2268 | if (scr_y < s->vga.hw_cursor_y || |
| 2269 | scr_y >= (s->vga.hw_cursor_y + h)) { |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2270 | return; |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2271 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2272 | |
Philippe Mathieu-Daudé | f0353b0 | 2018-06-25 09:42:06 -0300 | [diff] [blame] | 2273 | src = s->vga.vram_ptr + s->real_vram_size - 16 * KiB; |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2274 | if (s->vga.sr[0x12] & CIRRUS_CURSOR_LARGE) { |
| 2275 | src += (s->vga.sr[0x13] & 0x3c) * 256; |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2276 | src += (scr_y - s->vga.hw_cursor_y) * 16; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2277 | poffset = 8; |
| 2278 | content = ((uint32_t *)src)[0] | |
| 2279 | ((uint32_t *)src)[1] | |
| 2280 | ((uint32_t *)src)[2] | |
| 2281 | ((uint32_t *)src)[3]; |
| 2282 | } else { |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2283 | src += (s->vga.sr[0x13] & 0x3f) * 256; |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2284 | src += (scr_y - s->vga.hw_cursor_y) * 4; |
Benjamin Herrenschmidt | d3c2343 | 2014-06-22 11:00:50 +1000 | [diff] [blame] | 2285 | |
| 2286 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2287 | poffset = 128; |
| 2288 | content = ((uint32_t *)src)[0] | |
| 2289 | ((uint32_t *)(src + 128))[0]; |
| 2290 | } |
| 2291 | /* if nothing to draw, no need to continue */ |
| 2292 | if (!content) |
| 2293 | return; |
| 2294 | w = h; |
| 2295 | |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2296 | x1 = s->vga.hw_cursor_x; |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2297 | if (x1 >= s->vga.last_scr_width) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2298 | return; |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2299 | x2 = s->vga.hw_cursor_x + w; |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2300 | if (x2 > s->vga.last_scr_width) |
| 2301 | x2 = s->vga.last_scr_width; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2302 | w = x2 - x1; |
| 2303 | palette = s->cirrus_hidden_palette; |
Benjamin Herrenschmidt | d3c2343 | 2014-06-22 11:00:50 +1000 | [diff] [blame] | 2304 | color0 = rgb_to_pixel32(c6_to_8(palette[0x0 * 3]), |
| 2305 | c6_to_8(palette[0x0 * 3 + 1]), |
| 2306 | c6_to_8(palette[0x0 * 3 + 2])); |
| 2307 | color1 = rgb_to_pixel32(c6_to_8(palette[0xf * 3]), |
| 2308 | c6_to_8(palette[0xf * 3 + 1]), |
| 2309 | c6_to_8(palette[0xf * 3 + 2])); |
Benjamin Herrenschmidt | 70a041f | 2014-06-22 11:04:24 +1000 | [diff] [blame] | 2310 | d1 += x1 * 4; |
| 2311 | vga_draw_cursor_line(d1, src, poffset, w, color0, color1, 0xffffff); |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | /*************************************** |
| 2315 | * |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2316 | * LFB memory access |
| 2317 | * |
| 2318 | ***************************************/ |
| 2319 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 2320 | static uint64_t cirrus_linear_read(void *opaque, hwaddr addr, |
Avi Kivity | 899adf8 | 2011-08-08 16:09:02 +0300 | [diff] [blame] | 2321 | unsigned size) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2322 | { |
Juan Quintela | e05587e | 2009-08-24 18:42:54 +0200 | [diff] [blame] | 2323 | CirrusVGAState *s = opaque; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2324 | uint32_t ret; |
| 2325 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2326 | addr &= s->cirrus_addr_mask; |
| 2327 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2328 | if (((s->vga.sr[0x17] & 0x44) == 0x44) && |
bellard | 78e127e | 2004-06-08 00:58:26 +0000 | [diff] [blame] | 2329 | ((addr & s->linear_mmio_mask) == s->linear_mmio_mask)) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2330 | /* memory-mapped I/O */ |
| 2331 | ret = cirrus_mmio_blt_read(s, addr & 0xff); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2332 | } else if (0) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2333 | /* XXX handle bitblt */ |
| 2334 | ret = 0xff; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2335 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2336 | /* video memory */ |
| 2337 | if ((s->vga.gr[0x0B] & 0x14) == 0x14) { |
| 2338 | addr <<= 4; |
| 2339 | } else if (s->vga.gr[0x0B] & 0x02) { |
| 2340 | addr <<= 3; |
| 2341 | } |
| 2342 | addr &= s->cirrus_addr_mask; |
| 2343 | ret = *(s->vga.vram_ptr + addr); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | return ret; |
| 2347 | } |
| 2348 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 2349 | static void cirrus_linear_write(void *opaque, hwaddr addr, |
Avi Kivity | 899adf8 | 2011-08-08 16:09:02 +0300 | [diff] [blame] | 2350 | uint64_t val, unsigned size) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2351 | { |
Juan Quintela | e05587e | 2009-08-24 18:42:54 +0200 | [diff] [blame] | 2352 | CirrusVGAState *s = opaque; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2353 | unsigned mode; |
| 2354 | |
| 2355 | addr &= s->cirrus_addr_mask; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2356 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2357 | if (((s->vga.sr[0x17] & 0x44) == 0x44) && |
bellard | 78e127e | 2004-06-08 00:58:26 +0000 | [diff] [blame] | 2358 | ((addr & s->linear_mmio_mask) == s->linear_mmio_mask)) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2359 | /* memory-mapped I/O */ |
| 2360 | cirrus_mmio_blt_write(s, addr & 0xff, val); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2361 | } else if (s->cirrus_srcptr != s->cirrus_srcptr_end) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2362 | /* bitblt */ |
| 2363 | *s->cirrus_srcptr++ = (uint8_t) val; |
| 2364 | if (s->cirrus_srcptr >= s->cirrus_srcptr_end) { |
| 2365 | cirrus_bitblt_cputovideo_next(s); |
| 2366 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2367 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2368 | /* video memory */ |
| 2369 | if ((s->vga.gr[0x0B] & 0x14) == 0x14) { |
| 2370 | addr <<= 4; |
| 2371 | } else if (s->vga.gr[0x0B] & 0x02) { |
| 2372 | addr <<= 3; |
| 2373 | } |
| 2374 | addr &= s->cirrus_addr_mask; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2375 | |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2376 | mode = s->vga.gr[0x05] & 0x7; |
| 2377 | if (mode < 4 || mode > 5 || ((s->vga.gr[0x0B] & 0x4) == 0)) { |
| 2378 | *(s->vga.vram_ptr + addr) = (uint8_t) val; |
Blue Swirl | fd4aa97 | 2011-10-16 16:04:59 +0000 | [diff] [blame] | 2379 | memory_region_set_dirty(&s->vga.vram, addr, 1); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2380 | } else { |
| 2381 | if ((s->vga.gr[0x0B] & 0x14) != 0x14) { |
| 2382 | cirrus_mem_writeb_mode4and5_8bpp(s, mode, addr, val); |
| 2383 | } else { |
| 2384 | cirrus_mem_writeb_mode4and5_16bpp(s, mode, addr, val); |
| 2385 | } |
| 2386 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2390 | /*************************************** |
| 2391 | * |
| 2392 | * system to screen memory access |
| 2393 | * |
| 2394 | ***************************************/ |
| 2395 | |
| 2396 | |
Avi Kivity | 4e56f08 | 2011-08-08 16:08:59 +0300 | [diff] [blame] | 2397 | static uint64_t cirrus_linear_bitblt_read(void *opaque, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 2398 | hwaddr addr, |
Avi Kivity | 4e56f08 | 2011-08-08 16:08:59 +0300 | [diff] [blame] | 2399 | unsigned size) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2400 | { |
Avi Kivity | 4e56f08 | 2011-08-08 16:08:59 +0300 | [diff] [blame] | 2401 | CirrusVGAState *s = opaque; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2402 | |
| 2403 | /* XXX handle bitblt */ |
Avi Kivity | 4e56f08 | 2011-08-08 16:08:59 +0300 | [diff] [blame] | 2404 | (void)s; |
Philippe Mathieu-Daudé | bb6e9e9 | 2020-05-26 08:22:42 +0200 | [diff] [blame] | 2405 | qemu_log_mask(LOG_UNIMP, |
| 2406 | "cirrus: linear bitblt is not implemented\n"); |
| 2407 | |
Simran Singhal | b3ac2b9 | 2020-04-01 22:23:14 +0530 | [diff] [blame] | 2408 | return 0xff; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2409 | } |
| 2410 | |
Avi Kivity | 4e56f08 | 2011-08-08 16:08:59 +0300 | [diff] [blame] | 2411 | static void cirrus_linear_bitblt_write(void *opaque, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 2412 | hwaddr addr, |
Avi Kivity | 4e56f08 | 2011-08-08 16:08:59 +0300 | [diff] [blame] | 2413 | uint64_t val, |
| 2414 | unsigned size) |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2415 | { |
Juan Quintela | e05587e | 2009-08-24 18:42:54 +0200 | [diff] [blame] | 2416 | CirrusVGAState *s = opaque; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2417 | |
| 2418 | if (s->cirrus_srcptr != s->cirrus_srcptr_end) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2419 | /* bitblt */ |
| 2420 | *s->cirrus_srcptr++ = (uint8_t) val; |
| 2421 | if (s->cirrus_srcptr >= s->cirrus_srcptr_end) { |
| 2422 | cirrus_bitblt_cputovideo_next(s); |
| 2423 | } |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2424 | } |
| 2425 | } |
| 2426 | |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2427 | static const MemoryRegionOps cirrus_linear_bitblt_io_ops = { |
| 2428 | .read = cirrus_linear_bitblt_read, |
| 2429 | .write = cirrus_linear_bitblt_write, |
| 2430 | .endianness = DEVICE_LITTLE_ENDIAN, |
Avi Kivity | 4e56f08 | 2011-08-08 16:08:59 +0300 | [diff] [blame] | 2431 | .impl = { |
| 2432 | .min_access_size = 1, |
| 2433 | .max_access_size = 1, |
| 2434 | }, |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2435 | }; |
| 2436 | |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2437 | static void map_linear_vram_bank(CirrusVGAState *s, unsigned bank) |
| 2438 | { |
Avi Kivity | 7969d9e | 2011-12-04 19:49:22 +0200 | [diff] [blame] | 2439 | MemoryRegion *mr = &s->cirrus_bank[bank]; |
| 2440 | bool enabled = !(s->cirrus_srcptr != s->cirrus_srcptr_end) |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2441 | && !((s->vga.sr[0x07] & 0x01) == 0) |
| 2442 | && !((s->vga.gr[0x0B] & 0x14) == 0x14) |
Avi Kivity | 7969d9e | 2011-12-04 19:49:22 +0200 | [diff] [blame] | 2443 | && !(s->vga.gr[0x0B] & 0x02); |
aliguori | 2bec46d | 2008-11-24 20:21:41 +0000 | [diff] [blame] | 2444 | |
Avi Kivity | 7969d9e | 2011-12-04 19:49:22 +0200 | [diff] [blame] | 2445 | memory_region_set_enabled(mr, enabled); |
| 2446 | memory_region_set_alias_offset(mr, s->cirrus_bank_base[bank]); |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2447 | } |
aliguori | 2bec46d | 2008-11-24 20:21:41 +0000 | [diff] [blame] | 2448 | |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2449 | static void map_linear_vram(CirrusVGAState *s) |
| 2450 | { |
Jan Kiszka | 4c08fd1 | 2011-09-21 20:49:32 +0200 | [diff] [blame] | 2451 | if (s->bustype == CIRRUS_BUSTYPE_PCI && !s->linear_vram) { |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2452 | s->linear_vram = true; |
| 2453 | memory_region_add_subregion_overlap(&s->pci_bar, 0, &s->vga.vram, 1); |
| 2454 | } |
| 2455 | map_linear_vram_bank(s, 0); |
| 2456 | map_linear_vram_bank(s, 1); |
aliguori | 2bec46d | 2008-11-24 20:21:41 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | static void unmap_linear_vram(CirrusVGAState *s) |
| 2460 | { |
Jan Kiszka | 4c08fd1 | 2011-09-21 20:49:32 +0200 | [diff] [blame] | 2461 | if (s->bustype == CIRRUS_BUSTYPE_PCI && s->linear_vram) { |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2462 | s->linear_vram = false; |
| 2463 | memory_region_del_subregion(&s->pci_bar, &s->vga.vram); |
Jan Kiszka | 4516e45 | 2010-01-29 15:12:48 +0100 | [diff] [blame] | 2464 | } |
Avi Kivity | 7969d9e | 2011-12-04 19:49:22 +0200 | [diff] [blame] | 2465 | memory_region_set_enabled(&s->cirrus_bank[0], false); |
| 2466 | memory_region_set_enabled(&s->cirrus_bank[1], false); |
aliguori | 2bec46d | 2008-11-24 20:21:41 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 2469 | /* Compute the memory access functions */ |
| 2470 | static void cirrus_update_memory_access(CirrusVGAState *s) |
| 2471 | { |
| 2472 | unsigned mode; |
| 2473 | |
Avi Kivity | 64c048f | 2011-08-01 11:03:42 +0300 | [diff] [blame] | 2474 | memory_region_transaction_begin(); |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2475 | if ((s->vga.sr[0x17] & 0x44) == 0x44) { |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 2476 | goto generic_io; |
| 2477 | } else if (s->cirrus_srcptr != s->cirrus_srcptr_end) { |
| 2478 | goto generic_io; |
| 2479 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2480 | if ((s->vga.gr[0x0B] & 0x14) == 0x14) { |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 2481 | goto generic_io; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2482 | } else if (s->vga.gr[0x0B] & 0x02) { |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 2483 | goto generic_io; |
| 2484 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2485 | |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2486 | mode = s->vga.gr[0x05] & 0x7; |
| 2487 | if (mode < 4 || mode > 5 || ((s->vga.gr[0x0B] & 0x4) == 0)) { |
aliguori | 2bec46d | 2008-11-24 20:21:41 +0000 | [diff] [blame] | 2488 | map_linear_vram(s); |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 2489 | } else { |
| 2490 | generic_io: |
aliguori | 2bec46d | 2008-11-24 20:21:41 +0000 | [diff] [blame] | 2491 | unmap_linear_vram(s); |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 2492 | } |
| 2493 | } |
Avi Kivity | 64c048f | 2011-08-01 11:03:42 +0300 | [diff] [blame] | 2494 | memory_region_transaction_commit(); |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2498 | /* I/O ports */ |
| 2499 | |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2500 | static uint64_t cirrus_vga_ioport_read(void *opaque, hwaddr addr, |
| 2501 | unsigned size) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2502 | { |
Juan Quintela | b634307 | 2009-08-31 16:07:20 +0200 | [diff] [blame] | 2503 | CirrusVGAState *c = opaque; |
| 2504 | VGACommonState *s = &c->vga; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2505 | int val, index; |
| 2506 | |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2507 | addr += 0x3b0; |
Jan Kiszka | bd8f2f5 | 2012-08-23 13:02:33 +0200 | [diff] [blame] | 2508 | |
Juan Quintela | b634307 | 2009-08-31 16:07:20 +0200 | [diff] [blame] | 2509 | if (vga_ioport_invalid(s, addr)) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2510 | val = 0xff; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2511 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2512 | switch (addr) { |
| 2513 | case 0x3c0: |
| 2514 | if (s->ar_flip_flop == 0) { |
| 2515 | val = s->ar_index; |
| 2516 | } else { |
| 2517 | val = 0; |
| 2518 | } |
Juan Quintela | 8a82c32 | 2009-08-31 16:07:25 +0200 | [diff] [blame] | 2519 | break; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2520 | case 0x3c1: |
| 2521 | index = s->ar_index & 0x1f; |
| 2522 | if (index < 21) |
| 2523 | val = s->ar[index]; |
| 2524 | else |
| 2525 | val = 0; |
| 2526 | break; |
| 2527 | case 0x3c2: |
| 2528 | val = s->st00; |
| 2529 | break; |
| 2530 | case 0x3c4: |
| 2531 | val = s->sr_index; |
| 2532 | break; |
| 2533 | case 0x3c5: |
| 2534 | val = cirrus_vga_read_sr(c); |
| 2535 | break; |
| 2536 | break; |
| 2537 | case 0x3c6: |
| 2538 | val = cirrus_read_hidden_dac(c); |
| 2539 | break; |
| 2540 | case 0x3c7: |
| 2541 | val = s->dac_state; |
| 2542 | break; |
| 2543 | case 0x3c8: |
| 2544 | val = s->dac_write_index; |
| 2545 | c->cirrus_hidden_dac_lockindex = 0; |
| 2546 | break; |
bellard | ae184e4 | 2004-06-26 16:13:19 +0000 | [diff] [blame] | 2547 | case 0x3c9: |
Juan Quintela | 5deaeee | 2009-08-31 16:07:27 +0200 | [diff] [blame] | 2548 | val = cirrus_vga_read_palette(c); |
| 2549 | break; |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2550 | case 0x3ca: |
| 2551 | val = s->fcr; |
| 2552 | break; |
| 2553 | case 0x3cc: |
| 2554 | val = s->msr; |
| 2555 | break; |
| 2556 | case 0x3ce: |
| 2557 | val = s->gr_index; |
| 2558 | break; |
| 2559 | case 0x3cf: |
| 2560 | val = cirrus_vga_read_gr(c, s->gr_index); |
| 2561 | break; |
| 2562 | case 0x3b4: |
| 2563 | case 0x3d4: |
| 2564 | val = s->cr_index; |
| 2565 | break; |
| 2566 | case 0x3b5: |
| 2567 | case 0x3d5: |
Juan Quintela | b863d51 | 2009-08-31 16:07:31 +0200 | [diff] [blame] | 2568 | val = cirrus_vga_read_cr(c, s->cr_index); |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2569 | break; |
| 2570 | case 0x3ba: |
| 2571 | case 0x3da: |
| 2572 | /* just toggle to fool polling */ |
| 2573 | val = s->st01 = s->retrace(s); |
| 2574 | s->ar_flip_flop = 0; |
| 2575 | break; |
| 2576 | default: |
| 2577 | val = 0x00; |
| 2578 | break; |
| 2579 | } |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2580 | } |
Gerd Hoffmann | ec87f20 | 2017-02-08 14:51:33 +0100 | [diff] [blame] | 2581 | trace_vga_cirrus_read_io(addr, val); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2582 | return val; |
| 2583 | } |
| 2584 | |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2585 | static void cirrus_vga_ioport_write(void *opaque, hwaddr addr, uint64_t val, |
| 2586 | unsigned size) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2587 | { |
Juan Quintela | b634307 | 2009-08-31 16:07:20 +0200 | [diff] [blame] | 2588 | CirrusVGAState *c = opaque; |
| 2589 | VGACommonState *s = &c->vga; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2590 | int index; |
| 2591 | |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2592 | addr += 0x3b0; |
Jan Kiszka | bd8f2f5 | 2012-08-23 13:02:33 +0200 | [diff] [blame] | 2593 | |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2594 | /* check port range access depending on color/monochrome mode */ |
Juan Quintela | b634307 | 2009-08-31 16:07:20 +0200 | [diff] [blame] | 2595 | if (vga_ioport_invalid(s, addr)) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2596 | return; |
Juan Quintela | 25a18cb | 2009-08-31 16:07:19 +0200 | [diff] [blame] | 2597 | } |
Gerd Hoffmann | ec87f20 | 2017-02-08 14:51:33 +0100 | [diff] [blame] | 2598 | trace_vga_cirrus_write_io(addr, val); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2599 | |
| 2600 | switch (addr) { |
| 2601 | case 0x3c0: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2602 | if (s->ar_flip_flop == 0) { |
| 2603 | val &= 0x3f; |
| 2604 | s->ar_index = val; |
| 2605 | } else { |
| 2606 | index = s->ar_index & 0x1f; |
| 2607 | switch (index) { |
| 2608 | case 0x00 ... 0x0f: |
| 2609 | s->ar[index] = val & 0x3f; |
| 2610 | break; |
| 2611 | case 0x10: |
| 2612 | s->ar[index] = val & ~0x10; |
| 2613 | break; |
| 2614 | case 0x11: |
| 2615 | s->ar[index] = val; |
| 2616 | break; |
| 2617 | case 0x12: |
| 2618 | s->ar[index] = val & ~0xc0; |
| 2619 | break; |
| 2620 | case 0x13: |
| 2621 | s->ar[index] = val & ~0xf0; |
| 2622 | break; |
| 2623 | case 0x14: |
| 2624 | s->ar[index] = val & ~0xf0; |
| 2625 | break; |
| 2626 | default: |
| 2627 | break; |
| 2628 | } |
| 2629 | } |
| 2630 | s->ar_flip_flop ^= 1; |
| 2631 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2632 | case 0x3c2: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2633 | s->msr = val & ~0x10; |
| 2634 | s->update_retrace_info(s); |
| 2635 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2636 | case 0x3c4: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2637 | s->sr_index = val; |
| 2638 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2639 | case 0x3c5: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2640 | cirrus_vga_write_sr(c, val); |
Juan Quintela | 31c6320 | 2009-08-31 16:07:26 +0200 | [diff] [blame] | 2641 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2642 | case 0x3c6: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2643 | cirrus_write_hidden_dac(c, val); |
| 2644 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2645 | case 0x3c7: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2646 | s->dac_read_index = val; |
| 2647 | s->dac_sub_index = 0; |
| 2648 | s->dac_state = 3; |
| 2649 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2650 | case 0x3c8: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2651 | s->dac_write_index = val; |
| 2652 | s->dac_sub_index = 0; |
| 2653 | s->dac_state = 0; |
| 2654 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2655 | case 0x3c9: |
Juan Quintela | 86948bb | 2009-08-31 16:07:28 +0200 | [diff] [blame] | 2656 | cirrus_vga_write_palette(c, val); |
| 2657 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2658 | case 0x3ce: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2659 | s->gr_index = val; |
| 2660 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2661 | case 0x3cf: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2662 | cirrus_vga_write_gr(c, s->gr_index, val); |
| 2663 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2664 | case 0x3b4: |
| 2665 | case 0x3d4: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2666 | s->cr_index = val; |
| 2667 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2668 | case 0x3b5: |
| 2669 | case 0x3d5: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2670 | cirrus_vga_write_cr(c, val); |
| 2671 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2672 | case 0x3ba: |
| 2673 | case 0x3da: |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2674 | s->fcr = val & 0x10; |
| 2675 | break; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | /*************************************** |
| 2680 | * |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2681 | * memory-mapped I/O access |
| 2682 | * |
| 2683 | ***************************************/ |
| 2684 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 2685 | static uint64_t cirrus_mmio_read(void *opaque, hwaddr addr, |
Avi Kivity | 1e04d4d | 2011-08-08 16:08:58 +0300 | [diff] [blame] | 2686 | unsigned size) |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2687 | { |
Juan Quintela | e05587e | 2009-08-24 18:42:54 +0200 | [diff] [blame] | 2688 | CirrusVGAState *s = opaque; |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2689 | |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2690 | if (addr >= 0x100) { |
| 2691 | return cirrus_mmio_blt_read(s, addr - 0x100); |
| 2692 | } else { |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2693 | return cirrus_vga_ioport_read(s, addr + 0x10, size); |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2694 | } |
| 2695 | } |
| 2696 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 2697 | static void cirrus_mmio_write(void *opaque, hwaddr addr, |
Avi Kivity | 1e04d4d | 2011-08-08 16:08:58 +0300 | [diff] [blame] | 2698 | uint64_t val, unsigned size) |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2699 | { |
Juan Quintela | e05587e | 2009-08-24 18:42:54 +0200 | [diff] [blame] | 2700 | CirrusVGAState *s = opaque; |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2701 | |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2702 | if (addr >= 0x100) { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2703 | cirrus_mmio_blt_write(s, addr - 0x100, val); |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2704 | } else { |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2705 | cirrus_vga_ioport_write(s, addr + 0x10, val, size); |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2709 | static const MemoryRegionOps cirrus_mmio_io_ops = { |
| 2710 | .read = cirrus_mmio_read, |
| 2711 | .write = cirrus_mmio_write, |
| 2712 | .endianness = DEVICE_LITTLE_ENDIAN, |
Avi Kivity | 1e04d4d | 2011-08-08 16:08:58 +0300 | [diff] [blame] | 2713 | .impl = { |
| 2714 | .min_access_size = 1, |
| 2715 | .max_access_size = 1, |
| 2716 | }, |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2717 | }; |
| 2718 | |
bellard | 2c6ab83 | 2004-07-10 13:41:46 +0000 | [diff] [blame] | 2719 | /* load/save state */ |
| 2720 | |
Juan Quintela | e59fb37 | 2009-09-29 22:48:21 +0200 | [diff] [blame] | 2721 | static int cirrus_post_load(void *opaque, int version_id) |
bellard | 2c6ab83 | 2004-07-10 13:41:46 +0000 | [diff] [blame] | 2722 | { |
| 2723 | CirrusVGAState *s = opaque; |
| 2724 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2725 | s->vga.gr[0x00] = s->cirrus_shadow_gr0 & 0x0f; |
| 2726 | s->vga.gr[0x01] = s->cirrus_shadow_gr1 & 0x0f; |
bellard | 2c6ab83 | 2004-07-10 13:41:46 +0000 | [diff] [blame] | 2727 | |
Wang Xin | b7ee9e4 | 2018-11-23 14:46:46 +0800 | [diff] [blame] | 2728 | cirrus_update_bank_ptr(s, 0); |
| 2729 | cirrus_update_bank_ptr(s, 1); |
aliguori | 2bec46d | 2008-11-24 20:21:41 +0000 | [diff] [blame] | 2730 | cirrus_update_memory_access(s); |
bellard | 2c6ab83 | 2004-07-10 13:41:46 +0000 | [diff] [blame] | 2731 | /* force refresh */ |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2732 | s->vga.graphic_mode = -1; |
Wang Xin | b7ee9e4 | 2018-11-23 14:46:46 +0800 | [diff] [blame] | 2733 | |
bellard | 2c6ab83 | 2004-07-10 13:41:46 +0000 | [diff] [blame] | 2734 | return 0; |
| 2735 | } |
| 2736 | |
Thomas Huth | ce3cf70 | 2018-10-12 12:11:46 +0200 | [diff] [blame] | 2737 | const VMStateDescription vmstate_cirrus_vga = { |
Juan Quintela | 7e72abc | 2009-09-10 03:04:47 +0200 | [diff] [blame] | 2738 | .name = "cirrus_vga", |
| 2739 | .version_id = 2, |
| 2740 | .minimum_version_id = 1, |
Juan Quintela | 7e72abc | 2009-09-10 03:04:47 +0200 | [diff] [blame] | 2741 | .post_load = cirrus_post_load, |
Richard Henderson | f061316 | 2023-12-21 14:16:07 +1100 | [diff] [blame] | 2742 | .fields = (const VMStateField[]) { |
Juan Quintela | 7e72abc | 2009-09-10 03:04:47 +0200 | [diff] [blame] | 2743 | VMSTATE_UINT32(vga.latch, CirrusVGAState), |
| 2744 | VMSTATE_UINT8(vga.sr_index, CirrusVGAState), |
| 2745 | VMSTATE_BUFFER(vga.sr, CirrusVGAState), |
| 2746 | VMSTATE_UINT8(vga.gr_index, CirrusVGAState), |
| 2747 | VMSTATE_UINT8(cirrus_shadow_gr0, CirrusVGAState), |
| 2748 | VMSTATE_UINT8(cirrus_shadow_gr1, CirrusVGAState), |
| 2749 | VMSTATE_BUFFER_START_MIDDLE(vga.gr, CirrusVGAState, 2), |
| 2750 | VMSTATE_UINT8(vga.ar_index, CirrusVGAState), |
| 2751 | VMSTATE_BUFFER(vga.ar, CirrusVGAState), |
| 2752 | VMSTATE_INT32(vga.ar_flip_flop, CirrusVGAState), |
| 2753 | VMSTATE_UINT8(vga.cr_index, CirrusVGAState), |
| 2754 | VMSTATE_BUFFER(vga.cr, CirrusVGAState), |
| 2755 | VMSTATE_UINT8(vga.msr, CirrusVGAState), |
| 2756 | VMSTATE_UINT8(vga.fcr, CirrusVGAState), |
| 2757 | VMSTATE_UINT8(vga.st00, CirrusVGAState), |
| 2758 | VMSTATE_UINT8(vga.st01, CirrusVGAState), |
| 2759 | VMSTATE_UINT8(vga.dac_state, CirrusVGAState), |
| 2760 | VMSTATE_UINT8(vga.dac_sub_index, CirrusVGAState), |
| 2761 | VMSTATE_UINT8(vga.dac_read_index, CirrusVGAState), |
| 2762 | VMSTATE_UINT8(vga.dac_write_index, CirrusVGAState), |
| 2763 | VMSTATE_BUFFER(vga.dac_cache, CirrusVGAState), |
| 2764 | VMSTATE_BUFFER(vga.palette, CirrusVGAState), |
| 2765 | VMSTATE_INT32(vga.bank_offset, CirrusVGAState), |
| 2766 | VMSTATE_UINT8(cirrus_hidden_dac_lockindex, CirrusVGAState), |
| 2767 | VMSTATE_UINT8(cirrus_hidden_dac_data, CirrusVGAState), |
Gerd Hoffmann | 22382bb | 2014-10-16 10:22:23 +0200 | [diff] [blame] | 2768 | VMSTATE_UINT32(vga.hw_cursor_x, CirrusVGAState), |
| 2769 | VMSTATE_UINT32(vga.hw_cursor_y, CirrusVGAState), |
Juan Quintela | 7e72abc | 2009-09-10 03:04:47 +0200 | [diff] [blame] | 2770 | /* XXX: we do not save the bitblt state - we assume we do not save |
| 2771 | the state when the blitter is active */ |
| 2772 | VMSTATE_END_OF_LIST() |
Juan Quintela | 4f335fe | 2009-08-24 18:42:56 +0200 | [diff] [blame] | 2773 | } |
Juan Quintela | 7e72abc | 2009-09-10 03:04:47 +0200 | [diff] [blame] | 2774 | }; |
Juan Quintela | 4f335fe | 2009-08-24 18:42:56 +0200 | [diff] [blame] | 2775 | |
Juan Quintela | 7e72abc | 2009-09-10 03:04:47 +0200 | [diff] [blame] | 2776 | static const VMStateDescription vmstate_pci_cirrus_vga = { |
| 2777 | .name = "cirrus_vga", |
| 2778 | .version_id = 2, |
| 2779 | .minimum_version_id = 2, |
Richard Henderson | f061316 | 2023-12-21 14:16:07 +1100 | [diff] [blame] | 2780 | .fields = (const VMStateField[]) { |
Juan Quintela | 7e72abc | 2009-09-10 03:04:47 +0200 | [diff] [blame] | 2781 | VMSTATE_PCI_DEVICE(dev, PCICirrusVGAState), |
| 2782 | VMSTATE_STRUCT(cirrus_vga, PCICirrusVGAState, 0, |
| 2783 | vmstate_cirrus_vga, CirrusVGAState), |
| 2784 | VMSTATE_END_OF_LIST() |
| 2785 | } |
| 2786 | }; |
Juan Quintela | 4f335fe | 2009-08-24 18:42:56 +0200 | [diff] [blame] | 2787 | |
bellard | e36f36e | 2004-06-05 12:47:01 +0000 | [diff] [blame] | 2788 | /*************************************** |
| 2789 | * |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2790 | * initialize |
| 2791 | * |
| 2792 | ***************************************/ |
| 2793 | |
blueswir1 | 4abc796 | 2009-01-05 17:37:06 +0000 | [diff] [blame] | 2794 | static void cirrus_reset(void *opaque) |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2795 | { |
blueswir1 | 4abc796 | 2009-01-05 17:37:06 +0000 | [diff] [blame] | 2796 | CirrusVGAState *s = opaque; |
bellard | a508231 | 2004-06-06 15:16:19 +0000 | [diff] [blame] | 2797 | |
Juan Quintela | 03a3e7b | 2009-08-24 18:42:45 +0200 | [diff] [blame] | 2798 | vga_common_reset(&s->vga); |
aliguori | ee50c6b | 2009-01-21 18:31:05 +0000 | [diff] [blame] | 2799 | unmap_linear_vram(s); |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2800 | s->vga.sr[0x06] = 0x0f; |
blueswir1 | 4abc796 | 2009-01-05 17:37:06 +0000 | [diff] [blame] | 2801 | if (s->device_id == CIRRUS_ID_CLGD5446) { |
bellard | 78e127e | 2004-06-08 00:58:26 +0000 | [diff] [blame] | 2802 | /* 4MB 64 bit memory config, always PCI */ |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2803 | s->vga.sr[0x1F] = 0x2d; // MemClock |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2804 | s->vga.gr[0x18] = 0x0f; // fastest memory configuration |
| 2805 | s->vga.sr[0x0f] = 0x98; |
| 2806 | s->vga.sr[0x17] = 0x20; |
| 2807 | s->vga.sr[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */ |
bellard | 78e127e | 2004-06-08 00:58:26 +0000 | [diff] [blame] | 2808 | } else { |
Amarjargal Gundjalam | a076a3d | 2022-10-25 22:28:10 +0800 | [diff] [blame] | 2809 | s->vga.sr[0x1F] = 0x22; // MemClock |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2810 | s->vga.sr[0x0F] = CIRRUS_MEMSIZE_2M; |
| 2811 | s->vga.sr[0x17] = s->bustype; |
| 2812 | s->vga.sr[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */ |
bellard | 78e127e | 2004-06-08 00:58:26 +0000 | [diff] [blame] | 2813 | } |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2814 | s->vga.cr[0x27] = s->device_id; |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2815 | |
| 2816 | s->cirrus_hidden_dac_lockindex = 5; |
| 2817 | s->cirrus_hidden_dac_data = 0; |
blueswir1 | 4abc796 | 2009-01-05 17:37:06 +0000 | [diff] [blame] | 2818 | } |
bellard | 2c6ab83 | 2004-07-10 13:41:46 +0000 | [diff] [blame] | 2819 | |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2820 | static const MemoryRegionOps cirrus_linear_io_ops = { |
| 2821 | .read = cirrus_linear_read, |
| 2822 | .write = cirrus_linear_write, |
| 2823 | .endianness = DEVICE_LITTLE_ENDIAN, |
Avi Kivity | 899adf8 | 2011-08-08 16:09:02 +0300 | [diff] [blame] | 2824 | .impl = { |
| 2825 | .min_access_size = 1, |
| 2826 | .max_access_size = 1, |
| 2827 | }, |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2828 | }; |
| 2829 | |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2830 | static const MemoryRegionOps cirrus_vga_io_ops = { |
| 2831 | .read = cirrus_vga_ioport_read, |
| 2832 | .write = cirrus_vga_ioport_write, |
| 2833 | .endianness = DEVICE_LITTLE_ENDIAN, |
| 2834 | .impl = { |
| 2835 | .min_access_size = 1, |
| 2836 | .max_access_size = 1, |
| 2837 | }, |
| 2838 | }; |
| 2839 | |
Thomas Huth | ce3cf70 | 2018-10-12 12:11:46 +0200 | [diff] [blame] | 2840 | void cirrus_init_common(CirrusVGAState *s, Object *owner, |
| 2841 | int device_id, int is_pci, |
| 2842 | MemoryRegion *system_memory, MemoryRegion *system_io) |
blueswir1 | 4abc796 | 2009-01-05 17:37:06 +0000 | [diff] [blame] | 2843 | { |
| 2844 | int i; |
| 2845 | static int inited; |
| 2846 | |
| 2847 | if (!inited) { |
| 2848 | inited = 1; |
| 2849 | for(i = 0;i < 256; i++) |
| 2850 | rop_to_index[i] = CIRRUS_ROP_NOP_INDEX; /* nop rop */ |
| 2851 | rop_to_index[CIRRUS_ROP_0] = 0; |
| 2852 | rop_to_index[CIRRUS_ROP_SRC_AND_DST] = 1; |
| 2853 | rop_to_index[CIRRUS_ROP_NOP] = 2; |
| 2854 | rop_to_index[CIRRUS_ROP_SRC_AND_NOTDST] = 3; |
| 2855 | rop_to_index[CIRRUS_ROP_NOTDST] = 4; |
| 2856 | rop_to_index[CIRRUS_ROP_SRC] = 5; |
| 2857 | rop_to_index[CIRRUS_ROP_1] = 6; |
| 2858 | rop_to_index[CIRRUS_ROP_NOTSRC_AND_DST] = 7; |
| 2859 | rop_to_index[CIRRUS_ROP_SRC_XOR_DST] = 8; |
| 2860 | rop_to_index[CIRRUS_ROP_SRC_OR_DST] = 9; |
| 2861 | rop_to_index[CIRRUS_ROP_NOTSRC_OR_NOTDST] = 10; |
| 2862 | rop_to_index[CIRRUS_ROP_SRC_NOTXOR_DST] = 11; |
| 2863 | rop_to_index[CIRRUS_ROP_SRC_OR_NOTDST] = 12; |
| 2864 | rop_to_index[CIRRUS_ROP_NOTSRC] = 13; |
| 2865 | rop_to_index[CIRRUS_ROP_NOTSRC_OR_DST] = 14; |
| 2866 | rop_to_index[CIRRUS_ROP_NOTSRC_AND_NOTDST] = 15; |
| 2867 | s->device_id = device_id; |
| 2868 | if (is_pci) |
| 2869 | s->bustype = CIRRUS_BUSTYPE_PCI; |
| 2870 | else |
| 2871 | s->bustype = CIRRUS_BUSTYPE_ISA; |
| 2872 | } |
| 2873 | |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2874 | /* Register ioport 0x3b0 - 0x3df */ |
Paolo Bonzini | 9eb58a4 | 2013-06-06 21:21:13 -0400 | [diff] [blame] | 2875 | memory_region_init_io(&s->cirrus_vga_io, owner, &cirrus_vga_io_ops, s, |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2876 | "cirrus-io", 0x30); |
Jan Kiszka | eb25a1d | 2013-07-02 21:19:02 +0200 | [diff] [blame] | 2877 | memory_region_set_flush_coalesced(&s->cirrus_vga_io); |
Julien Grall | c75e6d8 | 2012-09-19 12:50:06 +0100 | [diff] [blame] | 2878 | memory_region_add_subregion(system_io, 0x3b0, &s->cirrus_vga_io); |
blueswir1 | 4abc796 | 2009-01-05 17:37:06 +0000 | [diff] [blame] | 2879 | |
Paolo Bonzini | 9eb58a4 | 2013-06-06 21:21:13 -0400 | [diff] [blame] | 2880 | memory_region_init(&s->low_mem_container, owner, |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2881 | "cirrus-lowmem-container", |
| 2882 | 0x20000); |
| 2883 | |
Paolo Bonzini | 9eb58a4 | 2013-06-06 21:21:13 -0400 | [diff] [blame] | 2884 | memory_region_init_io(&s->low_mem, owner, &cirrus_vga_mem_ops, s, |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2885 | "cirrus-low-memory", 0x20000); |
| 2886 | memory_region_add_subregion(&s->low_mem_container, 0, &s->low_mem); |
Avi Kivity | 7969d9e | 2011-12-04 19:49:22 +0200 | [diff] [blame] | 2887 | for (i = 0; i < 2; ++i) { |
| 2888 | static const char *names[] = { "vga.bank0", "vga.bank1" }; |
| 2889 | MemoryRegion *bank = &s->cirrus_bank[i]; |
Paolo Bonzini | 9eb58a4 | 2013-06-06 21:21:13 -0400 | [diff] [blame] | 2890 | memory_region_init_alias(bank, owner, names[i], &s->vga.vram, |
| 2891 | 0, 0x8000); |
Avi Kivity | 7969d9e | 2011-12-04 19:49:22 +0200 | [diff] [blame] | 2892 | memory_region_set_enabled(bank, false); |
| 2893 | memory_region_add_subregion_overlap(&s->low_mem_container, i * 0x8000, |
| 2894 | bank, 1); |
| 2895 | } |
Avi Kivity | be20f9e | 2011-08-15 17:17:37 +0300 | [diff] [blame] | 2896 | memory_region_add_subregion_overlap(system_memory, |
Hervé Poussineau | b19c1c0 | 2015-02-01 09:12:56 +0100 | [diff] [blame] | 2897 | 0x000a0000, |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2898 | &s->low_mem_container, |
| 2899 | 1); |
| 2900 | memory_region_set_coalescing(&s->low_mem); |
blueswir1 | 4abc796 | 2009-01-05 17:37:06 +0000 | [diff] [blame] | 2901 | |
aliguori | fefe54e | 2009-01-21 18:31:35 +0000 | [diff] [blame] | 2902 | /* I/O handler for LFB */ |
Paolo Bonzini | 9eb58a4 | 2013-06-06 21:21:13 -0400 | [diff] [blame] | 2903 | memory_region_init_io(&s->cirrus_linear_io, owner, &cirrus_linear_io_ops, s, |
Philippe Mathieu-Daudé | f0353b0 | 2018-06-25 09:42:06 -0300 | [diff] [blame] | 2904 | "cirrus-linear-io", s->vga.vram_size_mb * MiB); |
Jan Kiszka | bd8f2f5 | 2012-08-23 13:02:33 +0200 | [diff] [blame] | 2905 | memory_region_set_flush_coalesced(&s->cirrus_linear_io); |
aliguori | fefe54e | 2009-01-21 18:31:35 +0000 | [diff] [blame] | 2906 | |
| 2907 | /* I/O handler for LFB */ |
Paolo Bonzini | 9eb58a4 | 2013-06-06 21:21:13 -0400 | [diff] [blame] | 2908 | memory_region_init_io(&s->cirrus_linear_bitblt_io, owner, |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2909 | &cirrus_linear_bitblt_io_ops, |
| 2910 | s, |
| 2911 | "cirrus-bitblt-mmio", |
| 2912 | 0x400000); |
Jan Kiszka | bd8f2f5 | 2012-08-23 13:02:33 +0200 | [diff] [blame] | 2913 | memory_region_set_flush_coalesced(&s->cirrus_linear_bitblt_io); |
aliguori | fefe54e | 2009-01-21 18:31:35 +0000 | [diff] [blame] | 2914 | |
| 2915 | /* I/O handler for memory-mapped I/O */ |
Paolo Bonzini | 9eb58a4 | 2013-06-06 21:21:13 -0400 | [diff] [blame] | 2916 | memory_region_init_io(&s->cirrus_mmio_io, owner, &cirrus_mmio_io_ops, s, |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2917 | "cirrus-mmio", CIRRUS_PNPMMIO_SIZE); |
Jan Kiszka | bd8f2f5 | 2012-08-23 13:02:33 +0200 | [diff] [blame] | 2918 | memory_region_set_flush_coalesced(&s->cirrus_mmio_io); |
aliguori | fefe54e | 2009-01-21 18:31:35 +0000 | [diff] [blame] | 2919 | |
| 2920 | s->real_vram_size = |
Philippe Mathieu-Daudé | f0353b0 | 2018-06-25 09:42:06 -0300 | [diff] [blame] | 2921 | (s->device_id == CIRRUS_ID_CLGD5446) ? 4 * MiB : 2 * MiB; |
aliguori | fefe54e | 2009-01-21 18:31:35 +0000 | [diff] [blame] | 2922 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2923 | /* XXX: s->vga.vram_size must be a power of two */ |
aliguori | fefe54e | 2009-01-21 18:31:35 +0000 | [diff] [blame] | 2924 | s->cirrus_addr_mask = s->real_vram_size - 1; |
| 2925 | s->linear_mmio_mask = s->real_vram_size - 256; |
| 2926 | |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2927 | s->vga.get_bpp = cirrus_get_bpp; |
Paolo Bonzini | f9b925f | 2015-01-09 10:47:33 +0100 | [diff] [blame] | 2928 | s->vga.get_params = cirrus_get_params; |
Avi Kivity | 4e12cd9 | 2009-05-03 22:25:16 +0300 | [diff] [blame] | 2929 | s->vga.get_resolution = cirrus_get_resolution; |
| 2930 | s->vga.cursor_invalidate = cirrus_cursor_invalidate; |
| 2931 | s->vga.cursor_draw_line = cirrus_cursor_draw_line; |
aliguori | fefe54e | 2009-01-21 18:31:35 +0000 | [diff] [blame] | 2932 | |
Jan Kiszka | a08d436 | 2009-06-27 09:25:07 +0200 | [diff] [blame] | 2933 | qemu_register_reset(cirrus_reset, s); |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | /*************************************** |
| 2937 | * |
bellard | e6e5ad8 | 2004-06-05 10:31:55 +0000 | [diff] [blame] | 2938 | * PCI bus support |
| 2939 | * |
| 2940 | ***************************************/ |
| 2941 | |
Markus Armbruster | f409edf | 2015-01-19 15:52:35 +0100 | [diff] [blame] | 2942 | static void pci_cirrus_vga_realize(PCIDevice *dev, Error **errp) |
Gerd Hoffmann | a414c30 | 2009-07-28 18:18:00 +0200 | [diff] [blame] | 2943 | { |
Thomas Huth | 5f2011b | 2022-03-17 09:30:24 +0100 | [diff] [blame] | 2944 | PCICirrusVGAState *d = PCI_CIRRUS_VGA(dev); |
| 2945 | CirrusVGAState *s = &d->cirrus_vga; |
| 2946 | PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); |
| 2947 | int16_t device_id = pc->device_id; |
Gerd Hoffmann | a414c30 | 2009-07-28 18:18:00 +0200 | [diff] [blame] | 2948 | |
Thomas Huth | 5f2011b | 2022-03-17 09:30:24 +0100 | [diff] [blame] | 2949 | /* |
| 2950 | * Follow real hardware, cirrus card emulated has 4 MB video memory. |
| 2951 | * Also accept 8 MB/16 MB for backward compatibility. |
| 2952 | */ |
| 2953 | if (s->vga.vram_size_mb != 4 && s->vga.vram_size_mb != 8 && |
| 2954 | s->vga.vram_size_mb != 16) { |
| 2955 | error_setg(errp, "Invalid cirrus_vga ram size '%u'", |
| 2956 | s->vga.vram_size_mb); |
| 2957 | return; |
| 2958 | } |
| 2959 | /* setup VGA */ |
Thomas Huth | 6832deb | 2022-03-17 09:30:25 +0100 | [diff] [blame] | 2960 | if (!vga_common_init(&s->vga, OBJECT(dev), errp)) { |
| 2961 | return; |
| 2962 | } |
Thomas Huth | 5f2011b | 2022-03-17 09:30:24 +0100 | [diff] [blame] | 2963 | cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev), |
| 2964 | pci_address_space_io(dev)); |
| 2965 | s->vga.con = graphic_console_init(DEVICE(dev), 0, s->vga.hw_ops, &s->vga); |
Gerd Hoffmann | a414c30 | 2009-07-28 18:18:00 +0200 | [diff] [blame] | 2966 | |
Thomas Huth | 5f2011b | 2022-03-17 09:30:24 +0100 | [diff] [blame] | 2967 | /* setup PCI */ |
Paolo Bonzini | 3eadad5 | 2013-06-06 21:25:08 -0400 | [diff] [blame] | 2968 | memory_region_init(&s->pci_bar, OBJECT(dev), "cirrus-pci-bar0", 0x2000000); |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 2969 | |
| 2970 | /* XXX: add byte swapping apertures */ |
| 2971 | memory_region_add_subregion(&s->pci_bar, 0, &s->cirrus_linear_io); |
| 2972 | memory_region_add_subregion(&s->pci_bar, 0x1000000, |
| 2973 | &s->cirrus_linear_bitblt_io); |
| 2974 | |
Thomas Huth | 5f2011b | 2022-03-17 09:30:24 +0100 | [diff] [blame] | 2975 | /* setup memory space */ |
| 2976 | /* memory #0 LFB */ |
| 2977 | /* memory #1 memory-mapped I/O */ |
| 2978 | /* XXX: s->vga.vram_size must be a power of two */ |
| 2979 | pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->pci_bar); |
| 2980 | if (device_id == CIRRUS_ID_CLGD5446) { |
| 2981 | pci_register_bar(&d->dev, 1, 0, &s->cirrus_mmio_io); |
| 2982 | } |
Gerd Hoffmann | a414c30 | 2009-07-28 18:18:00 +0200 | [diff] [blame] | 2983 | } |
| 2984 | |
Marcelo Tosatti | 19403a6 | 2012-10-05 14:51:39 -0300 | [diff] [blame] | 2985 | static Property pci_vga_cirrus_properties[] = { |
| 2986 | DEFINE_PROP_UINT32("vgamem_mb", struct PCICirrusVGAState, |
Gerd Hoffmann | 73c1481 | 2017-03-14 13:28:34 +0100 | [diff] [blame] | 2987 | cirrus_vga.vga.vram_size_mb, 4), |
Gerd Hoffmann | 827bd51 | 2017-03-14 13:29:00 +0100 | [diff] [blame] | 2988 | DEFINE_PROP_BOOL("blitter", struct PCICirrusVGAState, |
| 2989 | cirrus_vga.enable_blitter, true), |
Gerd Hoffmann | 1fcfdc4 | 2018-07-02 18:33:44 +0200 | [diff] [blame] | 2990 | DEFINE_PROP_BOOL("global-vmstate", struct PCICirrusVGAState, |
| 2991 | cirrus_vga.vga.global_vmstate, false), |
Marcelo Tosatti | 19403a6 | 2012-10-05 14:51:39 -0300 | [diff] [blame] | 2992 | DEFINE_PROP_END_OF_LIST(), |
| 2993 | }; |
| 2994 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 2995 | static void cirrus_vga_class_init(ObjectClass *klass, void *data) |
| 2996 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 2997 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 2998 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 2999 | |
Markus Armbruster | f409edf | 2015-01-19 15:52:35 +0100 | [diff] [blame] | 3000 | k->realize = pci_cirrus_vga_realize; |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 3001 | k->romfile = VGABIOS_CIRRUS_FILENAME; |
| 3002 | k->vendor_id = PCI_VENDOR_ID_CIRRUS; |
| 3003 | k->device_id = CIRRUS_ID_CLGD5446; |
| 3004 | k->class_id = PCI_CLASS_DISPLAY_VGA; |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 3005 | set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 3006 | dc->desc = "Cirrus CLGD 54xx VGA"; |
| 3007 | dc->vmsd = &vmstate_pci_cirrus_vga; |
Marc-André Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 3008 | device_class_set_props(dc, pci_vga_cirrus_properties); |
Igor Mammedov | 2897ae0 | 2014-02-05 16:36:48 +0100 | [diff] [blame] | 3009 | dc->hotpluggable = false; |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 3010 | } |
| 3011 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 3012 | static const TypeInfo cirrus_vga_info = { |
Gonglei | d338bae | 2015-05-12 17:27:09 +0800 | [diff] [blame] | 3013 | .name = TYPE_PCI_CIRRUS_VGA, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 3014 | .parent = TYPE_PCI_DEVICE, |
| 3015 | .instance_size = sizeof(PCICirrusVGAState), |
| 3016 | .class_init = cirrus_vga_class_init, |
Eduardo Habkost | fd3b02c | 2017-09-27 16:56:34 -0300 | [diff] [blame] | 3017 | .interfaces = (InterfaceInfo[]) { |
| 3018 | { INTERFACE_CONVENTIONAL_PCI_DEVICE }, |
| 3019 | { }, |
| 3020 | }, |
Gerd Hoffmann | a414c30 | 2009-07-28 18:18:00 +0200 | [diff] [blame] | 3021 | }; |
| 3022 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 3023 | static void cirrus_vga_register_types(void) |
Gerd Hoffmann | a414c30 | 2009-07-28 18:18:00 +0200 | [diff] [blame] | 3024 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 3025 | type_register_static(&cirrus_vga_info); |
Gerd Hoffmann | a414c30 | 2009-07-28 18:18:00 +0200 | [diff] [blame] | 3026 | } |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 3027 | |
| 3028 | type_init(cirrus_vga_register_types) |