VirtualBox

Changeset 39151 in vbox


Ignore:
Timestamp:
Oct 31, 2011 2:17:15 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
74613
Message:

OHCI: More tests, added alignment todo.

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

Legend:

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

    r39149 r39151  
    41574157    Log2(("HcBulkHeadED_w(%#010x) - old=%#010x new=%#010x\n", val, pOhci->bulk_head, val & ~7));
    41584158    AssertMsg(!(val & 7), ("Invalid alignment, val=%#010x\n", val));
    4159     pOhci->bulk_head = val & ~7;
     4159    pOhci->bulk_head = val & ~7; /** @todo The ATI OHCI controller on my machine enforces 16-byte address alignment. */
    41604160    return VINF_SUCCESS;
    41614161}
     
    43474347static int HcLSThreshold_w(POHCI pOhci, uint32_t iReg, uint32_t val)
    43484348{
    4349     Log2(("HcLSThreshold_w(%#010x) => LST=0x%03x(%d)\n", val, val & 0x0fff, val & 0x0fff));
     4349    Log2(("HcLSThreshold_w(%#010x) => LST=0x%03x(%d)\n", val, val & 0x0fff));
    43504350    AssertMsg(val == OHCI_LS_THRESH,
    43514351              ("HCD tried to write bad LS threshold: 0x%x (see function header)\n", val));
     4352    /** @todo the HCD can change this. */
    43524353    return VINF_SUCCESS;
    43534354}
  • trunk/src/VBox/Devices/USB/testcase/tstOhciRegisterAccess.cpp

    r39149 r39151  
    7676    {
    7777        unsigned iReg;
     78        uint32_t fMask;
    7879        uint32_t uVal1;
    7980        uint32_t uVal2;
    8081    }  const s_aRegs[] =
    8182    {
    82         {  4 /* HcInterruptEnable */,   0x3fffff80, 0x3e555580 },
    83         {  5 /* HcInterruptDisable */,  0xffffffff, 0x59575351 },
    8483#if 0 /* deadly when missing bytes are taken as zero. */
    85         { 13 /* HcFmInterval */,        0x58871120, 0x01010101 },
     84        { 13 /* HcFmInterval */,        0xffffffff, 0x58871120, 0x01010101 },
    8685#endif
    87         { 16 /* HcPeriodicStart */,     0x01020304, 0x02010403 },
     86        { 16 /* HcPeriodicStart */,     0x00003fff, 0x01020304, 0x02010403 },
     87        { 17 /* HcLSThreshold */,       0x00000fff, 0xffffffff, 0x66666666 },
     88        { 10 /* HcBulkHeadED */,        0xfffffff0, 0xffffffff, 0xfefefef8 }, /* a bit risky... */
     89        { 11 /* HcBulkCurrentED */,     0xfffffff0, 0xffffffff, 0xfefefef8 }, /* a bit risky... */
    8890    };
    8991
     
    98100        LogRel(("TestOhciWrites: %p iReg=%2d %20s = %08RX32\n", uPtrReg.pv, iReg, g_apszRegNms[iReg], uInitialValue));
    99101
    100         bool                fDone    = true;
    101         const char         *pszError = NULL;
    102         RTCCUINTREG const   fFlags   = ASMIntDisableFlags();
    103 
    104         /*
    105          * DWORD writes.
    106          */
    107         uInitialValue = *uPtrReg.pu32;
    108         *uPtrReg.pu32 = uInitialValue;
    109         uint32_t u32A = *uPtrReg.pu32;
    110         uint32_t const uChangedValue = s_aRegs[i].uVal1 != uInitialValue ? s_aRegs[i].uVal1 : s_aRegs[i].uVal2;
    111         if (u32A == uInitialValue)
    112         {
    113             /* Change the value. */
    114             *uPtrReg.pu32 = uChangedValue;
     102        bool                fTryAgain       = true;
     103        const char         *pszError        = NULL;
     104        uint32_t            u32A            = 0;
     105        uint32_t            uChangedValue   = 0;
     106        uint32_t            uExpectedValue  = 0;
     107
     108        for (uint32_t iTry = 0; fTryAgain && iTry < 1024; iTry++)
     109        {
     110            pszError        = NULL;
     111            fTryAgain       = false;
     112            u32A            = 0;
     113            uChangedValue   = 0;
     114            uExpectedValue  = 0;
     115
     116            RTCCUINTREG const   fFlags = ASMIntDisableFlags();
     117            uInitialValue = *uPtrReg.pu32;
     118
     119            /*
     120             * DWORD writes.
     121             */
     122            if ((fTryAgain = (*uPtrReg.pu32 != uInitialValue)))
     123                break;
     124            *uPtrReg.pu32 = uInitialValue;
    115125            u32A = *uPtrReg.pu32;
    116             *uPtrReg.pu32 = uInitialValue;
    117             if (u32A != uChangedValue)
    118                 pszError = "Writing changed value failed";
     126            uChangedValue = s_aRegs[i].uVal1 != uInitialValue ? s_aRegs[i].uVal1 : s_aRegs[i].uVal2;
     127            if (u32A == uInitialValue)
     128            {
     129                /* Change the value. */
     130                *uPtrReg.pu32  = uChangedValue;
     131                u32A = *uPtrReg.pu32;
     132                *uPtrReg.pu32  = uInitialValue;
     133                uExpectedValue = uChangedValue & s_aRegs[i].fMask;
     134                if (u32A != uExpectedValue)
     135                    pszError = "Writing changed value failed";
     136                else
     137                {
     138                    u32A = *uPtrReg.pu32;
     139                    if (u32A != uInitialValue)
     140                        pszError = "Restore error 1";
     141                }
     142            }
    119143            else
    120             {
     144                pszError = "Writing back initial value failed";
     145
     146            /*
     147             * Write aligned word changes.
     148             */
     149            for (unsigned iWord = 0; iWord < 2 && !pszError && !fTryAgain; iWord++)
     150            {
     151                if ((fTryAgain = (*uPtrReg.pu32 != uInitialValue)))
     152                    break;
     153
     154                /* Change the value. */
     155                uPtrReg.pu16[iWord] = (uint16_t)(uChangedValue >> iWord * 16);
    121156                u32A = *uPtrReg.pu32;
    122                 if (u32A != uInitialValue)
    123                     pszError = "Restore error 1";
    124             }
     157                *uPtrReg.pu32  = uInitialValue;
     158                uExpectedValue = (uChangedValue & UINT32_C(0xffff) << iWord * 16) & s_aRegs[i].fMask;
     159                if (u32A != uExpectedValue)
     160                {
     161                    static const char * const s_apsz[] = { "word 0", "word 1" };
     162                    pszError = s_apsz[iWord];
     163                }
     164                else
     165                {
     166                    u32A = *uPtrReg.pu32;
     167                    if (u32A != uInitialValue)
     168                        pszError = "Restore error 2";
     169                }
     170            }
     171
     172            /*
     173             * Write aligned word change. We have to keep within the register,
     174             * unfortunately.
     175             */
     176            if (!pszError && !fTryAgain)
     177            {
     178                fTryAgain = *uPtrReg.pu32 != uInitialValue;
     179                if (!fTryAgain)
     180                {
     181                    /* Change the value. */
     182                    *(uint16_t volatile *)&uPtrReg.pu8[1] = (uint16_t)(uChangedValue >> 8);
     183                    u32A = *uPtrReg.pu32;
     184                    *uPtrReg.pu32  = uInitialValue;
     185                    uExpectedValue = (uChangedValue & UINT32_C(0x00ffff00)) & s_aRegs[i].fMask;
     186                    if (u32A != uExpectedValue)
     187                        pszError = "Unaligned word access";
     188                    else
     189                    {
     190                        u32A = *uPtrReg.pu32;
     191                        if (u32A != uInitialValue)
     192                            pszError = "Restore error 3";
     193                    }
     194                }
     195            }
     196
     197            /*
     198             * Write byte changes.
     199             */
     200            for (unsigned iByte = 0; iByte < 4 && !pszError && !fTryAgain; iByte++)
     201            {
     202                if ((fTryAgain = (*uPtrReg.pu32 != uInitialValue)))
     203                    break;
     204
     205                /* Change the value. */
     206                uPtrReg.pu8[iByte] = (uint8_t)(uChangedValue >> iByte * 8);
     207                u32A = *uPtrReg.pu32;
     208                *uPtrReg.pu32  = uInitialValue;
     209                uExpectedValue = (uChangedValue & UINT32_C(0xff) << iByte * 8) & s_aRegs[i].fMask;
     210                if (u32A != uExpectedValue)
     211                {
     212                    static const char * const s_apsz[] = { "byte 0", "byte 1", "byte 2", "byte 3" };
     213                    pszError = s_apsz[iByte];
     214                }
     215                else
     216                {
     217                    u32A = *uPtrReg.pu32;
     218                    if (u32A != uInitialValue)
     219                        pszError = "Restore error 4";
     220                }
     221            }
     222
     223            ASMSetFlags(fFlags);
     224            ASMNopPause();
    125225        }
    126         else
    127             pszError = "Writing back initial value failed";
    128 
    129 
    130         /*
    131          * Write byte changes.
    132          */
    133         for (unsigned iByte = 0; !pszError && iByte < 4; iByte)
    134         {
    135             /* Change the value. */
    136             uPtrReg.pu8[iByte] = (uint8_t)(uChangedValue >> iByte * 8);
    137             u32A = *uPtrReg.pu32;
    138             *uPtrReg.pu32 = uInitialValue;
    139             if (u32A != (uChangedValue & UINT32_C(0xff) << iByte * 8))
    140             {
    141                 static const char * const s_apsz[] = { "byte 0", "byte 1", "byte 2", "byte 3" };
    142                 pszError = s_apsz[iByte];
    143             }
    144             else
    145             {
    146                 u32A = *uPtrReg.pu32;
    147                 if (u32A != uInitialValue)
    148                     pszError = "Restore error 2";
    149             }
    150         }
    151 
    152         *uPtrReg.pu32 = uInitialValue;
    153 
    154         ASMSetFlags(fFlags);
    155         ASMNopPause();
    156226
    157227        /*
    158228         * Complain on failure.
    159229         */
    160         if (!fDone)
     230        if (fTryAgain)
    161231            LogRel(("TestOhciWrites: Warning! Register %s was never stable enough for testing! %08RX32 %08RX32 %08RX32\n",
    162232                    g_apszRegNms[iReg], uInitialValue, u32A, uChangedValue, uInitialValue));
    163233        else if (pszError)
    164234        {
    165             LogRel(("TestOhciWrites: Error! Register %s failed: %s; uInitialValue=%08RX32 uChangedValue=%08RX32 u32A=%08RX32\n",
    166                     g_apszRegNms[iReg], pszError, uInitialValue, uChangedValue, u32A));
     235            LogRel(("TestOhciWrites: Error! Register %s failed: %s; Initial=%08RX32 Changed=%08RX32 Expected=%08RX32 u32A=%08RX32\n",
     236                    g_apszRegNms[iReg], pszError, uInitialValue, uChangedValue, uExpectedValue, u32A));
    167237            fSuccess = false;
    168238        }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette