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