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