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