VirtualBox

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

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

wddm/3d: more visible rects support & fixes, enhances to dma command handling

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.6 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 /* mutex for context list operations */
304 FAST_MUTEX ContextMutex;
305 volatile uint32_t cContexts3D;
306
307 VBOXSHGSMILIST CtlList;
308 VBOXSHGSMILIST DmaCmdList;
309#ifdef VBOX_WITH_VIDEOHWACCEL
310 VBOXSHGSMILIST VhwaCmdList;
311#endif
312 BOOL bSetNotifyDxDpc;
313 BOOL bNotifyDxDpc;
314
315 VBOXWDDM_SOURCE aSources[VBOX_VIDEO_MAX_SCREENS];
316 VBOXWDDM_TARGET aTargets[VBOX_VIDEO_MAX_SCREENS];
317#endif
318} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
319
320#ifndef VBOXWDDM
321#define DEV_MOUSE_HIDDEN(dev) ((dev)->pPrimary->u.primary.fMouseHidden)
322#define DEV_SET_MOUSE_HIDDEN(dev) \
323do { \
324 (dev)->pPrimary->u.primary.fMouseHidden = TRUE; \
325} while (0)
326#define DEV_SET_MOUSE_SHOWN(dev) \
327do { \
328 (dev)->pPrimary->u.primary.fMouseHidden = FALSE; \
329} while (0)
330#else
331#define DEV_MOUSE_HIDDEN(dev) ((dev)->u.primary.fMouseHidden)
332#define DEV_SET_MOUSE_HIDDEN(dev) \
333do { \
334 (dev)->u.primary.fMouseHidden = TRUE; \
335} while (0)
336#define DEV_SET_MOUSE_SHOWN(dev) \
337do { \
338 (dev)->u.primary.fMouseHidden = FALSE; \
339} while (0)
340#endif
341extern "C"
342{
343#ifndef VBOXWDDM
344/* XPDM-WDDM common API */
345
346typedef PEVENT VBOXVCMNEVENT;
347typedef VBOXVCMNEVENT *PVBOXVCMNEVENT;
348
349DECLINLINE(VOID) VBoxVideoCmnPortWriteUchar(IN PUCHAR Port, IN UCHAR Value)
350{
351 VideoPortWritePortUchar(Port,Value);
352}
353
354DECLINLINE(VOID) VBoxVideoCmnPortWriteUshort(IN PUSHORT Port, IN USHORT Value)
355{
356 VideoPortWritePortUshort(Port,Value);
357}
358
359DECLINLINE(VOID) VBoxVideoCmnPortWriteUlong(IN PULONG Port, IN ULONG Value)
360{
361 VideoPortWritePortUlong(Port,Value);
362}
363
364DECLINLINE(UCHAR) VBoxVideoCmnPortReadUchar(IN PUCHAR Port)
365{
366 return VideoPortReadPortUchar(Port);
367}
368
369DECLINLINE(USHORT) VBoxVideoCmnPortReadUshort(IN PUSHORT Port)
370{
371 return VideoPortReadPortUshort(Port);
372}
373
374DECLINLINE(ULONG) VBoxVideoCmnPortReadUlong(IN PULONG Port)
375{
376 return VideoPortReadPortUlong(Port);
377}
378
379DECLINLINE(VOID) VBoxVideoCmnMemZero(PVOID pvMem, ULONG cbMem)
380{
381 VideoPortZeroMemory(pvMem, cbMem);
382}
383
384DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquire(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, OUT PVBOXVCMNIRQL OldIrql)
385{
386 pDeviceExtension->u.primary.VideoPortProcs.pfnAcquireSpinLock(pDeviceExtension, *SpinLock, OldIrql);
387}
388
389DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquireAtDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
390{
391 pDeviceExtension->u.primary.VideoPortProcs.pfnAcquireSpinLockAtDpcLevel(pDeviceExtension, *SpinLock);
392}
393
394DECLINLINE(VOID) VBoxVideoCmnSpinLockRelease(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, IN VBOXVCMNIRQL NewIrql)
395{
396 pDeviceExtension->u.primary.VideoPortProcs.pfnReleaseSpinLock(pDeviceExtension, *SpinLock, NewIrql);
397}
398
399DECLINLINE(VOID) VBoxVideoCmnSpinLockReleaseFromDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
400{
401 pDeviceExtension->u.primary.VideoPortProcs.pfnReleaseSpinLockFromDpcLevel(pDeviceExtension, *SpinLock);
402}
403
404DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockCreate(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
405{
406 return pDeviceExtension->u.primary.VideoPortProcs.pfnCreateSpinLock(pDeviceExtension, SpinLock);
407}
408
409DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
410{
411 return pDeviceExtension->u.primary.VideoPortProcs.pfnDeleteSpinLock(pDeviceExtension, *SpinLock);
412}
413
414DECLINLINE(LONG) VBoxVideoCmnEventSet(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
415{
416 return pDeviceExtension->u.primary.VideoPortProcs.pfnSetEvent(pDeviceExtension, (VBOXPEVENT)*pEvent); /** @todo slightly bogus cast */
417}
418
419DECLINLINE(VP_STATUS) VBoxVideoCmnEventCreateNotification(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent, IN BOOLEAN bSignaled)
420{
421 ULONG fFlags = NOTIFICATION_EVENT;
422 if(bSignaled)
423 fFlags |= INITIAL_EVENT_SIGNALED;
424
425 return pDeviceExtension->u.primary.VideoPortProcs.pfnCreateEvent(pDeviceExtension, fFlags, NULL, (VBOXPEVENT *)pEvent); /** @todo slightly bogus cast */
426}
427
428DECLINLINE(VP_STATUS) VBoxVideoCmnEventDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
429{
430 return pDeviceExtension->u.primary.VideoPortProcs.pfnDeleteEvent(pDeviceExtension, (VBOXPEVENT)*pEvent); /** @todo slightly bogus cast */
431}
432
433DECLINLINE(PVOID) VBoxVideoCmnMemAllocNonPaged(IN PDEVICE_EXTENSION pDeviceExtension, IN SIZE_T NumberOfBytes, IN ULONG Tag)
434{
435 return pDeviceExtension->u.primary.VideoPortProcs.pfnAllocatePool(pDeviceExtension, (VBOXVP_POOL_TYPE)VpNonPagedPool, NumberOfBytes, Tag);
436}
437
438DECLINLINE(VOID) VBoxVideoCmnMemFree(IN PDEVICE_EXTENSION pDeviceExtension, IN PVOID Ptr)
439{
440 pDeviceExtension->u.primary.VideoPortProcs.pfnFreePool(pDeviceExtension, Ptr);
441}
442
443DECLINLINE(VP_STATUS) VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg)
444{
445 *pReg = pDeviceExtension->pPrimary;
446 return NO_ERROR;
447}
448
449DECLINLINE(VP_STATUS) VBoxVideoCmnRegFini(IN VBOXCMNREG Reg)
450{
451 return NO_ERROR;
452}
453
454VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal);
455
456VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val);
457
458/* */
459
460RT_C_DECLS_BEGIN
461ULONG DriverEntry(IN PVOID Context1, IN PVOID Context2);
462RT_C_DECLS_END
463
464VP_STATUS VBoxVideoFindAdapter(
465 IN PVOID HwDeviceExtension,
466 IN PVOID HwContext,
467 IN PWSTR ArgumentString,
468 IN OUT PVIDEO_PORT_CONFIG_INFO ConfigInfo,
469 OUT PUCHAR Again);
470
471BOOLEAN VBoxVideoInitialize(PVOID HwDeviceExtension);
472
473BOOLEAN VBoxVideoStartIO(
474 PVOID HwDeviceExtension,
475 PVIDEO_REQUEST_PACKET RequestPacket);
476
477#if defined(VBOX_WITH_HGSMI) && defined(VBOX_WITH_VIDEOHWACCEL)
478BOOLEAN VBoxVideoInterrupt(PVOID HwDeviceExtension);
479#endif
480
481
482BOOLEAN VBoxVideoResetHW(
483 PVOID HwDeviceExtension,
484 ULONG Columns,
485 ULONG Rows);
486
487VP_STATUS VBoxVideoGetPowerState(
488 PVOID HwDeviceExtension,
489 ULONG HwId,
490 PVIDEO_POWER_MANAGEMENT VideoPowerControl);
491
492VP_STATUS VBoxVideoSetPowerState(
493 PVOID HwDeviceExtension,
494 ULONG HwId,
495 PVIDEO_POWER_MANAGEMENT VideoPowerControl);
496
497VP_STATUS VBoxVideoGetChildDescriptor(
498 PVOID HwDeviceExtension,
499 PVIDEO_CHILD_ENUM_INFO ChildEnumInfo,
500 PVIDEO_CHILD_TYPE VideoChildType,
501 PUCHAR pChildDescriptor,
502 PULONG pUId,
503 PULONG pUnused);
504
505
506void VBoxSetupVideoPortFunctions(PDEVICE_EXTENSION PrimaryExtension,
507 VBOXVIDEOPORTPROCS *pCallbacks,
508 PVIDEO_PORT_CONFIG_INFO pConfigInfo);
509
510#else
511
512/* XPDM-WDDM common API */
513DECLINLINE(VOID) VBoxVideoCmnPortWriteUchar(IN PUCHAR Port, IN UCHAR Value)
514{
515 WRITE_PORT_UCHAR(Port,Value);
516}
517
518DECLINLINE(VOID) VBoxVideoCmnPortWriteUshort(IN PUSHORT Port, IN USHORT Value)
519{
520 WRITE_PORT_USHORT(Port,Value);
521}
522
523DECLINLINE(VOID) VBoxVideoCmnPortWriteUlong(IN PULONG Port, IN ULONG Value)
524{
525 WRITE_PORT_ULONG(Port,Value);
526}
527
528DECLINLINE(UCHAR) VBoxVideoCmnPortReadUchar(IN PUCHAR Port)
529{
530 return READ_PORT_UCHAR(Port);
531}
532
533DECLINLINE(USHORT) VBoxVideoCmnPortReadUshort(IN PUSHORT Port)
534{
535 return READ_PORT_USHORT(Port);
536}
537
538DECLINLINE(ULONG) VBoxVideoCmnPortReadUlong(IN PULONG Port)
539{
540 return READ_PORT_ULONG(Port);
541}
542
543DECLINLINE(VOID) VBoxVideoCmnMemZero(PVOID pvMem, ULONG cbMem)
544{
545 memset(pvMem, 0, cbMem);
546}
547
548DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquire(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, OUT PVBOXVCMNIRQL OldIrql)
549{
550 KeAcquireSpinLock(SpinLock, OldIrql);
551}
552
553DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquireAtDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
554{
555 KeAcquireSpinLockAtDpcLevel(SpinLock);
556}
557
558DECLINLINE(VOID) VBoxVideoCmnSpinLockRelease(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, IN VBOXVCMNIRQL NewIrql)
559{
560 KeReleaseSpinLock(SpinLock, NewIrql);
561}
562
563DECLINLINE(VOID) VBoxVideoCmnSpinLockReleaseFromDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
564{
565 KeReleaseSpinLockFromDpcLevel(SpinLock);
566}
567
568DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockCreate(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
569{
570 KeInitializeSpinLock(SpinLock);
571 return NO_ERROR;
572}
573
574DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
575{
576 return NO_ERROR;
577}
578
579DECLINLINE(LONG) VBoxVideoCmnEventSet(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
580{
581 return KeSetEvent(pEvent, 0, FALSE);
582}
583
584DECLINLINE(VP_STATUS) VBoxVideoCmnEventCreateNotification(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent, IN BOOLEAN bSignaled)
585{
586 KeInitializeEvent(pEvent, NotificationEvent, bSignaled);
587 return NO_ERROR;
588}
589
590DECLINLINE(VP_STATUS) VBoxVideoCmnEventDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
591{
592 return NO_ERROR;
593}
594
595DECLINLINE(PVOID) VBoxVideoCmnMemAllocNonPaged(IN PDEVICE_EXTENSION pDeviceExtension, IN SIZE_T NumberOfBytes, IN ULONG Tag)
596{
597 return ExAllocatePoolWithTag(NonPagedPool, NumberOfBytes, Tag);
598}
599
600DECLINLINE(VOID) VBoxVideoCmnMemFree(IN PDEVICE_EXTENSION pDeviceExtension, IN PVOID Ptr)
601{
602 ExFreePool(Ptr);
603}
604
605VP_STATUS VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg);
606
607DECLINLINE(VP_STATUS) VBoxVideoCmnRegFini(IN VBOXCMNREG Reg)
608{
609 if(!Reg)
610 return ERROR_INVALID_PARAMETER;
611
612 NTSTATUS Status = ZwClose(Reg);
613 return Status == STATUS_SUCCESS ? NO_ERROR : ERROR_INVALID_PARAMETER;
614}
615
616VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal);
617
618VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val);
619
620/* */
621
622RT_C_DECLS_BEGIN
623NTSTATUS
624DriverEntry(
625 IN PDRIVER_OBJECT DriverObject,
626 IN PUNICODE_STRING RegistryPath
627 );
628RT_C_DECLS_END
629
630typedef struct VBOXWDDM_VIDEOMODES
631{
632 VIDEO_MODE_INFORMATION *pModes;
633 uint32_t cModes;
634 D3DKMDT_2DREGION pResolutions;
635 uint32_t cResolutions;
636 int32_t iPreferrableMode;
637 int32_t iCustomMode;
638} VBOXWDDM_VIDEOMODES;
639
640VOID VBoxWddmGetModesTable(PDEVICE_EXTENSION DeviceExtension, bool bRebuildTable,
641 VIDEO_MODE_INFORMATION ** ppModes, uint32_t * pcModes, int32_t * pPreferrableMode,
642 D3DKMDT_2DREGION **ppResolutions, uint32_t * pcResolutions);
643
644VOID VBoxWddmInvalidateModesTable(PDEVICE_EXTENSION DeviceExtension);
645
646/* @return STATUS_BUFFER_TOO_SMALL - if buffer is too small, STATUS_SUCCESS - on success */
647NTSTATUS VBoxWddmGetModesForResolution(PDEVICE_EXTENSION DeviceExtension, bool bRebuildTable,
648 D3DKMDT_2DREGION *pResolution,
649 VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t * piPreferrableMode);
650
651D3DDDIFORMAT vboxWddmCalcPixelFormat(VIDEO_MODE_INFORMATION *pInfo);
652
653DECLINLINE(ULONG) vboxWddmVramCpuVisibleSize(PDEVICE_EXTENSION pDevExt)
654{
655#ifdef VBOXWDDM_RENDER_FROM_SHADOW
656 /* all memory layout info should be initialized */
657 Assert(pDevExt->aSources[0].Vbva.offVBVA);
658 /* page aligned */
659 Assert(!(pDevExt->aSources[0].Vbva.offVBVA & 0xfff));
660
661 return (ULONG)(pDevExt->aSources[0].Vbva.offVBVA & ~0xfffULL);
662#else
663 /* all memory layout info should be initialized */
664 Assert(pDevExt->u.primary.Vdma.CmdHeap.area.offBase);
665 /* page aligned */
666 Assert(!(pDevExt->u.primary.Vdma.CmdHeap.area.offBase & 0xfff));
667
668 return pDevExt->u.primary.Vdma.CmdHeap.area.offBase & ~0xfffUL;
669#endif
670}
671
672DECLINLINE(ULONG) vboxWddmVramCpuVisibleSegmentSize(PDEVICE_EXTENSION pDevExt)
673{
674 return vboxWddmVramCpuVisibleSize(pDevExt);
675}
676
677#ifdef VBOXWDDM_RENDER_FROM_SHADOW
678DECLINLINE(ULONG) vboxWddmVramCpuInvisibleSegmentSize(PDEVICE_EXTENSION pDevExt)
679{
680 return vboxWddmVramCpuVisibleSegmentSize(pDevExt);
681}
682
683DECLINLINE(bool) vboxWddmCmpSurfDescsBase(VBOXWDDM_SURFACE_DESC *pDesc1, VBOXWDDM_SURFACE_DESC *pDesc2)
684{
685 if (pDesc1->width != pDesc2->width)
686 return false;
687 if (pDesc1->height != pDesc2->height)
688 return false;
689 if (pDesc1->format != pDesc2->format)
690 return false;
691 if (pDesc1->bpp != pDesc2->bpp)
692 return false;
693 if (pDesc1->pitch != pDesc2->pitch)
694 return false;
695 return true;
696}
697
698DECLINLINE(void) vboxWddmAssignShadow(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
699{
700 if (pSource->pShadowAllocation == pAllocation)
701 return;
702
703 if (pSource->pShadowAllocation)
704 {
705 PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pShadowAllocation;
706 /* clear the visibility info fo the current primary */
707 pOldAlloc->bVisible = FALSE;
708 pOldAlloc->bAssigned = FALSE;
709 Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
710 /* release the shadow surface */
711 pOldAlloc->SurfDesc.VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
712 }
713
714 if (pAllocation)
715 {
716 pAllocation->bVisible = FALSE;
717 /* this check ensures the shadow is not used for other source simultaneously */
718 Assert(pAllocation->SurfDesc.VidPnSourceId == D3DDDI_ID_UNINITIALIZED);
719 pAllocation->SurfDesc.VidPnSourceId = srcId;
720 pAllocation->bAssigned = TRUE;
721 if (!vboxWddmCmpSurfDescsBase(&pSource->SurfDesc, &pAllocation->SurfDesc))
722 pSource->offVram = VBOXVIDEOOFFSET_VOID; /* force guest->host notification */
723 pSource->SurfDesc = pAllocation->SurfDesc;
724 }
725
726 pSource->pShadowAllocation = pAllocation;
727}
728#endif
729
730DECLINLINE(VOID) vboxWddmAssignPrimary(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
731{
732 if (pSource->pPrimaryAllocation == pAllocation)
733 return;
734
735 if (pSource->pPrimaryAllocation)
736 {
737 PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pPrimaryAllocation;
738 /* clear the visibility info fo the current primary */
739 pOldAlloc->bVisible = FALSE;
740 pOldAlloc->bAssigned = FALSE;
741 Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
742 }
743
744 if (pAllocation)
745 {
746 pAllocation->bVisible = FALSE;
747 Assert(pAllocation->SurfDesc.VidPnSourceId == srcId);
748 pAllocation->SurfDesc.VidPnSourceId = srcId;
749 pAllocation->bAssigned = TRUE;
750 }
751
752 pSource->pPrimaryAllocation = pAllocation;
753}
754
755DECLINLINE(void) vboxVideoLeDetach(LIST_ENTRY *pList, LIST_ENTRY *pDstList)
756{
757 if (IsListEmpty(pList))
758 {
759 InitializeListHead(pDstList);
760 }
761 else
762 {
763 *pDstList = *pList;
764 Assert(pDstList->Flink->Blink == pList);
765 Assert(pDstList->Blink->Flink == pList);
766 /* pDstList->Flink & pDstList->Blink point to the "real| entries, never to pList
767 * since we've checked IsListEmpty(pList) above */
768 pDstList->Flink->Blink = pDstList;
769 pDstList->Blink->Flink = pDstList;
770 InitializeListHead(pList);
771 }
772}
773
774#endif
775
776void* vboxHGSMIBufferAlloc(PDEVICE_EXTENSION PrimaryExtension,
777 HGSMISIZE cbData,
778 uint8_t u8Ch,
779 uint16_t u16Op);
780void vboxHGSMIBufferFree (PDEVICE_EXTENSION PrimaryExtension, void *pvBuffer);
781int vboxHGSMIBufferSubmit (PDEVICE_EXTENSION PrimaryExtension, void *pvBuffer);
782
783BOOLEAN FASTCALL VBoxVideoSetCurrentModePerform(PDEVICE_EXTENSION DeviceExtension,
784 USHORT width, USHORT height, USHORT bpp
785#ifdef VBOXWDDM
786 , ULONG offDisplay
787#endif
788 );
789
790BOOLEAN FASTCALL VBoxVideoSetCurrentMode(
791 PDEVICE_EXTENSION DeviceExtension,
792 PVIDEO_MODE RequestedMode,
793 PSTATUS_BLOCK StatusBlock);
794
795BOOLEAN FASTCALL VBoxVideoResetDevice(
796 PDEVICE_EXTENSION DeviceExtension,
797 PSTATUS_BLOCK StatusBlock);
798
799BOOLEAN FASTCALL VBoxVideoMapVideoMemory(
800 PDEVICE_EXTENSION DeviceExtension,
801 PVIDEO_MEMORY RequestedAddress,
802 PVIDEO_MEMORY_INFORMATION MapInformation,
803 PSTATUS_BLOCK StatusBlock);
804
805BOOLEAN FASTCALL VBoxVideoUnmapVideoMemory(
806 PDEVICE_EXTENSION DeviceExtension,
807 PVIDEO_MEMORY VideoMemory,
808 PSTATUS_BLOCK StatusBlock);
809
810BOOLEAN FASTCALL VBoxVideoQueryNumAvailModes(
811 PDEVICE_EXTENSION DeviceExtension,
812 PVIDEO_NUM_MODES Modes,
813 PSTATUS_BLOCK StatusBlock);
814
815BOOLEAN FASTCALL VBoxVideoQueryAvailModes(
816 PDEVICE_EXTENSION DeviceExtension,
817 PVIDEO_MODE_INFORMATION ReturnedModes,
818 PSTATUS_BLOCK StatusBlock);
819
820BOOLEAN FASTCALL VBoxVideoQueryCurrentMode(
821 PDEVICE_EXTENSION DeviceExtension,
822 PVIDEO_MODE_INFORMATION VideoModeInfo,
823 PSTATUS_BLOCK StatusBlock);
824
825BOOLEAN FASTCALL VBoxVideoSetColorRegisters(
826 PDEVICE_EXTENSION DeviceExtension,
827 PVIDEO_CLUT ColorLookUpTable,
828 PSTATUS_BLOCK StatusBlock);
829
830int VBoxMapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
831 void **ppv,
832 ULONG ulOffset,
833 ULONG ulSize);
834
835void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
836 void **ppv, ULONG ulSize);
837
838void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension);
839
840#ifdef VBOX_WITH_HGSMI
841
842/*
843 * Host and Guest port IO helpers.
844 */
845DECLINLINE(void) VBoxHGSMIHostWrite(PDEVICE_EXTENSION PrimaryExtension, ULONG data)
846{
847#ifndef VBOXWDDM
848 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortHost, data);
849#else
850 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->u.primary.IOPortHost, data);
851#endif
852}
853
854DECLINLINE(ULONG) VBoxHGSMIHostRead(PDEVICE_EXTENSION PrimaryExtension)
855{
856#ifndef VBOXWDDM
857 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortHost);
858#else
859 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->u.primary.IOPortHost);
860#endif
861}
862
863DECLINLINE(void) VBoxHGSMIGuestWrite(PDEVICE_EXTENSION PrimaryExtension, ULONG data)
864{
865#ifndef VBOXWDDM
866 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortGuest, data);
867#else
868 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->u.primary.IOPortGuest, data);
869#endif
870}
871
872DECLINLINE(ULONG) VBoxHGSMIGuestRead(PDEVICE_EXTENSION PrimaryExtension)
873{
874#ifndef VBOXWDDM
875 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortGuest);
876#else
877 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->u.primary.IOPortGuest);
878#endif
879}
880
881BOOLEAN VBoxHGSMIIsSupported (PDEVICE_EXTENSION PrimaryExtension);
882
883VOID VBoxSetupDisplaysHGSMI (PDEVICE_EXTENSION PrimaryExtension,
884#ifndef VBOXWDDM
885 PVIDEO_PORT_CONFIG_INFO pConfigInfo,
886#endif
887 ULONG AdapterMemorySize);
888BOOLEAN vboxUpdatePointerShape (PDEVICE_EXTENSION DeviceExtension,
889 PVIDEO_POINTER_ATTRIBUTES pointerAttr,
890 uint32_t cbLength);
891
892#ifdef VBOXWDDM
893int VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension);
894#else
895DECLCALLBACK(void) hgsmiHostCmdComplete (HVBOXVIDEOHGSMI hHGSMI, struct _VBVAHOSTCMD * pCmd);
896DECLCALLBACK(int) hgsmiHostCmdRequest (HVBOXVIDEOHGSMI hHGSMI, uint8_t u8Channel, struct _VBVAHOSTCMD ** ppCmd);
897#endif
898
899
900int vboxVBVAChannelDisplayEnable(PDEVICE_EXTENSION PrimaryExtension,
901 int iDisplay, /* negative would mean this is a miniport handler */
902 uint8_t u8Channel);
903
904VOID VBoxVideoHGSMIDpc(
905 IN PVOID HwDeviceExtension,
906 IN PVOID Context
907 );
908
909void HGSMIClearIrq (PDEVICE_EXTENSION PrimaryExtension);
910
911#endif /* VBOX_WITH_HGSMI */
912} /* extern "C" */
913
914#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