VirtualBox

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

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

wddm: driver update w/o reboot working; dummy context creation in CreateDevice

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