VirtualBox

Changeset 54072 in vbox


Ignore:
Timestamp:
Feb 3, 2015 4:25:44 PM (10 years ago)
Author:
vboxsync
Message:

USB: Make the number of reported OHCI ports adjustable.

Location:
trunk/src/VBox/Devices
Files:
2 edited

Legend:

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

    r53911 r54072  
    119119
    120120
    121 /** Number of Downstream Ports on the root hub.
     121/** Maximum supported number of Downstream Ports on the root hub. 15 ports
     122 * is the maximum defined by the OHCI spec.
    122123 * If you change this you need to add more status register words to the 'opreg'
    123124 * array.
    124125 */
    125 #define OHCI_NDP 15
     126#define OHCI_NDP_MAX        15
     127
     128/** Default NDP, chosen to be compatible with everything. */
     129#define OHCI_NDP_DEFAULT    12
     130
     131/* Macro to query the number of currently configured ports. */
     132#define OHCI_NDP_CFG(pohci) ((pohci)->RootHub.desc_a & OHCI_RHA_NDP)
    126133
    127134/** Pointer to OHCI device data. */
     
    183190    uint32_t                            Alignment0; /**< Align aPorts on a 8 byte boundary. */
    184191#endif
    185     OHCIHUBPORT                         aPorts[OHCI_NDP];
     192    OHCIHUBPORT                         aPorts[OHCI_NDP_MAX];
    186193    R3PTRTYPE(POHCI)                    pOhci;
    187194} OHCIROOTHUB;
     
    204211    unsigned cDevs;
    205212    /** Array of devices which were detached. */
    206     PVUSBIDEVICE apDevs[OHCI_NDP];
     213    PVUSBIDEVICE apDevs[OHCI_NDP_MAX];
    207214} OHCILOAD;
    208215/** Pointer to an OHCILOAD structure. */
     
    921928
    922929    PDMCritSectEnter(pThis->pDevInsR3->pCritSectRoR3, VERR_IGNORED);
    923     for (iPort = 0; iPort < RT_ELEMENTS(pThis->RootHub.aPorts); iPort++)
     930    for (iPort = 0; iPort < OHCI_NDP_CFG(pThis); iPort++)
    924931    {
    925932        if (!pThis->RootHub.aPorts[iPort].pDev)
     
    963970     * Validate and adjust input.
    964971     */
    965     Assert(uPort >= 1 && uPort <= RT_ELEMENTS(pThis->RootHub.aPorts));
     972    Assert(uPort >= 1 && uPort <= OHCI_NDP_CFG(pThis));
    966973    uPort--;
    967974    Assert(!pThis->RootHub.aPorts[uPort].pDev);
     
    10001007     * Validate and adjust input.
    10011008     */
    1002     Assert(uPort >= 1 && uPort <= RT_ELEMENTS(pThis->RootHub.aPorts));
     1009    Assert(uPort >= 1 && uPort <= OHCI_NDP_CFG(pThis));
    10031010    uPort--;
    10041011    Assert(pThis->RootHub.aPorts[uPort].pDev == pDev);
     
    10571064
    10581065    pThis->RootHub.status = 0;
    1059     pThis->RootHub.desc_a = OHCI_RHA_NPS | OHCI_NDP;
     1066    pThis->RootHub.desc_a = OHCI_RHA_NPS | OHCI_NDP_CFG(pThis); /* Preserve NDP value. */
    10601067    pThis->RootHub.desc_b = 0x0; /* Impl. specific */
    10611068
     
    10721079     * into this. For the time being we stick with simple.
    10731080     */
    1074     for (unsigned iPort = 0; iPort < RT_ELEMENTS(pThis->RootHub.aPorts); iPort++)
     1081    for (unsigned iPort = 0; iPort < OHCI_NDP_CFG(pThis); iPort++)
    10751082    {
    10761083        if (pThis->RootHub.aPorts[iPort].pDev)
     
    46334640    Log2(("HcRhDescriptorA_w(%#010x) => %sNDP=%d %sPSM=%d %sNPS=%d %sDT=%d %sOCPM=%d %sNOCP=%d %sPOTGT=%#x - %sPowerSwitching Set%sPower\n",
    46344641          val,
    4635           chg & 0xff      ?"!!!": "", OHCI_NDP,
     4642          chg & 0xff      ?"!!!": "", val & 0xff,
    46364643          (chg >>  8) & 1 ? "*" : "", (val >>  8) & 1,
    46374644          (chg >>  9) & 1 ? "*" : "", (val >>  9) & 1,
     
    46464653
    46474654
    4648     if ((val & (OHCI_RHA_NDP | OHCI_RHA_DT)) != OHCI_NDP)
     4655    if ((val & (OHCI_RHA_NDP | OHCI_RHA_DT)) != OHCI_NDP_CFG(pThis))
    46494656    {
    46504657        Log(("ohci: %s: invalid write to NDP or DT in roothub descriptor A!!! val=0x%.8x\n",
    46514658                pThis->PciDev.name, val));
    46524659        val &= ~(OHCI_RHA_NDP | OHCI_RHA_DT);
    4653         val |= OHCI_NDP;
     4660        val |= OHCI_NDP_CFG(pThis);
    46544661    }
    46554662
     
    47264733    if ( val & OHCI_RHS_LPSC )
    47274734    {
    4728         int i;
     4735        unsigned i;
    47294736        Log2(("ohci: %s: global power up\n", pThis->PciDev.name));
    4730         for (i = 0; i < OHCI_NDP; i++)
     4737        for (i = 0; i < OHCI_NDP_CFG(pThis); i++)
    47314738            rhport_power(&pThis->RootHub, i, true /* power up */);
    47324739    }
     
    47354742    if ( val & OHCI_RHS_LPS )
    47364743    {
    4737         int i;
     4744        unsigned i;
    47384745        Log2(("ohci: %s: global power down\n", pThis->PciDev.name));
    4739         for (i = 0; i < OHCI_NDP; i++)
     4746        for (i = 0; i < OHCI_NDP_CFG(pThis); i++)
    47404747            rhport_power(&pThis->RootHub, i, false /* power down */);
    47414748    }
     
    48004807    POHCIHUBPORT pPort = NULL;
    48014808    unsigned iPort;
    4802     for (iPort = 0; iPort < RT_ELEMENTS(pThis->RootHub.aPorts); iPort++) /* lazy bird */
     4809    for (iPort = 0; iPort < OHCI_NDP_CFG(pThis); iPort++) /* lazy bird */
    48034810        if (pThis->RootHub.aPorts[iPort].pDev == pDev)
    48044811        {
     
    50215028
    50225029    /* The number of port status register depends on the definition
    5023      * of OHCI_NDP macro
     5030     * of OHCI_NDP_MAX macro
    50245031     */
    50255032    { "HcRhPortStatus[0]",   HcRhPortStatus_r,       HcRhPortStatus_w },        /* 21 */
     
    50405047};
    50415048
     5049/* Quick way to determine how many op regs are valid. Since at least one port must
     5050 * be configured (and no more than 15), there will be between 22 and 36 registers.
     5051 */
     5052#define NUM_OP_REGS(pohci)  (21 + OHCI_NDP_CFG(pohci))
     5053
     5054AssertCompile(RT_ELEMENTS(g_aOpRegs) > 21);
     5055AssertCompile(RT_ELEMENTS(g_aOpRegs) <= 36);
    50425056
    50435057/**
     
    50575071    int rc;
    50585072    const uint32_t iReg = (GCPhysAddr - pThis->MMIOBase) >> 2;
    5059     if (iReg < RT_ELEMENTS(g_aOpRegs))
     5073    if (iReg < NUM_OP_REGS(pThis))
    50605074    {
    50615075        const OHCIOPREG *pReg = &g_aOpRegs[iReg];
     
    50645078    else
    50655079    {
    5066         Log(("ohci: Trying to read register %u/%u!!!\n", iReg, RT_ELEMENTS(g_aOpRegs)));
     5080        Log(("ohci: Trying to read register %u/%u!!!\n", iReg, NUM_OP_REGS(pThis)));
    50675081        rc = VINF_IOM_MMIO_UNUSED_FF;
    50685082    }
     
    50875101    int rc;
    50885102    const uint32_t iReg = (GCPhysAddr - pThis->MMIOBase) >> 2;
    5089     if (iReg < RT_ELEMENTS(g_aOpRegs))
     5103    if (iReg < NUM_OP_REGS(pThis))
    50905104    {
    50915105        const OHCIOPREG *pReg = &g_aOpRegs[iReg];
     
    50945108    else
    50955109    {
    5096         Log(("ohci: Trying to write to register %u/%u!!!\n", iReg, RT_ELEMENTS(g_aOpRegs)));
     5110        Log(("ohci: Trying to write to register %u/%u!!!\n", iReg, NUM_OP_REGS(pThis)));
    50975111        rc = VINF_SUCCESS;
    50985112    }
     
    57035717static DECLCALLBACK(int) ohciR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    57045718{
    5705     POHCI pThis = PDMINS_2_DATA(pDevIns, POHCI);
     5719    POHCI       pThis = PDMINS_2_DATA(pDevIns, POHCI);
     5720    uint32_t    cPorts;
    57065721    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    57075722
     
    57405755
    57415756    /*
    5742      * Read configuration. No configuration keys are currently supported.
     5757     * Read configuration.
    57435758     */
    57445759    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "RZEnabled", "");
     
    57465761    AssertLogRelRCReturn(rc, rc);
    57475762
     5763    /* Number of ports option. */
     5764    rc = CFGMR3QueryU32Def(pCfg, "Ports", &cPorts, OHCI_NDP_DEFAULT);
     5765    if (RT_FAILURE(rc))
     5766        return PDMDEV_SET_ERROR(pDevIns, rc,
     5767                                N_("OHCI configuration error: failed to read Ports as integer"));
     5768
     5769    if (cPorts == 0 || cPorts > OHCI_NDP_MAX)
     5770        return PDMDevHlpVMSetError(pDevIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
     5771                                   N_("OHCI configuration error: Ports must be in range [%u,%u]"),
     5772                                   1, OHCI_NDP_MAX);
     5773
     5774    /* Store the configured NDP; it will be used everywhere else from now on. */
     5775    pThis->RootHub.desc_a = cPorts;
    57485776
    57495777    /*
  • trunk/src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp

    r54061 r54072  
    992992    GEN_CHECK_OFF(OHCIROOTHUB, aPorts);
    993993    GEN_CHECK_OFF(OHCIROOTHUB, aPorts[1]);
    994     GEN_CHECK_OFF(OHCIROOTHUB, aPorts[OHCI_NDP - 1]);
     994    GEN_CHECK_OFF(OHCIROOTHUB, aPorts[OHCI_NDP_MAX - 1]);
    995995    GEN_CHECK_OFF(OHCIROOTHUB, pOhci);
    996996
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