VirtualBox

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


Ignore:
Timestamp:
Feb 14, 2013 7:07:14 PM (12 years ago)
Author:
vboxsync
Message:

DevLsiLogicSCSI.cpp: Tell IOM that we only want to get DWORD aligned and sized MMIO reads. Saves us a bit of code at the cost of a Log statement.

File:
1 edited

Legend:

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

    r44694 r44695  
    501501
    502502    /* The interrupts are masked out. */
    503     pThis->uInterruptMask |= LSILOGIC_REG_HOST_INTR_MASK_DOORBELL |
    504                              LSILOGIC_REG_HOST_INTR_MASK_REPLY;
     503    pThis->uInterruptMask |= LSILOGIC_REG_HOST_INTR_MASK_DOORBELL
     504                           | LSILOGIC_REG_HOST_INTR_MASK_REPLY;
    505505    /* Reset interrupt states. */
    506506    pThis->uInterruptStatus = 0;
     
    11941194 * @returns VBox status code.
    11951195 * @param   pThis       Pointer to the LsiLogic device state.
    1196  * @param   uOffset     Offset of the register to read.
    1197  * @param   pv          Where to store the content of the register.
    1198  * @param   cb          Number of bytes to read.
    1199  */
    1200 static int lsilogicRegisterRead(PLSILOGICSCSI pThis, uint32_t uOffset, void *pv, unsigned cb)
     1196 * @param   offReg      Offset of the register to read.
     1197 * @param   pu32        Where to store the content of the register.
     1198 */
     1199static int lsilogicRegisterRead(PLSILOGICSCSI pThis, uint32_t offReg, uint32_t *pu32)
    12011200{
    12021201    int rc = VINF_SUCCESS;
    12031202    uint32_t u32 = 0;
     1203    Assert(!(offReg & 3));
    12041204
    12051205    /* Align to a 4 byte offset. */
    1206     switch (uOffset & ~3)
     1206    switch (offReg)
    12071207    {
    12081208        case LSILOGIC_REG_REPLY_QUEUE:
    12091209        {
    1210             /*
    1211              * Non 4-byte access may cause real strange behavior because the data is part of a physical guest address.
    1212              * But some drivers use 1-byte access to scan for SCSI controllers.
    1213              */
    1214             if (RT_UNLIKELY(cb != 4))
    1215                 LogFlowFunc((": cb is not 4 (%u)\n", cb));
    1216 
    12171210            rc = PDMCritSectEnter(&pThis->ReplyPostQueueCritSect, VINF_IOM_R3_MMIO_READ);
    12181211            if (rc != VINF_SUCCESS)
     
    12891282    }
    12901283
    1291     /* Clip data according to the read size. */
    1292     switch (cb)
    1293     {
    1294         case 4:
    1295         {
    1296             *(uint32_t *)pv = u32;
    1297             break;
    1298         }
    1299         case 2:
    1300         {
    1301             uint8_t uBitsOff = (uOffset - (uOffset & 3))*8;
    1302 
    1303             u32 &= (0xffff << uBitsOff);
    1304             *(uint16_t *)pv = (uint16_t)(u32 >> uBitsOff);
    1305             break;
    1306         }
    1307         case 1:
    1308         {
    1309             uint8_t uBitsOff = (uOffset - (uOffset & 3))*8;
    1310 
    1311             u32 &= (0xff << uBitsOff);
    1312             *(uint8_t *)pv = (uint8_t)(u32 >> uBitsOff);
    1313             break;
    1314         }
    1315         default:
    1316             AssertMsgFailed(("Invalid access size %u\n", cb));
    1317     }
    1318 
    1319     LogFlowFunc(("pThis=%#p uOffset=%#x pv=%#p{%.*Rhxs} cb=%u\n", pThis, uOffset, pv, cb, pv, cb));
    1320 
     1284    *pu32 = u32;
     1285    LogFlowFunc(("pThis=%#p offReg=%#x u32=%#x\n", pThis, offReg, u32));
    13211286    return rc;
    13221287}
     
    13371302}
    13381303
    1339 PDMBOTHCBDECL(int) lsilogicIOPortRead (PPDMDEVINS pDevIns, void *pvUser,
    1340                                        RTIOPORT Port, uint32_t *pu32, unsigned cb)
    1341 {
    1342     PLSILOGICSCSI  pThis = PDMINS_2_DATA(pDevIns, PLSILOGICSCSI);
    1343     uint32_t   uOffset = Port - pThis->IOPortBase;
    1344 
    1345     Assert(cb <= 4);
    1346 
    1347     int rc = lsilogicRegisterRead(pThis, uOffset, pu32, cb);
     1304/**
     1305 * @callback_method_impl{FNIOMIOPORTIN}
     1306 */
     1307PDMBOTHCBDECL(int) lsilogicIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
     1308{
     1309    PLSILOGICSCSI   pThis   = PDMINS_2_DATA(pDevIns, PLSILOGICSCSI);
     1310    uint32_t        offReg  = Port - pThis->IOPortBase;
     1311
     1312    int rc = lsilogicRegisterRead(pThis, offReg & ~(uint32_t)3, pu32);
    13481313    if (rc == VINF_IOM_R3_MMIO_READ)
    13491314        rc = VINF_IOM_R3_IOPORT_READ;
     
    13611326}
    13621327
    1363 PDMBOTHCBDECL(int) lsilogicMMIORead(PPDMDEVINS pDevIns, void *pvUser,
    1364                                     RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
    1365 {
    1366     PLSILOGICSCSI  pThis = PDMINS_2_DATA(pDevIns, PLSILOGICSCSI);
    1367     uint32_t   uOffset = GCPhysAddr - pThis->GCPhysMMIOBase;
    1368 
    1369     return lsilogicRegisterRead(pThis, uOffset, pv, cb);
     1328/**
     1329 * @callback_method_impl{FNIOMMMIOREAD}
     1330 */
     1331PDMBOTHCBDECL(int) lsilogicMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
     1332{
     1333    PLSILOGICSCSI   pThis  = PDMINS_2_DATA(pDevIns, PLSILOGICSCSI);
     1334    uint32_t        offReg = GCPhysAddr - pThis->GCPhysMMIOBase;
     1335    Assert(!(offReg & 3)); Assert(cb == 4);
     1336
     1337    return lsilogicRegisterRead(pThis, offReg, (uint32_t *)pv);
    13701338}
    13711339
     
    38473815              ("PCI region type and size do not match\n"));
    38483816
    3849     if ((enmType == PCI_ADDRESS_SPACE_MEM) && (iRegion == 1))
    3850     {
    3851         /* We use the assigned size here, because we currently only support page aligned MMIO ranges. */
     3817    if (enmType == PCI_ADDRESS_SPACE_MEM && iRegion == 1)
     3818    {
     3819        /*
     3820         * Non-4-byte access to LSILOGIC_REG_REPLY_QUEUE may cause real strange
     3821         * behavior because the data is part of a physical guest address.  But
     3822         * some drivers use 1-byte access to scan for SCSI controllers.  So, we
     3823         * simplify our code by telling IOM to read DWORDs.
     3824         */
    38523825        rc = PDMDevHlpMMIORegister(pDevIns, GCPhysAddress, cb, NULL /*pvUser*/,
    3853                                    IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
     3826                                   IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_PASSTHRU,
    38543827                                   lsilogicMMIOWrite, lsilogicMMIORead, pcszCtrl);
    38553828        if (RT_FAILURE(rc))
     
    49564929{
    49574930    PLSILOGICSCSI pThis = PDMINS_2_DATA(pDevIns, PLSILOGICSCSI);
    4958     int rc = VINF_SUCCESS;
    4959     char  szDevTag[20];
     4931    int           rc    = VINF_SUCCESS;
    49604932    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    49614933
     
    50174989    MMR3HeapFree(pszCtrlType);
    50184990
     4991    char szDevTag[20];
    50194992    RTStrPrintf(szDevTag, sizeof(szDevTag), "LSILOGIC%s-%u",
    50204993                pThis->enmCtrlType == LSILOGICCTRLTYPE_SCSI_SPI ? "SPI" : "SAS",
     
    50815054    pThis->IBase.pfnQueryInterface = lsilogicR3StatusQueryInterface;
    50825055    pThis->ILeds.pfnQueryStatusLed = lsilogicR3StatusQueryStatusLed;
     5056
     5057    /*
     5058     * Create critical sections protecting the reply post and free queues.
     5059     */
     5060    rc = PDMDevHlpCritSectInit(pDevIns, &pThis->ReplyFreeQueueCritSect, RT_SRC_POS, "%sRFQ", szDevTag);
     5061    if (RT_FAILURE(rc))
     5062        return PDMDEV_SET_ERROR(pDevIns, rc, N_("LsiLogic: cannot create critical section for reply free queue"));
     5063
     5064    rc = PDMDevHlpCritSectInit(pDevIns, &pThis->ReplyPostQueueCritSect, RT_SRC_POS, "%sRPQ", szDevTag);
     5065    if (RT_FAILURE(rc))
     5066        return PDMDEV_SET_ERROR(pDevIns, rc, N_("LsiLogic: cannot create critical section for reply post queue"));
    50835067
    50845068    /*
     
    51505134
    51515135    /*
    5152      * Create critical sections protecting the reply post and free queues.
    5153      */
    5154     rc = PDMDevHlpCritSectInit(pDevIns, &pThis->ReplyFreeQueueCritSect, RT_SRC_POS, "%sRFQ", szDevTag);
    5155     if (RT_FAILURE(rc))
    5156         return PDMDEV_SET_ERROR(pDevIns, rc,
    5157                                 N_("LsiLogic: cannot create critical section for reply free queue"));
    5158 
    5159     rc = PDMDevHlpCritSectInit(pDevIns, &pThis->ReplyPostQueueCritSect, RT_SRC_POS, "%sRPQ", szDevTag);
    5160     if (RT_FAILURE(rc))
    5161         return PDMDEV_SET_ERROR(pDevIns, rc,
    5162                                 N_("LsiLogic: cannot create critical section for reply post queue"));
    5163 
    5164     /*
    51655136     * Allocate task cache.
    51665137     */
     
    51685139                          lsilogicR3TaskStateCtor, lsilogicR3TaskStateDtor, NULL, 0);
    51695140    if (RT_FAILURE(rc))
    5170         return PDMDEV_SET_ERROR(pDevIns, rc,
    5171                                 N_("Cannot create task cache"));
     5141        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Cannot create task cache"));
    51725142
    51735143    if (pThis->enmCtrlType == LSILOGICCTRLTYPE_SCSI_SPI)
     
    51835153    pThis->paDeviceStates = (PLSILOGICDEVICE)RTMemAllocZ(sizeof(LSILOGICDEVICE) * pThis->cDeviceStates);
    51845154    if (!pThis->paDeviceStates)
    5185         return PDMDEV_SET_ERROR(pDevIns, rc,
    5186                                 N_("Failed to allocate memory for device states"));
     5155        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to allocate memory for device states"));
    51875156
    51885157    for (unsigned i = 0; i < pThis->cDeviceStates; i++)
     
    52005169        pDevice->ILed.pfnQueryStatusLed            = lsilogicR3DeviceQueryStatusLed;
    52015170
    5202         RTStrPrintf(szName, sizeof(szName), "Device%d", i);
     5171        RTStrPrintf(szName, sizeof(szName), "Device%u", i);
    52035172
    52045173        /* Attach SCSI driver. */
     
    52775246     */
    52785247    char szTmp[128];
    5279     RTStrPrintf(szTmp, sizeof(szTmp), "%s%d", pDevIns->pReg->szName, pDevIns->iInstance);
     5248    RTStrPrintf(szTmp, sizeof(szTmp), "%s%u", pDevIns->pReg->szName, pDevIns->iInstance);
    52805249    PDMDevHlpDBGFInfoRegister(pDevIns, szTmp,
    52815250                              pThis->enmCtrlType == LSILOGICCTRLTYPE_SCSI_SPI
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