IOFireWirePowerManager.cpp [plain text]
#include <IOKit/firewire/IOFireWirePowerManager.h>
#include <IOKit/firewire/IOFireWireController.h>
#import "FWDebugging.h"
OSDefineMetaClassAndStructors(IOFireWirePowerManager, OSObject)
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 0);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 1);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 2);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 3);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 4);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 5);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 6);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 7);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 8);
OSMetaClassDefineReservedUnused(IOFireWirePowerManager, 9);
#pragma mark -
IOFireWirePowerManager * IOFireWirePowerManager::createWithController( IOFireWireController * controller )
{
IOFireWirePowerManager * me = OSTypeAlloc( IOFireWirePowerManager );
if( me != NULL )
{
if( !me->initWithController(controller) )
{
me->release();
me = NULL;
}
}
return me;
}
bool IOFireWirePowerManager::initWithController( IOFireWireController * controller )
{
bool success = true;
if( !OSObject::init() )
success = false;
if( success )
{
fControl = controller;
fMaximumDeciwatts = 0;
fAllocatedDeciwatts = 0;
}
return success;
}
#pragma mark -
void IOFireWirePowerManager::setMaximumDeciwatts( UInt32 deciwatts )
{
FWKLOG(( "IOFireWirePowerManager::setMaximumDeciwatts - setting maximum milliwats to %d\n", deciwatts ));
fMaximumDeciwatts = deciwatts;
}
IOReturn IOFireWirePowerManager::allocateDeciwatts( UInt32 deciwatts )
{
IOReturn status = kIOReturnSuccess;
fControl->closeGate();
FWKLOG(( "IOFireWirePowerManager::allocateDeciwatts - allocating %d deciwatts\n", deciwatts ));
if( fAllocatedDeciwatts + deciwatts <= fMaximumDeciwatts )
{
fAllocatedDeciwatts += deciwatts;
}
else
{
status = kIOReturnNoResources;
}
fControl->openGate();
return status;
}
void IOFireWirePowerManager::deallocateDeciwatts( UInt32 deciwatts )
{
fControl->closeGate();
FWKLOG(( "IOFireWirePowerManager::deallocateDeciwatts - freeing %d deciwatts\n", deciwatts ));
if( deciwatts <= fAllocatedDeciwatts )
{
fAllocatedDeciwatts -= deciwatts;
}
else
{
IOLog( "IOFireWirePowerManager::deallocateDeciwatts - freed deciwatts %d > allocated deciwatts %d!\n", (uint32_t)deciwatts, (uint32_t)fAllocatedDeciwatts );
fAllocatedDeciwatts = 0;
}
if( deciwatts != 0 )
{
fControl->messageClients( kIOFWMessagePowerStateChanged );
}
fControl->openGate();
}