1 | /* $Id: VBoxVideoHGSMI.cpp 32622 2010-09-17 20:18:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Video miniport driver for NT/2k/XP - HGSMI related functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2009 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 |
|
---|
19 | #include "VBoxVideo.h"
|
---|
20 | #include "Helper.h"
|
---|
21 |
|
---|
22 | #include <iprt/asm.h>
|
---|
23 | #include <iprt/log.h>
|
---|
24 | #include <iprt/thread.h>
|
---|
25 | #include <VBox/VMMDev.h>
|
---|
26 | #include <VBox/VBoxGuest.h>
|
---|
27 | #include <VBox/VBoxVideo.h>
|
---|
28 |
|
---|
29 | #include <VBoxDisplay.h>
|
---|
30 |
|
---|
31 | #include "vboxioctl.h"
|
---|
32 |
|
---|
33 | #define MEM_TAG 'HVBV'
|
---|
34 |
|
---|
35 | void HGSMINotifyHostCmdComplete (PDEVICE_EXTENSION PrimaryExtension, HGSMIOFFSET offt)
|
---|
36 | {
|
---|
37 | VBoxHGSMIHostWrite(PrimaryExtension, offt);
|
---|
38 | }
|
---|
39 |
|
---|
40 | void HGSMIClearIrq (PDEVICE_EXTENSION PrimaryExtension)
|
---|
41 | {
|
---|
42 | VBoxHGSMIHostWrite(PrimaryExtension, HGSMIOFFSET_VOID);
|
---|
43 | }
|
---|
44 |
|
---|
45 | static void HGSMIHostCmdComplete (PDEVICE_EXTENSION PrimaryExtension, void * pvMem)
|
---|
46 | {
|
---|
47 | HGSMIOFFSET offMem = HGSMIPointerToOffset (&PrimaryExtension->u.primary.areaHostHeap, HGSMIBufferHeaderFromData (pvMem));
|
---|
48 | Assert(offMem != HGSMIOFFSET_VOID);
|
---|
49 | if(offMem != HGSMIOFFSET_VOID)
|
---|
50 | {
|
---|
51 | HGSMINotifyHostCmdComplete (PrimaryExtension, offMem);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | static void hgsmiHostCmdProcess(PDEVICE_EXTENSION PrimaryExtension, HGSMIOFFSET offBuffer)
|
---|
56 | {
|
---|
57 | int rc = HGSMIBufferProcess (&PrimaryExtension->u.primary.areaHostHeap,
|
---|
58 | &PrimaryExtension->u.primary.channels,
|
---|
59 | offBuffer);
|
---|
60 | Assert(!RT_FAILURE(rc));
|
---|
61 | if(RT_FAILURE(rc))
|
---|
62 | {
|
---|
63 | /* failure means the command was not submitted to the handler for some reason
|
---|
64 | * it's our responsibility to notify its completion in this case */
|
---|
65 | HGSMINotifyHostCmdComplete(PrimaryExtension, offBuffer);
|
---|
66 | }
|
---|
67 | /* if the cmd succeeded it's responsibility of the callback to complete it */
|
---|
68 | }
|
---|
69 |
|
---|
70 | static HGSMIOFFSET hgsmiGetHostBuffer (PDEVICE_EXTENSION PrimaryExtension)
|
---|
71 | {
|
---|
72 | return VBoxHGSMIHostRead(PrimaryExtension);
|
---|
73 | }
|
---|
74 |
|
---|
75 | static void hgsmiHostCommandQueryProcess (PDEVICE_EXTENSION PrimaryExtension)
|
---|
76 | {
|
---|
77 | HGSMIOFFSET offset = hgsmiGetHostBuffer (PrimaryExtension);
|
---|
78 | Assert(offset != HGSMIOFFSET_VOID);
|
---|
79 | if(offset != HGSMIOFFSET_VOID)
|
---|
80 | {
|
---|
81 | hgsmiHostCmdProcess(PrimaryExtension, offset);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | #define VBOX_HGSMI_LOCK(_pe, _plock, _dpc, _pold) \
|
---|
86 | do { \
|
---|
87 | if(_dpc) \
|
---|
88 | { \
|
---|
89 | VBoxVideoCmnSpinLockAcquireAtDpcLevel(_pe, _plock); \
|
---|
90 | } \
|
---|
91 | else \
|
---|
92 | {\
|
---|
93 | VBoxVideoCmnSpinLockAcquire(_pe, _plock, _pold); \
|
---|
94 | }\
|
---|
95 | } while(0)
|
---|
96 |
|
---|
97 | #define VBOX_HGSMI_UNLOCK(_pe, _plock, _dpc, _pold) \
|
---|
98 | do { \
|
---|
99 | if(_dpc) \
|
---|
100 | { \
|
---|
101 | VBoxVideoCmnSpinLockReleaseFromDpcLevel(_pe, _plock); \
|
---|
102 | } \
|
---|
103 | else \
|
---|
104 | {\
|
---|
105 | VBoxVideoCmnSpinLockRelease(_pe, _plock, _pold); \
|
---|
106 | }\
|
---|
107 | } while(0)
|
---|
108 |
|
---|
109 | VOID VBoxVideoHGSMIDpc(
|
---|
110 | IN PVOID HwDeviceExtension,
|
---|
111 | IN PVOID Context
|
---|
112 | )
|
---|
113 | {
|
---|
114 | PDEVICE_EXTENSION PrimaryExtension = (PDEVICE_EXTENSION)HwDeviceExtension;
|
---|
115 | uint32_t flags = (uint32_t)Context;
|
---|
116 | bool bProcessing = false;
|
---|
117 | VBOXVCMNIRQL OldIrql;
|
---|
118 | /* we check if another thread is processing the queue and exit if so */
|
---|
119 | do
|
---|
120 | {
|
---|
121 | bool bLock = false;
|
---|
122 | if(!(PrimaryExtension->u.primary.pHostFlags->u32HostFlags & HGSMIHOSTFLAGS_COMMANDS_PENDING))
|
---|
123 | {
|
---|
124 | if(!bProcessing)
|
---|
125 | {
|
---|
126 | break;
|
---|
127 | }
|
---|
128 | VBOX_HGSMI_LOCK(PrimaryExtension, &PrimaryExtension->u.primary.pSynchLock, flags, &OldIrql);
|
---|
129 | if(!(PrimaryExtension->u.primary.pHostFlags->u32HostFlags & HGSMIHOSTFLAGS_COMMANDS_PENDING))
|
---|
130 | {
|
---|
131 | Assert(PrimaryExtension->u.primary.bHostCmdProcessing);
|
---|
132 | PrimaryExtension->u.primary.bHostCmdProcessing = false;
|
---|
133 | VBOX_HGSMI_UNLOCK(PrimaryExtension, &PrimaryExtension->u.primary.pSynchLock, flags, OldIrql);
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | VBOX_HGSMI_UNLOCK(PrimaryExtension, &PrimaryExtension->u.primary.pSynchLock, flags, OldIrql);
|
---|
137 | }
|
---|
138 | else
|
---|
139 | {
|
---|
140 | if(!bProcessing)
|
---|
141 | {
|
---|
142 | VBOX_HGSMI_LOCK(PrimaryExtension, &PrimaryExtension->u.primary.pSynchLock, flags, &OldIrql);
|
---|
143 | if(!(PrimaryExtension->u.primary.pHostFlags->u32HostFlags & HGSMIHOSTFLAGS_COMMANDS_PENDING)
|
---|
144 | || PrimaryExtension->u.primary.bHostCmdProcessing)
|
---|
145 | {
|
---|
146 | VBOX_HGSMI_UNLOCK(PrimaryExtension, &PrimaryExtension->u.primary.pSynchLock, flags, OldIrql);
|
---|
147 | break;
|
---|
148 | }
|
---|
149 | Assert(!PrimaryExtension->u.primary.bHostCmdProcessing);
|
---|
150 | PrimaryExtension->u.primary.bHostCmdProcessing = true;
|
---|
151 | VBOX_HGSMI_UNLOCK(PrimaryExtension, &PrimaryExtension->u.primary.pSynchLock, flags, OldIrql);
|
---|
152 | bProcessing = true;
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | Assert(bProcessing);
|
---|
157 | Assert(PrimaryExtension->u.primary.bHostCmdProcessing);
|
---|
158 | Assert((PrimaryExtension->u.primary.pHostFlags->u32HostFlags & HGSMIHOSTFLAGS_COMMANDS_PENDING) != 0);
|
---|
159 | bProcessing = true;
|
---|
160 |
|
---|
161 | hgsmiHostCommandQueryProcess (PrimaryExtension);
|
---|
162 | } while(true/*!PrimaryExtension->u.primary.bPollingStop*/);
|
---|
163 | }
|
---|
164 |
|
---|
165 | /* Detect whether HGSMI is supported by the host. */
|
---|
166 | BOOLEAN VBoxHGSMIIsSupported (PDEVICE_EXTENSION PrimaryExtension)
|
---|
167 | {
|
---|
168 | USHORT DispiId;
|
---|
169 |
|
---|
170 | VBoxVideoCmnPortWriteUshort((PUSHORT)VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ID);
|
---|
171 | VBoxVideoCmnPortWriteUshort((PUSHORT)VBE_DISPI_IOPORT_DATA, VBE_DISPI_ID_HGSMI);
|
---|
172 |
|
---|
173 | DispiId = VBoxVideoCmnPortReadUshort((PUSHORT)VBE_DISPI_IOPORT_DATA);
|
---|
174 |
|
---|
175 | return (DispiId == VBE_DISPI_ID_HGSMI);
|
---|
176 | }
|
---|
177 |
|
---|
178 | typedef int FNHGSMICALLINIT (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData);
|
---|
179 | typedef FNHGSMICALLINIT *PFNHGSMICALLINIT;
|
---|
180 |
|
---|
181 | typedef int FNHGSMICALLFINALIZE (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData);
|
---|
182 | typedef FNHGSMICALLFINALIZE *PFNHGSMICALLFINALIZE;
|
---|
183 |
|
---|
184 | void* vboxHGSMIBufferAlloc(PDEVICE_EXTENSION PrimaryExtension,
|
---|
185 | HGSMISIZE cbData,
|
---|
186 | uint8_t u8Ch,
|
---|
187 | uint16_t u16Op)
|
---|
188 | {
|
---|
189 | #ifdef VBOX_WITH_WDDM
|
---|
190 | /* @todo: add synchronization */
|
---|
191 | #endif
|
---|
192 | return HGSMIHeapAlloc (&PrimaryExtension->u.primary.hgsmiAdapterHeap, cbData, u8Ch, u16Op);
|
---|
193 | }
|
---|
194 |
|
---|
195 | void vboxHGSMIBufferFree (PDEVICE_EXTENSION PrimaryExtension, void *pvBuffer)
|
---|
196 | {
|
---|
197 | #ifdef VBOX_WITH_WDDM
|
---|
198 | /* @todo: add synchronization */
|
---|
199 | #endif
|
---|
200 | HGSMIHeapFree (&PrimaryExtension->u.primary.hgsmiAdapterHeap, pvBuffer);
|
---|
201 | }
|
---|
202 |
|
---|
203 | int vboxHGSMIBufferSubmit (PDEVICE_EXTENSION PrimaryExtension, void *pvBuffer)
|
---|
204 | {
|
---|
205 | /* Initialize the buffer and get the offset for port IO. */
|
---|
206 | HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&PrimaryExtension->u.primary.hgsmiAdapterHeap, pvBuffer);
|
---|
207 |
|
---|
208 | Assert(offBuffer != HGSMIOFFSET_VOID);
|
---|
209 | if (offBuffer != HGSMIOFFSET_VOID)
|
---|
210 | {
|
---|
211 | /* Submit the buffer to the host. */
|
---|
212 | VBoxHGSMIGuestWrite(PrimaryExtension, offBuffer);
|
---|
213 | return VINF_SUCCESS;
|
---|
214 | }
|
---|
215 |
|
---|
216 | return VERR_INVALID_PARAMETER;
|
---|
217 | }
|
---|
218 |
|
---|
219 | static int vboxCallChannel (PDEVICE_EXTENSION PrimaryExtension,
|
---|
220 | uint8_t u8Ch,
|
---|
221 | uint16_t u16Op,
|
---|
222 | HGSMISIZE cbData,
|
---|
223 | PFNHGSMICALLINIT pfnInit,
|
---|
224 | PFNHGSMICALLFINALIZE pfnFinalize,
|
---|
225 | void *pvContext)
|
---|
226 | {
|
---|
227 | int rc = VINF_SUCCESS;
|
---|
228 |
|
---|
229 | /* Allocate the IO buffer. */
|
---|
230 | #ifndef VBOX_WITH_WDDM
|
---|
231 | if (PrimaryExtension->pPrimary != PrimaryExtension)
|
---|
232 | {
|
---|
233 | dprintf(("VBoxVideo::vboxCallChannel: not primary extension %p!!!\n", PrimaryExtension));
|
---|
234 | return VERR_INVALID_PARAMETER;
|
---|
235 | }
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | void *p = HGSMIHeapAlloc (&PrimaryExtension->u.primary.hgsmiAdapterHeap, cbData, u8Ch, u16Op);
|
---|
239 |
|
---|
240 | if (!p)
|
---|
241 | {
|
---|
242 | rc = VERR_NO_MEMORY;
|
---|
243 | }
|
---|
244 | else
|
---|
245 | {
|
---|
246 | /* Prepare data to be sent to the host. */
|
---|
247 | if (pfnInit)
|
---|
248 | {
|
---|
249 | rc = pfnInit (PrimaryExtension, pvContext, p);
|
---|
250 | }
|
---|
251 |
|
---|
252 | if (RT_SUCCESS (rc))
|
---|
253 | {
|
---|
254 | /* Initialize the buffer and get the offset for port IO. */
|
---|
255 | HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&PrimaryExtension->u.primary.hgsmiAdapterHeap,
|
---|
256 | p);
|
---|
257 |
|
---|
258 | /* Submit the buffer to the host. */
|
---|
259 | VBoxHGSMIGuestWrite(PrimaryExtension, offBuffer);
|
---|
260 |
|
---|
261 | if (pfnFinalize)
|
---|
262 | {
|
---|
263 | rc = pfnFinalize (PrimaryExtension, pvContext, p);
|
---|
264 | }
|
---|
265 | }
|
---|
266 | else
|
---|
267 | {
|
---|
268 | AssertFailed ();
|
---|
269 | rc = VERR_INTERNAL_ERROR;
|
---|
270 | }
|
---|
271 |
|
---|
272 | /* Free the IO buffer. */
|
---|
273 | HGSMIHeapFree (&PrimaryExtension->u.primary.hgsmiAdapterHeap, p);
|
---|
274 | }
|
---|
275 |
|
---|
276 | return rc;
|
---|
277 | }
|
---|
278 |
|
---|
279 | static int vboxCallVBVA (PDEVICE_EXTENSION PrimaryExtension,
|
---|
280 | uint16_t u16Op,
|
---|
281 | HGSMISIZE cbData,
|
---|
282 | PFNHGSMICALLINIT pfnInit,
|
---|
283 | PFNHGSMICALLFINALIZE pfnFinalize,
|
---|
284 | void *pvContext)
|
---|
285 | {
|
---|
286 | return vboxCallChannel (PrimaryExtension,
|
---|
287 | HGSMI_CH_VBVA,
|
---|
288 | u16Op,
|
---|
289 | cbData,
|
---|
290 | pfnInit,
|
---|
291 | pfnFinalize,
|
---|
292 | pvContext);
|
---|
293 | }
|
---|
294 |
|
---|
295 | typedef struct _QUERYCONFCTX
|
---|
296 | {
|
---|
297 | uint32_t u32Index;
|
---|
298 | ULONG *pulValue;
|
---|
299 | } QUERYCONFCTX;
|
---|
300 |
|
---|
301 | static int vbvaInitQueryConf (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
302 | {
|
---|
303 | NOREF (PrimaryExtension);
|
---|
304 |
|
---|
305 | QUERYCONFCTX *pCtx = (QUERYCONFCTX *)pvContext;
|
---|
306 | VBVACONF32 *p = (VBVACONF32 *)pvData;
|
---|
307 |
|
---|
308 | p->u32Index = pCtx->u32Index;
|
---|
309 | p->u32Value = 0;
|
---|
310 |
|
---|
311 | return VINF_SUCCESS;
|
---|
312 | }
|
---|
313 |
|
---|
314 | static int vbvaFinalizeQueryConf (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
315 | {
|
---|
316 | NOREF (PrimaryExtension);
|
---|
317 |
|
---|
318 | QUERYCONFCTX *pCtx = (QUERYCONFCTX *)pvContext;
|
---|
319 | VBVACONF32 *p = (VBVACONF32 *)pvData;
|
---|
320 |
|
---|
321 | if (pCtx->pulValue)
|
---|
322 | {
|
---|
323 | *pCtx->pulValue = p->u32Value;
|
---|
324 | }
|
---|
325 |
|
---|
326 | dprintf(("VBoxVideo::vboxQueryConf: u32Value = %d\n", p->u32Value));
|
---|
327 | return VINF_SUCCESS;
|
---|
328 | }
|
---|
329 |
|
---|
330 | static int vboxQueryConfHGSMI (PDEVICE_EXTENSION PrimaryExtension, uint32_t u32Index, ULONG *pulValue)
|
---|
331 | {
|
---|
332 | dprintf(("VBoxVideo::vboxQueryConf: u32Index = %d\n", u32Index));
|
---|
333 |
|
---|
334 | QUERYCONFCTX context;
|
---|
335 |
|
---|
336 | context.u32Index = u32Index;
|
---|
337 | context.pulValue = pulValue;
|
---|
338 |
|
---|
339 | int rc = vboxCallVBVA (PrimaryExtension,
|
---|
340 | VBVA_QUERY_CONF32,
|
---|
341 | sizeof (VBVACONF32),
|
---|
342 | vbvaInitQueryConf,
|
---|
343 | vbvaFinalizeQueryConf,
|
---|
344 | &context);
|
---|
345 |
|
---|
346 | dprintf(("VBoxVideo::vboxQueryConf: rc = %d\n", rc));
|
---|
347 |
|
---|
348 | return rc;
|
---|
349 | }
|
---|
350 | #ifndef VBOX_WITH_WDDM
|
---|
351 | static int vbvaInitInfoDisplay (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
352 | {
|
---|
353 | NOREF (pvContext);
|
---|
354 | VBVAINFOVIEW *p = (VBVAINFOVIEW *)pvData;
|
---|
355 |
|
---|
356 | int i;
|
---|
357 | PDEVICE_EXTENSION Extension;
|
---|
358 |
|
---|
359 | for (i = 0, Extension = PrimaryExtension;
|
---|
360 | i < PrimaryExtension->u.primary.cDisplays && Extension;
|
---|
361 | i++, Extension = Extension->pNext)
|
---|
362 | {
|
---|
363 | p[i].u32ViewIndex = Extension->iDevice;
|
---|
364 | p[i].u32ViewOffset = Extension->ulFrameBufferOffset;
|
---|
365 | p[i].u32ViewSize = PrimaryExtension->u.primary.ulMaxFrameBufferSize;
|
---|
366 |
|
---|
367 | /* How much VRAM should be reserved for the guest drivers to use VBVA. */
|
---|
368 | const uint32_t cbReservedVRAM = VBVA_DISPLAY_INFORMATION_SIZE + VBVA_MIN_BUFFER_SIZE;
|
---|
369 |
|
---|
370 | p[i].u32MaxScreenSize = p[i].u32ViewSize > cbReservedVRAM?
|
---|
371 | p[i].u32ViewSize - cbReservedVRAM:
|
---|
372 | 0;
|
---|
373 | }
|
---|
374 |
|
---|
375 | if (i == PrimaryExtension->u.primary.cDisplays && Extension == NULL)
|
---|
376 | {
|
---|
377 | return VINF_SUCCESS;
|
---|
378 | }
|
---|
379 |
|
---|
380 | AssertFailed ();
|
---|
381 | return VERR_INTERNAL_ERROR;
|
---|
382 | }
|
---|
383 | #else
|
---|
384 | int vbvaInitInfoCaps (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
385 | {
|
---|
386 | VBVACAPS *pCaps = (VBVACAPS*)pvData;
|
---|
387 | pCaps->rc = VERR_NOT_IMPLEMENTED;
|
---|
388 | pCaps->fCaps = VBVACAPS_COMPLETEGCMD_BY_IOREAD | VBVACAPS_IRQ;
|
---|
389 | return VINF_SUCCESS;
|
---|
390 | }
|
---|
391 |
|
---|
392 |
|
---|
393 | int vbvaFinalizeInfoCaps (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
394 | {
|
---|
395 | VBVACAPS *pCaps = (VBVACAPS*)pvData;
|
---|
396 | AssertRC(pCaps->rc);
|
---|
397 | return pCaps->rc;
|
---|
398 | }
|
---|
399 | #endif
|
---|
400 |
|
---|
401 | static int vbvaInitInfoHeap (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
402 | {
|
---|
403 | NOREF (pvContext);
|
---|
404 | VBVAINFOHEAP *p = (VBVAINFOHEAP *)pvData;
|
---|
405 |
|
---|
406 | p->u32HeapOffset = PrimaryExtension->u.primary.cbVRAM
|
---|
407 | - PrimaryExtension->u.primary.cbMiniportHeap
|
---|
408 | - VBVA_ADAPTER_INFORMATION_SIZE;
|
---|
409 | p->u32HeapSize = PrimaryExtension->u.primary.cbMiniportHeap;
|
---|
410 |
|
---|
411 | return VINF_SUCCESS;
|
---|
412 | }
|
---|
413 |
|
---|
414 | static int hgsmiInitFlagsLocation (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
415 | {
|
---|
416 | NOREF (pvContext);
|
---|
417 | HGSMIBUFFERLOCATION *p = (HGSMIBUFFERLOCATION *)pvData;
|
---|
418 |
|
---|
419 | p->offLocation = PrimaryExtension->u.primary.cbVRAM - sizeof (HGSMIHOSTFLAGS);
|
---|
420 | p->cbLocation = sizeof (HGSMIHOSTFLAGS);
|
---|
421 |
|
---|
422 | return VINF_SUCCESS;
|
---|
423 | }
|
---|
424 |
|
---|
425 |
|
---|
426 | static int vboxSetupAdapterInfoHGSMI (PDEVICE_EXTENSION PrimaryExtension)
|
---|
427 | {
|
---|
428 | dprintf(("VBoxVideo::vboxSetupAdapterInfo\n"));
|
---|
429 |
|
---|
430 | /* setup the flags first to ensure they are initialized by the time the host heap is ready */
|
---|
431 | int rc = vboxCallChannel(PrimaryExtension,
|
---|
432 | HGSMI_CH_HGSMI,
|
---|
433 | HGSMI_CC_HOST_FLAGS_LOCATION,
|
---|
434 | sizeof (HGSMIBUFFERLOCATION),
|
---|
435 | hgsmiInitFlagsLocation,
|
---|
436 | NULL,
|
---|
437 | NULL);
|
---|
438 | AssertRC(rc);
|
---|
439 | if(RT_SUCCESS (rc))
|
---|
440 | {
|
---|
441 | #ifndef VBOX_WITH_WDDM
|
---|
442 | rc = vboxCallVBVA (PrimaryExtension,
|
---|
443 | VBVA_INFO_VIEW,
|
---|
444 | sizeof (VBVAINFOVIEW) * PrimaryExtension->u.primary.cDisplays,
|
---|
445 | vbvaInitInfoDisplay,
|
---|
446 | NULL,
|
---|
447 | NULL);
|
---|
448 | AssertRC(rc);
|
---|
449 | if (RT_SUCCESS (rc))
|
---|
450 | #else
|
---|
451 | /* in case of WDDM we do not control the framebuffer location,
|
---|
452 | * i.e. it is assigned by Video Memory Manager,
|
---|
453 | * The FB information should be passed to guest from our DxgkDdiSetVidPnSourceAddress callback */
|
---|
454 |
|
---|
455 | /* Inform about caps */
|
---|
456 | rc = vboxCallVBVA (PrimaryExtension,
|
---|
457 | VBVA_INFO_CAPS,
|
---|
458 | sizeof (VBVACAPS),
|
---|
459 | vbvaInitInfoCaps,
|
---|
460 | vbvaFinalizeInfoCaps,
|
---|
461 | NULL);
|
---|
462 | AssertRC(rc);
|
---|
463 | if (RT_SUCCESS (rc))
|
---|
464 | #endif
|
---|
465 | {
|
---|
466 | /* Report the host heap location. */
|
---|
467 | rc = vboxCallVBVA (PrimaryExtension,
|
---|
468 | VBVA_INFO_HEAP,
|
---|
469 | sizeof (VBVAINFOHEAP),
|
---|
470 | vbvaInitInfoHeap,
|
---|
471 | NULL,
|
---|
472 | NULL);
|
---|
473 | AssertRC(rc);
|
---|
474 | }
|
---|
475 | }
|
---|
476 |
|
---|
477 |
|
---|
478 | dprintf(("VBoxVideo::vboxSetupAdapterInfo finished rc = %d\n", rc));
|
---|
479 |
|
---|
480 | return rc;
|
---|
481 | }
|
---|
482 |
|
---|
483 | #ifndef VBOX_WITH_WDDM
|
---|
484 | VP_STATUS vboxWaitForSingleObjectVoid(IN PVOID HwDeviceExtension, IN PVOID Object, IN PLARGE_INTEGER Timeout OPTIONAL)
|
---|
485 | {
|
---|
486 | return ERROR_INVALID_FUNCTION;
|
---|
487 | }
|
---|
488 |
|
---|
489 | LONG vboxSetEventVoid(IN PVOID HwDeviceExtension, IN PEVENT pEvent)
|
---|
490 | {
|
---|
491 | return 0;
|
---|
492 | }
|
---|
493 |
|
---|
494 | VOID vboxClearEventVoid (IN PVOID HwDeviceExtension, IN PEVENT pEvent)
|
---|
495 | {
|
---|
496 | }
|
---|
497 |
|
---|
498 | VP_STATUS vboxCreateEventVoid(IN PVOID HwDeviceExtension, IN ULONG EventFlag, IN PVOID Unused, OUT PEVENT *ppEvent)
|
---|
499 | {
|
---|
500 | return ERROR_INVALID_FUNCTION;
|
---|
501 | }
|
---|
502 |
|
---|
503 | VP_STATUS vboxDeleteEventVoid(IN PVOID HwDeviceExtension, IN PEVENT pEvent)
|
---|
504 | {
|
---|
505 | return ERROR_INVALID_FUNCTION;
|
---|
506 | }
|
---|
507 |
|
---|
508 | VP_STATUS vboxCreateSpinLockVoid (IN PVOID HwDeviceExtension, OUT PSPIN_LOCK *SpinLock)
|
---|
509 | {
|
---|
510 | return ERROR_INVALID_FUNCTION;
|
---|
511 | }
|
---|
512 |
|
---|
513 | VP_STATUS vboxDeleteSpinLockVoid (IN PVOID HwDeviceExtension, IN PSPIN_LOCK SpinLock)
|
---|
514 | {
|
---|
515 | return ERROR_INVALID_FUNCTION;
|
---|
516 | }
|
---|
517 |
|
---|
518 | VOID vboxAcquireSpinLockVoid (IN PVOID HwDeviceExtension, IN PSPIN_LOCK SpinLock, OUT PUCHAR OldIrql)
|
---|
519 | {
|
---|
520 | }
|
---|
521 |
|
---|
522 | VOID vboxReleaseSpinLockVoid (IN PVOID HwDeviceExtension, IN PSPIN_LOCK SpinLock, IN UCHAR NewIrql)
|
---|
523 | {
|
---|
524 | }
|
---|
525 |
|
---|
526 | VOID vboxAcquireSpinLockAtDpcLevelVoid (IN PVOID HwDeviceExtension, IN PSPIN_LOCK SpinLock)
|
---|
527 | {
|
---|
528 | }
|
---|
529 |
|
---|
530 | VOID vboxReleaseSpinLockFromDpcLevelVoid (IN PVOID HwDeviceExtension, IN PSPIN_LOCK SpinLock)
|
---|
531 | {
|
---|
532 | }
|
---|
533 |
|
---|
534 | PVOID vboxAllocatePoolVoid(IN PVOID HwDeviceExtension, IN VBOXVP_POOL_TYPE PoolType, IN size_t NumberOfBytes, IN ULONG Tag)
|
---|
535 | {
|
---|
536 | return NULL;
|
---|
537 | }
|
---|
538 |
|
---|
539 | VOID vboxFreePoolVoid(IN PVOID HwDeviceExtension, IN PVOID Ptr)
|
---|
540 | {
|
---|
541 | }
|
---|
542 |
|
---|
543 | BOOLEAN vboxQueueDpcVoid(IN PVOID HwDeviceExtension, IN PMINIPORT_DPC_ROUTINE CallbackRoutine, IN PVOID Context)
|
---|
544 | {
|
---|
545 | return FALSE;
|
---|
546 | }
|
---|
547 |
|
---|
548 | void VBoxSetupVideoPortFunctions(PDEVICE_EXTENSION PrimaryExtension, VBOXVIDEOPORTPROCS *pCallbacks, PVIDEO_PORT_CONFIG_INFO pConfigInfo)
|
---|
549 | {
|
---|
550 | memset(pCallbacks, 0, sizeof(VBOXVIDEOPORTPROCS));
|
---|
551 |
|
---|
552 | if (vboxQueryWinVersion() <= WINNT4)
|
---|
553 | {
|
---|
554 | /* VideoPortGetProcAddress is available for >= win2k */
|
---|
555 | pCallbacks->pfnWaitForSingleObject = vboxWaitForSingleObjectVoid;
|
---|
556 | pCallbacks->pfnSetEvent = vboxSetEventVoid;
|
---|
557 | pCallbacks->pfnClearEvent = vboxClearEventVoid;
|
---|
558 | pCallbacks->pfnCreateEvent = vboxCreateEventVoid;
|
---|
559 | pCallbacks->pfnDeleteEvent = vboxDeleteEventVoid;
|
---|
560 | pCallbacks->pfnCreateSpinLock = vboxCreateSpinLockVoid;
|
---|
561 | pCallbacks->pfnDeleteSpinLock = vboxDeleteSpinLockVoid;
|
---|
562 | pCallbacks->pfnAcquireSpinLock = vboxAcquireSpinLockVoid;
|
---|
563 | pCallbacks->pfnReleaseSpinLock = vboxReleaseSpinLockVoid;
|
---|
564 | pCallbacks->pfnAcquireSpinLockAtDpcLevel = vboxAcquireSpinLockAtDpcLevelVoid;
|
---|
565 | pCallbacks->pfnReleaseSpinLockFromDpcLevel = vboxReleaseSpinLockFromDpcLevelVoid;
|
---|
566 | pCallbacks->pfnAllocatePool = vboxAllocatePoolVoid;
|
---|
567 | pCallbacks->pfnFreePool = vboxFreePoolVoid;
|
---|
568 | pCallbacks->pfnQueueDpc = vboxQueueDpcVoid;
|
---|
569 | return;
|
---|
570 | }
|
---|
571 |
|
---|
572 | pCallbacks->pfnWaitForSingleObject = (PFNWAITFORSINGLEOBJECT)(pConfigInfo->VideoPortGetProcAddress)
|
---|
573 | (PrimaryExtension,
|
---|
574 | (PUCHAR)"VideoPortWaitForSingleObject");
|
---|
575 | Assert(pCallbacks->pfnWaitForSingleObject);
|
---|
576 |
|
---|
577 | pCallbacks->pfnSetEvent = (PFNSETEVENT)(pConfigInfo->VideoPortGetProcAddress)
|
---|
578 | (PrimaryExtension,
|
---|
579 | (PUCHAR)"VideoPortSetEvent");
|
---|
580 | Assert(pCallbacks->pfnSetEvent);
|
---|
581 |
|
---|
582 | pCallbacks->pfnClearEvent = (PFNCLEAREVENT)(pConfigInfo->VideoPortGetProcAddress)
|
---|
583 | (PrimaryExtension,
|
---|
584 | (PUCHAR)"VideoPortClearEvent");
|
---|
585 | Assert(pCallbacks->pfnClearEvent);
|
---|
586 |
|
---|
587 | pCallbacks->pfnCreateEvent = (PFNCREATEEVENT)(pConfigInfo->VideoPortGetProcAddress)
|
---|
588 | (PrimaryExtension,
|
---|
589 | (PUCHAR)"VideoPortCreateEvent");
|
---|
590 | Assert(pCallbacks->pfnCreateEvent);
|
---|
591 |
|
---|
592 | pCallbacks->pfnDeleteEvent = (PFNDELETEEVENT)(pConfigInfo->VideoPortGetProcAddress)
|
---|
593 | (PrimaryExtension,
|
---|
594 | (PUCHAR)"VideoPortDeleteEvent");
|
---|
595 | Assert(pCallbacks->pfnDeleteEvent);
|
---|
596 |
|
---|
597 | if(pCallbacks->pfnWaitForSingleObject
|
---|
598 | && pCallbacks->pfnSetEvent
|
---|
599 | && pCallbacks->pfnClearEvent
|
---|
600 | && pCallbacks->pfnCreateEvent
|
---|
601 | && pCallbacks->pfnDeleteEvent)
|
---|
602 | {
|
---|
603 | pCallbacks->fSupportedTypes |= VBOXVIDEOPORTPROCS_EVENT;
|
---|
604 | }
|
---|
605 | else
|
---|
606 | {
|
---|
607 | pCallbacks->pfnWaitForSingleObject = vboxWaitForSingleObjectVoid;
|
---|
608 | pCallbacks->pfnSetEvent = vboxSetEventVoid;
|
---|
609 | pCallbacks->pfnClearEvent = vboxClearEventVoid;
|
---|
610 | pCallbacks->pfnCreateEvent = vboxCreateEventVoid;
|
---|
611 | pCallbacks->pfnDeleteEvent = vboxDeleteEventVoid;
|
---|
612 | }
|
---|
613 |
|
---|
614 | pCallbacks->pfnCreateSpinLock = (PFNCREATESPINLOCK)(pConfigInfo->VideoPortGetProcAddress)
|
---|
615 | (PrimaryExtension,
|
---|
616 | (PUCHAR)"VideoPortCreateSpinLock");
|
---|
617 | Assert(pCallbacks->pfnCreateSpinLock);
|
---|
618 |
|
---|
619 | pCallbacks->pfnDeleteSpinLock = (PFNDELETESPINLOCK)(pConfigInfo->VideoPortGetProcAddress)
|
---|
620 | (PrimaryExtension,
|
---|
621 | (PUCHAR)"VideoPortDeleteSpinLock");
|
---|
622 | Assert(pCallbacks->pfnDeleteSpinLock);
|
---|
623 |
|
---|
624 | pCallbacks->pfnAcquireSpinLock = (PFNACQUIRESPINLOCK)(pConfigInfo->VideoPortGetProcAddress)
|
---|
625 | (PrimaryExtension,
|
---|
626 | (PUCHAR)"VideoPortAcquireSpinLock");
|
---|
627 | Assert(pCallbacks->pfnAcquireSpinLock);
|
---|
628 |
|
---|
629 | pCallbacks->pfnReleaseSpinLock = (PFNRELEASESPINLOCK)(pConfigInfo->VideoPortGetProcAddress)
|
---|
630 | (PrimaryExtension,
|
---|
631 | (PUCHAR)"VideoPortReleaseSpinLock");
|
---|
632 | Assert(pCallbacks->pfnReleaseSpinLock);
|
---|
633 |
|
---|
634 | pCallbacks->pfnAcquireSpinLockAtDpcLevel = (PFNACQUIRESPINLOCKATDPCLEVEL)(pConfigInfo->VideoPortGetProcAddress)
|
---|
635 | (PrimaryExtension,
|
---|
636 | (PUCHAR)"VideoPortAcquireSpinLockAtDpcLevel");
|
---|
637 | Assert(pCallbacks->pfnAcquireSpinLockAtDpcLevel);
|
---|
638 |
|
---|
639 | pCallbacks->pfnReleaseSpinLockFromDpcLevel = (PFNRELEASESPINLOCKFROMDPCLEVEL)(pConfigInfo->VideoPortGetProcAddress)
|
---|
640 | (PrimaryExtension,
|
---|
641 | (PUCHAR)"VideoPortReleaseSpinLockFromDpcLevel");
|
---|
642 | Assert(pCallbacks->pfnReleaseSpinLockFromDpcLevel);
|
---|
643 |
|
---|
644 | if(pCallbacks->pfnCreateSpinLock
|
---|
645 | && pCallbacks->pfnDeleteSpinLock
|
---|
646 | && pCallbacks->pfnAcquireSpinLock
|
---|
647 | && pCallbacks->pfnReleaseSpinLock
|
---|
648 | && pCallbacks->pfnAcquireSpinLockAtDpcLevel
|
---|
649 | && pCallbacks->pfnReleaseSpinLockFromDpcLevel)
|
---|
650 | {
|
---|
651 | pCallbacks->fSupportedTypes |= VBOXVIDEOPORTPROCS_SPINLOCK;
|
---|
652 | }
|
---|
653 | else
|
---|
654 | {
|
---|
655 | pCallbacks->pfnCreateSpinLock = vboxCreateSpinLockVoid;
|
---|
656 | pCallbacks->pfnDeleteSpinLock = vboxDeleteSpinLockVoid;
|
---|
657 | pCallbacks->pfnAcquireSpinLock = vboxAcquireSpinLockVoid;
|
---|
658 | pCallbacks->pfnReleaseSpinLock = vboxReleaseSpinLockVoid;
|
---|
659 | pCallbacks->pfnAcquireSpinLockAtDpcLevel = vboxAcquireSpinLockAtDpcLevelVoid;
|
---|
660 | pCallbacks->pfnReleaseSpinLockFromDpcLevel = vboxReleaseSpinLockFromDpcLevelVoid;
|
---|
661 | }
|
---|
662 |
|
---|
663 | pCallbacks->pfnAllocatePool = (PFNALLOCATEPOOL)(pConfigInfo->VideoPortGetProcAddress)
|
---|
664 | (PrimaryExtension,
|
---|
665 | (PUCHAR)"VideoPortAllocatePool");
|
---|
666 | Assert(pCallbacks->pfnAllocatePool);
|
---|
667 |
|
---|
668 | pCallbacks->pfnFreePool = (PFNFREEPOOL)(pConfigInfo->VideoPortGetProcAddress)
|
---|
669 | (PrimaryExtension,
|
---|
670 | (PUCHAR)"VideoPortFreePool");
|
---|
671 | Assert(pCallbacks->pfnFreePool);
|
---|
672 |
|
---|
673 | if(pCallbacks->pfnAllocatePool
|
---|
674 | && pCallbacks->pfnFreePool)
|
---|
675 | {
|
---|
676 | pCallbacks->fSupportedTypes |= VBOXVIDEOPORTPROCS_POOL;
|
---|
677 | }
|
---|
678 | else
|
---|
679 | {
|
---|
680 | pCallbacks->pfnAllocatePool = vboxAllocatePoolVoid;
|
---|
681 | pCallbacks->pfnFreePool = vboxFreePoolVoid;
|
---|
682 | }
|
---|
683 |
|
---|
684 | pCallbacks->pfnQueueDpc = (PFNQUEUEDPC)(pConfigInfo->VideoPortGetProcAddress)
|
---|
685 | (PrimaryExtension,
|
---|
686 | (PUCHAR)"VideoPortQueueDpc");
|
---|
687 | Assert(pCallbacks->pfnQueueDpc);
|
---|
688 |
|
---|
689 | if(pCallbacks->pfnQueueDpc)
|
---|
690 | {
|
---|
691 | pCallbacks->fSupportedTypes |= VBOXVIDEOPORTPROCS_DPC;
|
---|
692 | }
|
---|
693 | else
|
---|
694 | {
|
---|
695 | pCallbacks->pfnQueueDpc = vboxQueueDpcVoid;
|
---|
696 | }
|
---|
697 |
|
---|
698 | #ifdef DEBUG_misha
|
---|
699 | Assert(pCallbacks->fSupportedTypes & VBOXVIDEOPORTPROCS_EVENT);
|
---|
700 | Assert(pCallbacks->fSupportedTypes & VBOXVIDEOPORTPROCS_SPINLOCK);
|
---|
701 | #endif
|
---|
702 | }
|
---|
703 | #endif
|
---|
704 |
|
---|
705 | /**
|
---|
706 | * Helper function to register secondary displays (DualView). Note that this will not
|
---|
707 | * be available on pre-XP versions, and some editions on XP will fail because they are
|
---|
708 | * intentionally crippled.
|
---|
709 | *
|
---|
710 | * HGSMI variant is a bit different because it uses only HGSMI interface (VBVA channel)
|
---|
711 | * to talk to the host.
|
---|
712 | */
|
---|
713 | VOID VBoxSetupDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension,
|
---|
714 | #ifndef VBOX_WITH_WDDM
|
---|
715 | PVIDEO_PORT_CONFIG_INFO pConfigInfo,
|
---|
716 | #endif
|
---|
717 | ULONG AdapterMemorySize)
|
---|
718 | {
|
---|
719 | VP_STATUS rc = NO_ERROR;
|
---|
720 |
|
---|
721 | dprintf(("VBoxVideo::VBoxSetupDisplays: PrimaryExtension = %p\n",
|
---|
722 | PrimaryExtension));
|
---|
723 |
|
---|
724 | /* Preinitialize the primary extension.
|
---|
725 | * Note: bVBoxVideoSupported is set to FALSE, because HGSMI is active instead.
|
---|
726 | */
|
---|
727 | PrimaryExtension->pNext = NULL;
|
---|
728 | #ifndef VBOX_WITH_WDDM
|
---|
729 | PrimaryExtension->pPrimary = PrimaryExtension;
|
---|
730 | PrimaryExtension->iDevice = 0;
|
---|
731 | PrimaryExtension->ulFrameBufferOffset = 0;
|
---|
732 | PrimaryExtension->ulFrameBufferSize = 0;
|
---|
733 | #endif
|
---|
734 | PrimaryExtension->u.primary.ulVbvaEnabled = 0;
|
---|
735 | PrimaryExtension->u.primary.bVBoxVideoSupported = FALSE;
|
---|
736 | #ifndef VBOX_WITH_WDDM
|
---|
737 | PrimaryExtension->u.primary.cDisplays = 1;
|
---|
738 | #endif
|
---|
739 | PrimaryExtension->u.primary.cbVRAM = AdapterMemorySize;
|
---|
740 | PrimaryExtension->u.primary.cbMiniportHeap = 0;
|
---|
741 | PrimaryExtension->u.primary.pvMiniportHeap = NULL;
|
---|
742 | PrimaryExtension->u.primary.pvAdapterInformation = NULL;
|
---|
743 | PrimaryExtension->u.primary.pHostFlags = NULL;
|
---|
744 | PrimaryExtension->u.primary.ulMaxFrameBufferSize = 0;
|
---|
745 | PrimaryExtension->u.primary.bHGSMI = VBoxHGSMIIsSupported (PrimaryExtension);
|
---|
746 | VBoxVideoCmnMemZero(&PrimaryExtension->u.primary.areaHostHeap, sizeof(HGSMIAREA));
|
---|
747 | VBoxVideoCmnMemZero(&PrimaryExtension->areaDisplay, sizeof(HGSMIAREA));
|
---|
748 |
|
---|
749 | if (PrimaryExtension->u.primary.IOPortGuest == 0)
|
---|
750 | {
|
---|
751 | PrimaryExtension->u.primary.bHGSMI = false;
|
---|
752 | }
|
---|
753 |
|
---|
754 | if (PrimaryExtension->u.primary.bHGSMI)
|
---|
755 | {
|
---|
756 | /* Map the adapter information. It will be needed for HGSMI IO. */
|
---|
757 | rc = VBoxMapAdapterMemory (PrimaryExtension,
|
---|
758 | &PrimaryExtension->u.primary.pvAdapterInformation,
|
---|
759 | PrimaryExtension->u.primary.cbVRAM - VBVA_ADAPTER_INFORMATION_SIZE,
|
---|
760 | VBVA_ADAPTER_INFORMATION_SIZE
|
---|
761 | );
|
---|
762 | if (rc != NO_ERROR)
|
---|
763 | {
|
---|
764 | dprintf(("VBoxVideo::VBoxSetupDisplays: VBoxMapAdapterMemory pvAdapterInfoirrmation failed rc = %d\n",
|
---|
765 | rc));
|
---|
766 |
|
---|
767 | PrimaryExtension->u.primary.bHGSMI = FALSE;
|
---|
768 | }
|
---|
769 | else
|
---|
770 | {
|
---|
771 | /* Setup a HGSMI heap within the adapter information area. */
|
---|
772 | rc = HGSMIHeapSetup (&PrimaryExtension->u.primary.hgsmiAdapterHeap,
|
---|
773 | PrimaryExtension->u.primary.pvAdapterInformation,
|
---|
774 | VBVA_ADAPTER_INFORMATION_SIZE - sizeof(HGSMIHOSTFLAGS),
|
---|
775 | PrimaryExtension->u.primary.cbVRAM - VBVA_ADAPTER_INFORMATION_SIZE,
|
---|
776 | false /*fOffsetBased*/);
|
---|
777 |
|
---|
778 | if (RT_FAILURE (rc))
|
---|
779 | {
|
---|
780 | dprintf(("VBoxVideo::VBoxSetupDisplays: HGSMIHeapSetup failed rc = %d\n",
|
---|
781 | rc));
|
---|
782 |
|
---|
783 | PrimaryExtension->u.primary.bHGSMI = FALSE;
|
---|
784 | }
|
---|
785 | else
|
---|
786 | {
|
---|
787 | PrimaryExtension->u.primary.pHostFlags = (HGSMIHOSTFLAGS*)(((uint8_t*)PrimaryExtension->u.primary.pvAdapterInformation)
|
---|
788 | + VBVA_ADAPTER_INFORMATION_SIZE - sizeof(HGSMIHOSTFLAGS));
|
---|
789 | }
|
---|
790 | }
|
---|
791 | }
|
---|
792 |
|
---|
793 | /* Setup the host heap and the adapter memory. */
|
---|
794 | if (PrimaryExtension->u.primary.bHGSMI)
|
---|
795 | {
|
---|
796 | /* The miniport heap is used for the host buffers. */
|
---|
797 | ULONG cbMiniportHeap = 0;
|
---|
798 | vboxQueryConfHGSMI (PrimaryExtension, VBOX_VBVA_CONF32_HOST_HEAP_SIZE, &cbMiniportHeap);
|
---|
799 |
|
---|
800 | if (cbMiniportHeap != 0)
|
---|
801 | {
|
---|
802 | /* Do not allow too big heap. No more than 25% of VRAM is allowed. */
|
---|
803 | ULONG cbMiniportHeapMaxSize = AdapterMemorySize / 4;
|
---|
804 |
|
---|
805 | if (cbMiniportHeapMaxSize >= VBVA_ADAPTER_INFORMATION_SIZE)
|
---|
806 | {
|
---|
807 | cbMiniportHeapMaxSize -= VBVA_ADAPTER_INFORMATION_SIZE;
|
---|
808 | }
|
---|
809 |
|
---|
810 | if (cbMiniportHeap > cbMiniportHeapMaxSize)
|
---|
811 | {
|
---|
812 | cbMiniportHeap = cbMiniportHeapMaxSize;
|
---|
813 | }
|
---|
814 |
|
---|
815 | /* Round up to 4096 bytes. */
|
---|
816 | PrimaryExtension->u.primary.cbMiniportHeap = (cbMiniportHeap + 0xFFF) & ~0xFFF;
|
---|
817 |
|
---|
818 | dprintf(("VBoxVideo::VBoxSetupDisplays: cbMiniportHeap = 0x%08X, PrimaryExtension->u.primary.cbMiniportHeap = 0x%08X, cbMiniportHeapMaxSize = 0x%08X\n",
|
---|
819 | cbMiniportHeap, PrimaryExtension->u.primary.cbMiniportHeap, cbMiniportHeapMaxSize));
|
---|
820 |
|
---|
821 | /* Map the heap region.
|
---|
822 | *
|
---|
823 | * Note: the heap will be used for the host buffers submitted to the guest.
|
---|
824 | * The miniport driver is responsible for reading FIFO and notifying
|
---|
825 | * display drivers.
|
---|
826 | */
|
---|
827 | rc = VBoxMapAdapterMemory (PrimaryExtension,
|
---|
828 | &PrimaryExtension->u.primary.pvMiniportHeap,
|
---|
829 | PrimaryExtension->u.primary.cbVRAM
|
---|
830 | - VBVA_ADAPTER_INFORMATION_SIZE
|
---|
831 | - PrimaryExtension->u.primary.cbMiniportHeap,
|
---|
832 | PrimaryExtension->u.primary.cbMiniportHeap
|
---|
833 | );
|
---|
834 | if (rc != NO_ERROR)
|
---|
835 | {
|
---|
836 | PrimaryExtension->u.primary.pvMiniportHeap = NULL;
|
---|
837 | PrimaryExtension->u.primary.cbMiniportHeap = 0;
|
---|
838 | PrimaryExtension->u.primary.bHGSMI = FALSE;
|
---|
839 | }
|
---|
840 | else
|
---|
841 | {
|
---|
842 | HGSMIOFFSET offBase = PrimaryExtension->u.primary.cbVRAM
|
---|
843 | - VBVA_ADAPTER_INFORMATION_SIZE
|
---|
844 | - PrimaryExtension->u.primary.cbMiniportHeap;
|
---|
845 |
|
---|
846 | /* Init the host hap area. Buffers from the host will be placed there. */
|
---|
847 | HGSMIAreaInitialize (&PrimaryExtension->u.primary.areaHostHeap,
|
---|
848 | PrimaryExtension->u.primary.pvMiniportHeap,
|
---|
849 | PrimaryExtension->u.primary.cbMiniportHeap,
|
---|
850 | offBase);
|
---|
851 | }
|
---|
852 | }
|
---|
853 | else
|
---|
854 | {
|
---|
855 | /* Host has not requested a heap. */
|
---|
856 | PrimaryExtension->u.primary.pvMiniportHeap = NULL;
|
---|
857 | PrimaryExtension->u.primary.cbMiniportHeap = 0;
|
---|
858 | }
|
---|
859 | }
|
---|
860 |
|
---|
861 | /* Check whether the guest supports multimonitors. */
|
---|
862 | if (PrimaryExtension->u.primary.bHGSMI)
|
---|
863 | {
|
---|
864 | #ifndef VBOX_WITH_WDDM
|
---|
865 | typedef VP_STATUS (*PFNCREATESECONDARYDISPLAY)(PVOID, PVOID *, ULONG);
|
---|
866 | PFNCREATESECONDARYDISPLAY pfnCreateSecondaryDisplay = NULL;
|
---|
867 |
|
---|
868 | /* Dynamically query the VideoPort import to be binary compatible across Windows versions */
|
---|
869 | if (vboxQueryWinVersion() > WINNT4)
|
---|
870 | {
|
---|
871 | /* This bluescreens on NT4, hence the above version check */
|
---|
872 | pfnCreateSecondaryDisplay = (PFNCREATESECONDARYDISPLAY)(pConfigInfo->VideoPortGetProcAddress)
|
---|
873 | (PrimaryExtension,
|
---|
874 | (PUCHAR)"VideoPortCreateSecondaryDisplay");
|
---|
875 | }
|
---|
876 |
|
---|
877 | if (pfnCreateSecondaryDisplay != NULL)
|
---|
878 | #endif
|
---|
879 | {
|
---|
880 | /* Query the configured number of displays. */
|
---|
881 | ULONG cDisplays = 0;
|
---|
882 | vboxQueryConfHGSMI (PrimaryExtension, VBOX_VBVA_CONF32_MONITOR_COUNT, &cDisplays);
|
---|
883 |
|
---|
884 | dprintf(("VBoxVideo::VBoxSetupDisplays: cDisplays = %d\n",
|
---|
885 | cDisplays));
|
---|
886 |
|
---|
887 | if (cDisplays == 0 || cDisplays > VBOX_VIDEO_MAX_SCREENS)
|
---|
888 | {
|
---|
889 | /* Host reported some bad value. Continue in the 1 screen mode. */
|
---|
890 | cDisplays = 1;
|
---|
891 | }
|
---|
892 |
|
---|
893 | #ifndef VBOX_WITH_WDDM
|
---|
894 | PDEVICE_EXTENSION pPrev = PrimaryExtension;
|
---|
895 |
|
---|
896 | ULONG iDisplay;
|
---|
897 | for (iDisplay = 1; iDisplay < cDisplays; iDisplay++)
|
---|
898 | {
|
---|
899 | PDEVICE_EXTENSION SecondaryExtension = NULL;
|
---|
900 | rc = pfnCreateSecondaryDisplay (PrimaryExtension, (PVOID*)&SecondaryExtension, VIDEO_DUALVIEW_REMOVABLE);
|
---|
901 |
|
---|
902 | dprintf(("VBoxVideo::VBoxSetupDisplays: VideoPortCreateSecondaryDisplay returned %#x, SecondaryExtension = %p\n",
|
---|
903 | rc, SecondaryExtension));
|
---|
904 |
|
---|
905 | if (rc != NO_ERROR)
|
---|
906 | {
|
---|
907 | break;
|
---|
908 | }
|
---|
909 |
|
---|
910 | SecondaryExtension->pNext = NULL;
|
---|
911 | SecondaryExtension->pPrimary = PrimaryExtension;
|
---|
912 | SecondaryExtension->iDevice = iDisplay;
|
---|
913 | SecondaryExtension->ulFrameBufferOffset = 0;
|
---|
914 | SecondaryExtension->ulFrameBufferSize = 0;
|
---|
915 | SecondaryExtension->u.secondary.bEnabled = FALSE;
|
---|
916 |
|
---|
917 | /* Update the list pointers. */
|
---|
918 | pPrev->pNext = SecondaryExtension;
|
---|
919 | pPrev = SecondaryExtension;
|
---|
920 |
|
---|
921 | /* Take the successfully created display into account. */
|
---|
922 | PrimaryExtension->u.primary.cDisplays++;
|
---|
923 | }
|
---|
924 | #else
|
---|
925 | /* simply store the number of monitors, we will deal with VidPN stuff later */
|
---|
926 | PrimaryExtension->u.primary.cDisplays = cDisplays;
|
---|
927 | #endif
|
---|
928 | }
|
---|
929 |
|
---|
930 | /* Failure to create secondary displays is not fatal */
|
---|
931 | rc = NO_ERROR;
|
---|
932 | }
|
---|
933 |
|
---|
934 | #ifndef VBOX_WITH_WDDM
|
---|
935 | /* Now when the number of monitors is known and extensions are created,
|
---|
936 | * calculate the layout of framebuffers.
|
---|
937 | */
|
---|
938 | VBoxComputeFrameBufferSizes (PrimaryExtension);
|
---|
939 | #endif
|
---|
940 |
|
---|
941 | if (PrimaryExtension->u.primary.bHGSMI)
|
---|
942 | {
|
---|
943 | /* Setup the information for the host. */
|
---|
944 | rc = vboxSetupAdapterInfoHGSMI (PrimaryExtension);
|
---|
945 |
|
---|
946 | if (RT_FAILURE (rc))
|
---|
947 | {
|
---|
948 | PrimaryExtension->u.primary.bHGSMI = FALSE;
|
---|
949 | }
|
---|
950 | }
|
---|
951 |
|
---|
952 | #ifdef VBOX_WITH_WDDM
|
---|
953 | if (PrimaryExtension->u.primary.bHGSMI)
|
---|
954 | {
|
---|
955 | ULONG ulAvailable = PrimaryExtension->u.primary.cbVRAM
|
---|
956 | - PrimaryExtension->u.primary.cbMiniportHeap
|
---|
957 | - VBVA_ADAPTER_INFORMATION_SIZE;
|
---|
958 |
|
---|
959 | ULONG ulSize;
|
---|
960 | ULONG offset;
|
---|
961 | #ifdef VBOXVDMA
|
---|
962 | ulSize = ulAvailable / 2;
|
---|
963 | if (ulSize > VBOXWDDM_C_VDMA_BUFFER_SIZE)
|
---|
964 | ulSize = VBOXWDDM_C_VDMA_BUFFER_SIZE;
|
---|
965 |
|
---|
966 | /* Align down to 4096 bytes. */
|
---|
967 | ulSize &= ~0xFFF;
|
---|
968 | offset = ulAvailable - ulSize;
|
---|
969 |
|
---|
970 | Assert(!(offset & 0xFFF));
|
---|
971 | #else
|
---|
972 | offset = ulAvailable;
|
---|
973 | #endif
|
---|
974 | rc = vboxVdmaCreate (PrimaryExtension, &PrimaryExtension->u.primary.Vdma
|
---|
975 | #ifdef VBOXVDMA
|
---|
976 | , offset, ulSize
|
---|
977 | #endif
|
---|
978 | );
|
---|
979 | AssertRC(rc);
|
---|
980 | if (RT_SUCCESS(rc))
|
---|
981 | {
|
---|
982 | /* can enable it right away since the host does not need any screen/FB info
|
---|
983 | * for basic DMA functionality */
|
---|
984 | rc = vboxVdmaEnable(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
|
---|
985 | AssertRC(rc);
|
---|
986 | if (RT_FAILURE(rc))
|
---|
987 | vboxVdmaDestroy(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
|
---|
988 | }
|
---|
989 |
|
---|
990 | #ifdef VBOXWDDM_RENDER_FROM_SHADOW
|
---|
991 | if (RT_SUCCESS(rc))
|
---|
992 | {
|
---|
993 | ulAvailable = offset;
|
---|
994 | ulSize = ulAvailable / 2;
|
---|
995 | ulSize /= PrimaryExtension->u.primary.cDisplays;
|
---|
996 | Assert(ulSize > VBVA_MIN_BUFFER_SIZE);
|
---|
997 | if (ulSize > VBVA_MIN_BUFFER_SIZE)
|
---|
998 | {
|
---|
999 | ULONG ulRatio = ulSize/VBVA_MIN_BUFFER_SIZE;
|
---|
1000 | ulRatio >>= 4; /* /= 16; */
|
---|
1001 | if (ulRatio)
|
---|
1002 | ulSize = VBVA_MIN_BUFFER_SIZE * ulRatio;
|
---|
1003 | else
|
---|
1004 | ulSize = VBVA_MIN_BUFFER_SIZE;
|
---|
1005 | }
|
---|
1006 | else
|
---|
1007 | {
|
---|
1008 | /* todo: ?? */
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | ulSize &= ~0xFFF;
|
---|
1012 | Assert(ulSize);
|
---|
1013 |
|
---|
1014 | Assert(ulSize * PrimaryExtension->u.primary.cDisplays < ulAvailable);
|
---|
1015 |
|
---|
1016 | for (int i = PrimaryExtension->u.primary.cDisplays-1; i >= 0; --i)
|
---|
1017 | {
|
---|
1018 | offset -= ulSize;
|
---|
1019 | rc = vboxVbvaCreate(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva, offset, ulSize, i);
|
---|
1020 | AssertRC(rc);
|
---|
1021 | if (RT_SUCCESS(rc))
|
---|
1022 | {
|
---|
1023 | rc = vboxVbvaEnable(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva);
|
---|
1024 | AssertRC(rc);
|
---|
1025 | if (RT_FAILURE(rc))
|
---|
1026 | {
|
---|
1027 | /* @todo: de-initialize */
|
---|
1028 | }
|
---|
1029 | }
|
---|
1030 | }
|
---|
1031 | }
|
---|
1032 | #endif
|
---|
1033 |
|
---|
1034 | rc = VBoxMapAdapterMemory(PrimaryExtension, (void**)&PrimaryExtension->pvVisibleVram,
|
---|
1035 | 0,
|
---|
1036 | vboxWddmVramCpuVisibleSize(PrimaryExtension));
|
---|
1037 | Assert(rc == VINF_SUCCESS);
|
---|
1038 | if (rc != VINF_SUCCESS)
|
---|
1039 | PrimaryExtension->pvVisibleVram = NULL;
|
---|
1040 |
|
---|
1041 | if (RT_FAILURE(rc))
|
---|
1042 | PrimaryExtension->u.primary.bHGSMI = FALSE;
|
---|
1043 | }
|
---|
1044 | #endif
|
---|
1045 |
|
---|
1046 | if (!PrimaryExtension->u.primary.bHGSMI)
|
---|
1047 | {
|
---|
1048 | /* Unmap the memory if VBoxVideo is not supported. */
|
---|
1049 | VBoxUnmapAdapterMemory (PrimaryExtension, &PrimaryExtension->u.primary.pvMiniportHeap, PrimaryExtension->u.primary.cbMiniportHeap);
|
---|
1050 | VBoxUnmapAdapterInformation (PrimaryExtension);
|
---|
1051 |
|
---|
1052 | HGSMIHeapDestroy (&PrimaryExtension->u.primary.hgsmiAdapterHeap);
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | if (PrimaryExtension->u.primary.bHGSMI)
|
---|
1056 | {
|
---|
1057 | VBoxVideoCmnSpinLockCreate(PrimaryExtension, &PrimaryExtension->u.primary.pSynchLock);
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | dprintf(("VBoxVideo::VBoxSetupDisplays: finished\n"));
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | #ifdef VBOX_WITH_WDDM
|
---|
1064 | int VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension)
|
---|
1065 | {
|
---|
1066 | int rc = VINF_SUCCESS;
|
---|
1067 |
|
---|
1068 | Assert(PrimaryExtension->pvVisibleVram);
|
---|
1069 | if (PrimaryExtension->pvVisibleVram)
|
---|
1070 | VBoxUnmapAdapterMemory(PrimaryExtension, (void**)&PrimaryExtension->pvVisibleVram, vboxWddmVramCpuVisibleSize(PrimaryExtension));
|
---|
1071 |
|
---|
1072 | for (int i = PrimaryExtension->u.primary.cDisplays-1; i >= 0; --i)
|
---|
1073 | {
|
---|
1074 | rc = vboxVbvaDisable(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva);
|
---|
1075 | AssertRC(rc);
|
---|
1076 | if (RT_SUCCESS(rc))
|
---|
1077 | {
|
---|
1078 | rc = vboxVbvaDestroy(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva);
|
---|
1079 | AssertRC(rc);
|
---|
1080 | if (RT_FAILURE(rc))
|
---|
1081 | {
|
---|
1082 | /* @todo: */
|
---|
1083 | }
|
---|
1084 | }
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | rc = vboxVdmaDisable(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
|
---|
1088 | AssertRC(rc);
|
---|
1089 | if (RT_SUCCESS(rc))
|
---|
1090 | {
|
---|
1091 | rc = vboxVdmaDestroy(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
|
---|
1092 | AssertRC(rc);
|
---|
1093 | if (RT_SUCCESS(rc))
|
---|
1094 | {
|
---|
1095 | /*rc = */VBoxUnmapAdapterMemory(PrimaryExtension, &PrimaryExtension->u.primary.pvMiniportHeap, PrimaryExtension->u.primary.cbMiniportHeap);
|
---|
1096 | /*
|
---|
1097 | AssertRC(rc);
|
---|
1098 | if (RT_SUCCESS(rc))
|
---|
1099 | */
|
---|
1100 | {
|
---|
1101 | HGSMIHeapDestroy(&PrimaryExtension->u.primary.hgsmiAdapterHeap);
|
---|
1102 |
|
---|
1103 | /* Map the adapter information. It will be needed for HGSMI IO. */
|
---|
1104 | /*rc = */VBoxUnmapAdapterInformation(PrimaryExtension);
|
---|
1105 | /*
|
---|
1106 | AssertRC(rc);
|
---|
1107 | if (RT_FAILURE(rc))
|
---|
1108 | drprintf((__FUNCTION__"VBoxUnmapAdapterMemory PrimaryExtension->u.primary.pvAdapterInformation failed, rc(%d)\n", rc));
|
---|
1109 | */
|
---|
1110 |
|
---|
1111 | }
|
---|
1112 | }
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | return rc;
|
---|
1116 | }
|
---|
1117 | #endif
|
---|
1118 |
|
---|
1119 | /*
|
---|
1120 | * Send the pointer shape to the host.
|
---|
1121 | */
|
---|
1122 | typedef struct _MOUSEPOINTERSHAPECTX
|
---|
1123 | {
|
---|
1124 | VIDEO_POINTER_ATTRIBUTES *pPointerAttr;
|
---|
1125 | uint32_t cbData;
|
---|
1126 | int32_t i32Result;
|
---|
1127 | } MOUSEPOINTERSHAPECTX;
|
---|
1128 |
|
---|
1129 | static int vbvaInitMousePointerShape (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
1130 | {
|
---|
1131 | NOREF (PrimaryExtension);
|
---|
1132 |
|
---|
1133 | MOUSEPOINTERSHAPECTX *pCtx = (MOUSEPOINTERSHAPECTX *)pvContext;
|
---|
1134 | VBVAMOUSEPOINTERSHAPE *p = (VBVAMOUSEPOINTERSHAPE *)pvData;
|
---|
1135 |
|
---|
1136 | /* Will be updated by the host. */
|
---|
1137 | p->i32Result = VINF_SUCCESS;
|
---|
1138 |
|
---|
1139 | /* We have our custom flags in the field */
|
---|
1140 | p->fu32Flags = pCtx->pPointerAttr->Enable & 0x0000FFFF;
|
---|
1141 |
|
---|
1142 | p->u32HotX = (pCtx->pPointerAttr->Enable >> 16) & 0xFF;
|
---|
1143 | p->u32HotY = (pCtx->pPointerAttr->Enable >> 24) & 0xFF;
|
---|
1144 | p->u32Width = pCtx->pPointerAttr->Width;
|
---|
1145 | p->u32Height = pCtx->pPointerAttr->Height;
|
---|
1146 |
|
---|
1147 | if (p->fu32Flags & VBOX_MOUSE_POINTER_SHAPE)
|
---|
1148 | {
|
---|
1149 | /* If shape is supplied, then alway create the pointer visible.
|
---|
1150 | * See comments in 'vboxUpdatePointerShape'
|
---|
1151 | */
|
---|
1152 | p->fu32Flags |= VBOX_MOUSE_POINTER_VISIBLE;
|
---|
1153 |
|
---|
1154 | /* Copy the actual pointer data. */
|
---|
1155 | memcpy (p->au8Data, pCtx->pPointerAttr->Pixels, pCtx->cbData);
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | return VINF_SUCCESS;
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | static int vbvaFinalizeMousePointerShape (PDEVICE_EXTENSION PrimaryExtension, void *pvContext, void *pvData)
|
---|
1162 | {
|
---|
1163 | NOREF (PrimaryExtension);
|
---|
1164 |
|
---|
1165 | MOUSEPOINTERSHAPECTX *pCtx = (MOUSEPOINTERSHAPECTX *)pvContext;
|
---|
1166 | VBVAMOUSEPOINTERSHAPE *p = (VBVAMOUSEPOINTERSHAPE *)pvData;
|
---|
1167 |
|
---|
1168 | pCtx->i32Result = p->i32Result;
|
---|
1169 |
|
---|
1170 | return VINF_SUCCESS;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | BOOLEAN vboxUpdatePointerShape (PDEVICE_EXTENSION DeviceExtension,
|
---|
1174 | PVIDEO_POINTER_ATTRIBUTES pointerAttr,
|
---|
1175 | uint32_t cbLength)
|
---|
1176 | {
|
---|
1177 | #ifndef VBOX_WITH_WDDM
|
---|
1178 | PDEVICE_EXTENSION PrimaryExtension = DeviceExtension->pPrimary;
|
---|
1179 |
|
---|
1180 | /* In multimonitor case the HW mouse pointer is the same on all screens,
|
---|
1181 | * and Windows calls each display driver with the same pointer data: visible for
|
---|
1182 | * the screen where the pointer is and invisible for other screens.
|
---|
1183 | *
|
---|
1184 | * This driver passes the shape to the host only from primary screen and makes
|
---|
1185 | * the pointer always visible (in vbvaInitMousePointerShape).
|
---|
1186 | *
|
---|
1187 | * The simple solution makes it impossible to create the shape and keep the mouse
|
---|
1188 | * pointer invisible. New shapes will be created visible.
|
---|
1189 | * But:
|
---|
1190 | * 1) VBox frontends actually ignore the visibility flag if VBOX_MOUSE_POINTER_SHAPE
|
---|
1191 | * is set and always create new pointers visible.
|
---|
1192 | * 2) Windows uses DrvMovePointer to hide the pointer, which will still work.
|
---|
1193 | */
|
---|
1194 |
|
---|
1195 | if (DeviceExtension->iDevice != PrimaryExtension->iDevice)
|
---|
1196 | {
|
---|
1197 | dprintf(("vboxUpdatePointerShape: ignore non primary device %d(%d)\n",
|
---|
1198 | DeviceExtension->iDevice, PrimaryExtension->iDevice));
|
---|
1199 | /* Success. */
|
---|
1200 | return TRUE;
|
---|
1201 | }
|
---|
1202 | #else
|
---|
1203 | PDEVICE_EXTENSION PrimaryExtension = DeviceExtension;
|
---|
1204 | #endif
|
---|
1205 |
|
---|
1206 | uint32_t cbData = 0;
|
---|
1207 |
|
---|
1208 | if (pointerAttr->Enable & VBOX_MOUSE_POINTER_SHAPE)
|
---|
1209 | {
|
---|
1210 | /* Size of the pointer data: sizeof (AND mask) + sizeof (XOR_MASK) */
|
---|
1211 | cbData = ((((pointerAttr->Width + 7) / 8) * pointerAttr->Height + 3) & ~3)
|
---|
1212 | + pointerAttr->Width * 4 * pointerAttr->Height;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | #ifndef DEBUG_misha
|
---|
1216 | dprintf(("vboxUpdatePointerShape: cbData %d, %dx%d\n",
|
---|
1217 | cbData, pointerAttr->Width, pointerAttr->Height));
|
---|
1218 | #endif
|
---|
1219 |
|
---|
1220 | if (cbData > cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES))
|
---|
1221 | {
|
---|
1222 | dprintf(("vboxUpdatePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
|
---|
1223 | cbData, cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES)));
|
---|
1224 | return FALSE;
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | MOUSEPOINTERSHAPECTX ctx;
|
---|
1228 |
|
---|
1229 | ctx.pPointerAttr = pointerAttr;
|
---|
1230 | ctx.cbData = cbData;
|
---|
1231 | ctx.i32Result = VERR_NOT_SUPPORTED;
|
---|
1232 |
|
---|
1233 | int rc = vboxCallVBVA (PrimaryExtension,
|
---|
1234 | VBVA_MOUSE_POINTER_SHAPE,
|
---|
1235 | sizeof (VBVAMOUSEPOINTERSHAPE) + cbData,
|
---|
1236 | vbvaInitMousePointerShape,
|
---|
1237 | vbvaFinalizeMousePointerShape,
|
---|
1238 | &ctx);
|
---|
1239 | #ifndef DEBUG_misha
|
---|
1240 | dprintf(("VBoxVideo::vboxMousePointerShape: rc %d, i32Result = %d\n", rc, ctx.i32Result));
|
---|
1241 | #endif
|
---|
1242 |
|
---|
1243 | return RT_SUCCESS(rc) && RT_SUCCESS(ctx.i32Result);
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 | typedef struct _VBVAMINIPORT_CHANNELCONTEXT
|
---|
1247 | {
|
---|
1248 | PFNHGSMICHANNELHANDLER pfnChannelHandler;
|
---|
1249 | void *pvChannelHandler;
|
---|
1250 | }VBVAMINIPORT_CHANNELCONTEXT;
|
---|
1251 |
|
---|
1252 | typedef struct _VBVADISP_CHANNELCONTEXT
|
---|
1253 | {
|
---|
1254 | struct _VBVAHOSTCMD * pFirstCmd;
|
---|
1255 | struct _VBVAHOSTCMD * pLastCmd;
|
---|
1256 | VBOXVCMNSPIN_LOCK pSynchLock;
|
---|
1257 | #ifdef DEBUG
|
---|
1258 | int cCmds;
|
---|
1259 | #endif
|
---|
1260 | bool bValid;
|
---|
1261 | }VBVADISP_CHANNELCONTEXT;
|
---|
1262 |
|
---|
1263 | #ifdef DEBUG
|
---|
1264 | void dbgCheckListLocked(const VBVADISP_CHANNELCONTEXT *pList, struct _VBVAHOSTCMD * pCmd)
|
---|
1265 | {
|
---|
1266 | int counter = 0;
|
---|
1267 | for(struct _VBVAHOSTCMD * pCur = pList->pFirstCmd; pCur; pCur=pCur->u.pNext)
|
---|
1268 | {
|
---|
1269 | Assert(pCur != pCmd);
|
---|
1270 | if(pCur == pList->pLastCmd)
|
---|
1271 | {
|
---|
1272 | Assert(pCur->u.pNext == NULL);
|
---|
1273 | }
|
---|
1274 | if(pCur->u.pNext == NULL)
|
---|
1275 | {
|
---|
1276 | Assert(pCur == pList->pLastCmd);
|
---|
1277 | }
|
---|
1278 | counter++;
|
---|
1279 | }
|
---|
1280 |
|
---|
1281 | Assert(counter == pList->cCmds);
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | void dbgCheckList(PDEVICE_EXTENSION PrimaryExtension, VBVADISP_CHANNELCONTEXT *pList, struct _VBVAHOSTCMD * pCmd)
|
---|
1285 | {
|
---|
1286 | VBOXVCMNIRQL oldIrql;
|
---|
1287 | VBoxVideoCmnSpinLockAcquire(PrimaryExtension, &pList->pSynchLock, &oldIrql);
|
---|
1288 |
|
---|
1289 | dbgCheckListLocked(pList, pCmd);
|
---|
1290 |
|
---|
1291 | VBoxVideoCmnSpinLockRelease(PrimaryExtension, &pList->pSynchLock, oldIrql);
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | #define DBG_CHECKLIST_LOCKED(_pl, pc) dbgCheckListLocked(_pl, pc)
|
---|
1295 | #define DBG_CHECKLIST(_pe, _pl, pc) dbgCheckList(_pe, _pl, pc)
|
---|
1296 |
|
---|
1297 | #else
|
---|
1298 | #define DBG_CHECKLIST_LOCKED(_pl, pc) do{}while(0)
|
---|
1299 | #define DBG_CHECKLIST(_pe, _pl, pc) do{}while(0)
|
---|
1300 | #endif
|
---|
1301 |
|
---|
1302 |
|
---|
1303 | typedef struct _VBVA_CHANNELCONTEXTS
|
---|
1304 | {
|
---|
1305 | PDEVICE_EXTENSION PrimaryExtension;
|
---|
1306 | uint32_t cUsed;
|
---|
1307 | uint32_t cContexts;
|
---|
1308 | VBVAMINIPORT_CHANNELCONTEXT mpContext;
|
---|
1309 | VBVADISP_CHANNELCONTEXT aContexts[1];
|
---|
1310 | }VBVA_CHANNELCONTEXTS;
|
---|
1311 |
|
---|
1312 | static int vboxVBVADeleteChannelContexts(PDEVICE_EXTENSION PrimaryExtension, VBVA_CHANNELCONTEXTS * pContext)
|
---|
1313 | {
|
---|
1314 | VBoxVideoCmnMemFree(PrimaryExtension,pContext);
|
---|
1315 | return VINF_SUCCESS;
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 | static int vboxVBVACreateChannelContexts(PDEVICE_EXTENSION PrimaryExtension, VBVA_CHANNELCONTEXTS ** ppContext)
|
---|
1319 | {
|
---|
1320 | #ifndef VBOX_WITH_WDDM
|
---|
1321 | uint32_t cDisplays = (uint32_t)PrimaryExtension->u.primary.cDisplays;
|
---|
1322 | #else
|
---|
1323 | uint32_t cDisplays = (uint32_t)PrimaryExtension->u.primary.cDisplays;
|
---|
1324 | #endif
|
---|
1325 | const size_t size = RT_OFFSETOF(VBVA_CHANNELCONTEXTS, aContexts[cDisplays]);
|
---|
1326 | VBVA_CHANNELCONTEXTS * pContext = (VBVA_CHANNELCONTEXTS*)VBoxVideoCmnMemAllocNonPaged(PrimaryExtension, size, MEM_TAG);
|
---|
1327 | if(pContext)
|
---|
1328 | {
|
---|
1329 | memset(pContext, 0, size);
|
---|
1330 | pContext->cContexts = cDisplays;
|
---|
1331 | pContext->PrimaryExtension = PrimaryExtension;
|
---|
1332 | *ppContext = pContext;
|
---|
1333 | return VINF_SUCCESS;
|
---|
1334 | }
|
---|
1335 | return VERR_GENERAL_FAILURE;
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | static VBVADISP_CHANNELCONTEXT* vboxVBVAFindHandlerInfo(VBVA_CHANNELCONTEXTS *pCallbacks, int iId)
|
---|
1339 | {
|
---|
1340 | if(iId < 0)
|
---|
1341 | {
|
---|
1342 | return NULL;
|
---|
1343 | }
|
---|
1344 | else if(pCallbacks->cContexts > (uint32_t)iId)
|
---|
1345 | {
|
---|
1346 | return &pCallbacks->aContexts[iId];
|
---|
1347 | }
|
---|
1348 | return NULL;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | #ifndef VBOX_WITH_WDDM
|
---|
1352 | DECLCALLBACK(void) hgsmiHostCmdComplete (HVBOXVIDEOHGSMI hHGSMI, struct _VBVAHOSTCMD * pCmd)
|
---|
1353 | {
|
---|
1354 | PDEVICE_EXTENSION PrimaryExtension = ((PDEVICE_EXTENSION)hHGSMI)->pPrimary;
|
---|
1355 | HGSMIHostCmdComplete (PrimaryExtension, pCmd);
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | DECLCALLBACK(int) hgsmiHostCmdRequest (HVBOXVIDEOHGSMI hHGSMI, uint8_t u8Channel, struct _VBVAHOSTCMD ** ppCmd)
|
---|
1359 | {
|
---|
1360 | // if(display < 0)
|
---|
1361 | // return VERR_INVALID_PARAMETER;
|
---|
1362 | if(!ppCmd)
|
---|
1363 | return VERR_INVALID_PARAMETER;
|
---|
1364 |
|
---|
1365 | PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)hHGSMI;
|
---|
1366 | PDEVICE_EXTENSION PrimaryExtension = pDevExt->pPrimary;
|
---|
1367 |
|
---|
1368 | /* pick up the host commands */
|
---|
1369 | VBoxVideoHGSMIDpc(PrimaryExtension, NULL);
|
---|
1370 |
|
---|
1371 | HGSMICHANNEL * pChannel = HGSMIChannelFindById (&PrimaryExtension->u.primary.channels, u8Channel);
|
---|
1372 | if(pChannel)
|
---|
1373 | {
|
---|
1374 | VBVA_CHANNELCONTEXTS * pContexts = (VBVA_CHANNELCONTEXTS *)pChannel->handler.pvHandler;
|
---|
1375 | VBVADISP_CHANNELCONTEXT *pDispContext = vboxVBVAFindHandlerInfo(pContexts, pDevExt->iDevice);
|
---|
1376 | Assert(pDispContext);
|
---|
1377 | if(pDispContext)
|
---|
1378 | {
|
---|
1379 | UCHAR oldIrql;
|
---|
1380 | VBoxVideoCmnSpinLockAcquire(PrimaryExtension, &pDispContext->pSynchLock, &oldIrql);
|
---|
1381 |
|
---|
1382 | DBG_CHECKLIST_LOCKED(pDispContext, NULL);
|
---|
1383 |
|
---|
1384 | *ppCmd = pDispContext->pFirstCmd;
|
---|
1385 | pDispContext->pFirstCmd = NULL;
|
---|
1386 | pDispContext->pLastCmd = NULL;
|
---|
1387 | #ifdef DEBUG
|
---|
1388 | pDispContext->cCmds = 0;
|
---|
1389 | #endif
|
---|
1390 | VBoxVideoCmnSpinLockRelease(PrimaryExtension, &pDispContext->pSynchLock, oldIrql);
|
---|
1391 |
|
---|
1392 | DBG_CHECKLIST(PrimaryExtension, pDispContext, NULL);
|
---|
1393 |
|
---|
1394 | return VINF_SUCCESS;
|
---|
1395 | }
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 | return VERR_INVALID_PARAMETER;
|
---|
1399 | }
|
---|
1400 | #endif
|
---|
1401 |
|
---|
1402 | static DECLCALLBACK(int) vboxVBVAChannelGenericHandler(void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer)
|
---|
1403 | {
|
---|
1404 | VBVA_CHANNELCONTEXTS *pCallbacks = (VBVA_CHANNELCONTEXTS*)pvHandler;
|
---|
1405 | // Assert(0);
|
---|
1406 | Assert(cbBuffer > VBVAHOSTCMD_HDRSIZE);
|
---|
1407 | if(cbBuffer > VBVAHOSTCMD_HDRSIZE)
|
---|
1408 | {
|
---|
1409 | VBVAHOSTCMD *pHdr = (VBVAHOSTCMD*)pvBuffer;
|
---|
1410 | Assert(pHdr->iDstID >= 0);
|
---|
1411 | if(pHdr->iDstID >= 0)
|
---|
1412 | {
|
---|
1413 | VBVADISP_CHANNELCONTEXT* pHandler = vboxVBVAFindHandlerInfo(pCallbacks, pHdr->iDstID);
|
---|
1414 | Assert(pHandler && pHandler->bValid);
|
---|
1415 | if(pHandler && pHandler->bValid)
|
---|
1416 | {
|
---|
1417 | VBVAHOSTCMD *pFirst = NULL, *pLast = NULL;
|
---|
1418 | for(VBVAHOSTCMD *pCur = pHdr; pCur; )
|
---|
1419 | {
|
---|
1420 | Assert(!pCur->u.Data);
|
---|
1421 | Assert(!pFirst);
|
---|
1422 | Assert(!pLast);
|
---|
1423 |
|
---|
1424 | switch(u16ChannelInfo)
|
---|
1425 | {
|
---|
1426 | case VBVAHG_DISPLAY_CUSTOM:
|
---|
1427 | {
|
---|
1428 | if(pLast)
|
---|
1429 | {
|
---|
1430 | pLast->u.pNext = pCur;
|
---|
1431 | pLast = pCur;
|
---|
1432 | }
|
---|
1433 | else
|
---|
1434 | {
|
---|
1435 | pFirst = pCur;
|
---|
1436 | pLast = pCur;
|
---|
1437 | }
|
---|
1438 | Assert(!pCur->u.Data);
|
---|
1439 | //TODO: use offset here
|
---|
1440 | pCur = pCur->u.pNext;
|
---|
1441 | Assert(!pCur);
|
---|
1442 | Assert(pFirst);
|
---|
1443 | Assert(pFirst == pLast);
|
---|
1444 | break;
|
---|
1445 | }
|
---|
1446 | case VBVAHG_EVENT:
|
---|
1447 | {
|
---|
1448 | VBVAHOSTCMDEVENT *pEventCmd = VBVAHOSTCMD_BODY(pCur, VBVAHOSTCMDEVENT);
|
---|
1449 | #ifndef VBOX_WITH_WDDM
|
---|
1450 | PEVENT pEvent = (PEVENT)pEventCmd->pEvent;
|
---|
1451 | pCallbacks->PrimaryExtension->u.primary.VideoPortProcs.pfnSetEvent(
|
---|
1452 | pCallbacks->PrimaryExtension,
|
---|
1453 | pEvent);
|
---|
1454 | #else
|
---|
1455 | PKEVENT pEvent = (PKEVENT)pEventCmd->pEvent;
|
---|
1456 | KeSetEvent(pEvent, 0, FALSE);
|
---|
1457 | #endif
|
---|
1458 | }
|
---|
1459 | default:
|
---|
1460 | {
|
---|
1461 | DBG_CHECKLIST(pCallbacks->PrimaryExtension, pHandler, pCur);
|
---|
1462 | Assert(u16ChannelInfo==VBVAHG_EVENT);
|
---|
1463 | Assert(!pCur->u.Data);
|
---|
1464 | //TODO: use offset here
|
---|
1465 | if(pLast)
|
---|
1466 | pLast->u.pNext = pCur->u.pNext;
|
---|
1467 | VBVAHOSTCMD * pNext = pCur->u.pNext;
|
---|
1468 | pCur->u.pNext = NULL;
|
---|
1469 | HGSMIHostCmdComplete(pCallbacks->PrimaryExtension, pCur);
|
---|
1470 | pCur = pNext;
|
---|
1471 | Assert(!pCur);
|
---|
1472 | Assert(!pFirst);
|
---|
1473 | Assert(pFirst == pLast);
|
---|
1474 | break;
|
---|
1475 | }
|
---|
1476 | }
|
---|
1477 | }
|
---|
1478 |
|
---|
1479 | DBG_CHECKLIST(pCallbacks->PrimaryExtension, pHandler, pFirst);
|
---|
1480 |
|
---|
1481 | /* we do not support lists currently */
|
---|
1482 | Assert(pFirst == pLast);
|
---|
1483 | if(pLast)
|
---|
1484 | {
|
---|
1485 | Assert(pLast->u.pNext == NULL);
|
---|
1486 | }
|
---|
1487 |
|
---|
1488 | if(pFirst)
|
---|
1489 | {
|
---|
1490 | Assert(pLast);
|
---|
1491 | UCHAR oldIrql;
|
---|
1492 | VBoxVideoCmnSpinLockAcquire(pCallbacks->PrimaryExtension,
|
---|
1493 | &pHandler->pSynchLock,
|
---|
1494 | &oldIrql);
|
---|
1495 |
|
---|
1496 | DBG_CHECKLIST_LOCKED(pHandler, pFirst);
|
---|
1497 |
|
---|
1498 | if(pHandler->pLastCmd)
|
---|
1499 | {
|
---|
1500 | pHandler->pLastCmd->u.pNext = pFirst;
|
---|
1501 | Assert(pHandler->pFirstCmd);
|
---|
1502 | }
|
---|
1503 | else
|
---|
1504 | {
|
---|
1505 | Assert(!pHandler->pFirstCmd);
|
---|
1506 | pHandler->pFirstCmd = pFirst;
|
---|
1507 | }
|
---|
1508 | pHandler->pLastCmd = pLast;
|
---|
1509 | #ifdef DEBUG
|
---|
1510 | pHandler->cCmds++;
|
---|
1511 | #endif
|
---|
1512 | DBG_CHECKLIST_LOCKED(pHandler, NULL);
|
---|
1513 |
|
---|
1514 | VBoxVideoCmnSpinLockRelease(pCallbacks->PrimaryExtension,
|
---|
1515 | &pHandler->pSynchLock,
|
---|
1516 | oldIrql);
|
---|
1517 | }
|
---|
1518 | else
|
---|
1519 | {
|
---|
1520 | Assert(!pLast);
|
---|
1521 | }
|
---|
1522 | return VINF_SUCCESS;
|
---|
1523 | }
|
---|
1524 | }
|
---|
1525 | else
|
---|
1526 | {
|
---|
1527 | //TODO: impl
|
---|
1528 | // HGSMIMINIPORT_CHANNELCONTEXT *pHandler = vboxVideoHGSMIFindHandler;
|
---|
1529 | // if(pHandler && pHandler->pfnChannelHandler)
|
---|
1530 | // {
|
---|
1531 | // pHandler->pfnChannelHandler(pHandler->pvChannelHandler, u16ChannelInfo, pHdr, cbBuffer);
|
---|
1532 | //
|
---|
1533 | // return VINF_SUCCESS;
|
---|
1534 | // }
|
---|
1535 | }
|
---|
1536 | }
|
---|
1537 | /* no handlers were found, need to complete the command here */
|
---|
1538 | HGSMIHostCmdComplete(pCallbacks->PrimaryExtension, pvBuffer);
|
---|
1539 | return VINF_SUCCESS;
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 | static HGSMICHANNELHANDLER g_OldHandler;
|
---|
1543 |
|
---|
1544 | int vboxVBVAChannelDisplayEnable(PDEVICE_EXTENSION PrimaryExtension,
|
---|
1545 | int iDisplay, /* negative would mean this is a miniport handler */
|
---|
1546 | uint8_t u8Channel)
|
---|
1547 | {
|
---|
1548 | VBVA_CHANNELCONTEXTS * pContexts;
|
---|
1549 | HGSMICHANNEL * pChannel = HGSMIChannelFindById (&PrimaryExtension->u.primary.channels, u8Channel);
|
---|
1550 | if(!pChannel)
|
---|
1551 | {
|
---|
1552 | int rc = vboxVBVACreateChannelContexts(PrimaryExtension, &pContexts);
|
---|
1553 | if(RT_FAILURE(rc))
|
---|
1554 | {
|
---|
1555 | return rc;
|
---|
1556 | }
|
---|
1557 | }
|
---|
1558 | else
|
---|
1559 | {
|
---|
1560 | pContexts = (VBVA_CHANNELCONTEXTS *)pChannel->handler.pvHandler;
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 | VBVADISP_CHANNELCONTEXT *pDispContext = vboxVBVAFindHandlerInfo(pContexts, iDisplay);
|
---|
1564 | Assert(pDispContext);
|
---|
1565 | if(pDispContext)
|
---|
1566 | {
|
---|
1567 | #ifdef DEBUGVHWASTRICT
|
---|
1568 | Assert(!pDispContext->bValid);
|
---|
1569 | #endif
|
---|
1570 | Assert(!pDispContext->pFirstCmd);
|
---|
1571 | Assert(!pDispContext->pLastCmd);
|
---|
1572 | if(!pDispContext->bValid)
|
---|
1573 | {
|
---|
1574 | pDispContext->bValid = true;
|
---|
1575 | pDispContext->pFirstCmd = NULL;
|
---|
1576 | pDispContext->pLastCmd= NULL;
|
---|
1577 | #ifdef DEBUG
|
---|
1578 | pDispContext->cCmds = 0;
|
---|
1579 | #endif
|
---|
1580 |
|
---|
1581 | VBoxVideoCmnSpinLockCreate(PrimaryExtension, &pDispContext->pSynchLock);
|
---|
1582 |
|
---|
1583 | int rc = VINF_SUCCESS;
|
---|
1584 | if(!pChannel)
|
---|
1585 | {
|
---|
1586 | rc = HGSMIChannelRegister (&PrimaryExtension->u.primary.channels,
|
---|
1587 | u8Channel,
|
---|
1588 | "VGA Miniport HGSMI channel",
|
---|
1589 | vboxVBVAChannelGenericHandler,
|
---|
1590 | pContexts,
|
---|
1591 | &g_OldHandler);
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | if(RT_SUCCESS(rc))
|
---|
1595 | {
|
---|
1596 | pContexts->cUsed++;
|
---|
1597 | return VINF_SUCCESS;
|
---|
1598 | }
|
---|
1599 | }
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | if(!pChannel)
|
---|
1603 | {
|
---|
1604 | vboxVBVADeleteChannelContexts(PrimaryExtension, pContexts);
|
---|
1605 | }
|
---|
1606 |
|
---|
1607 | return VERR_GENERAL_FAILURE;
|
---|
1608 | }
|
---|
1609 |
|
---|
1610 | /** @todo Mouse pointer position to be read from VMMDev memory, address of the memory region
|
---|
1611 | * can be queried from VMMDev via an IOCTL. This VMMDev memory region will contain
|
---|
1612 | * host information which is needed by the guest.
|
---|
1613 | *
|
---|
1614 | * Reading will not cause a switch to the host.
|
---|
1615 | *
|
---|
1616 | * Have to take into account:
|
---|
1617 | * * synchronization: host must write to the memory only from EMT,
|
---|
1618 | * large structures must be read under flag, which tells the host
|
---|
1619 | * that the guest is currently reading the memory (OWNER flag?).
|
---|
1620 | * * guest writes: may be allocate a page for the host info and make
|
---|
1621 | * the page readonly for the guest.
|
---|
1622 | * * the information should be available only for additions drivers.
|
---|
1623 | * * VMMDev additions driver will inform the host which version of the info it expects,
|
---|
1624 | * host must support all versions.
|
---|
1625 | *
|
---|
1626 | */
|
---|
1627 |
|
---|