VirtualBox

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

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

DevVGA: Alignment fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.0 KB
Line 
1/* $Id: DevVGA.h 17308 2009-03-03 18:30:12Z 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 /* Keep track of ring 0 latched accesses to the VGA MMIO memory. */
304 uint64_t u64LastLatchedAccess;
305 uint32_t cLatchAccesses;
306 uint32_t Padding10;
307
308#ifdef VBE_BYTEWISE_IO
309 /** VBE read/write data/index flags */
310 uint8_t fReadVBEData;
311 uint8_t fWriteVBEData;
312 uint8_t fReadVBEIndex;
313 uint8_t fWriteVBEIndex;
314 /** VBE write data/index one byte buffer */
315 uint8_t cbWriteVBEData;
316 uint8_t cbWriteVBEIndex;
317# ifdef VBE_NEW_DYN_LIST
318 /** VBE Extra Data write address one byte buffer */
319 uint8_t cbWriteVBEExtraAddress;
320 uint8_t Padding6; /**< Alignment padding. */
321# else
322 uint8_t Padding6[2]; /**< Alignment padding. */
323# endif
324#endif
325
326#ifdef VBE_NEW_DYN_LIST
327 /** The VBE BIOS extra data. */
328 R3PTRTYPE(uint8_t *) pu8VBEExtraData;
329 /** The size of the VBE BIOS extra data. */
330 uint16_t cbVBEExtraData;
331 /** The VBE BIOS current memory address. */
332 uint16_t u16VBEExtraAddress;
333 uint16_t Padding7[2]; /**< Alignment padding. */
334#endif
335 /** Current logo data offset. */
336 uint32_t offLogoData;
337 /** The size of the BIOS logo data. */
338 uint32_t cbLogo;
339 /** The BIOS logo data. */
340 R3PTRTYPE(uint8_t *) pu8Logo;
341 /** The name of the logo file. */
342 R3PTRTYPE(char *) pszLogoFile;
343 /** Bitmap image data. */
344 R3PTRTYPE(uint8_t *) pu8LogoBitmap;
345 /** Current logo command. */
346 uint16_t LogoCommand;
347 /** Bitmap width. */
348 uint16_t cxLogo;
349 /** Bitmap height. */
350 uint16_t cyLogo;
351 /** Bitmap planes. */
352 uint16_t cLogoPlanes;
353 /** Bitmap depth. */
354 uint16_t cLogoBits;
355 /** Bitmap compression. */
356 uint16_t LogoCompression;
357 /** Bitmap colors used. */
358 uint16_t cLogoUsedColors;
359 /** Palette size. */
360 uint16_t cLogoPalEntries;
361 /** Clear screen flag. */
362 uint8_t fLogoClearScreen;
363 uint8_t Padding8[7]; /**< Alignment padding. */
364 /** Palette data. */
365 uint32_t au32LogoPalette[256];
366#endif /* VBOX */
367} VGAState;
368#ifdef VBOX
369/** VGA state. */
370typedef VGAState VGASTATE;
371/** Pointer to the VGA state. */
372typedef VGASTATE *PVGASTATE;
373#endif
374
375#ifdef VBE_NEW_DYN_LIST
376/**
377 * VBE Bios Extra Data structure.
378 * @remark duplicated in vbe.h.
379 */
380typedef struct VBEHeader
381{
382 /** Signature (VBEHEADER_MAGIC). */
383 uint16_t u16Signature;
384 /** Data size. */
385 uint16_t cbData;
386} VBEHeader;
387
388/** VBE Extra Data. */
389typedef VBEHeader VBEHEADER;
390/** Pointer to the VBE Extra Data. */
391typedef VBEHEADER *PVBEHEADER;
392
393/** The value of the VBEHEADER::u16Signature field.
394 * @remark duplicated in vbe.h. */
395#define VBEHEADER_MAGIC 0x77CC
396
397/** The extra port which is used to read the mode list.
398 * @remark duplicated in vbe.h. */
399#define VBE_EXTRA_PORT 0x3b6
400
401/** The extra port which is used for debug printf.
402 * @remark duplicated in vbe.h. */
403#define VBE_PRINTF_PORT 0x3b7
404
405#endif /* VBE_NEW_DYN_LIST */
406
407#if !defined(VBOX) || defined(IN_RING3)
408static inline int c6_to_8(int v)
409{
410 int b;
411 v &= 0x3f;
412 b = v & 1;
413 return (v << 2) | (b << 1) | b;
414}
415#endif /* !VBOX || IN_RING3 */
416
417#ifndef VBOX
418void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
419 unsigned long vga_ram_offset, int vga_ram_size);
420uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
421void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
422void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
423
424void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
425 int poffset, int w,
426 unsigned int color0, unsigned int color1,
427 unsigned int color_xor);
428void vga_draw_cursor_line_16(uint8_t *d1, const uint8_t *src1,
429 int poffset, int w,
430 unsigned int color0, unsigned int color1,
431 unsigned int color_xor);
432void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
433 int poffset, int w,
434 unsigned int color0, unsigned int color1,
435 unsigned int color_xor);
436
437extern const uint8_t sr_mask[8];
438extern const uint8_t gr_mask[16];
439#endif /* !VBOX */
440
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