VirtualBox

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

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

wddm/2D: more impl & fixes

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

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