pci_2100_a500.c revision 1.12 1 1.12 christos /* $NetBSD: pci_2100_a500.c,v 1.12 2014/03/21 16:39:29 christos Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 1999 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.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej *
19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
30 1.1 thorpej */
31 1.1 thorpej
32 1.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33 1.1 thorpej
34 1.12 christos __KERNEL_RCSID(0, "$NetBSD: pci_2100_a500.c,v 1.12 2014/03/21 16:39:29 christos Exp $");
35 1.1 thorpej
36 1.1 thorpej #include <sys/types.h>
37 1.1 thorpej #include <sys/param.h>
38 1.1 thorpej #include <sys/time.h>
39 1.1 thorpej #include <sys/systm.h>
40 1.1 thorpej #include <sys/errno.h>
41 1.1 thorpej #include <sys/malloc.h>
42 1.1 thorpej #include <sys/device.h>
43 1.1 thorpej #include <sys/syslog.h>
44 1.1 thorpej
45 1.1 thorpej #include <machine/autoconf.h>
46 1.1 thorpej
47 1.1 thorpej #include <dev/eisa/eisavar.h>
48 1.1 thorpej
49 1.1 thorpej #include <dev/pci/pcireg.h>
50 1.1 thorpej #include <dev/pci/pcivar.h>
51 1.1 thorpej
52 1.1 thorpej #include <alpha/pci/ttwogareg.h>
53 1.1 thorpej #include <alpha/pci/ttwogavar.h>
54 1.1 thorpej #include <alpha/pci/pci_2100_a500.h>
55 1.1 thorpej
56 1.1 thorpej static bus_space_tag_t pic_iot;
57 1.1 thorpej static bus_space_handle_t pic_master_ioh;
58 1.1 thorpej static bus_space_handle_t pic_slave_ioh[4];
59 1.1 thorpej static bus_space_handle_t pic_elcr_ioh;
60 1.1 thorpej
61 1.1 thorpej static const int pic_slave_to_master[4] = { 1, 3, 4, 5 };
62 1.1 thorpej
63 1.10 dyoung int dec_2100_a500_pic_intr_map(const struct pci_attach_args *,
64 1.1 thorpej pci_intr_handle_t *);
65 1.1 thorpej
66 1.10 dyoung int dec_2100_a500_icic_intr_map(const struct pci_attach_args *,
67 1.1 thorpej pci_intr_handle_t *);
68 1.1 thorpej
69 1.12 christos const char *dec_2100_a500_intr_string(void *, pci_intr_handle_t, char *, size_t);
70 1.1 thorpej const struct evcnt *dec_2100_a500_intr_evcnt(void *, pci_intr_handle_t);
71 1.1 thorpej void *dec_2100_a500_intr_establish(void *, pci_intr_handle_t,
72 1.1 thorpej int, int (*)(void *), void *);
73 1.1 thorpej void dec_2100_a500_intr_disestablish(void *, void *);
74 1.1 thorpej
75 1.1 thorpej int dec_2100_a500_eisa_intr_map(void *, u_int, eisa_intr_handle_t *);
76 1.12 christos const char *dec_2100_a500_eisa_intr_string(void *, int, char *, size_t);
77 1.1 thorpej const struct evcnt *dec_2100_a500_eisa_intr_evcnt(void *, int);
78 1.1 thorpej void *dec_2100_a500_eisa_intr_establish(void *, int, int, int,
79 1.1 thorpej int (*)(void *), void *);
80 1.1 thorpej void dec_2100_a500_eisa_intr_disestablish(void *, void *);
81 1.1 thorpej int dec_2100_a500_eisa_intr_alloc(void *, int, int, int *);
82 1.1 thorpej
83 1.1 thorpej #define PCI_STRAY_MAX 5
84 1.1 thorpej
85 1.1 thorpej /*
86 1.1 thorpej * On systems with cascaded 8259s, it's actually 32. Systems which
87 1.1 thorpej * use the ICIC interrupt logic have 64, however.
88 1.1 thorpej */
89 1.1 thorpej #define SABLE_MAX_IRQ 64
90 1.1 thorpej #define SABLE_8259_MAX_IRQ 32
91 1.1 thorpej
92 1.1 thorpej void dec_2100_a500_iointr(void *, u_long);
93 1.1 thorpej
94 1.1 thorpej void dec_2100_a500_pic_enable_intr(struct ttwoga_config *, int, int);
95 1.1 thorpej void dec_2100_a500_pic_init_intr(struct ttwoga_config *);
96 1.1 thorpej void dec_2100_a500_pic_setlevel(struct ttwoga_config *, int, int);
97 1.1 thorpej void dec_2100_a500_pic_eoi(struct ttwoga_config *, int);
98 1.1 thorpej
99 1.1 thorpej void dec_2100_a500_icic_enable_intr(struct ttwoga_config *, int, int);
100 1.1 thorpej void dec_2100_a500_icic_init_intr(struct ttwoga_config *);
101 1.1 thorpej void dec_2100_a500_icic_setlevel(struct ttwoga_config *, int, int);
102 1.1 thorpej void dec_2100_a500_icic_eoi(struct ttwoga_config *, int);
103 1.1 thorpej
104 1.1 thorpej #define T2_IRQ_EISA_START 7
105 1.1 thorpej #define T2_IRQ_EISA_COUNT 16
106 1.1 thorpej
107 1.1 thorpej #define T2_IRQ_IS_EISA(irq) \
108 1.1 thorpej ((irq) >= T2_IRQ_EISA_START && \
109 1.1 thorpej (irq) < (T2_IRQ_EISA_START + T2_IRQ_EISA_COUNT))
110 1.1 thorpej
111 1.1 thorpej const int dec_2100_a500_intr_deftype[SABLE_MAX_IRQ] = {
112 1.1 thorpej IST_LEVEL, /* PCI slot 0 A */
113 1.1 thorpej IST_LEVEL, /* on-board SCSI */
114 1.1 thorpej IST_LEVEL, /* on-board Ethernet */
115 1.1 thorpej IST_EDGE, /* mouse */
116 1.1 thorpej IST_LEVEL, /* PCI slot 1 A */
117 1.1 thorpej IST_LEVEL, /* PCI slot 2 A */
118 1.1 thorpej IST_EDGE, /* keyboard */
119 1.1 thorpej IST_EDGE, /* floppy (EISA IRQ 0) */
120 1.1 thorpej IST_EDGE, /* serial port 1 (EISA IRQ 1) */
121 1.1 thorpej IST_EDGE, /* parallel port (EISA IRQ 2) */
122 1.1 thorpej IST_NONE, /* EISA IRQ 3 (edge/level) */
123 1.1 thorpej IST_NONE, /* EISA IRQ 4 (edge/level) */
124 1.1 thorpej IST_NONE, /* EISA IRQ 5 (edge/level) */
125 1.1 thorpej IST_NONE, /* EISA IRQ 6 (edge/level) */
126 1.1 thorpej IST_NONE, /* EISA IRQ 7 (edge/level) */
127 1.1 thorpej IST_EDGE, /* serial port 0 (EISA IRQ 8) */
128 1.1 thorpej IST_NONE, /* EISA IRQ 9 (edge/level) */
129 1.1 thorpej IST_NONE, /* EISA IRQ 10 (edge/level) */
130 1.1 thorpej IST_NONE, /* EISA IRQ 11 (edge/level) */
131 1.1 thorpej IST_NONE, /* EISA IRQ 12 (edge/level) */
132 1.1 thorpej IST_LEVEL, /* PCI slot 2 B (EISA IRQ 13 n/c) */
133 1.1 thorpej IST_NONE, /* EISA IRQ 14 (edge/level) */
134 1.1 thorpej IST_NONE, /* EISA IRQ 15 (edge/level) */
135 1.1 thorpej IST_LEVEL, /* I2C (XXX double-check this) */
136 1.1 thorpej IST_LEVEL, /* PCI slot 0 B */
137 1.1 thorpej IST_LEVEL, /* PCI slot 1 B */
138 1.1 thorpej IST_LEVEL, /* PCI slot 0 C */
139 1.1 thorpej IST_LEVEL, /* PCI slot 1 C */
140 1.1 thorpej IST_LEVEL, /* PCI slot 2 C */
141 1.1 thorpej IST_LEVEL, /* PCI slot 0 D */
142 1.1 thorpej IST_LEVEL, /* PCI slot 1 D */
143 1.1 thorpej IST_LEVEL, /* PCI slot 2 D */
144 1.1 thorpej
145 1.1 thorpej /*
146 1.1 thorpej * These are the PCI interrupts on the T3/T4 systems. See
147 1.1 thorpej * dec_2100_a500_icic_intr_map() for the mapping.
148 1.1 thorpej */
149 1.1 thorpej IST_LEVEL,
150 1.1 thorpej IST_LEVEL,
151 1.1 thorpej IST_LEVEL,
152 1.1 thorpej IST_LEVEL,
153 1.1 thorpej IST_LEVEL,
154 1.1 thorpej IST_LEVEL,
155 1.1 thorpej IST_LEVEL,
156 1.1 thorpej IST_LEVEL,
157 1.1 thorpej IST_LEVEL,
158 1.1 thorpej IST_LEVEL,
159 1.1 thorpej IST_LEVEL,
160 1.1 thorpej IST_LEVEL,
161 1.1 thorpej IST_LEVEL,
162 1.1 thorpej IST_LEVEL,
163 1.1 thorpej IST_LEVEL,
164 1.1 thorpej IST_LEVEL,
165 1.1 thorpej IST_LEVEL,
166 1.1 thorpej IST_LEVEL,
167 1.1 thorpej IST_LEVEL,
168 1.1 thorpej IST_LEVEL,
169 1.1 thorpej IST_LEVEL,
170 1.1 thorpej IST_LEVEL,
171 1.1 thorpej IST_LEVEL,
172 1.1 thorpej IST_LEVEL,
173 1.1 thorpej IST_LEVEL,
174 1.1 thorpej IST_LEVEL,
175 1.1 thorpej IST_LEVEL,
176 1.1 thorpej IST_LEVEL,
177 1.1 thorpej IST_LEVEL,
178 1.1 thorpej IST_LEVEL,
179 1.1 thorpej IST_LEVEL,
180 1.1 thorpej IST_LEVEL,
181 1.1 thorpej };
182 1.1 thorpej
183 1.1 thorpej void
184 1.1 thorpej pci_2100_a500_pickintr(struct ttwoga_config *tcp)
185 1.1 thorpej {
186 1.1 thorpej pci_chipset_tag_t pc = &tcp->tc_pc;
187 1.1 thorpej char *cp;
188 1.1 thorpej int i;
189 1.1 thorpej
190 1.1 thorpej pic_iot = &tcp->tc_iot;
191 1.1 thorpej
192 1.1 thorpej pc->pc_intr_v = tcp;
193 1.1 thorpej pc->pc_intr_string = dec_2100_a500_intr_string;
194 1.1 thorpej pc->pc_intr_evcnt = dec_2100_a500_intr_evcnt;
195 1.1 thorpej pc->pc_intr_establish = dec_2100_a500_intr_establish;
196 1.1 thorpej pc->pc_intr_disestablish = dec_2100_a500_intr_disestablish;
197 1.1 thorpej
198 1.1 thorpej /* Not supported on T2. */
199 1.1 thorpej pc->pc_pciide_compat_intr_establish = NULL;
200 1.1 thorpej
201 1.12 christos #define PCI_2100_IRQ_STR 8
202 1.12 christos tcp->tc_intrtab = alpha_shared_intr_alloc(SABLE_MAX_IRQ,
203 1.12 christos PCI_2100_IRQ_STR);
204 1.1 thorpej for (i = 0; i < SABLE_MAX_IRQ; i++) {
205 1.1 thorpej alpha_shared_intr_set_dfltsharetype(tcp->tc_intrtab,
206 1.1 thorpej i, tcp->tc_hose == 0 ?
207 1.1 thorpej dec_2100_a500_intr_deftype[i] : IST_LEVEL);
208 1.1 thorpej alpha_shared_intr_set_maxstrays(tcp->tc_intrtab,
209 1.1 thorpej i, PCI_STRAY_MAX);
210 1.1 thorpej
211 1.1 thorpej cp = alpha_shared_intr_string(tcp->tc_intrtab, i);
212 1.12 christos snprintf(cp, PCI_2100_IRQ_STR, "irq %d", T2_IRQ_IS_EISA(i) ?
213 1.1 thorpej i - T2_IRQ_EISA_START : i);
214 1.1 thorpej evcnt_attach_dynamic(alpha_shared_intr_evcnt(
215 1.1 thorpej tcp->tc_intrtab, i), EVCNT_TYPE_INTR, NULL,
216 1.1 thorpej T2_IRQ_IS_EISA(i) ? "eisa" : "T2", cp);
217 1.1 thorpej }
218 1.1 thorpej
219 1.3 thorpej /* 64 16-byte vectors per hose. */
220 1.3 thorpej tcp->tc_vecbase = 0x800 + ((64 * 16) * tcp->tc_hose);
221 1.3 thorpej
222 1.1 thorpej /*
223 1.1 thorpej * T2 uses a custom layout of cascaded 8259 PICs for interrupt
224 1.1 thorpej * control. T3 and T4 use a built-in interrupt controller.
225 1.1 thorpej *
226 1.1 thorpej * Note that the external PCI bus (Hose 1) always uses
227 1.1 thorpej * the new interrupt controller.
228 1.1 thorpej */
229 1.1 thorpej if (tcp->tc_rev < TRN_T3 && tcp->tc_hose == 0) {
230 1.1 thorpej pc->pc_intr_map = dec_2100_a500_pic_intr_map;
231 1.1 thorpej tcp->tc_enable_intr = dec_2100_a500_pic_enable_intr;
232 1.1 thorpej tcp->tc_setlevel = dec_2100_a500_pic_setlevel;
233 1.1 thorpej tcp->tc_eoi = dec_2100_a500_pic_eoi;
234 1.1 thorpej dec_2100_a500_pic_init_intr(tcp);
235 1.1 thorpej } else {
236 1.1 thorpej pc->pc_intr_map = dec_2100_a500_icic_intr_map;
237 1.1 thorpej tcp->tc_enable_intr = dec_2100_a500_icic_enable_intr;
238 1.1 thorpej tcp->tc_setlevel = dec_2100_a500_icic_setlevel;
239 1.1 thorpej tcp->tc_eoi = dec_2100_a500_icic_eoi;
240 1.1 thorpej dec_2100_a500_icic_init_intr(tcp);
241 1.1 thorpej }
242 1.1 thorpej }
243 1.1 thorpej
244 1.1 thorpej void
245 1.1 thorpej pci_2100_a500_eisa_pickintr(pci_chipset_tag_t pc, eisa_chipset_tag_t ec)
246 1.1 thorpej {
247 1.1 thorpej
248 1.1 thorpej ec->ec_v = pc->pc_intr_v;
249 1.1 thorpej ec->ec_intr_map = dec_2100_a500_eisa_intr_map;
250 1.1 thorpej ec->ec_intr_string = dec_2100_a500_eisa_intr_string;
251 1.1 thorpej ec->ec_intr_evcnt = dec_2100_a500_eisa_intr_evcnt;
252 1.1 thorpej ec->ec_intr_establish = dec_2100_a500_eisa_intr_establish;
253 1.1 thorpej ec->ec_intr_disestablish = dec_2100_a500_eisa_intr_disestablish;
254 1.1 thorpej }
255 1.1 thorpej
256 1.1 thorpej void
257 1.1 thorpej pci_2100_a500_isa_pickintr(pci_chipset_tag_t pc, isa_chipset_tag_t ic)
258 1.1 thorpej {
259 1.1 thorpej
260 1.1 thorpej ic->ic_v = pc->pc_intr_v;
261 1.1 thorpej ic->ic_intr_evcnt = dec_2100_a500_eisa_intr_evcnt;
262 1.1 thorpej ic->ic_intr_establish = dec_2100_a500_eisa_intr_establish;
263 1.1 thorpej ic->ic_intr_disestablish = dec_2100_a500_eisa_intr_disestablish;
264 1.1 thorpej ic->ic_intr_alloc = dec_2100_a500_eisa_intr_alloc;
265 1.1 thorpej }
266 1.1 thorpej
267 1.1 thorpej /*****************************************************************************
268 1.1 thorpej * PCI interrupt support.
269 1.1 thorpej *****************************************************************************/
270 1.1 thorpej
271 1.1 thorpej int
272 1.10 dyoung dec_2100_a500_pic_intr_map(const struct pci_attach_args *pa,
273 1.2 sommerfe pci_intr_handle_t *ihp)
274 1.1 thorpej {
275 1.1 thorpej /*
276 1.1 thorpej * Interrupts in the Sable are even more of a pain than other
277 1.1 thorpej * Alpha systems. The interrupt logic is made up of 5 8259
278 1.1 thorpej * PICs, arranged as follows:
279 1.1 thorpej *
280 1.1 thorpej * Slave 0 --------------------------------+
281 1.1 thorpej * 0 PCI slot 0 A |
282 1.1 thorpej * 1 on-board SCSI |
283 1.1 thorpej * 2 on-board Ethernet |
284 1.1 thorpej * 3 mouse |
285 1.1 thorpej * 4 PCI slot 1 A |
286 1.1 thorpej * 5 PCI slot 2 A |
287 1.1 thorpej * 6 keyboard |
288 1.1 thorpej * 7 floppy (EISA IRQ 0) |
289 1.1 thorpej * |
290 1.1 thorpej * Slave 1 ------------------------+ | Master
291 1.1 thorpej * 0 serial port 1 (EISA IRQ 1) | | 0 ESC interrupt
292 1.1 thorpej * 1 parallel port (EISA IRQ 2) | +-- 1 Slave 0
293 1.1 thorpej * 2 EISA IRQ 3 | 2 reserved
294 1.1 thorpej * 3 EISA IRQ 4 +---------- 3 Slave 1
295 1.1 thorpej * 4 EISA IRQ 5 +---------- 4 Slave 2
296 1.1 thorpej * 5 EISA IRQ 6 | +-- 5 Slave 3
297 1.1 thorpej * 6 EISA IRQ 7 | | 6 reserved
298 1.1 thorpej * 7 serial port 0 (EISA IRQ 8) | | 7 n/c
299 1.1 thorpej * | |
300 1.1 thorpej * Slave 2 ------------------------+ |
301 1.1 thorpej * 0 EISA IRQ 9 |
302 1.1 thorpej * 1 EISA IRQ 10 |
303 1.1 thorpej * 2 EISA IRQ 11 |
304 1.1 thorpej * 3 EISA IRQ 12 |
305 1.1 thorpej * 4 PCI slot 2 B (EISA IRQ 13 n/c) |
306 1.1 thorpej * 5 EISA IRQ 14 |
307 1.1 thorpej * 6 EISA IRQ 15 |
308 1.1 thorpej * 7 I2C |
309 1.1 thorpej * |
310 1.1 thorpej * Slave 3 --------------------------------+
311 1.1 thorpej * 0 PCI slot 0 B
312 1.1 thorpej * 1 PCI slot 1 B
313 1.1 thorpej * 2 PCI slot 0 C
314 1.1 thorpej * 3 PCI slot 1 C
315 1.1 thorpej * 4 PCI slot 2 C
316 1.1 thorpej * 5 PCI slot 0 D
317 1.1 thorpej * 6 PCI slot 1 D
318 1.1 thorpej * 7 PCI slot 2 D
319 1.1 thorpej *
320 1.1 thorpej * Careful readers will note that the PCEB does not handle ISA
321 1.1 thorpej * interrupts at all; when ISA interrupts are established, they
322 1.1 thorpej * must be mapped to Sable interrupts. Thankfully, this is easy
323 1.1 thorpej * to do.
324 1.1 thorpej *
325 1.1 thorpej * The T3 and T4, generally found on Lynx, use a totally different
326 1.1 thorpej * scheme because they have more PCI interrupts to handle; see below.
327 1.1 thorpej */
328 1.1 thorpej static const int irqmap[9/*device*/][4/*pin*/] = {
329 1.1 thorpej { 0x02, -1, -1, -1 }, /* 0: on-board Ethernet */
330 1.1 thorpej { 0x01, -1, -1, -1 }, /* 1: on-board SCSI */
331 1.1 thorpej { -1, -1, -1, -1 }, /* 2: invalid */
332 1.1 thorpej { -1, -1, -1, -1 }, /* 3: invalid */
333 1.1 thorpej { -1, -1, -1, -1 }, /* 4: invalid */
334 1.1 thorpej { -1, -1, -1, -1 }, /* 5: invalid */
335 1.1 thorpej { 0x00, 0x18, 0x1a, 0x1d }, /* 6: PCI slot 0 */
336 1.1 thorpej { 0x04, 0x19, 0x1b, 0x1e }, /* 7: PCI slot 1 */
337 1.1 thorpej { 0x05, 0x14, 0x1c, 0x1f }, /* 8: PCI slot 2 */
338 1.1 thorpej };
339 1.2 sommerfe pcitag_t bustag = pa->pa_intrtag;
340 1.2 sommerfe int buspin = pa->pa_intrpin;
341 1.2 sommerfe pci_chipset_tag_t pc = pa->pa_pc;
342 1.1 thorpej int device, irq;
343 1.1 thorpej
344 1.1 thorpej if (buspin == 0) {
345 1.1 thorpej /* No IRQ used. */
346 1.1 thorpej return (1);
347 1.1 thorpej }
348 1.1 thorpej
349 1.1 thorpej if (buspin > 4) {
350 1.1 thorpej printf("dec_2100_a500_pic_intr_map: bad interrupt pin %d\n",
351 1.1 thorpej buspin);
352 1.1 thorpej return (1);
353 1.1 thorpej }
354 1.1 thorpej
355 1.4 thorpej pci_decompose_tag(pc, bustag, NULL, &device, NULL);
356 1.1 thorpej if (device > 8) {
357 1.1 thorpej printf("dec_2100_a500_pic_intr_map: bad device %d\n",
358 1.1 thorpej device);
359 1.1 thorpej return (1);
360 1.1 thorpej }
361 1.1 thorpej
362 1.1 thorpej irq = irqmap[device][buspin - 1];
363 1.1 thorpej if (irq == -1) {
364 1.1 thorpej printf("dec_2100_a500_pic_intr_map: no mapping for "
365 1.1 thorpej "device %d pin %d\n", device, buspin);
366 1.1 thorpej return (1);
367 1.1 thorpej }
368 1.1 thorpej *ihp = irq;
369 1.1 thorpej return (0);
370 1.1 thorpej }
371 1.1 thorpej
372 1.1 thorpej int
373 1.10 dyoung dec_2100_a500_icic_intr_map(const struct pci_attach_args *pa,
374 1.10 dyoung pci_intr_handle_t *ihp)
375 1.1 thorpej {
376 1.2 sommerfe pcitag_t bustag = pa->pa_intrtag;
377 1.2 sommerfe int buspin = pa->pa_intrpin;
378 1.2 sommerfe pci_chipset_tag_t pc = pa->pa_pc;
379 1.1 thorpej int device, irq;
380 1.1 thorpej
381 1.1 thorpej if (buspin == 0) {
382 1.1 thorpej /* No IRQ used. */
383 1.1 thorpej return (1);
384 1.1 thorpej }
385 1.1 thorpej
386 1.1 thorpej if (buspin > 4) {
387 1.1 thorpej printf("dec_2100_a500_icic_intr_map: bad interrupt in %d\n",
388 1.1 thorpej buspin);
389 1.1 thorpej return (1);
390 1.1 thorpej }
391 1.1 thorpej
392 1.4 thorpej pci_decompose_tag(pc, bustag, NULL, &device, NULL);
393 1.1 thorpej switch (device) {
394 1.1 thorpej case 0: /* on-board Ethernet */
395 1.1 thorpej irq = 24;
396 1.1 thorpej break;
397 1.1 thorpej
398 1.1 thorpej case 1: /* on-board SCSI */
399 1.1 thorpej irq = 28;
400 1.1 thorpej break;
401 1.1 thorpej
402 1.1 thorpej case 6: /* PCI slots */
403 1.1 thorpej case 7:
404 1.1 thorpej case 8:
405 1.1 thorpej irq = (32 + (4 * (device - 6))) + (buspin - 1);
406 1.1 thorpej break;
407 1.1 thorpej
408 1.1 thorpej default:
409 1.1 thorpej printf("dec_2100_a500_icic_intr_map: bad device %d\n",
410 1.1 thorpej device);
411 1.1 thorpej return (1);
412 1.1 thorpej }
413 1.1 thorpej
414 1.1 thorpej *ihp = irq;
415 1.1 thorpej return (0);
416 1.1 thorpej }
417 1.1 thorpej
418 1.1 thorpej const char *
419 1.12 christos dec_2100_a500_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
420 1.1 thorpej {
421 1.1 thorpej if (ih >= SABLE_MAX_IRQ)
422 1.12 christos panic("%s: bogus T2 IRQ 0x%lx", __func__, ih);
423 1.1 thorpej
424 1.12 christos snprintf(buf, len, "T2 irq %ld", ih);
425 1.12 christos return buf;
426 1.1 thorpej }
427 1.1 thorpej
428 1.1 thorpej const struct evcnt *
429 1.1 thorpej dec_2100_a500_intr_evcnt(void *v, pci_intr_handle_t ih)
430 1.1 thorpej {
431 1.1 thorpej struct ttwoga_config *tcp = v;
432 1.1 thorpej
433 1.1 thorpej if (ih >= SABLE_MAX_IRQ)
434 1.12 christos panic("%s: bogus T2 IRQ 0x%lx", __func__, ih);
435 1.1 thorpej
436 1.1 thorpej return (alpha_shared_intr_evcnt(tcp->tc_intrtab, ih));
437 1.1 thorpej }
438 1.1 thorpej
439 1.1 thorpej void *
440 1.1 thorpej dec_2100_a500_intr_establish(void *v, pci_intr_handle_t ih, int level,
441 1.1 thorpej int (*func)(void *), void *arg)
442 1.1 thorpej {
443 1.1 thorpej struct ttwoga_config *tcp = v;
444 1.1 thorpej void *cookie;
445 1.1 thorpej
446 1.1 thorpej if (ih >= SABLE_MAX_IRQ)
447 1.5 provos panic("dec_2100_a500_intr_establish: bogus IRQ 0x%lx",
448 1.1 thorpej ih);
449 1.1 thorpej
450 1.1 thorpej cookie = alpha_shared_intr_establish(tcp->tc_intrtab, ih,
451 1.1 thorpej dec_2100_a500_intr_deftype[ih], level, func, arg, "T2 irq");
452 1.1 thorpej
453 1.1 thorpej if (cookie != NULL &&
454 1.3 thorpej alpha_shared_intr_firstactive(tcp->tc_intrtab, ih)) {
455 1.3 thorpej scb_set(tcp->tc_vecbase + SCB_IDXTOVEC(ih),
456 1.8 ad dec_2100_a500_iointr, tcp, level);
457 1.1 thorpej (*tcp->tc_enable_intr)(tcp, ih, 1);
458 1.3 thorpej }
459 1.1 thorpej
460 1.1 thorpej return (cookie);
461 1.1 thorpej }
462 1.1 thorpej
463 1.1 thorpej void
464 1.1 thorpej dec_2100_a500_intr_disestablish(void *v, void *cookie)
465 1.1 thorpej {
466 1.1 thorpej struct ttwoga_config *tcp = v;
467 1.1 thorpej struct alpha_shared_intrhand *ih = cookie;
468 1.1 thorpej unsigned int irq = ih->ih_num;
469 1.1 thorpej int s;
470 1.1 thorpej
471 1.1 thorpej s = splhigh();
472 1.1 thorpej
473 1.1 thorpej alpha_shared_intr_disestablish(tcp->tc_intrtab, cookie,
474 1.1 thorpej "T2 irq");
475 1.1 thorpej if (alpha_shared_intr_isactive(tcp->tc_intrtab, irq) == 0) {
476 1.1 thorpej (*tcp->tc_enable_intr)(tcp, irq, 0);
477 1.1 thorpej alpha_shared_intr_set_dfltsharetype(tcp->tc_intrtab,
478 1.1 thorpej irq, dec_2100_a500_intr_deftype[irq]);
479 1.3 thorpej scb_free(tcp->tc_vecbase + SCB_IDXTOVEC(irq));
480 1.1 thorpej }
481 1.1 thorpej
482 1.1 thorpej splx(s);
483 1.1 thorpej }
484 1.1 thorpej
485 1.1 thorpej /*****************************************************************************
486 1.1 thorpej * EISA interrupt support.
487 1.1 thorpej *****************************************************************************/
488 1.1 thorpej
489 1.1 thorpej int
490 1.1 thorpej dec_2100_a500_eisa_intr_map(void *v, u_int eirq, eisa_intr_handle_t *ihp)
491 1.1 thorpej {
492 1.1 thorpej
493 1.1 thorpej if (eirq > 15) {
494 1.1 thorpej printf("dec_2100_a500_eisa_intr_map: bad EISA IRQ %d\n",
495 1.1 thorpej eirq);
496 1.1 thorpej *ihp = -1;
497 1.1 thorpej return (1);
498 1.1 thorpej }
499 1.1 thorpej
500 1.1 thorpej /*
501 1.1 thorpej * EISA IRQ 13 is not connected.
502 1.1 thorpej */
503 1.1 thorpej if (eirq == 13) {
504 1.1 thorpej printf("dec_2100_a500_eisa_intr_map: EISA IRQ 13 not "
505 1.1 thorpej "connected\n");
506 1.1 thorpej *ihp = -1;
507 1.1 thorpej return (1);
508 1.1 thorpej }
509 1.1 thorpej
510 1.1 thorpej /*
511 1.1 thorpej * Don't map to a T2 IRQ here; we must do this when we hook the
512 1.1 thorpej * interrupt up, since ISA interrupts aren't explicitly translated.
513 1.1 thorpej */
514 1.1 thorpej
515 1.1 thorpej *ihp = eirq;
516 1.1 thorpej return (0);
517 1.1 thorpej }
518 1.1 thorpej
519 1.1 thorpej const char *
520 1.12 christos dec_2100_a500_eisa_intr_string(void *v, int eirq, char *buf, size_t len)
521 1.1 thorpej {
522 1.1 thorpej if (eirq > 15 || eirq == 13)
523 1.12 christos panic("%s: bogus EISA IRQ 0x%x", __func__, eirq);
524 1.1 thorpej
525 1.12 christos snprintf(buf, len, "eisa irq %d (T2 irq %d)", eirq,
526 1.1 thorpej eirq + T2_IRQ_EISA_START);
527 1.12 christos return buf;
528 1.1 thorpej }
529 1.1 thorpej
530 1.1 thorpej const struct evcnt *
531 1.1 thorpej dec_2100_a500_eisa_intr_evcnt(void *v, int eirq)
532 1.1 thorpej {
533 1.1 thorpej struct ttwoga_config *tcp = v;
534 1.1 thorpej
535 1.1 thorpej if (eirq > 15 || eirq == 13)
536 1.12 christos panic("%s: bogus EISA IRQ 0x%x", __func__, eirq);
537 1.1 thorpej
538 1.1 thorpej return (alpha_shared_intr_evcnt(tcp->tc_intrtab,
539 1.1 thorpej eirq + T2_IRQ_EISA_START));
540 1.1 thorpej }
541 1.1 thorpej
542 1.1 thorpej void *
543 1.1 thorpej dec_2100_a500_eisa_intr_establish(void *v, int eirq, int type, int level,
544 1.1 thorpej int (*fn)(void *), void *arg)
545 1.1 thorpej {
546 1.1 thorpej struct ttwoga_config *tcp = v;
547 1.1 thorpej void *cookie;
548 1.1 thorpej int irq;
549 1.1 thorpej
550 1.1 thorpej if (eirq > 15 || type == IST_NONE)
551 1.1 thorpej panic("dec_2100_a500_eisa_intr_establish: bogus irq or type");
552 1.1 thorpej
553 1.1 thorpej if (eirq == 13) {
554 1.1 thorpej printf("dec_2100_a500_eisa_intr_establish: EISA IRQ 13 not "
555 1.1 thorpej "connected\n");
556 1.1 thorpej return (NULL);
557 1.1 thorpej }
558 1.1 thorpej
559 1.1 thorpej irq = eirq + T2_IRQ_EISA_START;
560 1.1 thorpej
561 1.1 thorpej /*
562 1.1 thorpej * We can't change the trigger type of some interrupts. Don't allow
563 1.1 thorpej * level triggers to be hooked up to non-changeable edge triggers.
564 1.1 thorpej */
565 1.1 thorpej if (dec_2100_a500_intr_deftype[irq] == IST_EDGE && type == IST_LEVEL) {
566 1.1 thorpej printf("dec_2100_a500_eisa_intr_establish: non-EDGE on EDGE\n");
567 1.1 thorpej return (NULL);
568 1.1 thorpej }
569 1.1 thorpej
570 1.1 thorpej cookie = alpha_shared_intr_establish(tcp->tc_intrtab, irq,
571 1.1 thorpej type, level, fn, arg, "T2 irq");
572 1.1 thorpej
573 1.1 thorpej if (cookie != NULL &&
574 1.3 thorpej alpha_shared_intr_firstactive(tcp->tc_intrtab, irq)) {
575 1.3 thorpej scb_set(tcp->tc_vecbase + SCB_IDXTOVEC(irq),
576 1.8 ad dec_2100_a500_iointr, tcp, level);
577 1.1 thorpej (*tcp->tc_setlevel)(tcp, eirq,
578 1.1 thorpej alpha_shared_intr_get_sharetype(tcp->tc_intrtab,
579 1.1 thorpej irq) == IST_LEVEL);
580 1.1 thorpej (*tcp->tc_enable_intr)(tcp, irq, 1);
581 1.1 thorpej }
582 1.1 thorpej
583 1.1 thorpej return (cookie);
584 1.1 thorpej }
585 1.1 thorpej
586 1.1 thorpej void
587 1.1 thorpej dec_2100_a500_eisa_intr_disestablish(void *v, void *cookie)
588 1.1 thorpej {
589 1.1 thorpej struct ttwoga_config *tcp = v;
590 1.1 thorpej struct alpha_shared_intrhand *ih = cookie;
591 1.1 thorpej int s, irq = ih->ih_num;
592 1.1 thorpej
593 1.1 thorpej s = splhigh();
594 1.1 thorpej
595 1.1 thorpej /* Remove it from the link. */
596 1.1 thorpej alpha_shared_intr_disestablish(tcp->tc_intrtab, cookie,
597 1.1 thorpej "T2 irq");
598 1.1 thorpej
599 1.1 thorpej if (alpha_shared_intr_isactive(tcp->tc_intrtab, irq) == 0) {
600 1.1 thorpej (*tcp->tc_enable_intr)(tcp, irq, 0);
601 1.1 thorpej alpha_shared_intr_set_dfltsharetype(tcp->tc_intrtab,
602 1.1 thorpej irq, dec_2100_a500_intr_deftype[irq]);
603 1.3 thorpej scb_free(tcp->tc_vecbase + SCB_IDXTOVEC(irq));
604 1.1 thorpej }
605 1.1 thorpej
606 1.1 thorpej splx(s);
607 1.1 thorpej }
608 1.1 thorpej
609 1.1 thorpej int
610 1.1 thorpej dec_2100_a500_eisa_intr_alloc(void *v, int mask, int type, int *eirqp)
611 1.1 thorpej {
612 1.1 thorpej
613 1.1 thorpej /* XXX Not supported right now. */
614 1.1 thorpej return (1);
615 1.1 thorpej }
616 1.1 thorpej
617 1.1 thorpej /*****************************************************************************
618 1.1 thorpej * Interrupt support routines.
619 1.1 thorpej *****************************************************************************/
620 1.1 thorpej
621 1.1 thorpej #define ICIC_ADDR(tcp, addr) \
622 1.1 thorpej do { \
623 1.1 thorpej alpha_mb(); \
624 1.1 thorpej T2GA((tcp), T2_AIR) = (addr); \
625 1.1 thorpej alpha_mb(); \
626 1.1 thorpej alpha_mb(); \
627 1.1 thorpej (void) T2GA((tcp), T2_AIR); \
628 1.1 thorpej alpha_mb(); \
629 1.1 thorpej alpha_mb(); \
630 1.1 thorpej } while (0)
631 1.1 thorpej
632 1.1 thorpej #define ICIC_READ(tcp) T2GA((tcp), T2_DIR)
633 1.1 thorpej #define ICIC_WRITE(tcp, val) \
634 1.1 thorpej do { \
635 1.1 thorpej alpha_mb(); \
636 1.1 thorpej T2GA((tcp), T2_DIR) = (val); \
637 1.1 thorpej alpha_mb(); \
638 1.1 thorpej alpha_mb(); \
639 1.1 thorpej } while (0)
640 1.1 thorpej
641 1.1 thorpej void
642 1.3 thorpej dec_2100_a500_iointr(void *arg, u_long vec)
643 1.1 thorpej {
644 1.3 thorpej struct ttwoga_config *tcp = arg;
645 1.3 thorpej int irq, rv;
646 1.3 thorpej
647 1.3 thorpej irq = SCB_VECTOIDX(vec - tcp->tc_vecbase);
648 1.1 thorpej
649 1.1 thorpej rv = alpha_shared_intr_dispatch(tcp->tc_intrtab, irq);
650 1.1 thorpej (*tcp->tc_eoi)(tcp, irq);
651 1.1 thorpej if (rv == 0) {
652 1.1 thorpej alpha_shared_intr_stray(tcp->tc_intrtab, irq, "T2 irq");
653 1.1 thorpej if (ALPHA_SHARED_INTR_DISABLE(tcp->tc_intrtab, irq))
654 1.1 thorpej (*tcp->tc_enable_intr)(tcp, irq, 0);
655 1.6 thorpej } else
656 1.6 thorpej alpha_shared_intr_reset_strays(tcp->tc_intrtab, irq);
657 1.1 thorpej }
658 1.1 thorpej
659 1.1 thorpej void
660 1.1 thorpej dec_2100_a500_pic_enable_intr(struct ttwoga_config *tcp, int irq, int onoff)
661 1.1 thorpej {
662 1.1 thorpej int pic;
663 1.11 matt uint8_t bit, mask;
664 1.1 thorpej
665 1.1 thorpej pic = irq >> 3;
666 1.1 thorpej bit = 1 << (irq & 0x7);
667 1.1 thorpej
668 1.1 thorpej mask = bus_space_read_1(pic_iot, pic_slave_ioh[pic], 1);
669 1.1 thorpej if (onoff)
670 1.1 thorpej mask &= ~bit;
671 1.1 thorpej else
672 1.1 thorpej mask |= bit;
673 1.1 thorpej bus_space_write_1(pic_iot, pic_slave_ioh[pic], 1, mask);
674 1.1 thorpej }
675 1.1 thorpej
676 1.1 thorpej void
677 1.1 thorpej dec_2100_a500_icic_enable_intr(struct ttwoga_config *tcp, int irq, int onoff)
678 1.1 thorpej {
679 1.11 matt uint64_t bit, mask;
680 1.1 thorpej
681 1.1 thorpej bit = 1UL << irq;
682 1.1 thorpej
683 1.1 thorpej ICIC_ADDR(tcp, 0x40);
684 1.1 thorpej
685 1.1 thorpej mask = ICIC_READ(tcp);
686 1.1 thorpej if (onoff)
687 1.1 thorpej mask &= ~bit;
688 1.1 thorpej else
689 1.1 thorpej mask |= bit;
690 1.1 thorpej ICIC_WRITE(tcp, mask);
691 1.1 thorpej }
692 1.1 thorpej
693 1.1 thorpej void
694 1.1 thorpej dec_2100_a500_pic_init_intr(struct ttwoga_config *tcp)
695 1.1 thorpej {
696 1.1 thorpej static const int picaddr[4] = {
697 1.1 thorpej 0x536, 0x53a, 0x53c, 0x53e
698 1.1 thorpej };
699 1.1 thorpej int pic;
700 1.1 thorpej
701 1.1 thorpej /*
702 1.1 thorpej * Map the master PIC.
703 1.1 thorpej */
704 1.1 thorpej if (bus_space_map(pic_iot, 0x534, 2, 0, &pic_master_ioh))
705 1.1 thorpej panic("dec_2100_a500_pic_init_intr: unable to map master PIC");
706 1.1 thorpej
707 1.1 thorpej /*
708 1.1 thorpej * Map all slave PICs and mask off the interrupts on them.
709 1.1 thorpej */
710 1.1 thorpej for (pic = 0; pic < 4; pic++) {
711 1.1 thorpej if (bus_space_map(pic_iot, picaddr[pic], 2, 0,
712 1.1 thorpej &pic_slave_ioh[pic]))
713 1.1 thorpej panic("dec_2100_a500_pic_init_intr: unable to map "
714 1.1 thorpej "slave PIC %d", pic);
715 1.1 thorpej bus_space_write_1(pic_iot, pic_slave_ioh[pic], 1, 0xff);
716 1.1 thorpej }
717 1.1 thorpej
718 1.1 thorpej /*
719 1.1 thorpej * Map the ELCR registers.
720 1.1 thorpej */
721 1.1 thorpej if (bus_space_map(pic_iot, 0x26, 2, 0, &pic_elcr_ioh))
722 1.1 thorpej panic("dec_2100_a500_pic_init_intr: unable to map ELCR "
723 1.1 thorpej "registers");
724 1.1 thorpej }
725 1.1 thorpej
726 1.1 thorpej void
727 1.1 thorpej dec_2100_a500_icic_init_intr(struct ttwoga_config *tcp)
728 1.1 thorpej {
729 1.1 thorpej
730 1.1 thorpej ICIC_ADDR(tcp, 0x40);
731 1.1 thorpej ICIC_WRITE(tcp, 0xffffffffffffffffUL);
732 1.1 thorpej }
733 1.1 thorpej
734 1.1 thorpej void
735 1.1 thorpej dec_2100_a500_pic_setlevel(struct ttwoga_config *tcp, int eirq, int level)
736 1.1 thorpej {
737 1.1 thorpej int elcr;
738 1.11 matt uint8_t bit, mask;
739 1.1 thorpej
740 1.1 thorpej switch (eirq) { /* EISA IRQ */
741 1.1 thorpej case 3:
742 1.1 thorpej case 4:
743 1.1 thorpej case 5:
744 1.1 thorpej case 6:
745 1.1 thorpej case 7:
746 1.1 thorpej elcr = 0;
747 1.1 thorpej bit = 1 << (eirq - 3);
748 1.1 thorpej break;
749 1.1 thorpej
750 1.1 thorpej case 9:
751 1.1 thorpej case 10:
752 1.1 thorpej case 11:
753 1.1 thorpej elcr = 0;
754 1.1 thorpej bit = 1 << (eirq - 4);
755 1.1 thorpej break;
756 1.1 thorpej
757 1.1 thorpej case 12:
758 1.1 thorpej elcr = 1;
759 1.1 thorpej bit = 1 << (eirq - 12);
760 1.1 thorpej break;
761 1.1 thorpej
762 1.1 thorpej case 14:
763 1.1 thorpej case 15:
764 1.1 thorpej elcr = 1;
765 1.1 thorpej bit = 1 << (eirq - 13);
766 1.1 thorpej break;
767 1.1 thorpej
768 1.1 thorpej default:
769 1.1 thorpej panic("dec_2100_a500_pic_setlevel: bogus EISA IRQ %d", eirq);
770 1.1 thorpej }
771 1.1 thorpej
772 1.1 thorpej mask = bus_space_read_1(pic_iot, pic_elcr_ioh, elcr);
773 1.1 thorpej if (level)
774 1.1 thorpej mask |= bit;
775 1.1 thorpej else
776 1.1 thorpej mask &= ~bit;
777 1.1 thorpej bus_space_write_1(pic_iot, pic_elcr_ioh, elcr, mask);
778 1.1 thorpej }
779 1.1 thorpej
780 1.1 thorpej void
781 1.1 thorpej dec_2100_a500_icic_setlevel(struct ttwoga_config *tcp, int eirq, int level)
782 1.1 thorpej {
783 1.11 matt uint64_t bit, mask;
784 1.1 thorpej
785 1.1 thorpej switch (eirq) {
786 1.1 thorpej case 3:
787 1.1 thorpej case 4:
788 1.1 thorpej case 5:
789 1.1 thorpej case 6:
790 1.1 thorpej case 7:
791 1.1 thorpej case 9:
792 1.1 thorpej case 10:
793 1.1 thorpej case 11:
794 1.1 thorpej case 12:
795 1.1 thorpej case 14:
796 1.1 thorpej case 15:
797 1.1 thorpej bit = 1UL << (eirq + T2_IRQ_EISA_START);
798 1.1 thorpej
799 1.1 thorpej ICIC_ADDR(tcp, 0x50);
800 1.1 thorpej mask = ICIC_READ(tcp);
801 1.1 thorpej if (level)
802 1.1 thorpej mask |= bit;
803 1.1 thorpej else
804 1.1 thorpej mask &= ~bit;
805 1.1 thorpej ICIC_WRITE(tcp, mask);
806 1.1 thorpej break;
807 1.1 thorpej
808 1.1 thorpej default:
809 1.1 thorpej panic("dec_2100_a500_icic_setlevel: bogus EISA IRQ %d", eirq);
810 1.1 thorpej }
811 1.1 thorpej }
812 1.1 thorpej
813 1.1 thorpej void
814 1.1 thorpej dec_2100_a500_pic_eoi(struct ttwoga_config *tcp, int irq)
815 1.1 thorpej {
816 1.1 thorpej int pic;
817 1.1 thorpej
818 1.1 thorpej if (irq >= 0 && irq <= 7)
819 1.1 thorpej pic = 0;
820 1.1 thorpej else if (irq >= 8 && irq <= 15)
821 1.1 thorpej pic = 1;
822 1.1 thorpej else if (irq >= 16 && irq <= 23)
823 1.1 thorpej pic = 2;
824 1.1 thorpej else
825 1.1 thorpej pic = 3;
826 1.1 thorpej
827 1.1 thorpej bus_space_write_1(pic_iot, pic_slave_ioh[pic], 0,
828 1.1 thorpej 0xe0 | (irq - (8 * pic)));
829 1.1 thorpej bus_space_write_1(pic_iot, pic_master_ioh, 0,
830 1.1 thorpej 0xe0 | pic_slave_to_master[pic]);
831 1.1 thorpej }
832 1.1 thorpej
833 1.1 thorpej void
834 1.1 thorpej dec_2100_a500_icic_eoi(struct ttwoga_config *tcp, int irq)
835 1.1 thorpej {
836 1.1 thorpej
837 1.1 thorpej T2GA(tcp, T2_VAR) = irq;
838 1.1 thorpej alpha_mb();
839 1.1 thorpej alpha_mb(); /* MAGIC */
840 1.1 thorpej }
841