VirtualBox

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

Last change on this file since 229 was 1, checked in by vboxsync, 55 years ago

import

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