1 | /* $Id: VBoxUhgsmiBase.h 42499 2012-08-01 10:26:43Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBoxVideo Display D3D User mode dll
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef ___VBoxUhgsmiBase_h__
|
---|
20 | #define ___VBoxUhgsmiBase_h__
|
---|
21 |
|
---|
22 | #include <VBox/VBoxUhgsmi.h>
|
---|
23 | #include <VBox/VBoxCrHgsmi.h>
|
---|
24 |
|
---|
25 | #include <windows.h>
|
---|
26 | #include <D3dkmthk.h>
|
---|
27 | //#include <D3dumddi.h>
|
---|
28 | #include "common/wddm/VBoxMPIf.h"
|
---|
29 |
|
---|
30 |
|
---|
31 | #ifndef VBOX_WITH_CRHGSMI
|
---|
32 | #error "VBOX_WITH_CRHGSMI not defined!"
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #if 0
|
---|
36 | typedef DECLCALLBACK(int) FNVBOXCRHGSMI_CTLCON_CALL(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, struct VBoxGuestHGCMCallInfo *pCallInfo, int cbCallInfo);
|
---|
37 | typedef FNVBOXCRHGSMI_CTLCON_CALL *PFNVBOXCRHGSMI_CTLCON_CALL;
|
---|
38 |
|
---|
39 | #define vboxCrHgsmiPrivateCtlConCall(_pHgsmi, _pCallInfo, _cbCallInfo) (_pHgsmi->pfnCtlConCall((_pHgsmi), (_pCallInfo), (_cbCallInfo)))
|
---|
40 |
|
---|
41 |
|
---|
42 | typedef DECLCALLBACK(int) FNVBOXCRHGSMI_CTLCON_GETCLIENTID(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, uint32_t *pu32ClientID);
|
---|
43 | typedef FNVBOXCRHGSMI_CTLCON_GETCLIENTID *PFNVBOXCRHGSMI_CTLCON_GETCLIENTID;
|
---|
44 |
|
---|
45 | #define vboxCrHgsmiPrivateCtlConGetClientID(_pHgsmi, _pu32ClientID) (_pHgsmi->pfnCtlConGetClientID((_pHgsmi), (_pu32ClientID)))
|
---|
46 | #else
|
---|
47 | int vboxCrHgsmiPrivateCtlConCall(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, struct VBoxGuestHGCMCallInfo *pCallInfo, int cbCallInfo);
|
---|
48 | int vboxCrHgsmiPrivateCtlConGetClientID(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, uint32_t *pu32ClientID);
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | typedef DECLCALLBACK(int) FNVBOXCRHGSMI_ESCAPE(struct VBOXUHGSMI_PRIVATE_BASE *pHgsmi, void *pvData, uint32_t cbData, BOOL fHwAccess);
|
---|
52 | typedef FNVBOXCRHGSMI_ESCAPE *PFNVBOXCRHGSMI_ESCAPE;
|
---|
53 |
|
---|
54 | #define vboxCrHgsmiPrivateEscape(_pHgsmi, _pvData, _cbData, _fHwAccess) (_pHgsmi->pfnEscape((_pHgsmi), (_pvData), (_cbData), (_fHwAccess)))
|
---|
55 |
|
---|
56 | typedef struct VBOXUHGSMI_PRIVATE_BASE
|
---|
57 | {
|
---|
58 | VBOXUHGSMI Base;
|
---|
59 | PFNVBOXCRHGSMI_ESCAPE pfnEscape;
|
---|
60 | } VBOXUHGSMI_PRIVATE_BASE, *PVBOXUHGSMI_PRIVATE_BASE;
|
---|
61 |
|
---|
62 | typedef struct VBOXUHGSMI_BUFFER_PRIVATE_BASE
|
---|
63 | {
|
---|
64 | VBOXUHGSMI_BUFFER Base;
|
---|
65 | PVBOXUHGSMI_PRIVATE_BASE pHgsmi;
|
---|
66 | } VBOXUHGSMI_BUFFER_PRIVATE_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_BASE;
|
---|
67 |
|
---|
68 | typedef struct VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE
|
---|
69 | {
|
---|
70 | VBOXUHGSMI_BUFFER_PRIVATE_BASE PrivateBase;
|
---|
71 | VBOXVIDEOCM_UM_ALLOC Alloc;
|
---|
72 | HANDLE hSynch;
|
---|
73 | } VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE;
|
---|
74 |
|
---|
75 | typedef struct VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE
|
---|
76 | {
|
---|
77 | VBOXUHGSMI_BUFFER_PRIVATE_BASE PrivateBase;
|
---|
78 | D3DKMT_HANDLE hAllocation;
|
---|
79 | UINT aLockPageIndices[1];
|
---|
80 | } VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE;
|
---|
81 |
|
---|
82 | #define VBOXUHGSMIBASE_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, Base)))
|
---|
83 | #define VBOXUHGSMIBASE_GET(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_BASE)
|
---|
84 | #define VBOXUHGSMIBASE_GET_BUFFER(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_BASE)
|
---|
85 |
|
---|
86 | #define VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, PrivateBase.Base)))
|
---|
87 | #define VBOXUHGSMIESCBASE_GET_BUFFER(_p) VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE)
|
---|
88 | #define VBOXUHGSMDXALLOCBASE_GET_BUFFER(_p) VBOXUHGSMIPRIVATEBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_DX_ALLOC_BASE)
|
---|
89 |
|
---|
90 | DECLINLINE(int) vboxUhgsmiBaseLockData(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags,
|
---|
91 | D3DDDICB_LOCKFLAGS *pfFlags, UINT *pNumPages, UINT* pPages)
|
---|
92 | {
|
---|
93 | D3DDDICB_LOCKFLAGS fLockFlags;
|
---|
94 | fLockFlags.Value = 0;
|
---|
95 | if (fFlags.bLockEntire)
|
---|
96 | {
|
---|
97 | Assert(!offLock);
|
---|
98 | fLockFlags.LockEntire = 1;
|
---|
99 | }
|
---|
100 | else
|
---|
101 | {
|
---|
102 | if (!cbLock)
|
---|
103 | {
|
---|
104 | Assert(0);
|
---|
105 | return VERR_INVALID_PARAMETER;
|
---|
106 | }
|
---|
107 | if (offLock + cbLock > pBuf->cbBuffer)
|
---|
108 | {
|
---|
109 | Assert(0);
|
---|
110 | return VERR_INVALID_PARAMETER;
|
---|
111 | }
|
---|
112 |
|
---|
113 | uint32_t iFirstPage = offLock >> 12;
|
---|
114 | uint32_t iAfterLastPage = (cbLock + 0xfff) >> 12;
|
---|
115 | uint32_t cPages = iAfterLastPage - iFirstPage;
|
---|
116 | uint32_t cBufPages = pBuf->cbBuffer >> 12;
|
---|
117 | Assert(cPages <= (cBufPages));
|
---|
118 |
|
---|
119 | if (cPages == cBufPages)
|
---|
120 | {
|
---|
121 | *pNumPages = 0;
|
---|
122 | fLockFlags.LockEntire = 1;
|
---|
123 | }
|
---|
124 | else
|
---|
125 | {
|
---|
126 | *pNumPages = cPages;
|
---|
127 | for (UINT i = 0, j = iFirstPage; i < cPages; ++i, ++j)
|
---|
128 | {
|
---|
129 | pPages[i] = j;
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | }
|
---|
134 |
|
---|
135 | fLockFlags.ReadOnly = fFlags.bReadOnly;
|
---|
136 | fLockFlags.WriteOnly = fFlags.bWriteOnly;
|
---|
137 | fLockFlags.DonotWait = fFlags.bDonotWait;
|
---|
138 | // fLockFlags.Discard = fFlags.bDiscard;
|
---|
139 | *pfFlags = fLockFlags;
|
---|
140 | return VINF_SUCCESS;
|
---|
141 | }
|
---|
142 |
|
---|
143 | #if 0
|
---|
144 | DECLINLINE(int) vboxUhgsmiBaseDmaFill(PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers,
|
---|
145 | VOID* pCommandBuffer, UINT *pCommandBufferSize,
|
---|
146 | D3DDDI_ALLOCATIONLIST *pAllocationList, UINT AllocationListSize,
|
---|
147 | D3DDDI_PATCHLOCATIONLIST *pPatchLocationList, UINT PatchLocationListSize)
|
---|
148 | {
|
---|
149 | const uint32_t cbDmaCmd = RT_OFFSETOF(VBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD, aBufInfos[cBuffers]);
|
---|
150 | if (*pCommandBufferSize < cbDmaCmd)
|
---|
151 | {
|
---|
152 | Assert(0);
|
---|
153 | return VERR_GENERAL_FAILURE;
|
---|
154 | }
|
---|
155 | if (AllocationListSize < cBuffers)
|
---|
156 | {
|
---|
157 | Assert(0);
|
---|
158 | return VERR_GENERAL_FAILURE;
|
---|
159 | }
|
---|
160 |
|
---|
161 | *pCommandBufferSize = cbDmaCmd;
|
---|
162 |
|
---|
163 | PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD)pCommandBuffer;
|
---|
164 | pHdr->Base.enmCmd = VBOXVDMACMD_TYPE_CHROMIUM_CMD;
|
---|
165 | pHdr->Base.u32CmdReserved = cBuffers;
|
---|
166 |
|
---|
167 | PVBOXWDDM_UHGSMI_BUFFER_UI_SUBMIT_INFO pBufSubmInfo = pHdr->aBufInfos;
|
---|
168 |
|
---|
169 | for (uint32_t i = 0; i < cBuffers; ++i)
|
---|
170 | {
|
---|
171 | PVBOXUHGSMI_BUFFER_SUBMIT pBufInfo = &aBuffers[i];
|
---|
172 | PVBOXUHGSMI_BUFFER_PRIVATE_BASE pBuffer = VBOXUHGSMIBASE_GET_BUFFER(pBufInfo->pBuf);
|
---|
173 |
|
---|
174 | memset(pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));
|
---|
175 | pAllocationList->hAllocation = pBuffer->hAllocation;
|
---|
176 | pAllocationList->Value = 0;
|
---|
177 | pAllocationList->WriteOperation = !pBufInfo->fFlags.bHostReadOnly;
|
---|
178 | pAllocationList->DoNotRetireInstance = pBufInfo->fFlags.bDoNotRetire;
|
---|
179 | pBufSubmInfo->bDoNotSignalCompletion = 0;
|
---|
180 | if (pBufInfo->fFlags.bEntireBuffer)
|
---|
181 | {
|
---|
182 | pBufSubmInfo->offData = 0;
|
---|
183 | pBufSubmInfo->cbData = pBuffer->Base.cbBuffer;
|
---|
184 | }
|
---|
185 | else
|
---|
186 | {
|
---|
187 | pBufSubmInfo->offData = pBufInfo->offData;
|
---|
188 | pBufSubmInfo->cbData = pBufInfo->cbData;
|
---|
189 | }
|
---|
190 |
|
---|
191 | ++pAllocationList;
|
---|
192 | ++pBufSubmInfo;
|
---|
193 | }
|
---|
194 |
|
---|
195 | return VINF_SUCCESS;
|
---|
196 | }
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferLock(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags, void**pvLock);
|
---|
200 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferUnlock(PVBOXUHGSMI_BUFFER pBuf);
|
---|
201 | int vboxUhgsmiBaseBufferTerm(PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE pBuffer);
|
---|
202 | static int vboxUhgsmiBaseEventChkCreate(VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, HANDLE *phSynch);
|
---|
203 | int vboxUhgsmiKmtEscBufferInit(PVBOXUHGSMI_PRIVATE_BASE pPrivate, PVBOXUHGSMI_BUFFER_PRIVATE_ESC_BASE pBuffer, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, PFNVBOXUHGSMI_BUFFER_DESTROY pfnDestroy);
|
---|
204 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferSubmit(PVBOXUHGSMI pHgsmi, PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers);
|
---|
205 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferDestroy(PVBOXUHGSMI_BUFFER pBuf);
|
---|
206 | DECLCALLBACK(int) vboxUhgsmiBaseEscBufferCreate(PVBOXUHGSMI pHgsmi, uint32_t cbBuf, VBOXUHGSMI_BUFFER_TYPE_FLAGS fUhgsmiType, PVBOXUHGSMI_BUFFER* ppBuf);
|
---|
207 | DECLINLINE(void) vboxUhgsmiBaseInit(PVBOXUHGSMI_PRIVATE_BASE pHgsmi, PFNVBOXCRHGSMI_ESCAPE pfnEscape)
|
---|
208 | {
|
---|
209 | pHgsmi->Base.pfnBufferCreate = vboxUhgsmiBaseEscBufferCreate;
|
---|
210 | pHgsmi->Base.pfnBufferSubmit = vboxUhgsmiBaseEscBufferSubmit;
|
---|
211 | pHgsmi->pfnEscape = pfnEscape;
|
---|
212 | }
|
---|
213 |
|
---|
214 | #endif /* #ifndef ___VBoxUhgsmiBase_h__ */
|
---|