Skip to content

Commit 87d1f2d

Browse files
authored
Only add/remove interrupts during startup/shutdown (#105)
1 parent 9597605 commit 87d1f2d

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

VoodooRMI/Transports/I2C/RMII2C.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,22 @@ bool RMII2C::start(IOService *provider) {
9595
goto exit;
9696
}
9797

98-
/* Implementation of polling */
98+
// Try to get interrupt source, fall back to polling though if we can't get an interrupt source
9999
interrupt_source = IOInterruptEventSource::interruptEventSource(this, OSMemberFunctionCast(IOInterruptEventAction, this, &RMII2C::interruptOccured), device_nub, 0);
100-
if (!interrupt_source) {
100+
101+
if (interrupt_source) {
102+
work_loop->addEventSource(interrupt_source);
103+
} else {
101104
IOLogInfo("%s::%s Could not get interrupt event source, falling back to polling", getName(), name);
102105
interrupt_simulator = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &RMII2C::simulateInterrupt));
103106
if (!interrupt_simulator) {
104107
IOLogError("%s::%s Could not get timer event source", getName(), name);
105108
goto exit;
106109
}
110+
111+
work_loop->addEventSource(interrupt_simulator);
107112
}
113+
108114

109115
PMinit();
110116
provider->joinPMtree(this);
@@ -121,20 +127,30 @@ bool RMII2C::start(IOService *provider) {
121127
}
122128

123129
void RMII2C::releaseResources() {
124-
if (command_gate)
130+
if (command_gate) {
125131
work_loop->removeEventSource(command_gate);
126-
OSSafeReleaseNULL(command_gate);
132+
}
127133

128134
stopInterrupt();
129-
OSSafeReleaseNULL(interrupt_source);
130-
OSSafeReleaseNULL(interrupt_simulator);
131-
OSSafeReleaseNULL(work_loop);
135+
136+
if (interrupt_source) {
137+
work_loop->removeEventSource(interrupt_source);
138+
}
139+
140+
if (interrupt_simulator) {
141+
work_loop->removeEventSource(interrupt_simulator);
142+
}
132143

133144
if (device_nub) {
134145
if (device_nub->isOpen(this))
135146
device_nub->close(this);
136147
device_nub = nullptr;
137148
}
149+
150+
OSSafeReleaseNULL(command_gate);
151+
OSSafeReleaseNULL(interrupt_source);
152+
OSSafeReleaseNULL(interrupt_simulator);
153+
OSSafeReleaseNULL(work_loop);
138154
OSSafeReleaseNULL(acpi_device);
139155

140156
IOLockFree(page_mutex);
@@ -388,11 +404,9 @@ IOReturn RMII2C::setPowerState(unsigned long powerState, IOService *whatDevice){
388404

389405
void RMII2C::startInterrupt() {
390406
if (interrupt_simulator) {
391-
work_loop->addEventSource(interrupt_simulator);
392407
interrupt_simulator->setTimeoutMS(200);
393408
interrupt_simulator->enable();
394409
} else if (interrupt_source) {
395-
work_loop->addEventSource(interrupt_source);
396410
interrupt_source->enable();
397411
}
398412
}
@@ -401,9 +415,7 @@ void RMII2C::stopInterrupt() {
401415
ready = false;
402416
if (interrupt_simulator) {
403417
interrupt_simulator->disable();
404-
work_loop->removeEventSource(interrupt_simulator);
405418
} else if (interrupt_source) {
406419
interrupt_source->disable();
407-
work_loop->removeEventSource(interrupt_source);
408420
}
409421
}

0 commit comments

Comments
 (0)