1 | /** @file
|
---|
2 | * VirtualBox Video miniport driver
|
---|
3 | *
|
---|
4 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
5 | *
|
---|
6 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
7 | * available from http://www.virtualbox.org. This file is free software;
|
---|
8 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
9 | * General Public License (GPL) as published by the Free Software
|
---|
10 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
11 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
12 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
13 | *
|
---|
14 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
15 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
16 | * additional information or have any questions.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef VBOXVIDEO_H
|
---|
20 | #define VBOXVIDEO_H
|
---|
21 |
|
---|
22 | #include <VBox/cdefs.h>
|
---|
23 | #include <VBox/types.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 |
|
---|
26 | #ifdef VBOX_WITH_HGSMI
|
---|
27 | #include <iprt/thread.h>
|
---|
28 |
|
---|
29 | #include <VBox/HGSMI/HGSMI.h>
|
---|
30 | #include <VBox/HGSMI/HGSMIChSetup.h>
|
---|
31 | #include "VBoxHGSMI.h"
|
---|
32 | #endif /* VBOX_WITH_HGSMI */
|
---|
33 |
|
---|
34 | RT_C_DECLS_BEGIN
|
---|
35 | #include "dderror.h"
|
---|
36 | #include "devioctl.h"
|
---|
37 | #include "miniport.h"
|
---|
38 | #include "ntddvdeo.h"
|
---|
39 | #include "video.h"
|
---|
40 | RT_C_DECLS_END
|
---|
41 |
|
---|
42 |
|
---|
43 | #define VBE_DISPI_IOPORT_INDEX 0x01CE
|
---|
44 | #define VBE_DISPI_IOPORT_DATA 0x01CF
|
---|
45 | #define VBE_DISPI_INDEX_ID 0x0
|
---|
46 | #define VBE_DISPI_INDEX_XRES 0x1
|
---|
47 | #define VBE_DISPI_INDEX_YRES 0x2
|
---|
48 | #define VBE_DISPI_INDEX_BPP 0x3
|
---|
49 | #define VBE_DISPI_INDEX_ENABLE 0x4
|
---|
50 | #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
|
---|
51 | #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
|
---|
52 | #define VBE_DISPI_INDEX_VBOX_VIDEO 0xa
|
---|
53 | #ifdef VBOX_WITH_HGSMI
|
---|
54 | #define VBE_DISPI_INDEX_VBVA_HOST 0xb
|
---|
55 | #define VBE_DISPI_INDEX_VBVA_GUEST 0xc
|
---|
56 | #endif /* VBOX_WITH_HGSMI */
|
---|
57 |
|
---|
58 | #define VBE_DISPI_ID2 0xB0C2
|
---|
59 | /* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
|
---|
60 | #define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
|
---|
61 | #ifdef VBOX_WITH_HGSMI
|
---|
62 | #define VBE_DISPI_ID_HGSMI 0xBE01
|
---|
63 | #endif /* VBOX_WITH_HGSMI */
|
---|
64 | #define VBE_DISPI_DISABLED 0x00
|
---|
65 | #define VBE_DISPI_ENABLED 0x01
|
---|
66 | #define VBE_DISPI_LFB_ENABLED 0x40
|
---|
67 | #define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
|
---|
68 | #define VBE_DISPI_TOTAL_VIDEO_MEMORY_MB 4
|
---|
69 | #define VBE_DISPI_TOTAL_VIDEO_MEMORY_KB (VBE_DISPI_TOTAL_VIDEO_MEMORY_MB * 1024)
|
---|
70 | #define VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES (VBE_DISPI_TOTAL_VIDEO_MEMORY_KB * 1024)
|
---|
71 |
|
---|
72 | typedef struct _DEVICE_EXTENSION
|
---|
73 | {
|
---|
74 | struct _DEVICE_EXTENSION *pNext; /* Next extension in the DualView extension list.
|
---|
75 | * The primary extension is the first one.
|
---|
76 | */
|
---|
77 |
|
---|
78 | struct _DEVICE_EXTENSION *pPrimary; /* Pointer to the primary device extension. */
|
---|
79 |
|
---|
80 | ULONG iDevice; /* Device index: 0 for primary, otherwise a secondary device. */
|
---|
81 |
|
---|
82 |
|
---|
83 | ULONG CurrentMode; /* Saved information about video modes */
|
---|
84 | ULONG CurrentModeWidth;
|
---|
85 | ULONG CurrentModeHeight;
|
---|
86 | ULONG CurrentModeBPP;
|
---|
87 |
|
---|
88 | ULONG ulFrameBufferOffset; /* The framebuffer position in the VRAM. */
|
---|
89 | ULONG ulFrameBufferSize; /* The size of the current framebuffer. */
|
---|
90 |
|
---|
91 | union {
|
---|
92 | /* Information that is only relevant to the primary device or is the same for all devices. */
|
---|
93 | struct {
|
---|
94 |
|
---|
95 | void *pvReqFlush; /* Pointer to preallocated generic request structure for
|
---|
96 | * VMMDevReq_VideoAccelFlush. Allocated when VBVA status
|
---|
97 | * is changed. Deallocated on HwReset.
|
---|
98 | */
|
---|
99 |
|
---|
100 |
|
---|
101 | ULONG ulVbvaEnabled; /* Indicates that VBVA mode is enabled. */
|
---|
102 |
|
---|
103 | BOOLEAN bVBoxVideoSupported; /* TRUE if VBoxVideo extensions, including DualView, are supported by the host. */
|
---|
104 |
|
---|
105 | int cDisplays; /* Number of displays. */
|
---|
106 |
|
---|
107 | ULONG cbVRAM; /* The VRAM size. */
|
---|
108 |
|
---|
109 | ULONG cbMiniportHeap; /* The size of reserved VRAM for miniport driver heap.
|
---|
110 | * It is at offset:
|
---|
111 | * cbAdapterMemorySize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE - cbMiniportHeap
|
---|
112 | */
|
---|
113 | PVOID pvMiniportHeap; /* The pointer to the miniport heap VRAM.
|
---|
114 | * This is mapped by miniport separately.
|
---|
115 | */
|
---|
116 | #ifdef VBOX_WITH_HGSMI
|
---|
117 | volatile HGSMIHOSTFLAGS * pHostFlags; /* HGSMI host flags */
|
---|
118 | volatile bool bHostCmdProcessing;
|
---|
119 | PSPIN_LOCK pSynchLock;
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | PVOID pvAdapterInformation; /* The pointer to the last 4K of VRAM.
|
---|
123 | * This is mapped by miniport separately.
|
---|
124 | */
|
---|
125 |
|
---|
126 | ULONG ulMaxFrameBufferSize; /* The size of the VRAM allocated for the a single framebuffer. */
|
---|
127 |
|
---|
128 | #ifndef VBOX_WITH_HGSMI
|
---|
129 | ULONG ulDisplayInformationSize; /* The size of the Display information, which is at offset:
|
---|
130 | * ulFrameBufferOffset + ulMaxFrameBufferSize.
|
---|
131 | */
|
---|
132 | #endif /* !VBOX_WITH_HGSMI */
|
---|
133 |
|
---|
134 | #ifdef VBOX_WITH_HGSMI
|
---|
135 | BOOLEAN bHGSMI; /* Whether HGSMI is enabled. */
|
---|
136 |
|
---|
137 | HGSMIAREA areaHostHeap; /* Host heap VRAM area. */
|
---|
138 |
|
---|
139 | HGSMICHANNELINFO channels;
|
---|
140 |
|
---|
141 | HGSMIHEAP hgsmiAdapterHeap;
|
---|
142 |
|
---|
143 | PSPIN_LOCK pGHRWLock; /* lock for making guest->host read/writes atomic */
|
---|
144 | #endif /* VBOX_WITH_HGSMI */
|
---|
145 | } primary;
|
---|
146 |
|
---|
147 | /* Secondary device information. */
|
---|
148 | struct {
|
---|
149 | BOOLEAN bEnabled; /* Device enabled flag */
|
---|
150 | } secondary;
|
---|
151 | } u;
|
---|
152 |
|
---|
153 | #ifdef VBOX_WITH_HGSMI
|
---|
154 | HGSMIAREA areaDisplay; /* Entire VRAM chunk for this display device. */
|
---|
155 | #endif /* VBOX_WITH_HGSMI */
|
---|
156 | } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
|
---|
157 |
|
---|
158 | extern "C"
|
---|
159 | {
|
---|
160 |
|
---|
161 | RT_C_DECLS_BEGIN
|
---|
162 | ULONG DriverEntry(IN PVOID Context1, IN PVOID Context2);
|
---|
163 | RT_C_DECLS_END
|
---|
164 |
|
---|
165 | VP_STATUS VBoxVideoFindAdapter(
|
---|
166 | IN PVOID HwDeviceExtension,
|
---|
167 | IN PVOID HwContext,
|
---|
168 | IN PWSTR ArgumentString,
|
---|
169 | IN OUT PVIDEO_PORT_CONFIG_INFO ConfigInfo,
|
---|
170 | OUT PUCHAR Again);
|
---|
171 |
|
---|
172 | BOOLEAN VBoxVideoInitialize(PVOID HwDeviceExtension);
|
---|
173 |
|
---|
174 | BOOLEAN VBoxVideoStartIO(
|
---|
175 | PVOID HwDeviceExtension,
|
---|
176 | PVIDEO_REQUEST_PACKET RequestPacket);
|
---|
177 |
|
---|
178 | #if defined(VBOX_WITH_HGSMI) && defined(VBOX_WITH_VIDEOHWACCEL)
|
---|
179 | BOOLEAN VBoxVideoInterrupt(PVOID HwDeviceExtension);
|
---|
180 | #endif
|
---|
181 |
|
---|
182 |
|
---|
183 | BOOLEAN VBoxVideoResetHW(
|
---|
184 | PVOID HwDeviceExtension,
|
---|
185 | ULONG Columns,
|
---|
186 | ULONG Rows);
|
---|
187 |
|
---|
188 | VP_STATUS VBoxVideoGetPowerState(
|
---|
189 | PVOID HwDeviceExtension,
|
---|
190 | ULONG HwId,
|
---|
191 | PVIDEO_POWER_MANAGEMENT VideoPowerControl);
|
---|
192 |
|
---|
193 | VP_STATUS VBoxVideoSetPowerState(
|
---|
194 | PVOID HwDeviceExtension,
|
---|
195 | ULONG HwId,
|
---|
196 | PVIDEO_POWER_MANAGEMENT VideoPowerControl);
|
---|
197 |
|
---|
198 | BOOLEAN FASTCALL VBoxVideoSetCurrentMode(
|
---|
199 | PDEVICE_EXTENSION DeviceExtension,
|
---|
200 | PVIDEO_MODE RequestedMode,
|
---|
201 | PSTATUS_BLOCK StatusBlock);
|
---|
202 |
|
---|
203 | BOOLEAN FASTCALL VBoxVideoResetDevice(
|
---|
204 | PDEVICE_EXTENSION DeviceExtension,
|
---|
205 | PSTATUS_BLOCK StatusBlock);
|
---|
206 |
|
---|
207 | BOOLEAN FASTCALL VBoxVideoMapVideoMemory(
|
---|
208 | PDEVICE_EXTENSION DeviceExtension,
|
---|
209 | PVIDEO_MEMORY RequestedAddress,
|
---|
210 | PVIDEO_MEMORY_INFORMATION MapInformation,
|
---|
211 | PSTATUS_BLOCK StatusBlock);
|
---|
212 |
|
---|
213 | BOOLEAN FASTCALL VBoxVideoUnmapVideoMemory(
|
---|
214 | PDEVICE_EXTENSION DeviceExtension,
|
---|
215 | PVIDEO_MEMORY VideoMemory,
|
---|
216 | PSTATUS_BLOCK StatusBlock);
|
---|
217 |
|
---|
218 | BOOLEAN FASTCALL VBoxVideoQueryNumAvailModes(
|
---|
219 | PDEVICE_EXTENSION DeviceExtension,
|
---|
220 | PVIDEO_NUM_MODES Modes,
|
---|
221 | PSTATUS_BLOCK StatusBlock);
|
---|
222 |
|
---|
223 | BOOLEAN FASTCALL VBoxVideoQueryAvailModes(
|
---|
224 | PDEVICE_EXTENSION DeviceExtension,
|
---|
225 | PVIDEO_MODE_INFORMATION ReturnedModes,
|
---|
226 | PSTATUS_BLOCK StatusBlock);
|
---|
227 |
|
---|
228 | BOOLEAN FASTCALL VBoxVideoQueryCurrentMode(
|
---|
229 | PDEVICE_EXTENSION DeviceExtension,
|
---|
230 | PVIDEO_MODE_INFORMATION VideoModeInfo,
|
---|
231 | PSTATUS_BLOCK StatusBlock);
|
---|
232 |
|
---|
233 | BOOLEAN FASTCALL VBoxVideoSetColorRegisters(
|
---|
234 | PDEVICE_EXTENSION DeviceExtension,
|
---|
235 | PVIDEO_CLUT ColorLookUpTable,
|
---|
236 | PSTATUS_BLOCK StatusBlock);
|
---|
237 |
|
---|
238 | VP_STATUS VBoxVideoGetChildDescriptor(
|
---|
239 | PVOID HwDeviceExtension,
|
---|
240 | PVIDEO_CHILD_ENUM_INFO ChildEnumInfo,
|
---|
241 | PVIDEO_CHILD_TYPE VideoChildType,
|
---|
242 | PUCHAR pChildDescriptor,
|
---|
243 | PULONG pUId,
|
---|
244 | PULONG pUnused);
|
---|
245 |
|
---|
246 | int VBoxMapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
|
---|
247 | void **ppv,
|
---|
248 | ULONG ulOffset,
|
---|
249 | ULONG ulSize);
|
---|
250 |
|
---|
251 | void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
|
---|
252 | void **ppv);
|
---|
253 |
|
---|
254 | void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension);
|
---|
255 |
|
---|
256 | #ifdef VBOX_WITH_HGSMI
|
---|
257 |
|
---|
258 | DECLINLINE(void) VBoxVideoHostWriteUlongLocked(USHORT dataType, ULONG data)
|
---|
259 | {
|
---|
260 | VideoPortWritePortUshort((PUSHORT)VBE_DISPI_IOPORT_INDEX, dataType);
|
---|
261 | VideoPortWritePortUlong((PULONG)VBE_DISPI_IOPORT_DATA, data);
|
---|
262 | }
|
---|
263 |
|
---|
264 | DECLINLINE(void) VBoxVideoHostWriteUshortLocked(USHORT dataType, USHORT data)
|
---|
265 | {
|
---|
266 | VideoPortWritePortUshort((PUSHORT)VBE_DISPI_IOPORT_INDEX, dataType);
|
---|
267 | VideoPortWritePortUshort((PUSHORT)VBE_DISPI_IOPORT_DATA, data);
|
---|
268 | }
|
---|
269 |
|
---|
270 | DECLINLINE(ULONG) VBoxVideoHostReadUlongLocked (USHORT dataType)
|
---|
271 | {
|
---|
272 | VideoPortWritePortUshort((PUSHORT)VBE_DISPI_IOPORT_INDEX, dataType);
|
---|
273 | return VideoPortReadPortUlong((PULONG)VBE_DISPI_IOPORT_DATA);
|
---|
274 | }
|
---|
275 |
|
---|
276 | DECLINLINE(void) VBoxVideoHostWriteUlong(PDEVICE_EXTENSION PrimaryExtension, USHORT dataType, ULONG data)
|
---|
277 | {
|
---|
278 | UCHAR oldIrql;
|
---|
279 | VideoPortAcquireSpinLock(PrimaryExtension,
|
---|
280 | PrimaryExtension->u.primary.pGHRWLock,
|
---|
281 | &oldIrql);
|
---|
282 | VBoxVideoHostWriteUlongLocked(dataType, data);
|
---|
283 | VideoPortReleaseSpinLock(PrimaryExtension,
|
---|
284 | PrimaryExtension->u.primary.pGHRWLock,
|
---|
285 | oldIrql);
|
---|
286 | }
|
---|
287 |
|
---|
288 | DECLINLINE(void) VBoxVideoHostWriteUshort(PDEVICE_EXTENSION PrimaryExtension, USHORT dataType, USHORT data)
|
---|
289 | {
|
---|
290 | UCHAR oldIrql;
|
---|
291 | VideoPortAcquireSpinLock(PrimaryExtension,
|
---|
292 | PrimaryExtension->u.primary.pGHRWLock,
|
---|
293 | &oldIrql);
|
---|
294 | VBoxVideoHostWriteUshortLocked(dataType, data);
|
---|
295 | VideoPortReleaseSpinLock(PrimaryExtension,
|
---|
296 | PrimaryExtension->u.primary.pGHRWLock,
|
---|
297 | oldIrql);
|
---|
298 | }
|
---|
299 |
|
---|
300 | DECLINLINE(ULONG) VBoxVideoHostReadUlong(PDEVICE_EXTENSION PrimaryExtension, USHORT dataType)
|
---|
301 | {
|
---|
302 | ULONG data;
|
---|
303 | UCHAR oldIrql;
|
---|
304 | VideoPortAcquireSpinLock(PrimaryExtension,
|
---|
305 | PrimaryExtension->u.primary.pGHRWLock,
|
---|
306 | &oldIrql);
|
---|
307 | data = VBoxVideoHostReadUlongLocked(dataType);
|
---|
308 | VideoPortReleaseSpinLock(PrimaryExtension,
|
---|
309 | PrimaryExtension->u.primary.pGHRWLock,
|
---|
310 | oldIrql);
|
---|
311 | return data;
|
---|
312 | }
|
---|
313 |
|
---|
314 | BOOLEAN VBoxHGSMIIsSupported (PDEVICE_EXTENSION PrimaryExtension);
|
---|
315 |
|
---|
316 | VOID VBoxSetupDisplaysHGSMI (PDEVICE_EXTENSION PrimaryExtension,
|
---|
317 | PVIDEO_PORT_CONFIG_INFO pConfigInfo,
|
---|
318 | ULONG AdapterMemorySize);
|
---|
319 | BOOLEAN vboxUpdatePointerShape (PDEVICE_EXTENSION PrimaryExtension,
|
---|
320 | PVIDEO_POINTER_ATTRIBUTES pointerAttr,
|
---|
321 | uint32_t cbLength);
|
---|
322 | DECLCALLBACK(void) hgsmiGHCommandPost(HVBOXVIDEOHGSMI hHGSMI, HGSMIOFFSET offCmd);
|
---|
323 | DECLCALLBACK(void) hgsmiHostCmdComplete (HVBOXVIDEOHGSMI hHGSMI, struct _VBVAHOSTCMD * pCmd);
|
---|
324 | DECLCALLBACK(int) hgsmiHostCmdRequest (HVBOXVIDEOHGSMI hHGSMI, uint8_t u8Channel, struct _VBVAHOSTCMD ** ppCmd);
|
---|
325 |
|
---|
326 |
|
---|
327 | int vboxVBVAChannelDisplayEnable(PDEVICE_EXTENSION PrimaryExtension,
|
---|
328 | int iDisplay, /* negative would mean this is a miniport handler */
|
---|
329 | uint8_t u8Channel);
|
---|
330 |
|
---|
331 | VOID VBoxVideoHGSMIDpc(
|
---|
332 | IN PVOID HwDeviceExtension,
|
---|
333 | IN PVOID Context
|
---|
334 | );
|
---|
335 |
|
---|
336 | void HGSMIClearIrq (PDEVICE_EXTENSION PrimaryExtension);
|
---|
337 |
|
---|
338 | #endif /* VBOX_WITH_HGSMI */
|
---|
339 | } /* extern "C" */
|
---|
340 |
|
---|
341 | #endif /* VBOXVIDEO_H */
|
---|