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