PassthruInterruptController.cpp [plain text]
extern "C" {
#include <mach/task.h>
#include <machine/machine_routines.h>
#include <pexpert/pexpert.h>
};
#include <IOKit/IOPlatformExpert.h>
#include <IOKit/IOService.h>
#include <IOKit/PassthruInterruptController.h>
#define super IOInterruptController
OSDefineMetaClassAndStructors(PassthruInterruptController, IOInterruptController);
bool
PassthruInterruptController::init(void)
{
if (!super::init() ||
!this->setProperty(gPlatformInterruptControllerName, kOSBooleanTrue) ||
!this->attach(getPlatform())) {
return false;
}
registerService();
if (getPlatform()->registerInterruptController(gPlatformInterruptControllerName, this) != kIOReturnSuccess) {
return false;
}
if (semaphore_create(kernel_task, &child_sentinel, SYNC_POLICY_FIFO, 0) != KERN_SUCCESS) {
return false;
}
return true;
}
void
PassthruInterruptController::setCPUInterruptProperties(IOService *service)
{
if ((service->getProperty(gIOInterruptControllersKey) != NULL) &&
(service->getProperty(gIOInterruptSpecifiersKey) != NULL)) {
return;
}
long zero = 0;
OSArray *specifier = OSArray::withCapacity(1);
OSData *tmpData = OSData::withBytes(&zero, sizeof(zero));
specifier->setObject(tmpData);
tmpData->release();
service->setProperty(gIOInterruptSpecifiersKey, specifier);
specifier->release();
OSArray *controller = OSArray::withCapacity(1);
controller->setObject(gPlatformInterruptControllerName);
service->setProperty(gIOInterruptControllersKey, controller);
controller->release();
}
IOReturn
PassthruInterruptController::registerInterrupt(IOService *nub,
int source,
void *target,
IOInterruptHandler handler,
void *refCon)
{
child_handler = handler;
child_nub = nub;
child_target = target;
child_refCon = refCon;
semaphore_signal(child_sentinel);
return kIOReturnSuccess;
}
void *
PassthruInterruptController::waitForChildController(void)
{
semaphore_wait(child_sentinel);
return child_target;
}
IOReturn
PassthruInterruptController::getInterruptType(IOService *,
int ,
int *interruptType)
{
if (interruptType == NULL) {
return kIOReturnBadArgument;
}
*interruptType = kIOInterruptTypeLevel;
return kIOReturnSuccess;
}
IOReturn
PassthruInterruptController::enableInterrupt(IOService *,
int )
{
return kIOReturnSuccess;
}
IOReturn
PassthruInterruptController::disableInterrupt(IOService *,
int )
{
return kIOReturnSuccess;
}
IOReturn
PassthruInterruptController::causeInterrupt(IOService *,
int )
{
ml_cause_interrupt();
return kIOReturnSuccess;
}
IOReturn
PassthruInterruptController::handleInterrupt(void *,
IOService *,
int source)
{
panic("handleInterrupt shouldn't be invoked directly");
}
void
PassthruInterruptController::externalInterrupt(void)
{
child_handler(child_target, child_refCon, child_nub, 0);
}