2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1998-9 Apple Computer, Inc. All rights reserved.
32 #include <IOKit/IOTypes.h>
33 #include <IOKit/IOLib.h>
34 #include <IOKit/pwr_mgt/RootDomain.h>
36 #include <IOKit/platform/AppleNMI.h>
39 #include <pexpert/pexpert.h>
42 bool RootRegistered( OSObject
* us
, void *, IOService
* yourDevice
);
44 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
46 #define super IOService
48 OSDefineMetaClassAndStructors(AppleNMI
, IOService
);
49 OSMetaClassDefineReservedUnused(AppleNMI
, 0);
50 OSMetaClassDefineReservedUnused(AppleNMI
, 1);
51 OSMetaClassDefineReservedUnused(AppleNMI
, 2);
52 OSMetaClassDefineReservedUnused(AppleNMI
, 3);
54 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
56 bool AppleNMI::start(IOService
*provider
)
58 if (!super::init()) return false;
60 enable_debugger
= FALSE
;
63 if (provider
->getProperty("enable_debugger"))
64 enable_debugger
= TRUE
; // Flag to automatically jump to debugger at NMI press
66 if (provider
->getProperty("mask_NMI"))
67 mask_NMI
= TRUE
; // Flag to mask/unmask NMI @ sleep/wake
69 // Get notified when Root Domain registers
70 addNotification( gIOPublishNotification
, serviceMatching("IOPMrootDomain"), (IOServiceNotificationHandler
)RootRegistered
, this, 0 );
72 // Register the interrupt.
73 provider
->registerInterrupt(0, this, (IOInterruptAction
) &AppleNMI::handleInterrupt
, 0);
74 provider
->enableInterrupt(0);
79 // **********************************************************************************
80 // The Root Power Domain has registered, so now we register as an interested driver
81 // so we know when the system is going to sleep or wake
82 // **********************************************************************************
83 bool RootRegistered( OSObject
* us
, void *, IOService
* yourDevice
)
85 if ( yourDevice
!= NULL
) {
86 ((AppleNMI
*)us
)->rootDomain
= yourDevice
;
87 ((IOPMrootDomain
*)yourDevice
)->registerInterestedDriver((IOService
*) us
);
93 IOReturn
AppleNMI::initNMI(IOInterruptController
*parentController
, OSData
*parentSource
)
95 // Allocate the IOInterruptSource so this can act like a nub.
96 _interruptSources
= (IOInterruptSource
*)IOMalloc(sizeof(IOInterruptSource
));
97 if (_interruptSources
== 0) return kIOReturnNoMemory
;
98 _numInterruptSources
= 1;
100 // Set up the IOInterruptSource to point at this.
101 _interruptSources
[0].interruptController
= parentController
;
102 _interruptSources
[0].vectorData
= parentSource
;
104 // call start using itself as its provider.
105 if (!start(this)) return kIOReturnError
;
107 return kIOReturnSuccess
;
110 IOReturn
AppleNMI::handleInterrupt(void * /*refCon*/, IOService
* /*nub*/, int /*source*/)
112 if(enable_debugger
== TRUE
)
113 Debugger("NMI"); // This is a direct call to the Debugger
115 PE_enter_debugger("NMI"); // This is a indirect call the Debugger that is dependent on the debug flag
117 return kIOReturnSuccess
;
120 //*********************************************************************************
121 // powerStateWillChangeTo
123 // We are notified here of power changes in the root domain. The root domain
124 // cannot actually turn itself on and off, but it notifies us anyway.
125 //*********************************************************************************
126 IOReturn
AppleNMI::powerStateWillChangeTo ( IOPMPowerFlags theFlags
, unsigned long, IOService
*)
128 volatile unsigned long *nmiIntSourceAddr
;
129 unsigned long nmiIntSource
;
131 if (mask_NMI
== TRUE
)
133 if ( ! (theFlags
& IOPMPowerOn
) )
135 IOLog("AppleNMI mask NMI\n");
137 // Mask NMI and change from edge to level whilst sleeping (copied directly from OS9 code)
138 nmiIntSourceAddr
= (volatile unsigned long *)kExtInt9_NMIIntSource
;
139 nmiIntSource
= ml_phys_read(nmiIntSourceAddr
);
140 nmiIntSource
|= kNMIIntLevelMask
;
141 ml_phys_write(nmiIntSourceAddr
, nmiIntSource
);
143 nmiIntSource
|= kNMIIntMask
;
144 ml_phys_write(nmiIntSourceAddr
, nmiIntSource
);
149 IOLog("AppleNMI unmask NMI\n");
151 // Unmask NMI and change back to edge (copied directly from OS9 code)
152 nmiIntSourceAddr
= (volatile unsigned long *)kExtInt9_NMIIntSource
;
153 nmiIntSource
= ml_phys_read(nmiIntSourceAddr
);
154 nmiIntSource
&= ~kNMIIntLevelMask
;
155 ml_phys_write(nmiIntSourceAddr
, nmiIntSource
);
157 nmiIntSource
&= ~kNMIIntMask
;
158 ml_phys_write(nmiIntSourceAddr
, nmiIntSource
);
163 return IOPMAckImplied
;