]> git.saurik.com Git - apple/xnu.git/blame - iokit/Drivers/platform/drvAppleNMI/AppleNMI.cpp
xnu-344.34.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 *
de355530
A
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.
1c79356b 11 *
de355530
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
de355530
A
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.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (c) 1998-9 Apple Computer, Inc. All rights reserved.
24 *
25 * DRI: Josh de Cesare
26 *
27 */
28
29#include <IOKit/IOTypes.h>
30#include <IOKit/IOLib.h>
31#include <IOKit/pwr_mgt/RootDomain.h>
32
33#include <IOKit/platform/AppleNMI.h>
34
35extern "C" {
36#include <pexpert/pexpert.h>
37}
38
39bool RootRegistered( OSObject * us, void *, IOService * yourDevice );
40
41/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
42
43#define super IOService
44
45OSDefineMetaClassAndStructors(AppleNMI, IOService);
46OSMetaClassDefineReservedUnused(AppleNMI, 0);
47OSMetaClassDefineReservedUnused(AppleNMI, 1);
48OSMetaClassDefineReservedUnused(AppleNMI, 2);
49OSMetaClassDefineReservedUnused(AppleNMI, 3);
50
51/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
52
53bool AppleNMI::start(IOService *provider)
54{
55 if (!super::init()) return false;
56
57 enable_debugger = FALSE;
58 mask_NMI = FALSE;
59
60 if (provider->getProperty("enable_debugger"))
61 enable_debugger = TRUE; // Flag to automatically jump to debugger at NMI press
62
63 if (provider->getProperty("mask_NMI"))
64 mask_NMI = TRUE; // Flag to mask/unmask NMI @ sleep/wake
65
66 // Get notified when Root Domain registers
67 addNotification( gIOPublishNotification, serviceMatching("IOPMrootDomain"), (IOServiceNotificationHandler)RootRegistered, this, 0 );
68
69 // Register the interrupt.
70 provider->registerInterrupt(0, this, (IOInterruptAction) &AppleNMI::handleInterrupt, 0);
71 provider->enableInterrupt(0);
72
73 return true;
74}
75
76// **********************************************************************************
77// The Root Power Domain has registered, so now we register as an interested driver
78// so we know when the system is going to sleep or wake
79// **********************************************************************************
80bool RootRegistered( OSObject * us, void *, IOService * yourDevice )
81{
82 if ( yourDevice != NULL ) {
83 ((AppleNMI *)us)->rootDomain = yourDevice;
84 ((IOPMrootDomain *)yourDevice)->registerInterestedDriver((IOService *) us);
85 }
86
87 return true;
88}
89
90IOReturn AppleNMI::initNMI(IOInterruptController *parentController, OSData *parentSource)
91{
92 // Allocate the IOInterruptSource so this can act like a nub.
93 _interruptSources = (IOInterruptSource *)IOMalloc(sizeof(IOInterruptSource));
94 if (_interruptSources == 0) return kIOReturnNoMemory;
95 _numInterruptSources = 1;
96
97 // Set up the IOInterruptSource to point at this.
98 _interruptSources[0].interruptController = parentController;
99 _interruptSources[0].vectorData = parentSource;
100
101 // call start using itself as its provider.
102 if (!start(this)) return kIOReturnError;
103
104 return kIOReturnSuccess;
105}
106
107IOReturn AppleNMI::handleInterrupt(void * /*refCon*/, IOService * /*nub*/, int /*source*/)
108{
109 if(enable_debugger == TRUE)
110 Debugger("NMI"); // This is a direct call to the Debugger
111 else
112 PE_enter_debugger("NMI"); // This is a indirect call the Debugger that is dependent on the debug flag
113
114 return kIOReturnSuccess;
115}
116
117//*********************************************************************************
118// powerStateWillChangeTo
119//
120// We are notified here of power changes in the root domain. The root domain
121// cannot actually turn itself on and off, but it notifies us anyway.
122//*********************************************************************************
123IOReturn AppleNMI::powerStateWillChangeTo ( IOPMPowerFlags theFlags, unsigned long, IOService*)
124{
125 volatile unsigned long *nmiIntSourceAddr;
126 unsigned long nmiIntSource;
127
128 if (mask_NMI == TRUE)
129 {
130 if ( ! (theFlags & IOPMPowerOn) )
131 {
132 IOLog("AppleNMI mask NMI\n");
133
134 // Mask NMI and change from edge to level whilst sleeping (copied directly from OS9 code)
135 nmiIntSourceAddr = (volatile unsigned long *)kExtInt9_NMIIntSource;
de355530 136 nmiIntSource = *nmiIntSourceAddr;
1c79356b 137 nmiIntSource |= kNMIIntLevelMask;
de355530 138 *nmiIntSourceAddr = nmiIntSource;
1c79356b
A
139 eieio();
140 nmiIntSource |= kNMIIntMask;
de355530 141 *nmiIntSourceAddr = nmiIntSource;
1c79356b
A
142 eieio();
143 }
144 else
145 {
146 IOLog("AppleNMI unmask NMI\n");
147
148 // Unmask NMI and change back to edge (copied directly from OS9 code)
149 nmiIntSourceAddr = (volatile unsigned long *)kExtInt9_NMIIntSource;
de355530 150 nmiIntSource = *nmiIntSourceAddr;
1c79356b 151 nmiIntSource &= ~kNMIIntLevelMask;
de355530 152 *nmiIntSourceAddr = nmiIntSource;
1c79356b
A
153 eieio();
154 nmiIntSource &= ~kNMIIntMask;
de355530 155 *nmiIntSourceAddr = nmiIntSource;
1c79356b
A
156 eieio();
157 }
158 }
159
160 return IOPMAckImplied;
161}