VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h@ 28800

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.7 KB
Line 
1/** @file
2 * VirtualBox Video miniport driver
3 *
4 * Copyright (C) 2006-2007 Oracle Corporation
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
15#ifndef VBOXVIDEO_H
16#define VBOXVIDEO_H
17
18#include <VBox/cdefs.h>
19#include <VBox/types.h>
20#include <iprt/assert.h>
21
22#ifdef VBOX_WITH_HGSMI
23//#include <iprt/thread.h>
24
25#include <VBox/HGSMI/HGSMI.h>
26#include <VBox/HGSMI/HGSMIChSetup.h>
27#include "VBoxHGSMI.h"
28#endif /* VBOX_WITH_HGSMI */
29
30RT_C_DECLS_BEGIN
31#ifndef VBOXWDDM
32#include "dderror.h"
33#include "devioctl.h"
34#include "miniport.h"
35#include "ntddvdeo.h"
36#include "video.h"
37#else
38# define VBOX_WITH_WORKAROUND_MISSING_PACK
39# if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
40# define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
41# define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
42# define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
43# define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
44# define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
45# define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
46# define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
47# define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
48# pragma warning(disable : 4163)
49# ifdef VBOX_WITH_WORKAROUND_MISSING_PACK
50# pragma warning(disable : 4103)
51# endif
52# include <ntddk.h>
53# pragma warning(default : 4163)
54# ifdef VBOX_WITH_WORKAROUND_MISSING_PACK
55# pragma pack()
56# pragma warning(default : 4103)
57# endif
58# undef _InterlockedExchange
59# undef _InterlockedExchangeAdd
60# undef _InterlockedCompareExchange
61# undef _InterlockedAddLargeStatistic
62# undef _interlockedbittestandset
63# undef _interlockedbittestandreset
64# undef _interlockedbittestandset64
65# undef _interlockedbittestandreset64
66# else
67# include <ntddk.h>
68# endif
69#include "dispmprt.h"
70#include "ntddvdeo.h"
71#include "dderror.h"
72#endif
73RT_C_DECLS_END
74
75#define VBE_DISPI_IOPORT_INDEX 0x01CE
76#define VBE_DISPI_IOPORT_DATA 0x01CF
77#define VBE_DISPI_INDEX_ID 0x0
78#define VBE_DISPI_INDEX_XRES 0x1
79#define VBE_DISPI_INDEX_YRES 0x2
80#define VBE_DISPI_INDEX_BPP 0x3
81#define VBE_DISPI_INDEX_ENABLE 0x4
82#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
83#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
84#define VBE_DISPI_INDEX_X_OFFSET 0x8
85#define VBE_DISPI_INDEX_Y_OFFSET 0x9
86#define VBE_DISPI_INDEX_VBOX_VIDEO 0xa
87
88#define VBE_DISPI_ID2 0xB0C2
89/* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
90#define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
91#ifdef VBOX_WITH_HGSMI
92#define VBE_DISPI_ID_HGSMI 0xBE01
93#endif /* VBOX_WITH_HGSMI */
94#define VBE_DISPI_DISABLED 0x00
95#define VBE_DISPI_ENABLED 0x01
96#define VBE_DISPI_LFB_ENABLED 0x40
97#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
98#define VBE_DISPI_TOTAL_VIDEO_MEMORY_MB 4
99#define VBE_DISPI_TOTAL_VIDEO_MEMORY_KB (VBE_DISPI_TOTAL_VIDEO_MEMORY_MB * 1024)
100#define VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES (VBE_DISPI_TOTAL_VIDEO_MEMORY_KB * 1024)
101
102#ifdef VBOX_WITH_HGSMI
103#define VGA_PORT_HGSMI_HOST 0x3b0
104#define VGA_PORT_HGSMI_GUEST 0x3d0
105#endif /* VBOX_WITH_HGSMI */
106
107/* common API types */
108#ifndef VBOXWDDM
109typedef PSPIN_LOCK VBOXVCMNSPIN_LOCK, *PVBOXVCMNSPIN_LOCK;
110typedef UCHAR VBOXVCMNIRQL, *PVBOXVCMNIRQL;
111
112typedef PEVENT VBOXVCMNEVENT, *PVBOXVCMNEVENT;
113
114typedef struct _DEVICE_EXTENSION * VBOXCMNREG;
115#else
116#include <VBox/VBoxVideo.h>
117#include "wddm/VBoxVideoWddm.h"
118#include "wddm/VBoxVideoShgsmi.h"
119#include "wddm/VBoxVideoVdma.h"
120#include "wddm/VBoxVideoVidPn.h"
121#ifdef VBOXWDDM_WITH_VBVA
122# include "wddm/VBoxVideoVbva.h"
123#endif
124
125
126typedef KSPIN_LOCK VBOXVCMNSPIN_LOCK, *PVBOXVCMNSPIN_LOCK;
127typedef KIRQL VBOXVCMNIRQL, *PVBOXVCMNIRQL;
128
129typedef KEVENT VBOXVCMNEVENT, *PVBOXVCMNEVENT;
130
131typedef HANDLE VBOXCMNREG;
132
133#define VBOXWDDM_POINTER_ATTRIBUTES_SIZE VBOXWDDM_ROUNDBOUND( \
134 VBOXWDDM_ROUNDBOUND( sizeof (VIDEO_POINTER_ATTRIBUTES), 4 ) + \
135 VBOXWDDM_ROUNDBOUND(VBOXWDDM_C_POINTER_MAX_WIDTH * VBOXWDDM_C_POINTER_MAX_HEIGHT * 4, 4) + \
136 VBOXWDDM_ROUNDBOUND((VBOXWDDM_C_POINTER_MAX_WIDTH * VBOXWDDM_C_POINTER_MAX_HEIGHT + 7) >> 3, 4) \
137 , 8)
138
139typedef struct VBOXWDDM_POINTER_INFO
140{
141 uint32_t xPos;
142 uint32_t yPos;
143 union
144 {
145 VIDEO_POINTER_ATTRIBUTES data;
146 char buffer[VBOXWDDM_POINTER_ATTRIBUTES_SIZE];
147 } Attributes;
148} VBOXWDDM_POINTER_INFO, *PVBOXWDDM_POINTER_INFO;
149
150typedef struct VBOXWDDM_SOURCE
151{
152 struct VBOXWDDM_ALLOCATION * pPrimaryAllocation;
153#ifdef VBOXWDDM_RENDER_FROM_SHADOW
154 struct VBOXWDDM_ALLOCATION * pShadowAllocation;
155 VBOXVIDEOOFFSET offVram;
156 VBOXWDDM_SURFACE_DESC SurfInfo;
157 VBOXVBVAINFO Vbva;
158#endif
159 VBOXWDDM_POINTER_INFO PointerInfo;
160} VBOXWDDM_SOURCE, *PVBOXWDDM_SOURCE;
161
162#endif
163
164typedef struct _DEVICE_EXTENSION
165{
166 struct _DEVICE_EXTENSION *pNext; /* Next extension in the DualView extension list.
167 * The primary extension is the first one.
168 */
169#ifndef VBOXWDDM
170 struct _DEVICE_EXTENSION *pPrimary; /* Pointer to the primary device extension. */
171
172 ULONG iDevice; /* Device index: 0 for primary, otherwise a secondary device. */
173
174 ULONG CurrentMode; /* Saved information about video modes */
175 ULONG CurrentModeWidth;
176 ULONG CurrentModeHeight;
177 ULONG CurrentModeBPP;
178
179 ULONG ulFrameBufferOffset; /* The framebuffer position in the VRAM. */
180 ULONG ulFrameBufferSize; /* The size of the current framebuffer. */
181#endif
182 union {
183 /* Information that is only relevant to the primary device or is the same for all devices. */
184 struct {
185
186 void *pvReqFlush; /* Pointer to preallocated generic request structure for
187 * VMMDevReq_VideoAccelFlush. Allocated when VBVA status
188 * is changed. Deallocated on HwReset.
189 */
190
191
192 ULONG ulVbvaEnabled; /* Indicates that VBVA mode is enabled. */
193
194 BOOLEAN bVBoxVideoSupported; /* TRUE if VBoxVideo extensions, including DualView, are supported by the host. */
195#ifndef VBOXWDDM
196 int cDisplays; /* Number of displays. */
197#endif
198 ULONG cbVRAM; /* The VRAM size. */
199
200 ULONG cbMiniportHeap; /* The size of reserved VRAM for miniport driver heap.
201 * It is at offset:
202 * cbAdapterMemorySize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE - cbMiniportHeap
203 */
204 PVOID pvMiniportHeap; /* The pointer to the miniport heap VRAM.
205 * This is mapped by miniport separately.
206 */
207#ifdef VBOXWDDM
208 VBOXVDMAINFO Vdma;
209# ifdef VBOXVDMA_WITH_VBVA
210 VBOXVBVAINFO Vbva;
211# endif
212#endif
213
214#ifdef VBOX_WITH_HGSMI
215 volatile HGSMIHOSTFLAGS * pHostFlags; /* HGSMI host flags */
216 volatile bool bHostCmdProcessing;
217 VBOXVCMNSPIN_LOCK pSynchLock;
218#endif
219
220 PVOID pvAdapterInformation; /* The pointer to the last 4K of VRAM.
221 * This is mapped by miniport separately.
222 */
223
224 ULONG ulMaxFrameBufferSize; /* The size of the VRAM allocated for the a single framebuffer. */
225
226 BOOLEAN fMouseHidden; /* Has the mouse cursor been hidden by the guest? */
227
228#ifndef VBOX_WITH_HGSMI
229 ULONG ulDisplayInformationSize; /* The size of the Display information, which is at offset:
230 * ulFrameBufferOffset + ulMaxFrameBufferSize.
231 */
232#endif /* !VBOX_WITH_HGSMI */
233
234#ifdef VBOX_WITH_HGSMI
235 BOOLEAN bHGSMI; /* Whether HGSMI is enabled. */
236
237 HGSMIAREA areaHostHeap; /* Host heap VRAM area. */
238
239 HGSMICHANNELINFO channels;
240
241 HGSMIHEAP hgsmiAdapterHeap;
242
243 /* The IO Port Number for host commands. */
244 RTIOPORT IOPortHost;
245
246 /* The IO Port Number for guest commands. */
247 RTIOPORT IOPortGuest;
248# ifndef VBOXWDDM
249 /* Video Port API dynamically picked up at runtime for binary backwards compatibility with older NT versions */
250 VBOXVIDEOPORTPROCS VideoPortProcs;
251# else
252 /* Display Port handle and callbacks */
253 DXGKRNL_INTERFACE DxgkInterface;
254# endif
255#endif /* VBOX_WITH_HGSMI */
256 } primary;
257
258 /* Secondary device information. */
259 struct {
260 BOOLEAN bEnabled; /* Device enabled flag */
261 } secondary;
262 } u;
263
264#ifdef VBOX_WITH_HGSMI
265 HGSMIAREA areaDisplay; /* Entire VRAM chunk for this display device. */
266#endif /* VBOX_WITH_HGSMI */
267
268#ifdef VBOXWDDM
269 PDEVICE_OBJECT pPDO;
270
271 VBOXSHGSMILIST CtlList;
272 VBOXSHGSMILIST DmaCmdList;
273 BOOL bSetNotifyDxDpc;
274 BOOL bNotifyDxDpc;
275
276 ULONG cSources;
277 /* currently we define the array for the max possible size since we do not know
278 * the monitor count at the DxgkDdiAddDevice,
279 * i.e. we obtain the monitor count in DxgkDdiStartDevice due to implementation of the currently re-used XPDM functionality
280 *
281 * @todo: use the dynamic array size calculated at DxgkDdiAddDevice
282 * */
283 VBOXWDDM_SOURCE aSources[VBOX_VIDEO_MAX_SCREENS];
284#endif
285} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
286
287#ifndef VBOXWDDM
288#define DEV_MOUSE_HIDDEN(dev) ((dev)->pPrimary->u.primary.fMouseHidden)
289#define DEV_SET_MOUSE_HIDDEN(dev) \
290do { \
291 (dev)->pPrimary->u.primary.fMouseHidden = TRUE; \
292} while (0)
293#define DEV_SET_MOUSE_SHOWN(dev) \
294do { \
295 (dev)->pPrimary->u.primary.fMouseHidden = FALSE; \
296} while (0)
297#else
298#define DEV_MOUSE_HIDDEN(dev) ((dev)->u.primary.fMouseHidden)
299#define DEV_SET_MOUSE_HIDDEN(dev) \
300do { \
301 (dev)->u.primary.fMouseHidden = TRUE; \
302} while (0)
303#define DEV_SET_MOUSE_SHOWN(dev) \
304do { \
305 (dev)->u.primary.fMouseHidden = FALSE; \
306} while (0)
307#endif
308extern "C"
309{
310#ifndef VBOXWDDM
311/* XPDM-WDDM common API */
312
313typedef PEVENT VBOXVCMNEVENT, *PVBOXVCMNEVENT;
314
315DECLINLINE(VOID) VBoxVideoCmnPortWriteUchar(IN PUCHAR Port, IN UCHAR Value)
316{
317 VideoPortWritePortUchar(Port,Value);
318}
319
320DECLINLINE(VOID) VBoxVideoCmnPortWriteUshort(IN PUSHORT Port, IN USHORT Value)
321{
322 VideoPortWritePortUshort(Port,Value);
323}
324
325DECLINLINE(VOID) VBoxVideoCmnPortWriteUlong(IN PULONG Port, IN ULONG Value)
326{
327 VideoPortWritePortUlong(Port,Value);
328}
329
330DECLINLINE(UCHAR) VBoxVideoCmnPortReadUchar(IN PUCHAR Port)
331{
332 return VideoPortReadPortUchar(Port);
333}
334
335DECLINLINE(USHORT) VBoxVideoCmnPortReadUshort(IN PUSHORT Port)
336{
337 return VideoPortReadPortUshort(Port);
338}
339
340DECLINLINE(ULONG) VBoxVideoCmnPortReadUlong(IN PULONG Port)
341{
342 return VideoPortReadPortUlong(Port);
343}
344
345DECLINLINE(VOID) VBoxVideoCmnMemZero(PVOID pvMem, ULONG cbMem)
346{
347 VideoPortZeroMemory(pvMem, cbMem);
348}
349
350DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquire(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, OUT PVBOXVCMNIRQL OldIrql)
351{
352 pDeviceExtension->u.primary.VideoPortProcs.pfnAcquireSpinLock(pDeviceExtension, *SpinLock, OldIrql);
353}
354
355DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquireAtDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
356{
357 pDeviceExtension->u.primary.VideoPortProcs.pfnAcquireSpinLockAtDpcLevel(pDeviceExtension, *SpinLock);
358}
359
360DECLINLINE(VOID) VBoxVideoCmnSpinLockRelease(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, IN VBOXVCMNIRQL NewIrql)
361{
362 pDeviceExtension->u.primary.VideoPortProcs.pfnReleaseSpinLock(pDeviceExtension, *SpinLock, NewIrql);
363}
364
365DECLINLINE(VOID) VBoxVideoCmnSpinLockReleaseFromDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
366{
367 pDeviceExtension->u.primary.VideoPortProcs.pfnReleaseSpinLockFromDpcLevel(pDeviceExtension, *SpinLock);
368}
369
370DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockCreate(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
371{
372 return pDeviceExtension->u.primary.VideoPortProcs.pfnCreateSpinLock(pDeviceExtension, SpinLock);
373}
374
375DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
376{
377 return pDeviceExtension->u.primary.VideoPortProcs.pfnDeleteSpinLock(pDeviceExtension, *SpinLock);
378}
379
380DECLINLINE(LONG) VBoxVideoCmnEventSet(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
381{
382 return pDeviceExtension->u.primary.VideoPortProcs.pfnSetEvent(pDeviceExtension, *pEvent);
383}
384
385DECLINLINE(VP_STATUS) VBoxVideoCmnEventCreateNotification(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent, IN BOOLEAN bSignaled)
386{
387 ULONG fFlags = NOTIFICATION_EVENT;
388 if(bSignaled)
389 fFlags |= INITIAL_EVENT_SIGNALED;
390
391 return pDeviceExtension->u.primary.VideoPortProcs.pfnCreateEvent(pDeviceExtension, fFlags, NULL, pEvent);
392}
393
394DECLINLINE(VP_STATUS) VBoxVideoCmnEventDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
395{
396 return pDeviceExtension->u.primary.VideoPortProcs.pfnDeleteEvent(pDeviceExtension, *pEvent);
397}
398
399DECLINLINE(PVOID) VBoxVideoCmnMemAllocNonPaged(IN PDEVICE_EXTENSION pDeviceExtension, IN SIZE_T NumberOfBytes, IN ULONG Tag)
400{
401 return pDeviceExtension->u.primary.VideoPortProcs.pfnAllocatePool(pDeviceExtension, (VBOXVP_POOL_TYPE)VpNonPagedPool, NumberOfBytes, Tag);
402}
403
404DECLINLINE(VOID) VBoxVideoCmnMemFree(IN PDEVICE_EXTENSION pDeviceExtension, IN PVOID Ptr)
405{
406 pDeviceExtension->u.primary.VideoPortProcs.pfnFreePool(pDeviceExtension, Ptr);
407}
408
409DECLINLINE(VP_STATUS) VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg)
410{
411 *pReg = pDeviceExtension->pPrimary;
412 return NO_ERROR;
413}
414
415DECLINLINE(VP_STATUS) VBoxVideoCmnRegFini(IN VBOXCMNREG Reg)
416{
417 return NO_ERROR;
418}
419
420VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal);
421
422VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val);
423
424/* */
425
426RT_C_DECLS_BEGIN
427ULONG DriverEntry(IN PVOID Context1, IN PVOID Context2);
428RT_C_DECLS_END
429
430VP_STATUS VBoxVideoFindAdapter(
431 IN PVOID HwDeviceExtension,
432 IN PVOID HwContext,
433 IN PWSTR ArgumentString,
434 IN OUT PVIDEO_PORT_CONFIG_INFO ConfigInfo,
435 OUT PUCHAR Again);
436
437BOOLEAN VBoxVideoInitialize(PVOID HwDeviceExtension);
438
439BOOLEAN VBoxVideoStartIO(
440 PVOID HwDeviceExtension,
441 PVIDEO_REQUEST_PACKET RequestPacket);
442
443#if defined(VBOX_WITH_HGSMI) && defined(VBOX_WITH_VIDEOHWACCEL)
444BOOLEAN VBoxVideoInterrupt(PVOID HwDeviceExtension);
445#endif
446
447
448BOOLEAN VBoxVideoResetHW(
449 PVOID HwDeviceExtension,
450 ULONG Columns,
451 ULONG Rows);
452
453VP_STATUS VBoxVideoGetPowerState(
454 PVOID HwDeviceExtension,
455 ULONG HwId,
456 PVIDEO_POWER_MANAGEMENT VideoPowerControl);
457
458VP_STATUS VBoxVideoSetPowerState(
459 PVOID HwDeviceExtension,
460 ULONG HwId,
461 PVIDEO_POWER_MANAGEMENT VideoPowerControl);
462
463VP_STATUS VBoxVideoGetChildDescriptor(
464 PVOID HwDeviceExtension,
465 PVIDEO_CHILD_ENUM_INFO ChildEnumInfo,
466 PVIDEO_CHILD_TYPE VideoChildType,
467 PUCHAR pChildDescriptor,
468 PULONG pUId,
469 PULONG pUnused);
470
471
472void VBoxSetupVideoPortFunctions(PDEVICE_EXTENSION PrimaryExtension,
473 VBOXVIDEOPORTPROCS *pCallbacks,
474 PVIDEO_PORT_CONFIG_INFO pConfigInfo);
475
476#else
477
478/* XPDM-WDDM common API */
479DECLINLINE(VOID) VBoxVideoCmnPortWriteUchar(IN PUCHAR Port, IN UCHAR Value)
480{
481 WRITE_PORT_UCHAR(Port,Value);
482}
483
484DECLINLINE(VOID) VBoxVideoCmnPortWriteUshort(IN PUSHORT Port, IN USHORT Value)
485{
486 WRITE_PORT_USHORT(Port,Value);
487}
488
489DECLINLINE(VOID) VBoxVideoCmnPortWriteUlong(IN PULONG Port, IN ULONG Value)
490{
491 WRITE_PORT_ULONG(Port,Value);
492}
493
494DECLINLINE(UCHAR) VBoxVideoCmnPortReadUchar(IN PUCHAR Port)
495{
496 return READ_PORT_UCHAR(Port);
497}
498
499DECLINLINE(USHORT) VBoxVideoCmnPortReadUshort(IN PUSHORT Port)
500{
501 return READ_PORT_USHORT(Port);
502}
503
504DECLINLINE(ULONG) VBoxVideoCmnPortReadUlong(IN PULONG Port)
505{
506 return READ_PORT_ULONG(Port);
507}
508
509DECLINLINE(VOID) VBoxVideoCmnMemZero(PVOID pvMem, ULONG cbMem)
510{
511 memset(pvMem, 0, cbMem);
512}
513
514DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquire(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, OUT PVBOXVCMNIRQL OldIrql)
515{
516 KeAcquireSpinLock(SpinLock, OldIrql);
517}
518
519DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquireAtDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
520{
521 KeAcquireSpinLockAtDpcLevel(SpinLock);
522}
523
524DECLINLINE(VOID) VBoxVideoCmnSpinLockRelease(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, IN VBOXVCMNIRQL NewIrql)
525{
526 KeReleaseSpinLock(SpinLock, NewIrql);
527}
528
529DECLINLINE(VOID) VBoxVideoCmnSpinLockReleaseFromDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
530{
531 KeReleaseSpinLockFromDpcLevel(SpinLock);
532}
533
534DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockCreate(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
535{
536 KeInitializeSpinLock(SpinLock);
537 return NO_ERROR;
538}
539
540DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
541{
542 return NO_ERROR;
543}
544
545DECLINLINE(LONG) VBoxVideoCmnEventSet(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
546{
547 return KeSetEvent(pEvent, 0, FALSE);
548}
549
550DECLINLINE(VP_STATUS) VBoxVideoCmnEventCreateNotification(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent, IN BOOLEAN bSignaled)
551{
552 KeInitializeEvent(pEvent, NotificationEvent, bSignaled);
553 return NO_ERROR;
554}
555
556DECLINLINE(VP_STATUS) VBoxVideoCmnEventDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
557{
558 return NO_ERROR;
559}
560
561DECLINLINE(PVOID) VBoxVideoCmnMemAllocNonPaged(IN PDEVICE_EXTENSION pDeviceExtension, IN SIZE_T NumberOfBytes, IN ULONG Tag)
562{
563 return ExAllocatePoolWithTag(NonPagedPool, NumberOfBytes, Tag);
564}
565
566DECLINLINE(VOID) VBoxVideoCmnMemFree(IN PDEVICE_EXTENSION pDeviceExtension, IN PVOID Ptr)
567{
568 ExFreePool(Ptr);
569}
570
571VP_STATUS VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg);
572
573DECLINLINE(VP_STATUS) VBoxVideoCmnRegFini(IN VBOXCMNREG Reg)
574{
575 if(!Reg)
576 return ERROR_INVALID_PARAMETER;
577
578 NTSTATUS Status = ZwClose(Reg);
579 return Status == STATUS_SUCCESS ? NO_ERROR : ERROR_INVALID_PARAMETER;
580}
581
582VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal);
583
584VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val);
585
586/* */
587
588RT_C_DECLS_BEGIN
589NTSTATUS
590DriverEntry(
591 IN PDRIVER_OBJECT DriverObject,
592 IN PUNICODE_STRING RegistryPath
593 );
594RT_C_DECLS_END
595
596typedef struct VBOXWDDM_VIDEOMODES
597{
598 VIDEO_MODE_INFORMATION *pModes;
599 uint32_t cModes;
600 D3DKMDT_2DREGION pResolutions;
601 uint32_t cResolutions;
602 int32_t iPreferrableMode;
603 int32_t iCustomMode;
604} VBOXWDDM_VIDEOMODES;
605
606VOID VBoxWddmGetModesTable(PDEVICE_EXTENSION DeviceExtension, bool bRebuildTable,
607 VIDEO_MODE_INFORMATION ** ppModes, uint32_t * pcModes, int32_t * pPreferrableMode,
608 D3DKMDT_2DREGION **ppResolutions, uint32_t * pcResolutions);
609
610VOID VBoxWddmInvalidateModesTable(PDEVICE_EXTENSION DeviceExtension);
611
612/* @return STATUS_BUFFER_TOO_SMALL - if buffer is too small, STATUS_SUCCESS - on success */
613NTSTATUS VBoxWddmGetModesForResolution(PDEVICE_EXTENSION DeviceExtension, bool bRebuildTable,
614 D3DKMDT_2DREGION *pResolution,
615 VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t * piPreferrableMode);
616
617D3DDDIFORMAT vboxWddmCalcPixelFormat(VIDEO_MODE_INFORMATION *pInfo);
618UINT vboxWddmCalcBitsPerPixel(D3DDDIFORMAT format);
619
620DECLINLINE(ULONG) vboxWddmVramCpuVisibleSize(PDEVICE_EXTENSION pDevExt)
621{
622#ifdef VBOXWDDM_RENDER_FROM_SHADOW
623 /* all memory layout info should be initialized */
624 Assert(pDevExt->aSources[0].Vbva.offVBVA);
625 /* page aligned */
626 Assert(!(pDevExt->aSources[0].Vbva.offVBVA & 0xfff));
627
628 return (ULONG)(pDevExt->aSources[0].Vbva.offVBVA & ~0xfffULL);
629#else
630 /* all memory layout info should be initialized */
631 Assert(pDevExt->u.primary.Vdma.CmdHeap.area.offBase);
632 /* page aligned */
633 Assert(!(pDevExt->u.primary.Vdma.CmdHeap.area.offBase & 0xfff));
634
635 return pDevExt->u.primary.Vdma.CmdHeap.area.offBase & ~0xfffUL;
636#endif
637}
638
639DECLINLINE(ULONG) vboxWddmVramCpuVisibleSegmentSize(PDEVICE_EXTENSION pDevExt)
640{
641 return vboxWddmVramCpuVisibleSize(pDevExt);
642}
643
644#ifdef VBOXWDDM_RENDER_FROM_SHADOW
645DECLINLINE(ULONG) vboxWddmVramCpuInvisibleSegmentSize(PDEVICE_EXTENSION pDevExt)
646{
647 return vboxWddmVramCpuVisibleSegmentSize(pDevExt);
648}
649
650DECLINLINE(bool) vboxWddmCmpSurfDescs(VBOXWDDM_SURFACE_DESC *pDesc1, VBOXWDDM_SURFACE_DESC *pDesc2)
651{
652 if (pDesc1->width != pDesc2->width)
653 return false;
654 if (pDesc1->height != pDesc2->height)
655 return false;
656 if (pDesc1->format != pDesc2->format)
657 return false;
658 if (pDesc1->bpp != pDesc2->bpp)
659 return false;
660 if (pDesc1->pitch != pDesc2->pitch)
661 return false;
662 return true;
663}
664
665DECLINLINE(void) vboxWddmAssignShadow(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
666{
667 if (pSource->pShadowAllocation == pAllocation)
668 return;
669
670 if (pSource->pShadowAllocation)
671 {
672 PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pShadowAllocation;
673 PVBOXWDDM_ALLOCATION_SHADOWSURFACE pOldShadowInfo = VBOXWDDM_ALLOCATION_BODY(pOldAlloc, VBOXWDDM_ALLOCATION_SHADOWSURFACE);
674 /* clear the visibility info fo the current primary */
675 pOldShadowInfo->bVisible = FALSE;
676 pOldShadowInfo->bAssigned = FALSE;
677 Assert(pOldShadowInfo->VidPnSourceId == srcId);
678 /* release the shadow surface */
679 pOldShadowInfo->VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
680 }
681
682 if (pAllocation)
683 {
684 PVBOXWDDM_ALLOCATION_SHADOWSURFACE pShadowInfo = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHADOWSURFACE);
685 pShadowInfo->bVisible = FALSE;
686 /* this check ensures the shadow is not used for other source simultaneously */
687 Assert(pShadowInfo->VidPnSourceId == D3DDDI_ID_UNINITIALIZED);
688 pShadowInfo->VidPnSourceId = srcId;
689 pShadowInfo->bAssigned = TRUE;
690 if (!vboxWddmCmpSurfDescs(&pSource->SurfInfo, &pAllocation->u.SurfInfo))
691 pSource->offVram = VBOXVIDEOOFFSET_VOID; /* force guest->host notification */
692 pSource->SurfInfo = pAllocation->u.SurfInfo;
693 }
694
695 pSource->pShadowAllocation = pAllocation;
696}
697#endif
698
699DECLINLINE(VOID) vboxWddmAssignPrimary(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
700{
701 if (pSource->pPrimaryAllocation == pAllocation)
702 return;
703
704 if (pSource->pPrimaryAllocation)
705 {
706 PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pPrimaryAllocation;
707 PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pOldPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pOldAlloc, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
708 /* clear the visibility info fo the current primary */
709 pOldPrimaryInfo->bVisible = FALSE;
710 pOldPrimaryInfo->bAssigned = FALSE;
711 Assert(pOldPrimaryInfo->VidPnSourceId == srcId);
712 }
713
714 if (pAllocation)
715 {
716 PVBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE pPrimaryInfo = VBOXWDDM_ALLOCATION_BODY(pAllocation, VBOXWDDM_ALLOCATION_SHAREDPRIMARYSURFACE);
717 pPrimaryInfo->bVisible = FALSE;
718 Assert(pPrimaryInfo->VidPnSourceId == srcId);
719 pPrimaryInfo->VidPnSourceId = srcId;
720 pPrimaryInfo->bAssigned = TRUE;
721 }
722
723 pSource->pPrimaryAllocation = pAllocation;
724}
725
726#endif
727
728void* vboxHGSMIBufferAlloc(PDEVICE_EXTENSION PrimaryExtension,
729 HGSMISIZE cbData,
730 uint8_t u8Ch,
731 uint16_t u16Op);
732void vboxHGSMIBufferFree (PDEVICE_EXTENSION PrimaryExtension, void *pvBuffer);
733int vboxHGSMIBufferSubmit (PDEVICE_EXTENSION PrimaryExtension, void *pvBuffer);
734
735BOOLEAN FASTCALL VBoxVideoSetCurrentModePerform(PDEVICE_EXTENSION DeviceExtension,
736 USHORT width, USHORT height, USHORT bpp
737#ifdef VBOXWDDM
738 , ULONG offDisplay
739#endif
740 );
741
742BOOLEAN FASTCALL VBoxVideoSetCurrentMode(
743 PDEVICE_EXTENSION DeviceExtension,
744 PVIDEO_MODE RequestedMode,
745 PSTATUS_BLOCK StatusBlock);
746
747BOOLEAN FASTCALL VBoxVideoResetDevice(
748 PDEVICE_EXTENSION DeviceExtension,
749 PSTATUS_BLOCK StatusBlock);
750
751BOOLEAN FASTCALL VBoxVideoMapVideoMemory(
752 PDEVICE_EXTENSION DeviceExtension,
753 PVIDEO_MEMORY RequestedAddress,
754 PVIDEO_MEMORY_INFORMATION MapInformation,
755 PSTATUS_BLOCK StatusBlock);
756
757BOOLEAN FASTCALL VBoxVideoUnmapVideoMemory(
758 PDEVICE_EXTENSION DeviceExtension,
759 PVIDEO_MEMORY VideoMemory,
760 PSTATUS_BLOCK StatusBlock);
761
762BOOLEAN FASTCALL VBoxVideoQueryNumAvailModes(
763 PDEVICE_EXTENSION DeviceExtension,
764 PVIDEO_NUM_MODES Modes,
765 PSTATUS_BLOCK StatusBlock);
766
767BOOLEAN FASTCALL VBoxVideoQueryAvailModes(
768 PDEVICE_EXTENSION DeviceExtension,
769 PVIDEO_MODE_INFORMATION ReturnedModes,
770 PSTATUS_BLOCK StatusBlock);
771
772BOOLEAN FASTCALL VBoxVideoQueryCurrentMode(
773 PDEVICE_EXTENSION DeviceExtension,
774 PVIDEO_MODE_INFORMATION VideoModeInfo,
775 PSTATUS_BLOCK StatusBlock);
776
777BOOLEAN FASTCALL VBoxVideoSetColorRegisters(
778 PDEVICE_EXTENSION DeviceExtension,
779 PVIDEO_CLUT ColorLookUpTable,
780 PSTATUS_BLOCK StatusBlock);
781
782int VBoxMapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
783 void **ppv,
784 ULONG ulOffset,
785 ULONG ulSize);
786
787void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
788 void **ppv, ULONG ulSize);
789
790void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension);
791
792#ifdef VBOX_WITH_HGSMI
793
794/*
795 * Host and Guest port IO helpers.
796 */
797DECLINLINE(void) VBoxHGSMIHostWrite(PDEVICE_EXTENSION PrimaryExtension, ULONG data)
798{
799#ifndef VBOXWDDM
800 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortHost, data);
801#else
802 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->u.primary.IOPortHost, data);
803#endif
804}
805
806DECLINLINE(ULONG) VBoxHGSMIHostRead(PDEVICE_EXTENSION PrimaryExtension)
807{
808#ifndef VBOXWDDM
809 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortHost);
810#else
811 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->u.primary.IOPortHost);
812#endif
813}
814
815DECLINLINE(void) VBoxHGSMIGuestWrite(PDEVICE_EXTENSION PrimaryExtension, ULONG data)
816{
817#ifndef VBOXWDDM
818 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortGuest, data);
819#else
820 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->u.primary.IOPortGuest, data);
821#endif
822}
823
824DECLINLINE(ULONG) VBoxHGSMIGuestRead(PDEVICE_EXTENSION PrimaryExtension)
825{
826#ifndef VBOXWDDM
827 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortGuest);
828#else
829 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->u.primary.IOPortGuest);
830#endif
831}
832
833BOOLEAN VBoxHGSMIIsSupported (PDEVICE_EXTENSION PrimaryExtension);
834
835VOID VBoxSetupDisplaysHGSMI (PDEVICE_EXTENSION PrimaryExtension,
836#ifndef VBOXWDDM
837 PVIDEO_PORT_CONFIG_INFO pConfigInfo,
838#endif
839 ULONG AdapterMemorySize);
840BOOLEAN vboxUpdatePointerShape (PDEVICE_EXTENSION DeviceExtension,
841 PVIDEO_POINTER_ATTRIBUTES pointerAttr,
842 uint32_t cbLength);
843#ifndef VBOXWDDM
844DECLCALLBACK(void) hgsmiHostCmdComplete (HVBOXVIDEOHGSMI hHGSMI, struct _VBVAHOSTCMD * pCmd);
845DECLCALLBACK(int) hgsmiHostCmdRequest (HVBOXVIDEOHGSMI hHGSMI, uint8_t u8Channel, struct _VBVAHOSTCMD ** ppCmd);
846#endif
847
848
849int vboxVBVAChannelDisplayEnable(PDEVICE_EXTENSION PrimaryExtension,
850 int iDisplay, /* negative would mean this is a miniport handler */
851 uint8_t u8Channel);
852
853VOID VBoxVideoHGSMIDpc(
854 IN PVOID HwDeviceExtension,
855 IN PVOID Context
856 );
857
858void HGSMIClearIrq (PDEVICE_EXTENSION PrimaryExtension);
859
860#endif /* VBOX_WITH_HGSMI */
861} /* extern "C" */
862
863#endif /* VBOXVIDEO_H */
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