]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/interrupt.c
3895c380044345616640a204b81ddcf9b42e7217
[apple/xnu.git] / osfmk / ppc / interrupt.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * @APPLE_FREE_COPYRIGHT@
30 */
31 #include <kern/misc_protos.h>
32 #include <kern/assert.h>
33 #include <kern/thread.h>
34 #include <kern/counters.h>
35 #include <ppc/misc_protos.h>
36 #include <ppc/proc_reg.h>
37 #include <ppc/exception.h>
38 #include <ppc/savearea.h>
39 #include <pexpert/pexpert.h>
40 #if NCPUS > 1
41 #include <ppc/POWERMAC/mp/MPPlugIn.h>
42 #endif /* NCPUS > 1 */
43 #include <sys/kdebug.h>
44
45 struct savearea * interrupt(
46 int type,
47 struct savearea *ssp,
48 unsigned int dsisr,
49 unsigned int dar)
50 {
51 int current_cpu, tmpr, targtemp;
52 unsigned int throttle;
53 uint64_t now;
54 thread_act_t act;
55
56 disable_preemption();
57
58 #if 0
59 {
60 extern void fctx_text(void);
61 fctx_test();
62 }
63 #endif
64
65
66 current_cpu = cpu_number();
67
68 switch (type) {
69
70 case T_THERMAL: /* Fix the air conditioning, I'm dripping with sweat, or freezing, whatever... */
71
72 /*
73 * Note that this code is just a hackification until we have a real thermal plan.
74 */
75
76 tmpr = ml_read_temp(); /* Find out just how hot it is */
77 targtemp = (dar >> 23) & 0x7F; /* Get the temprature we were looking for */
78 if(dar & 4) { /* Did the temprature drop down? */
79 #if 1
80 kprintf("THERMAL below (cpu %d) target = %d; actual = %d; thrm = %08X\n", current_cpu, targtemp, tmpr, dar);
81 #endif
82 #if 0
83 throttle = ml_throttle(0); /* Set throttle off */
84 #if 1
85 kprintf("THERMAL (cpu %d) throttle set off; last = %d\n", current_cpu, throttle);
86 #endif
87 #endif
88 ml_thrm_set(0, per_proc_info[current_cpu].thrm.throttleTemp); /* Set no low temp and max allowable as max */
89
90 #if 1
91 kprintf("THERMAL (cpu %d) temp set to: off min, %d max\n", current_cpu, per_proc_info[current_cpu].thrm.throttleTemp);
92 #endif
93 }
94 else {
95 #if 1
96 kprintf("THERMAL above (cpu %d) target = %d; actual = %d; thrm = %08X\n", current_cpu, targtemp, tmpr, dar);
97 #endif
98 #if 0
99 throttle = ml_throttle(32); /* Set throttle on about 1/8th */
100 #if 1
101 kprintf("THERMAL (cpu %d) throttle set to 32; last = %d\n", current_cpu, throttle);
102 #endif
103 #endif
104 ml_thrm_set(per_proc_info[current_cpu].thrm.throttleTemp - 4, 0); /* Set low temp to max - 4 and max off */
105 #if 1
106 kprintf("THERMAL (cpu %d) temp set to: %d min, off max\n", current_cpu, per_proc_info[current_cpu].thrm.throttleTemp - 4);
107 #endif
108
109 }
110 break;
111
112 case T_DECREMENTER:
113 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI, 0) | DBG_FUNC_NONE,
114 isync_mfdec(), ssp->save_srr0, 0, 0, 0);
115
116 #if 0
117 if (pcsample_enable) {
118 if (find_user_regs(current_act()))
119 add_pcsamples (user_pc(current_act()));
120 }
121 #endif
122
123 act = current_act(); /* Find ourselves */
124 if(act->mact.qactTimer != 0) { /* Is the timer set? */
125 clock_get_uptime(&now); /* Find out what time it is */
126 if (act->mact.qactTimer <= now) { /* It is set, has it popped? */
127 act->mact.qactTimer = 0; /* Clear single shot timer */
128 if((unsigned int)act->mact.vmmControl & 0xFFFFFFFE) { /* Are there any virtual machines? */
129 vmm_timer_pop(act); /* Yes, check out them out... */
130 }
131 }
132 }
133
134 rtclock_intr(0, ssp, 0);
135 break;
136
137 case T_INTERRUPT:
138 /* Call the platform interrupt routine */
139 counter_always(c_incoming_interrupts++);
140
141 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_START,
142 current_cpu, ssp->save_srr0, 0, 0, 0);
143
144 per_proc_info[current_cpu].interrupt_handler(
145 per_proc_info[current_cpu].interrupt_target,
146 per_proc_info[current_cpu].interrupt_refCon,
147 per_proc_info[current_cpu].interrupt_nub,
148 per_proc_info[current_cpu].interrupt_source);
149
150 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_END,
151 0, 0, 0, 0, 0);
152
153 break;
154
155 case T_SIGP:
156 /* Did the other processor signal us? */
157 cpu_signal_handler();
158 break;
159
160 case T_SHUTDOWN:
161 cpu_doshutdown();
162 panic("returning from cpu_doshutdown()\n");
163 break;
164
165
166 default:
167 #if MACH_KDP || MACH_KDB
168 (void)Call_Debugger(type, ssp);
169 #else
170 panic("Invalid interrupt type %x\n", type);
171 #endif
172 break;
173 }
174
175 enable_preemption();
176 return ssp;
177 }