VirtualBox

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

Last change on this file since 3460 was 3153, checked in by vboxsync, 18 years ago

Multimonitor support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.3 KB
Line 
1/** @file
2 *
3 * VBox VGA/VESA device
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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#ifdef VBOX
84/* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_CMONITORS. */
85#define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
86#endif /* VBOX */
87
88#define VBE_DISPI_DISABLED 0x00
89#define VBE_DISPI_ENABLED 0x01
90#define VBE_DISPI_GETCAPS 0x02
91#define VBE_DISPI_8BIT_DAC 0x20
92#define VBE_DISPI_LFB_ENABLED 0x40
93#define VBE_DISPI_NOCLEARMEM 0x80
94
95#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
96
97#ifdef CONFIG_BOCHS_VBE
98
99#define VGA_STATE_COMMON_BOCHS_VBE \
100 uint16_t vbe_index; \
101 uint16_t vbe_regs[VBE_DISPI_INDEX_NB]; \
102 uint32_t vbe_start_addr; \
103 uint32_t vbe_line_offset; \
104 uint32_t vbe_bank_mask;
105
106#else
107
108#define VGA_STATE_COMMON_BOCHS_VBE
109
110#endif /* !CONFIG_BOCHS_VBE */
111
112#define CH_ATTR_SIZE (160 * 100)
113#define VGA_MAX_HEIGHT VBE_DISPI_MAX_YRES
114
115#ifndef VBOX
116#define VGA_STATE_COMMON \
117 uint8_t *vram_ptr; \
118 unsigned long vram_offset; \
119 unsigned int vram_size; \
120 uint32_t latch; \
121 uint8_t sr_index; \
122 uint8_t sr[256]; \
123 uint8_t gr_index; \
124 uint8_t gr[256]; \
125 uint8_t ar_index; \
126 uint8_t ar[21]; \
127 int ar_flip_flop; \
128 uint8_t cr_index; \
129 uint8_t cr[256]; /* CRT registers */ \
130 uint8_t msr; /* Misc Output Register */ \
131 uint8_t fcr; /* Feature Control Register */ \
132 uint8_t st00; /* status 0 */ \
133 uint8_t st01; /* status 1 */ \
134 uint8_t dac_state; \
135 uint8_t dac_sub_index; \
136 uint8_t dac_read_index; \
137 uint8_t dac_write_index; \
138 uint8_t dac_cache[3]; /* used when writing */ \
139 uint8_t palette[768]; \
140 int32_t bank_offset; \
141 int (*get_bpp)(struct VGAState *s); \
142 void (*get_offsets)(struct VGAState *s, \
143 uint32_t *pline_offset, \
144 uint32_t *pstart_addr, \
145 uint32_t *pline_compare); \
146 void (*get_resolution)(struct VGAState *s, \
147 int *pwidth, \
148 int *pheight); \
149 VGA_STATE_COMMON_BOCHS_VBE \
150 /* display refresh support */ \
151 DisplayState *ds; \
152 uint32_t font_offsets[2]; \
153 int graphic_mode; \
154 uint8_t shift_control; \
155 uint8_t double_scan; \
156 uint32_t line_offset; \
157 uint32_t line_compare; \
158 uint32_t start_addr; \
159 uint32_t plane_updated; \
160 uint8_t last_cw, last_ch; \
161 uint32_t last_width, last_height; /* in chars or pixels */ \
162 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
163 uint8_t cursor_start, cursor_end; \
164 uint32_t cursor_offset; \
165 unsigned int (*rgb_to_pixel)(unsigned int r, \
166 unsigned int g, unsigned b); \
167 /* hardware mouse cursor support */ \
168 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
169 void (*cursor_invalidate)(struct VGAState *s); \
170 void (*cursor_draw_line)(struct VGAState *s, uint8_t *d, int y); \
171 /* tell for each page if it has been updated since the last time */ \
172 uint32_t last_palette[256]; \
173 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
174
175#else /* VBOX */
176
177struct VGAState;
178typedef int FNGETBPP(struct VGAState *s);
179typedef void FNGETOFFSETS(struct VGAState *s, uint32_t *pline_offset, uint32_t *pstart_addr, uint32_t *pline_compare);
180typedef void FNGETRESOLUTION(struct VGAState *s, int *pwidth, int *pheight);
181typedef unsigned int FNRGBTOPIXEL(unsigned int r, unsigned int g, unsigned b);
182typedef void FNCURSORINVALIDATE(struct VGAState *s);
183typedef void FNCURSORDRAWLINE(struct VGAState *s, uint8_t *d, int y);
184
185/* bird: vram_offset have been remove, function pointers declared external,
186 some type changes, and some padding have been added. */
187#define VGA_STATE_COMMON \
188 HCPTRTYPE(uint8_t *) vram_ptrHC; \
189 uint32_t vram_size; \
190 uint32_t latch; \
191 uint8_t sr_index; \
192 uint8_t sr[256]; \
193 uint8_t gr_index; \
194 uint8_t gr[256]; \
195 uint8_t ar_index; \
196 uint8_t ar[21]; \
197 int32_t ar_flip_flop; \
198 uint8_t cr_index; \
199 uint8_t cr[256]; /* CRT registers */ \
200 uint8_t msr; /* Misc Output Register */ \
201 uint8_t fcr; /* Feature Control Register */ \
202 uint8_t st00; /* status 0 */ \
203 uint8_t st01; /* status 1 */ \
204 uint8_t dac_state; \
205 uint8_t dac_sub_index; \
206 uint8_t dac_read_index; \
207 uint8_t dac_write_index; \
208 uint8_t dac_cache[3]; /* used when writing */ \
209 uint8_t palette[768]; \
210 int32_t bank_offset; \
211 int32_t padding0; \
212 R3PTRTYPE(FNGETBPP *) get_bpp; \
213 R3PTRTYPE(FNGETOFFSETS *) get_offsets; \
214 R3PTRTYPE(FNGETRESOLUTION *) get_resolution; \
215 VGA_STATE_COMMON_BOCHS_VBE \
216 /* display refresh support */ \
217 uint32_t font_offsets[2]; \
218 int32_t graphic_mode; \
219 uint8_t shift_control; \
220 uint8_t double_scan; \
221 uint8_t padding1[2]; \
222 uint32_t line_offset; \
223 uint32_t line_compare; \
224 uint32_t start_addr; \
225 uint32_t plane_updated; \
226 uint8_t last_cw, last_ch, padding2[2]; \
227 uint32_t last_width, last_height; /* in chars or pixels */ \
228 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
229 uint32_t last_bpp; \
230 uint8_t cursor_start, cursor_end, padding3[2]; \
231 uint32_t cursor_offset; \
232 uint32_t padding4; \
233 R3PTRTYPE(FNRGBTOPIXEL *) rgb_to_pixel; \
234 /* hardware mouse cursor support */ \
235 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
236 R3PTRTYPE(FNCURSORINVALIDATE *) cursor_invalidate; \
237 R3PTRTYPE(FNCURSORDRAWLINE *) cursor_draw_line; \
238 /* tell for each page if it has been updated since the last time */ \
239 uint32_t last_palette[256]; \
240 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
241
242#endif /* VBOX */
243
244typedef struct VGAState {
245 VGA_STATE_COMMON
246#ifdef VBOX
247 /** end-of-common-state-marker */
248 uint32_t u32Marker;
249 /** The physical address the VRAM was assigned. */
250 RTGCPHYS GCPhysVRAM;
251 /** Pointer to GC vram mapping. */
252 GCPTRTYPE(uint8_t *) vram_ptrGC;
253/** @todo r=bird: bool not RTUINT (my fault I guess). */
254 /** LFB was updated flag. */
255 RTUINT fLFBUpdated;
256 /** Indicates if the GC extensions are enabled or not. */
257 RTUINT fGCEnabled;
258 /** Indicates if the R0 extensions are enabled or not. */
259 RTUINT fR0Enabled;
260 /** Pointer to vgaGCLFBAccessHandler(). */
261 RTGCPTR GCPtrLFBHandler;
262 /** Flag indicating that there are dirty bits. This is used to optimize the handler resetting. */
263 bool fHaveDirtyBits;
264 /** Bitmap tracking dirty pages. */
265 uint32_t au32DirtyBitmap[VGA_VRAM_MAX / PAGE_SIZE / 32];
266 /** Pointer to the device instance - HC Ptr. */
267 PPDMDEVINSHC pDevInsHC;
268 /* * Pointer to the device instance - GC Ptr. */
269 /*GCPTRTYPE(PPDMDEVINS) pDevInsGC;*/
270
271 /** The display port base interface. */
272 PDMIBASE Base;
273 /** The display port interface. */
274 PDMIDISPLAYPORT Port;
275 /** Pointer to base interface of the driver. */
276 R3PTRTYPE(PPDMIBASE) pDrvBase;
277 /** Pointer to display connector interface of the driver. */
278 R3PTRTYPE(PPDMIDISPLAYCONNECTOR) pDrv;
279 /** Refresh timer handle - HC. */
280 PTMTIMERHC RefreshTimer;
281 /** Current refresh timer interval. */
282 uint32_t cMilliesRefreshInterval;
283
284 /** Number of virtual monitors */
285 uint32_t monitor_count;
286 uint32_t Padding0; /* May be removed if more data is added */
287
288 /** Whether to render the guest VRAM to the framebuffer memory. False only for some LFB modes. */
289 uint32_t fRenderVRAM;
290
291 /** The PCI device. */
292 PCIDEVICE Dev;
293
294 STAMPROFILE StatGCMemoryRead;
295 STAMPROFILE StatGCMemoryWrite;
296 STAMPROFILE StatGCIOPortRead;
297 STAMPROFILE StatGCIOPortWrite;
298
299#ifdef VBE_BYTEWISE_IO
300 /** VBE read/write data/index flags */
301 uint8_t fReadVBEData;
302 uint8_t fWriteVBEData;
303 uint8_t fReadVBEIndex;
304 uint8_t fWriteVBEIndex;
305 /** VBE write data/index one byte buffer */
306 uint8_t cbWriteVBEData;
307 uint8_t cbWriteVBEIndex;
308# ifdef VBE_NEW_DYN_LIST
309 /** VBE Extra Data write address one byte buffer */
310 uint8_t cbWriteVBEExtraAddress;
311 uint8_t Padding6; /**< Alignment padding. */
312# else
313 uint8_t Padding6[2]; /**< Alignment padding. */
314# endif
315#endif
316
317#ifdef VBE_NEW_DYN_LIST
318 /** The VBE BIOS extra data. */
319 R3PTRTYPE(uint8_t *) pu8VBEExtraData;
320 /** The size of the VBE BIOS extra data. */
321 uint16_t cbVBEExtraData;
322 /** The VBE BIOS current memory address. */
323 uint16_t u16VBEExtraAddress;
324 uint16_t Padding7[2]; /**< Alignment padding. */
325#endif
326
327#endif /* VBOX */
328} VGAState;
329#ifdef VBOX
330/** VGA state. */
331typedef VGAState VGASTATE;
332/** Pointer to the VGA state. */
333typedef VGASTATE *PVGASTATE;
334#endif
335
336#ifdef VBE_NEW_DYN_LIST
337/**
338 * VBE Bios Extra Data structure.
339 * @remark duplicated in vbe.h.
340 */
341typedef struct VBEHeader
342{
343 /** Signature (VBEHEADER_MAGIC). */
344 uint16_t u16Signature;
345 /** Data size. */
346 uint16_t cbData;
347} VBEHeader;
348
349/** VBE Extra Data. */
350typedef VBEHeader VBEHEADER;
351/** Pointer to the VBE Extra Data. */
352typedef VBEHEADER *PVBEHEADER;
353
354/** The value of the VBEHEADER::u16Signature field.
355 * @remark duplicated in vbe.h. */
356#define VBEHEADER_MAGIC 0x77CC
357
358/** The extra port which is used to read the mode list.
359 * @remark duplicated in vbe.h. */
360#define VBE_EXTRA_PORT 0x3b6
361
362/** The extra port which is used for debug printf.
363 * @remark duplicated in vbe.h. */
364#define VBE_PRINTF_PORT 0x3b7
365
366#endif /* VBE_NEW_DYN_LIST */
367
368#if !defined(VBOX) || defined(IN_RING3)
369static inline int c6_to_8(int v)
370{
371 int b;
372 v &= 0x3f;
373 b = v & 1;
374 return (v << 2) | (b << 1) | b;
375}
376#endif /* !VBOX || IN_RING3 */
377
378#ifndef VBOX
379void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
380 unsigned long vga_ram_offset, int vga_ram_size);
381uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
382void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
383void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
384
385void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
386 int poffset, int w,
387 unsigned int color0, unsigned int color1,
388 unsigned int color_xor);
389void vga_draw_cursor_line_16(uint8_t *d1, const uint8_t *src1,
390 int poffset, int w,
391 unsigned int color0, unsigned int color1,
392 unsigned int color_xor);
393void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
394 int poffset, int w,
395 unsigned int color0, unsigned int color1,
396 unsigned int color_xor);
397
398extern const uint8_t sr_mask[8];
399extern const uint8_t gr_mask[16];
400#endif /* !VBOX */
401
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