2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1998-2003 Apple Computer, Inc. All rights reserved.
30 #include <IOKit/IOTypes.h>
31 #include <IOKit/IOLib.h>
32 #include <IOKit/pwr_mgt/RootDomain.h>
34 #include <IOKit/platform/AppleNMI.h>
37 #include <pexpert/pexpert.h>
40 bool RootRegistered( OSObject
* us
, void *, IOService
* yourDevice
);
42 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
44 #define super IOService
46 OSDefineMetaClassAndStructors(AppleNMI
, IOService
);
47 OSMetaClassDefineReservedUnused(AppleNMI
, 0);
48 OSMetaClassDefineReservedUnused(AppleNMI
, 1);
49 OSMetaClassDefineReservedUnused(AppleNMI
, 2);
50 OSMetaClassDefineReservedUnused(AppleNMI
, 3);
52 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
54 bool AppleNMI::start(IOService
*provider
)
56 if (!super::start(provider
)) return false;
58 enable_debugger
= FALSE
;
61 if (provider
->getProperty("enable_debugger"))
62 enable_debugger
= TRUE
; // Flag to automatically jump to debugger at NMI press
64 if (provider
->getProperty("mask_NMI"))
65 mask_NMI
= TRUE
; // Flag to mask/unmask NMI @ sleep/wake
67 // Get notified when Root Domain registers
68 addNotification( gIOPublishNotification
, serviceMatching("IOPMrootDomain"), (IOServiceNotificationHandler
)RootRegistered
, this, 0 );
70 // Register the interrupt.
71 provider
->registerInterrupt(0, this, (IOInterruptAction
) &AppleNMI::handleInterrupt
, 0);
72 provider
->enableInterrupt(0);
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 // **********************************************************************************
81 bool RootRegistered( OSObject
* us
, void *, IOService
* yourDevice
)
83 if ( yourDevice
!= NULL
) {
84 ((AppleNMI
*)us
)->rootDomain
= yourDevice
;
85 ((IOPMrootDomain
*)yourDevice
)->registerInterestedDriver((IOService
*) us
);
91 IOReturn
AppleNMI::initNMI(IOInterruptController
*parentController
, OSData
*parentSource
)
93 return kIOReturnSuccess
;
96 IOReturn
AppleNMI::handleInterrupt(void * /*refCon*/, IOService
* /*nub*/, int /*source*/)
98 if(enable_debugger
== TRUE
)
99 Debugger("NMI"); // This is a direct call to the Debugger
101 PE_enter_debugger("NMI"); // This is a indirect call the Debugger that is dependent on the debug flag
103 return kIOReturnSuccess
;
106 //*********************************************************************************
107 // powerStateWillChangeTo
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 //*********************************************************************************
112 IOReturn
AppleNMI::powerStateWillChangeTo ( IOPMPowerFlags theFlags
, unsigned long, IOService
*)
114 volatile unsigned long *nmiIntSourceAddr
;
115 unsigned long nmiIntSource
;
117 if (mask_NMI
== TRUE
)
119 if ( ! (theFlags
& IOPMPowerOn
) )
121 // Mask NMI and change from edge to level whilst sleeping (copied directly from OS9 code)
122 nmiIntSourceAddr
= (volatile unsigned long *)kExtInt9_NMIIntSource
;
123 nmiIntSource
= ml_phys_read(nmiIntSourceAddr
);
124 nmiIntSource
|= kNMIIntLevelMask
;
125 ml_phys_write(nmiIntSourceAddr
, nmiIntSource
);
127 nmiIntSource
|= kNMIIntMask
;
128 ml_phys_write(nmiIntSourceAddr
, nmiIntSource
);
133 // Unmask NMI and change back to edge (copied directly from OS9 code)
134 nmiIntSourceAddr
= (volatile unsigned long *)kExtInt9_NMIIntSource
;
135 nmiIntSource
= ml_phys_read(nmiIntSourceAddr
);
136 nmiIntSource
&= ~kNMIIntLevelMask
;
137 ml_phys_write(nmiIntSourceAddr
, nmiIntSource
);
139 nmiIntSource
&= ~kNMIIntMask
;
140 ml_phys_write(nmiIntSourceAddr
, nmiIntSource
);
145 return IOPMAckImplied
;