pci_1000a.c revision 1.31 1 1.31 thorpej /* $NetBSD: pci_1000a.c,v 1.31 2021/06/25 18:08:34 thorpej Exp $ */
2 1.1 ross
3 1.1 ross /*
4 1.1 ross * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 ross * All rights reserved.
6 1.1 ross *
7 1.1 ross * This code is based on pci_kn20aa.c, written by Chris G. Demetriou at
8 1.1 ross * Carnegie-Mellon University. Platform support for Noritake, Pintake, and
9 1.1 ross * Corelle by Ross Harvey with copyright assignment by permission of Avalon
10 1.1 ross * Computer Systems, Inc.
11 1.1 ross *
12 1.1 ross * Redistribution and use in source and binary forms, with or without
13 1.1 ross * modification, are permitted provided that the following conditions
14 1.1 ross * are met:
15 1.1 ross * 1. Redistributions of source code must retain the above copyright
16 1.1 ross * notice, this list of conditions and the following disclaimer.
17 1.1 ross * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 ross * notice, this list of conditions and the following disclaimer in the
19 1.1 ross * documentation and/or other materials provided with the distribution.
20 1.1 ross *
21 1.1 ross * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 1.1 ross * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1 ross * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 ross * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 1.1 ross * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 ross * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 ross * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 ross * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 ross * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 ross * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 ross * POSSIBILITY OF SUCH DAMAGE.
32 1.1 ross */
33 1.1 ross
34 1.1 ross /*
35 1.1 ross * Copyright (c) 1995, 1996 Carnegie-Mellon University.
36 1.1 ross * All rights reserved.
37 1.1 ross *
38 1.1 ross * Author: Chris G. Demetriou
39 1.26 matt *
40 1.1 ross * Permission to use, copy, modify and distribute this software and
41 1.1 ross * its documentation is hereby granted, provided that both the copyright
42 1.1 ross * notice and this permission notice appear in all copies of the
43 1.1 ross * software, derivative works or modified versions, and any portions
44 1.1 ross * thereof, and that both notices appear in supporting documentation.
45 1.26 matt *
46 1.26 matt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47 1.26 matt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
48 1.1 ross * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 1.26 matt *
50 1.1 ross * Carnegie Mellon requests users of this software to return to
51 1.1 ross *
52 1.1 ross * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
53 1.1 ross * School of Computer Science
54 1.1 ross * Carnegie Mellon University
55 1.1 ross * Pittsburgh PA 15213-3890
56 1.1 ross *
57 1.1 ross * any improvements or extensions that they make and grant Carnegie the
58 1.1 ross * rights to redistribute these changes.
59 1.1 ross */
60 1.1 ross
61 1.1 ross #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
62 1.1 ross
63 1.31 thorpej __KERNEL_RCSID(0, "$NetBSD: pci_1000a.c,v 1.31 2021/06/25 18:08:34 thorpej Exp $");
64 1.1 ross
65 1.1 ross #include <sys/types.h>
66 1.1 ross #include <sys/param.h>
67 1.1 ross #include <sys/time.h>
68 1.1 ross #include <sys/systm.h>
69 1.1 ross #include <sys/errno.h>
70 1.1 ross #include <sys/malloc.h>
71 1.1 ross #include <sys/device.h>
72 1.1 ross #include <sys/syslog.h>
73 1.1 ross
74 1.1 ross #include <machine/autoconf.h>
75 1.30 thorpej #include <machine/rpb.h>
76 1.1 ross
77 1.1 ross #include <dev/pci/pcireg.h>
78 1.1 ross #include <dev/pci/pcivar.h>
79 1.1 ross
80 1.1 ross #include "sio.h"
81 1.9 thorpej #if NSIO > 0 || NPCEB > 0
82 1.1 ross #include <alpha/pci/siovar.h>
83 1.1 ross #endif
84 1.1 ross
85 1.11 thorpej #define PCI_NIRQ 32
86 1.11 thorpej #define PCI_STRAY_MAX 5
87 1.2 ross
88 1.1 ross #define IMR2IRQ(bn) ((bn) - 1)
89 1.1 ross #define IRQ2IMR(irq) ((irq) + 1)
90 1.1 ross
91 1.1 ross static bus_space_tag_t mystery_icu_iot;
92 1.1 ross static bus_space_handle_t mystery_icu_ioh[2];
93 1.1 ross
94 1.29 thorpej static int dec_1000a_intr_map(const struct pci_attach_args *,
95 1.29 thorpej pci_intr_handle_t *);
96 1.29 thorpej
97 1.29 thorpej static void dec_1000a_enable_intr(pci_chipset_tag_t, int irq);
98 1.29 thorpej static void dec_1000a_disable_intr(pci_chipset_tag_t, int irq);
99 1.29 thorpej static void pci_1000a_imi(void);
100 1.1 ross
101 1.30 thorpej static void
102 1.30 thorpej pci_1000a_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
103 1.30 thorpej pci_chipset_tag_t pc)
104 1.1 ross {
105 1.11 thorpej char *cp;
106 1.1 ross int i;
107 1.2 ross
108 1.1 ross mystery_icu_iot = iot;
109 1.1 ross
110 1.1 ross if (bus_space_map(iot, 0x54a, 2, 0, mystery_icu_ioh + 0)
111 1.1 ross || bus_space_map(iot, 0x54c, 2, 0, mystery_icu_ioh + 1))
112 1.1 ross panic("pci_1000a_pickintr");
113 1.29 thorpej
114 1.26 matt pc->pc_intr_v = core;
115 1.26 matt pc->pc_intr_map = dec_1000a_intr_map;
116 1.29 thorpej pc->pc_intr_string = alpha_pci_generic_intr_string;
117 1.29 thorpej pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
118 1.29 thorpej pc->pc_intr_establish = alpha_pci_generic_intr_establish;
119 1.29 thorpej pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
120 1.1 ross
121 1.1 ross pc->pc_pciide_compat_intr_establish = NULL;
122 1.1 ross
123 1.28 christos #define PCI_1000A_IRQ_STR 8
124 1.29 thorpej pc->pc_shared_intrs = alpha_shared_intr_alloc(PCI_NIRQ,
125 1.28 christos PCI_1000A_IRQ_STR);
126 1.31 thorpej pc->pc_intr_desc = "dec 1000a";
127 1.29 thorpej pc->pc_vecbase = 0x900;
128 1.29 thorpej pc->pc_nirq = PCI_NIRQ;
129 1.29 thorpej
130 1.29 thorpej pc->pc_intr_enable = dec_1000a_enable_intr;
131 1.29 thorpej pc->pc_intr_disable = dec_1000a_disable_intr;
132 1.29 thorpej
133 1.11 thorpej for (i = 0; i < PCI_NIRQ; i++) {
134 1.29 thorpej alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
135 1.1 ross PCI_STRAY_MAX);
136 1.1 ross
137 1.29 thorpej cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
138 1.28 christos snprintf(cp, PCI_1000A_IRQ_STR, "irq %d", i);
139 1.11 thorpej evcnt_attach_dynamic(alpha_shared_intr_evcnt(
140 1.29 thorpej pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
141 1.31 thorpej pc->pc_intr_desc, cp);
142 1.11 thorpej }
143 1.11 thorpej
144 1.1 ross pci_1000a_imi();
145 1.9 thorpej #if NSIO > 0 || NPCEB > 0
146 1.1 ross sio_intr_setup(pc, iot);
147 1.1 ross #endif
148 1.1 ross }
149 1.30 thorpej ALPHA_PCI_INTR_INIT(ST_DEC_1000A, pci_1000a_pickintr)
150 1.1 ross
151 1.26 matt int
152 1.25 dyoung dec_1000a_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
153 1.1 ross {
154 1.13 sommerfe pcitag_t bustag = pa->pa_intrtag;
155 1.13 sommerfe int buspin = pa->pa_intrpin;
156 1.13 sommerfe pci_chipset_tag_t pc = pa->pa_pc;
157 1.27 skrll int imrbit, device = 0; /* XXX gcc */
158 1.1 ross /*
159 1.1 ross * Get bit number in mystery ICU imr
160 1.1 ross */
161 1.1 ross static const signed char imrmap[][4] = {
162 1.1 ross # define IRQSPLIT(o) { (o), (o)+1, (o)+16, (o)+16+1 }
163 1.1 ross # define IRQNONE { 0, 0, 0, 0 }
164 1.1 ross /* 0 */ { 1, 0, 0, 0 }, /* Noritake and Pintake */
165 1.1 ross /* 1 */ IRQSPLIT(8),
166 1.1 ross /* 2 */ IRQSPLIT(10),
167 1.1 ross /* 3 */ IRQSPLIT(12),
168 1.1 ross /* 4 */ IRQSPLIT(14),
169 1.1 ross /* 5 */ { 1, 0, 0, 0 }, /* Corelle */
170 1.1 ross /* 6 */ { 10, 0, 0, 0 }, /* Corelle */
171 1.1 ross /* 7 */ IRQNONE,
172 1.6 ross /* 8 */ { 1, 0, 0, 0 }, /* isp behind ppb */
173 1.1 ross /* 9 */ IRQNONE,
174 1.1 ross /* 10 */ IRQNONE,
175 1.1 ross /* 11 */ IRQSPLIT(2),
176 1.1 ross /* 12 */ IRQSPLIT(4),
177 1.1 ross /* 13 */ IRQSPLIT(6),
178 1.1 ross /* 14 */ IRQSPLIT(8) /* Corelle */
179 1.1 ross };
180 1.1 ross
181 1.1 ross if (buspin == 0) /* No IRQ used. */
182 1.1 ross return 1;
183 1.1 ross if (!(1 <= buspin && buspin <= 4))
184 1.1 ross goto bad;
185 1.15 thorpej pci_decompose_tag(pc, bustag, NULL, &device, NULL);
186 1.1 ross if (0 <= device && device < sizeof imrmap / sizeof imrmap[0]) {
187 1.6 ross if (device == 0)
188 1.6 ross printf("dec_1000a_intr_map: ?! UNEXPECTED DEV 0\n");
189 1.1 ross imrbit = imrmap[device][buspin - 1];
190 1.1 ross if (imrbit) {
191 1.29 thorpej alpha_pci_intr_handle_init(ihp, IMR2IRQ(imrbit), 0);
192 1.1 ross return 0;
193 1.1 ross }
194 1.1 ross }
195 1.1 ross bad: printf("dec_1000a_intr_map: can't map dev %d pin %d\n", device, buspin);
196 1.1 ross return 1;
197 1.1 ross }
198 1.1 ross
199 1.1 ross /*
200 1.1 ross * Read and write the mystery ICU IMR registers
201 1.1 ross */
202 1.1 ross
203 1.1 ross #define IR(h) bus_space_read_2(mystery_icu_iot, mystery_icu_ioh[h], 0)
204 1.1 ross #define IW(h, v) bus_space_write_2(mystery_icu_iot, mystery_icu_ioh[h], 0, (v))
205 1.1 ross
206 1.1 ross /*
207 1.1 ross * Enable and disable interrupts at the ICU level
208 1.1 ross */
209 1.1 ross
210 1.1 ross static void
211 1.29 thorpej dec_1000a_enable_intr(pci_chipset_tag_t pc __unused, int irq)
212 1.1 ross {
213 1.1 ross int imrval = IRQ2IMR(irq);
214 1.1 ross int i = imrval >= 16;
215 1.1 ross
216 1.1 ross IW(i, IR(i) | 1 << (imrval & 0xf));
217 1.1 ross }
218 1.1 ross
219 1.1 ross static void
220 1.29 thorpej dec_1000a_disable_intr(pci_chipset_tag_t pc __unused, int irq)
221 1.1 ross {
222 1.1 ross int imrval = IRQ2IMR(irq);
223 1.1 ross int i = imrval >= 16;
224 1.1 ross
225 1.1 ross IW(i, IR(i) & ~(1 << (imrval & 0xf)));
226 1.1 ross }
227 1.29 thorpej
228 1.1 ross /*
229 1.1 ross * Initialize mystery ICU
230 1.1 ross */
231 1.1 ross static void
232 1.26 matt pci_1000a_imi(void)
233 1.1 ross {
234 1.1 ross IW(0, IR(0) & 1);
235 1.1 ross IW(1, IR(0) & 3);
236 1.1 ross }
237