1 | /* $Id: VBoxMPWddm.h 46757 2013-06-24 14:30:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox WDDM Miniport driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2013 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___VBoxMPWddm_h___
|
---|
19 | #define ___VBoxMPWddm_h___
|
---|
20 |
|
---|
21 | #ifdef VBOX_WDDM_WIN8
|
---|
22 | # define VBOX_WDDM_DRIVERNAME L"VBoxVideoW8"
|
---|
23 | #else
|
---|
24 | # define VBOX_WDDM_DRIVERNAME L"VBoxVideoWddm"
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | #ifndef DEBUG_misha
|
---|
28 | # ifdef Assert
|
---|
29 | # error "VBoxMPWddm.h must be included first."
|
---|
30 | # endif
|
---|
31 | # define RT_NO_STRICT
|
---|
32 | #endif
|
---|
33 | #include "common/VBoxMPUtils.h"
|
---|
34 | #include "common/VBoxMPDevExt.h"
|
---|
35 | #include "../../common/VBoxVideoTools.h"
|
---|
36 |
|
---|
37 | //#define VBOXWDDM_DEBUG_VIDPN
|
---|
38 |
|
---|
39 | #define VBOXWDDM_CFG_LOG_UM_BACKDOOR 0x00000001
|
---|
40 | #define VBOXWDDM_CFG_LOG_UM_DBGPRINT 0x00000002
|
---|
41 | #define VBOXWDDM_CFG_STR_LOG_UM L"VBoxLogUm"
|
---|
42 | extern DWORD g_VBoxLogUm;
|
---|
43 |
|
---|
44 | RT_C_DECLS_BEGIN
|
---|
45 | NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath);
|
---|
46 | RT_C_DECLS_END
|
---|
47 |
|
---|
48 | PVOID vboxWddmMemAlloc(IN SIZE_T cbSize);
|
---|
49 | PVOID vboxWddmMemAllocZero(IN SIZE_T cbSize);
|
---|
50 | VOID vboxWddmMemFree(PVOID pvMem);
|
---|
51 |
|
---|
52 | NTSTATUS vboxWddmCallIsr(PVBOXMP_DEVEXT pDevExt);
|
---|
53 |
|
---|
54 | DECLINLINE(PVBOXWDDM_RESOURCE) vboxWddmResourceForAlloc(PVBOXWDDM_ALLOCATION pAlloc)
|
---|
55 | {
|
---|
56 | #if 0
|
---|
57 | if(pAlloc->iIndex == VBOXWDDM_ALLOCATIONINDEX_VOID)
|
---|
58 | return NULL;
|
---|
59 | PVBOXWDDM_RESOURCE pRc = (PVBOXWDDM_RESOURCE)(((uint8_t*)pAlloc) - RT_OFFSETOF(VBOXWDDM_RESOURCE, aAllocations[pAlloc->iIndex]));
|
---|
60 | return pRc;
|
---|
61 | #else
|
---|
62 | return pAlloc->pResource;
|
---|
63 | #endif
|
---|
64 | }
|
---|
65 |
|
---|
66 | VOID vboxWddmAllocationDestroy(PVBOXWDDM_ALLOCATION pAllocation);
|
---|
67 |
|
---|
68 | DECLINLINE(VOID) vboxWddmAllocationRelease(PVBOXWDDM_ALLOCATION pAllocation)
|
---|
69 | {
|
---|
70 | uint32_t cRefs = ASMAtomicDecU32(&pAllocation->cRefs);
|
---|
71 | Assert(cRefs < UINT32_MAX/2);
|
---|
72 | if (!cRefs)
|
---|
73 | {
|
---|
74 | vboxWddmAllocationDestroy(pAllocation);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | DECLINLINE(VOID) vboxWddmAllocationRetain(PVBOXWDDM_ALLOCATION pAllocation)
|
---|
79 | {
|
---|
80 | ASMAtomicIncU32(&pAllocation->cRefs);
|
---|
81 | }
|
---|
82 |
|
---|
83 | DECLINLINE(VOID) vboxWddmAddrSetVram(PVBOXWDDM_ADDR pAddr, UINT SegmentId, VBOXVIDEOOFFSET offVram)
|
---|
84 | {
|
---|
85 | pAddr->SegmentId = SegmentId;
|
---|
86 | pAddr->offVram = offVram;
|
---|
87 | }
|
---|
88 |
|
---|
89 | DECLINLINE(bool) vboxWddmAddrVramEqual(PVBOXWDDM_ADDR pAddr1, PVBOXWDDM_ADDR pAddr2)
|
---|
90 | {
|
---|
91 | return pAddr1->SegmentId == pAddr2->SegmentId && pAddr1->offVram == pAddr2->offVram;
|
---|
92 | }
|
---|
93 |
|
---|
94 | DECLINLINE(VBOXVIDEOOFFSET) vboxWddmVramAddrToOffset(PVBOXMP_DEVEXT pDevExt, PHYSICAL_ADDRESS Addr)
|
---|
95 | {
|
---|
96 | PVBOXMP_COMMON pCommon = VBoxCommonFromDeviceExt(pDevExt);
|
---|
97 | AssertRelease(pCommon->phVRAM.QuadPart <= Addr.QuadPart);
|
---|
98 | return (VBOXVIDEOOFFSET)Addr.QuadPart - pCommon->phVRAM.QuadPart;
|
---|
99 | }
|
---|
100 |
|
---|
101 | #ifdef VBOXWDDM_RENDER_FROM_SHADOW
|
---|
102 | DECLINLINE(void) vboxWddmAssignShadow(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
|
---|
103 | {
|
---|
104 | if (pSource->pShadowAllocation == pAllocation && pSource->fGhSynced > 0)
|
---|
105 | {
|
---|
106 | Assert(pAllocation->bAssigned);
|
---|
107 | return;
|
---|
108 | }
|
---|
109 |
|
---|
110 | if (pSource->pShadowAllocation)
|
---|
111 | {
|
---|
112 | PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pShadowAllocation;
|
---|
113 | /* clear the visibility info fo the current primary */
|
---|
114 | pOldAlloc->bVisible = FALSE;
|
---|
115 | pOldAlloc->bAssigned = FALSE;
|
---|
116 | Assert(pOldAlloc->AllocData.SurfDesc.VidPnSourceId == srcId);
|
---|
117 | /* release the shadow surface */
|
---|
118 | pOldAlloc->AllocData.SurfDesc.VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
|
---|
119 | }
|
---|
120 |
|
---|
121 | if (pAllocation)
|
---|
122 | {
|
---|
123 | Assert(!pAllocation->bAssigned);
|
---|
124 | Assert(!pAllocation->bVisible);
|
---|
125 | /* this check ensures the shadow is not used for other source simultaneously */
|
---|
126 | Assert(pAllocation->AllocData.SurfDesc.VidPnSourceId == D3DDDI_ID_UNINITIALIZED);
|
---|
127 | pAllocation->AllocData.SurfDesc.VidPnSourceId = srcId;
|
---|
128 | pAllocation->bAssigned = TRUE;
|
---|
129 | pAllocation->bVisible = pSource->bVisible;
|
---|
130 |
|
---|
131 | if(!vboxWddmAddrVramEqual(&pSource->AllocData.Addr, &pAllocation->AllocData.Addr))
|
---|
132 | pSource->fGhSynced = 0; /* force guest->host notification */
|
---|
133 | pSource->AllocData.Addr = pAllocation->AllocData.Addr;
|
---|
134 | }
|
---|
135 |
|
---|
136 | pSource->pShadowAllocation = pAllocation;
|
---|
137 | }
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | DECLINLINE(VOID) vboxWddmAssignPrimary(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
|
---|
141 | {
|
---|
142 | /* vboxWddmAssignPrimary can not be run in reentrant order, so safely do a direct unlocked check here */
|
---|
143 | if (pSource->pPrimaryAllocation == pAllocation)
|
---|
144 | return;
|
---|
145 |
|
---|
146 | if (pSource->pPrimaryAllocation)
|
---|
147 | {
|
---|
148 | PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pPrimaryAllocation;
|
---|
149 | /* clear the visibility info fo the current primary */
|
---|
150 | pOldAlloc->bVisible = FALSE;
|
---|
151 | pOldAlloc->bAssigned = FALSE;
|
---|
152 | Assert(pOldAlloc->AllocData.SurfDesc.VidPnSourceId == srcId);
|
---|
153 |
|
---|
154 | vboxWddmAllocationRelease(pOldAlloc);
|
---|
155 | }
|
---|
156 |
|
---|
157 | if (pAllocation)
|
---|
158 | {
|
---|
159 | Assert(pAllocation->AllocData.SurfDesc.VidPnSourceId == srcId);
|
---|
160 | pAllocation->bAssigned = TRUE;
|
---|
161 | pAllocation->bVisible = pSource->bVisible;
|
---|
162 |
|
---|
163 | if(!vboxWddmAddrVramEqual(&pSource->AllocData.Addr, &pAllocation->AllocData.Addr))
|
---|
164 | pSource->fGhSynced = 0; /* force guest->host notification */
|
---|
165 | pSource->AllocData.Addr = pAllocation->AllocData.Addr;
|
---|
166 |
|
---|
167 | vboxWddmAllocationRetain(pAllocation);
|
---|
168 | }
|
---|
169 |
|
---|
170 | if (pAllocation && pAllocation->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE)
|
---|
171 | {
|
---|
172 | RTRECT Rect;
|
---|
173 | Rect.xLeft = 0;
|
---|
174 | Rect.yTop = 0;
|
---|
175 | Rect.xRight = pAllocation->AllocData.SurfDesc.width;
|
---|
176 | Rect.yBottom = pAllocation->AllocData.SurfDesc.height;
|
---|
177 |
|
---|
178 | VBoxVrListRectsSet(&pSource->VrList, 1, &Rect, NULL);
|
---|
179 | }
|
---|
180 | else
|
---|
181 | VBoxVrListClear(&pSource->VrList);
|
---|
182 |
|
---|
183 | pSource->fHas3DVrs = FALSE;
|
---|
184 |
|
---|
185 | KIRQL OldIrql;
|
---|
186 | KeAcquireSpinLock(&pSource->AllocationLock, &OldIrql);
|
---|
187 | pSource->pPrimaryAllocation = pAllocation;
|
---|
188 | KeReleaseSpinLock(&pSource->AllocationLock, OldIrql);
|
---|
189 | }
|
---|
190 |
|
---|
191 | DECLINLINE(PVBOXWDDM_ALLOCATION) vboxWddmAquirePrimary(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
|
---|
192 | {
|
---|
193 | PVBOXWDDM_ALLOCATION pPrimary;
|
---|
194 | KIRQL OldIrql;
|
---|
195 | KeAcquireSpinLock(&pSource->AllocationLock, &OldIrql);
|
---|
196 | pPrimary = pSource->pPrimaryAllocation;
|
---|
197 | if (pPrimary)
|
---|
198 | vboxWddmAllocationRetain(pPrimary);
|
---|
199 | KeReleaseSpinLock(&pSource->AllocationLock, OldIrql);
|
---|
200 | return pPrimary;
|
---|
201 | }
|
---|
202 |
|
---|
203 | #define VBOXWDDMENTRY_2_SWAPCHAIN(_pE) ((PVBOXWDDM_SWAPCHAIN)((uint8_t*)(_pE) - RT_OFFSETOF(VBOXWDDM_SWAPCHAIN, DevExtListEntry)))
|
---|
204 |
|
---|
205 | #ifdef VBOXWDDM_RENDER_FROM_SHADOW
|
---|
206 | # ifdef VBOX_WDDM_WIN8
|
---|
207 | # define VBOXWDDM_IS_FB_ALLOCATION(_pDevExt, _pAlloc) ( (_pAlloc)->bAssigned \
|
---|
208 | && ( (_pAlloc)->enmType == VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC \
|
---|
209 | || (_pAlloc)->enmType == \
|
---|
210 | ((g_VBoxDisplayOnly || (_pDevExt)->fRenderToShadowDisabled) ? VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE : VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE) \
|
---|
211 | ))
|
---|
212 | # else
|
---|
213 | # define VBOXWDDM_IS_FB_ALLOCATION(_pDevExt, _pAlloc) ( (_pAlloc)->bAssigned \
|
---|
214 | && ( (_pAlloc)->enmType == VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC \
|
---|
215 | || (_pAlloc)->enmType == \
|
---|
216 | (((_pDevExt)->fRenderToShadowDisabled) ? VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE : VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE) \
|
---|
217 | ))
|
---|
218 | # endif
|
---|
219 | # define VBOXWDDM_FB_ALLOCATION(_pDevExt, _pSrc) ( ((_pSrc)->pPrimaryAllocation && VBOXWDDM_IS_FB_ALLOCATION(_pDevExt, (_pSrc)->pPrimaryAllocation)) ? \
|
---|
220 | (_pSrc)->pPrimaryAllocation : ( \
|
---|
221 | ((_pSrc)->pShadowAllocation && VBOXWDDM_IS_FB_ALLOCATION(_pDevExt, (_pSrc)->pShadowAllocation)) ? \
|
---|
222 | (_pSrc)->pShadowAllocation : NULL \
|
---|
223 | ) \
|
---|
224 | )
|
---|
225 | # define VBOXWDDM_NONFB_ALLOCATION(_pDevExt, _pSrc) ( !((_pSrc)->pPrimaryAllocation && VBOXWDDM_IS_FB_ALLOCATION(_pDevExt, (_pSrc)->pPrimaryAllocation)) ? \
|
---|
226 | (_pSrc)->pPrimaryAllocation : ( \
|
---|
227 | ((_pSrc)->pShadowAllocation && VBOXWDDM_IS_FB_ALLOCATION(_pDevExt, (_pSrc)->pShadowAllocation)) ? \
|
---|
228 | (_pSrc)->pShadowAllocation : NULL \
|
---|
229 | ) \
|
---|
230 | )
|
---|
231 | #else
|
---|
232 | # define VBOXWDDM_FB_ALLOCATION(_pDevExt, _pSrc) ((_pSrc)->pPrimaryAllocation)
|
---|
233 | #endif
|
---|
234 |
|
---|
235 | #define VBOXWDDM_CTXLOCK_INIT(_p) do { \
|
---|
236 | KeInitializeSpinLock(&(_p)->ContextLock); \
|
---|
237 | } while (0)
|
---|
238 | #define VBOXWDDM_CTXLOCK_DATA KIRQL _ctxLockOldIrql;
|
---|
239 | #define VBOXWDDM_CTXLOCK_LOCK(_p) do { \
|
---|
240 | KeAcquireSpinLock(&(_p)->ContextLock, &_ctxLockOldIrql); \
|
---|
241 | } while (0)
|
---|
242 | #define VBOXWDDM_CTXLOCK_UNLOCK(_p) do { \
|
---|
243 | KeReleaseSpinLock(&(_p)->ContextLock, _ctxLockOldIrql); \
|
---|
244 | } while (0)
|
---|
245 |
|
---|
246 | #endif /* #ifndef ___VBoxMPWddm_h___ */
|
---|
247 |
|
---|