VirtualBox

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

Last change on this file since 30308 was 30226, checked in by vboxsync, 15 years ago

VBoxVideo.h: VBOXPEVENT casts for VCC100, needs checking as they seem slightly bogus to me.

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