/*
- * Copyright (c) 2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2019-2020 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <IOKit/IOCommand.h>
#include <IOKit/IOEventSource.h>
+#define USE_SETTLE_TIMER 0
+
//******************************************************************************
// PM command types
//******************************************************************************
void * target,
IOService * service,
IOPMActions * actions,
+ const IOPMRequest * request,
IOPMPowerStateIndex powerState,
- IOPMPowerChangeFlags * changeFlags,
- IOPMRequestTag requestTag );
+ IOPMPowerChangeFlags * changeFlagsPtr );
typedef void
(*IOPMActionPowerChangeDone)(
void * target,
IOService * service,
IOPMActions * actions,
+ const IOPMRequest * request,
IOPMPowerStateIndex powerState,
- IOPMPowerChangeFlags changeFlags,
- IOPMRequestTag requestTag );
+ IOPMPowerChangeFlags changeFlags );
typedef void
(*IOPMActionPowerChangeOverride)(
void * target,
IOService * service,
IOPMActions * actions,
- IOPMPowerStateIndex * powerState,
- IOPMPowerChangeFlags * changeFlags,
- IOPMRequestTag requestTag );
+ const IOPMRequest * request,
+ IOPMPowerStateIndex * powerStatePtr,
+ IOPMPowerChangeFlags * changeFlagsPtr );
typedef void
(*IOPMActionActivityTickle)(
IOPMActions * actions,
const OSSymbol * powerClient,
IOPMPowerStateIndex oldPowerState,
- IOPMPowerStateIndex newPowerState
- );
+ IOPMPowerStateIndex newPowerState );
struct IOPMActions {
void * target;
- uint32_t parameter;
IOPMActionPowerChangeStart actionPowerChangeStart;
IOPMActionPowerChangeDone actionPowerChangeDone;
IOPMActionPowerChangeOverride actionPowerChangeOverride;
IOPMActionActivityTickle actionActivityTickle;
IOPMActionUpdatePowerClient actionUpdatePowerClient;
+ uint32_t darkWakePowerState;
+ uint16_t flags;
+ uint16_t state;
+};
+
+// IOPMActions flags
+enum {
+ kPMActionsPCIBitNumberMask = 0x00ff,
+ kPMActionsFlagIsDisplayWrangler = 0x0100,
+ kPMActionsFlagIsGraphicsDriver = 0x0200,
+ kPMActionsFlagIsAudioDriver = 0x0400,
+ kPMActionsFlagHasDarkWakePowerState = 0x0800
};
-// IOPMActions parameter flags
+// IOPMActions state
enum {
- kPMActionsFlagIsDisplayWrangler = 0x00000100,
- kPMActionsFlagIsGraphicsDevice = 0x00000200,
- kPMActionsFlagIsAudioDevice = 0x00000400,
- kPMActionsFlagLimitPower = 0x00000800,
- kPMActionsPCIBitNumberMask = 0x000000ff
+ kPMActionsStatePowerClamped = 0x0001
};
//******************************************************************************
IOPMPowerFlags capabilityFlags;
IOPMPowerFlags outputPowerFlags;
IOPMPowerFlags inputPowerFlags;
- uint32_t staticPower;
+ unsigned long staticPower;
+#if USE_SETTLE_TIMER
uint32_t settleUpTime;
uint32_t settleDownTime;
+#endif
IOPMPowerStateIndex stateOrder;
IOPMPowerStateIndex stateOrderToIndex;
};
friend class IOService;
friend class IOPMWorkQueue;
- OSDeclareDefaultStructors( IOServicePM )
+ OSDeclareDefaultStructors( IOServicePM );
private:
// Link IOServicePM objects on IOPMWorkQueue.
uint32_t MachineState;
thread_call_t AckTimer;
+#if USE_SETTLE_TIMER
thread_call_t SettleTimer;
+#endif
thread_call_t IdleTimer;
thread_call_t WatchdogTimer;
thread_call_t SpinDumpTimer;
uint64_t WatchdogDeadline;
// Settle time after changing power state.
+#if USE_SETTLE_TIMER
uint32_t SettleTimeUS;
- uint32_t IdleTimerGeneration;
+#endif
+ IOPMPowerStateIndex IdleTimerGeneration;
// The flags describing current change note.
IOPMPowerChangeFlags HeadNoteChangeFlags;
IOLock * ActivityLock;
// Idle timer's period in seconds.
- unsigned long IdleTimerPeriod;
- unsigned long IdleTimerMinPowerState;
- unsigned long NextIdleTimerPeriod;
+ int IdleTimerPeriod;
+ int NextIdleTimerPeriod;
+ IOPMPowerStateIndex IdleTimerMinPowerState;
AbsoluteTime IdleTimerStartTime;
// Power state desired by a subclassed device object.
OSArray * NotifyClientArray;
// Used to uniquely identify power management notification to apps and clients.
- UInt16 SerialNumber;
+ uint16_t SerialNumber;
// Used to communicate desired function to tellClientsWithResponse().
// This is used because it avoids changing the signatures of the affected virtual methods.
uint32_t DriverCallReason;
uint32_t OutOfBandMessage;
uint32_t TempClampCount;
- uint32_t OverrideMaxPowerState;
- uint32_t DeviceUsablePowerState;
+ IOPMPowerStateIndex OverrideMaxPowerState;
+ IOPMPowerStateIndex DeviceUsablePowerState;
// Protected by ActivityLock - BEGIN
IOPMPowerStateIndex ActivityTicklePowerState;
#define fWatchdogLock pwrMgt->WatchdogLock
#define fBlockedArray pwrMgt->BlockedArray
#define fPendingResponseDeadline pwrMgt->PendingResponseDeadline
-#define fSpinDumpTimer pwrMgt->SpinDumpTimer
#define fSettleTimeUS pwrMgt->SettleTimeUS
#define fIdleTimerGeneration pwrMgt->IdleTimerGeneration
#define fHeadNoteChangeFlags pwrMgt->HeadNoteChangeFlags
#define WATCHDOG_SLEEP_TIMEOUT (180) // 180 secs
#define WATCHDOG_WAKE_TIMEOUT (180) // 180 secs
#else
-#define WATCHDOG_SLEEP_TIMEOUT (180) // 180 secs
-#define WATCHDOG_WAKE_TIMEOUT (180) // 180 secs
+#define WATCHDOG_SLEEP_TIMEOUT (35) // 35 secs (kMaxTimeRequested + 5s)
+#define WATCHDOG_WAKE_TIMEOUT (35) // 35 secs (kMaxTimeRequested + 5s)
#endif
// Max wait time in microseconds for kernel priority and capability clients
uint32_t maxTimeRequested;
uint32_t messageType;
uint32_t notifyType;
+ uint32_t skippedInDark;
+ uint32_t notSkippedInDark;
IOService * us;
IOPMPowerStateIndex stateNumber;
IOPMPowerFlags stateFlags;
// assertPMDriverCall() options
enum {
- kIOPMADC_NoInactiveCheck = 1
+ kIOPMDriverCallNoInactiveCheck = 1
+};
+
+// assertPMDriverCall() method
+enum {
+ kIOPMDriverCallMethodUnknown = 0,
+ kIOPMDriverCallMethodSetPowerState = 1,
+ kIOPMDriverCallMethodWillChange = 2,
+ kIOPMDriverCallMethodDidChange = 3,
+ kIOPMDriverCallMethodChangeDone = 4,
+ kIOPMDriverCallMethodSetAggressive = 5
};
//******************************************************************************
// PM Statistics & Diagnostics
//******************************************************************************
-extern const OSSymbol *gIOPMStatsResponseTimedOut;
-extern const OSSymbol *gIOPMStatsResponseCancel;
-extern const OSSymbol *gIOPMStatsResponseSlow;
-extern const OSSymbol *gIOPMStatsResponsePrompt;
-extern const OSSymbol *gIOPMStatsDriverPSChangeSlow;
+extern OSPtr<const OSSymbol> gIOPMStatsResponseTimedOut;
+extern OSPtr<const OSSymbol> gIOPMStatsResponseCancel;
+extern OSPtr<const OSSymbol> gIOPMStatsResponseSlow;
+extern OSPtr<const OSSymbol> gIOPMStatsResponsePrompt;
+extern OSPtr<const OSSymbol> gIOPMStatsDriverPSChangeSlow;
//******************************************************************************
// IOPMRequest
class IOPMRequest : public IOCommand
{
- OSDeclareDefaultStructors( IOPMRequest )
+ OSDeclareDefaultStructors( IOPMRequest );
protected:
- IOService * fTarget; // request target
- IOPMRequest * fRequestNext; // the next request in the chain
- IOPMRequest * fRequestRoot; // the root request in the call tree
- IOItemCount fWorkWaitCount;// execution blocked if non-zero
- IOItemCount fFreeWaitCount;// completion blocked if non-zero
- uint32_t fRequestType; // request type
+ IOService * fTarget; // request target
+ IOPMRequest * fRequestNext; // the next request in the chain
+ IOPMRequest * fRequestRoot; // the root request in the call tree
+ uint32_t fWorkWaitCount; // execution blocked if non-zero
+ uint32_t fFreeWaitCount; // completion blocked if non-zero
+ uint64_t fTimestamp; // MCTU
+ uint32_t fRequestType; // request type
bool fIsQuiesceBlocker;
IOPMCompletionAction fCompletionAction;
void * fCompletionParam;
public:
- uint32_t fRequestTag;
+ uint32_t fTag;
void * fArg0;
void * fArg1;
void * fArg2;
return (IOPMRequest *) this;
}
#endif
- return 0;
+ return NULL;
}
inline uint32_t
return fRequestType;
}
+ inline uint32_t
+ getTag( void ) const
+ {
+ return fTag;
+ }
+
inline bool
isReplyType( void ) const
{
isQuiesceType( void ) const
{
return (kIOPMRequestTypeQuiescePowerTree == fRequestType) &&
- (fCompletionAction != 0) && (fCompletionTarget != 0);
+ (fCompletionAction != NULL) && (fCompletionTarget != NULL);
}
inline void
fCompletionParam = param;
}
+ inline void
+ setTimestamp( uint64_t time )
+ {
+ fTimestamp = time;
+ }
+
+ inline uint64_t
+ getTimestamp( void ) const
+ {
+ return fTimestamp;
+ }
+
static IOPMRequest * create( void );
bool init( IOService * owner, IOOptionBits type );
void reset( void );
class IOPMRequestQueue : public IOEventSource
{
- OSDeclareDefaultStructors( IOPMRequestQueue )
+ OSDeclareDefaultStructors( IOPMRequestQueue );
public:
typedef bool (*Action)( IOService *, IOPMRequest *, IOPMRequestQueue * );
public:
static IOPMRequestQueue * create( IOService * inOwner, Action inAction );
- void queuePMRequest( IOPMRequest * request );
+ void queuePMRequest( LIBKERN_CONSUMED IOPMRequest * request );
void queuePMRequestChain( IOPMRequest ** requests, IOItemCount count );
};
class IOPMWorkQueue : public IOEventSource
{
- OSDeclareDefaultStructors( IOPMWorkQueue )
+ OSDeclareDefaultStructors( IOPMWorkQueue );
public:
typedef bool (*Action)( IOService *, IOPMRequest *, IOPMWorkQueue * );
class IOPMCompletionQueue : public IOEventSource
{
- OSDeclareDefaultStructors( IOPMCompletionQueue )
+ OSDeclareDefaultStructors( IOPMCompletionQueue );
public:
typedef bool (*Action)( IOService *, IOPMRequest *, IOPMCompletionQueue * );