VirtualBox

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

Last change on this file since 1071 was 488, checked in by vboxsync, 18 years ago

fixed bustage.

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