]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-792.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / RootDomain.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 #ifndef _IOKIT_ROOTDOMAIN_H
23 #define _IOKIT_ROOTDOMAIN_H
24
25 #include <IOKit/IOService.h>
26 #include <IOKit/pwr_mgt/IOPM.h>
27
28 class IOPMPowerStateQueue;
29 class RootDomainUserClient;
30
31 #define kRootDomainSupportedFeatures "Supported Features"
32
33 enum {
34 kRootDomainSleepNotSupported = 0x00000000,
35 kRootDomainSleepSupported = 0x00000001,
36 kFrameBufferDeepSleepSupported = 0x00000002,
37 kPCICantSleep = 0x00000004
38 };
39
40 // Constants for use as arguments to the settings callback PMU/SMU defines
41 // with registerPMSettingsController
42 enum {
43 kIOPMAutoWakeSetting = 1,
44 kIOPMAutoPowerOnSetting,
45 kIOPMWakeOnRingSetting,
46 kIOPMAutoRestartOnPowerLossSetting,
47 kIOPMWakeOnLidSetting,
48 kIOPMWakeOnACChangeSetting,
49 kIOPMTimeZoneSetting
50 };
51 typedef int IOPMSystemSettingType;
52
53
54
55 typedef IOReturn (*IOPMSettingControllerCallback)(IOPMSystemSettingType arg_type, int arg_val, void *info);
56
57 extern "C"
58 {
59 IONotifier * registerSleepWakeInterest(IOServiceInterestHandler, void *, void * = 0);
60 IONotifier * registerPrioritySleepWakeInterest(IOServiceInterestHandler handler, void * self, void * ref = 0);
61 IOReturn acknowledgeSleepWakeNotification(void * );
62 IOReturn vetoSleepWakeNotification(void * PMrefcon);
63 IOReturn rootDomainRestart ( void );
64 IOReturn rootDomainShutdown ( void );
65 }
66
67 #define IOPM_ROOTDOMAIN_REV 2
68
69 class IOPMrootDomain: public IOService
70 {
71 OSDeclareDefaultStructors(IOPMrootDomain)
72
73 public:
74
75 class IOService * wrangler; // we tickle the wrangler on button presses, etc
76
77 static IOPMrootDomain * construct( void );
78 virtual bool start( IOService * provider );
79 virtual IOReturn setAggressiveness ( unsigned long, unsigned long );
80 virtual IOReturn youAreRoot ( void );
81 virtual IOReturn sleepSystem ( void );
82 virtual IOReturn setProperties ( OSObject * );
83 IOReturn shutdownSystem ( void );
84 IOReturn restartSystem ( void );
85 virtual IOReturn receivePowerNotification (UInt32 msg);
86 virtual void setSleepSupported( IOOptionBits flags );
87 virtual IOOptionBits getSleepSupported();
88 virtual IOReturn requestPowerDomainState ( IOPMPowerFlags, IOPowerConnection *, unsigned long );
89 virtual void handleSleepTimerExpiration ( void );
90 void stopIgnoringClamshellEventsDuringWakeup ( void );
91 void wakeFromDoze( void );
92 void broadcast_it (unsigned long, unsigned long );
93 void publishFeature( const char *feature );
94 void unIdleDevice( IOService *, unsigned long );
95 void announcePowerSourceChange( void );
96
97 // Override of these methods for logging purposes.
98 virtual IOReturn changePowerStateTo ( unsigned long ordinal );
99 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
100
101 IOReturn registerPMSettingController(IOPMSettingControllerCallback, void *);
102
103 private:
104
105 class IORootParent * patriarch; // points to our parent
106 long sleepSlider; // pref: idle time before idle sleep
107 long longestNonSleepSlider; // pref: longest of other idle times
108 long extraSleepDelay; // sleepSlider - longestNonSleepSlider
109 thread_call_t extraSleepTimer; // used to wait between say display idle and system idle
110 thread_call_t clamshellWakeupIgnore; // Used to ignore clamshell close events while we're waking from sleep
111
112 virtual void powerChangeDone ( unsigned long );
113 virtual void command_received ( void *, void * , void * , void *);
114 virtual bool tellChangeDown ( unsigned long stateNum);
115 virtual bool askChangeDown ( unsigned long stateNum);
116 virtual void tellChangeUp ( unsigned long );
117 virtual void tellNoChangeDown ( unsigned long );
118 void reportUserInput ( void );
119 static IOReturn sysPowerDownHandler( void * target, void * refCon,
120 UInt32 messageType, IOService * service,
121 void * messageArgument, vm_size_t argSize );
122
123 static IOReturn displayWranglerNotification( void * target, void * refCon,
124 UInt32 messageType, IOService * service,
125 void * messageArgument, vm_size_t argSize );
126
127 static bool displayWranglerPublished( void * target, void * refCon,
128 IOService * newService);
129
130 static bool batteryLocationPublished( void * target, void * refCon,
131 IOService * resourceService );
132
133 void setQuickSpinDownTimeout ( void );
134 void adjustPowerState( void );
135 void restoreUserSpinDownTimeout ( void );
136
137 IOLock *featuresDictLock; // guards supportedFeatures
138 IOPMPowerStateQueue *pmPowerStateQueue;
139 unsigned int user_spindown; // User's selected disk spindown value
140
141 unsigned int systemBooting:1;
142 unsigned int ignoringClamshell:1;
143 unsigned int allowSleep:1;
144 unsigned int sleepIsSupported:1;
145 unsigned int canSleep:1;
146 unsigned int idleSleepPending:1;
147 unsigned int sleepASAP:1;
148 unsigned int desktopMode:1;
149
150 unsigned int acAdaptorConnect:1;
151 unsigned int ignoringClamshellDuringWakeup:1;
152 unsigned int reservedA:6;
153 unsigned char reservedB[3];
154
155 struct PMSettingCtrl {
156 IOPMSettingControllerCallback func;
157 void *refcon;
158 };
159
160 // Private helper to call PM setting controller
161 IOReturn setPMSetting(int type, OSNumber *);
162
163 struct ExpansionData {
164 PMSettingCtrl *_settingController;
165 thread_call_t diskSyncCalloutEntry;
166 IONotifier *_batteryLocationNotifier;
167 IONotifier *_displayWranglerNotifier;
168 };
169 ExpansionData *_reserved;
170 IOOptionBits platformSleepSupport;
171 };
172
173 class IORootParent: public IOService
174 {
175 OSDeclareDefaultStructors(IORootParent)
176
177 private:
178 unsigned long mostRecentChange;
179
180 public:
181
182 bool start ( IOService * nub );
183 void shutDownSystem ( void );
184 void restartSystem ( void );
185 void sleepSystem ( void );
186 void dozeSystem ( void );
187 void sleepToDoze ( void );
188 void wakeSystem ( void );
189 };
190
191
192 #endif /* _IOKIT_ROOTDOMAIN_H */