1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/* $OpenBSD: interrupt.c,v 1.34 2009/03/20 18:41:06 miod Exp $ */
/*
* Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/signalvar.h>
#include <sys/user.h>
#include <sys/malloc.h>
#include <sys/device.h>
#ifdef KTRACE
#include <sys/ktrace.h>
#endif
#include <machine/trap.h>
#include <machine/psl.h>
#include <machine/cpu.h>
#include <machine/intr.h>
#include <machine/autoconf.h>
#include <machine/frame.h>
#include <machine/regnum.h>
#include <machine/atomic.h>
#include <mips64/rm7000.h>
#include <mips64/archtype.h>
#ifdef DDB
#include <mips64/db_machdep.h>
#include <ddb/db_sym.h>
#endif
static struct evcount soft_count;
static int soft_irq = 0;
volatile intrmask_t cpl;
volatile intrmask_t ipending, astpending;
intrmask_t imask[NIPLS];
intrmask_t idle_mask;
int last_low_int;
struct {
intrmask_t int_mask;
intrmask_t (*int_hand)(intrmask_t, struct trap_frame *);
} cpu_int_tab[NLOWINT];
void dummy_do_pending_int(int);
int_f *pending_hand = &dummy_do_pending_int;
/*
* Modern versions of MIPS processors have extended interrupt
* capabilities. How these are handled differs from implementation
* to implementation. This code tries to hide away some of these
* in "higher level" interrupt code.
*
* Basically there are <n> interrupt inputs to the processor and
* typically the HW designer ties these interrupts to various
* sources in the HW. The low level code does not deal with interrupts
* in more than it dispatches handling to the code that has registered
* an interrupt handler for that particular interrupt. More than one
* handler can register to an interrupt input and one handler may register
* for more than one interrupt input. A handler is only called once even
* if it register for more than one interrupt input.
*
* The interrupt mechanism in this port uses a delayed masking model
* where interrupts are not really masked when doing an spl(). Instead
* a masked interrupt will be taken and validated in the various
* handlers. If the handler finds that an interrupt is masked it will
* register this interrupt as pending and return a new mask to this
* code that will turn off the interrupt hardware wise. Later when
* the pending interrupt is unmasked it will be processed as usual
* and the hardware mask will be restored.
*/
/*
* Interrupt mapping is as follows:
*
* irq can be between 1 and 10. This maps to CPU IPL2..IPL11.
* The two software interrupts IPL0 and IPL1 are reserved for
* kernel functions. IPL13 is used for the performance counters
* in the RM7000. IPL12 extra timer is currently not used.
*
* irq's maps into the software spl register to the bit corresponding
* to its status/mask bit in the cause/sr register shifted right eight
* places.
*
* A well designed system uses the CPUs interrupt inputs in a way, such
* that masking can be done according to the IPL in the CPU status and
* interrupt control register. However support for an external masking
* register is provided but will cause a slightly higher overhead when
* used. When an external masking register is used, no masking in the
* CPU is done. Instead a fixed mask is set and used throughout.
*/
void interrupt(struct trap_frame *);
void softintr(void);
/*
* Handle an interrupt. Both kernel and user mode is handled here.
*
* The interrupt handler is called with the CR_INT bits set that
* was given when the handlers was registered that needs servicing.
* The handler should return a similar word with a mask indicating
* which CR_INT bits that has been served.
*/
void
interrupt(struct trap_frame *trapframe)
{
u_int32_t pending;
u_int32_t cause;
int i;
intrmask_t xcpl;
/*
* Paranoic? Perhaps. But if we got here with the enable
* bit reset a mtc0 COP_0_STATUS_REG may have been interrupted.
* If this was a disable and the pipeline had advanced long
* enough... i don't know but better safe than sorry...
* The main effect is not the interrupts but the spl mechanism.
*/
if (!(trapframe->sr & SR_INT_ENAB)) {
return;
}
#ifdef DEBUG_INTERRUPT
trapdebug_enter(trapframe, 0);
#endif
uvmexp.intrs++;
/* Mask out interrupts from cause that are unmasked */
pending = trapframe->cause & CR_IPEND & trapframe->sr;
cause = pending;
if (cause & SOFT_INT_MASK_0) {
clearsoftintr0();
soft_count.ec_count++;
}
if (cause & CR_INT_PERF) {
rm7k_perfintr(trapframe);
cause &= ~CR_INT_PERF;
}
for (i = 0; i <= last_low_int; i++) {
intrmask_t active;
active = cpu_int_tab[i].int_mask & pending;
if (active) {
cause &= ~(*cpu_int_tab[i].int_hand)(active, trapframe);
}
}
/*
* Reenable all non served hardware levels.
*/
#if 0
/* XXX the following should, when req., change the IC reg as well */
setsr((trapframe->sr & ~pending) | SR_INT_ENAB);
#endif
xcpl = splsoft();
if ((ipending & SINT_ALLMASK) & ~xcpl) {
dosoftint(xcpl);
}
__asm__ (" .set noreorder\n");
cpl = xcpl;
__asm__ (" sync\n .set reorder\n");
}
/*
* Set up handler for external interrupt events.
* Use CR_INT_<n> to select the proper interrupt
* condition to dispatch on. We also enable the
* software ints here since they are always on.
*/
void
set_intr(int pri, intrmask_t mask,
intrmask_t (*int_hand)(intrmask_t, struct trap_frame *))
{
if ((idle_mask & SOFT_INT_MASK) == 0)
evcount_attach(&soft_count, "soft", (void *)&soft_irq, &evcount_intr);
if (pri < 0 || pri >= NLOWINT) {
panic("set_intr: to high priority");
}
if (pri > last_low_int)
last_low_int = pri;
if ((mask & ~CR_IPEND) != 0) {
panic("set_intr: invalid mask 0x%x", mask);
}
if (cpu_int_tab[pri].int_mask != 0 &&
(cpu_int_tab[pri].int_mask != mask ||
cpu_int_tab[pri].int_hand != int_hand)) {
panic("set_intr: int already set at pri %d", pri);
}
cpu_int_tab[pri].int_hand = int_hand;
cpu_int_tab[pri].int_mask = mask;
idle_mask |= mask | SOFT_INT_MASK;
}
/*
* This is called from MipsUserIntr() if astpending is set.
*/
void
softintr()
{
struct proc *p = curproc;
int sig;
uvmexp.softs++;
astpending = 0;
if (p->p_flag & P_OWEUPC) {
ADDUPROF(p);
}
if (want_resched)
preempt(NULL);
/* inline userret(p) */
while ((sig = CURSIG(p)) != 0) /* take pending signals */
postsig(sig);
p->p_cpu->ci_schedstate.spc_curpriority = p->p_priority = p->p_usrpri;
}
struct intrhand *intrhand[INTMASKSIZE];
void
dummy_do_pending_int(int newcpl)
{
/* Dummy handler */
}
/*
* splinit() is special in that sense that it require us to update
* the interrupt mask in the CPU since it may be the first time we arm
* the interrupt system. This function is called right after
* autoconfiguration has compleeted in autoconf.c.
* We enable everything in idle_mask.
*/
void
splinit()
{
u_int32_t sr;
spl0();
sr = updateimask(0);
sr |= SR_INT_ENAB;
setsr(sr);
#ifdef IMASK_EXTERNAL
hw_setintrmask(0);
#endif
}
#ifndef INLINE_SPLRAISE
int
splraise(int newcpl)
{
int oldcpl;
__asm__ (" .set noreorder\n");
oldcpl = cpl;
cpl = oldcpl | newcpl;
__asm__ (" sync\n .set reorder\n");
return (oldcpl);
}
#endif
|