i386 - Get completely rid of APIC_IO
[dragonfly.git] / sys / platform / pc32 / icu / icu_abi.c
CommitLineData
06f5be02
MD
1/*
2 * Copyright (c) 2005 The DragonFly Project. All rights reserved.
10ff1029
MD
3 * Copyright (c) 1991 The Regents of the University of California.
4 * All rights reserved.
06f5be02
MD
5 *
6 * This code is derived from software contributed to The DragonFly Project
7 * by Matthew Dillon <dillon@backplane.com>
10ff1029
MD
8 *
9 * This code is derived from software contributed to Berkeley by
10 * William Jolitz.
06f5be02
MD
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 *
d916dbc1 39 * $DragonFly: src/sys/platform/pc32/icu/icu_abi.c,v 1.14 2007/07/07 12:13:47 sephe Exp $
06f5be02
MD
40 */
41
37e7efec
MD
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/kernel.h>
45#include <sys/machintr.h>
10ff1029
MD
46#include <sys/interrupt.h>
47#include <sys/bus.h>
48
49#include <machine/segments.h>
50#include <machine/md_var.h>
a9295349 51#include <machine_base/isa/intr_machdep.h>
0b692e79
MD
52#include <machine/globaldata.h>
53
54#include <sys/thread2.h>
5f456c40
MD
55
56#include "icu.h"
57#include "icu_ipl.h"
37e7efec 58
37e7efec
MD
59extern void ICU_INTREN(int);
60extern void ICU_INTRDIS(int);
61
10ff1029
MD
62extern inthand_t
63 IDTVEC(icu_fastintr0), IDTVEC(icu_fastintr1),
64 IDTVEC(icu_fastintr2), IDTVEC(icu_fastintr3),
65 IDTVEC(icu_fastintr4), IDTVEC(icu_fastintr5),
66 IDTVEC(icu_fastintr6), IDTVEC(icu_fastintr7),
67 IDTVEC(icu_fastintr8), IDTVEC(icu_fastintr9),
68 IDTVEC(icu_fastintr10), IDTVEC(icu_fastintr11),
69 IDTVEC(icu_fastintr12), IDTVEC(icu_fastintr13),
70 IDTVEC(icu_fastintr14), IDTVEC(icu_fastintr15);
71
10ff1029 72static int icu_vectorctl(int, int, int);
37e7efec
MD
73static int icu_setvar(int, const void *);
74static int icu_getvar(int, void *);
75static void icu_finalize(void);
0b692e79 76static void icu_cleanup(void);
37e7efec 77
5f456c40 78static inthand_t *icu_fastintr[ICU_HWI_VECTORS] = {
10ff1029
MD
79 &IDTVEC(icu_fastintr0), &IDTVEC(icu_fastintr1),
80 &IDTVEC(icu_fastintr2), &IDTVEC(icu_fastintr3),
81 &IDTVEC(icu_fastintr4), &IDTVEC(icu_fastintr5),
82 &IDTVEC(icu_fastintr6), &IDTVEC(icu_fastintr7),
83 &IDTVEC(icu_fastintr8), &IDTVEC(icu_fastintr9),
84 &IDTVEC(icu_fastintr10), &IDTVEC(icu_fastintr11),
85 &IDTVEC(icu_fastintr12), &IDTVEC(icu_fastintr13),
86 &IDTVEC(icu_fastintr14), &IDTVEC(icu_fastintr15)
87};
88
79b62055 89struct machintr_abi MachIntrABI_ICU = {
37e7efec 90 MACHINTR_ICU,
0b692e79
MD
91 .intrdis = ICU_INTRDIS,
92 .intren = ICU_INTREN,
93 .vectorctl =icu_vectorctl,
94 .setvar = icu_setvar,
95 .getvar = icu_getvar,
96 .finalize = icu_finalize,
97 .cleanup = icu_cleanup
37e7efec
MD
98};
99
e96ee753
MD
100static int icu_imcr_present;
101
97359a5b
MD
102/*
103 * WARNING! SMP builds can use the ICU now so this code must be MP safe.
104 */
37e7efec
MD
105static
106int
d916dbc1 107icu_setvar(int varid, const void *buf)
37e7efec 108{
e96ee753
MD
109 int error = 0;
110
111 switch(varid) {
112 case MACHINTR_VAR_IMCR_PRESENT:
113 icu_imcr_present = *(const int *)buf;
114 break;
115 default:
116 error = ENOENT;
117 break;
118 }
119 return (error);
37e7efec
MD
120}
121
122static
123int
d916dbc1 124icu_getvar(int varid, void *buf)
37e7efec 125{
e96ee753
MD
126 int error = 0;
127
128 switch(varid) {
129 case MACHINTR_VAR_IMCR_PRESENT:
130 *(int *)buf = icu_imcr_present;
131 break;
132 default:
133 error = ENOENT;
134 break;
135 }
136 return (error);
37e7efec
MD
137}
138
0b692e79
MD
139/*
140 * Called before interrupts are physically enabled
141 */
37e7efec
MD
142static void
143icu_finalize(void)
144{
0b692e79
MD
145 int intr;
146
147 for (intr = 0; intr < ICU_HWI_VECTORS; ++intr) {
148 machintr_intrdis(intr);
149 }
37e7efec 150 machintr_intren(ICU_IRQ_SLAVE);
e96ee753
MD
151
152 /*
153 * If an IMCR is present, programming bit 0 disconnects the 8259
154 * from the BSP. The 8259 may still be connected to LINT0 on the BSP's
155 * LAPIC.
156 *
f4582d09
MD
157 * If we are running SMP the LAPIC is active, try to use virtual wire
158 * mode so we can use other interrupt sources within the LAPIC in
159 * addition to the 8259.
e96ee753
MD
160 */
161 if (icu_imcr_present) {
f4582d09 162#if defined(SMP)
e96ee753
MD
163 outb(0x22, 0x70);
164 outb(0x23, 0x01);
e96ee753
MD
165#endif
166 }
37e7efec
MD
167}
168
0b692e79
MD
169/*
170 * Called after interrupts physically enabled but before the
171 * critical section is released.
172 */
173static
174void
175icu_cleanup(void)
176{
0b692e79 177 mdcpu->gd_fpending = 0;
0b692e79
MD
178}
179
180
10ff1029
MD
181static
182int
183icu_vectorctl(int op, int intr, int flags)
184{
185 int error;
186 u_long ef;
187
5f456c40 188 if (intr < 0 || intr >= ICU_HWI_VECTORS || intr == ICU_IRQ_SLAVE)
10ff1029
MD
189 return (EINVAL);
190
191 ef = read_eflags();
192 cpu_disable_intr();
193 error = 0;
194
195 switch(op) {
196 case MACHINTR_VECTOR_SETUP:
729e15a8
SZ
197 setidt(IDT_OFFSET + intr, icu_fastintr[intr], SDT_SYS386IGT, SEL_KPL,
198 GSEL(GCODE_SEL, SEL_KPL));
10ff1029
MD
199 machintr_intren(intr);
200 break;
201 case MACHINTR_VECTOR_TEARDOWN:
35408d22 202 case MACHINTR_VECTOR_SETDEFAULT:
729e15a8 203 setidt(IDT_OFFSET + intr, icu_fastintr[intr], SDT_SYS386IGT, SEL_KPL,
10ff1029
MD
204 GSEL(GCODE_SEL, SEL_KPL));
205 machintr_intrdis(intr);
206 break;
207 default:
208 error = EOPNOTSUPP;
209 break;
210 }
211 write_eflags(ef);
212 return (error);
213}