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