1 | /* $Id: VBoxMPWddm.h 83840 2020-04-20 09:16:29Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox WDDM Miniport driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2020 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 GA_INCLUDED_SRC_WINNT_Graphics_Video_mp_wddm_VBoxMPWddm_h
|
---|
19 | #define GA_INCLUDED_SRC_WINNT_Graphics_Video_mp_wddm_VBoxMPWddm_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #define VBOX_WDDM_DRIVERNAME L"VBoxWddm"
|
---|
25 |
|
---|
26 | #include "common/VBoxMPUtils.h"
|
---|
27 | #include "common/VBoxMPDevExt.h"
|
---|
28 | #include "../../common/VBoxVideoTools.h"
|
---|
29 |
|
---|
30 | //#define VBOXWDDM_DEBUG_VIDPN
|
---|
31 |
|
---|
32 | #define VBOXWDDM_CFG_DRV_DEFAULT 0
|
---|
33 | #define VBOXWDDM_CFG_DRV_SECONDARY_TARGETS_CONNECTED 1
|
---|
34 |
|
---|
35 | #define VBOXWDDM_CFG_DRVTARGET_CONNECTED 1
|
---|
36 |
|
---|
37 | #define VBOXWDDM_CFG_LOG_UM_BACKDOOR 0x00000001
|
---|
38 | #define VBOXWDDM_CFG_LOG_UM_DBGPRINT 0x00000002
|
---|
39 | #define VBOXWDDM_CFG_STR_LOG_UM L"VBoxLogUm"
|
---|
40 |
|
---|
41 | #define VBOXWDDM_REG_DRV_FLAGS_NAME L"VBoxFlags"
|
---|
42 | #define VBOXWDDM_REG_DRV_DISPFLAGS_PREFIX L"VBoxDispFlags"
|
---|
43 |
|
---|
44 | #define VBOXWDDM_REG_DRVKEY_PREFIX L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class\\"
|
---|
45 |
|
---|
46 | #define VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Video\\"
|
---|
47 | #define VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY_SUBKEY L"\\Video"
|
---|
48 |
|
---|
49 |
|
---|
50 | #define VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_VISTA L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Control\\VIDEO\\"
|
---|
51 | #define VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_WIN7 L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\UnitedVideo\\CONTROL\\VIDEO\\"
|
---|
52 | #define VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_WIN10_17763 L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\UnitedVideo\\CONTROL\\VIDEO\\"
|
---|
53 |
|
---|
54 | #define VBOXWDDM_REG_DISPLAYSETTINGS_ATTACH_RELX L"Attach.RelativeX"
|
---|
55 | #define VBOXWDDM_REG_DISPLAYSETTINGS_ATTACH_RELY L"Attach.RelativeY"
|
---|
56 | #define VBOXWDDM_REG_DISPLAYSETTINGS_ATTACH_DESKTOP L"Attach.ToDesktop"
|
---|
57 |
|
---|
58 | extern DWORD g_VBoxLogUm;
|
---|
59 |
|
---|
60 | RT_C_DECLS_BEGIN
|
---|
61 | NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath);
|
---|
62 | RT_C_DECLS_END
|
---|
63 |
|
---|
64 | PVOID vboxWddmMemAlloc(IN SIZE_T cbSize);
|
---|
65 | PVOID vboxWddmMemAllocZero(IN SIZE_T cbSize);
|
---|
66 | VOID vboxWddmMemFree(PVOID pvMem);
|
---|
67 |
|
---|
68 | NTSTATUS vboxWddmCallIsr(PVBOXMP_DEVEXT pDevExt);
|
---|
69 |
|
---|
70 | DECLINLINE(PVBOXWDDM_RESOURCE) vboxWddmResourceForAlloc(PVBOXWDDM_ALLOCATION pAlloc)
|
---|
71 | {
|
---|
72 | #if 0
|
---|
73 | if(pAlloc->iIndex == VBOXWDDM_ALLOCATIONINDEX_VOID)
|
---|
74 | return NULL;
|
---|
75 | PVBOXWDDM_RESOURCE pRc = (PVBOXWDDM_RESOURCE)(((uint8_t*)pAlloc) - RT_OFFSETOF(VBOXWDDM_RESOURCE, aAllocations[pAlloc->iIndex]));
|
---|
76 | return pRc;
|
---|
77 | #else
|
---|
78 | return pAlloc->pResource;
|
---|
79 | #endif
|
---|
80 | }
|
---|
81 |
|
---|
82 | VOID vboxWddmAllocationDestroy(PVBOXWDDM_ALLOCATION pAllocation);
|
---|
83 |
|
---|
84 | DECLINLINE(BOOLEAN) vboxWddmAddrSetVram(PVBOXWDDM_ADDR pAddr, UINT SegmentId, VBOXVIDEOOFFSET offVram)
|
---|
85 | {
|
---|
86 | if (pAddr->SegmentId == SegmentId && pAddr->offVram == offVram)
|
---|
87 | return FALSE;
|
---|
88 |
|
---|
89 | pAddr->SegmentId = SegmentId;
|
---|
90 | pAddr->offVram = offVram;
|
---|
91 | return TRUE;
|
---|
92 | }
|
---|
93 |
|
---|
94 | DECLINLINE(bool) vboxWddmAddrVramEqual(const VBOXWDDM_ADDR *pAddr1, const VBOXWDDM_ADDR *pAddr2)
|
---|
95 | {
|
---|
96 | return pAddr1->SegmentId == pAddr2->SegmentId && pAddr1->offVram == pAddr2->offVram;
|
---|
97 | }
|
---|
98 |
|
---|
99 | DECLINLINE(VBOXVIDEOOFFSET) vboxWddmVramAddrToOffset(PVBOXMP_DEVEXT pDevExt, PHYSICAL_ADDRESS Addr)
|
---|
100 | {
|
---|
101 | PVBOXMP_COMMON pCommon = VBoxCommonFromDeviceExt(pDevExt);
|
---|
102 | AssertRelease(pCommon->phVRAM.QuadPart <= Addr.QuadPart);
|
---|
103 | return (VBOXVIDEOOFFSET)Addr.QuadPart - pCommon->phVRAM.QuadPart;
|
---|
104 | }
|
---|
105 |
|
---|
106 | DECLINLINE(VOID) vboxWddmAssignPrimary(PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation,
|
---|
107 | D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
|
---|
108 | {
|
---|
109 | RT_NOREF(srcId);
|
---|
110 |
|
---|
111 | /* vboxWddmAssignPrimary can not be run in reentrant order, so safely do a direct unlocked check here */
|
---|
112 | if (pSource->pPrimaryAllocation == pAllocation)
|
---|
113 | return;
|
---|
114 |
|
---|
115 | if (pSource->pPrimaryAllocation)
|
---|
116 | {
|
---|
117 | PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pPrimaryAllocation;
|
---|
118 | /* clear the visibility info fo the current primary */
|
---|
119 | pOldAlloc->bVisible = FALSE;
|
---|
120 | pOldAlloc->bAssigned = FALSE;
|
---|
121 | Assert(pOldAlloc->AllocData.SurfDesc.VidPnSourceId == srcId);
|
---|
122 | }
|
---|
123 |
|
---|
124 | if (pAllocation)
|
---|
125 | {
|
---|
126 | Assert(pAllocation->AllocData.SurfDesc.VidPnSourceId == srcId);
|
---|
127 | pAllocation->bAssigned = TRUE;
|
---|
128 | pAllocation->bVisible = pSource->bVisible;
|
---|
129 |
|
---|
130 | if (pSource->AllocData.hostID != pAllocation->AllocData.hostID)
|
---|
131 | {
|
---|
132 | pSource->u8SyncState &= ~VBOXWDDM_HGSYNC_F_SYNCED_LOCATION; /* force guest->host notification */
|
---|
133 | pSource->AllocData.hostID = pAllocation->AllocData.hostID;
|
---|
134 | }
|
---|
135 |
|
---|
136 | if (!vboxWddmAddrVramEqual(&pSource->AllocData.Addr, &pAllocation->AllocData.Addr))
|
---|
137 | {
|
---|
138 | if (!pAllocation->AllocData.hostID)
|
---|
139 | pSource->u8SyncState &= ~VBOXWDDM_HGSYNC_F_SYNCED_LOCATION; /* force guest->host notification */
|
---|
140 |
|
---|
141 | pSource->AllocData.Addr = pAllocation->AllocData.Addr;
|
---|
142 | }
|
---|
143 | }
|
---|
144 | else
|
---|
145 | {
|
---|
146 | pSource->u8SyncState &= ~VBOXWDDM_HGSYNC_F_SYNCED_LOCATION; /* force guest->host notification */
|
---|
147 | /*ensure we do not refer to the deleted host id */
|
---|
148 | pSource->AllocData.hostID = 0;
|
---|
149 | }
|
---|
150 |
|
---|
151 | KIRQL OldIrql;
|
---|
152 | KeAcquireSpinLock(&pSource->AllocationLock, &OldIrql);
|
---|
153 | pSource->pPrimaryAllocation = pAllocation;
|
---|
154 | KeReleaseSpinLock(&pSource->AllocationLock, OldIrql);
|
---|
155 | }
|
---|
156 |
|
---|
157 | DECLINLINE(VBOXVIDEOOFFSET) vboxWddmAddrFramOffset(const VBOXWDDM_ADDR *pAddr)
|
---|
158 | {
|
---|
159 | return (pAddr->offVram != VBOXVIDEOOFFSET_VOID && pAddr->SegmentId) ?
|
---|
160 | (pAddr->SegmentId == 1 ? pAddr->offVram : 0)
|
---|
161 | : VBOXVIDEOOFFSET_VOID;
|
---|
162 | }
|
---|
163 |
|
---|
164 | DECLINLINE(int) vboxWddmScreenInfoInit(VBVAINFOSCREEN RT_UNTRUSTED_VOLATILE_HOST *pScreen,
|
---|
165 | const VBOXWDDM_ALLOC_DATA *pAllocData, const POINT * pVScreenPos, uint16_t fFlags)
|
---|
166 | {
|
---|
167 | VBOXVIDEOOFFSET offVram = vboxWddmAddrFramOffset(&pAllocData->Addr);
|
---|
168 | if (offVram == VBOXVIDEOOFFSET_VOID && !(fFlags & (VBVA_SCREEN_F_DISABLED | VBVA_SCREEN_F_BLANK2)))
|
---|
169 | {
|
---|
170 | WARN(("offVram == VBOXVIDEOOFFSET_VOID"));
|
---|
171 | return VERR_INVALID_PARAMETER;
|
---|
172 | }
|
---|
173 |
|
---|
174 | pScreen->u32ViewIndex = pAllocData->SurfDesc.VidPnSourceId;
|
---|
175 | pScreen->i32OriginX = pVScreenPos->x;
|
---|
176 | pScreen->i32OriginY = pVScreenPos->y;
|
---|
177 | pScreen->u32StartOffset = (uint32_t)offVram;
|
---|
178 | pScreen->u32LineSize = pAllocData->SurfDesc.pitch;
|
---|
179 | pScreen->u32Width = pAllocData->SurfDesc.width;
|
---|
180 | pScreen->u32Height = pAllocData->SurfDesc.height;
|
---|
181 | pScreen->u16BitsPerPixel = (uint16_t)pAllocData->SurfDesc.bpp;
|
---|
182 | pScreen->u16Flags = fFlags;
|
---|
183 |
|
---|
184 | return VINF_SUCCESS;
|
---|
185 | }
|
---|
186 |
|
---|
187 | bool vboxWddmGhDisplayCheckSetInfoFromSource(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource);
|
---|
188 |
|
---|
189 | #define VBOXWDDM_IS_DISPLAYONLY() (g_VBoxDisplayOnly)
|
---|
190 |
|
---|
191 | # define VBOXWDDM_IS_FB_ALLOCATION(_pDevExt, _pAlloc) ((_pAlloc)->bAssigned)
|
---|
192 |
|
---|
193 | # define VBOXWDDM_FB_ALLOCATION(_pDevExt, _pSrc) ((_pSrc)->pPrimaryAllocation)
|
---|
194 |
|
---|
195 | #define VBOXWDDM_CTXLOCK_INIT(_p) do { \
|
---|
196 | KeInitializeSpinLock(&(_p)->ContextLock); \
|
---|
197 | } while (0)
|
---|
198 | #define VBOXWDDM_CTXLOCK_DATA KIRQL _ctxLockOldIrql;
|
---|
199 | #define VBOXWDDM_CTXLOCK_LOCK(_p) do { \
|
---|
200 | KeAcquireSpinLock(&(_p)->ContextLock, &_ctxLockOldIrql); \
|
---|
201 | } while (0)
|
---|
202 | #define VBOXWDDM_CTXLOCK_UNLOCK(_p) do { \
|
---|
203 | KeReleaseSpinLock(&(_p)->ContextLock, _ctxLockOldIrql); \
|
---|
204 | } while (0)
|
---|
205 |
|
---|
206 | DECLINLINE(PVBOXWDDM_ALLOCATION) vboxWddmGetAllocationFromAllocList(DXGK_ALLOCATIONLIST *pAllocList)
|
---|
207 | {
|
---|
208 | PVBOXWDDM_OPENALLOCATION pOa = (PVBOXWDDM_OPENALLOCATION)pAllocList->hDeviceSpecificAllocation;
|
---|
209 | return pOa->pAllocation;
|
---|
210 | }
|
---|
211 |
|
---|
212 | #endif /* !GA_INCLUDED_SRC_WINNT_Graphics_Video_mp_wddm_VBoxMPWddm_h */
|
---|
213 |
|
---|