VirtualBox

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


Ignore:
Timestamp:
Jan 23, 2025 4:42:56 PM (2 weeks ago)
Author:
vboxsync
Message:

DevXHCI: Removed some Parfait warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/DevXHCI.cpp

    r106061 r107924  
    315315
    316316/** Convert a zero-based index to a 1-based ID. */
    317 #define IDX_TO_ID(a)    (a + 1)
     317#define IDX_TO_ID(a)    (uint8_t)(a + 1)
    318318/** Convert a 1-based ID to a zero-based index. */
    319 #define ID_TO_IDX(a)    (a - 1)
     319#define ID_TO_IDX(a)    (uint8_t)(a - 1)
    320320
    321321/** PCI device related constants. */
     
    434434/** @name xHCI Extended capability types.
    435435 * @{ */
    436 #define XHCI_XCP_USB_LEGACY     1   /**< USB legacy support. */
    437 #define XHCI_XCP_PROTOCOL       2   /**< Protocols supported by ports. */
    438 #define XHCI_XCP_EXT_PM         3   /**< Extended power management (non-PCI). */
    439 #define XHCI_XCP_IOVIRT         4   /**< Hardware xHCI virtualization support. */
    440 #define XHCI_XCP_MSI            5   /**< Message interrupts (non-PCI). */
    441 #define XHCI_XCP_LOCAL_MEM      6   /**< Local memory (for debug support). */
    442 #define XHCI_XCP_USB_DEBUG      10  /**< USB debug capability. */
    443 #define XHCI_XCP_EXT_MSI        17  /**< MSI-X (non-PCI). */
     436#define XHCI_XCP_USB_LEGACY     1u  /**< USB legacy support. */
     437#define XHCI_XCP_PROTOCOL       2u  /**< Protocols supported by ports. */
     438#define XHCI_XCP_EXT_PM         3u  /**< Extended power management (non-PCI). */
     439#define XHCI_XCP_IOVIRT         4u  /**< Hardware xHCI virtualization support. */
     440#define XHCI_XCP_MSI            5u  /**< Message interrupts (non-PCI). */
     441#define XHCI_XCP_LOCAL_MEM      6u  /**< Local memory (for debug support). */
     442#define XHCI_XCP_USB_DEBUG      10u /**< USB debug capability. */
     443#define XHCI_XCP_EXT_MSI        17u /**< MSI-X (non-PCI). */
    444444/** @} */
    445445
     
    614614/** @name Event Ring Deqeue Pointer Register (ERDP) bits
    615615 * @{ */
    616 #define XHCI_ERDP_DESI_MASK     0x00000007  /**< RW   - Dequeue ERST Segment Index */
    617 #define XHCI_ERDP_EHB           RT_BIT(3)   /**< RW1C - Event Handler Busy */
     616#define XHCI_ERDP_DESI_MASK     UINT64_C(7)     /**< RW   - Dequeue ERST Segment Index */
     617#define XHCI_ERDP_EHB           RT_BIT_64(3)    /**< RW1C - Event Handler Busy */
    618618#define XHCI_ERDP_ADDR_MASK     UINT64_C(0xFFFFFFFFFFFFFFF0)    /**< RW - ERDP address mask */
    619619/** @} */
     
    18911891
    18921892/** Query the number of configured USB2 ports. */
    1893 #define XHCI_NDP_USB2(a_pThisCC)        ((unsigned)(a_pThisCC)->RootHub2.cPortsImpl)
     1893#define XHCI_NDP_USB2(a_pThisCC)        ((a_pThisCC)->RootHub2.cPortsImpl)
    18941894
    18951895/** Query the number of configured USB3 ports. */
    1896 #define XHCI_NDP_USB3(a_pThisCC)        ((unsigned)(a_pThisCC)->RootHub3.cPortsImpl)
     1896#define XHCI_NDP_USB3(a_pThisCC)        ((a_pThisCC)->RootHub3.cPortsImpl)
    18971897
    18981898/** Query the total number of configured ports. */
     
    19101910
    19111911/** Build a Protocol extended capability. */
    1912 static uint32_t xhciR3BuildProtocolCaps(uint8_t *pbCap, uint32_t cbMax, int cPorts, int nPortOfs, int ver)
     1912static uint32_t xhciR3BuildProtocolCaps(uint8_t *pbCap, uint32_t cbMax, unsigned cPorts, unsigned nPortOfs, int ver)
    19131913{
    19141914    uint32_t    *pu32Cap = (uint32_t *)pbCap;
     
    28152815{
    28162816    XHCI_CTX_XFER_COMPLETE  *pCtx = (XHCI_CTX_XFER_COMPLETE *)pvContext;
    2817     int                     rc;
    28182817    unsigned                uXferLen;
    28192818    unsigned                uResidue;
     
    28742873        if (pXferTRB->norm.ioc || (pXferTRB->norm.isp && uResidue))
    28752874        {
    2876             rc = xhciR3PostXferEvent(pDevIns, pThis, pXferTRB->norm.int_tgt, uResidue, cc,
    2877                                      pCtx->uSlotID, pCtx->uEpDCI, GCPhysXfrTRB, pXferTRB->norm.bei, false);
     2875            xhciR3PostXferEvent(pDevIns, pThis, pXferTRB->norm.int_tgt, uResidue, cc,
     2876                                pCtx->uSlotID, pCtx->uEpDCI, GCPhysXfrTRB, pXferTRB->norm.bei, false);
    28782877        }
    28792878        break;
     
    28812880        if (pXferTRB->evtd.ioc)
    28822881        {
    2883             rc = xhciR3PostXferEvent(pDevIns, pThis, pXferTRB->evtd.int_tgt, pCtx->uEDTLA, pCtx->uLastCC,
    2884                                      pCtx->uSlotID, pCtx->uEpDCI, pXferTRB->evtd.evt_data, pXferTRB->evtd.bei, true);
     2882            xhciR3PostXferEvent(pDevIns, pThis, pXferTRB->evtd.int_tgt, pCtx->uEDTLA, pCtx->uLastCC,
     2883                                pCtx->uSlotID, pCtx->uEpDCI, pXferTRB->evtd.evt_data, pXferTRB->evtd.bei, true);
    28852884        }
    28862885        /* Clear the EDTLA. */
     
    29312930    bool            fInFlight;
    29322931    bool            fContinue = true;
    2933     int             rc;
    29342932    unsigned        cTrbs = 0;
    29352933
     
    29742972                    pEpCtx->trep = pEpCtx->trdp;
    29752973                if (xfer.link.ioc)
    2976                     rc = xhciR3PostXferEvent(pDevIns, pThis, xfer.link.int_tgt, 0, XHCI_TCC_SUCCESS, uSlotID, uEpDCI,
    2977                                              GCPhysXfrTRB, false, false);
     2974                    xhciR3PostXferEvent(pDevIns, pThis, xfer.link.int_tgt, 0, XHCI_TCC_SUCCESS, uSlotID, uEpDCI,
     2975                                        GCPhysXfrTRB, false, false);
    29782976                break;
    29792977            case XHCI_TRB_NOOP_XFER:
     
    29862984                    pEpCtx->trep += sizeof(XHCI_XFER_TRB);
    29872985                if (xfer.nop.ioc)
    2988                     rc = xhciR3PostXferEvent(pDevIns, pThis, xfer.nop.int_tgt, 0, XHCI_TCC_SUCCESS, uSlotID, uEpDCI,
    2989                                              GCPhysXfrTRB, false, false);
     2986                    xhciR3PostXferEvent(pDevIns, pThis, xfer.nop.int_tgt, 0, XHCI_TCC_SUCCESS, uSlotID, uEpDCI,
     2987                                        GCPhysXfrTRB, false, false);
    29902988                break;
    29912989            default:
     
    30113009            /* Get out of the loop. */
    30123010            fContinue = false;
    3013             rc = VERR_NOT_SUPPORTED;    /* No good error code really... */
    30143011        }
    30153012    } while (fContinue);
     
    30433040    XHCI_XFER_TRB   xfer;
    30443041    RTGCPHYS        GCPhysXfrTRB;
    3045     int             rc;
    30463042    unsigned        uResidue = 0;
    30473043    uint8_t         uSlotID  = pUrb->pHci->uSlotID;
     
    31203116            ep_ctx.ep_state = XHCI_EPST_HALTED;
    31213117            cc = XHCI_TCC_STALL;
    3122             rc = xhciR3PostXferEvent(pDevIns, pThis, xfer.gen.int_tgt, uResidue, cc,
    3123                                      uSlotID, uEpDCI, GCPhysXfrTRB, false, false);
     3118            xhciR3PostXferEvent(pDevIns, pThis, xfer.gen.int_tgt, uResidue, cc,
     3119                                uSlotID, uEpDCI, GCPhysXfrTRB, false, false);
    31243120            break;
    31253121        case VUSBSTATUS_DNR:
     
    31293125            ep_ctx.ep_state = XHCI_EPST_HALTED;
    31303126            cc = XHCI_TCC_USB_XACT_ERR;
    3131             rc = xhciR3PostXferEvent(pDevIns, pThis, xfer.gen.int_tgt, uResidue, cc,
    3132                                      uSlotID, uEpDCI, GCPhysXfrTRB, false, false);
     3127            xhciR3PostXferEvent(pDevIns, pThis, xfer.gen.int_tgt, uResidue, cc,
     3128                                uSlotID, uEpDCI, GCPhysXfrTRB, false, false);
    31333129            break;
    31343130        case VUSBSTATUS_CRC:    /// @todo Separate status for canceling?!
    31353131            ep_ctx.ep_state = XHCI_EPST_HALTED;
    31363132            cc = XHCI_TCC_USB_XACT_ERR;
    3137             rc = xhciR3PostXferEvent(pDevIns, pThis, xfer.gen.int_tgt, uResidue, cc,
    3138                                      uSlotID, uEpDCI, GCPhysXfrTRB, false, false);
     3133            xhciR3PostXferEvent(pDevIns, pThis, xfer.gen.int_tgt, uResidue, cc,
     3134                                uSlotID, uEpDCI, GCPhysXfrTRB, false, false);
    31393135
    31403136            /* NB: The TRDP is *not* advanced and TREP is reset. */
     
    31483144            ep_ctx.ep_state = XHCI_EPST_HALTED;
    31493145            cc = XHCI_TCC_DATA_BUF_ERR;
    3150             rc = xhciR3PostXferEvent(pDevIns, pThis, xfer.gen.int_tgt, uResidue, cc,
    3151                                      uSlotID, uEpDCI, GCPhysXfrTRB, false, false);
     3146            xhciR3PostXferEvent(pDevIns, pThis, xfer.gen.int_tgt, uResidue, cc,
     3147                                uSlotID, uEpDCI, GCPhysXfrTRB, false, false);
    31523148            break;
    31533149        default:
     
    34933489    uint64_t                uTREP;
    34943490    PVUSBURB                pUrb;
    3495     unsigned                cIsoPackets;
     3491    uint8_t                 cIsoPackets;
    34963492    uint32_t                cbPktMax;
    34973493
     
    38063802    bool            dcs;
    38073803    bool            fContinue = true;
    3808     int             rc;
     3804    int             rc = VINF_SUCCESS;
    38093805    unsigned        cTrbs = 0;
    38103806
     
    40144010        xhciR3WriteBackEp(pDevIns, pThis, uSlotID, uDBTarget, &ep_ctx);
    40154011    }
    4016     return VINF_SUCCESS;
     4012    return rc;
    40174013}
    40184014
     
    50485044        /* Reset the given endpoint. */
    50495045        Log(("Reset Endpoint: slot ID %u, EP ID %u, TSP=%u\n", pCmd->rse.slot_id, pCmd->rse.ep_id, pCmd->rse.tsp));
    5050         cc = XHCI_TCC_SUCCESS;
    50515046        slot = ID_TO_IDX(pCmd->rse.slot_id);
    50525047        if ((slot >= RT_ELEMENTS(pThis->aSlotState)) || (pThis->aSlotState[slot] == XHCI_DEVSLOT_EMPTY))
     
    50615056        /* Stop the given endpoint. */
    50625057        Log(("Stop Endpoint: slot ID %u, EP ID %u, SP=%u\n", pCmd->stp.slot_id, pCmd->stp.ep_id, pCmd->stp.sp));
    5063         cc = XHCI_TCC_SUCCESS;
    50645058        slot = ID_TO_IDX(pCmd->stp.slot_id);
    50655059        if ((slot >= RT_ELEMENTS(pThis->aSlotState)) || (pThis->aSlotState[slot] == XHCI_DEVSLOT_EMPTY))
     
    50745068        /* Set TR Dequeue Pointer. */
    50755069        Log(("Set TRDP: slot ID %u, EP ID %u, TRDP=%RX64\n", pCmd->stdp.slot_id, pCmd->stdp.ep_id, pCmd->stdp.tr_dqp));
    5076         cc = XHCI_TCC_SUCCESS;
    50775070        slot = ID_TO_IDX(pCmd->stdp.slot_id);
    50785071        if ((slot >= RT_ELEMENTS(pThis->aSlotState)) || (pThis->aSlotState[slot] == XHCI_DEVSLOT_EMPTY))
     
    50875080        /* Reset a device. */
    50885081        Log(("Reset Device: slot ID %u\n", pCmd->rsd.slot_id));
    5089         cc = XHCI_TCC_SUCCESS;
    50905082        slot = ID_TO_IDX(pCmd->rsd.slot_id);
    50915083        if ((slot >= RT_ELEMENTS(pThis->aSlotState)) || (pThis->aSlotState[slot] == XHCI_DEVSLOT_EMPTY))
     
    51005092        /* Get port bandwidth. */
    51015093        Log(("Get Port Bandwidth: Dev Speed %u, Hub Slot ID %u, Context=%RX64\n", pCmd->gpbw.spd, pCmd->gpbw.slot_id, pCmd->gpbw.pbctx_ptr));
    5102         cc = XHCI_TCC_SUCCESS;
    51035094        if (pCmd->gpbw.slot_id)
    51045095            cc = XHCI_TCC_PARM_ERR; /* Potential undefined behavior, see 4.6.15. */
     
    55595550 * @returns true if device was connected and the flag was cleared.
    55605551 */
    5561 static bool xhciR3RhPortSetIfConnected(PXHCI pThis, int iPort, uint32_t fValue)
     5552static bool xhciR3RhPortSetIfConnected(PXHCI pThis, unsigned iPort, uint32_t fValue)
    55625553{
    55635554    /*
     
    59485939        Log(("Unknown USBCMD bits %#x are set!\n", val & ~XHCI_CMD_MASK));
    59495940
    5950     uint32_t old_cmd = pThis->cmd;
     5941
     5942    /* First deal with resets. These must be done in R3 and will initialize
     5943     * the USBCMD register.
     5944     */
     5945    if (val & (XHCI_CMD_HCRST | XHCI_CMD_LCRST))
     5946    {
    59515947#ifdef IN_RING3
    5952     pThis->cmd = val;
    5953 #endif
    5954 
    5955     if (val & XHCI_CMD_HCRST)
    5956     {
    5957 #ifdef IN_RING3
    5958         LogRel(("xHCI: Hardware reset\n"));
    5959         xhciR3DoReset(pThis, pThisCC, XHCI_USB_RESET, true /* reset devices */);
     5948        /* NB: xhciR3DoReset() overwrites pThis->cmd */
     5949        if (val & XHCI_CMD_HCRST)
     5950        {
     5951            LogRel(("xHCI: Hardware reset\n"));
     5952            xhciR3DoReset(pThis, pThisCC, XHCI_USB_RESET, true /* reset devices */);
     5953        }
     5954        else if (val & XHCI_CMD_LCRST)
     5955        {
     5956            LogRel(("xHCI: Software reset\n"));
     5957            xhciR3DoReset(pThis, pThisCC, XHCI_USB_SUSPEND, false /* N/A */);
     5958        }
     5959        else
     5960            Assert(0);
     5961
     5962        return VINF_SUCCESS;
    59605963#else
    59615964        return VINF_IOM_R3_MMIO_WRITE;
    59625965#endif
    59635966    }
    5964     else if (val & XHCI_CMD_LCRST)
    5965     {
    5966 #ifdef IN_RING3
    5967         LogRel(("xHCI: Software reset\n"));
    5968         xhciR3DoReset(pThis, pThisCC, XHCI_USB_SUSPEND, false /* N/A */);
    5969 #else
    5970         return VINF_IOM_R3_MMIO_WRITE;
    5971 #endif
    5972     }
    5973     else if (pThis->status & XHCI_STATUS_HCE)
    5974     {
    5975         /* If HCE is set, don't restart the controller. Only a reset
    5976          * will clear the HCE bit.
     5967
     5968    /* Not resetting, handle the remaining bits. */
     5969    if (pThis->status & XHCI_STATUS_HCE)
     5970    {
     5971        /* If the HCE (HC Error) status bit is set, don't do anything.
     5972         * Only a reset will clear the HCE bit.
    59775973         */
    59785974        Log(("xHCI: HCE bit set, ignoring USBCMD register changes!\n"));
    5979         pThis->cmd = old_cmd;
    59805975        return VINF_SUCCESS;
    59815976    }
    59825977    else
    59835978    {
    5984         /* See what changed and take action on that. First the R/S bit. */
    5985         uint32_t old_state = old_cmd & XHCI_CMD_RS;
    5986         uint32_t new_state = val     & XHCI_CMD_RS;
     5979        /* See what changed and take action on that. First the R/S bit.
     5980         * Note that R/S changes must also be done in R3, so we get them
     5981         * out of the way first.
     5982         * NB: xhciR3BusStop() modifies USBCMD.
     5983         */
     5984        uint32_t old_state = pThis->cmd & XHCI_CMD_RS;
     5985        uint32_t new_state = val        & XHCI_CMD_RS;
    59875986
    59885987        if (old_state != new_state)
     
    60066005
    60076006        /* Check EWE (Enable MFINDEX Wraparound Event) changes. */
    6008         old_state = old_cmd & XHCI_CMD_EWE;
    6009         new_state = val     & XHCI_CMD_EWE;
     6007        old_state = pThis->cmd & XHCI_CMD_EWE;
     6008        new_state = val        & XHCI_CMD_EWE;
    60106009
    60116010        if (old_state != new_state)
     
    60256024
    60266025        /* INTE transitions need to twiddle interrupts. */
    6027         old_state = old_cmd & XHCI_CMD_INTE;
    6028         new_state = val     & XHCI_CMD_INTE;
     6026        old_state = pThis->cmd & XHCI_CMD_INTE;
     6027        new_state = val        & XHCI_CMD_INTE;
    60296028        if (old_state != new_state)
    60306029        {
     
    60616060        }
    60626061    }
    6063 #ifndef IN_RING3
     6062
     6063    /* Finally update the USBCMD register. */
    60646064    pThis->cmd = val;
    6065 #endif
     6065
    60666066    return VINF_SUCCESS;
    60676067}
     
    78897889 * Worker for xhciR3Construct that registers a LUN (USB root hub).
    78907890 */
    7891 static int xhciR3RegisterHub(PPDMDEVINS pDevIns, PXHCIROOTHUBR3 pRh, int iLun, const char *pszDesc)
     7891static int xhciR3RegisterHub(PPDMDEVINS pDevIns, PXHCIROOTHUBR3 pRh, uint32_t iLun, const char *pszDesc)
    78927892{
    78937893    int rc = PDMDevHlpDriverAttach(pDevIns, iLun, &pRh->IBase, &pRh->pIBase, pszDesc);
    7894     AssertMsgRCReturn(rc, ("Configuration error: Failed to attach root hub driver to LUN #%d! (%Rrc)\n", iLun, rc), rc);
     7894    AssertMsgRCReturn(rc, ("Configuration error: Failed to attach root hub driver to LUN #%u! (%Rrc)\n", iLun, rc), rc);
    78957895
    78967896    pRh->pIRhConn = PDMIBASE_QUERY_INTERFACE(pRh->pIBase, VUSBIROOTHUBCONNECTOR);
     
    79177917    PXHCICC         pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PXHCICC);
    79187918    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    7919     uint32_t        cUsb2Ports;
    7920     uint32_t        cUsb3Ports;
     7919    uint8_t         cUsb2Ports;
     7920    uint8_t         cUsb3Ports;
    79217921    int             rc;
    79227922    LogFlow(("xhciR3Construct:\n"));
     
    79347934
    79357935    /* Number of USB2 ports option. */
    7936     rc = pHlp->pfnCFGMQueryU32Def(pCfg, "USB2Ports", &cUsb2Ports, XHCI_NDP_20_DEFAULT);
     7936    rc = pHlp->pfnCFGMQueryU8Def(pCfg, "USB2Ports", &cUsb2Ports, XHCI_NDP_20_DEFAULT);
    79377937    if (RT_FAILURE(rc))
    79387938        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    79457945
    79467946    /* Number of USB3 ports option. */
    7947     rc = pHlp->pfnCFGMQueryU32Def(pCfg, "USB3Ports", &cUsb3Ports, XHCI_NDP_30_DEFAULT);
     7947    rc = pHlp->pfnCFGMQueryU8Def(pCfg, "USB3Ports", &cUsb3Ports, XHCI_NDP_30_DEFAULT);
    79487948    if (RT_FAILURE(rc))
    79497949        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    80398039
    80408040    /* Set up the USB2 root hub interface. */
    8041     pThis->cUsb2Ports                              = (uint8_t)cUsb2Ports;
     8041    pThis->cUsb2Ports                              = cUsb2Ports;
    80428042    pThisCC->RootHub2.pXhciR3                      = pThisCC;
    80438043    pThisCC->RootHub2.cPortsImpl                   = cUsb2Ports;
     
    80538053
    80548054    /* Now the USB3 root hub interface. */
    8055     pThis->cUsb3Ports                              = (uint8_t)cUsb3Ports;
     8055    pThis->cUsb3Ports                              = cUsb3Ports;
    80568056    pThisCC->RootHub3.pXhciR3                      = pThisCC;
    80578057    pThisCC->RootHub3.cPortsImpl                   = cUsb3Ports;
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