VirtualBox

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

Last change on this file since 17275 was 15120, checked in by vboxsync, 16 years ago

Removed bank mask which assumed power of two VRAM size, replaced with max bank index.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.8 KB
Line 
1/* $Id: DevVGA.h 15120 2008-12-08 16:53:53Z 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#define MSR_COLOR_EMULATION 0x01
48#define MSR_PAGE_SELECT 0x20
49
50#define ST01_V_RETRACE 0x08
51#define ST01_DISP_ENABLE 0x01
52
53/* bochs VBE support */
54#define CONFIG_BOCHS_VBE
55
56#ifdef VBOX
57#define VBE_DISPI_MAX_XRES 16384
58#define VBE_DISPI_MAX_YRES 16384
59#else
60#define VBE_DISPI_MAX_XRES 1600
61#define VBE_DISPI_MAX_YRES 1200
62#endif
63#define VBE_DISPI_MAX_BPP 32
64
65#define VBE_DISPI_INDEX_ID 0x0
66#define VBE_DISPI_INDEX_XRES 0x1
67#define VBE_DISPI_INDEX_YRES 0x2
68#define VBE_DISPI_INDEX_BPP 0x3
69#define VBE_DISPI_INDEX_ENABLE 0x4
70#define VBE_DISPI_INDEX_BANK 0x5
71#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
72#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
73#define VBE_DISPI_INDEX_X_OFFSET 0x8
74#define VBE_DISPI_INDEX_Y_OFFSET 0x9
75#define VBE_DISPI_INDEX_VBOX_VIDEO 0xa
76#define VBE_DISPI_INDEX_NB 0xb
77
78#define VBE_DISPI_ID0 0xB0C0
79#define VBE_DISPI_ID1 0xB0C1
80#define VBE_DISPI_ID2 0xB0C2
81#define VBE_DISPI_ID3 0xB0C3
82#define VBE_DISPI_ID4 0xB0C4
83
84#ifdef VBOX
85/* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
86#define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
87#endif /* VBOX */
88
89#define VBE_DISPI_DISABLED 0x00
90#define VBE_DISPI_ENABLED 0x01
91#define VBE_DISPI_GETCAPS 0x02
92#define VBE_DISPI_8BIT_DAC 0x20
93#define VBE_DISPI_LFB_ENABLED 0x40
94#define VBE_DISPI_NOCLEARMEM 0x80
95
96#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
97
98#ifdef CONFIG_BOCHS_VBE
99
100#define VGA_STATE_COMMON_BOCHS_VBE \
101 uint16_t vbe_index; \
102 uint16_t vbe_regs[VBE_DISPI_INDEX_NB]; \
103 uint32_t vbe_start_addr; \
104 uint32_t vbe_line_offset; \
105 uint32_t vbe_bank_max;
106
107#else
108
109#define VGA_STATE_COMMON_BOCHS_VBE
110
111#endif /* !CONFIG_BOCHS_VBE */
112
113#define CH_ATTR_SIZE (160 * 100)
114#define VGA_MAX_HEIGHT VBE_DISPI_MAX_YRES
115
116#ifndef VBOX
117#define VGA_STATE_COMMON \
118 uint8_t *vram_ptr; \
119 unsigned long vram_offset; \
120 unsigned int vram_size; \
121 uint32_t latch; \
122 uint8_t sr_index; \
123 uint8_t sr[256]; \
124 uint8_t gr_index; \
125 uint8_t gr[256]; \
126 uint8_t ar_index; \
127 uint8_t ar[21]; \
128 int ar_flip_flop; \
129 uint8_t cr_index; \
130 uint8_t cr[256]; /* CRT registers */ \
131 uint8_t msr; /* Misc Output Register */ \
132 uint8_t fcr; /* Feature Control Register */ \
133 uint8_t st00; /* status 0 */ \
134 uint8_t st01; /* status 1 */ \
135 uint8_t dac_state; \
136 uint8_t dac_sub_index; \
137 uint8_t dac_read_index; \
138 uint8_t dac_write_index; \
139 uint8_t dac_cache[3]; /* used when writing */ \
140 uint8_t palette[768]; \
141 int32_t bank_offset; \
142 int (*get_bpp)(struct VGAState *s); \
143 void (*get_offsets)(struct VGAState *s, \
144 uint32_t *pline_offset, \
145 uint32_t *pstart_addr, \
146 uint32_t *pline_compare); \
147 void (*get_resolution)(struct VGAState *s, \
148 int *pwidth, \
149 int *pheight); \
150 VGA_STATE_COMMON_BOCHS_VBE \
151 /* display refresh support */ \
152 DisplayState *ds; \
153 uint32_t font_offsets[2]; \
154 int graphic_mode; \
155 uint8_t shift_control; \
156 uint8_t double_scan; \
157 uint32_t line_offset; \
158 uint32_t line_compare; \
159 uint32_t start_addr; \
160 uint32_t plane_updated; \
161 uint8_t last_cw, last_ch; \
162 uint32_t last_width, last_height; /* in chars or pixels */ \
163 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
164 uint8_t cursor_start, cursor_end; \
165 uint32_t cursor_offset; \
166 unsigned int (*rgb_to_pixel)(unsigned int r, \
167 unsigned int g, unsigned b); \
168 /* hardware mouse cursor support */ \
169 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
170 void (*cursor_invalidate)(struct VGAState *s); \
171 void (*cursor_draw_line)(struct VGAState *s, uint8_t *d, int y); \
172 /* tell for each page if it has been updated since the last time */ \
173 uint32_t last_palette[256]; \
174 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
175
176#else /* VBOX */
177
178struct VGAState;
179typedef int FNGETBPP(struct VGAState *s);
180typedef void FNGETOFFSETS(struct VGAState *s, uint32_t *pline_offset, uint32_t *pstart_addr, uint32_t *pline_compare);
181typedef void FNGETRESOLUTION(struct VGAState *s, int *pwidth, int *pheight);
182typedef unsigned int FNRGBTOPIXEL(unsigned int r, unsigned int g, unsigned b);
183typedef void FNCURSORINVALIDATE(struct VGAState *s);
184typedef void FNCURSORDRAWLINE(struct VGAState *s, uint8_t *d, int y);
185
186/* bird: vram_offset have been remove, function pointers declared external,
187 some type changes, and some padding have been added. */
188#define VGA_STATE_COMMON \
189 R3PTRTYPE(uint8_t *) vram_ptrR3; \
190 uint32_t vram_size; \
191 uint32_t latch; \
192 uint8_t sr_index; \
193 uint8_t sr[256]; \
194 uint8_t gr_index; \
195 uint8_t gr[256]; \
196 uint8_t ar_index; \
197 uint8_t ar[21]; \
198 int32_t ar_flip_flop; \
199 uint8_t cr_index; \
200 uint8_t cr[256]; /* CRT registers */ \
201 uint8_t msr; /* Misc Output Register */ \
202 uint8_t fcr; /* Feature Control Register */ \
203 uint8_t st00; /* status 0 */ \
204 uint8_t st01; /* status 1 */ \
205 uint8_t dac_state; \
206 uint8_t dac_sub_index; \
207 uint8_t dac_read_index; \
208 uint8_t dac_write_index; \
209 uint8_t dac_cache[3]; /* used when writing */ \
210 uint8_t palette[768]; \
211 int32_t bank_offset; \
212 int32_t padding0; \
213 R3PTRTYPE(FNGETBPP *) get_bpp; \
214 R3PTRTYPE(FNGETOFFSETS *) get_offsets; \
215 R3PTRTYPE(FNGETRESOLUTION *) get_resolution; \
216 VGA_STATE_COMMON_BOCHS_VBE \
217 /* display refresh support */ \
218 uint32_t font_offsets[2]; \
219 int32_t graphic_mode; \
220 uint8_t shift_control; \
221 uint8_t double_scan; \
222 uint8_t padding1[2]; \
223 uint32_t line_offset; \
224 uint32_t line_compare; \
225 uint32_t start_addr; \
226 uint32_t plane_updated; \
227 uint8_t last_cw, last_ch, padding2[2]; \
228 uint32_t last_width, last_height; /* in chars or pixels */ \
229 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
230 uint32_t last_bpp; \
231 uint8_t cursor_start, cursor_end, padding3[2]; \
232 uint32_t cursor_offset; \
233 uint32_t padding4; \
234 R3PTRTYPE(FNRGBTOPIXEL *) rgb_to_pixel; \
235 /* hardware mouse cursor support */ \
236 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
237 R3PTRTYPE(FNCURSORINVALIDATE *) cursor_invalidate; \
238 R3PTRTYPE(FNCURSORDRAWLINE *) cursor_draw_line; \
239 /* tell for each page if it has been updated since the last time */ \
240 uint32_t last_palette[256]; \
241 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
242
243#endif /* VBOX */
244
245typedef struct VGAState {
246 VGA_STATE_COMMON
247#ifdef VBOX
248 /** end-of-common-state-marker */
249 uint32_t u32Marker;
250 /** The physical address the VRAM was assigned. */
251 RTGCPHYS32 GCPhysVRAM;
252 /** The R0 vram pointer... */
253 R0PTRTYPE(uint8_t *) vram_ptrR0;
254 /** Pointer to the GC vram mapping. */
255 RCPTRTYPE(uint8_t *) vram_ptrRC;
256 /** LFB was updated flag. */
257 bool fLFBUpdated;
258 /** Indicates if the GC extensions are enabled or not. */
259 bool fGCEnabled;
260 /** Indicates if the R0 extensions are enabled or not. */
261 bool fR0Enabled;
262 /** Flag indicating that there are dirty bits. This is used to optimize the handler resetting. */
263 bool fHasDirtyBits;
264 /** Flag indicating that the VGA memory in the 0xa0000-0xbffff region has been remapped to allow direct access. */
265 bool fRemappedVGA;
266 /** Whether to render the guest VRAM to the framebuffer memory. False only for some LFB modes. */
267 bool fRenderVRAM;
268 bool padding9[2];
269
270 /** Current refresh timer interval. */
271 uint32_t cMilliesRefreshInterval;
272 /** Refresh timer handle - HC. */
273 PTMTIMERR3 RefreshTimer;
274
275 /** Bitmap tracking dirty pages. */
276 uint32_t au32DirtyBitmap[VGA_VRAM_MAX / PAGE_SIZE / 32];
277 /** Pointer to vgaGCLFBAccessHandler(). */
278 RTRCPTR RCPtrLFBHandler;
279 /** Pointer to the device instance - RC Ptr. */
280 PPDMDEVINSRC pDevInsRC;
281 /** Pointer to the device instance - R3 Ptr. */
282 PPDMDEVINSR3 pDevInsR3;
283 /** Pointer to the device instance - R0 Ptr. */
284 PPDMDEVINSR0 pDevInsR0;
285
286 /** The display port base interface. */
287 PDMIBASE Base;
288 /** The display port interface. */
289 PDMIDISPLAYPORT Port;
290 /** Pointer to base interface of the driver. */
291 R3PTRTYPE(PPDMIBASE) pDrvBase;
292 /** Pointer to display connector interface of the driver. */
293 R3PTRTYPE(PPDMIDISPLAYCONNECTOR) pDrv;
294
295 /** The PCI device. */
296 PCIDEVICE Dev;
297
298 STAMPROFILE StatRZMemoryRead;
299 STAMPROFILE StatR3MemoryRead;
300 STAMPROFILE StatRZMemoryWrite;
301 STAMPROFILE StatR3MemoryWrite;
302
303#ifdef VBE_BYTEWISE_IO
304 /** VBE read/write data/index flags */
305 uint8_t fReadVBEData;
306 uint8_t fWriteVBEData;
307 uint8_t fReadVBEIndex;
308 uint8_t fWriteVBEIndex;
309 /** VBE write data/index one byte buffer */
310 uint8_t cbWriteVBEData;
311 uint8_t cbWriteVBEIndex;
312# ifdef VBE_NEW_DYN_LIST
313 /** VBE Extra Data write address one byte buffer */
314 uint8_t cbWriteVBEExtraAddress;
315 uint8_t Padding6; /**< Alignment padding. */
316# else
317 uint8_t Padding6[2]; /**< Alignment padding. */
318# endif
319#endif
320
321#ifdef VBE_NEW_DYN_LIST
322 /** The VBE BIOS extra data. */
323 R3PTRTYPE(uint8_t *) pu8VBEExtraData;
324 /** The size of the VBE BIOS extra data. */
325 uint16_t cbVBEExtraData;
326 /** The VBE BIOS current memory address. */
327 uint16_t u16VBEExtraAddress;
328 uint16_t Padding7[2]; /**< Alignment padding. */
329#endif
330 /** Current logo data offset. */
331 uint32_t offLogoData;
332 /** The size of the BIOS logo data. */
333 uint32_t cbLogo;
334 /** The BIOS logo data. */
335 R3PTRTYPE(uint8_t *) pu8Logo;
336 /** The name of the logo file. */
337 R3PTRTYPE(char *) pszLogoFile;
338 /** Bitmap image data. */
339 R3PTRTYPE(uint8_t *) pu8LogoBitmap;
340 /** Current logo command. */
341 uint16_t LogoCommand;
342 /** Bitmap width. */
343 uint16_t cxLogo;
344 /** Bitmap height. */
345 uint16_t cyLogo;
346 /** Bitmap planes. */
347 uint16_t cLogoPlanes;
348 /** Bitmap depth. */
349 uint16_t cLogoBits;
350 /** Bitmap compression. */
351 uint16_t LogoCompression;
352 /** Bitmap colors used. */
353 uint16_t cLogoUsedColors;
354 /** Palette size. */
355 uint16_t cLogoPalEntries;
356 /** Clear screen flag. */
357 uint8_t fLogoClearScreen;
358 uint8_t Padding8[7]; /**< Alignment padding. */
359 /** Palette data. */
360 uint32_t au32LogoPalette[256];
361#endif /* VBOX */
362} VGAState;
363#ifdef VBOX
364/** VGA state. */
365typedef VGAState VGASTATE;
366/** Pointer to the VGA state. */
367typedef VGASTATE *PVGASTATE;
368#endif
369
370#ifdef VBE_NEW_DYN_LIST
371/**
372 * VBE Bios Extra Data structure.
373 * @remark duplicated in vbe.h.
374 */
375typedef struct VBEHeader
376{
377 /** Signature (VBEHEADER_MAGIC). */
378 uint16_t u16Signature;
379 /** Data size. */
380 uint16_t cbData;
381} VBEHeader;
382
383/** VBE Extra Data. */
384typedef VBEHeader VBEHEADER;
385/** Pointer to the VBE Extra Data. */
386typedef VBEHEADER *PVBEHEADER;
387
388/** The value of the VBEHEADER::u16Signature field.
389 * @remark duplicated in vbe.h. */
390#define VBEHEADER_MAGIC 0x77CC
391
392/** The extra port which is used to read the mode list.
393 * @remark duplicated in vbe.h. */
394#define VBE_EXTRA_PORT 0x3b6
395
396/** The extra port which is used for debug printf.
397 * @remark duplicated in vbe.h. */
398#define VBE_PRINTF_PORT 0x3b7
399
400#endif /* VBE_NEW_DYN_LIST */
401
402#if !defined(VBOX) || defined(IN_RING3)
403static inline int c6_to_8(int v)
404{
405 int b;
406 v &= 0x3f;
407 b = v & 1;
408 return (v << 2) | (b << 1) | b;
409}
410#endif /* !VBOX || IN_RING3 */
411
412#ifndef VBOX
413void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
414 unsigned long vga_ram_offset, int vga_ram_size);
415uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
416void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
417void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
418
419void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
420 int poffset, int w,
421 unsigned int color0, unsigned int color1,
422 unsigned int color_xor);
423void vga_draw_cursor_line_16(uint8_t *d1, const uint8_t *src1,
424 int poffset, int w,
425 unsigned int color0, unsigned int color1,
426 unsigned int color_xor);
427void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
428 int poffset, int w,
429 unsigned int color0, unsigned int color1,
430 unsigned int color_xor);
431
432extern const uint8_t sr_mask[8];
433extern const uint8_t gr_mask[16];
434#endif /* !VBOX */
435
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