VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h@ 30057

Last change on this file since 30057 was 29922, checked in by vboxsync, 15 years ago

wddm/2d: overlay surface creation fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.7 KB
Line 
1/** @file
2 * VirtualBox Video miniport driver
3 *
4 * Copyright (C) 2006-2007 Oracle Corporation
5 *
6 * This file is part of VirtualBox Open Source Edition (OSE), as
7 * available from http://www.virtualbox.org. This file is free software;
8 * you can redistribute it and/or modify it under the terms of the GNU
9 * General Public License (GPL) as published by the Free Software
10 * Foundation, in version 2 as it comes in the "COPYING" file of the
11 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
12 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13 */
14
15#ifndef VBOXVIDEO_H
16#define VBOXVIDEO_H
17
18#include <VBox/cdefs.h>
19#include <VBox/types.h>
20#include <iprt/assert.h>
21
22#ifdef VBOX_WITH_HGSMI
23//#include <iprt/thread.h>
24
25#include <VBox/HGSMI/HGSMI.h>
26#include <VBox/HGSMI/HGSMIChSetup.h>
27#include "VBoxHGSMI.h"
28#endif /* VBOX_WITH_HGSMI */
29
30RT_C_DECLS_BEGIN
31#ifndef VBOXWDDM
32#include "dderror.h"
33#include "devioctl.h"
34#include "miniport.h"
35#include "ntddvdeo.h"
36#include "video.h"
37#else
38# define VBOX_WITH_WORKAROUND_MISSING_PACK
39# if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
40# define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
41# define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
42# define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
43# define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
44# define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
45# define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
46# define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
47# define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
48# pragma warning(disable : 4163)
49# ifdef VBOX_WITH_WORKAROUND_MISSING_PACK
50# pragma warning(disable : 4103)
51# endif
52# include <ntddk.h>
53# pragma warning(default : 4163)
54# ifdef VBOX_WITH_WORKAROUND_MISSING_PACK
55# pragma pack()
56# pragma warning(default : 4103)
57# endif
58# undef _InterlockedExchange
59# undef _InterlockedExchangeAdd
60# undef _InterlockedCompareExchange
61# undef _InterlockedAddLargeStatistic
62# undef _interlockedbittestandset
63# undef _interlockedbittestandreset
64# undef _interlockedbittestandset64
65# undef _interlockedbittestandreset64
66# else
67# include <ntddk.h>
68# endif
69#include "dispmprt.h"
70#include "ntddvdeo.h"
71#include "dderror.h"
72#endif
73RT_C_DECLS_END
74
75#define VBE_DISPI_IOPORT_INDEX 0x01CE
76#define VBE_DISPI_IOPORT_DATA 0x01CF
77#define VBE_DISPI_INDEX_ID 0x0
78#define VBE_DISPI_INDEX_XRES 0x1
79#define VBE_DISPI_INDEX_YRES 0x2
80#define VBE_DISPI_INDEX_BPP 0x3
81#define VBE_DISPI_INDEX_ENABLE 0x4
82#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
83#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
84#define VBE_DISPI_INDEX_X_OFFSET 0x8
85#define VBE_DISPI_INDEX_Y_OFFSET 0x9
86#define VBE_DISPI_INDEX_VBOX_VIDEO 0xa
87
88#define VBE_DISPI_ID2 0xB0C2
89/* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
90#define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
91#ifdef VBOX_WITH_HGSMI
92#define VBE_DISPI_ID_HGSMI 0xBE01
93#endif /* VBOX_WITH_HGSMI */
94#define VBE_DISPI_DISABLED 0x00
95#define VBE_DISPI_ENABLED 0x01
96#define VBE_DISPI_LFB_ENABLED 0x40
97#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
98#define VBE_DISPI_TOTAL_VIDEO_MEMORY_MB 4
99#define VBE_DISPI_TOTAL_VIDEO_MEMORY_KB (VBE_DISPI_TOTAL_VIDEO_MEMORY_MB * 1024)
100#define VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES (VBE_DISPI_TOTAL_VIDEO_MEMORY_KB * 1024)
101
102#ifdef VBOX_WITH_HGSMI
103#define VGA_PORT_HGSMI_HOST 0x3b0
104#define VGA_PORT_HGSMI_GUEST 0x3d0
105#endif /* VBOX_WITH_HGSMI */
106
107/* common API types */
108#ifndef VBOXWDDM
109typedef PSPIN_LOCK VBOXVCMNSPIN_LOCK, *PVBOXVCMNSPIN_LOCK;
110typedef UCHAR VBOXVCMNIRQL, *PVBOXVCMNIRQL;
111
112typedef PEVENT VBOXVCMNEVENT, *PVBOXVCMNEVENT;
113
114typedef struct _DEVICE_EXTENSION * VBOXCMNREG;
115#else
116typedef struct _DEVICE_EXTENSION *PDEVICE_EXTENSION;
117#include <VBox/VBoxVideo.h>
118#include "wddm/VBoxVideoIf.h"
119#include "wddm/VBoxVideoWddm.h"
120#include "wddm/VBoxVideoShgsmi.h"
121#include "wddm/VBoxVideoVdma.h"
122#include "wddm/VBoxVideoVidPn.h"
123#ifdef VBOXWDDM_WITH_VBVA
124# include "wddm/VBoxVideoVbva.h"
125#endif
126#ifdef VBOX_WITH_VIDEOHWACCEL
127# include "wddm/VBoxVideoVhwa.h"
128#endif
129
130
131typedef KSPIN_LOCK VBOXVCMNSPIN_LOCK, *PVBOXVCMNSPIN_LOCK;
132typedef KIRQL VBOXVCMNIRQL, *PVBOXVCMNIRQL;
133
134typedef KEVENT VBOXVCMNEVENT, *PVBOXVCMNEVENT;
135
136typedef HANDLE VBOXCMNREG;
137
138#define VBOXWDDM_POINTER_ATTRIBUTES_SIZE VBOXWDDM_ROUNDBOUND( \
139 VBOXWDDM_ROUNDBOUND( sizeof (VIDEO_POINTER_ATTRIBUTES), 4 ) + \
140 VBOXWDDM_ROUNDBOUND(VBOXWDDM_C_POINTER_MAX_WIDTH * VBOXWDDM_C_POINTER_MAX_HEIGHT * 4, 4) + \
141 VBOXWDDM_ROUNDBOUND((VBOXWDDM_C_POINTER_MAX_WIDTH * VBOXWDDM_C_POINTER_MAX_HEIGHT + 7) >> 3, 4) \
142 , 8)
143
144typedef struct VBOXWDDM_POINTER_INFO
145{
146 uint32_t xPos;
147 uint32_t yPos;
148 union
149 {
150 VIDEO_POINTER_ATTRIBUTES data;
151 char buffer[VBOXWDDM_POINTER_ATTRIBUTES_SIZE];
152 } Attributes;
153} VBOXWDDM_POINTER_INFO, *PVBOXWDDM_POINTER_INFO;
154
155#ifdef VBOX_WITH_VIDEOHWACCEL
156typedef struct VBOXWDDM_VHWA
157{
158 VBOXVHWA_INFO Settings;
159 volatile uint32_t cOverlaysCreated;
160} VBOXWDDM_VHWA;
161#endif
162
163typedef struct VBOXWDDM_SOURCE
164{
165 struct VBOXWDDM_ALLOCATION * pPrimaryAllocation;
166#ifdef VBOXWDDM_RENDER_FROM_SHADOW
167 struct VBOXWDDM_ALLOCATION * pShadowAllocation;
168 VBOXVIDEOOFFSET offVram;
169 VBOXWDDM_SURFACE_DESC SurfDesc;
170 VBOXVBVAINFO Vbva;
171#endif
172#ifdef VBOX_WITH_VIDEOHWACCEL
173 /* @todo: in our case this seems more like a target property,
174 * but keep it here for now */
175 VBOXWDDM_VHWA Vhwa;
176#endif
177 VBOXWDDM_POINTER_INFO PointerInfo;
178} VBOXWDDM_SOURCE, *PVBOXWDDM_SOURCE;
179
180#endif
181
182typedef struct _DEVICE_EXTENSION
183{
184 struct _DEVICE_EXTENSION *pNext; /* Next extension in the DualView extension list.
185 * The primary extension is the first one.
186 */
187#ifndef VBOXWDDM
188 struct _DEVICE_EXTENSION *pPrimary; /* Pointer to the primary device extension. */
189
190 ULONG iDevice; /* Device index: 0 for primary, otherwise a secondary device. */
191
192 ULONG CurrentMode; /* Saved information about video modes */
193 ULONG CurrentModeWidth;
194 ULONG CurrentModeHeight;
195 ULONG CurrentModeBPP;
196
197 ULONG ulFrameBufferOffset; /* The framebuffer position in the VRAM. */
198 ULONG ulFrameBufferSize; /* The size of the current framebuffer. */
199#endif
200 union {
201 /* Information that is only relevant to the primary device or is the same for all devices. */
202 struct {
203
204 void *pvReqFlush; /* Pointer to preallocated generic request structure for
205 * VMMDevReq_VideoAccelFlush. Allocated when VBVA status
206 * is changed. Deallocated on HwReset.
207 */
208
209
210 ULONG ulVbvaEnabled; /* Indicates that VBVA mode is enabled. */
211
212 BOOLEAN bVBoxVideoSupported; /* TRUE if VBoxVideo extensions, including DualView, are supported by the host. */
213#ifndef VBOXWDDM
214 int cDisplays; /* Number of displays. */
215#endif
216 ULONG cbVRAM; /* The VRAM size. */
217
218 ULONG cbMiniportHeap; /* The size of reserved VRAM for miniport driver heap.
219 * It is at offset:
220 * cbAdapterMemorySize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE - cbMiniportHeap
221 */
222 PVOID pvMiniportHeap; /* The pointer to the miniport heap VRAM.
223 * This is mapped by miniport separately.
224 */
225#ifdef VBOXWDDM
226 VBOXVDMAINFO Vdma;
227# ifdef VBOXVDMA_WITH_VBVA
228 VBOXVBVAINFO Vbva;
229# endif
230#endif
231
232#ifdef VBOX_WITH_HGSMI
233 volatile HGSMIHOSTFLAGS * pHostFlags; /* HGSMI host flags */
234 volatile bool bHostCmdProcessing;
235 VBOXVCMNSPIN_LOCK pSynchLock;
236#endif
237
238 PVOID pvAdapterInformation; /* The pointer to the last 4K of VRAM.
239 * This is mapped by miniport separately.
240 */
241
242 ULONG ulMaxFrameBufferSize; /* The size of the VRAM allocated for the a single framebuffer. */
243
244 BOOLEAN fMouseHidden; /* Has the mouse cursor been hidden by the guest? */
245
246#ifndef VBOX_WITH_HGSMI
247 ULONG ulDisplayInformationSize; /* The size of the Display information, which is at offset:
248 * ulFrameBufferOffset + ulMaxFrameBufferSize.
249 */
250#endif /* !VBOX_WITH_HGSMI */
251
252#ifdef VBOX_WITH_HGSMI
253 BOOLEAN bHGSMI; /* Whether HGSMI is enabled. */
254
255 HGSMIAREA areaHostHeap; /* Host heap VRAM area. */
256
257 HGSMICHANNELINFO channels;
258
259 HGSMIHEAP hgsmiAdapterHeap;
260
261 /* The IO Port Number for host commands. */
262 RTIOPORT IOPortHost;
263
264 /* The IO Port Number for guest commands. */
265 RTIOPORT IOPortGuest;
266# ifndef VBOXWDDM
267 /* Video Port API dynamically picked up at runtime for binary backwards compatibility with older NT versions */
268 VBOXVIDEOPORTPROCS VideoPortProcs;
269# else
270 /* Display Port handle and callbacks */
271 DXGKRNL_INTERFACE DxgkInterface;
272# endif
273#endif /* VBOX_WITH_HGSMI */
274 } primary;
275
276 /* Secondary device information. */
277 struct {
278 BOOLEAN bEnabled; /* Device enabled flag */
279 } secondary;
280 } u;
281
282#ifdef VBOX_WITH_HGSMI
283 HGSMIAREA areaDisplay; /* Entire VRAM chunk for this display device. */
284#endif /* VBOX_WITH_HGSMI */
285
286#ifdef VBOXWDDM
287 PDEVICE_OBJECT pPDO;
288
289 VBOXSHGSMILIST CtlList;
290 VBOXSHGSMILIST DmaCmdList;
291#ifdef VBOX_WITH_VIDEOHWACCEL
292 VBOXSHGSMILIST VhwaCmdList;
293#endif
294 BOOL bSetNotifyDxDpc;
295 BOOL bNotifyDxDpc;
296
297 ULONG cSources;
298 /* currently we define the array for the max possible size since we do not know
299 * the monitor count at the DxgkDdiAddDevice,
300 * i.e. we obtain the monitor count in DxgkDdiStartDevice due to implementation of the currently re-used XPDM functionality
301 *
302 * @todo: use the dynamic array size calculated at DxgkDdiAddDevice
303 * */
304 VBOXWDDM_SOURCE aSources[VBOX_VIDEO_MAX_SCREENS];
305#endif
306} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
307
308#ifndef VBOXWDDM
309#define DEV_MOUSE_HIDDEN(dev) ((dev)->pPrimary->u.primary.fMouseHidden)
310#define DEV_SET_MOUSE_HIDDEN(dev) \
311do { \
312 (dev)->pPrimary->u.primary.fMouseHidden = TRUE; \
313} while (0)
314#define DEV_SET_MOUSE_SHOWN(dev) \
315do { \
316 (dev)->pPrimary->u.primary.fMouseHidden = FALSE; \
317} while (0)
318#else
319#define DEV_MOUSE_HIDDEN(dev) ((dev)->u.primary.fMouseHidden)
320#define DEV_SET_MOUSE_HIDDEN(dev) \
321do { \
322 (dev)->u.primary.fMouseHidden = TRUE; \
323} while (0)
324#define DEV_SET_MOUSE_SHOWN(dev) \
325do { \
326 (dev)->u.primary.fMouseHidden = FALSE; \
327} while (0)
328#endif
329extern "C"
330{
331#ifndef VBOXWDDM
332/* XPDM-WDDM common API */
333
334typedef PEVENT VBOXVCMNEVENT, *PVBOXVCMNEVENT;
335
336DECLINLINE(VOID) VBoxVideoCmnPortWriteUchar(IN PUCHAR Port, IN UCHAR Value)
337{
338 VideoPortWritePortUchar(Port,Value);
339}
340
341DECLINLINE(VOID) VBoxVideoCmnPortWriteUshort(IN PUSHORT Port, IN USHORT Value)
342{
343 VideoPortWritePortUshort(Port,Value);
344}
345
346DECLINLINE(VOID) VBoxVideoCmnPortWriteUlong(IN PULONG Port, IN ULONG Value)
347{
348 VideoPortWritePortUlong(Port,Value);
349}
350
351DECLINLINE(UCHAR) VBoxVideoCmnPortReadUchar(IN PUCHAR Port)
352{
353 return VideoPortReadPortUchar(Port);
354}
355
356DECLINLINE(USHORT) VBoxVideoCmnPortReadUshort(IN PUSHORT Port)
357{
358 return VideoPortReadPortUshort(Port);
359}
360
361DECLINLINE(ULONG) VBoxVideoCmnPortReadUlong(IN PULONG Port)
362{
363 return VideoPortReadPortUlong(Port);
364}
365
366DECLINLINE(VOID) VBoxVideoCmnMemZero(PVOID pvMem, ULONG cbMem)
367{
368 VideoPortZeroMemory(pvMem, cbMem);
369}
370
371DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquire(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, OUT PVBOXVCMNIRQL OldIrql)
372{
373 pDeviceExtension->u.primary.VideoPortProcs.pfnAcquireSpinLock(pDeviceExtension, *SpinLock, OldIrql);
374}
375
376DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquireAtDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
377{
378 pDeviceExtension->u.primary.VideoPortProcs.pfnAcquireSpinLockAtDpcLevel(pDeviceExtension, *SpinLock);
379}
380
381DECLINLINE(VOID) VBoxVideoCmnSpinLockRelease(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, IN VBOXVCMNIRQL NewIrql)
382{
383 pDeviceExtension->u.primary.VideoPortProcs.pfnReleaseSpinLock(pDeviceExtension, *SpinLock, NewIrql);
384}
385
386DECLINLINE(VOID) VBoxVideoCmnSpinLockReleaseFromDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
387{
388 pDeviceExtension->u.primary.VideoPortProcs.pfnReleaseSpinLockFromDpcLevel(pDeviceExtension, *SpinLock);
389}
390
391DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockCreate(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
392{
393 return pDeviceExtension->u.primary.VideoPortProcs.pfnCreateSpinLock(pDeviceExtension, SpinLock);
394}
395
396DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
397{
398 return pDeviceExtension->u.primary.VideoPortProcs.pfnDeleteSpinLock(pDeviceExtension, *SpinLock);
399}
400
401DECLINLINE(LONG) VBoxVideoCmnEventSet(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
402{
403 return pDeviceExtension->u.primary.VideoPortProcs.pfnSetEvent(pDeviceExtension, *pEvent);
404}
405
406DECLINLINE(VP_STATUS) VBoxVideoCmnEventCreateNotification(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent, IN BOOLEAN bSignaled)
407{
408 ULONG fFlags = NOTIFICATION_EVENT;
409 if(bSignaled)
410 fFlags |= INITIAL_EVENT_SIGNALED;
411
412 return pDeviceExtension->u.primary.VideoPortProcs.pfnCreateEvent(pDeviceExtension, fFlags, NULL, pEvent);
413}
414
415DECLINLINE(VP_STATUS) VBoxVideoCmnEventDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
416{
417 return pDeviceExtension->u.primary.VideoPortProcs.pfnDeleteEvent(pDeviceExtension, *pEvent);
418}
419
420DECLINLINE(PVOID) VBoxVideoCmnMemAllocNonPaged(IN PDEVICE_EXTENSION pDeviceExtension, IN SIZE_T NumberOfBytes, IN ULONG Tag)
421{
422 return pDeviceExtension->u.primary.VideoPortProcs.pfnAllocatePool(pDeviceExtension, (VBOXVP_POOL_TYPE)VpNonPagedPool, NumberOfBytes, Tag);
423}
424
425DECLINLINE(VOID) VBoxVideoCmnMemFree(IN PDEVICE_EXTENSION pDeviceExtension, IN PVOID Ptr)
426{
427 pDeviceExtension->u.primary.VideoPortProcs.pfnFreePool(pDeviceExtension, Ptr);
428}
429
430DECLINLINE(VP_STATUS) VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg)
431{
432 *pReg = pDeviceExtension->pPrimary;
433 return NO_ERROR;
434}
435
436DECLINLINE(VP_STATUS) VBoxVideoCmnRegFini(IN VBOXCMNREG Reg)
437{
438 return NO_ERROR;
439}
440
441VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal);
442
443VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val);
444
445/* */
446
447RT_C_DECLS_BEGIN
448ULONG DriverEntry(IN PVOID Context1, IN PVOID Context2);
449RT_C_DECLS_END
450
451VP_STATUS VBoxVideoFindAdapter(
452 IN PVOID HwDeviceExtension,
453 IN PVOID HwContext,
454 IN PWSTR ArgumentString,
455 IN OUT PVIDEO_PORT_CONFIG_INFO ConfigInfo,
456 OUT PUCHAR Again);
457
458BOOLEAN VBoxVideoInitialize(PVOID HwDeviceExtension);
459
460BOOLEAN VBoxVideoStartIO(
461 PVOID HwDeviceExtension,
462 PVIDEO_REQUEST_PACKET RequestPacket);
463
464#if defined(VBOX_WITH_HGSMI) && defined(VBOX_WITH_VIDEOHWACCEL)
465BOOLEAN VBoxVideoInterrupt(PVOID HwDeviceExtension);
466#endif
467
468
469BOOLEAN VBoxVideoResetHW(
470 PVOID HwDeviceExtension,
471 ULONG Columns,
472 ULONG Rows);
473
474VP_STATUS VBoxVideoGetPowerState(
475 PVOID HwDeviceExtension,
476 ULONG HwId,
477 PVIDEO_POWER_MANAGEMENT VideoPowerControl);
478
479VP_STATUS VBoxVideoSetPowerState(
480 PVOID HwDeviceExtension,
481 ULONG HwId,
482 PVIDEO_POWER_MANAGEMENT VideoPowerControl);
483
484VP_STATUS VBoxVideoGetChildDescriptor(
485 PVOID HwDeviceExtension,
486 PVIDEO_CHILD_ENUM_INFO ChildEnumInfo,
487 PVIDEO_CHILD_TYPE VideoChildType,
488 PUCHAR pChildDescriptor,
489 PULONG pUId,
490 PULONG pUnused);
491
492
493void VBoxSetupVideoPortFunctions(PDEVICE_EXTENSION PrimaryExtension,
494 VBOXVIDEOPORTPROCS *pCallbacks,
495 PVIDEO_PORT_CONFIG_INFO pConfigInfo);
496
497#else
498
499/* XPDM-WDDM common API */
500DECLINLINE(VOID) VBoxVideoCmnPortWriteUchar(IN PUCHAR Port, IN UCHAR Value)
501{
502 WRITE_PORT_UCHAR(Port,Value);
503}
504
505DECLINLINE(VOID) VBoxVideoCmnPortWriteUshort(IN PUSHORT Port, IN USHORT Value)
506{
507 WRITE_PORT_USHORT(Port,Value);
508}
509
510DECLINLINE(VOID) VBoxVideoCmnPortWriteUlong(IN PULONG Port, IN ULONG Value)
511{
512 WRITE_PORT_ULONG(Port,Value);
513}
514
515DECLINLINE(UCHAR) VBoxVideoCmnPortReadUchar(IN PUCHAR Port)
516{
517 return READ_PORT_UCHAR(Port);
518}
519
520DECLINLINE(USHORT) VBoxVideoCmnPortReadUshort(IN PUSHORT Port)
521{
522 return READ_PORT_USHORT(Port);
523}
524
525DECLINLINE(ULONG) VBoxVideoCmnPortReadUlong(IN PULONG Port)
526{
527 return READ_PORT_ULONG(Port);
528}
529
530DECLINLINE(VOID) VBoxVideoCmnMemZero(PVOID pvMem, ULONG cbMem)
531{
532 memset(pvMem, 0, cbMem);
533}
534
535DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquire(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, OUT PVBOXVCMNIRQL OldIrql)
536{
537 KeAcquireSpinLock(SpinLock, OldIrql);
538}
539
540DECLINLINE(VOID) VBoxVideoCmnSpinLockAcquireAtDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
541{
542 KeAcquireSpinLockAtDpcLevel(SpinLock);
543}
544
545DECLINLINE(VOID) VBoxVideoCmnSpinLockRelease(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock, IN VBOXVCMNIRQL NewIrql)
546{
547 KeReleaseSpinLock(SpinLock, NewIrql);
548}
549
550DECLINLINE(VOID) VBoxVideoCmnSpinLockReleaseFromDpcLevel(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
551{
552 KeReleaseSpinLockFromDpcLevel(SpinLock);
553}
554
555DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockCreate(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
556{
557 KeInitializeSpinLock(SpinLock);
558 return NO_ERROR;
559}
560
561DECLINLINE(VP_STATUS) VBoxVideoCmnSpinLockDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNSPIN_LOCK SpinLock)
562{
563 return NO_ERROR;
564}
565
566DECLINLINE(LONG) VBoxVideoCmnEventSet(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
567{
568 return KeSetEvent(pEvent, 0, FALSE);
569}
570
571DECLINLINE(VP_STATUS) VBoxVideoCmnEventCreateNotification(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent, IN BOOLEAN bSignaled)
572{
573 KeInitializeEvent(pEvent, NotificationEvent, bSignaled);
574 return NO_ERROR;
575}
576
577DECLINLINE(VP_STATUS) VBoxVideoCmnEventDelete(IN PDEVICE_EXTENSION pDeviceExtension, IN PVBOXVCMNEVENT pEvent)
578{
579 return NO_ERROR;
580}
581
582DECLINLINE(PVOID) VBoxVideoCmnMemAllocNonPaged(IN PDEVICE_EXTENSION pDeviceExtension, IN SIZE_T NumberOfBytes, IN ULONG Tag)
583{
584 return ExAllocatePoolWithTag(NonPagedPool, NumberOfBytes, Tag);
585}
586
587DECLINLINE(VOID) VBoxVideoCmnMemFree(IN PDEVICE_EXTENSION pDeviceExtension, IN PVOID Ptr)
588{
589 ExFreePool(Ptr);
590}
591
592VP_STATUS VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg);
593
594DECLINLINE(VP_STATUS) VBoxVideoCmnRegFini(IN VBOXCMNREG Reg)
595{
596 if(!Reg)
597 return ERROR_INVALID_PARAMETER;
598
599 NTSTATUS Status = ZwClose(Reg);
600 return Status == STATUS_SUCCESS ? NO_ERROR : ERROR_INVALID_PARAMETER;
601}
602
603VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal);
604
605VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val);
606
607/* */
608
609RT_C_DECLS_BEGIN
610NTSTATUS
611DriverEntry(
612 IN PDRIVER_OBJECT DriverObject,
613 IN PUNICODE_STRING RegistryPath
614 );
615RT_C_DECLS_END
616
617typedef struct VBOXWDDM_VIDEOMODES
618{
619 VIDEO_MODE_INFORMATION *pModes;
620 uint32_t cModes;
621 D3DKMDT_2DREGION pResolutions;
622 uint32_t cResolutions;
623 int32_t iPreferrableMode;
624 int32_t iCustomMode;
625} VBOXWDDM_VIDEOMODES;
626
627VOID VBoxWddmGetModesTable(PDEVICE_EXTENSION DeviceExtension, bool bRebuildTable,
628 VIDEO_MODE_INFORMATION ** ppModes, uint32_t * pcModes, int32_t * pPreferrableMode,
629 D3DKMDT_2DREGION **ppResolutions, uint32_t * pcResolutions);
630
631VOID VBoxWddmInvalidateModesTable(PDEVICE_EXTENSION DeviceExtension);
632
633/* @return STATUS_BUFFER_TOO_SMALL - if buffer is too small, STATUS_SUCCESS - on success */
634NTSTATUS VBoxWddmGetModesForResolution(PDEVICE_EXTENSION DeviceExtension, bool bRebuildTable,
635 D3DKMDT_2DREGION *pResolution,
636 VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t * piPreferrableMode);
637
638D3DDDIFORMAT vboxWddmCalcPixelFormat(VIDEO_MODE_INFORMATION *pInfo);
639
640DECLINLINE(ULONG) vboxWddmVramCpuVisibleSize(PDEVICE_EXTENSION pDevExt)
641{
642#ifdef VBOXWDDM_RENDER_FROM_SHADOW
643 /* all memory layout info should be initialized */
644 Assert(pDevExt->aSources[0].Vbva.offVBVA);
645 /* page aligned */
646 Assert(!(pDevExt->aSources[0].Vbva.offVBVA & 0xfff));
647
648 return (ULONG)(pDevExt->aSources[0].Vbva.offVBVA & ~0xfffULL);
649#else
650 /* all memory layout info should be initialized */
651 Assert(pDevExt->u.primary.Vdma.CmdHeap.area.offBase);
652 /* page aligned */
653 Assert(!(pDevExt->u.primary.Vdma.CmdHeap.area.offBase & 0xfff));
654
655 return pDevExt->u.primary.Vdma.CmdHeap.area.offBase & ~0xfffUL;
656#endif
657}
658
659DECLINLINE(ULONG) vboxWddmVramCpuVisibleSegmentSize(PDEVICE_EXTENSION pDevExt)
660{
661 return vboxWddmVramCpuVisibleSize(pDevExt);
662}
663
664#ifdef VBOXWDDM_RENDER_FROM_SHADOW
665DECLINLINE(ULONG) vboxWddmVramCpuInvisibleSegmentSize(PDEVICE_EXTENSION pDevExt)
666{
667 return vboxWddmVramCpuVisibleSegmentSize(pDevExt);
668}
669
670DECLINLINE(bool) vboxWddmCmpSurfDescsBase(VBOXWDDM_SURFACE_DESC *pDesc1, VBOXWDDM_SURFACE_DESC *pDesc2)
671{
672 if (pDesc1->width != pDesc2->width)
673 return false;
674 if (pDesc1->height != pDesc2->height)
675 return false;
676 if (pDesc1->format != pDesc2->format)
677 return false;
678 if (pDesc1->bpp != pDesc2->bpp)
679 return false;
680 if (pDesc1->pitch != pDesc2->pitch)
681 return false;
682 return true;
683}
684
685DECLINLINE(void) vboxWddmAssignShadow(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
686{
687 if (pSource->pShadowAllocation == pAllocation)
688 return;
689
690 if (pSource->pShadowAllocation)
691 {
692 PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pShadowAllocation;
693 /* clear the visibility info fo the current primary */
694 pOldAlloc->bVisible = FALSE;
695 pOldAlloc->bAssigned = FALSE;
696 Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
697 /* release the shadow surface */
698 pOldAlloc->SurfDesc.VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
699 }
700
701 if (pAllocation)
702 {
703 pAllocation->bVisible = FALSE;
704 /* this check ensures the shadow is not used for other source simultaneously */
705 Assert(pAllocation->SurfDesc.VidPnSourceId == D3DDDI_ID_UNINITIALIZED);
706 pAllocation->SurfDesc.VidPnSourceId = srcId;
707 pAllocation->bAssigned = TRUE;
708 if (!vboxWddmCmpSurfDescsBase(&pSource->SurfDesc, &pAllocation->SurfDesc))
709 pSource->offVram = VBOXVIDEOOFFSET_VOID; /* force guest->host notification */
710 pSource->SurfDesc = pAllocation->SurfDesc;
711 }
712
713 pSource->pShadowAllocation = pAllocation;
714}
715#endif
716
717DECLINLINE(VOID) vboxWddmAssignPrimary(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
718{
719 if (pSource->pPrimaryAllocation == pAllocation)
720 return;
721
722 if (pSource->pPrimaryAllocation)
723 {
724 PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pPrimaryAllocation;
725 /* clear the visibility info fo the current primary */
726 pOldAlloc->bVisible = FALSE;
727 pOldAlloc->bAssigned = FALSE;
728 Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
729 }
730
731 if (pAllocation)
732 {
733 pAllocation->bVisible = FALSE;
734 Assert(pAllocation->SurfDesc.VidPnSourceId == srcId);
735 pAllocation->SurfDesc.VidPnSourceId = srcId;
736 pAllocation->bAssigned = TRUE;
737 }
738
739 pSource->pPrimaryAllocation = pAllocation;
740}
741
742#endif
743
744void* vboxHGSMIBufferAlloc(PDEVICE_EXTENSION PrimaryExtension,
745 HGSMISIZE cbData,
746 uint8_t u8Ch,
747 uint16_t u16Op);
748void vboxHGSMIBufferFree (PDEVICE_EXTENSION PrimaryExtension, void *pvBuffer);
749int vboxHGSMIBufferSubmit (PDEVICE_EXTENSION PrimaryExtension, void *pvBuffer);
750
751BOOLEAN FASTCALL VBoxVideoSetCurrentModePerform(PDEVICE_EXTENSION DeviceExtension,
752 USHORT width, USHORT height, USHORT bpp
753#ifdef VBOXWDDM
754 , ULONG offDisplay
755#endif
756 );
757
758BOOLEAN FASTCALL VBoxVideoSetCurrentMode(
759 PDEVICE_EXTENSION DeviceExtension,
760 PVIDEO_MODE RequestedMode,
761 PSTATUS_BLOCK StatusBlock);
762
763BOOLEAN FASTCALL VBoxVideoResetDevice(
764 PDEVICE_EXTENSION DeviceExtension,
765 PSTATUS_BLOCK StatusBlock);
766
767BOOLEAN FASTCALL VBoxVideoMapVideoMemory(
768 PDEVICE_EXTENSION DeviceExtension,
769 PVIDEO_MEMORY RequestedAddress,
770 PVIDEO_MEMORY_INFORMATION MapInformation,
771 PSTATUS_BLOCK StatusBlock);
772
773BOOLEAN FASTCALL VBoxVideoUnmapVideoMemory(
774 PDEVICE_EXTENSION DeviceExtension,
775 PVIDEO_MEMORY VideoMemory,
776 PSTATUS_BLOCK StatusBlock);
777
778BOOLEAN FASTCALL VBoxVideoQueryNumAvailModes(
779 PDEVICE_EXTENSION DeviceExtension,
780 PVIDEO_NUM_MODES Modes,
781 PSTATUS_BLOCK StatusBlock);
782
783BOOLEAN FASTCALL VBoxVideoQueryAvailModes(
784 PDEVICE_EXTENSION DeviceExtension,
785 PVIDEO_MODE_INFORMATION ReturnedModes,
786 PSTATUS_BLOCK StatusBlock);
787
788BOOLEAN FASTCALL VBoxVideoQueryCurrentMode(
789 PDEVICE_EXTENSION DeviceExtension,
790 PVIDEO_MODE_INFORMATION VideoModeInfo,
791 PSTATUS_BLOCK StatusBlock);
792
793BOOLEAN FASTCALL VBoxVideoSetColorRegisters(
794 PDEVICE_EXTENSION DeviceExtension,
795 PVIDEO_CLUT ColorLookUpTable,
796 PSTATUS_BLOCK StatusBlock);
797
798int VBoxMapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
799 void **ppv,
800 ULONG ulOffset,
801 ULONG ulSize);
802
803void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
804 void **ppv, ULONG ulSize);
805
806void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension);
807
808#ifdef VBOX_WITH_HGSMI
809
810/*
811 * Host and Guest port IO helpers.
812 */
813DECLINLINE(void) VBoxHGSMIHostWrite(PDEVICE_EXTENSION PrimaryExtension, ULONG data)
814{
815#ifndef VBOXWDDM
816 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortHost, data);
817#else
818 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->u.primary.IOPortHost, data);
819#endif
820}
821
822DECLINLINE(ULONG) VBoxHGSMIHostRead(PDEVICE_EXTENSION PrimaryExtension)
823{
824#ifndef VBOXWDDM
825 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortHost);
826#else
827 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->u.primary.IOPortHost);
828#endif
829}
830
831DECLINLINE(void) VBoxHGSMIGuestWrite(PDEVICE_EXTENSION PrimaryExtension, ULONG data)
832{
833#ifndef VBOXWDDM
834 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortGuest, data);
835#else
836 VBoxVideoCmnPortWriteUlong((PULONG)PrimaryExtension->u.primary.IOPortGuest, data);
837#endif
838}
839
840DECLINLINE(ULONG) VBoxHGSMIGuestRead(PDEVICE_EXTENSION PrimaryExtension)
841{
842#ifndef VBOXWDDM
843 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->pPrimary->u.primary.IOPortGuest);
844#else
845 return VBoxVideoCmnPortReadUlong((PULONG)PrimaryExtension->u.primary.IOPortGuest);
846#endif
847}
848
849BOOLEAN VBoxHGSMIIsSupported (PDEVICE_EXTENSION PrimaryExtension);
850
851VOID VBoxSetupDisplaysHGSMI (PDEVICE_EXTENSION PrimaryExtension,
852#ifndef VBOXWDDM
853 PVIDEO_PORT_CONFIG_INFO pConfigInfo,
854#endif
855 ULONG AdapterMemorySize);
856BOOLEAN vboxUpdatePointerShape (PDEVICE_EXTENSION DeviceExtension,
857 PVIDEO_POINTER_ATTRIBUTES pointerAttr,
858 uint32_t cbLength);
859
860#ifdef VBOXWDDM
861int VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension);
862#else
863DECLCALLBACK(void) hgsmiHostCmdComplete (HVBOXVIDEOHGSMI hHGSMI, struct _VBVAHOSTCMD * pCmd);
864DECLCALLBACK(int) hgsmiHostCmdRequest (HVBOXVIDEOHGSMI hHGSMI, uint8_t u8Channel, struct _VBVAHOSTCMD ** ppCmd);
865#endif
866
867
868int vboxVBVAChannelDisplayEnable(PDEVICE_EXTENSION PrimaryExtension,
869 int iDisplay, /* negative would mean this is a miniport handler */
870 uint8_t u8Channel);
871
872VOID VBoxVideoHGSMIDpc(
873 IN PVOID HwDeviceExtension,
874 IN PVOID Context
875 );
876
877void HGSMIClearIrq (PDEVICE_EXTENSION PrimaryExtension);
878
879#endif /* VBOX_WITH_HGSMI */
880} /* extern "C" */
881
882#endif /* VBOXVIDEO_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette