ICU/APIC cleanup part 7/many.
[dragonfly.git] / sys / i386 / icu / icu_abi.c
1 /*
2  * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
3  * Copyright (c) 1991 The Regents of the University of California.
4  * All rights reserved.
5  * 
6  * This code is derived from software contributed to The DragonFly Project
7  * by Matthew Dillon <dillon@backplane.com>
8  *
9  * This code is derived from software contributed to Berkeley by
10  * William Jolitz.
11  * 
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in
20  *    the documentation and/or other materials provided with the
21  *    distribution.
22  * 3. Neither the name of The DragonFly Project nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific, prior written permission.
25  * 
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
30  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
32  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  * 
39  * $DragonFly: src/sys/i386/icu/Attic/icu_abi.c,v 1.4 2005/11/02 22:59:44 dillon Exp $
40  */
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 #include <sys/machintr.h>
46 #include <sys/interrupt.h>
47 #include <sys/bus.h>
48
49 #include <machine/segments.h>
50 #include <machine/md_var.h>
51 #include <i386/isa/intr_machdep.h>
52
53 #include "icu.h"
54 #include "icu_ipl.h"
55
56 #ifndef APIC_IO
57
58 extern void ICU_INTREN(int);
59 extern void ICU_INTRDIS(int);
60
61 extern inthand_t
62         IDTVEC(icu_fastintr0), IDTVEC(icu_fastintr1),
63         IDTVEC(icu_fastintr2), IDTVEC(icu_fastintr3),
64         IDTVEC(icu_fastintr4), IDTVEC(icu_fastintr5),
65         IDTVEC(icu_fastintr6), IDTVEC(icu_fastintr7),
66         IDTVEC(icu_fastintr8), IDTVEC(icu_fastintr9),
67         IDTVEC(icu_fastintr10), IDTVEC(icu_fastintr11),
68         IDTVEC(icu_fastintr12), IDTVEC(icu_fastintr13),
69         IDTVEC(icu_fastintr14), IDTVEC(icu_fastintr15);
70
71 extern inthand_t
72         IDTVEC(icu_slowintr0), IDTVEC(icu_slowintr1),
73         IDTVEC(icu_slowintr2), IDTVEC(icu_slowintr3),
74         IDTVEC(icu_slowintr4), IDTVEC(icu_slowintr5),
75         IDTVEC(icu_slowintr6), IDTVEC(icu_slowintr7),
76         IDTVEC(icu_slowintr8), IDTVEC(icu_slowintr9),
77         IDTVEC(icu_slowintr10), IDTVEC(icu_slowintr11),
78         IDTVEC(icu_slowintr12), IDTVEC(icu_slowintr13),
79         IDTVEC(icu_slowintr14), IDTVEC(icu_slowintr15);
80
81 extern unpendhand_t
82         IDTVEC(fastunpend0), IDTVEC(fastunpend1),
83         IDTVEC(fastunpend2), IDTVEC(fastunpend3),
84         IDTVEC(fastunpend4), IDTVEC(fastunpend5),
85         IDTVEC(fastunpend6), IDTVEC(fastunpend7),
86         IDTVEC(fastunpend8), IDTVEC(fastunpend9),
87         IDTVEC(fastunpend10), IDTVEC(fastunpend11),
88         IDTVEC(fastunpend12), IDTVEC(fastunpend13),
89         IDTVEC(fastunpend14), IDTVEC(fastunpend15);
90
91 static int icu_vectorctl(int, int, int);
92 static int icu_setvar(int, const void *);
93 static int icu_getvar(int, void *);
94 static void icu_finalize(void);
95
96 static inthand_t *icu_fastintr[ICU_HWI_VECTORS] = {
97         &IDTVEC(icu_fastintr0), &IDTVEC(icu_fastintr1),
98         &IDTVEC(icu_fastintr2), &IDTVEC(icu_fastintr3),
99         &IDTVEC(icu_fastintr4), &IDTVEC(icu_fastintr5),
100         &IDTVEC(icu_fastintr6), &IDTVEC(icu_fastintr7),
101         &IDTVEC(icu_fastintr8), &IDTVEC(icu_fastintr9),
102         &IDTVEC(icu_fastintr10), &IDTVEC(icu_fastintr11),
103         &IDTVEC(icu_fastintr12), &IDTVEC(icu_fastintr13),
104         &IDTVEC(icu_fastintr14), &IDTVEC(icu_fastintr15)
105 };
106
107 unpendhand_t *fastunpend[ICU_HWI_VECTORS] = {
108         IDTVEC(fastunpend0), IDTVEC(fastunpend1),
109         IDTVEC(fastunpend2), IDTVEC(fastunpend3),
110         IDTVEC(fastunpend4), IDTVEC(fastunpend5),
111         IDTVEC(fastunpend6), IDTVEC(fastunpend7),
112         IDTVEC(fastunpend8), IDTVEC(fastunpend9),
113         IDTVEC(fastunpend10), IDTVEC(fastunpend11),
114         IDTVEC(fastunpend12), IDTVEC(fastunpend13),
115         IDTVEC(fastunpend14), IDTVEC(fastunpend15)
116 };
117
118 static inthand_t *icu_slowintr[ICU_HWI_VECTORS] = {
119         &IDTVEC(icu_slowintr0), &IDTVEC(icu_slowintr1),
120         &IDTVEC(icu_slowintr2), &IDTVEC(icu_slowintr3),
121         &IDTVEC(icu_slowintr4), &IDTVEC(icu_slowintr5),
122         &IDTVEC(icu_slowintr6), &IDTVEC(icu_slowintr7),
123         &IDTVEC(icu_slowintr8), &IDTVEC(icu_slowintr9),
124         &IDTVEC(icu_slowintr10), &IDTVEC(icu_slowintr11),
125         &IDTVEC(icu_slowintr12), &IDTVEC(icu_slowintr13),
126         &IDTVEC(icu_slowintr14), &IDTVEC(icu_slowintr15)
127 };
128
129 struct machintr_abi MachIntrABI = {
130     MACHINTR_ICU,
131     ICU_INTRDIS,
132     ICU_INTREN,
133     icu_vectorctl,
134     icu_setvar,
135     icu_getvar,
136     icu_finalize
137 };
138
139 static 
140 int
141 icu_setvar(int varid __unused, const void *buf __unused)
142 {
143     return (ENOENT);
144 }
145
146 static
147 int
148 icu_getvar(int varid __unused, void *buf __unused)
149 {
150     return (ENOENT);
151 }
152
153 static void
154 icu_finalize(void)
155 {
156     machintr_intren(ICU_IRQ_SLAVE);
157 }
158
159 static
160 int
161 icu_vectorctl(int op, int intr, int flags)
162 {
163     int error;
164     u_long ef;
165
166     if (intr < 0 || intr >= ICU_HWI_VECTORS || intr == ICU_IRQ_SLAVE)
167         return (EINVAL);
168
169     ef = read_eflags();
170     cpu_disable_intr();
171     error = 0;
172
173     switch(op) {
174     case MACHINTR_VECTOR_SETUP:
175         setidt(IDT_OFFSET + intr,
176                 flags & INTR_FAST ? icu_fastintr[intr] : icu_slowintr[intr],
177                 SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
178         machintr_intren(intr);
179         break;
180     case MACHINTR_VECTOR_TEARDOWN:
181         setidt(IDT_OFFSET + intr, icu_slowintr[intr], SDT_SYS386IGT, SEL_KPL,
182                 GSEL(GCODE_SEL, SEL_KPL));
183         machintr_intrdis(intr);
184         break;
185     default:
186         error = EOPNOTSUPP;
187         break;
188     }
189     write_eflags(ef);
190     return (error);
191 }
192
193 #endif