2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef _IOKIT_ROOTDOMAIN_H
23 #define _IOKIT_ROOTDOMAIN_H
25 #include <IOKit/IOService.h>
26 #include <IOKit/pwr_mgt/IOPM.h>
28 class IOPMPowerStateQueue
;
29 class RootDomainUserClient
;
31 #define kRootDomainSupportedFeatures "Supported Features"
34 kRootDomainSleepNotSupported
= 0x00000000,
35 kRootDomainSleepSupported
= 0x00000001,
36 kFrameBufferDeepSleepSupported
= 0x00000002,
37 kPCICantSleep
= 0x00000004
40 // Constants for use as arguments to the settings callback PMU/SMU defines
41 // with registerPMSettingsController
43 kIOPMAutoWakeSetting
= 1,
44 kIOPMAutoPowerOnSetting
,
45 kIOPMWakeOnRingSetting
,
46 kIOPMAutoRestartOnPowerLossSetting
,
47 kIOPMWakeOnLidSetting
,
48 kIOPMWakeOnACChangeSetting
,
51 typedef int IOPMSystemSettingType
;
55 typedef IOReturn (*IOPMSettingControllerCallback
)(IOPMSystemSettingType arg_type
, int arg_val
, void *info
);
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 );
67 #define IOPM_ROOTDOMAIN_REV 2
69 class IOPMrootDomain
: public IOService
71 OSDeclareDefaultStructors(IOPMrootDomain
)
75 class IOService
* wrangler
; // we tickle the wrangler on button presses, etc
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 );
97 // Override of these methods for logging purposes.
98 virtual IOReturn
changePowerStateTo ( unsigned long ordinal
);
99 virtual IOReturn
changePowerStateToPriv ( unsigned long ordinal
);
101 IOReturn
registerPMSettingController(IOPMSettingControllerCallback
, void *);
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
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
);
123 static IOReturn
displayWranglerNotification( void * target
, void * refCon
,
124 UInt32 messageType
, IOService
* service
,
125 void * messageArgument
, vm_size_t argSize
);
127 static bool displayWranglerPublished( void * target
, void * refCon
,
128 IOService
* newService
);
130 static bool batteryLocationPublished( void * target
, void * refCon
,
131 IOService
* resourceService
);
133 void setQuickSpinDownTimeout ( void );
134 void adjustPowerState( void );
135 void restoreUserSpinDownTimeout ( void );
137 IOLock
*featuresDictLock
; // guards supportedFeatures
138 IOPMPowerStateQueue
*pmPowerStateQueue
;
139 unsigned int user_spindown
; // User's selected disk spindown value
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;
150 unsigned int acAdaptorConnect
:1;
151 unsigned int ignoringClamshellDuringWakeup
:1;
152 unsigned int reservedA
:6;
153 unsigned char reservedB
[3];
155 struct PMSettingCtrl
{
156 IOPMSettingControllerCallback func
;
160 // Private helper to call PM setting controller
161 IOReturn
setPMSetting(int type
, OSNumber
*);
163 struct ExpansionData
{
164 PMSettingCtrl
*_settingController
;
165 thread_call_t diskSyncCalloutEntry
;
166 IONotifier
*_batteryLocationNotifier
;
167 IONotifier
*_displayWranglerNotifier
;
169 ExpansionData
*_reserved
;
170 IOOptionBits platformSleepSupport
;
173 class IORootParent
: public IOService
175 OSDeclareDefaultStructors(IORootParent
)
178 unsigned long mostRecentChange
;
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 );
192 #endif /* _IOKIT_ROOTDOMAIN_H */