1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox X11 Additions graphics driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2013 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 | #ifdef DEBUG
|
---|
59 |
|
---|
60 | #define TRACE_ENTRY() \
|
---|
61 | do { \
|
---|
62 | xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
|
---|
63 | xf86Msg(X_INFO, ": entering\n"); \
|
---|
64 | } while(0)
|
---|
65 | #define TRACE_EXIT() \
|
---|
66 | do { \
|
---|
67 | xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
|
---|
68 | xf86Msg(X_INFO, ": leaving\n"); \
|
---|
69 | } while(0)
|
---|
70 | #define TRACE_LOG(...) \
|
---|
71 | do { \
|
---|
72 | xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
|
---|
73 | xf86Msg(X_INFO, __VA_ARGS__); \
|
---|
74 | } while(0)
|
---|
75 | # define TRACE_LINE() do \
|
---|
76 | { \
|
---|
77 | ErrorF ("%s: line %d\n", __FUNCTION__, __LINE__); \
|
---|
78 | } while(0)
|
---|
79 | # define XF86ASSERT(expr, out) \
|
---|
80 | if (!(expr)) \
|
---|
81 | { \
|
---|
82 | ErrorF ("\nAssertion failed!\n\n"); \
|
---|
83 | ErrorF ("%s\n", #expr); \
|
---|
84 | ErrorF ("at %s (%s:%d)\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
|
---|
85 | ErrorF out; \
|
---|
86 | FatalError("Aborting"); \
|
---|
87 | }
|
---|
88 | #else /* !DEBUG */
|
---|
89 |
|
---|
90 | #define TRACE_ENTRY() do { } while (0)
|
---|
91 | #define TRACE_EXIT() do { } while (0)
|
---|
92 | #define TRACE_LOG(...) do { } while (0)
|
---|
93 | #define XF86ASSERT(expr, out) do { } while (0)
|
---|
94 |
|
---|
95 | #endif /* !DEBUG */
|
---|
96 |
|
---|
97 | #define BOOL_STR(a) ((a) ? "TRUE" : "FALSE")
|
---|
98 |
|
---|
99 | #include <VBox/Hardware/VBoxVideoVBE.h>
|
---|
100 | #include <VBox/VMMDev.h>
|
---|
101 |
|
---|
102 | #include "xf86str.h"
|
---|
103 | #include "xf86Cursor.h"
|
---|
104 |
|
---|
105 | #define VBOX_VERSION 4000 /* Why? */
|
---|
106 | #define VBOX_NAME "VBoxVideo"
|
---|
107 | #define VBOX_DRIVER_NAME "vboxvideo"
|
---|
108 |
|
---|
109 | #ifdef VBOX_DRI
|
---|
110 | /* DRI support */
|
---|
111 | #define _XF86DRI_SERVER_
|
---|
112 | /* Hack to work around a libdrm header which is broken on Solaris */
|
---|
113 | #define u_int64_t uint64_t
|
---|
114 | /* Get rid of a warning due to a broken header file */
|
---|
115 | enum drm_bo_type { DRM_BO_TYPE };
|
---|
116 | #include "dri.h"
|
---|
117 | #undef u_int64_t
|
---|
118 | #include "sarea.h"
|
---|
119 | #include "GL/glxint.h"
|
---|
120 |
|
---|
121 | /* For some reason this is not in the header files. */
|
---|
122 | extern void GlxSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
|
---|
123 | void **configprivs);
|
---|
124 | #endif
|
---|
125 |
|
---|
126 | #define VBOX_VIDEO_MAJOR 1
|
---|
127 | #define VBOX_VIDEO_MINOR 0
|
---|
128 | #define VBOX_DRM_DRIVER_NAME "vboxvideo" /* For now, as this driver is basically a stub. */
|
---|
129 | #define VBOX_DRI_DRIVER_NAME "vboxvideo" /* For starters. */
|
---|
130 | #define VBOX_MAX_DRAWABLES 256 /* At random. */
|
---|
131 |
|
---|
132 | #define VBOXPTR(p) ((VBOXPtr)((p)->driverPrivate))
|
---|
133 |
|
---|
134 | /*XXX*/
|
---|
135 |
|
---|
136 | typedef struct VBOXRec
|
---|
137 | {
|
---|
138 | EntityInfoPtr pEnt;
|
---|
139 | #ifdef PCIACCESS
|
---|
140 | struct pci_device *pciInfo;
|
---|
141 | struct pci_device *vmmDevInfo;
|
---|
142 | #else
|
---|
143 | pciVideoPtr pciInfo;
|
---|
144 | PCITAG pciTag;
|
---|
145 | #endif
|
---|
146 | void *base;
|
---|
147 | /** The amount of VRAM available for use as a framebuffer */
|
---|
148 | unsigned long cbFBMax;
|
---|
149 | /** The size of the framebuffer and the VBVA buffers at the end of it. */
|
---|
150 | unsigned long cbView;
|
---|
151 | /** The current line size in bytes */
|
---|
152 | uint32_t cbLine;
|
---|
153 | /** Whether the pre-X-server mode was a VBE mode */
|
---|
154 | bool fSavedVBEMode;
|
---|
155 | /** Paramters of the saved pre-X-server VBE mode, invalid if there is none
|
---|
156 | */
|
---|
157 | uint16_t cSavedWidth, cSavedHeight, cSavedPitch, cSavedBPP, fSavedFlags;
|
---|
158 | CloseScreenProcPtr CloseScreen;
|
---|
159 | /** Default X server procedure for enabling and disabling framebuffer access */
|
---|
160 | xf86EnableDisableFBAccessProc *EnableDisableFBAccess;
|
---|
161 | OptionInfoPtr Options;
|
---|
162 | /** @todo we never actually free this */
|
---|
163 | xf86CursorInfoPtr pCurs;
|
---|
164 | Bool useDevice;
|
---|
165 | Bool forceSWCursor;
|
---|
166 | /** Do we know that the guest can handle absolute co-ordinates? */
|
---|
167 | Bool guestCanAbsolute;
|
---|
168 | /** Does this host support sending graphics commands using HGSMI? */
|
---|
169 | Bool fHaveHGSMI;
|
---|
170 | /** Number of screens attached */
|
---|
171 | uint32_t cScreens;
|
---|
172 | /** Position information for each virtual screen for the purposes of
|
---|
173 | * sending dirty rectangle information to the right one. */
|
---|
174 | RTRECT2 aScreenLocation[VBOX_VIDEO_MAX_SCREENS];
|
---|
175 | /** The last requested framebuffer size. */
|
---|
176 | RTRECTSIZE FBSize;
|
---|
177 | /** Has this screen been disabled by the guest? */
|
---|
178 | Bool afDisabled[VBOX_VIDEO_MAX_SCREENS];
|
---|
179 | #ifdef VBOXVIDEO_13
|
---|
180 | /** The virtual crtcs */
|
---|
181 | struct _xf86Crtc *paCrtcs[VBOX_VIDEO_MAX_SCREENS];
|
---|
182 | struct _xf86Output *paOutputs[VBOX_VIDEO_MAX_SCREENS];
|
---|
183 | #endif
|
---|
184 | /** Offsets of VBVA buffers in video RAM */
|
---|
185 | uint32_t aoffVBVABuffer[VBOX_VIDEO_MAX_SCREENS];
|
---|
186 | /** Context information about the VBVA buffers for each screen */
|
---|
187 | struct VBVABUFFERCONTEXT aVbvaCtx[VBOX_VIDEO_MAX_SCREENS];
|
---|
188 | /** The current preferred resolution for the screen */
|
---|
189 | RTRECTSIZE aPreferredSize[VBOX_VIDEO_MAX_SCREENS];
|
---|
190 | /** HGSMI guest heap context */
|
---|
191 | HGSMIGUESTCOMMANDCONTEXT guestCtx;
|
---|
192 | /** Unrestricted horizontal resolution flag. */
|
---|
193 | Bool fAnyX;
|
---|
194 | #ifdef VBOX_DRI
|
---|
195 | Bool useDRI;
|
---|
196 | int cVisualConfigs;
|
---|
197 | __GLXvisualConfig *pVisualConfigs;
|
---|
198 | DRIInfoRec *pDRIInfo;
|
---|
199 | int drmFD;
|
---|
200 | #endif
|
---|
201 | } VBOXRec, *VBOXPtr;
|
---|
202 |
|
---|
203 | extern Bool vbox_init(int scrnIndex, VBOXPtr pVBox);
|
---|
204 | extern Bool vbox_cursor_init (ScreenPtr pScreen);
|
---|
205 | extern Bool vbox_open (ScrnInfoPtr pScrn, ScreenPtr pScreen, VBOXPtr pVBox);
|
---|
206 | extern void vbox_close (ScrnInfoPtr pScrn, VBOXPtr pVBox);
|
---|
207 | extern Bool vbox_device_available(VBOXPtr pVBox);
|
---|
208 |
|
---|
209 | extern Bool vboxEnableVbva(ScrnInfoPtr pScrn);
|
---|
210 | extern void vboxDisableVbva(ScrnInfoPtr pScrn);
|
---|
211 |
|
---|
212 | extern Bool vboxEnableGraphicsCap(VBOXPtr pVBox);
|
---|
213 | extern Bool vboxDisableGraphicsCap(VBOXPtr pVBox);
|
---|
214 | extern Bool vboxGuestIsSeamless(ScrnInfoPtr pScrn);
|
---|
215 |
|
---|
216 | extern Bool vboxGetDisplayChangeRequest(ScrnInfoPtr pScrn, uint32_t *pcx,
|
---|
217 | uint32_t *pcy, uint32_t *pcBits,
|
---|
218 | uint32_t *piDisplay);
|
---|
219 | extern Bool vboxHostLikesVideoMode(ScrnInfoPtr pScrn, uint32_t cx, uint32_t cy, uint32_t cBits);
|
---|
220 | extern Bool vboxSaveVideoMode(ScrnInfoPtr pScrn, uint32_t cx, uint32_t cy, uint32_t cBits);
|
---|
221 | extern Bool vboxRetrieveVideoMode(ScrnInfoPtr pScrn, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits);
|
---|
222 | extern unsigned vboxNextStandardMode(ScrnInfoPtr pScrn, unsigned cIndex,
|
---|
223 | uint32_t *pcx, uint32_t *pcy,
|
---|
224 | uint32_t *pcBits);
|
---|
225 | extern void vboxGetPreferredMode(ScrnInfoPtr pScrn, uint32_t iScreen,
|
---|
226 | uint32_t *pcx, uint32_t *pcy,
|
---|
227 | uint32_t *pcBits);
|
---|
228 | extern void vboxWriteHostModes(ScrnInfoPtr pScrn, DisplayModePtr pCurrent);
|
---|
229 | extern void vboxAddModes(ScrnInfoPtr pScrn, uint32_t cxInit,
|
---|
230 | uint32_t cyInit);
|
---|
231 |
|
---|
232 | /* DRI stuff */
|
---|
233 | extern Bool VBOXDRIScreenInit(ScrnInfoPtr pScrn, ScreenPtr pScreen,
|
---|
234 | VBOXPtr pVBox);
|
---|
235 | extern Bool VBOXDRIFinishScreenInit(ScreenPtr pScreen);
|
---|
236 | extern void VBOXDRIUpdateStride(ScrnInfoPtr pScrn, VBOXPtr pVBox);
|
---|
237 | extern void VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox);
|
---|
238 |
|
---|
239 | /* EDID generation */
|
---|
240 | #ifdef VBOXVIDEO_13
|
---|
241 | extern Bool VBOXEDIDSet(struct _xf86Output *output, DisplayModePtr pmode);
|
---|
242 | #endif
|
---|
243 |
|
---|
244 | /* Utilities */
|
---|
245 |
|
---|
246 | static inline VBOXPtr VBOXGetRec(ScrnInfoPtr pScrn)
|
---|
247 | {
|
---|
248 | return ((VBOXPtr)pScrn->driverPrivate);
|
---|
249 | }
|
---|
250 |
|
---|
251 | /** Calculate the BPP from the screen depth */
|
---|
252 | static inline uint16_t vboxBPP(ScrnInfoPtr pScrn)
|
---|
253 | {
|
---|
254 | return pScrn->depth == 24 ? 32 : 16;
|
---|
255 | }
|
---|
256 |
|
---|
257 | /** Calculate the scan line length for a display width */
|
---|
258 | static inline int32_t vboxLineLength(ScrnInfoPtr pScrn, int32_t cDisplayWidth)
|
---|
259 | {
|
---|
260 | uint32_t cbLine = (cDisplayWidth * vboxBPP(pScrn) / 8 + 3) & ~3;
|
---|
261 | return cbLine < INT32_MAX ? cbLine : INT32_MAX;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /** Calculate the display pitch from the scan line length */
|
---|
265 | static inline int32_t vboxDisplayPitch(ScrnInfoPtr pScrn, int32_t cbLine)
|
---|
266 | {
|
---|
267 | return cbLine * 8 / vboxBPP(pScrn);
|
---|
268 | }
|
---|
269 |
|
---|
270 | extern void vboxClearVRAM(ScrnInfoPtr pScrn, int32_t cNewX, int32_t cNewY);
|
---|
271 | extern Bool VBOXSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth,
|
---|
272 | unsigned cHeight, int x, int y);
|
---|
273 | extern Bool VBOXAdjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height);
|
---|
274 |
|
---|
275 | #endif /* _VBOXVIDEO_H_ */
|
---|
276 |
|
---|