VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA.h@ 24213

Last change on this file since 24213 was 24053, checked in by vboxsync, 15 years ago

2d accel: perform data reset VGA device reset

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.9 KB
Line 
1/* $Id: DevVGA.h 24053 2009-10-23 18:54:16Z vboxsync $ */
2/** @file
3 * DevVGA - VBox VGA/VESA device, internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 * --------------------------------------------------------------------
21 *
22 * This code is based on:
23 *
24 * QEMU internal VGA defines.
25 *
26 * Copyright (c) 2003-2004 Fabrice Bellard
27 *
28 * Permission is hereby granted, free of charge, to any person obtaining a copy
29 * of this software and associated documentation files (the "Software"), to deal
30 * in the Software without restriction, including without limitation the rights
31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 * copies of the Software, and to permit persons to whom the Software is
33 * furnished to do so, subject to the following conditions:
34 *
35 * The above copyright notice and this permission notice shall be included in
36 * all copies or substantial portions of the Software.
37 *
38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
41 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44 * THE SOFTWARE.
45 */
46
47#ifdef VBOX_WITH_HGSMI
48#include "HGSMI/HGSMIHost.h"
49#endif /* VBOX_WITH_HGSMI */
50
51#define VGA_SAVEDSTATE_VERSION 4
52#define VGA_SAVEDSTATE_VERSION_HGSMI 3
53#define VGA_SAVEDSTATE_VERSION_PRE_HGSMI 2
54
55#define MSR_COLOR_EMULATION 0x01
56#define MSR_PAGE_SELECT 0x20
57
58#define ST01_V_RETRACE 0x08
59#define ST01_DISP_ENABLE 0x01
60
61/* bochs VBE support */
62#define CONFIG_BOCHS_VBE
63
64#ifdef VBOX
65#define VBE_DISPI_MAX_XRES 16384
66#define VBE_DISPI_MAX_YRES 16384
67#else
68#define VBE_DISPI_MAX_XRES 1600
69#define VBE_DISPI_MAX_YRES 1200
70#endif
71#define VBE_DISPI_MAX_BPP 32
72
73#define VBE_DISPI_INDEX_ID 0x0
74#define VBE_DISPI_INDEX_XRES 0x1
75#define VBE_DISPI_INDEX_YRES 0x2
76#define VBE_DISPI_INDEX_BPP 0x3
77#define VBE_DISPI_INDEX_ENABLE 0x4
78#define VBE_DISPI_INDEX_BANK 0x5
79#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
80#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
81#define VBE_DISPI_INDEX_X_OFFSET 0x8
82#define VBE_DISPI_INDEX_Y_OFFSET 0x9
83#define VBE_DISPI_INDEX_VBOX_VIDEO 0xa
84#define VBE_DISPI_INDEX_NB 0xb
85
86#define VBE_DISPI_ID0 0xB0C0
87#define VBE_DISPI_ID1 0xB0C1
88#define VBE_DISPI_ID2 0xB0C2
89#define VBE_DISPI_ID3 0xB0C3
90#define VBE_DISPI_ID4 0xB0C4
91
92#ifdef VBOX
93/* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
94#define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
95#ifdef VBOX_WITH_HGSMI
96/* The VBOX interface id. Indicates support for VBVA shared memory interface. */
97#define VBE_DISPI_ID_HGSMI 0xBE01
98#endif /* VBOX_WITH_HGSMI */
99#endif /* VBOX */
100
101#define VBE_DISPI_DISABLED 0x00
102#define VBE_DISPI_ENABLED 0x01
103#define VBE_DISPI_GETCAPS 0x02
104#define VBE_DISPI_8BIT_DAC 0x20
105#define VBE_DISPI_LFB_ENABLED 0x40
106#define VBE_DISPI_NOCLEARMEM 0x80
107
108#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
109
110#ifdef CONFIG_BOCHS_VBE
111
112#define VGA_STATE_COMMON_BOCHS_VBE \
113 uint16_t vbe_index; \
114 uint16_t vbe_regs[VBE_DISPI_INDEX_NB]; \
115 uint32_t vbe_start_addr; \
116 uint32_t vbe_line_offset; \
117 uint32_t vbe_bank_max;
118
119#else
120
121#define VGA_STATE_COMMON_BOCHS_VBE
122
123#endif /* !CONFIG_BOCHS_VBE */
124
125#define CH_ATTR_SIZE (160 * 100)
126#define VGA_MAX_HEIGHT VBE_DISPI_MAX_YRES
127
128#ifndef VBOX
129#define VGA_STATE_COMMON \
130 uint8_t *vram_ptr; \
131 unsigned long vram_offset; \
132 unsigned int vram_size; \
133 uint32_t latch; \
134 uint8_t sr_index; \
135 uint8_t sr[256]; \
136 uint8_t gr_index; \
137 uint8_t gr[256]; \
138 uint8_t ar_index; \
139 uint8_t ar[21]; \
140 int ar_flip_flop; \
141 uint8_t cr_index; \
142 uint8_t cr[256]; /* CRT registers */ \
143 uint8_t msr; /* Misc Output Register */ \
144 uint8_t fcr; /* Feature Control Register */ \
145 uint8_t st00; /* status 0 */ \
146 uint8_t st01; /* status 1 */ \
147 uint8_t dac_state; \
148 uint8_t dac_sub_index; \
149 uint8_t dac_read_index; \
150 uint8_t dac_write_index; \
151 uint8_t dac_cache[3]; /* used when writing */ \
152 uint8_t palette[768]; \
153 int32_t bank_offset; \
154 int (*get_bpp)(struct VGAState *s); \
155 void (*get_offsets)(struct VGAState *s, \
156 uint32_t *pline_offset, \
157 uint32_t *pstart_addr, \
158 uint32_t *pline_compare); \
159 void (*get_resolution)(struct VGAState *s, \
160 int *pwidth, \
161 int *pheight); \
162 VGA_STATE_COMMON_BOCHS_VBE \
163 /* display refresh support */ \
164 DisplayState *ds; \
165 uint32_t font_offsets[2]; \
166 int graphic_mode; \
167 uint8_t shift_control; \
168 uint8_t double_scan; \
169 uint32_t line_offset; \
170 uint32_t line_compare; \
171 uint32_t start_addr; \
172 uint32_t plane_updated; \
173 uint8_t last_cw, last_ch; \
174 uint32_t last_width, last_height; /* in chars or pixels */ \
175 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
176 uint8_t cursor_start, cursor_end; \
177 uint32_t cursor_offset; \
178 unsigned int (*rgb_to_pixel)(unsigned int r, \
179 unsigned int g, unsigned b); \
180 /* hardware mouse cursor support */ \
181 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
182 void (*cursor_invalidate)(struct VGAState *s); \
183 void (*cursor_draw_line)(struct VGAState *s, uint8_t *d, int y); \
184 /* tell for each page if it has been updated since the last time */ \
185 uint32_t last_palette[256]; \
186 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
187
188#else /* VBOX */
189
190struct VGAState;
191typedef int FNGETBPP(struct VGAState *s);
192typedef void FNGETOFFSETS(struct VGAState *s, uint32_t *pline_offset, uint32_t *pstart_addr, uint32_t *pline_compare);
193typedef void FNGETRESOLUTION(struct VGAState *s, int *pwidth, int *pheight);
194typedef unsigned int FNRGBTOPIXEL(unsigned int r, unsigned int g, unsigned b);
195typedef void FNCURSORINVALIDATE(struct VGAState *s);
196typedef void FNCURSORDRAWLINE(struct VGAState *s, uint8_t *d, int y);
197
198/* bird: vram_offset have been remove, function pointers declared external,
199 some type changes, and some padding have been added. */
200#define VGA_STATE_COMMON \
201 R3PTRTYPE(uint8_t *) vram_ptrR3; \
202 uint32_t vram_size; \
203 uint32_t latch; \
204 uint8_t sr_index; \
205 uint8_t sr[256]; \
206 uint8_t gr_index; \
207 uint8_t gr[256]; \
208 uint8_t ar_index; \
209 uint8_t ar[21]; \
210 int32_t ar_flip_flop; \
211 uint8_t cr_index; \
212 uint8_t cr[256]; /* CRT registers */ \
213 uint8_t msr; /* Misc Output Register */ \
214 uint8_t fcr; /* Feature Control Register */ \
215 uint8_t st00; /* status 0 */ \
216 uint8_t st01; /* status 1 */ \
217 uint8_t dac_state; \
218 uint8_t dac_sub_index; \
219 uint8_t dac_read_index; \
220 uint8_t dac_write_index; \
221 uint8_t dac_cache[3]; /* used when writing */ \
222 uint8_t palette[768]; \
223 int32_t bank_offset; \
224 int32_t padding0; \
225 R3PTRTYPE(FNGETBPP *) get_bpp; \
226 R3PTRTYPE(FNGETOFFSETS *) get_offsets; \
227 R3PTRTYPE(FNGETRESOLUTION *) get_resolution; \
228 VGA_STATE_COMMON_BOCHS_VBE \
229 /* display refresh support */ \
230 uint32_t font_offsets[2]; \
231 int32_t graphic_mode; \
232 uint8_t shift_control; \
233 uint8_t double_scan; \
234 uint8_t padding1[2]; \
235 uint32_t line_offset; \
236 uint32_t line_compare; \
237 uint32_t start_addr; \
238 uint32_t plane_updated; \
239 uint8_t last_cw, last_ch, padding2[2]; \
240 uint32_t last_width, last_height; /* in chars or pixels */ \
241 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
242 uint32_t last_bpp; \
243 uint8_t cursor_start, cursor_end, padding3[2]; \
244 uint32_t cursor_offset; \
245 uint32_t padding4; \
246 R3PTRTYPE(FNRGBTOPIXEL *) rgb_to_pixel; \
247 /* hardware mouse cursor support */ \
248 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
249 R3PTRTYPE(FNCURSORINVALIDATE *) cursor_invalidate; \
250 R3PTRTYPE(FNCURSORDRAWLINE *) cursor_draw_line; \
251 /* tell for each page if it has been updated since the last time */ \
252 uint32_t last_palette[256]; \
253 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
254
255#endif /* VBOX */
256
257typedef struct VGAState {
258 VGA_STATE_COMMON
259#ifdef VBOX
260 /** end-of-common-state-marker */
261 uint32_t u32Marker;
262 /** The physical address the VRAM was assigned. */
263 RTGCPHYS32 GCPhysVRAM;
264 /** The R0 vram pointer... */
265 R0PTRTYPE(uint8_t *) vram_ptrR0;
266 /** Pointer to the GC vram mapping. */
267 RCPTRTYPE(uint8_t *) vram_ptrRC;
268 /** LFB was updated flag. */
269 bool fLFBUpdated;
270 /** Indicates if the GC extensions are enabled or not. */
271 bool fGCEnabled;
272 /** Indicates if the R0 extensions are enabled or not. */
273 bool fR0Enabled;
274 /** Flag indicating that there are dirty bits. This is used to optimize the handler resetting. */
275 bool fHasDirtyBits;
276 /** Flag indicating that the VGA memory in the 0xa0000-0xbffff region has been remapped to allow direct access. */
277 bool fRemappedVGA;
278 /** Whether to render the guest VRAM to the framebuffer memory. False only for some LFB modes. */
279 bool fRenderVRAM;
280 bool Padding1[2];
281
282 uint32_t cMonitors;
283
284#ifdef VBOX_WITH_HGSMI
285 R3PTRTYPE(PHGSMIINSTANCE) pHGSMI;
286#endif /* VBOX_WITH_HGSMI */
287
288 /** Current refresh timer interval. */
289 uint32_t Padding2;
290 uint32_t cMilliesRefreshInterval;
291 /** Refresh timer handle - HC. */
292 PTMTIMERR3 RefreshTimer;
293
294 /** Bitmap tracking dirty pages. */
295 uint32_t au32DirtyBitmap[VGA_VRAM_MAX / PAGE_SIZE / 32];
296 /** Pointer to vgaGCLFBAccessHandler(). */
297 RTRCPTR RCPtrLFBHandler;
298 /** Pointer to the device instance - RC Ptr. */
299 PPDMDEVINSRC pDevInsRC;
300 /** Pointer to the device instance - R3 Ptr. */
301 PPDMDEVINSR3 pDevInsR3;
302 /** Pointer to the device instance - R0 Ptr. */
303 PPDMDEVINSR0 pDevInsR0;
304
305 /** The critical section. */
306 PDMCRITSECT lock;
307
308 /** The display port base interface. */
309 PDMIBASE Base;
310 /** The display port interface. */
311 PDMIDISPLAYPORT Port;
312#if defined(VBOX_WITH_HGSMI) && defined(VBOX_WITH_VIDEOHWACCEL)
313 /** VBVA callbacks interface */
314 PDMDDISPLAYVBVACALLBACKS VBVACallbacks;
315#else
316# if HC_ARCH_BITS == 32
317 uint32_t Padding3;
318# endif
319#endif
320 /** Pointer to base interface of the driver. */
321 R3PTRTYPE(PPDMIBASE) pDrvBase;
322 /** Pointer to display connector interface of the driver. */
323 R3PTRTYPE(PPDMIDISPLAYCONNECTOR) pDrv;
324
325 /** The PCI device. */
326 PCIDEVICE Dev;
327
328 STAMPROFILE StatRZMemoryRead;
329 STAMPROFILE StatR3MemoryRead;
330 STAMPROFILE StatRZMemoryWrite;
331 STAMPROFILE StatR3MemoryWrite;
332 STAMCOUNTER StatMapPage; /**< Counts IOMMMIOMapMMIO2Page calls. */
333
334 /* Keep track of ring 0 latched accesses to the VGA MMIO memory. */
335 uint64_t u64LastLatchedAccess;
336 uint32_t cLatchAccesses;
337 uint16_t uMaskLatchAccess;
338 uint16_t iMask;
339
340#ifdef VBE_BYTEWISE_IO
341 /** VBE read/write data/index flags */
342 uint8_t fReadVBEData;
343 uint8_t fWriteVBEData;
344 uint8_t fReadVBEIndex;
345 uint8_t fWriteVBEIndex;
346 /** VBE write data/index one byte buffer */
347 uint8_t cbWriteVBEData;
348 uint8_t cbWriteVBEIndex;
349# ifdef VBE_NEW_DYN_LIST
350 /** VBE Extra Data write address one byte buffer */
351 uint8_t cbWriteVBEExtraAddress;
352 uint8_t Padding4;
353# else
354 uint8_t Padding4[2];
355# endif
356#endif
357
358#ifdef VBE_NEW_DYN_LIST
359 /** The VBE BIOS extra data. */
360 R3PTRTYPE(uint8_t *) pu8VBEExtraData;
361 /** The size of the VBE BIOS extra data. */
362 uint16_t cbVBEExtraData;
363 /** The VBE BIOS current memory address. */
364 uint16_t u16VBEExtraAddress;
365 uint16_t Padding5[2];
366#endif
367 /** Current logo data offset. */
368 uint32_t offLogoData;
369 /** The size of the BIOS logo data. */
370 uint32_t cbLogo;
371 /** The BIOS logo data. */
372 R3PTRTYPE(uint8_t *) pu8Logo;
373 /** The name of the logo file. */
374 R3PTRTYPE(char *) pszLogoFile;
375 /** Bitmap image data. */
376 R3PTRTYPE(uint8_t *) pu8LogoBitmap;
377 /** Current logo command. */
378 uint16_t LogoCommand;
379 /** Bitmap width. */
380 uint16_t cxLogo;
381 /** Bitmap height. */
382 uint16_t cyLogo;
383 /** Bitmap planes. */
384 uint16_t cLogoPlanes;
385 /** Bitmap depth. */
386 uint16_t cLogoBits;
387 /** Bitmap compression. */
388 uint16_t LogoCompression;
389 /** Bitmap colors used. */
390 uint16_t cLogoUsedColors;
391 /** Palette size. */
392 uint16_t cLogoPalEntries;
393 /** Clear screen flag. */
394 uint8_t fLogoClearScreen;
395 uint8_t Padding6[7];
396 /** Palette data. */
397 uint32_t au32LogoPalette[256];
398#endif /* VBOX */
399#ifdef VBOX_WITH_HGSMI
400 /** Base port in the assigned PCI I/O space. */
401 RTIOPORT IOPortBase;
402 uint8_t Padding7[6];
403#endif /* VBOX_WITH_HGSMI */
404} VGAState;
405#ifdef VBOX
406/** VGA state. */
407typedef VGAState VGASTATE;
408/** Pointer to the VGA state. */
409typedef VGASTATE *PVGASTATE;
410#endif
411
412#ifdef VBE_NEW_DYN_LIST
413/**
414 * VBE Bios Extra Data structure.
415 * @remark duplicated in vbe.h.
416 */
417typedef struct VBEHeader
418{
419 /** Signature (VBEHEADER_MAGIC). */
420 uint16_t u16Signature;
421 /** Data size. */
422 uint16_t cbData;
423} VBEHeader;
424
425/** VBE Extra Data. */
426typedef VBEHeader VBEHEADER;
427/** Pointer to the VBE Extra Data. */
428typedef VBEHEADER *PVBEHEADER;
429
430/** The value of the VBEHEADER::u16Signature field.
431 * @remark duplicated in vbe.h. */
432#define VBEHEADER_MAGIC 0x77CC
433
434/** The extra port which is used to read the mode list.
435 * @remark duplicated in vbe.h. */
436#define VBE_EXTRA_PORT 0x3b6
437
438/** The extra port which is used for debug printf.
439 * @remark duplicated in vbe.h. */
440#define VBE_PRINTF_PORT 0x3b7
441
442#endif /* VBE_NEW_DYN_LIST */
443
444#if !defined(VBOX) || defined(IN_RING3)
445static inline int c6_to_8(int v)
446{
447 int b;
448 v &= 0x3f;
449 b = v & 1;
450 return (v << 2) | (b << 1) | b;
451}
452#endif /* !VBOX || IN_RING3 */
453
454
455#ifdef VBOX_WITH_HGSMI
456int VBVAInit (PVGASTATE pVGAState);
457void VBVADestroy (PVGASTATE pVGAState);
458int VBVAUpdateDisplay (PVGASTATE pVGAState);
459void VBVAReset (PVGASTATE pVGAState);
460void HGSMIReset (PHGSMIINSTANCE pIns);
461
462# ifdef VBOX_WITH_VIDEOHWACCEL
463int vbvaVHWACommandCompleteAsynch(PPDMDDISPLAYVBVACALLBACKS pInterface, PVBOXVHWACMD pCmd);
464int vbvaVHWAConstruct (PVGASTATE pVGAState);
465int vbvaVHWADisable (PVGASTATE pVGAState);
466int vbvaVHWAReset (PVGASTATE pVGAState);
467
468int vboxVBVASaveStatePrep (PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
469# endif
470
471int vboxVBVASaveStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
472int vboxVBVALoadStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version);
473int vboxVBVALoadStateDone (PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
474
475#endif /* VBOX_WITH_HGSMI */
476
477#ifndef VBOX
478void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
479 unsigned long vga_ram_offset, int vga_ram_size);
480uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
481void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
482void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
483
484void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
485 int poffset, int w,
486 unsigned int color0, unsigned int color1,
487 unsigned int color_xor);
488void vga_draw_cursor_line_16(uint8_t *d1, const uint8_t *src1,
489 int poffset, int w,
490 unsigned int color0, unsigned int color1,
491 unsigned int color_xor);
492void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
493 int poffset, int w,
494 unsigned int color0, unsigned int color1,
495 unsigned int color_xor);
496
497extern const uint8_t sr_mask[8];
498extern const uint8_t gr_mask[16];
499#endif /* !VBOX */
500
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette