VirtualBox

Changeset 84060 in vbox for trunk/src/VBox/Devices/Bus


Ignore:
Timestamp:
Apr 28, 2020 5:13:50 PM (5 years ago)
Author:
vboxsync
Message:

AMD IOMMU: bugref:9654 Bits.

File:
1 edited

Legend:

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

    r84027 r84060  
    417417/** PprOverflowEarly: PPR log overflow early warning. */
    418418#define IOMMU_STATUS_PPR_LOG_OVERFLOW_EARLY         RT_BIT_64(18)
     419/** @} */
     420
     421/**
     422 * @name IOMMU Control Register Bits.
     423 * In accordance with the AMD spec.
     424 * @{
     425 */
     426/** IommuEn: Enable the IOMMU. */
     427#define IOMMU_CTRL_IOMMU_EN                         RT_BIT_64(0)
     428/** HtTunEn: HyperTransport tunnel translation enable. */
     429#define IOMMU_CTRL_HT_TUNNEL_EN                     RT_BIT_64(1)
     430/** EventLogEn: Event log enable. */
     431#define IOMMU_CTRL_EVT_LOG_EN                       RT_BIT_64(2)
     432/** EventIntEn: Event interrupt enable. */
     433#define IOMMU_CTRL_EVT_INTR_EN                      RT_BIT_64(3)
     434/** ComWaitIntEn: Completion wait interrupt enable. */
     435#define IOMMU_CTRL_COMPLETION_WAIT_INTR_EN          RT_BIT_64(4)
     436/** InvTimeout: Invalidation timeout. */
     437#define IOMMU_CTRL_INV_TIMEOUT                      RT_BIT_64(5) | RT_BIT_64(6) | RT_BIT_64(7)
     438/** @todo IOMMU: the rest or remove it. */
    419439/** @} */
    420440
     
    12211241} IOMMU_CTRL_T;
    12221242AssertCompileSize(IOMMU_CTRL_T, 8);
     1243#define IOMMU_CTRL_VALID_MASK       UINT64_C(0x004defffffffffff)
    12231244
    12241245/**
     
    22092230
    22102231
     2232/**
     2233 * The IOMMU command thread.
     2234 *
     2235 * @returns VBox status code.
     2236 * @param   pDevIns     The IOMMU device instance.
     2237 * @param   pThread     The command thread.
     2238 */
     2239static DECLCALLBACK(int) iommuAmdR3CmdThread(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
     2240{
     2241    RT_NOREF(pDevIns, pThread);
     2242}
     2243
     2244
     2245/**
     2246 * Unblocks the command thread so it can respond to a state change.
     2247 *
     2248 * @returns VBox status code.
     2249 * @param   pDevIns     The IOMMU device instance.
     2250 * @param   pThread     The command thread.
     2251 */
     2252static DECLCALLBACK(int) iommuAmdR3CmdThreadWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
     2253{
     2254    RT_NOREF(pThread);
     2255    PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
     2256    return PDMDevHlpSUPSemEventSignal(pDevIns, pThis->hEvtCmdThread);
     2257}
     2258
    22112259
    22122260/**
     
    22802328
    22812329    /*
    2282      * Writing the command log base address, clears the command buffer head and tail pointers.
     2330     * Writing the command buffer base address, clears the command buffer head and tail pointers.
    22832331     * See AMD spec. 2.4 "Commands".
    22842332     */
     
    23352383
    23362384    return VINF_SUCCESS;
     2385}
     2386
     2387
     2388/**
     2389 * Writes the Control Register.
     2390 */
     2391static VBOXSTRICTRC iommuAmdCtrl_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
     2392{
     2393    RT_NOREF(pDevIns, iReg);
     2394
     2395    /* Mask out all unrecognized bits. */
     2396    u64Value &= IOMMU_CTRL_VALID_MASK;
     2397
     2398    IOMMU_CTRL_T const OldCtrl = iommuAmdGetCtrl(pThis);
     2399    IOMMU_CTRL_T NewCtrl;
     2400    NewCtrl.u64 = u64Value;
     2401
     2402    /* Enable or disable event logging when the bit transitions. */
     2403    if (OldCtrl.n.u1EvtLogEn != NewCtrl.n.u1EvtLogEn)
     2404    {
     2405        if (NewCtrl.n.u1EvtLogEn)
     2406        {
     2407            ASMAtomicAndU64(&pThis->Status.u64, ~IOMMU_STATUS_EVT_LOG_OVERFLOW);
     2408            ASMAtomicOrU64(&pThis->Status.u64, IOMMU_STATUS_EVT_LOG_RUNNING);
     2409        }
     2410        else
     2411            ASMAtomicAndU64(&pThis->Status.u64, ~IOMMU_STATUS_EVT_LOG_RUNNING);
     2412    }
     2413
     2414    /* Update the control register. */
     2415    ASMAtomicWriteU64(&pThis->Ctrl.u64, NewCtrl.u64);
     2416
     2417    /* Enable or disable command buffer processing when the bit transitions. */
     2418    if (OldCtrl.n.u1CmdBufEn != NewCtrl.n.u1CmdBufEn)
     2419    {
     2420        if (NewCtrl.n.u1CmdBufEn)
     2421        {
     2422            ASMAtomicOrU64(&pThis->Status.u64, IOMMU_STATUS_CMD_BUF_RUNNING);
     2423            /* If the command buffer isn't empty, kick the command thread to start processing commands. */
     2424            if (pThis->CmdBufHeadPtr.n.u15Ptr != pThis->CmdBufTailPtr.n.u15Ptr)
     2425                PDMDevHlpSUPSemEventSignal(pDevIns, pThis->hEvtCmdThread);
     2426        }
     2427        else
     2428        {
     2429            ASMAtomicAndU64(&pThis->Status.u64, ~IOMMU_STATUS_CMD_BUF_RUNNING);
     2430            /* Kick the command thread to stop processing commands. */
     2431            PDMDevHlpSUPSemEventSignal(pDevIns, pThis->hEvtCmdThread);
     2432        }
     2433    }
    23372434}
    23382435
     
    26232720
    26242721
    2625 /**
    2626  * The IOMMU command thread.
    2627  *
    2628  * @returns VBox status code.
    2629  * @param   pDevIns     The IOMMU device instance.
    2630  * @param   pThread     The command thread.
    2631  */
    2632 static DECLCALLBACK(int) iommuAmdR3CmdThread(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    2633 {
    2634     RT_NOREF(pDevIns, pThread);
    2635 }
    2636 
    2637 
    2638 /**
    2639  * Unblocks the command thread so it can respond to a state change.
    2640  *
    2641  * @returns VBox status code.
    2642  * @param   pDevIns     The IOMMU device instance.
    2643  * @param   pThread     The command thread.
    2644  */
    2645 static DECLCALLBACK(int) iommuAmdR3CmdThreadWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    2646 {
    2647     RT_NOREF(pThread);
    2648     PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
    2649     return PDMDevHlpSUPSemEventSignal(pDevIns, pThis->hEvtCmdThread);
    2650 }
    2651 
    2652 
    26532722#if 0
    26542723/**
     
    26892758        case IOMMU_MMIO_OFF_CMD_BUF_BAR:         return iommuAmdCmdBufBar_w(pDevIns, pThis, off, uValue);
    26902759        case IOMMU_MMIO_OFF_EVT_LOG_BAR:         return iommuAmdEvtLogBar_w(pDevIns, pThis, off, uValue);
    2691         case IOMMU_MMIO_OFF_CTRL:                /** @todo IOMMU: Control register. */
     2760        case IOMMU_MMIO_OFF_CTRL:                return iommuAmdCtrl_w(pDevIns, pThis, off, uValue);
    26922761        case IOMMU_MMIO_OFF_EXCL_BAR:            return iommuAmdExclRangeBar_w(pDevIns, pThis, off, uValue);
    26932762        case IOMMU_MMIO_OFF_EXCL_RANGE_LIMIT:    return iommuAmdExclRangeLimit_w(pDevIns, pThis, off, uValue);
     
    29983067
    29993068/**
    3000  * Writes an entry to the event log.
     3069 * Writes an entry to the event log in memory.
    30013070 *
    30023071 * @returns VBox status code.
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