2 * Copyright (c) 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@
23 #include <IOKit/IOUserClient.h>
24 #include <IOKit/IOMessage.h>
25 #include <IOKit/system_management/IOWatchDogTimer.h>
26 #include <IOKit/pwr_mgt/RootDomain.h>
29 static IOReturn
IOWatchDogTimerSleepHandler(void *target
, void *refCon
,
32 void *messageArgument
,
36 #define kWatchDogEnabledProperty "IOWatchDogEnabled"
39 #define super IOService
41 OSDefineMetaClassAndAbstractStructors(IOWatchDogTimer
, IOService
);
43 OSMetaClassDefineReservedUnused(IOWatchDogTimer
, 0);
44 OSMetaClassDefineReservedUnused(IOWatchDogTimer
, 1);
45 OSMetaClassDefineReservedUnused(IOWatchDogTimer
, 2);
46 OSMetaClassDefineReservedUnused(IOWatchDogTimer
, 3);
48 bool IOWatchDogTimer::start(IOService
*provider
)
50 if (!super::start(provider
)) return false;
52 notifier
= registerSleepWakeInterest(IOWatchDogTimerSleepHandler
, this);
53 if (notifier
== 0) return false;
55 setProperty(kWatchDogEnabledProperty
, kOSBooleanFalse
);
63 void IOWatchDogTimer::stop(IOService
*provider
)
69 IOReturn
IOWatchDogTimer::setProperties(OSObject
*properties
)
75 result
= IOUserClient::clientHasPrivilege(current_task(),
76 kIOClientPrivilegeAdministrator
);
77 if (result
!= kIOReturnSuccess
) return kIOReturnNotPrivileged
;
79 theNumber
= OSDynamicCast(OSNumber
, properties
);
80 if (theNumber
== 0) return kIOReturnBadArgument
;
82 theValue
= theNumber
->unsigned32BitValue();
84 setProperty(kWatchDogEnabledProperty
, kOSBooleanFalse
);
86 setProperty(kWatchDogEnabledProperty
, kOSBooleanTrue
);
89 setWatchDogTimer(theValue
);
91 return kIOReturnSuccess
;
94 static IOReturn
IOWatchDogTimerSleepHandler(void *target
, void */
*refCon*/
,
96 IOService */
*provider*/
,
97 void *messageArgument
,
98 vm_size_t
/*argSize*/)
100 IOWatchDogTimer
*watchDogTimer
= (IOWatchDogTimer
*)target
;
101 sleepWakeNote
*swNote
= (sleepWakeNote
*)messageArgument
;
103 if (messageType
!= kIOMessageSystemWillSleep
) return kIOReturnUnsupported
;
105 watchDogTimer
->setProperty(kWatchDogEnabledProperty
, kOSBooleanFalse
);
106 watchDogTimer
->setWatchDogTimer(0);
108 swNote
->returnValue
= 0;
109 acknowledgeSleepWakeNotification(swNote
->powerRef
);
111 return kIOReturnSuccess
;