VirtualBox

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

Last change on this file since 4787 was 4787, checked in by vboxsync, 17 years ago

Eliminated HCPTRTYPE and replaced with R3R0PTRTYPE where necessary.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.9 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 *
18 * This code is based on:
19 *
20 * QEMU internal VGA defines.
21 *
22 * Copyright (c) 2003-2004 Fabrice Bellard
23 *
24 * Permission is hereby granted, free of charge, to any person obtaining a copy
25 * of this software and associated documentation files (the "Software"), to deal
26 * in the Software without restriction, including without limitation the rights
27 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28 * copies of the Software, and to permit persons to whom the Software is
29 * furnished to do so, subject to the following conditions:
30 *
31 * The above copyright notice and this permission notice shall be included in
32 * all copies or substantial portions of the Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
37 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40 * THE SOFTWARE.
41 */
42
43#define MSR_COLOR_EMULATION 0x01
44#define MSR_PAGE_SELECT 0x20
45
46#define ST01_V_RETRACE 0x08
47#define ST01_DISP_ENABLE 0x01
48
49/* bochs VBE support */
50#define CONFIG_BOCHS_VBE
51
52#ifdef VBOX
53#define VBE_DISPI_MAX_XRES 16384
54#define VBE_DISPI_MAX_YRES 16384
55#else
56#define VBE_DISPI_MAX_XRES 1600
57#define VBE_DISPI_MAX_YRES 1200
58#endif
59#define VBE_DISPI_MAX_BPP 32
60
61#define VBE_DISPI_INDEX_ID 0x0
62#define VBE_DISPI_INDEX_XRES 0x1
63#define VBE_DISPI_INDEX_YRES 0x2
64#define VBE_DISPI_INDEX_BPP 0x3
65#define VBE_DISPI_INDEX_ENABLE 0x4
66#define VBE_DISPI_INDEX_BANK 0x5
67#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
68#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
69#define VBE_DISPI_INDEX_X_OFFSET 0x8
70#define VBE_DISPI_INDEX_Y_OFFSET 0x9
71#define VBE_DISPI_INDEX_VBOX_VIDEO 0xa
72#define VBE_DISPI_INDEX_NB 0xb
73
74#define VBE_DISPI_ID0 0xB0C0
75#define VBE_DISPI_ID1 0xB0C1
76#define VBE_DISPI_ID2 0xB0C2
77
78#ifdef VBOX
79/* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
80#define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
81#endif /* VBOX */
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 R3R0PTRTYPE(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 R3R0PTRTYPE(PPDMDEVINS) 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 PTMTIMERR3 RefreshTimer;
276 /** Current refresh timer interval. */
277 uint32_t cMilliesRefreshInterval;
278
279 /** Whether to render the guest VRAM to the framebuffer memory. False only for some LFB modes. */
280 uint32_t fRenderVRAM;
281
282 /** The PCI device. */
283 PCIDEVICE Dev;
284
285 STAMPROFILE StatGCMemoryRead;
286 STAMPROFILE StatGCMemoryWrite;
287 STAMPROFILE StatGCIOPortRead;
288 STAMPROFILE StatGCIOPortWrite;
289
290#ifdef VBE_BYTEWISE_IO
291 /** VBE read/write data/index flags */
292 uint8_t fReadVBEData;
293 uint8_t fWriteVBEData;
294 uint8_t fReadVBEIndex;
295 uint8_t fWriteVBEIndex;
296 /** VBE write data/index one byte buffer */
297 uint8_t cbWriteVBEData;
298 uint8_t cbWriteVBEIndex;
299# ifdef VBE_NEW_DYN_LIST
300 /** VBE Extra Data write address one byte buffer */
301 uint8_t cbWriteVBEExtraAddress;
302 uint8_t Padding6; /**< Alignment padding. */
303# else
304 uint8_t Padding6[2]; /**< Alignment padding. */
305# endif
306#endif
307
308#ifdef VBE_NEW_DYN_LIST
309 /** The VBE BIOS extra data. */
310 R3PTRTYPE(uint8_t *) pu8VBEExtraData;
311 /** The size of the VBE BIOS extra data. */
312 uint16_t cbVBEExtraData;
313 /** The VBE BIOS current memory address. */
314 uint16_t u16VBEExtraAddress;
315 uint16_t Padding7[2]; /**< Alignment padding. */
316#endif
317
318#endif /* VBOX */
319} VGAState;
320#ifdef VBOX
321/** VGA state. */
322typedef VGAState VGASTATE;
323/** Pointer to the VGA state. */
324typedef VGASTATE *PVGASTATE;
325#endif
326
327#ifdef VBE_NEW_DYN_LIST
328/**
329 * VBE Bios Extra Data structure.
330 * @remark duplicated in vbe.h.
331 */
332typedef struct VBEHeader
333{
334 /** Signature (VBEHEADER_MAGIC). */
335 uint16_t u16Signature;
336 /** Data size. */
337 uint16_t cbData;
338} VBEHeader;
339
340/** VBE Extra Data. */
341typedef VBEHeader VBEHEADER;
342/** Pointer to the VBE Extra Data. */
343typedef VBEHEADER *PVBEHEADER;
344
345/** The value of the VBEHEADER::u16Signature field.
346 * @remark duplicated in vbe.h. */
347#define VBEHEADER_MAGIC 0x77CC
348
349/** The extra port which is used to read the mode list.
350 * @remark duplicated in vbe.h. */
351#define VBE_EXTRA_PORT 0x3b6
352
353/** The extra port which is used for debug printf.
354 * @remark duplicated in vbe.h. */
355#define VBE_PRINTF_PORT 0x3b7
356
357#endif /* VBE_NEW_DYN_LIST */
358
359#if !defined(VBOX) || defined(IN_RING3)
360static inline int c6_to_8(int v)
361{
362 int b;
363 v &= 0x3f;
364 b = v & 1;
365 return (v << 2) | (b << 1) | b;
366}
367#endif /* !VBOX || IN_RING3 */
368
369#ifndef VBOX
370void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
371 unsigned long vga_ram_offset, int vga_ram_size);
372uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
373void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
374void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
375
376void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
377 int poffset, int w,
378 unsigned int color0, unsigned int color1,
379 unsigned int color_xor);
380void vga_draw_cursor_line_16(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_32(uint8_t *d1, const uint8_t *src1,
385 int poffset, int w,
386 unsigned int color0, unsigned int color1,
387 unsigned int color_xor);
388
389extern const uint8_t sr_mask[8];
390extern const uint8_t gr_mask[16];
391#endif /* !VBOX */
392
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