VirtualBox

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

Last change on this file since 30714 was 29742, checked in by vboxsync, 15 years ago

wddm/2D: more impl (get caps + initialization working)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.8 KB
Line 
1/* $Id: DevVGA.h 29742 2010-05-21 15:58:56Z vboxsync $ */
2/** @file
3 * DevVGA - VBox VGA/VESA device, internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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 *
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#ifdef VBOX
43/** The default amount of VRAM. */
44# define VGA_VRAM_DEFAULT (_4M)
45/** The maximum amount of VRAM. Limited by VBOX_MAX_ALLOC_PAGE_COUNT. */
46# define VGA_VRAM_MAX (256 * _1M)
47/** The minimum amount of VRAM. */
48# define VGA_VRAM_MIN (_1M)
49#endif
50
51#ifdef VBOX_WITH_HGSMI
52# include "HGSMI/HGSMIHost.h"
53#endif /* VBOX_WITH_HGSMI */
54#include "DevVGASavedState.h"
55
56#define MSR_COLOR_EMULATION 0x01
57#define MSR_PAGE_SELECT 0x20
58
59#define ST01_V_RETRACE 0x08
60#define ST01_DISP_ENABLE 0x01
61
62/* bochs VBE support */
63#define CONFIG_BOCHS_VBE
64
65#ifdef VBOX
66#define VBE_DISPI_MAX_XRES 16384
67#define VBE_DISPI_MAX_YRES 16384
68#else
69#define VBE_DISPI_MAX_XRES 1600
70#define VBE_DISPI_MAX_YRES 1200
71#endif
72#define VBE_DISPI_MAX_BPP 32
73
74#define VBE_DISPI_INDEX_ID 0x0
75#define VBE_DISPI_INDEX_XRES 0x1
76#define VBE_DISPI_INDEX_YRES 0x2
77#define VBE_DISPI_INDEX_BPP 0x3
78#define VBE_DISPI_INDEX_ENABLE 0x4
79#define VBE_DISPI_INDEX_BANK 0x5
80#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
81#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
82#define VBE_DISPI_INDEX_X_OFFSET 0x8
83#define VBE_DISPI_INDEX_Y_OFFSET 0x9
84#define VBE_DISPI_INDEX_VBOX_VIDEO 0xa
85#define VBE_DISPI_INDEX_NB 0xb
86
87#define VBE_DISPI_ID0 0xB0C0
88#define VBE_DISPI_ID1 0xB0C1
89#define VBE_DISPI_ID2 0xB0C2
90#define VBE_DISPI_ID3 0xB0C3
91#define VBE_DISPI_ID4 0xB0C4
92
93#ifdef VBOX
94/* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
95#define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
96#ifdef VBOX_WITH_HGSMI
97/* The VBOX interface id. Indicates support for VBVA shared memory interface. */
98#define VBE_DISPI_ID_HGSMI 0xBE01
99#endif /* VBOX_WITH_HGSMI */
100#endif /* VBOX */
101
102#define VBE_DISPI_DISABLED 0x00
103#define VBE_DISPI_ENABLED 0x01
104#define VBE_DISPI_GETCAPS 0x02
105#define VBE_DISPI_8BIT_DAC 0x20
106#define VBE_DISPI_LFB_ENABLED 0x40
107#define VBE_DISPI_NOCLEARMEM 0x80
108
109#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
110
111#ifdef CONFIG_BOCHS_VBE
112
113#define VGA_STATE_COMMON_BOCHS_VBE \
114 uint16_t vbe_index; \
115 uint16_t vbe_regs[VBE_DISPI_INDEX_NB]; \
116 uint32_t vbe_start_addr; \
117 uint32_t vbe_line_offset; \
118 uint32_t vbe_bank_max;
119
120#else
121
122#define VGA_STATE_COMMON_BOCHS_VBE
123
124#endif /* !CONFIG_BOCHS_VBE */
125
126#define CH_ATTR_SIZE (160 * 100)
127#define VGA_MAX_HEIGHT VBE_DISPI_MAX_YRES
128
129#ifndef VBOX
130#define VGA_STATE_COMMON \
131 uint8_t *vram_ptr; \
132 unsigned long vram_offset; \
133 unsigned int vram_size; \
134 uint32_t latch; \
135 uint8_t sr_index; \
136 uint8_t sr[256]; \
137 uint8_t gr_index; \
138 uint8_t gr[256]; \
139 uint8_t ar_index; \
140 uint8_t ar[21]; \
141 int ar_flip_flop; \
142 uint8_t cr_index; \
143 uint8_t cr[256]; /* CRT registers */ \
144 uint8_t msr; /* Misc Output Register */ \
145 uint8_t fcr; /* Feature Control Register */ \
146 uint8_t st00; /* status 0 */ \
147 uint8_t st01; /* status 1 */ \
148 uint8_t dac_state; \
149 uint8_t dac_sub_index; \
150 uint8_t dac_read_index; \
151 uint8_t dac_write_index; \
152 uint8_t dac_cache[3]; /* used when writing */ \
153 uint8_t palette[768]; \
154 int32_t bank_offset; \
155 int (*get_bpp)(struct VGAState *s); \
156 void (*get_offsets)(struct VGAState *s, \
157 uint32_t *pline_offset, \
158 uint32_t *pstart_addr, \
159 uint32_t *pline_compare); \
160 void (*get_resolution)(struct VGAState *s, \
161 int *pwidth, \
162 int *pheight); \
163 VGA_STATE_COMMON_BOCHS_VBE \
164 /* display refresh support */ \
165 DisplayState *ds; \
166 uint32_t font_offsets[2]; \
167 int graphic_mode; \
168 uint8_t shift_control; \
169 uint8_t double_scan; \
170 uint32_t line_offset; \
171 uint32_t line_compare; \
172 uint32_t start_addr; \
173 uint32_t plane_updated; \
174 uint8_t last_cw, last_ch; \
175 uint32_t last_width, last_height; /* in chars or pixels */ \
176 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
177 uint8_t cursor_start, cursor_end; \
178 uint32_t cursor_offset; \
179 unsigned int (*rgb_to_pixel)(unsigned int r, \
180 unsigned int g, unsigned b); \
181 /* hardware mouse cursor support */ \
182 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
183 void (*cursor_invalidate)(struct VGAState *s); \
184 void (*cursor_draw_line)(struct VGAState *s, uint8_t *d, int y); \
185 /* tell for each page if it has been updated since the last time */ \
186 uint32_t last_palette[256]; \
187 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
188
189#else /* VBOX */
190
191struct VGAState;
192typedef int FNGETBPP(struct VGAState *s);
193typedef void FNGETOFFSETS(struct VGAState *s, uint32_t *pline_offset, uint32_t *pstart_addr, uint32_t *pline_compare);
194typedef void FNGETRESOLUTION(struct VGAState *s, int *pwidth, int *pheight);
195typedef unsigned int FNRGBTOPIXEL(unsigned int r, unsigned int g, unsigned b);
196typedef void FNCURSORINVALIDATE(struct VGAState *s);
197typedef void FNCURSORDRAWLINE(struct VGAState *s, uint8_t *d, int y);
198
199/* bird: vram_offset have been remove, function pointers declared external,
200 some type changes, and some padding have been added. */
201#define VGA_STATE_COMMON \
202 R3PTRTYPE(uint8_t *) vram_ptrR3; \
203 uint32_t vram_size; \
204 uint32_t latch; \
205 uint8_t sr_index; \
206 uint8_t sr[256]; \
207 uint8_t gr_index; \
208 uint8_t gr[256]; \
209 uint8_t ar_index; \
210 uint8_t ar[21]; \
211 int32_t ar_flip_flop; \
212 uint8_t cr_index; \
213 uint8_t cr[256]; /* CRT registers */ \
214 uint8_t msr; /* Misc Output Register */ \
215 uint8_t fcr; /* Feature Control Register */ \
216 uint8_t st00; /* status 0 */ \
217 uint8_t st01; /* status 1 */ \
218 uint8_t dac_state; \
219 uint8_t dac_sub_index; \
220 uint8_t dac_read_index; \
221 uint8_t dac_write_index; \
222 uint8_t dac_cache[3]; /* used when writing */ \
223 uint8_t palette[768]; \
224 int32_t bank_offset; \
225 int32_t padding0; \
226 R3PTRTYPE(FNGETBPP *) get_bpp; \
227 R3PTRTYPE(FNGETOFFSETS *) get_offsets; \
228 R3PTRTYPE(FNGETRESOLUTION *) get_resolution; \
229 VGA_STATE_COMMON_BOCHS_VBE \
230 /* display refresh support */ \
231 uint32_t font_offsets[2]; \
232 int32_t graphic_mode; \
233 uint8_t shift_control; \
234 uint8_t double_scan; \
235 uint8_t padding1[2]; \
236 uint32_t line_offset; \
237 uint32_t line_compare; \
238 uint32_t start_addr; \
239 uint32_t plane_updated; \
240 uint8_t last_cw, last_ch, padding2[2]; \
241 uint32_t last_width, last_height; /* in chars or pixels */ \
242 uint32_t last_scr_width, last_scr_height; /* in pixels */ \
243 uint32_t last_bpp; \
244 uint8_t cursor_start, cursor_end, padding3[2]; \
245 uint32_t cursor_offset; \
246 uint32_t padding4; \
247 R3PTRTYPE(FNRGBTOPIXEL *) rgb_to_pixel; \
248 /* hardware mouse cursor support */ \
249 uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
250 R3PTRTYPE(FNCURSORINVALIDATE *) cursor_invalidate; \
251 R3PTRTYPE(FNCURSORDRAWLINE *) cursor_draw_line; \
252 /* tell for each page if it has been updated since the last time */ \
253 uint32_t last_palette[256]; \
254 uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
255
256#endif /* VBOX */
257
258#ifdef VBOXVDMA
259typedef struct VBOXVDMAHOST *PVBOXVDMAHOST;
260#endif
261
262typedef struct VGAState {
263 VGA_STATE_COMMON
264#ifdef VBOX
265 /** end-of-common-state-marker */
266 uint32_t u32Marker;
267 /** The physical address the VRAM was assigned. */
268 RTGCPHYS32 GCPhysVRAM;
269 /** The R0 vram pointer... */
270 R0PTRTYPE(uint8_t *) vram_ptrR0;
271 /** Pointer to the GC vram mapping. */
272 RCPTRTYPE(uint8_t *) vram_ptrRC;
273 /** LFB was updated flag. */
274 bool fLFBUpdated;
275 /** Indicates if the GC extensions are enabled or not. */
276 bool fGCEnabled;
277 /** Indicates if the R0 extensions are enabled or not. */
278 bool fR0Enabled;
279 /** Flag indicating that there are dirty bits. This is used to optimize the handler resetting. */
280 bool fHasDirtyBits;
281 /** Flag indicating that the VGA memory in the 0xa0000-0xbffff region has been remapped to allow direct access. */
282 bool fRemappedVGA;
283 /** Whether to render the guest VRAM to the framebuffer memory. False only for some LFB modes. */
284 bool fRenderVRAM;
285 bool Padding1[2];
286
287 uint32_t cMonitors;
288
289#ifdef VBOX_WITH_HGSMI
290 R3PTRTYPE(PHGSMIINSTANCE) pHGSMI;
291#endif /* VBOX_WITH_HGSMI */
292#ifdef VBOXVDMA
293 R3PTRTYPE(PVBOXVDMAHOST) pVdma;
294#endif
295
296 /** Current refresh timer interval. */
297 uint32_t Padding2;
298 uint32_t cMilliesRefreshInterval;
299 /** Refresh timer handle - HC. */
300 PTMTIMERR3 RefreshTimer;
301
302 /** Bitmap tracking dirty pages. */
303 uint32_t au32DirtyBitmap[VGA_VRAM_MAX / PAGE_SIZE / 32];
304 /** Pointer to vgaGCLFBAccessHandler(). */
305 RTRCPTR RCPtrLFBHandler;
306 /** Pointer to the device instance - RC Ptr. */
307 PPDMDEVINSRC pDevInsRC;
308 /** Pointer to the device instance - R3 Ptr. */
309 PPDMDEVINSR3 pDevInsR3;
310 /** Pointer to the device instance - R0 Ptr. */
311 PPDMDEVINSR0 pDevInsR0;
312
313 /** The critical section. */
314 PDMCRITSECT lock;
315
316 /** LUN\#0: The display port base interface. */
317 PDMIBASE IBase;
318 /** LUN\#0: The display port interface. */
319 PDMIDISPLAYPORT IPort;
320#if defined(VBOX_WITH_HGSMI) && defined(VBOX_WITH_VIDEOHWACCEL)
321 /** LUN\#0: VBVA callbacks interface */
322 PDMIDISPLAYVBVACALLBACKS IVBVACallbacks;
323#else
324# if HC_ARCH_BITS == 32
325 uint32_t Padding3;
326# endif
327#endif
328 /** Pointer to base interface of the driver. */
329 R3PTRTYPE(PPDMIBASE) pDrvBase;
330 /** Pointer to display connector interface of the driver. */
331 R3PTRTYPE(PPDMIDISPLAYCONNECTOR) pDrv;
332
333 /** The PCI device. */
334 PCIDEVICE Dev;
335
336 STAMPROFILE StatRZMemoryRead;
337 STAMPROFILE StatR3MemoryRead;
338 STAMPROFILE StatRZMemoryWrite;
339 STAMPROFILE StatR3MemoryWrite;
340 STAMCOUNTER StatMapPage; /**< Counts IOMMMIOMapMMIO2Page calls. */
341
342 /* Keep track of ring 0 latched accesses to the VGA MMIO memory. */
343 uint64_t u64LastLatchedAccess;
344 uint32_t cLatchAccesses;
345 uint16_t uMaskLatchAccess;
346 uint16_t iMask;
347
348#ifdef VBE_BYTEWISE_IO
349 /** VBE read/write data/index flags */
350 uint8_t fReadVBEData;
351 uint8_t fWriteVBEData;
352 uint8_t fReadVBEIndex;
353 uint8_t fWriteVBEIndex;
354 /** VBE write data/index one byte buffer */
355 uint8_t cbWriteVBEData;
356 uint8_t cbWriteVBEIndex;
357# ifdef VBE_NEW_DYN_LIST
358 /** VBE Extra Data write address one byte buffer */
359 uint8_t cbWriteVBEExtraAddress;
360 uint8_t Padding4;
361# else
362 uint8_t Padding4[2];
363# endif
364#endif
365
366#ifdef VBE_NEW_DYN_LIST
367 /** The VBE BIOS extra data. */
368 R3PTRTYPE(uint8_t *) pu8VBEExtraData;
369 /** The size of the VBE BIOS extra data. */
370 uint16_t cbVBEExtraData;
371 /** The VBE BIOS current memory address. */
372 uint16_t u16VBEExtraAddress;
373 uint16_t Padding5[2];
374#endif
375 /** Current logo data offset. */
376 uint32_t offLogoData;
377 /** The size of the BIOS logo data. */
378 uint32_t cbLogo;
379 /** The BIOS logo data. */
380 R3PTRTYPE(uint8_t *) pu8Logo;
381 /** The name of the logo file. */
382 R3PTRTYPE(char *) pszLogoFile;
383 /** Bitmap image data. */
384 R3PTRTYPE(uint8_t *) pu8LogoBitmap;
385 /** Current logo command. */
386 uint16_t LogoCommand;
387 /** Bitmap width. */
388 uint16_t cxLogo;
389 /** Bitmap height. */
390 uint16_t cyLogo;
391 /** Bitmap planes. */
392 uint16_t cLogoPlanes;
393 /** Bitmap depth. */
394 uint16_t cLogoBits;
395 /** Bitmap compression. */
396 uint16_t LogoCompression;
397 /** Bitmap colors used. */
398 uint16_t cLogoUsedColors;
399 /** Palette size. */
400 uint16_t cLogoPalEntries;
401 /** Clear screen flag. */
402 uint8_t fLogoClearScreen;
403 uint8_t Padding6[7];
404 /** Palette data. */
405 uint32_t au32LogoPalette[256];
406#endif /* VBOX */
407#ifdef VBOX_WITH_HGSMI
408 /** Base port in the assigned PCI I/O space. */
409 RTIOPORT IOPortBase;
410#ifdef VBOXVDMA
411 /* specifies guest driver caps, i.e. whether it can handle IRQs from the adapter,
412 * the way it can handle assync HGSMI command completion, etc. */
413 uint32_t fGuestCaps;
414#endif
415
416 uint8_t Padding7[6];
417#endif /* VBOX_WITH_HGSMI */
418} VGAState;
419#ifdef VBOX
420/** VGA state. */
421typedef VGAState VGASTATE;
422/** Pointer to the VGA state. */
423typedef VGASTATE *PVGASTATE;
424#endif
425
426#ifdef VBE_NEW_DYN_LIST
427/**
428 * VBE Bios Extra Data structure.
429 * @remark duplicated in vbe.h.
430 */
431typedef struct VBEHeader
432{
433 /** Signature (VBEHEADER_MAGIC). */
434 uint16_t u16Signature;
435 /** Data size. */
436 uint16_t cbData;
437} VBEHeader;
438
439/** VBE Extra Data. */
440typedef VBEHeader VBEHEADER;
441/** Pointer to the VBE Extra Data. */
442typedef VBEHEADER *PVBEHEADER;
443
444/** The value of the VBEHEADER::u16Signature field.
445 * @remark duplicated in vbe.h. */
446#define VBEHEADER_MAGIC 0x77CC
447
448/** The extra port which is used to read the mode list.
449 * @remark duplicated in vbe.h. */
450#define VBE_EXTRA_PORT 0x3b6
451
452/** The extra port which is used for debug printf.
453 * @remark duplicated in vbe.h. */
454#define VBE_PRINTF_PORT 0x3b7
455
456#endif /* VBE_NEW_DYN_LIST */
457
458#if !defined(VBOX) || defined(IN_RING3)
459static inline int c6_to_8(int v)
460{
461 int b;
462 v &= 0x3f;
463 b = v & 1;
464 return (v << 2) | (b << 1) | b;
465}
466#endif /* !VBOX || IN_RING3 */
467
468
469#ifdef VBOX_WITH_HGSMI
470int VBVAInit (PVGASTATE pVGAState);
471void VBVADestroy (PVGASTATE pVGAState);
472int VBVAUpdateDisplay (PVGASTATE pVGAState);
473void VBVAReset (PVGASTATE pVGAState);
474
475bool VBVAIsEnabled(PVGASTATE pVGAState);
476
477/* @return host-guest flags that were set on reset
478 * this allows the caller to make further cleaning when needed,
479 * e.g. reset the IRQ */
480uint32_t HGSMIReset (PHGSMIINSTANCE pIns);
481
482# ifdef VBOX_WITH_VIDEOHWACCEL
483int vbvaVHWACommandCompleteAsynch(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVHWACMD pCmd);
484int vbvaVHWAConstruct (PVGASTATE pVGAState);
485int vbvaVHWADisable (PVGASTATE pVGAState);
486int vbvaVHWAReset (PVGASTATE pVGAState);
487
488int vboxVBVASaveStatePrep (PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
489# endif
490
491int vboxVBVASaveStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
492int vboxVBVALoadStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version);
493int vboxVBVALoadStateDone (PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
494
495# ifdef VBOXVDMA
496typedef struct VBOXVDMAHOST *PVBOXVDMAHOST;
497int vboxVDMAConstruct(PVGASTATE pVGAState, struct VBOXVDMAHOST **ppVdma, uint32_t cPipeElements);
498int vboxVDMADestruct(PVBOXVDMAHOST pVdma);
499void vboxVDMAControl(PVBOXVDMAHOST pVdma, PVBOXVDMA_CTL pCmd);
500void vboxVDMACommand(PVBOXVDMAHOST pVdma, PVBOXVDMACBUF_DR pCmd);
501bool vboxVDMAIsEnabled(PVBOXVDMAHOST pVdma);
502# endif /* VBOXVDMA */
503
504#endif /* VBOX_WITH_HGSMI */
505
506#ifndef VBOX
507void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
508 unsigned long vga_ram_offset, int vga_ram_size);
509uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
510void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
511void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
512
513void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
514 int poffset, int w,
515 unsigned int color0, unsigned int color1,
516 unsigned int color_xor);
517void vga_draw_cursor_line_16(uint8_t *d1, const uint8_t *src1,
518 int poffset, int w,
519 unsigned int color0, unsigned int color1,
520 unsigned int color_xor);
521void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
522 int poffset, int w,
523 unsigned int color0, unsigned int color1,
524 unsigned int color_xor);
525
526extern const uint8_t sr_mask[8];
527extern const uint8_t gr_mask[16];
528#endif /* !VBOX */
529
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