1 | /** @file
|
---|
2 | * VirtualBox Video Acceleration (VBVA).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2009 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #define LOG_GROUP LOG_GROUP_DEV_VGA
|
---|
18 | #include <VBox/vmm/pdmifs.h>
|
---|
19 | #include <VBox/vmm/pdmdev.h>
|
---|
20 | #include <VBox/vmm/pgm.h>
|
---|
21 | #include <VBox/vmm/ssm.h>
|
---|
22 | #include <VBox/VMMDev.h>
|
---|
23 | #include <VBox/VBoxVideo.h>
|
---|
24 | #include <iprt/alloc.h>
|
---|
25 | #include <iprt/assert.h>
|
---|
26 | #include <iprt/asm.h>
|
---|
27 | #include <iprt/string.h>
|
---|
28 | #include <iprt/param.h>
|
---|
29 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
30 | #include <iprt/semaphore.h>
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include "DevVGA.h"
|
---|
34 |
|
---|
35 | /* A very detailed logging. */
|
---|
36 | #if 0 // def DEBUG_sunlover
|
---|
37 | #define LOGVBVABUFFER(a) LogFlow(a)
|
---|
38 | #else
|
---|
39 | #define LOGVBVABUFFER(a) do {} while(0)
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | typedef struct VBVAPARTIALRECORD
|
---|
43 | {
|
---|
44 | uint8_t *pu8;
|
---|
45 | uint32_t cb;
|
---|
46 | } VBVAPARTIALRECORD;
|
---|
47 |
|
---|
48 | typedef struct VBVAVIEW
|
---|
49 | {
|
---|
50 | VBVAINFOVIEW view;
|
---|
51 | VBVAINFOSCREEN screen;
|
---|
52 | VBVABUFFER *pVBVA;
|
---|
53 | uint32_t u32VBVAOffset;
|
---|
54 | VBVAPARTIALRECORD partialRecord;
|
---|
55 | } VBVAVIEW;
|
---|
56 |
|
---|
57 | typedef struct VBVAMOUSESHAPEINFO
|
---|
58 | {
|
---|
59 | bool fSet;
|
---|
60 | bool fVisible;
|
---|
61 | bool fAlpha;
|
---|
62 | uint32_t u32HotX;
|
---|
63 | uint32_t u32HotY;
|
---|
64 | uint32_t u32Width;
|
---|
65 | uint32_t u32Height;
|
---|
66 | uint32_t cbShape;
|
---|
67 | uint32_t cbAllocated;
|
---|
68 | uint8_t *pu8Shape;
|
---|
69 | } VBVAMOUSESHAPEINFO;
|
---|
70 |
|
---|
71 | /* @todo saved state: save and restore VBVACONTEXT */
|
---|
72 | typedef struct VBVACONTEXT
|
---|
73 | {
|
---|
74 | uint32_t cViews;
|
---|
75 | VBVAVIEW aViews[64 /* @todo SchemaDefs::MaxGuestMonitors*/];
|
---|
76 | VBVAMOUSESHAPEINFO mouseShapeInfo;
|
---|
77 | } VBVACONTEXT;
|
---|
78 |
|
---|
79 | /* Copies 'cb' bytes from the VBVA ring buffer to the 'pu8Dst'.
|
---|
80 | * Used for partial records or for records which cross the ring boundary.
|
---|
81 | */
|
---|
82 | static void vbvaFetchBytes (VBVABUFFER *pVBVA, uint8_t *pu8Dst, uint32_t cb)
|
---|
83 | {
|
---|
84 | /* @todo replace the 'if' with an assert. The caller must ensure this condition. */
|
---|
85 | if (cb >= pVBVA->cbData)
|
---|
86 | {
|
---|
87 | AssertMsgFailed (("cb = 0x%08X, ring buffer size 0x%08X", cb, pVBVA->cbData));
|
---|
88 | return;
|
---|
89 | }
|
---|
90 |
|
---|
91 | const uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
|
---|
92 | const uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
|
---|
93 | const int32_t i32Diff = cb - u32BytesTillBoundary;
|
---|
94 |
|
---|
95 | if (i32Diff <= 0)
|
---|
96 | {
|
---|
97 | /* Chunk will not cross buffer boundary. */
|
---|
98 | memcpy (pu8Dst, src, cb);
|
---|
99 | }
|
---|
100 | else
|
---|
101 | {
|
---|
102 | /* Chunk crosses buffer boundary. */
|
---|
103 | memcpy (pu8Dst, src, u32BytesTillBoundary);
|
---|
104 | memcpy (pu8Dst + u32BytesTillBoundary, &pVBVA->au8Data[0], i32Diff);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* Advance data offset. */
|
---|
108 | pVBVA->off32Data = (pVBVA->off32Data + cb) % pVBVA->cbData;
|
---|
109 |
|
---|
110 | return;
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | static bool vbvaPartialRead (VBVAPARTIALRECORD *pPartialRecord, uint32_t cbRecord, VBVABUFFER *pVBVA)
|
---|
115 | {
|
---|
116 | uint8_t *pu8New;
|
---|
117 |
|
---|
118 | LOGVBVABUFFER(("vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
|
---|
119 | pPartialRecord->pu8, pPartialRecord->cb, cbRecord));
|
---|
120 |
|
---|
121 | if (pPartialRecord->pu8)
|
---|
122 | {
|
---|
123 | Assert (pPartialRecord->cb);
|
---|
124 | pu8New = (uint8_t *)RTMemRealloc (pPartialRecord->pu8, cbRecord);
|
---|
125 | }
|
---|
126 | else
|
---|
127 | {
|
---|
128 | Assert (!pPartialRecord->cb);
|
---|
129 | pu8New = (uint8_t *)RTMemAlloc (cbRecord);
|
---|
130 | }
|
---|
131 |
|
---|
132 | if (!pu8New)
|
---|
133 | {
|
---|
134 | /* Memory allocation failed, fail the function. */
|
---|
135 | Log(("vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
|
---|
136 | cbRecord));
|
---|
137 |
|
---|
138 | if (pPartialRecord->pu8)
|
---|
139 | {
|
---|
140 | RTMemFree (pPartialRecord->pu8);
|
---|
141 | }
|
---|
142 |
|
---|
143 | pPartialRecord->pu8 = NULL;
|
---|
144 | pPartialRecord->cb = 0;
|
---|
145 |
|
---|
146 | return false;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /* Fetch data from the ring buffer. */
|
---|
150 | vbvaFetchBytes (pVBVA, pu8New + pPartialRecord->cb, cbRecord - pPartialRecord->cb);
|
---|
151 |
|
---|
152 | pPartialRecord->pu8 = pu8New;
|
---|
153 | pPartialRecord->cb = cbRecord;
|
---|
154 |
|
---|
155 | return true;
|
---|
156 | }
|
---|
157 |
|
---|
158 | /* For contiguous chunks just return the address in the buffer.
|
---|
159 | * For crossing boundary - allocate a buffer from heap.
|
---|
160 | */
|
---|
161 | static bool vbvaFetchCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR **ppHdr, uint32_t *pcbCmd)
|
---|
162 | {
|
---|
163 | uint32_t indexRecordFirst = pVBVA->indexRecordFirst;
|
---|
164 | uint32_t indexRecordFree = pVBVA->indexRecordFree;
|
---|
165 |
|
---|
166 | LOGVBVABUFFER(("first = %d, free = %d\n",
|
---|
167 | indexRecordFirst, indexRecordFree));
|
---|
168 |
|
---|
169 | if (indexRecordFirst == indexRecordFree)
|
---|
170 | {
|
---|
171 | /* No records to process. Return without assigning output variables. */
|
---|
172 | return true;
|
---|
173 | }
|
---|
174 |
|
---|
175 | uint32_t cbRecordCurrent = ASMAtomicReadU32(&pVBVA->aRecords[indexRecordFirst].cbRecord);
|
---|
176 |
|
---|
177 | LOGVBVABUFFER(("cbRecord = 0x%08X, pPartialRecord->cb = 0x%08X\n", cbRecordCurrent, pPartialRecord->cb));
|
---|
178 |
|
---|
179 | uint32_t cbRecord = cbRecordCurrent & ~VBVA_F_RECORD_PARTIAL;
|
---|
180 |
|
---|
181 | if (pPartialRecord->cb)
|
---|
182 | {
|
---|
183 | /* There is a partial read in process. Continue with it. */
|
---|
184 | Assert (pPartialRecord->pu8);
|
---|
185 |
|
---|
186 | LOGVBVABUFFER(("continue partial record cb = %d cbRecord 0x%08X, first = %d, free = %d\n",
|
---|
187 | pPartialRecord->cb, cbRecordCurrent, indexRecordFirst, indexRecordFree));
|
---|
188 |
|
---|
189 | if (cbRecord > pPartialRecord->cb)
|
---|
190 | {
|
---|
191 | /* New data has been added to the record. */
|
---|
192 | if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
|
---|
193 | {
|
---|
194 | return false;
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | if (!(cbRecordCurrent & VBVA_F_RECORD_PARTIAL))
|
---|
199 | {
|
---|
200 | /* The record is completed by guest. Return it to the caller. */
|
---|
201 | *ppHdr = (VBVACMDHDR *)pPartialRecord->pu8;
|
---|
202 | *pcbCmd = pPartialRecord->cb;
|
---|
203 |
|
---|
204 | pPartialRecord->pu8 = NULL;
|
---|
205 | pPartialRecord->cb = 0;
|
---|
206 |
|
---|
207 | /* Advance the record index. */
|
---|
208 | pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
|
---|
209 |
|
---|
210 | LOGVBVABUFFER(("partial done ok, data = %d, free = %d\n",
|
---|
211 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
212 | }
|
---|
213 |
|
---|
214 | return true;
|
---|
215 | }
|
---|
216 |
|
---|
217 | /* A new record need to be processed. */
|
---|
218 | if (cbRecordCurrent & VBVA_F_RECORD_PARTIAL)
|
---|
219 | {
|
---|
220 | /* Current record is being written by guest. '=' is important here,
|
---|
221 | * because the guest will do a FLUSH at this condition.
|
---|
222 | * This partial record is too large for the ring buffer and must
|
---|
223 | * be accumulated in an allocated buffer.
|
---|
224 | */
|
---|
225 | if (cbRecord >= pVBVA->cbData - pVBVA->cbPartialWriteThreshold)
|
---|
226 | {
|
---|
227 | /* Partial read must be started. */
|
---|
228 | if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
|
---|
229 | {
|
---|
230 | return false;
|
---|
231 | }
|
---|
232 |
|
---|
233 | LOGVBVABUFFER(("started partial record cb = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
|
---|
234 | pPartialRecord->cb, cbRecordCurrent, indexRecordFirst, indexRecordFree));
|
---|
235 | }
|
---|
236 |
|
---|
237 | return true;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /* Current record is complete. If it is not empty, process it. */
|
---|
241 | if (cbRecord)
|
---|
242 | {
|
---|
243 | /* The size of largest contiguous chunk in the ring biffer. */
|
---|
244 | uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
|
---|
245 |
|
---|
246 | /* The pointer to data in the ring buffer. */
|
---|
247 | uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
|
---|
248 |
|
---|
249 | /* Fetch or point the data. */
|
---|
250 | if (u32BytesTillBoundary >= cbRecord)
|
---|
251 | {
|
---|
252 | /* The command does not cross buffer boundary. Return address in the buffer. */
|
---|
253 | *ppHdr = (VBVACMDHDR *)src;
|
---|
254 |
|
---|
255 | /* Advance data offset. */
|
---|
256 | pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
|
---|
257 | }
|
---|
258 | else
|
---|
259 | {
|
---|
260 | /* The command crosses buffer boundary. Rare case, so not optimized. */
|
---|
261 | uint8_t *dst = (uint8_t *)RTMemAlloc (cbRecord);
|
---|
262 |
|
---|
263 | if (!dst)
|
---|
264 | {
|
---|
265 | LogFlowFunc (("could not allocate %d bytes from heap!!!\n", cbRecord));
|
---|
266 | pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
|
---|
267 | return false;
|
---|
268 | }
|
---|
269 |
|
---|
270 | vbvaFetchBytes (pVBVA, dst, cbRecord);
|
---|
271 |
|
---|
272 | *ppHdr = (VBVACMDHDR *)dst;
|
---|
273 |
|
---|
274 | LOGVBVABUFFER(("Allocated from heap %p\n", dst));
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | *pcbCmd = cbRecord;
|
---|
279 |
|
---|
280 | /* Advance the record index. */
|
---|
281 | pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
|
---|
282 |
|
---|
283 | LOGVBVABUFFER(("done ok, data = %d, free = %d\n",
|
---|
284 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
285 |
|
---|
286 | return true;
|
---|
287 | }
|
---|
288 |
|
---|
289 | static void vbvaReleaseCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR *pHdr, uint32_t cbCmd)
|
---|
290 | {
|
---|
291 | uint8_t *au8RingBuffer = &pVBVA->au8Data[0];
|
---|
292 |
|
---|
293 | if ( (uint8_t *)pHdr >= au8RingBuffer
|
---|
294 | && (uint8_t *)pHdr < &au8RingBuffer[pVBVA->cbData])
|
---|
295 | {
|
---|
296 | /* The pointer is inside ring buffer. Must be continuous chunk. */
|
---|
297 | Assert (pVBVA->cbData - ((uint8_t *)pHdr - au8RingBuffer) >= cbCmd);
|
---|
298 |
|
---|
299 | /* Do nothing. */
|
---|
300 |
|
---|
301 | Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
|
---|
302 | }
|
---|
303 | else
|
---|
304 | {
|
---|
305 | /* The pointer is outside. It is then an allocated copy. */
|
---|
306 | LOGVBVABUFFER(("Free heap %p\n", pHdr));
|
---|
307 |
|
---|
308 | if ((uint8_t *)pHdr == pPartialRecord->pu8)
|
---|
309 | {
|
---|
310 | pPartialRecord->pu8 = NULL;
|
---|
311 | pPartialRecord->cb = 0;
|
---|
312 | }
|
---|
313 | else
|
---|
314 | {
|
---|
315 | Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
|
---|
316 | }
|
---|
317 |
|
---|
318 | RTMemFree (pHdr);
|
---|
319 | }
|
---|
320 |
|
---|
321 | return;
|
---|
322 | }
|
---|
323 |
|
---|
324 | static int vbvaFlushProcess (unsigned uScreenId, PVGASTATE pVGAState, VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA)
|
---|
325 | {
|
---|
326 | LOGVBVABUFFER(("uScreenId %d, indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
|
---|
327 | uScreenId, pVBVA->indexRecordFirst, pVBVA->indexRecordFree, pVBVA->off32Data, pVBVA->off32Free));
|
---|
328 | struct {
|
---|
329 | /* The rectangle that includes all dirty rectangles. */
|
---|
330 | int32_t xLeft;
|
---|
331 | int32_t xRight;
|
---|
332 | int32_t yTop;
|
---|
333 | int32_t yBottom;
|
---|
334 | } dirtyRect;
|
---|
335 | RT_ZERO(dirtyRect);
|
---|
336 |
|
---|
337 | bool fUpdate = false; /* Whether there were any updates. */
|
---|
338 | bool fDirtyEmpty = true;
|
---|
339 |
|
---|
340 | for (;;)
|
---|
341 | {
|
---|
342 | VBVACMDHDR *phdr = NULL;
|
---|
343 | uint32_t cbCmd = ~0;
|
---|
344 |
|
---|
345 | /* Fetch the command data. */
|
---|
346 | if (!vbvaFetchCmd (pPartialRecord, pVBVA, &phdr, &cbCmd))
|
---|
347 | {
|
---|
348 | LogFunc(("unable to fetch command. off32Data = %d, off32Free = %d!!!\n",
|
---|
349 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
350 |
|
---|
351 | /* @todo old code disabled VBVA processing here. */
|
---|
352 | return VERR_NOT_SUPPORTED;
|
---|
353 | }
|
---|
354 |
|
---|
355 | if (cbCmd == uint32_t(~0))
|
---|
356 | {
|
---|
357 | /* No more commands yet in the queue. */
|
---|
358 | break;
|
---|
359 | }
|
---|
360 |
|
---|
361 | if (cbCmd != 0)
|
---|
362 | {
|
---|
363 | if (!fUpdate)
|
---|
364 | {
|
---|
365 | pVGAState->pDrv->pfnVBVAUpdateBegin (pVGAState->pDrv, uScreenId);
|
---|
366 | fUpdate = true;
|
---|
367 | }
|
---|
368 |
|
---|
369 | /* Updates the rectangle and sends the command to the VRDP server. */
|
---|
370 | pVGAState->pDrv->pfnVBVAUpdateProcess (pVGAState->pDrv, uScreenId, phdr, cbCmd);
|
---|
371 |
|
---|
372 | int32_t xRight = phdr->x + phdr->w;
|
---|
373 | int32_t yBottom = phdr->y + phdr->h;
|
---|
374 |
|
---|
375 | /* These are global coords, relative to the primary screen. */
|
---|
376 |
|
---|
377 | LOGVBVABUFFER(("cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
|
---|
378 | cbCmd, phdr->x, phdr->y, phdr->w, phdr->h));
|
---|
379 |
|
---|
380 | /* Collect all rects into one. */
|
---|
381 | if (fDirtyEmpty)
|
---|
382 | {
|
---|
383 | /* This is the first rectangle to be added. */
|
---|
384 | dirtyRect.xLeft = phdr->x;
|
---|
385 | dirtyRect.yTop = phdr->y;
|
---|
386 | dirtyRect.xRight = xRight;
|
---|
387 | dirtyRect.yBottom = yBottom;
|
---|
388 | fDirtyEmpty = false;
|
---|
389 | }
|
---|
390 | else
|
---|
391 | {
|
---|
392 | /* Adjust region coordinates. */
|
---|
393 | if (dirtyRect.xLeft > phdr->x)
|
---|
394 | {
|
---|
395 | dirtyRect.xLeft = phdr->x;
|
---|
396 | }
|
---|
397 |
|
---|
398 | if (dirtyRect.yTop > phdr->y)
|
---|
399 | {
|
---|
400 | dirtyRect.yTop = phdr->y;
|
---|
401 | }
|
---|
402 |
|
---|
403 | if (dirtyRect.xRight < xRight)
|
---|
404 | {
|
---|
405 | dirtyRect.xRight = xRight;
|
---|
406 | }
|
---|
407 |
|
---|
408 | if (dirtyRect.yBottom < yBottom)
|
---|
409 | {
|
---|
410 | dirtyRect.yBottom = yBottom;
|
---|
411 | }
|
---|
412 | }
|
---|
413 | }
|
---|
414 |
|
---|
415 | vbvaReleaseCmd (pPartialRecord, pVBVA, phdr, cbCmd);
|
---|
416 | }
|
---|
417 |
|
---|
418 | if (fUpdate)
|
---|
419 | {
|
---|
420 | if (dirtyRect.xRight - dirtyRect.xLeft)
|
---|
421 | {
|
---|
422 | pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, dirtyRect.xLeft, dirtyRect.yTop,
|
---|
423 | dirtyRect.xRight - dirtyRect.xLeft, dirtyRect.yBottom - dirtyRect.yTop);
|
---|
424 | }
|
---|
425 | else
|
---|
426 | {
|
---|
427 | pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, 0, 0, 0, 0);
|
---|
428 | }
|
---|
429 | }
|
---|
430 |
|
---|
431 | return VINF_SUCCESS;
|
---|
432 | }
|
---|
433 |
|
---|
434 | static int vbvaFlush (PVGASTATE pVGAState, VBVACONTEXT *pCtx)
|
---|
435 | {
|
---|
436 | unsigned uScreenId;
|
---|
437 |
|
---|
438 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
439 | {
|
---|
440 | VBVAPARTIALRECORD *pPartialRecord = &pCtx->aViews[uScreenId].partialRecord;
|
---|
441 | VBVABUFFER *pVBVA = pCtx->aViews[uScreenId].pVBVA;
|
---|
442 |
|
---|
443 | if (pVBVA)
|
---|
444 | {
|
---|
445 | vbvaFlushProcess (uScreenId, pVGAState, pPartialRecord, pVBVA);
|
---|
446 | }
|
---|
447 | }
|
---|
448 |
|
---|
449 | /* @todo rc */
|
---|
450 | return VINF_SUCCESS;
|
---|
451 | }
|
---|
452 |
|
---|
453 | static int vbvaResize (PVGASTATE pVGAState, VBVAVIEW *pView, const VBVAINFOSCREEN *pNewScreen)
|
---|
454 | {
|
---|
455 | /* Verify pNewScreen. */
|
---|
456 | /* @todo */
|
---|
457 |
|
---|
458 | /* Apply these changes. */
|
---|
459 | pView->screen = *pNewScreen;
|
---|
460 |
|
---|
461 | uint8_t *pu8VRAM = pVGAState->vram_ptrR3 + pView->view.u32ViewOffset;
|
---|
462 |
|
---|
463 | int rc = pVGAState->pDrv->pfnVBVAResize (pVGAState->pDrv, &pView->view, &pView->screen, pu8VRAM);
|
---|
464 |
|
---|
465 | /* @todo process VINF_VGA_RESIZE_IN_PROGRESS? */
|
---|
466 |
|
---|
467 | return rc;
|
---|
468 | }
|
---|
469 |
|
---|
470 | static int vbvaEnable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx, VBVABUFFER *pVBVA, uint32_t u32Offset, bool fRestored)
|
---|
471 | {
|
---|
472 | /* @todo old code did a UpdateDisplayAll at this place. */
|
---|
473 |
|
---|
474 | int rc;
|
---|
475 |
|
---|
476 | if (pVGAState->pDrv->pfnVBVAEnable)
|
---|
477 | {
|
---|
478 | pVBVA->hostFlags.u32HostEvents = 0;
|
---|
479 | pVBVA->hostFlags.u32SupportedOrders = 0;
|
---|
480 |
|
---|
481 | rc = pVGAState->pDrv->pfnVBVAEnable (pVGAState->pDrv, uScreenId, &pVBVA->hostFlags);
|
---|
482 | }
|
---|
483 | else
|
---|
484 | {
|
---|
485 | rc = VERR_NOT_SUPPORTED;
|
---|
486 | }
|
---|
487 |
|
---|
488 | if (RT_SUCCESS (rc))
|
---|
489 | {
|
---|
490 | /* pVBVA->hostFlags has been set up by pfnVBVAEnable. */
|
---|
491 | LogFlowFunc(("u32HostEvents 0x%08X, u32SupportedOrders 0x%08X\n",
|
---|
492 | pVBVA->hostFlags.u32HostEvents, pVBVA->hostFlags.u32SupportedOrders));
|
---|
493 |
|
---|
494 | if (!fRestored)
|
---|
495 | {
|
---|
496 | /* @todo Actually this function must not touch the partialRecord structure at all,
|
---|
497 | * because initially it is a zero and when VBVA is disabled this should be set to zero.
|
---|
498 | * But I'm not sure that no code depends on zeroing partialRecord here.
|
---|
499 | * So for now (a quick fix for 4.1) just do not do this if the VM was restored,
|
---|
500 | * when partialRecord might be loaded already from the saved state.
|
---|
501 | */
|
---|
502 | pCtx->aViews[uScreenId].partialRecord.pu8 = NULL;
|
---|
503 | pCtx->aViews[uScreenId].partialRecord.cb = 0;
|
---|
504 | }
|
---|
505 |
|
---|
506 | pCtx->aViews[uScreenId].pVBVA = pVBVA;
|
---|
507 | pCtx->aViews[uScreenId].u32VBVAOffset = u32Offset;
|
---|
508 | }
|
---|
509 |
|
---|
510 | return rc;
|
---|
511 | }
|
---|
512 |
|
---|
513 | static int vbvaDisable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx)
|
---|
514 | {
|
---|
515 | /* Process any pending orders and empty the VBVA ring buffer. */
|
---|
516 | vbvaFlush (pVGAState, pCtx);
|
---|
517 |
|
---|
518 | VBVAVIEW *pView = &pCtx->aViews[uScreenId];
|
---|
519 |
|
---|
520 | if (pView->pVBVA)
|
---|
521 | {
|
---|
522 | pView->pVBVA->hostFlags.u32HostEvents = 0;
|
---|
523 | pView->pVBVA->hostFlags.u32SupportedOrders = 0;
|
---|
524 |
|
---|
525 | pView->partialRecord.pu8 = NULL;
|
---|
526 | pView->partialRecord.cb = 0;
|
---|
527 |
|
---|
528 | pView->pVBVA = NULL;
|
---|
529 | pView->u32VBVAOffset = HGSMIOFFSET_VOID;
|
---|
530 | }
|
---|
531 |
|
---|
532 | pVGAState->pDrv->pfnVBVADisable (pVGAState->pDrv, uScreenId);
|
---|
533 | return VINF_SUCCESS;
|
---|
534 | }
|
---|
535 |
|
---|
536 | bool VBVAIsEnabled(PVGASTATE pVGAState)
|
---|
537 | {
|
---|
538 | PHGSMIINSTANCE pHGSMI = pVGAState->pHGSMI;
|
---|
539 | if (pHGSMI)
|
---|
540 | {
|
---|
541 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext(pHGSMI);
|
---|
542 | if (pCtx)
|
---|
543 | {
|
---|
544 | if (pCtx->cViews)
|
---|
545 | {
|
---|
546 | VBVAVIEW * pView = &pCtx->aViews[0];
|
---|
547 | if (pView->pVBVA)
|
---|
548 | return true;
|
---|
549 | }
|
---|
550 | }
|
---|
551 | }
|
---|
552 | return false;
|
---|
553 | }
|
---|
554 |
|
---|
555 | #ifdef DEBUG_sunlover
|
---|
556 | void dumpMouseShapeInfo(const VBVAMOUSESHAPEINFO *pMouseShapeInfo)
|
---|
557 | {
|
---|
558 | LogFlow(("fSet = %d, fVisible %d, fAlpha %d, @%d,%d %dx%d (%p, %d/%d)\n",
|
---|
559 | pMouseShapeInfo->fSet,
|
---|
560 | pMouseShapeInfo->fVisible,
|
---|
561 | pMouseShapeInfo->fAlpha,
|
---|
562 | pMouseShapeInfo->u32HotX,
|
---|
563 | pMouseShapeInfo->u32HotY,
|
---|
564 | pMouseShapeInfo->u32Width,
|
---|
565 | pMouseShapeInfo->u32Height,
|
---|
566 | pMouseShapeInfo->pu8Shape,
|
---|
567 | pMouseShapeInfo->cbShape,
|
---|
568 | pMouseShapeInfo->cbAllocated
|
---|
569 | ));
|
---|
570 | }
|
---|
571 | #endif
|
---|
572 |
|
---|
573 | static int vbvaUpdateMousePointerShape(PVGASTATE pVGAState, VBVAMOUSESHAPEINFO *pMouseShapeInfo, bool fShape, const uint8_t *pu8Shape)
|
---|
574 | {
|
---|
575 | int rc;
|
---|
576 | LogFlowFunc(("pVGAState %p, pMouseShapeInfo %p, fShape %d, pu8Shape %p\n",
|
---|
577 | pVGAState, pMouseShapeInfo, fShape, pu8Shape));
|
---|
578 | #ifdef DEBUG_sunlover
|
---|
579 | dumpMouseShapeInfo(pMouseShapeInfo);
|
---|
580 | #endif
|
---|
581 |
|
---|
582 | if (fShape && pu8Shape != NULL)
|
---|
583 | {
|
---|
584 | rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
|
---|
585 | pMouseShapeInfo->fVisible,
|
---|
586 | pMouseShapeInfo->fAlpha,
|
---|
587 | pMouseShapeInfo->u32HotX,
|
---|
588 | pMouseShapeInfo->u32HotY,
|
---|
589 | pMouseShapeInfo->u32Width,
|
---|
590 | pMouseShapeInfo->u32Height,
|
---|
591 | pu8Shape);
|
---|
592 | }
|
---|
593 | else
|
---|
594 | {
|
---|
595 | rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
|
---|
596 | pMouseShapeInfo->fVisible,
|
---|
597 | false,
|
---|
598 | 0, 0,
|
---|
599 | 0, 0,
|
---|
600 | NULL);
|
---|
601 | }
|
---|
602 |
|
---|
603 | return rc;
|
---|
604 | }
|
---|
605 |
|
---|
606 | static int vbvaMousePointerShape (PVGASTATE pVGAState, VBVACONTEXT *pCtx, const VBVAMOUSEPOINTERSHAPE *pShape, HGSMISIZE cbShape)
|
---|
607 | {
|
---|
608 | bool fVisible = (pShape->fu32Flags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
|
---|
609 | bool fAlpha = (pShape->fu32Flags & VBOX_MOUSE_POINTER_ALPHA) != 0;
|
---|
610 | bool fShape = (pShape->fu32Flags & VBOX_MOUSE_POINTER_SHAPE) != 0;
|
---|
611 |
|
---|
612 | HGSMISIZE cbPointerData = 0;
|
---|
613 |
|
---|
614 | if (fShape)
|
---|
615 | {
|
---|
616 | cbPointerData = ((((pShape->u32Width + 7) / 8) * pShape->u32Height + 3) & ~3)
|
---|
617 | + pShape->u32Width * 4 * pShape->u32Height;
|
---|
618 | }
|
---|
619 |
|
---|
620 | if (cbPointerData > cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data))
|
---|
621 | {
|
---|
622 | Log(("vbvaMousePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
|
---|
623 | cbPointerData, cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data)));
|
---|
624 | return VERR_INVALID_PARAMETER;
|
---|
625 | }
|
---|
626 |
|
---|
627 | /* Save mouse info it will be used to restore mouse pointer after restoring saved state. */
|
---|
628 | pCtx->mouseShapeInfo.fSet = true;
|
---|
629 | pCtx->mouseShapeInfo.fVisible = fVisible;
|
---|
630 | pCtx->mouseShapeInfo.fAlpha = fAlpha;
|
---|
631 | if (fShape)
|
---|
632 | {
|
---|
633 | /* Data related to shape. */
|
---|
634 | pCtx->mouseShapeInfo.u32HotX = pShape->u32HotX;
|
---|
635 | pCtx->mouseShapeInfo.u32HotY = pShape->u32HotY;
|
---|
636 | pCtx->mouseShapeInfo.u32Width = pShape->u32Width;
|
---|
637 | pCtx->mouseShapeInfo.u32Height = pShape->u32Height;
|
---|
638 |
|
---|
639 | /* Reallocate memory buffer if necessary. */
|
---|
640 | if (cbPointerData > pCtx->mouseShapeInfo.cbAllocated)
|
---|
641 | {
|
---|
642 | RTMemFree (pCtx->mouseShapeInfo.pu8Shape);
|
---|
643 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
644 | pCtx->mouseShapeInfo.cbShape = 0;
|
---|
645 |
|
---|
646 | uint8_t *pu8Shape = (uint8_t *)RTMemAlloc (cbPointerData);
|
---|
647 | if (pu8Shape)
|
---|
648 | {
|
---|
649 | pCtx->mouseShapeInfo.pu8Shape = pu8Shape;
|
---|
650 | pCtx->mouseShapeInfo.cbAllocated = cbPointerData;
|
---|
651 | }
|
---|
652 | }
|
---|
653 |
|
---|
654 | /* Copy shape bitmaps. */
|
---|
655 | if (pCtx->mouseShapeInfo.pu8Shape)
|
---|
656 | {
|
---|
657 | memcpy (pCtx->mouseShapeInfo.pu8Shape, &pShape->au8Data[0], cbPointerData);
|
---|
658 | pCtx->mouseShapeInfo.cbShape = cbPointerData;
|
---|
659 | }
|
---|
660 | }
|
---|
661 |
|
---|
662 | if (pVGAState->pDrv->pfnVBVAMousePointerShape == NULL)
|
---|
663 | {
|
---|
664 | return VERR_NOT_SUPPORTED;
|
---|
665 | }
|
---|
666 |
|
---|
667 | int rc = vbvaUpdateMousePointerShape(pVGAState, &pCtx->mouseShapeInfo, fShape, &pShape->au8Data[0]);
|
---|
668 |
|
---|
669 | return rc;
|
---|
670 | }
|
---|
671 |
|
---|
672 | static unsigned vbvaViewFromOffset (PHGSMIINSTANCE pIns, VBVACONTEXT *pCtx, const void *pvBuffer)
|
---|
673 | {
|
---|
674 | /* Check which view contains the buffer. */
|
---|
675 | HGSMIOFFSET offBuffer = HGSMIPointerToOffsetHost (pIns, pvBuffer);
|
---|
676 |
|
---|
677 | if (offBuffer != HGSMIOFFSET_VOID)
|
---|
678 | {
|
---|
679 | unsigned uScreenId;
|
---|
680 |
|
---|
681 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
682 | {
|
---|
683 | VBVAINFOVIEW *pView = &pCtx->aViews[uScreenId].view;
|
---|
684 |
|
---|
685 | if ( pView->u32ViewSize > 0
|
---|
686 | && pView->u32ViewOffset <= offBuffer
|
---|
687 | && offBuffer <= pView->u32ViewOffset + pView->u32ViewSize - 1)
|
---|
688 | {
|
---|
689 | return pView->u32ViewIndex;
|
---|
690 | }
|
---|
691 | }
|
---|
692 | }
|
---|
693 |
|
---|
694 | return ~0U;
|
---|
695 | }
|
---|
696 |
|
---|
697 | #ifdef DEBUG_sunlover
|
---|
698 | static void dumpctx(const VBVACONTEXT *pCtx)
|
---|
699 | {
|
---|
700 | Log(("VBVACONTEXT dump: cViews %d\n", pCtx->cViews));
|
---|
701 |
|
---|
702 | uint32_t iView;
|
---|
703 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
704 | {
|
---|
705 | const VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
706 |
|
---|
707 | Log((" view %d o 0x%x s 0x%x m 0x%x\n",
|
---|
708 | pView->view.u32ViewIndex,
|
---|
709 | pView->view.u32ViewOffset,
|
---|
710 | pView->view.u32ViewSize,
|
---|
711 | pView->view.u32MaxScreenSize));
|
---|
712 |
|
---|
713 | Log((" screen %d @%d,%d s 0x%x l 0x%x %dx%d bpp %d f 0x%x\n",
|
---|
714 | pView->screen.u32ViewIndex,
|
---|
715 | pView->screen.i32OriginX,
|
---|
716 | pView->screen.i32OriginY,
|
---|
717 | pView->screen.u32StartOffset,
|
---|
718 | pView->screen.u32LineSize,
|
---|
719 | pView->screen.u32Width,
|
---|
720 | pView->screen.u32Height,
|
---|
721 | pView->screen.u16BitsPerPixel,
|
---|
722 | pView->screen.u16Flags));
|
---|
723 |
|
---|
724 | Log((" VBVA o 0x%x p %p\n",
|
---|
725 | pView->u32VBVAOffset,
|
---|
726 | pView->pVBVA));
|
---|
727 |
|
---|
728 | Log((" PR cb 0x%x p %p\n",
|
---|
729 | pView->partialRecord.cb,
|
---|
730 | pView->partialRecord.pu8));
|
---|
731 | }
|
---|
732 |
|
---|
733 | dumpMouseShapeInfo(&pCtx->mouseShapeInfo);
|
---|
734 | }
|
---|
735 | #endif /* DEBUG_sunlover */
|
---|
736 |
|
---|
737 | #define VBOXVBVASAVEDSTATE_VHWAAVAILABLE_MAGIC 0x12345678
|
---|
738 | #define VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC 0x9abcdef0
|
---|
739 |
|
---|
740 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
741 | static void vbvaVHWAHHCommandReinit(VBOXVHWACMD* pHdr, VBOXVHWACMD_TYPE enmCmd, int32_t iDisplay)
|
---|
742 | {
|
---|
743 | memset(pHdr, 0, VBOXVHWACMD_HEADSIZE());
|
---|
744 | pHdr->cRefs = 1;
|
---|
745 | pHdr->iDisplay = iDisplay;
|
---|
746 | pHdr->rc = VERR_NOT_IMPLEMENTED;
|
---|
747 | pHdr->enmCmd = enmCmd;
|
---|
748 | pHdr->Flags = VBOXVHWACMD_FLAG_HH_CMD;
|
---|
749 | }
|
---|
750 |
|
---|
751 | static VBOXVHWACMD* vbvaVHWAHHCommandCreate (PVGASTATE pVGAState, VBOXVHWACMD_TYPE enmCmd, int32_t iDisplay, VBOXVHWACMD_LENGTH cbCmd)
|
---|
752 | {
|
---|
753 | VBOXVHWACMD* pHdr = (VBOXVHWACMD*)RTMemAlloc(cbCmd + VBOXVHWACMD_HEADSIZE());
|
---|
754 | Assert(pHdr);
|
---|
755 | if (pHdr)
|
---|
756 | vbvaVHWAHHCommandReinit(pHdr, enmCmd, iDisplay);
|
---|
757 |
|
---|
758 | return pHdr;
|
---|
759 | }
|
---|
760 |
|
---|
761 | DECLINLINE(void) vbvaVHWAHHCommandRelease (VBOXVHWACMD* pCmd)
|
---|
762 | {
|
---|
763 | uint32_t cRefs = ASMAtomicDecU32(&pCmd->cRefs);
|
---|
764 | if(!cRefs)
|
---|
765 | {
|
---|
766 | RTMemFree(pCmd);
|
---|
767 | }
|
---|
768 | }
|
---|
769 |
|
---|
770 | DECLINLINE(void) vbvaVHWAHHCommandRetain (VBOXVHWACMD* pCmd)
|
---|
771 | {
|
---|
772 | ASMAtomicIncU32(&pCmd->cRefs);
|
---|
773 | }
|
---|
774 |
|
---|
775 | static unsigned vbvaVHWAHandleCommand (PVGASTATE pVGAState, VBVACONTEXT *pCtx, PVBOXVHWACMD pCmd)
|
---|
776 | {
|
---|
777 | if (pVGAState->pDrv->pfnVHWACommandProcess)
|
---|
778 | pVGAState->pDrv->pfnVHWACommandProcess(pVGAState->pDrv, pCmd);
|
---|
779 | #ifdef DEBUG_misha
|
---|
780 | else
|
---|
781 | AssertFailed();
|
---|
782 | #endif
|
---|
783 | return 0;
|
---|
784 | }
|
---|
785 |
|
---|
786 | static DECLCALLBACK(void) vbvaVHWAHHCommandSetEventCallback(void * pContext)
|
---|
787 | {
|
---|
788 | RTSemEventSignal((RTSEMEVENT)pContext);
|
---|
789 | }
|
---|
790 |
|
---|
791 | static int vbvaVHWAHHCommandPost(PVGASTATE pVGAState, VBOXVHWACMD* pCmd)
|
---|
792 | {
|
---|
793 | RTSEMEVENT hComplEvent;
|
---|
794 | int rc = RTSemEventCreate(&hComplEvent);
|
---|
795 | AssertRC(rc);
|
---|
796 | if(RT_SUCCESS(rc))
|
---|
797 | {
|
---|
798 | /* ensure the cmd is not deleted until we process it */
|
---|
799 | vbvaVHWAHHCommandRetain (pCmd);
|
---|
800 | VBOXVHWA_HH_CALLBACK_SET(pCmd, vbvaVHWAHHCommandSetEventCallback, (void*)hComplEvent);
|
---|
801 | vbvaVHWAHandleCommand(pVGAState, NULL, pCmd);
|
---|
802 | if((ASMAtomicReadU32((volatile uint32_t *)&pCmd->Flags) & VBOXVHWACMD_FLAG_HG_ASYNCH) != 0)
|
---|
803 | {
|
---|
804 | rc = RTSemEventWaitNoResume(hComplEvent, RT_INDEFINITE_WAIT);
|
---|
805 | }
|
---|
806 | else
|
---|
807 | {
|
---|
808 | /* the command is completed */
|
---|
809 | }
|
---|
810 |
|
---|
811 | AssertRC(rc);
|
---|
812 | if(RT_SUCCESS(rc))
|
---|
813 | {
|
---|
814 | RTSemEventDestroy(hComplEvent);
|
---|
815 | }
|
---|
816 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
817 | }
|
---|
818 | return rc;
|
---|
819 | }
|
---|
820 |
|
---|
821 | int vbvaVHWAConstruct (PVGASTATE pVGAState)
|
---|
822 | {
|
---|
823 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_CONSTRUCT, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
|
---|
824 | Assert(pCmd);
|
---|
825 | if(pCmd)
|
---|
826 | {
|
---|
827 | uint32_t iDisplay = 0;
|
---|
828 | int rc = VINF_SUCCESS;
|
---|
829 | VBOXVHWACMD_HH_CONSTRUCT * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_CONSTRUCT);
|
---|
830 |
|
---|
831 | do
|
---|
832 | {
|
---|
833 | memset(pBody, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
|
---|
834 |
|
---|
835 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
836 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
837 |
|
---|
838 | pBody->pVM = pVM;
|
---|
839 | pBody->pvVRAM = pVGAState->vram_ptrR3;
|
---|
840 | pBody->cbVRAM = pVGAState->vram_size;
|
---|
841 |
|
---|
842 | rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
843 | AssertRC(rc);
|
---|
844 | if(RT_SUCCESS(rc))
|
---|
845 | {
|
---|
846 | rc = pCmd->rc;
|
---|
847 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
848 | if(rc == VERR_NOT_IMPLEMENTED)
|
---|
849 | {
|
---|
850 | /* @todo: set some flag in pVGAState indicating VHWA is not supported */
|
---|
851 | /* VERR_NOT_IMPLEMENTED is not a failure, we just do not support it */
|
---|
852 | rc = VINF_SUCCESS;
|
---|
853 | }
|
---|
854 |
|
---|
855 | if (!RT_SUCCESS(rc))
|
---|
856 | break;
|
---|
857 | }
|
---|
858 | else
|
---|
859 | break;
|
---|
860 |
|
---|
861 | ++iDisplay;
|
---|
862 | if (iDisplay >= pVGAState->cMonitors)
|
---|
863 | break;
|
---|
864 | vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_CONSTRUCT, (int32_t)iDisplay);
|
---|
865 | } while (true);
|
---|
866 |
|
---|
867 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
868 |
|
---|
869 | return rc;
|
---|
870 | }
|
---|
871 | return VERR_OUT_OF_RESOURCES;
|
---|
872 | }
|
---|
873 |
|
---|
874 | int vbvaVHWAReset (PVGASTATE pVGAState)
|
---|
875 | {
|
---|
876 | /* ensure we have all pending cmds processed and h->g cmds disabled */
|
---|
877 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_RESET, 0, 0);
|
---|
878 | Assert(pCmd);
|
---|
879 | if(pCmd)
|
---|
880 | {
|
---|
881 | int rc = VINF_SUCCESS;
|
---|
882 | uint32_t iDisplay = 0;
|
---|
883 |
|
---|
884 | do
|
---|
885 | {
|
---|
886 | rc =vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
887 | AssertRC(rc);
|
---|
888 | if(RT_SUCCESS(rc))
|
---|
889 | {
|
---|
890 | rc = pCmd->rc;
|
---|
891 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
892 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
893 | rc = VINF_SUCCESS;
|
---|
894 | }
|
---|
895 |
|
---|
896 | if (!RT_SUCCESS(rc))
|
---|
897 | break;
|
---|
898 |
|
---|
899 | ++iDisplay;
|
---|
900 | if (iDisplay >= pVGAState->cMonitors)
|
---|
901 | break;
|
---|
902 | vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_RESET, (int32_t)iDisplay);
|
---|
903 |
|
---|
904 | } while (true);
|
---|
905 |
|
---|
906 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
907 |
|
---|
908 | return rc;
|
---|
909 | }
|
---|
910 | return VERR_OUT_OF_RESOURCES;
|
---|
911 | }
|
---|
912 |
|
---|
913 | typedef DECLCALLBACK(bool) FNVBOXVHWAHHCMDPRECB(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, void *pvContext);
|
---|
914 | typedef FNVBOXVHWAHHCMDPRECB *PFNVBOXVHWAHHCMDPRECB;
|
---|
915 |
|
---|
916 | typedef DECLCALLBACK(bool) FNVBOXVHWAHHCMDPOSTCB(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, int rc, void *pvContext);
|
---|
917 | typedef FNVBOXVHWAHHCMDPOSTCB *PFNVBOXVHWAHHCMDPOSTCB;
|
---|
918 |
|
---|
919 | int vbvaVHWAHHPost(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, PFNVBOXVHWAHHCMDPRECB pfnPre, PFNVBOXVHWAHHCMDPOSTCB pfnPost, void *pvContext)
|
---|
920 | {
|
---|
921 | const VBOXVHWACMD_TYPE enmType = pCmd->enmCmd;
|
---|
922 | int rc = VINF_SUCCESS;
|
---|
923 | uint32_t iDisplay = 0;
|
---|
924 |
|
---|
925 | do
|
---|
926 | {
|
---|
927 | if (!pfnPre || pfnPre(pVGAState, pCmd, iDisplay, pvContext))
|
---|
928 | {
|
---|
929 | rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
930 | AssertRC(rc);
|
---|
931 | if (pfnPost)
|
---|
932 | {
|
---|
933 | if (!pfnPost(pVGAState, pCmd, iDisplay, rc, pvContext))
|
---|
934 | {
|
---|
935 | rc = VINF_SUCCESS;
|
---|
936 | break;
|
---|
937 | }
|
---|
938 | rc = VINF_SUCCESS;
|
---|
939 | }
|
---|
940 | else if(RT_SUCCESS(rc))
|
---|
941 | {
|
---|
942 | rc = pCmd->rc;
|
---|
943 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
944 | if(rc == VERR_NOT_IMPLEMENTED)
|
---|
945 | {
|
---|
946 | rc = VINF_SUCCESS;
|
---|
947 | }
|
---|
948 | }
|
---|
949 |
|
---|
950 | if (!RT_SUCCESS(rc))
|
---|
951 | break;
|
---|
952 | }
|
---|
953 |
|
---|
954 | ++iDisplay;
|
---|
955 | if (iDisplay >= pVGAState->cMonitors)
|
---|
956 | break;
|
---|
957 | vbvaVHWAHHCommandReinit(pCmd, enmType, (int32_t)iDisplay);
|
---|
958 | } while (true);
|
---|
959 |
|
---|
960 | return rc;
|
---|
961 | }
|
---|
962 |
|
---|
963 | /* @todo call this also on reset? */
|
---|
964 | int vbvaVHWAEnable (PVGASTATE pVGAState, bool bEnable)
|
---|
965 | {
|
---|
966 | const VBOXVHWACMD_TYPE enmType = bEnable ? VBOXVHWACMD_TYPE_HH_ENABLE : VBOXVHWACMD_TYPE_HH_DISABLE;
|
---|
967 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState,
|
---|
968 | enmType,
|
---|
969 | 0, 0);
|
---|
970 | Assert(pCmd);
|
---|
971 | if(pCmd)
|
---|
972 | {
|
---|
973 | int rc = vbvaVHWAHHPost (pVGAState, pCmd, NULL, NULL, NULL);
|
---|
974 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
975 | return rc;
|
---|
976 | }
|
---|
977 | return VERR_OUT_OF_RESOURCES;
|
---|
978 | }
|
---|
979 |
|
---|
980 | int vboxVBVASaveStatePrep (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
981 | {
|
---|
982 | /* ensure we have no pending commands */
|
---|
983 | return vbvaVHWAEnable(PDMINS_2_DATA(pDevIns, PVGASTATE), false);
|
---|
984 | }
|
---|
985 |
|
---|
986 | int vboxVBVASaveStateDone (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
987 | {
|
---|
988 | /* ensure we have no pending commands */
|
---|
989 | return vbvaVHWAEnable(PDMINS_2_DATA(pDevIns, PVGASTATE), true);
|
---|
990 | }
|
---|
991 |
|
---|
992 | int vbvaVHWACommandCompleteAsynch(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVHWACMD pCmd)
|
---|
993 | {
|
---|
994 | int rc;
|
---|
995 | if((pCmd->Flags & VBOXVHWACMD_FLAG_HH_CMD) == 0)
|
---|
996 | {
|
---|
997 | PVGASTATE pVGAState = PPDMIDISPLAYVBVACALLBACKS_2_PVGASTATE(pInterface);
|
---|
998 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
999 |
|
---|
1000 | Assert(pCmd->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH);
|
---|
1001 | #ifdef VBOX_WITH_WDDM
|
---|
1002 | if (pVGAState->fGuestCaps & VBVACAPS_COMPLETEGCMD_BY_IOREAD)
|
---|
1003 | {
|
---|
1004 | rc = HGSMICompleteGuestCommand(pIns, pCmd, !!(pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ));
|
---|
1005 | AssertRC(rc);
|
---|
1006 | }
|
---|
1007 | else
|
---|
1008 | #endif
|
---|
1009 | {
|
---|
1010 | VBVAHOSTCMD *pHostCmd;
|
---|
1011 | int32_t iDisplay = pCmd->iDisplay;
|
---|
1012 |
|
---|
1013 | if(pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_EVENT)
|
---|
1014 | {
|
---|
1015 | rc = HGSMIHostCommandAlloc (pIns,
|
---|
1016 | (void**)&pHostCmd,
|
---|
1017 | VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDEVENT)),
|
---|
1018 | HGSMI_CH_VBVA,
|
---|
1019 | VBVAHG_EVENT);
|
---|
1020 | AssertRC(rc);
|
---|
1021 | if(RT_SUCCESS(rc))
|
---|
1022 | {
|
---|
1023 | memset(pHostCmd, 0 , VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDEVENT)));
|
---|
1024 | pHostCmd->iDstID = pCmd->iDisplay;
|
---|
1025 | pHostCmd->customOpCode = 0;
|
---|
1026 | VBVAHOSTCMDEVENT *pBody = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDEVENT);
|
---|
1027 | pBody->pEvent = pCmd->GuestVBVAReserved1;
|
---|
1028 | }
|
---|
1029 | }
|
---|
1030 | else
|
---|
1031 | {
|
---|
1032 | HGSMIOFFSET offCmd = HGSMIPointerToOffsetHost (pIns, pCmd);
|
---|
1033 | Assert(offCmd != HGSMIOFFSET_VOID);
|
---|
1034 | if(offCmd != HGSMIOFFSET_VOID)
|
---|
1035 | {
|
---|
1036 | rc = HGSMIHostCommandAlloc (pIns,
|
---|
1037 | (void**)&pHostCmd,
|
---|
1038 | VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDVHWACMDCOMPLETE)),
|
---|
1039 | HGSMI_CH_VBVA,
|
---|
1040 | VBVAHG_DISPLAY_CUSTOM);
|
---|
1041 | AssertRC(rc);
|
---|
1042 | if(RT_SUCCESS(rc))
|
---|
1043 | {
|
---|
1044 | memset(pHostCmd, 0 , VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDVHWACMDCOMPLETE)));
|
---|
1045 | pHostCmd->iDstID = pCmd->iDisplay;
|
---|
1046 | pHostCmd->customOpCode = VBVAHG_DCUSTOM_VHWA_CMDCOMPLETE;
|
---|
1047 | VBVAHOSTCMDVHWACMDCOMPLETE *pBody = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDVHWACMDCOMPLETE);
|
---|
1048 | pBody->offCmd = offCmd;
|
---|
1049 | }
|
---|
1050 | }
|
---|
1051 | else
|
---|
1052 | {
|
---|
1053 | rc = VERR_INVALID_PARAMETER;
|
---|
1054 | }
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | if(RT_SUCCESS(rc))
|
---|
1058 | {
|
---|
1059 | rc = HGSMIHostCommandProcessAndFreeAsynch(pIns, pHostCmd, (pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ) != 0);
|
---|
1060 | AssertRC(rc);
|
---|
1061 | if(RT_SUCCESS(rc))
|
---|
1062 | {
|
---|
1063 | return rc;
|
---|
1064 | }
|
---|
1065 | HGSMIHostCommandFree (pIns, pHostCmd);
|
---|
1066 | }
|
---|
1067 | }
|
---|
1068 | }
|
---|
1069 | else
|
---|
1070 | {
|
---|
1071 | PFNVBOXVHWA_HH_CALLBACK pfn = VBOXVHWA_HH_CALLBACK_GET(pCmd);
|
---|
1072 | if(pfn)
|
---|
1073 | {
|
---|
1074 | pfn(VBOXVHWA_HH_CALLBACK_GET_ARG(pCmd));
|
---|
1075 | }
|
---|
1076 | rc = VINF_SUCCESS;
|
---|
1077 | }
|
---|
1078 | return rc;
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | typedef struct VBOXVBVASAVEDSTATECBDATA
|
---|
1082 | {
|
---|
1083 | PSSMHANDLE pSSM;
|
---|
1084 | int rc;
|
---|
1085 | bool ab2DOn[VBOX_VIDEO_MAX_SCREENS];
|
---|
1086 | } VBOXVBVASAVEDSTATECBDATA, *PVBOXVBVASAVEDSTATECBDATA;
|
---|
1087 |
|
---|
1088 | static DECLCALLBACK(bool) vboxVBVASaveStateBeginPostCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, int rc, void *pvContext)
|
---|
1089 | {
|
---|
1090 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1091 | if (RT_FAILURE(pData->rc))
|
---|
1092 | return false;
|
---|
1093 | if (RT_FAILURE(rc))
|
---|
1094 | {
|
---|
1095 | pData->rc = rc;
|
---|
1096 | return false;
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1100 | if (iDisplay >= RT_ELEMENTS(pData->ab2DOn))
|
---|
1101 | {
|
---|
1102 | pData->rc = VERR_INVALID_PARAMETER;
|
---|
1103 | return false;
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | Assert(RT_SUCCESS(pCmd->rc) || pCmd->rc == VERR_NOT_IMPLEMENTED);
|
---|
1107 | if (RT_SUCCESS(pCmd->rc))
|
---|
1108 | {
|
---|
1109 | pData->ab2DOn[iDisplay] = true;
|
---|
1110 | }
|
---|
1111 | else if (pCmd->rc != VERR_NOT_IMPLEMENTED)
|
---|
1112 | {
|
---|
1113 | pData->rc = pCmd->rc;
|
---|
1114 | return false;
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | return true;
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 | static DECLCALLBACK(bool) vboxVBVASaveStatePerformPreCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, void *pvContext)
|
---|
1121 | {
|
---|
1122 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1123 | if (RT_FAILURE(pData->rc))
|
---|
1124 | return false;
|
---|
1125 |
|
---|
1126 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1127 | if (iDisplay >= RT_ELEMENTS(pData->ab2DOn))
|
---|
1128 | {
|
---|
1129 | pData->rc = VERR_INVALID_PARAMETER;
|
---|
1130 | return false;
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | int rc;
|
---|
1134 |
|
---|
1135 | if (pData->ab2DOn[iDisplay])
|
---|
1136 | {
|
---|
1137 | rc = SSMR3PutU32 (pData->pSSM, VBOXVBVASAVEDSTATE_VHWAAVAILABLE_MAGIC); AssertRC(rc);
|
---|
1138 | if (RT_FAILURE(rc))
|
---|
1139 | {
|
---|
1140 | pData->rc = rc;
|
---|
1141 | return false;
|
---|
1142 | }
|
---|
1143 | return true;
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | rc = SSMR3PutU32 (pData->pSSM, VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC); AssertRC(rc);
|
---|
1147 | if (RT_FAILURE(rc))
|
---|
1148 | {
|
---|
1149 | pData->rc = rc;
|
---|
1150 | return false;
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | return false;
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | static DECLCALLBACK(bool) vboxVBVASaveStateEndPreCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, void *pvContext)
|
---|
1157 | {
|
---|
1158 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1159 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1160 | if (pData->ab2DOn[iDisplay])
|
---|
1161 | {
|
---|
1162 | return true;
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | return false;
|
---|
1166 | }
|
---|
1167 |
|
---|
1168 | static DECLCALLBACK(bool) vboxVBVALoadStatePerformPostCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, int rc, void *pvContext)
|
---|
1169 | {
|
---|
1170 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1171 | if (RT_FAILURE(pData->rc))
|
---|
1172 | return false;
|
---|
1173 | if (RT_FAILURE(rc))
|
---|
1174 | {
|
---|
1175 | pData->rc = rc;
|
---|
1176 | return false;
|
---|
1177 | }
|
---|
1178 |
|
---|
1179 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1180 | if (iDisplay >= RT_ELEMENTS(pData->ab2DOn))
|
---|
1181 | {
|
---|
1182 | pData->rc = VERR_INVALID_PARAMETER;
|
---|
1183 | return false;
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | Assert(RT_SUCCESS(pCmd->rc) || pCmd->rc == VERR_NOT_IMPLEMENTED);
|
---|
1187 | if (pCmd->rc == VERR_NOT_IMPLEMENTED)
|
---|
1188 | {
|
---|
1189 | pData->rc = SSMR3SkipToEndOfUnit(pData->pSSM);
|
---|
1190 | AssertRC(pData->rc);
|
---|
1191 | return false;
|
---|
1192 | }
|
---|
1193 | if (RT_FAILURE(pCmd->rc))
|
---|
1194 | {
|
---|
1195 | pData->rc = pCmd->rc;
|
---|
1196 | return false;
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | return true;
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | static DECLCALLBACK(bool) vboxVBVALoadStatePerformPreCb(PVGASTATE pVGAState, VBOXVHWACMD *pCmd, uint32_t iDisplay, void *pvContext)
|
---|
1203 | {
|
---|
1204 | PVBOXVBVASAVEDSTATECBDATA pData = (PVBOXVBVASAVEDSTATECBDATA)pvContext;
|
---|
1205 | if (RT_FAILURE(pData->rc))
|
---|
1206 | return false;
|
---|
1207 |
|
---|
1208 | Assert(iDisplay < RT_ELEMENTS(pData->ab2DOn));
|
---|
1209 | if (iDisplay >= RT_ELEMENTS(pData->ab2DOn))
|
---|
1210 | {
|
---|
1211 | pData->rc = VERR_INVALID_PARAMETER;
|
---|
1212 | return false;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | int rc;
|
---|
1216 | uint32_t u32;
|
---|
1217 | rc = SSMR3GetU32(pData->pSSM, &u32); AssertRC(rc);
|
---|
1218 | if (RT_FAILURE(rc))
|
---|
1219 | {
|
---|
1220 | pData->rc = rc;
|
---|
1221 | return false;
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | switch (u32)
|
---|
1225 | {
|
---|
1226 | case VBOXVBVASAVEDSTATE_VHWAAVAILABLE_MAGIC:
|
---|
1227 | return true;
|
---|
1228 | case VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC:
|
---|
1229 | return false;
|
---|
1230 | default:
|
---|
1231 | pData->rc = VERR_INVALID_STATE;
|
---|
1232 | return false;
|
---|
1233 | }
|
---|
1234 | }
|
---|
1235 | #endif /* #ifdef VBOX_WITH_VIDEOHWACCEL */
|
---|
1236 |
|
---|
1237 | int vboxVBVASaveDevStateExec (PVGASTATE pVGAState, PSSMHANDLE pSSM)
|
---|
1238 | {
|
---|
1239 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1240 | int rc = HGSMIHostSaveStateExec (pIns, pSSM);
|
---|
1241 | if (RT_SUCCESS(rc))
|
---|
1242 | {
|
---|
1243 | /* Save VBVACONTEXT. */
|
---|
1244 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
1245 |
|
---|
1246 | if (!pCtx)
|
---|
1247 | {
|
---|
1248 | AssertFailed();
|
---|
1249 |
|
---|
1250 | /* Still write a valid value to the SSM. */
|
---|
1251 | rc = SSMR3PutU32 (pSSM, 0);
|
---|
1252 | AssertRCReturn(rc, rc);
|
---|
1253 | }
|
---|
1254 | else
|
---|
1255 | {
|
---|
1256 | #ifdef DEBUG_sunlover
|
---|
1257 | dumpctx(pCtx);
|
---|
1258 | #endif
|
---|
1259 |
|
---|
1260 | rc = SSMR3PutU32 (pSSM, pCtx->cViews);
|
---|
1261 | AssertRCReturn(rc, rc);
|
---|
1262 |
|
---|
1263 | uint32_t iView;
|
---|
1264 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
1265 | {
|
---|
1266 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
1267 |
|
---|
1268 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewIndex);
|
---|
1269 | AssertRCReturn(rc, rc);
|
---|
1270 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewOffset);
|
---|
1271 | AssertRCReturn(rc, rc);
|
---|
1272 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewSize);
|
---|
1273 | AssertRCReturn(rc, rc);
|
---|
1274 | rc = SSMR3PutU32 (pSSM, pView->view.u32MaxScreenSize);
|
---|
1275 | AssertRCReturn(rc, rc);
|
---|
1276 |
|
---|
1277 | rc = SSMR3PutU32 (pSSM, pView->screen.u32ViewIndex);
|
---|
1278 | AssertRCReturn(rc, rc);
|
---|
1279 | rc = SSMR3PutS32 (pSSM, pView->screen.i32OriginX);
|
---|
1280 | AssertRCReturn(rc, rc);
|
---|
1281 | rc = SSMR3PutS32 (pSSM, pView->screen.i32OriginY);
|
---|
1282 | AssertRCReturn(rc, rc);
|
---|
1283 | rc = SSMR3PutU32 (pSSM, pView->screen.u32StartOffset);
|
---|
1284 | AssertRCReturn(rc, rc);
|
---|
1285 | rc = SSMR3PutU32 (pSSM, pView->screen.u32LineSize);
|
---|
1286 | AssertRCReturn(rc, rc);
|
---|
1287 | rc = SSMR3PutU32 (pSSM, pView->screen.u32Width);
|
---|
1288 | AssertRCReturn(rc, rc);
|
---|
1289 | rc = SSMR3PutU32 (pSSM, pView->screen.u32Height);
|
---|
1290 | AssertRCReturn(rc, rc);
|
---|
1291 | rc = SSMR3PutU16 (pSSM, pView->screen.u16BitsPerPixel);
|
---|
1292 | AssertRCReturn(rc, rc);
|
---|
1293 | rc = SSMR3PutU16 (pSSM, pView->screen.u16Flags);
|
---|
1294 | AssertRCReturn(rc, rc);
|
---|
1295 |
|
---|
1296 | rc = SSMR3PutU32 (pSSM, pView->pVBVA? pView->u32VBVAOffset: HGSMIOFFSET_VOID);
|
---|
1297 | AssertRCReturn(rc, rc);
|
---|
1298 |
|
---|
1299 | rc = SSMR3PutU32 (pSSM, pView->partialRecord.cb);
|
---|
1300 | AssertRCReturn(rc, rc);
|
---|
1301 |
|
---|
1302 | if (pView->partialRecord.cb > 0)
|
---|
1303 | {
|
---|
1304 | rc = SSMR3PutMem (pSSM, pView->partialRecord.pu8, pView->partialRecord.cb);
|
---|
1305 | AssertRCReturn(rc, rc);
|
---|
1306 | }
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | /* Save mouse pointer shape information. */
|
---|
1310 | rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fSet);
|
---|
1311 | AssertRCReturn(rc, rc);
|
---|
1312 | rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fVisible);
|
---|
1313 | AssertRCReturn(rc, rc);
|
---|
1314 | rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fAlpha);
|
---|
1315 | AssertRCReturn(rc, rc);
|
---|
1316 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32HotX);
|
---|
1317 | AssertRCReturn(rc, rc);
|
---|
1318 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32HotY);
|
---|
1319 | AssertRCReturn(rc, rc);
|
---|
1320 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32Width);
|
---|
1321 | AssertRCReturn(rc, rc);
|
---|
1322 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32Height);
|
---|
1323 | AssertRCReturn(rc, rc);
|
---|
1324 | rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.cbShape);
|
---|
1325 | AssertRCReturn(rc, rc);
|
---|
1326 | if (pCtx->mouseShapeInfo.cbShape)
|
---|
1327 | {
|
---|
1328 | rc = SSMR3PutMem (pSSM, pCtx->mouseShapeInfo.pu8Shape, pCtx->mouseShapeInfo.cbShape);
|
---|
1329 | AssertRCReturn(rc, rc);
|
---|
1330 | }
|
---|
1331 |
|
---|
1332 | #ifdef VBOX_WITH_WDDM
|
---|
1333 | /* Size of some additional data. For future extensions. */
|
---|
1334 | rc = SSMR3PutU32 (pSSM, 4);
|
---|
1335 | AssertRCReturn(rc, rc);
|
---|
1336 | rc = SSMR3PutU32 (pSSM, pVGAState->fGuestCaps);
|
---|
1337 | AssertRCReturn(rc, rc);
|
---|
1338 | #else
|
---|
1339 | /* Size of some additional data. For future extensions. */
|
---|
1340 | rc = SSMR3PutU32 (pSSM, 0);
|
---|
1341 | AssertRCReturn(rc, rc);
|
---|
1342 | #endif
|
---|
1343 | }
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | return rc;
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | int vboxVBVASaveStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
1350 | {
|
---|
1351 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
1352 | int rc;
|
---|
1353 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1354 | VBOXVBVASAVEDSTATECBDATA VhwaData = {0};
|
---|
1355 | VhwaData.pSSM = pSSM;
|
---|
1356 | uint32_t cbCmd = sizeof (VBOXVHWACMD_HH_SAVESTATE_SAVEPERFORM); /* maximum cmd size */
|
---|
1357 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEBEGIN, 0, cbCmd);
|
---|
1358 | Assert(pCmd);
|
---|
1359 | if(pCmd)
|
---|
1360 | {
|
---|
1361 | vbvaVHWAHHPost (pVGAState, pCmd, NULL, vboxVBVASaveStateBeginPostCb, &VhwaData);
|
---|
1362 | rc = VhwaData.rc;
|
---|
1363 | AssertRC(rc);
|
---|
1364 | if (RT_SUCCESS(rc))
|
---|
1365 | {
|
---|
1366 | #endif
|
---|
1367 | rc = vboxVBVASaveDevStateExec (pVGAState, pSSM);
|
---|
1368 | AssertRC(rc);
|
---|
1369 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1370 | if (RT_SUCCESS(rc))
|
---|
1371 | {
|
---|
1372 | vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEPERFORM, 0);
|
---|
1373 | VBOXVHWACMD_HH_SAVESTATE_SAVEPERFORM *pSave = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_SAVESTATE_SAVEPERFORM);
|
---|
1374 | pSave->pSSM = pSSM;
|
---|
1375 | vbvaVHWAHHPost (pVGAState, pCmd, vboxVBVASaveStatePerformPreCb, NULL, &VhwaData);
|
---|
1376 | rc = VhwaData.rc;
|
---|
1377 | AssertRC(rc);
|
---|
1378 | if (RT_SUCCESS(rc))
|
---|
1379 | {
|
---|
1380 | vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_SAVESTATE_SAVEEND, 0);
|
---|
1381 | vbvaVHWAHHPost (pVGAState, pCmd, vboxVBVASaveStateEndPreCb, NULL, &VhwaData);
|
---|
1382 | rc = VhwaData.rc;
|
---|
1383 | AssertRC(rc);
|
---|
1384 | }
|
---|
1385 | }
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
1389 | }
|
---|
1390 | else
|
---|
1391 | rc = VERR_OUT_OF_RESOURCES;
|
---|
1392 | #else
|
---|
1393 | if (RT_SUCCESS(rc))
|
---|
1394 | {
|
---|
1395 | for (uint32_t i = 0; i < pVGAState->cMonitors; ++i)
|
---|
1396 | {
|
---|
1397 | rc = SSMR3PutU32 (pSSM, VBOXVBVASAVEDSTATE_VHWAUNAVAILABLE_MAGIC);
|
---|
1398 | AssertRCReturn(rc, rc);
|
---|
1399 | }
|
---|
1400 | }
|
---|
1401 | #endif
|
---|
1402 | return rc;
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | int vboxVBVALoadStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
|
---|
1406 | {
|
---|
1407 | if (u32Version < VGA_SAVEDSTATE_VERSION_HGSMI)
|
---|
1408 | {
|
---|
1409 | /* Nothing was saved. */
|
---|
1410 | return VINF_SUCCESS;
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
1414 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1415 | int rc = HGSMIHostLoadStateExec (pIns, pSSM, u32Version);
|
---|
1416 | if (RT_SUCCESS(rc))
|
---|
1417 | {
|
---|
1418 | /* Load VBVACONTEXT. */
|
---|
1419 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
1420 |
|
---|
1421 | if (!pCtx)
|
---|
1422 | {
|
---|
1423 | /* This should not happen. */
|
---|
1424 | AssertFailed();
|
---|
1425 | rc = VERR_INVALID_PARAMETER;
|
---|
1426 | }
|
---|
1427 | else
|
---|
1428 | {
|
---|
1429 | uint32_t cViews = 0;
|
---|
1430 | rc = SSMR3GetU32 (pSSM, &cViews);
|
---|
1431 | AssertRCReturn(rc, rc);
|
---|
1432 |
|
---|
1433 | uint32_t iView;
|
---|
1434 | for (iView = 0; iView < cViews; iView++)
|
---|
1435 | {
|
---|
1436 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
1437 |
|
---|
1438 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewIndex);
|
---|
1439 | AssertRCReturn(rc, rc);
|
---|
1440 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewOffset);
|
---|
1441 | AssertRCReturn(rc, rc);
|
---|
1442 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewSize);
|
---|
1443 | AssertRCReturn(rc, rc);
|
---|
1444 | rc = SSMR3GetU32 (pSSM, &pView->view.u32MaxScreenSize);
|
---|
1445 | AssertRCReturn(rc, rc);
|
---|
1446 |
|
---|
1447 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32ViewIndex);
|
---|
1448 | AssertRCReturn(rc, rc);
|
---|
1449 | rc = SSMR3GetS32 (pSSM, &pView->screen.i32OriginX);
|
---|
1450 | AssertRCReturn(rc, rc);
|
---|
1451 | rc = SSMR3GetS32 (pSSM, &pView->screen.i32OriginY);
|
---|
1452 | AssertRCReturn(rc, rc);
|
---|
1453 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32StartOffset);
|
---|
1454 | AssertRCReturn(rc, rc);
|
---|
1455 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32LineSize);
|
---|
1456 | AssertRCReturn(rc, rc);
|
---|
1457 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32Width);
|
---|
1458 | AssertRCReturn(rc, rc);
|
---|
1459 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32Height);
|
---|
1460 | AssertRCReturn(rc, rc);
|
---|
1461 | rc = SSMR3GetU16 (pSSM, &pView->screen.u16BitsPerPixel);
|
---|
1462 | AssertRCReturn(rc, rc);
|
---|
1463 | rc = SSMR3GetU16 (pSSM, &pView->screen.u16Flags);
|
---|
1464 | AssertRCReturn(rc, rc);
|
---|
1465 |
|
---|
1466 | rc = SSMR3GetU32 (pSSM, &pView->u32VBVAOffset);
|
---|
1467 | AssertRCReturn(rc, rc);
|
---|
1468 |
|
---|
1469 | rc = SSMR3GetU32 (pSSM, &pView->partialRecord.cb);
|
---|
1470 | AssertRCReturn(rc, rc);
|
---|
1471 |
|
---|
1472 | if (pView->partialRecord.cb == 0)
|
---|
1473 | {
|
---|
1474 | pView->partialRecord.pu8 = NULL;
|
---|
1475 | }
|
---|
1476 | else
|
---|
1477 | {
|
---|
1478 | Assert(pView->partialRecord.pu8 == NULL); /* Should be it. */
|
---|
1479 |
|
---|
1480 | uint8_t *pu8 = (uint8_t *)RTMemAlloc (pView->partialRecord.cb);
|
---|
1481 |
|
---|
1482 | if (!pu8)
|
---|
1483 | {
|
---|
1484 | return VERR_NO_MEMORY;
|
---|
1485 | }
|
---|
1486 |
|
---|
1487 | pView->partialRecord.pu8 = pu8;
|
---|
1488 |
|
---|
1489 | rc = SSMR3GetMem (pSSM, pView->partialRecord.pu8, pView->partialRecord.cb);
|
---|
1490 | AssertRCReturn(rc, rc);
|
---|
1491 | }
|
---|
1492 |
|
---|
1493 | if ( pView->u32VBVAOffset == HGSMIOFFSET_VOID
|
---|
1494 | || pView->screen.u32LineSize == 0) /* Earlier broken saved states. */
|
---|
1495 | {
|
---|
1496 | pView->pVBVA = NULL;
|
---|
1497 | }
|
---|
1498 | else
|
---|
1499 | {
|
---|
1500 | pView->pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, pView->u32VBVAOffset);
|
---|
1501 | }
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 | if (u32Version > VGA_SAVEDSTATE_VERSION_WITH_CONFIG)
|
---|
1505 | {
|
---|
1506 | /* Read mouse pointer shape information. */
|
---|
1507 | rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fSet);
|
---|
1508 | AssertRCReturn(rc, rc);
|
---|
1509 | rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fVisible);
|
---|
1510 | AssertRCReturn(rc, rc);
|
---|
1511 | rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fAlpha);
|
---|
1512 | AssertRCReturn(rc, rc);
|
---|
1513 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32HotX);
|
---|
1514 | AssertRCReturn(rc, rc);
|
---|
1515 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32HotY);
|
---|
1516 | AssertRCReturn(rc, rc);
|
---|
1517 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32Width);
|
---|
1518 | AssertRCReturn(rc, rc);
|
---|
1519 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32Height);
|
---|
1520 | AssertRCReturn(rc, rc);
|
---|
1521 | rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.cbShape);
|
---|
1522 | AssertRCReturn(rc, rc);
|
---|
1523 | if (pCtx->mouseShapeInfo.cbShape)
|
---|
1524 | {
|
---|
1525 | pCtx->mouseShapeInfo.pu8Shape = (uint8_t *)RTMemAlloc(pCtx->mouseShapeInfo.cbShape);
|
---|
1526 | if (pCtx->mouseShapeInfo.pu8Shape == NULL)
|
---|
1527 | {
|
---|
1528 | return VERR_NO_MEMORY;
|
---|
1529 | }
|
---|
1530 | pCtx->mouseShapeInfo.cbAllocated = pCtx->mouseShapeInfo.cbShape;
|
---|
1531 | rc = SSMR3GetMem (pSSM, pCtx->mouseShapeInfo.pu8Shape, pCtx->mouseShapeInfo.cbShape);
|
---|
1532 | AssertRCReturn(rc, rc);
|
---|
1533 | }
|
---|
1534 | else
|
---|
1535 | {
|
---|
1536 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
1537 | }
|
---|
1538 |
|
---|
1539 | /* Size of some additional data. For future extensions. */
|
---|
1540 | uint32_t cbExtra = 0;
|
---|
1541 | rc = SSMR3GetU32 (pSSM, &cbExtra);
|
---|
1542 | AssertRCReturn(rc, rc);
|
---|
1543 | #ifdef VBOX_WITH_WDDM
|
---|
1544 | if (cbExtra >= 4)
|
---|
1545 | {
|
---|
1546 | rc = SSMR3GetU32 (pSSM, &pVGAState->fGuestCaps);
|
---|
1547 | AssertRCReturn(rc, rc);
|
---|
1548 | cbExtra -= 4;
|
---|
1549 | }
|
---|
1550 | #endif
|
---|
1551 | if (cbExtra > 0)
|
---|
1552 | {
|
---|
1553 | rc = SSMR3Skip(pSSM, cbExtra);
|
---|
1554 | AssertRCReturn(rc, rc);
|
---|
1555 | }
|
---|
1556 | }
|
---|
1557 |
|
---|
1558 | pCtx->cViews = iView;
|
---|
1559 | LogFlowFunc(("%d views loaded\n", pCtx->cViews));
|
---|
1560 |
|
---|
1561 | if (u32Version > VGA_SAVEDSTATE_VERSION_WDDM)
|
---|
1562 | {
|
---|
1563 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1564 | uint32_t cbCmd = sizeof (VBOXVHWACMD_HH_SAVESTATE_LOADPERFORM); /* maximum cmd size */
|
---|
1565 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_SAVESTATE_LOADPERFORM, 0, cbCmd);
|
---|
1566 | Assert(pCmd);
|
---|
1567 | if(pCmd)
|
---|
1568 | {
|
---|
1569 | VBOXVBVASAVEDSTATECBDATA VhwaData = {0};
|
---|
1570 | VhwaData.pSSM = pSSM;
|
---|
1571 | VBOXVHWACMD_HH_SAVESTATE_LOADPERFORM *pLoad = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_SAVESTATE_LOADPERFORM);
|
---|
1572 | pLoad->pSSM = pSSM;
|
---|
1573 | vbvaVHWAHHPost (pVGAState, pCmd, vboxVBVALoadStatePerformPreCb, vboxVBVALoadStatePerformPostCb, &VhwaData);
|
---|
1574 | rc = VhwaData.rc;
|
---|
1575 | AssertRC(rc);
|
---|
1576 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
1577 | }
|
---|
1578 | else
|
---|
1579 | {
|
---|
1580 | rc = VERR_OUT_OF_RESOURCES;
|
---|
1581 | }
|
---|
1582 | #else
|
---|
1583 | rc = SSMR3SkipToEndOfUnit(pSSM);
|
---|
1584 | AssertRCReturn(rc, rc);
|
---|
1585 | #endif
|
---|
1586 | }
|
---|
1587 |
|
---|
1588 | #ifdef DEBUG_sunlover
|
---|
1589 | dumpctx(pCtx);
|
---|
1590 | #endif
|
---|
1591 | }
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | return rc;
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | int vboxVBVALoadStateDone (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
1598 | {
|
---|
1599 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
1600 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
1601 |
|
---|
1602 | if (pCtx)
|
---|
1603 | {
|
---|
1604 | uint32_t iView;
|
---|
1605 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
1606 | {
|
---|
1607 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
1608 |
|
---|
1609 | if (pView->pVBVA)
|
---|
1610 | {
|
---|
1611 | vbvaEnable (iView, pVGAState, pCtx, pView->pVBVA, pView->u32VBVAOffset, true /* fRestored */);
|
---|
1612 | vbvaResize (pVGAState, pView, &pView->screen);
|
---|
1613 | }
|
---|
1614 | }
|
---|
1615 |
|
---|
1616 | if (pCtx->mouseShapeInfo.fSet)
|
---|
1617 | {
|
---|
1618 | vbvaUpdateMousePointerShape(pVGAState, &pCtx->mouseShapeInfo, true, pCtx->mouseShapeInfo.pu8Shape);
|
---|
1619 | }
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 | return VINF_SUCCESS;
|
---|
1623 | }
|
---|
1624 |
|
---|
1625 | /*
|
---|
1626 | *
|
---|
1627 | * New VBVA uses a new interface id: #define VBE_DISPI_ID_VBOX_VIDEO 0xBE01
|
---|
1628 | *
|
---|
1629 | * VBVA uses two 32 bits IO ports to write VRAM offsets of shared memory blocks for commands.
|
---|
1630 | * Read Write
|
---|
1631 | * Host port 0x3b0 to process completed
|
---|
1632 | * Guest port 0x3d0 control value? to process
|
---|
1633 | *
|
---|
1634 | */
|
---|
1635 |
|
---|
1636 | static DECLCALLBACK(void) vbvaNotifyGuest (void *pvCallback)
|
---|
1637 | {
|
---|
1638 | #if defined(VBOX_WITH_HGSMI) && (defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_VDMA) || defined(VBOX_WITH_WDDM))
|
---|
1639 | PVGASTATE pVGAState = (PVGASTATE)pvCallback;
|
---|
1640 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
1641 | PDMCritSectEnter(&pVGAState->lock, VERR_SEM_BUSY);
|
---|
1642 | HGSMISetHostGuestFlags(pVGAState->pHGSMI, HGSMIHOSTFLAGS_IRQ);
|
---|
1643 | PDMDevHlpPCISetIrq(pDevIns, 0, PDM_IRQ_LEVEL_HIGH);
|
---|
1644 | PDMCritSectLeave(&pVGAState->lock);
|
---|
1645 | #else
|
---|
1646 | NOREF(pvCallback);
|
---|
1647 | /* Do nothing. Later the VMMDev/VGA IRQ can be used for the notification. */
|
---|
1648 | #endif
|
---|
1649 | }
|
---|
1650 |
|
---|
1651 | /* The guest submitted a buffer. @todo Verify all guest data. */
|
---|
1652 | static DECLCALLBACK(int) vbvaChannelHandler (void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer)
|
---|
1653 | {
|
---|
1654 | int rc = VINF_SUCCESS;
|
---|
1655 |
|
---|
1656 | LogFlowFunc(("pvHandler %p, u16ChannelInfo %d, pvBuffer %p, cbBuffer %u\n",
|
---|
1657 | pvHandler, u16ChannelInfo, pvBuffer, cbBuffer));
|
---|
1658 |
|
---|
1659 | PVGASTATE pVGAState = (PVGASTATE)pvHandler;
|
---|
1660 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1661 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
1662 |
|
---|
1663 | switch (u16ChannelInfo)
|
---|
1664 | {
|
---|
1665 | #ifdef VBOX_WITH_VDMA
|
---|
1666 | case VBVA_VDMA_CMD:
|
---|
1667 | {
|
---|
1668 | if (cbBuffer < VBoxSHGSMIBufferHeaderSize() + sizeof (VBOXVDMACBUF_DR))
|
---|
1669 | {
|
---|
1670 | rc = VERR_INVALID_PARAMETER;
|
---|
1671 | break;
|
---|
1672 | }
|
---|
1673 | PVBOXVDMACBUF_DR pCmd = (PVBOXVDMACBUF_DR)VBoxSHGSMIBufferData ((PVBOXSHGSMIHEADER)pvBuffer);
|
---|
1674 | vboxVDMACommand(pVGAState->pVdma, pCmd, cbBuffer - VBoxSHGSMIBufferHeaderSize());
|
---|
1675 | rc = VINF_SUCCESS;
|
---|
1676 | break;
|
---|
1677 | }
|
---|
1678 | case VBVA_VDMA_CTL:
|
---|
1679 | {
|
---|
1680 | if (cbBuffer < VBoxSHGSMIBufferHeaderSize() + sizeof (VBOXVDMA_CTL))
|
---|
1681 | {
|
---|
1682 | rc = VERR_INVALID_PARAMETER;
|
---|
1683 | break;
|
---|
1684 | }
|
---|
1685 | PVBOXVDMA_CTL pCmd = (PVBOXVDMA_CTL)VBoxSHGSMIBufferData ((PVBOXSHGSMIHEADER)pvBuffer);
|
---|
1686 | vboxVDMAControl(pVGAState->pVdma, pCmd, cbBuffer - VBoxSHGSMIBufferHeaderSize());
|
---|
1687 | rc = VINF_SUCCESS;
|
---|
1688 | break;
|
---|
1689 | }
|
---|
1690 | #endif
|
---|
1691 | case VBVA_QUERY_CONF32:
|
---|
1692 | {
|
---|
1693 | if (cbBuffer < sizeof (VBVACONF32))
|
---|
1694 | {
|
---|
1695 | rc = VERR_INVALID_PARAMETER;
|
---|
1696 | break;
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 | VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
|
---|
1700 | LogFlowFunc(("VBVA_QUERY_CONF32: u32Index %d, u32Value 0x%x\n",
|
---|
1701 | pConf32->u32Index, pConf32->u32Value));
|
---|
1702 |
|
---|
1703 | if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
|
---|
1704 | {
|
---|
1705 | pConf32->u32Value = pCtx->cViews;
|
---|
1706 | }
|
---|
1707 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
|
---|
1708 | {
|
---|
1709 | /* @todo a value calculated from the vram size */
|
---|
1710 | pConf32->u32Value = 64*_1K;
|
---|
1711 | }
|
---|
1712 | else
|
---|
1713 | {
|
---|
1714 | Log(("Unsupported VBVA_QUERY_CONF32 index %d!!!\n",
|
---|
1715 | pConf32->u32Index));
|
---|
1716 | rc = VERR_INVALID_PARAMETER;
|
---|
1717 | }
|
---|
1718 | } break;
|
---|
1719 |
|
---|
1720 | case VBVA_SET_CONF32:
|
---|
1721 | {
|
---|
1722 | if (cbBuffer < sizeof (VBVACONF32))
|
---|
1723 | {
|
---|
1724 | rc = VERR_INVALID_PARAMETER;
|
---|
1725 | break;
|
---|
1726 | }
|
---|
1727 |
|
---|
1728 | VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
|
---|
1729 | LogFlowFunc(("VBVA_SET_CONF32: u32Index %d, u32Value 0x%x\n",
|
---|
1730 | pConf32->u32Index, pConf32->u32Value));
|
---|
1731 |
|
---|
1732 | if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
|
---|
1733 | {
|
---|
1734 | /* do nothing. this is a const. */
|
---|
1735 | }
|
---|
1736 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
|
---|
1737 | {
|
---|
1738 | /* do nothing. this is a const. */
|
---|
1739 | }
|
---|
1740 | else
|
---|
1741 | {
|
---|
1742 | Log(("Unsupported VBVA_SET_CONF32 index %d!!!\n",
|
---|
1743 | pConf32->u32Index));
|
---|
1744 | rc = VERR_INVALID_PARAMETER;
|
---|
1745 | }
|
---|
1746 | } break;
|
---|
1747 |
|
---|
1748 | case VBVA_INFO_VIEW:
|
---|
1749 | {
|
---|
1750 | if (cbBuffer < sizeof (VBVAINFOVIEW))
|
---|
1751 | {
|
---|
1752 | rc = VERR_INVALID_PARAMETER;
|
---|
1753 | break;
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 | /* Guest submits an array of VBVAINFOVIEW structures. */
|
---|
1757 | VBVAINFOVIEW *pView = (VBVAINFOVIEW *)pvBuffer;
|
---|
1758 |
|
---|
1759 | for (;
|
---|
1760 | cbBuffer >= sizeof (VBVAINFOVIEW);
|
---|
1761 | pView++, cbBuffer -= sizeof (VBVAINFOVIEW))
|
---|
1762 | {
|
---|
1763 | LogFlowFunc(("VBVA_INFO_VIEW: index %d, offset 0x%x, size 0x%x, max screen size 0x%x\n",
|
---|
1764 | pView->u32ViewIndex, pView->u32ViewOffset, pView->u32ViewSize, pView->u32MaxScreenSize));
|
---|
1765 |
|
---|
1766 | /* @todo verify view data. */
|
---|
1767 | if (pView->u32ViewIndex >= pCtx->cViews)
|
---|
1768 | {
|
---|
1769 | Log(("View index too large %d!!!\n",
|
---|
1770 | pView->u32ViewIndex));
|
---|
1771 | rc = VERR_INVALID_PARAMETER;
|
---|
1772 | break;
|
---|
1773 | }
|
---|
1774 |
|
---|
1775 | pCtx->aViews[pView->u32ViewIndex].view = *pView;
|
---|
1776 | }
|
---|
1777 | } break;
|
---|
1778 |
|
---|
1779 | case VBVA_INFO_HEAP:
|
---|
1780 | {
|
---|
1781 | if (cbBuffer < sizeof (VBVAINFOHEAP))
|
---|
1782 | {
|
---|
1783 | rc = VERR_INVALID_PARAMETER;
|
---|
1784 | break;
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | VBVAINFOHEAP *pHeap = (VBVAINFOHEAP *)pvBuffer;
|
---|
1788 | LogFlowFunc(("VBVA_INFO_HEAP: offset 0x%x, size 0x%x\n",
|
---|
1789 | pHeap->u32HeapOffset, pHeap->u32HeapSize));
|
---|
1790 |
|
---|
1791 | rc = HGSMISetupHostHeap (pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
|
---|
1792 | } break;
|
---|
1793 |
|
---|
1794 | case VBVA_FLUSH:
|
---|
1795 | {
|
---|
1796 | if (cbBuffer < sizeof (VBVAFLUSH))
|
---|
1797 | {
|
---|
1798 | rc = VERR_INVALID_PARAMETER;
|
---|
1799 | break;
|
---|
1800 | }
|
---|
1801 |
|
---|
1802 | VBVAFLUSH *pFlush = (VBVAFLUSH *)pvBuffer;
|
---|
1803 | LogFlowFunc(("VBVA_FLUSH: u32Reserved 0x%x\n",
|
---|
1804 | pFlush->u32Reserved));
|
---|
1805 |
|
---|
1806 | rc = vbvaFlush (pVGAState, pCtx);
|
---|
1807 | } break;
|
---|
1808 |
|
---|
1809 | case VBVA_INFO_SCREEN:
|
---|
1810 | {
|
---|
1811 | if (cbBuffer < sizeof (VBVAINFOSCREEN))
|
---|
1812 | {
|
---|
1813 | rc = VERR_INVALID_PARAMETER;
|
---|
1814 | break;
|
---|
1815 | }
|
---|
1816 |
|
---|
1817 | VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)pvBuffer;
|
---|
1818 | VBVAINFOVIEW *pView = &pCtx->aViews[pScreen->u32ViewIndex].view;
|
---|
1819 | /* Calculate the offset of the end of the screen so we can make
|
---|
1820 | * sure it is inside the view. I assume that screen rollover is not
|
---|
1821 | * implemented. */
|
---|
1822 | int64_t offEnd = (int64_t)pScreen->u32Height * pScreen->u32LineSize
|
---|
1823 | + pScreen->u32Width + pScreen->u32StartOffset;
|
---|
1824 | LogRelFlowFunc(("VBVA_INFO_SCREEN: [%d] @%d,%d %dx%d, line 0x%x, BPP %d, flags 0x%x\n",
|
---|
1825 | pScreen->u32ViewIndex, pScreen->i32OriginX, pScreen->i32OriginY,
|
---|
1826 | pScreen->u32Width, pScreen->u32Height,
|
---|
1827 | pScreen->u32LineSize, pScreen->u16BitsPerPixel, pScreen->u16Flags));
|
---|
1828 |
|
---|
1829 | if ( pScreen->u32ViewIndex < RT_ELEMENTS (pCtx->aViews)
|
---|
1830 | && pScreen->u16BitsPerPixel <= 32
|
---|
1831 | && pScreen->u32Width <= UINT16_MAX
|
---|
1832 | && pScreen->u32Height <= UINT16_MAX
|
---|
1833 | && pScreen->u32LineSize <= UINT16_MAX * 4
|
---|
1834 | && offEnd < pView->u32MaxScreenSize)
|
---|
1835 | {
|
---|
1836 | vbvaResize (pVGAState, &pCtx->aViews[pScreen->u32ViewIndex], pScreen);
|
---|
1837 | }
|
---|
1838 | else
|
---|
1839 | {
|
---|
1840 | LogRelFlow(("VBVA_INFO_SCREEN [%lu]: bad data: %lux%lu, line 0x%lx, BPP %u, start offset %lu, max screen size %lu\n",
|
---|
1841 | (unsigned long)pScreen->u32ViewIndex,
|
---|
1842 | (unsigned long)pScreen->u32Width,
|
---|
1843 | (unsigned long)pScreen->u32Height,
|
---|
1844 | (unsigned long)pScreen->u32LineSize,
|
---|
1845 | (unsigned long)pScreen->u16BitsPerPixel,
|
---|
1846 | (unsigned long)pScreen->u32StartOffset,
|
---|
1847 | (unsigned long)pView->u32MaxScreenSize));
|
---|
1848 | rc = VERR_INVALID_PARAMETER;
|
---|
1849 | }
|
---|
1850 | } break;
|
---|
1851 |
|
---|
1852 | case VBVA_ENABLE:
|
---|
1853 | {
|
---|
1854 | if (cbBuffer < sizeof (VBVAENABLE))
|
---|
1855 | {
|
---|
1856 | rc = VERR_INVALID_PARAMETER;
|
---|
1857 | break;
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | VBVAENABLE *pEnable = (VBVAENABLE *)pvBuffer;
|
---|
1861 | unsigned uScreenId;
|
---|
1862 | if (pEnable->u32Flags & VBVA_F_EXTENDED)
|
---|
1863 | {
|
---|
1864 | if (cbBuffer < sizeof (VBVAENABLE_EX))
|
---|
1865 | {
|
---|
1866 | rc = VERR_INVALID_PARAMETER;
|
---|
1867 | break;
|
---|
1868 | }
|
---|
1869 |
|
---|
1870 | VBVAENABLE_EX *pEnableEx = (VBVAENABLE_EX *)pvBuffer;
|
---|
1871 | uScreenId = pEnableEx->u32ScreenId;
|
---|
1872 | }
|
---|
1873 | else
|
---|
1874 | {
|
---|
1875 | uScreenId = vbvaViewFromOffset (pIns, pCtx, pvBuffer);
|
---|
1876 | }
|
---|
1877 |
|
---|
1878 | if (uScreenId == ~0U)
|
---|
1879 | {
|
---|
1880 | rc = VERR_INVALID_PARAMETER;
|
---|
1881 | break;
|
---|
1882 | }
|
---|
1883 |
|
---|
1884 | LogFlowFunc(("VBVA_ENABLE[%d]: u32Flags 0x%x u32Offset 0x%x\n",
|
---|
1885 | uScreenId, pEnable->u32Flags, pEnable->u32Offset));
|
---|
1886 |
|
---|
1887 | if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_ENABLE)
|
---|
1888 | {
|
---|
1889 | /* Guest reported offset relative to view. */
|
---|
1890 | uint32_t u32Offset = pEnable->u32Offset;
|
---|
1891 | if (!(pEnable->u32Flags & VBVA_F_ABSOFFSET))
|
---|
1892 | {
|
---|
1893 | u32Offset += pCtx->aViews[uScreenId].view.u32ViewOffset;
|
---|
1894 | }
|
---|
1895 |
|
---|
1896 | VBVABUFFER *pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, u32Offset);
|
---|
1897 |
|
---|
1898 | if (pVBVA)
|
---|
1899 | {
|
---|
1900 | /* Process any pending orders and empty the VBVA ring buffer. */
|
---|
1901 | vbvaFlush (pVGAState, pCtx);
|
---|
1902 |
|
---|
1903 | rc = vbvaEnable (uScreenId, pVGAState, pCtx, pVBVA, u32Offset, false /* fRestored */);
|
---|
1904 | }
|
---|
1905 | else
|
---|
1906 | {
|
---|
1907 | Log(("Invalid VBVABUFFER offset 0x%x!!!\n",
|
---|
1908 | pEnable->u32Offset));
|
---|
1909 | rc = VERR_INVALID_PARAMETER;
|
---|
1910 | }
|
---|
1911 | }
|
---|
1912 | else if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_DISABLE)
|
---|
1913 | {
|
---|
1914 | rc = vbvaDisable (uScreenId, pVGAState, pCtx);
|
---|
1915 | }
|
---|
1916 | else
|
---|
1917 | {
|
---|
1918 | Log(("Invalid VBVA_ENABLE flags 0x%x!!!\n",
|
---|
1919 | pEnable->u32Flags));
|
---|
1920 | rc = VERR_INVALID_PARAMETER;
|
---|
1921 | }
|
---|
1922 |
|
---|
1923 | pEnable->i32Result = rc;
|
---|
1924 | } break;
|
---|
1925 |
|
---|
1926 | case VBVA_MOUSE_POINTER_SHAPE:
|
---|
1927 | {
|
---|
1928 | if (cbBuffer < sizeof (VBVAMOUSEPOINTERSHAPE))
|
---|
1929 | {
|
---|
1930 | rc = VERR_INVALID_PARAMETER;
|
---|
1931 | break;
|
---|
1932 | }
|
---|
1933 |
|
---|
1934 | VBVAMOUSEPOINTERSHAPE *pShape = (VBVAMOUSEPOINTERSHAPE *)pvBuffer;
|
---|
1935 |
|
---|
1936 | LogFlowFunc(("VBVA_MOUSE_POINTER_SHAPE: i32Result 0x%x, fu32Flags 0x%x, hot spot %d,%d, size %dx%d\n",
|
---|
1937 | pShape->i32Result,
|
---|
1938 | pShape->fu32Flags,
|
---|
1939 | pShape->u32HotX,
|
---|
1940 | pShape->u32HotY,
|
---|
1941 | pShape->u32Width,
|
---|
1942 | pShape->u32Height));
|
---|
1943 |
|
---|
1944 | rc = vbvaMousePointerShape (pVGAState, pCtx, pShape, cbBuffer);
|
---|
1945 |
|
---|
1946 | pShape->i32Result = rc;
|
---|
1947 | } break;
|
---|
1948 |
|
---|
1949 |
|
---|
1950 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1951 | case VBVA_VHWA_CMD:
|
---|
1952 | {
|
---|
1953 | rc = vbvaVHWAHandleCommand (pVGAState, pCtx, (PVBOXVHWACMD)pvBuffer);
|
---|
1954 | } break;
|
---|
1955 | #endif
|
---|
1956 |
|
---|
1957 | #ifdef VBOX_WITH_WDDM
|
---|
1958 | case VBVA_INFO_CAPS:
|
---|
1959 | {
|
---|
1960 | if (cbBuffer < sizeof (VBVACAPS))
|
---|
1961 | {
|
---|
1962 | rc = VERR_INVALID_PARAMETER;
|
---|
1963 | break;
|
---|
1964 | }
|
---|
1965 |
|
---|
1966 | VBVACAPS *pCaps = (VBVACAPS*)pvBuffer;
|
---|
1967 | pVGAState->fGuestCaps = pCaps->fCaps;
|
---|
1968 | pCaps->rc = VINF_SUCCESS;
|
---|
1969 | } break;
|
---|
1970 | #endif
|
---|
1971 | default:
|
---|
1972 | Log(("Unsupported VBVA guest command %d!!!\n",
|
---|
1973 | u16ChannelInfo));
|
---|
1974 | break;
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 | return rc;
|
---|
1978 | }
|
---|
1979 |
|
---|
1980 | void VBVAReset (PVGASTATE pVGAState)
|
---|
1981 | {
|
---|
1982 | if (!pVGAState || !pVGAState->pHGSMI)
|
---|
1983 | {
|
---|
1984 | return;
|
---|
1985 | }
|
---|
1986 |
|
---|
1987 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
1988 |
|
---|
1989 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1990 | vbvaVHWAReset (pVGAState);
|
---|
1991 | #endif
|
---|
1992 |
|
---|
1993 | uint32_t HgFlags = HGSMIReset (pVGAState->pHGSMI);
|
---|
1994 | if(HgFlags & HGSMIHOSTFLAGS_IRQ)
|
---|
1995 | {
|
---|
1996 | /* this means the IRQ is LEVEL_HIGH, need to reset it */
|
---|
1997 | PDMDevHlpPCISetIrq(pVGAState->pDevInsR3, 0, PDM_IRQ_LEVEL_LOW);
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 | if (pCtx)
|
---|
2001 | {
|
---|
2002 | vbvaFlush (pVGAState, pCtx);
|
---|
2003 |
|
---|
2004 | unsigned uScreenId;
|
---|
2005 |
|
---|
2006 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
2007 | {
|
---|
2008 | vbvaDisable (uScreenId, pVGAState, pCtx);
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | pCtx->mouseShapeInfo.fSet = false;
|
---|
2012 | RTMemFree(pCtx->mouseShapeInfo.pu8Shape);
|
---|
2013 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
2014 | pCtx->mouseShapeInfo.cbAllocated = 0;
|
---|
2015 | pCtx->mouseShapeInfo.cbShape = 0;
|
---|
2016 | }
|
---|
2017 |
|
---|
2018 | }
|
---|
2019 |
|
---|
2020 | int VBVAUpdateDisplay (PVGASTATE pVGAState)
|
---|
2021 | {
|
---|
2022 | int rc = VERR_NOT_SUPPORTED; /* Assuming that the VGA device will have to do updates. */
|
---|
2023 |
|
---|
2024 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2025 |
|
---|
2026 | if (pCtx)
|
---|
2027 | {
|
---|
2028 | rc = vbvaFlush (pVGAState, pCtx);
|
---|
2029 |
|
---|
2030 | if (RT_SUCCESS (rc))
|
---|
2031 | {
|
---|
2032 | if (!pCtx->aViews[0].pVBVA)
|
---|
2033 | {
|
---|
2034 | /* VBVA is not enabled for the first view, so VGA device must do updates. */
|
---|
2035 | rc = VERR_NOT_SUPPORTED;
|
---|
2036 | }
|
---|
2037 | }
|
---|
2038 | }
|
---|
2039 |
|
---|
2040 | return rc;
|
---|
2041 | }
|
---|
2042 |
|
---|
2043 | static HGSMICHANNELHANDLER sOldChannelHandler;
|
---|
2044 |
|
---|
2045 | int VBVAInit (PVGASTATE pVGAState)
|
---|
2046 | {
|
---|
2047 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
2048 |
|
---|
2049 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
2050 |
|
---|
2051 | int rc = HGSMICreate (&pVGAState->pHGSMI,
|
---|
2052 | pVM,
|
---|
2053 | "VBVA",
|
---|
2054 | 0,
|
---|
2055 | pVGAState->vram_ptrR3,
|
---|
2056 | pVGAState->vram_size,
|
---|
2057 | vbvaNotifyGuest,
|
---|
2058 | pVGAState,
|
---|
2059 | sizeof (VBVACONTEXT));
|
---|
2060 |
|
---|
2061 | if (RT_SUCCESS (rc))
|
---|
2062 | {
|
---|
2063 | rc = HGSMIHostChannelRegister (pVGAState->pHGSMI,
|
---|
2064 | HGSMI_CH_VBVA,
|
---|
2065 | vbvaChannelHandler,
|
---|
2066 | pVGAState,
|
---|
2067 | &sOldChannelHandler);
|
---|
2068 | if (RT_SUCCESS (rc))
|
---|
2069 | {
|
---|
2070 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2071 | pCtx->cViews = pVGAState->cMonitors;
|
---|
2072 | }
|
---|
2073 | }
|
---|
2074 |
|
---|
2075 | return rc;
|
---|
2076 |
|
---|
2077 | }
|
---|
2078 |
|
---|
2079 | void VBVADestroy (PVGASTATE pVGAState)
|
---|
2080 | {
|
---|
2081 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2082 |
|
---|
2083 | if (pCtx)
|
---|
2084 | {
|
---|
2085 | pCtx->mouseShapeInfo.fSet = false;
|
---|
2086 | RTMemFree(pCtx->mouseShapeInfo.pu8Shape);
|
---|
2087 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
2088 | pCtx->mouseShapeInfo.cbAllocated = 0;
|
---|
2089 | pCtx->mouseShapeInfo.cbShape = 0;
|
---|
2090 | }
|
---|
2091 |
|
---|
2092 | HGSMIDestroy (pVGAState->pHGSMI);
|
---|
2093 | pVGAState->pHGSMI = NULL;
|
---|
2094 | }
|
---|