1 | /* $Id: VBoxMPDevExt.h 36867 2011-04-28 07:27:03Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox Miniport device extension header
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef VBOXMPDEVEXT_H
|
---|
20 | #define VBOXMPDEVEXT_H
|
---|
21 |
|
---|
22 | #include "VBoxMPUtils.h"
|
---|
23 | #include <VBox/VBoxVideoGuest.h>
|
---|
24 |
|
---|
25 | #ifdef VBOX_XPDM_MINIPORT
|
---|
26 | # include <miniport.h>
|
---|
27 | # include <ntddvdeo.h>
|
---|
28 | # include <video.h>
|
---|
29 | # include "common/xpdm/VBoxVideoPortAPI.h"
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #ifdef VBOX_WDDM_MINIPORT
|
---|
33 | # include "wddm/VBoxMPTypes.h"
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | typedef struct VBOXMP_COMMON
|
---|
37 | {
|
---|
38 | int cDisplays; /* Number of displays. */
|
---|
39 |
|
---|
40 | uint32_t cbVRAM; /* The VRAM size. */
|
---|
41 |
|
---|
42 | uint32_t cbMiniportHeap; /* The size of reserved VRAM for miniport driver heap.
|
---|
43 | * It is at offset:
|
---|
44 | * cbAdapterMemorySize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE - cbMiniportHeap
|
---|
45 | */
|
---|
46 | void *pvMiniportHeap; /* The pointer to the miniport heap VRAM.
|
---|
47 | * This is mapped by miniport separately.
|
---|
48 | */
|
---|
49 | void *pvAdapterInformation; /* The pointer to the last 4K of VRAM.
|
---|
50 | * This is mapped by miniport separately.
|
---|
51 | */
|
---|
52 |
|
---|
53 | /** Whether HGSMI is enabled. */
|
---|
54 | bool bHGSMI;
|
---|
55 | /** Context information needed to receive commands from the host. */
|
---|
56 | HGSMIHOSTCOMMANDCONTEXT hostCtx;
|
---|
57 | /** Context information needed to submit commands to the host. */
|
---|
58 | HGSMIGUESTCOMMANDCONTEXT guestCtx;
|
---|
59 | } VBOXMP_COMMON, *PVBOXMP_COMMON;
|
---|
60 |
|
---|
61 | typedef struct _VBOXMP_DEVEXT
|
---|
62 | {
|
---|
63 | struct _VBOXMP_DEVEXT *pNext; /* Next extension in the DualView extension list.
|
---|
64 | * The primary extension is the first one.
|
---|
65 | */
|
---|
66 | #ifdef VBOX_XPDM_MINIPORT
|
---|
67 | struct _VBOXMP_DEVEXT *pPrimary; /* Pointer to the primary device extension. */
|
---|
68 |
|
---|
69 | ULONG iDevice; /* Device index: 0 for primary, otherwise a secondary device. */
|
---|
70 |
|
---|
71 | ULONG CurrentMode; /* Saved information about video modes */
|
---|
72 | ULONG CurrentModeWidth;
|
---|
73 | ULONG CurrentModeHeight;
|
---|
74 | ULONG CurrentModeBPP;
|
---|
75 |
|
---|
76 | ULONG ulFrameBufferOffset; /* The framebuffer position in the VRAM. */
|
---|
77 | ULONG ulFrameBufferSize; /* The size of the current framebuffer. */
|
---|
78 | #endif /*VBOX_XPDM_MINIPORT*/
|
---|
79 |
|
---|
80 | #ifdef VBOX_WDDM_MINIPORT
|
---|
81 | PDEVICE_OBJECT pPDO;
|
---|
82 | UNICODE_STRING RegKeyName;
|
---|
83 | UNICODE_STRING VideoGuid;
|
---|
84 |
|
---|
85 | uint8_t * pvVisibleVram;
|
---|
86 |
|
---|
87 | VBOXVIDEOCM_MGR CmMgr;
|
---|
88 | /* hgsmi allocation manager */
|
---|
89 | VBOXVIDEOCM_ALLOC_MGR AllocMgr;
|
---|
90 | VBOXVDMADDI_CMD_QUEUE DdiCmdQueue;
|
---|
91 | LIST_ENTRY SwapchainList3D;
|
---|
92 | /* mutex for context list operations */
|
---|
93 | FAST_MUTEX ContextMutex;
|
---|
94 | KSPIN_LOCK SynchLock;
|
---|
95 | volatile uint32_t cContexts3D;
|
---|
96 | volatile uint32_t cUnlockedVBVADisabled;
|
---|
97 |
|
---|
98 | VBOXWDDM_GLOBAL_POINTER_INFO PointerInfo;
|
---|
99 |
|
---|
100 | VBOXSHGSMILIST CtlList;
|
---|
101 | VBOXSHGSMILIST DmaCmdList;
|
---|
102 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
103 | VBOXSHGSMILIST VhwaCmdList;
|
---|
104 | #endif
|
---|
105 | BOOL bNotifyDxDpc;
|
---|
106 |
|
---|
107 | VBOXWDDM_SOURCE aSources[VBOX_VIDEO_MAX_SCREENS];
|
---|
108 | VBOXWDDM_TARGET aTargets[VBOX_VIDEO_MAX_SCREENS];
|
---|
109 | #endif /*VBOX_WDDM_MINIPORT*/
|
---|
110 |
|
---|
111 | union {
|
---|
112 | /* Information that is only relevant to the primary device or is the same for all devices. */
|
---|
113 | struct {
|
---|
114 |
|
---|
115 | void *pvReqFlush; /* Pointer to preallocated generic request structure for
|
---|
116 | * VMMDevReq_VideoAccelFlush. Allocated when VBVA status
|
---|
117 | * is changed. Deallocated on HwReset.
|
---|
118 | */
|
---|
119 | ULONG ulVbvaEnabled; /* Indicates that VBVA mode is enabled. */
|
---|
120 | ULONG ulMaxFrameBufferSize; /* The size of the VRAM allocated for the a single framebuffer. */
|
---|
121 | BOOLEAN fMouseHidden; /* Has the mouse cursor been hidden by the guest? */
|
---|
122 | VBOXMP_COMMON commonInfo;
|
---|
123 | #ifdef VBOX_XPDM_MINIPORT
|
---|
124 | /* Video Port API dynamically picked up at runtime for binary backwards compatibility with older NT versions */
|
---|
125 | VBOXVIDEOPORTPROCS VideoPortProcs;
|
---|
126 | #endif
|
---|
127 |
|
---|
128 | #ifdef VBOX_WDDM_MINIPORT
|
---|
129 | VBOXVDMAINFO Vdma;
|
---|
130 | # ifdef VBOXVDMA_WITH_VBVA
|
---|
131 | VBOXVBVAINFO Vbva;
|
---|
132 | # endif
|
---|
133 | D3DKMDT_HVIDPN hCommittedVidPn; /* committed VidPn handle */
|
---|
134 | DXGKRNL_INTERFACE DxgkInterface; /* Display Port handle and callbacks */
|
---|
135 | #endif
|
---|
136 | } primary;
|
---|
137 |
|
---|
138 | /* Secondary device information. */
|
---|
139 | struct {
|
---|
140 | BOOLEAN bEnabled; /* Device enabled flag */
|
---|
141 | } secondary;
|
---|
142 | } u;
|
---|
143 |
|
---|
144 | HGSMIAREA areaDisplay; /* Entire VRAM chunk for this display device. */
|
---|
145 | BOOLEAN fAnyX; /* Unrestricted horizontal resolution flag. */
|
---|
146 | } VBOXMP_DEVEXT, *PVBOXMP_DEVEXT;
|
---|
147 |
|
---|
148 | DECLINLINE(PVBOXMP_DEVEXT) VBoxCommonToPrimaryExt(PVBOXMP_COMMON pCommon)
|
---|
149 | {
|
---|
150 | return RT_FROM_MEMBER(pCommon, VBOXMP_DEVEXT, u.primary.commonInfo);
|
---|
151 | }
|
---|
152 |
|
---|
153 | DECLINLINE(PVBOXMP_COMMON) VBoxCommonFromDeviceExt(PVBOXMP_DEVEXT pExt)
|
---|
154 | {
|
---|
155 | #ifdef VBOX_XPDM_MINIPORT
|
---|
156 | return &pExt->pPrimary->u.primary.commonInfo;
|
---|
157 | #else
|
---|
158 | return &pExt->u.primary.commonInfo;
|
---|
159 | #endif
|
---|
160 | }
|
---|
161 |
|
---|
162 | #ifdef VBOX_WDDM_MINIPORT
|
---|
163 | DECLINLINE(ULONG) vboxWddmVramCpuVisibleSize(PVBOXMP_DEVEXT pDevExt)
|
---|
164 | {
|
---|
165 | #ifdef VBOXWDDM_RENDER_FROM_SHADOW
|
---|
166 | /* all memory layout info should be initialized */
|
---|
167 | Assert(pDevExt->aSources[0].Vbva.offVBVA);
|
---|
168 | /* page aligned */
|
---|
169 | Assert(!(pDevExt->aSources[0].Vbva.offVBVA & 0xfff));
|
---|
170 |
|
---|
171 | return (ULONG)(pDevExt->aSources[0].Vbva.offVBVA & ~0xfffULL);
|
---|
172 | #else
|
---|
173 | /* all memory layout info should be initialized */
|
---|
174 | Assert(pDevExt->u.primary.Vdma.CmdHeap.area.offBase);
|
---|
175 | /* page aligned */
|
---|
176 | Assert(!(pDevExt->u.primary.Vdma.CmdHeap.area.offBase & 0xfff));
|
---|
177 |
|
---|
178 | return pDevExt->u.primary.Vdma.CmdHeap.area.offBase & ~0xfffUL;
|
---|
179 | #endif
|
---|
180 | }
|
---|
181 |
|
---|
182 | DECLINLINE(ULONG) vboxWddmVramCpuVisibleSegmentSize(PVBOXMP_DEVEXT pDevExt)
|
---|
183 | {
|
---|
184 | return vboxWddmVramCpuVisibleSize(pDevExt);
|
---|
185 | }
|
---|
186 |
|
---|
187 | #ifdef VBOXWDDM_RENDER_FROM_SHADOW
|
---|
188 | DECLINLINE(ULONG) vboxWddmVramCpuInvisibleSegmentSize(PVBOXMP_DEVEXT pDevExt)
|
---|
189 | {
|
---|
190 | return vboxWddmVramCpuVisibleSegmentSize(pDevExt);
|
---|
191 | }
|
---|
192 |
|
---|
193 | DECLINLINE(bool) vboxWddmCmpSurfDescsBase(VBOXWDDM_SURFACE_DESC *pDesc1, VBOXWDDM_SURFACE_DESC *pDesc2)
|
---|
194 | {
|
---|
195 | if (pDesc1->width != pDesc2->width)
|
---|
196 | return false;
|
---|
197 | if (pDesc1->height != pDesc2->height)
|
---|
198 | return false;
|
---|
199 | if (pDesc1->format != pDesc2->format)
|
---|
200 | return false;
|
---|
201 | if (pDesc1->bpp != pDesc2->bpp)
|
---|
202 | return false;
|
---|
203 | if (pDesc1->pitch != pDesc2->pitch)
|
---|
204 | return false;
|
---|
205 | return true;
|
---|
206 | }
|
---|
207 |
|
---|
208 | DECLINLINE(void) vboxWddmAssignShadow(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
|
---|
209 | {
|
---|
210 | if (pSource->pShadowAllocation == pAllocation)
|
---|
211 | {
|
---|
212 | Assert(pAllocation->bAssigned);
|
---|
213 | return;
|
---|
214 | }
|
---|
215 |
|
---|
216 | if (pSource->pShadowAllocation)
|
---|
217 | {
|
---|
218 | PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pShadowAllocation;
|
---|
219 | /* clear the visibility info fo the current primary */
|
---|
220 | pOldAlloc->bVisible = FALSE;
|
---|
221 | pOldAlloc->bAssigned = FALSE;
|
---|
222 | Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
|
---|
223 | /* release the shadow surface */
|
---|
224 | pOldAlloc->SurfDesc.VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
|
---|
225 | }
|
---|
226 |
|
---|
227 | if (pAllocation)
|
---|
228 | {
|
---|
229 | Assert(!pAllocation->bAssigned);
|
---|
230 | Assert(!pAllocation->bVisible);
|
---|
231 | pAllocation->bVisible = FALSE;
|
---|
232 | /* this check ensures the shadow is not used for other source simultaneously */
|
---|
233 | Assert(pAllocation->SurfDesc.VidPnSourceId == D3DDDI_ID_UNINITIALIZED);
|
---|
234 | pAllocation->SurfDesc.VidPnSourceId = srcId;
|
---|
235 | pAllocation->bAssigned = TRUE;
|
---|
236 | if (!vboxWddmCmpSurfDescsBase(&pSource->SurfDesc, &pAllocation->SurfDesc))
|
---|
237 | pSource->offVram = VBOXVIDEOOFFSET_VOID; /* force guest->host notification */
|
---|
238 | pSource->SurfDesc = pAllocation->SurfDesc;
|
---|
239 | }
|
---|
240 |
|
---|
241 | pSource->pShadowAllocation = pAllocation;
|
---|
242 | }
|
---|
243 | #endif
|
---|
244 |
|
---|
245 | DECLINLINE(VOID) vboxWddmAssignPrimary(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
|
---|
246 | {
|
---|
247 | if (pSource->pPrimaryAllocation == pAllocation)
|
---|
248 | return;
|
---|
249 |
|
---|
250 | if (pSource->pPrimaryAllocation)
|
---|
251 | {
|
---|
252 | PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pPrimaryAllocation;
|
---|
253 | /* clear the visibility info fo the current primary */
|
---|
254 | pOldAlloc->bVisible = FALSE;
|
---|
255 | pOldAlloc->bAssigned = FALSE;
|
---|
256 | Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
|
---|
257 | }
|
---|
258 |
|
---|
259 | if (pAllocation)
|
---|
260 | {
|
---|
261 | pAllocation->bVisible = FALSE;
|
---|
262 | Assert(pAllocation->SurfDesc.VidPnSourceId == srcId);
|
---|
263 | pAllocation->SurfDesc.VidPnSourceId = srcId;
|
---|
264 | pAllocation->bAssigned = TRUE;
|
---|
265 | }
|
---|
266 |
|
---|
267 | pSource->pPrimaryAllocation = pAllocation;
|
---|
268 | }
|
---|
269 | #endif /*VBOX_WDDM_MINIPORT*/
|
---|
270 |
|
---|
271 | #endif /*VBOXMPDEVEXT_H*/
|
---|