2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
26 #include <IOKit/IOUserClient.h>
27 #include <IOKit/IOMessage.h>
28 #include <IOKit/system_management/IOWatchDogTimer.h>
29 #include <IOKit/pwr_mgt/RootDomain.h>
32 static IOReturn
IOWatchDogTimerSleepHandler(void *target
, void *refCon
,
35 void *messageArgument
,
39 #define kWatchDogEnabledProperty "IOWatchDogEnabled"
42 #define super IOService
44 OSDefineMetaClassAndAbstractStructors(IOWatchDogTimer
, IOService
);
46 OSMetaClassDefineReservedUnused(IOWatchDogTimer
, 0);
47 OSMetaClassDefineReservedUnused(IOWatchDogTimer
, 1);
48 OSMetaClassDefineReservedUnused(IOWatchDogTimer
, 2);
49 OSMetaClassDefineReservedUnused(IOWatchDogTimer
, 3);
51 bool IOWatchDogTimer::start(IOService
*provider
)
53 if (!super::start(provider
)) return false;
55 notifier
= registerSleepWakeInterest(IOWatchDogTimerSleepHandler
, this);
56 if (notifier
== 0) return false;
58 setProperty(kWatchDogEnabledProperty
, kOSBooleanFalse
);
66 void IOWatchDogTimer::stop(IOService
*provider
)
72 IOReturn
IOWatchDogTimer::setProperties(OSObject
*properties
)
78 result
= IOUserClient::clientHasPrivilege(current_task(),
79 kIOClientPrivilegeAdministrator
);
80 if (result
!= kIOReturnSuccess
) return kIOReturnNotPrivileged
;
82 theNumber
= OSDynamicCast(OSNumber
, properties
);
83 if (theNumber
== 0) return kIOReturnBadArgument
;
85 theValue
= theNumber
->unsigned32BitValue();
87 setProperty(kWatchDogEnabledProperty
, kOSBooleanFalse
);
89 setProperty(kWatchDogEnabledProperty
, kOSBooleanTrue
);
92 setWatchDogTimer(theValue
);
94 return kIOReturnSuccess
;
97 static IOReturn
IOWatchDogTimerSleepHandler(void *target
, void */
*refCon*/
,
99 IOService */
*provider*/
,
100 void *messageArgument
,
101 vm_size_t
/*argSize*/)
103 IOWatchDogTimer
*watchDogTimer
= (IOWatchDogTimer
*)target
;
104 sleepWakeNote
*swNote
= (sleepWakeNote
*)messageArgument
;
106 if (messageType
!= kIOMessageSystemWillSleep
) return kIOReturnUnsupported
;
108 watchDogTimer
->setProperty(kWatchDogEnabledProperty
, kOSBooleanFalse
);
109 watchDogTimer
->setWatchDogTimer(0);
111 swNote
->returnValue
= 0;
112 acknowledgeSleepWakeNotification(swNote
->powerRef
);
114 return kIOReturnSuccess
;