1 | /** @file
|
---|
2 | * VirtualBox Video Acceleration (VBVA).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2009 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
17 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
18 | * additional information or have any questions.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #define LOG_GROUP LOG_GROUP_DEV_VGA
|
---|
22 | #include <VBox/pdmifs.h>
|
---|
23 | #include <VBox/pdmdev.h>
|
---|
24 | #include <VBox/pgm.h>
|
---|
25 | #include <VBox/ssm.h>
|
---|
26 | #include <VBox/VMMDev.h>
|
---|
27 | #include <VBox/VBoxVideo.h>
|
---|
28 | #include <iprt/alloc.h>
|
---|
29 | #include <iprt/assert.h>
|
---|
30 | #include <iprt/asm.h>
|
---|
31 | #include <iprt/string.h>
|
---|
32 | #include <iprt/param.h>
|
---|
33 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
34 | #include <iprt/semaphore.h>
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | /** The default amount of VRAM. */
|
---|
38 | #define VGA_VRAM_DEFAULT (_4M)
|
---|
39 | /** The maximum amount of VRAM. */
|
---|
40 | #define VGA_VRAM_MAX (128 * _1M)
|
---|
41 | /** The minimum amount of VRAM. */
|
---|
42 | #define VGA_VRAM_MIN (_1M)
|
---|
43 |
|
---|
44 | #include "DevVGA.h"
|
---|
45 |
|
---|
46 | /* A very detailed logging. */
|
---|
47 | #if 0 // def DEBUG_sunlover
|
---|
48 | #define LOGVBVABUFFER(a) LogFlow(a)
|
---|
49 | #else
|
---|
50 | #define LOGVBVABUFFER(a) do {} while(0)
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | typedef struct _VBVAPARTIALRECORD
|
---|
54 | {
|
---|
55 | uint8_t *pu8;
|
---|
56 | uint32_t cb;
|
---|
57 | } VBVAPARTIALRECORD;
|
---|
58 |
|
---|
59 | typedef struct _VBVAVIEW
|
---|
60 | {
|
---|
61 | VBVAINFOVIEW view;
|
---|
62 | VBVAINFOSCREEN screen;
|
---|
63 | VBVABUFFER *pVBVA;
|
---|
64 | uint32_t u32VBVAOffset;
|
---|
65 | VBVAPARTIALRECORD partialRecord;
|
---|
66 | } VBVAVIEW;
|
---|
67 |
|
---|
68 | /* @todo saved state: save and restore VBVACONTEXT */
|
---|
69 | typedef struct _VBVACONTEXT
|
---|
70 | {
|
---|
71 | uint32_t cViews;
|
---|
72 | VBVAVIEW aViews[64 /* @todo SchemaDefs::MaxGuestMonitors*/];
|
---|
73 | } VBVACONTEXT;
|
---|
74 |
|
---|
75 | /* Copies 'cb' bytes from the VBVA ring buffer to the 'pu8Dst'.
|
---|
76 | * Used for partial records or for records which cross the ring boundary.
|
---|
77 | */
|
---|
78 | static void vbvaFetchBytes (VBVABUFFER *pVBVA, uint8_t *pu8Dst, uint32_t cb)
|
---|
79 | {
|
---|
80 | /* @todo replace the 'if' with an assert. The caller must ensure this condition. */
|
---|
81 | if (cb >= pVBVA->cbData)
|
---|
82 | {
|
---|
83 | AssertMsgFailed (("cb = 0x%08X, ring buffer size 0x%08X", cb, pVBVA->cbData));
|
---|
84 | return;
|
---|
85 | }
|
---|
86 |
|
---|
87 | const uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
|
---|
88 | const uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
|
---|
89 | const int32_t i32Diff = cb - u32BytesTillBoundary;
|
---|
90 |
|
---|
91 | if (i32Diff <= 0)
|
---|
92 | {
|
---|
93 | /* Chunk will not cross buffer boundary. */
|
---|
94 | memcpy (pu8Dst, src, cb);
|
---|
95 | }
|
---|
96 | else
|
---|
97 | {
|
---|
98 | /* Chunk crosses buffer boundary. */
|
---|
99 | memcpy (pu8Dst, src, u32BytesTillBoundary);
|
---|
100 | memcpy (pu8Dst + u32BytesTillBoundary, &pVBVA->au8Data[0], i32Diff);
|
---|
101 | }
|
---|
102 |
|
---|
103 | /* Advance data offset. */
|
---|
104 | pVBVA->off32Data = (pVBVA->off32Data + cb) % pVBVA->cbData;
|
---|
105 |
|
---|
106 | return;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | static bool vbvaPartialRead (VBVAPARTIALRECORD *pPartialRecord, uint32_t cbRecord, VBVABUFFER *pVBVA)
|
---|
111 | {
|
---|
112 | uint8_t *pu8New;
|
---|
113 |
|
---|
114 | LOGVBVABUFFER(("vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
|
---|
115 | pPartialRecord->pu8, pPartialRecord->cb, cbRecord));
|
---|
116 |
|
---|
117 | if (pPartialRecord->pu8)
|
---|
118 | {
|
---|
119 | Assert (pPartialRecord->cb);
|
---|
120 | pu8New = (uint8_t *)RTMemRealloc (pPartialRecord->pu8, cbRecord);
|
---|
121 | }
|
---|
122 | else
|
---|
123 | {
|
---|
124 | Assert (!pPartialRecord->cb);
|
---|
125 | pu8New = (uint8_t *)RTMemAlloc (cbRecord);
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (!pu8New)
|
---|
129 | {
|
---|
130 | /* Memory allocation failed, fail the function. */
|
---|
131 | Log(("vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
|
---|
132 | cbRecord));
|
---|
133 |
|
---|
134 | if (pPartialRecord->pu8)
|
---|
135 | {
|
---|
136 | RTMemFree (pPartialRecord->pu8);
|
---|
137 | }
|
---|
138 |
|
---|
139 | pPartialRecord->pu8 = NULL;
|
---|
140 | pPartialRecord->cb = 0;
|
---|
141 |
|
---|
142 | return false;
|
---|
143 | }
|
---|
144 |
|
---|
145 | /* Fetch data from the ring buffer. */
|
---|
146 | vbvaFetchBytes (pVBVA, pu8New + pPartialRecord->cb, cbRecord - pPartialRecord->cb);
|
---|
147 |
|
---|
148 | pPartialRecord->pu8 = pu8New;
|
---|
149 | pPartialRecord->cb = cbRecord;
|
---|
150 |
|
---|
151 | return true;
|
---|
152 | }
|
---|
153 |
|
---|
154 | /* For contiguous chunks just return the address in the buffer.
|
---|
155 | * For crossing boundary - allocate a buffer from heap.
|
---|
156 | */
|
---|
157 | static bool vbvaFetchCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR **ppHdr, uint32_t *pcbCmd)
|
---|
158 | {
|
---|
159 | uint32_t indexRecordFirst = pVBVA->indexRecordFirst;
|
---|
160 | uint32_t indexRecordFree = pVBVA->indexRecordFree;
|
---|
161 |
|
---|
162 | LOGVBVABUFFER(("first = %d, free = %d\n",
|
---|
163 | indexRecordFirst, indexRecordFree));
|
---|
164 |
|
---|
165 | if (indexRecordFirst == indexRecordFree)
|
---|
166 | {
|
---|
167 | /* No records to process. Return without assigning output variables. */
|
---|
168 | return true;
|
---|
169 | }
|
---|
170 |
|
---|
171 | VBVARECORD *pRecord = &pVBVA->aRecords[indexRecordFirst];
|
---|
172 |
|
---|
173 | LOGVBVABUFFER(("cbRecord = 0x%08X\n", pRecord->cbRecord));
|
---|
174 |
|
---|
175 | uint32_t cbRecord = pRecord->cbRecord & ~VBVA_F_RECORD_PARTIAL;
|
---|
176 |
|
---|
177 | if (pPartialRecord->cb)
|
---|
178 | {
|
---|
179 | /* There is a partial read in process. Continue with it. */
|
---|
180 | Assert (pPartialRecord->pu8);
|
---|
181 |
|
---|
182 | LOGVBVABUFFER(("continue partial record cb = %d cbRecord 0x%08X, first = %d, free = %d\n",
|
---|
183 | pPartialRecord->cb, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
|
---|
184 |
|
---|
185 | if (cbRecord > pPartialRecord->cb)
|
---|
186 | {
|
---|
187 | /* New data has been added to the record. */
|
---|
188 | if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
|
---|
189 | {
|
---|
190 | return false;
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | if (!(pRecord->cbRecord & VBVA_F_RECORD_PARTIAL))
|
---|
195 | {
|
---|
196 | /* The record is completed by guest. Return it to the caller. */
|
---|
197 | *ppHdr = (VBVACMDHDR *)pPartialRecord->pu8;
|
---|
198 | *pcbCmd = pPartialRecord->cb;
|
---|
199 |
|
---|
200 | pPartialRecord->pu8 = NULL;
|
---|
201 | pPartialRecord->cb = 0;
|
---|
202 |
|
---|
203 | /* Advance the record index. */
|
---|
204 | pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
|
---|
205 |
|
---|
206 | LOGVBVABUFFER(("partial done ok, data = %d, free = %d\n",
|
---|
207 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
208 | }
|
---|
209 |
|
---|
210 | return true;
|
---|
211 | }
|
---|
212 |
|
---|
213 | /* A new record need to be processed. */
|
---|
214 | if (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL)
|
---|
215 | {
|
---|
216 | /* Current record is being written by guest. '=' is important here,
|
---|
217 | * because the guest will do a FLUSH at this condition.
|
---|
218 | * This partual record is too large for the ring buffer and must
|
---|
219 | * be accumulated in an allocated buffer.
|
---|
220 | */
|
---|
221 | if (cbRecord >= pVBVA->cbData - pVBVA->cbPartialWriteThreshold)
|
---|
222 | {
|
---|
223 | /* Partial read must be started. */
|
---|
224 | if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
|
---|
225 | {
|
---|
226 | return false;
|
---|
227 | }
|
---|
228 |
|
---|
229 | LOGVBVABUFFER(("started partial record cb = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
|
---|
230 | pPartialRecord->cb, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
|
---|
231 | }
|
---|
232 |
|
---|
233 | return true;
|
---|
234 | }
|
---|
235 |
|
---|
236 | /* Current record is complete. If it is not empty, process it. */
|
---|
237 | if (cbRecord)
|
---|
238 | {
|
---|
239 | /* The size of largest contiguos chunk in the ring biffer. */
|
---|
240 | uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
|
---|
241 |
|
---|
242 | /* The pointer to data in the ring buffer. */
|
---|
243 | uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
|
---|
244 |
|
---|
245 | /* Fetch or point the data. */
|
---|
246 | if (u32BytesTillBoundary >= cbRecord)
|
---|
247 | {
|
---|
248 | /* The command does not cross buffer boundary. Return address in the buffer. */
|
---|
249 | *ppHdr = (VBVACMDHDR *)src;
|
---|
250 |
|
---|
251 | /* Advance data offset. */
|
---|
252 | pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
|
---|
253 | }
|
---|
254 | else
|
---|
255 | {
|
---|
256 | /* The command crosses buffer boundary. Rare case, so not optimized. */
|
---|
257 | uint8_t *dst = (uint8_t *)RTMemAlloc (cbRecord);
|
---|
258 |
|
---|
259 | if (!dst)
|
---|
260 | {
|
---|
261 | LogFlowFunc (("could not allocate %d bytes from heap!!!\n", cbRecord));
|
---|
262 | pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
|
---|
263 | return false;
|
---|
264 | }
|
---|
265 |
|
---|
266 | vbvaFetchBytes (pVBVA, dst, cbRecord);
|
---|
267 |
|
---|
268 | *ppHdr = (VBVACMDHDR *)dst;
|
---|
269 |
|
---|
270 | LOGVBVABUFFER(("Allocated from heap %p\n", dst));
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | *pcbCmd = cbRecord;
|
---|
275 |
|
---|
276 | /* Advance the record index. */
|
---|
277 | pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
|
---|
278 |
|
---|
279 | LOGVBVABUFFER(("done ok, data = %d, free = %d\n",
|
---|
280 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
281 |
|
---|
282 | return true;
|
---|
283 | }
|
---|
284 |
|
---|
285 | static void vbvaReleaseCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR *pHdr, uint32_t cbCmd)
|
---|
286 | {
|
---|
287 | uint8_t *au8RingBuffer = &pVBVA->au8Data[0];
|
---|
288 |
|
---|
289 | if ( (uint8_t *)pHdr >= au8RingBuffer
|
---|
290 | && (uint8_t *)pHdr < &au8RingBuffer[pVBVA->cbData])
|
---|
291 | {
|
---|
292 | /* The pointer is inside ring buffer. Must be continuous chunk. */
|
---|
293 | Assert (pVBVA->cbData - ((uint8_t *)pHdr - au8RingBuffer) >= cbCmd);
|
---|
294 |
|
---|
295 | /* Do nothing. */
|
---|
296 |
|
---|
297 | Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
|
---|
298 | }
|
---|
299 | else
|
---|
300 | {
|
---|
301 | /* The pointer is outside. It is then an allocated copy. */
|
---|
302 | LOGVBVABUFFER(("Free heap %p\n", pHdr));
|
---|
303 |
|
---|
304 | if ((uint8_t *)pHdr == pPartialRecord->pu8)
|
---|
305 | {
|
---|
306 | pPartialRecord->pu8 = NULL;
|
---|
307 | pPartialRecord->cb = 0;
|
---|
308 | }
|
---|
309 | else
|
---|
310 | {
|
---|
311 | Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
|
---|
312 | }
|
---|
313 |
|
---|
314 | RTMemFree (pHdr);
|
---|
315 | }
|
---|
316 |
|
---|
317 | return;
|
---|
318 | }
|
---|
319 |
|
---|
320 | static int vbvaFlushProcess (unsigned uScreenId, PVGASTATE pVGAState, VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA)
|
---|
321 | {
|
---|
322 | LOGVBVABUFFER(("uScreenId %d, indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
|
---|
323 | uScreenId, pVBVA->indexRecordFirst, pVBVA->indexRecordFree, pVBVA->off32Data, pVBVA->off32Free));
|
---|
324 | struct {
|
---|
325 | /* The rectangle that includes all dirty rectangles. */
|
---|
326 | int32_t xLeft;
|
---|
327 | int32_t xRight;
|
---|
328 | int32_t yTop;
|
---|
329 | int32_t yBottom;
|
---|
330 | } dirtyRect;
|
---|
331 | memset(&dirtyRect, 0, sizeof(dirtyRect));
|
---|
332 |
|
---|
333 | bool fUpdate = false; /* Whether there were any updates. */
|
---|
334 |
|
---|
335 | for (;;)
|
---|
336 | {
|
---|
337 | VBVACMDHDR *phdr = NULL;
|
---|
338 | uint32_t cbCmd = ~0;
|
---|
339 |
|
---|
340 | /* Fetch the command data. */
|
---|
341 | if (!vbvaFetchCmd (pPartialRecord, pVBVA, &phdr, &cbCmd))
|
---|
342 | {
|
---|
343 | LogFunc(("unable to fetch command. off32Data = %d, off32Free = %d!!!\n",
|
---|
344 | pVBVA->off32Data, pVBVA->off32Free));
|
---|
345 |
|
---|
346 | /* @todo old code disabled VBVA processing here. */
|
---|
347 | return VERR_NOT_SUPPORTED;
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (cbCmd == uint32_t(~0))
|
---|
351 | {
|
---|
352 | /* No more commands yet in the queue. */
|
---|
353 | break;
|
---|
354 | }
|
---|
355 |
|
---|
356 | if (cbCmd != 0)
|
---|
357 | {
|
---|
358 | if (!fUpdate)
|
---|
359 | {
|
---|
360 | pVGAState->pDrv->pfnVBVAUpdateBegin (pVGAState->pDrv, uScreenId);
|
---|
361 | fUpdate = true;
|
---|
362 | }
|
---|
363 |
|
---|
364 | /* Updates the rectangle and sends the command to the VRDP server. */
|
---|
365 | pVGAState->pDrv->pfnVBVAUpdateProcess (pVGAState->pDrv, uScreenId, phdr, cbCmd);
|
---|
366 |
|
---|
367 | int32_t xRight = phdr->x + phdr->w;
|
---|
368 | int32_t yBottom = phdr->y + phdr->h;
|
---|
369 |
|
---|
370 | /* These are global coords, relative to the primary screen. */
|
---|
371 |
|
---|
372 | LOGVBVABUFFER(("cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
|
---|
373 | cbCmd, phdr->x, phdr->y, phdr->w, phdr->h));
|
---|
374 |
|
---|
375 | /* Collect all rects into one. */
|
---|
376 | if (dirtyRect.xRight == 0)
|
---|
377 | {
|
---|
378 | /* This is the first rectangle to be added. */
|
---|
379 | dirtyRect.xLeft = phdr->x;
|
---|
380 | dirtyRect.yTop = phdr->y;
|
---|
381 | dirtyRect.xRight = xRight;
|
---|
382 | dirtyRect.yBottom = yBottom;
|
---|
383 | }
|
---|
384 | else
|
---|
385 | {
|
---|
386 | /* Adjust region coordinates. */
|
---|
387 | if (dirtyRect.xLeft > phdr->x)
|
---|
388 | {
|
---|
389 | dirtyRect.xLeft = phdr->x;
|
---|
390 | }
|
---|
391 |
|
---|
392 | if (dirtyRect.yTop > phdr->y)
|
---|
393 | {
|
---|
394 | dirtyRect.yTop = phdr->y;
|
---|
395 | }
|
---|
396 |
|
---|
397 | if (dirtyRect.xRight < xRight)
|
---|
398 | {
|
---|
399 | dirtyRect.xRight = xRight;
|
---|
400 | }
|
---|
401 |
|
---|
402 | if (dirtyRect.yBottom < yBottom)
|
---|
403 | {
|
---|
404 | dirtyRect.yBottom = yBottom;
|
---|
405 | }
|
---|
406 | }
|
---|
407 | }
|
---|
408 |
|
---|
409 | vbvaReleaseCmd (pPartialRecord, pVBVA, phdr, cbCmd);
|
---|
410 | }
|
---|
411 |
|
---|
412 | if (fUpdate)
|
---|
413 | {
|
---|
414 | if(dirtyRect.xRight)
|
---|
415 | {
|
---|
416 | pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, dirtyRect.xLeft, dirtyRect.yTop,
|
---|
417 | dirtyRect.xRight - dirtyRect.xLeft, dirtyRect.yBottom - dirtyRect.yTop);
|
---|
418 | }
|
---|
419 | else
|
---|
420 | {
|
---|
421 | pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, 0, 0, 0, 0);
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | return VINF_SUCCESS;
|
---|
426 | }
|
---|
427 |
|
---|
428 | static int vbvaFlush (PVGASTATE pVGAState, VBVACONTEXT *pCtx)
|
---|
429 | {
|
---|
430 | unsigned uScreenId;
|
---|
431 |
|
---|
432 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
433 | {
|
---|
434 | VBVAPARTIALRECORD *pPartialRecord = &pCtx->aViews[uScreenId].partialRecord;
|
---|
435 | VBVABUFFER *pVBVA = pCtx->aViews[uScreenId].pVBVA;
|
---|
436 |
|
---|
437 | if (pVBVA)
|
---|
438 | {
|
---|
439 | vbvaFlushProcess (uScreenId, pVGAState, pPartialRecord, pVBVA);
|
---|
440 | }
|
---|
441 | }
|
---|
442 |
|
---|
443 | /* @todo rc */
|
---|
444 | return VINF_SUCCESS;
|
---|
445 | }
|
---|
446 |
|
---|
447 | static int vbvaResize (PVGASTATE pVGAState, VBVAVIEW *pView, const VBVAINFOSCREEN *pNewScreen)
|
---|
448 | {
|
---|
449 | /* Verify pNewScreen. */
|
---|
450 | /* @todo */
|
---|
451 |
|
---|
452 | /* Apply these changes. */
|
---|
453 | pView->screen = *pNewScreen;
|
---|
454 |
|
---|
455 | uint8_t *pu8VRAM = pVGAState->vram_ptrR3 + pView->view.u32ViewOffset;
|
---|
456 |
|
---|
457 | int rc = pVGAState->pDrv->pfnVBVAResize (pVGAState->pDrv, &pView->view, &pView->screen, pu8VRAM);
|
---|
458 |
|
---|
459 | /* @todo process VINF_VGA_RESIZE_IN_PROGRESS? */
|
---|
460 |
|
---|
461 | return rc;
|
---|
462 | }
|
---|
463 |
|
---|
464 | static int vbvaEnable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx, VBVABUFFER *pVBVA, uint32_t u32Offset)
|
---|
465 | {
|
---|
466 | /* @todo old code did a UpdateDisplayAll at this place. */
|
---|
467 |
|
---|
468 | int rc;
|
---|
469 |
|
---|
470 | if (pVGAState->pDrv->pfnVBVAEnable)
|
---|
471 | {
|
---|
472 | rc = pVGAState->pDrv->pfnVBVAEnable (pVGAState->pDrv, uScreenId);
|
---|
473 | }
|
---|
474 | else
|
---|
475 | {
|
---|
476 | rc = VERR_NOT_SUPPORTED;
|
---|
477 | }
|
---|
478 |
|
---|
479 | if (RT_SUCCESS (rc))
|
---|
480 | {
|
---|
481 | /* Setup flags. */
|
---|
482 | pVBVA->u32HostEvents = VBVA_F_MODE_ENABLED |
|
---|
483 | VBVA_F_MODE_VRDP |
|
---|
484 | VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
|
---|
485 |
|
---|
486 | pVBVA->u32SupportedOrders = ~0;
|
---|
487 |
|
---|
488 | pCtx->aViews[uScreenId].partialRecord.pu8 = NULL;
|
---|
489 | pCtx->aViews[uScreenId].partialRecord.cb = 0;
|
---|
490 |
|
---|
491 | pCtx->aViews[uScreenId].pVBVA = pVBVA;
|
---|
492 | pCtx->aViews[uScreenId].u32VBVAOffset = u32Offset;
|
---|
493 | }
|
---|
494 |
|
---|
495 | return rc;
|
---|
496 | }
|
---|
497 |
|
---|
498 | static int vbvaDisable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx)
|
---|
499 | {
|
---|
500 | /* Process any pending orders and empty the VBVA ring buffer. */
|
---|
501 | vbvaFlush (pVGAState, pCtx);
|
---|
502 |
|
---|
503 | VBVAVIEW *pView = &pCtx->aViews[uScreenId];
|
---|
504 |
|
---|
505 | if (pView->pVBVA)
|
---|
506 | {
|
---|
507 | pView->pVBVA->u32HostEvents = 0;
|
---|
508 | pView->pVBVA->u32SupportedOrders = 0;
|
---|
509 |
|
---|
510 | pView->partialRecord.pu8 = NULL;
|
---|
511 | pView->partialRecord.cb = 0;
|
---|
512 |
|
---|
513 | pView->pVBVA = NULL;
|
---|
514 | pView->u32VBVAOffset = HGSMIOFFSET_VOID;
|
---|
515 | }
|
---|
516 |
|
---|
517 | pVGAState->pDrv->pfnVBVADisable (pVGAState->pDrv, uScreenId);
|
---|
518 | return VINF_SUCCESS;
|
---|
519 | }
|
---|
520 |
|
---|
521 | static int vbvaMousePointerShape (PVGASTATE pVGAState, VBVACONTEXT *pCtx, const VBVAMOUSEPOINTERSHAPE *pShape, HGSMISIZE cbShape)
|
---|
522 | {
|
---|
523 | bool fVisible = (pShape->fu32Flags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
|
---|
524 | bool fAlpha = (pShape->fu32Flags & VBOX_MOUSE_POINTER_ALPHA) != 0;
|
---|
525 | bool fShape = (pShape->fu32Flags & VBOX_MOUSE_POINTER_SHAPE) != 0;
|
---|
526 |
|
---|
527 | HGSMISIZE cbPointerData = 0;
|
---|
528 |
|
---|
529 | if (fShape)
|
---|
530 | {
|
---|
531 | cbPointerData = ((((pShape->u32Width + 7) / 8) * pShape->u32Height + 3) & ~3)
|
---|
532 | + pShape->u32Width * 4 * pShape->u32Height;
|
---|
533 | }
|
---|
534 |
|
---|
535 | if (cbPointerData > cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data))
|
---|
536 | {
|
---|
537 | Log(("vbvaMousePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
|
---|
538 | cbPointerData, cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data)));
|
---|
539 | return VERR_INVALID_PARAMETER;
|
---|
540 | }
|
---|
541 |
|
---|
542 | if (pVGAState->pDrv->pfnVBVAMousePointerShape == NULL)
|
---|
543 | {
|
---|
544 | return VERR_NOT_SUPPORTED;
|
---|
545 | }
|
---|
546 |
|
---|
547 | int rc;
|
---|
548 |
|
---|
549 | if (fShape)
|
---|
550 | {
|
---|
551 | rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
|
---|
552 | fVisible,
|
---|
553 | fAlpha,
|
---|
554 | pShape->u32HotX, pShape->u32HotY,
|
---|
555 | pShape->u32Width, pShape->u32Height,
|
---|
556 | &pShape->au8Data[0]);
|
---|
557 | }
|
---|
558 | else
|
---|
559 | {
|
---|
560 | rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
|
---|
561 | fVisible,
|
---|
562 | false,
|
---|
563 | 0, 0,
|
---|
564 | 0, 0,
|
---|
565 | NULL);
|
---|
566 | }
|
---|
567 |
|
---|
568 | return rc;
|
---|
569 | }
|
---|
570 |
|
---|
571 | static unsigned vbvaViewFromOffset (PHGSMIINSTANCE pIns, VBVACONTEXT *pCtx, const void *pvBuffer)
|
---|
572 | {
|
---|
573 | /* Check which view contains the buffer. */
|
---|
574 | HGSMIOFFSET offBuffer = HGSMIPointerToOffsetHost (pIns, pvBuffer);
|
---|
575 |
|
---|
576 | if (offBuffer != HGSMIOFFSET_VOID)
|
---|
577 | {
|
---|
578 | unsigned uScreenId;
|
---|
579 |
|
---|
580 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
581 | {
|
---|
582 | VBVAINFOVIEW *pView = &pCtx->aViews[uScreenId].view;
|
---|
583 |
|
---|
584 | if ( pView->u32ViewSize > 0
|
---|
585 | && pView->u32ViewOffset <= offBuffer
|
---|
586 | && offBuffer <= pView->u32ViewOffset + pView->u32ViewSize - 1)
|
---|
587 | {
|
---|
588 | return pView->u32ViewIndex;
|
---|
589 | }
|
---|
590 | }
|
---|
591 | }
|
---|
592 |
|
---|
593 | return ~0U;
|
---|
594 | }
|
---|
595 |
|
---|
596 | #ifdef DEBUG_sunlover
|
---|
597 | static void dumpctx(const VBVACONTEXT *pCtx)
|
---|
598 | {
|
---|
599 | Log(("VBVACONTEXT dump: cViews %d\n", pCtx->cViews));
|
---|
600 |
|
---|
601 | uint32_t iView;
|
---|
602 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
603 | {
|
---|
604 | const VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
605 |
|
---|
606 | Log((" view %d o 0x%x s 0x%x m 0x%x\n",
|
---|
607 | pView->view.u32ViewIndex,
|
---|
608 | pView->view.u32ViewOffset,
|
---|
609 | pView->view.u32ViewSize,
|
---|
610 | pView->view.u32MaxScreenSize));
|
---|
611 |
|
---|
612 | Log((" screen %d @%d,%d s 0x%x l 0x%x %dx%d bpp %d f 0x%x\n",
|
---|
613 | pView->screen.u32ViewIndex,
|
---|
614 | pView->screen.i32OriginX,
|
---|
615 | pView->screen.i32OriginY,
|
---|
616 | pView->screen.u32StartOffset,
|
---|
617 | pView->screen.u32LineSize,
|
---|
618 | pView->screen.u32Width,
|
---|
619 | pView->screen.u32Height,
|
---|
620 | pView->screen.u16BitsPerPixel,
|
---|
621 | pView->screen.u16Flags));
|
---|
622 |
|
---|
623 | Log((" VBVA o 0x%x p %p\n",
|
---|
624 | pView->u32VBVAOffset,
|
---|
625 | pView->pVBVA));
|
---|
626 |
|
---|
627 | Log((" PR cb 0x%x p %p\n",
|
---|
628 | pView->partialRecord.cb,
|
---|
629 | pView->partialRecord.pu8));
|
---|
630 | }
|
---|
631 | }
|
---|
632 | #endif /* DEBUG_sunlover */
|
---|
633 |
|
---|
634 | int vboxVBVASaveStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
635 | {
|
---|
636 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
637 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
638 |
|
---|
639 | int rc = HGSMIHostSaveStateExec (pIns, pSSM);
|
---|
640 | if (RT_SUCCESS(rc))
|
---|
641 | {
|
---|
642 | /* Save VBVACONTEXT. */
|
---|
643 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
644 |
|
---|
645 | if (!pCtx)
|
---|
646 | {
|
---|
647 | AssertFailed();
|
---|
648 |
|
---|
649 | /* Still write a valid value to the SSM. */
|
---|
650 | rc = SSMR3PutU32 (pSSM, 0);
|
---|
651 | AssertRCReturn(rc, rc);
|
---|
652 | }
|
---|
653 | else
|
---|
654 | {
|
---|
655 | #ifdef DEBUG_sunlover
|
---|
656 | dumpctx(pCtx);
|
---|
657 | #endif
|
---|
658 |
|
---|
659 | rc = SSMR3PutU32 (pSSM, pCtx->cViews);
|
---|
660 | AssertRCReturn(rc, rc);
|
---|
661 |
|
---|
662 | uint32_t iView;
|
---|
663 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
664 | {
|
---|
665 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
666 |
|
---|
667 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewIndex);
|
---|
668 | AssertRCReturn(rc, rc);
|
---|
669 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewOffset);
|
---|
670 | AssertRCReturn(rc, rc);
|
---|
671 | rc = SSMR3PutU32 (pSSM, pView->view.u32ViewSize);
|
---|
672 | AssertRCReturn(rc, rc);
|
---|
673 | rc = SSMR3PutU32 (pSSM, pView->view.u32MaxScreenSize);
|
---|
674 | AssertRCReturn(rc, rc);
|
---|
675 |
|
---|
676 | rc = SSMR3PutU32 (pSSM, pView->screen.u32ViewIndex);
|
---|
677 | AssertRCReturn(rc, rc);
|
---|
678 | rc = SSMR3PutS32 (pSSM, pView->screen.i32OriginX);
|
---|
679 | AssertRCReturn(rc, rc);
|
---|
680 | rc = SSMR3PutS32 (pSSM, pView->screen.i32OriginY);
|
---|
681 | AssertRCReturn(rc, rc);
|
---|
682 | rc = SSMR3PutU32 (pSSM, pView->screen.u32StartOffset);
|
---|
683 | AssertRCReturn(rc, rc);
|
---|
684 | rc = SSMR3PutU32 (pSSM, pView->screen.u32LineSize);
|
---|
685 | AssertRCReturn(rc, rc);
|
---|
686 | rc = SSMR3PutU32 (pSSM, pView->screen.u32Width);
|
---|
687 | AssertRCReturn(rc, rc);
|
---|
688 | rc = SSMR3PutU32 (pSSM, pView->screen.u32Height);
|
---|
689 | AssertRCReturn(rc, rc);
|
---|
690 | rc = SSMR3PutU16 (pSSM, pView->screen.u16BitsPerPixel);
|
---|
691 | AssertRCReturn(rc, rc);
|
---|
692 | rc = SSMR3PutU16 (pSSM, pView->screen.u16Flags);
|
---|
693 | AssertRCReturn(rc, rc);
|
---|
694 |
|
---|
695 | rc = SSMR3PutU32 (pSSM, pView->pVBVA? pView->u32VBVAOffset: HGSMIOFFSET_VOID);
|
---|
696 | AssertRCReturn(rc, rc);
|
---|
697 |
|
---|
698 | rc = SSMR3PutU32 (pSSM, pView->partialRecord.cb);
|
---|
699 | AssertRCReturn(rc, rc);
|
---|
700 |
|
---|
701 | if (pView->partialRecord.cb > 0)
|
---|
702 | {
|
---|
703 | rc = SSMR3PutMem (pSSM, pView->partialRecord.pu8, pView->partialRecord.cb);
|
---|
704 | AssertRCReturn(rc, rc);
|
---|
705 | }
|
---|
706 | }
|
---|
707 | }
|
---|
708 | }
|
---|
709 |
|
---|
710 | return rc;
|
---|
711 | }
|
---|
712 |
|
---|
713 | int vboxVBVALoadStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
|
---|
714 | {
|
---|
715 | if (u32Version < 3)
|
---|
716 | {
|
---|
717 | /* Nothing was saved. */
|
---|
718 | return VINF_SUCCESS;
|
---|
719 | }
|
---|
720 |
|
---|
721 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
722 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
723 | int rc = HGSMIHostLoadStateExec (pIns, pSSM, u32Version);
|
---|
724 | if (RT_SUCCESS(rc))
|
---|
725 | {
|
---|
726 | /* Load VBVACONTEXT. */
|
---|
727 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
728 |
|
---|
729 | if (!pCtx)
|
---|
730 | {
|
---|
731 | /* This should not happen. */
|
---|
732 | AssertFailed();
|
---|
733 | rc = VERR_INVALID_PARAMETER;
|
---|
734 | }
|
---|
735 | else
|
---|
736 | {
|
---|
737 | uint32_t cViews = 0;
|
---|
738 | rc = SSMR3GetU32 (pSSM, &cViews);
|
---|
739 | AssertRCReturn(rc, rc);
|
---|
740 |
|
---|
741 | uint32_t iView;
|
---|
742 | for (iView = 0; iView < cViews; iView++)
|
---|
743 | {
|
---|
744 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
745 |
|
---|
746 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewIndex);
|
---|
747 | AssertRCReturn(rc, rc);
|
---|
748 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewOffset);
|
---|
749 | AssertRCReturn(rc, rc);
|
---|
750 | rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewSize);
|
---|
751 | AssertRCReturn(rc, rc);
|
---|
752 | rc = SSMR3GetU32 (pSSM, &pView->view.u32MaxScreenSize);
|
---|
753 | AssertRCReturn(rc, rc);
|
---|
754 |
|
---|
755 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32ViewIndex);
|
---|
756 | AssertRCReturn(rc, rc);
|
---|
757 | rc = SSMR3GetS32 (pSSM, &pView->screen.i32OriginX);
|
---|
758 | AssertRCReturn(rc, rc);
|
---|
759 | rc = SSMR3GetS32 (pSSM, &pView->screen.i32OriginY);
|
---|
760 | AssertRCReturn(rc, rc);
|
---|
761 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32StartOffset);
|
---|
762 | AssertRCReturn(rc, rc);
|
---|
763 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32LineSize);
|
---|
764 | AssertRCReturn(rc, rc);
|
---|
765 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32Width);
|
---|
766 | AssertRCReturn(rc, rc);
|
---|
767 | rc = SSMR3GetU32 (pSSM, &pView->screen.u32Height);
|
---|
768 | AssertRCReturn(rc, rc);
|
---|
769 | rc = SSMR3GetU16 (pSSM, &pView->screen.u16BitsPerPixel);
|
---|
770 | AssertRCReturn(rc, rc);
|
---|
771 | rc = SSMR3GetU16 (pSSM, &pView->screen.u16Flags);
|
---|
772 | AssertRCReturn(rc, rc);
|
---|
773 |
|
---|
774 | rc = SSMR3GetU32 (pSSM, &pView->u32VBVAOffset);
|
---|
775 | AssertRCReturn(rc, rc);
|
---|
776 |
|
---|
777 | rc = SSMR3GetU32 (pSSM, &pView->partialRecord.cb);
|
---|
778 | AssertRCReturn(rc, rc);
|
---|
779 |
|
---|
780 | if (pView->partialRecord.cb == 0)
|
---|
781 | {
|
---|
782 | pView->partialRecord.pu8 = NULL;
|
---|
783 | }
|
---|
784 | else
|
---|
785 | {
|
---|
786 | Assert(pView->partialRecord.pu8 == NULL); /* Should be it. */
|
---|
787 |
|
---|
788 | uint8_t *pu8 = (uint8_t *)RTMemAlloc (pView->partialRecord.cb);
|
---|
789 |
|
---|
790 | if (!pu8)
|
---|
791 | {
|
---|
792 | return VERR_NO_MEMORY;
|
---|
793 | }
|
---|
794 |
|
---|
795 | pView->partialRecord.pu8 = pu8;
|
---|
796 |
|
---|
797 | rc = SSMR3GetMem (pSSM, pView->partialRecord.pu8, pView->partialRecord.cb);
|
---|
798 | AssertRCReturn(rc, rc);
|
---|
799 | }
|
---|
800 |
|
---|
801 | if ( pView->u32VBVAOffset == HGSMIOFFSET_VOID
|
---|
802 | || pView->screen.u32LineSize == 0) /* Earlier broken saved states. */
|
---|
803 | {
|
---|
804 | pView->pVBVA = NULL;
|
---|
805 | }
|
---|
806 | else
|
---|
807 | {
|
---|
808 | pView->pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, pView->u32VBVAOffset);
|
---|
809 | }
|
---|
810 | }
|
---|
811 |
|
---|
812 | pCtx->cViews = iView;
|
---|
813 | LogFlowFunc(("%d views loaded\n", pCtx->cViews));
|
---|
814 |
|
---|
815 | #ifdef DEBUG_sunlover
|
---|
816 | dumpctx(pCtx);
|
---|
817 | #endif
|
---|
818 | }
|
---|
819 | }
|
---|
820 |
|
---|
821 | return rc;
|
---|
822 | }
|
---|
823 |
|
---|
824 | int vboxVBVALoadStateDone (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
825 | {
|
---|
826 | PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
|
---|
827 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
828 |
|
---|
829 | if (pCtx)
|
---|
830 | {
|
---|
831 | uint32_t iView;
|
---|
832 | for (iView = 0; iView < pCtx->cViews; iView++)
|
---|
833 | {
|
---|
834 | VBVAVIEW *pView = &pCtx->aViews[iView];
|
---|
835 |
|
---|
836 | if (pView->pVBVA)
|
---|
837 | {
|
---|
838 | vbvaEnable (iView, pVGAState, pCtx, pView->pVBVA, pView->u32VBVAOffset);
|
---|
839 | vbvaResize (pVGAState, pView, &pView->screen);
|
---|
840 | }
|
---|
841 | }
|
---|
842 | }
|
---|
843 |
|
---|
844 | return VINF_SUCCESS;
|
---|
845 | }
|
---|
846 |
|
---|
847 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
848 | static VBOXVHWACMD* vbvaVHWAHHCommandCreate (PVGASTATE pVGAState, VBOXVHWACMD_TYPE enmCmd, VBOXVHWACMD_LENGTH cbCmd)
|
---|
849 | {
|
---|
850 | VBOXVHWACMD* pHdr = (VBOXVHWACMD*)RTMemAlloc(cbCmd + VBOXVHWACMD_HEADSIZE());
|
---|
851 | Assert(pHdr);
|
---|
852 | if (pHdr)
|
---|
853 | {
|
---|
854 | memset(pHdr, 0, VBOXVHWACMD_HEADSIZE());
|
---|
855 | pHdr->cRefs = 1;
|
---|
856 | pHdr->rc = VERR_GENERAL_FAILURE;
|
---|
857 | pHdr->enmCmd = enmCmd;
|
---|
858 | pHdr->Flags = VBOXVHWACMD_FLAG_HH_CMD;
|
---|
859 | }
|
---|
860 |
|
---|
861 | return pHdr;
|
---|
862 | }
|
---|
863 |
|
---|
864 | DECLINLINE(void) vbvaVHWAHHCommandRelease (VBOXVHWACMD* pCmd)
|
---|
865 | {
|
---|
866 | uint32_t cRefs = ASMAtomicDecU32(&pCmd->cRefs);
|
---|
867 | if(!cRefs)
|
---|
868 | {
|
---|
869 | RTMemFree(pCmd);
|
---|
870 | }
|
---|
871 | }
|
---|
872 |
|
---|
873 | DECLINLINE(void) vbvaVHWAHHCommandRetain (VBOXVHWACMD* pCmd)
|
---|
874 | {
|
---|
875 | ASMAtomicIncU32(&pCmd->cRefs);
|
---|
876 | }
|
---|
877 |
|
---|
878 | static unsigned vbvaVHWAHandleCommand (PVGASTATE pVGAState, VBVACONTEXT *pCtx, PVBOXVHWACMD pCmd)
|
---|
879 | {
|
---|
880 | pVGAState->pDrv->pfnVHWACommandProcess(pVGAState->pDrv, pCmd);
|
---|
881 | return 0;
|
---|
882 | }
|
---|
883 |
|
---|
884 | static int vbvaVHWAHHCommandPost(PVGASTATE pVGAState, VBOXVHWACMD* pCmd)
|
---|
885 | {
|
---|
886 | RTSEMEVENT hComplEvent;
|
---|
887 | int rc = RTSemEventCreate(&hComplEvent);
|
---|
888 | AssertRC(rc);
|
---|
889 | if(RT_SUCCESS(rc))
|
---|
890 | {
|
---|
891 | /* ensure the cmd is not deleted until we process it */
|
---|
892 | vbvaVHWAHHCommandRetain (pCmd);
|
---|
893 | pCmd->GuestVBVAReserved1 = (uint64_t)hComplEvent;
|
---|
894 | vbvaVHWAHandleCommand(pVGAState, NULL, pCmd);
|
---|
895 | if((ASMAtomicReadU32((volatile uint32_t *)&pCmd->Flags) & VBOXVHWACMD_FLAG_HG_ASYNCH) != 0)
|
---|
896 | {
|
---|
897 | rc = RTSemEventWaitNoResume(hComplEvent, RT_INDEFINITE_WAIT);
|
---|
898 | }
|
---|
899 | else
|
---|
900 | {
|
---|
901 | /* the command is completed */
|
---|
902 | }
|
---|
903 |
|
---|
904 | AssertRC(rc);
|
---|
905 | if(RT_SUCCESS(rc))
|
---|
906 | {
|
---|
907 | RTSemEventDestroy(hComplEvent);
|
---|
908 | }
|
---|
909 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
910 | }
|
---|
911 | return rc;
|
---|
912 | }
|
---|
913 |
|
---|
914 | int vbvaVHWAConstruct (PVGASTATE pVGAState)
|
---|
915 | {
|
---|
916 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_CONSTRUCT, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
|
---|
917 | Assert(pCmd);
|
---|
918 | if(pCmd)
|
---|
919 | {
|
---|
920 | VBOXVHWACMD_HH_CONSTRUCT * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_CONSTRUCT);
|
---|
921 | memset(pBody, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
|
---|
922 |
|
---|
923 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
924 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
925 |
|
---|
926 | pBody->pVM = pVM;
|
---|
927 |
|
---|
928 | int rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
929 | AssertRC(rc);
|
---|
930 | if(RT_SUCCESS(rc))
|
---|
931 | {
|
---|
932 | rc = pCmd->rc;
|
---|
933 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
934 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
935 | if(rc == VERR_NOT_IMPLEMENTED)
|
---|
936 | {
|
---|
937 | /* @todo: set some flag in pVGAState indicating VHWA is not supported */
|
---|
938 | /* VERR_NOT_IMPLEMENTED is not a failure, we just do not support it */
|
---|
939 | rc = VINF_SUCCESS;
|
---|
940 | }
|
---|
941 | }
|
---|
942 | return rc;
|
---|
943 | }
|
---|
944 | return VERR_OUT_OF_RESOURCES;
|
---|
945 | }
|
---|
946 |
|
---|
947 | int vbvaVHWAReset (PVGASTATE pVGAState)
|
---|
948 | {
|
---|
949 | /* ensure we have all pending cmds processed and h->g cmds disabled */
|
---|
950 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_RESET, 0);
|
---|
951 | Assert(pCmd);
|
---|
952 | if(pCmd)
|
---|
953 | {
|
---|
954 | int rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
955 | AssertRC(rc);
|
---|
956 | if(RT_SUCCESS(rc))
|
---|
957 | {
|
---|
958 | rc = pCmd->rc;
|
---|
959 | #ifndef DEBUG_misha /** @todo the assertion below hits when booting dsl here and resetting during early boot... */
|
---|
960 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
961 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
962 | rc = VINF_SUCCESS;
|
---|
963 | #else
|
---|
964 | AssertRC(rc);
|
---|
965 | #endif
|
---|
966 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
967 | }
|
---|
968 | return rc;
|
---|
969 | }
|
---|
970 | return VERR_OUT_OF_RESOURCES;
|
---|
971 | }
|
---|
972 |
|
---|
973 | /* @todo call this also on reset? */
|
---|
974 | int vbvaVHWADisable (PVGASTATE pVGAState)
|
---|
975 | {
|
---|
976 | VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_DISABLE, 0);
|
---|
977 | Assert(pCmd);
|
---|
978 | if(pCmd)
|
---|
979 | {
|
---|
980 | int rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
|
---|
981 | AssertRC(rc);
|
---|
982 | if(RT_SUCCESS(rc))
|
---|
983 | {
|
---|
984 | rc = pCmd->rc;
|
---|
985 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
|
---|
986 | vbvaVHWAHHCommandRelease(pCmd);
|
---|
987 | if(rc == VERR_NOT_IMPLEMENTED)
|
---|
988 | {
|
---|
989 | rc = VINF_SUCCESS;
|
---|
990 | }
|
---|
991 | }
|
---|
992 | return rc;
|
---|
993 | }
|
---|
994 | return VERR_OUT_OF_RESOURCES;
|
---|
995 | }
|
---|
996 |
|
---|
997 | int vboxVBVASaveStatePrep (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
998 | {
|
---|
999 | /* ensure we have no pending commands */
|
---|
1000 | return vbvaVHWADisable(PDMINS_2_DATA(pDevIns, PVGASTATE));
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | #define PPDMDDISPLAYVBVACALLBACKS_2_PVGASTATE(_pcb) ( (PVGASTATE)((uint8_t *)(_pcb) - RT_OFFSETOF(VGASTATE, VBVACallbacks)) )
|
---|
1004 |
|
---|
1005 | int vbvaVHWACommandCompleteAsynch(PPDMDDISPLAYVBVACALLBACKS pInterface, PVBOXVHWACMD pCmd)
|
---|
1006 | {
|
---|
1007 | int rc;
|
---|
1008 | if((pCmd->Flags & VBOXVHWACMD_FLAG_HH_CMD) == 0)
|
---|
1009 | {
|
---|
1010 | PVGASTATE pVGAState = PPDMDDISPLAYVBVACALLBACKS_2_PVGASTATE(pInterface);
|
---|
1011 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1012 | VBVAHOSTCMD *pHostCmd;
|
---|
1013 | // Assert(0);
|
---|
1014 |
|
---|
1015 | int32_t iDisplay = pCmd->iDisplay;
|
---|
1016 | Assert(pCmd->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH);
|
---|
1017 | if(pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_EVENT)
|
---|
1018 | {
|
---|
1019 | rc = HGSMIHostCommandAlloc (pIns,
|
---|
1020 | (void**)&pHostCmd,
|
---|
1021 | VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDEVENT)),
|
---|
1022 | HGSMI_CH_VBVA,
|
---|
1023 | VBVAHG_EVENT);
|
---|
1024 | AssertRC(rc);
|
---|
1025 | if(RT_SUCCESS(rc))
|
---|
1026 | {
|
---|
1027 | memset(pHostCmd, 0 , VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDEVENT)));
|
---|
1028 | pHostCmd->iDstID = pCmd->iDisplay;
|
---|
1029 | pHostCmd->customOpCode = 0;
|
---|
1030 | VBVAHOSTCMDEVENT *pBody = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDEVENT);
|
---|
1031 | pBody->pEvent = pCmd->GuestVBVAReserved1;
|
---|
1032 | }
|
---|
1033 | }
|
---|
1034 | else
|
---|
1035 | {
|
---|
1036 | HGSMIOFFSET offCmd = HGSMIPointerToOffsetHost (pIns, pCmd);
|
---|
1037 | Assert(offCmd != HGSMIOFFSET_VOID);
|
---|
1038 | if(offCmd != HGSMIOFFSET_VOID)
|
---|
1039 | {
|
---|
1040 | rc = HGSMIHostCommandAlloc (pIns,
|
---|
1041 | (void**)&pHostCmd,
|
---|
1042 | VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDVHWACMDCOMPLETE)),
|
---|
1043 | HGSMI_CH_VBVA,
|
---|
1044 | VBVAHG_DISPLAY_CUSTOM);
|
---|
1045 | AssertRC(rc);
|
---|
1046 | if(RT_SUCCESS(rc))
|
---|
1047 | {
|
---|
1048 | memset(pHostCmd, 0 , VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDVHWACMDCOMPLETE)));
|
---|
1049 | pHostCmd->iDstID = pCmd->iDisplay;
|
---|
1050 | pHostCmd->customOpCode = VBVAHG_DCUSTOM_VHWA_CMDCOMPLETE;
|
---|
1051 | VBVAHOSTCMDVHWACMDCOMPLETE *pBody = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDVHWACMDCOMPLETE);
|
---|
1052 | pBody->offCmd = offCmd;
|
---|
1053 | }
|
---|
1054 | }
|
---|
1055 | else
|
---|
1056 | {
|
---|
1057 | rc = VERR_INVALID_PARAMETER;
|
---|
1058 | }
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | if(RT_SUCCESS(rc))
|
---|
1062 | {
|
---|
1063 | rc = HGSMIHostCommandProcessAndFreeAsynch(pIns, pHostCmd, (pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ) != 0);
|
---|
1064 | AssertRC(rc);
|
---|
1065 | if(RT_SUCCESS(rc))
|
---|
1066 | {
|
---|
1067 | return rc;
|
---|
1068 | }
|
---|
1069 | HGSMIHostCommandFree (pIns, pHostCmd);
|
---|
1070 | }
|
---|
1071 | }
|
---|
1072 | else
|
---|
1073 | {
|
---|
1074 | if(pCmd->GuestVBVAReserved1)
|
---|
1075 | {
|
---|
1076 | RTSEMEVENT hComplEvent = (RTSEMEVENT)pCmd->GuestVBVAReserved1;
|
---|
1077 | RTSemEventSignal(hComplEvent);
|
---|
1078 | }
|
---|
1079 | rc = VINF_SUCCESS;
|
---|
1080 | }
|
---|
1081 | return rc;
|
---|
1082 | }
|
---|
1083 | #endif
|
---|
1084 |
|
---|
1085 |
|
---|
1086 | /*
|
---|
1087 | *
|
---|
1088 | * New VBVA uses a new interface id: #define VBE_DISPI_ID_VBOX_VIDEO 0xBE01
|
---|
1089 | *
|
---|
1090 | * VBVA uses two 32 bits IO ports to write VRAM offsets of shared memory blocks for commands.
|
---|
1091 | * Read Write
|
---|
1092 | * Host port 0x3b0 to process completed
|
---|
1093 | * Guest port 0x3d0 control value? to process
|
---|
1094 | *
|
---|
1095 | */
|
---|
1096 |
|
---|
1097 | static DECLCALLBACK(void) vbvaNotifyGuest (void *pvCallback)
|
---|
1098 | {
|
---|
1099 | #if defined(VBOX_WITH_HGSMI) && defined(VBOX_WITH_VIDEOHWACCEL)
|
---|
1100 | PVGASTATE pVGAState = (PVGASTATE)pvCallback;
|
---|
1101 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
1102 | PDMCritSectEnter(&pVGAState->lock, VERR_SEM_BUSY);
|
---|
1103 | HGSMISetHostGuestFlags(pVGAState->pHGSMI, HGSMIHOSTFLAGS_IRQ);
|
---|
1104 | PDMDevHlpPCISetIrq(pDevIns, 0, PDM_IRQ_LEVEL_HIGH);
|
---|
1105 | PDMCritSectLeave(&pVGAState->lock);
|
---|
1106 | #else
|
---|
1107 | NOREF(pvCallback);
|
---|
1108 | /* Do nothing. Later the VMMDev/VGA IRQ can be used for the notification. */
|
---|
1109 | #endif
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | /* The guest submitted a buffer. @todo Verify all guest data. */
|
---|
1113 | static DECLCALLBACK(int) vbvaChannelHandler (void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer)
|
---|
1114 | {
|
---|
1115 | int rc = VINF_SUCCESS;
|
---|
1116 |
|
---|
1117 | LogFlowFunc(("pvHandler %p, u16ChannelInfo %d, pvBuffer %p, cbBuffer %u\n",
|
---|
1118 | pvHandler, u16ChannelInfo, pvBuffer, cbBuffer));
|
---|
1119 |
|
---|
1120 | PVGASTATE pVGAState = (PVGASTATE)pvHandler;
|
---|
1121 | PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
|
---|
1122 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
|
---|
1123 |
|
---|
1124 | switch (u16ChannelInfo)
|
---|
1125 | {
|
---|
1126 | case VBVA_QUERY_CONF32:
|
---|
1127 | {
|
---|
1128 | if (cbBuffer < sizeof (VBVACONF32))
|
---|
1129 | {
|
---|
1130 | rc = VERR_INVALID_PARAMETER;
|
---|
1131 | break;
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
|
---|
1135 | LogFlowFunc(("VBVA_QUERY_CONF32: u32Index %d, u32Value 0x%x\n",
|
---|
1136 | pConf32->u32Index, pConf32->u32Value));
|
---|
1137 |
|
---|
1138 | if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
|
---|
1139 | {
|
---|
1140 | pConf32->u32Value = pCtx->cViews;
|
---|
1141 | }
|
---|
1142 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
|
---|
1143 | {
|
---|
1144 | /* @todo a value caclucated from the vram size */
|
---|
1145 | pConf32->u32Value = 64*_1K;
|
---|
1146 | }
|
---|
1147 | else
|
---|
1148 | {
|
---|
1149 | Log(("Unsupported VBVA_QUERY_CONF32 index %d!!!\n",
|
---|
1150 | pConf32->u32Index));
|
---|
1151 | rc = VERR_INVALID_PARAMETER;
|
---|
1152 | }
|
---|
1153 | } break;
|
---|
1154 |
|
---|
1155 | case VBVA_SET_CONF32:
|
---|
1156 | {
|
---|
1157 | if (cbBuffer < sizeof (VBVACONF32))
|
---|
1158 | {
|
---|
1159 | rc = VERR_INVALID_PARAMETER;
|
---|
1160 | break;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
|
---|
1164 | LogFlowFunc(("VBVA_SET_CONF32: u32Index %d, u32Value 0x%x\n",
|
---|
1165 | pConf32->u32Index, pConf32->u32Value));
|
---|
1166 |
|
---|
1167 | if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
|
---|
1168 | {
|
---|
1169 | /* do nothing. this is a const. */
|
---|
1170 | }
|
---|
1171 | else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
|
---|
1172 | {
|
---|
1173 | /* do nothing. this is a const. */
|
---|
1174 | }
|
---|
1175 | else
|
---|
1176 | {
|
---|
1177 | Log(("Unsupported VBVA_SET_CONF32 index %d!!!\n",
|
---|
1178 | pConf32->u32Index));
|
---|
1179 | rc = VERR_INVALID_PARAMETER;
|
---|
1180 | }
|
---|
1181 | } break;
|
---|
1182 |
|
---|
1183 | case VBVA_INFO_VIEW:
|
---|
1184 | {
|
---|
1185 | if (cbBuffer < sizeof (VBVAINFOVIEW))
|
---|
1186 | {
|
---|
1187 | rc = VERR_INVALID_PARAMETER;
|
---|
1188 | break;
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | /* Guest submits an array of VBVAINFOVIEW structures. */
|
---|
1192 | VBVAINFOVIEW *pView = (VBVAINFOVIEW *)pvBuffer;
|
---|
1193 |
|
---|
1194 | for (;
|
---|
1195 | cbBuffer >= sizeof (VBVAINFOVIEW);
|
---|
1196 | pView++, cbBuffer -= sizeof (VBVAINFOVIEW))
|
---|
1197 | {
|
---|
1198 | LogFlowFunc(("VBVA_INFO_VIEW: index %d, offset 0x%x, size 0x%x, max screen size 0x%x\n",
|
---|
1199 | pView->u32ViewIndex, pView->u32ViewOffset, pView->u32ViewSize, pView->u32MaxScreenSize));
|
---|
1200 |
|
---|
1201 | /* @todo verify view data. */
|
---|
1202 | if (pView->u32ViewIndex >= pCtx->cViews)
|
---|
1203 | {
|
---|
1204 | Log(("View index too large %d!!!\n",
|
---|
1205 | pView->u32ViewIndex));
|
---|
1206 | rc = VERR_INVALID_PARAMETER;
|
---|
1207 | break;
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | pCtx->aViews[pView->u32ViewIndex].view = *pView;
|
---|
1211 | }
|
---|
1212 | } break;
|
---|
1213 |
|
---|
1214 | case VBVA_INFO_HEAP:
|
---|
1215 | {
|
---|
1216 | if (cbBuffer < sizeof (VBVAINFOHEAP))
|
---|
1217 | {
|
---|
1218 | rc = VERR_INVALID_PARAMETER;
|
---|
1219 | break;
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | VBVAINFOHEAP *pHeap = (VBVAINFOHEAP *)pvBuffer;
|
---|
1223 | LogFlowFunc(("VBVA_INFO_HEAP: offset 0x%x, size 0x%x\n",
|
---|
1224 | pHeap->u32HeapOffset, pHeap->u32HeapSize));
|
---|
1225 |
|
---|
1226 | rc = HGSMISetupHostHeap (pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
|
---|
1227 | } break;
|
---|
1228 |
|
---|
1229 | case VBVA_FLUSH:
|
---|
1230 | {
|
---|
1231 | if (cbBuffer < sizeof (VBVAFLUSH))
|
---|
1232 | {
|
---|
1233 | rc = VERR_INVALID_PARAMETER;
|
---|
1234 | break;
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | VBVAFLUSH *pFlush = (VBVAFLUSH *)pvBuffer;
|
---|
1238 | LogFlowFunc(("VBVA_FLUSH: u32Reserved 0x%x\n",
|
---|
1239 | pFlush->u32Reserved));
|
---|
1240 |
|
---|
1241 | rc = vbvaFlush (pVGAState, pCtx);
|
---|
1242 | } break;
|
---|
1243 |
|
---|
1244 | case VBVA_INFO_SCREEN:
|
---|
1245 | {
|
---|
1246 | if (cbBuffer < sizeof (VBVAINFOSCREEN))
|
---|
1247 | {
|
---|
1248 | rc = VERR_INVALID_PARAMETER;
|
---|
1249 | break;
|
---|
1250 | }
|
---|
1251 |
|
---|
1252 | VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)pvBuffer;
|
---|
1253 | LogFlowFunc(("VBVA_INFO_SCREEN: [%d] @%d,%d %dx%d, line 0x%x, BPP %d, flags 0x%x\n",
|
---|
1254 | pScreen->u32ViewIndex, pScreen->i32OriginX, pScreen->i32OriginY,
|
---|
1255 | pScreen->u32Width, pScreen->u32Height,
|
---|
1256 | pScreen->u32LineSize, pScreen->u16BitsPerPixel, pScreen->u16Flags));
|
---|
1257 |
|
---|
1258 | if (pScreen->u32ViewIndex < RT_ELEMENTS (pCtx->aViews))
|
---|
1259 | {
|
---|
1260 | vbvaResize (pVGAState, &pCtx->aViews[pScreen->u32ViewIndex], pScreen);
|
---|
1261 | }
|
---|
1262 | else
|
---|
1263 | {
|
---|
1264 | Log(("View index too large %d!!!\n",
|
---|
1265 | pScreen->u32ViewIndex));
|
---|
1266 | rc = VERR_INVALID_PARAMETER;
|
---|
1267 | }
|
---|
1268 | } break;
|
---|
1269 |
|
---|
1270 | case VBVA_ENABLE:
|
---|
1271 | {
|
---|
1272 | if (cbBuffer < sizeof (VBVAENABLE))
|
---|
1273 | {
|
---|
1274 | rc = VERR_INVALID_PARAMETER;
|
---|
1275 | break;
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | unsigned uScreenId = vbvaViewFromOffset (pIns, pCtx, pvBuffer);
|
---|
1279 |
|
---|
1280 | if (uScreenId == ~0U)
|
---|
1281 | {
|
---|
1282 | rc = VERR_INVALID_PARAMETER;
|
---|
1283 | break;
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | VBVAENABLE *pEnable = (VBVAENABLE *)pvBuffer;
|
---|
1287 | LogFlowFunc(("VBVA_ENABLE[%d]: u32Flags 0x%x u32Offset 0x%x\n",
|
---|
1288 | uScreenId, pEnable->u32Flags, pEnable->u32Offset));
|
---|
1289 |
|
---|
1290 | if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_ENABLE)
|
---|
1291 | {
|
---|
1292 | /* Guest reported offset relative to view. */
|
---|
1293 | uint32_t u32Offset = pEnable->u32Offset + pCtx->aViews[uScreenId].view.u32ViewOffset;
|
---|
1294 |
|
---|
1295 | VBVABUFFER *pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, u32Offset);
|
---|
1296 |
|
---|
1297 | if (pVBVA)
|
---|
1298 | {
|
---|
1299 | /* Process any pending orders and empty the VBVA ring buffer. */
|
---|
1300 | vbvaFlush (pVGAState, pCtx);
|
---|
1301 |
|
---|
1302 | rc = vbvaEnable (uScreenId, pVGAState, pCtx, pVBVA, u32Offset);
|
---|
1303 | }
|
---|
1304 | else
|
---|
1305 | {
|
---|
1306 | Log(("Invalid VBVABUFFER offset 0x%x!!!\n",
|
---|
1307 | pEnable->u32Offset));
|
---|
1308 | rc = VERR_INVALID_PARAMETER;
|
---|
1309 | }
|
---|
1310 | }
|
---|
1311 | else if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_DISABLE)
|
---|
1312 | {
|
---|
1313 | rc = vbvaDisable (uScreenId, pVGAState, pCtx);
|
---|
1314 | }
|
---|
1315 | else
|
---|
1316 | {
|
---|
1317 | Log(("Invalid VBVA_ENABLE flags 0x%x!!!\n",
|
---|
1318 | pEnable->u32Flags));
|
---|
1319 | rc = VERR_INVALID_PARAMETER;
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | pEnable->i32Result = rc;
|
---|
1323 | } break;
|
---|
1324 |
|
---|
1325 | case VBVA_MOUSE_POINTER_SHAPE:
|
---|
1326 | {
|
---|
1327 | if (cbBuffer < sizeof (VBVAMOUSEPOINTERSHAPE))
|
---|
1328 | {
|
---|
1329 | rc = VERR_INVALID_PARAMETER;
|
---|
1330 | break;
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | VBVAMOUSEPOINTERSHAPE *pShape = (VBVAMOUSEPOINTERSHAPE *)pvBuffer;
|
---|
1334 |
|
---|
1335 | LogFlowFunc(("VBVA_MOUSE_POINTER_SHAPE: i32Result 0x%x, fu32Flags 0x%x, hot spot %d,%d, size %dx%d\n",
|
---|
1336 | pShape->i32Result,
|
---|
1337 | pShape->fu32Flags,
|
---|
1338 | pShape->u32HotX,
|
---|
1339 | pShape->u32HotY,
|
---|
1340 | pShape->u32Width,
|
---|
1341 | pShape->u32Height));
|
---|
1342 |
|
---|
1343 | rc = vbvaMousePointerShape (pVGAState, pCtx, pShape, cbBuffer);
|
---|
1344 |
|
---|
1345 | pShape->i32Result = rc;
|
---|
1346 | } break;
|
---|
1347 |
|
---|
1348 |
|
---|
1349 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1350 | case VBVA_VHWA_CMD:
|
---|
1351 | {
|
---|
1352 | rc = vbvaVHWAHandleCommand (pVGAState, pCtx, (PVBOXVHWACMD)pvBuffer);
|
---|
1353 | } break;
|
---|
1354 | #endif
|
---|
1355 |
|
---|
1356 | default:
|
---|
1357 | Log(("Unsupported VBVA guest command %d!!!\n",
|
---|
1358 | u16ChannelInfo));
|
---|
1359 | break;
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | return rc;
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | void VBVAReset (PVGASTATE pVGAState)
|
---|
1366 | {
|
---|
1367 | if (!pVGAState || !pVGAState->pHGSMI)
|
---|
1368 | {
|
---|
1369 | return;
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
1373 |
|
---|
1374 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1375 | vbvaVHWAReset (pVGAState);
|
---|
1376 | #endif
|
---|
1377 |
|
---|
1378 | HGSMIReset (pVGAState->pHGSMI);
|
---|
1379 |
|
---|
1380 | if (pCtx)
|
---|
1381 | {
|
---|
1382 | vbvaFlush (pVGAState, pCtx);
|
---|
1383 |
|
---|
1384 | unsigned uScreenId;
|
---|
1385 |
|
---|
1386 | for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
|
---|
1387 | {
|
---|
1388 | vbvaDisable (uScreenId, pVGAState, pCtx);
|
---|
1389 | }
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 | }
|
---|
1393 |
|
---|
1394 | int VBVAUpdateDisplay (PVGASTATE pVGAState)
|
---|
1395 | {
|
---|
1396 | int rc = VERR_NOT_SUPPORTED; /* Assuming that the VGA device will have to do updates. */
|
---|
1397 |
|
---|
1398 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
1399 |
|
---|
1400 | if (pCtx)
|
---|
1401 | {
|
---|
1402 | rc = vbvaFlush (pVGAState, pCtx);
|
---|
1403 |
|
---|
1404 | if (RT_SUCCESS (rc))
|
---|
1405 | {
|
---|
1406 | if (!pCtx->aViews[0].pVBVA)
|
---|
1407 | {
|
---|
1408 | /* VBVA is not enabled for the first view, so VGA device must do updates. */
|
---|
1409 | rc = VERR_NOT_SUPPORTED;
|
---|
1410 | }
|
---|
1411 | }
|
---|
1412 | }
|
---|
1413 |
|
---|
1414 | return rc;
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | static HGSMICHANNELHANDLER sOldChannelHandler;
|
---|
1418 |
|
---|
1419 | int VBVAInit (PVGASTATE pVGAState)
|
---|
1420 | {
|
---|
1421 | PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
|
---|
1422 |
|
---|
1423 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
1424 |
|
---|
1425 | int rc = HGSMICreate (&pVGAState->pHGSMI,
|
---|
1426 | pVM,
|
---|
1427 | "VBVA",
|
---|
1428 | 0,
|
---|
1429 | pVGAState->vram_ptrR3,
|
---|
1430 | pVGAState->vram_size,
|
---|
1431 | vbvaNotifyGuest,
|
---|
1432 | pVGAState,
|
---|
1433 | sizeof (VBVACONTEXT));
|
---|
1434 |
|
---|
1435 | if (RT_SUCCESS (rc))
|
---|
1436 | {
|
---|
1437 | rc = HGSMIHostChannelRegister (pVGAState->pHGSMI,
|
---|
1438 | HGSMI_CH_VBVA,
|
---|
1439 | vbvaChannelHandler,
|
---|
1440 | pVGAState,
|
---|
1441 | &sOldChannelHandler);
|
---|
1442 | if (RT_SUCCESS (rc))
|
---|
1443 | {
|
---|
1444 | VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
|
---|
1445 | pCtx->cViews = pVGAState->cMonitors;
|
---|
1446 | }
|
---|
1447 | }
|
---|
1448 |
|
---|
1449 | return rc;
|
---|
1450 |
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | void VBVADestroy (PVGASTATE pVGAState)
|
---|
1454 | {
|
---|
1455 | HGSMIDestroy (pVGAState->pHGSMI);
|
---|
1456 | pVGAState->pHGSMI = NULL;
|
---|
1457 | }
|
---|