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