2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _IOKIT_IOSERVICEPMPRIVATE_H
30 #define _IOKIT_IOSERVICEPMPRIVATE_H
32 #include <IOKit/IOCommand.h>
33 #include <IOKit/IOEventSource.h>
35 //******************************************************************************
37 //******************************************************************************
41 kIOPMRequestTypeInvalid
= 0x00,
42 kIOPMRequestTypePMStop
= 0x01,
43 kIOPMRequestTypeAddPowerChild1
= 0x02,
44 kIOPMRequestTypeAddPowerChild2
= 0x03,
45 kIOPMRequestTypeAddPowerChild3
= 0x04,
46 kIOPMRequestTypeRegisterPowerDriver
= 0x05,
47 kIOPMRequestTypeAdjustPowerState
= 0x06,
48 kIOPMRequestTypePowerDomainWillChange
= 0x07,
49 kIOPMRequestTypePowerDomainDidChange
= 0x08,
50 kIOPMRequestTypePowerOverrideOnPriv
= 0x09,
51 kIOPMRequestTypePowerOverrideOffPriv
= 0x0A,
52 kIOPMRequestTypeActivityTickle
= 0x0B,
53 kIOPMRequestTypeRequestPowerState
= 0x0C,
54 kIOPMRequestTypeSynchronizePowerTree
= 0x0D,
55 kIOPMRequestTypeRequestPowerStateOverride
= 0x0E,
56 kIOPMRequestTypeSetIdleTimerPeriod
= 0x0F,
57 kIOPMRequestTypeIgnoreIdleTimer
= 0x10,
58 kIOPMRequestTypeQuiescePowerTree
= 0x11,
61 kIOPMRequestTypeReplyStart
= 0x80,
62 kIOPMRequestTypeAckPowerChange
= 0x81,
63 kIOPMRequestTypeAckSetPowerState
= 0x82,
64 kIOPMRequestTypeAllowPowerChange
= 0x83,
65 kIOPMRequestTypeCancelPowerChange
= 0x84,
66 kIOPMRequestTypeInterestChanged
= 0x85,
67 kIOPMRequestTypeIdleCancel
= 0x86,
68 kIOPMRequestTypeChildNotifyDelayCancel
= 0x87
71 //******************************************************************************
72 // PM actions - For root domain only
73 //******************************************************************************
78 (*IOPMActionPowerChangeStart
)(
81 IOPMActions
* actions
,
82 IOPMPowerStateIndex powerState
,
83 IOPMPowerChangeFlags
* changeFlags
,
84 IOPMRequestTag requestTag
);
87 (*IOPMActionPowerChangeDone
)(
90 IOPMActions
* actions
,
91 IOPMPowerStateIndex powerState
,
92 IOPMPowerChangeFlags changeFlags
,
93 IOPMRequestTag requestTag
);
96 (*IOPMActionPowerChangeOverride
)(
99 IOPMActions
* actions
,
100 IOPMPowerStateIndex
* powerState
,
101 IOPMPowerChangeFlags
* changeFlags
,
102 IOPMRequestTag requestTag
);
105 (*IOPMActionActivityTickle
)(
108 IOPMActions
* actions
);
111 (*IOPMActionUpdatePowerClient
)(
114 IOPMActions
* actions
,
115 const OSSymbol
* powerClient
,
116 IOPMPowerStateIndex oldPowerState
,
117 IOPMPowerStateIndex newPowerState
123 IOPMActionPowerChangeStart actionPowerChangeStart
;
124 IOPMActionPowerChangeDone actionPowerChangeDone
;
125 IOPMActionPowerChangeOverride actionPowerChangeOverride
;
126 IOPMActionActivityTickle actionActivityTickle
;
127 IOPMActionUpdatePowerClient actionUpdatePowerClient
;
130 // IOPMActions parameter flags
132 kPMActionsFlagIsDisplayWrangler
= 0x00000100,
133 kPMActionsFlagIsGraphicsDevice
= 0x00000200,
134 kPMActionsFlagIsAudioDevice
= 0x00000400,
135 kPMActionsFlagLimitPower
= 0x00000800,
136 kPMActionsPCIBitNumberMask
= 0x000000ff
139 //******************************************************************************
140 // Internal concise representation of IOPMPowerState
143 IOPMPowerFlags capabilityFlags
;
144 IOPMPowerFlags outputPowerFlags
;
145 IOPMPowerFlags inputPowerFlags
;
146 uint32_t staticPower
;
147 uint32_t settleUpTime
;
148 uint32_t settleDownTime
;
149 IOPMPowerStateIndex stateOrder
;
150 IOPMPowerStateIndex stateOrderToIndex
;
153 //******************************************************************************
155 //******************************************************************************
157 class IOServicePM
: public OSObject
159 friend class IOService
;
160 friend class IOPMWorkQueue
;
162 OSDeclareDefaultStructors( IOServicePM
)
165 // Link IOServicePM objects on IOPMWorkQueue.
166 queue_chain_t WorkChain
;
168 // Queue of IOPMRequest objects.
169 queue_head_t RequestHead
;
171 // IOService creator and owner.
174 // List of interested drivers (protected by PMLock).
175 IOPMinformeeList
* InterestedDrivers
;
177 // How long to wait for controlling driver to acknowledge.
178 IOReturn DriverTimer
;
180 // Current power management machine state.
181 uint32_t MachineState
;
183 thread_call_t AckTimer
;
184 thread_call_t SettleTimer
;
185 thread_call_t IdleTimer
;
186 thread_call_t WatchdogTimer
;
187 thread_call_t SpinDumpTimer
;
189 IOLock
* WatchdogLock
;
190 OSArray
* BlockedArray
;
191 uint64_t PendingResponseDeadline
;
192 uint64_t WatchdogDeadline
;
194 // Settle time after changing power state.
195 uint32_t SettleTimeUS
;
196 uint32_t IdleTimerGeneration
;
198 // The flags describing current change note.
199 IOPMPowerChangeFlags HeadNoteChangeFlags
;
201 // The new power state number being changed to.
202 IOPMPowerStateIndex HeadNotePowerState
;
204 // Points to the entry in the power state array.
205 IOPMPSEntry
* HeadNotePowerArrayEntry
;
207 // Power flags supplied by all parents (domain).
208 IOPMPowerFlags HeadNoteDomainFlags
;
210 // Power flags supplied by domain accounting for parent changes.
211 IOPMPowerFlags HeadNoteDomainTargetFlags
;
213 // Connection attached to the changing parent.
214 IOPowerConnection
* HeadNoteParentConnection
;
216 // Power flags supplied by the changing parent.
217 IOPMPowerFlags HeadNoteParentFlags
;
219 // Number of acks still outstanding.
220 uint32_t HeadNotePendingAcks
;
225 unsigned int InitialPowerChange
:1;
226 unsigned int InitialSetPowerState
:1;
227 unsigned int DeviceOverrideEnabled
:1;
228 unsigned int DoNotPowerDown
:1;
229 unsigned int ParentsKnowState
:1;
230 unsigned int StrictTreeOrder
:1;
231 unsigned int IdleTimerStopped
:1;
232 unsigned int AdjustPowerScheduled
:1;
234 unsigned int IsPreChange
:1;
235 unsigned int DriverCallBusy
:1;
236 unsigned int PCDFunctionOverride
:1;
237 unsigned int IdleTimerIgnored
:1;
238 unsigned int HasAdvisoryDesire
:1;
239 unsigned int AdvisoryTickleUsed
:1;
240 unsigned int ResetPowerStateOnWake
:1;
242 // Time of last device activity.
243 AbsoluteTime DeviceActiveTimestamp
;
244 AbsoluteTime MaxPowerStateEntryTime
;
245 AbsoluteTime MaxPowerStateExitTime
;
247 // Used to protect activity flag.
248 IOLock
* ActivityLock
;
250 // Idle timer's period in seconds.
251 unsigned long IdleTimerPeriod
;
252 unsigned long IdleTimerMinPowerState
;
253 unsigned long NextIdleTimerPeriod
;
254 AbsoluteTime IdleTimerStartTime
;
256 // Power state desired by a subclassed device object.
257 IOPMPowerStateIndex DeviceDesire
;
259 // This is the power state we desire currently.
260 IOPMPowerStateIndex DesiredPowerState
;
262 // This is what our parent thinks our need is.
263 IOPMPowerFlags PreviousRequestPowerFlags
;
265 // Cache result from getName(), used in logging.
268 // Number of power states in the power array.
269 IOPMPowerStateIndex NumberOfPowerStates
;
271 // Ordered highest power state in the power array.
272 IOPMPowerStateIndex HighestPowerState
;
274 // Power state array.
275 IOPMPSEntry
* PowerStates
;
277 // The controlling driver.
278 IOService
* ControllingDriver
;
280 // Our current power state.
281 IOPMPowerStateIndex CurrentPowerState
;
283 // Logical OR of power flags for each power domain parent.
284 IOPMPowerFlags ParentsCurrentPowerFlags
;
286 // The highest power state we can achieve in current power domain.
287 IOPMPowerStateIndex MaxPowerState
;
289 // Logical OR of all output power flags in the power state array.
290 IOPMPowerFlags MergedOutputPowerFlags
;
292 // OSArray which manages responses from notified apps and clients.
293 OSArray
* ResponseArray
;
294 OSArray
* NotifyClientArray
;
296 // Used to uniquely identify power management notification to apps and clients.
299 // Used to communicate desired function to tellClientsWithResponse().
300 // This is used because it avoids changing the signatures of the affected virtual methods.
301 int OutOfBandParameter
;
303 AbsoluteTime DriverCallStartTime
;
304 IOPMPowerFlags CurrentCapabilityFlags
;
305 unsigned long CurrentPowerConsumption
;
306 IOPMPowerStateIndex TempClampPowerState
;
307 OSArray
* NotifyChildArray
;
308 OSDictionary
* PowerClients
;
309 thread_call_t DriverCallEntry
;
310 void * DriverCallParamPtr
;
311 IOItemCount DriverCallParamCount
;
312 IOItemCount DriverCallParamSlots
;
313 uint32_t DriverCallReason
;
314 uint32_t OutOfBandMessage
;
315 uint32_t TempClampCount
;
316 uint32_t OverrideMaxPowerState
;
317 uint32_t DeviceUsablePowerState
;
319 // Protected by ActivityLock - BEGIN
320 IOPMPowerStateIndex ActivityTicklePowerState
;
321 IOPMPowerStateIndex AdvisoryTicklePowerState
;
322 uint32_t ActivityTickleCount
;
323 uint32_t DeviceWasActive
: 1;
324 uint32_t AdvisoryTickled
: 1;
325 // Protected by ActivityLock - END
328 uint32_t SavedMachineState
;
330 // Protected by PMLock - BEGIN
333 uint32_t PMDriverCallWait
: 1;
336 queue_head_t PMDriverCallQueue
;
337 OSSet
* InsertInterestSet
;
338 OSSet
* RemoveInterestSet
;
341 uint32_t ReportClientCnt
;
343 // Protected by PMLock - END
349 IOPMActions PMActions
;
351 // Serialize IOServicePM state for debug output.
352 IOReturn
gatedSerialize( OSSerialize
* s
) const;
353 virtual bool serialize( OSSerialize
* s
) const APPLE_KEXT_OVERRIDE
;
356 void pmPrint( uint32_t event
, uintptr_t param1
, uintptr_t param2
) const;
357 void pmTrace( uint32_t event
, uint32_t eventFunc
, uintptr_t param1
, uintptr_t param2
) const;
360 #define fOwner pwrMgt->Owner
361 #define fInterestedDrivers pwrMgt->InterestedDrivers
362 #define fDriverTimer pwrMgt->DriverTimer
363 #define fMachineState pwrMgt->MachineState
364 #define fAckTimer pwrMgt->AckTimer
365 #define fSettleTimer pwrMgt->SettleTimer
366 #define fIdleTimer pwrMgt->IdleTimer
367 #define fWatchdogTimer pwrMgt->WatchdogTimer
368 #define fWatchdogDeadline pwrMgt->WatchdogDeadline
369 #define fWatchdogLock pwrMgt->WatchdogLock
370 #define fBlockedArray pwrMgt->BlockedArray
371 #define fPendingResponseDeadline pwrMgt->PendingResponseDeadline
372 #define fSpinDumpTimer pwrMgt->SpinDumpTimer
373 #define fSettleTimeUS pwrMgt->SettleTimeUS
374 #define fIdleTimerGeneration pwrMgt->IdleTimerGeneration
375 #define fHeadNoteChangeFlags pwrMgt->HeadNoteChangeFlags
376 #define fHeadNotePowerState pwrMgt->HeadNotePowerState
377 #define fHeadNotePowerArrayEntry pwrMgt->HeadNotePowerArrayEntry
378 #define fHeadNoteDomainFlags pwrMgt->HeadNoteDomainFlags
379 #define fHeadNoteDomainTargetFlags pwrMgt->HeadNoteDomainTargetFlags
380 #define fHeadNoteParentConnection pwrMgt->HeadNoteParentConnection
381 #define fHeadNoteParentFlags pwrMgt->HeadNoteParentFlags
382 #define fHeadNotePendingAcks pwrMgt->HeadNotePendingAcks
383 #define fPMLock pwrMgt->PMLock
384 #define fInitialPowerChange pwrMgt->InitialPowerChange
385 #define fInitialSetPowerState pwrMgt->InitialSetPowerState
386 #define fDeviceOverrideEnabled pwrMgt->DeviceOverrideEnabled
387 #define fDoNotPowerDown pwrMgt->DoNotPowerDown
388 #define fParentsKnowState pwrMgt->ParentsKnowState
389 #define fStrictTreeOrder pwrMgt->StrictTreeOrder
390 #define fIdleTimerStopped pwrMgt->IdleTimerStopped
391 #define fAdjustPowerScheduled pwrMgt->AdjustPowerScheduled
392 #define fIsPreChange pwrMgt->IsPreChange
393 #define fDriverCallBusy pwrMgt->DriverCallBusy
394 #define fPCDFunctionOverride pwrMgt->PCDFunctionOverride
395 #define fIdleTimerIgnored pwrMgt->IdleTimerIgnored
396 #define fHasAdvisoryDesire pwrMgt->HasAdvisoryDesire
397 #define fAdvisoryTickleUsed pwrMgt->AdvisoryTickleUsed
398 #define fResetPowerStateOnWake pwrMgt->ResetPowerStateOnWake
399 #define fDeviceActiveTimestamp pwrMgt->DeviceActiveTimestamp
400 #define fMaxPowerStateEntryTime pwrMgt->MaxPowerStateEntryTime
401 #define fMaxPowerStateExitTime pwrMgt->MaxPowerStateExitTime
402 #define fActivityLock pwrMgt->ActivityLock
403 #define fIdleTimerPeriod pwrMgt->IdleTimerPeriod
404 #define fIdleTimerMinPowerState pwrMgt->IdleTimerMinPowerState
405 #define fNextIdleTimerPeriod pwrMgt->NextIdleTimerPeriod
406 #define fIdleTimerStartTime pwrMgt->IdleTimerStartTime
407 #define fDeviceDesire pwrMgt->DeviceDesire
408 #define fDesiredPowerState pwrMgt->DesiredPowerState
409 #define fPreviousRequestPowerFlags pwrMgt->PreviousRequestPowerFlags
410 #define fName pwrMgt->Name
411 #define fNumberOfPowerStates pwrMgt->NumberOfPowerStates
412 #define fHighestPowerState pwrMgt->HighestPowerState
413 #define fPowerStates pwrMgt->PowerStates
414 #define fControllingDriver pwrMgt->ControllingDriver
415 #define fCurrentPowerState pwrMgt->CurrentPowerState
416 #define fParentsCurrentPowerFlags pwrMgt->ParentsCurrentPowerFlags
417 #define fMaxPowerState pwrMgt->MaxPowerState
418 #define fMergedOutputPowerFlags pwrMgt->MergedOutputPowerFlags
419 #define fResponseArray pwrMgt->ResponseArray
420 #define fNotifyClientArray pwrMgt->NotifyClientArray
421 #define fSerialNumber pwrMgt->SerialNumber
422 #define fOutOfBandParameter pwrMgt->OutOfBandParameter
423 #define fDriverCallStartTime pwrMgt->DriverCallStartTime
424 #define fCurrentCapabilityFlags pwrMgt->CurrentCapabilityFlags
425 #define fCurrentPowerConsumption pwrMgt->CurrentPowerConsumption
426 #define fTempClampPowerState pwrMgt->TempClampPowerState
427 #define fNotifyChildArray pwrMgt->NotifyChildArray
428 #define fPowerClients pwrMgt->PowerClients
429 #define fDriverCallEntry pwrMgt->DriverCallEntry
430 #define fDriverCallParamPtr pwrMgt->DriverCallParamPtr
431 #define fDriverCallParamCount pwrMgt->DriverCallParamCount
432 #define fDriverCallParamSlots pwrMgt->DriverCallParamSlots
433 #define fDriverCallReason pwrMgt->DriverCallReason
434 #define fOutOfBandMessage pwrMgt->OutOfBandMessage
435 #define fTempClampCount pwrMgt->TempClampCount
436 #define fOverrideMaxPowerState pwrMgt->OverrideMaxPowerState
437 #define fDeviceUsablePowerState pwrMgt->DeviceUsablePowerState
438 #define fActivityTicklePowerState pwrMgt->ActivityTicklePowerState
439 #define fAdvisoryTicklePowerState pwrMgt->AdvisoryTicklePowerState
440 #define fActivityTickleCount pwrMgt->ActivityTickleCount
441 #define fDeviceWasActive pwrMgt->DeviceWasActive
442 #define fAdvisoryTickled pwrMgt->AdvisoryTickled
443 #define fWaitReason pwrMgt->WaitReason
444 #define fSavedMachineState pwrMgt->SavedMachineState
445 #define fLockedFlags pwrMgt->LockedFlags
446 #define fPMDriverCallQueue pwrMgt->PMDriverCallQueue
447 #define fInsertInterestSet pwrMgt->InsertInterestSet
448 #define fRemoveInterestSet pwrMgt->RemoveInterestSet
449 #define fReportClientCnt pwrMgt->ReportClientCnt
450 #define fReportBuf pwrMgt->ReportBuf
451 #define fPMVars pwrMgt->PMVars
452 #define fPMActions pwrMgt->PMActions
454 #define StateOrder(state) (((state) < fNumberOfPowerStates) \
455 ? pwrMgt->PowerStates[(state)].stateOrder \
457 #define StateMax(a,b) (StateOrder((a)) < StateOrder((b)) ? (b) : (a))
458 #define StateMin(a,b) (StateOrder((a)) < StateOrder((b)) ? (a) : (b))
460 #define kPowerStateZero (0)
463 When an IOService is waiting for acknowledgement to a power change
464 notification from an interested driver or the controlling driver,
465 the ack timer is ticking every tenth of a second.
466 (100000000 nanoseconds are one tenth of a second).
468 #define ACK_TIMER_PERIOD 100000000
470 #if defined(__i386__) || defined(__x86_64__)
471 #define WATCHDOG_SLEEP_TIMEOUT (180) // 180 secs
472 #define WATCHDOG_WAKE_TIMEOUT (180) // 180 secs
474 #define WATCHDOG_SLEEP_TIMEOUT (180) // 180 secs
475 #define WATCHDOG_WAKE_TIMEOUT (180) // 180 secs
478 // Max wait time in microseconds for kernel priority and capability clients
479 // with async message handlers to acknowledge.
481 #define kPriorityClientMaxWait (90 * 1000 * 1000)
482 #define kCapabilityClientMaxWait (240 * 1000 * 1000)
484 // Attributes describing a power state change.
485 // See IOPMPowerChangeFlags data type.
487 #define kIOPMParentInitiated 0x0001 // power change initiated by our parent
488 #define kIOPMSelfInitiated 0x0002 // power change initiated by this device
489 #define kIOPMNotDone 0x0004 // we couldn't make this change
490 #define kIOPMDomainWillChange 0x0008 // change started by PowerDomainWillChangeTo
491 #define kIOPMDomainDidChange 0x0010 // change started by PowerDomainDidChangeTo
492 #define kIOPMDomainPowerDrop 0x0020 // Domain is lowering power
493 #define kIOPMIgnoreChildren 0x0040 // Ignore children and driver power desires
494 #define kIOPMSkipAskPowerDown 0x0080 // skip the ask app phase
495 #define kIOPMSynchronize 0x0100 // change triggered by power tree re-sync
496 #define kIOPMSyncNoChildNotify 0x0200 // sync root domain only, not entire tree
497 #define kIOPMSyncTellPowerDown 0x0400 // send the ask/will power off messages
498 #define kIOPMSyncCancelPowerDown 0x0800 // sleep cancel for maintenance wake
499 #define kIOPMInitialPowerChange 0x1000 // set for initial power change
500 #define kIOPMRootChangeUp 0x2000 // Root power domain change up
501 #define kIOPMRootChangeDown 0x4000 // Root power domain change down
502 #define kIOPMExpireIdleTimer 0x8000 // Accelerate idle timer expiration
504 #define kIOPMRootBroadcastFlags (kIOPMSynchronize | \
505 kIOPMRootChangeUp | kIOPMRootChangeDown)
507 // Activity tickle request flags
508 #define kTickleTypePowerDrop 0x01
509 #define kTickleTypePowerRise 0x02
510 #define kTickleTypeActivity 0x04
511 #define kTickleTypeAdvisory 0x08
514 kDriverCallInformPreChange
,
515 kDriverCallInformPostChange
,
516 kDriverCallSetPowerState
,
517 kRootDomainInformPreChange
520 struct DriverCallParam
{
525 // values of OutOfBandParameter
529 kNotifyCapabilityChangeApps
,
530 kNotifyCapabilityChangePriority
533 typedef bool (*IOPMMessageFilter
)(
534 void * target
, void * object
, void * arg1
, void * arg2
, void * arg3
);
536 // used for applyToInterested
537 struct IOPMInterestContext
{
538 OSArray
* responseArray
;
539 OSArray
* notifyClients
;
540 uint16_t serialNumber
;
542 uint8_t enableTracing
;
543 uint32_t maxTimeRequested
;
544 uint32_t messageType
;
547 IOPMPowerStateIndex stateNumber
;
548 IOPMPowerFlags stateFlags
;
549 IOPMPowerChangeFlags changeFlags
;
550 const char * errorLog
;
551 IOPMMessageFilter messageFilter
;
554 // assertPMDriverCall() options
556 kIOPMADC_NoInactiveCheck
= 1
559 //******************************************************************************
560 // PM Statistics & Diagnostics
561 //******************************************************************************
563 extern const OSSymbol
*gIOPMStatsResponseTimedOut
;
564 extern const OSSymbol
*gIOPMStatsResponseCancel
;
565 extern const OSSymbol
*gIOPMStatsResponseSlow
;
566 extern const OSSymbol
*gIOPMStatsResponsePrompt
;
567 extern const OSSymbol
*gIOPMStatsDriverPSChangeSlow
;
569 //******************************************************************************
571 //******************************************************************************
573 class IOPMRequest
: public IOCommand
575 OSDeclareDefaultStructors( IOPMRequest
)
578 IOService
* fTarget
; // request target
579 IOPMRequest
* fRequestNext
; // the next request in the chain
580 IOPMRequest
* fRequestRoot
; // the root request in the call tree
581 IOItemCount fWorkWaitCount
; // execution blocked if non-zero
582 IOItemCount fFreeWaitCount
; // completion blocked if non-zero
583 uint32_t fRequestType
; // request type
584 bool fIsQuiesceBlocker
;
586 IOPMCompletionAction fCompletionAction
;
587 void * fCompletionTarget
;
588 void * fCompletionParam
;
591 uint32_t fRequestTag
;
596 inline bool isWorkBlocked( void ) const
598 return (fWorkWaitCount
!= 0);
601 inline bool isFreeBlocked( void ) const
603 return (fFreeWaitCount
!= 0);
606 inline IOPMRequest
* getNextRequest( void ) const
611 inline IOPMRequest
* getRootRequest( void ) const
613 if (fRequestRoot
) return fRequestRoot
;
615 if (fCompletionAction
) return (IOPMRequest
*) this;
620 inline uint32_t getType( void ) const
625 inline bool isReplyType( void ) const
627 return (fRequestType
> kIOPMRequestTypeReplyStart
);
630 inline IOService
* getTarget( void ) const
635 inline bool isQuiesceBlocker( void ) const
637 return fIsQuiesceBlocker
;
640 inline bool isQuiesceType( void ) const
642 return ((kIOPMRequestTypeQuiescePowerTree
== fRequestType
) &&
643 (fCompletionAction
!= 0) && (fCompletionTarget
!= 0));
646 inline void installCompletionAction(
648 IOPMCompletionAction action
,
651 fCompletionTarget
= target
;
652 fCompletionAction
= action
;
653 fCompletionParam
= param
;
656 static IOPMRequest
* create( void );
657 bool init( IOService
* owner
, IOOptionBits type
);
659 bool attachNextRequest( IOPMRequest
* next
);
660 bool detachNextRequest( void );
661 bool attachRootRequest( IOPMRequest
* root
);
662 bool detachRootRequest( void );
665 //******************************************************************************
667 //******************************************************************************
669 class IOPMRequestQueue
: public IOEventSource
671 OSDeclareDefaultStructors( IOPMRequestQueue
)
674 typedef bool (*Action
)( IOService
*, IOPMRequest
*, IOPMRequestQueue
* );
680 enum { kMaxDequeueCount
= 256 };
682 virtual bool checkForWork( void ) APPLE_KEXT_OVERRIDE
;
683 virtual void free( void ) APPLE_KEXT_OVERRIDE
;
684 virtual bool init( IOService
* inOwner
, Action inAction
);
687 static IOPMRequestQueue
* create( IOService
* inOwner
, Action inAction
);
688 void queuePMRequest( IOPMRequest
* request
);
689 void queuePMRequestChain( IOPMRequest
** requests
, IOItemCount count
);
692 //******************************************************************************
694 //******************************************************************************
696 #define WORK_QUEUE_STATS 1
698 class IOPMWorkQueue
: public IOEventSource
700 OSDeclareDefaultStructors( IOPMWorkQueue
)
703 typedef bool (*Action
)( IOService
*, IOPMRequest
*, IOPMWorkQueue
* );
706 uint64_t fStatCheckForWork
;
707 uint64_t fStatScanEntries
;
708 uint64_t fStatQueueEmpty
;
709 uint64_t fStatNoWorkDone
;
713 queue_head_t fWorkQueue
;
714 Action fInvokeAction
;
715 Action fRetireAction
;
716 uint32_t fQueueLength
;
717 uint32_t fConsumerCount
;
718 volatile uint32_t fProducerCount
;
719 IOPMRequest
* fQuiesceRequest
;
720 AbsoluteTime fQuiesceStartTime
;
721 AbsoluteTime fQuiesceFinishTime
;
723 virtual bool checkForWork( void ) APPLE_KEXT_OVERRIDE
;
724 virtual bool init( IOService
* inOwner
, Action invoke
, Action retire
);
725 bool checkRequestQueue( queue_head_t
* queue
, bool * empty
);
728 static IOPMWorkQueue
* create( IOService
* inOwner
, Action invoke
, Action retire
);
729 bool queuePMRequest( IOPMRequest
* request
, IOServicePM
* pwrMgt
);
730 void signalWorkAvailable( void );
731 void incrementProducerCount( void );
732 void attachQuiesceRequest( IOPMRequest
* quiesceRequest
);
733 void finishQuiesceRequest( IOPMRequest
* quiesceRequest
);
736 //******************************************************************************
737 // IOPMCompletionQueue
738 //******************************************************************************
740 class IOPMCompletionQueue
: public IOEventSource
742 OSDeclareDefaultStructors( IOPMCompletionQueue
)
745 typedef bool (*Action
)( IOService
*, IOPMRequest
*, IOPMCompletionQueue
* );
750 virtual bool checkForWork( void ) APPLE_KEXT_OVERRIDE
;
751 virtual bool init( IOService
* inOwner
, Action inAction
);
754 static IOPMCompletionQueue
* create( IOService
* inOwner
, Action inAction
);
755 bool queuePMRequest( IOPMRequest
* request
);
758 #endif /* !_IOKIT_IOSERVICEPMPRIVATE_H */