DevVGA_VBVA.cpp revision e8d309b9da17d55dbaf8de632612470b4f16d926
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/*
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * VirtualBox Video Acceleration (VBVA).
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/*
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * available from http://www.virtualbox.org. This file is free software;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * you can redistribute it and/or modify it under the terms of the GNU
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * General Public License (GPL) as published by the Free Software
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * additional information or have any questions.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#define LOG_GROUP LOG_GROUP_DEV_VGA
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/pdmifs.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/pdmdev.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/pgm.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/ssm.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/VMMDev.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/VBoxVideo.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <iprt/alloc.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <iprt/assert.h>
c8bcebedf264bc1287bcce50bdf66d08e28a88dcvboxsync#include <iprt/asm.h>
5debbbcc37114f1dbecaecfc66c81ea2fbda6140vboxsync#include <iprt/string.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <iprt/param.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#ifdef VBOX_WITH_VIDEOHWACCEL
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <iprt/semaphore.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#endif
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync/** The default amount of VRAM. */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync#define VGA_VRAM_DEFAULT (_4M)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync/** The maximum amount of VRAM. */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync#define VGA_VRAM_MAX (128 * _1M)
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync/** The minimum amount of VRAM. */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync#define VGA_VRAM_MIN (_1M)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync#include "DevVGA.h"
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync/* A very detailed logging. */
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync#if 0 // def DEBUG_sunlover
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync#define LOGVBVABUFFER(a) LogFlow(a)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync#else
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync#define LOGVBVABUFFER(a) do {} while(0)
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync#endif
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsynctypedef struct _VBVAPARTIALRECORD
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync{
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync uint8_t *pu8;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync uint32_t cb;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync} VBVAPARTIALRECORD;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsynctypedef struct _VBVAVIEW
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVAINFOVIEW view;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVAINFOSCREEN screen;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVABUFFER *pVBVA;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync uint32_t u32VBVAOffset;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVAPARTIALRECORD partialRecord;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync} VBVAVIEW;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/* @todo saved state: save and restore VBVACONTEXT */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsynctypedef struct _VBVACONTEXT
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync uint32_t cViews;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVAVIEW aViews[64 /* @todo SchemaDefs::MaxGuestMonitors*/];
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync} VBVACONTEXT;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/* Copies 'cb' bytes from the VBVA ring buffer to the 'pu8Dst'.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Used for partial records or for records which cross the ring boundary.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncstatic void vbvaFetchBytes (VBVABUFFER *pVBVA, uint8_t *pu8Dst, uint32_t cb)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* @todo replace the 'if' with an assert. The caller must ensure this condition. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (cb >= pVBVA->cbData)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync AssertMsgFailed (("cb = 0x%08X, ring buffer size 0x%08X", cb, pVBVA->cbData));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync const uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync const uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync const int32_t i32Diff = cb - u32BytesTillBoundary;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (i32Diff <= 0)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Chunk will not cross buffer boundary. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync memcpy (pu8Dst, src, cb);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync else
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Chunk crosses buffer boundary. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync memcpy (pu8Dst, src, u32BytesTillBoundary);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync memcpy (pu8Dst + u32BytesTillBoundary, &pVBVA->au8Data[0], i32Diff);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Advance data offset. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVBVA->off32Data = (pVBVA->off32Data + cb) % pVBVA->cbData;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncstatic bool vbvaPartialRead (VBVAPARTIALRECORD *pPartialRecord, uint32_t cbRecord, VBVABUFFER *pVBVA)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync uint8_t *pu8New;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync LOGVBVABUFFER(("vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pPartialRecord->pu8, pPartialRecord->cb, cbRecord));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pPartialRecord->pu8)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert (pPartialRecord->cb);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pu8New = (uint8_t *)RTMemRealloc (pPartialRecord->pu8, cbRecord);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync else
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert (!pPartialRecord->cb);
ada022f71e6728d4f2b15e643d35aa94992656c7vboxsync pu8New = (uint8_t *)RTMemAlloc (cbRecord);
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync }
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync if (!pu8New)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Memory allocation failed, fail the function. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Log(("vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync cbRecord));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pPartialRecord->pu8)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync RTMemFree (pPartialRecord->pu8);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pPartialRecord->pu8 = NULL;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pPartialRecord->cb = 0;
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return false;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Fetch data from the ring buffer. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vbvaFetchBytes (pVBVA, pu8New + pPartialRecord->cb, cbRecord - pPartialRecord->cb);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pPartialRecord->pu8 = pu8New;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pPartialRecord->cb = cbRecord;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return true;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync/* For contiguous chunks just return the address in the buffer.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * For crossing boundary - allocate a buffer from heap.
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsyncstatic bool vbvaFetchCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR **ppHdr, uint32_t *pcbCmd)
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync{
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync uint32_t indexRecordFirst = pVBVA->indexRecordFirst;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync uint32_t indexRecordFree = pVBVA->indexRecordFree;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync LOGVBVABUFFER(("first = %d, free = %d\n",
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync indexRecordFirst, indexRecordFree));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (indexRecordFirst == indexRecordFree)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* No records to process. Return without assigning output variables. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return true;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVARECORD *pRecord = &pVBVA->aRecords[indexRecordFirst];
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync LOGVBVABUFFER(("cbRecord = 0x%08X\n", pRecord->cbRecord));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync uint32_t cbRecord = pRecord->cbRecord & ~VBVA_F_RECORD_PARTIAL;
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pPartialRecord->cb)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* There is a partial read in process. Continue with it. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert (pPartialRecord->pu8);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync LOGVBVABUFFER(("continue partial record cb = %d cbRecord 0x%08X, first = %d, free = %d\n",
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pPartialRecord->cb, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (cbRecord > pPartialRecord->cb)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* New data has been added to the record. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return false;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (!(pRecord->cbRecord & VBVA_F_RECORD_PARTIAL))
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* The record is completed by guest. Return it to the caller. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *ppHdr = (VBVACMDHDR *)pPartialRecord->pu8;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync *pcbCmd = pPartialRecord->cb;
9f9eff04f209bd905529ee3b76076e55568db917vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pPartialRecord->pu8 = NULL;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pPartialRecord->cb = 0;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync /* Advance the record index. */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync LOGVBVABUFFER(("partial done ok, data = %d, free = %d\n",
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pVBVA->off32Data, pVBVA->off32Free));
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync }
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync return true;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync }
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync /* A new record need to be processed. */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync if (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL)
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync {
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync /* Current record is being written by guest. '=' is important here,
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync * because the guest will do a FLUSH at this condition.
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync * This partual record is too large for the ring buffer and must
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync * be accumulated in an allocated buffer.
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync if (cbRecord >= pVBVA->cbData - pVBVA->cbPartialWriteThreshold)
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync {
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync /* Partial read must be started. */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync if (!vbvaPartialRead (pPartialRecord, cbRecord, pVBVA))
9f9eff04f209bd905529ee3b76076e55568db917vboxsync {
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync return false;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync }
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync LOGVBVABUFFER(("started partial record cb = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pPartialRecord->cb, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync }
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync return true;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync }
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync /* Current record is complete. If it is not empty, process it. */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync if (cbRecord)
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync {
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync /* The size of largest contiguos chunk in the ring biffer. */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync uint32_t u32BytesTillBoundary = pVBVA->cbData - pVBVA->off32Data;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync /* The pointer to data in the ring buffer. */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync uint8_t *src = &pVBVA->au8Data[pVBVA->off32Data];
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Fetch or point the data. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (u32BytesTillBoundary >= cbRecord)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* The command does not cross buffer boundary. Return address in the buffer. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *ppHdr = (VBVACMDHDR *)src;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Advance data offset. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync else
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* The command crosses buffer boundary. Rare case, so not optimized. */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync uint8_t *dst = (uint8_t *)RTMemAlloc (cbRecord);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (!dst)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync LogFlowFunc (("could not allocate %d bytes from heap!!!\n", cbRecord));
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pVBVA->off32Data = (pVBVA->off32Data + cbRecord) % pVBVA->cbData;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return false;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vbvaFetchBytes (pVBVA, dst, cbRecord);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *ppHdr = (VBVACMDHDR *)dst;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync LOGVBVABUFFER(("Allocated from heap %p\n", dst));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync *pcbCmd = cbRecord;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync /* Advance the record index. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVBVA->indexRecordFirst = (indexRecordFirst + 1) % RT_ELEMENTS(pVBVA->aRecords);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync LOGVBVABUFFER(("done ok, data = %d, free = %d\n",
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVBVA->off32Data, pVBVA->off32Free));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return true;
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncstatic void vbvaReleaseCmd (VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA, VBVACMDHDR *pHdr, uint32_t cbCmd)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync uint8_t *au8RingBuffer = &pVBVA->au8Data[0];
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if ( (uint8_t *)pHdr >= au8RingBuffer
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync && (uint8_t *)pHdr < &au8RingBuffer[pVBVA->cbData])
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync /* The pointer is inside ring buffer. Must be continuous chunk. */
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync Assert (pVBVA->cbData - ((uint8_t *)pHdr - au8RingBuffer) >= cbCmd);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync /* Do nothing. */
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync else
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* The pointer is outside. It is then an allocated copy. */
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync LOGVBVABUFFER(("Free heap %p\n", pHdr));
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync if ((uint8_t *)pHdr == pPartialRecord->pu8)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pPartialRecord->pu8 = NULL;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pPartialRecord->cb = 0;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync else
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync Assert (!pPartialRecord->pu8 && pPartialRecord->cb == 0);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync RTMemFree (pHdr);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync return;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync}
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsyncstatic int vbvaFlushProcess (unsigned uScreenId, PVGASTATE pVGAState, VBVAPARTIALRECORD *pPartialRecord, VBVABUFFER *pVBVA)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync{
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync LOGVBVABUFFER(("uScreenId %d, indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync uScreenId, pVBVA->indexRecordFirst, pVBVA->indexRecordFree, pVBVA->off32Data, pVBVA->off32Free));
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync struct {
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync /* The rectangle that includes all dirty rectangles. */
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync int32_t xLeft;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync int32_t xRight;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync int32_t yTop;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync int32_t yBottom;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync } dirtyRect;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync memset(&dirtyRect, 0, sizeof(dirtyRect));
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync bool fUpdate = false; /* Whether there were any updates. */
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync for (;;)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVACMDHDR *phdr = NULL;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync uint32_t cbCmd = ~0;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Fetch the command data. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (!vbvaFetchCmd (pPartialRecord, pVBVA, &phdr, &cbCmd))
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync LogFunc(("unable to fetch command. off32Data = %d, off32Free = %d!!!\n",
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync pVBVA->off32Data, pVBVA->off32Free));
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync /* @todo old code disabled VBVA processing here. */
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync return VERR_NOT_SUPPORTED;
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync }
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (cbCmd == uint32_t(~0))
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync /* No more commands yet in the queue. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync break;
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync }
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (cbCmd != 0)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (!fUpdate)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVGAState->pDrv->pfnVBVAUpdateBegin (pVGAState->pDrv, uScreenId);
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync fUpdate = true;
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync }
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync /* Updates the rectangle and sends the command to the VRDP server. */
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync pVGAState->pDrv->pfnVBVAUpdateProcess (pVGAState->pDrv, uScreenId, phdr, cbCmd);
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync
e61cd03db2217b7ec7467065af02d7ea7549149evboxsync int32_t xRight = phdr->x + phdr->w;
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync int32_t yBottom = phdr->y + phdr->h;
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync
e61cd03db2217b7ec7467065af02d7ea7549149evboxsync /* These are global coords, relative to the primary screen. */
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync LOGVBVABUFFER(("cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync cbCmd, phdr->x, phdr->y, phdr->w, phdr->h));
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync /* Collect all rects into one. */
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync if (dirtyRect.xRight == 0)
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* This is the first rectangle to be added. */
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync dirtyRect.xLeft = phdr->x;
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync dirtyRect.yTop = phdr->y;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync dirtyRect.xRight = xRight;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync dirtyRect.yBottom = yBottom;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync }
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync else
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync {
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync /* Adjust region coordinates. */
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync if (dirtyRect.xLeft > phdr->x)
e61cd03db2217b7ec7467065af02d7ea7549149evboxsync {
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync dirtyRect.xLeft = phdr->x;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync if (dirtyRect.yTop > phdr->y)
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync {
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync dirtyRect.yTop = phdr->y;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync }
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync if (dirtyRect.xRight < xRight)
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync {
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync dirtyRect.xRight = xRight;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync }
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync if (dirtyRect.yBottom < yBottom)
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync {
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync dirtyRect.yBottom = yBottom;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vbvaReleaseCmd (pPartialRecord, pVBVA, phdr, cbCmd);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
243041cd7eae9f34b08e7340533b2a88218ee57evboxsync if (fUpdate)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if(dirtyRect.xRight)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, dirtyRect.xLeft, dirtyRect.yTop,
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync dirtyRect.xRight - dirtyRect.xLeft, dirtyRect.yBottom - dirtyRect.yTop);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync else
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVGAState->pDrv->pfnVBVAUpdateEnd (pVGAState->pDrv, uScreenId, 0, 0, 0, 0);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VINF_SUCCESS;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncstatic int vbvaFlush (PVGASTATE pVGAState, VBVACONTEXT *pCtx)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync unsigned uScreenId;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVAPARTIALRECORD *pPartialRecord = &pCtx->aViews[uScreenId].partialRecord;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VBVABUFFER *pVBVA = pCtx->aViews[uScreenId].pVBVA;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pVBVA)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync vbvaFlushProcess (uScreenId, pVGAState, pPartialRecord, pVBVA);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* @todo rc */
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync return VINF_SUCCESS;
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncstatic int vbvaResize (PVGASTATE pVGAState, VBVAVIEW *pView, const VBVAINFOSCREEN *pNewScreen)
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync{
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync /* Verify pNewScreen. */
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync /* @todo */
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* Apply these changes. */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pView->screen = *pNewScreen;
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync uint8_t *pu8VRAM = pVGAState->vram_ptrR3 + pView->view.u32ViewOffset;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync int rc = pVGAState->pDrv->pfnVBVAResize (pVGAState->pDrv, &pView->view, &pView->screen, pu8VRAM);
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /* @todo process VINF_VGA_RESIZE_IN_PROGRESS? */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync return rc;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync}
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsyncstatic int vbvaEnable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx, VBVABUFFER *pVBVA, uint32_t u32Offset)
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync{
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync /* @todo old code did a UpdateDisplayAll at this place. */
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync int rc;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (pVGAState->pDrv->pfnVBVAEnable)
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync rc = pVGAState->pDrv->pfnVBVAEnable (pVGAState->pDrv, uScreenId);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync else
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync rc = VERR_NOT_SUPPORTED;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (RT_SUCCESS (rc))
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync /* Setup flags. */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pVBVA->u32HostEvents = VBVA_F_MODE_ENABLED |
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync VBVA_F_MODE_VRDP |
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pVBVA->u32SupportedOrders = ~0;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pCtx->aViews[uScreenId].partialRecord.pu8 = NULL;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pCtx->aViews[uScreenId].partialRecord.cb = 0;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pCtx->aViews[uScreenId].pVBVA = pVBVA;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pCtx->aViews[uScreenId].u32VBVAOffset = u32Offset;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync return rc;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync}
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsyncstatic int vbvaDisable (unsigned uScreenId, PVGASTATE pVGAState, VBVACONTEXT *pCtx)
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync{
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync /* Process any pending orders and empty the VBVA ring buffer. */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync vbvaFlush (pVGAState, pCtx);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync VBVAVIEW *pView = &pCtx->aViews[uScreenId];
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (pView->pVBVA)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pView->pVBVA->u32HostEvents = 0;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pView->pVBVA->u32SupportedOrders = 0;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync pView->partialRecord.pu8 = NULL;
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync pView->partialRecord.cb = 0;
0c436e66dac8edc81d43b54cd878ed239a63574bvboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pView->pVBVA = NULL;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pView->u32VBVAOffset = HGSMIOFFSET_VOID;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pVGAState->pDrv->pfnVBVADisable (pVGAState->pDrv, uScreenId);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync return VINF_SUCCESS;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync}
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsyncstatic int vbvaMousePointerShape (PVGASTATE pVGAState, VBVACONTEXT *pCtx, const VBVAMOUSEPOINTERSHAPE *pShape, HGSMISIZE cbShape)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync{
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync bool fVisible = (pShape->fu32Flags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync bool fAlpha = (pShape->fu32Flags & VBOX_MOUSE_POINTER_ALPHA) != 0;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync bool fShape = (pShape->fu32Flags & VBOX_MOUSE_POINTER_SHAPE) != 0;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync HGSMISIZE cbPointerData = 0;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync if (fShape)
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync cbPointerData = ((((pShape->u32Width + 7) / 8) * pShape->u32Height + 3) & ~3)
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync + pShape->u32Width * 4 * pShape->u32Height;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (cbPointerData > cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data))
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync Log(("vbvaMousePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync cbPointerData, cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data)));
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync return VERR_INVALID_PARAMETER;
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync }
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync if (pVGAState->pDrv->pfnVBVAMousePointerShape == NULL)
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync {
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync return VERR_NOT_SUPPORTED;
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync }
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync int rc;
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync if (fShape)
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync {
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync fVisible,
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync fAlpha,
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pShape->u32HotX, pShape->u32HotY,
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pShape->u32Width, pShape->u32Height,
9ee72227058430bcead5831131741b5dc1601f00vboxsync &pShape->au8Data[0]);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync else
9ee72227058430bcead5831131741b5dc1601f00vboxsync {
9ee72227058430bcead5831131741b5dc1601f00vboxsync rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync fVisible,
9ee72227058430bcead5831131741b5dc1601f00vboxsync false,
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync 0, 0,
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync 0, 0,
7c930c3ee58f55e1a2cebfa2ad3ae918569a8f44vboxsync NULL);
9ee72227058430bcead5831131741b5dc1601f00vboxsync }
7c930c3ee58f55e1a2cebfa2ad3ae918569a8f44vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync return rc;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync}
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsyncstatic unsigned vbvaViewFromOffset (PHGSMIINSTANCE pIns, VBVACONTEXT *pCtx, const void *pvBuffer)
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync{
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync /* Check which view contains the buffer. */
9ee72227058430bcead5831131741b5dc1601f00vboxsync HGSMIOFFSET offBuffer = HGSMIPointerToOffsetHost (pIns, pvBuffer);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
7c930c3ee58f55e1a2cebfa2ad3ae918569a8f44vboxsync if (offBuffer != HGSMIOFFSET_VOID)
9ee72227058430bcead5831131741b5dc1601f00vboxsync {
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync unsigned uScreenId;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync {
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync VBVAINFOVIEW *pView = &pCtx->aViews[uScreenId].view;
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync if ( pView->u32ViewSize > 0
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync && pView->u32ViewOffset <= offBuffer
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync && offBuffer <= pView->u32ViewOffset + pView->u32ViewSize - 1)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync return pView->u32ViewIndex;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
7c930c3ee58f55e1a2cebfa2ad3ae918569a8f44vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync return ~0;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync}
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync#ifdef DEBUG_sunlover
70142706c9117b6c1befe7a5be768d25c699ead5vboxsyncstatic void dumpctx(const VBVACONTEXT *pCtx)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync{
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync Log(("VBVACONTEXT dump: cViews %d\n", pCtx->cViews));
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync uint32_t iView;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync for (iView = 0; iView < pCtx->cViews; iView++)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync const VBVAVIEW *pView = &pCtx->aViews[iView];
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync Log((" view %d o 0x%x s 0x%x m 0x%x\n",
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->view.u32ViewIndex,
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pView->view.u32ViewOffset,
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pView->view.u32ViewSize,
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->view.u32MaxScreenSize));
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync Log((" screen %d @%d,%d s 0x%x l 0x%x %dx%d bpp %d f 0x%x\n",
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->screen.u32ViewIndex,
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync pView->screen.i32OriginX,
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync pView->screen.i32OriginY,
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->screen.u32StartOffset,
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->screen.u32LineSize,
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->screen.u32Width,
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->screen.u32Height,
7c930c3ee58f55e1a2cebfa2ad3ae918569a8f44vboxsync pView->screen.u16BitsPerPixel,
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pView->screen.u16Flags));
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync Log((" VBVA o 0x%x p %p\n",
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->u32VBVAOffset,
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->pVBVA));
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync Log((" PR cb 0x%x p %p\n",
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync pView->partialRecord.cb,
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pView->partialRecord.pu8));
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync}
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync#endif /* DEBUG_sunlover */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsyncint vboxVBVASaveStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync{
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync int rc = HGSMIHostSaveStateExec (pIns, pSSM);
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync if (RT_SUCCESS(rc))
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync /* Save VBVACONTEXT. */
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (!pCtx)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync AssertFailed();
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync /* Still write a valid value to the SSM. */
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync rc = SSMR3PutU32 (pSSM, 0);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync else
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync#ifdef DEBUG_sunlover
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync dumpctx(pCtx);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync#endif
9ee72227058430bcead5831131741b5dc1601f00vboxsync
9ee72227058430bcead5831131741b5dc1601f00vboxsync rc = SSMR3PutU32 (pSSM, pCtx->cViews);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync AssertRCReturn(rc, rc);
9ee72227058430bcead5831131741b5dc1601f00vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync uint32_t iView;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync for (iView = 0; iView < pCtx->cViews; iView++)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync VBVAVIEW *pView = &pCtx->aViews[iView];
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync rc = SSMR3PutU32 (pSSM, pView->view.u32ViewIndex);
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync AssertRCReturn(rc, rc);
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync rc = SSMR3PutU32 (pSSM, pView->view.u32ViewOffset);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->view.u32ViewSize);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->view.u32MaxScreenSize);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->screen.u32ViewIndex);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutS32 (pSSM, pView->screen.i32OriginX);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutS32 (pSSM, pView->screen.i32OriginY);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->screen.u32StartOffset);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->screen.u32LineSize);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->screen.u32Width);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->screen.u32Height);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU16 (pSSM, pView->screen.u16BitsPerPixel);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU16 (pSSM, pView->screen.u16Flags);
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync AssertRCReturn(rc, rc);
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->pVBVA? pView->u32VBVAOffset: HGSMIOFFSET_VOID);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync rc = SSMR3PutU32 (pSSM, pView->partialRecord.cb);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync if (pView->partialRecord.cb > 0)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync rc = SSMR3PutMem (pSSM, pView->partialRecord.pu8, pView->partialRecord.cb);
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync AssertRCReturn(rc, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync return rc;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync}
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsyncint vboxVBVALoadStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync{
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync if (u32Version < 3)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync {
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync /* Nothing was saved. */
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync return VINF_SUCCESS;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync }
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync int rc = HGSMIHostLoadStateExec (pIns, pSSM, u32Version);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (RT_SUCCESS(rc))
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync /* Load VBVACONTEXT. */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (!pCtx)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync /* This should not happen. */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync AssertFailed();
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync rc = VERR_INVALID_PARAMETER;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync else
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync uint32_t cViews = 0;
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU32 (pSSM, &cViews);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync uint32_t iView;
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync for (iView = 0; iView < cViews; iView++)
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync {
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync VBVAVIEW *pView = &pCtx->aViews[iView];
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewIndex);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewOffset);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU32 (pSSM, &pView->view.u32ViewSize);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync rc = SSMR3GetU32 (pSSM, &pView->view.u32MaxScreenSize);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync rc = SSMR3GetU32 (pSSM, &pView->screen.u32ViewIndex);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetS32 (pSSM, &pView->screen.i32OriginX);
9ee72227058430bcead5831131741b5dc1601f00vboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetS32 (pSSM, &pView->screen.i32OriginY);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU32 (pSSM, &pView->screen.u32StartOffset);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU32 (pSSM, &pView->screen.u32LineSize);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU32 (pSSM, &pView->screen.u32Width);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU32 (pSSM, &pView->screen.u32Height);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync rc = SSMR3GetU16 (pSSM, &pView->screen.u16BitsPerPixel);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync AssertRCReturn(rc, rc);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync rc = SSMR3GetU16 (pSSM, &pView->screen.u16Flags);
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync AssertRCReturn(rc, rc);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync rc = SSMR3GetU32 (pSSM, &pView->u32VBVAOffset);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync AssertRCReturn(rc, rc);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync rc = SSMR3GetU32 (pSSM, &pView->partialRecord.cb);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync AssertRCReturn(rc, rc);
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync if (pView->partialRecord.cb == 0)
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync {
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync pView->partialRecord.pu8 = NULL;
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync }
33d90ac36a3ebf89e46a50252fe9542602a6b2bevboxsync else
28563f589b9e002e0ca7d7e2567f423fb620b1advboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync Assert(pView->partialRecord.pu8 == NULL); /* Should be it. */
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync uint8_t *pu8 = (uint8_t *)RTMemAlloc (pView->partialRecord.cb);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync if (!pu8)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync return VERR_NO_MEMORY;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pView->partialRecord.pu8 = pu8;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync rc = SSMR3GetMem (pSSM, pView->partialRecord.pu8, pView->partialRecord.cb);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync AssertRCReturn(rc, rc);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync if ( pView->u32VBVAOffset == HGSMIOFFSET_VOID
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync || pView->screen.u32LineSize == 0) /* Earlier broken saved states. */
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pView->pVBVA = NULL;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync else
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pView->pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, pView->u32VBVAOffset);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pCtx->cViews = iView;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync LogFlowFunc(("%d views loaded\n", pCtx->cViews));
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync#ifdef DEBUG_sunlover
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync dumpctx(pCtx);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync#endif
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync return rc;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync}
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsyncint vboxVBVALoadStateDone (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync{
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync PVGASTATE pVGAState = PDMINS_2_DATA(pDevIns, PVGASTATE);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync if (pCtx)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync uint32_t iView;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync for (iView = 0; iView < pCtx->cViews; iView++)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync VBVAVIEW *pView = &pCtx->aViews[iView];
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync if (pView->pVBVA)
76b4af0cf9fc1811afa84c646645382467a5350bvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync vbvaEnable (iView, pVGAState, pCtx, pView->pVBVA, pView->u32VBVAOffset);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync vbvaResize (pVGAState, pView, &pView->screen);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync return VINF_SUCCESS;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync}
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
32ad75b4af91dad97e4f6c0b1d9f2fd63d173f19vboxsync#ifdef VBOX_WITH_VIDEOHWACCEL
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsyncstatic VBOXVHWACMD* vbvaVHWAHHCommandCreate (PVGASTATE pVGAState, VBOXVHWACMD_TYPE enmCmd, VBOXVHWACMD_LENGTH cbCmd)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync{
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync VBOXVHWACMD* pHdr = (VBOXVHWACMD*)RTMemAlloc(cbCmd + VBOXVHWACMD_HEADSIZE());
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync Assert(pHdr);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync if (pHdr)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync memset(pHdr, 0, sizeof(VBOXVHWACMD));
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pHdr->cRefs = 1;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pHdr->rc = VERR_GENERAL_FAILURE;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pHdr->enmCmd = enmCmd;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pHdr->Flags = VBOXVHWACMD_FLAG_HH_CMD;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync return pHdr;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync}
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsyncDECLINLINE(void) vbvaVHWAHHCommandRelease (VBOXVHWACMD* pCmd)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync{
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync uint32_t cRefs = ASMAtomicDecU32(&pCmd->cRefs);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync if(!cRefs)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync RTMemFree(pCmd);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync}
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsyncDECLINLINE(void) vbvaVHWAHHCommandRetain (VBOXVHWACMD* pCmd)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync{
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync ASMAtomicIncU32(&pCmd->cRefs);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync}
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsyncstatic unsigned vbvaVHWAHandleCommand (PVGASTATE pVGAState, VBVACONTEXT *pCtx, PVBOXVHWACMD pCmd)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync{
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pVGAState->pDrv->pfnVHWACommandProcess(pVGAState->pDrv, pCmd);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync return 0;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync}
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsyncstatic int vbvaVHWAHHCommandPost(PVGASTATE pVGAState, VBOXVHWACMD* pCmd)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync{
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync RTSEMEVENT hComplEvent;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync int rc = RTSemEventCreate(&hComplEvent);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync Assert(RT_SUCCESS(rc));
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync if(RT_SUCCESS(rc))
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync /* ensure the cmd is not deleted until we process it */
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync vbvaVHWAHHCommandRetain (pCmd);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync pCmd->GuestVBVAReserved1 = (uint64_t)hComplEvent;
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync vbvaVHWAHandleCommand(pVGAState, NULL, pCmd);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync if((ASMAtomicReadU32((volatile uint32_t *)&pCmd->Flags) & VBOXVHWACMD_FLAG_HG_ASYNCH) != 0)
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync rc = RTSemEventWaitNoResume(hComplEvent, RT_INDEFINITE_WAIT);
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync else
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync {
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync /* the command is completed */
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync }
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync Assert(RT_SUCCESS(rc));
if(RT_SUCCESS(rc))
{
RTSemEventDestroy(hComplEvent);
}
vbvaVHWAHHCommandRelease(pCmd);
}
return rc;
}
int vbvaVHWAConstruct (PVGASTATE pVGAState)
{
VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_CONSTRUCT, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
Assert(pCmd);
if(pCmd)
{
VBOXVHWACMD_HH_CONSTRUCT * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_CONSTRUCT);
memset(pBody, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
PVM pVM = PDMDevHlpGetVM(pDevIns);
pBody->pVM = pVM;
int rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
Assert(RT_SUCCESS(rc));
if(RT_SUCCESS(rc))
{
rc = pCmd->rc;
Assert(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED);
vbvaVHWAHHCommandRelease(pCmd);
if(rc == VERR_NOT_IMPLEMENTED)
{
/* @todo: set some flag in pVGAState indicating VHWA is not supported */
/* VERR_NOT_IMPLEMENTED is not a failure, we just do not support it */
rc = VINF_SUCCESS;
}
}
return rc;
}
return VERR_OUT_OF_RESOURCES;
}
/* @todo call this also on reset? */
int vbvaVHWADisable (PVGASTATE pVGAState)
{
VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_DISABLE, 0);
Assert(pCmd);
if(pCmd)
{
int rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
Assert(RT_SUCCESS(rc));
if(RT_SUCCESS(rc))
{
rc = pCmd->rc;
Assert(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED);
vbvaVHWAHHCommandRelease(pCmd);
if(rc == VERR_NOT_IMPLEMENTED)
{
rc = VINF_SUCCESS;
}
}
return rc;
}
return VERR_OUT_OF_RESOURCES;
}
int vboxVBVASaveStatePrep (PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
{
/* ensure we have no pending commands */
return vbvaVHWADisable(PDMINS_2_DATA(pDevIns, PVGASTATE));
}
#define PPDMDDISPLAYVBVACALLBACKS_2_PVGASTATE(_pcb) ( (PVGASTATE)((uint8_t *)(_pcb) - RT_OFFSETOF(VGASTATE, VBVACallbacks)) )
int vbvaVHWACommandCompleteAsynch(PPDMDDISPLAYVBVACALLBACKS pInterface, PVBOXVHWACMD pCmd)
{
int rc;
if((pCmd->Flags & VBOXVHWACMD_FLAG_HH_CMD) == 0)
{
PVGASTATE pVGAState = PPDMDDISPLAYVBVACALLBACKS_2_PVGASTATE(pInterface);
PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
VBVAHOSTCMD *pHostCmd;
// Assert(0);
int32_t iDisplay = pCmd->iDisplay;
Assert(pCmd->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH);
if(pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_EVENT)
{
rc = HGSMIHostCommandAlloc (pIns,
(void**)&pHostCmd,
VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDEVENT)),
HGSMI_CH_VBVA,
VBVAHG_EVENT);
Assert(RT_SUCCESS(rc));
if(RT_SUCCESS(rc))
{
memset(pHostCmd, 0 , VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDEVENT)));
pHostCmd->iDstID = pCmd->iDisplay;
pHostCmd->customOpCode = 0;
VBVAHOSTCMDEVENT *pBody = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDEVENT);
pBody->pEvent = pCmd->GuestVBVAReserved1;
}
}
else
{
HGSMIOFFSET offCmd = HGSMIPointerToOffsetHost (pIns, pCmd);
Assert(offCmd != HGSMIOFFSET_VOID);
if(offCmd != HGSMIOFFSET_VOID)
{
rc = HGSMIHostCommandAlloc (pIns,
(void**)&pHostCmd,
VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDVHWACMDCOMPLETE)),
HGSMI_CH_VBVA,
VBVAHG_DISPLAY_CUSTOM);
Assert(RT_SUCCESS(rc));
if(RT_SUCCESS(rc))
{
memset(pHostCmd, 0 , VBVAHOSTCMD_SIZE(sizeof(VBVAHOSTCMDVHWACMDCOMPLETE)));
pHostCmd->iDstID = pCmd->iDisplay;
pHostCmd->customOpCode = VBVAHG_DCUSTOM_VHWA_CMDCOMPLETE;
VBVAHOSTCMDVHWACMDCOMPLETE *pBody = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDVHWACMDCOMPLETE);
pBody->offCmd = offCmd;
}
}
else
{
rc = VERR_INVALID_PARAMETER;
}
}
if(RT_SUCCESS(rc))
{
rc = HGSMIHostCommandProcessAndFreeAsynch(pIns, pHostCmd, (pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ) != 0);
Assert(RT_SUCCESS(rc));
if(RT_SUCCESS(rc))
{
return rc;
}
HGSMIHostCommandFree (pIns, pHostCmd);
}
}
else
{
if(pCmd->GuestVBVAReserved1)
{
RTSEMEVENT hComplEvent = (RTSEMEVENT)pCmd->GuestVBVAReserved1;
RTSemEventSignal(hComplEvent);
}
rc = VINF_SUCCESS;
}
return rc;
}
#endif
/*
*
* New VBVA uses a new interface id: #define VBE_DISPI_ID_VBOX_VIDEO 0xBE01
*
* VBVA uses two 32 bits PCI IO ports to write VRAM offsets of shared memory blocks for commands.
* IOPortBase+ Read Write
* VGA_PORT_OFF_HGSMI_GUEST control value? to process
* VGA_PORT_OFF_HGSMI_HOST to process completed
*
*/
static DECLCALLBACK(void) vbvaNotifyGuest (void *pvCallback)
{
#if defined(VBOX_WITH_HGSMI) && defined(VBOX_WITH_VIDEOHWACCEL)
PVGASTATE pVGAState = (PVGASTATE)pvCallback;
PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
PDMCritSectEnter(&pVGAState->lock, VERR_SEM_BUSY);
HGSMISetHostGuestFlags(pVGAState->pHGSMI, HGSMIHOSTFLAGS_IRQ);
PDMDevHlpPCISetIrq(pDevIns, 0, PDM_IRQ_LEVEL_HIGH);
PDMCritSectLeave(&pVGAState->lock);
#else
NOREF(pvCallback);
/* Do nothing. Later the VMMDev/VGA IRQ can be used for the notification. */
#endif
}
/* The guest submitted a buffer. @todo Verify all guest data. */
static DECLCALLBACK(int) vbvaChannelHandler (void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer)
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pvHandler %p, u16ChannelInfo %d, pvBuffer %p, cbBuffer %u\n",
pvHandler, u16ChannelInfo, pvBuffer, cbBuffer));
PVGASTATE pVGAState = (PVGASTATE)pvHandler;
PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pIns);
switch (u16ChannelInfo)
{
case VBVA_QUERY_CONF32:
{
if (cbBuffer < sizeof (VBVACONF32))
{
rc = VERR_INVALID_PARAMETER;
break;
}
VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
LogFlowFunc(("VBVA_QUERY_CONF32: u32Index %d, u32Value 0x%x\n",
pConf32->u32Index, pConf32->u32Value));
if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
{
pConf32->u32Value = pCtx->cViews;
}
else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
{
/* @todo a value caclucated from the vram size */
pConf32->u32Value = 64*_1K;
}
else
{
Log(("Unsupported VBVA_QUERY_CONF32 index %d!!!\n",
pConf32->u32Index));
rc = VERR_INVALID_PARAMETER;
}
} break;
case VBVA_SET_CONF32:
{
if (cbBuffer < sizeof (VBVACONF32))
{
rc = VERR_INVALID_PARAMETER;
break;
}
VBVACONF32 *pConf32 = (VBVACONF32 *)pvBuffer;
LogFlowFunc(("VBVA_SET_CONF32: u32Index %d, u32Value 0x%x\n",
pConf32->u32Index, pConf32->u32Value));
if (pConf32->u32Index == VBOX_VBVA_CONF32_MONITOR_COUNT)
{
/* do nothing. this is a const. */
}
else if (pConf32->u32Index == VBOX_VBVA_CONF32_HOST_HEAP_SIZE)
{
/* do nothing. this is a const. */
}
else
{
Log(("Unsupported VBVA_SET_CONF32 index %d!!!\n",
pConf32->u32Index));
rc = VERR_INVALID_PARAMETER;
}
} break;
case VBVA_INFO_VIEW:
{
if (cbBuffer < sizeof (VBVAINFOVIEW))
{
rc = VERR_INVALID_PARAMETER;
break;
}
/* Guest submits an array of VBVAINFOVIEW structures. */
VBVAINFOVIEW *pView = (VBVAINFOVIEW *)pvBuffer;
for (;
cbBuffer >= sizeof (VBVAINFOVIEW);
pView++, cbBuffer -= sizeof (VBVAINFOVIEW))
{
LogFlowFunc(("VBVA_INFO_VIEW: index %d, offset 0x%x, size 0x%x, max screen size 0x%x\n",
pView->u32ViewIndex, pView->u32ViewOffset, pView->u32ViewSize, pView->u32MaxScreenSize));
/* @todo verify view data. */
if (pView->u32ViewIndex >= pCtx->cViews)
{
Log(("View index too large %d!!!\n",
pView->u32ViewIndex));
rc = VERR_INVALID_PARAMETER;
break;
}
pCtx->aViews[pView->u32ViewIndex].view = *pView;
}
} break;
case VBVA_INFO_HEAP:
{
if (cbBuffer < sizeof (VBVAINFOHEAP))
{
rc = VERR_INVALID_PARAMETER;
break;
}
VBVAINFOHEAP *pHeap = (VBVAINFOHEAP *)pvBuffer;
LogFlowFunc(("VBVA_INFO_HEAP: offset 0x%x, size 0x%x\n",
pHeap->u32HeapOffset, pHeap->u32HeapSize));
rc = HGSMISetupHostHeap (pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
} break;
case VBVA_FLUSH:
{
if (cbBuffer < sizeof (VBVAFLUSH))
{
rc = VERR_INVALID_PARAMETER;
break;
}
VBVAFLUSH *pFlush = (VBVAFLUSH *)pvBuffer;
LogFlowFunc(("VBVA_FLUSH: u32Reserved 0x%x\n",
pFlush->u32Reserved));
rc = vbvaFlush (pVGAState, pCtx);
} break;
case VBVA_INFO_SCREEN:
{
if (cbBuffer < sizeof (VBVAINFOSCREEN))
{
rc = VERR_INVALID_PARAMETER;
break;
}
VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)pvBuffer;
LogFlowFunc(("VBVA_INFO_SCREEN: [%d] @%d,%d %dx%d, line 0x%x, BPP %d, flags 0x%x\n",
pScreen->u32ViewIndex, pScreen->i32OriginX, pScreen->i32OriginY,
pScreen->u32Width, pScreen->u32Height,
pScreen->u32LineSize, pScreen->u16BitsPerPixel, pScreen->u16Flags));
if (pScreen->u32ViewIndex < RT_ELEMENTS (pCtx->aViews))
{
vbvaResize (pVGAState, &pCtx->aViews[pScreen->u32ViewIndex], pScreen);
}
else
{
Log(("View index too large %d!!!\n",
pScreen->u32ViewIndex));
rc = VERR_INVALID_PARAMETER;
}
} break;
case VBVA_ENABLE:
{
if (cbBuffer < sizeof (VBVAENABLE))
{
rc = VERR_INVALID_PARAMETER;
break;
}
unsigned uScreenId = vbvaViewFromOffset (pIns, pCtx, pvBuffer);
if (uScreenId == ~0)
{
rc = VERR_INVALID_PARAMETER;
break;
}
VBVAENABLE *pEnable = (VBVAENABLE *)pvBuffer;
LogFlowFunc(("VBVA_ENABLE[%d]: u32Flags 0x%x u32Offset 0x%x\n",
uScreenId, pEnable->u32Flags, pEnable->u32Offset));
if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_ENABLE)
{
/* Guest reported offset relative to view. */
uint32_t u32Offset = pEnable->u32Offset + pCtx->aViews[uScreenId].view.u32ViewOffset;
VBVABUFFER *pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost (pIns, u32Offset);
if (pVBVA)
{
/* Process any pending orders and empty the VBVA ring buffer. */
vbvaFlush (pVGAState, pCtx);
rc = vbvaEnable (uScreenId, pVGAState, pCtx, pVBVA, u32Offset);
}
else
{
Log(("Invalid VBVABUFFER offset 0x%x!!!\n",
pEnable->u32Offset));
rc = VERR_INVALID_PARAMETER;
}
}
else if ((pEnable->u32Flags & (VBVA_F_ENABLE | VBVA_F_DISABLE)) == VBVA_F_DISABLE)
{
rc = vbvaDisable (uScreenId, pVGAState, pCtx);
}
else
{
Log(("Invalid VBVA_ENABLE flags 0x%x!!!\n",
pEnable->u32Flags));
rc = VERR_INVALID_PARAMETER;
}
pEnable->i32Result = rc;
} break;
case VBVA_MOUSE_POINTER_SHAPE:
{
if (cbBuffer < sizeof (VBVAMOUSEPOINTERSHAPE))
{
rc = VERR_INVALID_PARAMETER;
break;
}
VBVAMOUSEPOINTERSHAPE *pShape = (VBVAMOUSEPOINTERSHAPE *)pvBuffer;
LogFlowFunc(("VBVA_MOUSE_POINTER_SHAPE: i32Result 0x%x, fu32Flags 0x%x, hot spot %d,%d, size %dx%d\n",
pShape->i32Result,
pShape->fu32Flags,
pShape->u32HotX,
pShape->u32HotY,
pShape->u32Width,
pShape->u32Height));
rc = vbvaMousePointerShape (pVGAState, pCtx, pShape, cbBuffer);
pShape->i32Result = rc;
} break;
#ifdef VBOX_WITH_VIDEOHWACCEL
case VBVA_VHWA_CMD:
{
rc = vbvaVHWAHandleCommand (pVGAState, pCtx, (PVBOXVHWACMD)pvBuffer);
} break;
#endif
default:
Log(("Unsupported VBVA guest command %d!!!\n",
u16ChannelInfo));
break;
}
return rc;
}
void VBVAReset (PVGASTATE pVGAState)
{
if (!pVGAState || !pVGAState->pHGSMI)
{
return;
}
VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
if (pCtx)
{
vbvaFlush (pVGAState, pCtx);
unsigned uScreenId;
for (uScreenId = 0; uScreenId < pCtx->cViews; uScreenId++)
{
vbvaDisable (uScreenId, pVGAState, pCtx);
}
}
}
int VBVAUpdateDisplay (PVGASTATE pVGAState)
{
int rc = VERR_NOT_SUPPORTED; /* Assuming that the VGA device will have to do updates. */
VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
if (pCtx)
{
rc = vbvaFlush (pVGAState, pCtx);
if (RT_SUCCESS (rc))
{
if (!pCtx->aViews[0].pVBVA)
{
/* VBVA is not enabled for the first view, so VGA device must do updates. */
rc = VERR_NOT_SUPPORTED;
}
}
}
return rc;
}
static HGSMICHANNELHANDLER sOldChannelHandler;
int VBVAInit (PVGASTATE pVGAState)
{
PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
PVM pVM = PDMDevHlpGetVM(pDevIns);
int rc = HGSMICreate (&pVGAState->pHGSMI,
pVM,
"VBVA",
0,
pVGAState->vram_ptrR3,
pVGAState->vram_size,
vbvaNotifyGuest,
pVGAState,
sizeof (VBVACONTEXT));
if (RT_SUCCESS (rc))
{
rc = HGSMIHostChannelRegister (pVGAState->pHGSMI,
HGSMI_CH_VBVA,
vbvaChannelHandler,
pVGAState,
&sOldChannelHandler);
if (RT_SUCCESS (rc))
{
VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
pCtx->cViews = pVGAState->cMonitors;
}
}
return rc;
}
void VBVADestroy (PVGASTATE pVGAState)
{
HGSMIDestroy (pVGAState->pHGSMI);
pVGAState->pHGSMI = NULL;
}