VirtualBox

Changeset 88590 in vbox


Ignore:
Timestamp:
Apr 20, 2021 2:49:16 AM (4 years ago)
Author:
vboxsync
Message:

Intel IOMMU: WIP.

File:
1 edited

Legend:

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

    r88589 r88590  
    131131 * DMAR error diagnostics.
    132132 *
    133  * @note Members of this enum are used as array indices, so no gaps are allowed.
    134  *       Please update g_apsz when you add new fields to this enum.
     133 * @note Members of this enum are used as array indices, so no gaps in enum
     134 *       values are not allowed. Update g_apszDmarDiagDesc when you modify
     135 *       fields in this enum.
    135136 */
    136137typedef enum
     
    211212typedef DMAR *PDMAR;
    212213/** Pointer to the const DMAR device state. */
    213 typedef const DMAR *PCDMAR;
     214typedef DMAR const *PCDMAR;
    214215
    215216/**
     
    226227typedef DMARR3 *PDMARR3;
    227228/** Pointer to the const ring-3 DMAR device state. */
    228 typedef const DMARR3 *PCDMARR3;
     229typedef DMARR3 const *PCDMARR3;
    229230
    230231/**
     
    241242typedef DMARR0 *PDMARR0;
    242243/** Pointer to the const ring-0 IOMMU device state. */
    243 typedef const DMARR0 *PCDMARR0;
     244typedef DMARR0 const *PCDMARR0;
    244245
    245246/**
     
    256257typedef DMARRC *PDMARRC;
    257258/** Pointer to the const raw-mode DMAR device state. */
    258 typedef const DMARRC *PCIDMARRC;
     259typedef DMARRC const *PCIDMARRC;
    259260
    260261/** The DMAR device state for the current context. */
     
    263264typedef CTX_SUFF(PDMAR) PDMARCC;
    264265/** Pointer to the const DMAR device state for the current context. */
    265 typedef const CTX_SUFF(PDMAR) PCDMARCC;
     266typedef CTX_SUFF(PDMAR) const PCDMARCC;
    266267
    267268
     
    627628
    628629/**
    629  * Modifies a 32-bit register.
     630 * Reads a 32-bit register with exactly the value it contains.
    630631 *
    631632 * @param   pThis       The shared DMAR device state.
     
    634635 * @param   fOrMask     The OR mask.
    635636 */
    636 static void dmarRegChange32(PDMAR pThis, uint16_t offReg, uint32_t fAndMask, uint32_t fOrMask)
     637static uint32_t dmarRegReadRaw32(PCDMAR pThis, uint16_t offReg)
    637638{
    638639    uint8_t idxGroup;
    639     uint8_t *pabRegs = dmarRegGetGroup(pThis, offReg, sizeof(uint32_t), &idxGroup);
     640    uint8_t const *pabRegs = dmarRegGetGroupRo(pThis, offReg, sizeof(uint32_t), &idxGroup);
    640641    NOREF(idxGroup);
    641     uint32_t uReg = *(uint32_t *)(pabRegs + offReg);
    642     uReg = (uReg & fAndMask) | fOrMask;
    643     *(uint32_t *)(pabRegs + offReg) = uReg;
    644 }
    645 
    646 
    647 /**
    648  * Modifies a 64-bit register.
     642    return *(uint32_t *)(pabRegs + offReg);
     643}
     644
     645
     646/**
     647 * Reads a 64-bit register with exactly the value it contains.
    649648 *
    650649 * @param   pThis       The shared DMAR device state.
    651650 * @param   offReg      The MMIO offset of the register.
    652  * @param   fAndMask    The AND mask (applied first).
    653  * @param   fOrMask     The OR mask.
    654  */
    655 static void dmarRegChange64(PDMAR pThis, uint16_t offReg, uint64_t fAndMask, uint64_t fOrMask)
     651 */
     652static uint32_t dmarRegReadRaw64(PCDMAR pThis, uint16_t offReg)
    656653{
    657654    uint8_t idxGroup;
    658     uint8_t *pabRegs = dmarRegGetGroup(pThis, offReg, sizeof(uint64_t), &idxGroup);
     655    uint8_t const *pabRegs = dmarRegGetGroupRo(pThis, offReg, sizeof(uint64_t), &idxGroup);
    659656    NOREF(idxGroup);
    660     uint64_t uReg = *(uint64_t *)(pabRegs + offReg);
    661     uReg = (uReg & fAndMask) | fOrMask;
    662     *(uint64_t *)(pabRegs + offReg) = uReg;
    663 }
    664 
    665 
    666 /**
    667  * Reads a 64-bit register with exactly the value it contains.
     657    return *(uint64_t *)(pabRegs + offReg);
     658}
     659
     660
     661/**
     662 * Reads a 32-bit register with exactly the value it contains along with their
     663 * corresponding masks
     664 *
     665 * @param   pThis       The shared DMAR device state.
     666 * @param   offReg      The MMIO offset of the register.
     667 * @param   puReg       Where to store the raw 32-bit register value.
     668 * @param   pfRwMask    Where to store the RW mask corresponding to this register.
     669 * @param   pfRw1cMask  Where to store the RW1C mask corresponding to this register.
     670 */
     671static void dmarRegReadRaw32Ex(PCDMAR pThis, uint16_t offReg, uint32_t *puReg, uint32_t *pfRwMask, uint32_t *pfRw1cMask)
     672{
     673    uint8_t idxGroup;
     674    uint8_t const *pabRegs      = dmarRegGetGroupRo(pThis, offReg, sizeof(uint32_t), &idxGroup);
     675    Assert(idxGroup < RT_ELEMENTS(g_apbRwMasks));
     676    uint8_t const *pabRwMasks   = g_apbRwMasks[idxGroup];
     677    uint8_t const *pabRw1cMasks = g_apbRw1cMasks[idxGroup];
     678    *puReg      = *(uint32_t *)(pabRegs      + offReg);
     679    *pfRwMask   = *(uint32_t *)(pabRwMasks   + offReg);
     680    *pfRw1cMask = *(uint32_t *)(pabRw1cMasks + offReg);
     681}
     682
     683
     684/**
     685 * Reads a 64-bit register with exactly the value it contains along with their
     686 * corresponding masks.
    668687 *
    669688 * @param   pThis       The shared DMAR device state.
     
    673692 * @param   pfRw1cMask  Where to store the RW1C mask corresponding to this register.
    674693 */
    675 static void dmarRegReadRaw64(PCDMAR pThis, uint16_t offReg, uint64_t *puReg, uint64_t *pfRwMask, uint64_t *pfRw1cMask)
     694static void dmarRegReadRaw64Ex(PCDMAR pThis, uint16_t offReg, uint64_t *puReg, uint64_t *pfRwMask, uint64_t *pfRw1cMask)
    676695{
    677696    uint8_t idxGroup;
     
    687706
    688707/**
    689  * Reads a 32-bit register with exactly the value it contains.
    690  *
    691  * @param   pThis       The shared DMAR device state.
    692  * @param   offReg      The MMIO offset of the register.
    693  * @param   puReg       Where to store the raw 32-bit register value.
    694  * @param   pfRwMask    Where to store the RW mask corresponding to this register.
    695  * @param   pfRw1cMask  Where to store the RW1C mask corresponding to this register.
    696  */
    697 static void dmarRegReadRaw32(PCDMAR pThis, uint16_t offReg, uint32_t *puReg, uint32_t *pfRwMask, uint32_t *pfRw1cMask)
    698 {
    699     uint8_t idxGroup;
    700     uint8_t const *pabRegs      = dmarRegGetGroupRo(pThis, offReg, sizeof(uint32_t), &idxGroup);
    701     Assert(idxGroup < RT_ELEMENTS(g_apbRwMasks));
    702     uint8_t const *pabRwMasks   = g_apbRwMasks[idxGroup];
    703     uint8_t const *pabRw1cMasks = g_apbRw1cMasks[idxGroup];
    704     *puReg      = *(uint32_t *)(pabRegs      + offReg);
    705     *pfRwMask   = *(uint32_t *)(pabRwMasks   + offReg);
    706     *pfRw1cMask = *(uint32_t *)(pabRw1cMasks + offReg);
    707 }
    708 
    709 
    710 /**
    711708 * Writes a 64-bit register as it would be when written by software.
    712709 * This will preserve read-only bits, mask off reserved bits and clear RW1C bits.
     
    723720    uint64_t fRwMask;
    724721    uint64_t fRw1cMask;
    725     dmarRegReadRaw64(pThis, offReg, &uCurReg, &fRwMask, &fRw1cMask);
     722    dmarRegReadRaw64Ex(pThis, offReg, &uCurReg, &fRwMask, &fRw1cMask);
    726723
    727724    uint64_t const fRoBits   = uCurReg & ~fRwMask;      /* Preserve current read-only and reserved bits. */
     
    751748    uint32_t fRwMask;
    752749    uint32_t fRw1cMask;
    753     dmarRegReadRaw32(pThis, offReg, &uCurReg, &fRwMask, &fRw1cMask);
     750    dmarRegReadRaw32Ex(pThis, offReg, &uCurReg, &fRwMask, &fRw1cMask);
    754751
    755752    uint32_t const fRoBits   = uCurReg & ~fRwMask;      /* Preserve current read-only and reserved bits. */
     
    773770static uint64_t dmarRegRead64(PCDMAR pThis, uint16_t offReg)
    774771{
    775     uint64_t uCurReg;
    776     uint64_t fRwMask;
    777     uint64_t fRw1cMask;
    778     dmarRegReadRaw64(pThis, offReg, &uCurReg, &fRwMask, &fRw1cMask);
    779     NOREF(fRwMask); NOREF(fRw1cMask);
    780     return uCurReg;
     772    return dmarRegReadRaw64(pThis, offReg);
    781773}
    782774
     
    791783static uint32_t dmarRegRead32(PCDMAR pThis, uint16_t offReg)
    792784{
    793     uint32_t uCurReg;
    794     uint32_t fRwMask;
    795     uint32_t fRw1cMask;
    796     dmarRegReadRaw32(pThis, offReg, &uCurReg, &fRwMask, &fRw1cMask);
    797     NOREF(fRwMask); NOREF(fRw1cMask);
    798     return uCurReg;
     785    return dmarRegReadRaw32(pThis, offReg);
     786}
     787
     788
     789/**
     790 * Modifies a 32-bit register.
     791 *
     792 * @param   pThis       The shared DMAR device state.
     793 * @param   offReg      The MMIO offset of the register.
     794 * @param   fAndMask    The AND mask (applied first).
     795 * @param   fOrMask     The OR mask.
     796 * @remarks This does NOT apply RO or RW1C masks while modifying the
     797 *          register.
     798 */
     799static void dmarRegChange32(PDMAR pThis, uint16_t offReg, uint32_t fAndMask, uint32_t fOrMask)
     800{
     801    uint32_t uReg = dmarRegRead32(pThis, offReg);
     802    uReg = (uReg & fAndMask) | fOrMask;
     803    dmarRegWriteRaw32(pThis, offReg, uReg);
     804}
     805
     806
     807/**
     808 * Modifies a 64-bit register.
     809 *
     810 * @param   pThis       The shared DMAR device state.
     811 * @param   offReg      The MMIO offset of the register.
     812 * @param   fAndMask    The AND mask (applied first).
     813 * @param   fOrMask     The OR mask.
     814 * @remarks This does NOT apply RO or RW1C masks while modifying the
     815 *          register.
     816 */
     817static void dmarRegChange64(PDMAR pThis, uint16_t offReg, uint64_t fAndMask, uint64_t fOrMask)
     818{
     819    uint64_t uReg = dmarRegRead64(pThis, offReg);
     820    uReg = (uReg & fAndMask) | fOrMask;
     821    dmarRegWriteRaw64(pThis, offReg, uReg);
    799822}
    800823
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