necpb.c revision 1.5.2.5 1 1.5.2.5 bouyer /* $NetBSD: necpb.c,v 1.5.2.5 2001/01/18 09:22:12 bouyer Exp $ */
2 1.5.2.2 bouyer
3 1.5.2.2 bouyer /*-
4 1.5.2.2 bouyer * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 1.5.2.2 bouyer * All rights reserved.
6 1.5.2.2 bouyer *
7 1.5.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.5.2.2 bouyer * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.5.2.2 bouyer * NASA Ames Research Center.
10 1.5.2.2 bouyer *
11 1.5.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.5.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.5.2.2 bouyer * are met:
14 1.5.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.5.2.2 bouyer * notice, this list of conditions and the following disclaimer.
16 1.5.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
17 1.5.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
18 1.5.2.2 bouyer * documentation and/or other materials provided with the distribution.
19 1.5.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
20 1.5.2.2 bouyer * must display the following acknowledgement:
21 1.5.2.2 bouyer * This product includes software developed by the NetBSD
22 1.5.2.2 bouyer * Foundation, Inc. and its contributors.
23 1.5.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.5.2.2 bouyer * contributors may be used to endorse or promote products derived
25 1.5.2.2 bouyer * from this software without specific prior written permission.
26 1.5.2.2 bouyer *
27 1.5.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.5.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.5.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.5.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.5.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.5.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.5.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.5.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.5.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.5.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.5.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
38 1.5.2.2 bouyer */
39 1.5.2.2 bouyer
40 1.5.2.2 bouyer /*
41 1.5.2.2 bouyer * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
42 1.5.2.2 bouyer * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
43 1.5.2.2 bouyer *
44 1.5.2.2 bouyer * Redistribution and use in source and binary forms, with or without
45 1.5.2.2 bouyer * modification, are permitted provided that the following conditions
46 1.5.2.2 bouyer * are met:
47 1.5.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
48 1.5.2.2 bouyer * notice, this list of conditions and the following disclaimer.
49 1.5.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
50 1.5.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
51 1.5.2.2 bouyer * documentation and/or other materials provided with the distribution.
52 1.5.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
53 1.5.2.2 bouyer * must display the following acknowledgement:
54 1.5.2.2 bouyer * This product includes software developed by Charles M. Hannum.
55 1.5.2.2 bouyer * 4. The name of the author may not be used to endorse or promote products
56 1.5.2.2 bouyer * derived from this software without specific prior written permission.
57 1.5.2.2 bouyer *
58 1.5.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 1.5.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 1.5.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 1.5.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 1.5.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 1.5.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 1.5.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 1.5.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 1.5.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 1.5.2.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 1.5.2.2 bouyer */
69 1.5.2.2 bouyer
70 1.5.2.2 bouyer #include <sys/types.h>
71 1.5.2.2 bouyer #include <sys/param.h>
72 1.5.2.2 bouyer #include <sys/time.h>
73 1.5.2.2 bouyer #include <sys/systm.h>
74 1.5.2.2 bouyer #include <sys/errno.h>
75 1.5.2.2 bouyer #include <sys/device.h>
76 1.5.2.2 bouyer #include <sys/malloc.h>
77 1.5.2.2 bouyer #include <sys/extent.h>
78 1.5.2.2 bouyer
79 1.5.2.2 bouyer #include <uvm/uvm_extern.h>
80 1.5.2.2 bouyer
81 1.5.2.2 bouyer #define _ARC_BUS_DMA_PRIVATE
82 1.5.2.2 bouyer #include <machine/bus.h>
83 1.5.2.2 bouyer
84 1.5.2.2 bouyer #include <machine/pio.h>
85 1.5.2.2 bouyer
86 1.5.2.2 bouyer #include <machine/autoconf.h>
87 1.5.2.2 bouyer #include <machine/cpu.h>
88 1.5.2.2 bouyer
89 1.5.2.2 bouyer #include <dev/pci/pcivar.h>
90 1.5.2.2 bouyer #include <dev/pci/pcireg.h>
91 1.5.2.2 bouyer
92 1.5.2.4 bouyer #include <arc/jazz/rd94.h>
93 1.5.2.2 bouyer #include <arc/pci/necpbvar.h>
94 1.5.2.2 bouyer
95 1.5.2.2 bouyer int necpbmatch __P((struct device *, struct cfdata *, void *));
96 1.5.2.2 bouyer void necpbattach __P((struct device *, struct device *, void *));
97 1.5.2.2 bouyer
98 1.5.2.2 bouyer static int necpbprint __P((void *, const char *));
99 1.5.2.2 bouyer
100 1.5.2.2 bouyer void necpb_attach_hook __P((struct device *, struct device *,
101 1.5.2.2 bouyer struct pcibus_attach_args *));
102 1.5.2.2 bouyer int necpb_bus_maxdevs __P((pci_chipset_tag_t, int));
103 1.5.2.2 bouyer pcitag_t necpb_make_tag __P((pci_chipset_tag_t, int, int, int));
104 1.5.2.2 bouyer void necpb_decompose_tag __P((pci_chipset_tag_t, pcitag_t, int *,
105 1.5.2.2 bouyer int *, int *));
106 1.5.2.2 bouyer pcireg_t necpb_conf_read __P((pci_chipset_tag_t, pcitag_t, int));
107 1.5.2.2 bouyer void necpb_conf_write __P((pci_chipset_tag_t, pcitag_t, int,
108 1.5.2.2 bouyer pcireg_t));
109 1.5.2.5 bouyer int necpb_intr_map __P((struct pci_attach_args *,
110 1.5.2.2 bouyer pci_intr_handle_t *));
111 1.5.2.2 bouyer const char * necpb_intr_string __P((pci_chipset_tag_t, pci_intr_handle_t));
112 1.5.2.2 bouyer void * necpb_intr_establish __P((pci_chipset_tag_t, pci_intr_handle_t,
113 1.5.2.2 bouyer int, int (*func)(void *), void *));
114 1.5.2.2 bouyer void necpb_intr_disestablish __P((pci_chipset_tag_t, void *));
115 1.5.2.2 bouyer
116 1.5.2.2 bouyer int necpb_intr(unsigned, struct clockframe *);
117 1.5.2.2 bouyer
118 1.5.2.2 bouyer
119 1.5.2.2 bouyer struct cfattach necpb_ca = {
120 1.5.2.2 bouyer sizeof(struct necpb_softc), necpbmatch, necpbattach,
121 1.5.2.2 bouyer };
122 1.5.2.2 bouyer
123 1.5.2.2 bouyer extern struct cfdriver necpb_cd;
124 1.5.2.2 bouyer
125 1.5.2.2 bouyer static struct necpb_intrhand *necpb_inttbl[4];
126 1.5.2.2 bouyer
127 1.5.2.2 bouyer /* There can be only one. */
128 1.5.2.2 bouyer int necpbfound;
129 1.5.2.2 bouyer struct necpb_config necpb_configuration;
130 1.5.2.2 bouyer static long necpb_mem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(10) / sizeof(long)];
131 1.5.2.2 bouyer static long necpb_io_ex_storage[EXTENT_FIXED_STORAGE_SIZE(10) / sizeof(long)];
132 1.5.2.2 bouyer
133 1.5.2.2 bouyer int
134 1.5.2.2 bouyer necpbmatch(parent, match, aux)
135 1.5.2.2 bouyer struct device *parent;
136 1.5.2.2 bouyer struct cfdata *match;
137 1.5.2.2 bouyer void *aux;
138 1.5.2.2 bouyer {
139 1.5.2.2 bouyer struct confargs *ca = aux;
140 1.5.2.2 bouyer
141 1.5.2.2 bouyer if (strcmp(ca->ca_name, necpb_cd.cd_name) != 0)
142 1.5.2.2 bouyer return (0);
143 1.5.2.2 bouyer
144 1.5.2.2 bouyer if (necpbfound)
145 1.5.2.2 bouyer return (0);
146 1.5.2.2 bouyer
147 1.5.2.2 bouyer return (1);
148 1.5.2.2 bouyer }
149 1.5.2.2 bouyer
150 1.5.2.2 bouyer /*
151 1.5.2.2 bouyer * Set up the chipset's function pointers.
152 1.5.2.2 bouyer */
153 1.5.2.2 bouyer void
154 1.5.2.2 bouyer necpb_init(ncp)
155 1.5.2.2 bouyer struct necpb_config *ncp;
156 1.5.2.2 bouyer {
157 1.5.2.2 bouyer pcitag_t tag;
158 1.5.2.2 bouyer pcireg_t csr;
159 1.5.2.2 bouyer
160 1.5.2.2 bouyer if (ncp->nc_initialized)
161 1.5.2.2 bouyer return;
162 1.5.2.2 bouyer
163 1.5.2.2 bouyer arc_large_bus_space_init(&ncp->nc_memt, "necpcimem",
164 1.5.2.2 bouyer RD94_P_PCI_MEM, 0, RD94_S_PCI_MEM);
165 1.5.2.2 bouyer arc_bus_space_init_extent(&ncp->nc_memt, (caddr_t)necpb_mem_ex_storage,
166 1.5.2.2 bouyer sizeof(necpb_mem_ex_storage));
167 1.5.2.2 bouyer
168 1.5.2.2 bouyer arc_bus_space_init(&ncp->nc_iot, "necpciio",
169 1.5.2.2 bouyer RD94_P_PCI_IO, RD94_V_PCI_IO, 0, RD94_S_PCI_IO);
170 1.5.2.2 bouyer arc_bus_space_init_extent(&ncp->nc_iot, (caddr_t)necpb_io_ex_storage,
171 1.5.2.2 bouyer sizeof(necpb_io_ex_storage));
172 1.5.2.2 bouyer
173 1.5.2.2 bouyer jazz_bus_dma_tag_init(&ncp->nc_dmat);
174 1.5.2.2 bouyer
175 1.5.2.2 bouyer ncp->nc_pc.pc_attach_hook = necpb_attach_hook;
176 1.5.2.2 bouyer ncp->nc_pc.pc_bus_maxdevs = necpb_bus_maxdevs;
177 1.5.2.2 bouyer ncp->nc_pc.pc_make_tag = necpb_make_tag;
178 1.5.2.2 bouyer ncp->nc_pc.pc_conf_read = necpb_conf_read;
179 1.5.2.2 bouyer ncp->nc_pc.pc_conf_write = necpb_conf_write;
180 1.5.2.2 bouyer ncp->nc_pc.pc_intr_map = necpb_intr_map;
181 1.5.2.2 bouyer ncp->nc_pc.pc_intr_string = necpb_intr_string;
182 1.5.2.2 bouyer ncp->nc_pc.pc_intr_establish = necpb_intr_establish;
183 1.5.2.2 bouyer ncp->nc_pc.pc_intr_disestablish = necpb_intr_disestablish;
184 1.5.2.2 bouyer
185 1.5.2.2 bouyer /* XXX: enable all mem/io/busmaster */
186 1.5.2.2 bouyer tag = necpb_make_tag(&ncp->nc_pc, 0, 3, 0);
187 1.5.2.2 bouyer csr = necpb_conf_read(&ncp->nc_pc, tag, PCI_COMMAND_STATUS_REG);
188 1.5.2.2 bouyer csr |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
189 1.5.2.2 bouyer PCI_COMMAND_MASTER_ENABLE;
190 1.5.2.2 bouyer necpb_conf_write(&ncp->nc_pc, tag, PCI_COMMAND_STATUS_REG, csr);
191 1.5.2.2 bouyer
192 1.5.2.2 bouyer tag = necpb_make_tag(&ncp->nc_pc, 0, 4, 0);
193 1.5.2.2 bouyer csr = necpb_conf_read(&ncp->nc_pc, tag, PCI_COMMAND_STATUS_REG);
194 1.5.2.2 bouyer csr |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
195 1.5.2.2 bouyer PCI_COMMAND_MASTER_ENABLE;
196 1.5.2.2 bouyer necpb_conf_write(&ncp->nc_pc, tag, PCI_COMMAND_STATUS_REG, csr);
197 1.5.2.2 bouyer
198 1.5.2.2 bouyer tag = necpb_make_tag(&ncp->nc_pc, 0, 5, 0);
199 1.5.2.2 bouyer csr = necpb_conf_read(&ncp->nc_pc, tag, PCI_COMMAND_STATUS_REG);
200 1.5.2.2 bouyer csr |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
201 1.5.2.2 bouyer PCI_COMMAND_MASTER_ENABLE;
202 1.5.2.2 bouyer necpb_conf_write(&ncp->nc_pc, tag, PCI_COMMAND_STATUS_REG, csr);
203 1.5.2.2 bouyer
204 1.5.2.2 bouyer ncp->nc_initialized = 1;
205 1.5.2.2 bouyer }
206 1.5.2.2 bouyer
207 1.5.2.2 bouyer void
208 1.5.2.2 bouyer necpbattach(parent, self, aux)
209 1.5.2.2 bouyer struct device *parent, *self;
210 1.5.2.2 bouyer void *aux;
211 1.5.2.2 bouyer {
212 1.5.2.2 bouyer struct necpb_softc *sc = (struct necpb_softc *)self;
213 1.5.2.2 bouyer struct pcibus_attach_args pba;
214 1.5.2.2 bouyer int i;
215 1.5.2.2 bouyer
216 1.5.2.2 bouyer necpbfound = 1;
217 1.5.2.2 bouyer
218 1.5.2.2 bouyer printf("\n");
219 1.5.2.2 bouyer
220 1.5.2.2 bouyer sc->sc_ncp = &necpb_configuration;
221 1.5.2.2 bouyer necpb_init(sc->sc_ncp);
222 1.5.2.2 bouyer
223 1.5.2.2 bouyer out32(RD94_SYS_PCI_INTMASK, 0xf);
224 1.5.2.2 bouyer
225 1.5.2.2 bouyer for (i = 0; i < 4; i++)
226 1.5.2.2 bouyer necpb_inttbl[i] = NULL;
227 1.5.2.2 bouyer
228 1.5.2.2 bouyer set_intr(MIPS_INT_MASK_2, necpb_intr, 3);
229 1.5.2.2 bouyer
230 1.5.2.2 bouyer pba.pba_busname = "pci";
231 1.5.2.2 bouyer pba.pba_iot = &sc->sc_ncp->nc_iot;
232 1.5.2.2 bouyer pba.pba_memt = &sc->sc_ncp->nc_memt;
233 1.5.2.2 bouyer pba.pba_dmat = &sc->sc_ncp->nc_dmat;
234 1.5.2.2 bouyer pba.pba_pc = &sc->sc_ncp->nc_pc;
235 1.5.2.2 bouyer pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
236 1.5.2.2 bouyer pba.pba_bus = 0;
237 1.5.2.2 bouyer
238 1.5.2.2 bouyer config_found(self, &pba, necpbprint);
239 1.5.2.2 bouyer }
240 1.5.2.2 bouyer
241 1.5.2.2 bouyer static int
242 1.5.2.2 bouyer necpbprint(aux, pnp)
243 1.5.2.2 bouyer void *aux;
244 1.5.2.2 bouyer const char *pnp;
245 1.5.2.2 bouyer {
246 1.5.2.2 bouyer struct pcibus_attach_args *pba = aux;
247 1.5.2.2 bouyer
248 1.5.2.2 bouyer if (pnp)
249 1.5.2.2 bouyer printf("%s at %s", pba->pba_busname, pnp);
250 1.5.2.2 bouyer printf(" bus %d", pba->pba_bus);
251 1.5.2.2 bouyer return (UNCONF);
252 1.5.2.2 bouyer }
253 1.5.2.2 bouyer
254 1.5.2.2 bouyer void
255 1.5.2.2 bouyer necpb_attach_hook(parent, self, pba)
256 1.5.2.2 bouyer struct device *parent, *self;
257 1.5.2.2 bouyer struct pcibus_attach_args *pba;
258 1.5.2.2 bouyer {
259 1.5.2.2 bouyer }
260 1.5.2.2 bouyer
261 1.5.2.2 bouyer int
262 1.5.2.2 bouyer necpb_bus_maxdevs(pc, busno)
263 1.5.2.2 bouyer pci_chipset_tag_t pc;
264 1.5.2.2 bouyer int busno;
265 1.5.2.2 bouyer {
266 1.5.2.2 bouyer return (32);
267 1.5.2.2 bouyer }
268 1.5.2.2 bouyer
269 1.5.2.2 bouyer pcitag_t
270 1.5.2.2 bouyer necpb_make_tag(pc, bus, device, function)
271 1.5.2.2 bouyer pci_chipset_tag_t pc;
272 1.5.2.2 bouyer int bus, device, function;
273 1.5.2.2 bouyer {
274 1.5.2.2 bouyer pcitag_t tag;
275 1.5.2.2 bouyer
276 1.5.2.2 bouyer if (bus >= 256 || device >= 32 || function >= 8)
277 1.5.2.2 bouyer panic("necpb_make_tag: bad request");
278 1.5.2.2 bouyer
279 1.5.2.2 bouyer tag = 0x80000000 | (bus << 16) | (device << 11) | (function << 8);
280 1.5.2.2 bouyer return (tag);
281 1.5.2.2 bouyer }
282 1.5.2.2 bouyer
283 1.5.2.2 bouyer void
284 1.5.2.2 bouyer necpb_decompose_tag(pc, tag, bp, dp, fp)
285 1.5.2.2 bouyer pci_chipset_tag_t pc;
286 1.5.2.2 bouyer pcitag_t tag;
287 1.5.2.2 bouyer int *bp, *dp, *fp;
288 1.5.2.2 bouyer {
289 1.5.2.2 bouyer if (bp != NULL)
290 1.5.2.2 bouyer *bp = (tag >> 16) & 0xff;
291 1.5.2.2 bouyer if (dp != NULL)
292 1.5.2.2 bouyer *dp = (tag >> 11) & 0x1f;
293 1.5.2.2 bouyer if (fp != NULL)
294 1.5.2.2 bouyer *fp = (tag >> 8) & 0x07;
295 1.5.2.2 bouyer }
296 1.5.2.2 bouyer
297 1.5.2.2 bouyer pcireg_t
298 1.5.2.2 bouyer necpb_conf_read(pc, tag, reg)
299 1.5.2.2 bouyer pci_chipset_tag_t pc;
300 1.5.2.2 bouyer pcitag_t tag;
301 1.5.2.2 bouyer int reg;
302 1.5.2.2 bouyer {
303 1.5.2.2 bouyer pcireg_t data;
304 1.5.2.2 bouyer int s;
305 1.5.2.2 bouyer
306 1.5.2.2 bouyer s = splhigh();
307 1.5.2.2 bouyer out32(RD94_SYS_PCI_CONFADDR, tag | reg);
308 1.5.2.2 bouyer data = in32(RD94_SYS_PCI_CONFDATA);
309 1.5.2.2 bouyer out32(RD94_SYS_PCI_CONFADDR, 0);
310 1.5.2.2 bouyer splx(s);
311 1.5.2.2 bouyer
312 1.5.2.2 bouyer return (data);
313 1.5.2.2 bouyer }
314 1.5.2.2 bouyer
315 1.5.2.2 bouyer void
316 1.5.2.2 bouyer necpb_conf_write(pc, tag, reg, data)
317 1.5.2.2 bouyer pci_chipset_tag_t pc;
318 1.5.2.2 bouyer pcitag_t tag;
319 1.5.2.2 bouyer int reg;
320 1.5.2.2 bouyer pcireg_t data;
321 1.5.2.2 bouyer {
322 1.5.2.2 bouyer int s;
323 1.5.2.2 bouyer
324 1.5.2.2 bouyer s = splhigh();
325 1.5.2.2 bouyer out32(RD94_SYS_PCI_CONFADDR, tag | reg);
326 1.5.2.2 bouyer out32(RD94_SYS_PCI_CONFDATA, data);
327 1.5.2.2 bouyer out32(RD94_SYS_PCI_CONFADDR, 0);
328 1.5.2.2 bouyer splx(s);
329 1.5.2.2 bouyer }
330 1.5.2.2 bouyer
331 1.5.2.2 bouyer int
332 1.5.2.5 bouyer necpb_intr_map(pa, ihp)
333 1.5.2.5 bouyer struct pci_attach_args *pa;
334 1.5.2.2 bouyer pci_intr_handle_t *ihp;
335 1.5.2.2 bouyer {
336 1.5.2.5 bouyer pci_chipset_tag_t pc = pa->pa_pc;
337 1.5.2.5 bouyer pcitag_t intrtag = pa->pa_intrtag;
338 1.5.2.5 bouyer int pin = pa->pa_intrpin;
339 1.5.2.2 bouyer int bus, dev;
340 1.5.2.2 bouyer
341 1.5.2.2 bouyer if (pin == 0) {
342 1.5.2.2 bouyer /* No IRQ used. */
343 1.5.2.2 bouyer *ihp = -1;
344 1.5.2.2 bouyer return (1);
345 1.5.2.2 bouyer }
346 1.5.2.2 bouyer
347 1.5.2.2 bouyer if (pin > 4) {
348 1.5.2.2 bouyer printf("necpb_intr_map: bad interrupt pin %d\n", pin);
349 1.5.2.2 bouyer *ihp = -1;
350 1.5.2.2 bouyer return (1);
351 1.5.2.2 bouyer }
352 1.5.2.2 bouyer
353 1.5.2.2 bouyer necpb_decompose_tag(pc, intrtag, &bus, &dev, NULL);
354 1.5.2.2 bouyer if (bus != 0) {
355 1.5.2.2 bouyer *ihp = -1;
356 1.5.2.2 bouyer return (1);
357 1.5.2.2 bouyer }
358 1.5.2.2 bouyer
359 1.5.2.2 bouyer switch (dev) {
360 1.5.2.2 bouyer case 3:
361 1.5.2.2 bouyer *ihp = (pin+2) % 4;
362 1.5.2.2 bouyer break;
363 1.5.2.2 bouyer case 4:
364 1.5.2.2 bouyer *ihp = (pin+1) % 4;
365 1.5.2.2 bouyer break;
366 1.5.2.2 bouyer case 5:
367 1.5.2.2 bouyer *ihp = (pin) % 4;
368 1.5.2.2 bouyer break;
369 1.5.2.2 bouyer default:
370 1.5.2.2 bouyer *ihp = -1;
371 1.5.2.2 bouyer return (1);
372 1.5.2.2 bouyer }
373 1.5.2.2 bouyer
374 1.5.2.2 bouyer return (0);
375 1.5.2.2 bouyer }
376 1.5.2.2 bouyer
377 1.5.2.2 bouyer const char *
378 1.5.2.2 bouyer necpb_intr_string(pc, ih)
379 1.5.2.2 bouyer pci_chipset_tag_t pc;
380 1.5.2.2 bouyer pci_intr_handle_t ih;
381 1.5.2.2 bouyer {
382 1.5.2.2 bouyer static char str[8];
383 1.5.2.2 bouyer
384 1.5.2.2 bouyer if (ih >= 4)
385 1.5.2.3 bouyer panic("necpb_intr_string: bogus handle %ld", ih);
386 1.5.2.2 bouyer sprintf(str, "int %c", 'A' + (int)ih);
387 1.5.2.2 bouyer return (str);
388 1.5.2.2 bouyer }
389 1.5.2.2 bouyer
390 1.5.2.2 bouyer void *
391 1.5.2.2 bouyer necpb_intr_establish(pc, ih, level, func, arg)
392 1.5.2.2 bouyer pci_chipset_tag_t pc;
393 1.5.2.2 bouyer pci_intr_handle_t ih;
394 1.5.2.2 bouyer int level, (*func) __P((void *));
395 1.5.2.2 bouyer void *arg;
396 1.5.2.2 bouyer {
397 1.5.2.2 bouyer struct necpb_intrhand *n, *p;
398 1.5.2.2 bouyer u_int32_t mask;
399 1.5.2.2 bouyer
400 1.5.2.2 bouyer if (ih >= 4)
401 1.5.2.2 bouyer panic("necpb_intr_establish: bogus handle");
402 1.5.2.2 bouyer
403 1.5.2.2 bouyer n = malloc(sizeof(struct necpb_intrhand), M_DEVBUF, M_NOWAIT);
404 1.5.2.2 bouyer if (n == NULL)
405 1.5.2.2 bouyer panic("necpb_intr_establish: can't malloc interrupt handle");
406 1.5.2.2 bouyer
407 1.5.2.2 bouyer n->ih_func = func;
408 1.5.2.2 bouyer n->ih_arg = arg;
409 1.5.2.2 bouyer n->ih_next = NULL;
410 1.5.2.2 bouyer n->ih_intn = ih;
411 1.5.2.2 bouyer
412 1.5.2.2 bouyer if (necpb_inttbl[ih] == NULL) {
413 1.5.2.2 bouyer necpb_inttbl[ih] = n;
414 1.5.2.2 bouyer mask = in32(RD94_SYS_PCI_INTMASK);
415 1.5.2.2 bouyer mask |= 1 << ih;
416 1.5.2.2 bouyer out32(RD94_SYS_PCI_INTMASK, mask);
417 1.5.2.2 bouyer } else {
418 1.5.2.2 bouyer p = necpb_inttbl[ih];
419 1.5.2.2 bouyer while (p->ih_next != NULL)
420 1.5.2.2 bouyer p = p->ih_next;
421 1.5.2.2 bouyer p->ih_next = n;
422 1.5.2.2 bouyer }
423 1.5.2.2 bouyer
424 1.5.2.2 bouyer return n;
425 1.5.2.2 bouyer }
426 1.5.2.2 bouyer
427 1.5.2.2 bouyer void
428 1.5.2.2 bouyer necpb_intr_disestablish(pc, cookie)
429 1.5.2.2 bouyer pci_chipset_tag_t pc;
430 1.5.2.2 bouyer void *cookie;
431 1.5.2.2 bouyer {
432 1.5.2.2 bouyer struct necpb_intrhand *n, *p, *q;
433 1.5.2.2 bouyer u_int32_t mask;
434 1.5.2.2 bouyer
435 1.5.2.2 bouyer n = cookie;
436 1.5.2.2 bouyer
437 1.5.2.2 bouyer q = NULL;
438 1.5.2.2 bouyer p = necpb_inttbl[n->ih_intn];
439 1.5.2.2 bouyer while (p != n) {
440 1.5.2.2 bouyer if (p == NULL)
441 1.5.2.2 bouyer panic("necpb_intr_disestablish: broken intr table");
442 1.5.2.2 bouyer q = p;
443 1.5.2.2 bouyer p = p->ih_next;
444 1.5.2.2 bouyer }
445 1.5.2.2 bouyer
446 1.5.2.2 bouyer if (q == NULL) {
447 1.5.2.2 bouyer necpb_inttbl[n->ih_intn] = n->ih_next;
448 1.5.2.2 bouyer if (n->ih_next == NULL) {
449 1.5.2.2 bouyer mask = in32(RD94_SYS_PCI_INTMASK);
450 1.5.2.2 bouyer mask &= ~(1 << n->ih_intn);
451 1.5.2.2 bouyer out32(RD94_SYS_PCI_INTMASK, mask);
452 1.5.2.2 bouyer }
453 1.5.2.2 bouyer } else
454 1.5.2.2 bouyer q->ih_next = n->ih_next;
455 1.5.2.2 bouyer
456 1.5.2.2 bouyer free(n, M_DEVBUF);
457 1.5.2.2 bouyer }
458 1.5.2.2 bouyer
459 1.5.2.2 bouyer /*
460 1.5.2.2 bouyer * Handle PCI/EISA interrupt.
461 1.5.2.2 bouyer */
462 1.5.2.2 bouyer int
463 1.5.2.2 bouyer necpb_intr(mask, cf)
464 1.5.2.2 bouyer unsigned mask;
465 1.5.2.2 bouyer struct clockframe *cf;
466 1.5.2.2 bouyer {
467 1.5.2.2 bouyer u_int32_t vector, stat;
468 1.5.2.2 bouyer struct necpb_intrhand *p;
469 1.5.2.2 bouyer int a;
470 1.5.2.2 bouyer
471 1.5.2.2 bouyer vector = in32(RD94_SYS_INTSTAT2) & 0xffff;
472 1.5.2.2 bouyer
473 1.5.2.2 bouyer if (vector == 0x4000) {
474 1.5.2.2 bouyer stat = in32(RD94_SYS_PCI_INTSTAT);
475 1.5.2.2 bouyer stat &= in32(RD94_SYS_PCI_INTMASK);
476 1.5.2.2 bouyer for (a=0; a<4; a++) {
477 1.5.2.2 bouyer if (stat & (1 << a)) {
478 1.5.2.2 bouyer #if 0
479 1.5.2.2 bouyer printf("pint %d\n", a);
480 1.5.2.2 bouyer #endif
481 1.5.2.2 bouyer p = necpb_inttbl[a];
482 1.5.2.2 bouyer while (p != NULL) {
483 1.5.2.2 bouyer (*p->ih_func)(p->ih_arg);
484 1.5.2.2 bouyer p = p->ih_next;
485 1.5.2.2 bouyer }
486 1.5.2.2 bouyer }
487 1.5.2.2 bouyer }
488 1.5.2.2 bouyer } else if (vector == 0x8000) {
489 1.5.2.2 bouyer printf("eisa_nmi\n");
490 1.5.2.2 bouyer } else {
491 1.5.2.2 bouyer printf("eint %d\n", vector & 0xff);
492 1.5.2.2 bouyer #if 0
493 1.5.2.2 bouyer eisa_intr(vector & 0xff);
494 1.5.2.2 bouyer #endif
495 1.5.2.2 bouyer }
496 1.5.2.2 bouyer
497 1.5.2.2 bouyer return (~0);
498 1.5.2.2 bouyer }
499