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