2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <libkern/c++/OSObject.h>
24 #include <IOKit/IOReturn.h>
26 class IOPowerConnection
;
28 // This is a list of State Changes which are in progress. Its purpose is to keep track of the
29 // notifications and acknowledgements caused by state change. A change is added to the list
30 // when either our parent notifies us that the power domain is changing state or when we decide
31 // to change power to our device or domain.
33 // A change is removed from the list when all interested parties have been informed of the upcoming
34 // change, all of them have acknowledged the notification, the change has been made, all interested
35 // parties have been informed that the change was made, and all of them have acknowledged.
37 // The list is strictly first-in, first-out. It is implemented as a circular list in a linear
38 // array. There are two pointers into the array. The circular list is empty when these two
39 // pointers are equal.
41 // More specifically, a change note is put into the array when one of these things happens:
42 // the device decides it is idle and needs to reduce power. (changePowerStateTo)
43 // the device decides it is not idle and needs to increase power. (changePowerStateTo)
44 // the controlling driver requests a state change. (changePowerStateTo)
45 // some client needs to use the device but it is powered down. (makeUsable)
46 // the parent says the domain power is changing. (powerStateWillChangeTo)
47 // a child says it no longer needs power, and all other children are similarly idle. (requestDomainState)
48 //. a child wants more power in the domain so it can raise its power state. (requestDomainState)
50 // A change note is removed from the array when all interested drivers and power domain
51 // children have acknowledged the change.
53 // Each change note contains:
54 // A flag field which describes the change.
55 // Which power state the device will be in after the change.
56 // The power flags which describe the result of this change.
58 struct changeNoteItem
{
60 unsigned long newStateNumber
;
61 IOPMPowerFlags outputPowerCharacter
;
62 IOPMPowerFlags inputPowerRequirement
;
63 IOPMPowerFlags domainState
;
64 IOPowerConnection
* parent
;
65 IOPMPowerFlags singleParentState
;
66 IOPMPowerFlags capabilityFlags
;
69 typedef struct changeNoteItem changeNoteItem
;
74 #define IOPMParentInitiated 1 // this power change initiated by our parent
75 #define IOPMWeInitiated 2 // this power change initiated by this device (not parent)
76 #define IOPMNotDone 4 // we couldn't make this change
77 #define IOPMNotInUse 8 // this list element not currently in use
78 #define IOPMDomainWillChange 16 // parent change started by PowerDomainWillChangeTo
79 #define IOPMDomainDidChange 32 // parent change started by PowerDomainDidChangeTo
82 // Length of change note list is maximum 5. There cannot be two adjacent device-initiated change notes unless
83 // one is currently being actioned, because two adjacent in-active device-initiated changes are always collapsed
84 // into one, and there cannot be more than two parent-initiated change notes in the queue (from one parent),
85 // because the parent does not
86 // initiate a change (by calling domainStateWillChange) until everybody has acknowledged the previous one
87 // (by calling domainStateDidChange), although if we are the last to send that acknowledgement, the change we
88 // are acknowledging will still be in the queue as we acknowledge, and at that point the parent can give us another
89 // (by callingdomainStateWillChange). So we need room for two parent changes, two non-adjacent device changes,
90 // one more per additional parent, say two more,
91 // and room for one more device change to get into the queue before collapsing it with its neighbor. In this case, seven
92 // entryies suffices. Or, we need
93 // room for two adjacent device changes (one in progress), a parent change, another device change, another parent change,
94 // another device change, another parent change, another device change, plus
95 // one more device change to get into the queue before collapsing it with its neighbor. Nine entries in this case.
96 // I'm not sure what irrationallity causes me to code for twenty entries in the queue.
97 #define IOPMMaxChangeNotes 20
99 class IOPMchangeNoteList
:public OSObject
101 OSDeclareDefaultStructors(IOPMchangeNoteList
)
104 unsigned long firstInList
; // points to oldest active change note in list
105 unsigned long firstUnused
; // points just beyond newest change note in list
109 changeNoteItem changeNote
[IOPMMaxChangeNotes
];
112 void initialize ( void );
114 long createChangeNote ( void );
116 long currentChange ( void );
118 long latestChange ( void );
120 IOReturn
releaseHeadChangeNote ( void );
122 IOReturn
releaseTailChangeNote ( void );
124 bool changeNoteInUse ( unsigned long ordinal
);
126 long nextChangeNote ( unsigned long ordinal
);
128 unsigned long increment (unsigned long ordinal
);
130 unsigned long decrement (unsigned long ordinal
);
132 long previousChangeNote (unsigned long ordinal
);
134 bool listEmpty ( void );