VirtualBox

Changeset 85016 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Jul 1, 2020 5:28:16 AM (4 years ago)
Author:
vboxsync
Message:

Network/DeviVirtioNet_1_0.cpp: More clean up and naming for readability and consistency. Also moved MMIO parsing/loggin/accessor macros into header file to use consistently among VirtioCore.cpp, DevVirtioNet_1_0.cpp, DevVirtioSCSI.cpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp

    r84876 r85016  
    164164{
    165165    // Device-writable part
    166     uint32_t uEvent;                                            /**< event                                          */
     166    uint32_t uEvent;                                            /**< event                                           */
    167167    uint8_t  abVirtioLun[8];                                    /**< lun                                             */
    168168    uint32_t uReason;                                           /**< reason                                          */
     
    216216    uint8_t  uCdb[1];                                           /**< cdb                                          */
    217217
    218     REQ_CMD_PI_T piHdr;                                         /**< T10 Pi block integrity (optional feature)     */
     218    REQ_CMD_PI_T piHdr;                                         /**< T10 Pi block integrity (optional feature)    */
    219219    uint8_t  uPiOut[1];                                         /**< pi_out[]          T10 pi block integrity     */
    220220    uint8_t  uDataOut[1];                                       /**< dataout                                      */
     
    11821182    {
    11831183        size_t cbSeg = cbReqHdr - offReq;
    1184         RTGCPHYS GCPhys = virtioCoreGCPhysChainGetNextSegment(pVirtqBuf->pSgPhysSend, &cbSeg);
     1184        RTGCPHYS GCPhys = virtioCoreGCPhysChainGetNextSeg(pVirtqBuf->pSgPhysSend, &cbSeg);
    11851185        PDMDevHlpPCIPhysReadMeta(pDevIns, GCPhys, &VirtqReq.ab[offReq], cbSeg);
    11861186        offReq += cbSeg;
     
    13451345        virtioScsiR3FreeReq(pTarget, pReq);
    13461346    }
    1347 
    13481347    return VINF_SUCCESS;
    13491348}
     
    13711370    RT_ZERO(ScsiCtrlUnion);
    13721371
    1373     size_t const cbCtrl = RT_MIN(pVirtqBuf->cbPhysSend, sizeof(VIRTIO_SCSI_CTRL_UNION_T));
    1374     for (size_t offCtrl = 0; offCtrl < cbCtrl; )
    1375     {
    1376         size_t cbSeg = cbCtrl - offCtrl;
    1377         RTGCPHYS GCPhys = virtioCoreGCPhysChainGetNextSegment(pVirtqBuf->pSgPhysSend, &cbSeg);
    1378         PDMDevHlpPCIPhysReadMeta(pDevIns, GCPhys, &ScsiCtrlUnion.ab[offCtrl], cbSeg);
    1379         offCtrl += cbSeg;
     1372    size_t const cb = RT_MIN(pVirtqBuf->cbPhysSend, sizeof(VIRTIO_SCSI_CTRL_UNION_T));
     1373    for (size_t uOffset = 0; uOffset < cb; )
     1374    {
     1375        size_t cbSeg = cb - uOffset;
     1376        RTGCPHYS GCPhys = virtioCoreGCPhysChainGetNextSeg(pVirtqBuf->pSgPhysSend, &cbSeg);
     1377        PDMDevHlpPCIPhysReadMeta(pDevIns, GCPhys, &ScsiCtrlUnion.ab[uOffset], cbSeg);
     1378        uOffset += cbSeg;
    13801379    }
    13811380
     
    15911590                  PVIRTQBUF pVirtqBuf;
    15921591                  int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, &pThis->Virtio, uVirtqNbr,
    1593                                                     pWorkerR3->auRedoDescs[i], &pVirtqBuf);
     1592                                                        pWorkerR3->auRedoDescs[i], &pVirtqBuf);
    15941593                  if (RT_FAILURE(rc))
    15951594                      LogRel(("Error fetching desc chain to redo, %Rrc", rc));
     
    17801779
    17811780/**
    1782  * Resolves to boolean true if uOffset matches a field offset and size exactly,
    1783  * (or if 64-bit field, if it accesses either 32-bit part as a 32-bit access)
    1784  * Assumption is this critereon is mandated by VirtIO 1.0, Section 4.1.3.1)
    1785  * (Easily re-written to allow unaligned bounded access to a field).
    1786  *
    1787  * @param   member   - Member of VIRTIO_PCI_COMMON_CFG_T
    1788  * @result           - true or false
    1789  */
    1790 #define MATCH_SCSI_CONFIG(member) \
    1791         (   (   RT_SIZEOFMEMB(VIRTIOSCSI_CONFIG_T, member) == 8 \
    1792              && (   offConfig == RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member) \
    1793                  || offConfig == RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member) + sizeof(uint32_t)) \
    1794              && cb == sizeof(uint32_t)) \
    1795          || (   offConfig == RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member) \
    1796              && cb == RT_SIZEOFMEMB(VIRTIOSCSI_CONFIG_T, member)) )
    1797 
    1798 #ifdef LOG_ENABLED
    1799 # define LOG_SCSI_CONFIG_ACCESSOR(member) \
    1800         virtioCoreLogMappedIoValue(__FUNCTION__, #member, RT_SIZEOFMEMB(VIRTIOSCSI_CONFIG_T, member), \
    1801                                pv, cb, offIntra, fWrite, false, 0);
    1802 #else
    1803 # define LOG_SCSI_CONFIG_ACCESSOR(member) do { } while (0)
    1804 #endif
    1805 
    1806 #define SCSI_CONFIG_ACCESSOR(member) \
    1807     do \
    1808     { \
    1809         uint32_t offIntra = offConfig - RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member); \
    1810         if (fWrite) \
    1811             memcpy((char *)&pThis->virtioScsiConfig.member + offIntra, pv, cb); \
    1812         else \
    1813             memcpy(pv, (const char *)&pThis->virtioScsiConfig.member + offIntra, cb); \
    1814         LOG_SCSI_CONFIG_ACCESSOR(member); \
    1815     } while(0)
    1816 
    1817 #define SCSI_CONFIG_ACCESSOR_READONLY(member) \
    1818     do \
    1819     { \
    1820         uint32_t offIntra = offConfig - RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member); \
    1821         if (fWrite) \
    1822             LogFunc(("Guest attempted to write readonly virtio_pci_common_cfg.%s\n", #member)); \
    1823         else \
    1824         { \
    1825             memcpy(pv, (const char *)&pThis->virtioScsiConfig.member + offIntra, cb); \
    1826             LOG_SCSI_CONFIG_ACCESSOR(member); \
    1827         } \
    1828     } while(0)
    1829 
    1830 /**
    18311781 * Worker for virtioScsiR3DevCapWrite and virtioScsiR3DevCapRead.
    18321782 */
    1833 static int virtioScsiR3CfgAccessed(PVIRTIOSCSI pThis, uint32_t offConfig, void *pv, uint32_t cb, bool fWrite)
     1783static int virtioScsiR3CfgAccessed(PVIRTIOSCSI pThis, uint32_t uOffsetOfAccess, void *pv, uint32_t cb, bool fWrite)
    18341784{
    18351785    AssertReturn(pv && cb <= sizeof(uint32_t), fWrite ? VINF_SUCCESS : VINF_IOM_MMIO_UNUSED_00);
    18361786
    1837     if (MATCH_SCSI_CONFIG(uNumVirtqs))
    1838         SCSI_CONFIG_ACCESSOR_READONLY(uNumVirtqs);
     1787    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uNumVirtqs,     VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1788        VIRTIO_DEV_CONFIG_ACCESS_READONLY( uNumVirtqs,     VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18391789    else
    1840     if (MATCH_SCSI_CONFIG(uSegMax))
    1841         SCSI_CONFIG_ACCESSOR_READONLY(uSegMax);
     1790    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uSegMax,        VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1791        VIRTIO_DEV_CONFIG_ACCESS_READONLY( uSegMax,        VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18421792    else
    1843     if (MATCH_SCSI_CONFIG(uMaxSectors))
    1844         SCSI_CONFIG_ACCESSOR_READONLY(uMaxSectors);
     1793    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uMaxSectors,    VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1794        VIRTIO_DEV_CONFIG_ACCESS_READONLY( uMaxSectors,    VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18451795    else
    1846     if (MATCH_SCSI_CONFIG(uCmdPerLun))
    1847         SCSI_CONFIG_ACCESSOR_READONLY(uCmdPerLun);
     1796    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uCmdPerLun,     VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1797        VIRTIO_DEV_CONFIG_ACCESS_READONLY( uCmdPerLun,     VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18481798    else
    1849     if (MATCH_SCSI_CONFIG(uEventInfoSize))
    1850         SCSI_CONFIG_ACCESSOR_READONLY(uEventInfoSize);
     1799    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uEventInfoSize, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1800        VIRTIO_DEV_CONFIG_ACCESS_READONLY( uEventInfoSize, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18511801    else
    1852     if (MATCH_SCSI_CONFIG(uSenseSize))
    1853         SCSI_CONFIG_ACCESSOR(uSenseSize);
     1802    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uSenseSize,     VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1803        VIRTIO_DEV_CONFIG_ACCESS(          uSenseSize,     VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18541804    else
    1855     if (MATCH_SCSI_CONFIG(uCdbSize))
    1856         SCSI_CONFIG_ACCESSOR(uCdbSize);
     1805    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uCdbSize,       VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1806        VIRTIO_DEV_CONFIG_ACCESS(          uCdbSize,       VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18571807    else
    1858     if (MATCH_SCSI_CONFIG(uMaxChannel))
    1859         SCSI_CONFIG_ACCESSOR_READONLY(uMaxChannel);
     1808    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uMaxChannel,    VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1809        VIRTIO_DEV_CONFIG_ACCESS_READONLY( uMaxChannel,    VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18601810    else
    1861     if (MATCH_SCSI_CONFIG(uMaxTarget))
    1862         SCSI_CONFIG_ACCESSOR_READONLY(uMaxTarget);
     1811    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uMaxTarget,     VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1812        VIRTIO_DEV_CONFIG_ACCESS_READONLY( uMaxTarget,     VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18631813    else
    1864     if (MATCH_SCSI_CONFIG(uMaxLun))
    1865         SCSI_CONFIG_ACCESSOR_READONLY(uMaxLun);
     1814    if (VIRTIO_DEV_CONFIG_MATCH_MEMBER(    uMaxLun,        VIRTIOSCSI_CONFIG_T, uOffsetOfAccess))
     1815        VIRTIO_DEV_CONFIG_ACCESS_READONLY( uMaxLun,        VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig);
    18661816    else
    18671817    {
    1868         LogFunc(("Bad access by guest to virtio_scsi_config: off=%u (%#x), cb=%u\n", offConfig, offConfig, cb));
     1818        LogFunc(("Bad access by guest to virtio_scsi_config: off=%u (%#x), cb=%u\n", uOffsetOfAccess, uOffsetOfAccess, cb));
    18691819        return fWrite ? VINF_SUCCESS : VINF_IOM_MMIO_UNUSED_00;
    18701820    }
    18711821    return VINF_SUCCESS;
    18721822}
    1873 
    1874 #undef SCSI_CONFIG_ACCESSOR_READONLY
    1875 #undef SCSI_CONFIG_ACCESSOR
    1876 #undef LOG_ACCESSOR
    1877 #undef MATCH_SCSI_CONFIG
    18781823
    18791824/**
     
    25282473    for (uint16_t uVirtqNbr = 0; uVirtqNbr < VIRTIOSCSI_VIRTQ_CNT; uVirtqNbr++)
    25292474    {
    2530         rc = virtioCoreR3VirtqAttach(&pThis->Virtio, uVirtqNbr, VIRTQNAME(uVirtqNbr));
     2475        rc = virtioCoreVirtqAttach(&pThis->Virtio, uVirtqNbr, VIRTQNAME(uVirtqNbr));
    25312476        if (RT_FAILURE(rc))
    25322477            continue;
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