]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/interrupt.c
xnu-1228.12.14.tar.gz
[apple/xnu.git] / osfmk / ppc / interrupt.c
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31/*
32 * @APPLE_FREE_COPYRIGHT@
33 */
2d21ac55 34
1c79356b
A
35#include <kern/misc_protos.h>
36#include <kern/assert.h>
37#include <kern/thread.h>
38#include <kern/counters.h>
0c530ab8
A
39#include <kern/etimer.h>
40#include <kern/pms.h>
1c79356b 41#include <ppc/misc_protos.h>
55e303ae 42#include <ppc/trap.h>
1c79356b
A
43#include <ppc/proc_reg.h>
44#include <ppc/exception.h>
45#include <ppc/savearea.h>
2d21ac55
A
46#include <ppc/vmachmon.h>
47#include <ppc/machine_cpu.h>
1c79356b 48#include <pexpert/pexpert.h>
1c79356b
A
49#include <sys/kdebug.h>
50
2d21ac55
A
51perfCallback perfIntHook; /* Pointer to CHUD trap hook routine */
52
53#if CONFIG_DTRACE
54#if (DEVELOPMENT || DEBUG )
55#include <mach/sdt.h>
56#endif
57
58extern vm_offset_t dtrace_get_cpu_int_stack_top(void);
59
60vm_offset_t dtrace_get_cpu_int_stack_top(void)
61{
62 return getPerProc()->intstack_top_ss;
63}
64
65/* See <rdar://problem/4613924> */
66perfCallback tempDTraceIntHook; /* Pointer to DTrace fbt int handler */
67#endif
91447636
A
68
69void unresolved_kernel_trap(int trapno,
70 struct savearea *ssp,
71 unsigned int dsisr,
72 addr64_t dar,
73 const char *message);
55e303ae 74
2d21ac55
A
75unsigned int isync_mfdec(void);
76
9bccf70c 77struct savearea * interrupt(
1c79356b 78 int type,
9bccf70c 79 struct savearea *ssp,
1c79356b
A
80 unsigned int dsisr,
81 unsigned int dar)
82{
483a1d10 83 int current_cpu;
91447636 84 struct per_proc_info *proc_info;
0b4e3aa0 85 uint64_t now;
91447636 86 thread_t thread;
1c79356b
A
87
88 disable_preemption();
55e303ae
A
89
90 if(perfIntHook) { /* Is there a hook? */
91 if(perfIntHook(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp; /* If it succeeds, we are done... */
92 }
1c79356b 93
2d21ac55
A
94#if CONFIG_DTRACE
95 if(tempDTraceIntHook) { /* Is there a hook? */
96 if(tempDTraceIntHook(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp; /* If it succeeds, we are done... */
97 }
98#endif
99
9bccf70c
A
100#if 0
101 {
102 extern void fctx_text(void);
103 fctx_test();
104 }
105#endif
91447636
A
106
107
1c79356b 108 current_cpu = cpu_number();
91447636 109 proc_info = getPerProc();
1c79356b
A
110
111 switch (type) {
112
1c79356b
A
113 case T_DECREMENTER:
114 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI, 0) | DBG_FUNC_NONE,
55e303ae 115 isync_mfdec(), (unsigned int)ssp->save_srr0, 0, 0, 0);
1c79356b 116
3a60a9f5
A
117 now = mach_absolute_time(); /* Find out what time it is */
118
119 if(now >= proc_info->pms.pmsPop) { /* Is it time for power management state change? */
120 pmsStep(1); /* Yes, advance step */
121 now = mach_absolute_time(); /* Get the time again since we ran a bit */
122 }
123
91447636
A
124 thread = current_thread(); /* Find ourselves */
125 if(thread->machine.qactTimer != 0) { /* Is the timer set? */
91447636
A
126 if (thread->machine.qactTimer <= now) { /* It is set, has it popped? */
127 thread->machine.qactTimer = 0; /* Clear single shot timer */
128 if((unsigned int)thread->machine.vmmControl & 0xFFFFFFFE) { /* Are there any virtual machines? */
129 vmm_timer_pop(thread); /* Yes, check out them out... */
1c79356b
A
130 }
131 }
132 }
133
0c530ab8 134 etimer_intr(USER_MODE(ssp->save_srr1), ssp->save_srr0); /* Handle event timer */
1c79356b
A
135 break;
136
137 case T_INTERRUPT:
138 /* Call the platform interrupt routine */
2d21ac55 139 counter(c_incoming_interrupts++);
1c79356b
A
140
141 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_START,
55e303ae 142 current_cpu, (unsigned int)ssp->save_srr0, 0, 0, 0);
1c79356b 143
2d21ac55
A
144#if CONFIG_DTRACE && (DEVELOPMENT || DEBUG )
145 DTRACE_INT5(interrupt__start, void *, proc_info->interrupt_nub, int, proc_info->interrupt_source,
146 void *, proc_info->interrupt_target, IOInterruptHandler, proc_info->interrupt_handler,
147 void *, proc_info->interrupt_refCon);
148#endif
149
91447636
A
150 proc_info->interrupt_handler(
151 proc_info->interrupt_target,
152 proc_info->interrupt_refCon,
153 proc_info->interrupt_nub,
154 proc_info->interrupt_source);
1c79356b 155
2d21ac55
A
156#if CONFIG_DTRACE && (DEVELOPMENT || DEBUG )
157 DTRACE_INT5(interrupt__complete, void *, proc_info->interrupt_nub, int, proc_info->interrupt_source,
158 void *, proc_info->interrupt_target, IOInterruptHandler, proc_info->interrupt_handler,
159 void *, proc_info->interrupt_refCon);
160#endif
161
1c79356b
A
162 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_END,
163 0, 0, 0, 0, 0);
164
165 break;
166
167 case T_SIGP:
168 /* Did the other processor signal us? */
169 cpu_signal_handler();
170 break;
171
172 case T_SHUTDOWN:
173 cpu_doshutdown();
174 panic("returning from cpu_doshutdown()\n");
175 break;
176
177
178 default:
3a60a9f5
A
179 if (!Call_Debugger(type, ssp))
180 unresolved_kernel_trap(type, ssp, dsisr, dar, NULL);
1c79356b
A
181 break;
182 }
183
184 enable_preemption();
185 return ssp;
186}