1 | /* $Id: DevVGA_VBVA.cpp 55560 2015-04-30 14:57:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Video Acceleration (VBVA).
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2015 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #define LOG_GROUP LOG_GROUP_DEV_VGA
|
---|
22 | #include <VBox/vmm/pdmifs.h>
|
---|
23 | #include <VBox/vmm/pdmdev.h>
|
---|
24 | #include <VBox/vmm/pgm.h>
|
---|
25 | #include <VBox/vmm/ssm.h>
|
---|
26 | #include <VBox/VMMDev.h>
|
---|
27 | #include <VBox/VBoxVideo.h>
|
---|
28 | #include <iprt/alloc.h>
|
---|
29 | #include <iprt/assert.h>
|
---|
30 | #include <iprt/asm.h>
|
---|
31 | #include <iprt/string.h>
|
---|
32 | #include <iprt/param.h>
|
---|
33 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
34 | #include <iprt/semaphore.h>
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #include "DevVGA.h"
|
---|
38 |
|
---|
39 | /* A very detailed logging. */
|
---|
40 | #if 0 // def DEBUG_sunlover
|
---|
41 | #define LOGVBVABUFFER(a) LogFlow(a)
|
---|
42 | #else
|
---|
43 | #define LOGVBVABUFFER(a) do {} while (0)
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | /*******************************************************************************
|
---|
47 | * Structures and Typedefs *
|
---|
48 | *******************************************************************************/
|
---|
49 | typedef struct VBVAPARTIALRECORD
|
---|
50 | {
|
---|
51 | uint8_t *pu8;
|
---|
52 | uint32_t cb;
|
---|
53 | } VBVAPARTIALRECORD;
|
---|
54 |
|
---|
55 | typedef struct VBVAVIEW
|
---|
56 | {
|
---|
57 | VBVAINFOVIEW view;
|
---|
58 | VBVAINFOSCREEN screen;
|
---|
59 | VBVABUFFER *pVBVA;
|
---|
60 | uint32_t u32VBVAOffset;
|
---|
61 | VBVAPARTIALRECORD partialRecord;
|
---|
62 | } VBVAVIEW;
|
---|
63 |
|
---|
64 | typedef struct VBVAMOUSESHAPEINFO
|
---|
65 | {
|
---|
66 | bool fSet;
|
---|
67 | bool fVisible;
|
---|
68 | bool fAlpha;
|
---|
69 | uint32_t u32HotX;
|
---|
70 | uint32_t u32HotY;
|
---|
71 | uint32_t u32Width;
|
---|
72 | uint32_t u32Height;
|
---|
73 | uint32_t cbShape;
|
---|
74 | uint32_t cbAllocated;
|
---|
75 | uint8_t *pu8Shape;
|
---|
76 | } VBVAMOUSESHAPEINFO;
|
---|
77 |
|
---|
78 | /** @todo saved state: save and restore VBVACONTEXT */
|
---|
79 | typedef struct VBVACONTEXT
|
---|
80 | {
|
---|
81 | uint32_t cViews;
|
---|
82 | VBVAVIEW aViews[64 /* @todo SchemaDefs::MaxGuestMonitors*/];
|
---|
83 | VBVAMOUSESHAPEINFO mouseShapeInfo;
|
---|
84 | bool fPaused;
|
---|
85 | uint32_t xCursor;
|
---|
86 | uint32_t yCursor;
|
---|
87 | VBVAMODEHINT aModeHints[VBOX_VIDEO_MAX_SCREENS];
|
---|
88 | } VBVACONTEXT;
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | /** Copies @a cb bytes from the VBVA ring buffer to the @a pu8Dst.
|
---|
93 | * Used for partial records or for records which cross the ring boundary.
|
---|
94 | */
|
---|
95 | static void vbvaFetchBytes (VBVABUFFER *pVBVA, uint8_t *pu8Dst, uint32_t cb)
|
---|
96 | {
|
---|
97 | /** @todo replace the 'if' with an assert. The caller must ensure this condition. */
|
---|
98 | if (cb >= pVBVA->cbData)
|
---|
99 | {
|
---|
100 | AssertMsgFailed (("cb = 0x%08X, ring buffer size 0x%08X", cb, pVBVA->cbData));
|
---|
101 | return;
|
---|
102 | }
|
---|
103 |
|
---|
104 | const uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
|
---|
105 | const uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
|
---|
106 | const int32_t i32Diff = cb - u32BytesTillBoundary;
|
---|
107 |
|
---|
108 | if (i32Diff <= 0)
|
---|
109 | {
|
---|
110 | /* Chunk will not cross buffer boundary. */
|
---|
111 | memcpy (pu8Dst, src, cb);
|
---|
112 | }
|
---|
113 | else
|
---|
114 | {
|
---|
115 | /* Chunk crosses buffer boundary. */
|
---|
116 | memcpy (pu8Dst, src, u32BytesTillBoundary);
|
---|
117 | memcpy (pu8Dst + u32BytesTillBoundary, &pVBVA->au8Data[0], i32Diff);
|
---|
118 | }
|
---|
119 |
|
---|
120 | /* Advance data offset. */
|
---|
121 | pVBVA->off32Data = (pVBVA->off32Data + cb) % pVBVA->cbData;
|
---|
122 |
|
---|
123 | return;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | static bool vbvaPartialRead (VBVAPARTIALRECORD *pPartialRecord, uint32_t cbRecord, VBVABUFFER *pVBVA)
|
---|
128 | {
|
---|
129 | uint8_t *pu8New;
|
---|
130 |
|
---|
131 | LOGVBVABUFFER(("vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
|
---|
132 | pPartialRecord->pu8, pPartialRecord->cb, cbRecord));
|
---|
133 |
|
---|
134 | if (pPartialRecord->pu8)
|
---|
135 | {
|
---|
136 | Assert (pPartialRecord->cb);
|
---|
137 | pu8New = (uint8_t *)RTMemRealloc (pPartialRecord->pu8, cbRecord);
|
---|
138 | }
|
---|
139 | else
|
---|
140 | {
|
---|
141 | Assert (!pPartialRecord->cb);
|
---|
142 | pu8New = (uint8_t *)RTMemAlloc (cbRecord);
|
---|
143 | }
|
---|
144 |
|
---|
145 | if (!pu8New)
|
---|
146 | {
|
---|
147 | /* Memory allocation failed, fail the function. */
|
---|
148 | Log(("vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
|
---|
149 | cbRecord));
|
---|
150 |
|
---|
151 | if (pPartialRecord->pu8)
|
---|
152 | {
|
---|
153 | RTMemFree (pPartialRecord->pu8);
|
---|
154 | }
|
---|
155 |
|
---|
156 | pPartialRecord->pu8 = NULL;
|
---|
157 | pPartialRecord->cb = 0;
|
---|
158 |
|
---|
159 | return false;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /* Fetch data from the ring buffer. */
|
---|
163 | vbvaFetchBytes (pVBVA, pu8New + pPartialRecord->cb, cbRecord - pPartialRecord->cb);
|
---|
164 |
|
---|
165 | pPartialRecord->pu8 = pu8New;
|
---|
166 | pPartialRecord->cb = cbRecord;
|
---|
167 |
|
---|
168 | return true;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /* For contiguous chunks just return the address in the buffer.
|
---|
172 | * For crossing boundary - allocate a buffer from heap.
|
---|
173 | */
|
---|
174 | static bool vbvaFetchCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR **ppHdr, uint32_t *pcbCmd)
|
---|
175 | {
|
---|
176 | uint32_t indexRecordFirst = pVBVA->indexRecordFirst;
|
---|
177 | uint32_t indexRecordFree = pVBVA->indexRecordFree;
|
---|
178 |
|
---|
179 | LOGVBVABUFFER(("first = %d, free = %d\n",
|
---|
180 | indexRecordFirst, indexRecordFree));
|
---|
181 |
|
---|
182 | if (indexRecordFirst == indexRecordFree)
|
---|
183 | {
|
---|
184 | /* No records to process. Return without assigning output variables. */
|
---|
185 | return true;
|
---|
186 | }
|
---|
187 |
|
---|
188 | uint32_t cbRecordCurrent = ASMAtomicReadU32(&pVBVA->aRecords[indexRecordFirst].cbRecord);
|
---|
189 |
|
---|
190 | LOGVBVABUFFER(("cbRecord = 0x%08X, pPartialRecord->cb = 0x%08X\n", cbRecordCurrent, pPartialRecord->cb));
|
---|
191 |
|
---|
192 | uint32_t cbRecord = cbRecordCurrent & ~VBVA_F_RECORD_PARTIAL;
|
---|
193 |
|
---|
194 | if (pPartialRecord->cb)
|
---|
195 | {
|
---|
196 | /* There is a partial read in process. Continue with it. */
|
---|
197 | Assert (pPartialRecord->pu8);
|
---|
198 |
|
---|
199 | LOGVBVABUFFER(("continue partial record cb = %d cbRecord 0x%08X, first = %d, free = %d\n",
|
---|
200 | pPartialRecord->cb, cbRecordCurrent, indexRecordFirst, indexRecordFree));
|
---|
201 |
|
---|
202 | if (cbRecord > pPartialRecord->cb)
|
---|
203 | {
|
---|
204 | /* New data has been added to the record. */
|
---|
205 | if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
|
---|
206 | {
|
---|
207 | return false;
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | if (!(cbRecordCurrent & VBVA_F_RECORD_PARTIAL))
|
---|
212 | {
|
---|
213 | /* The record is completed by guest. Return it to the caller. */
|
---|
214 | *ppHdr = (VBVACMDHDR *)pPartialRecord->pu8;
|
---|
215 | *pcbCmd = pPartialRecord->cb;
|
---|
216 |
|
---|
217 | pPartialRecord->pu8 = NULL;
|
---|
218 | pPartialRecord->cb = 0;
|
---|
219 |
|
---|
220 | /* Advance the record index. */
|
---|
221 | pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
|
---|
222 |
|
---|
223 | LOGVBVABUFFER(("partial done ok, data = %d, free = %d\n",
|
---|
224 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
225 | }
|
---|
226 |
|
---|
227 | return true;
|
---|
228 | }
|
---|
229 |
|
---|
230 | /* A new record need to be processed. */
|
---|
231 | if (cbRecordCurrent & VBVA_F_RECORD_PARTIAL)
|
---|
232 | {
|
---|
233 | /* Current record is being written by guest. '=' is important here,
|
---|
234 | * because the guest will do a FLUSH at this condition.
|
---|
235 | * This partial record is too large for the ring buffer and must
|
---|
236 | * be accumulated in an allocated buffer.
|
---|
237 | */
|
---|
238 | if (cbRecord >= pVBVA->cbData - pVBVA->cbPartialWriteThreshold)
|
---|
239 | {
|
---|
240 | /* Partial read must be started. */
|
---|
241 | if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
|
---|
242 | {
|
---|
243 | return false;
|
---|
244 | }
|
---|
245 |
|
---|
246 | LOGVBVABUFFER(("started partial record cb = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
|
---|
247 | pPartialRecord->cb, cbRecordCurrent, indexRecordFirst, indexRecordFree));
|
---|
248 | }
|
---|
249 |
|
---|
250 | return true;
|
---|
251 | }
|
---|
252 |
|
---|
253 | /* Current record is complete. If it is not empty, process it. */
|
---|
254 | if (cbRecord)
|
---|
255 | {
|
---|
256 | /* The size of largest contiguous chunk in the ring biffer. */
|
---|
257 | uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
|
---|
258 |
|
---|
259 | /* The pointer to data in the ring buffer. */
|
---|
260 | uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
|
---|
261 |
|
---|
262 | /* Fetch or point the data. */
|
---|
263 | if (u32BytesTillBoundary >= cbRecord)
|
---|
264 | {
|
---|
265 | /* The command does not cross buffer boundary. Return address in the buffer. */
|
---|
266 | *ppHdr = (VBVACMDHDR *)src;
|
---|
267 |
|
---|
268 | /* Advance data offset. */
|
---|
269 | pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
|
---|
270 | }
|
---|
271 | else
|
---|
272 | {
|
---|
273 | /* The command crosses buffer boundary. Rare case, so not optimized. */
|
---|
274 | uint8_t *dst = (uint8_t *)RTMemAlloc (cbRecord);
|
---|
275 |
|
---|
276 | if (!dst)
|
---|
277 | {
|
---|
278 | LogFlowFunc (("could not allocate %d bytes from heap!!!\n", cbRecord));
|
---|
279 | pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
|
---|
280 | return false;
|
---|
281 | }
|
---|
282 |
|
---|
283 | vbvaFetchBytes (pVBVA, dst, cbRecord);
|
---|
284 |
|
---|
285 | *ppHdr = (VBVACMDHDR *)dst;
|
---|
286 |
|
---|
287 | LOGVBVABUFFER(("Allocated from heap %p\n", dst));
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | *pcbCmd = cbRecord;
|
---|
292 |
|
---|
293 | /* Advance the record index. */
|
---|
294 | pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
|
---|
295 |
|
---|
296 | LOGVBVABUFFER(("done ok, data = %d, free = %d\n",
|
---|
297 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
298 |
|
---|
299 | return true;
|
---|
300 | }
|
---|
301 |
|
---|
302 | static void vbvaReleaseCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR *pHdr, uint32_t cbCmd)
|
---|
303 | {
|
---|
304 | uint8_t *au8RingBuffer = &pVBVA->au8Data[0];
|
---|
305 |
|
---|
306 | if ( (uint8_t *)pHdr >= au8RingBuffer
|
---|
307 | && (uint8_t *)pHdr < &au8RingBuffer[pVBVA->cbData])
|
---|
308 | {
|
---|
309 | /* The pointer is inside ring buffer. Must be continuous chunk. */
|
---|
310 | Assert (pVBVA->cbData - ((uint8_t *)pHdr - au8RingBuffer) >= cbCmd);
|
---|
311 |
|
---|
312 | /* Do nothing. */
|
---|
313 |
|
---|
314 | Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
|
---|
315 | }
|
---|
316 | else
|
---|
317 | {
|
---|
318 | /* The pointer is outside. It is then an allocated copy. */
|
---|
319 | LOGVBVABUFFER(("Free heap %p\n", pHdr));
|
---|
320 |
|
---|
321 | if ((uint8_t *)pHdr == pPartialRecord->pu8)
|
---|
322 | {
|
---|
323 | pPartialRecord->pu8 = NULL;
|
---|
324 | pPartialRecord->cb = 0;
|
---|
325 | }
|
---|
326 | else
|
---|
327 | {
|
---|
328 | Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
|
---|
329 | }
|
---|
330 |
|
---|
331 | RTMemFree (pHdr);
|
---|
332 | }
|
---|
333 |
|
---|
334 | return;
|
---|
335 | }
|
---|
336 |
|
---|
337 | static int vbvaFlushProcess (unsigned uScreenId, PVGASTATE pVGAState, VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA)
|
---|
338 | {
|
---|
339 | LOGVBVABUFFER(("uScreenId %d, indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
|
---|
340 | uScreenId, pVBVA->indexRecordFirst, pVBVA->indexRecordFree, pVBVA->off32Data, pVBVA->off32Free));
|
---|
341 | struct {
|
---|
342 | /* The rectangle that includes all dirty rectangles. */
|
---|
343 | int32_t xLeft;
|
---|
344 | int32_t xRight;
|
---|
345 | int32_t yTop;
|
---|
346 | int32_t yBottom;
|
---|
347 | } dirtyRect;
|
---|
348 | RT_ZERO(dirtyRect);
|
---|
349 |
|
---|
350 | bool fUpdate = false; /* Whether there were any updates. */
|
---|
351 | bool fDirtyEmpty = true;
|
---|
352 |
|
---|
353 | for (;;)
|
---|
354 | {
|
---|
355 | VBVACMDHDR *phdr = NULL;
|
---|
356 | uint32_t cbCmd = ~0;
|
---|
357 |
|
---|
358 | /* Fetch the command data. */
|
---|
359 | if (!vbvaFetchCmd (pPartialRecord, pVBVA, &phdr, &cbCmd))
|
---|
360 | {
|
---|
361 | LogFunc(("unable to fetch command. off32Data = %d, off32Free = %d!!!\n",
|
---|
362 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
363 |
|
---|
364 | /* @todo old code disabled VBVA processing here. */
|
---|
365 | return VERR_NOT_SUPPORTED;
|
---|
366 | }
|
---|
367 |
|
---|
368 | if (cbCmd == uint32_t(~0))
|
---|
369 | {
|
---|
370 | /* No more commands yet in the queue. */
|
---|
371 | break;
|
---|
372 | }
|
---|
373 |
|
---|
374 | if (cbCmd != 0)
|
---|
375 | {
|
---|
376 | if (!fUpdate)
|
---|
377 | {
|
---|
378 | pVGAState->pDrv->pfnVBVAUpdateBegin (pVGAState->pDrv, uScreenId);
|
---|
379 | fUpdate = true;
|
---|
380 | }
|
---|
381 |
|
---|
382 | /* Updates the rectangle and sends the command to the VRDP server. */
|
---|
383 | pVGAState->pDrv->pfnVBVAUpdateProcess (pVGAState->pDrv, uScreenId, phdr, cbCmd);
|
---|
384 |
|
---|
385 | int32_t xRight = phdr->x + phdr->w;
|
---|
386 | int32_t yBottom = phdr->y + phdr->h;
|
---|
387 |
|
---|
388 | /* These are global coords, relative to the primary screen. */
|
---|
389 |
|
---|
390 | LOGVBVABUFFER(("cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
|
---|
391 | cbCmd, phdr->x, phdr->y, phdr->w, phdr->h));
|
---|
392 | LogRel3(("%s: update command cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
|
---|
393 | __PRETTY_FUNCTION__, cbCmd, phdr->x, phdr->y, phdr->w,
|
---|
394 | phdr->h));
|
---|
395 |
|
---|
396 | /* Collect all rects into one. */
|
---|
397 | if (fDirtyEmpty)
|
---|
398 | {
|
---|
399 | /* This is the first rectangle to be added. */
|
---|
400 | dirtyRect.xLeft = phdr->x;
|
---|
401 | dirtyRect.yTop = phdr->y;
|
---|
402 | dirtyRect.xRight = xRight;
|
---|
403 | dirtyRect.yBottom = yBottom;
|
---|
404 | fDirtyEmpty = false;
|
---|
405 | }
|
---|
406 | else
|
---|
407 | {
|
---|
408 | /* Adjust region coordinates. */
|
---|
409 | if (dirtyRect.xLeft > phdr->x)
|
---|
410 | {
|
---|
411 | dirtyRect.xLeft = phdr->x;
|
---|
412 | }
|
---|
413 |
|
---|
414 | if (dirtyRect.yTop > phdr->y)
|
---|
415 | {
|
---|
416 | dirtyRect.yTop = phdr->y;
|
---|
417 | }
|
---|
418 |
|
---|
419 | if (dirtyRect.xRight < xRight)
|
---|
420 | {
|
---|
421 | dirtyRect.xRight = xRight;
|
---|
422 | }
|
---|
423 |
|
---|
424 | if (dirtyRect.yBottom < yBottom)
|
---|
425 | {
|
---|
426 | dirtyRect.yBottom = yBottom;
|
---|
427 | }
|
---|
428 | }
|
---|
429 | }
|
---|
430 |
|
---|
431 | vbvaReleaseCmd (pPartialRecord, pVBVA, phdr, cbCmd);
|
---|
432 | }
|
---|
433 |
|
---|
434 | if (fUpdate)
|
---|
435 | {
|
---|
436 | if (dirtyRect.xRight - dirtyRect.xLeft)
|
---|
437 | {
|
---|
438 | LogRel3(("%s: sending update screen=%d, x=%d, y=%d, w=%d, h=%d\n",
|
---|
439 | __PRETTY_FUNCTION__, uScreenId, dirtyRect.xLeft,
|
---|
440 | dirtyRect.yTop, dirtyRect.xRight - dirtyRect.xLeft,
|
---|
441 | dirtyRect.yBottom - dirtyRect.yTop));
|
---|
442 | pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, dirtyRect.xLeft, dirtyRect.yTop,
|
---|
443 | dirtyRect.xRight - dirtyRect.xLeft, dirtyRect.yBottom - dirtyRect.yTop);
|
---|
444 | }
|
---|
445 | else
|
---|
446 | {
|
---|
447 | pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, 0, 0, 0, 0);
|
---|
448 | }
|
---|
449 | }
|
---|
450 |
|
---|
451 | return VINF_SUCCESS;
|
---|
452 | }
|
---|
453 |
|
---|
454 | static int vbvaFlush (PVGASTATE pVGAState, VBVACONTEXT *pCtx)
|
---|
455 | {
|
---|
456 | unsigned uScreenId;
|
---|
457 |
|
---|
458 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
459 | {
|
---|
460 | VBVAPARTIALRECORD *pPartialRecord = &pCtx->aViews[uScreenId].partialRecord;
|
---|
461 | VBVABUFFER *pVBVA = pCtx->aViews[uScreenId].pVBVA;
|
---|
462 |
|
---|
463 | if (pVBVA)
|
---|
464 | {
|
---|
465 | vbvaFlushProcess (uScreenId, pVGAState, pPartialRecord, pVBVA);
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | /* @todo rc */
|
---|
470 | return VINF_SUCCESS;
|
---|
471 | }
|
---|
472 |
|
---|
473 | static int vbvaResize (PVGASTATE pVGAState, VBVAVIEW *pView, const VBVAINFOSCREEN *pNewScreen)
|
---|
474 | {
|
---|
475 | /* Verify pNewScreen. */
|
---|
476 | /* @todo */
|
---|
477 |
|
---|
478 | /* Apply these changes. */
|
---|
479 | pView->screen = *pNewScreen;
|
---|
480 |
|
---|
481 | uint8_t *pu8VRAM = pVGAState->vram_ptrR3 + pView->view.u32ViewOffset;
|
---|
482 |
|
---|
483 | int rc = pVGAState->pDrv->pfnVBVAResize (pVGAState->pDrv, &pView->view, &pView->screen, pu8VRAM);
|
---|
484 |
|
---|
485 | /* @todo process VINF_VGA_RESIZE_IN_PROGRESS? */
|
---|
486 |
|
---|
487 | return rc;
|
---|
488 | }
|
---|
489 |
|
---|
490 | static int vbvaEnable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx, VBVABUFFER *pVBVA, uint32_t u32Offset, bool fRestored)
|
---|
491 | {
|
---|
492 | /* @todo old code did a UpdateDisplayAll at this place. */
|
---|
493 |
|
---|
494 | int rc;
|
---|
495 |
|
---|
496 | if (pVGAState->pDrv->pfnVBVAEnable)
|
---|
497 | {
|
---|
498 | pVBVA->hostFlags.u32HostEvents = 0;
|
---|
499 | pVBVA->hostFlags.u32SupportedOrders = 0;
|
---|
500 |
|
---|
501 | rc = pVGAState->pDrv->pfnVBVAEnable (pVGAState->pDrv, uScreenId, &pVBVA->hostFlags, false);
|
---|
502 | }
|
---|
503 | else
|
---|
504 | {
|
---|
505 | rc = VERR_NOT_SUPPORTED;
|
---|
506 | }
|
---|
507 |
|
---|
508 | if (RT_SUCCESS (rc))
|
---|
509 | {
|
---|
510 | /* pVBVA->hostFlags has been set up by pfnVBVAEnable. */
|
---|
511 | LogFlowFunc(("u32HostEvents 0x%08X, u32SupportedOrders 0x%08X\n",
|
---|
512 | pVBVA->hostFlags.u32HostEvents, pVBVA->hostFlags.u32SupportedOrders));
|
---|
513 |
|
---|
514 | if (!fRestored)
|
---|
515 | {
|
---|
516 | /* @todo Actually this function must not touch the partialRecord structure at all,
|
---|
517 | * because initially it is a zero and when VBVA is disabled this should be set to zero.
|
---|
518 | * But I'm not sure that no code depends on zeroing partialRecord here.
|
---|
519 | * So for now (a quick fix for 4.1) just do not do this if the VM was restored,
|
---|
520 | * when partialRecord might be loaded already from the saved state.
|
---|
521 | */
|
---|
522 | pCtx->aViews[uScreenId].partialRecord.pu8 = NULL;
|
---|
523 | pCtx->aViews[uScreenId].partialRecord.cb = 0;
|
---|
524 | }
|
---|
525 |
|
---|
526 | pCtx->aViews[uScreenId].pVBVA = pVBVA;
|
---|
527 | pCtx->aViews[uScreenId].u32VBVAOffset = u32Offset;
|
---|
528 |
|
---|
529 | /* VBVA is working so disable the pause. */
|
---|
530 | pCtx->fPaused = false;
|
---|
531 | }
|
---|
532 |
|
---|
533 | return rc;
|
---|
534 | }
|
---|
535 |
|
---|
536 | static int vbvaDisable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx)
|
---|
537 | {
|
---|
538 | /* Process any pending orders and empty the VBVA ring buffer. */
|
---|
539 | vbvaFlush (pVGAState, pCtx);
|
---|
540 |
|
---|
541 | VBVAVIEW *pView = &pCtx->aViews[uScreenId];
|
---|
542 |
|
---|
543 | if (pView->pVBVA)
|
---|
544 | {
|
---|
545 | pView->pVBVA->hostFlags.u32HostEvents = 0;
|
---|
546 | pView->pVBVA->hostFlags.u32SupportedOrders = 0;
|
---|
547 |
|
---|
548 | pView->partialRecord.pu8 = NULL;
|
---|
549 | pView->partialRecord.cb = 0;
|
---|
550 |
|
---|
551 | pView->pVBVA = NULL;
|
---|
552 | pView->u32VBVAOffset = HGSMIOFFSET_VOID;
|
---|
553 | }
|
---|
554 |
|
---|
555 | pVGAState->pDrv->pfnVBVADisable (pVGAState->pDrv, uScreenId);
|
---|
556 | return VINF_SUCCESS;
|
---|
557 | }
|
---|
558 |
|
---|
559 | bool VBVAIsEnabled(PVGASTATE pVGAState)
|
---|
560 | {
|
---|
561 | PHGSMIINSTANCE pHGSMI = pVGAState->pHGSMI;
|
---|
562 | if (pHGSMI)
|
---|
563 | {
|
---|
564 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext(pHGSMI);
|
---|
565 | if (pCtx)
|
---|
566 | {
|
---|
567 | if (pCtx->cViews)
|
---|
568 | {
|
---|
569 | VBVAVIEW * pView = &pCtx->aViews[0];
|
---|
570 | if (pView->pVBVA)
|
---|
571 | return true;
|
---|
572 | }
|
---|
573 | }
|
---|
574 | }
|
---|
575 | return false;
|
---|
576 | }
|
---|
577 |
|
---|
578 | #ifdef DEBUG_sunlover
|
---|
579 | void dumpMouseShapeInfo(const VBVAMOUSESHAPEINFO *pMouseShapeInfo)
|
---|
580 | {
|
---|
581 | LogFlow(("fSet = %d, fVisible %d, fAlpha %d, @%d,%d %dx%d (%p, %d/%d)\n",
|
---|
582 | pMouseShapeInfo->fSet,
|
---|
583 | pMouseShapeInfo->fVisible,
|
---|
584 | pMouseShapeInfo->fAlpha,
|
---|
585 | pMouseShapeInfo->u32HotX,
|
---|
586 | pMouseShapeInfo->u32HotY,
|
---|
587 | pMouseShapeInfo->u32Width,
|
---|
588 | pMouseShapeInfo->u32Height,
|
---|
589 | pMouseShapeInfo->pu8Shape,
|
---|
590 | pMouseShapeInfo->cbShape,
|
---|
591 | pMouseShapeInfo->cbAllocated
|
---|
592 | ));
|
---|
593 | }
|
---|
594 | #endif
|
---|
595 |
|
---|
596 | static int vbvaUpdateMousePointerShape(PVGASTATE pVGAState, VBVAMOUSESHAPEINFO *pMouseShapeInfo, bool fShape, const uint8_t *pu8Shape)
|
---|
597 | {
|
---|
598 | int rc;
|
---|
599 | LogFlowFunc(("pVGAState %p, pMouseShapeInfo %p, fShape %d, pu8Shape %p\n",
|
---|
600 | pVGAState, pMouseShapeInfo, fShape, pu8Shape));
|
---|
601 | #ifdef DEBUG_sunlover
|
---|
602 | dumpMouseShapeInfo(pMouseShapeInfo);
|
---|
603 | #endif
|
---|
604 |
|
---|
605 | if (fShape && pu8Shape != NULL)
|
---|
606 | {
|
---|
607 | rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
|
---|
608 | pMouseShapeInfo->fVisible,
|
---|
609 | pMouseShapeInfo->fAlpha,
|
---|
610 | pMouseShapeInfo->u32HotX,
|
---|
611 | pMouseShapeInfo->u32HotY,
|
---|
612 | pMouseShapeInfo->u32Width,
|
---|
613 | pMouseShapeInfo->u32Height,
|
---|
614 | pu8Shape);
|
---|
615 | }
|
---|
616 | else
|
---|
617 | {
|
---|
618 | rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
|
---|
619 | pMouseShapeInfo->fVisible,
|
---|
620 | false,
|
---|
621 | 0, 0,
|
---|
622 | 0, 0,
|
---|
623 | NULL);
|
---|
624 | }
|
---|
625 |
|
---|
626 | return rc;
|
---|
627 | }
|
---|
628 |
|
---|
629 | static int vbvaMousePointerShape (PVGASTATE pVGAState, VBVACONTEXT *pCtx, const VBVAMOUSEPOINTERSHAPE *pShape, HGSMISIZE cbShape)
|
---|
630 | {
|
---|
631 | bool fVisible = (pShape->fu32Flags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
|
---|
632 | bool fAlpha = (pShape->fu32Flags & VBOX_MOUSE_POINTER_ALPHA) != 0;
|
---|
633 | bool fShape = (pShape->fu32Flags & VBOX_MOUSE_POINTER_SHAPE) != 0;
|
---|
634 |
|
---|
635 | HGSMISIZE cbPointerData = 0;
|
---|
636 |
|
---|
637 | if (fShape)
|
---|
638 | {
|
---|
639 | if (pShape->u32Width > 8192 || pShape->u32Height > 8192)
|
---|
640 | {
|
---|
641 | Log(("vbvaMousePointerShape: unsupported size %ux%u\n",
|
---|
642 | pShape->u32Width, pShape->u32Height));
|
---|
643 | return VERR_INVALID_PARAMETER;
|
---|
644 | }
|
---|
645 |
|
---|
646 | cbPointerData = ((((pShape->u32Width + 7) / 8) * pShape->u32Height + 3) & ~3)
|
---|
647 | + pShape->u32Width * 4 * pShape->u32Height;
|
---|
648 | }
|
---|
649 |
|
---|
650 | if (cbPointerData > cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data))
|
---|
651 | {
|
---|
652 | Log(("vbvaMousePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
|
---|
653 | cbPointerData, cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data)));
|
---|
654 | return VERR_INVALID_PARAMETER;
|
---|
655 | }
|
---|
656 |
|
---|
657 | /* Save mouse info it will be used to restore mouse pointer after restoring saved state. */
|
---|
658 | pCtx->mouseShapeInfo.fSet = true;
|
---|
659 | pCtx->mouseShapeInfo.fVisible = fVisible;
|
---|
660 | pCtx->mouseShapeInfo.fAlpha = fAlpha;
|
---|
661 | if (fShape)
|
---|
662 | {
|
---|
663 | /* Data related to shape. */
|
---|
664 | pCtx->mouseShapeInfo.u32HotX = pShape->u32HotX;
|
---|
665 | pCtx->mouseShapeInfo.u32HotY = pShape->u32HotY;
|
---|
666 | pCtx->mouseShapeInfo.u32Width = pShape->u32Width;
|
---|
667 | pCtx->mouseShapeInfo.u32Height = pShape->u32Height;
|
---|
668 |
|
---|
669 | /* Reallocate memory buffer if necessary. */
|
---|
670 | if (cbPointerData > pCtx->mouseShapeInfo.cbAllocated)
|
---|
671 | {
|
---|
672 | RTMemFree (pCtx->mouseShapeInfo.pu8Shape);
|
---|
673 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
674 | pCtx->mouseShapeInfo.cbShape = 0;
|
---|
675 |
|
---|
676 | uint8_t *pu8Shape = (uint8_t *)RTMemAlloc (cbPointerData);
|
---|
677 | if (pu8Shape)
|
---|
678 | {
|
---|
679 | pCtx->mouseShapeInfo.pu8Shape = pu8Shape;
|
---|
680 | pCtx->mouseShapeInfo.cbAllocated = cbPointerData;
|
---|
681 | }
|
---|
682 | }
|
---|
683 |
|
---|
684 | /* Copy shape bitmaps. */
|
---|
685 | if (pCtx->mouseShapeInfo.pu8Shape)
|
---|
686 | {
|
---|
687 | memcpy (pCtx->mouseShapeInfo.pu8Shape, &pShape->au8Data[0], cbPointerData);
|
---|
688 | pCtx->mouseShapeInfo.cbShape = cbPointerData;
|
---|
689 | }
|
---|
690 | }
|
---|
691 |
|
---|
692 | if (pVGAState->pDrv->pfnVBVAMousePointerShape == NULL)
|
---|
693 | {
|
---|
694 | return VERR_NOT_SUPPORTED;
|
---|
695 | }
|
---|
696 |
|
---|
697 | int rc = vbvaUpdateMousePointerShape(pVGAState, &pCtx->mouseShapeInfo, fShape, &pShape->au8Data[0]);
|
---|
698 |
|
---|
699 | return rc;
|
---|
700 | }
|
---|
701 |
|
---|
702 | static unsigned vbvaViewFromOffset (PHGSMIINSTANCE pIns, VBVACONTEXT *pCtx, const void *pvBuffer)
|
---|
703 | {
|
---|
704 | /* Check which view contains the buffer. */
|
---|
705 | HGSMIOFFSET offBuffer = HGSMIPointerToOffsetHost (pIns, pvBuffer);
|
---|
706 |
|
---|
707 | if (offBuffer != HGSMIOFFSET_VOID)
|
---|
708 | {
|
---|
709 | unsigned uScreenId;
|
---|
710 |
|
---|
711 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
712 | {
|
---|
713 | VBVAINFOVIEW *pView = &pCtx->aViews[uScreenId].view;
|
---|
714 |
|
---|
715 | if ( pView->u32ViewSize > 0
|
---|
716 | && pView->u32ViewOffset <= offBuffer
|
---|
717 | && offBuffer <= pView->u32ViewOffset + pView->u32ViewSize - 1)
|
---|
718 | {
|
---|
719 | return pView->u32ViewIndex;
|
---|
720 | }
|
---|
721 | }
|
---|
722 | }
|
---|
723 |
|
---|
724 | return ~0U;
|
---|
725 | }
|
---|
726 |
|
---|
727 | #ifdef DEBUG_sunlover
|
---|
728 | static void dumpctx(const VBVACONTEXT *pCtx)
|
---|
729 | {
|
---|
730 | Log(("VBVACONTEXT dump: cViews %d\n", pCtx->cViews));
|
---|
731 |
|
---|
732 | uint32_t iView;
|
---|
733 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
734 | {
|
---|
735 | const VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
736 |
|
---|
737 | Log((" view %d o 0x%x s 0x%x m 0x%x\n",
|
---|
738 | pView->view.u32ViewIndex,
|
---|
739 | pView->view.u32ViewOffset,
|
---|
740 | pView->view.u32ViewSize,
|
---|
741 | pView->view.u32MaxScreenSize));
|
---|
742 |
|
---|
743 | Log((" screen %d @%d,%d s 0x%x l 0x%x %dx%d bpp %d f 0x%x\n",
|
---|
744 | pView->screen.u32ViewIndex,
|
---|
745 | pView->screen.i32OriginX,
|
---|
746 | pView->screen.i32OriginY,
|
---|
747 | pView->screen.u32StartOffset,
|
---|
748 | pView->screen.u32LineSize,
|
---|
749 | pView->screen.u32Width,
|
---|
750 | pView->screen.u32Height,
|
---|
751 | pView->screen.u16BitsPerPixel,
|
---|
752 | pView->screen.u16Flags));
|
---|
753 |
|
---|
754 | Log((" VBVA o 0x%x p %p\n",
|
---|
755 | pView->u32VBVAOffset,
|
---|
756 | pView->pVBVA));
|
---|
757 |
|
---|
758 | Log((" PR cb 0x%x p %p\n",
|
---|
759 | pView->partialRecord.cb,
|
---|
760 | pView->partialRecord.pu8));
|
---|
761 | }
|
---|
762 |
|
---|
763 | dumpMouseShapeInfo(&pCtx->mouseShapeInfo);
|
---|
764 | }
|
---|
765 | #endif /* DEBUG_sunlover */
|
---|
766 |
|
---|
767 | #define VBOXVBVASAVEDSTATE_VHWAAVAILABLE_MAGIC 0x12345678
|
---|
768 | #define VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC 0x9abcdef0
|
---|
769 |
|
---|
770 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
771 | static void vbvaVHWAHHCommandReinit(VBOXVHWACMD* pHdr, VBOXVHWACMD_TYPE enmCmd, int32_t iDisplay)
|
---|
772 | {
|
---|
773 | memset(pHdr, 0, VBOXVHWACMD_HEADSIZE());
|
---|
774 | pHdr->cRefs = 1;
|
---|
775 | pHdr->iDisplay = iDisplay;
|
---|
776 | pHdr->rc = VERR_NOT_IMPLEMENTED;
|
---|
777 | pHdr->enmCmd = enmCmd;
|
---|
778 | pHdr->Flags = VBOXVHWACMD_FLAG_HH_CMD;
|
---|
779 | }
|
---|
780 |
|
---|
781 | static VBOXVHWACMD* vbvaVHWAHHCommandCreate (PVGASTATE pVGAState, VBOXVHWACMD_TYPE enmCmd, int32_t iDisplay, VBOXVHWACMD_LENGTH cbCmd)
|
---|
782 | {
|
---|
783 | VBOXVHWACMD* pHdr = (VBOXVHWACMD*)RTMemAllocZ(cbCmd + VBOXVHWACMD_HEADSIZE());
|
---|
784 | Assert(pHdr);
|
---|
785 | if (pHdr)
|
---|
786 | vbvaVHWAHHCommandReinit(pHdr, enmCmd, iDisplay);
|
---|
787 |
|
---|
788 | return pHdr;
|
---|
789 | }
|
---|
790 |
|
---|
791 | DECLINLINE(void) vbvaVHWAHHCommandRelease (VBOXVHWACMD* pCmd)
|
---|
792 | {
|
---|
793 | uint32_t cRefs = ASMAtomicDecU32(&pCmd->cRefs);
|
---|
794 | if(!cRefs)
|
---|
795 | {
|
---|
796 | RTMemFree(pCmd);
|
---|
797 | }
|
---|
798 | }
|
---|
799 |
|
---|
800 | DECLINLINE(void) vbvaVHWAHHCommandRetain (VBOXVHWACMD* pCmd)
|
---|
801 | {
|
---|
802 | ASMAtomicIncU32(&pCmd->cRefs);
|
---|
803 | }
|
---|
804 |
|
---|
805 | static void vbvaVHWACommandComplete(PVGASTATE pVGAState, PVBOXVHWACMD pCommand, bool fAsyncCommand)
|
---|
806 | {
|
---|
807 | if (fAsyncCommand)
|
---|
808 | {
|
---|
809 | Assert(pCommand->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH);
|
---|
810 | vbvaVHWACommandCompleteAsync(&pVGAState->IVBVACallbacks, pCommand);
|
---|
811 | }
|
---|
812 | else
|
---|
813 | {
|
---|
814 | Log(("VGA Command <<< Sync rc %d %#p, %d\n", pCommand->rc, pCommand, pCommand->enmCmd));
|
---|
815 | pCommand->Flags &= (~VBOXVHWACMD_FLAG_HG_ASYNCH);
|
---|
816 | }
|
---|
817 |
|
---|
818 | }
|
---|
819 |
|
---|
820 | static void vbvaVHWACommandCompleteAllPending(PVGASTATE pVGAState, int rc)
|
---|
821 | {
|
---|
822 | if (!ASMAtomicUoReadU32(&pVGAState->pendingVhwaCommands.cPending))
|
---|
823 | return;
|
---|
824 |
|
---|
825 | VBOX_VHWA_PENDINGCMD *pIter, *pNext;
|
---|
826 |
|
---|
827 | PDMCritSectEnter(&pVGAState->CritSect, VERR_SEM_BUSY);
|
---|
828 |
|
---|
829 | RTListForEachSafe(&pVGAState->pendingVhwaCommands.PendingList, pIter, pNext, VBOX_VHWA_PENDINGCMD, Node)
|
---|
830 | {
|
---|
831 | pIter->pCommand->rc = rc;
|
---|
832 | vbvaVHWACommandComplete(pVGAState, pIter->pCommand, true);
|
---|
833 |
|
---|
834 | /* the command is submitted/processed, remove from the pend list */
|
---|
835 | RTListNodeRemove(&pIter->Node);
|
---|
836 | ASMAtomicDecU32(&pVGAState->pendingVhwaCommands.cPending);
|
---|
837 | RTMemFree(pIter);
|
---|
838 | }
|
---|
839 |
|
---|
840 | PDMCritSectLeave(&pVGAState->CritSect);
|
---|
841 | }
|
---|
842 |
|
---|
843 | static void vbvaVHWACommandClearAllPending(PVGASTATE pVGAState)
|
---|
844 | {
|
---|
845 | if (!ASMAtomicUoReadU32(&pVGAState->pendingVhwaCommands.cPending))
|
---|
846 | return;
|
---|
847 |
|
---|
848 | VBOX_VHWA_PENDINGCMD *pIter, *pNext;
|
---|
849 |
|
---|
850 | PDMCritSectEnter(&pVGAState->CritSect, VERR_SEM_BUSY);
|
---|
851 |
|
---|
852 | RTListForEachSafe(&pVGAState->pendingVhwaCommands.PendingList, pIter, pNext, VBOX_VHWA_PENDINGCMD, Node)
|
---|
853 | {
|
---|
854 | RTListNodeRemove(&pIter->Node);
|
---|
855 | ASMAtomicDecU32(&pVGAState->pendingVhwaCommands.cPending);
|
---|
856 | RTMemFree(pIter);
|
---|
857 | }
|
---|
858 |
|
---|
859 | PDMCritSectLeave(&pVGAState->CritSect);
|
---|
860 | }
|
---|
861 |
|
---|
862 | static void vbvaVHWACommandPend(PVGASTATE pVGAState, PVBOXVHWACMD pCommand)
|
---|
863 | {
|
---|
864 | int rc = VERR_BUFFER_OVERFLOW;
|
---|
865 |
|
---|
866 | if (ASMAtomicUoReadU32(&pVGAState->pendingVhwaCommands.cPending) < VBOX_VHWA_MAX_PENDING_COMMANDS)
|
---|
867 | {
|
---|
868 | VBOX_VHWA_PENDINGCMD *pPend = (VBOX_VHWA_PENDINGCMD*)RTMemAlloc(sizeof (*pPend));
|
---|
869 | if (pPend)
|
---|
870 | {
|
---|
871 | pCommand->Flags |= VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
872 | pPend->pCommand = pCommand;
|
---|
873 | PDMCritSectEnter(&pVGAState->CritSect, VERR_SEM_BUSY);
|
---|
874 | if (ASMAtomicUoReadU32(&pVGAState->pendingVhwaCommands.cPending) < VBOX_VHWA_MAX_PENDING_COMMANDS)
|
---|
875 | {
|
---|
876 | RTListAppend(&pVGAState->pendingVhwaCommands.PendingList, &pPend->Node);
|
---|
877 | ASMAtomicIncU32(&pVGAState->pendingVhwaCommands.cPending);
|
---|
878 | PDMCritSectLeave(&pVGAState->CritSect);
|
---|
879 | return;
|
---|
880 | }
|
---|
881 | PDMCritSectLeave(&pVGAState->CritSect);
|
---|
882 | LogRel(("Pending command count has reached its threshold.. completing them all.."));
|
---|
883 | RTMemFree(pPend);
|
---|
884 | }
|
---|
885 | else
|
---|
886 | rc = VERR_NO_MEMORY;
|
---|
887 | }
|
---|
888 | else
|
---|
889 | LogRel(("Pending command count has reached its threshold, completing them all.."));
|
---|
890 |
|
---|
891 | vbvaVHWACommandCompleteAllPending(pVGAState, rc);
|
---|
892 |
|
---|
893 | pCommand->rc = rc;
|
---|
894 |
|
---|
895 | vbvaVHWACommandComplete(pVGAState, pCommand, false);
|
---|
896 | }
|
---|
897 |
|
---|
898 | static bool vbvaVHWACommandCanPend(PVBOXVHWACMD pCommand)
|
---|
899 | {
|
---|
900 | switch (pCommand->enmCmd)
|
---|
901 | {
|
---|
902 | case VBOXVHWACMD_TYPE_HH_CONSTRUCT:
|
---|
903 | case VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEBEGIN:
|
---|
904 | case VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEEND:
|
---|
905 | case VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEPERFORM:
|
---|
906 | case VBOXVHWACMD_TYPE_HH_SAVESTATE_LOADPERFORM:
|
---|
907 | return false;
|
---|
908 | default:
|
---|
909 | return true;
|
---|
910 | }
|
---|
911 | }
|
---|
912 |
|
---|
913 | static int vbvaVHWACommandSavePending(PVGASTATE pVGAState, PSSMHANDLE pSSM)
|
---|
914 | {
|
---|
915 | int rc = SSMR3PutU32(pSSM, pVGAState->pendingVhwaCommands.cPending);
|
---|
916 | AssertRCReturn(rc, rc);
|
---|
917 | VBOX_VHWA_PENDINGCMD *pIter;
|
---|
918 | RTListForEach(&pVGAState->pendingVhwaCommands.PendingList, pIter, VBOX_VHWA_PENDINGCMD, Node)
|
---|
919 | {
|
---|
920 | rc = SSMR3PutU32(pSSM, (uint32_t)(((uint8_t*)pIter->pCommand) - ((uint8_t*)pVGAState->vram_ptrR3)));
|
---|
921 | AssertRCReturn(rc, rc);
|
---|
922 | }
|
---|
923 | return rc;
|
---|
924 | }
|
---|
925 |
|
---|
926 | static int vbvaVHWACommandLoadPending(PVGASTATE pVGAState, PSSMHANDLE pSSM, uint32_t u32Version)
|
---|
927 | {
|
---|
928 | if (u32Version < VGA_SAVEDSTATE_VERSION_WITH_PENDVHWA)
|
---|
929 | return VINF_SUCCESS;
|
---|
930 |
|
---|
931 | int rc;
|
---|
932 | uint32_t u32;
|
---|
933 | rc = SSMR3GetU32(pSSM, &u32);
|
---|
934 | AssertRCReturn(rc, rc);
|
---|
935 | for (uint32_t i = 0; i < u32; ++i)
|
---|
936 | {
|
---|
937 | uint32_t off32;
|
---|
938 | rc = SSMR3GetU32(pSSM, &off32);
|
---|
939 | AssertRCReturn(rc, rc);
|
---|
940 | PVBOXVHWACMD pCommand = (PVBOXVHWACMD)(((uint8_t*)pVGAState->vram_ptrR3) + off32);
|
---|
941 | vbvaVHWACommandPend(pVGAState, pCommand);
|
---|
942 | }
|
---|
943 | return rc;
|
---|
944 | }
|
---|
945 |
|
---|
946 |
|
---|
947 | static bool vbvaVHWACommandSubmit(PVGASTATE pVGAState, PVBOXVHWACMD pCommand, bool fAsyncCommand)
|
---|
948 | {
|
---|
949 | unsigned id = (unsigned)pCommand->iDisplay;
|
---|
950 | bool fPend = false;
|
---|
951 |
|
---|
952 | if (pVGAState->pDrv->pfnVHWACommandProcess)
|
---|
953 | {
|
---|
954 | Log(("VGA Command >>> %#p, %d\n", pCommand, pCommand->enmCmd));
|
---|
955 | int rc = pVGAState->pDrv->pfnVHWACommandProcess(pVGAState->pDrv, pCommand);
|
---|
956 | if (rc == VINF_CALLBACK_RETURN)
|
---|
957 | {
|
---|
958 | Log(("VGA Command --- Going Async %#p, %d\n", pCommand, pCommand->enmCmd));
|
---|
959 | return true; /* command will be completed asynchronously, return right away */
|
---|
960 | }
|
---|
961 | else if (rc == VERR_INVALID_STATE)
|
---|
962 | {
|
---|
963 | Log(("VGA Command --- Trying Pend %#p, %d\n", pCommand, pCommand->enmCmd));
|
---|
964 | fPend = vbvaVHWACommandCanPend(pCommand);
|
---|
965 | if (!fPend)
|
---|
966 | {
|
---|
967 | Log(("VGA Command --- Can NOT Pend %#p, %d\n", pCommand, pCommand->enmCmd));
|
---|
968 | pCommand->rc = rc;
|
---|
969 | }
|
---|
970 | else
|
---|
971 | Log(("VGA Command --- Can Pend %#p, %d\n", pCommand, pCommand->enmCmd));
|
---|
972 | }
|
---|
973 | else
|
---|
974 | {
|
---|
975 | Log(("VGA Command --- Going Complete Sync rc %d %#p, %d\n", rc, pCommand, pCommand->enmCmd));
|
---|
976 | pCommand->rc = rc;
|
---|
977 | }
|
---|
978 |
|
---|
979 | /* the command was completed, take a special care about it (seee below) */
|
---|
980 | }
|
---|
981 | else
|
---|
982 | {
|
---|
983 | AssertFailed();
|
---|
984 | pCommand->rc = VERR_INVALID_STATE;
|
---|
985 | }
|
---|
986 |
|
---|
987 | if (fPend)
|
---|
988 | return false;
|
---|
989 |
|
---|
990 | vbvaVHWACommandComplete(pVGAState, pCommand, fAsyncCommand);
|
---|
991 |
|
---|
992 | return true;
|
---|
993 | }
|
---|
994 |
|
---|
995 | static bool vbvaVHWACheckPendingCommands(PVGASTATE pVGAState)
|
---|
996 | {
|
---|
997 | if (!ASMAtomicUoReadU32(&pVGAState->pendingVhwaCommands.cPending))
|
---|
998 | return true;
|
---|
999 |
|
---|
1000 | VBOX_VHWA_PENDINGCMD *pIter, *pNext;
|
---|
1001 |
|
---|
1002 | PDMCritSectEnter(&pVGAState->CritSect, VERR_SEM_BUSY);
|
---|
1003 |
|
---|
1004 | RTListForEachSafe(&pVGAState->pendingVhwaCommands.PendingList, pIter, pNext, VBOX_VHWA_PENDINGCMD, Node)
|
---|
1005 | {
|
---|
1006 | if (!vbvaVHWACommandSubmit(pVGAState, pIter->pCommand, true))
|
---|
1007 | {
|
---|
1008 | PDMCritSectLeave(&pVGAState->CritSect);
|
---|
1009 | return false; /* the command should be pended still */
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | /* the command is submitted/processed, remove from the pend list */
|
---|
1013 | RTListNodeRemove(&pIter->Node);
|
---|
1014 | ASMAtomicDecU32(&pVGAState->pendingVhwaCommands.cPending);
|
---|
1015 | RTMemFree(pIter);
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | PDMCritSectLeave(&pVGAState->CritSect);
|
---|
1019 |
|
---|
1020 | return true;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | void vbvaTimerCb(PVGASTATE pVGAState)
|
---|
1024 | {
|
---|
1025 | vbvaVHWACheckPendingCommands(pVGAState);
|
---|
1026 | }
|
---|
1027 | static void vbvaVHWAHandleCommand(PVGASTATE pVGAState, PVBOXVHWACMD pCmd)
|
---|
1028 | {
|
---|
1029 | if (vbvaVHWACheckPendingCommands(pVGAState))
|
---|
1030 | {
|
---|
1031 | if (vbvaVHWACommandSubmit(pVGAState, pCmd, false))
|
---|
1032 | return;
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | vbvaVHWACommandPend(pVGAState, pCmd);
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | static DECLCALLBACK(void) vbvaVHWAHHCommandSetEventCallback(void * pContext)
|
---|
1039 | {
|
---|
1040 | RTSemEventSignal((RTSEMEVENT)pContext);
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | static int vbvaVHWAHHCommandPost(PVGASTATE pVGAState, VBOXVHWACMD* pCmd)
|
---|
1044 | {
|
---|
1045 | RTSEMEVENT hComplEvent;
|
---|
1046 | int rc = RTSemEventCreate(&hComplEvent);
|
---|
1047 | AssertRC(rc);
|
---|
1048 | if(RT_SUCCESS(rc))
|
---|
1049 | {
|
---|
1050 | /* ensure the cmd is not deleted until we process it */
|
---|
1051 | vbvaVHWAHHCommandRetain (pCmd);
|
---|
1052 | VBOXVHWA_HH_CALLBACK_SET(pCmd, vbvaVHWAHHCommandSetEventCallback, (void*)hComplEvent);
|
---|
1053 | vbvaVHWAHandleCommand(pVGAState, pCmd);
|
---|
1054 | if((ASMAtomicReadU32((volatile uint32_t *)&pCmd->Flags) & VBOXVHWACMD_FLAG_HG_ASYNCH) != 0)
|
---|
1055 | {
|
---|
1056 | rc = RTSemEventWaitNoResume(hComplEvent, RT_INDEFINITE_WAIT);
|
---|
1057 | }
|
---|
1058 | else
|
---|
1059 | {
|
---|
1060 | /* the command is completed */
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | AssertRC(rc);
|
---|
1064 | if(RT_SUCCESS(rc))
|
---|
1065 | {
|
---|
1066 | RTSemEventDestroy(hComplEvent);
|
---|
1067 | }
|
---|
1068 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
1069 | }
|
---|
1070 | return rc;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | int vbvaVHWAConstruct (PVGASTATE pVGAState)
|
---|
1074 | {
|
---|
1075 | pVGAState->pendingVhwaCommands.cPending = 0;
|
---|
1076 | RTListInit(&pVGAState->pendingVhwaCommands.PendingList);
|
---|
1077 |
|
---|
1078 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_CONSTRUCT, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
|
---|
1079 | Assert(pCmd);
|
---|
1080 | if(pCmd)
|
---|
1081 | {
|
---|
1082 | uint32_t iDisplay = 0;
|
---|
1083 | int rc = VINF_SUCCESS;
|
---|
1084 | VBOXVHWACMD_HH_CONSTRUCT * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_CONSTRUCT);
|
---|
1085 |
|
---|
1086 | do
|
---|
1087 | {
|
---|
1088 | memset(pBody, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
|
---|
1089 |
|
---|
1090 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
1091 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
1092 |
|
---|
1093 | pBody->pVM = pVM;
|
---|
1094 | pBody->pvVRAM = pVGAState->vram_ptrR3;
|
---|
1095 | pBody->cbVRAM = pVGAState->vram_size;
|
---|
1096 |
|
---|
1097 | rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
1098 | AssertRC(rc);
|
---|
1099 | if(RT_SUCCESS(rc))
|
---|
1100 | {
|
---|
1101 | rc = pCmd->rc;
|
---|
1102 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
1103 | if(rc == VERR_NOT_IMPLEMENTED)
|
---|
1104 | {
|
---|
1105 | /* @todo: set some flag in pVGAState indicating VHWA is not supported */
|
---|
1106 | /* VERR_NOT_IMPLEMENTED is not a failure, we just do not support it */
|
---|
1107 | rc = VINF_SUCCESS;
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | if (!RT_SUCCESS(rc))
|
---|
1111 | break;
|
---|
1112 | }
|
---|
1113 | else
|
---|
1114 | break;
|
---|
1115 |
|
---|
1116 | ++iDisplay;
|
---|
1117 | if (iDisplay >= pVGAState->cMonitors)
|
---|
1118 | break;
|
---|
1119 | vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_CONSTRUCT, (int32_t)iDisplay);
|
---|
1120 | } while (true);
|
---|
1121 |
|
---|
1122 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
1123 |
|
---|
1124 | return rc;
|
---|
1125 | }
|
---|
1126 | return VERR_OUT_OF_RESOURCES;
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | int vbvaVHWAReset (PVGASTATE pVGAState)
|
---|
1130 | {
|
---|
1131 | vbvaVHWACommandClearAllPending(pVGAState);
|
---|
1132 |
|
---|
1133 | /* ensure we have all pending cmds processed and h->g cmds disabled */
|
---|
1134 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_RESET, 0, 0);
|
---|
1135 | Assert(pCmd);
|
---|
1136 | if(pCmd)
|
---|
1137 | {
|
---|
1138 | int rc = VINF_SUCCESS;
|
---|
1139 | uint32_t iDisplay = 0;
|
---|
1140 |
|
---|
1141 | do
|
---|
1142 | {
|
---|
1143 | rc =vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
1144 | AssertRC(rc);
|
---|
1145 | if(RT_SUCCESS(rc))
|
---|
1146 | {
|
---|
1147 | rc = pCmd->rc;
|
---|
1148 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
1149 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
1150 | rc = VINF_SUCCESS;
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | if (!RT_SUCCESS(rc))
|
---|
1154 | break;
|
---|
1155 |
|
---|
1156 | ++iDisplay;
|
---|
1157 | if (iDisplay >= pVGAState->cMonitors)
|
---|
1158 | break;
|
---|
1159 | vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_RESET, (int32_t)iDisplay);
|
---|
1160 |
|
---|
1161 | } while (true);
|
---|
1162 |
|
---|
1163 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
1164 |
|
---|
1165 | return rc;
|
---|
1166 | }
|
---|
1167 | return VERR_OUT_OF_RESOURCES;
|
---|
1168 | }
|
---|
1169 |
|
---|
1170 | typedef DECLCALLBACK(bool) FNVBOXVHWAHHCMDPRECB(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, void *pvContext);
|
---|
1171 | typedef FNVBOXVHWAHHCMDPRECB *PFNVBOXVHWAHHCMDPRECB;
|
---|
1172 |
|
---|
1173 | typedef DECLCALLBACK(bool) FNVBOXVHWAHHCMDPOSTCB(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, int rc, void *pvContext);
|
---|
1174 | typedef FNVBOXVHWAHHCMDPOSTCB *PFNVBOXVHWAHHCMDPOSTCB;
|
---|
1175 |
|
---|
1176 | int vbvaVHWAHHPost(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, PFNVBOXVHWAHHCMDPRECB pfnPre, PFNVBOXVHWAHHCMDPOSTCB pfnPost, void *pvContext)
|
---|
1177 | {
|
---|
1178 | const VBOXVHWACMD_TYPE enmType = pCmd->enmCmd;
|
---|
1179 | int rc = VINF_SUCCESS;
|
---|
1180 | uint32_t iDisplay = 0;
|
---|
1181 |
|
---|
1182 | do
|
---|
1183 | {
|
---|
1184 | if (!pfnPre || pfnPre(pVGAState, pCmd, iDisplay, pvContext))
|
---|
1185 | {
|
---|
1186 | rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
1187 | AssertRC(rc);
|
---|
1188 | if (pfnPost)
|
---|
1189 | {
|
---|
1190 | if (!pfnPost(pVGAState, pCmd, iDisplay, rc, pvContext))
|
---|
1191 | {
|
---|
1192 | rc = VINF_SUCCESS;
|
---|
1193 | break;
|
---|
1194 | }
|
---|
1195 | rc = VINF_SUCCESS;
|
---|
1196 | }
|
---|
1197 | else if(RT_SUCCESS(rc))
|
---|
1198 | {
|
---|
1199 | rc = pCmd->rc;
|
---|
1200 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
1201 | if(rc == VERR_NOT_IMPLEMENTED)
|
---|
1202 | {
|
---|
1203 | rc = VINF_SUCCESS;
|
---|
1204 | }
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | if (!RT_SUCCESS(rc))
|
---|
1208 | break;
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | ++iDisplay;
|
---|
1212 | if (iDisplay >= pVGAState->cMonitors)
|
---|
1213 | break;
|
---|
1214 | vbvaVHWAHHCommandReinit(pCmd, enmType, (int32_t)iDisplay);
|
---|
1215 | } while (true);
|
---|
1216 |
|
---|
1217 | return rc;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | /* @todo call this also on reset? */
|
---|
1221 | int vbvaVHWAEnable (PVGASTATE pVGAState, bool bEnable)
|
---|
1222 | {
|
---|
1223 | const VBOXVHWACMD_TYPE enmType = bEnable ? VBOXVHWACMD_TYPE_HH_ENABLE : VBOXVHWACMD_TYPE_HH_DISABLE;
|
---|
1224 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState,
|
---|
1225 | enmType,
|
---|
1226 | 0, 0);
|
---|
1227 | Assert(pCmd);
|
---|
1228 | if(pCmd)
|
---|
1229 | {
|
---|
1230 | int rc = vbvaVHWAHHPost (pVGAState, pCmd, NULL, NULL, NULL);
|
---|
1231 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
1232 | return rc;
|
---|
1233 | }
|
---|
1234 | return VERR_OUT_OF_RESOURCES;
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | int vboxVBVASaveStatePrep (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
1238 | {
|
---|
1239 | /* ensure we have no pending commands */
|
---|
1240 | return vbvaVHWAEnable(PDMINS_2_DATA(pDevIns, PVGASTATE), false);
|
---|
1241 | }
|
---|
1242 |
|
---|
1243 | int vboxVBVASaveStateDone (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
1244 | {
|
---|
1245 | /* ensure we have no pending commands */
|
---|
1246 | return vbvaVHWAEnable(PDMINS_2_DATA(pDevIns, PVGASTATE), true);
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | int vbvaVHWACommandCompleteAsync(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVHWACMD pCmd)
|
---|
1250 | {
|
---|
1251 | int rc;
|
---|
1252 | Log(("VGA Command <<< Async rc %d %#p, %d\n", pCmd->rc, pCmd, pCmd->enmCmd));
|
---|
1253 |
|
---|
1254 | if((pCmd->Flags & VBOXVHWACMD_FLAG_HH_CMD) == 0)
|
---|
1255 | {
|
---|
1256 | PVGASTATE pVGAState = PPDMIDISPLAYVBVACALLBACKS_2_PVGASTATE(pInterface);
|
---|
1257 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1258 |
|
---|
1259 | Assert(pCmd->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH);
|
---|
1260 | #ifdef VBOX_WITH_WDDM
|
---|
1261 | if (pVGAState->fGuestCaps & VBVACAPS_COMPLETEGCMD_BY_IOREAD)
|
---|
1262 | {
|
---|
1263 | rc = HGSMICompleteGuestCommand(pIns, pCmd, !!(pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ));
|
---|
1264 | AssertRC(rc);
|
---|
1265 | }
|
---|
1266 | else
|
---|
1267 | #endif
|
---|
1268 | {
|
---|
1269 | VBVAHOSTCMD *pHostCmd;
|
---|
1270 | int32_t iDisplay = pCmd->iDisplay;
|
---|
1271 |
|
---|
1272 | if(pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_EVENT)
|
---|
1273 | {
|
---|
1274 | rc = HGSMIHostCommandAlloc (pIns,
|
---|
1275 | (void**)&pHostCmd,
|
---|
1276 | VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDEVENT)),
|
---|
1277 | HGSMI_CH_VBVA,
|
---|
1278 | VBVAHG_EVENT);
|
---|
1279 | AssertRC(rc);
|
---|
1280 | if(RT_SUCCESS(rc))
|
---|
1281 | {
|
---|
1282 | memset(pHostCmd, 0 , VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDEVENT)));
|
---|
1283 | pHostCmd->iDstID = pCmd->iDisplay;
|
---|
1284 | pHostCmd->customOpCode = 0;
|
---|
1285 | VBVAHOSTCMDEVENT *pBody = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDEVENT);
|
---|
1286 | pBody->pEvent = pCmd->GuestVBVAReserved1;
|
---|
1287 | }
|
---|
1288 | }
|
---|
1289 | else
|
---|
1290 | {
|
---|
1291 | HGSMIOFFSET offCmd = HGSMIPointerToOffsetHost (pIns, pCmd);
|
---|
1292 | Assert(offCmd != HGSMIOFFSET_VOID);
|
---|
1293 | if(offCmd != HGSMIOFFSET_VOID)
|
---|
1294 | {
|
---|
1295 | rc = HGSMIHostCommandAlloc (pIns,
|
---|
1296 | (void**)&pHostCmd,
|
---|
1297 | VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDVHWACMDCOMPLETE)),
|
---|
1298 | HGSMI_CH_VBVA,
|
---|
1299 | VBVAHG_DISPLAY_CUSTOM);
|
---|
1300 | AssertRC(rc);
|
---|
1301 | if(RT_SUCCESS(rc))
|
---|
1302 | {
|
---|
1303 | memset(pHostCmd, 0 , VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDVHWACMDCOMPLETE)));
|
---|
1304 | pHostCmd->iDstID = pCmd->iDisplay;
|
---|
1305 | pHostCmd->customOpCode = VBVAHG_DCUSTOM_VHWA_CMDCOMPLETE;
|
---|
1306 | VBVAHOSTCMDVHWACMDCOMPLETE *pBody = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDVHWACMDCOMPLETE);
|
---|
1307 | pBody->offCmd = offCmd;
|
---|
1308 | }
|
---|
1309 | }
|
---|
1310 | else
|
---|
1311 | {
|
---|
1312 | rc = VERR_INVALID_PARAMETER;
|
---|
1313 | }
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | if(RT_SUCCESS(rc))
|
---|
1317 | {
|
---|
1318 | rc = HGSMIHostCommandSubmitAndFreeAsynch(pIns, pHostCmd, RT_BOOL(pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ));
|
---|
1319 | AssertRC(rc);
|
---|
1320 | if(RT_SUCCESS(rc))
|
---|
1321 | {
|
---|
1322 | return rc;
|
---|
1323 | }
|
---|
1324 | HGSMIHostCommandFree (pIns, pHostCmd);
|
---|
1325 | }
|
---|
1326 | }
|
---|
1327 | }
|
---|
1328 | else
|
---|
1329 | {
|
---|
1330 | PFNVBOXVHWA_HH_CALLBACK pfn = VBOXVHWA_HH_CALLBACK_GET(pCmd);
|
---|
1331 | if(pfn)
|
---|
1332 | {
|
---|
1333 | pfn(VBOXVHWA_HH_CALLBACK_GET_ARG(pCmd));
|
---|
1334 | }
|
---|
1335 | rc = VINF_SUCCESS;
|
---|
1336 | }
|
---|
1337 | return rc;
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | typedef struct VBOXVBVASAVEDSTATECBDATA
|
---|
1341 | {
|
---|
1342 | PSSMHANDLE pSSM;
|
---|
1343 | int rc;
|
---|
1344 | bool ab2DOn[VBOX_VIDEO_MAX_SCREENS];
|
---|
1345 | } VBOXVBVASAVEDSTATECBDATA, *PVBOXVBVASAVEDSTATECBDATA;
|
---|
1346 |
|
---|
1347 | static DECLCALLBACK(bool) vboxVBVASaveStateBeginPostCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, int rc, void *pvContext)
|
---|
1348 | {
|
---|
1349 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1350 | if (RT_FAILURE(pData->rc))
|
---|
1351 | return false;
|
---|
1352 | if (RT_FAILURE(rc))
|
---|
1353 | {
|
---|
1354 | pData->rc = rc;
|
---|
1355 | return false;
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1359 | if (iDisplay >= RT_ELEMENTS(pData->ab2DOn))
|
---|
1360 | {
|
---|
1361 | pData->rc = VERR_INVALID_PARAMETER;
|
---|
1362 | return false;
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | Assert(RT_SUCCESS(pCmd->rc) || pCmd->rc == VERR_NOT_IMPLEMENTED);
|
---|
1366 | if (RT_SUCCESS(pCmd->rc))
|
---|
1367 | {
|
---|
1368 | pData->ab2DOn[iDisplay] = true;
|
---|
1369 | }
|
---|
1370 | else if (pCmd->rc != VERR_NOT_IMPLEMENTED)
|
---|
1371 | {
|
---|
1372 | pData->rc = pCmd->rc;
|
---|
1373 | return false;
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | return true;
|
---|
1377 | }
|
---|
1378 |
|
---|
1379 | static DECLCALLBACK(bool) vboxVBVASaveStatePerformPreCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, void *pvContext)
|
---|
1380 | {
|
---|
1381 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1382 | if (RT_FAILURE(pData->rc))
|
---|
1383 | return false;
|
---|
1384 |
|
---|
1385 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1386 | if (iDisplay >= RT_ELEMENTS(pData->ab2DOn))
|
---|
1387 | {
|
---|
1388 | pData->rc = VERR_INVALID_PARAMETER;
|
---|
1389 | return false;
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 | int rc;
|
---|
1393 |
|
---|
1394 | if (pData->ab2DOn[iDisplay])
|
---|
1395 | {
|
---|
1396 | rc = SSMR3PutU32 (pData->pSSM, VBOXVBVASAVEDSTATE_VHWAAVAILABLE_MAGIC); AssertRC(rc);
|
---|
1397 | if (RT_FAILURE(rc))
|
---|
1398 | {
|
---|
1399 | pData->rc = rc;
|
---|
1400 | return false;
|
---|
1401 | }
|
---|
1402 | return true;
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | rc = SSMR3PutU32 (pData->pSSM, VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC); AssertRC(rc);
|
---|
1406 | if (RT_FAILURE(rc))
|
---|
1407 | {
|
---|
1408 | pData->rc = rc;
|
---|
1409 | return false;
|
---|
1410 | }
|
---|
1411 |
|
---|
1412 | return false;
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 | static DECLCALLBACK(bool) vboxVBVASaveStateEndPreCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, void *pvContext)
|
---|
1416 | {
|
---|
1417 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1418 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1419 | if (pData->ab2DOn[iDisplay])
|
---|
1420 | {
|
---|
1421 | return true;
|
---|
1422 | }
|
---|
1423 |
|
---|
1424 | return false;
|
---|
1425 | }
|
---|
1426 |
|
---|
1427 | static DECLCALLBACK(bool) vboxVBVALoadStatePerformPostCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, int rc, void *pvContext)
|
---|
1428 | {
|
---|
1429 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1430 | if (RT_FAILURE(pData->rc))
|
---|
1431 | return false;
|
---|
1432 | if (RT_FAILURE(rc))
|
---|
1433 | {
|
---|
1434 | pData->rc = rc;
|
---|
1435 | return false;
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1439 | if (iDisplay >= RT_ELEMENTS(pData->ab2DOn))
|
---|
1440 | {
|
---|
1441 | pData->rc = VERR_INVALID_PARAMETER;
|
---|
1442 | return false;
|
---|
1443 | }
|
---|
1444 |
|
---|
1445 | Assert(RT_SUCCESS(pCmd->rc) || pCmd->rc == VERR_NOT_IMPLEMENTED);
|
---|
1446 | if (pCmd->rc == VERR_NOT_IMPLEMENTED)
|
---|
1447 | {
|
---|
1448 | pData->rc = SSMR3SkipToEndOfUnit(pData->pSSM);
|
---|
1449 | AssertRC(pData->rc);
|
---|
1450 | return false;
|
---|
1451 | }
|
---|
1452 | if (RT_FAILURE(pCmd->rc))
|
---|
1453 | {
|
---|
1454 | pData->rc = pCmd->rc;
|
---|
1455 | return false;
|
---|
1456 | }
|
---|
1457 |
|
---|
1458 | return true;
|
---|
1459 | }
|
---|
1460 |
|
---|
1461 | static DECLCALLBACK(bool) vboxVBVALoadStatePerformPreCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, void *pvContext)
|
---|
1462 | {
|
---|
1463 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1464 | if (RT_FAILURE(pData->rc))
|
---|
1465 | return false;
|
---|
1466 |
|
---|
1467 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1468 | if (iDisplay >= RT_ELEMENTS(pData->ab2DOn))
|
---|
1469 | {
|
---|
1470 | pData->rc = VERR_INVALID_PARAMETER;
|
---|
1471 | return false;
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | int rc;
|
---|
1475 | uint32_t u32;
|
---|
1476 | rc = SSMR3GetU32(pData->pSSM, &u32); AssertRC(rc);
|
---|
1477 | if (RT_FAILURE(rc))
|
---|
1478 | {
|
---|
1479 | pData->rc = rc;
|
---|
1480 | return false;
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 | switch (u32)
|
---|
1484 | {
|
---|
1485 | case VBOXVBVASAVEDSTATE_VHWAAVAILABLE_MAGIC:
|
---|
1486 | pData->ab2DOn[iDisplay] = true;
|
---|
1487 | return true;
|
---|
1488 | case VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC:
|
---|
1489 | pData->ab2DOn[iDisplay] = false;
|
---|
1490 | return false;
|
---|
1491 | default:
|
---|
1492 | pData->rc = VERR_INVALID_STATE;
|
---|
1493 | return false;
|
---|
1494 | }
|
---|
1495 | }
|
---|
1496 | #endif /* #ifdef VBOX_WITH_VIDEOHWACCEL */
|
---|
1497 |
|
---|
1498 | int vboxVBVASaveDevStateExec (PVGASTATE pVGAState, PSSMHANDLE pSSM)
|
---|
1499 | {
|
---|
1500 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1501 | int rc = HGSMIHostSaveStateExec (pIns, pSSM);
|
---|
1502 | if (RT_SUCCESS(rc))
|
---|
1503 | {
|
---|
1504 | /* Save VBVACONTEXT. */
|
---|
1505 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
1506 |
|
---|
1507 | if (!pCtx)
|
---|
1508 | {
|
---|
1509 | AssertFailed();
|
---|
1510 |
|
---|
1511 | /* Still write a valid value to the SSM. */
|
---|
1512 | rc = SSMR3PutU32 (pSSM, 0);
|
---|
1513 | AssertRCReturn(rc, rc);
|
---|
1514 | }
|
---|
1515 | else
|
---|
1516 | {
|
---|
1517 | #ifdef DEBUG_sunlover
|
---|
1518 | dumpctx(pCtx);
|
---|
1519 | #endif
|
---|
1520 |
|
---|
1521 | rc = SSMR3PutU32 (pSSM, pCtx->cViews);
|
---|
1522 | AssertRCReturn(rc, rc);
|
---|
1523 |
|
---|
1524 | uint32_t iView;
|
---|
1525 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
1526 | {
|
---|
1527 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
1528 |
|
---|
1529 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewIndex);
|
---|
1530 | AssertRCReturn(rc, rc);
|
---|
1531 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewOffset);
|
---|
1532 | AssertRCReturn(rc, rc);
|
---|
1533 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewSize);
|
---|
1534 | AssertRCReturn(rc, rc);
|
---|
1535 | rc = SSMR3PutU32 (pSSM, pView->view.u32MaxScreenSize);
|
---|
1536 | AssertRCReturn(rc, rc);
|
---|
1537 |
|
---|
1538 | rc = SSMR3PutU32 (pSSM, pView->screen.u32ViewIndex);
|
---|
1539 | AssertRCReturn(rc, rc);
|
---|
1540 | rc = SSMR3PutS32 (pSSM, pView->screen.i32OriginX);
|
---|
1541 | AssertRCReturn(rc, rc);
|
---|
1542 | rc = SSMR3PutS32 (pSSM, pView->screen.i32OriginY);
|
---|
1543 | AssertRCReturn(rc, rc);
|
---|
1544 | rc = SSMR3PutU32 (pSSM, pView->screen.u32StartOffset);
|
---|
1545 | AssertRCReturn(rc, rc);
|
---|
1546 | rc = SSMR3PutU32 (pSSM, pView->screen.u32LineSize);
|
---|
1547 | AssertRCReturn(rc, rc);
|
---|
1548 | rc = SSMR3PutU32 (pSSM, pView->screen.u32Width);
|
---|
1549 | AssertRCReturn(rc, rc);
|
---|
1550 | rc = SSMR3PutU32 (pSSM, pView->screen.u32Height);
|
---|
1551 | AssertRCReturn(rc, rc);
|
---|
1552 | rc = SSMR3PutU16 (pSSM, pView->screen.u16BitsPerPixel);
|
---|
1553 | AssertRCReturn(rc, rc);
|
---|
1554 | rc = SSMR3PutU16 (pSSM, pView->screen.u16Flags);
|
---|
1555 | AssertRCReturn(rc, rc);
|
---|
1556 |
|
---|
1557 | rc = SSMR3PutU32 (pSSM, pView->pVBVA? pView->u32VBVAOffset: HGSMIOFFSET_VOID);
|
---|
1558 | AssertRCReturn(rc, rc);
|
---|
1559 |
|
---|
1560 | rc = SSMR3PutU32 (pSSM, pView->partialRecord.cb);
|
---|
1561 | AssertRCReturn(rc, rc);
|
---|
1562 |
|
---|
1563 | if (pView->partialRecord.cb > 0)
|
---|
1564 | {
|
---|
1565 | rc = SSMR3PutMem (pSSM, pView->partialRecord.pu8, pView->partialRecord.cb);
|
---|
1566 | AssertRCReturn(rc, rc);
|
---|
1567 | }
|
---|
1568 | }
|
---|
1569 |
|
---|
1570 | /* Save mouse pointer shape information. */
|
---|
1571 | rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fSet);
|
---|
1572 | AssertRCReturn(rc, rc);
|
---|
1573 | rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fVisible);
|
---|
1574 | AssertRCReturn(rc, rc);
|
---|
1575 | rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fAlpha);
|
---|
1576 | AssertRCReturn(rc, rc);
|
---|
1577 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32HotX);
|
---|
1578 | AssertRCReturn(rc, rc);
|
---|
1579 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32HotY);
|
---|
1580 | AssertRCReturn(rc, rc);
|
---|
1581 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32Width);
|
---|
1582 | AssertRCReturn(rc, rc);
|
---|
1583 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32Height);
|
---|
1584 | AssertRCReturn(rc, rc);
|
---|
1585 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.cbShape);
|
---|
1586 | AssertRCReturn(rc, rc);
|
---|
1587 | if (pCtx->mouseShapeInfo.cbShape)
|
---|
1588 | {
|
---|
1589 | rc = SSMR3PutMem (pSSM, pCtx->mouseShapeInfo.pu8Shape, pCtx->mouseShapeInfo.cbShape);
|
---|
1590 | AssertRCReturn(rc, rc);
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | #ifdef VBOX_WITH_WDDM
|
---|
1594 | /* Size of some additional data. For future extensions. */
|
---|
1595 | rc = SSMR3PutU32 (pSSM, 4);
|
---|
1596 | AssertRCReturn(rc, rc);
|
---|
1597 | rc = SSMR3PutU32 (pSSM, pVGAState->fGuestCaps);
|
---|
1598 | AssertRCReturn(rc, rc);
|
---|
1599 | #else
|
---|
1600 | /* Size of some additional data. For future extensions. */
|
---|
1601 | rc = SSMR3PutU32 (pSSM, 0);
|
---|
1602 | AssertRCReturn(rc, rc);
|
---|
1603 | #endif
|
---|
1604 | rc = SSMR3PutU32 (pSSM, RT_ELEMENTS(pCtx->aModeHints));
|
---|
1605 | AssertRCReturn(rc, rc);
|
---|
1606 | rc = SSMR3PutU32 (pSSM, sizeof(VBVAMODEHINT));
|
---|
1607 | AssertRCReturn(rc, rc);
|
---|
1608 | for (unsigned i = 0; i < RT_ELEMENTS(pCtx->aModeHints); ++i)
|
---|
1609 | {
|
---|
1610 | rc = SSMR3PutMem (pSSM, &pCtx->aModeHints[i],
|
---|
1611 | sizeof(VBVAMODEHINT));
|
---|
1612 | AssertRCReturn(rc, rc);
|
---|
1613 | }
|
---|
1614 | }
|
---|
1615 | }
|
---|
1616 |
|
---|
1617 | return rc;
|
---|
1618 | }
|
---|
1619 |
|
---|
1620 | int vboxVBVASaveStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
1621 | {
|
---|
1622 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
1623 | int rc;
|
---|
1624 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1625 | VBOXVBVASAVEDSTATECBDATA VhwaData = {0};
|
---|
1626 | VhwaData.pSSM = pSSM;
|
---|
1627 | uint32_t cbCmd = sizeof (VBOXVHWACMD_HH_SAVESTATE_SAVEPERFORM); /* maximum cmd size */
|
---|
1628 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEBEGIN, 0, cbCmd);
|
---|
1629 | Assert(pCmd);
|
---|
1630 | if(pCmd)
|
---|
1631 | {
|
---|
1632 | vbvaVHWAHHPost (pVGAState, pCmd, NULL, vboxVBVASaveStateBeginPostCb, &VhwaData);
|
---|
1633 | rc = VhwaData.rc;
|
---|
1634 | AssertRC(rc);
|
---|
1635 | if (RT_SUCCESS(rc))
|
---|
1636 | {
|
---|
1637 | #endif
|
---|
1638 | rc = vboxVBVASaveDevStateExec (pVGAState, pSSM);
|
---|
1639 | AssertRC(rc);
|
---|
1640 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1641 | if (RT_SUCCESS(rc))
|
---|
1642 | {
|
---|
1643 | vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEPERFORM, 0);
|
---|
1644 | VBOXVHWACMD_HH_SAVESTATE_SAVEPERFORM *pSave = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_SAVESTATE_SAVEPERFORM);
|
---|
1645 | pSave->pSSM = pSSM;
|
---|
1646 | vbvaVHWAHHPost (pVGAState, pCmd, vboxVBVASaveStatePerformPreCb, NULL, &VhwaData);
|
---|
1647 | rc = VhwaData.rc;
|
---|
1648 | AssertRC(rc);
|
---|
1649 | if (RT_SUCCESS(rc))
|
---|
1650 | {
|
---|
1651 | rc = vbvaVHWACommandSavePending(pVGAState, pSSM);
|
---|
1652 | AssertRCReturn(rc, rc);
|
---|
1653 |
|
---|
1654 | vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEEND, 0);
|
---|
1655 | vbvaVHWAHHPost (pVGAState, pCmd, vboxVBVASaveStateEndPreCb, NULL, &VhwaData);
|
---|
1656 | rc = VhwaData.rc;
|
---|
1657 | AssertRC(rc);
|
---|
1658 | }
|
---|
1659 | }
|
---|
1660 | }
|
---|
1661 |
|
---|
1662 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
1663 | }
|
---|
1664 | else
|
---|
1665 | rc = VERR_OUT_OF_RESOURCES;
|
---|
1666 | #else
|
---|
1667 | if (RT_SUCCESS(rc))
|
---|
1668 | {
|
---|
1669 | for (uint32_t i = 0; i < pVGAState->cMonitors; ++i)
|
---|
1670 | {
|
---|
1671 | rc = SSMR3PutU32 (pSSM, VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC);
|
---|
1672 | AssertRCReturn(rc, rc);
|
---|
1673 | }
|
---|
1674 | }
|
---|
1675 |
|
---|
1676 | /* no pending commands */
|
---|
1677 | SSMR3PutU32(pSSM, 0);
|
---|
1678 | #endif
|
---|
1679 | return rc;
|
---|
1680 | }
|
---|
1681 |
|
---|
1682 | int vboxVBVALoadStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
|
---|
1683 | {
|
---|
1684 | if (u32Version < VGA_SAVEDSTATE_VERSION_HGSMI)
|
---|
1685 | {
|
---|
1686 | /* Nothing was saved. */
|
---|
1687 | return VINF_SUCCESS;
|
---|
1688 | }
|
---|
1689 |
|
---|
1690 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
1691 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1692 | int rc = HGSMIHostLoadStateExec (pIns, pSSM, u32Version);
|
---|
1693 | if (RT_SUCCESS(rc))
|
---|
1694 | {
|
---|
1695 | /* Load VBVACONTEXT. */
|
---|
1696 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
1697 |
|
---|
1698 | if (!pCtx)
|
---|
1699 | {
|
---|
1700 | /* This should not happen. */
|
---|
1701 | AssertFailed();
|
---|
1702 | rc = VERR_INVALID_PARAMETER;
|
---|
1703 | }
|
---|
1704 | else
|
---|
1705 | {
|
---|
1706 | uint32_t cViews = 0;
|
---|
1707 | rc = SSMR3GetU32 (pSSM, &cViews);
|
---|
1708 | AssertRCReturn(rc, rc);
|
---|
1709 |
|
---|
1710 | uint32_t iView;
|
---|
1711 | for (iView = 0; iView < cViews; iView++)
|
---|
1712 | {
|
---|
1713 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
1714 |
|
---|
1715 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewIndex);
|
---|
1716 | AssertRCReturn(rc, rc);
|
---|
1717 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewOffset);
|
---|
1718 | AssertRCReturn(rc, rc);
|
---|
1719 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewSize);
|
---|
1720 | AssertRCReturn(rc, rc);
|
---|
1721 | rc = SSMR3GetU32 (pSSM, &pView->view.u32MaxScreenSize);
|
---|
1722 | AssertRCReturn(rc, rc);
|
---|
1723 |
|
---|
1724 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32ViewIndex);
|
---|
1725 | AssertRCReturn(rc, rc);
|
---|
1726 | rc = SSMR3GetS32 (pSSM, &pView->screen.i32OriginX);
|
---|
1727 | AssertRCReturn(rc, rc);
|
---|
1728 | rc = SSMR3GetS32 (pSSM, &pView->screen.i32OriginY);
|
---|
1729 | AssertRCReturn(rc, rc);
|
---|
1730 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32StartOffset);
|
---|
1731 | AssertRCReturn(rc, rc);
|
---|
1732 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32LineSize);
|
---|
1733 | AssertRCReturn(rc, rc);
|
---|
1734 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32Width);
|
---|
1735 | AssertRCReturn(rc, rc);
|
---|
1736 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32Height);
|
---|
1737 | AssertRCReturn(rc, rc);
|
---|
1738 | rc = SSMR3GetU16 (pSSM, &pView->screen.u16BitsPerPixel);
|
---|
1739 | AssertRCReturn(rc, rc);
|
---|
1740 | rc = SSMR3GetU16 (pSSM, &pView->screen.u16Flags);
|
---|
1741 | AssertRCReturn(rc, rc);
|
---|
1742 |
|
---|
1743 | rc = SSMR3GetU32 (pSSM, &pView->u32VBVAOffset);
|
---|
1744 | AssertRCReturn(rc, rc);
|
---|
1745 |
|
---|
1746 | rc = SSMR3GetU32 (pSSM, &pView->partialRecord.cb);
|
---|
1747 | AssertRCReturn(rc, rc);
|
---|
1748 |
|
---|
1749 | if (pView->partialRecord.cb == 0)
|
---|
1750 | {
|
---|
1751 | pView->partialRecord.pu8 = NULL;
|
---|
1752 | }
|
---|
1753 | else
|
---|
1754 | {
|
---|
1755 | Assert(pView->partialRecord.pu8 == NULL); /* Should be it. */
|
---|
1756 |
|
---|
1757 | uint8_t *pu8 = (uint8_t *)RTMemAlloc (pView->partialRecord.cb);
|
---|
1758 |
|
---|
1759 | if (!pu8)
|
---|
1760 | {
|
---|
1761 | return VERR_NO_MEMORY;
|
---|
1762 | }
|
---|
1763 |
|
---|
1764 | pView->partialRecord.pu8 = pu8;
|
---|
1765 |
|
---|
1766 | rc = SSMR3GetMem (pSSM, pView->partialRecord.pu8, pView->partialRecord.cb);
|
---|
1767 | AssertRCReturn(rc, rc);
|
---|
1768 | }
|
---|
1769 |
|
---|
1770 | if (pView->u32VBVAOffset == HGSMIOFFSET_VOID)
|
---|
1771 | {
|
---|
1772 | pView->pVBVA = NULL;
|
---|
1773 | }
|
---|
1774 | else
|
---|
1775 | {
|
---|
1776 | pView->pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, pView->u32VBVAOffset);
|
---|
1777 | }
|
---|
1778 | }
|
---|
1779 |
|
---|
1780 | if (u32Version > VGA_SAVEDSTATE_VERSION_WITH_CONFIG)
|
---|
1781 | {
|
---|
1782 | /* Read mouse pointer shape information. */
|
---|
1783 | rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fSet);
|
---|
1784 | AssertRCReturn(rc, rc);
|
---|
1785 | rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fVisible);
|
---|
1786 | AssertRCReturn(rc, rc);
|
---|
1787 | rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fAlpha);
|
---|
1788 | AssertRCReturn(rc, rc);
|
---|
1789 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32HotX);
|
---|
1790 | AssertRCReturn(rc, rc);
|
---|
1791 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32HotY);
|
---|
1792 | AssertRCReturn(rc, rc);
|
---|
1793 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32Width);
|
---|
1794 | AssertRCReturn(rc, rc);
|
---|
1795 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32Height);
|
---|
1796 | AssertRCReturn(rc, rc);
|
---|
1797 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.cbShape);
|
---|
1798 | AssertRCReturn(rc, rc);
|
---|
1799 | if (pCtx->mouseShapeInfo.cbShape)
|
---|
1800 | {
|
---|
1801 | pCtx->mouseShapeInfo.pu8Shape = (uint8_t *)RTMemAlloc(pCtx->mouseShapeInfo.cbShape);
|
---|
1802 | if (pCtx->mouseShapeInfo.pu8Shape == NULL)
|
---|
1803 | {
|
---|
1804 | return VERR_NO_MEMORY;
|
---|
1805 | }
|
---|
1806 | pCtx->mouseShapeInfo.cbAllocated = pCtx->mouseShapeInfo.cbShape;
|
---|
1807 | rc = SSMR3GetMem (pSSM, pCtx->mouseShapeInfo.pu8Shape, pCtx->mouseShapeInfo.cbShape);
|
---|
1808 | AssertRCReturn(rc, rc);
|
---|
1809 | }
|
---|
1810 | else
|
---|
1811 | {
|
---|
1812 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
1813 | }
|
---|
1814 |
|
---|
1815 | /* Size of some additional data. For future extensions. */
|
---|
1816 | uint32_t cbExtra = 0;
|
---|
1817 | rc = SSMR3GetU32 (pSSM, &cbExtra);
|
---|
1818 | AssertRCReturn(rc, rc);
|
---|
1819 | #ifdef VBOX_WITH_WDDM
|
---|
1820 | if (cbExtra >= 4)
|
---|
1821 | {
|
---|
1822 | rc = SSMR3GetU32 (pSSM, &pVGAState->fGuestCaps);
|
---|
1823 | AssertRCReturn(rc, rc);
|
---|
1824 | pVGAState->pDrv->pfnVBVAGuestCapabilityUpdate(pVGAState->pDrv, pVGAState->fGuestCaps);
|
---|
1825 | cbExtra -= 4;
|
---|
1826 | }
|
---|
1827 | #endif
|
---|
1828 | if (cbExtra > 0)
|
---|
1829 | {
|
---|
1830 | rc = SSMR3Skip(pSSM, cbExtra);
|
---|
1831 | AssertRCReturn(rc, rc);
|
---|
1832 | }
|
---|
1833 |
|
---|
1834 | if (u32Version >= VGA_SAVEDSTATE_VERSION_MODE_HINTS)
|
---|
1835 | {
|
---|
1836 | uint32_t cModeHints, cbModeHints;
|
---|
1837 | rc = SSMR3GetU32 (pSSM, &cModeHints);
|
---|
1838 | AssertRCReturn(rc, rc);
|
---|
1839 | rc = SSMR3GetU32 (pSSM, &cbModeHints);
|
---|
1840 | AssertRCReturn(rc, rc);
|
---|
1841 | memset(&pCtx->aModeHints, ~0, sizeof(pCtx->aModeHints));
|
---|
1842 | unsigned iHint;
|
---|
1843 | for (iHint = 0; iHint < cModeHints; ++iHint)
|
---|
1844 | {
|
---|
1845 | if ( cbModeHints <= sizeof(VBVAMODEHINT)
|
---|
1846 | && iHint < RT_ELEMENTS(pCtx->aModeHints))
|
---|
1847 | rc = SSMR3GetMem(pSSM, &pCtx->aModeHints[iHint],
|
---|
1848 | cbModeHints);
|
---|
1849 | else
|
---|
1850 | rc = SSMR3Skip(pSSM, cbModeHints);
|
---|
1851 | AssertRCReturn(rc, rc);
|
---|
1852 | }
|
---|
1853 | }
|
---|
1854 | }
|
---|
1855 |
|
---|
1856 | pCtx->cViews = iView;
|
---|
1857 | LogFlowFunc(("%d views loaded\n", pCtx->cViews));
|
---|
1858 |
|
---|
1859 | if (u32Version > VGA_SAVEDSTATE_VERSION_WDDM)
|
---|
1860 | {
|
---|
1861 | bool fLoadCommands;
|
---|
1862 |
|
---|
1863 | if (u32Version < VGA_SAVEDSTATE_VERSION_FIXED_PENDVHWA)
|
---|
1864 | {
|
---|
1865 | const char *pcszOsArch = SSMR3HandleHostOSAndArch(pSSM);
|
---|
1866 | Assert(pcszOsArch);
|
---|
1867 | fLoadCommands = !pcszOsArch || RTStrNCmp(pcszOsArch, RT_STR_TUPLE("solaris"));
|
---|
1868 | }
|
---|
1869 | else
|
---|
1870 | fLoadCommands = true;
|
---|
1871 |
|
---|
1872 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1873 | uint32_t cbCmd = sizeof (VBOXVHWACMD_HH_SAVESTATE_LOADPERFORM); /* maximum cmd size */
|
---|
1874 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_SAVESTATE_LOADPERFORM, 0, cbCmd);
|
---|
1875 | Assert(pCmd);
|
---|
1876 | if(pCmd)
|
---|
1877 | {
|
---|
1878 | VBOXVBVASAVEDSTATECBDATA VhwaData = {0};
|
---|
1879 | VhwaData.pSSM = pSSM;
|
---|
1880 | VBOXVHWACMD_HH_SAVESTATE_LOADPERFORM *pLoad = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_SAVESTATE_LOADPERFORM);
|
---|
1881 | pLoad->pSSM = pSSM;
|
---|
1882 | vbvaVHWAHHPost (pVGAState, pCmd, vboxVBVALoadStatePerformPreCb, vboxVBVALoadStatePerformPostCb, &VhwaData);
|
---|
1883 | rc = VhwaData.rc;
|
---|
1884 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
1885 | AssertRCReturn(rc, rc);
|
---|
1886 |
|
---|
1887 | if (fLoadCommands)
|
---|
1888 | {
|
---|
1889 | rc = vbvaVHWACommandLoadPending(pVGAState, pSSM, u32Version);
|
---|
1890 | AssertRCReturn(rc, rc);
|
---|
1891 | }
|
---|
1892 | }
|
---|
1893 | else
|
---|
1894 | {
|
---|
1895 | rc = VERR_OUT_OF_RESOURCES;
|
---|
1896 | }
|
---|
1897 | #else
|
---|
1898 | uint32_t u32;
|
---|
1899 |
|
---|
1900 | for (uint32_t i = 0; i < pVGAState->cMonitors; ++i)
|
---|
1901 | {
|
---|
1902 | rc = SSMR3GetU32(pSSM, &u32);
|
---|
1903 | AssertRCReturn(rc, rc);
|
---|
1904 |
|
---|
1905 | if (u32 != VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC)
|
---|
1906 | {
|
---|
1907 | LogRel(("2D data while 2D is not supported\n"));
|
---|
1908 | return VERR_NOT_SUPPORTED;
|
---|
1909 | }
|
---|
1910 | }
|
---|
1911 |
|
---|
1912 | if (fLoadCommands)
|
---|
1913 | {
|
---|
1914 | rc = SSMR3GetU32(pSSM, &u32);
|
---|
1915 | AssertRCReturn(rc, rc);
|
---|
1916 |
|
---|
1917 | if (u32)
|
---|
1918 | {
|
---|
1919 | LogRel(("2D pending command while 2D is not supported\n"));
|
---|
1920 | return VERR_NOT_SUPPORTED;
|
---|
1921 | }
|
---|
1922 | }
|
---|
1923 | #endif
|
---|
1924 | }
|
---|
1925 |
|
---|
1926 | #ifdef DEBUG_sunlover
|
---|
1927 | dumpctx(pCtx);
|
---|
1928 | #endif
|
---|
1929 | }
|
---|
1930 | }
|
---|
1931 |
|
---|
1932 | return rc;
|
---|
1933 | }
|
---|
1934 |
|
---|
1935 | int vboxVBVALoadStateDone (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
1936 | {
|
---|
1937 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
1938 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
1939 |
|
---|
1940 | if (pCtx)
|
---|
1941 | {
|
---|
1942 | uint32_t iView;
|
---|
1943 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
1944 | {
|
---|
1945 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
1946 |
|
---|
1947 | if (pView->pVBVA)
|
---|
1948 | {
|
---|
1949 | #ifdef VBOX_WITH_CRHGSMI
|
---|
1950 | Assert(!vboxCmdVBVAIsEnabled(pVGAState));
|
---|
1951 | #endif
|
---|
1952 | vbvaEnable (iView, pVGAState, pCtx, pView->pVBVA, pView->u32VBVAOffset, true /* fRestored */);
|
---|
1953 | vbvaResize (pVGAState, pView, &pView->screen);
|
---|
1954 | }
|
---|
1955 | }
|
---|
1956 |
|
---|
1957 | if (pCtx->mouseShapeInfo.fSet)
|
---|
1958 | {
|
---|
1959 | vbvaUpdateMousePointerShape(pVGAState, &pCtx->mouseShapeInfo, true, pCtx->mouseShapeInfo.pu8Shape);
|
---|
1960 | }
|
---|
1961 | }
|
---|
1962 |
|
---|
1963 | return VINF_SUCCESS;
|
---|
1964 | }
|
---|
1965 |
|
---|
1966 | void VBVARaiseIrq (PVGASTATE pVGAState, uint32_t fFlags)
|
---|
1967 | {
|
---|
1968 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
1969 | PDMCritSectEnter(&pVGAState->CritSect, VERR_SEM_BUSY);
|
---|
1970 |
|
---|
1971 | HGSMISetHostGuestFlags(pVGAState->pHGSMI, HGSMIHOSTFLAGS_IRQ | fFlags);
|
---|
1972 | PDMDevHlpPCISetIrq(pDevIns, 0, PDM_IRQ_LEVEL_HIGH);
|
---|
1973 |
|
---|
1974 | PDMCritSectLeave(&pVGAState->CritSect);
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 | static DECLCALLBACK(int) vbvaRaiseIrqEMT(PVGASTATE pVGAState, uint32_t fFlags)
|
---|
1978 | {
|
---|
1979 | VBVARaiseIrq(pVGAState, fFlags);
|
---|
1980 | return VINF_SUCCESS;
|
---|
1981 | }
|
---|
1982 |
|
---|
1983 | void VBVARaiseIrqNoWait(PVGASTATE pVGAState, uint32_t fFlags)
|
---|
1984 | {
|
---|
1985 | /* we can not use PDMDevHlpPCISetIrqNoWait here, because we need to set IRG host flag and raise IRQ atomically,
|
---|
1986 | * otherwise there might be a situation, when:
|
---|
1987 | * 1. Flag is set
|
---|
1988 | * 2. guest issues an IRQ clean request, that cleans up the flag and the interrupt
|
---|
1989 | * 3. IRQ is set */
|
---|
1990 | VMR3ReqCallNoWait(PDMDevHlpGetVM(pVGAState->pDevInsR3), VMCPUID_ANY, (PFNRT)vbvaRaiseIrqEMT, 2, pVGAState, fFlags);
|
---|
1991 | }
|
---|
1992 |
|
---|
1993 | int VBVAInfoView(PVGASTATE pVGAState, VBVAINFOVIEW *pView)
|
---|
1994 | {
|
---|
1995 | LogFlowFunc(("VBVA_INFO_VIEW: index %d, offset 0x%x, size 0x%x, max screen size 0x%x\n",
|
---|
1996 | pView->u32ViewIndex, pView->u32ViewOffset, pView->u32ViewSize, pView->u32MaxScreenSize));
|
---|
1997 |
|
---|
1998 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1999 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
2000 |
|
---|
2001 | /* @todo verify view data. */
|
---|
2002 | if (pView->u32ViewIndex >= pCtx->cViews)
|
---|
2003 | {
|
---|
2004 | Log(("View index too large %d!!!\n",
|
---|
2005 | pView->u32ViewIndex));
|
---|
2006 | return VERR_INVALID_PARAMETER;
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | pCtx->aViews[pView->u32ViewIndex].view = *pView;
|
---|
2010 |
|
---|
2011 | return VINF_SUCCESS;
|
---|
2012 | }
|
---|
2013 |
|
---|
2014 | int VBVAInfoScreen(PVGASTATE pVGAState, VBVAINFOSCREEN *pScreen)
|
---|
2015 | {
|
---|
2016 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
2017 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
2018 | VBVAINFOVIEW *pView = &pCtx->aViews[pScreen->u32ViewIndex].view;
|
---|
2019 | /* Calculate the offset of the end of the screen so we can make
|
---|
2020 | * sure it is inside the view. I assume that screen rollover is not
|
---|
2021 | * implemented. */
|
---|
2022 | int64_t offEnd = (int64_t)pScreen->u32Height * pScreen->u32LineSize
|
---|
2023 | + pScreen->u32Width + pScreen->u32StartOffset;
|
---|
2024 | LogRel(("VBVA_INFO_SCREEN: [%d] @%d,%d %dx%d, line 0x%x, BPP %d, flags 0x%x\n",
|
---|
2025 | pScreen->u32ViewIndex, pScreen->i32OriginX, pScreen->i32OriginY,
|
---|
2026 | pScreen->u32Width, pScreen->u32Height,
|
---|
2027 | pScreen->u32LineSize, pScreen->u16BitsPerPixel, pScreen->u16Flags));
|
---|
2028 |
|
---|
2029 | if ( pScreen->u32ViewIndex < RT_ELEMENTS (pCtx->aViews)
|
---|
2030 | && pScreen->u16BitsPerPixel <= 32
|
---|
2031 | && pScreen->u32Width <= UINT16_MAX
|
---|
2032 | && pScreen->u32Height <= UINT16_MAX
|
---|
2033 | && pScreen->u32LineSize <= UINT16_MAX * 4
|
---|
2034 | && offEnd < pView->u32MaxScreenSize)
|
---|
2035 | {
|
---|
2036 | vbvaResize (pVGAState, &pCtx->aViews[pScreen->u32ViewIndex], pScreen);
|
---|
2037 | return VINF_SUCCESS;
|
---|
2038 | }
|
---|
2039 |
|
---|
2040 | LogRelFlow(("VBVA_INFO_SCREEN [%lu]: bad data: %lux%lu, line 0x%lx, BPP %u, start offset %lu, max screen size %lu\n",
|
---|
2041 | (unsigned long)pScreen->u32ViewIndex,
|
---|
2042 | (unsigned long)pScreen->u32Width,
|
---|
2043 | (unsigned long)pScreen->u32Height,
|
---|
2044 | (unsigned long)pScreen->u32LineSize,
|
---|
2045 | (unsigned long)pScreen->u16BitsPerPixel,
|
---|
2046 | (unsigned long)pScreen->u32StartOffset,
|
---|
2047 | (unsigned long)pView->u32MaxScreenSize));
|
---|
2048 | return VERR_INVALID_PARAMETER;
|
---|
2049 | }
|
---|
2050 |
|
---|
2051 | int VBVAGetInfoViewAndScreen(PVGASTATE pVGAState, uint32_t u32ViewIndex, VBVAINFOVIEW *pView, VBVAINFOSCREEN *pScreen)
|
---|
2052 | {
|
---|
2053 | if (u32ViewIndex >= pVGAState->cMonitors)
|
---|
2054 | return VERR_INVALID_PARAMETER;
|
---|
2055 |
|
---|
2056 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
2057 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
2058 |
|
---|
2059 | if (pView)
|
---|
2060 | *pView = pCtx->aViews[u32ViewIndex].view;
|
---|
2061 |
|
---|
2062 | if (pScreen)
|
---|
2063 | *pScreen = pCtx->aViews[u32ViewIndex].screen;
|
---|
2064 |
|
---|
2065 | return VINF_SUCCESS;
|
---|
2066 | }
|
---|
2067 |
|
---|
2068 |
|
---|
2069 | /*
|
---|
2070 | *
|
---|
2071 | * New VBVA uses a new interface id: #define VBE_DISPI_ID_VBOX_VIDEO 0xBE01
|
---|
2072 | *
|
---|
2073 | * VBVA uses two 32 bits IO ports to write VRAM offsets of shared memory blocks for commands.
|
---|
2074 | * Read Write
|
---|
2075 | * Host port 0x3b0 to process completed
|
---|
2076 | * Guest port 0x3d0 control value? to process
|
---|
2077 | *
|
---|
2078 | */
|
---|
2079 |
|
---|
2080 | static DECLCALLBACK(void) vbvaNotifyGuest (void *pvCallback)
|
---|
2081 | {
|
---|
2082 | #if defined(VBOX_WITH_HGSMI) && (defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_VDMA) || defined(VBOX_WITH_WDDM))
|
---|
2083 | PVGASTATE pVGAState = (PVGASTATE)pvCallback;
|
---|
2084 | VBVARaiseIrqNoWait (pVGAState, 0);
|
---|
2085 | #else
|
---|
2086 | NOREF(pvCallback);
|
---|
2087 | /* Do nothing. Later the VMMDev/VGA IRQ can be used for the notification. */
|
---|
2088 | #endif
|
---|
2089 | }
|
---|
2090 |
|
---|
2091 | /* The guest submitted a buffer. @todo Verify all guest data. */
|
---|
2092 | static DECLCALLBACK(int) vbvaChannelHandler (void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer)
|
---|
2093 | {
|
---|
2094 | int rc = VINF_SUCCESS;
|
---|
2095 |
|
---|
2096 | LogFlowFunc(("pvHandler %p, u16ChannelInfo %d, pvBuffer %p, cbBuffer %u\n",
|
---|
2097 | pvHandler, u16ChannelInfo, pvBuffer, cbBuffer));
|
---|
2098 |
|
---|
2099 | PVGASTATE pVGAState = (PVGASTATE)pvHandler;
|
---|
2100 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
2101 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
2102 |
|
---|
2103 | switch (u16ChannelInfo)
|
---|
2104 | {
|
---|
2105 | case VBVA_CMDVBVA_SUBMIT:
|
---|
2106 | {
|
---|
2107 | # ifdef VBOX_WITH_CRHGSMI
|
---|
2108 | rc = vboxCmdVBVACmdSubmit(pVGAState);
|
---|
2109 | #endif
|
---|
2110 | break;
|
---|
2111 | }
|
---|
2112 | case VBVA_CMDVBVA_FLUSH:
|
---|
2113 | {
|
---|
2114 | # ifdef VBOX_WITH_CRHGSMI
|
---|
2115 | rc =vboxCmdVBVACmdFlush(pVGAState);
|
---|
2116 | #endif
|
---|
2117 | break;
|
---|
2118 | }
|
---|
2119 | case VBVA_CMDVBVA_CTL:
|
---|
2120 | {
|
---|
2121 | #ifdef VBOX_WITH_CRHGSMI
|
---|
2122 | if (cbBuffer < VBoxSHGSMIBufferHeaderSize() + sizeof (VBOXCMDVBVA_CTL))
|
---|
2123 | {
|
---|
2124 | Log(("buffer too small\n"));
|
---|
2125 | #ifdef DEBUG_misha
|
---|
2126 | AssertMsgFailed(("buffer too small\n"));
|
---|
2127 | #endif
|
---|
2128 | rc = VERR_INVALID_PARAMETER;
|
---|
2129 | break;
|
---|
2130 | }
|
---|
2131 | VBOXCMDVBVA_CTL *pCtl = (VBOXCMDVBVA_CTL*)VBoxSHGSMIBufferData((PVBOXSHGSMIHEADER)pvBuffer);
|
---|
2132 | rc = vboxCmdVBVACmdCtl(pVGAState, pCtl, cbBuffer - VBoxSHGSMIBufferHeaderSize());
|
---|
2133 | #endif
|
---|
2134 | break;
|
---|
2135 | }
|
---|
2136 | #ifdef VBOX_WITH_VDMA
|
---|
2137 | case VBVA_VDMA_CMD:
|
---|
2138 | {
|
---|
2139 | if (cbBuffer < VBoxSHGSMIBufferHeaderSize() + sizeof (VBOXVDMACBUF_DR))
|
---|
2140 | {
|
---|
2141 | rc = VERR_INVALID_PARAMETER;
|
---|
2142 | break;
|
---|
2143 | }
|
---|
2144 | PVBOXVDMACBUF_DR pCmd = (PVBOXVDMACBUF_DR)VBoxSHGSMIBufferData ((PVBOXSHGSMIHEADER)pvBuffer);
|
---|
2145 | vboxVDMACommand(pVGAState->pVdma, pCmd, cbBuffer - VBoxSHGSMIBufferHeaderSize());
|
---|
2146 | rc = VINF_SUCCESS;
|
---|
2147 | break;
|
---|
2148 | }
|
---|
2149 | case VBVA_VDMA_CTL:
|
---|
2150 | {
|
---|
2151 | if (cbBuffer < VBoxSHGSMIBufferHeaderSize() + sizeof (VBOXVDMA_CTL))
|
---|
2152 | {
|
---|
2153 | rc = VERR_INVALID_PARAMETER;
|
---|
2154 | break;
|
---|
2155 | }
|
---|
2156 | PVBOXVDMA_CTL pCmd = (PVBOXVDMA_CTL)VBoxSHGSMIBufferData ((PVBOXSHGSMIHEADER)pvBuffer);
|
---|
2157 | vboxVDMAControl(pVGAState->pVdma, pCmd, cbBuffer - VBoxSHGSMIBufferHeaderSize());
|
---|
2158 | rc = VINF_SUCCESS;
|
---|
2159 | break;
|
---|
2160 | }
|
---|
2161 | #endif
|
---|
2162 | case VBVA_QUERY_CONF32:
|
---|
2163 | {
|
---|
2164 | if (cbBuffer < sizeof (VBVACONF32))
|
---|
2165 | {
|
---|
2166 | rc = VERR_INVALID_PARAMETER;
|
---|
2167 | break;
|
---|
2168 | }
|
---|
2169 |
|
---|
2170 | VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
|
---|
2171 | LogFlowFunc(("VBVA_QUERY_CONF32: u32Index %d, u32Value 0x%x\n",
|
---|
2172 | pConf32->u32Index, pConf32->u32Value));
|
---|
2173 |
|
---|
2174 | if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
|
---|
2175 | {
|
---|
2176 | pConf32->u32Value = pCtx->cViews;
|
---|
2177 | }
|
---|
2178 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
|
---|
2179 | {
|
---|
2180 | /* @todo a value calculated from the vram size */
|
---|
2181 | pConf32->u32Value = 64*_1K;
|
---|
2182 | }
|
---|
2183 | else if ( pConf32->u32Index == VBOX_VBVA_CONF32_MODE_HINT_REPORTING
|
---|
2184 | || pConf32->u32Index == VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING)
|
---|
2185 | {
|
---|
2186 | pConf32->u32Value = VINF_SUCCESS;
|
---|
2187 | }
|
---|
2188 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_CURSOR_CAPABILITIES)
|
---|
2189 | {
|
---|
2190 | pConf32->u32Value = pVGAState->fHostCursorCapabilities;
|
---|
2191 | }
|
---|
2192 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_SCREEN_FLAGS)
|
---|
2193 | {
|
---|
2194 | pConf32->u32Value = VBVA_SCREEN_F_ACTIVE | VBVA_SCREEN_F_DISABLED | VBVA_SCREEN_F_BLANK;
|
---|
2195 | }
|
---|
2196 | else
|
---|
2197 | {
|
---|
2198 | Log(("Unsupported VBVA_QUERY_CONF32 index %d!!!\n",
|
---|
2199 | pConf32->u32Index));
|
---|
2200 | rc = VERR_INVALID_PARAMETER;
|
---|
2201 | }
|
---|
2202 | } break;
|
---|
2203 |
|
---|
2204 | case VBVA_SET_CONF32:
|
---|
2205 | {
|
---|
2206 | if (cbBuffer < sizeof (VBVACONF32))
|
---|
2207 | {
|
---|
2208 | rc = VERR_INVALID_PARAMETER;
|
---|
2209 | break;
|
---|
2210 | }
|
---|
2211 |
|
---|
2212 | VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
|
---|
2213 | LogFlowFunc(("VBVA_SET_CONF32: u32Index %d, u32Value 0x%x\n",
|
---|
2214 | pConf32->u32Index, pConf32->u32Value));
|
---|
2215 |
|
---|
2216 | if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
|
---|
2217 | {
|
---|
2218 | /* do nothing. this is a const. */
|
---|
2219 | }
|
---|
2220 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
|
---|
2221 | {
|
---|
2222 | /* do nothing. this is a const. */
|
---|
2223 | }
|
---|
2224 | else
|
---|
2225 | {
|
---|
2226 | Log(("Unsupported VBVA_SET_CONF32 index %d!!!\n",
|
---|
2227 | pConf32->u32Index));
|
---|
2228 | rc = VERR_INVALID_PARAMETER;
|
---|
2229 | }
|
---|
2230 | } break;
|
---|
2231 |
|
---|
2232 | case VBVA_INFO_VIEW:
|
---|
2233 | {
|
---|
2234 | #ifdef VBOX_WITH_CRHGSMI
|
---|
2235 | if (vboxCmdVBVAIsEnabled(pVGAState))
|
---|
2236 | {
|
---|
2237 | AssertMsgFailed(("VBVA_INFO_VIEW is not acceptible for CmdVbva\n"));
|
---|
2238 | rc = VERR_INVALID_PARAMETER;
|
---|
2239 | break;
|
---|
2240 | }
|
---|
2241 | #endif
|
---|
2242 |
|
---|
2243 | if (cbBuffer < sizeof (VBVAINFOVIEW))
|
---|
2244 | {
|
---|
2245 | rc = VERR_INVALID_PARAMETER;
|
---|
2246 | break;
|
---|
2247 | }
|
---|
2248 |
|
---|
2249 | /* Guest submits an array of VBVAINFOVIEW structures. */
|
---|
2250 | VBVAINFOVIEW *pView = (VBVAINFOVIEW *)pvBuffer;
|
---|
2251 |
|
---|
2252 | for (;
|
---|
2253 | cbBuffer >= sizeof (VBVAINFOVIEW);
|
---|
2254 | pView++, cbBuffer -= sizeof (VBVAINFOVIEW))
|
---|
2255 | {
|
---|
2256 | VBVAINFOVIEW View = *pView;
|
---|
2257 | rc = VBVAInfoView(pVGAState, &View);
|
---|
2258 | if (RT_FAILURE(rc))
|
---|
2259 | break;
|
---|
2260 | }
|
---|
2261 | } break;
|
---|
2262 |
|
---|
2263 | case VBVA_INFO_HEAP:
|
---|
2264 | {
|
---|
2265 | if (cbBuffer < sizeof (VBVAINFOHEAP))
|
---|
2266 | {
|
---|
2267 | rc = VERR_INVALID_PARAMETER;
|
---|
2268 | break;
|
---|
2269 | }
|
---|
2270 |
|
---|
2271 | VBVAINFOHEAP *pHeap = (VBVAINFOHEAP *)pvBuffer;
|
---|
2272 | LogFlowFunc(("VBVA_INFO_HEAP: offset 0x%x, size 0x%x\n",
|
---|
2273 | pHeap->u32HeapOffset, pHeap->u32HeapSize));
|
---|
2274 |
|
---|
2275 | rc = HGSMIHostHeapSetup(pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
|
---|
2276 | } break;
|
---|
2277 |
|
---|
2278 | case VBVA_FLUSH:
|
---|
2279 | {
|
---|
2280 | if (cbBuffer < sizeof (VBVAFLUSH))
|
---|
2281 | {
|
---|
2282 | rc = VERR_INVALID_PARAMETER;
|
---|
2283 | break;
|
---|
2284 | }
|
---|
2285 |
|
---|
2286 | VBVAFLUSH *pFlush = (VBVAFLUSH *)pvBuffer;
|
---|
2287 | LogFlowFunc(("VBVA_FLUSH: u32Reserved 0x%x\n",
|
---|
2288 | pFlush->u32Reserved));
|
---|
2289 |
|
---|
2290 | rc = vbvaFlush (pVGAState, pCtx);
|
---|
2291 | } break;
|
---|
2292 |
|
---|
2293 | case VBVA_INFO_SCREEN:
|
---|
2294 | {
|
---|
2295 | if (cbBuffer < sizeof (VBVAINFOSCREEN))
|
---|
2296 | {
|
---|
2297 | rc = VERR_INVALID_PARAMETER;
|
---|
2298 | break;
|
---|
2299 | }
|
---|
2300 |
|
---|
2301 | #ifdef VBOX_WITH_CRHGSMI
|
---|
2302 | if (vboxCmdVBVAIsEnabled(pVGAState))
|
---|
2303 | {
|
---|
2304 | AssertMsgFailed(("VBVA_INFO_SCREEN is not acceptible for CmdVbva\n"));
|
---|
2305 | rc = VERR_INVALID_PARAMETER;
|
---|
2306 | break;
|
---|
2307 | }
|
---|
2308 | #endif
|
---|
2309 |
|
---|
2310 | VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)pvBuffer;
|
---|
2311 | VBVAINFOSCREEN Screen = *pScreen;
|
---|
2312 | rc = VBVAInfoScreen(pVGAState, &Screen);
|
---|
2313 | } break;
|
---|
2314 |
|
---|
2315 | case VBVA_ENABLE:
|
---|
2316 | {
|
---|
2317 | #ifdef VBOX_WITH_CRHGSMI
|
---|
2318 | if (vboxCmdVBVAIsEnabled(pVGAState))
|
---|
2319 | {
|
---|
2320 | AssertMsgFailed(("VBVA_ENABLE is not acceptible for CmdVbva\n"));
|
---|
2321 | rc = VERR_INVALID_PARAMETER;
|
---|
2322 | break;
|
---|
2323 | }
|
---|
2324 | #endif
|
---|
2325 |
|
---|
2326 | if (cbBuffer < sizeof (VBVAENABLE))
|
---|
2327 | {
|
---|
2328 | rc = VERR_INVALID_PARAMETER;
|
---|
2329 | break;
|
---|
2330 | }
|
---|
2331 |
|
---|
2332 | VBVAENABLE *pEnable = (VBVAENABLE *)pvBuffer;
|
---|
2333 | unsigned uScreenId;
|
---|
2334 | if (pEnable->u32Flags & VBVA_F_EXTENDED)
|
---|
2335 | {
|
---|
2336 | if (cbBuffer < sizeof (VBVAENABLE_EX))
|
---|
2337 | {
|
---|
2338 | rc = VERR_INVALID_PARAMETER;
|
---|
2339 | break;
|
---|
2340 | }
|
---|
2341 |
|
---|
2342 | VBVAENABLE_EX *pEnableEx = (VBVAENABLE_EX *)pvBuffer;
|
---|
2343 | uScreenId = pEnableEx->u32ScreenId;
|
---|
2344 | }
|
---|
2345 | else
|
---|
2346 | {
|
---|
2347 | uScreenId = vbvaViewFromOffset (pIns, pCtx, pvBuffer);
|
---|
2348 | }
|
---|
2349 |
|
---|
2350 | if (uScreenId == ~0U)
|
---|
2351 | {
|
---|
2352 | rc = VERR_INVALID_PARAMETER;
|
---|
2353 | break;
|
---|
2354 | }
|
---|
2355 |
|
---|
2356 | LogFlowFunc(("VBVA_ENABLE[%d]: u32Flags 0x%x u32Offset 0x%x\n",
|
---|
2357 | uScreenId, pEnable->u32Flags, pEnable->u32Offset));
|
---|
2358 |
|
---|
2359 | if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_ENABLE)
|
---|
2360 | {
|
---|
2361 | /* Guest reported offset relative to view. */
|
---|
2362 | uint32_t u32Offset = pEnable->u32Offset;
|
---|
2363 | if (!(pEnable->u32Flags & VBVA_F_ABSOFFSET))
|
---|
2364 | {
|
---|
2365 | u32Offset += pCtx->aViews[uScreenId].view.u32ViewOffset;
|
---|
2366 | }
|
---|
2367 |
|
---|
2368 | VBVABUFFER *pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, u32Offset);
|
---|
2369 |
|
---|
2370 | if (pVBVA)
|
---|
2371 | {
|
---|
2372 | /* Process any pending orders and empty the VBVA ring buffer. */
|
---|
2373 | vbvaFlush (pVGAState, pCtx);
|
---|
2374 |
|
---|
2375 | rc = vbvaEnable (uScreenId, pVGAState, pCtx, pVBVA, u32Offset, false /* fRestored */);
|
---|
2376 | }
|
---|
2377 | else
|
---|
2378 | {
|
---|
2379 | Log(("Invalid VBVABUFFER offset 0x%x!!!\n",
|
---|
2380 | pEnable->u32Offset));
|
---|
2381 | rc = VERR_INVALID_PARAMETER;
|
---|
2382 | }
|
---|
2383 | }
|
---|
2384 | else if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_DISABLE)
|
---|
2385 | {
|
---|
2386 | rc = vbvaDisable (uScreenId, pVGAState, pCtx);
|
---|
2387 | }
|
---|
2388 | else
|
---|
2389 | {
|
---|
2390 | Log(("Invalid VBVA_ENABLE flags 0x%x!!!\n",
|
---|
2391 | pEnable->u32Flags));
|
---|
2392 | rc = VERR_INVALID_PARAMETER;
|
---|
2393 | }
|
---|
2394 |
|
---|
2395 | pEnable->i32Result = rc;
|
---|
2396 | } break;
|
---|
2397 |
|
---|
2398 | case VBVA_MOUSE_POINTER_SHAPE:
|
---|
2399 | {
|
---|
2400 | if (cbBuffer < sizeof (VBVAMOUSEPOINTERSHAPE))
|
---|
2401 | {
|
---|
2402 | rc = VERR_INVALID_PARAMETER;
|
---|
2403 | break;
|
---|
2404 | }
|
---|
2405 |
|
---|
2406 | VBVAMOUSEPOINTERSHAPE *pShape = (VBVAMOUSEPOINTERSHAPE *)pvBuffer;
|
---|
2407 |
|
---|
2408 | LogFlowFunc(("VBVA_MOUSE_POINTER_SHAPE: i32Result 0x%x, fu32Flags 0x%x, hot spot %d,%d, size %dx%d\n",
|
---|
2409 | pShape->i32Result,
|
---|
2410 | pShape->fu32Flags,
|
---|
2411 | pShape->u32HotX,
|
---|
2412 | pShape->u32HotY,
|
---|
2413 | pShape->u32Width,
|
---|
2414 | pShape->u32Height));
|
---|
2415 |
|
---|
2416 | rc = vbvaMousePointerShape (pVGAState, pCtx, pShape, cbBuffer);
|
---|
2417 |
|
---|
2418 | pShape->i32Result = rc;
|
---|
2419 | } break;
|
---|
2420 |
|
---|
2421 |
|
---|
2422 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
2423 | case VBVA_VHWA_CMD:
|
---|
2424 | {
|
---|
2425 | if (cbBuffer < sizeof (VBOXVHWACMD))
|
---|
2426 | {
|
---|
2427 | rc = VERR_INVALID_PARAMETER;
|
---|
2428 | break;
|
---|
2429 | }
|
---|
2430 | vbvaVHWAHandleCommand(pVGAState, (PVBOXVHWACMD)pvBuffer);
|
---|
2431 | rc = VINF_SUCCESS;
|
---|
2432 | break;
|
---|
2433 | } break;
|
---|
2434 | #endif
|
---|
2435 |
|
---|
2436 | #ifdef VBOX_WITH_WDDM
|
---|
2437 | case VBVA_INFO_CAPS:
|
---|
2438 | {
|
---|
2439 | if (cbBuffer < sizeof (VBVACAPS))
|
---|
2440 | {
|
---|
2441 | rc = VERR_INVALID_PARAMETER;
|
---|
2442 | break;
|
---|
2443 | }
|
---|
2444 |
|
---|
2445 | VBVACAPS *pCaps = (VBVACAPS*)pvBuffer;
|
---|
2446 | pVGAState->fGuestCaps = pCaps->fCaps;
|
---|
2447 | pVGAState->pDrv->pfnVBVAGuestCapabilityUpdate(pVGAState->pDrv,
|
---|
2448 | pCaps->fCaps);
|
---|
2449 | pCaps->rc = VINF_SUCCESS;
|
---|
2450 | } break;
|
---|
2451 | #endif
|
---|
2452 | case VBVA_SCANLINE_CFG:
|
---|
2453 | {
|
---|
2454 | if (cbBuffer < sizeof (VBVASCANLINECFG))
|
---|
2455 | {
|
---|
2456 | rc = VERR_INVALID_PARAMETER;
|
---|
2457 | break;
|
---|
2458 | }
|
---|
2459 |
|
---|
2460 | VBVASCANLINECFG *pCfg = (VBVASCANLINECFG*)pvBuffer;
|
---|
2461 | pVGAState->fScanLineCfg = pCfg->fFlags;
|
---|
2462 | pCfg->rc = VINF_SUCCESS;
|
---|
2463 | } break;
|
---|
2464 |
|
---|
2465 | case VBVA_QUERY_MODE_HINTS:
|
---|
2466 | {
|
---|
2467 | if (cbBuffer < sizeof(VBVAQUERYMODEHINTS))
|
---|
2468 | {
|
---|
2469 | rc = VERR_INVALID_PARAMETER;
|
---|
2470 | break;
|
---|
2471 | }
|
---|
2472 | VBVAQUERYMODEHINTS *pModeHintQuery = (VBVAQUERYMODEHINTS*)pvBuffer;
|
---|
2473 | LogRelFlowFunc(("VBVA_QUERY_MODE_HINTS: cHintsQueried=%u, cbHintStructureGuest=%u\n",
|
---|
2474 | (unsigned)pModeHintQuery->cHintsQueried,
|
---|
2475 | (unsigned)pModeHintQuery->cbHintStructureGuest));
|
---|
2476 | if (cbBuffer < sizeof (VBVAQUERYMODEHINTS)
|
---|
2477 | + (uint64_t)pModeHintQuery->cHintsQueried
|
---|
2478 | * pModeHintQuery->cbHintStructureGuest)
|
---|
2479 | {
|
---|
2480 | pModeHintQuery->rc = VERR_INVALID_PARAMETER;
|
---|
2481 | break;
|
---|
2482 | }
|
---|
2483 | pModeHintQuery->rc = VINF_SUCCESS;
|
---|
2484 | uint8_t *pbHint = (uint8_t *)pvBuffer + sizeof(VBVAQUERYMODEHINTS);
|
---|
2485 | memset(pbHint, ~0, cbBuffer - sizeof(VBVAQUERYMODEHINTS));
|
---|
2486 | unsigned iHint;
|
---|
2487 | for (iHint = 0; iHint < pModeHintQuery->cHintsQueried
|
---|
2488 | && iHint < VBOX_VIDEO_MAX_SCREENS; ++iHint)
|
---|
2489 | {
|
---|
2490 | memcpy(pbHint, &pCtx->aModeHints[iHint],
|
---|
2491 | RT_MIN(pModeHintQuery->cbHintStructureGuest,
|
---|
2492 | sizeof(VBVAMODEHINT)));
|
---|
2493 | pbHint += pModeHintQuery->cbHintStructureGuest;
|
---|
2494 | Assert(pbHint - (uint8_t *)pvBuffer <= cbBuffer);
|
---|
2495 | }
|
---|
2496 | } break;
|
---|
2497 |
|
---|
2498 | case VBVA_REPORT_INPUT_MAPPING:
|
---|
2499 | {
|
---|
2500 | if (cbBuffer != sizeof(VBVAREPORTINPUTMAPPING))
|
---|
2501 | {
|
---|
2502 | rc = VERR_INVALID_PARAMETER;
|
---|
2503 | break;
|
---|
2504 | }
|
---|
2505 | VBVAREPORTINPUTMAPPING *pReport = (VBVAREPORTINPUTMAPPING *)pvBuffer;
|
---|
2506 | LogRelFlowFunc(("VBVA_REPORT_INPUT_MAPPING: x=%u, y=%u, cx=%u, cy=%u\n", (unsigned)pReport->x, (unsigned)pReport->y,
|
---|
2507 | (unsigned)pReport->cx, (unsigned)pReport->cy));
|
---|
2508 | pVGAState->pDrv->pfnVBVAInputMappingUpdate(pVGAState->pDrv, pReport->x, pReport->y, pReport->cx, pReport->cy);
|
---|
2509 | } break;
|
---|
2510 |
|
---|
2511 | case VBVA_CURSOR_POSITION:
|
---|
2512 | {
|
---|
2513 | if (cbBuffer != sizeof(VBVACURSORPOSITION))
|
---|
2514 | {
|
---|
2515 | rc = VERR_INVALID_PARAMETER;
|
---|
2516 | break;
|
---|
2517 | }
|
---|
2518 | VBVACURSORPOSITION *pReport
|
---|
2519 | = (VBVACURSORPOSITION *)pvBuffer;
|
---|
2520 | LogRelFlowFunc(("VBVA_CURSOR_POSITION: fReportPosition=%RTbool",
|
---|
2521 | RT_BOOL(pReport->fReportPosition)));
|
---|
2522 | if (RT_BOOL(pReport->fReportPosition))
|
---|
2523 | LogRelFlowFunc(("VBVA_CURSOR_POSITION: fReportPosition=true, x=%u, y=%u\n",
|
---|
2524 | (unsigned)pReport->x, (unsigned)pReport->y));
|
---|
2525 | else
|
---|
2526 | LogRelFlowFunc(("VBVA_CURSOR_POSITION: fReportPosition=false\n"));
|
---|
2527 | pReport->x = pCtx->xCursor;
|
---|
2528 | pReport->y = pCtx->yCursor;
|
---|
2529 | } break;
|
---|
2530 |
|
---|
2531 | default:
|
---|
2532 | Log(("Unsupported VBVA guest command %d!!!\n",
|
---|
2533 | u16ChannelInfo));
|
---|
2534 | break;
|
---|
2535 | }
|
---|
2536 |
|
---|
2537 | return rc;
|
---|
2538 | }
|
---|
2539 |
|
---|
2540 | /* When VBVA is paused, then VGA device is allowed to work but
|
---|
2541 | * no HGSMI etc state is changed.
|
---|
2542 | */
|
---|
2543 | void VBVAPause(PVGASTATE pVGAState, bool fPause)
|
---|
2544 | {
|
---|
2545 | if (!pVGAState || !pVGAState->pHGSMI)
|
---|
2546 | {
|
---|
2547 | return;
|
---|
2548 | }
|
---|
2549 |
|
---|
2550 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext(pVGAState->pHGSMI);
|
---|
2551 |
|
---|
2552 | if (pCtx)
|
---|
2553 | {
|
---|
2554 | pCtx->fPaused = fPause;
|
---|
2555 | }
|
---|
2556 | }
|
---|
2557 |
|
---|
2558 | void VBVAReset (PVGASTATE pVGAState)
|
---|
2559 | {
|
---|
2560 | if (!pVGAState || !pVGAState->pHGSMI)
|
---|
2561 | {
|
---|
2562 | return;
|
---|
2563 | }
|
---|
2564 |
|
---|
2565 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2566 |
|
---|
2567 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
2568 | vbvaVHWAReset (pVGAState);
|
---|
2569 | #endif
|
---|
2570 |
|
---|
2571 | uint32_t HgFlags = HGSMIReset (pVGAState->pHGSMI);
|
---|
2572 | if(HgFlags & HGSMIHOSTFLAGS_IRQ)
|
---|
2573 | {
|
---|
2574 | /* this means the IRQ is LEVEL_HIGH, need to reset it */
|
---|
2575 | PDMDevHlpPCISetIrq(pVGAState->pDevInsR3, 0, PDM_IRQ_LEVEL_LOW);
|
---|
2576 | }
|
---|
2577 |
|
---|
2578 | if (pCtx)
|
---|
2579 | {
|
---|
2580 | vbvaFlush (pVGAState, pCtx);
|
---|
2581 |
|
---|
2582 | unsigned uScreenId;
|
---|
2583 |
|
---|
2584 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
2585 | {
|
---|
2586 | vbvaDisable (uScreenId, pVGAState, pCtx);
|
---|
2587 | }
|
---|
2588 |
|
---|
2589 | pCtx->mouseShapeInfo.fSet = false;
|
---|
2590 | RTMemFree(pCtx->mouseShapeInfo.pu8Shape);
|
---|
2591 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
2592 | pCtx->mouseShapeInfo.cbAllocated = 0;
|
---|
2593 | pCtx->mouseShapeInfo.cbShape = 0;
|
---|
2594 | }
|
---|
2595 |
|
---|
2596 | }
|
---|
2597 |
|
---|
2598 | int VBVAUpdateDisplay (PVGASTATE pVGAState)
|
---|
2599 | {
|
---|
2600 | int rc = VERR_NOT_SUPPORTED; /* Assuming that the VGA device will have to do updates. */
|
---|
2601 |
|
---|
2602 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2603 |
|
---|
2604 | if (pCtx)
|
---|
2605 | {
|
---|
2606 | if (!pCtx->fPaused)
|
---|
2607 | {
|
---|
2608 | rc = vbvaFlush (pVGAState, pCtx);
|
---|
2609 |
|
---|
2610 | if (RT_SUCCESS (rc))
|
---|
2611 | {
|
---|
2612 | if (!pCtx->aViews[0].pVBVA)
|
---|
2613 | {
|
---|
2614 | /* VBVA is not enabled for the first view, so VGA device must do updates. */
|
---|
2615 | rc = VERR_NOT_SUPPORTED;
|
---|
2616 | }
|
---|
2617 | }
|
---|
2618 | }
|
---|
2619 | }
|
---|
2620 |
|
---|
2621 | return rc;
|
---|
2622 | }
|
---|
2623 |
|
---|
2624 | static int vbvaSendModeHintWorker(PVGASTATE pThis, uint32_t cx, uint32_t cy,
|
---|
2625 | uint32_t cBPP, uint32_t iDisplay, uint32_t dx,
|
---|
2626 | uint32_t dy, uint32_t fEnabled,
|
---|
2627 | uint32_t fNotifyGuest)
|
---|
2628 | {
|
---|
2629 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext(pThis->pHGSMI);
|
---|
2630 | /** @note See Display::setVideoModeHint: "It is up to the guest to decide
|
---|
2631 | * whether the hint is valid. Therefore don't do any VRAM sanity checks
|
---|
2632 | * here! */
|
---|
2633 | if (iDisplay >= RT_MIN(pThis->cMonitors, RT_ELEMENTS(pCtx->aModeHints)))
|
---|
2634 | return VERR_OUT_OF_RANGE;
|
---|
2635 | pCtx->aModeHints[iDisplay].magic = VBVAMODEHINT_MAGIC;
|
---|
2636 | pCtx->aModeHints[iDisplay].cx = cx;
|
---|
2637 | pCtx->aModeHints[iDisplay].cy = cy;
|
---|
2638 | pCtx->aModeHints[iDisplay].cBPP = cBPP;
|
---|
2639 | pCtx->aModeHints[iDisplay].dx = dx;
|
---|
2640 | pCtx->aModeHints[iDisplay].dy = dy;
|
---|
2641 | pCtx->aModeHints[iDisplay].fEnabled = fEnabled;
|
---|
2642 | if (fNotifyGuest && pThis->fGuestCaps & VBVACAPS_IRQ && pThis->fGuestCaps & VBVACAPS_VIDEO_MODE_HINTS)
|
---|
2643 | VBVARaiseIrq(pThis, HGSMIHOSTFLAGS_HOTPLUG);
|
---|
2644 | return VINF_SUCCESS;
|
---|
2645 | }
|
---|
2646 |
|
---|
2647 | /** Converts a display port interface pointer to a vga state pointer. */
|
---|
2648 | #define IDISPLAYPORT_2_VGASTATE(pInterface) ( (PVGASTATE)((uintptr_t)pInterface - RT_OFFSETOF(VGASTATE, IPort)) )
|
---|
2649 |
|
---|
2650 | DECLCALLBACK(int) vbvaPortSendModeHint(PPDMIDISPLAYPORT pInterface, uint32_t cx,
|
---|
2651 | uint32_t cy, uint32_t cBPP,
|
---|
2652 | uint32_t iDisplay, uint32_t dx,
|
---|
2653 | uint32_t dy, uint32_t fEnabled,
|
---|
2654 | uint32_t fNotifyGuest)
|
---|
2655 | {
|
---|
2656 | PVGASTATE pThis;
|
---|
2657 | int rc;
|
---|
2658 |
|
---|
2659 | pThis = IDISPLAYPORT_2_VGASTATE(pInterface);
|
---|
2660 | rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
|
---|
2661 | AssertRC(rc);
|
---|
2662 | rc = vbvaSendModeHintWorker(pThis, cx, cy, cBPP, iDisplay, dx, dy, fEnabled,
|
---|
2663 | fNotifyGuest);
|
---|
2664 | PDMCritSectLeave(&pThis->CritSect);
|
---|
2665 | return rc;
|
---|
2666 | }
|
---|
2667 |
|
---|
2668 | DECLCALLBACK(void) vbvaPortReportHostCursorCapabilities(PPDMIDISPLAYPORT pInterface, uint32_t fCapabilitiesAdded,
|
---|
2669 | uint32_t fCapabilitiesRemoved)
|
---|
2670 | {
|
---|
2671 | PVGASTATE pThis = IDISPLAYPORT_2_VGASTATE(pInterface);
|
---|
2672 | int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
|
---|
2673 | AssertRC(rc);
|
---|
2674 | pThis->fHostCursorCapabilities |= fCapabilitiesAdded;
|
---|
2675 | pThis->fHostCursorCapabilities &= ~fCapabilitiesRemoved;
|
---|
2676 | if (pThis->fGuestCaps & VBVACAPS_IRQ && pThis->fGuestCaps & VBVACAPS_DISABLE_CURSOR_INTEGRATION)
|
---|
2677 | VBVARaiseIrqNoWait(pThis, HGSMIHOSTFLAGS_CURSOR_CAPABILITIES);
|
---|
2678 | PDMCritSectLeave(&pThis->CritSect);
|
---|
2679 | }
|
---|
2680 |
|
---|
2681 | DECLCALLBACK(void) vbvaPortReportHostCursorPosition
|
---|
2682 | (PPDMIDISPLAYPORT pInterface, uint32_t x, uint32_t y)
|
---|
2683 | {
|
---|
2684 | PVGASTATE pThis = IDISPLAYPORT_2_VGASTATE(pInterface);
|
---|
2685 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext(pThis->pHGSMI);
|
---|
2686 | int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
|
---|
2687 | AssertRC(rc);
|
---|
2688 | pCtx->xCursor = x;
|
---|
2689 | pCtx->yCursor = y;
|
---|
2690 | PDMCritSectLeave(&pThis->CritSect);
|
---|
2691 | }
|
---|
2692 |
|
---|
2693 | int VBVAInit (PVGASTATE pVGAState)
|
---|
2694 | {
|
---|
2695 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
2696 |
|
---|
2697 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
2698 |
|
---|
2699 | int rc = HGSMICreate (&pVGAState->pHGSMI,
|
---|
2700 | pVM,
|
---|
2701 | "VBVA",
|
---|
2702 | 0,
|
---|
2703 | pVGAState->vram_ptrR3,
|
---|
2704 | pVGAState->vram_size,
|
---|
2705 | vbvaNotifyGuest,
|
---|
2706 | pVGAState,
|
---|
2707 | sizeof (VBVACONTEXT));
|
---|
2708 |
|
---|
2709 | if (RT_SUCCESS (rc))
|
---|
2710 | {
|
---|
2711 | rc = HGSMIHostChannelRegister (pVGAState->pHGSMI,
|
---|
2712 | HGSMI_CH_VBVA,
|
---|
2713 | vbvaChannelHandler,
|
---|
2714 | pVGAState);
|
---|
2715 | if (RT_SUCCESS (rc))
|
---|
2716 | {
|
---|
2717 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2718 | pCtx->cViews = pVGAState->cMonitors;
|
---|
2719 | pCtx->fPaused = true;
|
---|
2720 | memset(pCtx->aModeHints, ~0, sizeof(pCtx->aModeHints));
|
---|
2721 | pVGAState->fHostCursorCapabilities = 0;
|
---|
2722 | }
|
---|
2723 | }
|
---|
2724 |
|
---|
2725 | return rc;
|
---|
2726 |
|
---|
2727 | }
|
---|
2728 |
|
---|
2729 | void VBVADestroy (PVGASTATE pVGAState)
|
---|
2730 | {
|
---|
2731 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2732 |
|
---|
2733 | if (pCtx)
|
---|
2734 | {
|
---|
2735 | pCtx->mouseShapeInfo.fSet = false;
|
---|
2736 | RTMemFree(pCtx->mouseShapeInfo.pu8Shape);
|
---|
2737 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
2738 | pCtx->mouseShapeInfo.cbAllocated = 0;
|
---|
2739 | pCtx->mouseShapeInfo.cbShape = 0;
|
---|
2740 | }
|
---|
2741 |
|
---|
2742 | HGSMIDestroy (pVGAState->pHGSMI);
|
---|
2743 | pVGAState->pHGSMI = NULL;
|
---|
2744 | }
|
---|