/* $Id$ */
/** @file
* tstOhciRegisterAccess - OHCI Register Access Tests / Experiments.
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/asm-amd64-x86.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Register names. */
static const char * const g_apszRegNms[] =
{
/* 00 */ "HcRevision",
/* 01 */ "HcControl",
/* 02 */ "HcCommandStatus",
/* 03 */ "HcInterruptStatus",
/* 04 */ "HcInterruptEnable",
/* 05 */ "HcInterruptDisable",
/* 06 */ "HcHCCA",
/* 07 */ "HcPeriodCurrentED",
/* 08 */ "HcControlHeadED",
/* 09 */ "HcControlCurrentED",
/* 10 */ "HcBulkHeadED",
/* 11 */ "HcBulkCurrentED",
/* 12 */ "HcDoneHead",
/* 13 */ "HcFmInterval",
/* 14 */ "HcFmRemaining",
/* 15 */ "HcFmNumber",
/* 16 */ "HcPeriodicStart",
/* 17 */ "HcLSThreshold",
/* 18 */ "HcRhDescriptorA",
/* 19 */ "HcRhDescriptorB",
/* 20 */ "HcRhStatus",
/* Variable number of root hub ports: */
/* 21 */ "HcRhPortStatus[0]",
/* 22 */ "HcRhPortStatus[1]",
/* 23 */ "HcRhPortStatus[2]",
/* 24 */ "HcRhPortStatus[3]",
/* 25 */ "HcRhPortStatus[4]",
/* 26 */ "HcRhPortStatus[5]",
/* 27 */ "HcRhPortStatus[6]",
/* 28 */ "HcRhPortStatus[7]"
};
{
static struct
{
unsigned iReg;
} const s_aRegs[] =
{
#if 0 /* deadly when missing bytes are taken as zero. */
{ 13 /* HcFmInterval */, 0xffffffff, 0x58871120, 0x01010101 },
#endif
{ 16 /* HcPeriodicStart */, 0x00003fff, 0x01020304, 0x02010403 },
{ 17 /* HcLSThreshold */, 0x00000fff, 0xffffffff, 0x66666666 },
{ 10 /* HcBulkHeadED */, 0xfffffff0, 0xffffffff, 0xfefefef8 }, /* a bit risky... */
{ 11 /* HcBulkCurrentED */, 0xfffffff0, 0xffffffff, 0xfefefef8 }, /* a bit risky... */
};
bool fSuccess = true;
for (unsigned i = 0; i < RT_ELEMENTS(s_aRegs); i++)
{
LogRel(("TestOhciWrites: %p iReg=%2d %20s = %08RX32\n", uPtrReg.pv, iReg, g_apszRegNms[iReg], uInitialValue));
bool fTryAgain = true;
{
fTryAgain = false;
u32A = 0;
uChangedValue = 0;
uExpectedValue = 0;
/*
* DWORD writes.
*/
break;
if (u32A == uInitialValue)
{
/* Change the value. */
if (u32A != uExpectedValue)
pszError = "Writing changed value failed";
else
{
if (u32A != uInitialValue)
pszError = "Restore error 1";
}
}
else
pszError = "Writing back initial value failed";
/*
* Write aligned word changes.
*/
{
break;
/* Change the value. */
if (u32A != uExpectedValue)
{
}
else
{
if (u32A != uInitialValue)
pszError = "Restore error 2";
}
}
/*
* Write aligned word change. We have to keep within the register,
* unfortunately.
*/
{
if (!fTryAgain)
{
/* Change the value. */
if (u32A != uExpectedValue)
pszError = "Unaligned word access";
else
{
if (u32A != uInitialValue)
pszError = "Restore error 3";
}
}
}
/*
* Write byte changes.
*/
{
break;
/* Change the value. */
if (u32A != uExpectedValue)
{
}
else
{
if (u32A != uInitialValue)
pszError = "Restore error 4";
}
}
ASMNopPause();
}
/*
* Complain on failure.
*/
if (fTryAgain)
LogRel(("TestOhciWrites: Warning! Register %s was never stable enough for testing! %08RX32 %08RX32 %08RX32\n",
else if (pszError)
{
LogRel(("TestOhciWrites: Error! Register %s failed: %s; Initial=%08RX32 Changed=%08RX32 Expected=%08RX32 u32A=%08RX32\n",
fSuccess = false;
}
}
return fSuccess;
}
{
static struct
{
unsigned iReg;
} const s_aRegs[] =
{
#if 0 /* HCD can write this */
{ 17 /* HcLSThreshold */, 5, { 0x627, 0x628, 0x629, 0x666, 0x599, 0, 0, 0 } } /* ??? */
#endif
};
bool fSuccess = true;
for (unsigned i = 0; i < RT_ELEMENTS(s_aRegs); i++)
{
LogRel(("TestOhciReadOnly: %p iReg=%2d %20s = %08RX32\n", uPtrReg.pv, iReg, g_apszRegNms[iReg], uInitialValue));
bool fTryAgain = true;
{
fTryAgain = false;
u32A = 0;
uChangedValue = 0;
/*
* Try aligned dword, word and byte writes for now.
*/
{
if (uInitialValue == uChangedValue)
continue;
/* dword */
break;
if (u32A != uInitialValue)
pszError = "dword access";
else
{
if (u32A != uInitialValue)
pszError = "Restore error 1";
}
/* word */
{
break;
if (u32A != uInitialValue)
else
{
if (u32A != uInitialValue)
pszError = "Restore error 2";
}
}
/* byte */
{
break;
if (u32A != uInitialValue)
{
}
else
{
if (u32A != uInitialValue)
pszError = "Restore error 3";
}
}
}
ASMNopPause();
}
/*
* Complain on failure.
*/
if (fTryAgain)
LogRel(("TestOhciReadOnly: Warning! Register %s was never stable enough for testing! %08RX32 %08RX32 %08RX32\n",
else if (pszError)
{
LogRel(("TestOhciReadOnly: Error! Register %s failed: %s; uInitialValue=%08RX32 uChangedValue=%08RX32 u32A=%08RX32\n",
fSuccess = false;
}
}
return fSuccess;
}
{
/*
* We can read just about any register we like since read shouldn't have
* any side effects. However, some registers are volatile and makes for
* difficult targets, thus the ugly code.
*/
bool fSuccess = true;
{
bool fDone = false;
LogRel(("TestOhciReads: %p iReg=%2d %20s = %08RX32\n", uPtr.pv, iReg, g_apszRegNms[iReg], uInitialValue));
{
fDone = true;
/* Test byte access. */
{
{
fDone = false;
break;
}
{
};
if (u32B != uInitialValue)
{
break;
}
}
/* Test aligned word access. */
if (fDone)
{
{
{
fDone = false;
break;
}
if (u32B != uInitialValue)
{
break;
}
}
}
/* Test unaligned word access. */
if (fDone)
{
{
{
fDone = false;
break;
}
switch (iWord)
{
}
{
static const char * const s_apsz[] = { "unaligned word 0", "unaligned word 1", "unaligned word 2" };
break;
}
}
}
/* Test unaligned dword access. */
if (fDone)
{
{
{
fDone = false;
break;
}
switch (iByte)
{
case 0: break;
}
{
static const char * const s_apsz[] =
{
"unaligned dword -3", "unaligned dword -2", "unaligned dword -1",
"unaligned dword 0", "unaligned dword 1", "unaligned dword 2", "unaligned dword 3"
};
break;
}
}
}
ASMNopPause();
} /* try loop */
/*
* Complain on failure.
*/
if (!fDone)
LogRel(("TestOhciReads: Warning! Register %s was never stable enough for testing! %08RX32 %08RX32 %08RX32\n",
else if (pszError)
{
LogRel(("TestOhciReads: Error! Register %s failed: %s; uInitialValue=%08RX32 u32B=%08RX32\n",
fSuccess = false;
}
}
return fSuccess;
}
{
/*
* Map the OHCI registers so we can access them.
*/
if (RT_FAILURE(rc))
{
return rc;
}
rc = RTR0MemObjMapKernel(&hMapObj, hMemObj, (void *)-1, 0 /*uAlignment*/, RTMEM_PROT_READ | RTMEM_PROT_WRITE);
if (RT_SUCCESS(rc))
{
{
/*
* Do the access tests.
*/
if (fSuccess)
if (fSuccess)
if (fSuccess)
LogRel(("tstOhciRegisterAccess: Success!\n"));
else
LogRel(("tstOhciRegisterAccess: Failed!\n"));
}
else
/*
* Clean up.
*/
RTR0MemObjFree(hMapObj, false);
}
else
RTR0MemObjFree(hMemObj, false);
return rc;
}