IOReturn AppleRS232Serial::setPowerState(unsigned long powerStateOrdinal, IOService *whatDevice) { bool ok; UInt32 counter = 0; ELG(0, powerStateOrdinal, "setPowerState - powerStateOrdinal"); retain(); // paranoia is your friend, make sure we're not freed fWaitForGatedCmd = true; // could do this async, but let's be sync initially ok = thread_call_enter1(fPowerThreadCall, (void *)powerStateOrdinal); // schedule work on workloop if (ok) { // if thread was already pending ... ALERT(0, 0, "setPowerState - thread already pending?"); // a 'never' in current flow release(); // don't need/want the retain, so undo it } while (fWaitForGatedCmd) { // we're being sync for now, wait for it to finish IOSleep(2); // it should be very fast counter++; } ELG(0, counter, "setPowerState - finished after N sleeps of 2ms each"); return IOPMAckImplied; // we're done }/* end setPowerState */
void AppleUSBUHCI::RHCheckStatus() { int i; UInt16 status; /* Read port status registers. * Check for resumed ports. * If the status changed on either, call the * port status changed method. */ for (i=0; i<kUHCI_NUM_PORTS; i++) { if (!_rhPortBeingResumed[i]) // only check ports which are not being resumed { status = ReadPortStatus(i); if (status & kUHCI_PORTSC_RD) { if (_myPowerState >= kUSBPowerStateLowPower) { if (_myPowerState == kUSBPowerStateLowPower) EnsureUsability(); USBLog(3, "AppleUSBUHCI[%p]::RHCheckStatus - resume detected on port %d, spawning thread to resume", this, i+1); _rhPortBeingResumed[i] = true; thread_call_enter1(_rhResumePortTimerThread[i], (void*)(i+1)); } else { USBLog(3, "AppleUSBUHCI[%p]::RHCheckStatus - resume detected while not below low power state, not changing bits until we are back on", this); } } } } }
IOReturn IOI2CDevice::message( UInt32 type, IOService *provider, void *argument) { if (type == 0x1012c) { // DLOG("######################################\nIOI2CDevice@%lx::message called\n", fI2CAddress); if (provider == NULL) return kIOReturnBadArgument; if (fPowerStateThreadCall == 0) return kIOReturnUnsupported; if (fStateFlags & kStateFlags_TEARDOWN) return kIOReturnUnsupported; fSysPowerRef = provider; thread_call_enter1(fPowerStateThreadCall, (thread_call_param_t)(kIOI2CPowerState_OFF)); // DLOG("IOI2CDevice@%lx::message processed\n######################################\n", fI2CAddress); return kIOReturnSuccess; } return super::message(type, provider, argument); }
IOReturn IOI2CDevice::setPowerState( unsigned long newPowerState, IOService *dontCare) { DLOGPWR("IOI2CDevice@%lx::setPowerState called with state:%lu\n", fI2CAddress, newPowerState); if (pm_vars == NULL) return IOPMAckImplied; if (fPowerStateThreadCall == 0) return IOPMAckImplied; if (fCurrentPowerState == newPowerState) return IOPMAckImplied; thread_call_enter1(fPowerStateThreadCall, (thread_call_param_t)newPowerState); return kSetPowerStateTimeout; }
void darwin_iwi3945::queue_te(int num, thread_call_func_t func, thread_call_param_t par, UInt32 timei, bool start) { if (tlink[num]) queue_td(num,NULL); //IWI_DEBUG("queue_te0 %d\n",tlink[num]); if (!tlink[num]) tlink[num]=thread_call_allocate(func,this); //IWI_DEBUG("queue_te1 %d\n",tlink[num]); uint64_t timei2; if (timei) clock_interval_to_deadline(timei,kMillisecondScale,&timei2); //IWI_DEBUG("queue_te time %d %d\n",timei,timei2); int r; if (start==true && tlink[num]) { if (!par && !timei) r=thread_call_enter(tlink[num]); if (!par && timei) r=thread_call_enter_delayed(tlink[num],timei2); if (par && !timei) r=thread_call_enter1(tlink[num],par); if (par && timei) r=thread_call_enter1_delayed(tlink[num],par,timei2); } //IWI_DEBUG("queue_te result %d\n",r); }
IOReturn AppleUSBUHCI::RHSuspendPort(int port, bool suspended) { UInt16 cmd, value; USBLog(3, "AppleUSBUHCI[%p]::RHSuspendPort %d (%s) _rhPortBeingResumed[%d](%s)", this, port, suspended ? "SUSPEND" : "RESUME", (int)port-1, _rhPortBeingResumed[port-1] ? "true" : "false"); showRegisters(7, "RHSuspendPort"); port--; // convert 1-based to 0-based. if (_rhPortBeingResumed[port]) { if (!suspended) { USBLog(3, "AppleUSBUHCI[%p]::RHSuspendPort - resume on port (%d) already being resumed - gracefully ignoring", this, (int)port+1); return kIOReturnSuccess; } USBLog(1, "AppleUSBUHCI[%p]::RHSuspendPort - trying to suspend port (%d) which is being resumed - UNEXPECTED", this, (int)port+1); USBTrace( kUSBTUHCI, kTPUHCIRHSuspendPort, (uintptr_t)this, (int)port+1, 0, 0); } cmd = ioRead16(kUHCI_CMD); value = ReadPortStatus(port) & kUHCI_PORTSC_MASK; if (suspended) { value |= kUHCI_PORTSC_SUSPEND; value &= ~kUHCI_PORTSC_RD; } else { if (cmd & kUHCI_CMD_EGSM) { /* Can't un-suspend a port during global suspend. */ USBError(1, "AppleUSBUHCI[%p]: attempt to resume during global suspend", this); return kIOReturnError; } value |= (kUHCI_PORTSC_SUSPEND | kUHCI_PORTSC_RD); } // Always enable the port also. value |= kUHCI_PORTSC_PED; USBLog(5, "AppleUSBUHCI[%p]: writing (%p) to port control", this, (void*)value); WritePortStatus(port, value); if (suspended) { /* Suspending. * Sleep for 3ms to ensure nothing goes out on the bus * until devices are suspended. */ IOSleep(3); } else { // Resuming USBLog(5,"AppleUSBUHCI[%p]::RHSuspendPort - resuming port %d, calling out to timer", this, (int)port+1); _rhPortBeingResumed[port] = true; thread_call_enter1(_rhResumePortTimerThread[port], (void*)(port+1)); } USBLog(5, "AppleUSBUHCI[%p]::RHSuspendPort %d (%s) calling UIMRootHubStatusChange", this, port+1, suspended ? "SUSPEND" : "RESUME"); UIMRootHubStatusChange(); USBLog(5, "AppleUSBUHCI[%p]::RHSuspendPort %d (%s) DONE", this, port+1, suspended ? "SUSPEND" : "RESUME"); return kIOReturnSuccess; }