]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMchangeNoteList.cpp
5d8d94c8bc20041cad01b4c75f07ff364364fee9
[apple/xnu.git] / iokit / Kernel / IOPMchangeNoteList.cpp
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 <IOKit/pwr_mgt/IOPM.h>
26 #include <IOKit/pwr_mgt/IOPMchangeNoteList.h>
27
28 #define super OSObject
29 OSDefineMetaClassAndStructors(IOPMchangeNoteList,OSObject)
30
31 //*********************************************************************************
32 // init
33 //
34 //*********************************************************************************
35 void IOPMchangeNoteList::initialize ( void )
36 {
37 long i;
38
39 firstInList = 0;
40 firstUnused = 0;
41 for ( i = 0; i < IOPMMaxChangeNotes; i++ ) {
42 changeNote[i].flags = IOPMNotInUse;
43 }
44 }
45
46 //*********************************************************************************
47 // createChangeNote
48 //
49 //*********************************************************************************
50
51 long IOPMchangeNoteList::createChangeNote ( void )
52 {
53 unsigned long i, j;
54
55 i = increment(firstUnused);
56 if ( firstInList == i ) {
57 return -1;
58 }
59 j = firstUnused;
60 firstUnused = i;
61
62 return j;
63 }
64
65 //*********************************************************************************
66 // currentChange
67 //
68 // Return the ordinal of the first change note in the list.
69 // If the list is empty, return -1.
70 //*********************************************************************************
71
72 long IOPMchangeNoteList::currentChange ( void )
73 {
74 if ( firstUnused == firstInList ) {
75 return -1;
76 }
77 else {
78 return firstInList;
79 }
80 }
81
82 //*********************************************************************************
83 // latestChange
84 //
85 // Return the ordinal of the last change note in the list.
86 // If the list is empty, return -1.
87 //*********************************************************************************
88
89 long IOPMchangeNoteList::latestChange ( void )
90 {
91 if ( firstUnused == firstInList ) {
92 return -1;
93 }
94 else {
95 return decrement(firstUnused);
96 }
97 }
98
99 //*********************************************************************************
100 // releaseHeadChangeNote
101 //
102 // Mark the head node unused.
103 // This happens when the first change in the list is completely processed.
104 // That is, all interested parties have acknowledged it, and power is settled
105 // at the new level.
106 //*********************************************************************************
107
108 IOReturn IOPMchangeNoteList::releaseHeadChangeNote ( void )
109 {
110 changeNote[firstInList].flags = IOPMNotInUse;
111 firstInList = increment(firstInList);
112 return IOPMNoErr;
113 }
114
115 //*********************************************************************************
116 // releaseTailChangeNote
117 //
118 // Mark the tail node unused.
119 // This happens when a power change is queued up after another which has
120 // not yet been started, and the second one supercedes the first. The data in
121 // the second is copied into the first and the the second is released. This
122 // collapses the first change out of the list.
123 //*********************************************************************************
124
125 IOReturn IOPMchangeNoteList::releaseTailChangeNote ( void )
126 {
127 firstUnused = decrement(firstUnused);
128 changeNote[firstUnused].flags = IOPMNotInUse;
129 return IOPMNoErr;
130 }
131
132 //*********************************************************************************
133 // changeNoteInUse
134 //
135 //*********************************************************************************
136
137 bool IOPMchangeNoteList::changeNoteInUse ( unsigned long ordinal )
138 {
139 if ( changeNote[ordinal].flags == IOPMNotInUse ) {
140 return false;
141 }
142 else {
143 return true;
144 }
145 }
146
147 //*********************************************************************************
148 // nextChangeNote
149 //
150 // If the parameter corresponds to the most recent power change notification
151 // passed to drivers and children, return -1. Otherwise, return the array
152 // position of the next notification in the circular list.
153 //*********************************************************************************
154
155 long IOPMchangeNoteList::nextChangeNote ( unsigned long ordinal )
156 {
157 unsigned long i;
158
159 i = increment(ordinal);
160 if ( i == firstUnused) {
161 return -1;
162 }
163 return ( i );
164 }
165
166 //*********************************************************************************
167 // increment
168 //
169 // Increment the parameter mod the circular list size and return it.
170 //*********************************************************************************
171
172 unsigned long IOPMchangeNoteList::increment ( unsigned long ordinal )
173 {
174 if ( ordinal == (IOPMMaxChangeNotes - 1) ) {
175 return 0;
176 }
177 else {
178 return ordinal + 1;
179 }
180 }
181
182 //*********************************************************************************
183 // decrement
184 //
185 // Decrement the parameter mod the circular list size and return it.
186 //*********************************************************************************
187
188 unsigned long IOPMchangeNoteList::decrement ( unsigned long ordinal )
189 {
190 if ( ordinal == 0 ) {
191 return IOPMMaxChangeNotes - 1;
192 }
193 else {
194 return ordinal - 1;
195 }
196 }
197
198 //*********************************************************************************
199 // previousChangeNote
200 //
201 // If the parameter corresponds to the oldest power change notification
202 // passed to drivers and children, return -1. Otherwise, return the array
203 // position of the previous notification in the circular list.
204 //*********************************************************************************
205
206 long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal )
207 {
208 if ( ordinal == firstInList ) {
209 return -1;
210 }
211 return decrement(ordinal);
212 }
213
214 //*********************************************************************************
215 // listEmpty
216 //
217 //*********************************************************************************
218
219 bool IOPMchangeNoteList::listEmpty ( void )
220 {
221 return ( firstInList == firstUnused ) ;
222 }