VirtualBox

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

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

wddm/3d: basics for visible regions handling

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette