threaded interrupts 1: Rewrite the ICU interrupt code, splz, and doreti code.
[dragonfly.git] / sys / platform / pc32 / isa / intr_machdep.h
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $FreeBSD: src/sys/i386/isa/intr_machdep.h,v 1.19.2.2 2001/10/14 20:05:50 luigi Exp $
34  * $DragonFly: src/sys/platform/pc32/isa/intr_machdep.h,v 1.3 2003/06/29 03:28:43 dillon Exp $
35  */
36
37 #ifndef _I386_ISA_INTR_MACHDEP_H_
38 #define _I386_ISA_INTR_MACHDEP_H_
39
40 #ifndef _SYS_INTERRUPT_H_
41 #include <sys/interrupt.h>
42 #endif
43
44 /*
45  * Low level interrupt code.
46  */ 
47
48 #ifdef _KERNEL
49
50 #if defined(SMP) || defined(APIC_IO)
51 /*
52  * XXX FIXME: rethink location for all IPI vectors.
53  */
54
55 /*
56     APIC TPR priority vector levels:
57
58         0xff (255) +-------------+
59                    |             | 15 (IPIs: Xspuriousint)
60         0xf0 (240) +-------------+
61                    |             | 14
62         0xe0 (224) +-------------+
63                    |             | 13
64         0xd0 (208) +-------------+
65                    |             | 12
66         0xc0 (192) +-------------+
67                    |             | 11
68         0xb0 (176) +-------------+
69                    |             | 10 (IPIs: Xcpustop)
70         0xa0 (160) +-------------+
71                    |             |  9 (IPIs: Xinvltlb)
72         0x90 (144) +-------------+
73                    |             |  8 (linux/BSD syscall, IGNORE FAST HW INTS)
74         0x80 (128) +-------------+
75                    |             |  7 (FAST_INTR 16-23)
76         0x70 (112) +-------------+
77                    |             |  6 (FAST_INTR 0-15)
78         0x60 (96)  +-------------+
79                    |             |  5 (IGNORE HW INTS)
80         0x50 (80)  +-------------+
81                    |             |  4 (2nd IO APIC)
82         0x40 (64)  +------+------+
83                    |      |      |  3 (upper APIC hardware INTs: PCI)
84         0x30 (48)  +------+------+
85                    |             |  2 (start of hardware INTs: ISA)
86         0x20 (32)  +-------------+
87                    |             |  1 (exceptions, traps, etc.)
88         0x10 (16)  +-------------+
89                    |             |  0 (exceptions, traps, etc.)
90         0x00 (0)   +-------------+
91  */
92
93 /* IDT vector base for regular (aka. slow) and fast interrupts */
94 #define TPR_SLOW_INTS           0x20
95 #define TPR_FAST_INTS           0x60
96
97 /* blocking values for local APIC Task Priority Register */
98 #define TPR_BLOCK_HWI           0x4f            /* hardware INTs */
99 #define TPR_IGNORE_HWI          0x5f            /* ignore INTs */
100 #define TPR_BLOCK_FHWI          0x7f            /* hardware FAST INTs */
101 #define TPR_IGNORE_FHWI         0x8f            /* ignore FAST INTs */
102 #define TPR_BLOCK_XINVLTLB      0x9f            /*  */
103 #define TPR_BLOCK_XCPUSTOP      0xaf            /*  */
104 #define TPR_BLOCK_ALL           0xff            /* all INTs */
105
106
107 #ifdef TEST_TEST1
108 /* put a 'fake' HWI in top of APIC prio 0x3x, 32 + 31 = 63 = 0x3f */
109 #define XTEST1_OFFSET           (ICU_OFFSET + 31)
110 #endif /** TEST_TEST1 */
111
112 /* TLB shootdowns */
113 #define XINVLTLB_OFFSET         (ICU_OFFSET + 112)
114
115 #ifdef BETTER_CLOCK
116 /* inter-cpu clock handling */
117 #define XCPUCHECKSTATE_OFFSET   (ICU_OFFSET + 113)
118 #endif
119
120 /* inter-CPU rendezvous */
121 #define XRENDEZVOUS_OFFSET      (ICU_OFFSET + 114)
122
123 /* IPI to generate an additional software trap at the target CPU */
124 #define XCPUAST_OFFSET          (ICU_OFFSET +  48)
125
126 /* IPI to signal the CPU holding the ISR lock that another IRQ has appeared */
127 #define XFORWARD_IRQ_OFFSET     (ICU_OFFSET +  49)
128
129 /* IPI to signal CPUs to stop and wait for another CPU to restart them */
130 #define XCPUSTOP_OFFSET         (ICU_OFFSET + 128)
131
132 /*
133  * Note: this vector MUST be xxxx1111, 32 + 223 = 255 = 0xff:
134  */
135 #define XSPURIOUSINT_OFFSET     (ICU_OFFSET + 223)
136
137 #endif /* SMP || APIC_IO */
138
139 #ifndef LOCORE
140
141 /*
142  * Type of the first (asm) part of an interrupt handler.
143  */
144 typedef void inthand_t(u_int cs, u_int ef, u_int esp, u_int ss);
145 typedef void unpendhand_t(void);
146
147 #define IDTVEC(name)    __CONCAT(X,name)
148
149 extern u_long *intr_countp[];   /* pointers into intrcnt[] */
150 extern inthand2_t *intr_handler[];      /* C entry points for FAST ints */
151 extern u_int intr_mask[];       /* sets of intrs masked during handling of 1 */
152 extern void *intr_unit[];       /* cookies to pass to intr handlers */
153
154 inthand_t
155         IDTVEC(fastintr0), IDTVEC(fastintr1),
156         IDTVEC(fastintr2), IDTVEC(fastintr3),
157         IDTVEC(fastintr4), IDTVEC(fastintr5),
158         IDTVEC(fastintr6), IDTVEC(fastintr7),
159         IDTVEC(fastintr8), IDTVEC(fastintr9),
160         IDTVEC(fastintr10), IDTVEC(fastintr11),
161         IDTVEC(fastintr12), IDTVEC(fastintr13),
162         IDTVEC(fastintr14), IDTVEC(fastintr15);
163 inthand_t
164         IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3),
165         IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7),
166         IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11),
167         IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15);
168
169 unpendhand_t
170         IDTVEC(fastunpend0), IDTVEC(fastunpend1),
171         IDTVEC(fastunpend2), IDTVEC(fastunpend3),
172         IDTVEC(fastunpend4), IDTVEC(fastunpend5),
173         IDTVEC(fastunpend6), IDTVEC(fastunpend7),
174         IDTVEC(fastunpend8), IDTVEC(fastunpend9),
175         IDTVEC(fastunpend10), IDTVEC(fastunpend11),
176         IDTVEC(fastunpend12), IDTVEC(fastunpend13),
177         IDTVEC(fastunpend14), IDTVEC(fastunpend15);
178
179 #if defined(APIC_IO)
180 inthand_t
181         IDTVEC(fastintr16), IDTVEC(fastintr17),
182         IDTVEC(fastintr18), IDTVEC(fastintr19),
183         IDTVEC(fastintr20), IDTVEC(fastintr21),
184         IDTVEC(fastintr22), IDTVEC(fastintr23);
185 inthand_t
186         IDTVEC(intr16), IDTVEC(intr17), IDTVEC(intr18), IDTVEC(intr19),
187         IDTVEC(intr20), IDTVEC(intr21), IDTVEC(intr22), IDTVEC(intr23);
188 unpendhand_t
189         IDTVEC(fastunpend16), IDTVEC(fastunpend17),
190         IDTVEC(fastunpend18), IDTVEC(fastunpend19),
191         IDTVEC(fastunpend20), IDTVEC(fastunpend21),
192         IDTVEC(fastunpend22), IDTVEC(fastunpend23);
193 #endif
194
195 #if defined(SMP)
196 inthand_t
197         Xinvltlb,       /* TLB shootdowns */
198 #ifdef BETTER_CLOCK
199         Xcpucheckstate, /* Check cpu state */
200 #endif
201         Xcpuast,        /* Additional software trap on other cpu */ 
202         Xforward_irq,   /* Forward irq to cpu holding ISR lock */
203         Xcpustop,       /* CPU stops & waits for another CPU to restart it */
204         Xspuriousint,   /* handle APIC "spurious INTs" */
205         Xrendezvous;    /* handle CPU rendezvous */
206
207 #ifdef TEST_TEST1
208 inthand_t
209         Xtest1;         /* 'fake' HWI at top of APIC prio 0x3x, 32+31 = 0x3f */
210 #endif /** TEST_TEST1 */
211 #endif /* SMP */
212
213 void    call_fast_unpend(int irq);
214 void    isa_defaultirq __P((void));
215 int     isa_nmi __P((int cd));
216 int     icu_setup __P((int intr, inthand2_t *func, void *arg, 
217                        u_int *maskptr, int flags));
218 int     icu_unset __P((int intr, inthand2_t *handler));
219 int     update_intr_masks __P((void));
220
221 intrmask_t splq __P((intrmask_t mask));
222
223 #define INTR_FAST               0x00000001 /* fast interrupt handler */
224 #define INTR_EXCL               0x00010000 /* excl. intr, default is shared */
225
226 /*
227  * WARNING: These are internal functions and not to be used by device drivers!
228  * They are subject to change without notice. 
229  */
230 struct intrec *inthand_add(const char *name, int irq, inthand2_t handler,
231                            void *arg, intrmask_t *maskptr, int flags);
232
233 int inthand_remove(struct intrec *idesc);
234
235 #endif /* LOCORE */
236
237 #endif /* _KERNEL */
238
239 #endif /* !_I386_ISA_INTR_MACHDEP_H_ */