VirtualBox

Changeset 70600 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jan 16, 2018 3:56:12 PM (7 years ago)
Author:
vboxsync
Message:

DevVGA: cleanup in progress.

Location:
trunk/src/VBox/Devices/Graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp

    r70597 r70600  
    22452245            const uint64_t u64ScreenSize = (uint64_t)screen.u32LineSize * screen.u32Height;
    22462246            if (   screen.u32StartOffset <= pView->u32ViewSize
    2247                 && u64ScreenSize <= pView->u32MaxScreenSize
     2247                && u64ScreenSize         <= pView->u32MaxScreenSize
    22482248                && screen.u32StartOffset <= pView->u32ViewSize - (uint32_t)u64ScreenSize)
    22492249            {
     
    22522252            }
    22532253
    2254             /** @todo why not use "%#RX" instead of "0x%RX"? */
    2255             LogRelFlow(("VBVA: InfoScreen: invalid data! size 0x%RX64, max 0x%RX32\n",
     2254            LogRelFlow(("VBVA: InfoScreen: invalid data! size %#RX64, max %#RX32\n",
    22562255                        u64ScreenSize, pView->u32MaxScreenSize));
    22572256        }
    22582257    }
    22592258    else
    2260     {
    2261         LogRelFlow(("VBVA: InfoScreen: invalid data! index %RU32(%RU32)\n", screen.u32ViewIndex,
    2262                     pCtx->cViews));
    2263     }
     2259        LogRelFlow(("VBVA: InfoScreen: invalid data! index %RU32(%RU32)\n", screen.u32ViewIndex, pCtx->cViews));
    22642260
    22652261    return VERR_INVALID_PARAMETER;
  • trunk/src/VBox/Devices/Graphics/DevVGA_VDMA.cpp

    r70597 r70600  
    202202
    203203
     204/**
     205 * List selector for VBoxVBVAExHCtlSubmit(), vdmaVBVACtlSubmit().
     206 */
     207typedef enum
     208{
     209    VBVAEXHOSTCTL_SOURCE_GUEST = 0,
     210    VBVAEXHOSTCTL_SOURCE_HOST
     211} VBVAEXHOSTCTL_SOURCE;
     212
     213
    204214/*********************************************************************************************************************************
    205215*   Internal Functions                                                                                                           *
    206216*********************************************************************************************************************************/
    207217#ifdef VBOX_WITH_CRHGSMI
    208 static int vdmaVBVANotifyDisable(PVGASTATE pVGAState);
    209 
     218static int  vdmaVBVANotifyDisable(PVGASTATE pVGAState);
    210219static void VBoxVBVAExHPDataCompleteCmd(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint32_t cbCmd);
    211220static void VBoxVBVAExHPDataCompleteCtl(struct VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL *pCtl, int rc);
     221static int  VBoxVDMAThreadEventNotify(PVBOXVDMATHREAD pThread);
     222static int  vboxVDMACmdExecBpbTransfer(PVBOXVDMAHOST pVdma, const VBOXVDMACMD_DMA_BPB_TRANSFER *pTransfer, uint32_t cbBuffer);
     223static int  vdmaVBVACtlSubmitSync(PVBOXVDMAHOST pVdma, VBVAEXHOSTCTL *pCtl, VBVAEXHOSTCTL_SOURCE enmSource);
     224static DECLCALLBACK(void) vdmaVBVACtlSubmitSyncCompletion(VBVAEXHOSTCONTEXT *pVbva, struct VBVAEXHOSTCTL *pCtl,
     225                                                          int rc, void *pvContext);
    212226
    213227/* VBoxVBVAExHP**, i.e. processor functions, can NOT be called concurrently with each other,
    214228 * can be called concurrently with istelf as well as with other VBoxVBVAEx** functions except Init/Start/Term aparently */
    215 static int VBoxVBVAExHSCheckCommands(struct VBVAEXHOSTCONTEXT *pCmdVbva);
    216 
    217 static int VBoxVBVAExHSInit(struct VBVAEXHOSTCONTEXT *pCmdVbva);
    218 static int VBoxVBVAExHSEnable(struct VBVAEXHOSTCONTEXT *pCmdVbva, VBVABUFFER *pVBVA);
    219 static int VBoxVBVAExHSDisable(struct VBVAEXHOSTCONTEXT *pCmdVbva);
    220 static void VBoxVBVAExHSTerm(struct VBVAEXHOSTCONTEXT *pCmdVbva);
    221 static int VBoxVBVAExHSSaveState(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t* pu8VramBase, PSSMHANDLE pSSM);
    222 static int VBoxVBVAExHSLoadState(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t* pu8VramBase, PSSMHANDLE pSSM, uint32_t u32Version);
    223 
    224229#endif /* VBOX_WITH_CRHGSMI */
    225230
     
    228233#ifdef VBOX_WITH_CRHGSMI
    229234
    230 static VBVAEXHOSTCTL* VBoxVBVAExHCtlAlloc(VBVAEXHOSTCONTEXT *pCmdVbva)
     235/**
     236 * Creates a host control command.
     237 */
     238static VBVAEXHOSTCTL *VBoxVBVAExHCtlCreate(VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL_TYPE enmType)
    231239{
    232240# ifndef VBOXVDBG_MEMCACHE_DISABLE
    233     return (VBVAEXHOSTCTL*)RTMemCacheAlloc(pCmdVbva->CtlCache);
     241    VBVAEXHOSTCTL *pCtl = (VBVAEXHOSTCTL*)RTMemCacheAlloc(pCmdVbva->CtlCache);
    234242# else
    235     return (VBVAEXHOSTCTL*)RTMemAlloc(sizeof (VBVAEXHOSTCTL));
     243    VBVAEXHOSTCTL *pCtl = (VBVAEXHOSTCTL*)RTMemAlloc(sizeof(VBVAEXHOSTCTL));
    236244# endif
    237 }
    238 
     245    if (pCtl)
     246    {
     247        RT_ZERO(*pCtl);
     248        pCtl->enmType = enmType;
     249    }
     250    else
     251        WARN(("VBoxVBVAExHCtlAlloc failed\n"));
     252    return pCtl;
     253}
     254
     255/**
     256 * Destroys a host control command.
     257 */
    239258static void VBoxVBVAExHCtlFree(VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL *pCtl)
    240259{
     
    246265}
    247266
    248 static VBVAEXHOSTCTL *VBoxVBVAExHCtlCreate(VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL_TYPE enmType)
    249 {
    250     VBVAEXHOSTCTL* pCtl = VBoxVBVAExHCtlAlloc(pCmdVbva);
    251     if (!pCtl)
    252     {
    253         WARN(("VBoxVBVAExHCtlAlloc failed\n"));
    254         return NULL;
    255     }
    256 
    257     pCtl->enmType = enmType;
    258     return pCtl;
    259 }
    260 
     267
     268
     269/**
     270 * Works the VBVA state.
     271 */
    261272static int vboxVBVAExHSProcessorAcquire(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    262273{
     
    264275
    265276    if (ASMAtomicCmpXchgS32(&pCmdVbva->i32State, VBVAEXHOSTCONTEXT_STATE_PROCESSING, VBVAEXHOSTCONTEXT_STATE_LISTENING))
    266             return VINF_SUCCESS;
     277        return VINF_SUCCESS;
    267278    return VERR_SEM_BUSY;
    268279}
    269280
    270 static VBVAEXHOSTCTL* vboxVBVAExHPCheckCtl(struct VBVAEXHOSTCONTEXT *pCmdVbva, bool *pfHostCtl, bool fHostOnlyMode)
     281/**
     282 * Worker for vboxVBVAExHPDataGet() and VBoxVBVAExHPCheckHostCtlOnDisable() that
     283 * gets the next control command.
     284 *
     285 * @returns Pointer to command if found, NULL if not.
     286 * @param   pCmdVbva        The VBVA command context.
     287 * @param   pfHostCtl       Where to indicate whether it's a host or guest
     288 *                          control command.
     289 * @param   fHostOnlyMode   Whether to only fetch host commands, or both.
     290 */
     291static VBVAEXHOSTCTL *vboxVBVAExHPCheckCtl(struct VBVAEXHOSTCONTEXT *pCmdVbva, bool *pfHostCtl, bool fHostOnlyMode)
    271292{
    272293    Assert(pCmdVbva->i32State == VBVAEXHOSTCONTEXT_STATE_PROCESSING);
     
    278299    if (RT_SUCCESS(rc))
    279300    {
    280         VBVAEXHOSTCTL* pCtl = RTListGetFirst(&pCmdVbva->HostCtlList, VBVAEXHOSTCTL, Node);
     301        VBVAEXHOSTCTL *pCtl = RTListGetFirst(&pCmdVbva->HostCtlList, VBVAEXHOSTCTL, Node);
    281302        if (pCtl)
    282303            *pfHostCtl = true;
     
    304325    }
    305326    else
    306         WARN(("RTCritSectEnter failed %d\n", rc));
     327        WARN(("RTCritSectEnter failed %Rrc\n", rc));
    307328
    308329    return NULL;
    309330}
    310331
    311 static VBVAEXHOSTCTL* VBoxVBVAExHPCheckHostCtlOnDisable(struct VBVAEXHOSTCONTEXT *pCmdVbva)
     332/**
     333 * Worker for vboxVDMACrHgcmHandleEnableRemainingHostCommand().
     334 */
     335static VBVAEXHOSTCTL *VBoxVBVAExHPCheckHostCtlOnDisable(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    312336{
    313337    bool fHostCtl = false;
    314     VBVAEXHOSTCTL* pCtl = vboxVBVAExHPCheckCtl(pCmdVbva, &fHostCtl, true);
     338    VBVAEXHOSTCTL *pCtl = vboxVBVAExHPCheckCtl(pCmdVbva, &fHostCtl, true);
    315339    Assert(!pCtl || fHostCtl);
    316340    return pCtl;
     
    333357}
    334358
     359/**
     360 * Works the VBVA state in response to VBVAEXHOSTCTL_TYPE_HH_INTERNAL_RESUME.
     361 */
    335362static int VBoxVBVAExHPResume(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    336363{
     
    345372}
    346373
     374/**
     375 * Worker for vboxVBVAExHPDataGet that processes PAUSE and RESUME requests.
     376 *
     377 * Unclear why these cannot be handled the normal way.
     378 *
     379 * @returns true if handled, false if not.
     380 * @param   pCmdVbva            The VBVA context.
     381 * @param   pCtl                The host control command.
     382 */
    347383static bool vboxVBVAExHPCheckProcessCtlInternal(struct VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL* pCtl)
    348384{
     
    366402}
    367403
     404/**
     405 * Works the VBVA state.
     406 */
    368407static void vboxVBVAExHPProcessorRelease(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    369408{
     
    373412}
    374413
     414/**
     415 * Works the VBVA state.
     416 */
    375417static void vboxVBVAExHPHgEventSet(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    376418{
     
    380422}
    381423
     424/**
     425 * Works the VBVA state.
     426 */
    382427static void vboxVBVAExHPHgEventClear(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    383428{
     
    457502}
    458503
     504/**
     505 * Control command completion routine used by many.
     506 */
    459507static void VBoxVBVAExHPDataCompleteCtl(struct VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL *pCtl, int rc)
    460508{
     
    489537                    return VBVAEXHOST_DATA_TYPE_HOSTCTL;
    490538                }
    491                 continue;
     539                continue; /* Processed by vboxVBVAExHPCheckProcessCtlInternal, get next. */
    492540            }
    493541            *ppCmd = (uint8_t*)pCtl;
     
    511559            default:
    512560                /* this is something really unexpected, i.e. most likely guest has written something incorrect to the VBVA buffer */
    513                 WARN(("Warning: vboxVBVAExHCmdGet returned unexpected status %d\n", rc));
     561                WARN(("Warning: vboxVBVAExHCmdGet returned unexpected status %Rrc\n", rc));
    514562                return VBVAEXHOST_DATA_TYPE_NO_DATA;
    515563        }
     
    557605}
    558606
     607/**
     608 * Checks for pending VBVA command or (internal) control command.
     609 */
    559610DECLINLINE(bool) vboxVBVAExHSHasCommands(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    560611{
    561612    VBVABUFFER *pVBVA = pCmdVbva->pVBVA;
    562 
    563613    if (pVBVA)
    564614    {
     
    570620    }
    571621
    572     return !!ASMAtomicReadU32(&pCmdVbva->u32cCtls);
     622    return ASMAtomicReadU32(&pCmdVbva->u32cCtls) > 0;
    573623}
    574624
     
    599649}
    600650
     651/**
     652 * Worker for vboxVDMAConstruct() that initializes the give VBVA host context.
     653 */
    601654static int VBoxVBVAExHSInit(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    602655{
    603     memset(pCmdVbva, 0, sizeof (*pCmdVbva));
     656    RT_ZERO(*pCmdVbva);
    604657    int rc = RTCritSectInit(&pCmdVbva->CltCritSect);
    605658    if (RT_SUCCESS(rc))
     
    607660# ifndef VBOXVDBG_MEMCACHE_DISABLE
    608661        rc = RTMemCacheCreate(&pCmdVbva->CtlCache, sizeof (VBVAEXHOSTCTL),
    609                                 0, /* size_t cbAlignment */
    610                                 UINT32_MAX, /* uint32_t cMaxObjects */
    611                                 NULL, /* PFNMEMCACHECTOR pfnCtor*/
    612                                 NULL, /* PFNMEMCACHEDTOR pfnDtor*/
    613                                 NULL, /* void *pvUser*/
    614                                 0 /* uint32_t fFlags*/
    615                                 );
     662                              0, /* size_t cbAlignment */
     663                              UINT32_MAX, /* uint32_t cMaxObjects */
     664                              NULL, /* PFNMEMCACHECTOR pfnCtor*/
     665                              NULL, /* PFNMEMCACHEDTOR pfnDtor*/
     666                              NULL, /* void *pvUser*/
     667                              0 /* uint32_t fFlags*/
     668                              );
    616669        if (RT_SUCCESS(rc))
    617670# endif
     
    619672            RTListInit(&pCmdVbva->GuestCtlList);
    620673            RTListInit(&pCmdVbva->HostCtlList);
    621             pCmdVbva->i32State = VBVAEXHOSTCONTEXT_STATE_PROCESSING;
     674            pCmdVbva->i32State       = VBVAEXHOSTCONTEXT_STATE_PROCESSING;
    622675            pCmdVbva->i32EnableState = VBVAEXHOSTCONTEXT_ESTATE_DISABLED;
    623676            return VINF_SUCCESS;
    624677        }
    625678# ifndef VBOXVDBG_MEMCACHE_DISABLE
    626         else
    627             WARN(("RTMemCacheCreate failed %d\n", rc));
     679        WARN(("RTMemCacheCreate failed %Rrc\n", rc));
    628680# endif
    629681    }
    630682    else
    631         WARN(("RTCritSectInit failed %d\n", rc));
     683        WARN(("RTCritSectInit failed %Rrc\n", rc));
    632684
    633685    return rc;
    634686}
    635687
     688/**
     689 * Checks if VBVA state is some form of enabled.
     690 */
    636691DECLINLINE(bool) VBoxVBVAExHSIsEnabled(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    637692{
    638     return (ASMAtomicUoReadS32(&pCmdVbva->i32EnableState) >= VBVAEXHOSTCONTEXT_ESTATE_PAUSED);
    639 }
    640 
     693    return ASMAtomicUoReadS32(&pCmdVbva->i32EnableState) >= VBVAEXHOSTCONTEXT_ESTATE_PAUSED;
     694}
     695
     696/**
     697 * Checks if VBVA state is disabled.
     698 */
    641699DECLINLINE(bool) VBoxVBVAExHSIsDisabled(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    642700{
    643     return (ASMAtomicUoReadS32(&pCmdVbva->i32EnableState) == VBVAEXHOSTCONTEXT_ESTATE_DISABLED);
    644 }
    645 
     701    return ASMAtomicUoReadS32(&pCmdVbva->i32EnableState) == VBVAEXHOSTCONTEXT_ESTATE_DISABLED;
     702}
     703
     704/**
     705 * Worker for vdmaVBVAEnableProcess().
     706 *
     707 * @thread VDMA
     708 */
    646709static int VBoxVBVAExHSEnable(struct VBVAEXHOSTCONTEXT *pCmdVbva, VBVABUFFER *pVBVA)
    647710{
     
    658721}
    659722
     723/**
     724 * Works the enable state.
     725 * @thread VDMA, CR, EMT, ...
     726 */
    660727static int VBoxVBVAExHSDisable(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    661728{
     
    667734}
    668735
     736/**
     737 * Worker for vboxVDMADestruct() and vboxVDMAConstruct().
     738 */
    669739static void VBoxVBVAExHSTerm(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    670740{
     
    685755# endif
    686756
    687     memset(pCmdVbva, 0, sizeof (*pCmdVbva));
    688 }
    689 
     757    RT_ZERO(*pCmdVbva);
     758}
     759
     760
     761/**
     762 * Worker for vboxVBVAExHSSaveStateLocked().
     763 * @thread VDMA
     764 */
    690765static int vboxVBVAExHSSaveGuestCtl(struct VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL* pCtl, uint8_t* pu8VramBase, PSSMHANDLE pSSM)
    691766{
     
    701776}
    702777
     778/**
     779 * Worker for VBoxVBVAExHSSaveState().
     780 * @thread VDMA
     781 */
    703782static int vboxVBVAExHSSaveStateLocked(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t* pu8VramBase, PSSMHANDLE pSSM)
    704783{
     
    723802}
    724803
    725 
    726 /** Saves state
     804/**
     805 * Handles VBVAEXHOSTCTL_TYPE_HH_SAVESTATE for vboxVDMACrHostCtlProcess, saving
     806 * state on the VDMA thread.
     807 *
    727808 * @returns - same as VBoxVBVAExHSCheckCommands, or failure on load state fail
     809 * @thread VDMA
    728810 */
    729811static int VBoxVBVAExHSSaveState(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t* pu8VramBase, PSSMHANDLE pSSM)
    730812{
    731813    int rc = RTCritSectEnter(&pCmdVbva->CltCritSect);
    732     if (RT_FAILURE(rc))
    733     {
    734         WARN(("RTCritSectEnter failed %d\n", rc));
    735         return rc;
    736     }
     814    AssertRCReturn(rc, rc);
    737815
    738816    rc = vboxVBVAExHSSaveStateLocked(pCmdVbva, pu8VramBase, pSSM);
    739817    if (RT_FAILURE(rc))
    740         WARN(("vboxVBVAExHSSaveStateLocked failed %d\n", rc));
     818        WARN(("vboxVBVAExHSSaveStateLocked failed %Rrc\n", rc));
    741819
    742820    RTCritSectLeave(&pCmdVbva->CltCritSect);
    743 
    744821    return rc;
    745822}
    746823
     824
     825/**
     826 * Worker for vboxVBVAExHSLoadStateLocked.
     827 * @retval VINF_EOF if end stuff to load.
     828 * @thread VDMA
     829 */
    747830static int vboxVBVAExHSLoadGuestCtl(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t* pu8VramBase, PSSMHANDLE pSSM, uint32_t u32Version)
    748831{
     
    755838        return VINF_EOF;
    756839
    757     VBVAEXHOSTCTL* pHCtl = VBoxVBVAExHCtlCreate(pCmdVbva, (VBVAEXHOSTCTL_TYPE)u32);
     840    VBVAEXHOSTCTL *pHCtl = VBoxVBVAExHCtlCreate(pCmdVbva, (VBVAEXHOSTCTL_TYPE)u32);
    758841    if (!pHCtl)
    759842    {
     
    776859}
    777860
    778 
     861/**
     862 * Worker for VBoxVBVAExHSLoadState.
     863 * @thread VDMA
     864 */
    779865static int vboxVBVAExHSLoadStateLocked(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t* pu8VramBase, PSSMHANDLE pSSM, uint32_t u32Version)
    780866{
     
    786872
    787873    int rc;
    788 
    789     do {
     874    do
     875    {
    790876        rc = vboxVBVAExHSLoadGuestCtl(pCmdVbva, pu8VramBase, pSSM, u32Version);
    791877        AssertLogRelRCReturn(rc, rc);
    792     } while (VINF_EOF != rc);
     878    } while (rc != VINF_EOF);
    793879
    794880    return VINF_SUCCESS;
    795881}
    796882
    797 /** Loads state
     883/**
     884 * Handles VBVAEXHOSTCTL_TYPE_HH_LOADSTATE for vboxVDMACrHostCtlProcess(),
     885 * loading state on the VDMA thread.
     886 *
    798887 * @returns - same as VBoxVBVAExHSCheckCommands, or failure on load state fail
     888 * @thread VDMA
    799889 */
    800890static int VBoxVBVAExHSLoadState(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t* pu8VramBase, PSSMHANDLE pSSM, uint32_t u32Version)
     
    802892    Assert(VGA_SAVEDSTATE_VERSION_3D <= u32Version);
    803893    int rc = RTCritSectEnter(&pCmdVbva->CltCritSect);
    804     if (RT_FAILURE(rc))
    805     {
    806         WARN(("RTCritSectEnter failed %d\n", rc));
    807         return rc;
    808     }
     894    AssertRCReturn(rc, rc);
    809895
    810896    rc = vboxVBVAExHSLoadStateLocked(pCmdVbva, pu8VramBase, pSSM, u32Version);
    811897    if (RT_FAILURE(rc))
    812         WARN(("vboxVBVAExHSSaveStateLocked failed %d\n", rc));
     898        WARN(("vboxVBVAExHSSaveStateLocked failed %Rrc\n", rc));
    813899
    814900    RTCritSectLeave(&pCmdVbva->CltCritSect);
    815 
    816901    return rc;
    817902}
    818903
    819 typedef enum
    820 {
    821     VBVAEXHOSTCTL_SOURCE_GUEST = 0,
    822     VBVAEXHOSTCTL_SOURCE_HOST
    823 } VBVAEXHOSTCTL_SOURCE;
    824 
    825 
     904
     905
     906/**
     907 * Queues a control command to the VDMA worker thread.
     908 *
     909 * The @a enmSource argument decides which list (guest/host) it's queued on.
     910 *
     911 */
    826912static int VBoxVBVAExHCtlSubmit(VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL* pCtl, VBVAEXHOSTCTL_SOURCE enmSource,
    827913                                PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
    828914{
    829     if (!VBoxVBVAExHSIsEnabled(pCmdVbva))
     915    int rc;
     916    if (VBoxVBVAExHSIsEnabled(pCmdVbva))
     917    {
     918        pCtl->pfnComplete = pfnComplete;
     919        pCtl->pvComplete  = pvComplete;
     920
     921        rc = RTCritSectEnter(&pCmdVbva->CltCritSect);
     922        if (RT_SUCCESS(rc))
     923        {
     924            /* Recheck that we're enabled after we've got the lock. */
     925            if (VBoxVBVAExHSIsEnabled(pCmdVbva))
     926            {
     927                /* Queue it. */
     928                if (enmSource > VBVAEXHOSTCTL_SOURCE_GUEST)
     929                    RTListAppend(&pCmdVbva->HostCtlList, &pCtl->Node);
     930                else
     931                    RTListAppend(&pCmdVbva->GuestCtlList, &pCtl->Node);
     932                ASMAtomicIncU32(&pCmdVbva->u32cCtls);
     933
     934                RTCritSectLeave(&pCmdVbva->CltCritSect);
     935
     936                /* Work the state or something. */
     937                rc = VBoxVBVAExHSCheckCommands(pCmdVbva);
     938            }
     939            else
     940            {
     941                RTCritSectLeave(&pCmdVbva->CltCritSect);
     942                Log(("cmd vbva not enabled (race)\n"));
     943                rc = VERR_INVALID_STATE;
     944            }
     945        }
     946        else
     947            AssertRC(rc);
     948    }
     949    else
    830950    {
    831951        Log(("cmd vbva not enabled\n"));
    832         return VERR_INVALID_STATE;
    833     }
    834 
    835     pCtl->pfnComplete = pfnComplete;
    836     pCtl->pvComplete = pvComplete;
    837 
    838     int rc = RTCritSectEnter(&pCmdVbva->CltCritSect);
     952        rc = VERR_INVALID_STATE;
     953    }
     954    return rc;
     955}
     956
     957/**
     958 * Submits the control command and notifies the VDMA thread.
     959 */
     960static int vdmaVBVACtlSubmit(PVBOXVDMAHOST pVdma, VBVAEXHOSTCTL *pCtl, VBVAEXHOSTCTL_SOURCE enmSource,
     961                             PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
     962{
     963    int rc = VBoxVBVAExHCtlSubmit(&pVdma->CmdVbva, pCtl, enmSource, pfnComplete, pvComplete);
    839964    if (RT_SUCCESS(rc))
    840965    {
    841         if (!VBoxVBVAExHSIsEnabled(pCmdVbva))
    842         {
    843             Log(("cmd vbva not enabled\n"));
    844             RTCritSectLeave(&pCmdVbva->CltCritSect);
    845             return VERR_INVALID_STATE;
    846         }
    847 
    848         if (enmSource > VBVAEXHOSTCTL_SOURCE_GUEST)
    849             RTListAppend(&pCmdVbva->HostCtlList, &pCtl->Node);
    850         else
    851             RTListAppend(&pCmdVbva->GuestCtlList, &pCtl->Node);
    852 
    853         ASMAtomicIncU32(&pCmdVbva->u32cCtls);
    854 
    855         RTCritSectLeave(&pCmdVbva->CltCritSect);
    856 
    857         rc = VBoxVBVAExHSCheckCommands(pCmdVbva);
     966        if (rc == VINF_SUCCESS)
     967            return VBoxVDMAThreadEventNotify(&pVdma->Thread);
     968        Assert(rc == VINF_ALREADY_INITIALIZED);
    858969    }
    859970    else
    860         WARN(("RTCritSectEnter failed %d\n", rc));
     971        Log(("VBoxVBVAExHCtlSubmit failed %Rrc\n", rc));
    861972
    862973    return rc;
    863974}
     975
    864976
    865977/**
     
    870982    Assert(pThread->u32State == VBOXVDMATHREAD_STATE_CREATING);
    871983    PFNVBOXVDMATHREAD_CHANGED pfnChanged = pThread->pfnChanged;
    872     void *pvChanged = pThread->pvChanged;
     984    void                     *pvChanged = pThread->pvChanged;
    873985
    874986    pThread->pfnChanged = NULL;
    875     pThread->pvChanged = NULL;
     987    pThread->pvChanged  = NULL;
    876988
    877989    ASMAtomicWriteU32(&pThread->u32State, VBOXVDMATHREAD_STATE_CREATED);
     
    8881000    Assert(pThread->u32State == VBOXVDMATHREAD_STATE_TERMINATING);
    8891001    PFNVBOXVDMATHREAD_CHANGED pfnChanged = pThread->pfnChanged;
    890     void *pvChanged = pThread->pvChanged;
     1002    void                     *pvChanged = pThread->pvChanged;
    8911003
    8921004    pThread->pfnChanged = NULL;
    893     pThread->pvChanged = NULL;
     1005    pThread->pvChanged  = NULL;
    8941006
    8951007    if (pfnChanged)
     
    9101022void VBoxVDMAThreadInit(PVBOXVDMATHREAD pThread)
    9111023{
    912     memset(pThread, 0, sizeof (*pThread));
     1024    RT_ZERO(*pThread);
    9131025    pThread->u32State = VBOXVDMATHREAD_STATE_TERMINATED;
    9141026}
     
    9241036        case VBOXVDMATHREAD_STATE_TERMINATED:
    9251037            return VINF_SUCCESS;
     1038
    9261039        case VBOXVDMATHREAD_STATE_TERMINATING:
    9271040        {
    9281041            int rc = RTThreadWait(pThread->hWorkerThread, RT_INDEFINITE_WAIT, NULL);
    929             if (!RT_SUCCESS(rc))
     1042            if (RT_SUCCESS(rc))
    9301043            {
    931                 WARN(("RTThreadWait failed %d\n", rc));
    932                 return rc;
     1044                RTSemEventDestroy(pThread->hEvent);
     1045                pThread->hEvent        = NIL_RTSEMEVENT;
     1046                pThread->hWorkerThread = NIL_RTTHREAD;
     1047                ASMAtomicWriteU32(&pThread->u32State, VBOXVDMATHREAD_STATE_TERMINATED);
    9331048            }
    934 
    935             RTSemEventDestroy(pThread->hEvent);
    936 
    937             ASMAtomicWriteU32(&pThread->u32State, VBOXVDMATHREAD_STATE_TERMINATED);
    938             return VINF_SUCCESS;
    939         }
     1049            else
     1050                WARN(("RTThreadWait failed %Rrc\n", rc));
     1051            return rc;
     1052        }
     1053
    9401054        default:
    9411055            WARN(("invalid state"));
     
    9511065{
    9521066    int rc = VBoxVDMAThreadCleanup(pThread);
    953     if (RT_FAILURE(rc))
    954     {
    955         WARN(("VBoxVDMAThreadCleanup failed %d\n", rc));
    956         return rc;
    957     }
    958 
    959     rc = RTSemEventCreate(&pThread->hEvent);
    9601067    if (RT_SUCCESS(rc))
    9611068    {
    962         pThread->u32State = VBOXVDMATHREAD_STATE_CREATING;
     1069        rc = RTSemEventCreate(&pThread->hEvent);
     1070        pThread->u32State   = VBOXVDMATHREAD_STATE_CREATING;
    9631071        pThread->pfnChanged = pfnCreated;
    964         pThread->pvChanged = pvCreated;
     1072        pThread->pvChanged  = pvCreated;
    9651073        rc = RTThreadCreate(&pThread->hWorkerThread, pfnThread, pvThread, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "VDMA");
    9661074        if (RT_SUCCESS(rc))
    9671075            return VINF_SUCCESS;
    968         WARN(("RTThreadCreate failed %d\n", rc));
    969 
     1076
     1077        WARN(("RTThreadCreate failed %Rrc\n", rc));
    9701078        RTSemEventDestroy(pThread->hEvent);
     1079        pThread->hEvent        = NIL_RTSEMEVENT;
     1080        pThread->hWorkerThread = NIL_RTTHREAD;
     1081        pThread->u32State      = VBOXVDMATHREAD_STATE_TERMINATED;
    9711082    }
    9721083    else
    973         WARN(("RTSemEventCreate failed %d\n", rc));
    974 
    975     pThread->u32State = VBOXVDMATHREAD_STATE_TERMINATED;
    976 
     1084        WARN(("VBoxVDMAThreadCleanup failed %Rrc\n", rc));
    9771085    return rc;
    9781086}
    9791087
    980 DECLINLINE(int) VBoxVDMAThreadEventNotify(PVBOXVDMATHREAD pThread)
     1088/**
     1089 * Notifies the VDMA thread.
     1090 * @thread !VDMA
     1091 */
     1092static int VBoxVDMAThreadEventNotify(PVBOXVDMATHREAD pThread)
    9811093{
    9821094    int rc = RTSemEventSignal(pThread->hEvent);
     
    9851097}
    9861098
    987 DECLINLINE(int) VBoxVDMAThreadEventWait(PVBOXVDMATHREAD pThread, RTMSINTERVAL cMillies)
    988 {
    989     int rc = RTSemEventWait(pThread->hEvent, cMillies);
    990     AssertRC(rc);
    991     return rc;
    992 }
    993 
    994 int VBoxVDMAThreadTerm(PVBOXVDMATHREAD pThread, PFNVBOXVDMATHREAD_CHANGED pfnTerminated, void*pvTerminated, bool fNotify)
    995 {
    996     int rc;
    997     do
     1099/**
     1100 * State worker for VBVAEXHOSTCTL_TYPE_HH_ON_HGCM_UNLOAD &
     1101 * VBVAEXHOSTCTL_TYPE_GHH_DISABLE in vboxVDMACrHostCtlProcess(), and
     1102 * VBVAEXHOSTCTL_TYPE_GHH_DISABLE in vboxVDMACrGuestCtlProcess().
     1103 *
     1104 * @thread VDMA
     1105 */
     1106static int VBoxVDMAThreadTerm(PVBOXVDMATHREAD pThread, PFNVBOXVDMATHREAD_CHANGED pfnTerminated, void *pvTerminated, bool fNotify)
     1107{
     1108    for (;;)
    9981109    {
    9991110        uint32_t u32State = ASMAtomicUoReadU32(&pThread->u32State);
     
    10021113            case VBOXVDMATHREAD_STATE_CREATED:
    10031114                pThread->pfnChanged = pfnTerminated;
    1004                 pThread->pvChanged = pvTerminated;
     1115                pThread->pvChanged  = pvTerminated;
    10051116                ASMAtomicWriteU32(&pThread->u32State, VBOXVDMATHREAD_STATE_TERMINATING);
    10061117                if (fNotify)
    10071118                {
    1008                     rc = VBoxVDMAThreadEventNotify(pThread);
     1119                    int rc = VBoxVDMAThreadEventNotify(pThread);
    10091120                    AssertRC(rc);
    10101121                }
    10111122                return VINF_SUCCESS;
     1123
    10121124            case VBOXVDMATHREAD_STATE_TERMINATING:
    10131125            case VBOXVDMATHREAD_STATE_TERMINATED:
    1014             {
    10151126                WARN(("thread is marked to termination or terminated\nn"));
    10161127                return VERR_INVALID_STATE;
    1017             }
     1128
    10181129            case VBOXVDMATHREAD_STATE_CREATING:
    1019             {
    10201130                /* wait till the thread creation is completed */
    10211131                WARN(("concurrent thread create/destron\n"));
    10221132                RTThreadYield();
    10231133                continue;
    1024             }
     1134
    10251135            default:
    10261136                WARN(("invalid state"));
    10271137                return VERR_INVALID_STATE;
    10281138        }
    1029     } while (1);
    1030 
    1031     WARN(("should never be here\n"));
    1032     return VERR_INTERNAL_ERROR;
    1033 }
    1034 
    1035 static int vdmaVBVACtlSubmitSync(PVBOXVDMAHOST pVdma, VBVAEXHOSTCTL *pCtl, VBVAEXHOSTCTL_SOURCE enmSource);
    1036 
     1139    }
     1140}
     1141
     1142
     1143
     1144/*
     1145 *
     1146 *
     1147 * vboxVDMACrCtlPost / vboxVDMACrCtlPostAsync
     1148 * vboxVDMACrCtlPost / vboxVDMACrCtlPostAsync
     1149 * vboxVDMACrCtlPost / vboxVDMACrCtlPostAsync
     1150 *
     1151 *
     1152 */
     1153
     1154/** Completion callback for vboxVDMACrCtlPostAsync(). */
    10371155typedef DECLCALLBACK(void) FNVBOXVDMACRCTL_CALLBACK(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, void* pvContext);
     1156/** Pointer to a vboxVDMACrCtlPostAsync completion callback. */
    10381157typedef FNVBOXVDMACRCTL_CALLBACK *PFNVBOXVDMACRCTL_CALLBACK;
    10391158
     1159/**
     1160 * Private wrapper around VBOXVDMACMD_CHROMIUM_CTL.
     1161 */
    10401162typedef struct VBOXVDMACMD_CHROMIUM_CTL_PRIVATE
    10411163{
    1042     uint32_t cRefs;
    1043     int32_t rc;
    1044     PFNVBOXVDMACRCTL_CALLBACK pfnCompletion;
    1045     void *pvCompletion;
    1046     VBOXVDMACMD_CHROMIUM_CTL Cmd;
     1164    uint32_t                    uMagic; /**< VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC */
     1165    uint32_t                    cRefs;
     1166    int32_t volatile            rc;
     1167    PFNVBOXVDMACRCTL_CALLBACK   pfnCompletion;
     1168    void                       *pvCompletion;
     1169    RTSEMEVENT                  hEvtDone;
     1170    VBOXVDMACMD_CHROMIUM_CTL    Cmd;
    10471171} VBOXVDMACMD_CHROMIUM_CTL_PRIVATE, *PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE;
    1048 
    1049 # define VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(_p) ((PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE)(((uint8_t*)(_p)) - RT_OFFSETOF(VBOXVDMACMD_CHROMIUM_CTL_PRIVATE, Cmd)))
    1050 
     1172/** Magic number for VBOXVDMACMD_CHROMIUM_CTL_PRIVATE (Michael Wolff). */
     1173# define VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC         UINT32_C(0x19530827)
     1174
     1175/** Converts from a VBOXVDMACMD_CHROMIUM_CTL::Cmd pointer to a pointer to the
     1176 * containing structure. */
     1177# define VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(_p)  RT_FROM_MEMBER(pCmd, VBOXVDMACMD_CHROMIUM_CTL_PRIVATE, Cmd)
     1178
     1179/**
     1180 * Creates a VBOXVDMACMD_CHROMIUM_CTL_PRIVATE instance.
     1181 */
    10511182static PVBOXVDMACMD_CHROMIUM_CTL vboxVDMACrCtlCreate(VBOXVDMACMD_CHROMIUM_CTL_TYPE enmCmd, uint32_t cbCmd)
    10521183{
    1053     PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr = (PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE)RTMemAllocZ(cbCmd + RT_OFFSETOF(VBOXVDMACMD_CHROMIUM_CTL_PRIVATE, Cmd));
    1054     Assert(pHdr);
     1184    PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr;
     1185    pHdr = (PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE)RTMemAllocZ(cbCmd + RT_OFFSETOF(VBOXVDMACMD_CHROMIUM_CTL_PRIVATE, Cmd));
    10551186    if (pHdr)
    10561187    {
    1057         pHdr->cRefs = 1;
    1058         pHdr->rc = VERR_NOT_IMPLEMENTED;
     1188        pHdr->uMagic      = VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC;
     1189        pHdr->cRefs       = 1;
     1190        pHdr->rc          = VERR_NOT_IMPLEMENTED;
     1191        pHdr->hEvtDone    = NIL_RTSEMEVENT;
    10591192        pHdr->Cmd.enmType = enmCmd;
    1060         pHdr->Cmd.cbCmd = cbCmd;
     1193        pHdr->Cmd.cbCmd   = cbCmd;
    10611194        return &pHdr->Cmd;
    10621195    }
    1063 
    10641196    return NULL;
    10651197}
    10661198
    1067 DECLINLINE(void) vboxVDMACrCtlRelease (PVBOXVDMACMD_CHROMIUM_CTL pCmd)
     1199/**
     1200 * Releases a reference to a VBOXVDMACMD_CHROMIUM_CTL_PRIVATE instance.
     1201 */
     1202DECLINLINE(void) vboxVDMACrCtlRelease(PVBOXVDMACMD_CHROMIUM_CTL pCmd)
    10681203{
    10691204    PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr = VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(pCmd);
     1205    Assert(pHdr->uMagic == VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC);
     1206
    10701207    uint32_t cRefs = ASMAtomicDecU32(&pHdr->cRefs);
    10711208    if (!cRefs)
     1209    {
     1210        pHdr->uMagic = ~VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC;
     1211        if (pHdr->hEvtDone != NIL_RTSEMEVENT)
     1212        {
     1213            RTSemEventDestroy(pHdr->hEvtDone);
     1214            pHdr->hEvtDone = NIL_RTSEMEVENT;
     1215        }
    10721216        RTMemFree(pHdr);
    1073 }
    1074 
    1075 #if 0 /* unused */
     1217    }
     1218}
     1219
     1220/**
     1221 * Releases a reference to a VBOXVDMACMD_CHROMIUM_CTL_PRIVATE instance.
     1222 */
    10761223DECLINLINE(void) vboxVDMACrCtlRetain(PVBOXVDMACMD_CHROMIUM_CTL pCmd)
    10771224{
    10781225    PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr = VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(pCmd);
    1079     ASMAtomicIncU32(&pHdr->cRefs);
    1080 }
    1081 #endif /* unused */
    1082 
    1083 DECLINLINE(int) vboxVDMACrCtlGetRc (PVBOXVDMACMD_CHROMIUM_CTL pCmd)
     1226    Assert(pHdr->uMagic == VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC);
     1227
     1228    uint32_t cRefs = ASMAtomicIncU32(&pHdr->cRefs);
     1229    Assert(cRefs > 1);
     1230    Assert(cRefs < _1K);
     1231    RT_NOREF_PV(cRefs);
     1232}
     1233
     1234/**
     1235 * Gets the result from our private chromium control command.
     1236 *
     1237 * @returns status code.
     1238 * @param   pCmd                The command.
     1239 */
     1240DECLINLINE(int) vboxVDMACrCtlGetRc(PVBOXVDMACMD_CHROMIUM_CTL pCmd)
    10841241{
    10851242    PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr = VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(pCmd);
     1243    Assert(pHdr->uMagic == VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC);
    10861244    return pHdr->rc;
    10871245}
    10881246
    1089 static DECLCALLBACK(void) vboxVDMACrCtlCbSetEvent(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, void* pvContext)
    1090 {
     1247/**
     1248 * @interface_method_impl{PDMIDISPLAYVBVACALLBACKS,pfnCrHgsmiControlCompleteAsync,
     1249 *      Some indirect completion magic, you gotta love this code! }
     1250 */
     1251DECLCALLBACK(int) vboxVDMACrHgsmiControlCompleteAsync(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCmd, int rc)
     1252{
     1253    PVGASTATE                           pVGAState = PPDMIDISPLAYVBVACALLBACKS_2_PVGASTATE(pInterface);
     1254    PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE   pHdr      = VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(pCmd);
     1255    Assert(pHdr->uMagic == VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC);
     1256
     1257    pHdr->rc = rc;
     1258    if (pHdr->pfnCompletion)
     1259        pHdr->pfnCompletion(pVGAState, pCmd, pHdr->pvCompletion);
     1260    return VINF_SUCCESS;
     1261}
     1262
     1263/**
     1264 * @callback_method_impl{FNCRCTLCOMPLETION,
     1265 *      Completion callback for vboxVDMACrCtlPost. }
     1266 */
     1267static DECLCALLBACK(void) vboxVDMACrCtlCbSetEvent(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, void *pvContext)
     1268{
     1269    PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr = (PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE)pvContext;
     1270    Assert(pHdr == VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(pCmd));
     1271    Assert(pHdr->uMagic == VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_MAGIC);
    10911272    RT_NOREF(pVGAState, pCmd);
    1092     RTSemEventSignal((RTSEMEVENT)pvContext);
    1093 }
    1094 
    1095 # if 0 /** @todo vboxVDMACrCtlCbReleaseCmd is unused */
    1096 static DECLCALLBACK(void) vboxVDMACrCtlCbReleaseCmd(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, void* pvContext)
    1097 {
    1098     RT_NOREF(pVGAState, pvContext);
    1099     vboxVDMACrCtlRelease(pCmd);
    1100 }
    1101 # endif
    1102 
    1103 static int vboxVDMACrCtlPostAsync (PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, uint32_t cbCmd, PFNVBOXVDMACRCTL_CALLBACK pfnCompletion, void *pvCompletion)
     1273
     1274    int rc = RTSemEventSignal(pHdr->hEvtDone);
     1275    AssertRC(rc);
     1276
     1277    vboxVDMACrCtlRelease(&pHdr->Cmd);
     1278}
     1279
     1280/**
     1281 * Worker for vboxVDMACrCtlPost().
     1282 */
     1283static int vboxVDMACrCtlPostAsync(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, uint32_t cbCmd,
     1284                                  PFNVBOXVDMACRCTL_CALLBACK pfnCompletion, void *pvCompletion)
    11041285{
    11051286    if (   pVGAState->pDrv
     
    11081289        PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr = VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(pCmd);
    11091290        pHdr->pfnCompletion = pfnCompletion;
    1110         pHdr->pvCompletion = pvCompletion;
     1291        pHdr->pvCompletion  = pvCompletion;
    11111292        pVGAState->pDrv->pfnCrHgsmiControlProcess(pVGAState->pDrv, pCmd, cbCmd);
    11121293        return VINF_SUCCESS;
    11131294    }
    1114 # ifdef DEBUG_misha
    1115     Assert(0);
    1116 # endif
    11171295    return VERR_NOT_SUPPORTED;
    11181296}
     
    11231301static int vboxVDMACrCtlPost(PVGASTATE pVGAState, PVBOXVDMACMD_CHROMIUM_CTL pCmd, uint32_t cbCmd)
    11241302{
    1125     RTSEMEVENT hComplEvent;
    1126     int rc = RTSemEventCreate(&hComplEvent);
     1303    PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pHdr = VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(pCmd);
     1304
     1305    /* Allocate the semaphore. */
     1306    Assert(pHdr->hEvtDone == NIL_RTSEMEVENT);
     1307    int rc = RTSemEventCreate(&pHdr->hEvtDone);
     1308    AssertRCReturn(rc, rc);
     1309
     1310    /* Grab a reference for the completion routine. */
     1311    vboxVDMACrCtlRetain(&pHdr->Cmd);
     1312
     1313    /* Submit and wait for it. */
     1314    rc = vboxVDMACrCtlPostAsync(pVGAState, pCmd, cbCmd, vboxVDMACrCtlCbSetEvent, pHdr);
    11271315    AssertRC(rc);
    11281316    if (RT_SUCCESS(rc))
    1129     {
    1130         rc = vboxVDMACrCtlPostAsync(pVGAState, pCmd, cbCmd, vboxVDMACrCtlCbSetEvent, (void*)hComplEvent);
    1131 # ifdef DEBUG_misha
    1132         AssertRC(rc);
    1133 # endif
    1134         if (RT_SUCCESS(rc))
    1135         {
    1136             rc = RTSemEventWaitNoResume(hComplEvent, RT_INDEFINITE_WAIT);
    1137             AssertRC(rc);
    1138             if (RT_SUCCESS(rc))
    1139             {
    1140                 RTSemEventDestroy(hComplEvent);
    1141             }
    1142         }
    1143         else
    1144         {
    1145             /* the command is completed */
    1146             RTSemEventDestroy(hComplEvent);
    1147         }
    1148     }
     1317        rc = RTSemEventWaitNoResume(pHdr->hEvtDone, RT_INDEFINITE_WAIT);
     1318    else
     1319        vboxVDMACrCtlRelease(pCmd);
    11491320    return rc;
    11501321}
    11511322
     1323
     1324/**
     1325 * Structure for passing data between vboxVDMACrHgcmSubmitSync() and the
     1326 * completion routine vboxVDMACrHgcmSubmitSyncCompletion().
     1327 */
    11521328typedef struct VDMA_VBVA_CTL_CYNC_COMPLETION
    11531329{
    1154     int rc;
     1330    int volatile rc;
    11551331    RTSEMEVENT hEvent;
    11561332} VDMA_VBVA_CTL_CYNC_COMPLETION;
    11571333
    1158 static DECLCALLBACK(void) vboxVDMACrHgcmSubmitSyncCompletion(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd, int rc, void *pvCompletion)
    1159 {
    1160     RT_NOREF(pCmd, cbCmd);
     1334/**
     1335 * @callback_method_impl{FNCRCTLCOMPLETION,
     1336 *      Completion callback for vboxVDMACrHgcmSubmitSync() that signals the
     1337 *      waiting thread.}
     1338 */
     1339static DECLCALLBACK(void) vboxVDMACrHgcmSubmitSyncCompletion(struct VBOXCRCMDCTL *pCmd, uint32_t cbCmd, int rc, void *pvCompletion)
     1340{
    11611341    VDMA_VBVA_CTL_CYNC_COMPLETION *pData = (VDMA_VBVA_CTL_CYNC_COMPLETION*)pvCompletion;
    11621342    pData->rc = rc;
    11631343    rc = RTSemEventSignal(pData->hEvent);
    1164     if (!RT_SUCCESS(rc))
    1165         WARN(("RTSemEventSignal failed %d\n", rc));
    1166 }
    1167 
     1344    AssertLogRelRC(rc);
     1345
     1346    RT_NOREF(pCmd, cbCmd);
     1347}
     1348
     1349/**
     1350 * Worker for vboxVDMACrHgcmHandleEnable() and vdmaVBVAEnableProcess() that
     1351 * works pVGAState->pDrv->pfnCrHgcmCtlSubmit.
     1352 *
     1353 * @thread VDMA
     1354 */
    11681355static int vboxVDMACrHgcmSubmitSync(struct VBOXVDMAHOST *pVdma, VBOXCRCMDCTL* pCtl, uint32_t cbCtl)
    11691356{
     
    11731360    if (!RT_SUCCESS(rc))
    11741361    {
    1175         WARN(("RTSemEventCreate failed %d\n", rc));
     1362        WARN(("RTSemEventCreate failed %Rrc\n", rc));
    11761363        return rc;
    11771364    }
     
    11891376            if (!RT_SUCCESS(rc))
    11901377            {
    1191                 WARN(("pfnCrHgcmCtlSubmit command failed %d\n", rc));
     1378                WARN(("pfnCrHgcmCtlSubmit command failed %Rrc\n", rc));
    11921379            }
    11931380
    11941381        }
    11951382        else
    1196             WARN(("RTSemEventWait failed %d\n", rc));
     1383            WARN(("RTSemEventWait failed %Rrc\n", rc));
    11971384    }
    11981385    else
    1199         WARN(("pfnCrHgcmCtlSubmit failed %d\n", rc));
     1386        WARN(("pfnCrHgcmCtlSubmit failed %Rrc\n", rc));
    12001387
    12011388
     
    12051392}
    12061393
     1394
     1395/**
     1396 * Worker for vboxVDMAReset().
     1397 */
    12071398static int vdmaVBVACtlDisableSync(PVBOXVDMAHOST pVdma)
    12081399{
    12091400    VBVAEXHOSTCTL HCtl;
     1401    RT_ZERO(HCtl);
    12101402    HCtl.enmType = VBVAEXHOSTCTL_TYPE_GHH_DISABLE;
    12111403    int rc = vdmaVBVACtlSubmitSync(pVdma, &HCtl, VBVAEXHOSTCTL_SOURCE_HOST);
    1212     if (RT_FAILURE(rc))
    1213     {
    1214         Log(("vdmaVBVACtlSubmitSync failed %d\n", rc));
    1215         return rc;
    1216     }
    1217 
    1218     vgaUpdateDisplayAll(pVdma->pVGAState, /* fFailOnResize = */ false);
    1219 
    1220     return VINF_SUCCESS;
    1221 }
    1222 
    1223 static DECLCALLBACK(uint8_t*) vboxVDMACrHgcmHandleEnableRemainingHostCommand(HVBOXCRCMDCTL_REMAINING_HOST_COMMAND hClient, uint32_t *pcbCtl, int prevCmdRc)
     1404    if (RT_SUCCESS(rc))
     1405        vgaUpdateDisplayAll(pVdma->pVGAState, /* fFailOnResize = */ false);
     1406    else
     1407        Log(("vdmaVBVACtlSubmitSync failed %Rrc\n", rc));
     1408    return rc;
     1409}
     1410
     1411
     1412/**
     1413 * @interface_method_impl{VBOXCRCMDCTL_HGCMENABLE_DATA,pfnRHCmd,
     1414 *      Used by vboxVDMACrHgcmNotifyTerminatingCb() and called by
     1415 *      crVBoxServerCrCmdDisablePostProcess() during crServerTearDown() to drain
     1416 *      command queues or something.}
     1417 */
     1418static DECLCALLBACK(uint8_t *)
     1419vboxVDMACrHgcmHandleEnableRemainingHostCommand(HVBOXCRCMDCTL_REMAINING_HOST_COMMAND hClient, uint32_t *pcbCtl, int prevCmdRc)
    12241420{
    12251421    struct VBOXVDMAHOST *pVdma = hClient;
     1422
    12261423    if (!pVdma->pCurRemainingHostCtl)
    1227     {
    1228         /* disable VBVA, all subsequent host commands will go HGCM way */
    1229         VBoxVBVAExHSDisable(&pVdma->CmdVbva);
    1230     }
     1424        VBoxVBVAExHSDisable(&pVdma->CmdVbva); /* disable VBVA, all subsequent host commands will go HGCM way */
    12311425    else
    1232     {
    12331426        VBoxVBVAExHPDataCompleteCtl(&pVdma->CmdVbva, pVdma->pCurRemainingHostCtl, prevCmdRc);
    1234     }
    12351427
    12361428    pVdma->pCurRemainingHostCtl = VBoxVBVAExHPCheckHostCtlOnDisable(&pVdma->CmdVbva);
     
    12451437}
    12461438
     1439/**
     1440 * @interface_method_impl{VBOXCRCMDCTL_HGCMDISABLE_DATA,pfnNotifyTermDone,
     1441 *      Called by crServerTearDown().}
     1442 */
    12471443static DECLCALLBACK(void) vboxVDMACrHgcmNotifyTerminatingDoneCb(HVBOXCRCMDCTL_NOTIFY_TERMINATING hClient)
    12481444{
     
    12561452}
    12571453
    1258 static DECLCALLBACK(int) vboxVDMACrHgcmNotifyTerminatingCb(HVBOXCRCMDCTL_NOTIFY_TERMINATING hClient, VBOXCRCMDCTL_HGCMENABLE_DATA *pHgcmEnableData)
     1454/**
     1455 * @interface_method_impl{VBOXCRCMDCTL_HGCMDISABLE_DATA,pfnNotifyTerm,
     1456 *      Called by crServerTearDown().}
     1457 */
     1458static DECLCALLBACK(int) vboxVDMACrHgcmNotifyTerminatingCb(HVBOXCRCMDCTL_NOTIFY_TERMINATING hClient,
     1459                                                           VBOXCRCMDCTL_HGCMENABLE_DATA *pHgcmEnableData)
    12591460{
    12601461    struct VBOXVDMAHOST *pVdma = hClient;
     1462
    12611463    VBVAEXHOSTCTL HCtl;
     1464    RT_ZERO(HCtl);
    12621465    HCtl.enmType = VBVAEXHOSTCTL_TYPE_HH_ON_HGCM_UNLOAD;
    12631466    int rc = vdmaVBVACtlSubmitSync(pVdma, &HCtl, VBVAEXHOSTCTL_SOURCE_HOST);
    12641467
    1265     pHgcmEnableData->hRHCmd = pVdma;
     1468    pHgcmEnableData->hRHCmd   = pVdma;
    12661469    pHgcmEnableData->pfnRHCmd = vboxVDMACrHgcmHandleEnableRemainingHostCommand;
    12671470
    1268     if (RT_FAILURE(rc))
    1269     {
    1270         if (rc == VERR_INVALID_STATE)
    1271             rc = VINF_SUCCESS;
    1272         else
    1273             WARN(("vdmaVBVACtlSubmitSync failed %d\n", rc));
    1274     }
     1471    if (rc == VERR_INVALID_STATE)
     1472        rc = VINF_SUCCESS;
     1473    else if (RT_FAILURE(rc))
     1474        WARN(("vdmaVBVACtlSubmitSync failed %Rrc\n", rc));
    12751475
    12761476    return rc;
    12771477}
    12781478
     1479/**
     1480 * Worker for vdmaVBVAEnableProcess() and vdmaVBVADisableProcess().
     1481 *
     1482 * @thread VDMA
     1483 */
    12791484static int vboxVDMACrHgcmHandleEnable(struct VBOXVDMAHOST *pVdma)
    12801485{
    12811486    VBOXCRCMDCTL_ENABLE Enable;
    1282     Enable.Hdr.enmType = VBOXCRCMDCTL_TYPE_ENABLE;
    1283     Enable.Data.hRHCmd = pVdma;
     1487    RT_ZERO(Enable);
     1488    Enable.Hdr.enmType   = VBOXCRCMDCTL_TYPE_ENABLE;
     1489    Enable.Data.hRHCmd   = pVdma;
    12841490    Enable.Data.pfnRHCmd = vboxVDMACrHgcmHandleEnableRemainingHostCommand;
    12851491
     
    12931499
    12941500    Assert(VBoxVBVAExHSIsEnabled(&pVdma->CmdVbva));
    1295     WARN(("vboxVDMACrHgcmSubmitSync failed %d\n", rc));
    1296 
     1501    WARN(("vboxVDMACrHgcmSubmitSync failed %Rrc\n", rc));
    12971502    return rc;
    12981503}
    12991504
     1505/**
     1506 * Handles VBVAEXHOSTCTL_TYPE_GHH_ENABLE and VBVAEXHOSTCTL_TYPE_GHH_ENABLE_PAUSED
     1507 * for vboxVDMACrGuestCtlProcess().
     1508 *
     1509 * @thread VDMA
     1510 */
    13001511static int vdmaVBVAEnableProcess(struct VBOXVDMAHOST *pVdma, uint32_t u32Offset)
    13011512{
     
    13061517    }
    13071518
     1519/** @todo r=bird: This needs a closer look! */
    13081520    VBVABUFFER *pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost(pVdma->pHgsmi, u32Offset);
    13091521    if (!pVBVA)
    13101522    {
    1311         WARN(("invalid offset %d\n", u32Offset));
     1523        WARN(("invalid offset %d (%#x)\n", u32Offset, u32Offset));
    13121524        return VERR_INVALID_PARAMETER;
    13131525    }
     
    13231535
    13241536        VBOXCRCMDCTL_DISABLE Disable;
    1325         Disable.Hdr.enmType = VBOXCRCMDCTL_TYPE_DISABLE;
    1326         Disable.Data.hNotifyTerm = pVdma;
    1327         Disable.Data.pfnNotifyTerm = vboxVDMACrHgcmNotifyTerminatingCb;
     1537        Disable.Hdr.enmType            = VBOXCRCMDCTL_TYPE_DISABLE;
     1538        Disable.Data.hNotifyTerm       = pVdma;
     1539        Disable.Data.pfnNotifyTerm     = vboxVDMACrHgcmNotifyTerminatingCb;
    13281540        Disable.Data.pfnNotifyTermDone = vboxVDMACrHgcmNotifyTerminatingDoneCb;
    13291541        rc = vboxVDMACrHgcmSubmitSync(pVdma, &Disable.Hdr, sizeof (Disable));
     
    13321544            PVGASTATE pVGAState = pVdma->pVGAState;
    13331545            VBOXCRCMD_SVRENABLE_INFO Info;
    1334             Info.hCltScr = pVGAState->pDrv;
    1335             Info.pfnCltScrUpdateBegin = pVGAState->pDrv->pfnVBVAUpdateBegin;
     1546            Info.hCltScr                = pVGAState->pDrv;
     1547            Info.pfnCltScrUpdateBegin   = pVGAState->pDrv->pfnVBVAUpdateBegin;
    13361548            Info.pfnCltScrUpdateProcess = pVGAState->pDrv->pfnVBVAUpdateProcess;
    1337             Info.pfnCltScrUpdateEnd = pVGAState->pDrv->pfnVBVAUpdateEnd;
     1549            Info.pfnCltScrUpdateEnd     = pVGAState->pDrv->pfnVBVAUpdateEnd;
    13381550            rc = pVdma->CrSrvInfo.pfnEnable(pVdma->CrSrvInfo.hSvr, &Info);
    13391551            if (RT_SUCCESS(rc))
    13401552                return VINF_SUCCESS;
    1341             else
    1342                 WARN(("pfnEnable failed %d\n", rc));
    1343 
     1553
     1554            WARN(("pfnEnable failed %Rrc\n", rc));
    13441555            vboxVDMACrHgcmHandleEnable(pVdma);
    13451556        }
    13461557        else
    1347             WARN(("vboxVDMACrHgcmSubmitSync failed %d\n", rc));
     1558            WARN(("vboxVDMACrHgcmSubmitSync failed %Rrc\n", rc));
    13481559
    13491560        VBoxVBVAExHSDisable(&pVdma->CmdVbva);
    13501561    }
    13511562    else
    1352         WARN(("VBoxVBVAExHSEnable failed %d\n", rc));
     1563        WARN(("VBoxVBVAExHSEnable failed %Rrc\n", rc));
    13531564
    13541565    return rc;
    13551566}
    13561567
     1568/**
     1569 * Worker for several vboxVDMACrHostCtlProcess() commands.
     1570 *
     1571 * @returns IPRT status code.
     1572 * @param   pVdma           The VDMA channel.
     1573 * @param   fDoHgcmEnable   ???
     1574 * @thread  VDMA
     1575 */
    13571576static int vdmaVBVADisableProcess(struct VBOXVDMAHOST *pVdma, bool fDoHgcmEnable)
    13581577{
     
    13881607
    13891608            VBOXCRCMD_SVRENABLE_INFO Info;
    1390             Info.hCltScr = pVGAState->pDrv;
    1391             Info.pfnCltScrUpdateBegin = pVGAState->pDrv->pfnVBVAUpdateBegin;
     1609            Info.hCltScr                = pVGAState->pDrv;
     1610            Info.pfnCltScrUpdateBegin   = pVGAState->pDrv->pfnVBVAUpdateBegin;
    13921611            Info.pfnCltScrUpdateProcess = pVGAState->pDrv->pfnVBVAUpdateProcess;
    1393             Info.pfnCltScrUpdateEnd = pVGAState->pDrv->pfnVBVAUpdateEnd;
    1394             pVdma->CrSrvInfo.pfnEnable(pVdma->CrSrvInfo.hSvr, &Info);
     1612            Info.pfnCltScrUpdateEnd     = pVGAState->pDrv->pfnVBVAUpdateEnd;
     1613            pVdma->CrSrvInfo.pfnEnable(pVdma->CrSrvInfo.hSvr, &Info); /** @todo ignoring return code */
    13951614        }
    13961615    }
    13971616    else
    1398         WARN(("pfnDisable failed %d\n", rc));
     1617        WARN(("pfnDisable failed %Rrc\n", rc));
    13991618
    14001619    return rc;
    14011620}
    14021621
     1622/**
     1623 * Handles VBVAEXHOST_DATA_TYPE_HOSTCTL for vboxVDMAWorkerThread.
     1624 *
     1625 * @returns VBox status code.
     1626 * @param   pVdma                   The VDMA channel.
     1627 * @param   pCmd                    The control command to process.  Should be
     1628 *                                  safe, i.e. not shared with guest.
     1629 * @param   pfContinue              Where to return whether to continue or not.
     1630 * @thread  VDMA
     1631 */
    14031632static int vboxVDMACrHostCtlProcess(struct VBOXVDMAHOST *pVdma, VBVAEXHOSTCTL *pCmd, bool *pfContinue)
    14041633{
    14051634    *pfContinue = true;
    14061635
     1636    int rc;
    14071637    switch (pCmd->enmType)
    14081638    {
     1639        /*
     1640         * See vdmaVBVACtlOpaqueHostSubmit() and its callers.
     1641         */
    14091642        case VBVAEXHOSTCTL_TYPE_GHH_BE_OPAQUE:
    1410         {
    1411             if (!VBoxVBVAExHSIsEnabled(&pVdma->CmdVbva))
     1643            if (VBoxVBVAExHSIsEnabled(&pVdma->CmdVbva))
    14121644            {
     1645                if (pVdma->CrSrvInfo.pfnHostCtl)
     1646                    return pVdma->CrSrvInfo.pfnHostCtl(pVdma->CrSrvInfo.hSvr, pCmd->u.cmd.pu8Cmd, pCmd->u.cmd.cbCmd);
    14131647                WARN(("VBVAEXHOSTCTL_TYPE_GHH_BE_OPAQUE for disabled vdma VBVA\n"));
    1414                 return VERR_INVALID_STATE;
    14151648            }
    1416             if (!pVdma->CrSrvInfo.pfnHostCtl)
     1649            else
     1650                WARN(("VBVAEXHOSTCTL_TYPE_GHH_BE_OPAQUE for HGCM-less mode\n"));
     1651            return VERR_INVALID_STATE;
     1652
     1653        /*
     1654         * See vdmaVBVACtlDisableSync().
     1655         */
     1656        case VBVAEXHOSTCTL_TYPE_GHH_DISABLE:
     1657            rc = vdmaVBVADisableProcess(pVdma, true /* fDoHgcmEnable */);
     1658            if (RT_SUCCESS(rc))
     1659                rc = VBoxVDMAThreadTerm(&pVdma->Thread, NULL, NULL, false /* fNotify */ );
     1660            else
     1661                WARN(("vdmaVBVADisableProcess failed %Rrc\n", rc));
     1662            return rc;
     1663
     1664        /*
     1665         * See vboxVDMACrHgcmNotifyTerminatingCb().
     1666         */
     1667        case VBVAEXHOSTCTL_TYPE_HH_ON_HGCM_UNLOAD:
     1668            rc = vdmaVBVADisableProcess(pVdma, false /* fDoHgcmEnable */);
     1669            if (RT_SUCCESS(rc))
    14171670            {
    1418                 /* Should not be. */
    1419                 WARN(("VBVAEXHOSTCTL_TYPE_GHH_BE_OPAQUE for HGCM-less mode\n"));
    1420                 return VERR_INVALID_STATE;
     1671                rc = VBoxVDMAThreadTerm(&pVdma->Thread, NULL, NULL, true /* fNotify */);
     1672                if (RT_SUCCESS(rc))
     1673                    *pfContinue = false;
     1674                else
     1675                    WARN(("VBoxVDMAThreadTerm failed %Rrc\n", rc));
    14211676            }
    1422             return pVdma->CrSrvInfo.pfnHostCtl(pVdma->CrSrvInfo.hSvr, pCmd->u.cmd.pu8Cmd, pCmd->u.cmd.cbCmd);
    1423         }
    1424         case VBVAEXHOSTCTL_TYPE_GHH_DISABLE:
    1425         {
    1426             int rc = vdmaVBVADisableProcess(pVdma, true);
    1427             if (RT_FAILURE(rc))
     1677            else
     1678                WARN(("vdmaVBVADisableProcess failed %Rrc\n", rc));
     1679            return rc;
     1680
     1681        /*
     1682         * See vboxVDMASaveStateExecPerform().
     1683         */
     1684        case VBVAEXHOSTCTL_TYPE_HH_SAVESTATE:
     1685            rc = VBoxVBVAExHSSaveState(&pVdma->CmdVbva, pVdma->pVGAState->vram_ptrR3, pCmd->u.state.pSSM);
     1686            if (RT_SUCCESS(rc))
    14281687            {
    1429                 WARN(("vdmaVBVADisableProcess failed %d\n", rc));
    1430                 return rc;
     1688                VGA_SAVED_STATE_PUT_MARKER(pCmd->u.state.pSSM, 4);
     1689                if (pVdma->CrSrvInfo.pfnSaveState)
     1690                    rc = pVdma->CrSrvInfo.pfnSaveState(pVdma->CrSrvInfo.hSvr, pCmd->u.state.pSSM);
    14311691            }
    1432 
    1433             return VBoxVDMAThreadTerm(&pVdma->Thread, NULL, NULL, false);
    1434         }
    1435         case VBVAEXHOSTCTL_TYPE_HH_ON_HGCM_UNLOAD:
    1436         {
    1437             int rc = vdmaVBVADisableProcess(pVdma, false);
    1438             if (RT_FAILURE(rc))
     1692            else
     1693                WARN(("VBoxVBVAExHSSaveState failed %Rrc\n", rc));
     1694            return rc;
     1695
     1696        /*
     1697         * See vboxVDMASaveLoadExecPerform().
     1698         */
     1699        case VBVAEXHOSTCTL_TYPE_HH_LOADSTATE:
     1700            rc = VBoxVBVAExHSLoadState(&pVdma->CmdVbva, pVdma->pVGAState->vram_ptrR3, pCmd->u.state.pSSM, pCmd->u.state.u32Version);
     1701            if (RT_SUCCESS(rc))
    14391702            {
    1440                 WARN(("vdmaVBVADisableProcess failed %d\n", rc));
    1441                 return rc;
     1703                VGA_SAVED_STATE_GET_MARKER_RETURN_ON_MISMATCH(pCmd->u.state.pSSM, pCmd->u.state.u32Version, 4);
     1704                if (pVdma->CrSrvInfo.pfnLoadState)
     1705                {
     1706                    rc = pVdma->CrSrvInfo.pfnLoadState(pVdma->CrSrvInfo.hSvr, pCmd->u.state.pSSM, pCmd->u.state.u32Version);
     1707                    if (RT_FAILURE(rc))
     1708                        WARN(("pfnLoadState failed %Rrc\n", rc));
     1709                }
    14421710            }
    1443 
    1444             rc = VBoxVDMAThreadTerm(&pVdma->Thread, NULL, NULL, true);
    1445             if (RT_FAILURE(rc))
    1446             {
    1447                 WARN(("VBoxVDMAThreadTerm failed %d\n", rc));
    1448                 return rc;
    1449             }
    1450 
    1451             *pfContinue = false;
    1452             return VINF_SUCCESS;
    1453         }
    1454         case VBVAEXHOSTCTL_TYPE_HH_SAVESTATE:
     1711            else
     1712                WARN(("VBoxVBVAExHSLoadState failed %Rrc\n", rc));
     1713            return rc;
     1714
     1715        /*
     1716         * See vboxVDMASaveLoadDone().
     1717         */
     1718        case VBVAEXHOSTCTL_TYPE_HH_LOADSTATE_DONE:
    14551719        {
    14561720            PVGASTATE pVGAState = pVdma->pVGAState;
    1457             uint8_t * pu8VramBase = pVGAState->vram_ptrR3;
    1458             int rc = VBoxVBVAExHSSaveState(&pVdma->CmdVbva, pu8VramBase, pCmd->u.state.pSSM);
    1459             if (RT_FAILURE(rc))
    1460             {
    1461                 WARN(("VBoxVBVAExHSSaveState failed %d\n", rc));
    1462                 return rc;
    1463             }
    1464             VGA_SAVED_STATE_PUT_MARKER(pCmd->u.state.pSSM, 4);
    1465 
    1466             if (!pVdma->CrSrvInfo.pfnSaveState)
    1467             {
    1468                 /* Done. */
    1469                 return VINF_SUCCESS;
    1470             }
    1471 
    1472             return pVdma->CrSrvInfo.pfnSaveState(pVdma->CrSrvInfo.hSvr, pCmd->u.state.pSSM);
    1473         }
    1474         case VBVAEXHOSTCTL_TYPE_HH_LOADSTATE:
    1475         {
    1476             PVGASTATE pVGAState = pVdma->pVGAState;
    1477             uint8_t * pu8VramBase = pVGAState->vram_ptrR3;
    1478 
    1479             int rc = VBoxVBVAExHSLoadState(&pVdma->CmdVbva, pu8VramBase, pCmd->u.state.pSSM, pCmd->u.state.u32Version);
    1480             if (RT_FAILURE(rc))
    1481             {
    1482                 WARN(("VBoxVBVAExHSSaveState failed %d\n", rc));
    1483                 return rc;
    1484             }
    1485 
    1486             VGA_SAVED_STATE_GET_MARKER_RETURN_ON_MISMATCH(pCmd->u.state.pSSM, pCmd->u.state.u32Version, 4);
    1487             if (!pVdma->CrSrvInfo.pfnLoadState)
    1488             {
    1489                 /* Done. */
    1490                 return VINF_SUCCESS;
    1491             }
    1492 
    1493             rc = pVdma->CrSrvInfo.pfnLoadState(pVdma->CrSrvInfo.hSvr, pCmd->u.state.pSSM, pCmd->u.state.u32Version);
    1494             if (RT_FAILURE(rc))
    1495             {
    1496                 WARN(("pfnLoadState failed %d\n", rc));
    1497                 return rc;
    1498             }
    1499 
    1500             return VINF_SUCCESS;
    1501         }
    1502         case VBVAEXHOSTCTL_TYPE_HH_LOADSTATE_DONE:
    1503         {
    1504             PVGASTATE pVGAState = pVdma->pVGAState;
    1505 
    15061721            for (uint32_t i = 0; i < pVGAState->cMonitors; ++i)
    15071722            {
    15081723                VBVAINFOSCREEN CurScreen;
    1509                 VBVAINFOVIEW CurView;
    1510 
    1511                 int rc = VBVAGetInfoViewAndScreen(pVGAState, i, &CurView, &CurScreen);
    1512                 if (RT_FAILURE(rc))
    1513                 {
    1514                     WARN(("VBVAGetInfoViewAndScreen failed %d\n", rc));
    1515                     return rc;
    1516                 }
     1724                VBVAINFOVIEW   CurView;
     1725                rc = VBVAGetInfoViewAndScreen(pVGAState, i, &CurView, &CurScreen);
     1726                AssertLogRelMsgRCReturn(rc, ("VBVAGetInfoViewAndScreen [screen #%u] -> %#x\n", i, rc), rc);
    15171727
    15181728                rc = VBVAInfoScreen(pVGAState, &CurScreen);
    1519                 if (RT_FAILURE(rc))
    1520                 {
    1521                     WARN(("VBVAInfoScreen failed %d\n", rc));
    1522                     return rc;
    1523                 }
     1729                AssertLogRelMsgRCReturn(rc, ("VBVAInfoScreen [screen #%u] -> %#x\n", i, rc), rc);
    15241730            }
    15251731
    15261732            return VINF_SUCCESS;
    15271733        }
     1734
    15281735        default:
    15291736            WARN(("unexpected host ctl type %d\n", pCmd->enmType));
     
    15321739}
    15331740
     1741/**
     1742 * Worker for vboxVDMACrGuestCtlResizeEntryProcess.
     1743 *
     1744 * @returns VINF_SUCCESS or VERR_INVALID_PARAMETER.
     1745 * @param   pVGAState           The VGA device state.
     1746 * @param   pScreen             The screen info (safe copy).
     1747 */
    15341748static int vboxVDMASetupScreenInfo(PVGASTATE pVGAState, VBVAINFOSCREEN *pScreen)
    15351749{
    1536     const uint32_t u32ViewIndex = pScreen->u32ViewIndex;
    1537     const uint16_t u16Flags = pScreen->u16Flags;
    1538 
    1539     if (u16Flags & VBVA_SCREEN_F_DISABLED)
    1540     {
    1541         if (   u32ViewIndex < pVGAState->cMonitors
    1542             || u32ViewIndex == UINT32_C(0xFFFFFFFF))
     1750    const uint32_t idxView = pScreen->u32ViewIndex;
     1751    const uint16_t fFlags = pScreen->u16Flags;
     1752
     1753    if (fFlags & VBVA_SCREEN_F_DISABLED)
     1754    {
     1755        if (   idxView < pVGAState->cMonitors
     1756            || idxView == UINT32_C(0xFFFFFFFF))
    15431757        {
    15441758            RT_ZERO(*pScreen);
    1545             pScreen->u32ViewIndex = u32ViewIndex;
    1546             pScreen->u16Flags = VBVA_SCREEN_F_ACTIVE | VBVA_SCREEN_F_DISABLED;
     1759            pScreen->u32ViewIndex = idxView;
     1760            pScreen->u16Flags     = VBVA_SCREEN_F_ACTIVE | VBVA_SCREEN_F_DISABLED;
    15471761            return VINF_SUCCESS;
    15481762        }
     
    15501764    else
    15511765    {
    1552         if (u16Flags & VBVA_SCREEN_F_BLANK2)
    1553         {
    1554             if (   u32ViewIndex >= pVGAState->cMonitors
    1555                 && u32ViewIndex != UINT32_C(0xFFFFFFFF))
    1556             {
     1766        if (fFlags & VBVA_SCREEN_F_BLANK2)
     1767        {
     1768            if (   idxView >= pVGAState->cMonitors
     1769                && idxView != UINT32_C(0xFFFFFFFF))
    15571770                return VERR_INVALID_PARAMETER;
    1558             }
    15591771
    15601772            /* Special case for blanking using current video mode.
     
    15621774             */
    15631775            RT_ZERO(*pScreen);
    1564             pScreen->u32ViewIndex = u32ViewIndex;
    1565             pScreen->u16Flags = u16Flags;
     1776            pScreen->u32ViewIndex = idxView;
     1777            pScreen->u16Flags     = fFlags;
    15661778            return VINF_SUCCESS;
    15671779        }
    15681780
    1569         if (   u32ViewIndex < pVGAState->cMonitors
     1781        if (   idxView < pVGAState->cMonitors
    15701782            && pScreen->u16BitsPerPixel <= 32
    15711783            && pScreen->u32Width <= UINT16_MAX
     
    15781790                const uint64_t u64ScreenSize = (uint64_t)pScreen->u32LineSize * pScreen->u32Height;
    15791791                if (   pScreen->u32StartOffset <= pVGAState->vram_size
    1580                     && u64ScreenSize <= pVGAState->vram_size
     1792                    && u64ScreenSize           <= pVGAState->vram_size
    15811793                    && pScreen->u32StartOffset <= pVGAState->vram_size - (uint32_t)u64ScreenSize)
    1582                 {
    15831794                    return VINF_SUCCESS;
    1584                 }
    15851795            }
    15861796        }
    15871797    }
    15881798
     1799    LogFunc(("Failed\n"));
    15891800    return VERR_INVALID_PARAMETER;
    15901801}
     
    16221833        if (RT_FAILURE(rc))
    16231834        {
    1624             WARN(("pfnResize failed %d\n", rc));
     1835            WARN(("pfnResize failed %Rrc\n", rc));
    16251836            return rc;
    16261837        }
     
    16291840    /* A fake view which contains the current screen for the 2D VBVAInfoView. */
    16301841    VBVAINFOVIEW View;
    1631     View.u32ViewOffset = 0;
    1632     View.u32ViewSize = Screen.u32LineSize * Screen.u32Height + Screen.u32StartOffset;
     1842    View.u32ViewOffset    = 0;
     1843    View.u32ViewSize      = Screen.u32LineSize * Screen.u32Height + Screen.u32StartOffset;
    16331844    View.u32MaxScreenSize = Screen.u32LineSize * Screen.u32Height;
    16341845
     
    16361847
    16371848    for (int i = ASMBitFirstSet(aTargetMap, pVGAState->cMonitors);
    1638             i >= 0;
    1639             i = ASMBitNextSet(aTargetMap, pVGAState->cMonitors, i))
     1849         i >= 0;
     1850         i = ASMBitNextSet(aTargetMap, pVGAState->cMonitors, i))
    16401851    {
    16411852        Screen.u32ViewIndex = i;
     
    16591870            if (RT_FAILURE(rc))
    16601871            {
    1661                 WARN(("VBVAInfoView failed %d\n", rc));
     1872                WARN(("VBVAInfoView failed %Rrc\n", rc));
    16621873                break;
    16631874            }
     
    16671878        if (RT_FAILURE(rc))
    16681879        {
    1669             WARN(("VBVAInfoScreen failed %d\n", rc));
     1880            WARN(("VBVAInfoScreen failed %Rrc\n", rc));
    16701881            break;
    16711882        }
     
    16821893 * @returns VBox status code.
    16831894 * @param   pVdma               The VDMA channel.
    1684  * @param   pCmd                The command to process.
     1895 * @param   pCmd                The command to process.  Maybe safe (not shared
     1896 *                              with guest).
    16851897 *
    16861898 * @thread  VDMA
     
    17251937                        if (RT_FAILURE(rc))
    17261938                        {
    1727                             WARN(("vboxVDMACrGuestCtlResizeEntryProcess failed %d\n", rc));
     1939                            WARN(("vboxVDMACrGuestCtlResizeEntryProcess failed %Rrc\n", rc));
    17281940                            return rc;
    17291941                        }
     
    17571969                if (RT_SUCCESS(rc))
    17581970                    return VINF_SUCCESS;
    1759                 WARN(("VBoxVBVAExHPPause failed %d\n", rc));
     1971                WARN(("VBoxVBVAExHPPause failed %Rrc\n", rc));
    17601972            }
    17611973            else
    1762                 WARN(("vdmaVBVAEnableProcess failed %d\n", rc));
     1974                WARN(("vdmaVBVAEnableProcess failed %Rrc\n", rc));
    17631975            return rc;
    17641976        }
     
    17691981        case VBVAEXHOSTCTL_TYPE_GHH_DISABLE:
    17701982        {
    1771             int rc = vdmaVBVADisableProcess(pVdma, true);
     1983            int rc = vdmaVBVADisableProcess(pVdma, true /* fDoHgcmEnable */);
    17721984            if (RT_FAILURE(rc))
    17731985            {
    1774                 WARN(("vdmaVBVADisableProcess failed %d\n", rc));
     1986                WARN(("vdmaVBVADisableProcess failed %Rrc\n", rc));
    17751987                return rc;
    17761988            }
     
    17801992                              (PFNRT)vgaUpdateDisplayAll, 2, pVdma->pVGAState, /* fFailOnResize = */ false);
    17811993
    1782             return VBoxVDMAThreadTerm(&pVdma->Thread, NULL, NULL, false);
     1994            return VBoxVDMAThreadTerm(&pVdma->Thread, NULL, NULL, false /* fNotify */);
    17831995        }
    17841996
    17851997        default:
    1786             WARN(("unexpected ctl type %d\n", pCmd->enmType));
     1998            WARN(("unexpected ctl type %Rrc\n", pCmd->enmType));
    17871999            return VERR_INVALID_PARAMETER;
    17882000    }
     
    18142026        }
    18152027        else
    1816             WARN(("PDMDevHlpPhysGCPhys2CCPtrReadOnly failed %d", rc));
     2028            WARN(("PDMDevHlpPhysGCPhys2CCPtrReadOnly failed %Rrc", rc));
    18172029    }
    18182030    else
     
    18262038        }
    18272039        else
    1828             WARN(("PDMDevHlpPhysGCPhys2CCPtr failed %d", rc));
     2040            WARN(("PDMDevHlpPhysGCPhys2CCPtr failed %Rrc", rc));
    18292041    }
    18302042
     
    20162228            if (!RT_SUCCESS(rc))
    20172229            {
    2018                 WARN(("PDMDevHlpPhysGCPhys2CCPtrReadOnly failed %d\n", rc));
     2230                WARN(("PDMDevHlpPhysGCPhys2CCPtrReadOnly failed %Rrc\n", rc));
    20192231                return -1;
    20202232            }
     
    21252337}
    21262338
     2339/**
     2340 * Worker for vboxVDMAConstruct().
     2341 */
    21272342static int vboxVDMACrCtlHgsmiSetup(struct VBOXVDMAHOST *pVdma)
    21282343{
    2129     PVBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP pCmd = (PVBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP)
    2130             vboxVDMACrCtlCreate (VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP, sizeof (*pCmd));
    2131     int rc = VERR_NO_MEMORY;
     2344    PVBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP pCmd;
     2345    pCmd = (PVBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP)vboxVDMACrCtlCreate(VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP, sizeof(*pCmd));
     2346    int rc;
    21322347    if (pCmd)
    21332348    {
     
    21452360                pVdma->CrSrvInfo = pCmd->CrCmdServerInfo;
    21462361            else if (rc != VERR_NOT_SUPPORTED)
    2147                 WARN(("vboxVDMACrCtlGetRc returned %d\n", rc));
     2362                WARN(("vboxVDMACrCtlGetRc returned %Rrc\n", rc));
    21482363        }
    21492364        else
    2150             WARN(("vboxVDMACrCtlPost failed %d\n", rc));
     2365            WARN(("vboxVDMACrCtlPost failed %Rrc\n", rc));
    21512366
    21522367        vboxVDMACrCtlRelease(&pCmd->Hdr);
    21532368    }
     2369    else
     2370        rc = VERR_NO_MEMORY;
    21542371
    21552372    if (!RT_SUCCESS(rc))
     
    21582375    return rc;
    21592376}
    2160 
    2161 static int vboxVDMACmdExecBpbTransfer(PVBOXVDMAHOST pVdma, const VBOXVDMACMD_DMA_BPB_TRANSFER *pTransfer, uint32_t cbBuffer);
    21622377
    21632378/**
     
    22442459}
    22452460
    2246 int vboxVDMACrHgsmiCommandCompleteAsync(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, int rc)
    2247 {
    2248     PVGASTATE pVGAState = PPDMIDISPLAYVBVACALLBACKS_2_PVGASTATE(pInterface);
    2249     PHGSMIINSTANCE pIns = pVGAState->pHGSMI;
    2250     VBOXVDMACMD *pDmaHdr = VBOXVDMACMD_FROM_BODY(pCmd);
    2251     VBOXVDMACBUF_DR *pDr = VBOXVDMACBUF_DR_FROM_TAIL(pDmaHdr);
     2461/**
     2462 * @interface_method_impl{PDMIDISPLAYVBVACALLBACKS,pfnCrHgsmiControlCompleteAsync,
     2463 *      Some indirect completion magic, you gotta love this code! }
     2464 */
     2465DECLCALLBACK(int) vboxVDMACrHgsmiCommandCompleteAsync(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, int rc)
     2466{
     2467    PVGASTATE           pVGAState = PPDMIDISPLAYVBVACALLBACKS_2_PVGASTATE(pInterface);
     2468    PHGSMIINSTANCE      pIns      = pVGAState->pHGSMI;
     2469    VBOXVDMACMD        *pDmaHdr   = VBOXVDMACMD_FROM_BODY(pCmd);
     2470    VBOXVDMACBUF_DR    *pDr       = VBOXVDMACBUF_DR_FROM_TAIL(pDmaHdr);
     2471
    22522472    AssertRC(rc);
    22532473    pDr->rc = rc;
     
    22562476    rc = VBoxSHGSMICommandComplete(pIns, pDr);
    22572477    AssertRC(rc);
     2478
    22582479    return rc;
    2259 }
    2260 
    2261 int vboxVDMACrHgsmiControlCompleteAsync(PPDMIDISPLAYVBVACALLBACKS pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCmd, int rc)
    2262 {
    2263     PVGASTATE pVGAState = PPDMIDISPLAYVBVACALLBACKS_2_PVGASTATE(pInterface);
    2264     PVBOXVDMACMD_CHROMIUM_CTL_PRIVATE pCmdPrivate = VBOXVDMACMD_CHROMIUM_CTL_PRIVATE_FROM_CTL(pCmd);
    2265     pCmdPrivate->rc = rc;
    2266     if (pCmdPrivate->pfnCompletion)
    2267     {
    2268         pCmdPrivate->pfnCompletion(pVGAState, pCmd, pCmdPrivate->pvCompletion);
    2269     }
    2270     return VINF_SUCCESS;
    22712480}
    22722481
     
    26802889            }
    26812890            RT_FALL_THRU();
     2891
    26822892            case VBVAEXHOST_DATA_TYPE_NO_DATA:
    2683                 rc = VBoxVDMAThreadEventWait(&pVdma->Thread, RT_INDEFINITE_WAIT);
    2684                 AssertRC(rc);
     2893                rc = RTSemEventWaitNoResume(pVdma->Thread.hEvent, RT_INDEFINITE_WAIT);
     2894                AssertMsg(RT_SUCCESS(rc) || rc == VERR_INTERRUPTED, ("%Rrc\n", rc));
    26852895                break;
    26862896
     
    27022912 * @param   cbCmd       Number of valid bytes at @a pCmd.  This is at least
    27032913 *                      sizeof(VBOXVDMACBUF_DR).
     2914 * @thread  VDMA
    27042915 */
    27052916static void vboxVDMACommandProcess(PVBOXVDMAHOST pVdma, PVBOXVDMACBUF_DR pCmd, uint32_t cbCmd)
     
    28553066                    }
    28563067
    2857                     WARN(("RTCritSectInit failed %d\n", rc));
     3068                    WARN(("RTCritSectInit failed %Rrc\n", rc));
    28583069                    VBoxVBVAExHSTerm(&pVdma->CmdVbva);
    28593070                }
    28603071                else
    2861                     WARN(("VBoxVBVAExHSInit failed %d\n", rc));
     3072                    WARN(("VBoxVBVAExHSInit failed %Rrc\n", rc));
    28623073                RTSemEventMultiDestroy(pVdma->HostCrCtlCompleteEvent);
    28633074            }
    28643075            else
    2865                 WARN(("RTSemEventMultiCreate failed %d\n", rc));
     3076                WARN(("RTSemEventMultiCreate failed %Rrc\n", rc));
    28663077#endif
    28673078            /* the timer is cleaned up automatically */
     
    29863197#ifdef VBOX_WITH_CRHGSMI
    29873198
    2988 static DECLCALLBACK(void) vdmaVBVACtlSubmitSyncCompletion(VBVAEXHOSTCONTEXT *pVbva, struct VBVAEXHOSTCTL *pCtl, int rc, void *pvContext);
    2989 
    2990 static int vdmaVBVACtlSubmit(PVBOXVDMAHOST pVdma, VBVAEXHOSTCTL* pCtl, VBVAEXHOSTCTL_SOURCE enmSource,
    2991                              PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
    2992 {
    2993     int rc = VBoxVBVAExHCtlSubmit(&pVdma->CmdVbva, pCtl, enmSource, pfnComplete, pvComplete);
    2994     if (RT_SUCCESS(rc))
    2995     {
    2996         if (rc == VINF_SUCCESS)
    2997             return VBoxVDMAThreadEventNotify(&pVdma->Thread);
    2998         Assert(rc == VINF_ALREADY_INITIALIZED);
    2999     }
    3000     else
    3001         Log(("VBoxVBVAExHCtlSubmit failed %d\n", rc));
    3002 
    3003     return rc;
    3004 }
    3005 
    30063199/**
    30073200 * @callback_method_impl{FNVBVAEXHOSTCTL_COMPLETE,
     
    30403233
    30413234        VBoxVBVAExHCtlFree(&pVdma->CmdVbva, pHCtl);
    3042         Log(("vdmaVBVACtlSubmit failed rc %d\n", rc));
     3235        Log(("vdmaVBVACtlSubmit failed %Rrc\n", rc));
    30433236    }
    30443237    else
     
    30633256        return VINF_SUCCESS;
    30643257
    3065     WARN(("vdmaVBVACtlGenericSubmit failed %d\n", rc));
     3258    WARN(("vdmaVBVACtlGenericSubmit failed %Rrc\n", rc));
    30663259    pCtl->i32Result = rc;
    30673260    rc = VBoxSHGSMICommandComplete(pVdma->pHgsmi, pCtl);
     
    30993292            rc = pVGAState->pDrv->pfnCrHgcmCtlSubmit(pVGAState->pDrv, pCmd, cbCmd, pfnCompletion, pvCompletion);
    31003293            if (!RT_SUCCESS(rc))
    3101                 WARN(("pfnCrHgsmiControlProcess failed %d\n", rc));
     3294                WARN(("pfnCrHgsmiControlProcess failed %Rrc\n", rc));
    31023295
    31033296            return rc;
    31043297        }
    3105         WARN(("vdmaVBVACtlGenericSubmit failed %d\n", rc));
     3298        WARN(("vdmaVBVACtlGenericSubmit failed %Rrc\n", rc));
    31063299        return rc;
    31073300    }
     
    31203313        if (!RT_SUCCESS(rc))
    31213314        {
    3122             WARN(("pfnVBVAEnable failed %d\n", rc));
     3315            WARN(("pfnVBVAEnable failed %Rrc\n", rc));
    31233316            for (uint32_t j = 0; j < i; j++)
    31243317            {
     
    31713364        }
    31723365        else if (RT_FAILURE(rc))
    3173             WARN(("vboxVDMACrGuestCtlProcess failed %d\n", rc));
     3366            WARN(("vboxVDMACrGuestCtlProcess failed %Rrc\n", rc));
    31743367    }
    31753368    else
    3176         WARN(("vdmaVBVACtlThreadCreatedEnable is passed %d\n", rc));
     3369        WARN(("vdmaVBVACtlThreadCreatedEnable is passed %Rrc\n", rc));
    31773370
    31783371    VBoxVBVAExHPDataCompleteCtl(&pVdma->CmdVbva, pHCtl, rc);
     
    32243417    if (!RT_SUCCESS(rc))
    32253418    {
    3226         WARN(("RTSemEventCreate failed %d\n", rc));
     3419        WARN(("RTSemEventCreate failed %Rrc\n", rc));
    32273420        return rc;
    32283421    }
     
    32363429            rc = Data.rc;
    32373430            if (!RT_SUCCESS(rc))
    3238                 WARN(("vdmaVBVACtlSubmitSyncCompletion returned %d\n", rc));
     3431                WARN(("vdmaVBVACtlSubmitSyncCompletion returned %Rrc\n", rc));
    32393432        }
    32403433        else
    3241             WARN(("RTSemEventWait failed %d\n", rc));
     3434            WARN(("RTSemEventWait failed %Rrc\n", rc));
    32423435    }
    32433436    else
    3244         WARN(("vdmaVBVACtlSubmit failed %d\n", rc));
     3437        WARN(("vdmaVBVACtlSubmit failed %Rrc\n", rc));
    32453438
    32463439    RTSemEventDestroy(Data.hEvent);
     
    32763469        return VINF_SUCCESS;
    32773470
    3278     WARN(("vdmaVBVACtlSubmit failed rc %d\n", rc));
     3471    WARN(("vdmaVBVACtlSubmit failed rc %Rrc\n", rc));
    32793472    VBoxVBVAExHCtlFree(&pVdma->CmdVbva, pHCtl);
    32803473    return rc;
     
    33033496        return VINF_SUCCESS;
    33043497
    3305     WARN(("vdmaVBVACtlEnableDisableSubmitInternal failed %d\n", rc));
     3498    WARN(("vdmaVBVACtlEnableDisableSubmitInternal failed %Rrc\n", rc));
    33063499    pEnable->Hdr.i32Result = rc;
    33073500    rc = VBoxSHGSMICommandComplete(pVdma->pHgsmi, &pEnable->Hdr);
     
    33223515    rc = RTSemEventSignal(pData->hEvent);
    33233516    if (!RT_SUCCESS(rc))
    3324         WARN(("RTSemEventSignal failed %d\n", rc));
     3517        WARN(("RTSemEventSignal failed %Rrc\n", rc));
    33253518}
    33263519
     
    33333526    if (!RT_SUCCESS(rc))
    33343527    {
    3335         WARN(("RTSemEventCreate failed %d\n", rc));
     3528        WARN(("RTSemEventCreate failed %Rrc\n", rc));
    33363529        return rc;
    33373530    }
     
    33453538            rc = Data.rc;
    33463539            if (!RT_SUCCESS(rc))
    3347                 WARN(("vdmaVBVACtlSubmitSyncCompletion returned %d\n", rc));
     3540                WARN(("vdmaVBVACtlSubmitSyncCompletion returned %Rrc\n", rc));
    33483541        }
    33493542        else
    3350             WARN(("RTSemEventWait failed %d\n", rc));
     3543            WARN(("RTSemEventWait failed %Rrc\n", rc));
    33513544    }
    33523545    else
    3353         Log(("vdmaVBVACtlSubmit failed %d\n", rc));
     3546        Log(("vdmaVBVACtlSubmit failed %Rrc\n", rc));
    33543547
    33553548    RTSemEventDestroy(Data.hEvent);
     
    34633656    }
    34643657    else
    3465         WARN(("RTCritSectEnter failed %d\n", rc));
     3658        WARN(("RTCritSectEnter failed %Rrc\n", rc));
    34663659
    34673660    return rc;
     
    34923685        else
    34933686        {
    3494             WARN(("RTCritSectEnter failed %d\n", rc));
     3687            WARN(("RTCritSectEnter failed %Rrc\n", rc));
    34953688            break;
    34963689        }
     
    35183711    if (!RT_SUCCESS(rc))
    35193712    {
    3520         WARN(("vdmaVBVACtlOpaqueHostSubmit failed %d", rc));
     3713        WARN(("vdmaVBVACtlOpaqueHostSubmit failed %Rrc", rc));
    35213714        return rc;
    35223715    }
     
    35483741    rc = Data.rc;
    35493742    if (!RT_SUCCESS(rc))
    3550         WARN(("host call failed %d", rc));
     3743        WARN(("host call failed %Rrc", rc));
    35513744
    35523745    return rc;
     
    36543847    if (rc != VERR_INVALID_STATE)
    36553848    {
    3656         WARN(("vdmaVBVAPause failed %d\n", rc));
     3849        WARN(("vdmaVBVAPause failed %Rrc\n", rc));
    36573850        return rc;
    36583851    }
     
    36633856
    36643857    PVGASTATE pVGAState = pVdma->pVGAState;
    3665     PVBOXVDMACMD_CHROMIUM_CTL pCmd = (PVBOXVDMACMD_CHROMIUM_CTL)vboxVDMACrCtlCreate(
    3666             VBOXVDMACMD_CHROMIUM_CTL_TYPE_SAVESTATE_BEGIN, sizeof (*pCmd));
    3667     Assert(pCmd);
     3858    PVBOXVDMACMD_CHROMIUM_CTL pCmd;
     3859    pCmd = (PVBOXVDMACMD_CHROMIUM_CTL)vboxVDMACrCtlCreate(VBOXVDMACMD_CHROMIUM_CTL_TYPE_SAVESTATE_BEGIN, sizeof(*pCmd));
    36683860    if (pCmd)
    36693861    {
     
    36713863        AssertRC(rc);
    36723864        if (RT_SUCCESS(rc))
    3673         {
    36743865            rc = vboxVDMACrCtlGetRc(pCmd);
    3675         }
    36763866        vboxVDMACrCtlRelease(pCmd);
    36773867        return rc;
     
    36933883    if (rc != VERR_INVALID_STATE)
    36943884    {
    3695         WARN(("vdmaVBVAResume failed %d\n", rc));
     3885        WARN(("vdmaVBVAResume failed %Rrc\n", rc));
    36963886        return rc;
    36973887    }
     
    37023892
    37033893    PVGASTATE pVGAState = pVdma->pVGAState;
    3704     PVBOXVDMACMD_CHROMIUM_CTL pCmd = (PVBOXVDMACMD_CHROMIUM_CTL)vboxVDMACrCtlCreate(
    3705             VBOXVDMACMD_CHROMIUM_CTL_TYPE_SAVESTATE_END, sizeof (*pCmd));
     3894    PVBOXVDMACMD_CHROMIUM_CTL pCmd;
     3895    pCmd = (PVBOXVDMACMD_CHROMIUM_CTL)vboxVDMACrCtlCreate(VBOXVDMACMD_CHROMIUM_CTL_TYPE_SAVESTATE_END, sizeof(*pCmd));
    37063896    Assert(pCmd);
    37073897    if (pCmd)
     
    37103900        AssertRC(rc);
    37113901        if (RT_SUCCESS(rc))
    3712         {
    37133902            rc = vboxVDMACrCtlGetRc(pCmd);
    3714         }
    37153903        vboxVDMACrCtlRelease(pCmd);
    37163904        return rc;
     
    37963984/** @todo r=bird: BTW. would be great if you put in a couple of comments here and there explaining what
    37973985       * the purpose of this code is. */
    3798     VBVAEXHOSTCTL* pHCtl = VBoxVBVAExHCtlCreate(&pVdma->CmdVbva, VBVAEXHOSTCTL_TYPE_HH_LOADSTATE_DONE);
     3986    VBVAEXHOSTCTL *pHCtl = VBoxVBVAExHCtlCreate(&pVdma->CmdVbva, VBVAEXHOSTCTL_TYPE_HH_LOADSTATE_DONE);
    37993987    if (!pHCtl)
    38003988    {
     
    38113999    if (RT_FAILURE(rc))
    38124000    {
    3813         Log(("vdmaVBVACtlSubmit failed rc %d\n", rc));
     4001        Log(("vdmaVBVACtlSubmit failed %Rrc\n", rc));
    38144002        VBoxVBVAExHCtlFree(&pVdma->CmdVbva, pHCtl);
    38154003        return rc;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette