pci_eb164.c revision 1.48 1 1.48 thorpej /* $NetBSD: pci_eb164.c,v 1.48 2021/06/25 18:08:34 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.48 thorpej __KERNEL_RCSID(0, "$NetBSD: pci_eb164.c,v 1.48 2021/06/25 18:08:34 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 "sio.h"
85 1.1 cgd #if NSIO
86 1.1 cgd #include <alpha/pci/siovar.h>
87 1.1 cgd #endif
88 1.1 cgd
89 1.46 thorpej static int dec_eb164_intr_map(const struct pci_attach_args *,
90 1.46 thorpej pci_intr_handle_t *);
91 1.14 thorpej
92 1.44 matt #define EB164_SIO_IRQ 4
93 1.3 cgd #define EB164_MAX_IRQ 24
94 1.3 cgd #define PCI_STRAY_MAX 5
95 1.3 cgd
96 1.46 thorpej static bus_space_tag_t eb164_intrgate_iot;
97 1.46 thorpej static bus_space_handle_t eb164_intrgate_ioh;
98 1.3 cgd
99 1.46 thorpej /* See pci_eb164_intr.s */
100 1.46 thorpej extern void eb164_intr_enable(pci_chipset_tag_t, int irq);
101 1.46 thorpej extern void eb164_intr_disable(pci_chipset_tag_t, int irq);
102 1.1 cgd
103 1.47 thorpej static void
104 1.47 thorpej pci_eb164_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
105 1.47 thorpej pci_chipset_tag_t pc)
106 1.1 cgd {
107 1.47 thorpej struct cia_config *ccp = core;
108 1.26 thorpej char *cp;
109 1.3 cgd int i;
110 1.1 cgd
111 1.47 thorpej pc->pc_intr_v = core;
112 1.44 matt pc->pc_intr_map = dec_eb164_intr_map;
113 1.46 thorpej pc->pc_intr_string = alpha_pci_generic_intr_string;
114 1.46 thorpej pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
115 1.46 thorpej pc->pc_intr_establish = alpha_pci_generic_intr_establish;
116 1.46 thorpej pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
117 1.1 cgd
118 1.14 thorpej pc->pc_pciide_compat_intr_establish =
119 1.46 thorpej sio_pciide_compat_intr_establish;
120 1.14 thorpej
121 1.3 cgd eb164_intrgate_iot = iot;
122 1.3 cgd if (bus_space_map(eb164_intrgate_iot, 0x804, 3, 0,
123 1.3 cgd &eb164_intrgate_ioh) != 0)
124 1.3 cgd panic("pci_eb164_pickintr: couldn't map interrupt PLD");
125 1.3 cgd for (i = 0; i < EB164_MAX_IRQ; i++)
126 1.46 thorpej eb164_intr_disable(pc, i);
127 1.3 cgd
128 1.45 christos #define PCI_EB164_IRQ_STR 8
129 1.46 thorpej pc->pc_shared_intrs = alpha_shared_intr_alloc(EB164_MAX_IRQ,
130 1.45 christos PCI_EB164_IRQ_STR);
131 1.48 thorpej pc->pc_intr_desc = "eb164";
132 1.46 thorpej pc->pc_vecbase = 0x900;
133 1.46 thorpej pc->pc_nirq = EB164_MAX_IRQ;
134 1.46 thorpej
135 1.46 thorpej pc->pc_intr_enable = eb164_intr_enable;
136 1.46 thorpej pc->pc_intr_disable = eb164_intr_disable;
137 1.46 thorpej
138 1.20 thorpej for (i = 0; i < EB164_MAX_IRQ; i++) {
139 1.20 thorpej /*
140 1.20 thorpej * Systems with a Pyxis seem to have problems with
141 1.20 thorpej * stray interrupts, so just ignore them. Sigh,
142 1.20 thorpej * I hate buggy hardware.
143 1.20 thorpej */
144 1.46 thorpej alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
145 1.21 thorpej (ccp->cc_flags & CCF_ISPYXIS) ? 0 : PCI_STRAY_MAX);
146 1.26 thorpej
147 1.46 thorpej cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
148 1.45 christos snprintf(cp, PCI_EB164_IRQ_STR, "irq %d", i);
149 1.26 thorpej evcnt_attach_dynamic(alpha_shared_intr_evcnt(
150 1.46 thorpej pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
151 1.48 thorpej pc->pc_intr_desc, cp);
152 1.20 thorpej }
153 1.3 cgd
154 1.1 cgd #if NSIO
155 1.11 thorpej sio_intr_setup(pc, iot);
156 1.46 thorpej eb164_intr_enable(pc, EB164_SIO_IRQ);
157 1.1 cgd #endif
158 1.1 cgd }
159 1.47 thorpej ALPHA_PCI_INTR_INIT(ST_EB164, pci_eb164_pickintr)
160 1.1 cgd
161 1.46 thorpej static int
162 1.42 dyoung dec_eb164_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
163 1.1 cgd {
164 1.44 matt pcitag_t bustag = pa->pa_intrtag;
165 1.46 thorpej int buspin = pa->pa_intrpin;
166 1.29 sommerfe pci_chipset_tag_t pc = pa->pa_pc;
167 1.16 thorpej int bus, device, function;
168 1.44 matt uint64_t variation;
169 1.1 cgd
170 1.15 thorpej if (buspin == 0) {
171 1.15 thorpej /* No IRQ used. */
172 1.15 thorpej return 1;
173 1.15 thorpej }
174 1.46 thorpej if (buspin < 0 || buspin > 4) {
175 1.15 thorpej printf("dec_eb164_intr_map: bad interrupt pin %d\n", buspin);
176 1.15 thorpej return 1;
177 1.15 thorpej }
178 1.1 cgd
179 1.31 thorpej pci_decompose_tag(pc, bustag, &bus, &device, &function);
180 1.16 thorpej
181 1.18 thorpej variation = hwrpb->rpb_variation & SV_ST_MASK;
182 1.18 thorpej
183 1.12 thorpej /*
184 1.18 thorpej *
185 1.18 thorpej * The AlphaPC 164 and AlphaPC 164LX have a CMD PCI IDE controller
186 1.18 thorpej * at bus 0 device 11. These are wired to compatibility mode,
187 1.18 thorpej * so do not map their interrupts.
188 1.18 thorpej *
189 1.18 thorpej * The AlphaPC 164SX has PCI IDE on functions 1 and 2 of the
190 1.18 thorpej * Cypress PCI-ISA bridge at bus 0 device 8. These, too, are
191 1.18 thorpej * wired to compatibility mode.
192 1.18 thorpej *
193 1.18 thorpej * Real EB164s have ISA IDE on the Super I/O chip.
194 1.12 thorpej */
195 1.18 thorpej if (bus == 0) {
196 1.18 thorpej if (variation >= SV_ST_ALPHAPC164_366 &&
197 1.18 thorpej variation <= SV_ST_ALPHAPC164LX_600) {
198 1.18 thorpej if (device == 8)
199 1.18 thorpej panic("dec_eb164_intr_map: SIO device");
200 1.18 thorpej if (device == 11)
201 1.18 thorpej return (1);
202 1.18 thorpej } else if (variation >= SV_ST_ALPHAPC164SX_400 &&
203 1.18 thorpej variation <= SV_ST_ALPHAPC164SX_600) {
204 1.18 thorpej if (device == 8) {
205 1.18 thorpej if (function == 0)
206 1.18 thorpej panic("dec_eb164_intr_map: SIO device");
207 1.18 thorpej return (1);
208 1.18 thorpej }
209 1.18 thorpej } else {
210 1.18 thorpej if (device == 8)
211 1.18 thorpej panic("dec_eb164_intr_map: SIO device");
212 1.18 thorpej }
213 1.16 thorpej }
214 1.16 thorpej
215 1.46 thorpej return alpha_pci_generic_intr_map(pa, ihp);
216 1.3 cgd }
217 1.3 cgd
218 1.4 cgd #if 0 /* THIS DOES NOT WORK! see pci_eb164_intr.S. */
219 1.44 matt uint8_t eb164_intr_mask[3] = { 0xff, 0xff, 0xff };
220 1.3 cgd
221 1.3 cgd void
222 1.46 thorpej eb164_intr_enable(pci_chipset_tag_t pc __unused, int irq)
223 1.3 cgd {
224 1.3 cgd int byte = (irq / 8), bit = (irq % 8);
225 1.3 cgd
226 1.3 cgd #if 1
227 1.4 cgd printf("eb164_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
228 1.3 cgd #endif
229 1.3 cgd eb164_intr_mask[byte] &= ~(1 << bit);
230 1.3 cgd
231 1.3 cgd bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
232 1.3 cgd eb164_intr_mask[byte]);
233 1.3 cgd }
234 1.3 cgd
235 1.3 cgd void
236 1.46 thorpej eb164_intr_disable(pci_chipset_tag_t pc __unused, int irq)
237 1.3 cgd {
238 1.3 cgd int byte = (irq / 8), bit = (irq % 8);
239 1.3 cgd
240 1.3 cgd #if 1
241 1.4 cgd printf("eb164_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
242 1.3 cgd #endif
243 1.3 cgd eb164_intr_mask[byte] |= (1 << bit);
244 1.3 cgd
245 1.3 cgd bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
246 1.3 cgd eb164_intr_mask[byte]);
247 1.1 cgd }
248 1.4 cgd #endif
249