pci_eb164.c revision 1.46 1 1.46 thorpej /* $NetBSD: pci_eb164.c,v 1.46 2020/09/22 15:24:02 thorpej Exp $ */
2 1.14 thorpej
3 1.14 thorpej /*-
4 1.14 thorpej * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.14 thorpej * All rights reserved.
6 1.14 thorpej *
7 1.14 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.14 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.14 thorpej * NASA Ames Research Center.
10 1.14 thorpej *
11 1.14 thorpej * Redistribution and use in source and binary forms, with or without
12 1.14 thorpej * modification, are permitted provided that the following conditions
13 1.14 thorpej * are met:
14 1.14 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.14 thorpej * notice, this list of conditions and the following disclaimer.
16 1.14 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.14 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.14 thorpej * documentation and/or other materials provided with the distribution.
19 1.14 thorpej *
20 1.14 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.14 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.14 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.14 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.14 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.14 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.14 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.14 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.14 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.14 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.14 thorpej * POSSIBILITY OF SUCH DAMAGE.
31 1.14 thorpej */
32 1.1 cgd
33 1.1 cgd /*
34 1.1 cgd * Copyright (c) 1995, 1996 Carnegie-Mellon University.
35 1.1 cgd * All rights reserved.
36 1.1 cgd *
37 1.1 cgd * Author: Chris G. Demetriou
38 1.44 matt *
39 1.1 cgd * Permission to use, copy, modify and distribute this software and
40 1.1 cgd * its documentation is hereby granted, provided that both the copyright
41 1.1 cgd * notice and this permission notice appear in all copies of the
42 1.1 cgd * software, derivative works or modified versions, and any portions
43 1.1 cgd * thereof, and that both notices appear in supporting documentation.
44 1.44 matt *
45 1.44 matt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 1.44 matt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 1.1 cgd * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 1.44 matt *
49 1.1 cgd * Carnegie Mellon requests users of this software to return to
50 1.1 cgd *
51 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
52 1.1 cgd * School of Computer Science
53 1.1 cgd * Carnegie Mellon University
54 1.1 cgd * Pittsburgh PA 15213-3890
55 1.1 cgd *
56 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
57 1.1 cgd * rights to redistribute these changes.
58 1.1 cgd */
59 1.5 cgd
60 1.6 cgd #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
61 1.6 cgd
62 1.46 thorpej __KERNEL_RCSID(0, "$NetBSD: pci_eb164.c,v 1.46 2020/09/22 15:24:02 thorpej Exp $");
63 1.1 cgd
64 1.1 cgd #include <sys/types.h>
65 1.1 cgd #include <sys/param.h>
66 1.1 cgd #include <sys/time.h>
67 1.1 cgd #include <sys/systm.h>
68 1.1 cgd #include <sys/errno.h>
69 1.1 cgd #include <sys/malloc.h>
70 1.1 cgd #include <sys/device.h>
71 1.1 cgd #include <sys/syslog.h>
72 1.1 cgd
73 1.1 cgd #include <machine/autoconf.h>
74 1.18 thorpej #include <machine/rpb.h>
75 1.1 cgd
76 1.1 cgd #include <dev/pci/pcireg.h>
77 1.1 cgd #include <dev/pci/pcivar.h>
78 1.14 thorpej #include <dev/pci/pciidereg.h>
79 1.14 thorpej #include <dev/pci/pciidevar.h>
80 1.1 cgd
81 1.1 cgd #include <alpha/pci/ciareg.h>
82 1.1 cgd #include <alpha/pci/ciavar.h>
83 1.1 cgd
84 1.1 cgd #include <alpha/pci/pci_eb164.h>
85 1.1 cgd
86 1.1 cgd #include "sio.h"
87 1.1 cgd #if NSIO
88 1.1 cgd #include <alpha/pci/siovar.h>
89 1.1 cgd #endif
90 1.1 cgd
91 1.46 thorpej static int dec_eb164_intr_map(const struct pci_attach_args *,
92 1.46 thorpej pci_intr_handle_t *);
93 1.14 thorpej
94 1.44 matt #define EB164_SIO_IRQ 4
95 1.3 cgd #define EB164_MAX_IRQ 24
96 1.3 cgd #define PCI_STRAY_MAX 5
97 1.3 cgd
98 1.46 thorpej static bus_space_tag_t eb164_intrgate_iot;
99 1.46 thorpej static bus_space_handle_t eb164_intrgate_ioh;
100 1.3 cgd
101 1.46 thorpej /* See pci_eb164_intr.s */
102 1.46 thorpej extern void eb164_intr_enable(pci_chipset_tag_t, int irq);
103 1.46 thorpej extern void eb164_intr_disable(pci_chipset_tag_t, int irq);
104 1.1 cgd
105 1.1 cgd void
106 1.38 dsl pci_eb164_pickintr(struct cia_config *ccp)
107 1.1 cgd {
108 1.10 thorpej bus_space_tag_t iot = &ccp->cc_iot;
109 1.1 cgd pci_chipset_tag_t pc = &ccp->cc_pc;
110 1.26 thorpej char *cp;
111 1.3 cgd int i;
112 1.1 cgd
113 1.44 matt pc->pc_intr_v = ccp;
114 1.44 matt pc->pc_intr_map = dec_eb164_intr_map;
115 1.46 thorpej pc->pc_intr_string = alpha_pci_generic_intr_string;
116 1.46 thorpej pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
117 1.46 thorpej pc->pc_intr_establish = alpha_pci_generic_intr_establish;
118 1.46 thorpej pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
119 1.1 cgd
120 1.14 thorpej pc->pc_pciide_compat_intr_establish =
121 1.46 thorpej sio_pciide_compat_intr_establish;
122 1.14 thorpej
123 1.3 cgd eb164_intrgate_iot = iot;
124 1.3 cgd if (bus_space_map(eb164_intrgate_iot, 0x804, 3, 0,
125 1.3 cgd &eb164_intrgate_ioh) != 0)
126 1.3 cgd panic("pci_eb164_pickintr: couldn't map interrupt PLD");
127 1.3 cgd for (i = 0; i < EB164_MAX_IRQ; i++)
128 1.46 thorpej eb164_intr_disable(pc, i);
129 1.3 cgd
130 1.45 christos #define PCI_EB164_IRQ_STR 8
131 1.46 thorpej pc->pc_shared_intrs = alpha_shared_intr_alloc(EB164_MAX_IRQ,
132 1.45 christos PCI_EB164_IRQ_STR);
133 1.46 thorpej pc->pc_intr_desc = "eb164 irq";
134 1.46 thorpej pc->pc_vecbase = 0x900;
135 1.46 thorpej pc->pc_nirq = EB164_MAX_IRQ;
136 1.46 thorpej
137 1.46 thorpej pc->pc_intr_enable = eb164_intr_enable;
138 1.46 thorpej pc->pc_intr_disable = eb164_intr_disable;
139 1.46 thorpej
140 1.20 thorpej for (i = 0; i < EB164_MAX_IRQ; i++) {
141 1.20 thorpej /*
142 1.20 thorpej * Systems with a Pyxis seem to have problems with
143 1.20 thorpej * stray interrupts, so just ignore them. Sigh,
144 1.20 thorpej * I hate buggy hardware.
145 1.20 thorpej */
146 1.46 thorpej alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
147 1.21 thorpej (ccp->cc_flags & CCF_ISPYXIS) ? 0 : PCI_STRAY_MAX);
148 1.26 thorpej
149 1.46 thorpej cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
150 1.45 christos snprintf(cp, PCI_EB164_IRQ_STR, "irq %d", i);
151 1.26 thorpej evcnt_attach_dynamic(alpha_shared_intr_evcnt(
152 1.46 thorpej pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
153 1.26 thorpej "eb164", cp);
154 1.20 thorpej }
155 1.3 cgd
156 1.1 cgd #if NSIO
157 1.11 thorpej sio_intr_setup(pc, iot);
158 1.46 thorpej eb164_intr_enable(pc, EB164_SIO_IRQ);
159 1.1 cgd #endif
160 1.1 cgd }
161 1.1 cgd
162 1.46 thorpej static int
163 1.42 dyoung dec_eb164_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
164 1.1 cgd {
165 1.44 matt pcitag_t bustag = pa->pa_intrtag;
166 1.46 thorpej int buspin = pa->pa_intrpin;
167 1.29 sommerfe pci_chipset_tag_t pc = pa->pa_pc;
168 1.16 thorpej int bus, device, function;
169 1.44 matt uint64_t variation;
170 1.1 cgd
171 1.15 thorpej if (buspin == 0) {
172 1.15 thorpej /* No IRQ used. */
173 1.15 thorpej return 1;
174 1.15 thorpej }
175 1.46 thorpej if (buspin < 0 || buspin > 4) {
176 1.15 thorpej printf("dec_eb164_intr_map: bad interrupt pin %d\n", buspin);
177 1.15 thorpej return 1;
178 1.15 thorpej }
179 1.1 cgd
180 1.31 thorpej pci_decompose_tag(pc, bustag, &bus, &device, &function);
181 1.16 thorpej
182 1.18 thorpej variation = hwrpb->rpb_variation & SV_ST_MASK;
183 1.18 thorpej
184 1.12 thorpej /*
185 1.18 thorpej *
186 1.18 thorpej * The AlphaPC 164 and AlphaPC 164LX have a CMD PCI IDE controller
187 1.18 thorpej * at bus 0 device 11. These are wired to compatibility mode,
188 1.18 thorpej * so do not map their interrupts.
189 1.18 thorpej *
190 1.18 thorpej * The AlphaPC 164SX has PCI IDE on functions 1 and 2 of the
191 1.18 thorpej * Cypress PCI-ISA bridge at bus 0 device 8. These, too, are
192 1.18 thorpej * wired to compatibility mode.
193 1.18 thorpej *
194 1.18 thorpej * Real EB164s have ISA IDE on the Super I/O chip.
195 1.12 thorpej */
196 1.18 thorpej if (bus == 0) {
197 1.18 thorpej if (variation >= SV_ST_ALPHAPC164_366 &&
198 1.18 thorpej variation <= SV_ST_ALPHAPC164LX_600) {
199 1.18 thorpej if (device == 8)
200 1.18 thorpej panic("dec_eb164_intr_map: SIO device");
201 1.18 thorpej if (device == 11)
202 1.18 thorpej return (1);
203 1.18 thorpej } else if (variation >= SV_ST_ALPHAPC164SX_400 &&
204 1.18 thorpej variation <= SV_ST_ALPHAPC164SX_600) {
205 1.18 thorpej if (device == 8) {
206 1.18 thorpej if (function == 0)
207 1.18 thorpej panic("dec_eb164_intr_map: SIO device");
208 1.18 thorpej return (1);
209 1.18 thorpej }
210 1.18 thorpej } else {
211 1.18 thorpej if (device == 8)
212 1.18 thorpej panic("dec_eb164_intr_map: SIO device");
213 1.18 thorpej }
214 1.16 thorpej }
215 1.16 thorpej
216 1.46 thorpej return alpha_pci_generic_intr_map(pa, ihp);
217 1.3 cgd }
218 1.3 cgd
219 1.4 cgd #if 0 /* THIS DOES NOT WORK! see pci_eb164_intr.S. */
220 1.44 matt uint8_t eb164_intr_mask[3] = { 0xff, 0xff, 0xff };
221 1.3 cgd
222 1.3 cgd void
223 1.46 thorpej eb164_intr_enable(pci_chipset_tag_t pc __unused, int irq)
224 1.3 cgd {
225 1.3 cgd int byte = (irq / 8), bit = (irq % 8);
226 1.3 cgd
227 1.3 cgd #if 1
228 1.4 cgd printf("eb164_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
229 1.3 cgd #endif
230 1.3 cgd eb164_intr_mask[byte] &= ~(1 << bit);
231 1.3 cgd
232 1.3 cgd bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
233 1.3 cgd eb164_intr_mask[byte]);
234 1.3 cgd }
235 1.3 cgd
236 1.3 cgd void
237 1.46 thorpej eb164_intr_disable(pci_chipset_tag_t pc __unused, int irq)
238 1.3 cgd {
239 1.3 cgd int byte = (irq / 8), bit = (irq % 8);
240 1.3 cgd
241 1.3 cgd #if 1
242 1.4 cgd printf("eb164_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
243 1.3 cgd #endif
244 1.3 cgd eb164_intr_mask[byte] |= (1 << bit);
245 1.3 cgd
246 1.3 cgd bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
247 1.3 cgd eb164_intr_mask[byte]);
248 1.1 cgd }
249 1.4 cgd #endif
250