pci_6600.c revision 1.1.6.1 1 1.1.6.1 bouyer /* $NetBSD: pci_6600.c,v 1.1.6.1 2000/11/20 19:57:13 bouyer Exp $ */
2 1.1 ross
3 1.1 ross /*-
4 1.1 ross * Copyright (c) 1999 by Ross Harvey. All rights reserved.
5 1.1 ross *
6 1.1 ross * Redistribution and use in source and binary forms, with or without
7 1.1 ross * modification, are permitted provided that the following conditions
8 1.1 ross * are met:
9 1.1 ross * 1. Redistributions of source code must retain the above copyright
10 1.1 ross * notice, this list of conditions and the following disclaimer.
11 1.1 ross * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 ross * notice, this list of conditions and the following disclaimer in the
13 1.1 ross * documentation and/or other materials provided with the distribution.
14 1.1 ross * 3. All advertising materials mentioning features or use of this software
15 1.1 ross * must display the following acknowledgement:
16 1.1 ross * This product includes software developed by Ross Harvey.
17 1.1 ross * 4. The name of Ross Harvey may not be used to endorse or promote products
18 1.1 ross * derived from this software without specific prior written permission.
19 1.1 ross *
20 1.1 ross * THIS SOFTWARE IS PROVIDED BY ROSS HARVEY ``AS IS'' AND ANY EXPRESS
21 1.1 ross * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 1.1 ross * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP0SE
23 1.1 ross * ARE DISCLAIMED. IN NO EVENT SHALL ROSS HARVEY BE LIABLE FOR ANY
24 1.1 ross * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.1 ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.1 ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.1 ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.1 ross * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1 ross * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1 ross * SUCH DAMAGE.
31 1.1 ross *
32 1.1 ross */
33 1.1 ross
34 1.1 ross #include <sys/cdefs.h>
35 1.1 ross
36 1.1.6.1 bouyer __KERNEL_RCSID(0, "$NetBSD: pci_6600.c,v 1.1.6.1 2000/11/20 19:57:13 bouyer Exp $");
37 1.1 ross
38 1.1 ross #include <sys/param.h>
39 1.1 ross #include <sys/systm.h>
40 1.1 ross #include <sys/kernel.h>
41 1.1 ross #include <sys/device.h>
42 1.1 ross #include <sys/malloc.h>
43 1.1.6.1 bouyer
44 1.1.6.1 bouyer #include <uvm/uvm_extern.h>
45 1.1 ross
46 1.1 ross #include <machine/autoconf.h>
47 1.1 ross #define _ALPHA_BUS_DMA_PRIVATE
48 1.1 ross #include <machine/bus.h>
49 1.1 ross #include <machine/rpb.h>
50 1.1 ross #include <machine/alpha.h>
51 1.1 ross
52 1.1 ross #include <dev/pci/pcireg.h>
53 1.1 ross #include <dev/pci/pcivar.h>
54 1.1 ross #include <dev/pci/pciidereg.h>
55 1.1 ross #include <dev/pci/pciidevar.h>
56 1.1 ross
57 1.1 ross #include <alpha/pci/tsreg.h>
58 1.1 ross #include <alpha/pci/tsvar.h>
59 1.1 ross #include <alpha/pci/pci_6600.h>
60 1.1 ross
61 1.1 ross #define pci_6600() { Generate ctags(1) key. }
62 1.1 ross
63 1.1 ross #include "sio.h"
64 1.1 ross #if NSIO
65 1.1 ross #include <alpha/pci/siovar.h>
66 1.1 ross #endif
67 1.1 ross
68 1.1.6.1 bouyer #define PCI_NIRQ 64
69 1.1 ross #define PCI_STRAY_MAX 5
70 1.1.6.1 bouyer
71 1.1.6.1 bouyer /*
72 1.1.6.1 bouyer * Some Tsunami models have a PCI device (the USB controller) with interrupts
73 1.1.6.1 bouyer * tied to ISA IRQ lines. The IRQ is encoded as:
74 1.1.6.1 bouyer *
75 1.1.6.1 bouyer * line = 0xe0 | isa_irq;
76 1.1.6.1 bouyer */
77 1.1.6.1 bouyer #define DEC_6600_LINE_IS_ISA(line) ((line) >= 0xe0 && (line) <= 0xef)
78 1.1.6.1 bouyer #define DEC_6600_LINE_ISA_IRQ(line) ((line) & 0x0f)
79 1.1 ross
80 1.1 ross static char *irqtype = "6600 irq";
81 1.1 ross static struct tsp_config *sioprimary;
82 1.1 ross
83 1.1 ross void dec_6600_intr_disestablish __P((void *, void *));
84 1.1 ross void *dec_6600_intr_establish __P((
85 1.1 ross void *, pci_intr_handle_t, int, int (*func)(void *), void *));
86 1.1 ross const char *dec_6600_intr_string __P((void *, pci_intr_handle_t));
87 1.1.6.1 bouyer const struct evcnt *dec_6600_intr_evcnt __P((void *, pci_intr_handle_t));
88 1.1 ross int dec_6600_intr_map __P((void *, pcitag_t, int, int, pci_intr_handle_t *));
89 1.1 ross void *dec_6600_pciide_compat_intr_establish __P((void *, struct device *,
90 1.1 ross struct pci_attach_args *, int, int (*)(void *), void *));
91 1.1 ross
92 1.1 ross struct alpha_shared_intr *dec_6600_pci_intr;
93 1.1 ross
94 1.1 ross void dec_6600_iointr __P((void *framep, unsigned long vec));
95 1.1 ross extern void dec_6600_intr_enable __P((int irq));
96 1.1 ross extern void dec_6600_intr_disable __P((int irq));
97 1.1 ross
98 1.1 ross void
99 1.1 ross pci_6600_pickintr(pcp)
100 1.1 ross struct tsp_config *pcp;
101 1.1 ross {
102 1.1 ross bus_space_tag_t iot = &pcp->pc_iot;
103 1.1 ross pci_chipset_tag_t pc = &pcp->pc_pc;
104 1.1.6.1 bouyer char *cp;
105 1.1 ross int i;
106 1.1 ross
107 1.1 ross pc->pc_intr_v = pcp;
108 1.1 ross pc->pc_intr_map = dec_6600_intr_map;
109 1.1 ross pc->pc_intr_string = dec_6600_intr_string;
110 1.1.6.1 bouyer pc->pc_intr_evcnt = dec_6600_intr_evcnt;
111 1.1 ross pc->pc_intr_establish = dec_6600_intr_establish;
112 1.1 ross pc->pc_intr_disestablish = dec_6600_intr_disestablish;
113 1.1 ross pc->pc_pciide_compat_intr_establish = NULL;
114 1.1 ross
115 1.1 ross /*
116 1.1 ross * System-wide and Pchip-0-only logic...
117 1.1 ross */
118 1.1 ross if (dec_6600_pci_intr == NULL) {
119 1.1 ross sioprimary = pcp;
120 1.1 ross pc->pc_pciide_compat_intr_establish =
121 1.1 ross dec_6600_pciide_compat_intr_establish;
122 1.1.6.1 bouyer dec_6600_pci_intr = alpha_shared_intr_alloc(PCI_NIRQ, 8);
123 1.1.6.1 bouyer for (i = 0; i < PCI_NIRQ; i++) {
124 1.1 ross alpha_shared_intr_set_maxstrays(dec_6600_pci_intr, i,
125 1.1 ross PCI_STRAY_MAX);
126 1.1.6.1 bouyer alpha_shared_intr_set_private(dec_6600_pci_intr, i,
127 1.1.6.1 bouyer sioprimary);
128 1.1.6.1 bouyer
129 1.1.6.1 bouyer cp = alpha_shared_intr_string(dec_6600_pci_intr, i);
130 1.1.6.1 bouyer sprintf(cp, "irq %d", i);
131 1.1.6.1 bouyer evcnt_attach_dynamic(alpha_shared_intr_evcnt(
132 1.1.6.1 bouyer dec_6600_pci_intr, 1), EVCNT_TYPE_INTR, NULL,
133 1.1.6.1 bouyer "dec_6600", cp);
134 1.1.6.1 bouyer }
135 1.1 ross #if NSIO
136 1.1 ross sio_intr_setup(pc, iot);
137 1.1 ross dec_6600_intr_enable(55); /* irq line for sio */
138 1.1 ross #endif
139 1.1 ross set_iointr(dec_6600_iointr);
140 1.1 ross }
141 1.1 ross }
142 1.1 ross
143 1.1 ross int
144 1.1 ross dec_6600_intr_map(acv, bustag, buspin, line, ihp)
145 1.1 ross void *acv;
146 1.1 ross pcitag_t bustag;
147 1.1 ross int buspin, line;
148 1.1 ross pci_intr_handle_t *ihp;
149 1.1 ross {
150 1.1 ross struct tsp_config *pcp = acv;
151 1.1 ross pci_chipset_tag_t pc = &pcp->pc_pc;
152 1.1 ross int bus, device, function;
153 1.1 ross
154 1.1 ross if (buspin == 0) {
155 1.1 ross /* No IRQ used. */
156 1.1 ross return 1;
157 1.1 ross }
158 1.1 ross if (buspin > 4) {
159 1.1 ross printf("intr_map: bad interrupt pin %d\n", buspin);
160 1.1 ross return 1;
161 1.1 ross }
162 1.1 ross
163 1.1.6.1 bouyer alpha_pci_decompose_tag(pc, bustag, &bus, &device, &function);
164 1.1.6.1 bouyer
165 1.1 ross /*
166 1.1 ross * The console places the interrupt mapping in the "line" value.
167 1.1 ross * A value of (char)-1 indicates there is no mapping.
168 1.1 ross */
169 1.1.6.1 bouyer if (line == 0xff) {
170 1.1.6.1 bouyer printf("dec_6600_intr_map: no mapping for %d/%d/%d\n",
171 1.1.6.1 bouyer bus, device, function);
172 1.1.6.1 bouyer return (1);
173 1.1.6.1 bouyer }
174 1.1.6.1 bouyer
175 1.1.6.1 bouyer #if NSIO == 0
176 1.1.6.1 bouyer if (DEC_6600_LINE_IS_ISA(line)) {
177 1.1.6.1 bouyer printf("dec_6600_intr_map: ISA IRQ %d for %d/%d/%d\n",
178 1.1.6.1 bouyer DEC_6600_LINE_ISA_IRQ(line), bus, device, function);
179 1.1 ross return (1);
180 1.1 ross }
181 1.1.6.1 bouyer #endif
182 1.1 ross
183 1.1.6.1 bouyer if (DEC_6600_LINE_IS_ISA(line) == 0 && line >= PCI_NIRQ)
184 1.1.6.1 bouyer panic("dec_6600_intr_map: dec 6600 irq too large (%d)\n",
185 1.1.6.1 bouyer line);
186 1.1 ross
187 1.1 ross *ihp = line;
188 1.1 ross return (0);
189 1.1 ross }
190 1.1 ross
191 1.1.6.1 bouyer const char *
192 1.1.6.1 bouyer dec_6600_intr_string(acv, ih)
193 1.1.6.1 bouyer void *acv;
194 1.1 ross pci_intr_handle_t ih;
195 1.1 ross {
196 1.1.6.1 bouyer
197 1.1.6.1 bouyer static const char irqfmt[] = "dec 6600 irq %ld";
198 1.1.6.1 bouyer static char irqstr[sizeof irqfmt];
199 1.1.6.1 bouyer
200 1.1.6.1 bouyer #if NSIO
201 1.1.6.1 bouyer if (DEC_6600_LINE_IS_ISA(ih))
202 1.1.6.1 bouyer return (sio_intr_string(NULL /*XXX*/,
203 1.1.6.1 bouyer DEC_6600_LINE_ISA_IRQ(ih)));
204 1.1.6.1 bouyer #endif
205 1.1.6.1 bouyer
206 1.1.6.1 bouyer snprintf(irqstr, sizeof irqstr, irqfmt, ih);
207 1.1.6.1 bouyer return (irqstr);
208 1.1 ross }
209 1.1 ross
210 1.1.6.1 bouyer const struct evcnt *
211 1.1.6.1 bouyer dec_6600_intr_evcnt(acv, ih)
212 1.1 ross void *acv;
213 1.1 ross pci_intr_handle_t ih;
214 1.1 ross {
215 1.1 ross
216 1.1.6.1 bouyer #if NSIO
217 1.1.6.1 bouyer if (DEC_6600_LINE_IS_ISA(ih))
218 1.1.6.1 bouyer return (sio_intr_evcnt(NULL /*XXX*/,
219 1.1.6.1 bouyer DEC_6600_LINE_ISA_IRQ(ih)));
220 1.1.6.1 bouyer #endif
221 1.1 ross
222 1.1.6.1 bouyer return (alpha_shared_intr_evcnt(dec_6600_pci_intr, ih));
223 1.1 ross }
224 1.1 ross
225 1.1 ross void *
226 1.1 ross dec_6600_intr_establish(acv, ih, level, func, arg)
227 1.1 ross void *acv, *arg;
228 1.1 ross pci_intr_handle_t ih;
229 1.1 ross int level;
230 1.1 ross int (*func) __P((void *));
231 1.1 ross {
232 1.1 ross void *cookie;
233 1.1 ross
234 1.1.6.1 bouyer #if NSIO
235 1.1.6.1 bouyer if (DEC_6600_LINE_IS_ISA(ih))
236 1.1.6.1 bouyer return (sio_intr_establish(NULL /*XXX*/,
237 1.1.6.1 bouyer DEC_6600_LINE_ISA_IRQ(ih), IST_LEVEL, level, func, arg));
238 1.1.6.1 bouyer #endif
239 1.1.6.1 bouyer
240 1.1.6.1 bouyer if (ih >= PCI_NIRQ)
241 1.1.6.1 bouyer panic("dec_6600_intr_establish: bogus dec 6600 IRQ 0x%lx\n",
242 1.1.6.1 bouyer ih);
243 1.1.6.1 bouyer
244 1.1 ross cookie = alpha_shared_intr_establish(dec_6600_pci_intr, ih, IST_LEVEL,
245 1.1 ross level, func, arg, irqtype);
246 1.1 ross
247 1.1 ross if (cookie != NULL && alpha_shared_intr_isactive(dec_6600_pci_intr, ih))
248 1.1 ross dec_6600_intr_enable(ih);
249 1.1 ross return (cookie);
250 1.1 ross }
251 1.1 ross
252 1.1 ross void
253 1.1 ross dec_6600_intr_disestablish(acv, cookie)
254 1.1 ross void *acv, *cookie;
255 1.1 ross {
256 1.1 ross struct alpha_shared_intrhand *ih = cookie;
257 1.1 ross unsigned int irq = ih->ih_num;
258 1.1 ross int s;
259 1.1.6.1 bouyer
260 1.1.6.1 bouyer #if NSIO
261 1.1.6.1 bouyer /*
262 1.1.6.1 bouyer * We have to determine if this is an ISA IRQ or not! We do this
263 1.1.6.1 bouyer * by checking to see if the intrhand points back to an intrhead
264 1.1.6.1 bouyer * that points to the sioprimary TSP. If not, it's an ISA IRQ.
265 1.1.6.1 bouyer * Pretty disgusting, eh?
266 1.1.6.1 bouyer */
267 1.1.6.1 bouyer if (ih->ih_intrhead->intr_private != sioprimary) {
268 1.1.6.1 bouyer sio_intr_disestablish(NULL /*XXX*/, cookie);
269 1.1.6.1 bouyer return;
270 1.1.6.1 bouyer }
271 1.1.6.1 bouyer #endif
272 1.1 ross
273 1.1 ross s = splhigh();
274 1.1 ross
275 1.1 ross alpha_shared_intr_disestablish(dec_6600_pci_intr, cookie, irqtype);
276 1.1 ross if (alpha_shared_intr_isactive(dec_6600_pci_intr, irq) == 0) {
277 1.1 ross dec_6600_intr_disable(irq);
278 1.1 ross alpha_shared_intr_set_dfltsharetype(dec_6600_pci_intr, irq,
279 1.1 ross IST_NONE);
280 1.1 ross }
281 1.1 ross
282 1.1 ross splx(s);
283 1.1 ross }
284 1.1 ross
285 1.1 ross void
286 1.1 ross dec_6600_iointr(framep, vec)
287 1.1 ross void *framep;
288 1.1 ross unsigned long vec;
289 1.1 ross {
290 1.1 ross int irq;
291 1.1 ross
292 1.1 ross if (vec >= 0x900) {
293 1.1 ross irq = (vec - 0x900) >> 4;
294 1.1 ross
295 1.1.6.1 bouyer if (irq >= PCI_NIRQ)
296 1.1 ross panic("iointr: irq %d is too high", irq);
297 1.1 ross
298 1.1 ross if (!alpha_shared_intr_dispatch(dec_6600_pci_intr, irq)) {
299 1.1 ross alpha_shared_intr_stray(dec_6600_pci_intr, irq,
300 1.1 ross irqtype);
301 1.1 ross if (ALPHA_SHARED_INTR_DISABLE(dec_6600_pci_intr, irq))
302 1.1 ross dec_6600_intr_disable(irq);
303 1.1 ross }
304 1.1 ross return;
305 1.1 ross }
306 1.1 ross #if NSIO
307 1.1 ross if (vec >= 0x800) {
308 1.1 ross sio_iointr(framep, vec);
309 1.1 ross return;
310 1.1 ross }
311 1.1 ross #endif
312 1.1 ross panic("iointr: weird vec 0x%lx\n", vec);
313 1.1 ross }
314 1.1 ross
315 1.1 ross void
316 1.1 ross dec_6600_intr_enable(irq)
317 1.1 ross int irq;
318 1.1 ross {
319 1.1 ross alpha_mb();
320 1.1 ross STQP(TS_C_DIM0) |= 1UL << irq;
321 1.1 ross alpha_mb();
322 1.1 ross }
323 1.1 ross
324 1.1 ross void
325 1.1 ross dec_6600_intr_disable(irq)
326 1.1 ross int irq;
327 1.1 ross {
328 1.1 ross alpha_mb();
329 1.1 ross STQP(TS_C_DIM0) &= ~(1UL << irq);
330 1.1 ross alpha_mb();
331 1.1 ross }
332 1.1 ross
333 1.1 ross void *
334 1.1 ross dec_6600_pciide_compat_intr_establish(v, dev, pa, chan, func, arg)
335 1.1 ross void *v;
336 1.1 ross struct device *dev;
337 1.1 ross struct pci_attach_args *pa;
338 1.1 ross int chan;
339 1.1 ross int (*func) __P((void *));
340 1.1 ross void *arg;
341 1.1 ross {
342 1.1 ross pci_chipset_tag_t pc = pa->pa_pc;
343 1.1 ross void *cookie = NULL;
344 1.1 ross int bus, irq;
345 1.1 ross
346 1.1 ross alpha_pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
347 1.1 ross
348 1.1.6.1 bouyer /*
349 1.1.6.1 bouyer * If this isn't PCI bus #0 on the TSP that holds the PCI-ISA
350 1.1.6.1 bouyer * bridge, all bets are off.
351 1.1.6.1 bouyer */
352 1.1 ross if (bus != 0 || pc->pc_intr_v != sioprimary)
353 1.1.6.1 bouyer return (NULL);
354 1.1 ross
355 1.1 ross irq = PCIIDE_COMPAT_IRQ(chan);
356 1.1 ross #if NSIO
357 1.1 ross cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
358 1.1 ross func, arg);
359 1.1.6.1 bouyer if (cookie == NULL)
360 1.1.6.1 bouyer return (NULL);
361 1.1.6.1 bouyer printf("%s: %s channel interrupting at %s\n", dev->dv_xname,
362 1.1.6.1 bouyer PCIIDE_CHANNEL_NAME(chan), sio_intr_string(NULL /*XXX*/, irq));
363 1.1 ross #endif
364 1.1 ross return (cookie);
365 1.1 ross }
366