MP Implementation 1/2: Get the APIC code working again, sweetly integrate the
[dragonfly.git] / sys / i386 / 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/i386/isa/Attic/intr_machdep.h,v 1.4 2003/07/06 21:23:49 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 #ifndef LOCORE
42 #include <sys/interrupt.h>
43 #endif
44 #endif
45
46 /*
47  * Low level interrupt code.
48  */ 
49
50 #ifdef _KERNEL
51
52 #if defined(SMP) || defined(APIC_IO)
53 /*
54  * XXX FIXME: rethink location for all IPI vectors.
55  */
56
57 /*
58     APIC TPR priority vector levels:
59
60         0xff (255) +-------------+
61                    |             | 15 (IPIs: Xspuriousint)
62         0xf0 (240) +-------------+
63                    |             | 14
64         0xe0 (224) +-------------+
65                    |             | 13
66         0xd0 (208) +-------------+
67                    |             | 12
68         0xc0 (192) +-------------+
69                    |             | 11
70         0xb0 (176) +-------------+
71                    |             | 10 (IPIs: Xcpustop)
72         0xa0 (160) +-------------+
73                    |             |  9 (IPIs: Xinvltlb)
74         0x90 (144) +-------------+
75                    |             |  8 (linux/BSD syscall, IGNORE FAST HW INTS)
76         0x80 (128) +-------------+
77                    |             |  7 (FAST_INTR 16-23)
78         0x70 (112) +-------------+
79                    |             |  6 (FAST_INTR 0-15)
80         0x60 (96)  +-------------+
81                    |             |  5 (IGNORE HW INTS)
82         0x50 (80)  +-------------+
83                    |             |  4 (2nd IO APIC)
84         0x40 (64)  +------+------+
85                    |      |      |  3 (upper APIC hardware INTs: PCI)
86         0x30 (48)  +------+------+
87                    |             |  2 (start of hardware INTs: ISA)
88         0x20 (32)  +-------------+
89                    |             |  1 (exceptions, traps, etc.)
90         0x10 (16)  +-------------+
91                    |             |  0 (exceptions, traps, etc.)
92         0x00 (0)   +-------------+
93  */
94
95 /* IDT vector base for regular (aka. slow) and fast interrupts */
96 #define TPR_SLOW_INTS           0x20
97 #define TPR_FAST_INTS           0x60
98
99 /* blocking values for local APIC Task Priority Register */
100 #define TPR_BLOCK_HWI           0x4f            /* hardware INTs */
101 #define TPR_IGNORE_HWI          0x5f            /* ignore INTs */
102 #define TPR_BLOCK_FHWI          0x7f            /* hardware FAST INTs */
103 #define TPR_IGNORE_FHWI         0x8f            /* ignore FAST INTs */
104 #define TPR_IPI_ONLY            0x8f            /* ignore FAST INTs */
105 #define TPR_BLOCK_XINVLTLB      0x9f            /*  */
106 #define TPR_BLOCK_XCPUSTOP      0xaf            /*  */
107 #define TPR_BLOCK_ALL           0xff            /* all INTs */
108
109
110 #ifdef TEST_TEST1
111 /* put a 'fake' HWI in top of APIC prio 0x3x, 32 + 31 = 63 = 0x3f */
112 #define XTEST1_OFFSET           (ICU_OFFSET + 31)
113 #endif /** TEST_TEST1 */
114
115 /* TLB shootdowns */
116 #define XINVLTLB_OFFSET         (ICU_OFFSET + 112)
117
118 #ifdef BETTER_CLOCK
119 /* inter-cpu clock handling */
120 #define XCPUCHECKSTATE_OFFSET   (ICU_OFFSET + 113)
121 #endif
122
123 /* inter-CPU rendezvous */
124 #define XRENDEZVOUS_OFFSET      (ICU_OFFSET + 114)
125
126 /* IPI to generate an additional software trap at the target CPU */
127 #define XCPUAST_OFFSET          (ICU_OFFSET +  48)
128
129 /* IPI to signal the CPU holding the ISR lock that another IRQ has appeared */
130 #define XFORWARD_IRQ_OFFSET     (ICU_OFFSET +  49)
131
132 /* IPI to signal CPUs to stop and wait for another CPU to restart them */
133 #define XCPUSTOP_OFFSET         (ICU_OFFSET + 128)
134
135 /*
136  * Note: this vector MUST be xxxx1111, 32 + 223 = 255 = 0xff:
137  */
138 #define XSPURIOUSINT_OFFSET     (ICU_OFFSET + 223)
139
140 #endif /* SMP || APIC_IO */
141
142 #ifndef LOCORE
143
144 /*
145  * Type of the first (asm) part of an interrupt handler.
146  */
147 typedef void inthand_t(u_int cs, u_int ef, u_int esp, u_int ss);
148 typedef void unpendhand_t(void);
149
150 #define IDTVEC(name)    __CONCAT(X,name)
151
152 extern u_long *intr_countp[];   /* pointers into intrcnt[] */
153 extern inthand2_t *intr_handler[];      /* C entry points for FAST ints */
154 extern u_int intr_mask[];       /* sets of intrs masked during handling of 1 */
155 extern void *intr_unit[];       /* cookies to pass to intr handlers */
156
157 inthand_t
158         IDTVEC(fastintr0), IDTVEC(fastintr1),
159         IDTVEC(fastintr2), IDTVEC(fastintr3),
160         IDTVEC(fastintr4), IDTVEC(fastintr5),
161         IDTVEC(fastintr6), IDTVEC(fastintr7),
162         IDTVEC(fastintr8), IDTVEC(fastintr9),
163         IDTVEC(fastintr10), IDTVEC(fastintr11),
164         IDTVEC(fastintr12), IDTVEC(fastintr13),
165         IDTVEC(fastintr14), IDTVEC(fastintr15);
166 inthand_t
167         IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3),
168         IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7),
169         IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11),
170         IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15);
171
172 unpendhand_t
173         IDTVEC(fastunpend0), IDTVEC(fastunpend1),
174         IDTVEC(fastunpend2), IDTVEC(fastunpend3),
175         IDTVEC(fastunpend4), IDTVEC(fastunpend5),
176         IDTVEC(fastunpend6), IDTVEC(fastunpend7),
177         IDTVEC(fastunpend8), IDTVEC(fastunpend9),
178         IDTVEC(fastunpend10), IDTVEC(fastunpend11),
179         IDTVEC(fastunpend12), IDTVEC(fastunpend13),
180         IDTVEC(fastunpend14), IDTVEC(fastunpend15);
181
182 #if defined(APIC_IO)
183 inthand_t
184         IDTVEC(fastintr16), IDTVEC(fastintr17),
185         IDTVEC(fastintr18), IDTVEC(fastintr19),
186         IDTVEC(fastintr20), IDTVEC(fastintr21),
187         IDTVEC(fastintr22), IDTVEC(fastintr23);
188 inthand_t
189         IDTVEC(intr16), IDTVEC(intr17), IDTVEC(intr18), IDTVEC(intr19),
190         IDTVEC(intr20), IDTVEC(intr21), IDTVEC(intr22), IDTVEC(intr23);
191 unpendhand_t
192         IDTVEC(fastunpend16), IDTVEC(fastunpend17),
193         IDTVEC(fastunpend18), IDTVEC(fastunpend19),
194         IDTVEC(fastunpend20), IDTVEC(fastunpend21),
195         IDTVEC(fastunpend22), IDTVEC(fastunpend23);
196 #endif
197
198 #if defined(SMP)
199 inthand_t
200         Xinvltlb,       /* TLB shootdowns */
201 #ifdef BETTER_CLOCK
202         Xcpucheckstate, /* Check cpu state */
203 #endif
204         Xcpuast,        /* Additional software trap on other cpu */ 
205         Xforward_irq,   /* Forward irq to cpu holding ISR lock */
206         Xcpustop,       /* CPU stops & waits for another CPU to restart it */
207         Xspuriousint,   /* handle APIC "spurious INTs" */
208         Xrendezvous;    /* handle CPU rendezvous */
209
210 #ifdef TEST_TEST1
211 inthand_t
212         Xtest1;         /* 'fake' HWI at top of APIC prio 0x3x, 32+31 = 0x3f */
213 #endif /** TEST_TEST1 */
214 #endif /* SMP */
215
216 void    call_fast_unpend(int irq);
217 void    isa_defaultirq __P((void));
218 int     isa_nmi __P((int cd));
219 int     icu_setup __P((int intr, inthand2_t *func, void *arg, 
220                        u_int *maskptr, int flags));
221 int     icu_unset __P((int intr, inthand2_t *handler));
222 int     update_intr_masks __P((void));
223
224 intrmask_t splq __P((intrmask_t mask));
225
226 #define INTR_FAST               0x00000001 /* fast interrupt handler */
227 #define INTR_EXCL               0x00010000 /* excl. intr, default is shared */
228
229 /*
230  * WARNING: These are internal functions and not to be used by device drivers!
231  * They are subject to change without notice. 
232  */
233 struct intrec *inthand_add(const char *name, int irq, inthand2_t handler,
234                            void *arg, intrmask_t *maskptr, int flags);
235
236 int inthand_remove(struct intrec *idesc);
237
238 #endif /* LOCORE */
239
240 #endif /* _KERNEL */
241
242 #endif /* !_I386_ISA_INTR_MACHDEP_H_ */