]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOServicePMPrivate.h
96e5bfaccc6c7933ff41cc54544c13f3ea9fea62
[apple/xnu.git] / iokit / Kernel / IOServicePMPrivate.h
1 /*
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #ifndef _IOKIT_IOSERVICEPMPRIVATE_H
30 #define _IOKIT_IOSERVICEPMPRIVATE_H
31
32 #include <IOKit/IOCommand.h>
33 #include <IOKit/IOEventSource.h>
34
35 //******************************************************************************
36 // PM command types
37 //******************************************************************************
38
39 enum {
40 /* Command Types */
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
58 /* Reply Types */
59 kIOPMRequestTypeReplyStart = 0x80,
60 kIOPMRequestTypeAckPowerChange = 0x81,
61 kIOPMRequestTypeAckSetPowerState = 0x82,
62 kIOPMRequestTypeAllowPowerChange = 0x83,
63 kIOPMRequestTypeCancelPowerChange = 0x84,
64 kIOPMRequestTypeInterestChanged = 0x85,
65 kIOPMRequestTypeIdleCancel = 0x86,
66 kIOPMRequestTypeChildNotifyDelayCancel = 0x87
67 };
68
69 //******************************************************************************
70 // PM actions - For root domain only
71 //******************************************************************************
72
73 struct IOPMActions;
74
75 typedef void
76 (*IOPMActionPowerChangeStart)(
77 void * target,
78 IOService * service,
79 IOPMActions * actions,
80 uint32_t powerState,
81 uint32_t * changeFlags );
82
83 typedef void
84 (*IOPMActionPowerChangeDone)(
85 void * target,
86 IOService * service,
87 IOPMActions * actions,
88 uint32_t powerState,
89 uint32_t changeFlags );
90
91 typedef void
92 (*IOPMActionPowerChangeOverride)(
93 void * target,
94 IOService * service,
95 IOPMActions * actions,
96 unsigned long * powerState,
97 uint32_t * changeFlags );
98
99 typedef void
100 (*IOPMActionActivityTickle)(
101 void * target,
102 IOService * service,
103 IOPMActions * actions );
104
105 struct IOPMActions {
106 void * target;
107 uint32_t parameter;
108 IOPMActionPowerChangeStart actionPowerChangeStart;
109 IOPMActionPowerChangeDone actionPowerChangeDone;
110 IOPMActionPowerChangeOverride actionPowerChangeOverride;
111 IOPMActionActivityTickle actionActivityTickle;
112 };
113
114 //******************************************************************************
115
116 enum {
117 kIOPMEventClassSystemEvent = 0x00,
118 kIOPMEventClassDriverEvent = 0x1
119 };
120
121 class PMEventDetails : public OSObject
122 {
123 OSDeclareDefaultStructors( PMEventDetails );
124 friend class IOServicePM;
125 friend class IOPMrootDomain;
126 friend class IOPMTimeline;
127 public:
128 static PMEventDetails *eventDetails(uint32_t type,
129 const char *ownerName,
130 uintptr_t ownerUnique,
131 const char *interestName,
132 uint8_t oldState,
133 uint8_t newState,
134 uint32_t result,
135 uint32_t elapsedTimeUS);
136
137 static PMEventDetails *eventDetails(uint32_t type,
138 const char *uuid,
139 uint32_t reason,
140 uint32_t result);
141 private:
142 uint8_t eventClassifier;
143 uint32_t eventType;
144 const char *ownerName;
145 uintptr_t ownerUnique;
146 const char *interestName;
147 uint8_t oldState;
148 uint8_t newState;
149 uint32_t result;
150 uint32_t elapsedTimeUS;
151
152 const char *uuid;
153 uint32_t reason;
154 };
155
156 // Internal concise representation of IOPMPowerState
157 struct IOPMPSEntry
158 {
159 IOPMPowerFlags capabilityFlags;
160 IOPMPowerFlags outputPowerFlags;
161 IOPMPowerFlags inputPowerFlags;
162 uint32_t staticPower;
163 uint32_t settleUpTime;
164 uint32_t settleDownTime;
165 };
166
167 //******************************************************************************
168 // IOServicePM
169 //******************************************************************************
170
171 class IOServicePM : public OSObject
172 {
173 friend class IOService;
174 friend class IOPMWorkQueue;
175
176 OSDeclareDefaultStructors( IOServicePM )
177
178 private:
179 // Link IOServicePM objects on IOPMWorkQueue.
180 queue_chain_t WorkChain;
181
182 // Queue of IOPMRequest objects.
183 queue_head_t RequestHead;
184
185 // IOService creator and owner.
186 IOService * Owner;
187
188 // List of interested drivers (protected by PMLock).
189 IOPMinformeeList * InterestedDrivers;
190
191 // How long to wait for controlling driver to acknowledge.
192 IOReturn DriverTimer;
193
194 // Current power management machine state.
195 uint32_t MachineState;
196
197 thread_call_t AckTimer;
198 thread_call_t SettleTimer;
199 thread_call_t IdleTimer;
200
201 // Settle time after changing power state.
202 uint32_t SettleTimeUS;
203
204 // The flags describing current change note.
205 IOPMPowerChangeFlags HeadNoteChangeFlags;
206
207 // The new power state number being changed to.
208 IOPMPowerStateIndex HeadNotePowerState;
209
210 // Points to the entry in the power state array.
211 IOPMPSEntry * HeadNotePowerArrayEntry;
212
213 // Power flags supplied by all parents (domain).
214 IOPMPowerFlags HeadNoteDomainFlags;
215
216 // Power flags supplied by domain accounting for parent changes.
217 IOPMPowerFlags HeadNoteDomainTargetFlags;
218
219 // Connection attached to the changing parent.
220 IOPowerConnection * HeadNoteParentConnection;
221
222 // Power flags supplied by the changing parent.
223 IOPMPowerFlags HeadNoteParentFlags;
224
225 // Number of acks still outstanding.
226 uint32_t HeadNotePendingAcks;
227
228 // PM state lock.
229 IOLock * PMLock;
230
231 unsigned int InitialPowerChange:1;
232 unsigned int InitialSetPowerState:1;
233 unsigned int DeviceOverrideEnabled:1;
234 unsigned int DeviceWasActive:1;
235 unsigned int DoNotPowerDown:1;
236 unsigned int ParentsKnowState:1;
237 unsigned int StrictTreeOrder:1;
238 unsigned int IdleTimerStopped:1;
239 unsigned int AdjustPowerScheduled:1;
240 unsigned int IsPreChange:1;
241 unsigned int DriverCallBusy:1;
242 unsigned int PCDFunctionOverride:1;
243
244 // Time of last device activity.
245 AbsoluteTime DeviceActiveTimestamp;
246
247 // Used to protect activity flag.
248 IOLock * ActivityLock;
249
250 // Idle timer's period in seconds.
251 unsigned long IdleTimerPeriod;
252 unsigned long IdleTimerMinPowerState;
253 AbsoluteTime IdleTimerStartTime;
254
255 // Power state desired by a subclassed device object.
256 IOPMPowerStateIndex DeviceDesire;
257
258 // This is the power state we desire currently.
259 IOPMPowerStateIndex DesiredPowerState;
260
261 // This is what our parent thinks our need is.
262 IOPMPowerFlags PreviousRequestPowerFlags;
263
264 // Cache result from getName(), used in logging.
265 const char * Name;
266
267 // Number of power states in the power array.
268 IOPMPowerStateIndex NumberOfPowerStates;
269
270 // Power state array.
271 IOPMPSEntry * PowerStates;
272
273 // The controlling driver.
274 IOService * ControllingDriver;
275
276 // Our current power state.
277 IOPMPowerStateIndex CurrentPowerState;
278
279 // Logical OR of power flags for each power domain parent.
280 IOPMPowerFlags ParentsCurrentPowerFlags;
281
282 // The highest power state we can achieve in current power domain.
283 IOPMPowerStateIndex MaxPowerState;
284
285 // Logical OR of all output power character flags in the array.
286 IOPMPowerFlags OutputPowerCharacterFlags;
287
288 // OSArray which manages responses from notified apps and clients.
289 OSArray * ResponseArray;
290 OSArray * NotifyClientArray;
291
292 // Used to uniquely identify power management notification to apps and clients.
293 UInt16 SerialNumber;
294
295 // Used to communicate desired function to tellClientsWithResponse().
296 // This is used because it avoids changing the signatures of the affected virtual methods.
297 int OutOfBandParameter;
298
299 AbsoluteTime DriverCallStartTime;
300 IOPMPowerFlags CurrentCapabilityFlags;
301 long ActivityTicklePowerState;
302 unsigned long CurrentPowerConsumption;
303 IOPMPowerStateIndex TempClampPowerState;
304 OSArray * NotifyChildArray;
305 OSDictionary * PowerClients;
306 thread_call_t DriverCallEntry;
307 void * DriverCallParamPtr;
308 IOItemCount DriverCallParamCount;
309 IOItemCount DriverCallParamSlots;
310 uint32_t DriverCallReason;
311 uint32_t OutOfBandMessage;
312 uint32_t TempClampCount;
313 uint32_t OverrideMaxPowerState;
314 uint32_t ActivityTickleCount;
315 uint32_t WaitReason;
316 uint32_t SavedMachineState;
317 uint32_t RootDomainState;
318
319 // Protected by PMLock - BEGIN
320 struct {
321 uint32_t PMStop : 1;
322 uint32_t PMDriverCallWait : 1;
323 } LockedFlags;
324
325 queue_head_t PMDriverCallQueue;
326 OSSet * InsertInterestSet;
327 OSSet * RemoveInterestSet;
328 // Protected by PMLock - END
329
330 #if PM_VARS_SUPPORT
331 IOPMprot * PMVars;
332 #endif
333
334 IOPMActions PMActions;
335
336 // Serialize IOServicePM state for debug output.
337 IOReturn gatedSerialize( OSSerialize * s );
338 virtual bool serialize( OSSerialize * s ) const;
339 };
340
341 #define fOwner pwrMgt->Owner
342 #define fInterestedDrivers pwrMgt->InterestedDrivers
343 #define fDriverTimer pwrMgt->DriverTimer
344 #define fMachineState pwrMgt->MachineState
345 #define fAckTimer pwrMgt->AckTimer
346 #define fSettleTimer pwrMgt->SettleTimer
347 #define fIdleTimer pwrMgt->IdleTimer
348 #define fSettleTimeUS pwrMgt->SettleTimeUS
349 #define fHeadNoteChangeFlags pwrMgt->HeadNoteChangeFlags
350 #define fHeadNotePowerState pwrMgt->HeadNotePowerState
351 #define fHeadNotePowerArrayEntry pwrMgt->HeadNotePowerArrayEntry
352 #define fHeadNoteDomainFlags pwrMgt->HeadNoteDomainFlags
353 #define fHeadNoteDomainTargetFlags pwrMgt->HeadNoteDomainTargetFlags
354 #define fHeadNoteParentConnection pwrMgt->HeadNoteParentConnection
355 #define fHeadNoteParentFlags pwrMgt->HeadNoteParentFlags
356 #define fHeadNotePendingAcks pwrMgt->HeadNotePendingAcks
357 #define fPMLock pwrMgt->PMLock
358 #define fInitialPowerChange pwrMgt->InitialPowerChange
359 #define fInitialSetPowerState pwrMgt->InitialSetPowerState
360 #define fDeviceOverrideEnabled pwrMgt->DeviceOverrideEnabled
361 #define fDeviceWasActive pwrMgt->DeviceWasActive
362 #define fDoNotPowerDown pwrMgt->DoNotPowerDown
363 #define fParentsKnowState pwrMgt->ParentsKnowState
364 #define fStrictTreeOrder pwrMgt->StrictTreeOrder
365 #define fIdleTimerStopped pwrMgt->IdleTimerStopped
366 #define fAdjustPowerScheduled pwrMgt->AdjustPowerScheduled
367 #define fIsPreChange pwrMgt->IsPreChange
368 #define fDriverCallBusy pwrMgt->DriverCallBusy
369 #define fPCDFunctionOverride pwrMgt->PCDFunctionOverride
370 #define fDeviceActiveTimestamp pwrMgt->DeviceActiveTimestamp
371 #define fActivityLock pwrMgt->ActivityLock
372 #define fIdleTimerPeriod pwrMgt->IdleTimerPeriod
373 #define fIdleTimerMinPowerState pwrMgt->IdleTimerMinPowerState
374 #define fIdleTimerStartTime pwrMgt->IdleTimerStartTime
375 #define fDeviceDesire pwrMgt->DeviceDesire
376 #define fDesiredPowerState pwrMgt->DesiredPowerState
377 #define fPreviousRequestPowerFlags pwrMgt->PreviousRequestPowerFlags
378 #define fName pwrMgt->Name
379 #define fNumberOfPowerStates pwrMgt->NumberOfPowerStates
380 #define fPowerStates pwrMgt->PowerStates
381 #define fControllingDriver pwrMgt->ControllingDriver
382 #define fCurrentPowerState pwrMgt->CurrentPowerState
383 #define fParentsCurrentPowerFlags pwrMgt->ParentsCurrentPowerFlags
384 #define fMaxPowerState pwrMgt->MaxPowerState
385 #define fOutputPowerCharacterFlags pwrMgt->OutputPowerCharacterFlags
386 #define fResponseArray pwrMgt->ResponseArray
387 #define fNotifyClientArray pwrMgt->NotifyClientArray
388 #define fSerialNumber pwrMgt->SerialNumber
389 #define fOutOfBandParameter pwrMgt->OutOfBandParameter
390 #define fDriverCallStartTime pwrMgt->DriverCallStartTime
391 #define fCurrentCapabilityFlags pwrMgt->CurrentCapabilityFlags
392 #define fActivityTicklePowerState pwrMgt->ActivityTicklePowerState
393 #define fCurrentPowerConsumption pwrMgt->CurrentPowerConsumption
394 #define fTempClampPowerState pwrMgt->TempClampPowerState
395 #define fNotifyChildArray pwrMgt->NotifyChildArray
396 #define fPowerClients pwrMgt->PowerClients
397 #define fDriverCallEntry pwrMgt->DriverCallEntry
398 #define fDriverCallParamPtr pwrMgt->DriverCallParamPtr
399 #define fDriverCallParamCount pwrMgt->DriverCallParamCount
400 #define fDriverCallParamSlots pwrMgt->DriverCallParamSlots
401 #define fDriverCallReason pwrMgt->DriverCallReason
402 #define fOutOfBandMessage pwrMgt->OutOfBandMessage
403 #define fTempClampCount pwrMgt->TempClampCount
404 #define fOverrideMaxPowerState pwrMgt->OverrideMaxPowerState
405 #define fActivityTickleCount pwrMgt->ActivityTickleCount
406 #define fWaitReason pwrMgt->WaitReason
407 #define fSavedMachineState pwrMgt->SavedMachineState
408 #define fRootDomainState pwrMgt->RootDomainState
409 #define fLockedFlags pwrMgt->LockedFlags
410 #define fPMDriverCallQueue pwrMgt->PMDriverCallQueue
411 #define fInsertInterestSet pwrMgt->InsertInterestSet
412 #define fRemoveInterestSet pwrMgt->RemoveInterestSet
413 #define fPMVars pwrMgt->PMVars
414 #define fPMActions pwrMgt->PMActions
415
416 /*
417 When an IOService is waiting for acknowledgement to a power change
418 notification from an interested driver or the controlling driver,
419 the ack timer is ticking every tenth of a second.
420 (100000000 nanoseconds are one tenth of a second).
421 */
422 #define ACK_TIMER_PERIOD 100000000
423
424 // Max wait time in microseconds for kernel priority and capability clients
425 // with async message handlers to acknowledge.
426 //
427 #define kPriorityClientMaxWait (90 * 1000 * 1000)
428 #define kCapabilityClientMaxWait (240 * 1000 * 1000)
429
430 // Attributes describing a power state change.
431 // See IOPMPowerChangeFlags data type.
432 //
433 #define kIOPMParentInitiated 0x0001 // this power change initiated by our parent
434 #define kIOPMSelfInitiated 0x0002 // this power change initiated by this device
435 #define kIOPMNotDone 0x0004 // we couldn't make this change
436 #define kIOPMDomainWillChange 0x0008 // change started by PowerDomainWillChangeTo
437 #define kIOPMDomainDidChange 0x0010 // change started by PowerDomainDidChangeTo
438 #define kIOPMDomainPowerDrop 0x0020 // Domain is lowering power
439 #define kIOPMIgnoreChildren 0x0040 // Ignore children and driver power desires
440 #define kIOPMSkipAskPowerDown 0x0080 // skip the ask app phase
441 #define kIOPMSynchronize 0x0100 // change triggered by power tree re-sync
442 #define kIOPMSyncNoChildNotify 0x0200 // sync root domain only, not entire tree
443 #define kIOPMSyncTellPowerDown 0x0400 // send the ask/will power off messages
444 #define kIOPMSyncCancelPowerDown 0x0800 // sleep cancel for maintenance wake
445
446 enum {
447 kDriverCallInformPreChange,
448 kDriverCallInformPostChange,
449 kDriverCallSetPowerState
450 };
451
452 struct DriverCallParam {
453 OSObject * Target;
454 IOReturn Result;
455 };
456
457 // values of OutOfBandParameter
458 enum {
459 kNotifyApps,
460 kNotifyPriority,
461 kNotifyCapabilityChangeApps,
462 kNotifyCapabilityChangePriority
463 };
464
465 typedef bool (*IOPMMessageFilter)(
466 void * target, void * object, void * arg1, void * arg2, void * arg3 );
467
468 // used for applyToInterested
469 struct IOPMInterestContext {
470 OSArray * responseArray;
471 OSArray * notifyClients;
472 uint16_t serialNumber;
473 uint8_t isPreChange;
474 uint8_t enableTracing;
475 uint32_t maxTimeRequested;
476 uint32_t messageType;
477 uint32_t notifyType;
478 IOService * us;
479 IOPMPowerStateIndex stateNumber;
480 IOPMPowerFlags stateFlags;
481 IOPMPowerChangeFlags changeFlags;
482 const char * errorLog;
483 IOPMMessageFilter messageFilter;
484 };
485
486 // assertPMDriverCall() options
487 enum {
488 kIOPMADC_NoInactiveCheck = 1
489 };
490
491 //******************************************************************************
492 // PM Statistics & Diagnostics
493 //******************************************************************************
494
495 extern const OSSymbol *gIOPMStatsApplicationResponseTimedOut;
496 extern const OSSymbol *gIOPMStatsApplicationResponseCancel;
497 extern const OSSymbol *gIOPMStatsApplicationResponseSlow;
498
499 //******************************************************************************
500 // IOPMRequest
501 //******************************************************************************
502
503 typedef void (*IOPMCompletionAction)(void * target, void * param, IOReturn status);
504
505 class IOPMRequest : public IOCommand
506 {
507 OSDeclareDefaultStructors( IOPMRequest )
508
509 protected:
510 IOService * fTarget; // request target
511 IOPMRequest * fRequestNext; // the next request in the chain
512 IOPMRequest * fRequestRoot; // the root request in the issue tree
513 IOItemCount fWorkWaitCount; // execution blocked if non-zero
514 IOItemCount fFreeWaitCount; // completion blocked if non-zero
515 uint32_t fType; // request type
516
517 IOPMCompletionAction fCompletionAction;
518 void * fCompletionTarget;
519 void * fCompletionParam;
520 IOReturn fCompletionStatus;
521
522 public:
523 void * fArg0;
524 void * fArg1;
525 void * fArg2;
526
527 inline bool isWorkBlocked( void ) const
528 {
529 return (fWorkWaitCount != 0);
530 }
531
532 inline bool isFreeBlocked( void ) const
533 {
534 return (fFreeWaitCount != 0);
535 }
536
537 inline IOPMRequest * getNextRequest( void ) const
538 {
539 return fRequestNext;
540 }
541
542 inline IOPMRequest * getRootRequest( void ) const
543 {
544 if (fRequestRoot) return fRequestRoot;
545 if (fCompletionAction) return (IOPMRequest *) this;
546 return 0;
547 }
548
549 inline uint32_t getType( void ) const
550 {
551 return fType;
552 }
553
554 inline bool isReplyType( void ) const
555 {
556 return (fType > kIOPMRequestTypeReplyStart);
557 }
558
559 inline IOService * getTarget( void ) const
560 {
561 return fTarget;
562 }
563
564 inline bool isCompletionInstalled( void )
565 {
566 return (fCompletionAction != 0);
567 }
568
569 inline void installCompletionAction(
570 IOPMCompletionAction action,
571 void * target,
572 void * param )
573 {
574 fCompletionAction = action;
575 fCompletionTarget = target;
576 fCompletionParam = param;
577 }
578
579 static IOPMRequest * create( void );
580 bool init( IOService * owner, IOOptionBits type );
581 void reset( void );
582 bool attachNextRequest( IOPMRequest * next );
583 bool detachNextRequest( void );
584 bool attachRootRequest( IOPMRequest * root );
585 bool detachRootRequest( void );
586 };
587
588 //******************************************************************************
589 // IOPMRequestQueue
590 //******************************************************************************
591
592 class IOPMRequestQueue : public IOEventSource
593 {
594 OSDeclareDefaultStructors( IOPMRequestQueue )
595
596 public:
597 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMRequestQueue * );
598
599 protected:
600 queue_head_t fQueue;
601 IOLock * fLock;
602
603 virtual bool checkForWork( void );
604 virtual void free( void );
605 virtual bool init( IOService * inOwner, Action inAction );
606
607 public:
608 static IOPMRequestQueue * create( IOService * inOwner, Action inAction );
609 void queuePMRequest( IOPMRequest * request );
610 void queuePMRequestChain( IOPMRequest ** requests, IOItemCount count );
611 };
612
613 //******************************************************************************
614 // IOPMWorkQueue
615 //******************************************************************************
616
617 #define WORK_QUEUE_STATS 1
618
619 class IOPMWorkQueue : public IOEventSource
620 {
621 OSDeclareDefaultStructors( IOPMWorkQueue )
622
623 public:
624 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMWorkQueue * );
625
626 #if WORK_QUEUE_STATS
627 uint64_t fStatCheckForWork;
628 uint64_t fStatScanEntries;
629 uint64_t fStatQueueEmpty;
630 uint64_t fStatNoWorkDone;
631 #endif
632
633 protected:
634 queue_head_t fWorkQueue;
635 Action fWorkAction;
636 Action fRetireAction;
637 uint32_t fQueueLength;
638 uint32_t fConsumerCount;
639 volatile uint32_t fProducerCount;
640
641 virtual bool checkForWork( void );
642 virtual bool init( IOService * inOwner, Action work, Action retire );
643 bool checkRequestQueue( queue_head_t * queue, bool * empty );
644
645 public:
646 static IOPMWorkQueue * create( IOService * inOwner, Action work, Action retire );
647 bool queuePMRequest( IOPMRequest * request, IOServicePM * pwrMgt );
648 void signalWorkAvailable( void );
649 void incrementProducerCount( void );
650 };
651
652 //******************************************************************************
653 // IOPMCompletionQueue
654 //******************************************************************************
655
656 class IOPMCompletionQueue : public IOEventSource
657 {
658 OSDeclareDefaultStructors( IOPMCompletionQueue )
659
660 public:
661 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMCompletionQueue * );
662
663 protected:
664 queue_head_t fQueue;
665
666 virtual bool checkForWork( void );
667 virtual bool init( IOService * inOwner, Action inAction );
668
669 public:
670 static IOPMCompletionQueue * create( IOService * inOwner, Action inAction );
671 bool queuePMRequest( IOPMRequest * request );
672 };
673
674 #endif /* !_IOKIT_IOSERVICEPMPRIVATE_H */