]> git.saurik.com Git - apple/xnu.git/blame - iokit/Families/IOSystemManagement/IOWatchDogTimer.cpp
xnu-344.21.73.tar.gz
[apple/xnu.git] / iokit / Families / IOSystemManagement / IOWatchDogTimer.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
d7e50217
A
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d7e50217
A
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.
22 *
1c79356b
A
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26#include <IOKit/IOUserClient.h>
27#include <IOKit/IOMessage.h>
28#include <IOKit/system_management/IOWatchDogTimer.h>
29#include <IOKit/pwr_mgt/RootDomain.h>
30
31
32static IOReturn IOWatchDogTimerSleepHandler(void *target, void *refCon,
33 UInt32 messageType,
34 IOService *provider,
35 void *messageArgument,
36 vm_size_t argSize);
37
38
39#define kWatchDogEnabledProperty "IOWatchDogEnabled"
40
41
42#define super IOService
43
44OSDefineMetaClassAndAbstractStructors(IOWatchDogTimer, IOService);
45
46OSMetaClassDefineReservedUnused(IOWatchDogTimer, 0);
47OSMetaClassDefineReservedUnused(IOWatchDogTimer, 1);
48OSMetaClassDefineReservedUnused(IOWatchDogTimer, 2);
49OSMetaClassDefineReservedUnused(IOWatchDogTimer, 3);
50
51bool IOWatchDogTimer::start(IOService *provider)
52{
53 if (!super::start(provider)) return false;
54
55 notifier = registerSleepWakeInterest(IOWatchDogTimerSleepHandler, this);
56 if (notifier == 0) return false;
57
58 setProperty(kWatchDogEnabledProperty, kOSBooleanFalse);
59 setWatchDogTimer(0);
60
61 registerService();
62
63 return true;
64}
65
66void IOWatchDogTimer::stop(IOService *provider)
67{
68 setWatchDogTimer(0);
69 notifier->remove();
70}
71
72IOReturn IOWatchDogTimer::setProperties(OSObject *properties)
73{
74 OSNumber *theNumber;
75 UInt32 theValue;
76 IOReturn result;
77
78 result = IOUserClient::clientHasPrivilege(current_task(),
79 kIOClientPrivilegeAdministrator);
80 if (result != kIOReturnSuccess) return kIOReturnNotPrivileged;
81
82 theNumber = OSDynamicCast(OSNumber, properties);
83 if (theNumber == 0) return kIOReturnBadArgument;
84
85 theValue = theNumber->unsigned32BitValue();
86 if (theValue == 0) {
87 setProperty(kWatchDogEnabledProperty, kOSBooleanFalse);
88 } else {
89 setProperty(kWatchDogEnabledProperty, kOSBooleanTrue);
90 }
91
92 setWatchDogTimer(theValue);
93
94 return kIOReturnSuccess;
95}
96
97static IOReturn IOWatchDogTimerSleepHandler(void *target, void */*refCon*/,
98 UInt32 messageType,
99 IOService */*provider*/,
100 void *messageArgument,
101 vm_size_t /*argSize*/)
102{
103 IOWatchDogTimer *watchDogTimer = (IOWatchDogTimer *)target;
104 sleepWakeNote *swNote = (sleepWakeNote *)messageArgument;
105
106 if (messageType != kIOMessageSystemWillSleep) return kIOReturnUnsupported;
107
108 watchDogTimer->setProperty(kWatchDogEnabledProperty, kOSBooleanFalse);
109 watchDogTimer->setWatchDogTimer(0);
110
111 swNote->returnValue = 0;
112 acknowledgeSleepWakeNotification(swNote->powerRef);
113
114 return kIOReturnSuccess;
115}