pci_6600.c revision 1.27 1 1.27 thorpej /* $NetBSD: pci_6600.c,v 1.27 2020/09/23 18:48:50 thorpej 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.27 thorpej __KERNEL_RCSID(0, "$NetBSD: pci_6600.c,v 1.27 2020/09/23 18:48:50 thorpej 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.6 mrg
44 1.1 ross #include <machine/autoconf.h>
45 1.1 ross #define _ALPHA_BUS_DMA_PRIVATE
46 1.23 dyoung #include <sys/bus.h>
47 1.1 ross #include <machine/rpb.h>
48 1.1 ross #include <machine/alpha.h>
49 1.1 ross
50 1.1 ross #include <dev/pci/pcireg.h>
51 1.1 ross #include <dev/pci/pcivar.h>
52 1.1 ross #include <dev/pci/pciidereg.h>
53 1.1 ross #include <dev/pci/pciidevar.h>
54 1.1 ross
55 1.1 ross #include <alpha/pci/tsreg.h>
56 1.1 ross #include <alpha/pci/tsvar.h>
57 1.1 ross #include <alpha/pci/pci_6600.h>
58 1.1 ross
59 1.1 ross #define pci_6600() { Generate ctags(1) key. }
60 1.1 ross
61 1.1 ross #include "sio.h"
62 1.1 ross #if NSIO
63 1.1 ross #include <alpha/pci/siovar.h>
64 1.1 ross #endif
65 1.1 ross
66 1.4 thorpej #define PCI_NIRQ 64
67 1.27 thorpej #define PCI_SIO_IRQ 55
68 1.1 ross #define PCI_STRAY_MAX 5
69 1.1 ross
70 1.2 thorpej /*
71 1.2 thorpej * Some Tsunami models have a PCI device (the USB controller) with interrupts
72 1.2 thorpej * tied to ISA IRQ lines. The IRQ is encoded as:
73 1.2 thorpej *
74 1.2 thorpej * line = 0xe0 | isa_irq;
75 1.2 thorpej */
76 1.2 thorpej #define DEC_6600_LINE_IS_ISA(line) ((line) >= 0xe0 && (line) <= 0xef)
77 1.2 thorpej #define DEC_6600_LINE_ISA_IRQ(line) ((line) & 0x0f)
78 1.2 thorpej
79 1.1 ross static struct tsp_config *sioprimary;
80 1.1 ross
81 1.26 thorpej static void dec_6600_intr_disestablish(pci_chipset_tag_t, void *);
82 1.26 thorpej static void *dec_6600_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
83 1.26 thorpej int, int (*func)(void *), void *);
84 1.26 thorpej static const char *dec_6600_intr_string(pci_chipset_tag_t, pci_intr_handle_t,
85 1.26 thorpej char *, size_t);
86 1.26 thorpej static const struct evcnt *dec_6600_intr_evcnt(pci_chipset_tag_t,
87 1.26 thorpej pci_intr_handle_t);
88 1.26 thorpej static int dec_6600_intr_map(const struct pci_attach_args *,
89 1.26 thorpej pci_intr_handle_t *);
90 1.26 thorpej
91 1.26 thorpej static void *dec_6600_pciide_compat_intr_establish(device_t,
92 1.26 thorpej const struct pci_attach_args *, int,
93 1.26 thorpej int (*)(void *), void *);
94 1.26 thorpej
95 1.26 thorpej static void dec_6600_intr_enable(pci_chipset_tag_t, int irq);
96 1.26 thorpej static void dec_6600_intr_disable(pci_chipset_tag_t, int irq);
97 1.1 ross
98 1.27 thorpej /* Software copy of enabled interrupt bits. */
99 1.27 thorpej static uint64_t dec_6600_intr_enables __read_mostly;
100 1.27 thorpej
101 1.1 ross void
102 1.17 dsl pci_6600_pickintr(struct tsp_config *pcp)
103 1.1 ross {
104 1.1 ross bus_space_tag_t iot = &pcp->pc_iot;
105 1.1 ross pci_chipset_tag_t pc = &pcp->pc_pc;
106 1.4 thorpej char *cp;
107 1.1 ross int i;
108 1.1 ross
109 1.24 matt pc->pc_intr_v = pcp;
110 1.24 matt pc->pc_intr_map = dec_6600_intr_map;
111 1.24 matt pc->pc_intr_string = dec_6600_intr_string;
112 1.3 cgd pc->pc_intr_evcnt = dec_6600_intr_evcnt;
113 1.24 matt pc->pc_intr_establish = dec_6600_intr_establish;
114 1.24 matt pc->pc_intr_disestablish = dec_6600_intr_disestablish;
115 1.26 thorpej
116 1.1 ross pc->pc_pciide_compat_intr_establish = NULL;
117 1.1 ross
118 1.26 thorpej pc->pc_intr_desc = "dec 6600 irq";
119 1.26 thorpej pc->pc_vecbase = 0x900;
120 1.26 thorpej pc->pc_nirq = PCI_NIRQ;
121 1.26 thorpej
122 1.26 thorpej pc->pc_intr_enable = dec_6600_intr_enable;
123 1.26 thorpej pc->pc_intr_disable = dec_6600_intr_disable;
124 1.26 thorpej
125 1.1 ross /*
126 1.1 ross * System-wide and Pchip-0-only logic...
127 1.1 ross */
128 1.26 thorpej if (sioprimary == NULL) {
129 1.1 ross sioprimary = pcp;
130 1.1 ross pc->pc_pciide_compat_intr_establish =
131 1.1 ross dec_6600_pciide_compat_intr_establish;
132 1.25 christos #define PCI_6600_IRQ_STR 8
133 1.26 thorpej pc->pc_shared_intrs = alpha_shared_intr_alloc(PCI_NIRQ,
134 1.25 christos PCI_6600_IRQ_STR);
135 1.4 thorpej for (i = 0; i < PCI_NIRQ; i++) {
136 1.26 thorpej alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
137 1.1 ross PCI_STRAY_MAX);
138 1.26 thorpej alpha_shared_intr_set_private(pc->pc_shared_intrs, i,
139 1.2 thorpej sioprimary);
140 1.4 thorpej
141 1.26 thorpej cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
142 1.25 christos snprintf(cp, PCI_6600_IRQ_STR, "irq %d", i);
143 1.4 thorpej evcnt_attach_dynamic(alpha_shared_intr_evcnt(
144 1.26 thorpej pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
145 1.26 thorpej "dec 6600", cp);
146 1.2 thorpej }
147 1.1 ross #if NSIO
148 1.1 ross sio_intr_setup(pc, iot);
149 1.27 thorpej dec_6600_intr_enable(pc, PCI_SIO_IRQ); /* irq line for sio */
150 1.1 ross #endif
151 1.26 thorpej } else {
152 1.26 thorpej pc->pc_shared_intrs = sioprimary->pc_pc.pc_shared_intrs;
153 1.1 ross }
154 1.1 ross }
155 1.1 ross
156 1.26 thorpej static int
157 1.21 dyoung dec_6600_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
158 1.1 ross {
159 1.7 sommerfe pcitag_t bustag = pa->pa_intrtag;
160 1.7 sommerfe int buspin = pa->pa_intrpin, line = pa->pa_intrline;
161 1.7 sommerfe pci_chipset_tag_t pc = pa->pa_pc;
162 1.1 ross int bus, device, function;
163 1.1 ross
164 1.1 ross if (buspin == 0) {
165 1.1 ross /* No IRQ used. */
166 1.1 ross return 1;
167 1.1 ross }
168 1.26 thorpej if (buspin < 0 || buspin > 4) {
169 1.1 ross printf("intr_map: bad interrupt pin %d\n", buspin);
170 1.1 ross return 1;
171 1.1 ross }
172 1.1 ross
173 1.9 thorpej pci_decompose_tag(pc, bustag, &bus, &device, &function);
174 1.2 thorpej
175 1.1 ross /*
176 1.1 ross * The console places the interrupt mapping in the "line" value.
177 1.1 ross * A value of (char)-1 indicates there is no mapping.
178 1.1 ross */
179 1.2 thorpej if (line == 0xff) {
180 1.2 thorpej printf("dec_6600_intr_map: no mapping for %d/%d/%d\n",
181 1.2 thorpej bus, device, function);
182 1.1 ross return (1);
183 1.1 ross }
184 1.1 ross
185 1.2 thorpej #if NSIO == 0
186 1.2 thorpej if (DEC_6600_LINE_IS_ISA(line)) {
187 1.2 thorpej printf("dec_6600_intr_map: ISA IRQ %d for %d/%d/%d\n",
188 1.2 thorpej DEC_6600_LINE_ISA_IRQ(line), bus, device, function);
189 1.2 thorpej return (1);
190 1.2 thorpej }
191 1.2 thorpej #endif
192 1.2 thorpej
193 1.4 thorpej if (DEC_6600_LINE_IS_ISA(line) == 0 && line >= PCI_NIRQ)
194 1.10 provos panic("dec_6600_intr_map: dec 6600 irq too large (%d)",
195 1.2 thorpej line);
196 1.1 ross
197 1.26 thorpej alpha_pci_intr_handle_init(ihp, line, 0);
198 1.1 ross return (0);
199 1.1 ross }
200 1.1 ross
201 1.26 thorpej static const char *
202 1.26 thorpej dec_6600_intr_string(pci_chipset_tag_t const pc, pci_intr_handle_t const ih,
203 1.26 thorpej char * const buf, size_t const len)
204 1.1 ross {
205 1.26 thorpej #if NSIO
206 1.26 thorpej const u_int irq = alpha_pci_intr_handle_get_irq(&ih);
207 1.1 ross
208 1.26 thorpej if (DEC_6600_LINE_IS_ISA(irq))
209 1.2 thorpej return (sio_intr_string(NULL /*XXX*/,
210 1.26 thorpej DEC_6600_LINE_ISA_IRQ(irq), buf, len));
211 1.2 thorpej #endif
212 1.2 thorpej
213 1.26 thorpej return alpha_pci_generic_intr_string(pc, ih, buf, len);
214 1.3 cgd }
215 1.3 cgd
216 1.26 thorpej static const struct evcnt *
217 1.26 thorpej dec_6600_intr_evcnt(pci_chipset_tag_t const pc, pci_intr_handle_t const ih)
218 1.3 cgd {
219 1.26 thorpej #if NSIO
220 1.26 thorpej const u_int irq = alpha_pci_intr_handle_get_irq(&ih);
221 1.3 cgd
222 1.26 thorpej if (DEC_6600_LINE_IS_ISA(irq))
223 1.3 cgd return (sio_intr_evcnt(NULL /*XXX*/,
224 1.26 thorpej DEC_6600_LINE_ISA_IRQ(irq)));
225 1.3 cgd #endif
226 1.3 cgd
227 1.26 thorpej return alpha_pci_generic_intr_evcnt(pc, ih);
228 1.1 ross }
229 1.1 ross
230 1.26 thorpej static void *
231 1.26 thorpej dec_6600_intr_establish(pci_chipset_tag_t const pc, pci_intr_handle_t const ih,
232 1.26 thorpej int const level, int (*func)(void *), void *arg)
233 1.1 ross {
234 1.26 thorpej #if NSIO
235 1.26 thorpej const u_int irq = alpha_pci_intr_handle_get_irq(&ih);
236 1.26 thorpej const u_int flags = alpha_pci_intr_handle_get_flags(&ih);
237 1.1 ross
238 1.26 thorpej if (DEC_6600_LINE_IS_ISA(irq))
239 1.2 thorpej return (sio_intr_establish(NULL /*XXX*/,
240 1.26 thorpej DEC_6600_LINE_ISA_IRQ(irq), IST_LEVEL, level, flags,
241 1.26 thorpej func, arg));
242 1.2 thorpej #endif
243 1.2 thorpej
244 1.26 thorpej return alpha_pci_generic_intr_establish(pc, ih, level, func, arg);
245 1.1 ross }
246 1.1 ross
247 1.26 thorpej static void
248 1.26 thorpej dec_6600_intr_disestablish(pci_chipset_tag_t const pc, void * const cookie)
249 1.1 ross {
250 1.26 thorpej #if NSIO
251 1.26 thorpej struct alpha_shared_intrhand * const ih = cookie;
252 1.2 thorpej
253 1.2 thorpej /*
254 1.2 thorpej * We have to determine if this is an ISA IRQ or not! We do this
255 1.2 thorpej * by checking to see if the intrhand points back to an intrhead
256 1.2 thorpej * that points to the sioprimary TSP. If not, it's an ISA IRQ.
257 1.2 thorpej * Pretty disgusting, eh?
258 1.2 thorpej */
259 1.2 thorpej if (ih->ih_intrhead->intr_private != sioprimary) {
260 1.2 thorpej sio_intr_disestablish(NULL /*XXX*/, cookie);
261 1.2 thorpej return;
262 1.2 thorpej }
263 1.2 thorpej #endif
264 1.24 matt
265 1.26 thorpej return alpha_pci_generic_intr_disestablish(pc, cookie);
266 1.1 ross }
267 1.1 ross
268 1.26 thorpej static void
269 1.26 thorpej dec_6600_intr_enable(pci_chipset_tag_t const pc __unused, int const irq)
270 1.1 ross {
271 1.27 thorpej dec_6600_intr_enables |= 1UL << irq;
272 1.1 ross alpha_mb();
273 1.27 thorpej STQP(TS_C_DIM0) = dec_6600_intr_enables;
274 1.1 ross alpha_mb();
275 1.1 ross }
276 1.1 ross
277 1.26 thorpej static void
278 1.26 thorpej dec_6600_intr_disable(pci_chipset_tag_t const pc __unused, int const irq)
279 1.1 ross {
280 1.27 thorpej dec_6600_intr_enables &= ~(1UL << irq);
281 1.1 ross alpha_mb();
282 1.27 thorpej STQP(TS_C_DIM0) = dec_6600_intr_enables;
283 1.1 ross alpha_mb();
284 1.1 ross }
285 1.1 ross
286 1.26 thorpej static void *
287 1.26 thorpej dec_6600_pciide_compat_intr_establish(device_t dev,
288 1.21 dyoung const struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
289 1.1 ross {
290 1.26 thorpej pci_chipset_tag_t const pc = pa->pa_pc;
291 1.1 ross
292 1.2 thorpej /*
293 1.26 thorpej * If this isn't the TSP that holds the PCI-ISA bridge,
294 1.26 thorpej * all bets are off.
295 1.2 thorpej */
296 1.26 thorpej if (pc->pc_intr_v != sioprimary)
297 1.2 thorpej return (NULL);
298 1.1 ross
299 1.26 thorpej return sio_pciide_compat_intr_establish(dev, pa, chan, func, arg);
300 1.1 ross }
301