]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/interrupt.c
xnu-517.7.7.tar.gz
[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 * 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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * @APPLE_FREE_COPYRIGHT@
27 */
28 #include <kern/misc_protos.h>
29 #include <kern/assert.h>
30 #include <kern/thread.h>
31 #include <kern/counters.h>
32 #include <ppc/misc_protos.h>
33 #include <ppc/trap.h>
34 #include <ppc/proc_reg.h>
35 #include <ppc/exception.h>
36 #include <ppc/savearea.h>
37 #include <pexpert/pexpert.h>
38 #include <sys/kdebug.h>
39
40 perfTrap perfIntHook = 0; /* Pointer to performance trap hook routine */
41
42 struct savearea * interrupt(
43 int type,
44 struct savearea *ssp,
45 unsigned int dsisr,
46 unsigned int dar)
47 {
48 int current_cpu, tmpr, targtemp;
49 unsigned int throttle;
50 uint64_t now;
51 thread_act_t act;
52
53 disable_preemption();
54
55 if(perfIntHook) { /* Is there a hook? */
56 if(perfIntHook(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp; /* If it succeeds, we are done... */
57 }
58
59 #if 0
60 {
61 extern void fctx_text(void);
62 fctx_test();
63 }
64 #endif
65
66
67 current_cpu = cpu_number();
68
69 switch (type) {
70
71 case T_THERMAL: /* Fix the air conditioning, I'm dripping with sweat, or freezing, whatever... */
72
73 /*
74 * Note that this code is just a hackification until we have a real thermal plan.
75 */
76
77 tmpr = ml_read_temp(); /* Find out just how hot it is */
78 targtemp = (dar >> 23) & 0x7F; /* Get the temprature we were looking for */
79 if(dar & 4) { /* Did the temprature drop down? */
80 #if 1
81 kprintf("THERMAL below (cpu %d) target = %d; actual = %d; thrm = %08X\n", current_cpu, targtemp, tmpr, dar);
82 #endif
83 #if 0
84 throttle = ml_throttle(0); /* Set throttle off */
85 #if 1
86 kprintf("THERMAL (cpu %d) throttle set off; last = %d\n", current_cpu, throttle);
87 #endif
88 #endif
89 ml_thrm_set(0, per_proc_info[current_cpu].thrm.throttleTemp); /* Set no low temp and max allowable as max */
90
91 #if 1
92 kprintf("THERMAL (cpu %d) temp set to: off min, %d max\n", current_cpu, per_proc_info[current_cpu].thrm.throttleTemp);
93 #endif
94 }
95 else {
96 #if 1
97 kprintf("THERMAL above (cpu %d) target = %d; actual = %d; thrm = %08X\n", current_cpu, targtemp, tmpr, dar);
98 #endif
99 #if 0
100 throttle = ml_throttle(32); /* Set throttle on about 1/8th */
101 #if 1
102 kprintf("THERMAL (cpu %d) throttle set to 32; last = %d\n", current_cpu, throttle);
103 #endif
104 #endif
105 ml_thrm_set(per_proc_info[current_cpu].thrm.throttleTemp - 4, 0); /* Set low temp to max - 4 and max off */
106 #if 1
107 kprintf("THERMAL (cpu %d) temp set to: %d min, off max\n", current_cpu, per_proc_info[current_cpu].thrm.throttleTemp - 4);
108 #endif
109
110 }
111 break;
112
113 case T_DECREMENTER:
114 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI, 0) | DBG_FUNC_NONE,
115 isync_mfdec(), (unsigned int)ssp->save_srr0, 0, 0, 0);
116
117 #if 0
118 if (pcsample_enable) {
119 if (find_user_regs(current_act()))
120 add_pcsamples (user_pc(current_act()));
121 }
122 #endif
123
124 act = current_act(); /* Find ourselves */
125 if(act->mact.qactTimer != 0) { /* Is the timer set? */
126 clock_get_uptime(&now); /* Find out what time it is */
127 if (act->mact.qactTimer <= now) { /* It is set, has it popped? */
128 act->mact.qactTimer = 0; /* Clear single shot timer */
129 if((unsigned int)act->mact.vmmControl & 0xFFFFFFFE) { /* Are there any virtual machines? */
130 vmm_timer_pop(act); /* Yes, check out them out... */
131 }
132 }
133 }
134
135 rtclock_intr(0, ssp, 0);
136 break;
137
138 case T_INTERRUPT:
139 /* Call the platform interrupt routine */
140 counter_always(c_incoming_interrupts++);
141
142 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_START,
143 current_cpu, (unsigned int)ssp->save_srr0, 0, 0, 0);
144
145 per_proc_info[current_cpu].interrupt_handler(
146 per_proc_info[current_cpu].interrupt_target,
147 per_proc_info[current_cpu].interrupt_refCon,
148 per_proc_info[current_cpu].interrupt_nub,
149 per_proc_info[current_cpu].interrupt_source);
150
151 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_END,
152 0, 0, 0, 0, 0);
153
154 break;
155
156 case T_SIGP:
157 /* Did the other processor signal us? */
158 cpu_signal_handler();
159 break;
160
161 case T_SHUTDOWN:
162 cpu_doshutdown();
163 panic("returning from cpu_doshutdown()\n");
164 break;
165
166
167 default:
168 #if MACH_KDP || MACH_KDB
169 (void)Call_Debugger(type, ssp);
170 #else
171 panic("Invalid interrupt type %x\n", type);
172 #endif
173 break;
174 }
175
176 enable_preemption();
177 return ssp;
178 }