VirtualBox

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

Last change on this file since 32930 was 32915, checked in by vboxsync, 14 years ago

Additions/WINNT/Graphics: more refactorings

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