1 | /*
|
---|
2 | * Copyright (C) 2010 Oracle Corporation
|
---|
3 | *
|
---|
4 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
5 | * available from http://www.virtualbox.org. This file is free software;
|
---|
6 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
7 | * General Public License (GPL) as published by the Free Software
|
---|
8 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
9 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
10 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
11 | */
|
---|
12 | #ifndef ___VBoxVideoVdma_h___
|
---|
13 | #define ___VBoxVideoVdma_h___
|
---|
14 |
|
---|
15 | #include <iprt/cdefs.h>
|
---|
16 | #include <iprt/asm.h>
|
---|
17 | #include <VBox/VBoxVideo.h>
|
---|
18 | #include "../VBoxVideo.h"
|
---|
19 |
|
---|
20 | /* ddi dma command queue handling */
|
---|
21 | typedef enum
|
---|
22 | {
|
---|
23 | VBOXVDMADDI_STATE_UNCKNOWN = 0,
|
---|
24 | VBOXVDMADDI_STATE_NOT_QUEUED,
|
---|
25 | VBOXVDMADDI_STATE_PENDING,
|
---|
26 | VBOXVDMADDI_STATE_SUBMITTED,
|
---|
27 | VBOXVDMADDI_STATE_COMPLETED
|
---|
28 | } VBOXVDMADDI_STATE;
|
---|
29 |
|
---|
30 | typedef struct VBOXVDMADDI_CMD *PVBOXVDMADDI_CMD;
|
---|
31 | typedef DECLCALLBACK(VOID) FNVBOXVDMADDICMDCOMPLETE_DPC(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext);
|
---|
32 | typedef FNVBOXVDMADDICMDCOMPLETE_DPC *PFNVBOXVDMADDICMDCOMPLETE_DPC;
|
---|
33 |
|
---|
34 | typedef struct VBOXVDMADDI_CMD
|
---|
35 | {
|
---|
36 | LIST_ENTRY QueueEntry;
|
---|
37 | VBOXVDMADDI_STATE enmState;
|
---|
38 | uint32_t u32FenceId;
|
---|
39 | DXGK_INTERRUPT_TYPE enmComplType;
|
---|
40 | PVBOXWDDM_CONTEXT pContext;
|
---|
41 | PFNVBOXVDMADDICMDCOMPLETE_DPC pfnComplete;
|
---|
42 | PVOID pvComplete;
|
---|
43 | } VBOXVDMADDI_CMD, *PVBOXVDMADDI_CMD;
|
---|
44 |
|
---|
45 | typedef struct VBOXVDMADDI_CMD_QUEUE
|
---|
46 | {
|
---|
47 | volatile uint32_t cQueuedCmds;
|
---|
48 | LIST_ENTRY CmdQueue;
|
---|
49 | LIST_ENTRY DpcCmdQueue;
|
---|
50 | } VBOXVDMADDI_CMD_QUEUE, *PVBOXVDMADDI_CMD_QUEUE;
|
---|
51 |
|
---|
52 | VOID vboxVdmaDdiQueueInit(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue);
|
---|
53 | BOOLEAN vboxVdmaDdiCmdCompletedIrq(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd, DXGK_INTERRUPT_TYPE enmComplType);
|
---|
54 | VOID vboxVdmaDdiCmdSubmittedIrq(PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd);
|
---|
55 |
|
---|
56 | NTSTATUS vboxVdmaDdiCmdCompleted(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd, DXGK_INTERRUPT_TYPE enmComplType);
|
---|
57 | NTSTATUS vboxVdmaDdiCmdSubmitted(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd);
|
---|
58 |
|
---|
59 | DECLINLINE(VOID) vboxVdmaDdiCmdInit(PVBOXVDMADDI_CMD pCmd,
|
---|
60 | uint32_t u32FenceId, PVBOXWDDM_CONTEXT pContext,
|
---|
61 | PFNVBOXVDMADDICMDCOMPLETE_DPC pfnComplete, PVOID pvComplete)
|
---|
62 | {
|
---|
63 | pCmd->QueueEntry.Blink = NULL;
|
---|
64 | pCmd->QueueEntry.Flink = NULL;
|
---|
65 | pCmd->enmState = VBOXVDMADDI_STATE_NOT_QUEUED;
|
---|
66 | pCmd->u32FenceId = u32FenceId;
|
---|
67 | pCmd->pContext = pContext;
|
---|
68 | pCmd->pfnComplete = pfnComplete;
|
---|
69 | pCmd->pvComplete = pvComplete;
|
---|
70 | }
|
---|
71 |
|
---|
72 | NTSTATUS vboxVdmaDdiCmdFenceComplete(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, uint32_t u32FenceId, DXGK_INTERRUPT_TYPE enmComplType);
|
---|
73 |
|
---|
74 | DECLCALLBACK(VOID) vboxVdmaDdiCmdCompletionCbFree(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext);
|
---|
75 |
|
---|
76 | DECLINLINE(VOID) vboxVdmaDdiCmdGetCompletedListIsr(PVBOXVDMADDI_CMD_QUEUE pQueue, LIST_ENTRY *pList)
|
---|
77 | {
|
---|
78 | vboxVideoLeDetach(&pQueue->DpcCmdQueue, pList);
|
---|
79 | }
|
---|
80 |
|
---|
81 | DECLINLINE(BOOLEAN) vboxVdmaDdiCmdIsCompletedListEmptyIsr(PVBOXVDMADDI_CMD_QUEUE pQueue)
|
---|
82 | {
|
---|
83 | return IsListEmpty(&pQueue->DpcCmdQueue);
|
---|
84 | }
|
---|
85 |
|
---|
86 | #define VBOXVDMADDI_CMD_FROM_ENTRY(_pEntry) ((PVBOXVDMADDI_CMD)(((uint8_t*)(_pEntry)) - RT_OFFSETOF(VBOXVDMADDI_CMD, QueueEntry)))
|
---|
87 |
|
---|
88 | DECLINLINE(VOID) vboxVdmaDdiCmdHandleCompletedList(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, LIST_ENTRY *pList)
|
---|
89 | {
|
---|
90 | LIST_ENTRY *pEntry = pList->Flink;
|
---|
91 | while (pEntry != pList)
|
---|
92 | {
|
---|
93 | PVBOXVDMADDI_CMD pCmd = VBOXVDMADDI_CMD_FROM_ENTRY(pEntry);
|
---|
94 | pEntry = pEntry->Flink;
|
---|
95 | if (pCmd->pfnComplete)
|
---|
96 | pCmd->pfnComplete(pDevExt, pCmd, pCmd->pvComplete);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | #ifdef VBOXWDDM_RENDER_FROM_SHADOW
|
---|
101 | NTSTATUS vboxVdmaHlpUpdatePrimary(PDEVICE_EXTENSION pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, RECT* pRect);
|
---|
102 | #endif
|
---|
103 |
|
---|
104 | #if 0
|
---|
105 | typedef DECLCALLBACK(int) FNVBOXVDMASUBMIT(struct _DEVICE_EXTENSION* pDevExt, struct VBOXVDMAINFO * pInfo, HGSMIOFFSET offDr, PVOID pvContext);
|
---|
106 | typedef FNVBOXVDMASUBMIT *PFNVBOXVDMASUBMIT;
|
---|
107 |
|
---|
108 | typedef struct VBOXVDMASUBMIT
|
---|
109 | {
|
---|
110 | PFNVBOXVDMASUBMIT pfnSubmit;
|
---|
111 | PVOID pvContext;
|
---|
112 | } VBOXVDMASUBMIT, *PVBOXVDMASUBMIT;
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | /* start */
|
---|
116 | typedef enum
|
---|
117 | {
|
---|
118 | VBOXVDMAPIPE_STATE_CLOSED = 0,
|
---|
119 | VBOXVDMAPIPE_STATE_CREATED = 1,
|
---|
120 | VBOXVDMAPIPE_STATE_OPENNED = 2,
|
---|
121 | VBOXVDMAPIPE_STATE_CLOSING = 3
|
---|
122 | } VBOXVDMAPIPE_STATE;
|
---|
123 |
|
---|
124 | typedef struct VBOXVDMAPIPE
|
---|
125 | {
|
---|
126 | KSPIN_LOCK SinchLock;
|
---|
127 | KEVENT Event;
|
---|
128 | LIST_ENTRY CmdListHead;
|
---|
129 | VBOXVDMAPIPE_STATE enmState;
|
---|
130 | /* true iff the other end needs Event notification */
|
---|
131 | bool bNeedNotify;
|
---|
132 | } VBOXVDMAPIPE, *PVBOXVDMAPIPE;
|
---|
133 |
|
---|
134 | typedef struct VBOXVDMAPIPE_CMD_HDR
|
---|
135 | {
|
---|
136 | LIST_ENTRY ListEntry;
|
---|
137 | } VBOXVDMAPIPE_CMD_HDR, *PVBOXVDMAPIPE_CMD_HDR;
|
---|
138 |
|
---|
139 | #define VBOXVDMAPIPE_CMD_HDR_FROM_ENTRY(_pE) ( (PVBOXVDMAPIPE_CMD_HDR)((uint8_t *)(_pE) - RT_OFFSETOF(VBOXVDMAPIPE_CMD_HDR, ListEntry)) )
|
---|
140 |
|
---|
141 | typedef enum
|
---|
142 | {
|
---|
143 | VBOXVDMAPIPE_CMD_TYPE_UNDEFINED = 0,
|
---|
144 | VBOXVDMAPIPE_CMD_TYPE_RECTSINFO,
|
---|
145 | VBOXVDMAPIPE_CMD_TYPE_DMACMD
|
---|
146 | } VBOXVDMAPIPE_CMD_TYPE;
|
---|
147 |
|
---|
148 | typedef struct VBOXVDMAPIPE_CMD_DR
|
---|
149 | {
|
---|
150 | VBOXVDMAPIPE_CMD_HDR PipeHdr;
|
---|
151 | VBOXVDMAPIPE_CMD_TYPE enmType;
|
---|
152 | } VBOXVDMAPIPE_CMD_DR, *PVBOXVDMAPIPE_CMD_DR;
|
---|
153 |
|
---|
154 | #define VBOXVDMAPIPE_CMD_DR_FROM_ENTRY(_pE) ( (PVBOXVDMAPIPE_CMD_DR)VBOXVDMAPIPE_CMD_HDR_FROM_ENTRY(_pE) )
|
---|
155 |
|
---|
156 | typedef struct VBOXWDDM_DMA_ALLOCINFO
|
---|
157 | {
|
---|
158 | PVBOXWDDM_ALLOCATION pAlloc;
|
---|
159 | VBOXVIDEOOFFSET offAlloc;
|
---|
160 | UINT segmentIdAlloc;
|
---|
161 | D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId;
|
---|
162 | } VBOXWDDM_DMA_ALLOCINFO, *PVBOXWDDM_DMA_ALLOCINFO;
|
---|
163 |
|
---|
164 | typedef struct VBOXVDMAPIPE_RECTS
|
---|
165 | {
|
---|
166 | RECT ContextRect;
|
---|
167 | VBOXWDDM_RECTS_INFO UpdateRects;
|
---|
168 | } VBOXVDMAPIPE_RECTS, *PVBOXVDMAPIPE_RECTS;
|
---|
169 |
|
---|
170 | typedef struct VBOXVDMAPIPE_CMD_RECTSINFO
|
---|
171 | {
|
---|
172 | VBOXVDMAPIPE_CMD_DR Hdr;
|
---|
173 | VBOXVDMADDI_CMD DdiCmd;
|
---|
174 | struct VBOXWDDM_SWAPCHAIN *pSwapchain;
|
---|
175 | VBOXVDMAPIPE_RECTS ContextsRects;
|
---|
176 | } VBOXVDMAPIPE_CMD_RECTSINFO, *PVBOXVDMAPIPE_CMD_RECTSINFO;
|
---|
177 |
|
---|
178 | typedef struct VBOXVDMAPIPE_FLAGS_DMACMD
|
---|
179 | {
|
---|
180 | union
|
---|
181 | {
|
---|
182 | struct
|
---|
183 | {
|
---|
184 | UINT b2DRelated : 1;
|
---|
185 | UINT b3DRelated : 1;
|
---|
186 | UINT bDecVBVAUnlock : 1;
|
---|
187 | UINT Reserved : 29;
|
---|
188 | };
|
---|
189 | UINT Value;
|
---|
190 | };
|
---|
191 | } VBOXVDMAPIPE_FLAGS_DMACMD, *PVBOXVDMAPIPE_FLAGS_DMACMD;
|
---|
192 | typedef struct VBOXVDMAPIPE_CMD_DMACMD
|
---|
193 | {
|
---|
194 | VBOXVDMAPIPE_CMD_DR Hdr;
|
---|
195 | VBOXVDMADDI_CMD DdiCmd;
|
---|
196 | PDEVICE_EXTENSION pDevExt;
|
---|
197 | VBOXVDMACMD_TYPE enmCmd;
|
---|
198 | VBOXVDMAPIPE_FLAGS_DMACMD fFlags;
|
---|
199 | } VBOXVDMAPIPE_CMD_DMACMD, *PVBOXVDMAPIPE_CMD_DMACMD;
|
---|
200 |
|
---|
201 | typedef struct VBOXVDMA_CLRFILL
|
---|
202 | {
|
---|
203 | VBOXWDDM_DMA_ALLOCINFO Alloc;
|
---|
204 | UINT Color;
|
---|
205 | VBOXWDDM_RECTS_INFO Rects;
|
---|
206 | } VBOXVDMA_CLRFILL, *PVBOXVDMA_CLRFILL;
|
---|
207 |
|
---|
208 | typedef struct VBOXVDMAPIPE_CMD_DMACMD_CLRFILL
|
---|
209 | {
|
---|
210 | VBOXVDMAPIPE_CMD_DMACMD Hdr;
|
---|
211 | VBOXVDMA_CLRFILL ClrFill;
|
---|
212 | } VBOXVDMAPIPE_CMD_DMACMD_CLRFILL, *PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL;
|
---|
213 |
|
---|
214 | typedef struct VBOXVDMA_BLT
|
---|
215 | {
|
---|
216 | VBOXWDDM_DMA_ALLOCINFO SrcAlloc;
|
---|
217 | VBOXWDDM_DMA_ALLOCINFO DstAlloc;
|
---|
218 | RECT SrcRect;
|
---|
219 | VBOXVDMAPIPE_RECTS DstRects;
|
---|
220 | } VBOXVDMA_BLT, *PVBOXVDMA_BLT;
|
---|
221 |
|
---|
222 | typedef struct VBOXVDMAPIPE_CMD_DMACMD_BLT
|
---|
223 | {
|
---|
224 | VBOXVDMAPIPE_CMD_DMACMD Hdr;
|
---|
225 | VBOXVDMA_BLT Blt;
|
---|
226 | } VBOXVDMAPIPE_CMD_DMACMD_BLT, *PVBOXVDMAPIPE_CMD_DMACMD_BLT;
|
---|
227 |
|
---|
228 | typedef struct VBOXVDMA_FLIP
|
---|
229 | {
|
---|
230 | VBOXWDDM_DMA_ALLOCINFO Alloc;
|
---|
231 | } VBOXVDMA_FLIP, *PVBOXVDMA_FLIP;
|
---|
232 |
|
---|
233 | typedef struct VBOXVDMAPIPE_CMD_DMACMD_FLIP
|
---|
234 | {
|
---|
235 | VBOXVDMAPIPE_CMD_DMACMD Hdr;
|
---|
236 | VBOXVDMA_FLIP Flip;
|
---|
237 | } VBOXVDMAPIPE_CMD_DMACMD_FLIP, *PVBOXVDMAPIPE_CMD_DMACMD_FLIP;
|
---|
238 |
|
---|
239 | typedef struct VBOXVDMA_SHADOW2PRIMARY
|
---|
240 | {
|
---|
241 | VBOXWDDM_DMA_ALLOCINFO ShadowAlloc;
|
---|
242 | RECT SrcRect;
|
---|
243 | D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
|
---|
244 | } VBOXVDMA_SHADOW2PRIMARY, *PVBOXVDMA_SHADOW2PRIMARY;
|
---|
245 |
|
---|
246 | typedef struct VBOXVDMAGG
|
---|
247 | {
|
---|
248 | VBOXVDMAPIPE CmdPipe;
|
---|
249 | PKTHREAD pThread;
|
---|
250 | } VBOXVDMAGG, *PVBOXVDMAGG;
|
---|
251 |
|
---|
252 | /* DMA commands are currently submitted over HGSMI */
|
---|
253 | typedef struct VBOXVDMAINFO
|
---|
254 | {
|
---|
255 | #ifdef VBOX_WITH_VDMA
|
---|
256 | HGSMIHEAP CmdHeap;
|
---|
257 | #endif
|
---|
258 | UINT uLastCompletedPagingBufferCmdFenceId;
|
---|
259 | BOOL fEnabled;
|
---|
260 | #if 0
|
---|
261 | VBOXVDMASUBMIT Submitter;
|
---|
262 | #endif
|
---|
263 | /* dma-related commands list processed on the guest w/o host part involvement (guest-guest commands) */
|
---|
264 | VBOXVDMAGG DmaGg;
|
---|
265 | } VBOXVDMAINFO, *PVBOXVDMAINFO;
|
---|
266 |
|
---|
267 | int vboxVdmaCreate (struct _DEVICE_EXTENSION* pDevExt, VBOXVDMAINFO *pInfo
|
---|
268 | #ifdef VBOX_WITH_VDMA
|
---|
269 | , ULONG offBuffer, ULONG cbBuffer
|
---|
270 | #endif
|
---|
271 | #if 0
|
---|
272 | , PFNVBOXVDMASUBMIT pfnSubmit, PVOID pvContext
|
---|
273 | #endif
|
---|
274 | );
|
---|
275 | int vboxVdmaDisable (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo);
|
---|
276 | int vboxVdmaEnable (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo);
|
---|
277 | int vboxVdmaDestroy (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo);
|
---|
278 |
|
---|
279 | #ifdef VBOX_WITH_VDMA
|
---|
280 | int vboxVdmaFlush (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo);
|
---|
281 | int vboxVdmaCBufDrSubmit (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo, PVBOXVDMACBUF_DR pDr);
|
---|
282 | int vboxVdmaCBufDrSubmitSynch (PDEVICE_EXTENSION pDevExt, PVBOXVDMAINFO pInfo, PVBOXVDMACBUF_DR pDr);
|
---|
283 | struct VBOXVDMACBUF_DR* vboxVdmaCBufDrCreate (PVBOXVDMAINFO pInfo, uint32_t cbTrailingData);
|
---|
284 | void vboxVdmaCBufDrFree (PVBOXVDMAINFO pInfo, struct VBOXVDMACBUF_DR* pDr);
|
---|
285 |
|
---|
286 | #define VBOXVDMACBUF_DR_DATA_OFFSET() (sizeof (VBOXVDMACBUF_DR))
|
---|
287 | #define VBOXVDMACBUF_DR_SIZE(_cbData) (VBOXVDMACBUF_DR_DATA_OFFSET() + (_cbData))
|
---|
288 | #define VBOXVDMACBUF_DR_DATA(_pDr) ( ((uint8_t*)(_pDr)) + VBOXVDMACBUF_DR_DATA_OFFSET() )
|
---|
289 |
|
---|
290 | AssertCompile(sizeof (VBOXVDMADDI_CMD) <= RT_SIZEOFMEMB(VBOXVDMACBUF_DR, aGuestData));
|
---|
291 | #define VBOXVDMADDI_CMD_FROM_BUF_DR(_pDr) ((PVBOXVDMADDI_CMD)(_pDr)->aGuestData)
|
---|
292 | #define VBOXVDMACBUF_DR_FROM_DDI_CMD(_pCmd) ((PVBOXVDMACBUF_DR)(((uint_8*)(_pCmd)) - RT_OFFSETOF(VBOXVDMACBUF_DR, aGuestData)))
|
---|
293 |
|
---|
294 | #endif
|
---|
295 | NTSTATUS vboxVdmaGgCmdSubmit(PVBOXVDMAGG pVdma, PVBOXVDMAPIPE_CMD_DR pCmd);
|
---|
296 | PVBOXVDMAPIPE_CMD_DR vboxVdmaGgCmdCreate(PVBOXVDMAGG pVdma, VBOXVDMAPIPE_CMD_TYPE enmType, uint32_t cbCmd);
|
---|
297 | void vboxVdmaGgCmdDestroy(PVBOXVDMAPIPE_CMD_DR pDr);
|
---|
298 |
|
---|
299 | #define VBOXVDMAPIPE_CMD_DR_FROM_DDI_CMD(_pCmd) ((PVBOXVDMAPIPE_CMD_DR)(((uint8_t*)(_pCmd)) - RT_OFFSETOF(VBOXVDMAPIPE_CMD_DR, DdiCmd)))
|
---|
300 | DECLCALLBACK(VOID) vboxVdmaGgDdiCmdDestroy(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext);
|
---|
301 | #endif /* #ifndef ___VBoxVideoVdma_h___ */
|
---|