]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/interrupt.c
xnu-1456.1.26.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
b0d623f7 51volatile perfCallback perfIntHook; /* Pointer to CHUD trap hook routine */
2d21ac55
A
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 89
b0d623f7
A
90 perfCallback fn = perfIntHook;
91 if(fn) { /* Is there a hook? */
92 if(fn(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp; /* If it succeeds, we are done... */
55e303ae 93 }
1c79356b 94
2d21ac55
A
95#if CONFIG_DTRACE
96 if(tempDTraceIntHook) { /* Is there a hook? */
97 if(tempDTraceIntHook(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp; /* If it succeeds, we are done... */
98 }
99#endif
100
9bccf70c
A
101#if 0
102 {
103 extern void fctx_text(void);
104 fctx_test();
105 }
106#endif
91447636
A
107
108
1c79356b 109 current_cpu = cpu_number();
91447636 110 proc_info = getPerProc();
1c79356b
A
111
112 switch (type) {
113
1c79356b
A
114 case T_DECREMENTER:
115 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI, 0) | DBG_FUNC_NONE,
55e303ae 116 isync_mfdec(), (unsigned int)ssp->save_srr0, 0, 0, 0);
1c79356b 117
3a60a9f5
A
118 now = mach_absolute_time(); /* Find out what time it is */
119
120 if(now >= proc_info->pms.pmsPop) { /* Is it time for power management state change? */
121 pmsStep(1); /* Yes, advance step */
122 now = mach_absolute_time(); /* Get the time again since we ran a bit */
123 }
124
91447636
A
125 thread = current_thread(); /* Find ourselves */
126 if(thread->machine.qactTimer != 0) { /* Is the timer set? */
91447636
A
127 if (thread->machine.qactTimer <= now) { /* It is set, has it popped? */
128 thread->machine.qactTimer = 0; /* Clear single shot timer */
129 if((unsigned int)thread->machine.vmmControl & 0xFFFFFFFE) { /* Are there any virtual machines? */
130 vmm_timer_pop(thread); /* Yes, check out them out... */
1c79356b
A
131 }
132 }
133 }
134
0c530ab8 135 etimer_intr(USER_MODE(ssp->save_srr1), ssp->save_srr0); /* Handle event timer */
1c79356b
A
136 break;
137
138 case T_INTERRUPT:
139 /* Call the platform interrupt routine */
2d21ac55 140 counter(c_incoming_interrupts++);
1c79356b
A
141
142 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_START,
55e303ae 143 current_cpu, (unsigned int)ssp->save_srr0, 0, 0, 0);
1c79356b 144
2d21ac55
A
145#if CONFIG_DTRACE && (DEVELOPMENT || DEBUG )
146 DTRACE_INT5(interrupt__start, void *, proc_info->interrupt_nub, int, proc_info->interrupt_source,
147 void *, proc_info->interrupt_target, IOInterruptHandler, proc_info->interrupt_handler,
148 void *, proc_info->interrupt_refCon);
149#endif
150
91447636
A
151 proc_info->interrupt_handler(
152 proc_info->interrupt_target,
153 proc_info->interrupt_refCon,
154 proc_info->interrupt_nub,
155 proc_info->interrupt_source);
1c79356b 156
2d21ac55
A
157#if CONFIG_DTRACE && (DEVELOPMENT || DEBUG )
158 DTRACE_INT5(interrupt__complete, void *, proc_info->interrupt_nub, int, proc_info->interrupt_source,
159 void *, proc_info->interrupt_target, IOInterruptHandler, proc_info->interrupt_handler,
160 void *, proc_info->interrupt_refCon);
161#endif
162
1c79356b
A
163 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_END,
164 0, 0, 0, 0, 0);
165
166 break;
167
168 case T_SIGP:
169 /* Did the other processor signal us? */
170 cpu_signal_handler();
171 break;
172
173 case T_SHUTDOWN:
174 cpu_doshutdown();
175 panic("returning from cpu_doshutdown()\n");
176 break;
177
178
179 default:
3a60a9f5
A
180 if (!Call_Debugger(type, ssp))
181 unresolved_kernel_trap(type, ssp, dsisr, dar, NULL);
1c79356b
A
182 break;
183 }
184
185 enable_preemption();
186 return ssp;
187}