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