PMDriverAssertionExerciser.cpp [plain text]
#include <IOKit/IOLib.h>
#include <IOKit/IOReturn.h>
#include <IOKit/IOService.h>
#include <IOKit/pwr_mgt/RootDomain.h>
#include <IOKit/pwr_mgt/IOPM.h>
#include <IOKit/pwr_mgt/IOPMPrivate.h>
#include "PMDriverAssertionExerciser.h"
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOTimerEventSource.h>
#define kTestRepeatRateMS 15*1000
#define super IOService
OSDefineMetaClassAndStructors(PMDriverAssertionExerciser, IOService)
bool PMDriverAssertionExerciser::doGetAndSetTest(void)
{
IOPMDriverAssertionLevel _l = kIOPMDriverAssertionLevelOff;
IOPMDriverAssertionLevel _newLevel = kIOPMDriverAssertionLevelOff;
IOReturn ret;
_l = rootDomain->getPMAssertionLevel(kIOPMDriverAssertionCPUBit);
IOLog("PMDriverAssertionExerciser:: Performing Set Assertion Level (current level=%d)", _l);
if (kIOPMDriverAssertionLevelOn == _l)
{
_newLevel = kIOPMDriverAssertionLevelOff;
} else if (kIOPMDriverAssertionLevelOff == _l) {
_newLevel = kIOPMDriverAssertionLevelOn;
} else {
IOLog("[FAIL] AssertionExerciser: Bogus - assertion level for 0x%04x is %d\n",
kIOPMDriverAssertionCPUBit, _l);
}
ret = rootDomain->setPMAssertionLevel(myAssertion, _newLevel);
if (kIOReturnSuccess == ret)
{
IOLog("[PASS] IOPMrootDomain::setPMAssertionLevel %d returns kIOReturnSuccess\n", (uint32_t)_newLevel);
} else {
IOLog("[FAIL] IOPMrootDomain::setPMAssertionLevel %d error 0x%08x\n", (uint32_t)_newLevel, ret);
}
return true;
}
bool PMDriverAssertionExerciser::doCreateAndReleaseTest(void)
{
IOPMDriverAssertionID newAssertion;
IOReturn ret;
IOLog("PMDriverAssertionExerciser:: Performing Create & Release Test");
newAssertion = rootDomain->createPMAssertion(kIOPMDriverAssertionCPUBit, kIOPMDriverAssertionLevelOn, this,
"com.apple.debug.PMDriverAssertionExerciser.create-release");
if (0 == myAssertion)
{
IOLog("[FAIL] IOPMrootDomain::createPMAssertion error returned NULL assertion");
goto exit;
}
ret = rootDomain->releasePMAssertion(myAssertion);
if (kIOReturnSuccess == ret) {
IOLog("[PASS] Created and Released a PM Assertion\n");
} else {
IOLog("[FAIL] Created PM Assertion, but Release returned fail code 0x%08x\n", ret);
}
exit:
return true;
}
void PMDriverAssertionExerciser::PMDriverTimerAction(OSObject *gifted __unused, IOTimerEventSource *eventSource __unused)
{
this->doGetAndSetTest();
this->doCreateAndReleaseTest();
myTimer->setTimeoutMS(kTestRepeatRateMS);
}
bool PMDriverAssertionExerciser::start( IOService *provider )
{
IOPMDriverAssertionLevel level = kIOPMDriverAssertionLevelOn;
IOPMDriverAssertionType keepCPU = kIOPMDriverAssertionCPUBit;
IOReturn ret;
IOWorkLoop *wl = NULL;
rootDomain = getPMRootDomain();
if(!rootDomain)
return false;
myAssertion = rootDomain->createPMAssertion(keepCPU, level, this,
"com.apple.debug.PMDriverAssertionExerciser.loop-on-off");
if (0 == myAssertion)
{
IOLog("IOPMrootDomain::createPMAssertion error returned NULL assertion");
return true;
}
if (!(wl = getWorkLoop()))
return true;
myTimer = IOTimerEventSource::timerEventSource(this,
OSMemberFunctionCast(IOTimerEventSource::Action, this,
&PMDriverAssertionExerciser::PMDriverTimerAction));
if (myTimer) {
myTimer->setTimeoutMS(15*1000);
wl->addEventSource(myTimer);
}
PMinit();
provider->joinPMtree(this);
return true;
}
void PMDriverAssertionExerciser::stop( IOService *provider )
{
IOReturn ret;
if (myAssertion)
ret = rootDomain->releasePMAssertion(myAssertion);
return;
}