DevVGA_VDMA.cpp revision 4264e5514216aa306ace75f8b256f88849a0833b
/** @file
* Video DMA (VDMA) support.
*/
/*
* Copyright (C) 2006-2009 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <VBox/VBoxVideo.h>
#include <iprt/semaphore.h>
#include "DevVGA.h"
#include "HGSMI/SHGSMIHost.h"
#include "HGSMI/HGSMIHostHlp.h"
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
typedef enum
{
typedef struct VBOXVDMAPIPE
{
/* critical section for accessing pipe properties */
/* true iff the other end needs Event notification */
bool bNeedNotify;
typedef enum
{
typedef struct VBOXVDMAPIPE_CMD_BODY
{
union
{
void *pvCmd;
} u;
typedef struct VBOXVDMAPIPE_CMD
{
#define VBOXVDMAPIPE_CMD_FROM_ENTRY(_pE) ( (PVBOXVDMAPIPE_CMD)((uint8_t *)(_pE) - RT_OFFSETOF(VBOXVDMAPIPE_CMD, Entry)) )
typedef struct VBOXVDMAPIPE_CMD_POOL
{
#endif
typedef struct VBOXVDMAHOST
{
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
#endif
#ifdef VBOX_WITH_CRHGSMI
typedef DECLCALLBACK(void) FNVBOXVDMACRCTL_CALLBACK(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, void* pvContext);
typedef struct VBOXVDMACMD_CHROMIUM_CTL_PRIVATE
{
void *pvCompletion;
#define VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(_p) ((PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE)(((uint8_t*)(_p)) - RT_OFFSETOF(VBOXVDMACMD_CHROMIUM_CTL_PRIVATE, Cmd)))
static PVBOXVDMACMD_CHROMIUM_CTL vboxVDMACrCtlCreate(VBOXVDMACMD_CHROMIUM_CTL_TYPE enmCmd, uint32_t cbCmd)
{
PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr = (PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE)RTMemAllocZ(cbCmd + RT_OFFSETOF(VBOXVDMACMD_CHROMIUM_CTL_PRIVATE, Cmd));
if (pHdr)
{
}
return NULL;
}
{
if(!cRefs)
{
}
}
{
}
{
}
static DECLCALLBACK(void) vboxVDMACrCtlCbSetEvent(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, void* pvContext)
{
}
static DECLCALLBACK(void) vboxVDMACrCtlCbReleaseCmd(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, void* pvContext)
{
}
static int vboxVDMACrCtlPostAsync (PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, uint32_t cbCmd, PFNVBOXVDMACRCTL_CALLBACK pfnCompletion, void *pvCompletion)
{
{
return VINF_SUCCESS;
}
#ifdef DEBUG_misha
Assert(0);
#endif
return VERR_NOT_SUPPORTED;
}
{
if(RT_SUCCESS(rc))
{
#ifdef DEBUG_misha
#endif
if (RT_SUCCESS(rc))
{
if(RT_SUCCESS(rc))
{
}
}
else
{
/* the command is completed */
}
}
return rc;
}
{
PVBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP pCmd = (PVBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP)vboxVDMACrCtlCreate(
VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP, sizeof (*pCmd));
if (pCmd)
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
return VERR_NO_MEMORY;
}
static int vboxVDMACmdExecBpbTransfer(PVBOXVDMAHOST pVdma, const PVBOXVDMACMD_DMA_BPB_TRANSFER pTransfer, uint32_t cbBuffer);
/* check if this is external cmd to be passed to chromium backend */
static int vboxVDMACmdCheckCrCmd(struct VBOXVDMAHOST *pVdma, PVBOXVDMACBUF_DR pCmdDr, uint32_t cbCmdDr)
{
int rc = VINF_NOT_SUPPORTED;
{
{
AssertMsgFailed(("invalid buffer data!"));
return VERR_INVALID_PARAMETER;
}
{
AssertMsgFailed(("invalid command buffer data!"));
return VERR_INVALID_PARAMETER;
}
}
if (pDmaCmd)
{
{
{
{
AssertMsgFailed(("invalid chromium command buffer size!"));
return VERR_INVALID_PARAMETER;
}
rc = VINF_SUCCESS;
{
break;
}
else
{
Assert(0);
}
break;
}
{
{
AssertMsgFailed(("invalid bpb transfer buffer size!"));
return VERR_INVALID_PARAMETER;
}
if (RT_SUCCESS(rc))
{
rc = VINF_SUCCESS;
}
break;
}
default:
break;
}
}
return rc;
}
int vboxVDMACrHgsmiCommandCompleteAsync(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, int rc)
{
return rc;
}
int vboxVDMACrHgsmiControlCompleteAsync(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCmd, int rc)
{
if (pCmdPrivate->pfnCompletion)
{
}
return VINF_SUCCESS;
}
#endif
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
/* to simplify things and to avoid extra backend if modifications we assume the VBOXVDMA_RECTL is the same as VBVACMDHDR */
static int vboxVDMANotifyPrimaryUpdate (PVGASTATE pVGAState, unsigned uScreenId, const VBOXVDMA_RECTL * pRectl)
{
/* Updates the rectangle and sends the command to the VRDP server. */
sizeof (VBOXVDMA_RECTL));
return VINF_SUCCESS;
}
#endif
{
/* we do not support color conversion */
/* we do not support stretching */
return VERR_INVALID_FUNCTION;
{
}
else
{
uint32_t offDstLineEnd = ((pDstRectl->left * pDstDesc->bpp + 7) >> 3) + ((pDstDesc->bpp * pDstRectl->width + 7) >> 3);
uint32_t offSrcLineEnd = ((pSrcRectl->left * pSrcDesc->bpp + 7) >> 3) + ((pSrcDesc->bpp * pSrcRectl->width + 7) >> 3);
for (uint32_t i = 0; ; ++i)
{
break;
pvDstStart += cbDstSkip;
pvSrcStart += cbSrcSkip;
}
}
return VINF_SUCCESS;
}
{
else
{
{
}
{
}
}
}
/*
* @return on success the number of bytes the command contained, otherwise - VERR_xxx error code
*/
static int vboxVDMACmdExecBlt(PVBOXVDMAHOST pVdma, const PVBOXVDMACMD_DMA_PRESENT_BLT pBlt, uint32_t cbBuffer)
{
const uint32_t cbBlt = VBOXVDMACMD_BODY_FIELD_OFFSET(uint32_t, VBOXVDMACMD_DMA_PRESENT_BLT, aDstSubRects[pBlt->cDstSubRects]);
return VERR_INVALID_FUNCTION;
/* we do not support stretching for now */
return VERR_INVALID_FUNCTION;
return VERR_INVALID_FUNCTION;
VBOXVDMA_RECTL updateRectl = {0, 0, 0, 0};
if (pBlt->cDstSubRects)
{
{
{
}
{
}
if (!RT_SUCCESS(rc))
return rc;
}
}
else
{
if (!RT_SUCCESS(rc))
return rc;
}
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
int iView = 0;
/* @todo: fixme: check if update is needed and get iView */
#endif
return cbBlt;
}
static int vboxVDMACmdExecBpbTransfer(PVBOXVDMAHOST pVdma, const PVBOXVDMACMD_DMA_BPB_TRANSFER pTransfer, uint32_t cbBuffer)
{
return VERR_INVALID_PARAMETER;
const void * pvSrc;
void * pvDst;
int rc = VINF_SUCCESS;
uint32_t cbTransfered = 0;
bool bSrcLocked = false;
bool bDstLocked = false;
do
{
{
}
else
{
phPage += cbTransfered;
if (RT_SUCCESS(rc))
{
bSrcLocked = true;
}
else
{
break;
}
}
{
}
else
{
phPage += cbTransfered;
if (RT_SUCCESS(rc))
{
bDstLocked = true;
}
else
{
break;
}
}
if (RT_SUCCESS(rc))
{
}
else
{
cbTransfer = 0; /* to break */
}
if (bSrcLocked)
if (bDstLocked)
} while (cbTransfer);
if (RT_SUCCESS(rc))
return sizeof (*pTransfer);
return rc;
}
{
do
{
if (!pvBuffer)
return VERR_INVALID_PARAMETER;
if (cbBuffer < VBOXVDMACMD_HEADER_SIZE())
return VERR_INVALID_PARAMETER;
{
{
#ifdef VBOXWDDM_TEST_UHGSMI
static int count = 0;
if (count==0)
{
start = RTTimeNanoTS();
}
++count;
if (count==100000)
{
end = RTTimeNanoTS();
}
#endif
/* todo: post the buffer to chromium */
return VINF_SUCCESS;
}
{
if (cbBlt >= 0)
{
return VINF_SUCCESS;
else
{
}
}
else
return cbBlt; /* error */
break;
}
{
const PVBOXVDMACMD_DMA_BPB_TRANSFER pTransfer = VBOXVDMACMD_BODY(pCmd, VBOXVDMACMD_DMA_BPB_TRANSFER);
Assert(cbTransfer >= 0);
if (cbTransfer >= 0)
{
return VINF_SUCCESS;
else
{
pvBuffer -= cbTransfer;
}
}
else
return cbTransfer; /* error */
break;
}
case VBOXVDMACMD_TYPE_DMA_NOP:
return VINF_SUCCESS;
return VINF_SUCCESS;
default:
return VERR_INVALID_FUNCTION;
}
} while (1);
/* we should not be here */
return VERR_INVALID_STATE;
}
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
pPipe->bNeedNotify = true;
return VINF_SUCCESS;
// RTCritSectDelete(pPipe->hCritSect);
}
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
{
pPipe->bNeedNotify = false;
rc = VINF_SUCCESS;
break;
pPipe->bNeedNotify = false;
break;
default:
break;
}
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
{
rc = VINF_SUCCESS;
break;
break;
default:
break;
}
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
bool bNeedNotify = false;
{
pPipe->bNeedNotify = false;
break;
pPipe->bNeedNotify = false;
break;
break;
default:
break;
}
if (bNeedNotify)
{
}
}
return rc;
}
typedef FNHVBOXVDMARWCB *PFNHVBOXVDMARWCB;
{
if (RT_SUCCESS(rc))
{
do
{
{
if (bProcessing)
{
rc = VINF_SUCCESS;
break;
}
{
break;
}
}
else
{
break;
}
if (!RT_SUCCESS(rc))
break;
if (!RT_SUCCESS(rc))
break;
} while (1);
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
bool bNeedNotify = false;
{
if (bModified)
{
pPipe->bNeedNotify = false;
}
}
else
if (bNeedNotify)
{
}
}
return rc;
}
{
/* ensure the pipe is closed */
return VERR_INVALID_STATE;
return VINF_SUCCESS;
}
#endif
{
int rc;
bool bReleaseLocked = false;
do
{
{
}
else
{
{
/* @todo: more advanced mechanism of command buffer proc is actually needed */
break;
}
const void * pvPageBuf;
if (!RT_SUCCESS(rc))
{
/* @todo: if (rc == VERR_PGM_PHYS_PAGE_RESERVED) -> fall back on using PGMPhysRead ?? */
break;
}
bReleaseLocked = true;
}
if (bReleaseLocked)
} while (0);
}
{
}
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
typedef struct
{
struct VBOXVDMAHOST *pVdma;
bool bHasCmd;
{
if (pEntry)
{
return true;
}
return false;
}
{
if (RT_SUCCESS(rc))
{
do
{
if (RT_SUCCESS(rc))
{
{
{
break;
}
{
break;
}
default:
break;
}
{
rc = VINF_SUCCESS;
break;
}
}
else
break;
} while (1);
}
/* always try to close the pipe to make sure the client side is notified */
return rc;
}
#endif
{
int rc;
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
PVBOXVDMAHOST pVdma = (PVBOXVDMAHOST)RTMemAllocZ (RT_OFFSETOF(VBOXVDMAHOST, CmdPool.aCmds[cPipeElements]));
#else
#endif
if (pVdma)
{
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
if (RT_SUCCESS(rc))
{
rc = RTThreadCreate(&pVdma->hWorkerThread, vboxVDMAWorkerThread, pVdma, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "VDMA");
if (RT_SUCCESS(rc))
{
for (uint32_t i = 0; i < cPipeElements; ++i)
{
}
# if 0 //def VBOX_WITH_CRHGSMI
# endif
#endif
#ifdef VBOX_WITH_CRHGSMI
#endif
return VINF_SUCCESS;
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
}
}
#endif
}
else
return rc;
}
{
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
/* @todo: implement*/
#endif
return VINF_SUCCESS;
}
#ifdef VBOX_VDMA_WITH_WORKERTHREAD
typedef struct
{
struct VBOXVDMAHOST *pVdma;
bool bQueued;
{
if (pEntry)
{
return true;
}
/* @todo: should we try to flush some commands here? */
return false;
}
#endif
{
#ifdef VBOX_WITH_CRHGSMI
VBOXVDMACMD_CHROMIUM_CTL_TYPE_SAVESTATE_BEGIN, sizeof (*pCmd));
if (pCmd)
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
return VERR_NO_MEMORY;
#else
return VINF_SUCCESS;
#endif
}
{
#ifdef VBOX_WITH_CRHGSMI
VBOXVDMACMD_CHROMIUM_CTL_TYPE_SAVESTATE_END, sizeof (*pCmd));
if (pCmd)
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
return VERR_NO_MEMORY;
#else
return VINF_SUCCESS;
#endif
}
{
#if 1
{
case VBOXVDMA_CTL_TYPE_ENABLE:
break;
break;
case VBOXVDMA_CTL_TYPE_FLUSH:
break;
default:
}
#else
/* test asinch completion */
if (RT_SUCCESS(rc))
{
{
/* success */
return;
}
}
/* failure */
#endif
}
{
int rc = VERR_NOT_IMPLEMENTED;
#ifdef VBOX_WITH_CRHGSMI
/* chromium commands are processed by crhomium hgcm thread independently from our internal cmd processing pipeline
* this is why we process them specially */
if (rc == VINF_SUCCESS)
return;
if (RT_FAILURE(rc))
{
return;
}
#endif
#ifndef VBOX_VDMA_WITH_WORKERTHREAD
#else
# ifdef DEBUG_misha
Assert(0);
# endif
if (RT_SUCCESS(rc))
{
{
/* success */
return;
}
}
/* failure */
#endif
}