1 | /* $Id: DevVGA_VBVA.cpp 53809 2015-01-14 19:49:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Video Acceleration (VBVA).
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2013 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 | VBVAMODEHINT aModeHints[VBOX_VIDEO_MAX_SCREENS];
|
---|
86 | } VBVACONTEXT;
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | /** Copies @a cb bytes from the VBVA ring buffer to the @a pu8Dst.
|
---|
91 | * Used for partial records or for records which cross the ring boundary.
|
---|
92 | */
|
---|
93 | static void vbvaFetchBytes (VBVABUFFER *pVBVA, uint8_t *pu8Dst, uint32_t cb)
|
---|
94 | {
|
---|
95 | /** @todo replace the 'if' with an assert. The caller must ensure this condition. */
|
---|
96 | if (cb >= pVBVA->cbData)
|
---|
97 | {
|
---|
98 | AssertMsgFailed (("cb = 0x%08X, ring buffer size 0x%08X", cb, pVBVA->cbData));
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | const uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
|
---|
103 | const uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
|
---|
104 | const int32_t i32Diff = cb - u32BytesTillBoundary;
|
---|
105 |
|
---|
106 | if (i32Diff <= 0)
|
---|
107 | {
|
---|
108 | /* Chunk will not cross buffer boundary. */
|
---|
109 | memcpy (pu8Dst, src, cb);
|
---|
110 | }
|
---|
111 | else
|
---|
112 | {
|
---|
113 | /* Chunk crosses buffer boundary. */
|
---|
114 | memcpy (pu8Dst, src, u32BytesTillBoundary);
|
---|
115 | memcpy (pu8Dst + u32BytesTillBoundary, &pVBVA->au8Data[0], i32Diff);
|
---|
116 | }
|
---|
117 |
|
---|
118 | /* Advance data offset. */
|
---|
119 | pVBVA->off32Data = (pVBVA->off32Data + cb) % pVBVA->cbData;
|
---|
120 |
|
---|
121 | return;
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | static bool vbvaPartialRead (VBVAPARTIALRECORD *pPartialRecord, uint32_t cbRecord, VBVABUFFER *pVBVA)
|
---|
126 | {
|
---|
127 | uint8_t *pu8New;
|
---|
128 |
|
---|
129 | LOGVBVABUFFER(("vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
|
---|
130 | pPartialRecord->pu8, pPartialRecord->cb, cbRecord));
|
---|
131 |
|
---|
132 | if (pPartialRecord->pu8)
|
---|
133 | {
|
---|
134 | Assert (pPartialRecord->cb);
|
---|
135 | pu8New = (uint8_t *)RTMemRealloc (pPartialRecord->pu8, cbRecord);
|
---|
136 | }
|
---|
137 | else
|
---|
138 | {
|
---|
139 | Assert (!pPartialRecord->cb);
|
---|
140 | pu8New = (uint8_t *)RTMemAlloc (cbRecord);
|
---|
141 | }
|
---|
142 |
|
---|
143 | if (!pu8New)
|
---|
144 | {
|
---|
145 | /* Memory allocation failed, fail the function. */
|
---|
146 | Log(("vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
|
---|
147 | cbRecord));
|
---|
148 |
|
---|
149 | if (pPartialRecord->pu8)
|
---|
150 | {
|
---|
151 | RTMemFree (pPartialRecord->pu8);
|
---|
152 | }
|
---|
153 |
|
---|
154 | pPartialRecord->pu8 = NULL;
|
---|
155 | pPartialRecord->cb = 0;
|
---|
156 |
|
---|
157 | return false;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /* Fetch data from the ring buffer. */
|
---|
161 | vbvaFetchBytes (pVBVA, pu8New + pPartialRecord->cb, cbRecord - pPartialRecord->cb);
|
---|
162 |
|
---|
163 | pPartialRecord->pu8 = pu8New;
|
---|
164 | pPartialRecord->cb = cbRecord;
|
---|
165 |
|
---|
166 | return true;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /* For contiguous chunks just return the address in the buffer.
|
---|
170 | * For crossing boundary - allocate a buffer from heap.
|
---|
171 | */
|
---|
172 | static bool vbvaFetchCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR **ppHdr, uint32_t *pcbCmd)
|
---|
173 | {
|
---|
174 | uint32_t indexRecordFirst = pVBVA->indexRecordFirst;
|
---|
175 | uint32_t indexRecordFree = pVBVA->indexRecordFree;
|
---|
176 |
|
---|
177 | LOGVBVABUFFER(("first = %d, free = %d\n",
|
---|
178 | indexRecordFirst, indexRecordFree));
|
---|
179 |
|
---|
180 | if (indexRecordFirst == indexRecordFree)
|
---|
181 | {
|
---|
182 | /* No records to process. Return without assigning output variables. */
|
---|
183 | return true;
|
---|
184 | }
|
---|
185 |
|
---|
186 | uint32_t cbRecordCurrent = ASMAtomicReadU32(&pVBVA->aRecords[indexRecordFirst].cbRecord);
|
---|
187 |
|
---|
188 | LOGVBVABUFFER(("cbRecord = 0x%08X, pPartialRecord->cb = 0x%08X\n", cbRecordCurrent, pPartialRecord->cb));
|
---|
189 |
|
---|
190 | uint32_t cbRecord = cbRecordCurrent & ~VBVA_F_RECORD_PARTIAL;
|
---|
191 |
|
---|
192 | if (pPartialRecord->cb)
|
---|
193 | {
|
---|
194 | /* There is a partial read in process. Continue with it. */
|
---|
195 | Assert (pPartialRecord->pu8);
|
---|
196 |
|
---|
197 | LOGVBVABUFFER(("continue partial record cb = %d cbRecord 0x%08X, first = %d, free = %d\n",
|
---|
198 | pPartialRecord->cb, cbRecordCurrent, indexRecordFirst, indexRecordFree));
|
---|
199 |
|
---|
200 | if (cbRecord > pPartialRecord->cb)
|
---|
201 | {
|
---|
202 | /* New data has been added to the record. */
|
---|
203 | if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
|
---|
204 | {
|
---|
205 | return false;
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | if (!(cbRecordCurrent & VBVA_F_RECORD_PARTIAL))
|
---|
210 | {
|
---|
211 | /* The record is completed by guest. Return it to the caller. */
|
---|
212 | *ppHdr = (VBVACMDHDR *)pPartialRecord->pu8;
|
---|
213 | *pcbCmd = pPartialRecord->cb;
|
---|
214 |
|
---|
215 | pPartialRecord->pu8 = NULL;
|
---|
216 | pPartialRecord->cb = 0;
|
---|
217 |
|
---|
218 | /* Advance the record index. */
|
---|
219 | pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
|
---|
220 |
|
---|
221 | LOGVBVABUFFER(("partial done ok, data = %d, free = %d\n",
|
---|
222 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
223 | }
|
---|
224 |
|
---|
225 | return true;
|
---|
226 | }
|
---|
227 |
|
---|
228 | /* A new record need to be processed. */
|
---|
229 | if (cbRecordCurrent & VBVA_F_RECORD_PARTIAL)
|
---|
230 | {
|
---|
231 | /* Current record is being written by guest. '=' is important here,
|
---|
232 | * because the guest will do a FLUSH at this condition.
|
---|
233 | * This partial record is too large for the ring buffer and must
|
---|
234 | * be accumulated in an allocated buffer.
|
---|
235 | */
|
---|
236 | if (cbRecord >= pVBVA->cbData - pVBVA->cbPartialWriteThreshold)
|
---|
237 | {
|
---|
238 | /* Partial read must be started. */
|
---|
239 | if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
|
---|
240 | {
|
---|
241 | return false;
|
---|
242 | }
|
---|
243 |
|
---|
244 | LOGVBVABUFFER(("started partial record cb = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
|
---|
245 | pPartialRecord->cb, cbRecordCurrent, indexRecordFirst, indexRecordFree));
|
---|
246 | }
|
---|
247 |
|
---|
248 | return true;
|
---|
249 | }
|
---|
250 |
|
---|
251 | /* Current record is complete. If it is not empty, process it. */
|
---|
252 | if (cbRecord)
|
---|
253 | {
|
---|
254 | /* The size of largest contiguous chunk in the ring biffer. */
|
---|
255 | uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
|
---|
256 |
|
---|
257 | /* The pointer to data in the ring buffer. */
|
---|
258 | uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
|
---|
259 |
|
---|
260 | /* Fetch or point the data. */
|
---|
261 | if (u32BytesTillBoundary >= cbRecord)
|
---|
262 | {
|
---|
263 | /* The command does not cross buffer boundary. Return address in the buffer. */
|
---|
264 | *ppHdr = (VBVACMDHDR *)src;
|
---|
265 |
|
---|
266 | /* Advance data offset. */
|
---|
267 | pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
|
---|
268 | }
|
---|
269 | else
|
---|
270 | {
|
---|
271 | /* The command crosses buffer boundary. Rare case, so not optimized. */
|
---|
272 | uint8_t *dst = (uint8_t *)RTMemAlloc (cbRecord);
|
---|
273 |
|
---|
274 | if (!dst)
|
---|
275 | {
|
---|
276 | LogFlowFunc (("could not allocate %d bytes from heap!!!\n", cbRecord));
|
---|
277 | pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
|
---|
278 | return false;
|
---|
279 | }
|
---|
280 |
|
---|
281 | vbvaFetchBytes (pVBVA, dst, cbRecord);
|
---|
282 |
|
---|
283 | *ppHdr = (VBVACMDHDR *)dst;
|
---|
284 |
|
---|
285 | LOGVBVABUFFER(("Allocated from heap %p\n", dst));
|
---|
286 | }
|
---|
287 | }
|
---|
288 |
|
---|
289 | *pcbCmd = cbRecord;
|
---|
290 |
|
---|
291 | /* Advance the record index. */
|
---|
292 | pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
|
---|
293 |
|
---|
294 | LOGVBVABUFFER(("done ok, data = %d, free = %d\n",
|
---|
295 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
296 |
|
---|
297 | return true;
|
---|
298 | }
|
---|
299 |
|
---|
300 | static void vbvaReleaseCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR *pHdr, uint32_t cbCmd)
|
---|
301 | {
|
---|
302 | uint8_t *au8RingBuffer = &pVBVA->au8Data[0];
|
---|
303 |
|
---|
304 | if ( (uint8_t *)pHdr >= au8RingBuffer
|
---|
305 | && (uint8_t *)pHdr < &au8RingBuffer[pVBVA->cbData])
|
---|
306 | {
|
---|
307 | /* The pointer is inside ring buffer. Must be continuous chunk. */
|
---|
308 | Assert (pVBVA->cbData - ((uint8_t *)pHdr - au8RingBuffer) >= cbCmd);
|
---|
309 |
|
---|
310 | /* Do nothing. */
|
---|
311 |
|
---|
312 | Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
|
---|
313 | }
|
---|
314 | else
|
---|
315 | {
|
---|
316 | /* The pointer is outside. It is then an allocated copy. */
|
---|
317 | LOGVBVABUFFER(("Free heap %p\n", pHdr));
|
---|
318 |
|
---|
319 | if ((uint8_t *)pHdr == pPartialRecord->pu8)
|
---|
320 | {
|
---|
321 | pPartialRecord->pu8 = NULL;
|
---|
322 | pPartialRecord->cb = 0;
|
---|
323 | }
|
---|
324 | else
|
---|
325 | {
|
---|
326 | Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
|
---|
327 | }
|
---|
328 |
|
---|
329 | RTMemFree (pHdr);
|
---|
330 | }
|
---|
331 |
|
---|
332 | return;
|
---|
333 | }
|
---|
334 |
|
---|
335 | static int vbvaFlushProcess (unsigned uScreenId, PVGASTATE pVGAState, VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA)
|
---|
336 | {
|
---|
337 | LOGVBVABUFFER(("uScreenId %d, indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
|
---|
338 | uScreenId, pVBVA->indexRecordFirst, pVBVA->indexRecordFree, pVBVA->off32Data, pVBVA->off32Free));
|
---|
339 | struct {
|
---|
340 | /* The rectangle that includes all dirty rectangles. */
|
---|
341 | int32_t xLeft;
|
---|
342 | int32_t xRight;
|
---|
343 | int32_t yTop;
|
---|
344 | int32_t yBottom;
|
---|
345 | } dirtyRect;
|
---|
346 | RT_ZERO(dirtyRect);
|
---|
347 |
|
---|
348 | bool fUpdate = false; /* Whether there were any updates. */
|
---|
349 | bool fDirtyEmpty = true;
|
---|
350 |
|
---|
351 | for (;;)
|
---|
352 | {
|
---|
353 | VBVACMDHDR *phdr = NULL;
|
---|
354 | uint32_t cbCmd = ~0;
|
---|
355 |
|
---|
356 | /* Fetch the command data. */
|
---|
357 | if (!vbvaFetchCmd (pPartialRecord, pVBVA, &phdr, &cbCmd))
|
---|
358 | {
|
---|
359 | LogFunc(("unable to fetch command. off32Data = %d, off32Free = %d!!!\n",
|
---|
360 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
361 |
|
---|
362 | /* @todo old code disabled VBVA processing here. */
|
---|
363 | return VERR_NOT_SUPPORTED;
|
---|
364 | }
|
---|
365 |
|
---|
366 | if (cbCmd == uint32_t(~0))
|
---|
367 | {
|
---|
368 | /* No more commands yet in the queue. */
|
---|
369 | break;
|
---|
370 | }
|
---|
371 |
|
---|
372 | if (cbCmd != 0)
|
---|
373 | {
|
---|
374 | if (!fUpdate)
|
---|
375 | {
|
---|
376 | pVGAState->pDrv->pfnVBVAUpdateBegin (pVGAState->pDrv, uScreenId);
|
---|
377 | fUpdate = true;
|
---|
378 | }
|
---|
379 |
|
---|
380 | /* Updates the rectangle and sends the command to the VRDP server. */
|
---|
381 | pVGAState->pDrv->pfnVBVAUpdateProcess (pVGAState->pDrv, uScreenId, phdr, cbCmd);
|
---|
382 |
|
---|
383 | int32_t xRight = phdr->x + phdr->w;
|
---|
384 | int32_t yBottom = phdr->y + phdr->h;
|
---|
385 |
|
---|
386 | /* These are global coords, relative to the primary screen. */
|
---|
387 |
|
---|
388 | LOGVBVABUFFER(("cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
|
---|
389 | cbCmd, phdr->x, phdr->y, phdr->w, phdr->h));
|
---|
390 | LogRel3(("%s: update command cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
|
---|
391 | __PRETTY_FUNCTION__, cbCmd, phdr->x, phdr->y, phdr->w,
|
---|
392 | phdr->h));
|
---|
393 |
|
---|
394 | /* Collect all rects into one. */
|
---|
395 | if (fDirtyEmpty)
|
---|
396 | {
|
---|
397 | /* This is the first rectangle to be added. */
|
---|
398 | dirtyRect.xLeft = phdr->x;
|
---|
399 | dirtyRect.yTop = phdr->y;
|
---|
400 | dirtyRect.xRight = xRight;
|
---|
401 | dirtyRect.yBottom = yBottom;
|
---|
402 | fDirtyEmpty = false;
|
---|
403 | }
|
---|
404 | else
|
---|
405 | {
|
---|
406 | /* Adjust region coordinates. */
|
---|
407 | if (dirtyRect.xLeft > phdr->x)
|
---|
408 | {
|
---|
409 | dirtyRect.xLeft = phdr->x;
|
---|
410 | }
|
---|
411 |
|
---|
412 | if (dirtyRect.yTop > phdr->y)
|
---|
413 | {
|
---|
414 | dirtyRect.yTop = phdr->y;
|
---|
415 | }
|
---|
416 |
|
---|
417 | if (dirtyRect.xRight < xRight)
|
---|
418 | {
|
---|
419 | dirtyRect.xRight = xRight;
|
---|
420 | }
|
---|
421 |
|
---|
422 | if (dirtyRect.yBottom < yBottom)
|
---|
423 | {
|
---|
424 | dirtyRect.yBottom = yBottom;
|
---|
425 | }
|
---|
426 | }
|
---|
427 | }
|
---|
428 |
|
---|
429 | vbvaReleaseCmd (pPartialRecord, pVBVA, phdr, cbCmd);
|
---|
430 | }
|
---|
431 |
|
---|
432 | if (fUpdate)
|
---|
433 | {
|
---|
434 | if (dirtyRect.xRight - dirtyRect.xLeft)
|
---|
435 | {
|
---|
436 | LogRel3(("%s: sending update screen=%d, x=%d, y=%d, w=%d, h=%d\n",
|
---|
437 | __PRETTY_FUNCTION__, uScreenId, dirtyRect.xLeft,
|
---|
438 | dirtyRect.yTop, dirtyRect.xRight - dirtyRect.xLeft,
|
---|
439 | dirtyRect.yBottom - dirtyRect.yTop));
|
---|
440 | pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, dirtyRect.xLeft, dirtyRect.yTop,
|
---|
441 | dirtyRect.xRight - dirtyRect.xLeft, dirtyRect.yBottom - dirtyRect.yTop);
|
---|
442 | }
|
---|
443 | else
|
---|
444 | {
|
---|
445 | pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, 0, 0, 0, 0);
|
---|
446 | }
|
---|
447 | }
|
---|
448 |
|
---|
449 | return VINF_SUCCESS;
|
---|
450 | }
|
---|
451 |
|
---|
452 | static int vbvaFlush (PVGASTATE pVGAState, VBVACONTEXT *pCtx)
|
---|
453 | {
|
---|
454 | unsigned uScreenId;
|
---|
455 |
|
---|
456 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
457 | {
|
---|
458 | VBVAPARTIALRECORD *pPartialRecord = &pCtx->aViews[uScreenId].partialRecord;
|
---|
459 | VBVABUFFER *pVBVA = pCtx->aViews[uScreenId].pVBVA;
|
---|
460 |
|
---|
461 | if (pVBVA)
|
---|
462 | {
|
---|
463 | vbvaFlushProcess (uScreenId, pVGAState, pPartialRecord, pVBVA);
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | /* @todo rc */
|
---|
468 | return VINF_SUCCESS;
|
---|
469 | }
|
---|
470 |
|
---|
471 | static int vbvaResize (PVGASTATE pVGAState, VBVAVIEW *pView, const VBVAINFOSCREEN *pNewScreen)
|
---|
472 | {
|
---|
473 | /* Verify pNewScreen. */
|
---|
474 | /* @todo */
|
---|
475 |
|
---|
476 | /* Apply these changes. */
|
---|
477 | pView->screen = *pNewScreen;
|
---|
478 |
|
---|
479 | uint8_t *pu8VRAM = pVGAState->vram_ptrR3 + pView->view.u32ViewOffset;
|
---|
480 |
|
---|
481 | int rc = pVGAState->pDrv->pfnVBVAResize (pVGAState->pDrv, &pView->view, &pView->screen, pu8VRAM);
|
---|
482 |
|
---|
483 | /* @todo process VINF_VGA_RESIZE_IN_PROGRESS? */
|
---|
484 |
|
---|
485 | return rc;
|
---|
486 | }
|
---|
487 |
|
---|
488 | static int vbvaEnable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx, VBVABUFFER *pVBVA, uint32_t u32Offset, bool fRestored)
|
---|
489 | {
|
---|
490 | /* @todo old code did a UpdateDisplayAll at this place. */
|
---|
491 |
|
---|
492 | int rc;
|
---|
493 |
|
---|
494 | if (pVGAState->pDrv->pfnVBVAEnable)
|
---|
495 | {
|
---|
496 | pVBVA->hostFlags.u32HostEvents = 0;
|
---|
497 | pVBVA->hostFlags.u32SupportedOrders = 0;
|
---|
498 | pVGAState->fGuestCaps = 0;
|
---|
499 | pVGAState->pDrv->pfnVBVAGuestCapabilityUpdate(pVGAState->pDrv, 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 = HGSMIHostCommandProcessAndFreeAsynch(pIns, pHostCmd, (pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ) != 0);
|
---|
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 | {
|
---|
2185 | pConf32->u32Value = VINF_SUCCESS;
|
---|
2186 | }
|
---|
2187 | else
|
---|
2188 | {
|
---|
2189 | Log(("Unsupported VBVA_QUERY_CONF32 index %d!!!\n",
|
---|
2190 | pConf32->u32Index));
|
---|
2191 | rc = VERR_INVALID_PARAMETER;
|
---|
2192 | }
|
---|
2193 | } break;
|
---|
2194 |
|
---|
2195 | case VBVA_SET_CONF32:
|
---|
2196 | {
|
---|
2197 | if (cbBuffer < sizeof (VBVACONF32))
|
---|
2198 | {
|
---|
2199 | rc = VERR_INVALID_PARAMETER;
|
---|
2200 | break;
|
---|
2201 | }
|
---|
2202 |
|
---|
2203 | VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
|
---|
2204 | LogFlowFunc(("VBVA_SET_CONF32: u32Index %d, u32Value 0x%x\n",
|
---|
2205 | pConf32->u32Index, pConf32->u32Value));
|
---|
2206 |
|
---|
2207 | if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
|
---|
2208 | {
|
---|
2209 | /* do nothing. this is a const. */
|
---|
2210 | }
|
---|
2211 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
|
---|
2212 | {
|
---|
2213 | /* do nothing. this is a const. */
|
---|
2214 | }
|
---|
2215 | else
|
---|
2216 | {
|
---|
2217 | Log(("Unsupported VBVA_SET_CONF32 index %d!!!\n",
|
---|
2218 | pConf32->u32Index));
|
---|
2219 | rc = VERR_INVALID_PARAMETER;
|
---|
2220 | }
|
---|
2221 | } break;
|
---|
2222 |
|
---|
2223 | case VBVA_INFO_VIEW:
|
---|
2224 | {
|
---|
2225 | #ifdef VBOX_WITH_CRHGSMI
|
---|
2226 | if (vboxCmdVBVAIsEnabled(pVGAState))
|
---|
2227 | {
|
---|
2228 | AssertMsgFailed(("VBVA_INFO_VIEW is not acceptible for CmdVbva\n"));
|
---|
2229 | rc = VERR_INVALID_PARAMETER;
|
---|
2230 | break;
|
---|
2231 | }
|
---|
2232 | #endif
|
---|
2233 |
|
---|
2234 | if (cbBuffer < sizeof (VBVAINFOVIEW))
|
---|
2235 | {
|
---|
2236 | rc = VERR_INVALID_PARAMETER;
|
---|
2237 | break;
|
---|
2238 | }
|
---|
2239 |
|
---|
2240 | /* Guest submits an array of VBVAINFOVIEW structures. */
|
---|
2241 | VBVAINFOVIEW *pView = (VBVAINFOVIEW *)pvBuffer;
|
---|
2242 |
|
---|
2243 | for (;
|
---|
2244 | cbBuffer >= sizeof (VBVAINFOVIEW);
|
---|
2245 | pView++, cbBuffer -= sizeof (VBVAINFOVIEW))
|
---|
2246 | {
|
---|
2247 | VBVAINFOVIEW View = *pView;
|
---|
2248 | rc = VBVAInfoView(pVGAState, &View);
|
---|
2249 | if (RT_FAILURE(rc))
|
---|
2250 | break;
|
---|
2251 | }
|
---|
2252 | } break;
|
---|
2253 |
|
---|
2254 | case VBVA_INFO_HEAP:
|
---|
2255 | {
|
---|
2256 | if (cbBuffer < sizeof (VBVAINFOHEAP))
|
---|
2257 | {
|
---|
2258 | rc = VERR_INVALID_PARAMETER;
|
---|
2259 | break;
|
---|
2260 | }
|
---|
2261 |
|
---|
2262 | VBVAINFOHEAP *pHeap = (VBVAINFOHEAP *)pvBuffer;
|
---|
2263 | LogFlowFunc(("VBVA_INFO_HEAP: offset 0x%x, size 0x%x\n",
|
---|
2264 | pHeap->u32HeapOffset, pHeap->u32HeapSize));
|
---|
2265 |
|
---|
2266 | rc = HGSMISetupHostHeap (pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
|
---|
2267 | } break;
|
---|
2268 |
|
---|
2269 | case VBVA_FLUSH:
|
---|
2270 | {
|
---|
2271 | if (cbBuffer < sizeof (VBVAFLUSH))
|
---|
2272 | {
|
---|
2273 | rc = VERR_INVALID_PARAMETER;
|
---|
2274 | break;
|
---|
2275 | }
|
---|
2276 |
|
---|
2277 | VBVAFLUSH *pFlush = (VBVAFLUSH *)pvBuffer;
|
---|
2278 | LogFlowFunc(("VBVA_FLUSH: u32Reserved 0x%x\n",
|
---|
2279 | pFlush->u32Reserved));
|
---|
2280 |
|
---|
2281 | rc = vbvaFlush (pVGAState, pCtx);
|
---|
2282 | } break;
|
---|
2283 |
|
---|
2284 | case VBVA_INFO_SCREEN:
|
---|
2285 | {
|
---|
2286 | if (cbBuffer < sizeof (VBVAINFOSCREEN))
|
---|
2287 | {
|
---|
2288 | rc = VERR_INVALID_PARAMETER;
|
---|
2289 | break;
|
---|
2290 | }
|
---|
2291 |
|
---|
2292 | #ifdef VBOX_WITH_CRHGSMI
|
---|
2293 | if (vboxCmdVBVAIsEnabled(pVGAState))
|
---|
2294 | {
|
---|
2295 | AssertMsgFailed(("VBVA_INFO_SCREEN is not acceptible for CmdVbva\n"));
|
---|
2296 | rc = VERR_INVALID_PARAMETER;
|
---|
2297 | break;
|
---|
2298 | }
|
---|
2299 | #endif
|
---|
2300 |
|
---|
2301 | VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)pvBuffer;
|
---|
2302 | VBVAINFOSCREEN Screen = *pScreen;
|
---|
2303 | rc = VBVAInfoScreen(pVGAState, &Screen);
|
---|
2304 | } break;
|
---|
2305 |
|
---|
2306 | case VBVA_ENABLE:
|
---|
2307 | {
|
---|
2308 | #ifdef VBOX_WITH_CRHGSMI
|
---|
2309 | if (vboxCmdVBVAIsEnabled(pVGAState))
|
---|
2310 | {
|
---|
2311 | AssertMsgFailed(("VBVA_ENABLE is not acceptible for CmdVbva\n"));
|
---|
2312 | rc = VERR_INVALID_PARAMETER;
|
---|
2313 | break;
|
---|
2314 | }
|
---|
2315 | #endif
|
---|
2316 |
|
---|
2317 | if (cbBuffer < sizeof (VBVAENABLE))
|
---|
2318 | {
|
---|
2319 | rc = VERR_INVALID_PARAMETER;
|
---|
2320 | break;
|
---|
2321 | }
|
---|
2322 |
|
---|
2323 | VBVAENABLE *pEnable = (VBVAENABLE *)pvBuffer;
|
---|
2324 | unsigned uScreenId;
|
---|
2325 | if (pEnable->u32Flags & VBVA_F_EXTENDED)
|
---|
2326 | {
|
---|
2327 | if (cbBuffer < sizeof (VBVAENABLE_EX))
|
---|
2328 | {
|
---|
2329 | rc = VERR_INVALID_PARAMETER;
|
---|
2330 | break;
|
---|
2331 | }
|
---|
2332 |
|
---|
2333 | VBVAENABLE_EX *pEnableEx = (VBVAENABLE_EX *)pvBuffer;
|
---|
2334 | uScreenId = pEnableEx->u32ScreenId;
|
---|
2335 | }
|
---|
2336 | else
|
---|
2337 | {
|
---|
2338 | uScreenId = vbvaViewFromOffset (pIns, pCtx, pvBuffer);
|
---|
2339 | }
|
---|
2340 |
|
---|
2341 | if (uScreenId == ~0U)
|
---|
2342 | {
|
---|
2343 | rc = VERR_INVALID_PARAMETER;
|
---|
2344 | break;
|
---|
2345 | }
|
---|
2346 |
|
---|
2347 | LogFlowFunc(("VBVA_ENABLE[%d]: u32Flags 0x%x u32Offset 0x%x\n",
|
---|
2348 | uScreenId, pEnable->u32Flags, pEnable->u32Offset));
|
---|
2349 |
|
---|
2350 | if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_ENABLE)
|
---|
2351 | {
|
---|
2352 | /* Guest reported offset relative to view. */
|
---|
2353 | uint32_t u32Offset = pEnable->u32Offset;
|
---|
2354 | if (!(pEnable->u32Flags & VBVA_F_ABSOFFSET))
|
---|
2355 | {
|
---|
2356 | u32Offset += pCtx->aViews[uScreenId].view.u32ViewOffset;
|
---|
2357 | }
|
---|
2358 |
|
---|
2359 | VBVABUFFER *pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, u32Offset);
|
---|
2360 |
|
---|
2361 | if (pVBVA)
|
---|
2362 | {
|
---|
2363 | /* Process any pending orders and empty the VBVA ring buffer. */
|
---|
2364 | vbvaFlush (pVGAState, pCtx);
|
---|
2365 |
|
---|
2366 | rc = vbvaEnable (uScreenId, pVGAState, pCtx, pVBVA, u32Offset, false /* fRestored */);
|
---|
2367 | }
|
---|
2368 | else
|
---|
2369 | {
|
---|
2370 | Log(("Invalid VBVABUFFER offset 0x%x!!!\n",
|
---|
2371 | pEnable->u32Offset));
|
---|
2372 | rc = VERR_INVALID_PARAMETER;
|
---|
2373 | }
|
---|
2374 | }
|
---|
2375 | else if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_DISABLE)
|
---|
2376 | {
|
---|
2377 | rc = vbvaDisable (uScreenId, pVGAState, pCtx);
|
---|
2378 | }
|
---|
2379 | else
|
---|
2380 | {
|
---|
2381 | Log(("Invalid VBVA_ENABLE flags 0x%x!!!\n",
|
---|
2382 | pEnable->u32Flags));
|
---|
2383 | rc = VERR_INVALID_PARAMETER;
|
---|
2384 | }
|
---|
2385 |
|
---|
2386 | pEnable->i32Result = rc;
|
---|
2387 | } break;
|
---|
2388 |
|
---|
2389 | case VBVA_MOUSE_POINTER_SHAPE:
|
---|
2390 | {
|
---|
2391 | if (cbBuffer < sizeof (VBVAMOUSEPOINTERSHAPE))
|
---|
2392 | {
|
---|
2393 | rc = VERR_INVALID_PARAMETER;
|
---|
2394 | break;
|
---|
2395 | }
|
---|
2396 |
|
---|
2397 | VBVAMOUSEPOINTERSHAPE *pShape = (VBVAMOUSEPOINTERSHAPE *)pvBuffer;
|
---|
2398 |
|
---|
2399 | LogFlowFunc(("VBVA_MOUSE_POINTER_SHAPE: i32Result 0x%x, fu32Flags 0x%x, hot spot %d,%d, size %dx%d\n",
|
---|
2400 | pShape->i32Result,
|
---|
2401 | pShape->fu32Flags,
|
---|
2402 | pShape->u32HotX,
|
---|
2403 | pShape->u32HotY,
|
---|
2404 | pShape->u32Width,
|
---|
2405 | pShape->u32Height));
|
---|
2406 |
|
---|
2407 | rc = vbvaMousePointerShape (pVGAState, pCtx, pShape, cbBuffer);
|
---|
2408 |
|
---|
2409 | pShape->i32Result = rc;
|
---|
2410 | } break;
|
---|
2411 |
|
---|
2412 |
|
---|
2413 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
2414 | case VBVA_VHWA_CMD:
|
---|
2415 | {
|
---|
2416 | if (cbBuffer < sizeof (VBOXVHWACMD))
|
---|
2417 | {
|
---|
2418 | rc = VERR_INVALID_PARAMETER;
|
---|
2419 | break;
|
---|
2420 | }
|
---|
2421 | vbvaVHWAHandleCommand(pVGAState, (PVBOXVHWACMD)pvBuffer);
|
---|
2422 | rc = VINF_SUCCESS;
|
---|
2423 | break;
|
---|
2424 | } break;
|
---|
2425 | #endif
|
---|
2426 |
|
---|
2427 | #ifdef VBOX_WITH_WDDM
|
---|
2428 | case VBVA_INFO_CAPS:
|
---|
2429 | {
|
---|
2430 | if (cbBuffer < sizeof (VBVACAPS))
|
---|
2431 | {
|
---|
2432 | rc = VERR_INVALID_PARAMETER;
|
---|
2433 | break;
|
---|
2434 | }
|
---|
2435 |
|
---|
2436 | VBVACAPS *pCaps = (VBVACAPS*)pvBuffer;
|
---|
2437 | pVGAState->fGuestCaps = pCaps->fCaps;
|
---|
2438 | pVGAState->pDrv->pfnVBVAGuestCapabilityUpdate(pVGAState->pDrv,
|
---|
2439 | pCaps->fCaps);
|
---|
2440 | pCaps->rc = VINF_SUCCESS;
|
---|
2441 | } break;
|
---|
2442 | #endif
|
---|
2443 | case VBVA_SCANLINE_CFG:
|
---|
2444 | {
|
---|
2445 | if (cbBuffer < sizeof (VBVASCANLINECFG))
|
---|
2446 | {
|
---|
2447 | rc = VERR_INVALID_PARAMETER;
|
---|
2448 | break;
|
---|
2449 | }
|
---|
2450 |
|
---|
2451 | VBVASCANLINECFG *pCfg = (VBVASCANLINECFG*)pvBuffer;
|
---|
2452 | pVGAState->fScanLineCfg = pCfg->fFlags;
|
---|
2453 | pCfg->rc = VINF_SUCCESS;
|
---|
2454 | } break;
|
---|
2455 |
|
---|
2456 | case VBVA_QUERY_MODE_HINTS:
|
---|
2457 | {
|
---|
2458 | if (cbBuffer < sizeof(VBVAQUERYMODEHINTS))
|
---|
2459 | {
|
---|
2460 | rc = VERR_INVALID_PARAMETER;
|
---|
2461 | break;
|
---|
2462 | }
|
---|
2463 | VBVAQUERYMODEHINTS *pModeHintQuery = (VBVAQUERYMODEHINTS*)pvBuffer;
|
---|
2464 | LogRelFlowFunc(("VBVA_QUERY_MODE_HINTS: cHintsQueried=%u, cbHintStructureGuest=%u\n",
|
---|
2465 | (unsigned)pModeHintQuery->cHintsQueried,
|
---|
2466 | (unsigned)pModeHintQuery->cbHintStructureGuest));
|
---|
2467 | if (cbBuffer < sizeof (VBVAQUERYMODEHINTS)
|
---|
2468 | + (uint64_t)pModeHintQuery->cHintsQueried
|
---|
2469 | * pModeHintQuery->cbHintStructureGuest)
|
---|
2470 | {
|
---|
2471 | pModeHintQuery->rc = VERR_INVALID_PARAMETER;
|
---|
2472 | break;
|
---|
2473 | }
|
---|
2474 | pModeHintQuery->rc = VINF_SUCCESS;
|
---|
2475 | uint8_t *pbHint = (uint8_t *)pvBuffer + sizeof(VBVAQUERYMODEHINTS);
|
---|
2476 | memset(pbHint, ~0, cbBuffer - sizeof(VBVAQUERYMODEHINTS));
|
---|
2477 | unsigned iHint;
|
---|
2478 | for (iHint = 0; iHint < pModeHintQuery->cHintsQueried
|
---|
2479 | && iHint < VBOX_VIDEO_MAX_SCREENS; ++iHint)
|
---|
2480 | {
|
---|
2481 | memcpy(pbHint, &pCtx->aModeHints[iHint],
|
---|
2482 | RT_MIN(pModeHintQuery->cbHintStructureGuest,
|
---|
2483 | sizeof(VBVAMODEHINT)));
|
---|
2484 | pbHint += pModeHintQuery->cbHintStructureGuest;
|
---|
2485 | Assert(pbHint - (uint8_t *)pvBuffer <= cbBuffer);
|
---|
2486 | }
|
---|
2487 | } break;
|
---|
2488 |
|
---|
2489 | default:
|
---|
2490 | Log(("Unsupported VBVA guest command %d!!!\n",
|
---|
2491 | u16ChannelInfo));
|
---|
2492 | break;
|
---|
2493 | }
|
---|
2494 |
|
---|
2495 | return rc;
|
---|
2496 | }
|
---|
2497 |
|
---|
2498 | /* When VBVA is paused, then VGA device is allowed to work but
|
---|
2499 | * no HGSMI etc state is changed.
|
---|
2500 | */
|
---|
2501 | void VBVAPause(PVGASTATE pVGAState, bool fPause)
|
---|
2502 | {
|
---|
2503 | if (!pVGAState || !pVGAState->pHGSMI)
|
---|
2504 | {
|
---|
2505 | return;
|
---|
2506 | }
|
---|
2507 |
|
---|
2508 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext(pVGAState->pHGSMI);
|
---|
2509 |
|
---|
2510 | if (pCtx)
|
---|
2511 | {
|
---|
2512 | pCtx->fPaused = fPause;
|
---|
2513 | }
|
---|
2514 | }
|
---|
2515 |
|
---|
2516 | void VBVAReset (PVGASTATE pVGAState)
|
---|
2517 | {
|
---|
2518 | if (!pVGAState || !pVGAState->pHGSMI)
|
---|
2519 | {
|
---|
2520 | return;
|
---|
2521 | }
|
---|
2522 |
|
---|
2523 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2524 |
|
---|
2525 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
2526 | vbvaVHWAReset (pVGAState);
|
---|
2527 | #endif
|
---|
2528 |
|
---|
2529 | uint32_t HgFlags = HGSMIReset (pVGAState->pHGSMI);
|
---|
2530 | if(HgFlags & HGSMIHOSTFLAGS_IRQ)
|
---|
2531 | {
|
---|
2532 | /* this means the IRQ is LEVEL_HIGH, need to reset it */
|
---|
2533 | PDMDevHlpPCISetIrq(pVGAState->pDevInsR3, 0, PDM_IRQ_LEVEL_LOW);
|
---|
2534 | }
|
---|
2535 |
|
---|
2536 | if (pCtx)
|
---|
2537 | {
|
---|
2538 | vbvaFlush (pVGAState, pCtx);
|
---|
2539 |
|
---|
2540 | unsigned uScreenId;
|
---|
2541 |
|
---|
2542 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
2543 | {
|
---|
2544 | vbvaDisable (uScreenId, pVGAState, pCtx);
|
---|
2545 | }
|
---|
2546 |
|
---|
2547 | pCtx->mouseShapeInfo.fSet = false;
|
---|
2548 | RTMemFree(pCtx->mouseShapeInfo.pu8Shape);
|
---|
2549 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
2550 | pCtx->mouseShapeInfo.cbAllocated = 0;
|
---|
2551 | pCtx->mouseShapeInfo.cbShape = 0;
|
---|
2552 | }
|
---|
2553 |
|
---|
2554 | }
|
---|
2555 |
|
---|
2556 | int VBVAUpdateDisplay (PVGASTATE pVGAState)
|
---|
2557 | {
|
---|
2558 | int rc = VERR_NOT_SUPPORTED; /* Assuming that the VGA device will have to do updates. */
|
---|
2559 |
|
---|
2560 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2561 |
|
---|
2562 | if (pCtx)
|
---|
2563 | {
|
---|
2564 | if (!pCtx->fPaused)
|
---|
2565 | {
|
---|
2566 | rc = vbvaFlush (pVGAState, pCtx);
|
---|
2567 |
|
---|
2568 | if (RT_SUCCESS (rc))
|
---|
2569 | {
|
---|
2570 | if (!pCtx->aViews[0].pVBVA)
|
---|
2571 | {
|
---|
2572 | /* VBVA is not enabled for the first view, so VGA device must do updates. */
|
---|
2573 | rc = VERR_NOT_SUPPORTED;
|
---|
2574 | }
|
---|
2575 | }
|
---|
2576 | }
|
---|
2577 | }
|
---|
2578 |
|
---|
2579 | return rc;
|
---|
2580 | }
|
---|
2581 |
|
---|
2582 | static int vbvaSendModeHintWorker(PVGASTATE pThis, uint32_t cx, uint32_t cy,
|
---|
2583 | uint32_t cBPP, uint32_t iDisplay, uint32_t dx,
|
---|
2584 | uint32_t dy, uint32_t fEnabled,
|
---|
2585 | uint32_t fNotifyGuest)
|
---|
2586 | {
|
---|
2587 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext(pThis->pHGSMI);
|
---|
2588 | /** @note See Display::setVideoModeHint: "It is up to the guest to decide
|
---|
2589 | * whether the hint is valid. Therefore don't do any VRAM sanity checks
|
---|
2590 | * here! */
|
---|
2591 | if (iDisplay > RT_MIN(pThis->cMonitors, RT_ELEMENTS(pCtx->aModeHints)))
|
---|
2592 | return VERR_OUT_OF_RANGE;
|
---|
2593 | pCtx->aModeHints[iDisplay].magic = VBVAMODEHINT_MAGIC;
|
---|
2594 | pCtx->aModeHints[iDisplay].cx = cx;
|
---|
2595 | pCtx->aModeHints[iDisplay].cy = cy;
|
---|
2596 | pCtx->aModeHints[iDisplay].cBPP = cBPP;
|
---|
2597 | pCtx->aModeHints[iDisplay].dx = dx;
|
---|
2598 | pCtx->aModeHints[iDisplay].dy = dy;
|
---|
2599 | pCtx->aModeHints[iDisplay].fEnabled = fEnabled;
|
---|
2600 | if (fNotifyGuest && pThis->fGuestCaps & VBVACAPS_IRQ)
|
---|
2601 | VBVARaiseIrq(pThis, HGSMIHOSTFLAGS_HOTPLUG);
|
---|
2602 | return VINF_SUCCESS;
|
---|
2603 | }
|
---|
2604 |
|
---|
2605 | /** Converts a display port interface pointer to a vga state pointer. */
|
---|
2606 | #define IDISPLAYPORT_2_VGASTATE(pInterface) ( (PVGASTATE)((uintptr_t)pInterface - RT_OFFSETOF(VGASTATE, IPort)) )
|
---|
2607 |
|
---|
2608 | DECLCALLBACK(int) vbvaPortSendModeHint(PPDMIDISPLAYPORT pInterface, uint32_t cx,
|
---|
2609 | uint32_t cy, uint32_t cBPP,
|
---|
2610 | uint32_t iDisplay, uint32_t dx,
|
---|
2611 | uint32_t dy, uint32_t fEnabled,
|
---|
2612 | uint32_t fNotifyGuest)
|
---|
2613 | {
|
---|
2614 | PVGASTATE pThis;
|
---|
2615 | int rc;
|
---|
2616 |
|
---|
2617 | pThis = IDISPLAYPORT_2_VGASTATE(pInterface);
|
---|
2618 | rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
|
---|
2619 | AssertRC(rc);
|
---|
2620 | rc = vbvaSendModeHintWorker(pThis, cx, cy, cBPP, iDisplay, dx, dy, fEnabled,
|
---|
2621 | fNotifyGuest);
|
---|
2622 | PDMCritSectLeave(&pThis->CritSect);
|
---|
2623 | return rc;
|
---|
2624 | }
|
---|
2625 |
|
---|
2626 | static HGSMICHANNELHANDLER sOldChannelHandler;
|
---|
2627 |
|
---|
2628 | int VBVAInit (PVGASTATE pVGAState)
|
---|
2629 | {
|
---|
2630 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
2631 |
|
---|
2632 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
2633 |
|
---|
2634 | int rc = HGSMICreate (&pVGAState->pHGSMI,
|
---|
2635 | pVM,
|
---|
2636 | "VBVA",
|
---|
2637 | 0,
|
---|
2638 | pVGAState->vram_ptrR3,
|
---|
2639 | pVGAState->vram_size,
|
---|
2640 | vbvaNotifyGuest,
|
---|
2641 | pVGAState,
|
---|
2642 | sizeof (VBVACONTEXT));
|
---|
2643 |
|
---|
2644 | if (RT_SUCCESS (rc))
|
---|
2645 | {
|
---|
2646 | rc = HGSMIHostChannelRegister (pVGAState->pHGSMI,
|
---|
2647 | HGSMI_CH_VBVA,
|
---|
2648 | vbvaChannelHandler,
|
---|
2649 | pVGAState,
|
---|
2650 | &sOldChannelHandler);
|
---|
2651 | if (RT_SUCCESS (rc))
|
---|
2652 | {
|
---|
2653 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2654 | pCtx->cViews = pVGAState->cMonitors;
|
---|
2655 | pCtx->fPaused = true;
|
---|
2656 | memset(pCtx->aModeHints, ~0, sizeof(*pCtx->aModeHints));
|
---|
2657 | }
|
---|
2658 | }
|
---|
2659 |
|
---|
2660 | return rc;
|
---|
2661 |
|
---|
2662 | }
|
---|
2663 |
|
---|
2664 | void VBVADestroy (PVGASTATE pVGAState)
|
---|
2665 | {
|
---|
2666 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
2667 |
|
---|
2668 | if (pCtx)
|
---|
2669 | {
|
---|
2670 | pCtx->mouseShapeInfo.fSet = false;
|
---|
2671 | RTMemFree(pCtx->mouseShapeInfo.pu8Shape);
|
---|
2672 | pCtx->mouseShapeInfo.pu8Shape = NULL;
|
---|
2673 | pCtx->mouseShapeInfo.cbAllocated = 0;
|
---|
2674 | pCtx->mouseShapeInfo.cbShape = 0;
|
---|
2675 | }
|
---|
2676 |
|
---|
2677 | HGSMIDestroy (pVGAState->pHGSMI);
|
---|
2678 | pVGAState->pHGSMI = NULL;
|
---|
2679 | }
|
---|