VirtualBox

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

Last change on this file since 2477 was 2106, checked in by vboxsync, 18 years ago

Do not block EMT while resizing the framebuffer.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.2 KB
Line 
1/** @file
2 *
3 * VBox VGA/VESA device
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 *
21 * --------------------------------------------------------------------
22 *
23 * This code is based on:
24 *
25 * QEMU internal VGA defines.
26 *
27 * Copyright (c) 2003-2004 Fabrice Bellard
28 *
29 * Permission is hereby granted, free of charge, to any person obtaining a copy
30 * of this software and associated documentation files (the "Software"), to deal
31 * in the Software without restriction, including without limitation the rights
32 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33 * copies of the Software, and to permit persons to whom the Software is
34 * furnished to do so, subject to the following conditions:
35 *
36 * The above copyright notice and this permission notice shall be included in
37 * all copies or substantial portions of the Software.
38 *
39 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
42 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
45 * THE SOFTWARE.
46 */
47
48#define MSR_COLOR_EMULATION 0x01
49#define MSR_PAGE_SELECT 0x20
50
51#define ST01_V_RETRACE 0x08
52#define ST01_DISP_ENABLE 0x01
53
54/* bochs VBE support */
55#define CONFIG_BOCHS_VBE
56
57#ifdef VBOX
58#define VBE_DISPI_MAX_XRES 16384
59#define VBE_DISPI_MAX_YRES 16384
60#else
61#define VBE_DISPI_MAX_XRES 1600
62#define VBE_DISPI_MAX_YRES 1200
63#endif
64#define VBE_DISPI_MAX_BPP 32
65
66#define VBE_DISPI_INDEX_ID 0x0
67#define VBE_DISPI_INDEX_XRES 0x1
68#define VBE_DISPI_INDEX_YRES 0x2
69#define VBE_DISPI_INDEX_BPP 0x3
70#define VBE_DISPI_INDEX_ENABLE 0x4
71#define VBE_DISPI_INDEX_BANK 0x5
72#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
73#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
74#define VBE_DISPI_INDEX_X_OFFSET 0x8
75#define VBE_DISPI_INDEX_Y_OFFSET 0x9
76#define VBE_DISPI_INDEX_CMONITORS 0xa
77#define VBE_DISPI_INDEX_NB 0xb
78
79#define VBE_DISPI_ID0 0xB0C0
80#define VBE_DISPI_ID1 0xB0C1
81#define VBE_DISPI_ID2 0xB0C2
82
83#define VBE_DISPI_DISABLED 0x00
84#define VBE_DISPI_ENABLED 0x01
85#define VBE_DISPI_GETCAPS 0x02
86#define VBE_DISPI_8BIT_DAC 0x20
87#define VBE_DISPI_LFB_ENABLED 0x40
88#define VBE_DISPI_NOCLEARMEM 0x80
89
90#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
91
92#ifdef CONFIG_BOCHS_VBE
93
94#define VGA_STATE_COMMON_BOCHS_VBE \
95 uint16_t vbe_index; \
96 uint16_t vbe_regs[VBE_DISPI_INDEX_NB]; \
97 uint32_t vbe_start_addr; \
98 uint32_t vbe_line_offset; \
99 uint32_t vbe_bank_mask;
100
101#else
102
103#define VGA_STATE_COMMON_BOCHS_VBE
104
105#endif /* !CONFIG_BOCHS_VBE */
106
107#define CH_ATTR_SIZE (160 * 100)
108#define VGA_MAX_HEIGHT VBE_DISPI_MAX_YRES
109
110#ifndef VBOX
111#define VGA_STATE_COMMON \
112 uint8_t *vram_ptr; \
113 unsigned long vram_offset; \
114 unsigned int vram_size; \
115 uint32_t latch; \
116 uint8_t sr_index; \
117 uint8_t sr[256]; \
118 uint8_t gr_index; \
119 uint8_t gr[256]; \
120 uint8_t ar_index; \
121 uint8_t ar[21]; \
122 int ar_flip_flop; \
123 uint8_t cr_index; \
124 uint8_t cr[256]; /* CRT registers */ \
125 uint8_t msr; /* Misc Output Register */ \
126 uint8_t fcr; /* Feature Control Register */ \
127 uint8_t st00; /* status 0 */ \
128 uint8_t st01; /* status 1 */ \
129 uint8_t dac_state; \
130 uint8_t dac_sub_index; \
131 uint8_t dac_read_index; \
132 uint8_t dac_write_index; \
133 uint8_t dac_cache[3]; /* used when writing */ \
134 uint8_t palette[768]; \
135 int32_t bank_offset; \
136 int (*get_bpp)(struct VGAState *s); \
137 void (*get_offsets)(struct VGAState *s, \
138 uint32_t *pline_offset, \
139 uint32_t *pstart_addr, \
140 uint32_t *pline_compare); \
141 void (*get_resolution)(struct VGAState *s, \
142 int *pwidth, \
143 int *pheight); \
144 VGA_STATE_COMMON_BOCHS_VBE \
145 /* display refresh support */ \
146 DisplayState *ds; \
147 uint32_t font_offsets[2]; \
148 int graphic_mode; \
149 uint8_t shift_control; \
150 uint8_t double_scan; \
151 uint32_t line_offset; \
152 uint32_t line_compare; \
153 uint32_t start_addr; \
154 uint32_t plane_updated; \
155 uint8_t last_cw, last_ch; \
156 uint32_t last_width, last_height; /* in chars or pixels */ \
157 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
158 uint8_t cursor_start, cursor_end; \
159 uint32_t cursor_offset; \
160 unsigned int (*rgb_to_pixel)(unsigned int r, \
161 unsigned int g, unsigned b); \
162 /* hardware mouse cursor support */ \
163 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
164 void (*cursor_invalidate)(struct VGAState *s); \
165 void (*cursor_draw_line)(struct VGAState *s, uint8_t *d, int y); \
166 /* tell for each page if it has been updated since the last time */ \
167 uint32_t last_palette[256]; \
168 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
169
170#else /* VBOX */
171
172struct VGAState;
173typedef int FNGETBPP(struct VGAState *s);
174typedef void FNGETOFFSETS(struct VGAState *s, uint32_t *pline_offset, uint32_t *pstart_addr, uint32_t *pline_compare);
175typedef void FNGETRESOLUTION(struct VGAState *s, int *pwidth, int *pheight);
176typedef unsigned int FNRGBTOPIXEL(unsigned int r, unsigned int g, unsigned b);
177typedef void FNCURSORINVALIDATE(struct VGAState *s);
178typedef void FNCURSORDRAWLINE(struct VGAState *s, uint8_t *d, int y);
179
180/* bird: vram_offset have been remove, function pointers declared external,
181 some type changes, and some padding have been added. */
182#define VGA_STATE_COMMON \
183 HCPTRTYPE(uint8_t *) vram_ptrHC; \
184 uint32_t vram_size; \
185 uint32_t latch; \
186 uint8_t sr_index; \
187 uint8_t sr[256]; \
188 uint8_t gr_index; \
189 uint8_t gr[256]; \
190 uint8_t ar_index; \
191 uint8_t ar[21]; \
192 int32_t ar_flip_flop; \
193 uint8_t cr_index; \
194 uint8_t cr[256]; /* CRT registers */ \
195 uint8_t msr; /* Misc Output Register */ \
196 uint8_t fcr; /* Feature Control Register */ \
197 uint8_t st00; /* status 0 */ \
198 uint8_t st01; /* status 1 */ \
199 uint8_t dac_state; \
200 uint8_t dac_sub_index; \
201 uint8_t dac_read_index; \
202 uint8_t dac_write_index; \
203 uint8_t dac_cache[3]; /* used when writing */ \
204 uint8_t palette[768]; \
205 int32_t bank_offset; \
206 int32_t padding0; \
207 R3PTRTYPE(FNGETBPP *) get_bpp; \
208 R3PTRTYPE(FNGETOFFSETS *) get_offsets; \
209 R3PTRTYPE(FNGETRESOLUTION *) get_resolution; \
210 VGA_STATE_COMMON_BOCHS_VBE \
211 /* display refresh support */ \
212 uint32_t font_offsets[2]; \
213 int32_t graphic_mode; \
214 uint8_t shift_control; \
215 uint8_t double_scan; \
216 uint8_t padding1[2]; \
217 uint32_t line_offset; \
218 uint32_t line_compare; \
219 uint32_t start_addr; \
220 uint32_t plane_updated; \
221 uint8_t last_cw, last_ch, padding2[2]; \
222 uint32_t last_width, last_height; /* in chars or pixels */ \
223 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
224 uint32_t last_bpp; \
225 uint8_t cursor_start, cursor_end, padding3[2]; \
226 uint32_t cursor_offset; \
227 uint32_t padding4; \
228 R3PTRTYPE(FNRGBTOPIXEL *) rgb_to_pixel; \
229 /* hardware mouse cursor support */ \
230 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
231 R3PTRTYPE(FNCURSORINVALIDATE *) cursor_invalidate; \
232 R3PTRTYPE(FNCURSORDRAWLINE *) cursor_draw_line; \
233 /* tell for each page if it has been updated since the last time */ \
234 uint32_t last_palette[256]; \
235 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
236
237#endif /* VBOX */
238
239typedef struct VGAState {
240 VGA_STATE_COMMON
241#ifdef VBOX
242 /** end-of-common-state-marker */
243 uint32_t u32Marker;
244 /** The physical address the VRAM was assigned. */
245 RTGCPHYS GCPhysVRAM;
246 /** Pointer to GC vram mapping. */
247 GCPTRTYPE(uint8_t *) vram_ptrGC;
248/** @todo r=bird: bool not RTUINT (my fault I guess). */
249 /** LFB was updated flag. */
250 RTUINT fLFBUpdated;
251 /** Indicates if the GC extensions are enabled or not. */
252 RTUINT fGCEnabled;
253 /** Indicates if the R0 extensions are enabled or not. */
254 RTUINT fR0Enabled;
255 /** Pointer to vgaGCLFBAccessHandler(). */
256 RTGCPTR GCPtrLFBHandler;
257 /** Flag indicating that there are dirty bits. This is used to optimize the handler resetting. */
258 bool fHaveDirtyBits;
259 /** Bitmap tracking dirty pages. */
260 uint32_t au32DirtyBitmap[VGA_VRAM_MAX / PAGE_SIZE / 32];
261 /** Pointer to the device instance - HC Ptr. */
262 PPDMDEVINSHC pDevInsHC;
263 /* * Pointer to the device instance - GC Ptr. */
264 /*GCPTRTYPE(PPDMDEVINS) pDevInsGC;*/
265
266 /** The display port base interface. */
267 PDMIBASE Base;
268 /** The display port interface. */
269 PDMIDISPLAYPORT Port;
270 /** Pointer to base interface of the driver. */
271 R3PTRTYPE(PPDMIBASE) pDrvBase;
272 /** Pointer to display connector interface of the driver. */
273 R3PTRTYPE(PPDMIDISPLAYCONNECTOR) pDrv;
274 /** Refresh timer handle - HC. */
275 PTMTIMERHC RefreshTimer;
276 /** Current refresh timer interval. */
277 uint32_t cMilliesRefreshInterval;
278
279 /** Number of virtual monitors */
280 uint32_t monitor_count;
281 uint32_t Padding0; /* May be removed if more data is added */
282
283 /** Whether to render the guest VRAM to the framebuffer memory. False only for some LFB modes. */
284 uint32_t fRenderVRAM;
285
286 /** The PCI device. */
287 PCIDEVICE Dev;
288
289 STAMPROFILE StatGCMemoryRead;
290 STAMPROFILE StatGCMemoryWrite;
291 STAMPROFILE StatGCIOPortRead;
292 STAMPROFILE StatGCIOPortWrite;
293
294#ifdef VBE_BYTEWISE_IO
295 /** VBE read/write data/index flags */
296 uint8_t fReadVBEData;
297 uint8_t fWriteVBEData;
298 uint8_t fReadVBEIndex;
299 uint8_t fWriteVBEIndex;
300 /** VBE write data/index one byte buffer */
301 uint8_t cbWriteVBEData;
302 uint8_t cbWriteVBEIndex;
303# ifdef VBE_NEW_DYN_LIST
304 /** VBE Extra Data write address one byte buffer */
305 uint8_t cbWriteVBEExtraAddress;
306 uint8_t Padding6; /**< Alignment padding. */
307# else
308 uint8_t Padding6[2]; /**< Alignment padding. */
309# endif
310#endif
311
312#ifdef VBE_NEW_DYN_LIST
313 /** The VBE BIOS extra data. */
314 R3PTRTYPE(uint8_t *) pu8VBEExtraData;
315 /** The size of the VBE BIOS extra data. */
316 uint16_t cbVBEExtraData;
317 /** The VBE BIOS current memory address. */
318 uint16_t u16VBEExtraAddress;
319 uint16_t Padding7[2]; /**< Alignment padding. */
320#endif
321
322#endif /* VBOX */
323} VGAState;
324#ifdef VBOX
325/** VGA state. */
326typedef VGAState VGASTATE;
327/** Pointer to the VGA state. */
328typedef VGASTATE *PVGASTATE;
329#endif
330
331#ifdef VBE_NEW_DYN_LIST
332/**
333 * VBE Bios Extra Data structure.
334 * @remark duplicated in vbe.h.
335 */
336typedef struct VBEHeader
337{
338 /** Signature (VBEHEADER_MAGIC). */
339 uint16_t u16Signature;
340 /** Data size. */
341 uint16_t cbData;
342} VBEHeader;
343
344/** VBE Extra Data. */
345typedef VBEHeader VBEHEADER;
346/** Pointer to the VBE Extra Data. */
347typedef VBEHEADER *PVBEHEADER;
348
349/** The value of the VBEHEADER::u16Signature field.
350 * @remark duplicated in vbe.h. */
351#define VBEHEADER_MAGIC 0x77CC
352
353/** The extra port which is used to read the mode list.
354 * @remark duplicated in vbe.h. */
355#define VBE_EXTRA_PORT 0x3b6
356
357/** The extra port which is used for debug printf.
358 * @remark duplicated in vbe.h. */
359#define VBE_PRINTF_PORT 0x3b7
360
361#endif /* VBE_NEW_DYN_LIST */
362
363#if !defined(VBOX) || defined(IN_RING3)
364static inline int c6_to_8(int v)
365{
366 int b;
367 v &= 0x3f;
368 b = v & 1;
369 return (v << 2) | (b << 1) | b;
370}
371#endif /* !VBOX || IN_RING3 */
372
373#ifndef VBOX
374void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
375 unsigned long vga_ram_offset, int vga_ram_size);
376uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
377void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
378void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
379
380void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
381 int poffset, int w,
382 unsigned int color0, unsigned int color1,
383 unsigned int color_xor);
384void vga_draw_cursor_line_16(uint8_t *d1, const uint8_t *src1,
385 int poffset, int w,
386 unsigned int color0, unsigned int color1,
387 unsigned int color_xor);
388void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
389 int poffset, int w,
390 unsigned int color0, unsigned int color1,
391 unsigned int color_xor);
392
393extern const uint8_t sr_mask[8];
394extern const uint8_t gr_mask[16];
395#endif /* !VBOX */
396
Note: See TracBrowser for help on using the repository browser.

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