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