2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1998-2003 Apple Computer, Inc. All rights reserved.
29 #include <IOKit/IOTypes.h>
30 #include <IOKit/IOLib.h>
31 #include <IOKit/pwr_mgt/RootDomain.h>
33 #include <IOKit/platform/AppleNMI.h>
36 #include <pexpert/pexpert.h>
39 bool RootRegistered( OSObject
* us
, void *, IOService
* yourDevice
);
41 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 #define super IOService
45 OSDefineMetaClassAndStructors(AppleNMI
, IOService
);
46 OSMetaClassDefineReservedUnused(AppleNMI
, 0);
47 OSMetaClassDefineReservedUnused(AppleNMI
, 1);
48 OSMetaClassDefineReservedUnused(AppleNMI
, 2);
49 OSMetaClassDefineReservedUnused(AppleNMI
, 3);
51 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
53 bool AppleNMI::start(IOService
*provider
)
55 if (!super::start(provider
)) return false;
57 enable_debugger
= FALSE
;
60 if (provider
->getProperty("enable_debugger"))
61 enable_debugger
= TRUE
; // Flag to automatically jump to debugger at NMI press
63 if (provider
->getProperty("mask_NMI"))
64 mask_NMI
= TRUE
; // Flag to mask/unmask NMI @ sleep/wake
66 // Get notified when Root Domain registers
67 addNotification( gIOPublishNotification
, serviceMatching("IOPMrootDomain"), (IOServiceNotificationHandler
)RootRegistered
, this, 0 );
69 // Register the interrupt.
70 IOInterruptAction handler
= OSMemberFunctionCast(IOInterruptAction
,
71 this, &AppleNMI::handleInterrupt
);
72 provider
->registerInterrupt(0, this, handler
, 0);
73 provider
->enableInterrupt(0);
78 // **********************************************************************************
79 // The Root Power Domain has registered, so now we register as an interested driver
80 // so we know when the system is going to sleep or wake
81 // **********************************************************************************
82 bool RootRegistered( OSObject
* us
, void *, IOService
* yourDevice
)
84 if ( yourDevice
!= NULL
) {
85 ((AppleNMI
*)us
)->rootDomain
= yourDevice
;
86 ((IOPMrootDomain
*)yourDevice
)->registerInterestedDriver((IOService
*) us
);
92 IOReturn
AppleNMI::initNMI(IOInterruptController
*parentController
, OSData
*parentSource
)
94 return kIOReturnSuccess
;
97 IOReturn
AppleNMI::handleInterrupt(void * /*refCon*/, IOService
* /*nub*/, int /*source*/)
99 if(enable_debugger
== TRUE
)
100 Debugger("NMI"); // This is a direct call to the Debugger
102 PE_enter_debugger("NMI"); // This is a indirect call the Debugger that is dependent on the debug flag
104 return kIOReturnSuccess
;
107 //*********************************************************************************
108 // powerStateWillChangeTo
110 // We are notified here of power changes in the root domain. The root domain
111 // cannot actually turn itself on and off, but it notifies us anyway.
112 //*********************************************************************************
113 IOReturn
AppleNMI::powerStateWillChangeTo ( IOPMPowerFlags theFlags
, unsigned long, IOService
*)
115 volatile unsigned long *nmiIntSourceAddr
;
116 unsigned long nmiIntSource
;
118 if (mask_NMI
== TRUE
)
120 if ( ! (theFlags
& IOPMPowerOn
) )
122 // Mask NMI and change from edge to level whilst sleeping (copied directly from OS9 code)
123 nmiIntSourceAddr
= (volatile unsigned long *)kExtInt9_NMIIntSource
;
124 nmiIntSource
= ml_phys_read((vm_address_t
)nmiIntSourceAddr
);
125 nmiIntSource
|= kNMIIntLevelMask
;
126 ml_phys_write((vm_address_t
)nmiIntSourceAddr
, nmiIntSource
);
128 nmiIntSource
|= kNMIIntMask
;
129 ml_phys_write((vm_address_t
)nmiIntSourceAddr
, nmiIntSource
);
134 // Unmask NMI and change back to edge (copied directly from OS9 code)
135 nmiIntSourceAddr
= (volatile unsigned long *)kExtInt9_NMIIntSource
;
136 nmiIntSource
= ml_phys_read((vm_address_t
)nmiIntSourceAddr
);
137 nmiIntSource
&= ~kNMIIntLevelMask
;
138 ml_phys_write((vm_address_t
)nmiIntSourceAddr
, nmiIntSource
);
140 nmiIntSource
&= ~kNMIIntMask
;
141 ml_phys_write((vm_address_t
)nmiIntSourceAddr
, nmiIntSource
);
146 return IOPMAckImplied
;