pci_eb64plus.c revision 1.6 1 1.6 cgd /* $NetBSD: pci_eb64plus.c,v 1.6 2000/06/04 19:14:23 cgd Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 thorpej * NASA Ames Research Center.
10 1.1 thorpej *
11 1.1 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1 thorpej * modification, are permitted provided that the following conditions
13 1.1 thorpej * are met:
14 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1 thorpej * documentation and/or other materials provided with the distribution.
19 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.1 thorpej * must display the following acknowledgement:
21 1.1 thorpej * This product includes software developed by the NetBSD
22 1.1 thorpej * Foundation, Inc. and its contributors.
23 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 thorpej * contributors may be used to endorse or promote products derived
25 1.1 thorpej * from this software without specific prior written permission.
26 1.1 thorpej *
27 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
38 1.1 thorpej */
39 1.1 thorpej
40 1.1 thorpej /*
41 1.1 thorpej * Copyright (c) 1995, 1996 Carnegie-Mellon University.
42 1.1 thorpej * All rights reserved.
43 1.1 thorpej *
44 1.1 thorpej * Author: Chris G. Demetriou
45 1.1 thorpej *
46 1.1 thorpej * Permission to use, copy, modify and distribute this software and
47 1.1 thorpej * its documentation is hereby granted, provided that both the copyright
48 1.1 thorpej * notice and this permission notice appear in all copies of the
49 1.1 thorpej * software, derivative works or modified versions, and any portions
50 1.1 thorpej * thereof, and that both notices appear in supporting documentation.
51 1.1 thorpej *
52 1.1 thorpej * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53 1.1 thorpej * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
54 1.1 thorpej * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55 1.1 thorpej *
56 1.1 thorpej * Carnegie Mellon requests users of this software to return to
57 1.1 thorpej *
58 1.1 thorpej * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
59 1.1 thorpej * School of Computer Science
60 1.1 thorpej * Carnegie Mellon University
61 1.1 thorpej * Pittsburgh PA 15213-3890
62 1.1 thorpej *
63 1.1 thorpej * any improvements or extensions that they make and grant Carnegie the
64 1.1 thorpej * rights to redistribute these changes.
65 1.1 thorpej */
66 1.1 thorpej
67 1.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
68 1.1 thorpej
69 1.6 cgd __KERNEL_RCSID(0, "$NetBSD: pci_eb64plus.c,v 1.6 2000/06/04 19:14:23 cgd Exp $");
70 1.1 thorpej
71 1.1 thorpej #include <sys/types.h>
72 1.1 thorpej #include <sys/param.h>
73 1.1 thorpej #include <sys/time.h>
74 1.1 thorpej #include <sys/systm.h>
75 1.1 thorpej #include <sys/errno.h>
76 1.1 thorpej #include <sys/malloc.h>
77 1.1 thorpej #include <sys/device.h>
78 1.1 thorpej #include <sys/syslog.h>
79 1.1 thorpej
80 1.1 thorpej #include <vm/vm.h>
81 1.1 thorpej
82 1.1 thorpej #include <machine/autoconf.h>
83 1.1 thorpej
84 1.1 thorpej #include <dev/pci/pcireg.h>
85 1.1 thorpej #include <dev/pci/pcivar.h>
86 1.1 thorpej
87 1.1 thorpej #include <alpha/pci/apecsreg.h>
88 1.1 thorpej #include <alpha/pci/apecsvar.h>
89 1.1 thorpej
90 1.1 thorpej #include <alpha/pci/pci_eb64plus.h>
91 1.1 thorpej
92 1.1 thorpej #ifndef EVCNT_COUNTERS
93 1.1 thorpej #include <machine/intrcnt.h>
94 1.1 thorpej #endif
95 1.1 thorpej
96 1.1 thorpej #include "sio.h"
97 1.1 thorpej #if NSIO
98 1.1 thorpej #include <alpha/pci/siovar.h>
99 1.1 thorpej #endif
100 1.1 thorpej
101 1.1 thorpej int dec_eb64plus_intr_map __P((void *, pcitag_t, int, int,
102 1.1 thorpej pci_intr_handle_t *));
103 1.1 thorpej const char *dec_eb64plus_intr_string __P((void *, pci_intr_handle_t));
104 1.6 cgd const struct evcnt *dec_eb64plus_intr_evcnt __P((void *, pci_intr_handle_t));
105 1.1 thorpej void *dec_eb64plus_intr_establish __P((void *, pci_intr_handle_t,
106 1.1 thorpej int, int (*func)(void *), void *));
107 1.1 thorpej void dec_eb64plus_intr_disestablish __P((void *, void *));
108 1.1 thorpej
109 1.1 thorpej #define EB64PLUS_MAX_IRQ 32
110 1.1 thorpej #define PCI_STRAY_MAX 5
111 1.1 thorpej
112 1.1 thorpej struct alpha_shared_intr *eb64plus_pci_intr;
113 1.1 thorpej #ifdef EVCNT_COUNTERS
114 1.1 thorpej struct evcnt eb64plus_intr_evcnt;
115 1.1 thorpej #endif
116 1.1 thorpej
117 1.1 thorpej bus_space_tag_t eb64plus_intrgate_iot;
118 1.1 thorpej bus_space_handle_t eb64plus_intrgate_ioh;
119 1.1 thorpej
120 1.1 thorpej void eb64plus_iointr __P((void *framep, unsigned long vec));
121 1.1 thorpej extern void eb64plus_intr_enable __P((int irq)); /* pci_eb64plus_intr.S */
122 1.1 thorpej extern void eb64plus_intr_disable __P((int irq)); /* pci_eb64plus_intr.S */
123 1.1 thorpej
124 1.1 thorpej void
125 1.1 thorpej pci_eb64plus_pickintr(acp)
126 1.1 thorpej struct apecs_config *acp;
127 1.1 thorpej {
128 1.1 thorpej bus_space_tag_t iot = &acp->ac_iot;
129 1.1 thorpej pci_chipset_tag_t pc = &acp->ac_pc;
130 1.1 thorpej int i;
131 1.1 thorpej
132 1.1 thorpej pc->pc_intr_v = acp;
133 1.1 thorpej pc->pc_intr_map = dec_eb64plus_intr_map;
134 1.1 thorpej pc->pc_intr_string = dec_eb64plus_intr_string;
135 1.6 cgd pc->pc_intr_evcnt = dec_eb64plus_intr_evcnt;
136 1.1 thorpej pc->pc_intr_establish = dec_eb64plus_intr_establish;
137 1.1 thorpej pc->pc_intr_disestablish = dec_eb64plus_intr_disestablish;
138 1.1 thorpej
139 1.1 thorpej /* Not supported on the EB64+. */
140 1.1 thorpej pc->pc_pciide_compat_intr_establish = NULL;
141 1.1 thorpej
142 1.1 thorpej eb64plus_intrgate_iot = iot;
143 1.1 thorpej if (bus_space_map(eb64plus_intrgate_iot, 0x804, 3, 0,
144 1.1 thorpej &eb64plus_intrgate_ioh) != 0)
145 1.1 thorpej panic("pci_eb64plus_pickintr: couldn't map interrupt PLD");
146 1.1 thorpej for (i = 0; i < EB64PLUS_MAX_IRQ; i++)
147 1.1 thorpej eb64plus_intr_disable(i);
148 1.1 thorpej
149 1.1 thorpej eb64plus_pci_intr = alpha_shared_intr_alloc(EB64PLUS_MAX_IRQ);
150 1.1 thorpej for (i = 0; i < EB64PLUS_MAX_IRQ; i++)
151 1.1 thorpej alpha_shared_intr_set_maxstrays(eb64plus_pci_intr, i,
152 1.1 thorpej PCI_STRAY_MAX);
153 1.1 thorpej
154 1.1 thorpej #if NSIO
155 1.1 thorpej sio_intr_setup(pc, iot);
156 1.1 thorpej #endif
157 1.1 thorpej
158 1.1 thorpej set_iointr(eb64plus_iointr);
159 1.1 thorpej }
160 1.1 thorpej
161 1.1 thorpej int
162 1.1 thorpej dec_eb64plus_intr_map(acv, bustag, buspin, line, ihp)
163 1.1 thorpej void *acv;
164 1.1 thorpej pcitag_t bustag;
165 1.1 thorpej int buspin, line;
166 1.1 thorpej pci_intr_handle_t *ihp;
167 1.1 thorpej {
168 1.1 thorpej struct apecs_config *acp = acv;
169 1.1 thorpej pci_chipset_tag_t pc = &acp->ac_pc;
170 1.1 thorpej int bus, device, function;
171 1.1 thorpej
172 1.1 thorpej if (buspin == 0) {
173 1.1 thorpej /* No IRQ used. */
174 1.1 thorpej return 1;
175 1.1 thorpej }
176 1.1 thorpej if (buspin > 4) {
177 1.1 thorpej printf("dec_eb64plus_intr_map: bad interrupt pin %d\n", buspin);
178 1.1 thorpej return 1;
179 1.1 thorpej }
180 1.1 thorpej
181 1.1 thorpej alpha_pci_decompose_tag(pc, bustag, &bus, &device, &function);
182 1.1 thorpej
183 1.1 thorpej /*
184 1.1 thorpej * The console places the interrupt mapping in the "line" value.
185 1.1 thorpej * A value of (char)-1 indicates there is no mapping.
186 1.1 thorpej */
187 1.1 thorpej if (line == 0xff) {
188 1.1 thorpej printf("dec_eb64plus_intr_map: no mapping for %d/%d/%d\n",
189 1.1 thorpej bus, device, function);
190 1.1 thorpej return (1);
191 1.1 thorpej }
192 1.1 thorpej
193 1.1 thorpej if (line >= EB64PLUS_MAX_IRQ)
194 1.1 thorpej panic("dec_eb64plus_intr_map: eb64+ irq too large (%d)\n",
195 1.1 thorpej line);
196 1.1 thorpej
197 1.1 thorpej *ihp = line;
198 1.1 thorpej return (0);
199 1.1 thorpej }
200 1.1 thorpej
201 1.1 thorpej const char *
202 1.1 thorpej dec_eb64plus_intr_string(acv, ih)
203 1.1 thorpej void *acv;
204 1.1 thorpej pci_intr_handle_t ih;
205 1.1 thorpej {
206 1.1 thorpej static char irqstr[15]; /* 11 + 2 + NULL + sanity */
207 1.1 thorpej
208 1.1 thorpej if (ih > EB64PLUS_MAX_IRQ)
209 1.5 thorpej panic("dec_eb64plus_intr_string: bogus eb64+ IRQ 0x%lx\n", ih);
210 1.5 thorpej sprintf(irqstr, "eb64+ irq %ld", ih);
211 1.1 thorpej return (irqstr);
212 1.6 cgd }
213 1.6 cgd
214 1.6 cgd const struct evcnt *
215 1.6 cgd dec_eb64plus_intr_evcnt(acv, ih)
216 1.6 cgd void *acv;
217 1.6 cgd pci_intr_handle_t ih;
218 1.6 cgd {
219 1.6 cgd
220 1.6 cgd /* XXX for now, no evcnt parent reported */
221 1.6 cgd return (NULL);
222 1.1 thorpej }
223 1.1 thorpej
224 1.1 thorpej void *
225 1.1 thorpej dec_eb64plus_intr_establish(acv, ih, level, func, arg)
226 1.1 thorpej void *acv, *arg;
227 1.1 thorpej pci_intr_handle_t ih;
228 1.1 thorpej int level;
229 1.1 thorpej int (*func) __P((void *));
230 1.1 thorpej {
231 1.1 thorpej void *cookie;
232 1.1 thorpej
233 1.1 thorpej if (ih > EB64PLUS_MAX_IRQ)
234 1.5 thorpej panic("dec_eb64plus_intr_establish: bogus eb64+ IRQ 0x%lx\n",
235 1.5 thorpej ih);
236 1.1 thorpej
237 1.1 thorpej cookie = alpha_shared_intr_establish(eb64plus_pci_intr, ih, IST_LEVEL,
238 1.1 thorpej level, func, arg, "eb64+ irq");
239 1.1 thorpej
240 1.1 thorpej if (cookie != NULL && alpha_shared_intr_isactive(eb64plus_pci_intr, ih))
241 1.1 thorpej eb64plus_intr_enable(ih);
242 1.1 thorpej return (cookie);
243 1.1 thorpej }
244 1.1 thorpej
245 1.1 thorpej void
246 1.1 thorpej dec_eb64plus_intr_disestablish(acv, cookie)
247 1.1 thorpej void *acv, *cookie;
248 1.1 thorpej {
249 1.4 thorpej struct alpha_shared_intrhand *ih = cookie;
250 1.4 thorpej unsigned int irq = ih->ih_num;
251 1.4 thorpej int s;
252 1.4 thorpej
253 1.4 thorpej s = splhigh();
254 1.4 thorpej
255 1.4 thorpej alpha_shared_intr_disestablish(eb64plus_pci_intr, cookie,
256 1.4 thorpej "eb64+ irq");
257 1.4 thorpej if (alpha_shared_intr_isactive(eb64plus_pci_intr, irq) == 0) {
258 1.4 thorpej eb64plus_intr_disable(irq);
259 1.4 thorpej alpha_shared_intr_set_dfltsharetype(eb64plus_pci_intr, irq,
260 1.4 thorpej IST_NONE);
261 1.4 thorpej }
262 1.4 thorpej
263 1.4 thorpej splx(s);
264 1.1 thorpej }
265 1.1 thorpej
266 1.1 thorpej void
267 1.1 thorpej eb64plus_iointr(framep, vec)
268 1.1 thorpej void *framep;
269 1.1 thorpej unsigned long vec;
270 1.1 thorpej {
271 1.1 thorpej int irq;
272 1.1 thorpej
273 1.1 thorpej if (vec >= 0x900) {
274 1.1 thorpej if (vec >= 0x900 + (EB64PLUS_MAX_IRQ << 4))
275 1.5 thorpej panic("eb64plus_iointr: vec 0x%lx out of range\n", vec);
276 1.1 thorpej irq = (vec - 0x900) >> 4;
277 1.1 thorpej
278 1.1 thorpej #ifdef EVCNT_COUNTERS
279 1.1 thorpej eb64plus_intr_evcnt.ev_count++;
280 1.1 thorpej #else
281 1.1 thorpej if (EB64PLUS_MAX_IRQ != INTRCNT_EB64PLUS_IRQ_LEN)
282 1.1 thorpej panic("eb64plus interrupt counter sizes inconsistent");
283 1.1 thorpej intrcnt[INTRCNT_EB64PLUS_IRQ + irq]++;
284 1.1 thorpej #endif
285 1.1 thorpej
286 1.1 thorpej if (!alpha_shared_intr_dispatch(eb64plus_pci_intr, irq)) {
287 1.1 thorpej alpha_shared_intr_stray(eb64plus_pci_intr, irq,
288 1.1 thorpej "eb64+ irq");
289 1.3 thorpej if (ALPHA_SHARED_INTR_DISABLE(eb64plus_pci_intr, irq))
290 1.1 thorpej eb64plus_intr_disable(irq);
291 1.1 thorpej }
292 1.1 thorpej return;
293 1.1 thorpej }
294 1.1 thorpej #if NSIO
295 1.1 thorpej if (vec >= 0x800) {
296 1.1 thorpej sio_iointr(framep, vec);
297 1.1 thorpej return;
298 1.1 thorpej }
299 1.1 thorpej #endif
300 1.5 thorpej panic("eb64plus_iointr: weird vec 0x%lx\n", vec);
301 1.1 thorpej }
302 1.1 thorpej
303 1.1 thorpej #if 0 /* THIS DOES NOT WORK! see pci_eb64plus_intr.S. */
304 1.1 thorpej u_int8_t eb64plus_intr_mask[3] = { 0xff, 0xff, 0xff };
305 1.1 thorpej
306 1.1 thorpej void
307 1.1 thorpej eb64plus_intr_enable(irq)
308 1.1 thorpej int irq;
309 1.1 thorpej {
310 1.1 thorpej int byte = (irq / 8), bit = (irq % 8);
311 1.1 thorpej
312 1.1 thorpej #if 1
313 1.1 thorpej printf("eb64plus_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
314 1.1 thorpej #endif
315 1.1 thorpej eb64plus_intr_mask[byte] &= ~(1 << bit);
316 1.1 thorpej
317 1.1 thorpej bus_space_write_1(eb64plus_intrgate_iot, eb64plus_intrgate_ioh, byte,
318 1.1 thorpej eb64plus_intr_mask[byte]);
319 1.1 thorpej }
320 1.1 thorpej
321 1.1 thorpej void
322 1.1 thorpej eb64plus_intr_disable(irq)
323 1.1 thorpej int irq;
324 1.1 thorpej {
325 1.1 thorpej int byte = (irq / 8), bit = (irq % 8);
326 1.1 thorpej
327 1.1 thorpej #if 1
328 1.1 thorpej printf("eb64plus_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
329 1.1 thorpej #endif
330 1.1 thorpej eb64plus_intr_mask[byte] |= (1 << bit);
331 1.1 thorpej
332 1.1 thorpej bus_space_write_1(eb64plus_intrgate_iot, eb64plus_intrgate_ioh, byte,
333 1.1 thorpej eb64plus_intr_mask[byte]);
334 1.1 thorpej }
335 1.1 thorpej #endif
336