summaryrefslogtreecommitdiff
path: root/src/vboxvideo.h
blob: 8323a3027ab5429ab52eae4972d7078b1ac5c710 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/* $Id: vboxvideo.h 118369 2017-10-13 15:50:47Z michael $ */
/** @file
 * VirtualBox X11 Additions graphics driver
 */

/*
 * Copyright (C) 2006-2017 Oracle Corporation
 *
 * This code is based on:
 *
 * X11 VESA driver
 *
 * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of Conectiva Linux shall
 * not be used in advertising or otherwise to promote the sale, use or other
 * dealings in this Software without prior written authorization from
 * Conectiva Linux.
 *
 * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
 *          Michael Thayer <michael.thayer@oracle.com>
 */

#ifndef _VBOXVIDEO_H_
#define _VBOXVIDEO_H_

/* these *must* come before anything else that might include stdbool.h,
   otherwise we're running into trouble with older X headers (up to 1.20)
   using "bool" as field name */
#include "xf86.h"
#include "xf86str.h"
#include "xf86Cursor.h"

#include <VBoxVideoGuest.h>
#include <VBoxVideo.h>
#include "version-generated.h"

#define VBOX_VENDORID 0x80EE
#define VBOX_DEVICEID 0xBEEF

#ifndef VBVA_SCREEN_F_BLANK
# define VBVA_SCREEN_F_BLANK    0x0004
#endif

#include <VBoxVideoVBE.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif


#ifdef DEBUG

#define TRACE_ENTRY() do { xf86ErrorF("%s: entering\n", __func__); } while(0)
#define TRACE_EXIT() do { xf86ErrorF("%s: leaving\n", __func__); } while(0)
#define TRACE_LINE() \
    do { xf86ErrorF("%s: line\n", __func__, __LINE__); } while(0)
#define TRACE_LOG(...) \
do { \
    xf86ErrorF("%s: ", __func__); \
    xf86ErrorF(__VA_ARGS__); \
} while(0)

#else  /* !DEBUG */

#define TRACE_ENTRY()         do { } while (0)
#define TRACE_EXIT()          do { } while (0)
#define TRACE_LOG(...)        do { } while (0)

#endif  /* !DEBUG */

#define VBOX_VERSION            VBOX_VERSION_MAJOR * 10000 \
                              + VBOX_VERSION_MINOR * 100
#define VBOX_NAME               "VBoxVideo"
#define VBOX_DRIVER_NAME        "vboxvideo"

#define VBOX_VIDEO_MAJOR  VBOX_VERSION_MAJOR
#define VBOX_VIDEO_MINOR  VBOX_VERSION_MINOR

#define VBOX_VIDEO_MIN_SIZE    64
#define VBOX_VIDEO_MAX_VIRTUAL (INT16_MAX - 1)

#define VBOXPTR(p) ((VBOXPtr)((p)->driverPrivate))

/** Helper to work round different ways of getting the root window in different
 * server versions. */
# define ROOT_WINDOW(pScrn) screenInfo.screens[(pScrn)->scrnIndex]->root

/** Structure containing all virtual monitor-specific information. */
struct VBoxScreen
{
    /** Position information for each virtual screen for the purposes of
     * sending dirty rectangle information to the right one. */
    RTRECT2 aScreenLocation;
    /** Is this CRTC enabled or in DPMS off state? */
    Bool fPowerOn;
    /** The virtual crtcs. */
    struct _xf86Crtc *paCrtcs;
    /** The virtual outputs, logically not distinct from crtcs. */
    struct _xf86Output *paOutputs;
    /** Offsets of VBVA buffers in video RAM */
    uint32_t aoffVBVABuffer;
    /** Context information about the VBVA buffers for each screen */
    struct VBVABUFFERCONTEXT aVbvaCtx;
    /** The current preferred resolution for the screen */
    RTRECTSIZE aPreferredSize;
    /** The current preferred location for the screen. */
    RTPOINT aPreferredLocation;
    /** Has this screen been enabled by the host? */
    Bool afConnected;
    /** Does this screen have a preferred location? */
    Bool afHaveLocation;
};

typedef struct VBOXRec
{
    EntityInfoPtr pEnt;
    struct pci_device *pciInfo;
    void *base;
    /** The amount of VRAM available for use as a framebuffer */
    unsigned long cbFBMax;
    /** The size of the framebuffer and the VBVA buffers at the end of it. */
    unsigned long cbView;
    /** Whether the pre-X-server mode was a VBE mode */
    Bool fSavedVBEMode;
    /** Parameters of the saved pre-X-server VBE mode, invalid if there is none
     */
    uint16_t cSavedWidth, cSavedHeight, cSavedPitch, cSavedBPP, fSavedFlags;
    CloseScreenProcPtr CloseScreen;
    /** Default X server procedure for enabling and disabling framebuffer access */
    xf86EnableDisableFBAccessProc *EnableDisableFBAccess;
    OptionInfoPtr Options;
    /** @todo we never actually free this */
    xf86CursorInfoPtr pCurs;
    /** Do we currently want to use the host cursor? */
    Bool fUseHardwareCursor;
    /** Number of screens attached */
    uint32_t cScreens;
    /** Information about each virtual screen. */
    struct VBoxScreen *pScreens;
    /** Can we get mode hint and cursor integration information from HGSMI? */
    Bool fHaveHGSMIModeHints;
    /** Does the host support the screen blanking flag? */
    Bool fHostHasScreenBlankingFlag;
    /** Array of structures for receiving mode hints. */
    VBVAMODEHINT *paVBVAModeHints;
# ifdef RT_OS_LINUX
    /** Input device file descriptor for getting ACPI hot-plug events. */
    int fdACPIDevices;
    /** Input handler handle for ACPI hot-plug listener. */
    void *hACPIEventHandler;
# endif
    /** HGSMI guest heap context */
    HGSMIGUESTCOMMANDCONTEXT guestCtx;
    /** Unrestricted horizontal resolution flag. */
    Bool fAnyX;
} VBOXRec, *VBOXPtr;

#define VBOXGetRec(pScrn) ((VBOXPtr)(pScrn)->driverPrivate)

/* setmode.c */

/** Structure describing the virtual frame buffer.  It starts at the beginning
 * of the video RAM. */
struct vbvxFrameBuffer {
    /** X offset of first screen in frame buffer. */
    int x0;
    /** Y offset of first screen in frame buffer. */
    int y0;
    /** Frame buffer virtual width. */
    unsigned cWidth;
    /** Frame buffer virtual height. */
    unsigned cHeight;
    /** Bits per pixel. */
    unsigned cBPP;
};

extern void vbvxClearVRAM(ScrnInfoPtr pScrn, size_t cbOldSize, size_t cbNewSize);
extern void vbvxSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth, unsigned cHeight, int x, int y, Bool fEnabled,
                        Bool fConnected, struct vbvxFrameBuffer *pFrameBuffer);
extern void vbvxSetSolarisMouseRange(int width, int height);

/* pointer.h */
extern Bool vbvxCursorInit(ScreenPtr pScreen);
extern void vbvxCursorTerm(VBOXPtr pVBox);

/* vbva.c */
extern void vbvxHandleDirtyRect(ScrnInfoPtr pScrn, int iRects, BoxPtr aRects);
extern void vbvxSetUpHGSMIHeapInGuest(VBOXPtr pVBox, uint32_t cbVRAM);
extern Bool vboxEnableVbva(ScrnInfoPtr pScrn);
extern void vboxDisableVbva(ScrnInfoPtr pScrn);

/* getmode.c */
extern void vboxAddModes(ScrnInfoPtr pScrn);
extern void VBoxInitialiseSizeHints(ScrnInfoPtr pScrn);
extern void vbvxReadSizesAndCursorIntegrationFromProperties(ScrnInfoPtr pScrn, Bool *pfNeedUpdate);
extern void vbvxReadSizesAndCursorIntegrationFromHGSMI(ScrnInfoPtr pScrn, Bool *pfNeedUpdate);
extern void vbvxSetUpLinuxACPI(ScreenPtr pScreen);
extern void vbvxCleanUpLinuxACPI(ScreenPtr pScreen);

/* EDID generation */
extern Bool VBOXEDIDSet(struct _xf86Output *output, DisplayModePtr pmode);

#endif /* _VBOXVIDEO_H_ */