]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMchangeNoteList.cpp
5305dbc8eb06cad830257e6aff1a93767bc610b5
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 <IOKit/pwr_mgt/IOPM.h>
24 #include <IOKit/pwr_mgt/IOPMchangeNoteList.h>
25 #include <IOKit/pwr_mgt/IOPowerConnection.h>
27 #define super OSObject
28 OSDefineMetaClassAndStructors(IOPMchangeNoteList
,OSObject
)
30 //*********************************************************************************
33 //*********************************************************************************
34 void IOPMchangeNoteList::initialize ( void )
40 for ( i
= 0; i
< IOPMMaxChangeNotes
; i
++ ) {
41 changeNote
[i
].flags
= IOPMNotInUse
;
45 //*********************************************************************************
48 //*********************************************************************************
50 long IOPMchangeNoteList::createChangeNote ( void )
54 i
= increment(firstUnused
);
55 if ( firstInList
== i
) {
64 //*********************************************************************************
67 // Return the ordinal of the first change note in the list.
68 // If the list is empty, return -1.
69 //*********************************************************************************
71 long IOPMchangeNoteList::currentChange ( void )
73 if ( firstUnused
== firstInList
) {
81 //*********************************************************************************
84 // Return the ordinal of the last change note in the list.
85 // If the list is empty, return -1.
86 //*********************************************************************************
88 long IOPMchangeNoteList::latestChange ( void )
90 if ( firstUnused
== firstInList
) {
94 return decrement(firstUnused
);
98 //*********************************************************************************
99 // releaseHeadChangeNote
101 // Mark the head node unused.
102 // This happens when the first change in the list is completely processed.
103 // That is, all interested parties have acknowledged it, and power is settled
105 //*********************************************************************************
107 IOReturn
IOPMchangeNoteList::releaseHeadChangeNote ( void )
109 IOPowerConnection
*tmp
;
111 if((tmp
= changeNote
[firstInList
].parent
)) {
112 changeNote
[firstInList
].parent
= 0;
116 changeNote
[firstInList
].flags
= IOPMNotInUse
;
117 firstInList
= increment(firstInList
);
121 //*********************************************************************************
122 // releaseTailChangeNote
124 // Mark the tail node unused.
125 // This happens when a power change is queued up after another which has
126 // not yet been started, and the second one supercedes the first. The data in
127 // the second is copied into the first and the the second is released. This
128 // collapses the first change out of the list.
129 //*********************************************************************************
131 IOReturn
IOPMchangeNoteList::releaseTailChangeNote ( void )
133 IOPowerConnection
*tmp
;
135 if((tmp
= changeNote
[firstInList
].parent
)) {
136 changeNote
[firstInList
].parent
= 0;
140 firstUnused
= decrement(firstUnused
);
141 changeNote
[firstUnused
].flags
= IOPMNotInUse
;
145 //*********************************************************************************
148 //*********************************************************************************
150 bool IOPMchangeNoteList::changeNoteInUse ( unsigned long ordinal
)
152 if ( changeNote
[ordinal
].flags
== IOPMNotInUse
) {
160 //*********************************************************************************
163 // If the parameter corresponds to the most recent power change notification
164 // passed to drivers and children, return -1. Otherwise, return the array
165 // position of the next notification in the circular list.
166 //*********************************************************************************
168 long IOPMchangeNoteList::nextChangeNote ( unsigned long ordinal
)
172 i
= increment(ordinal
);
173 if ( i
== firstUnused
) {
179 //*********************************************************************************
182 // Increment the parameter mod the circular list size and return it.
183 //*********************************************************************************
185 unsigned long IOPMchangeNoteList::increment ( unsigned long ordinal
)
187 if ( ordinal
== (IOPMMaxChangeNotes
- 1) ) {
195 //*********************************************************************************
198 // Decrement the parameter mod the circular list size and return it.
199 //*********************************************************************************
201 unsigned long IOPMchangeNoteList::decrement ( unsigned long ordinal
)
203 if ( ordinal
== 0 ) {
204 return IOPMMaxChangeNotes
- 1;
211 //*********************************************************************************
212 // previousChangeNote
214 // If the parameter corresponds to the oldest power change notification
215 // passed to drivers and children, return -1. Otherwise, return the array
216 // position of the previous notification in the circular list.
217 //*********************************************************************************
219 long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal
)
221 if ( ordinal
== firstInList
) {
224 return decrement(ordinal
);
227 //*********************************************************************************
230 //*********************************************************************************
232 bool IOPMchangeNoteList::listEmpty ( void )
234 return ( firstInList
== firstUnused
) ;