VirtualBox

Changeset 88549 in vbox


Ignore:
Timestamp:
Apr 15, 2021 4:35:16 PM (4 years ago)
Author:
vboxsync
Message:

Intel IOMMU: bugref:9967 Don't prevent ourselves from being able to pass const pointer to shared instance data when we only read registers. const identification becomes immensely useful when code complexity grows.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Bus/DevIommuIntel.cpp

    r88537 r88549  
    495495
    496496/**
     497 * Gets the index of the group the register belongs to given its MMIO offset.
     498 *
     499 * @returns The group index.
     500 * @param   offReg      The MMIO offset of the register.
     501 * @param   cbReg       The size of the access being made (for bounds checking on
     502 *                      debug builds).
     503 */
     504DECLINLINE(uint8_t) dmarRegGetGroupIndex(uint16_t offReg, uint8_t cbReg)
     505{
     506    uint16_t const offLast = offReg + cbReg - 1;
     507    AssertCompile(DMAR_MMIO_GROUP_0_OFF_FIRST == 0);
     508    AssertMsg(DMAR_IS_MMIO_OFF_VALID(offLast), ("off=%#x cb=%u\n", offReg, cbReg));
     509    return !(offLast < DMAR_MMIO_GROUP_0_OFF_END);
     510}
     511
     512
     513/**
    497514 * Gets the group the register belongs to given its MMIO offset.
    498515 *
     
    507524DECLINLINE(uint8_t *) dmarRegGetGroup(PDMAR pThis, uint16_t offReg, uint8_t cbReg, uint8_t *pIdxGroup)
    508525{
    509     uint16_t const offLast = offReg + cbReg - 1;
    510     AssertCompile(DMAR_MMIO_GROUP_0_OFF_FIRST == 0);
    511     AssertMsg(DMAR_IS_MMIO_OFF_VALID(offLast), ("off=%#x cb=%u\n", offReg, cbReg));
    512 
    513     uint8_t *const apbRegs[] = { &pThis->abRegs0[0], &pThis->abRegs1[0] };
    514     *pIdxGroup = !(offLast < DMAR_MMIO_GROUP_0_OFF_END);
     526    *pIdxGroup = dmarRegGetGroupIndex(offReg, cbReg);
     527    uint8_t *apbRegs[] = { &pThis->abRegs0[0], &pThis->abRegs1[0] };
     528    return apbRegs[*pIdxGroup];
     529}
     530
     531
     532/**
     533 * Const/read-only version of dmarRegGetGroup.
     534 *
     535 * @copydoc dmarRegGetGroup
     536 */
     537DECLINLINE(uint8_t const*) dmarRegGetGroupRo(PCDMAR pThis, uint16_t offReg, uint8_t cbReg, uint8_t *pIdxGroup)
     538{
     539    *pIdxGroup = dmarRegGetGroupIndex(offReg, cbReg);
     540    uint8_t const *apbRegs[] = { &pThis->abRegs0[0], &pThis->abRegs1[0] };
    515541    return apbRegs[*pIdxGroup];
    516542}
     
    558584 * @param   pfRw1cMask  Where to store the RW1C mask corresponding to this register.
    559585 */
    560 DECLINLINE(void) dmarRegReadRaw64(PDMAR pThis, uint16_t offReg, uint64_t *puReg, uint64_t *pfRwMask, uint64_t *pfRw1cMask)
     586DECLINLINE(void) dmarRegReadRaw64(PCDMAR pThis, uint16_t offReg, uint64_t *puReg, uint64_t *pfRwMask, uint64_t *pfRw1cMask)
    561587{
    562588    uint8_t idxGroup;
    563     uint8_t const *pabRegs      = dmarRegGetGroup(pThis, offReg, sizeof(uint64_t), &idxGroup);
     589    uint8_t const *pabRegs      = dmarRegGetGroupRo(pThis, offReg, sizeof(uint64_t), &idxGroup);
    564590    Assert(idxGroup < RT_ELEMENTS(g_apbRwMasks));
    565591    uint8_t const *pabRwMasks   = g_apbRwMasks[idxGroup];
     
    580606 * @param   pfRw1cMask  Where to store the RW1C mask corresponding to this register.
    581607 */
    582 DECLINLINE(void) dmarRegReadRaw32(PDMAR pThis, uint16_t offReg, uint32_t *puReg, uint32_t *pfRwMask, uint32_t *pfRw1cMask)
     608DECLINLINE(void) dmarRegReadRaw32(PCDMAR pThis, uint16_t offReg, uint32_t *puReg, uint32_t *pfRwMask, uint32_t *pfRw1cMask)
    583609{
    584610    uint8_t idxGroup;
    585     uint8_t const *pabRegs      = dmarRegGetGroup(pThis, offReg, sizeof(uint32_t), &idxGroup);
     611    uint8_t const *pabRegs      = dmarRegGetGroupRo(pThis, offReg, sizeof(uint32_t), &idxGroup);
    586612    Assert(idxGroup < RT_ELEMENTS(g_apbRwMasks));
    587613    uint8_t const *pabRwMasks   = g_apbRwMasks[idxGroup];
     
    656682 * @param   offReg  The MMIO offset of the register.
    657683 */
    658 static uint64_t dmarRegRead64(PDMAR pThis, uint16_t offReg)
     684static uint64_t dmarRegRead64(PCDMAR pThis, uint16_t offReg)
    659685{
    660686    uint64_t uCurReg;
     
    674700 * @param   offReg  The MMIO offset of the register.
    675701 */
    676 static uint32_t dmarRegRead32(PDMAR pThis, uint16_t offReg)
     702static uint32_t dmarRegRead32(PCDMAR pThis, uint16_t offReg)
    677703{
    678704    uint32_t uCurReg;
     
    695721static VBOXSTRICTRC dmarIqtRegWrite(PPDMDEVINS pDevIns, uint16_t off, uint64_t uIqtReg)
    696722{
    697     /* We only care about the low dword of VTD_MMIO_OFF_IQT_REG. */
    698     PDMAR pThis = PDMDEVINS_2_DATA(pDevIns, PDMAR);
     723    /* We only care about the low 32-bits. */
    699724    if (off == VTD_MMIO_OFF_IQT_REG)
    700725    {
    701726        /* Verify if the queue tail offset is aligned according to the descriptor width in IQA_REG. */
     727        PDMAR pThis = PDMDEVINS_2_DATA(pDevIns, PDMAR);
    702728        uint16_t const offQueueTail = VTD_IQT_REG_GET_QT(uIqtReg);
    703729        uint64_t const uIqaReg      = dmarRegRead64(pThis, VTD_MMIO_OFF_IQA_REG);
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