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