1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox X11 Additions graphics driver
|
---|
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 | * X11 VESA driver
|
---|
21 | *
|
---|
22 | * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
|
---|
23 | *
|
---|
24 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
25 | * copy of this software and associated documentation files (the "Software"),
|
---|
26 | * to deal in the Software without restriction, including without limitation
|
---|
27 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
28 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
29 | * Software is 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 | * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
38 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
---|
39 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
---|
40 | * SOFTWARE.
|
---|
41 | *
|
---|
42 | * Except as contained in this notice, the name of Conectiva Linux shall
|
---|
43 | * not be used in advertising or otherwise to promote the sale, use or other
|
---|
44 | * dealings in this Software without prior written authorization from
|
---|
45 | * Conectiva Linux.
|
---|
46 | *
|
---|
47 | * Authors: Paulo César Pereira de Andrade <[email protected]>
|
---|
48 | *
|
---|
49 | * $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vesa/vesa.h,v 1.9 2001/05/04 19:05:49 dawes Exp $
|
---|
50 | */
|
---|
51 |
|
---|
52 | #ifndef _VBOXVIDEO_H_
|
---|
53 | #define _VBOXVIDEO_H_
|
---|
54 |
|
---|
55 | #include <VBox/VBoxVideoGuest.h>
|
---|
56 | #include <VBox/VBoxVideo.h>
|
---|
57 |
|
---|
58 | #include <iprt/asm-math.h>
|
---|
59 |
|
---|
60 | #ifdef DEBUG
|
---|
61 |
|
---|
62 | #define TRACE_ENTRY() \
|
---|
63 | do { \
|
---|
64 | xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
|
---|
65 | xf86Msg(X_INFO, ": entering\n"); \
|
---|
66 | } while(0)
|
---|
67 | #define TRACE_EXIT() \
|
---|
68 | do { \
|
---|
69 | xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
|
---|
70 | xf86Msg(X_INFO, ": leaving\n"); \
|
---|
71 | } while(0)
|
---|
72 | #define TRACE_LOG(...) \
|
---|
73 | do { \
|
---|
74 | xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
|
---|
75 | xf86Msg(X_INFO, __VA_ARGS__); \
|
---|
76 | } while(0)
|
---|
77 | # define TRACE_LINE() do \
|
---|
78 | { \
|
---|
79 | ErrorF ("%s: line %d\n", __FUNCTION__, __LINE__); \
|
---|
80 | } while(0)
|
---|
81 | # define XF86ASSERT(expr, out) \
|
---|
82 | if (!(expr)) \
|
---|
83 | { \
|
---|
84 | ErrorF ("\nAssertion failed!\n\n"); \
|
---|
85 | ErrorF ("%s\n", #expr); \
|
---|
86 | ErrorF ("at %s (%s:%d)\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
|
---|
87 | ErrorF out; \
|
---|
88 | FatalError("Aborting"); \
|
---|
89 | }
|
---|
90 | #else /* !DEBUG */
|
---|
91 |
|
---|
92 | #define TRACE_ENTRY() do { } while (0)
|
---|
93 | #define TRACE_EXIT() do { } while (0)
|
---|
94 | #define TRACE_LOG(...) do { } while (0)
|
---|
95 | #define XF86ASSERT(expr, out) do { } while (0)
|
---|
96 |
|
---|
97 | #endif /* !DEBUG */
|
---|
98 |
|
---|
99 | #define BOOL_STR(a) ((a) ? "TRUE" : "FALSE")
|
---|
100 |
|
---|
101 | #include <VBox/Hardware/VBoxVideoVBE.h>
|
---|
102 | #include <VBox/VMMDev.h>
|
---|
103 |
|
---|
104 | /* All drivers should typically include these */
|
---|
105 | #include "xf86.h"
|
---|
106 | #include "xf86_OSproc.h"
|
---|
107 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
|
---|
108 | # include "xf86Resources.h"
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | #include <iprt/string.h>
|
---|
112 | #include "compiler.h"
|
---|
113 |
|
---|
114 | #ifndef PCIACCESS
|
---|
115 | /* Drivers for PCI hardware need this */
|
---|
116 | # include "xf86PciInfo.h"
|
---|
117 | /* Drivers that need to access the PCI config space directly need this */
|
---|
118 | # include "xf86Pci.h"
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | /* ShadowFB support */
|
---|
122 | #include "shadowfb.h"
|
---|
123 |
|
---|
124 | /* Dga definitions */
|
---|
125 | #include "dgaproc.h"
|
---|
126 |
|
---|
127 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
|
---|
128 | # include "xf86RAC.h"
|
---|
129 | #endif
|
---|
130 |
|
---|
131 | #include "fb.h"
|
---|
132 |
|
---|
133 | #define VBOX_VERSION 4000 /* Why? */
|
---|
134 | #include "xf86Cursor.h"
|
---|
135 | #define VBOX_NAME "VBoxVideo"
|
---|
136 | #define VBOX_DRIVER_NAME "vboxvideo"
|
---|
137 |
|
---|
138 | #ifdef VBOX_DRI
|
---|
139 | /* DRI support */
|
---|
140 | #define _XF86DRI_SERVER_
|
---|
141 | /* Hack to work around a libdrm header which is broken on Solaris */
|
---|
142 | #define u_int64_t uint64_t
|
---|
143 | /* Get rid of a warning due to a broken header file */
|
---|
144 | enum drm_bo_type { DRM_BO_TYPE };
|
---|
145 | #include "dri.h"
|
---|
146 | #undef u_int64_t
|
---|
147 | #include "sarea.h"
|
---|
148 | #include "GL/glxint.h"
|
---|
149 | #include "GL/glxtokens.h"
|
---|
150 |
|
---|
151 | /* For some reason this is not in the header files. */
|
---|
152 | extern void GlxSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
|
---|
153 | void **configprivs);
|
---|
154 | #endif
|
---|
155 |
|
---|
156 | #define VBOX_VIDEO_MAJOR 1
|
---|
157 | #define VBOX_VIDEO_MINOR 0
|
---|
158 | #define VBOX_DRM_DRIVER_NAME "vboxvideo" /* For now, as this driver is basically a stub. */
|
---|
159 | #define VBOX_DRI_DRIVER_NAME "vboxvideo" /* For starters. */
|
---|
160 | #define VBOX_MAX_DRAWABLES 256 /* At random. */
|
---|
161 |
|
---|
162 | #define VBOXPTR(p) ((VBOXPtr)((p)->driverPrivate))
|
---|
163 |
|
---|
164 | /*XXX*/
|
---|
165 |
|
---|
166 | typedef struct VBOXRec
|
---|
167 | {
|
---|
168 | EntityInfoPtr pEnt;
|
---|
169 | #ifdef PCIACCESS
|
---|
170 | struct pci_device *pciInfo;
|
---|
171 | struct pci_device *vmmDevInfo;
|
---|
172 | #else
|
---|
173 | pciVideoPtr pciInfo;
|
---|
174 | PCITAG pciTag;
|
---|
175 | #endif
|
---|
176 | void *base;
|
---|
177 | /** The amount of VRAM available for use as a framebuffer */
|
---|
178 | unsigned long cbFBMax;
|
---|
179 | /** The size of the framebuffer and the VBVA buffers at the end of it. */
|
---|
180 | unsigned long cbView;
|
---|
181 | /** The current line size in bytes */
|
---|
182 | uint32_t cbLine;
|
---|
183 | /** Whether the pre-X-server mode was a VBE mode */
|
---|
184 | bool fSavedVBEMode;
|
---|
185 | /** Paramters of the saved pre-X-server VBE mode, invalid if there is none
|
---|
186 | */
|
---|
187 | uint16_t cSavedWidth, cSavedHeight, cSavedPitch, cSavedBPP, fSavedFlags;
|
---|
188 | CloseScreenProcPtr CloseScreen;
|
---|
189 | /** Default X server procedure for enabling and disabling framebuffer access */
|
---|
190 | xf86EnableDisableFBAccessProc *EnableDisableFBAccess;
|
---|
191 | /** Is access to the framebuffer currently allowed? */
|
---|
192 | Bool accessEnabled;
|
---|
193 | OptionInfoPtr Options;
|
---|
194 | /** @todo we never actually free this */
|
---|
195 | xf86CursorInfoPtr pCurs;
|
---|
196 | Bool useDevice;
|
---|
197 | Bool forceSWCursor;
|
---|
198 | /** Do we know that the guest can handle absolute co-ordinates? */
|
---|
199 | Bool guestCanAbsolute;
|
---|
200 | /** Are we currently switched to a virtual terminal? If so, it is not
|
---|
201 | * safe to touch the hardware. */
|
---|
202 | Bool vtSwitch;
|
---|
203 | /** Does this host support sending graphics commands using HGSMI? */
|
---|
204 | Bool fHaveHGSMI;
|
---|
205 | /** Number of screens attached */
|
---|
206 | uint32_t cScreens;
|
---|
207 | /** Position information for each virtual screen for the purposes of
|
---|
208 | * sending dirty rectangle information to the right one. */
|
---|
209 | RTRECT2 aScreenLocation[VBOX_VIDEO_MAX_SCREENS];
|
---|
210 | /** Has this screen been disabled by the guest? */
|
---|
211 | Bool afDisabled[VBOX_VIDEO_MAX_SCREENS];
|
---|
212 | #ifdef VBOXVIDEO_13
|
---|
213 | /** The virtual crtcs */
|
---|
214 | struct _xf86Crtc *paCrtcs[VBOX_VIDEO_MAX_SCREENS];
|
---|
215 | struct _xf86Output *paOutputs[VBOX_VIDEO_MAX_SCREENS];
|
---|
216 | #endif
|
---|
217 | /** Offsets of VBVA buffers in video RAM */
|
---|
218 | uint32_t aoffVBVABuffer[VBOX_VIDEO_MAX_SCREENS];
|
---|
219 | /** Context information about the VBVA buffers for each screen */
|
---|
220 | struct VBVABUFFERCONTEXT aVbvaCtx[VBOX_VIDEO_MAX_SCREENS];
|
---|
221 | /** The current preferred resolution for the screen */
|
---|
222 | RTRECTSIZE aPreferredSize[VBOX_VIDEO_MAX_SCREENS];
|
---|
223 | /** HGSMI guest heap context */
|
---|
224 | HGSMIGUESTCOMMANDCONTEXT guestCtx;
|
---|
225 | /** Unrestricted horizontal resolution flag. */
|
---|
226 | Bool fAnyX;
|
---|
227 | #ifdef VBOX_DRI
|
---|
228 | Bool useDRI;
|
---|
229 | int cVisualConfigs;
|
---|
230 | __GLXvisualConfig *pVisualConfigs;
|
---|
231 | DRIInfoRec *pDRIInfo;
|
---|
232 | int drmFD;
|
---|
233 | #endif
|
---|
234 | } VBOXRec, *VBOXPtr;
|
---|
235 |
|
---|
236 | extern Bool vbox_init(int scrnIndex, VBOXPtr pVBox);
|
---|
237 | extern Bool vbox_cursor_init (ScreenPtr pScreen);
|
---|
238 | extern Bool vbox_open (ScrnInfoPtr pScrn, ScreenPtr pScreen, VBOXPtr pVBox);
|
---|
239 | extern void vbox_close (ScrnInfoPtr pScrn, VBOXPtr pVBox);
|
---|
240 | extern Bool vbox_device_available(VBOXPtr pVBox);
|
---|
241 |
|
---|
242 | extern Bool vboxEnableVbva(ScrnInfoPtr pScrn);
|
---|
243 | extern void vboxDisableVbva(ScrnInfoPtr pScrn);
|
---|
244 |
|
---|
245 | extern Bool vboxEnableGraphicsCap(VBOXPtr pVBox);
|
---|
246 | extern Bool vboxDisableGraphicsCap(VBOXPtr pVBox);
|
---|
247 | extern Bool vboxGuestIsSeamless(ScrnInfoPtr pScrn);
|
---|
248 |
|
---|
249 | extern Bool vboxGetDisplayChangeRequest(ScrnInfoPtr pScrn, uint32_t *pcx,
|
---|
250 | uint32_t *pcy, uint32_t *pcBits,
|
---|
251 | uint32_t *piDisplay);
|
---|
252 | extern Bool vboxHostLikesVideoMode(ScrnInfoPtr pScrn, uint32_t cx, uint32_t cy, uint32_t cBits);
|
---|
253 | extern Bool vboxSaveVideoMode(ScrnInfoPtr pScrn, uint32_t cx, uint32_t cy, uint32_t cBits);
|
---|
254 | extern Bool vboxRetrieveVideoMode(ScrnInfoPtr pScrn, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits);
|
---|
255 | extern unsigned vboxNextStandardMode(ScrnInfoPtr pScrn, unsigned cIndex,
|
---|
256 | uint32_t *pcx, uint32_t *pcy,
|
---|
257 | uint32_t *pcBits);
|
---|
258 | extern void vboxGetPreferredMode(ScrnInfoPtr pScrn, uint32_t iScreen,
|
---|
259 | uint32_t *pcx, uint32_t *pcy,
|
---|
260 | uint32_t *pcBits);
|
---|
261 | extern void vboxWriteHostModes(ScrnInfoPtr pScrn, DisplayModePtr pCurrent);
|
---|
262 | extern void vboxAddModes(ScrnInfoPtr pScrn, uint32_t cxInit,
|
---|
263 | uint32_t cyInit);
|
---|
264 |
|
---|
265 | /* DRI stuff */
|
---|
266 | extern Bool VBOXDRIScreenInit(int scrnIndex, ScreenPtr pScreen, VBOXPtr pVBox);
|
---|
267 | extern Bool VBOXDRIFinishScreenInit(ScreenPtr pScreen);
|
---|
268 | extern void VBOXDRIUpdateStride(ScrnInfoPtr pScrn, VBOXPtr pVBox);
|
---|
269 | extern void VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox);
|
---|
270 |
|
---|
271 | /* EDID generation */
|
---|
272 | #ifdef VBOXVIDEO_13
|
---|
273 | extern Bool VBOXEDIDSet(struct _xf86Output *output, DisplayModePtr pmode);
|
---|
274 | #endif
|
---|
275 |
|
---|
276 | /* Utilities */
|
---|
277 |
|
---|
278 | static inline VBOXPtr VBOXGetRec(ScrnInfoPtr pScrn)
|
---|
279 | {
|
---|
280 | if (!pScrn->driverPrivate)
|
---|
281 | {
|
---|
282 | pScrn->driverPrivate = calloc(sizeof(VBOXRec), 1);
|
---|
283 | }
|
---|
284 |
|
---|
285 | return ((VBOXPtr)pScrn->driverPrivate);
|
---|
286 | }
|
---|
287 |
|
---|
288 | /** Calculate the BPP from the screen depth */
|
---|
289 | static inline uint16_t vboxBPP(ScrnInfoPtr pScrn)
|
---|
290 | {
|
---|
291 | return pScrn->depth == 24 ? 32 : 16;
|
---|
292 | }
|
---|
293 |
|
---|
294 | /** Calculate the scan line length for a display width */
|
---|
295 | static inline int32_t vboxLineLength(ScrnInfoPtr pScrn, int32_t cDisplayWidth)
|
---|
296 | {
|
---|
297 | uint64_t cbLine = ((uint64_t)cDisplayWidth * vboxBPP(pScrn) / 8 + 3) & ~3;
|
---|
298 | return cbLine < INT32_MAX ? cbLine : INT32_MAX;
|
---|
299 | }
|
---|
300 |
|
---|
301 | /** Calculate the display pitch from the scan line length */
|
---|
302 | static inline int32_t vboxDisplayPitch(ScrnInfoPtr pScrn, int32_t cbLine)
|
---|
303 | {
|
---|
304 | return ASMDivU64ByU32RetU32((uint64_t)cbLine * 8, vboxBPP(pScrn));
|
---|
305 | }
|
---|
306 |
|
---|
307 | extern void vboxClearVRAM(ScrnInfoPtr pScrn, int32_t cNewX, int32_t cNewY);
|
---|
308 | extern Bool VBOXSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth,
|
---|
309 | unsigned cHeight, int x, int y);
|
---|
310 | extern Bool VBOXAdjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height);
|
---|
311 |
|
---|
312 | #endif /* _VBOXVIDEO_H_ */
|
---|
313 |
|
---|