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
|
/* $OpenBSD: intr.h,v 1.1 2004/08/06 21:12:19 pefo 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.
*
*/
#ifndef _MACHINE_INTR_H_
#define _MACHINE_INTR_H_
/*
* The interrupt mask cpl is a mask which can be used with the
* CPU interrupt mask register or an external HW mask register.
* If interrupts are masked by the CPU interrupt mask all external
* masks should be enabled and any routing set up so that the
* interrupt source is routed to the CPU interrupt corresponding
* to the interrupts "priority level". In this case the generic
* interrupt handler can be used.
*
* The IMASK_EXTERNAL define is used to select wether the CPU
* interrupt mask should be controlled by the cpl mask value
* or not. If the mask is external, the CPU mask is never changed
* from the value it gets when interrupt dispatchers are registred.
* When an external masking register is used dedicated interrupt
* handlers must be written as well as ipending handlers.
*/
#define IMASK_EXTERNAL /* XXX move this to config */
/* Interrupt priority `levels'; not mutually exclusive. */
#define IPL_BIO 0 /* block I/O */
#define IPL_NET 1 /* network */
#define IPL_TTY 2 /* terminal */
#define IPL_VM 3 /* memory allocation */
#define IPL_CLOCK 4 /* clock */
#define IPL_NONE 5 /* nothing */
#define IPL_HIGH 6 /* everything */
#define NIPLS 7 /* Number of levels */
/* Interrupt sharing types. */
#define IST_NONE 0 /* none */
#define IST_PULSE 1 /* pulsed */
#define IST_EDGE 2 /* edge-triggered */
#define IST_LEVEL 3 /* level-triggered */
/* Soft interrupt masks. */
#define SINT_CLOCK 31
#define SINT_CLOCKMASK (1 << SINT_CLOCK)
#define SINT_NET 30
#define SINT_NETMASK ((1 << SINT_NET) | SINT_CLOCKMASK)
#define SINT_TTY 29
#define SINT_TTYMASK ((1 << SINT_TTY) | SINT_CLOCKMASK)
#define SINT_ALLMASK (SINT_CLOCKMASK | SINT_NETMASK | SINT_TTYMASK)
#define SPL_CLOCK 28
#define SPL_CLOCKMASK (1 << SPL_CLOCK)
#ifndef _LOCORE
#if 1
#define splbio() splraise(imask[IPL_BIO])
#define splnet() splraise(imask[IPL_NET])
#define spltty() splraise(imask[IPL_TTY])
#define splclock() splraise(SPL_CLOCKMASK|SINT_ALLMASK)
#define splimp() splraise(imask[IPL_VM])
#define splvm() splraise(imask[IPL_VM])
#define splsoftclock() splraise(SINT_CLOCKMASK)
#define splsoftnet() splraise(SINT_NETMASK|SINT_CLOCKMASK)
#define splsofttty() splraise(SINT_TTYMASK)
#else
#define splbio() splhigh()
#define splnet() splhigh()
#define spltty() splhigh()
#define splclock() splhigh()
#define splimp() splhigh()
#define splvm() splhigh()
#define splsoftclock() splhigh()
#define splsoftnet() splhigh()
#define splsofttty() splhigh()
#endif
#define splstatclock() splhigh()
#define splhigh() splraise(-1)
#define spl0() spllower(0)
#define spllowersoftclock() spllower(SINT_CLOCKMASK)
#define setsoftclock() set_sint(SINT_CLOCKMASK);
#define setsoftnet() set_sint(SINT_NETMASK);
#define setsofttty() set_sint(SINT_TTYMASK);
void splinit(void);
#define splassert(X)
/*
* Schedule prioritys for base interrupts (cpu)
*/
#define INTPRI_CLOCK 1
#define INTPRI_MACEIO 2
#define INTPRI_MACEAUX 3
/*
* Define a type for interrupt masks. We may need 64 bits here.
*/
typedef u_int32_t intrmask_t; /* Type of var holding interrupt mask */
#define INTMASKSIZE (sizeof(intrmask_t) * 8)
void clearsoftclock(void);
void clearsoftnet(void);
#if 0
void clearsofttty(void);
#endif
volatile intrmask_t cpl;
volatile intrmask_t ipending, astpending;
intrmask_t imask[NIPLS];
/*
* A note on clock interrupts. Clock interrupts are always
* allowed to happen but will not be serviced if masked.
* The reason for this is that clocks usually sits on INT5
* and can not be easily masked if external HW masking is used.
*/
/* Inlines */
static __inline void register_pending_int_handler(void (*)(void));
static __inline int splraise(int newcpl);
static __inline void splx(int newcpl);
static __inline int spllower(int newcpl);
typedef void (void_f) (void);
void_f *pending_hand;
static __inline void
register_pending_int_handler(void(*pending)(void))
{
pending_hand = pending;
}
/*
*/
static __inline int
splraise(int newcpl)
{
int oldcpl;
__asm__ (" .set noreorder\n");
oldcpl = cpl;
cpl = oldcpl | newcpl;
__asm__ (" sync\n .set reorder\n");
return(oldcpl);
}
static __inline void
splx(int newcpl)
{
cpl = newcpl;
if((ipending & ~newcpl) && (pending_hand != NULL)) {
(*pending_hand)();
}
}
static __inline int
spllower(int newcpl)
{
int oldcpl;
oldcpl = cpl;
cpl = newcpl;
if((ipending & ~newcpl) && (pending_hand != NULL)) {
(*pending_hand)();
}
return(oldcpl);
}
/*
* Atomically update ipending.
*/
void set_sint(int pending);
/*
* Interrupt control struct used by interrupt dispatchers
* to hold interrupt handler info.
*/
struct intrhand {
struct intrhand *ih_next;
int (*ih_fun)(void *);
void *ih_arg;
u_long ih_count;
int ih_level;
int ih_irq;
char *ih_what;
void *frame;
};
/*
* Low level interrupt dispatcher registration data.
*/
#define NLOWINT 16 /* Number of low level registrations possible */
struct trap_frame;
struct {
intrmask_t int_mask;
intrmask_t (*int_hand)(intrmask_t, struct trap_frame *);
} cpu_int_tab[NLOWINT];
intrmask_t idle_mask;
int last_low_int;
void set_intr(int, intrmask_t, intrmask_t(*)(intrmask_t, struct trap_frame *));
#ifdef IMASK_EXTERNAL
void hw_setintrmask(intrmask_t);
extern void *hwmask_addr;
#endif
/*
* Generic interrupt handling code that can be used for simple
* interrupt hardware models. Functions can also be used by
* more complex code especially the mask calculation code.
*/
void *generic_intr_establish(void *, u_long, int, int,
int (*) __P((void *)), void *, char *);
void generic_intr_disestablish(void *, void *);
void generic_intr_makemasks(void);
void generic_do_pending_int(void);
intrmask_t generic_iointr(intrmask_t, struct trap_frame *);
#endif /* _LOCORE */
#endif /* _MACHINE_INTR_H_ */
|