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 | PVBOXWDDM_CONTEXT pContext;
|
---|
40 | PFNVBOXVDMADDICMDCOMPLETE_DPC pfnComplete;
|
---|
41 | PVOID pvComplete;
|
---|
42 | } VBOXVDMADDI_CMD, *PVBOXVDMADDI_CMD;
|
---|
43 |
|
---|
44 | typedef struct VBOXVDMADDI_CMD_QUEUE
|
---|
45 | {
|
---|
46 | volatile uint32_t cQueuedCmds;
|
---|
47 | LIST_ENTRY CmdQueue;
|
---|
48 | LIST_ENTRY DpcCmdQueue;
|
---|
49 | } VBOXVDMADDI_CMD_QUEUE, *PVBOXVDMADDI_CMD_QUEUE;
|
---|
50 |
|
---|
51 | VOID vboxVdmaDdiQueueInit(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue);
|
---|
52 | BOOLEAN vboxVdmaDdiCmdCompletedIrq(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd);
|
---|
53 | VOID vboxVdmaDdiCmdSubmittedIrq(PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd);
|
---|
54 |
|
---|
55 | NTSTATUS vboxVdmaDdiCmdCompleted(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd);
|
---|
56 | NTSTATUS vboxVdmaDdiCmdSubmitted(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, PVBOXVDMADDI_CMD pCmd);
|
---|
57 |
|
---|
58 | DECLINLINE(VOID) vboxVdmaDdiCmdInit(PVBOXVDMADDI_CMD pCmd,
|
---|
59 | uint32_t u32FenceId, PVBOXWDDM_CONTEXT pContext,
|
---|
60 | PFNVBOXVDMADDICMDCOMPLETE_DPC pfnComplete, PVOID pvComplete)
|
---|
61 | {
|
---|
62 | pCmd->QueueEntry.Blink = NULL;
|
---|
63 | pCmd->QueueEntry.Flink = NULL;
|
---|
64 | pCmd->enmState = VBOXVDMADDI_STATE_NOT_QUEUED;
|
---|
65 | pCmd->u32FenceId = u32FenceId;
|
---|
66 | pCmd->pContext = pContext;
|
---|
67 | pCmd->pfnComplete = pfnComplete;
|
---|
68 | pCmd->pvComplete = pvComplete;
|
---|
69 | }
|
---|
70 |
|
---|
71 | NTSTATUS vboxVdmaDdiCmdFenceComplete(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, uint32_t u32FenceId);
|
---|
72 |
|
---|
73 | DECLCALLBACK(VOID) vboxVdmaDdiCmdCompletionCbFree(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext);
|
---|
74 |
|
---|
75 | DECLINLINE(VOID) vboxVdmaDdiCmdGetCompletedListIsr(PVBOXVDMADDI_CMD_QUEUE pQueue, LIST_ENTRY *pList)
|
---|
76 | {
|
---|
77 | vboxVideoLeDetach(&pQueue->DpcCmdQueue, pList);
|
---|
78 | }
|
---|
79 |
|
---|
80 | #define VBOXVDMADDI_CMD_FROM_ENTRY(_pEntry) ((PVBOXVDMADDI_CMD)(((uint8_t*)(_pEntry)) - RT_OFFSETOF(VBOXVDMADDI_CMD, QueueEntry)))
|
---|
81 |
|
---|
82 | DECLINLINE(VOID) vboxVdmaDdiCmdHandleCompletedList(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD_QUEUE pQueue, LIST_ENTRY *pList)
|
---|
83 | {
|
---|
84 | LIST_ENTRY *pEntry = pList->Flink;
|
---|
85 | while (pEntry != pList)
|
---|
86 | {
|
---|
87 | PVBOXVDMADDI_CMD pCmd = VBOXVDMADDI_CMD_FROM_ENTRY(pEntry);
|
---|
88 | pEntry = pEntry->Flink;
|
---|
89 | if (pCmd->pfnComplete)
|
---|
90 | pCmd->pfnComplete(pDevExt, pCmd, pCmd->pvComplete);
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | #ifdef VBOXWDDM_RENDER_FROM_SHADOW
|
---|
95 | NTSTATUS vboxVdmaHlpUpdatePrimary(PDEVICE_EXTENSION pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, RECT* pRect);
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | #if 0
|
---|
99 | typedef DECLCALLBACK(int) FNVBOXVDMASUBMIT(struct _DEVICE_EXTENSION* pDevExt, struct VBOXVDMAINFO * pInfo, HGSMIOFFSET offDr, PVOID pvContext);
|
---|
100 | typedef FNVBOXVDMASUBMIT *PFNVBOXVDMASUBMIT;
|
---|
101 |
|
---|
102 | typedef struct VBOXVDMASUBMIT
|
---|
103 | {
|
---|
104 | PFNVBOXVDMASUBMIT pfnSubmit;
|
---|
105 | PVOID pvContext;
|
---|
106 | } VBOXVDMASUBMIT, *PVBOXVDMASUBMIT;
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | /* start */
|
---|
110 | typedef enum
|
---|
111 | {
|
---|
112 | VBOXVDMAPIPE_STATE_CLOSED = 0,
|
---|
113 | VBOXVDMAPIPE_STATE_CREATED = 1,
|
---|
114 | VBOXVDMAPIPE_STATE_OPENNED = 2,
|
---|
115 | VBOXVDMAPIPE_STATE_CLOSING = 3
|
---|
116 | } VBOXVDMAPIPE_STATE;
|
---|
117 |
|
---|
118 | typedef struct VBOXVDMAPIPE
|
---|
119 | {
|
---|
120 | KSPIN_LOCK SinchLock;
|
---|
121 | KEVENT Event;
|
---|
122 | LIST_ENTRY CmdListHead;
|
---|
123 | VBOXVDMAPIPE_STATE enmState;
|
---|
124 | /* true iff the other end needs Event notification */
|
---|
125 | bool bNeedNotify;
|
---|
126 | } VBOXVDMAPIPE, *PVBOXVDMAPIPE;
|
---|
127 |
|
---|
128 | typedef struct VBOXVDMAPIPE_CMD_HDR
|
---|
129 | {
|
---|
130 | LIST_ENTRY ListEntry;
|
---|
131 | } VBOXVDMAPIPE_CMD_HDR, *PVBOXVDMAPIPE_CMD_HDR;
|
---|
132 |
|
---|
133 | #define VBOXVDMAPIPE_CMD_HDR_FROM_ENTRY(_pE) ( (PVBOXVDMAPIPE_CMD_HDR)((uint8_t *)(_pE) - RT_OFFSETOF(VBOXVDMAPIPE_CMD_HDR, ListEntry)) )
|
---|
134 |
|
---|
135 | typedef enum
|
---|
136 | {
|
---|
137 | VBOXVDMAPIPE_CMD_TYPE_UNDEFINED = 0,
|
---|
138 | VBOXVDMAPIPE_CMD_TYPE_RECTSINFO,
|
---|
139 | VBOXVDMAPIPE_CMD_TYPE_DMACMD
|
---|
140 | } VBOXVDMAPIPE_CMD_TYPE;
|
---|
141 |
|
---|
142 | typedef struct VBOXVDMAPIPE_CMD_DR
|
---|
143 | {
|
---|
144 | VBOXVDMAPIPE_CMD_HDR PipeHdr;
|
---|
145 | VBOXVDMAPIPE_CMD_TYPE enmType;
|
---|
146 | } VBOXVDMAPIPE_CMD_DR, *PVBOXVDMAPIPE_CMD_DR;
|
---|
147 |
|
---|
148 | #define VBOXVDMAPIPE_CMD_DR_FROM_ENTRY(_pE) ( (PVBOXVDMAPIPE_CMD_DR)VBOXVDMAPIPE_CMD_HDR_FROM_ENTRY(_pE) )
|
---|
149 |
|
---|
150 | typedef struct VBOXWDDM_DMA_ALLOCINFO
|
---|
151 | {
|
---|
152 | PVBOXWDDM_ALLOCATION pAlloc;
|
---|
153 | VBOXVIDEOOFFSET offAlloc;
|
---|
154 | UINT segmentIdAlloc;
|
---|
155 | D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId;
|
---|
156 | } VBOXWDDM_DMA_ALLOCINFO, *PVBOXWDDM_DMA_ALLOCINFO;
|
---|
157 |
|
---|
158 | typedef struct VBOXVDMAPIPE_RECTS
|
---|
159 | {
|
---|
160 | RECT ContextRect;
|
---|
161 | VBOXWDDM_RECTS_INFO UpdateRects;
|
---|
162 | } VBOXVDMAPIPE_RECTS, *PVBOXVDMAPIPE_RECTS;
|
---|
163 |
|
---|
164 | typedef struct VBOXVDMAPIPE_CMD_RECTSINFO
|
---|
165 | {
|
---|
166 | VBOXVDMAPIPE_CMD_DR Hdr;
|
---|
167 | VBOXVDMADDI_CMD DdiCmd;
|
---|
168 | struct VBOXWDDM_SWAPCHAIN *pSwapchain;
|
---|
169 | VBOXVDMAPIPE_RECTS ContextsRects;
|
---|
170 | } VBOXVDMAPIPE_CMD_RECTSINFO, *PVBOXVDMAPIPE_CMD_RECTSINFO;
|
---|
171 |
|
---|
172 | typedef struct VBOXVDMAPIPE_FLAGS_DMACMD
|
---|
173 | {
|
---|
174 | union
|
---|
175 | {
|
---|
176 | struct
|
---|
177 | {
|
---|
178 | UINT b2DRelated : 1;
|
---|
179 | UINT b3DRelated : 1;
|
---|
180 | UINT bDecVBVAUnlock : 1;
|
---|
181 | UINT Reserved : 29;
|
---|
182 | };
|
---|
183 | UINT Value;
|
---|
184 | };
|
---|
185 | } VBOXVDMAPIPE_FLAGS_DMACMD, *PVBOXVDMAPIPE_FLAGS_DMACMD;
|
---|
186 | typedef struct VBOXVDMAPIPE_CMD_DMACMD
|
---|
187 | {
|
---|
188 | VBOXVDMAPIPE_CMD_DR Hdr;
|
---|
189 | VBOXVDMADDI_CMD DdiCmd;
|
---|
190 | PDEVICE_EXTENSION pDevExt;
|
---|
191 | VBOXVDMACMD_TYPE enmCmd;
|
---|
192 | VBOXVDMAPIPE_FLAGS_DMACMD fFlags;
|
---|
193 | } VBOXVDMAPIPE_CMD_DMACMD, *PVBOXVDMAPIPE_CMD_DMACMD;
|
---|
194 |
|
---|
195 | typedef struct VBOXVDMA_CLRFILL
|
---|
196 | {
|
---|
197 | VBOXWDDM_DMA_ALLOCINFO Alloc;
|
---|
198 | UINT Color;
|
---|
199 | VBOXWDDM_RECTS_INFO Rects;
|
---|
200 | } VBOXVDMA_CLRFILL, *PVBOXVDMA_CLRFILL;
|
---|
201 |
|
---|
202 | typedef struct VBOXVDMAPIPE_CMD_DMACMD_CLRFILL
|
---|
203 | {
|
---|
204 | VBOXVDMAPIPE_CMD_DMACMD Hdr;
|
---|
205 | VBOXVDMA_CLRFILL ClrFill;
|
---|
206 | } VBOXVDMAPIPE_CMD_DMACMD_CLRFILL, *PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL;
|
---|
207 |
|
---|
208 | typedef struct VBOXVDMA_BLT
|
---|
209 | {
|
---|
210 | VBOXWDDM_DMA_ALLOCINFO SrcAlloc;
|
---|
211 | VBOXWDDM_DMA_ALLOCINFO DstAlloc;
|
---|
212 | RECT SrcRect;
|
---|
213 | VBOXVDMAPIPE_RECTS DstRects;
|
---|
214 | } VBOXVDMA_BLT, *PVBOXVDMA_BLT;
|
---|
215 |
|
---|
216 | typedef struct VBOXVDMAPIPE_CMD_DMACMD_BLT
|
---|
217 | {
|
---|
218 | VBOXVDMAPIPE_CMD_DMACMD Hdr;
|
---|
219 | VBOXVDMA_BLT Blt;
|
---|
220 | } VBOXVDMAPIPE_CMD_DMACMD_BLT, *PVBOXVDMAPIPE_CMD_DMACMD_BLT;
|
---|
221 |
|
---|
222 | typedef struct VBOXVDMA_FLIP
|
---|
223 | {
|
---|
224 | VBOXWDDM_DMA_ALLOCINFO Alloc;
|
---|
225 | } VBOXVDMA_FLIP, *PVBOXVDMA_FLIP;
|
---|
226 |
|
---|
227 | typedef struct VBOXVDMAPIPE_CMD_DMACMD_FLIP
|
---|
228 | {
|
---|
229 | VBOXVDMAPIPE_CMD_DMACMD Hdr;
|
---|
230 | VBOXVDMA_FLIP Flip;
|
---|
231 | } VBOXVDMAPIPE_CMD_DMACMD_FLIP, *PVBOXVDMAPIPE_CMD_DMACMD_FLIP;
|
---|
232 |
|
---|
233 | typedef struct VBOXVDMA_SHADOW2PRIMARY
|
---|
234 | {
|
---|
235 | VBOXWDDM_DMA_ALLOCINFO ShadowAlloc;
|
---|
236 | RECT SrcRect;
|
---|
237 | D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
|
---|
238 | } VBOXVDMA_SHADOW2PRIMARY, *PVBOXVDMA_SHADOW2PRIMARY;
|
---|
239 |
|
---|
240 | typedef struct VBOXVDMAGG
|
---|
241 | {
|
---|
242 | VBOXVDMAPIPE CmdPipe;
|
---|
243 | PKTHREAD pThread;
|
---|
244 | } VBOXVDMAGG, *PVBOXVDMAGG;
|
---|
245 |
|
---|
246 | /* DMA commands are currently submitted over HGSMI */
|
---|
247 | typedef struct VBOXVDMAINFO
|
---|
248 | {
|
---|
249 | #ifdef VBOXVDMA
|
---|
250 | HGSMIHEAP CmdHeap;
|
---|
251 | #endif
|
---|
252 | UINT uLastCompletedPagingBufferCmdFenceId;
|
---|
253 | BOOL fEnabled;
|
---|
254 | #if 0
|
---|
255 | VBOXVDMASUBMIT Submitter;
|
---|
256 | #endif
|
---|
257 | /* dma-related commands list processed on the guest w/o host part involvement (guest-guest commands) */
|
---|
258 | VBOXVDMAGG DmaGg;
|
---|
259 | } VBOXVDMAINFO, *PVBOXVDMAINFO;
|
---|
260 |
|
---|
261 | int vboxVdmaCreate (struct _DEVICE_EXTENSION* pDevExt, VBOXVDMAINFO *pInfo
|
---|
262 | #ifdef VBOXVDMA
|
---|
263 | , ULONG offBuffer, ULONG cbBuffer
|
---|
264 | #endif
|
---|
265 | #if 0
|
---|
266 | , PFNVBOXVDMASUBMIT pfnSubmit, PVOID pvContext
|
---|
267 | #endif
|
---|
268 | );
|
---|
269 | int vboxVdmaDisable (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo);
|
---|
270 | int vboxVdmaEnable (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo);
|
---|
271 | int vboxVdmaDestroy (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo);
|
---|
272 |
|
---|
273 | #ifdef VBOXVDMA
|
---|
274 | int vboxVdmaFlush (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo);
|
---|
275 | int vboxVdmaCBufDrSubmit (struct _DEVICE_EXTENSION* pDevExt, PVBOXVDMAINFO pInfo, PVBOXVDMACBUF_DR pDr);
|
---|
276 | struct VBOXVDMACBUF_DR* vboxVdmaCBufDrCreate (PVBOXVDMAINFO pInfo, uint32_t cbTrailingData);
|
---|
277 | void vboxVdmaCBufDrFree (PVBOXVDMAINFO pInfo, struct VBOXVDMACBUF_DR* pDr);
|
---|
278 |
|
---|
279 | #define VBOXVDMACBUF_DR_DATA_OFFSET() (sizeof (VBOXVDMACBUF_DR))
|
---|
280 | #define VBOXVDMACBUF_DR_SIZE(_cbData) (VBOXVDMACBUF_DR_DATA_OFFSET() + (_cbData))
|
---|
281 | #define VBOXVDMACBUF_DR_DATA(_pDr) ( ((uint8_t*)(_pDr)) + VBOXVDMACBUF_DR_DATA_OFFSET() )
|
---|
282 | #endif
|
---|
283 | NTSTATUS vboxVdmaGgCmdSubmit(PVBOXVDMAGG pVdma, PVBOXVDMAPIPE_CMD_DR pCmd);
|
---|
284 | PVBOXVDMAPIPE_CMD_DR vboxVdmaGgCmdCreate(PVBOXVDMAGG pVdma, VBOXVDMAPIPE_CMD_TYPE enmType, uint32_t cbCmd);
|
---|
285 | void vboxVdmaGgCmdDestroy(PVBOXVDMAPIPE_CMD_DR pDr);
|
---|
286 |
|
---|
287 | #define VBOXVDMAPIPE_CMD_DR_FROM_DDI_CMD(_pCmd) ((PVBOXVDMAPIPE_CMD_DR)(((uint8_t*)(_pCmd)) - RT_OFFSETOF(VBOXVDMAPIPE_CMD_DR, DdiCmd)))
|
---|
288 | DECLCALLBACK(VOID) vboxVdmaGgDdiCmdDestroy(PDEVICE_EXTENSION pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext);
|
---|
289 |
|
---|
290 | #endif /* #ifndef ___VBoxVideoVdma_h___ */
|
---|