1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * Copyright (c) 1998-2003 Apple Computer, Inc.  All rights reserved.
30 *
31 *  DRI: Josh de Cesare
32 *
33 */
34
35#include <IOKit/IOTypes.h>
36#include <IOKit/IOLib.h>
37#include <IOKit/pwr_mgt/RootDomain.h>
38
39#include "AppleARMNMI.h"
40
41extern "C" {
42#include <pexpert/pexpert.h>
43} bool RootRegistered(OSObject * us, void *, IOService * yourDevice);
44
45/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
46
47#define super IOService
48
49OSDefineMetaClassAndStructors(AppleARMNMI, IOService);
50OSMetaClassDefineReservedUnused(AppleARMNMI, 0);
51OSMetaClassDefineReservedUnused(AppleARMNMI, 1);
52OSMetaClassDefineReservedUnused(AppleARMNMI, 2);
53OSMetaClassDefineReservedUnused(AppleARMNMI, 3);
54
55/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
56
57bool AppleARMNMI::start(IOService * provider)
58{
59    if (!super::start(provider))
60        return false;
61
62    enable_debugger = FALSE;
63    mask_NMI = FALSE;
64
65    if (provider->getProperty("enable_debugger"))
66        enable_debugger = TRUE; // Flag to automatically jump to debugger at NMI press
67
68    if (provider->getProperty("mask_NMI"))
69        mask_NMI = TRUE;        // Flag to mask/unmask NMI @ sleep/wake
70
71    // Register the interrupt.
72    IOInterruptAction handler = OSMemberFunctionCast(IOInterruptAction,
73                                                     this, &AppleARMNMI::handleInterrupt);
74    provider->registerInterrupt(0, this, handler, 0);
75    provider->enableInterrupt(0);
76
77    return true;
78}
79
80IOReturn AppleARMNMI::initNMI(IOInterruptController * parentController, OSData * parentSource)
81{
82    return kIOReturnSuccess;
83}
84
85IOReturn AppleARMNMI::handleInterrupt(void * /*refCon */ , IOService * /*nub */ , int /*source */ )
86{
87    if (enable_debugger == TRUE)
88        Debugger("NMI");        // This is a direct call to the Debugger
89    else
90        PE_enter_debugger("NMI");   // This is a indirect call the Debugger that is dependent on the debug flag
91
92    return kIOReturnSuccess;
93}
94