VirtualBox

Ignore:
Timestamp:
Apr 30, 2015 2:57:47 PM (10 years ago)
Author:
vboxsync
Message:

HGSMI: host command submission cleanup, removed obsolete code, comments.

File:
1 edited

Legend:

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

    r55421 r55560  
    199199    HGSMIINSTANCE *pIns;               /* Backlink to the HGSMI instance. */
    200200
    201 #if 0
    202     /* removed to allow saved state handling */
    203     /* The event which is signalled when the command has been processed by the host. */
    204     RTSEMEVENTMULTI hEvent;
    205 #endif
    206 
    207201    volatile uint32_t fl;              /* Status flags of the entry. */
    208202
    209203    HGSMIOFFSET offBuffer;             /* Offset of the HGSMI buffer header in the HGSMI host heap:
    210204                                        * [pIns->hostHeap.area.offBase .. offLast]. */
    211 
    212 #if 0
    213     /* removed to allow saved state handling */
    214     /* The command completion callback. */
    215     PFNHGSMIHOSTFIFOCALLBACK pfnCallback;
    216     void *pvCallback;
    217 #endif
    218 
    219205} HGSMIHOSTFIFOENTRY;
    220206
     
    399385
    400386            hgsmiFIFOUnlock(pIns);
    401 #if 0
    402             /* Inform the submitter. */
    403             if (pEntry->pfnCallback)
    404             {
    405                 pEntry->pfnCallback (pEntry->pvCallback);
    406             }
    407 #else
     387
    408388            hgsmiHostCommandFreeCallback(pEntry);
    409 #endif
     389
    410390            return true;
    411391        }
     
    501481    ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, (~flags));
    502482}
    503 
    504 #if 0
    505 static void hgsmiRaiseEvent (const HGSMIHOSTFIFOENTRY *pEntry)
    506 {
    507     int rc = RTSemEventMultiSignal (pEntry->hEvent);
    508     AssertRC(rc);
    509 }
    510 
    511 static int hgsmiWaitEvent (const HGSMIHOSTFIFOENTRY *pEntry)
    512 {
    513     int rc = RTSemEventMultiWait (pEntry->hEvent, RT_INDEFINITE_WAIT);
    514     AssertRC(rc);
    515     return rc;
    516 }
    517 #endif
    518483
    519484/*
     
    723688    {
    724689        pEntry->fl = HGSMI_F_HOST_FIFO_ALLOCATED;
    725 #if 0
    726         rc = RTSemEventMultiCreate (&pEntry->hEvent);
    727 
    728         if (RT_FAILURE (rc))
    729         {
    730             RTMemFree (pEntry);
    731         }
    732 #endif
    733690    }
    734691    else
     
    748705{
    749706    NOREF (pIns);
    750 #if 0
    751     if (pEntry->hEvent)
    752     {
    753         RTSemEventMultiDestroy (pEntry->hEvent);
    754     }
    755 #endif
    756707    RTMemFree (pEntry);
    757708}
     
    786737}
    787738
    788 static int hgsmiHostCommandFree (HGSMIINSTANCE *pIns,
    789                                                 void *pvData)
    790 {
    791     int rc = VINF_SUCCESS;
    792     if (HGSMIAreaContainsPointer(&pIns->hostHeap.area, pvData))
    793     {
    794         HGSMIHOSTFIFOENTRY *pEntry = NULL;
    795         HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
    796 
    797         rc = hgsmiFIFOLock (pIns);
    798         if(RT_SUCCESS(rc))
    799         {
    800             /* Search the Processed list for the given offBuffer. */
    801             HGSMIHOSTFIFOENTRY *pIter;
    802             RTListForEach(&pIns->hostFIFOProcessed, pIter, HGSMIHOSTFIFOENTRY, nodeEntry)
    803             {
    804                 Assert(pIter->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_PROCESSED));
    805 
    806                 if (pIter->offBuffer == offBuffer)
    807                 {
    808                     pEntry = pIter;
    809                     break;
    810                 }
     739static int hgsmiHostCommandFree(HGSMIINSTANCE *pIns,
     740                                void *pvData)
     741{
     742    HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
     743    HGSMIHOSTFIFOENTRY *pEntry = NULL;
     744
     745    int rc = hgsmiFIFOLock(pIns);
     746    if (RT_SUCCESS(rc))
     747    {
     748        /* Search the Processed list for the given offBuffer. */
     749        HGSMIHOSTFIFOENTRY *pIter;
     750        RTListForEach(&pIns->hostFIFOProcessed, pIter, HGSMIHOSTFIFOENTRY, nodeEntry)
     751        {
     752            Assert(pIter->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_PROCESSED));
     753
     754            if (pIter->offBuffer == offBuffer)
     755            {
     756                pEntry = pIter;
     757                break;
    811758            }
    812 
    813             if (pEntry)
    814             {
    815                 RTListNodeRemove(&pEntry->nodeEntry);
    816             }
    817             else
    818             {
    819                 AssertLogRelMsgFailed(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n",
    820                                        pIns->pszName, offBuffer));
    821             }
    822 
    823             hgsmiFIFOUnlock (pIns);
    824 
    825             rc = hgsmiHostHeapLock (pIns);
    826             if(RT_SUCCESS(rc))
    827             {
    828                 /* Deallocate the host heap memory. */
    829                 hgsmiHostHeapDataFree(&pIns->hostHeap, pvData);
    830 
    831                 hgsmiHostHeapUnlock(pIns);
    832             }
    833 
    834             if(pEntry)
    835             {
    836                 /* Deallocate the entry. */
    837                 hgsmiHostFIFOFree (pIns, pEntry);
    838             }
    839         }
    840 
    841     }
    842     else
    843     {
    844         AssertLogRelMsgFailed(("HGSMI[%s]: the host frees invalid FIFO entry: %p\n",
    845                                pIns->pszName, pvData));
    846         rc = VERR_INVALID_POINTER;
    847     }
    848     return rc;
    849 }
    850 
    851 #if 0
    852 static DECLCALLBACK(void) hgsmiHostCommandRaiseEventCallback (void *pvCallback)
     759        }
     760
     761        if (pEntry)
     762        {
     763            RTListNodeRemove(&pEntry->nodeEntry);
     764        }
     765        else
     766        {
     767            AssertLogRelMsgFailed(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n",
     768                                   pIns->pszName, offBuffer));
     769        }
     770
     771        hgsmiFIFOUnlock (pIns);
     772
     773        rc = hgsmiHostHeapLock (pIns);
     774        if (RT_SUCCESS(rc))
     775        {
     776            /* Deallocate the host heap memory. */
     777            hgsmiHostHeapDataFree(&pIns->hostHeap, pvData);
     778
     779            hgsmiHostHeapUnlock(pIns);
     780        }
     781
     782        if (pEntry)
     783        {
     784            /* Deallocate the entry. */
     785            hgsmiHostFIFOFree(pIns, pEntry);
     786        }
     787    }
     788
     789    return rc;
     790}
     791
     792static DECLCALLBACK(void) hgsmiHostCommandFreeCallback (void *pvCallback)
    853793{
    854794    /* Guest has processed the command. */
     
    858798
    859799    /* This is a simple callback, just signal the event. */
    860     hgsmiRaiseEvent (pEntry);
    861 }
    862 #endif
    863 
    864 static DECLCALLBACK(void) hgsmiHostCommandFreeCallback (void *pvCallback)
    865 {
    866     /* Guest has processed the command. */
    867     HGSMIHOSTFIFOENTRY *pEntry = (HGSMIHOSTFIFOENTRY *)pvCallback;
    868 
    869     Assert(pEntry->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_PROCESSED));
    870 
    871     /* This is a simple callback, just signal the event. */
    872800    hgsmiHostCommandFreeByEntry (pEntry);
    873801}
    874802
    875 static int hgsmiHostCommandWrite (HGSMIINSTANCE *pIns, HGSMIOFFSET offMem
    876 #if 0
    877         , PFNHGSMIHOSTFIFOCALLBACK pfnCallback, void **ppvContext
    878 #endif
    879         )
    880 {
     803static int hgsmiHostCommandWrite(HGSMIINSTANCE *pIns,
     804                                 HGSMIOFFSET offBuffer)
     805{
     806    AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
     807
    881808    HGSMIHOSTFIFOENTRY *pEntry;
    882 
    883     AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
    884     int rc = hgsmiHostFIFOAlloc (pIns, &pEntry);
    885 
    886     if (RT_SUCCESS (rc))
     809    int rc = hgsmiHostFIFOAlloc(pIns, &pEntry);
     810
     811    if (RT_SUCCESS(rc))
    887812    {
    888813        /* Initialize the new entry and add it to the FIFO. */
     
    890815
    891816        pEntry->pIns = pIns;
    892         pEntry->offBuffer = offMem;
    893 #if 0
    894         pEntry->pfnCallback = pfnCallback;
    895         pEntry->pvCallback = pEntry;
    896 #endif
     817        pEntry->offBuffer = offBuffer;
    897818
    898819        rc = hgsmiFIFOLock(pIns);
    899         if (RT_SUCCESS (rc))
    900         {
     820        if (RT_SUCCESS(rc))
     821        {
     822            ASMAtomicOrU32(&pIns->pHGFlags->u32HostFlags, HGSMIHOSTFLAGS_COMMANDS_PENDING);
    901823            RTListAppend(&pIns->hostFIFO, &pEntry->nodeEntry);
    902             ASMAtomicOrU32(&pIns->pHGFlags->u32HostFlags, HGSMIHOSTFLAGS_COMMANDS_PENDING);
    903824
    904825            hgsmiFIFOUnlock(pIns);
    905 #if 0
    906             *ppvContext = pEntry;
    907 #endif
    908826        }
    909827        else
     
    920838 * Append the shared memory block to the FIFO, inform the guest.
    921839 *
    922  * @param pIns       Pointer to HGSMI instance,
    923  * @param pv         The HC memory pointer to the information.
    924  * @param ppvContext Where to store a pointer, which will allow the caller
    925  *                   to wait for the command completion.
    926  * @param            bDoIrq specifies whether the guest interrupt should be generated,
    927  * i.e. in case the command is not urgent(e.g. some guest command completion notification that does not require post-processing)
    928  * the command could be posted without raising an irq.
    929  *
     840 * @param pIns       Pointer to HGSMI instance.
     841 * @param pvData     The shared memory block data pointer.
     842 * @param fDoIrq     Whether the guest interrupt should be generated, i.e. if the command is not
     843 *                   urgent (e.g. some guest command completion notification that does not require
     844 *                   post-processing) the command could be submitted without raising an irq.
    930845 * @thread EMT
    931846 */
    932 static int hgsmiHostCommandProcess (HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer,
    933 #if 0
    934         PFNHGSMIHOSTFIFOCALLBACK pfnCallback, void **ppvContext,
    935 #endif
    936         bool bDoIrq)
    937 {
    938 //    HGSMIOFFSET offMem;
    939 //
    940 //    int rc = hgsmiCheckMemPtr (pIns, pvMem, &offMem);
    941 //
    942 //    if (RT_SUCCESS (rc))
    943 //    {
    944         /* Append the command to FIFO. */
    945         int rc = hgsmiHostCommandWrite (pIns, offBuffer
    946 #if 0
    947                 , pfnCallback, ppvContext
    948 #endif
    949                 );
    950 
    951         if (RT_SUCCESS (rc))
    952         {
    953             if(bDoIrq)
    954             {
    955                 /* Now guest can read the FIFO, the notification is informational. */
    956                 hgsmiNotifyGuest (pIns);
    957             }
    958         }
    959 //    }
    960 //    else
    961 //    {
    962 //        AssertFailed ();
    963 //    }
    964 
    965     return rc;
    966 }
    967 #if 0
    968 static void hgsmiWait (void *pvContext)
    969 {
    970     HGSMIHOSTFIFOENTRY *pEntry = (HGSMIHOSTFIFOENTRY *)pvContext;
    971 
    972     for (;;)
    973     {
    974         hgsmiWaitEvent (pEntry);
    975 
    976         if (pEntry->fl & (HGSMI_F_HOST_FIFO_PROCESSED | HGSMI_F_HOST_FIFO_CANCELED))
    977         {
    978             return;
    979         }
    980     }
    981 }
    982 #endif
     847static int hgsmiHostCommandSubmit(HGSMIINSTANCE *pIns,
     848                                  void *pvData,
     849                                  bool fDoIrq)
     850{
     851    /* Append the command to FIFO. */
     852    HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
     853    int rc = hgsmiHostCommandWrite(pIns, offBuffer);
     854    if (RT_SUCCESS(rc))
     855    {
     856        if (fDoIrq)
     857        {
     858            /* Now guest can read the FIFO, the notification is informational. */
     859            hgsmiNotifyGuest(pIns);
     860        }
     861    }
     862
     863    return rc;
     864}
     865
    983866/**
    984867 * Allocate a shared memory buffer. The host can write command/data to the memory.
     
    993876 * @param u16ChannelInfo Command parameter.
    994877 */
    995 int HGSMIHostCommandAlloc (HGSMIINSTANCE *pIns,
    996                            void **ppvData,
    997                            HGSMISIZE cbData,
    998                            uint8_t u8Channel,
    999                            uint16_t u16ChannelInfo)
    1000 {
    1001     LogFlowFunc (("pIns = %p, cbData = 0x%08X(%d)\n", pIns, cbData, cbData));
    1002 
    1003     int rc = hgsmiHostHeapLock (pIns);
    1004     if(RT_SUCCESS(rc))
     878int HGSMIHostCommandAlloc(HGSMIINSTANCE *pIns,
     879                          void **ppvData,
     880                          HGSMISIZE cbData,
     881                          uint8_t u8Channel,
     882                          uint16_t u16ChannelInfo)
     883{
     884    LogFlowFunc(("pIns = %p, cbData = %d, u8Channel %d, u16ChannelInfo 0x%04X\n",
     885                 pIns, cbData, u8Channel, u16ChannelInfo));
     886
     887    int rc = hgsmiHostHeapLock(pIns);
     888    if (RT_SUCCESS(rc))
    1005889    {
    1006890        void *pvData = hgsmiHostHeapDataAlloc(&pIns->hostHeap,
     
    1016900        else
    1017901        {
    1018             LogRel(("HGSMI[%s]: host heap allocation failed %dbytes\n", pIns->pszName, cbData));
     902            LogRel(("HGSMI[%s]: host heap allocation failed %d bytes\n", pIns->pszName, cbData));
    1019903            rc = VERR_NO_MEMORY;
    1020904        }
     
    1033917 * @param pIns   HGSMI instance,
    1034918 * @param pvData The pointer returned by 'HGSMIHostCommandAlloc'.
    1035  * @param bDoIrq Specifies whether the guest interrupt should be generated.
     919 * @param fDoIrq Specifies whether the guest interrupt should be generated.
    1036920 *               In case the command is not urgent (e.g. some guest command
    1037921 *               completion notification that does not require post-processing)
    1038922 *               the command could be posted without raising an irq.
    1039923 */
    1040 int HGSMIHostCommandProcessAndFreeAsynch (PHGSMIINSTANCE pIns,
    1041                              void *pvData,
    1042                              bool bDoIrq)
    1043 {
    1044     LogFlowFunc(("pIns = %p, pvData = %p\n", pIns, pvData));
    1045 
    1046 #if 0
    1047     void *pvContext = NULL;
    1048 #endif
    1049 
    1050     HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
    1051 
    1052     int rc = hgsmiHostCommandProcess (pIns, offBuffer,
    1053 #if 0
    1054             hgsmiHostCommandFreeCallback, &pvContext,
    1055 #endif
    1056             bDoIrq);
    1057     AssertRC (rc);
     924int HGSMIHostCommandSubmitAndFreeAsynch(PHGSMIINSTANCE pIns,
     925                                        void *pvData,
     926                                        bool fDoIrq)
     927{
     928    LogFlowFunc(("pIns = %p, pvData = %p, fDoIrq = %d\n", pIns, pvData, fDoIrq));
     929
     930    int rc;
     931    if (HGSMIAreaContainsPointer(&pIns->hostHeap.area, pvData))
     932    {
     933        rc = hgsmiHostCommandSubmit(pIns, pvData, fDoIrq);
     934    }
     935    else
     936    {
     937        AssertLogRelMsgFailed(("HGSMI[%s]: host submits invalid command %p/%p\n",
     938                               pIns->pszName, pvData, pIns->hostHeap.area.pu8Base));
     939        rc = VERR_INVALID_POINTER;
     940    }
    1058941
    1059942    LogFlowFunc(("rc = %Rrc\n", rc));
    1060 
    1061     return rc;
    1062 }
    1063 #if 0
    1064 /**
    1065  * Submit the shared memory block to the guest.
    1066  *
    1067  * @param pIns  Pointer to HGSMI instance,
    1068  * @param pvMem The pointer returned by 'HGSMIHostCommandAlloc'.
    1069  */
    1070 int HGSMIHostCommandProcess (HGSMIINSTANCE *pIns,
    1071                              void *pvMem)
    1072 {
    1073     LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
    1074 
    1075     VM_ASSERT_OTHER_THREAD(pIns->pVM);
    1076 
    1077     void *pvContext = NULL;
    1078 
    1079     HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
    1080 
    1081 //    /* Have to forward to EMT because FIFO processing is there. */
    1082 //    int rc = VMR3ReqCallVoid (pIns->pVM, &pReq, RT_INDEFINITE_WAIT,
    1083 //                              (PFNRT) hgsmiHostCommandProcess,
    1084 //                              3, pIns, offBuffer, &pvContext);
    1085 
    1086     int rc = hgsmiHostCommandProcess (pIns, offBuffer,
    1087 #if 0
    1088             hgsmiHostCommandRaiseEventCallback, &pvContext,
    1089 #endif
    1090             true);
    1091     AssertReleaseRC (rc);
    1092 
    1093     if (RT_SUCCESS (rc))
    1094     {
    1095         /* Wait for completion. */
    1096         hgsmiWait (pvContext);
    1097     }
    1098 
    1099     LogFlowFunc(("rc = %Rrc\n", rc));
    1100 
    1101     return rc;
    1102 }
    1103 #endif
     943    return rc;
     944}
    1104945
    1105946/**
    1106947 * Free the shared memory block.
    1107948 *
    1108  * @param pIns  Pointer to HGSMI instance,
    1109  * @param pvMem The pointer returned by 'HGSMIHostCommandAlloc'.
     949 * @param pIns   Pointer to HGSMI instance,
     950 * @param pvData The pointer returned by 'HGSMIHostCommandAlloc'.
    1110951 */
    1111 int HGSMIHostCommandFree (HGSMIINSTANCE *pIns,
    1112                           void *pvMem)
    1113 {
    1114     LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
    1115 
    1116     return hgsmiHostCommandFree (pIns, pvMem);
     952int HGSMIHostCommandFree(HGSMIINSTANCE *pIns,
     953                         void *pvData)
     954{
     955    LogFlowFunc(("pIns = %p, pvData = %p\n", pIns, pvData));
     956
     957    int rc;
     958    if (HGSMIAreaContainsPointer(&pIns->hostHeap.area, pvData))
     959    {
     960        rc = hgsmiHostCommandFree(pIns, pvData);
     961    }
     962    else
     963    {
     964        AssertLogRelMsgFailed(("HGSMI[%s]: the host frees invalid FIFO entry %p/%p\n",
     965                               pIns->pszName, pvData, pIns->hostHeap.area.pu8Base));
     966        rc = VERR_INVALID_POINTER;
     967    }
     968
     969    LogFlowFunc(("rc = %Rrc\n", rc));
     970    return rc;
    1117971}
    1118972
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