malta_intr.c revision 1.3.2.2 1 1.3.2.2 jdolecek /* $NetBSD: malta_intr.c,v 1.3.2.2 2002/06/23 17:35:59 jdolecek Exp $ */
2 1.3.2.2 jdolecek
3 1.3.2.2 jdolecek /*
4 1.3.2.2 jdolecek * Copyright 2001, 2002 Wasabi Systems, Inc.
5 1.3.2.2 jdolecek * All rights reserved.
6 1.3.2.2 jdolecek *
7 1.3.2.2 jdolecek * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
8 1.3.2.2 jdolecek *
9 1.3.2.2 jdolecek * Redistribution and use in source and binary forms, with or without
10 1.3.2.2 jdolecek * modification, are permitted provided that the following conditions
11 1.3.2.2 jdolecek * are met:
12 1.3.2.2 jdolecek * 1. Redistributions of source code must retain the above copyright
13 1.3.2.2 jdolecek * notice, this list of conditions and the following disclaimer.
14 1.3.2.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.2.2 jdolecek * notice, this list of conditions and the following disclaimer in the
16 1.3.2.2 jdolecek * documentation and/or other materials provided with the distribution.
17 1.3.2.2 jdolecek * 3. All advertising materials mentioning features or use of this software
18 1.3.2.2 jdolecek * must display the following acknowledgement:
19 1.3.2.2 jdolecek * This product includes software developed for the NetBSD Project by
20 1.3.2.2 jdolecek * Wasabi Systems, Inc.
21 1.3.2.2 jdolecek * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.3.2.2 jdolecek * or promote products derived from this software without specific prior
23 1.3.2.2 jdolecek * written permission.
24 1.3.2.2 jdolecek *
25 1.3.2.2 jdolecek * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.3.2.2 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.3.2.2 jdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.3.2.2 jdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.3.2.2 jdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.3.2.2 jdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.3.2.2 jdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.3.2.2 jdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.3.2.2 jdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.3.2.2 jdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.3.2.2 jdolecek * POSSIBILITY OF SUCH DAMAGE.
36 1.3.2.2 jdolecek */
37 1.3.2.2 jdolecek
38 1.3.2.2 jdolecek /*
39 1.3.2.2 jdolecek * Platform-specific interrupt support for the MIPS Malta.
40 1.3.2.2 jdolecek */
41 1.3.2.2 jdolecek
42 1.3.2.2 jdolecek
43 1.3.2.2 jdolecek #include <sys/param.h>
44 1.3.2.2 jdolecek #include <sys/device.h>
45 1.3.2.2 jdolecek #include <sys/kernel.h>
46 1.3.2.2 jdolecek #include <sys/malloc.h>
47 1.3.2.2 jdolecek
48 1.3.2.2 jdolecek #include <mips/locore.h>
49 1.3.2.2 jdolecek
50 1.3.2.2 jdolecek #include <evbmips/evbmips/clockvar.h>
51 1.3.2.2 jdolecek
52 1.3.2.2 jdolecek #include <evbmips/malta/maltavar.h>
53 1.3.2.2 jdolecek #include <evbmips/malta/pci/pcibvar.h>
54 1.3.2.2 jdolecek
55 1.3.2.2 jdolecek #include <dev/ic/mc146818reg.h> /* for malta_cal_timer() */
56 1.3.2.2 jdolecek
57 1.3.2.2 jdolecek #include <dev/isa/isavar.h>
58 1.3.2.2 jdolecek #include <dev/pci/pciidereg.h>
59 1.3.2.2 jdolecek
60 1.3.2.2 jdolecek /*
61 1.3.2.2 jdolecek * This is a mask of bits to clear in the SR when we go to a
62 1.3.2.2 jdolecek * given hardware interrupt priority level.
63 1.3.2.2 jdolecek */
64 1.3.2.2 jdolecek const u_int32_t ipl_sr_bits[_IPL_N] = {
65 1.3.2.2 jdolecek 0, /* IPL_NONE */
66 1.3.2.2 jdolecek
67 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_0, /* IPL_SOFT */
68 1.3.2.2 jdolecek
69 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_0, /* IPL_SOFTCLOCK */
70 1.3.2.2 jdolecek
71 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_0|
72 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_1, /* IPL_SOFTNET */
73 1.3.2.2 jdolecek
74 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_0|
75 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_1, /* IPL_SOFTSERIAL */
76 1.3.2.2 jdolecek
77 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_0|
78 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_1|
79 1.3.2.2 jdolecek MIPS_INT_MASK_0, /* IPL_BIO */
80 1.3.2.2 jdolecek
81 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_0|
82 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_1|
83 1.3.2.2 jdolecek MIPS_INT_MASK_0, /* IPL_NET */
84 1.3.2.2 jdolecek
85 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_0|
86 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_1|
87 1.3.2.2 jdolecek MIPS_INT_MASK_0, /* IPL_{TTY,SERIAL} */
88 1.3.2.2 jdolecek
89 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_0|
90 1.3.2.2 jdolecek MIPS_SOFT_INT_MASK_1|
91 1.3.2.2 jdolecek MIPS_INT_MASK_0|
92 1.3.2.2 jdolecek MIPS_INT_MASK_1|
93 1.3.2.2 jdolecek MIPS_INT_MASK_2|
94 1.3.2.2 jdolecek MIPS_INT_MASK_3|
95 1.3.2.2 jdolecek MIPS_INT_MASK_4|
96 1.3.2.2 jdolecek MIPS_INT_MASK_5, /* IPL_{CLOCK,HIGH} */
97 1.3.2.2 jdolecek };
98 1.3.2.2 jdolecek
99 1.3.2.2 jdolecek struct malta_cpuintr {
100 1.3.2.2 jdolecek LIST_HEAD(, evbmips_intrhand) cintr_list;
101 1.3.2.2 jdolecek struct evcnt cintr_count;
102 1.3.2.2 jdolecek };
103 1.3.2.2 jdolecek #define NINTRS 5 /* MIPS INT0 - INT4 */
104 1.3.2.2 jdolecek
105 1.3.2.2 jdolecek struct malta_cpuintr malta_cpuintrs[NINTRS];
106 1.3.2.2 jdolecek const char *malta_cpuintrnames[NINTRS] = {
107 1.3.2.2 jdolecek "int 0 (piix4)",
108 1.3.2.2 jdolecek "int 1 (smi)",
109 1.3.2.2 jdolecek "int 2 (uart)",
110 1.3.2.2 jdolecek "int 3 (core hi/gt64120)",
111 1.3.2.2 jdolecek "int 4 (core lo)",
112 1.3.2.2 jdolecek };
113 1.3.2.2 jdolecek
114 1.3.2.2 jdolecek static int malta_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
115 1.3.2.2 jdolecek static const char
116 1.3.2.2 jdolecek *malta_pci_intr_string(void *, pci_intr_handle_t);
117 1.3.2.2 jdolecek static const struct evcnt
118 1.3.2.2 jdolecek *malta_pci_intr_evcnt(void *, pci_intr_handle_t);
119 1.3.2.2 jdolecek static void *malta_pci_intr_establish(void *, pci_intr_handle_t, int,
120 1.3.2.2 jdolecek int (*)(void *), void *);
121 1.3.2.2 jdolecek static void malta_pci_intr_disestablish(void *, void *);
122 1.3.2.2 jdolecek static void malta_pci_conf_interrupt(void *, int, int, int, int, int *);
123 1.3.2.2 jdolecek static void *malta_pciide_compat_intr_establish(void *, struct device *,
124 1.3.2.2 jdolecek struct pci_attach_args *, int, int (*)(void *), void *);
125 1.3.2.2 jdolecek
126 1.3.2.2 jdolecek void
127 1.3.2.2 jdolecek evbmips_intr_init(void)
128 1.3.2.2 jdolecek {
129 1.3.2.2 jdolecek struct malta_config *mcp = &malta_configuration;
130 1.3.2.2 jdolecek int i;
131 1.3.2.2 jdolecek
132 1.3.2.2 jdolecek for (i = 0; i < NINTRS; i++) {
133 1.3.2.2 jdolecek LIST_INIT(&malta_cpuintrs[i].cintr_list);
134 1.3.2.2 jdolecek evcnt_attach_dynamic(&malta_cpuintrs[i].cintr_count,
135 1.3.2.2 jdolecek EVCNT_TYPE_INTR, NULL, "mips", malta_cpuintrnames[i]);
136 1.3.2.2 jdolecek }
137 1.3.2.2 jdolecek
138 1.3.2.2 jdolecek evcnt_attach_static(&mips_int5_evcnt);
139 1.3.2.2 jdolecek
140 1.3.2.2 jdolecek mcp->mc_pc.pc_intr_v = NULL;
141 1.3.2.2 jdolecek mcp->mc_pc.pc_intr_map = malta_pci_intr_map;
142 1.3.2.2 jdolecek mcp->mc_pc.pc_intr_string = malta_pci_intr_string;
143 1.3.2.2 jdolecek mcp->mc_pc.pc_intr_evcnt = malta_pci_intr_evcnt;
144 1.3.2.2 jdolecek mcp->mc_pc.pc_intr_establish = malta_pci_intr_establish;
145 1.3.2.2 jdolecek mcp->mc_pc.pc_intr_disestablish = malta_pci_intr_disestablish;
146 1.3.2.2 jdolecek mcp->mc_pc.pc_conf_interrupt = malta_pci_conf_interrupt;
147 1.3.2.2 jdolecek mcp->mc_pc.pc_pciide_compat_intr_establish =
148 1.3.2.2 jdolecek malta_pciide_compat_intr_establish;
149 1.3.2.2 jdolecek }
150 1.3.2.2 jdolecek
151 1.3.2.2 jdolecek void
152 1.3.2.2 jdolecek malta_cal_timer(bus_space_tag_t st, bus_space_handle_t sh)
153 1.3.2.2 jdolecek {
154 1.3.2.2 jdolecek u_long ctrdiff[4], startctr, endctr;
155 1.3.2.2 jdolecek u_int8_t regc;
156 1.3.2.2 jdolecek int i;
157 1.3.2.2 jdolecek
158 1.3.2.2 jdolecek /* Disable interrupts first. */
159 1.3.2.2 jdolecek bus_space_write_1(st, sh, 0, MC_REGB);
160 1.3.2.2 jdolecek bus_space_write_1(st, sh, 1, MC_REGB_SQWE | MC_REGB_BINARY |
161 1.3.2.2 jdolecek MC_REGB_24HR);
162 1.3.2.2 jdolecek
163 1.3.2.2 jdolecek /* Initialize for 16Hz. */
164 1.3.2.2 jdolecek bus_space_write_1(st, sh, 0, MC_REGA);
165 1.3.2.2 jdolecek bus_space_write_1(st, sh, 1, MC_BASE_32_KHz | MC_RATE_16_Hz);
166 1.3.2.2 jdolecek
167 1.3.2.2 jdolecek /* Run the loop an extra time to prime the cache. */
168 1.3.2.2 jdolecek for (i = 0; i < 4; i++) {
169 1.3.2.2 jdolecek // led_display('h', 'z', '0' + i, ' ');
170 1.3.2.2 jdolecek
171 1.3.2.2 jdolecek /* Enable the interrupt. */
172 1.3.2.2 jdolecek bus_space_write_1(st, sh, 0, MC_REGB);
173 1.3.2.2 jdolecek bus_space_write_1(st, sh, 1, MC_REGB_PIE | MC_REGB_SQWE |
174 1.3.2.2 jdolecek MC_REGB_BINARY | MC_REGB_24HR);
175 1.3.2.2 jdolecek
176 1.3.2.2 jdolecek /* Go to REGC. */
177 1.3.2.2 jdolecek bus_space_write_1(st, sh, 0, MC_REGC);
178 1.3.2.2 jdolecek
179 1.3.2.2 jdolecek /* Wait for it to happen. */
180 1.3.2.2 jdolecek startctr = mips3_cp0_count_read();
181 1.3.2.2 jdolecek do {
182 1.3.2.2 jdolecek regc = bus_space_read_1(st, sh, 1);
183 1.3.2.2 jdolecek endctr = mips3_cp0_count_read();
184 1.3.2.2 jdolecek } while ((regc & MC_REGC_IRQF) == 0);
185 1.3.2.2 jdolecek
186 1.3.2.2 jdolecek /* Already ACK'd. */
187 1.3.2.2 jdolecek
188 1.3.2.2 jdolecek /* Disable. */
189 1.3.2.2 jdolecek bus_space_write_1(st, sh, 0, MC_REGB);
190 1.3.2.2 jdolecek bus_space_write_1(st, sh, 1, MC_REGB_SQWE | MC_REGB_BINARY |
191 1.3.2.2 jdolecek MC_REGB_24HR);
192 1.3.2.2 jdolecek
193 1.3.2.2 jdolecek ctrdiff[i] = endctr - startctr;
194 1.3.2.2 jdolecek }
195 1.3.2.2 jdolecek
196 1.3.2.2 jdolecek /* Compute the number of cycles per second. */
197 1.3.2.2 jdolecek curcpu()->ci_cpu_freq = ((ctrdiff[2] + ctrdiff[3]) / 2) * 16/*Hz*/;
198 1.3.2.2 jdolecek
199 1.3.2.2 jdolecek /* Compute the number of ticks for hz. */
200 1.3.2.2 jdolecek curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
201 1.3.2.2 jdolecek
202 1.3.2.2 jdolecek /* Compute the delay divisor and reciprical. */
203 1.3.2.2 jdolecek curcpu()->ci_divisor_delay =
204 1.3.2.2 jdolecek ((curcpu()->ci_cpu_freq + 500000) / 1000000);
205 1.3.2.2 jdolecek MIPS_SET_CI_RECIPRICAL(curcpu());
206 1.3.2.2 jdolecek
207 1.3.2.2 jdolecek /*
208 1.3.2.2 jdolecek * Get correct cpu frequency if the CPU runs at twice the
209 1.3.2.2 jdolecek * external/cp0-count frequency.
210 1.3.2.2 jdolecek */
211 1.3.2.2 jdolecek if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
212 1.3.2.2 jdolecek curcpu()->ci_cpu_freq *= 2;
213 1.3.2.2 jdolecek
214 1.3.2.2 jdolecek #ifdef DEBUG
215 1.3.2.2 jdolecek printf("Timer calibration: %lu cycles/sec [(%lu, %lu) * 16]\n",
216 1.3.2.2 jdolecek curcpu()->ci_cpu_freq, ctrdiff[2], ctrdiff[3]);
217 1.3.2.2 jdolecek #endif
218 1.3.2.2 jdolecek }
219 1.3.2.2 jdolecek
220 1.3.2.2 jdolecek void *
221 1.3.2.2 jdolecek evbmips_intr_establish(int irq, int (*func)(void *), void *arg)
222 1.3.2.2 jdolecek {
223 1.3.2.2 jdolecek struct evbmips_intrhand *ih;
224 1.3.2.2 jdolecek int s;
225 1.3.2.2 jdolecek
226 1.3.2.2 jdolecek ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
227 1.3.2.2 jdolecek if (ih == NULL)
228 1.3.2.2 jdolecek return (NULL);
229 1.3.2.2 jdolecek
230 1.3.2.2 jdolecek ih->ih_func = func;
231 1.3.2.2 jdolecek ih->ih_arg = arg;
232 1.3.2.2 jdolecek
233 1.3.2.2 jdolecek s = splhigh();
234 1.3.2.2 jdolecek
235 1.3.2.2 jdolecek /*
236 1.3.2.2 jdolecek * Link it into the tables.
237 1.3.2.2 jdolecek */
238 1.3.2.2 jdolecek LIST_INSERT_HEAD(&malta_cpuintrs[0].cintr_list, ih, ih_q);
239 1.3.2.2 jdolecek
240 1.3.2.2 jdolecek /* XXX - should check that MIPS_INT_MASK_0 is set... */
241 1.3.2.2 jdolecek
242 1.3.2.2 jdolecek splx(s);
243 1.3.2.2 jdolecek
244 1.3.2.2 jdolecek return (ih);
245 1.3.2.2 jdolecek }
246 1.3.2.2 jdolecek
247 1.3.2.2 jdolecek void
248 1.3.2.2 jdolecek evbmips_intr_disestablish(void *arg)
249 1.3.2.2 jdolecek {
250 1.3.2.2 jdolecek struct evbmips_intrhand *ih = arg;
251 1.3.2.2 jdolecek int s;
252 1.3.2.2 jdolecek
253 1.3.2.2 jdolecek s = splhigh();
254 1.3.2.2 jdolecek
255 1.3.2.2 jdolecek /*
256 1.3.2.2 jdolecek * First, remove it from the table.
257 1.3.2.2 jdolecek */
258 1.3.2.2 jdolecek LIST_REMOVE(ih, ih_q);
259 1.3.2.2 jdolecek
260 1.3.2.2 jdolecek /* XXX - disable MIPS_INT_MASK_0 if list is empty? */
261 1.3.2.2 jdolecek
262 1.3.2.2 jdolecek splx(s);
263 1.3.2.2 jdolecek
264 1.3.2.2 jdolecek free(ih, M_DEVBUF);
265 1.3.2.2 jdolecek }
266 1.3.2.2 jdolecek
267 1.3.2.2 jdolecek void
268 1.3.2.2 jdolecek evbmips_iointr(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
269 1.3.2.2 jdolecek {
270 1.3.2.2 jdolecek struct evbmips_intrhand *ih;
271 1.3.2.2 jdolecek
272 1.3.2.2 jdolecek /* Check for error interrupts (SMI, GT62140) */
273 1.3.2.2 jdolecek if (ipending & (MIPS_INT_MASK_1 | MIPS_INT_MASK_3)) {
274 1.3.2.2 jdolecek if (ipending & MIPS_INT_MASK_1)
275 1.3.2.2 jdolecek panic("piix4 SMI interrupt");
276 1.3.2.2 jdolecek if (ipending & MIPS_INT_MASK_3)
277 1.3.2.2 jdolecek panic("gt62140 error interrupt");
278 1.3.2.2 jdolecek }
279 1.3.2.2 jdolecek
280 1.3.2.2 jdolecek /*
281 1.3.2.2 jdolecek * Read the interrupt pending registers, mask them with the
282 1.3.2.2 jdolecek * ones we have enabled, and service them in order of decreasing
283 1.3.2.2 jdolecek * priority.
284 1.3.2.2 jdolecek */
285 1.3.2.2 jdolecek if (ipending & MIPS_INT_MASK_0) {
286 1.3.2.2 jdolecek /* All interrupts are gated through MIPS HW interrupt 0 */
287 1.3.2.2 jdolecek malta_cpuintrs[0].cintr_count.ev_count++;
288 1.3.2.2 jdolecek LIST_FOREACH(ih, &malta_cpuintrs[0].cintr_list, ih_q)
289 1.3.2.2 jdolecek (*ih->ih_func)(ih->ih_arg);
290 1.3.2.2 jdolecek cause &= ~MIPS_INT_MASK_0;
291 1.3.2.2 jdolecek }
292 1.3.2.2 jdolecek
293 1.3.2.2 jdolecek /* Re-enable anything that we have processed. */
294 1.3.2.2 jdolecek _splset(MIPS_SR_INT_IE | ((status & ~cause) & MIPS_HARD_INT_MASK));
295 1.3.2.2 jdolecek }
296 1.3.2.2 jdolecek
297 1.3.2.2 jdolecek /*
298 1.3.2.2 jdolecek * YAMON configures pa_intrline correctly (so far), so we trust it to DTRT
299 1.3.2.2 jdolecek * in the future...
300 1.3.2.2 jdolecek */
301 1.3.2.2 jdolecek #undef YAMON_IRQ_MAP_BAD
302 1.3.2.2 jdolecek
303 1.3.2.2 jdolecek /*
304 1.3.2.2 jdolecek * PCI interrupt support
305 1.3.2.2 jdolecek */
306 1.3.2.2 jdolecek static int
307 1.3.2.2 jdolecek malta_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
308 1.3.2.2 jdolecek {
309 1.3.2.2 jdolecek #ifdef YAMON_IRQ_MAP_BAD
310 1.3.2.2 jdolecek static const int pciirqmap[13/*device*/][4/*pin*/] = {
311 1.3.2.2 jdolecek { -1, -1, -1, 11 }, /* 10: USB */
312 1.3.2.2 jdolecek { 10, -1, -1, -1 }, /* 11: Ethernet */
313 1.3.2.2 jdolecek { 11, -1, -1, -1 }, /* 12: Audio */
314 1.3.2.2 jdolecek { -1, -1, -1, -1 }, /* 13: not used */
315 1.3.2.2 jdolecek { -1, -1, -1, -1 }, /* 14: not used */
316 1.3.2.2 jdolecek { -1, -1, -1, -1 }, /* 15: not used */
317 1.3.2.2 jdolecek { -1, -1, -1, -1 }, /* 16: not used */
318 1.3.2.2 jdolecek { -1, -1, -1, -1 }, /* 17: Core card(?) */
319 1.3.2.2 jdolecek { 10, 10, 11, 11 }, /* 18: PCI Slot 1 */
320 1.3.2.2 jdolecek { 10, 11, 11, 10 }, /* 19: PCI Slot 2 */
321 1.3.2.2 jdolecek { 11, 11, 10, 10 }, /* 20: PCI Slot 3 */
322 1.3.2.2 jdolecek { 11, 10, 10, 11 }, /* 21: PCI Slot 4 */
323 1.3.2.2 jdolecek };
324 1.3.2.2 jdolecek int buspin, device, irq;
325 1.3.2.2 jdolecek #else /* !YAMON_IRQ_MAP_BAD */
326 1.3.2.2 jdolecek int buspin;
327 1.3.2.2 jdolecek #endif /* !YAMON_IRQ_MAP_BAD */
328 1.3.2.2 jdolecek
329 1.3.2.2 jdolecek buspin = pa->pa_intrpin;
330 1.3.2.2 jdolecek
331 1.3.2.2 jdolecek if (buspin == 0) {
332 1.3.2.2 jdolecek /* No IRQ used. */
333 1.3.2.2 jdolecek return (1);
334 1.3.2.2 jdolecek }
335 1.3.2.2 jdolecek
336 1.3.2.2 jdolecek if (buspin > 4) {
337 1.3.2.2 jdolecek printf("malta_pci_intr_map: bad interrupt pin %d\n", buspin);
338 1.3.2.2 jdolecek return (1);
339 1.3.2.2 jdolecek }
340 1.3.2.2 jdolecek
341 1.3.2.2 jdolecek #ifdef YAMON_IRQ_MAP_BAD
342 1.3.2.2 jdolecek pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &device, NULL);
343 1.3.2.2 jdolecek
344 1.3.2.2 jdolecek if (device < 10 || device > 21) {
345 1.3.2.2 jdolecek printf("malta_pci_intr_map: bad device %d\n", device);
346 1.3.2.2 jdolecek return (1);
347 1.3.2.2 jdolecek }
348 1.3.2.2 jdolecek
349 1.3.2.2 jdolecek irq = pciirqmap[device - 10][buspin - 1];
350 1.3.2.2 jdolecek if (irq == -1) {
351 1.3.2.2 jdolecek printf("malta_pci_intr_map: no mapping for device %d pin %d\n",
352 1.3.2.2 jdolecek device, buspin);
353 1.3.2.2 jdolecek return (1);
354 1.3.2.2 jdolecek }
355 1.3.2.2 jdolecek
356 1.3.2.2 jdolecek *ihp = irq;
357 1.3.2.2 jdolecek #else /* !YAMON_IRQ_MAP_BAD */
358 1.3.2.2 jdolecek *ihp = pa->pa_intrline;
359 1.3.2.2 jdolecek #endif /* !YAMON_IRQ_MAP_BAD */
360 1.3.2.2 jdolecek return (0);
361 1.3.2.2 jdolecek }
362 1.3.2.2 jdolecek
363 1.3.2.2 jdolecek static const char *
364 1.3.2.2 jdolecek malta_pci_intr_string(void *v, pci_intr_handle_t irq)
365 1.3.2.2 jdolecek {
366 1.3.2.2 jdolecek
367 1.3.2.2 jdolecek return (isa_intr_string(pcib_ic, irq));
368 1.3.2.2 jdolecek }
369 1.3.2.2 jdolecek
370 1.3.2.2 jdolecek static const struct evcnt *
371 1.3.2.2 jdolecek malta_pci_intr_evcnt(void *v, pci_intr_handle_t irq)
372 1.3.2.2 jdolecek {
373 1.3.2.2 jdolecek
374 1.3.2.2 jdolecek return (isa_intr_evcnt(pcib_ic, irq));
375 1.3.2.2 jdolecek }
376 1.3.2.2 jdolecek
377 1.3.2.2 jdolecek static void *
378 1.3.2.2 jdolecek malta_pci_intr_establish(void *v, pci_intr_handle_t irq, int level,
379 1.3.2.2 jdolecek int (*func)(void *), void *arg)
380 1.3.2.2 jdolecek {
381 1.3.2.2 jdolecek
382 1.3.2.2 jdolecek return (isa_intr_establish(pcib_ic, irq, IST_LEVEL, level, func, arg));
383 1.3.2.2 jdolecek }
384 1.3.2.2 jdolecek
385 1.3.2.2 jdolecek static void
386 1.3.2.2 jdolecek malta_pci_intr_disestablish(void *v, void *arg)
387 1.3.2.2 jdolecek {
388 1.3.2.2 jdolecek
389 1.3.2.2 jdolecek return (isa_intr_disestablish(pcib_ic, arg));
390 1.3.2.2 jdolecek }
391 1.3.2.2 jdolecek
392 1.3.2.2 jdolecek static void
393 1.3.2.2 jdolecek malta_pci_conf_interrupt(void *v, int bus, int dev, int func, int swiz,
394 1.3.2.2 jdolecek int *iline)
395 1.3.2.2 jdolecek {
396 1.3.2.2 jdolecek
397 1.3.2.2 jdolecek /*
398 1.3.2.2 jdolecek * We actually don't need to do anything; everything is handled
399 1.3.2.2 jdolecek * in pci_intr_map().
400 1.3.2.2 jdolecek */
401 1.3.2.2 jdolecek *iline = 0;
402 1.3.2.2 jdolecek }
403 1.3.2.2 jdolecek
404 1.3.2.2 jdolecek void *
405 1.3.2.2 jdolecek malta_pciide_compat_intr_establish(void *v, struct device *dev,
406 1.3.2.2 jdolecek struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
407 1.3.2.2 jdolecek {
408 1.3.2.2 jdolecek pci_chipset_tag_t pc = pa->pa_pc;
409 1.3.2.2 jdolecek void *cookie;
410 1.3.2.2 jdolecek int bus, irq;
411 1.3.2.2 jdolecek
412 1.3.2.2 jdolecek pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
413 1.3.2.2 jdolecek
414 1.3.2.2 jdolecek /*
415 1.3.2.2 jdolecek * If this isn't PCI bus #0, all bets are off.
416 1.3.2.2 jdolecek */
417 1.3.2.2 jdolecek if (bus != 0)
418 1.3.2.2 jdolecek return (NULL);
419 1.3.2.2 jdolecek
420 1.3.2.2 jdolecek irq = PCIIDE_COMPAT_IRQ(chan);
421 1.3.2.2 jdolecek cookie = isa_intr_establish(pcib_ic, irq, IST_EDGE, IPL_BIO, func, arg);
422 1.3.2.2 jdolecek if (cookie == NULL)
423 1.3.2.2 jdolecek return (NULL);
424 1.3.2.2 jdolecek printf("%s: %s channel interrupting at %s\n", dev->dv_xname,
425 1.3.2.2 jdolecek PCIIDE_CHANNEL_NAME(chan), malta_pci_intr_string(v, irq));
426 1.3.2.2 jdolecek return (cookie);
427 1.3.2.2 jdolecek }
428