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