1 | /* $Id: VBoxMPCr.h 50940 2014-04-01 11:22:34Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox WDDM Miniport driver
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2012 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 | #ifndef ___VBoxMPCr_h__
|
---|
19 | #define ___VBoxMPCr_h__
|
---|
20 |
|
---|
21 | #ifdef VBOX_WITH_CROGL
|
---|
22 |
|
---|
23 | #include <VBox/VBoxGuestLib.h>
|
---|
24 | #include <VBoxGuestR0LibCrOgl.h>
|
---|
25 |
|
---|
26 | typedef struct VBOXMP_CRCTLCON
|
---|
27 | {
|
---|
28 | HVBOXCRCTL hCrCtl;
|
---|
29 | uint32_t cCrCtlRefs;
|
---|
30 | } VBOXMP_CRCTLCON, *PVBOXMP_CRCTLCON;
|
---|
31 |
|
---|
32 | void VBoxMpCrCtlConInit();
|
---|
33 |
|
---|
34 | bool VBoxMpCrCtlConIs3DSupported();
|
---|
35 |
|
---|
36 | int VBoxMpCrCtlConConnect(PVBOXMP_DEVEXT pDevExt, PVBOXMP_CRCTLCON pCrCtlCon,
|
---|
37 | uint32_t crVersionMajor, uint32_t crVersionMinor,
|
---|
38 | uint32_t *pu32ClientID);
|
---|
39 | int VBoxMpCrCtlConDisconnect(PVBOXMP_DEVEXT pDevExt, PVBOXMP_CRCTLCON pCrCtlCon, uint32_t u32ClientID);
|
---|
40 | int VBoxMpCrCtlConCall(PVBOXMP_CRCTLCON pCrCtlCon, struct VBoxGuestHGCMCallInfo *pData, uint32_t cbData);
|
---|
41 | int VBoxMpCrCtlConCallUserData(PVBOXMP_CRCTLCON pCrCtlCon, struct VBoxGuestHGCMCallInfo *pData, uint32_t cbData);
|
---|
42 |
|
---|
43 | # include <cr_pack.h>
|
---|
44 |
|
---|
45 | typedef struct VBOXMP_CRSHGSMICON_BUFDR
|
---|
46 | {
|
---|
47 | uint32_t cbBuf;
|
---|
48 | void *pvBuf;
|
---|
49 | } VBOXMP_CRSHGSMICON_BUFDR, *PVBOXMP_CRSHGSMICON_BUFDR;
|
---|
50 |
|
---|
51 | typedef struct VBOXMP_CRSHGSMICON_BUFDR_CACHE
|
---|
52 | {
|
---|
53 | volatile PVBOXMP_CRSHGSMICON_BUFDR pBufDr;
|
---|
54 | } VBOXMP_CRSHGSMICON_BUFDR_CACHE, *PVBOXMP_CRSHGSMICON_BUFDR_CACHE;
|
---|
55 |
|
---|
56 | typedef struct VBOXMP_CRSHGSMITRANSPORT
|
---|
57 | {
|
---|
58 | PVBOXMP_DEVEXT pDevExt;
|
---|
59 | VBOXMP_CRSHGSMICON_BUFDR_CACHE WbDrCache;
|
---|
60 | } VBOXMP_CRSHGSMITRANSPORT, *PVBOXMP_CRSHGSMITRANSPORT;
|
---|
61 |
|
---|
62 | /** the rx buffer passed here is only valid in the context of the callback.
|
---|
63 | * the callee must NOT free it or use outside of the callback context.
|
---|
64 | * */
|
---|
65 | typedef DECLCALLBACK(void) FNVBOXMP_CRSHGSMITRANSPORT_SENDWRITEREADASYNC_COMPLETION(PVBOXMP_CRSHGSMITRANSPORT pCon, int rc, void *pvRx, uint32_t cbRx, void *pvCtx);
|
---|
66 | typedef FNVBOXMP_CRSHGSMITRANSPORT_SENDWRITEREADASYNC_COMPLETION *PFNVBOXMP_CRSHGSMITRANSPORT_SENDWRITEREADASYNC_COMPLETION;
|
---|
67 |
|
---|
68 | typedef DECLCALLBACK(void) FNVBOXMP_CRSHGSMITRANSPORT_SENDWRITEASYNC_COMPLETION(PVBOXMP_CRSHGSMITRANSPORT pCon, int rc, void *pvCtx);
|
---|
69 | typedef FNVBOXMP_CRSHGSMITRANSPORT_SENDWRITEASYNC_COMPLETION *PFNVBOXMP_CRSHGSMITRANSPORT_SENDWRITEASYNC_COMPLETION;
|
---|
70 |
|
---|
71 | int VBoxMpCrShgsmiTransportCreate(PVBOXMP_CRSHGSMITRANSPORT pCon, PVBOXMP_DEVEXT pDevExt);
|
---|
72 | void VBoxMpCrShgsmiTransportTerm(PVBOXMP_CRSHGSMITRANSPORT pCon);
|
---|
73 | void* VBoxMpCrShgsmiTransportCmdCreateWriteReadAsync(PVBOXMP_CRSHGSMITRANSPORT pCon, uint32_t u32ClientID, void *pvBuffer, uint32_t cbBuffer,
|
---|
74 | PFNVBOXMP_CRSHGSMITRANSPORT_SENDWRITEREADASYNC_COMPLETION pfnCompletion, uint32_t cbContextData);
|
---|
75 | void* VBoxMpCrShgsmiTransportCmdCreateWriteAsync(PVBOXMP_CRSHGSMITRANSPORT pCon, uint32_t u32ClientID, void *pvBuffer, uint32_t cbBuffer,
|
---|
76 | PFNVBOXMP_CRSHGSMITRANSPORT_SENDWRITEASYNC_COMPLETION pfnCompletion, uint32_t cbContextData);
|
---|
77 | int VBoxMpCrShgsmiTransportCmdSubmitWriteReadAsync(PVBOXMP_CRSHGSMITRANSPORT pCon, void *pvContext);
|
---|
78 | int VBoxMpCrShgsmiTransportCmdSubmitWriteAsync(PVBOXMP_CRSHGSMITRANSPORT pCon, void *pvContext);
|
---|
79 | void VBoxMpCrShgsmiTransportCmdTermWriteReadAsync(PVBOXMP_CRSHGSMITRANSPORT pCon, void *pvContext);
|
---|
80 | void VBoxMpCrShgsmiTransportCmdTermWriteAsync(PVBOXMP_CRSHGSMITRANSPORT pCon, void *pvContext);
|
---|
81 |
|
---|
82 | void* VBoxMpCrShgsmiTransportBufAlloc(PVBOXMP_CRSHGSMITRANSPORT pCon, uint32_t cbBuffer);
|
---|
83 | void VBoxMpCrShgsmiTransportBufFree(PVBOXMP_CRSHGSMITRANSPORT pCon, void* pvBuffer);
|
---|
84 |
|
---|
85 | typedef struct VBOXMP_CRPACKER
|
---|
86 | {
|
---|
87 | CRPackContext CrPacker;
|
---|
88 | CRPackBuffer CrBuffer;
|
---|
89 | } VBOXMP_CRPACKER, *PVBOXMP_CRPACKER;
|
---|
90 |
|
---|
91 | DECLINLINE(void) VBoxMpCrPackerInit(PVBOXMP_CRPACKER pPacker)
|
---|
92 | {
|
---|
93 | memset(pPacker, 0, sizeof (*pPacker));
|
---|
94 | }
|
---|
95 |
|
---|
96 | DECLINLINE(void) VBoxMpCrPackerTerm(PVBOXMP_CRPACKER pPacker)
|
---|
97 | {}
|
---|
98 |
|
---|
99 | DECLINLINE(void) VBoxMpCrPackerTxBufferInit(PVBOXMP_CRPACKER pPacker, void *pvBuffer, uint32_t cbBuffer, uint32_t cCommands)
|
---|
100 | {
|
---|
101 | crPackInitBuffer(&pPacker->CrBuffer, pvBuffer, cbBuffer, cbBuffer, cCommands);
|
---|
102 | crPackSetBuffer(&pPacker->CrPacker, &pPacker->CrBuffer);
|
---|
103 | }
|
---|
104 |
|
---|
105 | DECLINLINE(CRMessageOpcodes*) vboxMpCrPackerPrependHeader( const CRPackBuffer *pBuffer, uint32_t *cbData, void **ppvPackBuffer)
|
---|
106 | {
|
---|
107 | UINT num_opcodes;
|
---|
108 | CRMessageOpcodes *hdr;
|
---|
109 |
|
---|
110 | Assert(pBuffer);
|
---|
111 | Assert(pBuffer->opcode_current < pBuffer->opcode_start);
|
---|
112 | Assert(pBuffer->opcode_current >= pBuffer->opcode_end);
|
---|
113 | Assert(pBuffer->data_current > pBuffer->data_start);
|
---|
114 | Assert(pBuffer->data_current <= pBuffer->data_end);
|
---|
115 |
|
---|
116 | num_opcodes = (UINT)(pBuffer->opcode_start - pBuffer->opcode_current);
|
---|
117 | hdr = (CRMessageOpcodes *)
|
---|
118 | ( pBuffer->data_start - ( ( num_opcodes + 3 ) & ~0x3 ) - sizeof(*hdr) );
|
---|
119 |
|
---|
120 | Assert((void *) hdr >= pBuffer->pack);
|
---|
121 |
|
---|
122 | hdr->header.type = CR_MESSAGE_OPCODES;
|
---|
123 | hdr->numOpcodes = num_opcodes;
|
---|
124 |
|
---|
125 | *cbData = (UINT)(pBuffer->data_current - (unsigned char *) hdr);
|
---|
126 | *ppvPackBuffer = pBuffer->pack;
|
---|
127 |
|
---|
128 | return hdr;
|
---|
129 | }
|
---|
130 |
|
---|
131 | DECLINLINE(void*) VBoxMpCrPackerTxBufferComplete(PVBOXMP_CRPACKER pPacker, uint32_t *pcbBuffer, void **ppvPackBuffer)
|
---|
132 | {
|
---|
133 | crPackReleaseBuffer(&pPacker->CrPacker);
|
---|
134 | uint32_t cbData;
|
---|
135 | CRMessageOpcodes *pHdr;
|
---|
136 | void *pvPackBuffer;
|
---|
137 | if (pPacker->CrBuffer.opcode_current != pPacker->CrBuffer.opcode_start)
|
---|
138 | pHdr = vboxMpCrPackerPrependHeader(&pPacker->CrBuffer, &cbData, &pvPackBuffer);
|
---|
139 | else
|
---|
140 | {
|
---|
141 | cbData = 0;
|
---|
142 | pHdr = NULL;
|
---|
143 | pvPackBuffer = NULL;
|
---|
144 | }
|
---|
145 | *pcbBuffer = cbData;
|
---|
146 | *ppvPackBuffer = pvPackBuffer;
|
---|
147 | return pHdr;
|
---|
148 | }
|
---|
149 |
|
---|
150 | DECLINLINE(uint32_t) VBoxMpCrPackerTxBufferGetFreeBufferSize(PVBOXMP_CRPACKER pPacker)
|
---|
151 | {
|
---|
152 | return (uint32_t)(pPacker->CrBuffer.data_end - pPacker->CrBuffer.data_start);
|
---|
153 | }
|
---|
154 |
|
---|
155 | DECLINLINE(void) vboxMpCrUnpackerRxWriteback(CRMessageWriteback *pWb)
|
---|
156 | {
|
---|
157 | int *pWriteback;
|
---|
158 | memcpy(&pWriteback, &(pWb->writeback_ptr), sizeof (pWriteback));
|
---|
159 | (*pWriteback)--;
|
---|
160 | }
|
---|
161 |
|
---|
162 | DECLINLINE(void) vboxMpCrUnpackerRxReadback(CRMessageReadback *pRb, uint32_t cbRx)
|
---|
163 | {
|
---|
164 | int cbPayload = cbRx - sizeof (*pRb);
|
---|
165 | int *pWriteback;
|
---|
166 | void *pDst;
|
---|
167 | memcpy(&pWriteback, &(pRb->writeback_ptr), sizeof (pWriteback));
|
---|
168 | memcpy(&pDst, &(pRb->readback_ptr), sizeof (pDst));
|
---|
169 |
|
---|
170 | (*pWriteback)--;
|
---|
171 | memcpy(pDst, ((uint8_t*)pRb) + sizeof (*pRb), cbPayload);
|
---|
172 | }
|
---|
173 |
|
---|
174 | DECLINLINE(int) VBoxMpCrUnpackerRxBufferProcess(void *pvBuffer, uint32_t cbBuffer)
|
---|
175 | {
|
---|
176 | CRMessage *pMsg = (CRMessage*)pvBuffer;
|
---|
177 | switch (pMsg->header.type)
|
---|
178 | {
|
---|
179 | case CR_MESSAGE_WRITEBACK:
|
---|
180 | vboxMpCrUnpackerRxWriteback(&(pMsg->writeback));
|
---|
181 | return VINF_SUCCESS;
|
---|
182 | case CR_MESSAGE_READBACK:
|
---|
183 | vboxMpCrUnpackerRxReadback(&(pMsg->readback), cbBuffer);
|
---|
184 | return VINF_SUCCESS;
|
---|
185 | default:
|
---|
186 | WARN(("unknown msg code %d", pMsg->header.type));
|
---|
187 | return VERR_NOT_SUPPORTED;
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | DECLINLINE(void*) VBoxMpCrCmdRxReadbackData(CRMessageReadback *pRx)
|
---|
192 | {
|
---|
193 | return (void*)(pRx+1);
|
---|
194 | }
|
---|
195 |
|
---|
196 | DECLINLINE(uint32_t) VBoxMpCrCmdRxReadbackDataSize(CRMessageReadback *pRx, uint32_t cbRx)
|
---|
197 | {
|
---|
198 | return cbRx - sizeof (*pRx);
|
---|
199 | }
|
---|
200 | int VBoxMpCrCmdRxReadbackHandler(CRMessageReadback *pRx, uint32_t cbRx);
|
---|
201 | int VBoxMpCrCmdRxHandler(CRMessageHeader *pRx, uint32_t cbRx);
|
---|
202 |
|
---|
203 | /* must be called after calling VBoxMpCrCtlConIs3DSupported only */
|
---|
204 | uint32_t VBoxMpCrGetHostCaps();
|
---|
205 |
|
---|
206 | #define VBOXMP_CRCMD_HEADER_SIZE sizeof (CRMessageOpcodes)
|
---|
207 | /* last +4 below is 4-aligned command opcode size (i.e. ((1 + 3) & ~3)) */
|
---|
208 | #define VBOXMP_CRCMD_SIZE_WINDOWPOSITION (20 + 4)
|
---|
209 | #define VBOXMP_CRCMD_SIZE_WINDOWVISIBLEREGIONS(_cRects) (16 + (_cRects) * 4 * sizeof (GLint) + 4)
|
---|
210 | #define VBOXMP_CRCMD_SIZE_VBOXTEXPRESENT(_cRects) (28 + (_cRects) * 4 * sizeof (GLint) + 4)
|
---|
211 | #define VBOXMP_CRCMD_SIZE_WINDOWSHOW (16 + 4)
|
---|
212 | #define VBOXMP_CRCMD_SIZE_WINDOWSIZE (20 + 4)
|
---|
213 | #define VBOXMP_CRCMD_SIZE_GETCHROMIUMPARAMETERVCR (36 + 4)
|
---|
214 | #define VBOXMP_CRCMD_SIZE_CHROMIUMPARAMETERICR (16 + 4)
|
---|
215 | #define VBOXMP_CRCMD_SIZE_WINDOWCREATE (256 + 28 + 4)
|
---|
216 | #define VBOXMP_CRCMD_SIZE_WINDOWDESTROY (12 + 4)
|
---|
217 | #define VBOXMP_CRCMD_SIZE_CREATECONTEXT (256 + 32 + 4)
|
---|
218 | #define VBOXMP_CRCMD_SIZE_DESTROYCONTEXT (12 + 4)
|
---|
219 |
|
---|
220 | #endif /* #ifdef VBOX_WITH_CROGL */
|
---|
221 |
|
---|
222 | #endif /* #ifndef ___VBoxMPCr_h__ */
|
---|