VirtualBox

Changeset 73331 in vbox for trunk/src


Ignore:
Timestamp:
Jul 23, 2018 3:23:48 PM (6 years ago)
Author:
vboxsync
Message:

Serial: Fixes

Location:
trunk/src/VBox/Devices/Serial
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Serial/DrvCharNew.cpp

    r73299 r73331  
    114114static DECLCALLBACK(int) drvCharDataAvailWrNotify(PPDMISERIALCONNECTOR pInterface, size_t cbAvail)
    115115{
     116    LogFlowFunc(("pInterface=%#p cbAvail=%zu\n", pInterface, cbAvail));
    116117    PDRVCHAR pThis = RT_FROM_MEMBER(pInterface, DRVCHAR, ISerialConnector);
    117118
     
    130131static DECLCALLBACK(int) drvCharReadRdr(PPDMISERIALCONNECTOR pInterface, void *pvBuf, size_t cbRead, size_t *pcbRead)
    131132{
     133    LogFlowFunc(("pInterface=%#p pvBuf=%#p cbRead=%zu pcbRead=%#p\n", pInterface, pvBuf, cbRead, pcbRead));
    132134    PDRVCHAR pThis = RT_FROM_MEMBER(pInterface, DRVCHAR, ISerialConnector);
    133135    int rc = VINF_SUCCESS;
     
    136138    size_t cbToRead = RT_MIN(cbRead, pThis->cbRemaining);
    137139    memcpy(pvBuf, pThis->pbBuf, cbToRead);
     140
     141    pThis->pbBuf += cbToRead;
    138142    *pcbRead = cbToRead;
    139143    size_t cbOld = ASMAtomicSubZ(&pThis->cbRemaining, cbToRead);
     
    142146    STAM_COUNTER_ADD(&pThis->StatBytesRead, cbToRead);
    143147
     148    LogFlowFunc(("-> %Rrc\n", rc));
    144149    return rc;
    145150}
     
    230235                {
    231236                    /* Stuff as much data into the TX buffer as we can. */
    232                     size_t cbToFetch = RT_ELEMENTS(pThis->abTxBuf) - pThis->cbTxUsed;
     237                    size_t cbToFetch = RT_MIN(RT_ELEMENTS(pThis->abTxBuf) - pThis->cbTxUsed, pThis->cbAvailWr);
    233238                    size_t cbFetched = 0;
    234239                    rc = pThis->pDrvSerialPort->pfnReadWr(pThis->pDrvSerialPort, &pThis->abTxBuf[pThis->cbTxUsed], cbToFetch,
     
    239244                    {
    240245                        ASMAtomicSubZ(&pThis->cbAvailWr, cbFetched);
    241                         pThis->cbTxUsed += cbFetched;
     246                        pThis->cbTxUsed  += cbFetched;
    242247                    }
    243248                    else
     
    281286                    break;
    282287                }
    283                 pThis->pbBuf = &pThis->abBuffer[0];
    284                 ASMAtomicWriteZ(&pThis->cbRemaining, cbRead);
    285                 /* Notify the upper device/driver. */
    286                 rc = pThis->pDrvSerialPort->pfnDataAvailRdrNotify(pThis->pDrvSerialPort, cbRead);
     288
     289                if (cbRead)
     290                {
     291                    pThis->pbBuf = &pThis->abBuffer[0];
     292                    ASMAtomicWriteZ(&pThis->cbRemaining, cbRead);
     293                    /* Notify the upper device/driver. */
     294                    rc = pThis->pDrvSerialPort->pfnDataAvailRdrNotify(pThis->pDrvSerialPort, cbRead);
     295                }
    287296            }
    288297        }
  • trunk/src/VBox/Devices/Serial/DrvHostSerialNew.cpp

    r73243 r73331  
    394394                {
    395395                    /* Stuff as much data into the TX buffer as we can. */
    396                     size_t cbToFetch = RT_ELEMENTS(pThis->abTxBuf) - pThis->cbTxUsed;
     396                    size_t cbToFetch = RT_MIN(RT_ELEMENTS(pThis->abTxBuf) - pThis->cbTxUsed, pThis->cbAvailWr);
    397397                    size_t cbFetched = 0;
    398398                    rc = pThis->pDrvSerialPort->pfnReadWr(pThis->pDrvSerialPort, &pThis->abTxBuf[pThis->cbTxUsed], cbToFetch,
     
    403403                    {
    404404                        ASMAtomicSubZ(&pThis->cbAvailWr, cbFetched);
    405                         pThis->cbTxUsed += cbFetched;
     405                        pThis->cbTxUsed  += cbFetched;
    406406                    }
    407407                    else
  • trunk/src/VBox/Devices/Serial/UartCore.cpp

    r73306 r73331  
    614614    while (cbFilled < cbFill)
    615615    {
    616         size_t cbThisRead = RT_MIN(cbFill - cbFilled, (uint8_t)(pFifo->cbMax - pFifo->offWrite));
     616        size_t cbThisRead = cbFill - cbFilled;
     617
     618        if (pFifo->offRead <= pFifo->offWrite)
     619            cbThisRead = RT_MIN(cbThisRead, (uint8_t)(pFifo->cbMax - pFifo->offWrite));
     620        else
     621            cbThisRead = RT_MIN(cbThisRead, (uint8_t)(pFifo->offRead - pFifo->offWrite));
     622
    617623        size_t cbRead = 0;
    618624        int rc = pThis->pDrvSerial->pfnReadRdr(pThis->pDrvSerial, &pFifo->abBuf[pFifo->offWrite], cbThisRead, &cbRead);
     
    670676    else
    671677        uartR3ByteFetch(pThis);
     678}
     679
     680
     681/**
     682 * Reset the transmit/receive related bits to the standard values
     683 * (after a detach/attach/reset event).
     684 *
     685 * @returns nothing.
     686 * @param   pThis               The serial port instance.
     687 */
     688static void uartR3XferReset(PUARTCORE pThis)
     689{
     690    pThis->uRegLsr = UART_REG_LSR_THRE | UART_REG_LSR_TEMT;
     691
     692    uartFifoClear(&pThis->FifoXmit);
     693    uartFifoClear(&pThis->FifoRecv);
     694    uartR3ParamsUpdate(pThis);
     695    uartIrqUpdate(pThis);
     696
     697    if (pThis->pDrvSerial)
     698    {
     699        /* Set the modem lines to reflect the current state. */
     700        int rc = pThis->pDrvSerial->pfnChgModemLines(pThis->pDrvSerial, false /*fRts*/, false /*fDtr*/);
     701        if (RT_FAILURE(rc))
     702            LogRel(("Serial#%d: Failed to set modem lines with %Rrc during reset\n",
     703                    pThis->pDevInsR3->iInstance, rc));
     704
     705        uint32_t fStsLines = 0;
     706        rc = pThis->pDrvSerial->pfnQueryStsLines(pThis->pDrvSerial, &fStsLines);
     707        if (RT_SUCCESS(rc))
     708            uartR3StsLinesUpdate(pThis, fStsLines);
     709        else
     710            LogRel(("Serial#%d: Failed to query status line status with %Rrc during reset\n",
     711                    pThis->pDevInsR3->iInstance, rc));
     712    }
     713
    672714}
    673715#endif
     
    16001642    pThis->FifoXmit.cbMax = 16;
    16011643    pThis->FifoRecv.cbMax = 16;
    1602     uartFifoClear(&pThis->FifoXmit);
    1603     uartFifoClear(&pThis->FifoRecv);
    16041644    pThis->FifoRecv.cbItl = 1;
    16051645
    1606     uartR3ParamsUpdate(pThis);
    1607     uartIrqUpdate(pThis);
    1608 
    1609     if (pThis->pDrvSerial)
    1610     {
    1611         /* Set the modem lines to reflect the current state. */
    1612         int rc = pThis->pDrvSerial->pfnChgModemLines(pThis->pDrvSerial, false /*fRts*/, false /*fDtr*/);
    1613         if (RT_FAILURE(rc))
    1614             LogRel(("Serial#%d: Failed to set modem lines with %Rrc during reset\n",
    1615                     pThis->pDevInsR3->iInstance, rc));
    1616 
    1617         uint32_t fStsLines = 0;
    1618         rc = pThis->pDrvSerial->pfnQueryStsLines(pThis->pDrvSerial, &fStsLines);
    1619         if (RT_SUCCESS(rc))
    1620             uartR3StsLinesUpdate(pThis, fStsLines);
    1621         else
    1622             LogRel(("Serial#%d: Failed to query status line status with %Rrc during reset\n",
    1623                     pThis->pDevInsR3->iInstance, rc));
    1624     }
     1646    uartR3XferReset(pThis);
    16251647}
    16261648
     
    16371659            return VERR_PDM_MISSING_INTERFACE;
    16381660        }
     1661        uartR3XferReset(pThis);
    16391662    }
    16401663    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
     
    16431666        pThis->pDrvSerial = NULL;
    16441667        rc = VINF_SUCCESS;
     1668        uartR3XferReset(pThis);
    16451669        LogRel(("Serial#%d: no unit\n", pThis->pDevInsR3->iInstance));
    16461670    }
     
    16571681    pThis->pDrvBase   = NULL;
    16581682    pThis->pDrvSerial = NULL;
     1683    uartR3XferReset(pThis);
    16591684}
    16601685
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