root / hw / vmware_vga.c @ dd4239d6
History | View | Annotate | Download (33.7 kB)
1 | d34cab9f | ths | /*
|
---|---|---|---|
2 | d34cab9f | ths | * QEMU VMware-SVGA "chipset".
|
3 | d34cab9f | ths | *
|
4 | d34cab9f | ths | * Copyright (c) 2007 Andrzej Zaborowski <balrog@zabor.org>
|
5 | d34cab9f | ths | *
|
6 | d34cab9f | ths | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | d34cab9f | ths | * of this software and associated documentation files (the "Software"), to deal
|
8 | d34cab9f | ths | * in the Software without restriction, including without limitation the rights
|
9 | d34cab9f | ths | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | d34cab9f | ths | * copies of the Software, and to permit persons to whom the Software is
|
11 | d34cab9f | ths | * furnished to do so, subject to the following conditions:
|
12 | d34cab9f | ths | *
|
13 | d34cab9f | ths | * The above copyright notice and this permission notice shall be included in
|
14 | d34cab9f | ths | * all copies or substantial portions of the Software.
|
15 | d34cab9f | ths | *
|
16 | d34cab9f | ths | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | d34cab9f | ths | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | d34cab9f | ths | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | d34cab9f | ths | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | d34cab9f | ths | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | d34cab9f | ths | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | d34cab9f | ths | * THE SOFTWARE.
|
23 | d34cab9f | ths | */
|
24 | 87ecb68b | pbrook | #include "hw.h" |
25 | 87ecb68b | pbrook | #include "console.h" |
26 | 87ecb68b | pbrook | #include "pci.h" |
27 | d34cab9f | ths | |
28 | d34cab9f | ths | #define VERBOSE
|
29 | d34cab9f | ths | #undef DIRECT_VRAM
|
30 | d34cab9f | ths | #define HW_RECT_ACCEL
|
31 | d34cab9f | ths | #define HW_FILL_ACCEL
|
32 | d34cab9f | ths | #define HW_MOUSE_ACCEL
|
33 | d34cab9f | ths | |
34 | d34cab9f | ths | # include "vga_int.h" |
35 | d34cab9f | ths | |
36 | d34cab9f | ths | struct vmsvga_state_s {
|
37 | 4e12cd94 | Avi Kivity | VGACommonState vga; |
38 | d34cab9f | ths | |
39 | d34cab9f | ths | int width;
|
40 | d34cab9f | ths | int height;
|
41 | d34cab9f | ths | int invalidated;
|
42 | d34cab9f | ths | int depth;
|
43 | d34cab9f | ths | int bypp;
|
44 | d34cab9f | ths | int enable;
|
45 | d34cab9f | ths | int config;
|
46 | d34cab9f | ths | struct {
|
47 | d34cab9f | ths | int id;
|
48 | d34cab9f | ths | int x;
|
49 | d34cab9f | ths | int y;
|
50 | d34cab9f | ths | int on;
|
51 | d34cab9f | ths | } cursor; |
52 | d34cab9f | ths | |
53 | c227f099 | Anthony Liguori | target_phys_addr_t vram_base; |
54 | d34cab9f | ths | |
55 | d34cab9f | ths | int index;
|
56 | d34cab9f | ths | int scratch_size;
|
57 | d34cab9f | ths | uint32_t *scratch; |
58 | d34cab9f | ths | int new_width;
|
59 | d34cab9f | ths | int new_height;
|
60 | d34cab9f | ths | uint32_t guest; |
61 | d34cab9f | ths | uint32_t svgaid; |
62 | d34cab9f | ths | uint32_t wred; |
63 | d34cab9f | ths | uint32_t wgreen; |
64 | d34cab9f | ths | uint32_t wblue; |
65 | d34cab9f | ths | int syncing;
|
66 | d34cab9f | ths | int fb_size;
|
67 | d34cab9f | ths | |
68 | d34cab9f | ths | union {
|
69 | d34cab9f | ths | uint32_t *fifo; |
70 | d34cab9f | ths | struct __attribute__((__packed__)) {
|
71 | d34cab9f | ths | uint32_t min; |
72 | d34cab9f | ths | uint32_t max; |
73 | d34cab9f | ths | uint32_t next_cmd; |
74 | d34cab9f | ths | uint32_t stop; |
75 | d34cab9f | ths | /* Add registers here when adding capabilities. */
|
76 | d34cab9f | ths | uint32_t fifo[0];
|
77 | d34cab9f | ths | } *cmd; |
78 | d34cab9f | ths | }; |
79 | d34cab9f | ths | |
80 | d34cab9f | ths | #define REDRAW_FIFO_LEN 512 |
81 | d34cab9f | ths | struct vmsvga_rect_s {
|
82 | d34cab9f | ths | int x, y, w, h;
|
83 | d34cab9f | ths | } redraw_fifo[REDRAW_FIFO_LEN]; |
84 | d34cab9f | ths | int redraw_fifo_first, redraw_fifo_last;
|
85 | d34cab9f | ths | }; |
86 | d34cab9f | ths | |
87 | d34cab9f | ths | struct pci_vmsvga_state_s {
|
88 | d34cab9f | ths | PCIDevice card; |
89 | d34cab9f | ths | struct vmsvga_state_s chip;
|
90 | d34cab9f | ths | }; |
91 | d34cab9f | ths | |
92 | d34cab9f | ths | #define SVGA_MAGIC 0x900000UL |
93 | d34cab9f | ths | #define SVGA_MAKE_ID(ver) (SVGA_MAGIC << 8 | (ver)) |
94 | d34cab9f | ths | #define SVGA_ID_0 SVGA_MAKE_ID(0) |
95 | d34cab9f | ths | #define SVGA_ID_1 SVGA_MAKE_ID(1) |
96 | d34cab9f | ths | #define SVGA_ID_2 SVGA_MAKE_ID(2) |
97 | d34cab9f | ths | |
98 | d34cab9f | ths | #define SVGA_LEGACY_BASE_PORT 0x4560 |
99 | d34cab9f | ths | #define SVGA_INDEX_PORT 0x0 |
100 | d34cab9f | ths | #define SVGA_VALUE_PORT 0x1 |
101 | d34cab9f | ths | #define SVGA_BIOS_PORT 0x2 |
102 | d34cab9f | ths | |
103 | d34cab9f | ths | #define SVGA_VERSION_2
|
104 | d34cab9f | ths | |
105 | d34cab9f | ths | #ifdef SVGA_VERSION_2
|
106 | d34cab9f | ths | # define SVGA_ID SVGA_ID_2
|
107 | d34cab9f | ths | # define SVGA_IO_BASE SVGA_LEGACY_BASE_PORT
|
108 | d34cab9f | ths | # define SVGA_IO_MUL 1 |
109 | d34cab9f | ths | # define SVGA_FIFO_SIZE 0x10000 |
110 | 1f72aae5 | balrog | # define SVGA_MEM_BASE 0xe0000000 |
111 | d34cab9f | ths | # define SVGA_PCI_DEVICE_ID PCI_DEVICE_ID_VMWARE_SVGA2
|
112 | d34cab9f | ths | #else
|
113 | d34cab9f | ths | # define SVGA_ID SVGA_ID_1
|
114 | d34cab9f | ths | # define SVGA_IO_BASE SVGA_LEGACY_BASE_PORT
|
115 | d34cab9f | ths | # define SVGA_IO_MUL 4 |
116 | d34cab9f | ths | # define SVGA_FIFO_SIZE 0x10000 |
117 | 1f72aae5 | balrog | # define SVGA_MEM_BASE 0xe0000000 |
118 | d34cab9f | ths | # define SVGA_PCI_DEVICE_ID PCI_DEVICE_ID_VMWARE_SVGA
|
119 | d34cab9f | ths | #endif
|
120 | d34cab9f | ths | |
121 | d34cab9f | ths | enum {
|
122 | d34cab9f | ths | /* ID 0, 1 and 2 registers */
|
123 | d34cab9f | ths | SVGA_REG_ID = 0,
|
124 | d34cab9f | ths | SVGA_REG_ENABLE = 1,
|
125 | d34cab9f | ths | SVGA_REG_WIDTH = 2,
|
126 | d34cab9f | ths | SVGA_REG_HEIGHT = 3,
|
127 | d34cab9f | ths | SVGA_REG_MAX_WIDTH = 4,
|
128 | d34cab9f | ths | SVGA_REG_MAX_HEIGHT = 5,
|
129 | d34cab9f | ths | SVGA_REG_DEPTH = 6,
|
130 | d34cab9f | ths | SVGA_REG_BITS_PER_PIXEL = 7, /* Current bpp in the guest */ |
131 | d34cab9f | ths | SVGA_REG_PSEUDOCOLOR = 8,
|
132 | d34cab9f | ths | SVGA_REG_RED_MASK = 9,
|
133 | d34cab9f | ths | SVGA_REG_GREEN_MASK = 10,
|
134 | d34cab9f | ths | SVGA_REG_BLUE_MASK = 11,
|
135 | d34cab9f | ths | SVGA_REG_BYTES_PER_LINE = 12,
|
136 | d34cab9f | ths | SVGA_REG_FB_START = 13,
|
137 | d34cab9f | ths | SVGA_REG_FB_OFFSET = 14,
|
138 | d34cab9f | ths | SVGA_REG_VRAM_SIZE = 15,
|
139 | d34cab9f | ths | SVGA_REG_FB_SIZE = 16,
|
140 | d34cab9f | ths | |
141 | d34cab9f | ths | /* ID 1 and 2 registers */
|
142 | d34cab9f | ths | SVGA_REG_CAPABILITIES = 17,
|
143 | d34cab9f | ths | SVGA_REG_MEM_START = 18, /* Memory for command FIFO */ |
144 | d34cab9f | ths | SVGA_REG_MEM_SIZE = 19,
|
145 | d34cab9f | ths | SVGA_REG_CONFIG_DONE = 20, /* Set when memory area configured */ |
146 | d34cab9f | ths | SVGA_REG_SYNC = 21, /* Write to force synchronization */ |
147 | d34cab9f | ths | SVGA_REG_BUSY = 22, /* Read to check if sync is done */ |
148 | d34cab9f | ths | SVGA_REG_GUEST_ID = 23, /* Set guest OS identifier */ |
149 | d34cab9f | ths | SVGA_REG_CURSOR_ID = 24, /* ID of cursor */ |
150 | d34cab9f | ths | SVGA_REG_CURSOR_X = 25, /* Set cursor X position */ |
151 | d34cab9f | ths | SVGA_REG_CURSOR_Y = 26, /* Set cursor Y position */ |
152 | d34cab9f | ths | SVGA_REG_CURSOR_ON = 27, /* Turn cursor on/off */ |
153 | d34cab9f | ths | SVGA_REG_HOST_BITS_PER_PIXEL = 28, /* Current bpp in the host */ |
154 | d34cab9f | ths | SVGA_REG_SCRATCH_SIZE = 29, /* Number of scratch registers */ |
155 | d34cab9f | ths | SVGA_REG_MEM_REGS = 30, /* Number of FIFO registers */ |
156 | d34cab9f | ths | SVGA_REG_NUM_DISPLAYS = 31, /* Number of guest displays */ |
157 | d34cab9f | ths | SVGA_REG_PITCHLOCK = 32, /* Fixed pitch for all modes */ |
158 | d34cab9f | ths | |
159 | d34cab9f | ths | SVGA_PALETTE_BASE = 1024, /* Base of SVGA color map */ |
160 | d34cab9f | ths | SVGA_PALETTE_END = SVGA_PALETTE_BASE + 767,
|
161 | d34cab9f | ths | SVGA_SCRATCH_BASE = SVGA_PALETTE_BASE + 768,
|
162 | d34cab9f | ths | }; |
163 | d34cab9f | ths | |
164 | d34cab9f | ths | #define SVGA_CAP_NONE 0 |
165 | d34cab9f | ths | #define SVGA_CAP_RECT_FILL (1 << 0) |
166 | d34cab9f | ths | #define SVGA_CAP_RECT_COPY (1 << 1) |
167 | d34cab9f | ths | #define SVGA_CAP_RECT_PAT_FILL (1 << 2) |
168 | d34cab9f | ths | #define SVGA_CAP_LEGACY_OFFSCREEN (1 << 3) |
169 | d34cab9f | ths | #define SVGA_CAP_RASTER_OP (1 << 4) |
170 | d34cab9f | ths | #define SVGA_CAP_CURSOR (1 << 5) |
171 | d34cab9f | ths | #define SVGA_CAP_CURSOR_BYPASS (1 << 6) |
172 | d34cab9f | ths | #define SVGA_CAP_CURSOR_BYPASS_2 (1 << 7) |
173 | d34cab9f | ths | #define SVGA_CAP_8BIT_EMULATION (1 << 8) |
174 | d34cab9f | ths | #define SVGA_CAP_ALPHA_CURSOR (1 << 9) |
175 | d34cab9f | ths | #define SVGA_CAP_GLYPH (1 << 10) |
176 | d34cab9f | ths | #define SVGA_CAP_GLYPH_CLIPPING (1 << 11) |
177 | d34cab9f | ths | #define SVGA_CAP_OFFSCREEN_1 (1 << 12) |
178 | d34cab9f | ths | #define SVGA_CAP_ALPHA_BLEND (1 << 13) |
179 | d34cab9f | ths | #define SVGA_CAP_3D (1 << 14) |
180 | d34cab9f | ths | #define SVGA_CAP_EXTENDED_FIFO (1 << 15) |
181 | d34cab9f | ths | #define SVGA_CAP_MULTIMON (1 << 16) |
182 | d34cab9f | ths | #define SVGA_CAP_PITCHLOCK (1 << 17) |
183 | d34cab9f | ths | |
184 | d34cab9f | ths | /*
|
185 | d34cab9f | ths | * FIFO offsets (seen as an array of 32-bit words)
|
186 | d34cab9f | ths | */
|
187 | d34cab9f | ths | enum {
|
188 | d34cab9f | ths | /*
|
189 | d34cab9f | ths | * The original defined FIFO offsets
|
190 | d34cab9f | ths | */
|
191 | d34cab9f | ths | SVGA_FIFO_MIN = 0,
|
192 | d34cab9f | ths | SVGA_FIFO_MAX, /* The distance from MIN to MAX must be at least 10K */
|
193 | d34cab9f | ths | SVGA_FIFO_NEXT_CMD, |
194 | d34cab9f | ths | SVGA_FIFO_STOP, |
195 | d34cab9f | ths | |
196 | d34cab9f | ths | /*
|
197 | d34cab9f | ths | * Additional offsets added as of SVGA_CAP_EXTENDED_FIFO
|
198 | d34cab9f | ths | */
|
199 | d34cab9f | ths | SVGA_FIFO_CAPABILITIES = 4,
|
200 | d34cab9f | ths | SVGA_FIFO_FLAGS, |
201 | d34cab9f | ths | SVGA_FIFO_FENCE, |
202 | d34cab9f | ths | SVGA_FIFO_3D_HWVERSION, |
203 | d34cab9f | ths | SVGA_FIFO_PITCHLOCK, |
204 | d34cab9f | ths | }; |
205 | d34cab9f | ths | |
206 | d34cab9f | ths | #define SVGA_FIFO_CAP_NONE 0 |
207 | d34cab9f | ths | #define SVGA_FIFO_CAP_FENCE (1 << 0) |
208 | d34cab9f | ths | #define SVGA_FIFO_CAP_ACCELFRONT (1 << 1) |
209 | d34cab9f | ths | #define SVGA_FIFO_CAP_PITCHLOCK (1 << 2) |
210 | d34cab9f | ths | |
211 | d34cab9f | ths | #define SVGA_FIFO_FLAG_NONE 0 |
212 | d34cab9f | ths | #define SVGA_FIFO_FLAG_ACCELFRONT (1 << 0) |
213 | d34cab9f | ths | |
214 | d34cab9f | ths | /* These values can probably be changed arbitrarily. */
|
215 | d34cab9f | ths | #define SVGA_SCRATCH_SIZE 0x8000 |
216 | d34cab9f | ths | #define SVGA_MAX_WIDTH 2360 |
217 | d34cab9f | ths | #define SVGA_MAX_HEIGHT 1770 |
218 | d34cab9f | ths | |
219 | d34cab9f | ths | #ifdef VERBOSE
|
220 | d34cab9f | ths | # define GUEST_OS_BASE 0x5001 |
221 | d34cab9f | ths | static const char *vmsvga_guest_id[] = { |
222 | f707cfba | balrog | [0x00] = "Dos", |
223 | f707cfba | balrog | [0x01] = "Windows 3.1", |
224 | f707cfba | balrog | [0x02] = "Windows 95", |
225 | f707cfba | balrog | [0x03] = "Windows 98", |
226 | f707cfba | balrog | [0x04] = "Windows ME", |
227 | f707cfba | balrog | [0x05] = "Windows NT", |
228 | f707cfba | balrog | [0x06] = "Windows 2000", |
229 | f707cfba | balrog | [0x07] = "Linux", |
230 | f707cfba | balrog | [0x08] = "OS/2", |
231 | 511d2b14 | blueswir1 | [0x09] = "an unknown OS", |
232 | f707cfba | balrog | [0x0a] = "BSD", |
233 | f707cfba | balrog | [0x0b] = "Whistler", |
234 | 511d2b14 | blueswir1 | [0x0c] = "an unknown OS", |
235 | 511d2b14 | blueswir1 | [0x0d] = "an unknown OS", |
236 | 511d2b14 | blueswir1 | [0x0e] = "an unknown OS", |
237 | 511d2b14 | blueswir1 | [0x0f] = "an unknown OS", |
238 | 511d2b14 | blueswir1 | [0x10] = "an unknown OS", |
239 | 511d2b14 | blueswir1 | [0x11] = "an unknown OS", |
240 | 511d2b14 | blueswir1 | [0x12] = "an unknown OS", |
241 | 511d2b14 | blueswir1 | [0x13] = "an unknown OS", |
242 | 511d2b14 | blueswir1 | [0x14] = "an unknown OS", |
243 | f707cfba | balrog | [0x15] = "Windows 2003", |
244 | d34cab9f | ths | }; |
245 | d34cab9f | ths | #endif
|
246 | d34cab9f | ths | |
247 | d34cab9f | ths | enum {
|
248 | d34cab9f | ths | SVGA_CMD_INVALID_CMD = 0,
|
249 | d34cab9f | ths | SVGA_CMD_UPDATE = 1,
|
250 | d34cab9f | ths | SVGA_CMD_RECT_FILL = 2,
|
251 | d34cab9f | ths | SVGA_CMD_RECT_COPY = 3,
|
252 | d34cab9f | ths | SVGA_CMD_DEFINE_BITMAP = 4,
|
253 | d34cab9f | ths | SVGA_CMD_DEFINE_BITMAP_SCANLINE = 5,
|
254 | d34cab9f | ths | SVGA_CMD_DEFINE_PIXMAP = 6,
|
255 | d34cab9f | ths | SVGA_CMD_DEFINE_PIXMAP_SCANLINE = 7,
|
256 | d34cab9f | ths | SVGA_CMD_RECT_BITMAP_FILL = 8,
|
257 | d34cab9f | ths | SVGA_CMD_RECT_PIXMAP_FILL = 9,
|
258 | d34cab9f | ths | SVGA_CMD_RECT_BITMAP_COPY = 10,
|
259 | d34cab9f | ths | SVGA_CMD_RECT_PIXMAP_COPY = 11,
|
260 | d34cab9f | ths | SVGA_CMD_FREE_OBJECT = 12,
|
261 | d34cab9f | ths | SVGA_CMD_RECT_ROP_FILL = 13,
|
262 | d34cab9f | ths | SVGA_CMD_RECT_ROP_COPY = 14,
|
263 | d34cab9f | ths | SVGA_CMD_RECT_ROP_BITMAP_FILL = 15,
|
264 | d34cab9f | ths | SVGA_CMD_RECT_ROP_PIXMAP_FILL = 16,
|
265 | d34cab9f | ths | SVGA_CMD_RECT_ROP_BITMAP_COPY = 17,
|
266 | d34cab9f | ths | SVGA_CMD_RECT_ROP_PIXMAP_COPY = 18,
|
267 | d34cab9f | ths | SVGA_CMD_DEFINE_CURSOR = 19,
|
268 | d34cab9f | ths | SVGA_CMD_DISPLAY_CURSOR = 20,
|
269 | d34cab9f | ths | SVGA_CMD_MOVE_CURSOR = 21,
|
270 | d34cab9f | ths | SVGA_CMD_DEFINE_ALPHA_CURSOR = 22,
|
271 | d34cab9f | ths | SVGA_CMD_DRAW_GLYPH = 23,
|
272 | d34cab9f | ths | SVGA_CMD_DRAW_GLYPH_CLIPPED = 24,
|
273 | d34cab9f | ths | SVGA_CMD_UPDATE_VERBOSE = 25,
|
274 | d34cab9f | ths | SVGA_CMD_SURFACE_FILL = 26,
|
275 | d34cab9f | ths | SVGA_CMD_SURFACE_COPY = 27,
|
276 | d34cab9f | ths | SVGA_CMD_SURFACE_ALPHA_BLEND = 28,
|
277 | d34cab9f | ths | SVGA_CMD_FRONT_ROP_FILL = 29,
|
278 | d34cab9f | ths | SVGA_CMD_FENCE = 30,
|
279 | d34cab9f | ths | }; |
280 | d34cab9f | ths | |
281 | d34cab9f | ths | /* Legal values for the SVGA_REG_CURSOR_ON register in cursor bypass mode */
|
282 | d34cab9f | ths | enum {
|
283 | d34cab9f | ths | SVGA_CURSOR_ON_HIDE = 0,
|
284 | d34cab9f | ths | SVGA_CURSOR_ON_SHOW = 1,
|
285 | d34cab9f | ths | SVGA_CURSOR_ON_REMOVE_FROM_FB = 2,
|
286 | d34cab9f | ths | SVGA_CURSOR_ON_RESTORE_TO_FB = 3,
|
287 | d34cab9f | ths | }; |
288 | d34cab9f | ths | |
289 | d34cab9f | ths | static inline void vmsvga_update_rect(struct vmsvga_state_s *s, |
290 | d34cab9f | ths | int x, int y, int w, int h) |
291 | d34cab9f | ths | { |
292 | d34cab9f | ths | #ifndef DIRECT_VRAM
|
293 | a8fbaf96 | balrog | int line;
|
294 | a8fbaf96 | balrog | int bypl;
|
295 | a8fbaf96 | balrog | int width;
|
296 | a8fbaf96 | balrog | int start;
|
297 | a8fbaf96 | balrog | uint8_t *src; |
298 | a8fbaf96 | balrog | uint8_t *dst; |
299 | a8fbaf96 | balrog | |
300 | a8fbaf96 | balrog | if (x + w > s->width) {
|
301 | a8fbaf96 | balrog | fprintf(stderr, "%s: update width too large x: %d, w: %d\n",
|
302 | a8fbaf96 | balrog | __FUNCTION__, x, w); |
303 | a8fbaf96 | balrog | x = MIN(x, s->width); |
304 | a8fbaf96 | balrog | w = s->width - x; |
305 | a8fbaf96 | balrog | } |
306 | a8fbaf96 | balrog | |
307 | a8fbaf96 | balrog | if (y + h > s->height) {
|
308 | a8fbaf96 | balrog | fprintf(stderr, "%s: update height too large y: %d, h: %d\n",
|
309 | a8fbaf96 | balrog | __FUNCTION__, y, h); |
310 | a8fbaf96 | balrog | y = MIN(y, s->height); |
311 | a8fbaf96 | balrog | h = s->height - y; |
312 | a8fbaf96 | balrog | } |
313 | a8fbaf96 | balrog | |
314 | a8fbaf96 | balrog | line = h; |
315 | a8fbaf96 | balrog | bypl = s->bypp * s->width; |
316 | a8fbaf96 | balrog | width = s->bypp * w; |
317 | a8fbaf96 | balrog | start = s->bypp * x + bypl * y; |
318 | 4e12cd94 | Avi Kivity | src = s->vga.vram_ptr + start; |
319 | 4e12cd94 | Avi Kivity | dst = ds_get_data(s->vga.ds) + start; |
320 | d34cab9f | ths | |
321 | d34cab9f | ths | for (; line > 0; line --, src += bypl, dst += bypl) |
322 | d34cab9f | ths | memcpy(dst, src, width); |
323 | d34cab9f | ths | #endif
|
324 | d34cab9f | ths | |
325 | 4e12cd94 | Avi Kivity | dpy_update(s->vga.ds, x, y, w, h); |
326 | d34cab9f | ths | } |
327 | d34cab9f | ths | |
328 | d34cab9f | ths | static inline void vmsvga_update_screen(struct vmsvga_state_s *s) |
329 | d34cab9f | ths | { |
330 | d34cab9f | ths | #ifndef DIRECT_VRAM
|
331 | 4e12cd94 | Avi Kivity | memcpy(ds_get_data(s->vga.ds), s->vga.vram_ptr, s->bypp * s->width * s->height); |
332 | d34cab9f | ths | #endif
|
333 | d34cab9f | ths | |
334 | 4e12cd94 | Avi Kivity | dpy_update(s->vga.ds, 0, 0, s->width, s->height); |
335 | d34cab9f | ths | } |
336 | d34cab9f | ths | |
337 | d34cab9f | ths | #ifdef DIRECT_VRAM
|
338 | d34cab9f | ths | # define vmsvga_update_rect_delayed vmsvga_update_rect
|
339 | d34cab9f | ths | #else
|
340 | d34cab9f | ths | static inline void vmsvga_update_rect_delayed(struct vmsvga_state_s *s, |
341 | d34cab9f | ths | int x, int y, int w, int h) |
342 | d34cab9f | ths | { |
343 | d34cab9f | ths | struct vmsvga_rect_s *rect = &s->redraw_fifo[s->redraw_fifo_last ++];
|
344 | d34cab9f | ths | s->redraw_fifo_last &= REDRAW_FIFO_LEN - 1;
|
345 | d34cab9f | ths | rect->x = x; |
346 | d34cab9f | ths | rect->y = y; |
347 | d34cab9f | ths | rect->w = w; |
348 | d34cab9f | ths | rect->h = h; |
349 | d34cab9f | ths | } |
350 | d34cab9f | ths | #endif
|
351 | d34cab9f | ths | |
352 | d34cab9f | ths | static inline void vmsvga_update_rect_flush(struct vmsvga_state_s *s) |
353 | d34cab9f | ths | { |
354 | d34cab9f | ths | struct vmsvga_rect_s *rect;
|
355 | d34cab9f | ths | if (s->invalidated) {
|
356 | d34cab9f | ths | s->redraw_fifo_first = s->redraw_fifo_last; |
357 | d34cab9f | ths | return;
|
358 | d34cab9f | ths | } |
359 | d34cab9f | ths | /* Overlapping region updates can be optimised out here - if someone
|
360 | d34cab9f | ths | * knows a smart algorithm to do that, please share. */
|
361 | d34cab9f | ths | while (s->redraw_fifo_first != s->redraw_fifo_last) {
|
362 | d34cab9f | ths | rect = &s->redraw_fifo[s->redraw_fifo_first ++]; |
363 | d34cab9f | ths | s->redraw_fifo_first &= REDRAW_FIFO_LEN - 1;
|
364 | d34cab9f | ths | vmsvga_update_rect(s, rect->x, rect->y, rect->w, rect->h); |
365 | d34cab9f | ths | } |
366 | d34cab9f | ths | } |
367 | d34cab9f | ths | |
368 | d34cab9f | ths | #ifdef HW_RECT_ACCEL
|
369 | d34cab9f | ths | static inline void vmsvga_copy_rect(struct vmsvga_state_s *s, |
370 | d34cab9f | ths | int x0, int y0, int x1, int y1, int w, int h) |
371 | d34cab9f | ths | { |
372 | d34cab9f | ths | # ifdef DIRECT_VRAM
|
373 | 0e1f5a0c | aliguori | uint8_t *vram = ds_get_data(s->ds); |
374 | d34cab9f | ths | # else
|
375 | 4e12cd94 | Avi Kivity | uint8_t *vram = s->vga.vram_ptr; |
376 | d34cab9f | ths | # endif
|
377 | d34cab9f | ths | int bypl = s->bypp * s->width;
|
378 | d34cab9f | ths | int width = s->bypp * w;
|
379 | d34cab9f | ths | int line = h;
|
380 | d34cab9f | ths | uint8_t *ptr[2];
|
381 | d34cab9f | ths | |
382 | d34cab9f | ths | # ifdef DIRECT_VRAM
|
383 | d34cab9f | ths | if (s->ds->dpy_copy)
|
384 | 3023f332 | aliguori | qemu_console_copy(s->ds, x0, y0, x1, y1, w, h); |
385 | d34cab9f | ths | else
|
386 | d34cab9f | ths | # endif
|
387 | d34cab9f | ths | { |
388 | d34cab9f | ths | if (y1 > y0) {
|
389 | d34cab9f | ths | ptr[0] = vram + s->bypp * x0 + bypl * (y0 + h - 1); |
390 | d34cab9f | ths | ptr[1] = vram + s->bypp * x1 + bypl * (y1 + h - 1); |
391 | d34cab9f | ths | for (; line > 0; line --, ptr[0] -= bypl, ptr[1] -= bypl) |
392 | d34cab9f | ths | memmove(ptr[1], ptr[0], width); |
393 | d34cab9f | ths | } else {
|
394 | d34cab9f | ths | ptr[0] = vram + s->bypp * x0 + bypl * y0;
|
395 | d34cab9f | ths | ptr[1] = vram + s->bypp * x1 + bypl * y1;
|
396 | d34cab9f | ths | for (; line > 0; line --, ptr[0] += bypl, ptr[1] += bypl) |
397 | d34cab9f | ths | memmove(ptr[1], ptr[0], width); |
398 | d34cab9f | ths | } |
399 | d34cab9f | ths | } |
400 | d34cab9f | ths | |
401 | d34cab9f | ths | vmsvga_update_rect_delayed(s, x1, y1, w, h); |
402 | d34cab9f | ths | } |
403 | d34cab9f | ths | #endif
|
404 | d34cab9f | ths | |
405 | d34cab9f | ths | #ifdef HW_FILL_ACCEL
|
406 | d34cab9f | ths | static inline void vmsvga_fill_rect(struct vmsvga_state_s *s, |
407 | d34cab9f | ths | uint32_t c, int x, int y, int w, int h) |
408 | d34cab9f | ths | { |
409 | d34cab9f | ths | # ifdef DIRECT_VRAM
|
410 | 0e1f5a0c | aliguori | uint8_t *vram = ds_get_data(s->ds); |
411 | d34cab9f | ths | # else
|
412 | 4e12cd94 | Avi Kivity | uint8_t *vram = s->vga.vram_ptr; |
413 | d34cab9f | ths | # endif
|
414 | d34cab9f | ths | int bypp = s->bypp;
|
415 | d34cab9f | ths | int bypl = bypp * s->width;
|
416 | d34cab9f | ths | int width = bypp * w;
|
417 | d34cab9f | ths | int line = h;
|
418 | d34cab9f | ths | int column;
|
419 | d34cab9f | ths | uint8_t *fst = vram + bypp * x + bypl * y; |
420 | d34cab9f | ths | uint8_t *dst; |
421 | d34cab9f | ths | uint8_t *src; |
422 | d34cab9f | ths | uint8_t col[4];
|
423 | d34cab9f | ths | |
424 | d34cab9f | ths | # ifdef DIRECT_VRAM
|
425 | d34cab9f | ths | if (s->ds->dpy_fill)
|
426 | d34cab9f | ths | s->ds->dpy_fill(s->ds, x, y, w, h, c); |
427 | d34cab9f | ths | else
|
428 | d34cab9f | ths | # endif
|
429 | d34cab9f | ths | { |
430 | d34cab9f | ths | col[0] = c;
|
431 | d34cab9f | ths | col[1] = c >> 8; |
432 | d34cab9f | ths | col[2] = c >> 16; |
433 | d34cab9f | ths | col[3] = c >> 24; |
434 | d34cab9f | ths | |
435 | d34cab9f | ths | if (line --) {
|
436 | d34cab9f | ths | dst = fst; |
437 | d34cab9f | ths | src = col; |
438 | d34cab9f | ths | for (column = width; column > 0; column --) { |
439 | d34cab9f | ths | *(dst ++) = *(src ++); |
440 | d34cab9f | ths | if (src - col == bypp)
|
441 | d34cab9f | ths | src = col; |
442 | d34cab9f | ths | } |
443 | d34cab9f | ths | dst = fst; |
444 | d34cab9f | ths | for (; line > 0; line --) { |
445 | d34cab9f | ths | dst += bypl; |
446 | d34cab9f | ths | memcpy(dst, fst, width); |
447 | d34cab9f | ths | } |
448 | d34cab9f | ths | } |
449 | d34cab9f | ths | } |
450 | d34cab9f | ths | |
451 | d34cab9f | ths | vmsvga_update_rect_delayed(s, x, y, w, h); |
452 | d34cab9f | ths | } |
453 | d34cab9f | ths | #endif
|
454 | d34cab9f | ths | |
455 | d34cab9f | ths | struct vmsvga_cursor_definition_s {
|
456 | d34cab9f | ths | int width;
|
457 | d34cab9f | ths | int height;
|
458 | d34cab9f | ths | int id;
|
459 | d34cab9f | ths | int bpp;
|
460 | d34cab9f | ths | int hot_x;
|
461 | d34cab9f | ths | int hot_y;
|
462 | d34cab9f | ths | uint32_t mask[1024];
|
463 | d34cab9f | ths | uint32_t image[1024];
|
464 | d34cab9f | ths | }; |
465 | d34cab9f | ths | |
466 | d34cab9f | ths | #define SVGA_BITMAP_SIZE(w, h) ((((w) + 31) >> 5) * (h)) |
467 | d34cab9f | ths | #define SVGA_PIXMAP_SIZE(w, h, bpp) (((((w) * (bpp)) + 31) >> 5) * (h)) |
468 | d34cab9f | ths | |
469 | d34cab9f | ths | #ifdef HW_MOUSE_ACCEL
|
470 | d34cab9f | ths | static inline void vmsvga_cursor_define(struct vmsvga_state_s *s, |
471 | d34cab9f | ths | struct vmsvga_cursor_definition_s *c)
|
472 | d34cab9f | ths | { |
473 | d34cab9f | ths | int i;
|
474 | d34cab9f | ths | for (i = SVGA_BITMAP_SIZE(c->width, c->height) - 1; i >= 0; i --) |
475 | d34cab9f | ths | c->mask[i] = ~c->mask[i]; |
476 | d34cab9f | ths | |
477 | 4e12cd94 | Avi Kivity | if (s->vga.ds->cursor_define)
|
478 | 4e12cd94 | Avi Kivity | s->vga.ds->cursor_define(c->width, c->height, c->bpp, c->hot_x, c->hot_y, |
479 | d34cab9f | ths | (uint8_t *) c->image, (uint8_t *) c->mask); |
480 | d34cab9f | ths | } |
481 | d34cab9f | ths | #endif
|
482 | d34cab9f | ths | |
483 | ff9cf2cb | balrog | #define CMD(f) le32_to_cpu(s->cmd->f)
|
484 | ff9cf2cb | balrog | |
485 | d34cab9f | ths | static inline int vmsvga_fifo_empty(struct vmsvga_state_s *s) |
486 | d34cab9f | ths | { |
487 | d34cab9f | ths | if (!s->config || !s->enable)
|
488 | f707cfba | balrog | return 1; |
489 | d34cab9f | ths | return (s->cmd->next_cmd == s->cmd->stop);
|
490 | d34cab9f | ths | } |
491 | d34cab9f | ths | |
492 | ff9cf2cb | balrog | static inline uint32_t vmsvga_fifo_read_raw(struct vmsvga_state_s *s) |
493 | d34cab9f | ths | { |
494 | ff9cf2cb | balrog | uint32_t cmd = s->fifo[CMD(stop) >> 2];
|
495 | ff9cf2cb | balrog | s->cmd->stop = cpu_to_le32(CMD(stop) + 4);
|
496 | ff9cf2cb | balrog | if (CMD(stop) >= CMD(max))
|
497 | d34cab9f | ths | s->cmd->stop = s->cmd->min; |
498 | d34cab9f | ths | return cmd;
|
499 | d34cab9f | ths | } |
500 | d34cab9f | ths | |
501 | ff9cf2cb | balrog | static inline uint32_t vmsvga_fifo_read(struct vmsvga_state_s *s) |
502 | ff9cf2cb | balrog | { |
503 | ff9cf2cb | balrog | return le32_to_cpu(vmsvga_fifo_read_raw(s));
|
504 | ff9cf2cb | balrog | } |
505 | ff9cf2cb | balrog | |
506 | d34cab9f | ths | static void vmsvga_fifo_run(struct vmsvga_state_s *s) |
507 | d34cab9f | ths | { |
508 | d34cab9f | ths | uint32_t cmd, colour; |
509 | d34cab9f | ths | int args = 0; |
510 | d34cab9f | ths | int x, y, dx, dy, width, height;
|
511 | d34cab9f | ths | struct vmsvga_cursor_definition_s cursor;
|
512 | d34cab9f | ths | while (!vmsvga_fifo_empty(s))
|
513 | d34cab9f | ths | switch (cmd = vmsvga_fifo_read(s)) {
|
514 | d34cab9f | ths | case SVGA_CMD_UPDATE:
|
515 | d34cab9f | ths | case SVGA_CMD_UPDATE_VERBOSE:
|
516 | d34cab9f | ths | x = vmsvga_fifo_read(s); |
517 | d34cab9f | ths | y = vmsvga_fifo_read(s); |
518 | d34cab9f | ths | width = vmsvga_fifo_read(s); |
519 | d34cab9f | ths | height = vmsvga_fifo_read(s); |
520 | d34cab9f | ths | vmsvga_update_rect_delayed(s, x, y, width, height); |
521 | d34cab9f | ths | break;
|
522 | d34cab9f | ths | |
523 | d34cab9f | ths | case SVGA_CMD_RECT_FILL:
|
524 | d34cab9f | ths | colour = vmsvga_fifo_read(s); |
525 | d34cab9f | ths | x = vmsvga_fifo_read(s); |
526 | d34cab9f | ths | y = vmsvga_fifo_read(s); |
527 | d34cab9f | ths | width = vmsvga_fifo_read(s); |
528 | d34cab9f | ths | height = vmsvga_fifo_read(s); |
529 | d34cab9f | ths | #ifdef HW_FILL_ACCEL
|
530 | d34cab9f | ths | vmsvga_fill_rect(s, colour, x, y, width, height); |
531 | d34cab9f | ths | break;
|
532 | d34cab9f | ths | #else
|
533 | d34cab9f | ths | goto badcmd;
|
534 | d34cab9f | ths | #endif
|
535 | d34cab9f | ths | |
536 | d34cab9f | ths | case SVGA_CMD_RECT_COPY:
|
537 | d34cab9f | ths | x = vmsvga_fifo_read(s); |
538 | d34cab9f | ths | y = vmsvga_fifo_read(s); |
539 | d34cab9f | ths | dx = vmsvga_fifo_read(s); |
540 | d34cab9f | ths | dy = vmsvga_fifo_read(s); |
541 | d34cab9f | ths | width = vmsvga_fifo_read(s); |
542 | d34cab9f | ths | height = vmsvga_fifo_read(s); |
543 | d34cab9f | ths | #ifdef HW_RECT_ACCEL
|
544 | d34cab9f | ths | vmsvga_copy_rect(s, x, y, dx, dy, width, height); |
545 | d34cab9f | ths | break;
|
546 | d34cab9f | ths | #else
|
547 | d34cab9f | ths | goto badcmd;
|
548 | d34cab9f | ths | #endif
|
549 | d34cab9f | ths | |
550 | d34cab9f | ths | case SVGA_CMD_DEFINE_CURSOR:
|
551 | d34cab9f | ths | cursor.id = vmsvga_fifo_read(s); |
552 | d34cab9f | ths | cursor.hot_x = vmsvga_fifo_read(s); |
553 | d34cab9f | ths | cursor.hot_y = vmsvga_fifo_read(s); |
554 | d34cab9f | ths | cursor.width = x = vmsvga_fifo_read(s); |
555 | d34cab9f | ths | cursor.height = y = vmsvga_fifo_read(s); |
556 | d34cab9f | ths | vmsvga_fifo_read(s); |
557 | d34cab9f | ths | cursor.bpp = vmsvga_fifo_read(s); |
558 | d34cab9f | ths | for (args = 0; args < SVGA_BITMAP_SIZE(x, y); args ++) |
559 | ff9cf2cb | balrog | cursor.mask[args] = vmsvga_fifo_read_raw(s); |
560 | d34cab9f | ths | for (args = 0; args < SVGA_PIXMAP_SIZE(x, y, cursor.bpp); args ++) |
561 | ff9cf2cb | balrog | cursor.image[args] = vmsvga_fifo_read_raw(s); |
562 | d34cab9f | ths | #ifdef HW_MOUSE_ACCEL
|
563 | d34cab9f | ths | vmsvga_cursor_define(s, &cursor); |
564 | d34cab9f | ths | break;
|
565 | d34cab9f | ths | #else
|
566 | d34cab9f | ths | args = 0;
|
567 | d34cab9f | ths | goto badcmd;
|
568 | d34cab9f | ths | #endif
|
569 | d34cab9f | ths | |
570 | d34cab9f | ths | /*
|
571 | d34cab9f | ths | * Other commands that we at least know the number of arguments
|
572 | d34cab9f | ths | * for so we can avoid FIFO desync if driver uses them illegally.
|
573 | d34cab9f | ths | */
|
574 | d34cab9f | ths | case SVGA_CMD_DEFINE_ALPHA_CURSOR:
|
575 | d34cab9f | ths | vmsvga_fifo_read(s); |
576 | d34cab9f | ths | vmsvga_fifo_read(s); |
577 | d34cab9f | ths | vmsvga_fifo_read(s); |
578 | d34cab9f | ths | x = vmsvga_fifo_read(s); |
579 | d34cab9f | ths | y = vmsvga_fifo_read(s); |
580 | d34cab9f | ths | args = x * y; |
581 | d34cab9f | ths | goto badcmd;
|
582 | d34cab9f | ths | case SVGA_CMD_RECT_ROP_FILL:
|
583 | d34cab9f | ths | args = 6;
|
584 | d34cab9f | ths | goto badcmd;
|
585 | d34cab9f | ths | case SVGA_CMD_RECT_ROP_COPY:
|
586 | d34cab9f | ths | args = 7;
|
587 | d34cab9f | ths | goto badcmd;
|
588 | d34cab9f | ths | case SVGA_CMD_DRAW_GLYPH_CLIPPED:
|
589 | d34cab9f | ths | vmsvga_fifo_read(s); |
590 | d34cab9f | ths | vmsvga_fifo_read(s); |
591 | d34cab9f | ths | args = 7 + (vmsvga_fifo_read(s) >> 2); |
592 | d34cab9f | ths | goto badcmd;
|
593 | d34cab9f | ths | case SVGA_CMD_SURFACE_ALPHA_BLEND:
|
594 | d34cab9f | ths | args = 12;
|
595 | d34cab9f | ths | goto badcmd;
|
596 | d34cab9f | ths | |
597 | d34cab9f | ths | /*
|
598 | d34cab9f | ths | * Other commands that are not listed as depending on any
|
599 | d34cab9f | ths | * CAPABILITIES bits, but are not described in the README either.
|
600 | d34cab9f | ths | */
|
601 | d34cab9f | ths | case SVGA_CMD_SURFACE_FILL:
|
602 | d34cab9f | ths | case SVGA_CMD_SURFACE_COPY:
|
603 | d34cab9f | ths | case SVGA_CMD_FRONT_ROP_FILL:
|
604 | d34cab9f | ths | case SVGA_CMD_FENCE:
|
605 | d34cab9f | ths | case SVGA_CMD_INVALID_CMD:
|
606 | d34cab9f | ths | break; /* Nop */ |
607 | d34cab9f | ths | |
608 | d34cab9f | ths | default:
|
609 | d34cab9f | ths | badcmd:
|
610 | d34cab9f | ths | while (args --)
|
611 | d34cab9f | ths | vmsvga_fifo_read(s); |
612 | d34cab9f | ths | printf("%s: Unknown command 0x%02x in SVGA command FIFO\n",
|
613 | d34cab9f | ths | __FUNCTION__, cmd); |
614 | d34cab9f | ths | break;
|
615 | d34cab9f | ths | } |
616 | d34cab9f | ths | |
617 | d34cab9f | ths | s->syncing = 0;
|
618 | d34cab9f | ths | } |
619 | d34cab9f | ths | |
620 | d34cab9f | ths | static uint32_t vmsvga_index_read(void *opaque, uint32_t address) |
621 | d34cab9f | ths | { |
622 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
623 | d34cab9f | ths | return s->index;
|
624 | d34cab9f | ths | } |
625 | d34cab9f | ths | |
626 | d34cab9f | ths | static void vmsvga_index_write(void *opaque, uint32_t address, uint32_t index) |
627 | d34cab9f | ths | { |
628 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
629 | d34cab9f | ths | s->index = index; |
630 | d34cab9f | ths | } |
631 | d34cab9f | ths | |
632 | d34cab9f | ths | static uint32_t vmsvga_value_read(void *opaque, uint32_t address) |
633 | d34cab9f | ths | { |
634 | d34cab9f | ths | uint32_t caps; |
635 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
636 | d34cab9f | ths | switch (s->index) {
|
637 | d34cab9f | ths | case SVGA_REG_ID:
|
638 | d34cab9f | ths | return s->svgaid;
|
639 | d34cab9f | ths | |
640 | d34cab9f | ths | case SVGA_REG_ENABLE:
|
641 | d34cab9f | ths | return s->enable;
|
642 | d34cab9f | ths | |
643 | d34cab9f | ths | case SVGA_REG_WIDTH:
|
644 | d34cab9f | ths | return s->width;
|
645 | d34cab9f | ths | |
646 | d34cab9f | ths | case SVGA_REG_HEIGHT:
|
647 | d34cab9f | ths | return s->height;
|
648 | d34cab9f | ths | |
649 | d34cab9f | ths | case SVGA_REG_MAX_WIDTH:
|
650 | d34cab9f | ths | return SVGA_MAX_WIDTH;
|
651 | d34cab9f | ths | |
652 | d34cab9f | ths | case SVGA_REG_MAX_HEIGHT:
|
653 | f707cfba | balrog | return SVGA_MAX_HEIGHT;
|
654 | d34cab9f | ths | |
655 | d34cab9f | ths | case SVGA_REG_DEPTH:
|
656 | d34cab9f | ths | return s->depth;
|
657 | d34cab9f | ths | |
658 | d34cab9f | ths | case SVGA_REG_BITS_PER_PIXEL:
|
659 | d34cab9f | ths | return (s->depth + 7) & ~7; |
660 | d34cab9f | ths | |
661 | d34cab9f | ths | case SVGA_REG_PSEUDOCOLOR:
|
662 | d34cab9f | ths | return 0x0; |
663 | d34cab9f | ths | |
664 | d34cab9f | ths | case SVGA_REG_RED_MASK:
|
665 | d34cab9f | ths | return s->wred;
|
666 | d34cab9f | ths | case SVGA_REG_GREEN_MASK:
|
667 | d34cab9f | ths | return s->wgreen;
|
668 | d34cab9f | ths | case SVGA_REG_BLUE_MASK:
|
669 | d34cab9f | ths | return s->wblue;
|
670 | d34cab9f | ths | |
671 | d34cab9f | ths | case SVGA_REG_BYTES_PER_LINE:
|
672 | d34cab9f | ths | return ((s->depth + 7) >> 3) * s->new_width; |
673 | d34cab9f | ths | |
674 | d34cab9f | ths | case SVGA_REG_FB_START:
|
675 | 3016d80b | balrog | return s->vram_base;
|
676 | d34cab9f | ths | |
677 | d34cab9f | ths | case SVGA_REG_FB_OFFSET:
|
678 | d34cab9f | ths | return 0x0; |
679 | d34cab9f | ths | |
680 | d34cab9f | ths | case SVGA_REG_VRAM_SIZE:
|
681 | 4e12cd94 | Avi Kivity | return s->vga.vram_size - SVGA_FIFO_SIZE;
|
682 | d34cab9f | ths | |
683 | d34cab9f | ths | case SVGA_REG_FB_SIZE:
|
684 | d34cab9f | ths | return s->fb_size;
|
685 | d34cab9f | ths | |
686 | d34cab9f | ths | case SVGA_REG_CAPABILITIES:
|
687 | d34cab9f | ths | caps = SVGA_CAP_NONE; |
688 | d34cab9f | ths | #ifdef HW_RECT_ACCEL
|
689 | d34cab9f | ths | caps |= SVGA_CAP_RECT_COPY; |
690 | d34cab9f | ths | #endif
|
691 | d34cab9f | ths | #ifdef HW_FILL_ACCEL
|
692 | d34cab9f | ths | caps |= SVGA_CAP_RECT_FILL; |
693 | d34cab9f | ths | #endif
|
694 | d34cab9f | ths | #ifdef HW_MOUSE_ACCEL
|
695 | 4e12cd94 | Avi Kivity | if (s->vga.ds->mouse_set)
|
696 | d34cab9f | ths | caps |= SVGA_CAP_CURSOR | SVGA_CAP_CURSOR_BYPASS_2 | |
697 | d34cab9f | ths | SVGA_CAP_CURSOR_BYPASS; |
698 | d34cab9f | ths | #endif
|
699 | d34cab9f | ths | return caps;
|
700 | d34cab9f | ths | |
701 | d34cab9f | ths | case SVGA_REG_MEM_START:
|
702 | 4e12cd94 | Avi Kivity | return s->vram_base + s->vga.vram_size - SVGA_FIFO_SIZE;
|
703 | d34cab9f | ths | |
704 | d34cab9f | ths | case SVGA_REG_MEM_SIZE:
|
705 | d34cab9f | ths | return SVGA_FIFO_SIZE;
|
706 | d34cab9f | ths | |
707 | d34cab9f | ths | case SVGA_REG_CONFIG_DONE:
|
708 | d34cab9f | ths | return s->config;
|
709 | d34cab9f | ths | |
710 | d34cab9f | ths | case SVGA_REG_SYNC:
|
711 | d34cab9f | ths | case SVGA_REG_BUSY:
|
712 | d34cab9f | ths | return s->syncing;
|
713 | d34cab9f | ths | |
714 | d34cab9f | ths | case SVGA_REG_GUEST_ID:
|
715 | d34cab9f | ths | return s->guest;
|
716 | d34cab9f | ths | |
717 | d34cab9f | ths | case SVGA_REG_CURSOR_ID:
|
718 | d34cab9f | ths | return s->cursor.id;
|
719 | d34cab9f | ths | |
720 | d34cab9f | ths | case SVGA_REG_CURSOR_X:
|
721 | d34cab9f | ths | return s->cursor.x;
|
722 | d34cab9f | ths | |
723 | d34cab9f | ths | case SVGA_REG_CURSOR_Y:
|
724 | d34cab9f | ths | return s->cursor.x;
|
725 | d34cab9f | ths | |
726 | d34cab9f | ths | case SVGA_REG_CURSOR_ON:
|
727 | d34cab9f | ths | return s->cursor.on;
|
728 | d34cab9f | ths | |
729 | d34cab9f | ths | case SVGA_REG_HOST_BITS_PER_PIXEL:
|
730 | d34cab9f | ths | return (s->depth + 7) & ~7; |
731 | d34cab9f | ths | |
732 | d34cab9f | ths | case SVGA_REG_SCRATCH_SIZE:
|
733 | d34cab9f | ths | return s->scratch_size;
|
734 | d34cab9f | ths | |
735 | d34cab9f | ths | case SVGA_REG_MEM_REGS:
|
736 | d34cab9f | ths | case SVGA_REG_NUM_DISPLAYS:
|
737 | d34cab9f | ths | case SVGA_REG_PITCHLOCK:
|
738 | d34cab9f | ths | case SVGA_PALETTE_BASE ... SVGA_PALETTE_END:
|
739 | d34cab9f | ths | return 0; |
740 | d34cab9f | ths | |
741 | d34cab9f | ths | default:
|
742 | d34cab9f | ths | if (s->index >= SVGA_SCRATCH_BASE &&
|
743 | d34cab9f | ths | s->index < SVGA_SCRATCH_BASE + s->scratch_size) |
744 | d34cab9f | ths | return s->scratch[s->index - SVGA_SCRATCH_BASE];
|
745 | d34cab9f | ths | printf("%s: Bad register %02x\n", __FUNCTION__, s->index);
|
746 | d34cab9f | ths | } |
747 | d34cab9f | ths | |
748 | d34cab9f | ths | return 0; |
749 | d34cab9f | ths | } |
750 | d34cab9f | ths | |
751 | d34cab9f | ths | static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value) |
752 | d34cab9f | ths | { |
753 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
754 | d34cab9f | ths | switch (s->index) {
|
755 | d34cab9f | ths | case SVGA_REG_ID:
|
756 | d34cab9f | ths | if (value == SVGA_ID_2 || value == SVGA_ID_1 || value == SVGA_ID_0)
|
757 | d34cab9f | ths | s->svgaid = value; |
758 | d34cab9f | ths | break;
|
759 | d34cab9f | ths | |
760 | d34cab9f | ths | case SVGA_REG_ENABLE:
|
761 | f707cfba | balrog | s->enable = value; |
762 | f707cfba | balrog | s->config &= !!value; |
763 | d34cab9f | ths | s->width = -1;
|
764 | d34cab9f | ths | s->height = -1;
|
765 | d34cab9f | ths | s->invalidated = 1;
|
766 | 4e12cd94 | Avi Kivity | s->vga.invalidate(&s->vga); |
767 | d34cab9f | ths | if (s->enable)
|
768 | d34cab9f | ths | s->fb_size = ((s->depth + 7) >> 3) * s->new_width * s->new_height; |
769 | d34cab9f | ths | break;
|
770 | d34cab9f | ths | |
771 | d34cab9f | ths | case SVGA_REG_WIDTH:
|
772 | d34cab9f | ths | s->new_width = value; |
773 | d34cab9f | ths | s->invalidated = 1;
|
774 | d34cab9f | ths | break;
|
775 | d34cab9f | ths | |
776 | d34cab9f | ths | case SVGA_REG_HEIGHT:
|
777 | d34cab9f | ths | s->new_height = value; |
778 | d34cab9f | ths | s->invalidated = 1;
|
779 | d34cab9f | ths | break;
|
780 | d34cab9f | ths | |
781 | d34cab9f | ths | case SVGA_REG_DEPTH:
|
782 | d34cab9f | ths | case SVGA_REG_BITS_PER_PIXEL:
|
783 | d34cab9f | ths | if (value != s->depth) {
|
784 | d34cab9f | ths | printf("%s: Bad colour depth: %i bits\n", __FUNCTION__, value);
|
785 | d34cab9f | ths | s->config = 0;
|
786 | d34cab9f | ths | } |
787 | d34cab9f | ths | break;
|
788 | d34cab9f | ths | |
789 | d34cab9f | ths | case SVGA_REG_CONFIG_DONE:
|
790 | d34cab9f | ths | if (value) {
|
791 | 4e12cd94 | Avi Kivity | s->fifo = (uint32_t *) &s->vga.vram_ptr[s->vga.vram_size - SVGA_FIFO_SIZE]; |
792 | d34cab9f | ths | /* Check range and alignment. */
|
793 | ff9cf2cb | balrog | if ((CMD(min) | CMD(max) |
|
794 | ff9cf2cb | balrog | CMD(next_cmd) | CMD(stop)) & 3)
|
795 | d34cab9f | ths | break;
|
796 | ff9cf2cb | balrog | if (CMD(min) < (uint8_t *) s->cmd->fifo - (uint8_t *) s->fifo)
|
797 | d34cab9f | ths | break;
|
798 | ff9cf2cb | balrog | if (CMD(max) > SVGA_FIFO_SIZE)
|
799 | d34cab9f | ths | break;
|
800 | ff9cf2cb | balrog | if (CMD(max) < CMD(min) + 10 * 1024) |
801 | d34cab9f | ths | break;
|
802 | d34cab9f | ths | } |
803 | f707cfba | balrog | s->config = !!value; |
804 | d34cab9f | ths | break;
|
805 | d34cab9f | ths | |
806 | d34cab9f | ths | case SVGA_REG_SYNC:
|
807 | d34cab9f | ths | s->syncing = 1;
|
808 | d34cab9f | ths | vmsvga_fifo_run(s); /* Or should we just wait for update_display? */
|
809 | d34cab9f | ths | break;
|
810 | d34cab9f | ths | |
811 | d34cab9f | ths | case SVGA_REG_GUEST_ID:
|
812 | d34cab9f | ths | s->guest = value; |
813 | d34cab9f | ths | #ifdef VERBOSE
|
814 | d34cab9f | ths | if (value >= GUEST_OS_BASE && value < GUEST_OS_BASE +
|
815 | b1503cda | malc | ARRAY_SIZE(vmsvga_guest_id)) |
816 | d34cab9f | ths | printf("%s: guest runs %s.\n", __FUNCTION__,
|
817 | d34cab9f | ths | vmsvga_guest_id[value - GUEST_OS_BASE]); |
818 | d34cab9f | ths | #endif
|
819 | d34cab9f | ths | break;
|
820 | d34cab9f | ths | |
821 | d34cab9f | ths | case SVGA_REG_CURSOR_ID:
|
822 | d34cab9f | ths | s->cursor.id = value; |
823 | d34cab9f | ths | break;
|
824 | d34cab9f | ths | |
825 | d34cab9f | ths | case SVGA_REG_CURSOR_X:
|
826 | d34cab9f | ths | s->cursor.x = value; |
827 | d34cab9f | ths | break;
|
828 | d34cab9f | ths | |
829 | d34cab9f | ths | case SVGA_REG_CURSOR_Y:
|
830 | d34cab9f | ths | s->cursor.y = value; |
831 | d34cab9f | ths | break;
|
832 | d34cab9f | ths | |
833 | d34cab9f | ths | case SVGA_REG_CURSOR_ON:
|
834 | d34cab9f | ths | s->cursor.on |= (value == SVGA_CURSOR_ON_SHOW); |
835 | d34cab9f | ths | s->cursor.on &= (value != SVGA_CURSOR_ON_HIDE); |
836 | d34cab9f | ths | #ifdef HW_MOUSE_ACCEL
|
837 | 4e12cd94 | Avi Kivity | if (s->vga.ds->mouse_set && value <= SVGA_CURSOR_ON_SHOW)
|
838 | 4e12cd94 | Avi Kivity | s->vga.ds->mouse_set(s->cursor.x, s->cursor.y, s->cursor.on); |
839 | d34cab9f | ths | #endif
|
840 | d34cab9f | ths | break;
|
841 | d34cab9f | ths | |
842 | d34cab9f | ths | case SVGA_REG_MEM_REGS:
|
843 | d34cab9f | ths | case SVGA_REG_NUM_DISPLAYS:
|
844 | d34cab9f | ths | case SVGA_REG_PITCHLOCK:
|
845 | d34cab9f | ths | case SVGA_PALETTE_BASE ... SVGA_PALETTE_END:
|
846 | d34cab9f | ths | break;
|
847 | d34cab9f | ths | |
848 | d34cab9f | ths | default:
|
849 | d34cab9f | ths | if (s->index >= SVGA_SCRATCH_BASE &&
|
850 | d34cab9f | ths | s->index < SVGA_SCRATCH_BASE + s->scratch_size) { |
851 | d34cab9f | ths | s->scratch[s->index - SVGA_SCRATCH_BASE] = value; |
852 | d34cab9f | ths | break;
|
853 | d34cab9f | ths | } |
854 | d34cab9f | ths | printf("%s: Bad register %02x\n", __FUNCTION__, s->index);
|
855 | d34cab9f | ths | } |
856 | d34cab9f | ths | } |
857 | d34cab9f | ths | |
858 | d34cab9f | ths | static uint32_t vmsvga_bios_read(void *opaque, uint32_t address) |
859 | d34cab9f | ths | { |
860 | d34cab9f | ths | printf("%s: what are we supposed to return?\n", __FUNCTION__);
|
861 | d34cab9f | ths | return 0xcafe; |
862 | d34cab9f | ths | } |
863 | d34cab9f | ths | |
864 | d34cab9f | ths | static void vmsvga_bios_write(void *opaque, uint32_t address, uint32_t data) |
865 | d34cab9f | ths | { |
866 | d34cab9f | ths | printf("%s: what are we supposed to do with (%08x)?\n",
|
867 | d34cab9f | ths | __FUNCTION__, data); |
868 | d34cab9f | ths | } |
869 | d34cab9f | ths | |
870 | d34cab9f | ths | static inline void vmsvga_size(struct vmsvga_state_s *s) |
871 | d34cab9f | ths | { |
872 | d34cab9f | ths | if (s->new_width != s->width || s->new_height != s->height) {
|
873 | d34cab9f | ths | s->width = s->new_width; |
874 | d34cab9f | ths | s->height = s->new_height; |
875 | 4e12cd94 | Avi Kivity | qemu_console_resize(s->vga.ds, s->width, s->height); |
876 | d34cab9f | ths | s->invalidated = 1;
|
877 | d34cab9f | ths | } |
878 | d34cab9f | ths | } |
879 | d34cab9f | ths | |
880 | d34cab9f | ths | static void vmsvga_update_display(void *opaque) |
881 | d34cab9f | ths | { |
882 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
883 | d34cab9f | ths | if (!s->enable) {
|
884 | 4e12cd94 | Avi Kivity | s->vga.update(&s->vga); |
885 | d34cab9f | ths | return;
|
886 | d34cab9f | ths | } |
887 | d34cab9f | ths | |
888 | d34cab9f | ths | vmsvga_size(s); |
889 | d34cab9f | ths | |
890 | d34cab9f | ths | vmsvga_fifo_run(s); |
891 | d34cab9f | ths | vmsvga_update_rect_flush(s); |
892 | d34cab9f | ths | |
893 | d34cab9f | ths | /*
|
894 | d34cab9f | ths | * Is it more efficient to look at vram VGA-dirty bits or wait
|
895 | d34cab9f | ths | * for the driver to issue SVGA_CMD_UPDATE?
|
896 | d34cab9f | ths | */
|
897 | d34cab9f | ths | if (s->invalidated) {
|
898 | d34cab9f | ths | s->invalidated = 0;
|
899 | d34cab9f | ths | vmsvga_update_screen(s); |
900 | d34cab9f | ths | } |
901 | d34cab9f | ths | } |
902 | d34cab9f | ths | |
903 | d34cab9f | ths | static void vmsvga_reset(struct vmsvga_state_s *s) |
904 | d34cab9f | ths | { |
905 | d34cab9f | ths | s->index = 0;
|
906 | d34cab9f | ths | s->enable = 0;
|
907 | d34cab9f | ths | s->config = 0;
|
908 | d34cab9f | ths | s->width = -1;
|
909 | d34cab9f | ths | s->height = -1;
|
910 | d34cab9f | ths | s->svgaid = SVGA_ID; |
911 | 4445b0a6 | Andrzej Zaborowski | s->depth = 24;
|
912 | d34cab9f | ths | s->bypp = (s->depth + 7) >> 3; |
913 | d34cab9f | ths | s->cursor.on = 0;
|
914 | d34cab9f | ths | s->redraw_fifo_first = 0;
|
915 | d34cab9f | ths | s->redraw_fifo_last = 0;
|
916 | d34cab9f | ths | switch (s->depth) {
|
917 | d34cab9f | ths | case 8: |
918 | d34cab9f | ths | s->wred = 0x00000007;
|
919 | d34cab9f | ths | s->wgreen = 0x00000038;
|
920 | d34cab9f | ths | s->wblue = 0x000000c0;
|
921 | d34cab9f | ths | break;
|
922 | d34cab9f | ths | case 15: |
923 | d34cab9f | ths | s->wred = 0x0000001f;
|
924 | d34cab9f | ths | s->wgreen = 0x000003e0;
|
925 | d34cab9f | ths | s->wblue = 0x00007c00;
|
926 | d34cab9f | ths | break;
|
927 | d34cab9f | ths | case 16: |
928 | d34cab9f | ths | s->wred = 0x0000001f;
|
929 | d34cab9f | ths | s->wgreen = 0x000007e0;
|
930 | d34cab9f | ths | s->wblue = 0x0000f800;
|
931 | d34cab9f | ths | break;
|
932 | d34cab9f | ths | case 24: |
933 | f707cfba | balrog | s->wred = 0x00ff0000;
|
934 | d34cab9f | ths | s->wgreen = 0x0000ff00;
|
935 | f707cfba | balrog | s->wblue = 0x000000ff;
|
936 | d34cab9f | ths | break;
|
937 | d34cab9f | ths | case 32: |
938 | f707cfba | balrog | s->wred = 0x00ff0000;
|
939 | d34cab9f | ths | s->wgreen = 0x0000ff00;
|
940 | f707cfba | balrog | s->wblue = 0x000000ff;
|
941 | d34cab9f | ths | break;
|
942 | d34cab9f | ths | } |
943 | d34cab9f | ths | s->syncing = 0;
|
944 | d34cab9f | ths | } |
945 | d34cab9f | ths | |
946 | d34cab9f | ths | static void vmsvga_invalidate_display(void *opaque) |
947 | d34cab9f | ths | { |
948 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
949 | d34cab9f | ths | if (!s->enable) {
|
950 | 4e12cd94 | Avi Kivity | s->vga.invalidate(&s->vga); |
951 | d34cab9f | ths | return;
|
952 | d34cab9f | ths | } |
953 | d34cab9f | ths | |
954 | d34cab9f | ths | s->invalidated = 1;
|
955 | d34cab9f | ths | } |
956 | d34cab9f | ths | |
957 | f707cfba | balrog | /* save the vga display in a PPM image even if no display is
|
958 | f707cfba | balrog | available */
|
959 | d34cab9f | ths | static void vmsvga_screen_dump(void *opaque, const char *filename) |
960 | d34cab9f | ths | { |
961 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
962 | d34cab9f | ths | if (!s->enable) {
|
963 | 4e12cd94 | Avi Kivity | s->vga.screen_dump(&s->vga, filename); |
964 | d34cab9f | ths | return;
|
965 | d34cab9f | ths | } |
966 | d34cab9f | ths | |
967 | f707cfba | balrog | if (s->depth == 32) { |
968 | e07d630a | aliguori | DisplaySurface *ds = qemu_create_displaysurface_from(s->width, |
969 | 4e12cd94 | Avi Kivity | s->height, 32, ds_get_linesize(s->vga.ds), s->vga.vram_ptr);
|
970 | e07d630a | aliguori | ppm_save(filename, ds); |
971 | e07d630a | aliguori | qemu_free(ds); |
972 | f707cfba | balrog | } |
973 | d34cab9f | ths | } |
974 | d34cab9f | ths | |
975 | c227f099 | Anthony Liguori | static void vmsvga_text_update(void *opaque, console_ch_t *chardata) |
976 | 4d3b6f6e | balrog | { |
977 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
978 | 4d3b6f6e | balrog | |
979 | 4e12cd94 | Avi Kivity | if (s->vga.text_update)
|
980 | 4e12cd94 | Avi Kivity | s->vga.text_update(&s->vga, chardata); |
981 | 4d3b6f6e | balrog | } |
982 | 4d3b6f6e | balrog | |
983 | d34cab9f | ths | #ifdef DIRECT_VRAM
|
984 | c227f099 | Anthony Liguori | static uint32_t vmsvga_vram_readb(void *opaque, target_phys_addr_t addr) |
985 | d34cab9f | ths | { |
986 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
987 | d34cab9f | ths | if (addr < s->fb_size)
|
988 | 0e1f5a0c | aliguori | return *(uint8_t *) (ds_get_data(s->ds) + addr);
|
989 | d34cab9f | ths | else
|
990 | b584726d | pbrook | return *(uint8_t *) (s->vram_ptr + addr);
|
991 | d34cab9f | ths | } |
992 | d34cab9f | ths | |
993 | c227f099 | Anthony Liguori | static uint32_t vmsvga_vram_readw(void *opaque, target_phys_addr_t addr) |
994 | d34cab9f | ths | { |
995 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
996 | d34cab9f | ths | if (addr < s->fb_size)
|
997 | 0e1f5a0c | aliguori | return *(uint16_t *) (ds_get_data(s->ds) + addr);
|
998 | d34cab9f | ths | else
|
999 | b584726d | pbrook | return *(uint16_t *) (s->vram_ptr + addr);
|
1000 | d34cab9f | ths | } |
1001 | d34cab9f | ths | |
1002 | c227f099 | Anthony Liguori | static uint32_t vmsvga_vram_readl(void *opaque, target_phys_addr_t addr) |
1003 | d34cab9f | ths | { |
1004 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
1005 | d34cab9f | ths | if (addr < s->fb_size)
|
1006 | 0e1f5a0c | aliguori | return *(uint32_t *) (ds_get_data(s->ds) + addr);
|
1007 | d34cab9f | ths | else
|
1008 | b584726d | pbrook | return *(uint32_t *) (s->vram_ptr + addr);
|
1009 | d34cab9f | ths | } |
1010 | d34cab9f | ths | |
1011 | c227f099 | Anthony Liguori | static void vmsvga_vram_writeb(void *opaque, target_phys_addr_t addr, |
1012 | d34cab9f | ths | uint32_t value) |
1013 | d34cab9f | ths | { |
1014 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
1015 | d34cab9f | ths | if (addr < s->fb_size)
|
1016 | 0e1f5a0c | aliguori | *(uint8_t *) (ds_get_data(s->ds) + addr) = value; |
1017 | d34cab9f | ths | else
|
1018 | b584726d | pbrook | *(uint8_t *) (s->vram_ptr + addr) = value; |
1019 | d34cab9f | ths | } |
1020 | d34cab9f | ths | |
1021 | c227f099 | Anthony Liguori | static void vmsvga_vram_writew(void *opaque, target_phys_addr_t addr, |
1022 | d34cab9f | ths | uint32_t value) |
1023 | d34cab9f | ths | { |
1024 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
1025 | d34cab9f | ths | if (addr < s->fb_size)
|
1026 | 0e1f5a0c | aliguori | *(uint16_t *) (ds_get_data(s->ds) + addr) = value; |
1027 | d34cab9f | ths | else
|
1028 | b584726d | pbrook | *(uint16_t *) (s->vram_ptr + addr) = value; |
1029 | d34cab9f | ths | } |
1030 | d34cab9f | ths | |
1031 | c227f099 | Anthony Liguori | static void vmsvga_vram_writel(void *opaque, target_phys_addr_t addr, |
1032 | d34cab9f | ths | uint32_t value) |
1033 | d34cab9f | ths | { |
1034 | 467d44b2 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
1035 | d34cab9f | ths | if (addr < s->fb_size)
|
1036 | 0e1f5a0c | aliguori | *(uint32_t *) (ds_get_data(s->ds) + addr) = value; |
1037 | d34cab9f | ths | else
|
1038 | b584726d | pbrook | *(uint32_t *) (s->vram_ptr + addr) = value; |
1039 | d34cab9f | ths | } |
1040 | d34cab9f | ths | |
1041 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const vmsvga_vram_read[] = { |
1042 | d34cab9f | ths | vmsvga_vram_readb, |
1043 | d34cab9f | ths | vmsvga_vram_readw, |
1044 | d34cab9f | ths | vmsvga_vram_readl, |
1045 | d34cab9f | ths | }; |
1046 | d34cab9f | ths | |
1047 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const vmsvga_vram_write[] = { |
1048 | d34cab9f | ths | vmsvga_vram_writeb, |
1049 | d34cab9f | ths | vmsvga_vram_writew, |
1050 | d34cab9f | ths | vmsvga_vram_writel, |
1051 | d34cab9f | ths | }; |
1052 | d34cab9f | ths | #endif
|
1053 | d34cab9f | ths | |
1054 | bacbe284 | Juan Quintela | static int vmsvga_post_load(void *opaque, int version_id) |
1055 | d34cab9f | ths | { |
1056 | bacbe284 | Juan Quintela | struct vmsvga_state_s *s = opaque;
|
1057 | d34cab9f | ths | |
1058 | d34cab9f | ths | s->invalidated = 1;
|
1059 | d34cab9f | ths | if (s->config)
|
1060 | 4e12cd94 | Avi Kivity | s->fifo = (uint32_t *) &s->vga.vram_ptr[s->vga.vram_size - SVGA_FIFO_SIZE]; |
1061 | d34cab9f | ths | |
1062 | d34cab9f | ths | return 0; |
1063 | d34cab9f | ths | } |
1064 | d34cab9f | ths | |
1065 | bacbe284 | Juan Quintela | const VMStateDescription vmstate_vmware_vga_internal = {
|
1066 | bacbe284 | Juan Quintela | .name = "vmware_vga_internal",
|
1067 | bacbe284 | Juan Quintela | .version_id = 0,
|
1068 | bacbe284 | Juan Quintela | .minimum_version_id = 0,
|
1069 | bacbe284 | Juan Quintela | .minimum_version_id_old = 0,
|
1070 | bacbe284 | Juan Quintela | .post_load = vmsvga_post_load, |
1071 | bacbe284 | Juan Quintela | .fields = (VMStateField []) { |
1072 | bacbe284 | Juan Quintela | VMSTATE_INT32_EQUAL(depth, struct vmsvga_state_s),
|
1073 | bacbe284 | Juan Quintela | VMSTATE_INT32(enable, struct vmsvga_state_s),
|
1074 | bacbe284 | Juan Quintela | VMSTATE_INT32(config, struct vmsvga_state_s),
|
1075 | bacbe284 | Juan Quintela | VMSTATE_INT32(cursor.id, struct vmsvga_state_s),
|
1076 | bacbe284 | Juan Quintela | VMSTATE_INT32(cursor.x, struct vmsvga_state_s),
|
1077 | bacbe284 | Juan Quintela | VMSTATE_INT32(cursor.y, struct vmsvga_state_s),
|
1078 | bacbe284 | Juan Quintela | VMSTATE_INT32(cursor.on, struct vmsvga_state_s),
|
1079 | bacbe284 | Juan Quintela | VMSTATE_INT32(index, struct vmsvga_state_s),
|
1080 | bacbe284 | Juan Quintela | VMSTATE_VARRAY_INT32(scratch, struct vmsvga_state_s,
|
1081 | bacbe284 | Juan Quintela | scratch_size, 0, vmstate_info_uint32, uint32_t),
|
1082 | bacbe284 | Juan Quintela | VMSTATE_INT32(new_width, struct vmsvga_state_s),
|
1083 | bacbe284 | Juan Quintela | VMSTATE_INT32(new_height, struct vmsvga_state_s),
|
1084 | bacbe284 | Juan Quintela | VMSTATE_UINT32(guest, struct vmsvga_state_s),
|
1085 | bacbe284 | Juan Quintela | VMSTATE_UINT32(svgaid, struct vmsvga_state_s),
|
1086 | bacbe284 | Juan Quintela | VMSTATE_INT32(syncing, struct vmsvga_state_s),
|
1087 | bacbe284 | Juan Quintela | VMSTATE_INT32(fb_size, struct vmsvga_state_s),
|
1088 | bacbe284 | Juan Quintela | VMSTATE_END_OF_LIST() |
1089 | bacbe284 | Juan Quintela | } |
1090 | bacbe284 | Juan Quintela | }; |
1091 | bacbe284 | Juan Quintela | |
1092 | bacbe284 | Juan Quintela | const VMStateDescription vmstate_vmware_vga = {
|
1093 | bacbe284 | Juan Quintela | .name = "vmware_vga",
|
1094 | bacbe284 | Juan Quintela | .version_id = 0,
|
1095 | bacbe284 | Juan Quintela | .minimum_version_id = 0,
|
1096 | bacbe284 | Juan Quintela | .minimum_version_id_old = 0,
|
1097 | bacbe284 | Juan Quintela | .fields = (VMStateField []) { |
1098 | bacbe284 | Juan Quintela | VMSTATE_PCI_DEVICE(card, struct pci_vmsvga_state_s),
|
1099 | bacbe284 | Juan Quintela | VMSTATE_STRUCT(chip, struct pci_vmsvga_state_s, 0, |
1100 | bacbe284 | Juan Quintela | vmstate_vmware_vga_internal, struct vmsvga_state_s),
|
1101 | bacbe284 | Juan Quintela | VMSTATE_END_OF_LIST() |
1102 | bacbe284 | Juan Quintela | } |
1103 | bacbe284 | Juan Quintela | }; |
1104 | bacbe284 | Juan Quintela | |
1105 | b584726d | pbrook | static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size) |
1106 | d34cab9f | ths | { |
1107 | d34cab9f | ths | s->scratch_size = SVGA_SCRATCH_SIZE; |
1108 | fe740c43 | Juan Quintela | s->scratch = qemu_malloc(s->scratch_size * 4);
|
1109 | d34cab9f | ths | |
1110 | 4445b0a6 | Andrzej Zaborowski | vmsvga_reset(s); |
1111 | 4445b0a6 | Andrzej Zaborowski | |
1112 | a4a2f59c | Juan Quintela | vga_common_init(&s->vga, vga_ram_size); |
1113 | a4a2f59c | Juan Quintela | vga_init(&s->vga); |
1114 | f74599c4 | Juan Quintela | vmstate_register(0, &vmstate_vga_common, &s->vga);
|
1115 | e93a5f4f | balrog | |
1116 | 4e12cd94 | Avi Kivity | s->vga.ds = graphic_console_init(vmsvga_update_display, |
1117 | 4e12cd94 | Avi Kivity | vmsvga_invalidate_display, |
1118 | 4e12cd94 | Avi Kivity | vmsvga_screen_dump, |
1119 | c89507f7 | Juan Quintela | vmsvga_text_update, s); |
1120 | 931ea435 | balrog | |
1121 | 931ea435 | balrog | #ifdef CONFIG_BOCHS_VBE
|
1122 | 931ea435 | balrog | /* XXX: use optimized standard vga accesses */
|
1123 | 931ea435 | balrog | cpu_register_physical_memory(VBE_DISPI_LFB_PHYSICAL_ADDRESS, |
1124 | 4e12cd94 | Avi Kivity | vga_ram_size, s->vga.vram_offset); |
1125 | 931ea435 | balrog | #endif
|
1126 | d34cab9f | ths | } |
1127 | d34cab9f | ths | |
1128 | 1492a3c4 | balrog | static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num, |
1129 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
1130 | 1492a3c4 | balrog | { |
1131 | 1492a3c4 | balrog | struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev; |
1132 | 1492a3c4 | balrog | struct vmsvga_state_s *s = &d->chip;
|
1133 | 1492a3c4 | balrog | |
1134 | 1492a3c4 | balrog | register_ioport_read(addr + SVGA_IO_MUL * SVGA_INDEX_PORT, |
1135 | 1492a3c4 | balrog | 1, 4, vmsvga_index_read, s); |
1136 | 1492a3c4 | balrog | register_ioport_write(addr + SVGA_IO_MUL * SVGA_INDEX_PORT, |
1137 | 1492a3c4 | balrog | 1, 4, vmsvga_index_write, s); |
1138 | 1492a3c4 | balrog | register_ioport_read(addr + SVGA_IO_MUL * SVGA_VALUE_PORT, |
1139 | 1492a3c4 | balrog | 1, 4, vmsvga_value_read, s); |
1140 | 1492a3c4 | balrog | register_ioport_write(addr + SVGA_IO_MUL * SVGA_VALUE_PORT, |
1141 | 1492a3c4 | balrog | 1, 4, vmsvga_value_write, s); |
1142 | 1492a3c4 | balrog | register_ioport_read(addr + SVGA_IO_MUL * SVGA_BIOS_PORT, |
1143 | 1492a3c4 | balrog | 1, 4, vmsvga_bios_read, s); |
1144 | 1492a3c4 | balrog | register_ioport_write(addr + SVGA_IO_MUL * SVGA_BIOS_PORT, |
1145 | 1492a3c4 | balrog | 1, 4, vmsvga_bios_write, s); |
1146 | 1492a3c4 | balrog | } |
1147 | 1492a3c4 | balrog | |
1148 | 3016d80b | balrog | static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num, |
1149 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
1150 | 3016d80b | balrog | { |
1151 | 3016d80b | balrog | struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev; |
1152 | 3016d80b | balrog | struct vmsvga_state_s *s = &d->chip;
|
1153 | c227f099 | Anthony Liguori | ram_addr_t iomemtype; |
1154 | 3016d80b | balrog | |
1155 | 3016d80b | balrog | s->vram_base = addr; |
1156 | 3016d80b | balrog | #ifdef DIRECT_VRAM
|
1157 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(vmsvga_vram_read, |
1158 | 3016d80b | balrog | vmsvga_vram_write, s); |
1159 | 3016d80b | balrog | #else
|
1160 | 4e12cd94 | Avi Kivity | iomemtype = s->vga.vram_offset | IO_MEM_RAM; |
1161 | 3016d80b | balrog | #endif
|
1162 | 4e12cd94 | Avi Kivity | cpu_register_physical_memory(s->vram_base, s->vga.vram_size, |
1163 | 3016d80b | balrog | iomemtype); |
1164 | 3016d80b | balrog | } |
1165 | 3016d80b | balrog | |
1166 | 81a322d4 | Gerd Hoffmann | static int pci_vmsvga_initfn(PCIDevice *dev) |
1167 | d34cab9f | ths | { |
1168 | a414c306 | Gerd Hoffmann | struct pci_vmsvga_state_s *s =
|
1169 | a414c306 | Gerd Hoffmann | DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
|
1170 | d34cab9f | ths | |
1171 | deb54399 | aliguori | pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE); |
1172 | deb54399 | aliguori | pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID); |
1173 | d34cab9f | ths | s->card.config[PCI_COMMAND] = 0x07; /* I/O + Memory */ |
1174 | 173a543b | blueswir1 | pci_config_set_class(s->card.config, PCI_CLASS_DISPLAY_VGA); |
1175 | d34cab9f | ths | s->card.config[0x0c] = 0x08; /* Cache line size */ |
1176 | d34cab9f | ths | s->card.config[0x0d] = 0x40; /* Latency timer */ |
1177 | 6407f373 | Isaku Yamahata | s->card.config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; |
1178 | d34cab9f | ths | s->card.config[0x2c] = PCI_VENDOR_ID_VMWARE & 0xff; |
1179 | d34cab9f | ths | s->card.config[0x2d] = PCI_VENDOR_ID_VMWARE >> 8; |
1180 | d34cab9f | ths | s->card.config[0x2e] = SVGA_PCI_DEVICE_ID & 0xff; |
1181 | d34cab9f | ths | s->card.config[0x2f] = SVGA_PCI_DEVICE_ID >> 8; |
1182 | d34cab9f | ths | s->card.config[0x3c] = 0xff; /* End */ |
1183 | d34cab9f | ths | |
1184 | 28c2c264 | Avi Kivity | pci_register_bar(&s->card, 0, 0x10, |
1185 | 0392a017 | Isaku Yamahata | PCI_BASE_ADDRESS_SPACE_IO, pci_vmsvga_map_ioport); |
1186 | 28c2c264 | Avi Kivity | pci_register_bar(&s->card, 1, VGA_RAM_SIZE,
|
1187 | 0392a017 | Isaku Yamahata | PCI_BASE_ADDRESS_MEM_PREFETCH, pci_vmsvga_map_mem); |
1188 | 1492a3c4 | balrog | |
1189 | fbe1b595 | Paul Brook | vmsvga_init(&s->chip, VGA_RAM_SIZE); |
1190 | d34cab9f | ths | |
1191 | bacbe284 | Juan Quintela | vmstate_register(0, &vmstate_vmware_vga, s);
|
1192 | 81a322d4 | Gerd Hoffmann | return 0; |
1193 | d34cab9f | ths | } |
1194 | a414c306 | Gerd Hoffmann | |
1195 | a414c306 | Gerd Hoffmann | void pci_vmsvga_init(PCIBus *bus)
|
1196 | a414c306 | Gerd Hoffmann | { |
1197 | a414c306 | Gerd Hoffmann | pci_create_simple(bus, -1, "QEMUware SVGA"); |
1198 | a414c306 | Gerd Hoffmann | } |
1199 | a414c306 | Gerd Hoffmann | |
1200 | a414c306 | Gerd Hoffmann | static PCIDeviceInfo vmsvga_info = {
|
1201 | a414c306 | Gerd Hoffmann | .qdev.name = "QEMUware SVGA",
|
1202 | a414c306 | Gerd Hoffmann | .qdev.size = sizeof(struct pci_vmsvga_state_s), |
1203 | a414c306 | Gerd Hoffmann | .init = pci_vmsvga_initfn, |
1204 | a414c306 | Gerd Hoffmann | }; |
1205 | a414c306 | Gerd Hoffmann | |
1206 | a414c306 | Gerd Hoffmann | static void vmsvga_register(void) |
1207 | a414c306 | Gerd Hoffmann | { |
1208 | a414c306 | Gerd Hoffmann | pci_qdev_register(&vmsvga_info); |
1209 | a414c306 | Gerd Hoffmann | } |
1210 | a414c306 | Gerd Hoffmann | device_init(vmsvga_register); |