]> git.saurik.com Git - apple/xnu.git/blame - iokit/Drivers/platform/drvAppleNMI/AppleNMI.cpp
xnu-792.6.56.tar.gz
[apple/xnu.git] / iokit / Drivers / platform / drvAppleNMI / AppleNMI.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
ff6e181a
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
1c79356b 12 *
ff6e181a
A
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
ff6e181a
A
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
1c79356b
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
91447636 24 * Copyright (c) 1998-2003 Apple Computer, Inc. All rights reserved.
1c79356b
A
25 *
26 * DRI: Josh de Cesare
27 *
28 */
29
30#include <IOKit/IOTypes.h>
31#include <IOKit/IOLib.h>
32#include <IOKit/pwr_mgt/RootDomain.h>
33
34#include <IOKit/platform/AppleNMI.h>
35
36extern "C" {
37#include <pexpert/pexpert.h>
38}
39
40bool RootRegistered( OSObject * us, void *, IOService * yourDevice );
41
42/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43
44#define super IOService
45
46OSDefineMetaClassAndStructors(AppleNMI, IOService);
47OSMetaClassDefineReservedUnused(AppleNMI, 0);
48OSMetaClassDefineReservedUnused(AppleNMI, 1);
49OSMetaClassDefineReservedUnused(AppleNMI, 2);
50OSMetaClassDefineReservedUnused(AppleNMI, 3);
51
52/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
53
54bool AppleNMI::start(IOService *provider)
55{
91447636 56 if (!super::start(provider)) return false;
1c79356b
A
57
58 enable_debugger = FALSE;
59 mask_NMI = FALSE;
60
61 if (provider->getProperty("enable_debugger"))
62 enable_debugger = TRUE; // Flag to automatically jump to debugger at NMI press
63
64 if (provider->getProperty("mask_NMI"))
65 mask_NMI = TRUE; // Flag to mask/unmask NMI @ sleep/wake
66
67 // Get notified when Root Domain registers
68 addNotification( gIOPublishNotification, serviceMatching("IOPMrootDomain"), (IOServiceNotificationHandler)RootRegistered, this, 0 );
69
70 // Register the interrupt.
71 provider->registerInterrupt(0, this, (IOInterruptAction) &AppleNMI::handleInterrupt, 0);
72 provider->enableInterrupt(0);
73
74 return true;
75}
76
77// **********************************************************************************
78// The Root Power Domain has registered, so now we register as an interested driver
79// so we know when the system is going to sleep or wake
80// **********************************************************************************
81bool RootRegistered( OSObject * us, void *, IOService * yourDevice )
82{
83 if ( yourDevice != NULL ) {
84 ((AppleNMI *)us)->rootDomain = yourDevice;
85 ((IOPMrootDomain *)yourDevice)->registerInterestedDriver((IOService *) us);
86 }
87
88 return true;
89}
90
91IOReturn AppleNMI::initNMI(IOInterruptController *parentController, OSData *parentSource)
92{
1c79356b
A
93 return kIOReturnSuccess;
94}
95
96IOReturn AppleNMI::handleInterrupt(void * /*refCon*/, IOService * /*nub*/, int /*source*/)
97{
98 if(enable_debugger == TRUE)
99 Debugger("NMI"); // This is a direct call to the Debugger
100 else
101 PE_enter_debugger("NMI"); // This is a indirect call the Debugger that is dependent on the debug flag
102
103 return kIOReturnSuccess;
104}
105
106//*********************************************************************************
107// powerStateWillChangeTo
108//
109// We are notified here of power changes in the root domain. The root domain
110// cannot actually turn itself on and off, but it notifies us anyway.
111//*********************************************************************************
112IOReturn AppleNMI::powerStateWillChangeTo ( IOPMPowerFlags theFlags, unsigned long, IOService*)
113{
114 volatile unsigned long *nmiIntSourceAddr;
115 unsigned long nmiIntSource;
116
117 if (mask_NMI == TRUE)
118 {
119 if ( ! (theFlags & IOPMPowerOn) )
120 {
1c79356b
A
121 // Mask NMI and change from edge to level whilst sleeping (copied directly from OS9 code)
122 nmiIntSourceAddr = (volatile unsigned long *)kExtInt9_NMIIntSource;
55e303ae 123 nmiIntSource = ml_phys_read(nmiIntSourceAddr);
1c79356b 124 nmiIntSource |= kNMIIntLevelMask;
55e303ae 125 ml_phys_write(nmiIntSourceAddr, nmiIntSource);
1c79356b
A
126 eieio();
127 nmiIntSource |= kNMIIntMask;
55e303ae 128 ml_phys_write(nmiIntSourceAddr, nmiIntSource);
1c79356b
A
129 eieio();
130 }
131 else
132 {
1c79356b
A
133 // Unmask NMI and change back to edge (copied directly from OS9 code)
134 nmiIntSourceAddr = (volatile unsigned long *)kExtInt9_NMIIntSource;
55e303ae 135 nmiIntSource = ml_phys_read(nmiIntSourceAddr);
1c79356b 136 nmiIntSource &= ~kNMIIntLevelMask;
55e303ae 137 ml_phys_write(nmiIntSourceAddr, nmiIntSource);
1c79356b
A
138 eieio();
139 nmiIntSource &= ~kNMIIntMask;
55e303ae 140 ml_phys_write(nmiIntSourceAddr, nmiIntSource);
1c79356b
A
141 eieio();
142 }
143 }
91447636 144
1c79356b
A
145 return IOPMAckImplied;
146}