]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMchangeNoteList.cpp
faf7b06010d93d1ba795403a1bab14cf06bca56d
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #include <IOKit/pwr_mgt/IOPM.h>
31 #include <IOKit/pwr_mgt/IOPMchangeNoteList.h>
32 #include <IOKit/pwr_mgt/IOPowerConnection.h>
34 #define super OSObject
35 OSDefineMetaClassAndStructors(IOPMchangeNoteList
,OSObject
)
37 //*********************************************************************************
40 //*********************************************************************************
41 void IOPMchangeNoteList::initialize ( void )
47 for ( i
= 0; i
< IOPMMaxChangeNotes
; i
++ ) {
48 changeNote
[i
].flags
= IOPMNotInUse
;
52 //*********************************************************************************
55 //*********************************************************************************
57 long IOPMchangeNoteList::createChangeNote ( void )
61 i
= increment(firstUnused
);
62 if ( firstInList
== i
) {
71 //*********************************************************************************
74 // Return the ordinal of the first change note in the list.
75 // If the list is empty, return -1.
76 //*********************************************************************************
78 long IOPMchangeNoteList::currentChange ( void )
80 if ( firstUnused
== firstInList
) {
88 //*********************************************************************************
91 // Return the ordinal of the last change note in the list.
92 // If the list is empty, return -1.
93 //*********************************************************************************
95 long IOPMchangeNoteList::latestChange ( void )
97 if ( firstUnused
== firstInList
) {
101 return decrement(firstUnused
);
105 //*********************************************************************************
106 // releaseHeadChangeNote
108 // Mark the head node unused.
109 // This happens when the first change in the list is completely processed.
110 // That is, all interested parties have acknowledged it, and power is settled
112 //*********************************************************************************
114 IOReturn
IOPMchangeNoteList::releaseHeadChangeNote ( void )
116 IOPowerConnection
*tmp
;
118 if((tmp
= changeNote
[firstInList
].parent
)) {
119 changeNote
[firstInList
].parent
= 0;
123 changeNote
[firstInList
].flags
= IOPMNotInUse
;
124 firstInList
= increment(firstInList
);
128 //*********************************************************************************
129 // releaseTailChangeNote
131 // Mark the tail node unused.
132 // This happens when a power change is queued up after another which has
133 // not yet been started, and the second one supercedes the first. The data in
134 // the second is copied into the first and the the second is released. This
135 // collapses the first change out of the list.
136 //*********************************************************************************
138 IOReturn
IOPMchangeNoteList::releaseTailChangeNote ( void )
140 IOPowerConnection
*tmp
;
142 if((tmp
= changeNote
[firstInList
].parent
)) {
143 changeNote
[firstInList
].parent
= 0;
147 firstUnused
= decrement(firstUnused
);
148 changeNote
[firstUnused
].flags
= IOPMNotInUse
;
152 //*********************************************************************************
155 //*********************************************************************************
157 bool IOPMchangeNoteList::changeNoteInUse ( unsigned long ordinal
)
159 if ( changeNote
[ordinal
].flags
== IOPMNotInUse
) {
167 //*********************************************************************************
170 // If the parameter corresponds to the most recent power change notification
171 // passed to drivers and children, return -1. Otherwise, return the array
172 // position of the next notification in the circular list.
173 //*********************************************************************************
175 long IOPMchangeNoteList::nextChangeNote ( unsigned long ordinal
)
179 i
= increment(ordinal
);
180 if ( i
== firstUnused
) {
186 //*********************************************************************************
189 // Increment the parameter mod the circular list size and return it.
190 //*********************************************************************************
192 unsigned long IOPMchangeNoteList::increment ( unsigned long ordinal
)
194 if ( ordinal
== (IOPMMaxChangeNotes
- 1) ) {
202 //*********************************************************************************
205 // Decrement the parameter mod the circular list size and return it.
206 //*********************************************************************************
208 unsigned long IOPMchangeNoteList::decrement ( unsigned long ordinal
)
210 if ( ordinal
== 0 ) {
211 return IOPMMaxChangeNotes
- 1;
218 //*********************************************************************************
219 // previousChangeNote
221 // If the parameter corresponds to the oldest power change notification
222 // passed to drivers and children, return -1. Otherwise, return the array
223 // position of the previous notification in the circular list.
224 //*********************************************************************************
226 long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal
)
228 if ( ordinal
== firstInList
) {
231 return decrement(ordinal
);
234 //*********************************************************************************
237 //*********************************************************************************
239 bool IOPMchangeNoteList::listEmpty ( void )
241 return ( firstInList
== firstUnused
) ;