pcc.c revision 1.20 1 1.20 scw /* $NetBSD: pcc.c,v 1.20 2001/08/12 18:33:13 scw Exp $ */
2 1.10 thorpej
3 1.10 thorpej /*-
4 1.10 thorpej * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5 1.10 thorpej * All rights reserved.
6 1.10 thorpej *
7 1.10 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.13 scw * by Jason R. Thorpe and Steve C. Woodford.
9 1.10 thorpej *
10 1.10 thorpej * Redistribution and use in source and binary forms, with or without
11 1.10 thorpej * modification, are permitted provided that the following conditions
12 1.10 thorpej * are met:
13 1.10 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.10 thorpej * notice, this list of conditions and the following disclaimer.
15 1.10 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.10 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.10 thorpej * documentation and/or other materials provided with the distribution.
18 1.10 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.10 thorpej * must display the following acknowledgement:
20 1.10 thorpej * This product includes software developed by the NetBSD
21 1.10 thorpej * Foundation, Inc. and its contributors.
22 1.10 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.10 thorpej * contributors may be used to endorse or promote products derived
24 1.10 thorpej * from this software without specific prior written permission.
25 1.10 thorpej *
26 1.10 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.10 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.10 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.10 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.10 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.10 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.10 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.10 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.10 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.10 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.10 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.10 thorpej */
38 1.1 chuck
39 1.1 chuck /*
40 1.1 chuck * Copyright (c) 1995 Charles D. Cranor
41 1.1 chuck * All rights reserved.
42 1.1 chuck *
43 1.1 chuck * Redistribution and use in source and binary forms, with or without
44 1.1 chuck * modification, are permitted provided that the following conditions
45 1.1 chuck * are met:
46 1.1 chuck * 1. Redistributions of source code must retain the above copyright
47 1.1 chuck * notice, this list of conditions and the following disclaimer.
48 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 chuck * notice, this list of conditions and the following disclaimer in the
50 1.1 chuck * documentation and/or other materials provided with the distribution.
51 1.1 chuck * 3. All advertising materials mentioning features or use of this software
52 1.1 chuck * must display the following acknowledgement:
53 1.1 chuck * This product includes software developed by Charles D. Cranor.
54 1.1 chuck * 4. The name of the author may not be used to endorse or promote products
55 1.1 chuck * derived from this software without specific prior written permission.
56 1.1 chuck *
57 1.1 chuck * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 1.1 chuck * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 1.1 chuck * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 1.1 chuck * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 1.1 chuck * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62 1.1 chuck * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 1.1 chuck * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 1.1 chuck * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 1.1 chuck * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66 1.1 chuck * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 1.1 chuck */
68 1.1 chuck
69 1.1 chuck /*
70 1.1 chuck * peripheral channel controller
71 1.1 chuck */
72 1.12 scw
73 1.1 chuck #include <sys/param.h>
74 1.13 scw #include <sys/kernel.h>
75 1.1 chuck #include <sys/systm.h>
76 1.1 chuck #include <sys/device.h>
77 1.14 scw #include <sys/kcore.h>
78 1.13 scw
79 1.1 chuck #include <machine/cpu.h>
80 1.13 scw #include <machine/bus.h>
81 1.3 chuck
82 1.13 scw #include <mvme68k/dev/mainbus.h>
83 1.1 chuck #include <mvme68k/dev/pccreg.h>
84 1.3 chuck #include <mvme68k/dev/pccvar.h>
85 1.1 chuck
86 1.1 chuck /*
87 1.13 scw * Autoconfiguration stuff for the PCC chip on mvme147
88 1.1 chuck */
89 1.1 chuck
90 1.13 scw void pccattach __P((struct device *, struct device *, void *));
91 1.13 scw int pccmatch __P((struct device *, struct cfdata *, void *));
92 1.13 scw int pccprint __P((void *, const char *));
93 1.1 chuck
94 1.2 thorpej struct cfattach pcc_ca = {
95 1.13 scw sizeof(struct pcc_softc), pccmatch, pccattach
96 1.2 thorpej };
97 1.2 thorpej
98 1.11 thorpej extern struct cfdriver pcc_cd;
99 1.13 scw static int pccintr __P((void *));
100 1.19 scw static int pccsoftintr __P((void *));
101 1.19 scw static void pccsoftintrassert __P((void));
102 1.3 chuck
103 1.1 chuck /*
104 1.13 scw * Structure used to describe a device for autoconfiguration purposes.
105 1.1 chuck */
106 1.13 scw struct pcc_device {
107 1.13 scw char *pcc_name; /* name of device (e.g. "clock") */
108 1.13 scw bus_addr_t pcc_offset; /* offset from PCC base */
109 1.13 scw };
110 1.1 chuck
111 1.3 chuck /*
112 1.3 chuck * Devices that live on the PCC, attached in this order.
113 1.3 chuck */
114 1.13 scw static struct pcc_device pcc_devices[] = {
115 1.20 scw {"clock", 0},
116 1.13 scw {"zsc", PCC_ZS0_OFF},
117 1.13 scw {"zsc", PCC_ZS1_OFF},
118 1.13 scw {"le", PCC_LE_OFF},
119 1.13 scw {"wdsc", PCC_WDSC_OFF},
120 1.13 scw {"lpt", PCC_LPT_OFF},
121 1.13 scw {"vmepcc", PCC_VME_OFF},
122 1.13 scw {NULL, 0},
123 1.13 scw };
124 1.13 scw
125 1.13 scw static int pcc_vec2intctrl[] = {
126 1.13 scw PCCREG_ACFAIL_INTR_CTRL,/* PCCV_ACFAIL */
127 1.13 scw PCCREG_BUSERR_INTR_CTRL,/* PCCV_BERR */
128 1.13 scw PCCREG_ABORT_INTR_CTRL, /* PCCV_ABORT */
129 1.13 scw PCCREG_SERIAL_INTR_CTRL,/* PCCV_ZS */
130 1.13 scw PCCREG_LANCE_INTR_CTRL, /* PCCV_LE */
131 1.13 scw PCCREG_SCSI_INTR_CTRL, /* PCCV_SCSI */
132 1.13 scw PCCREG_DMA_INTR_CTRL, /* PCCV_DMA */
133 1.13 scw PCCREG_PRNT_INTR_CTRL, /* PCCV_PRINTER */
134 1.13 scw PCCREG_TMR1_INTR_CTRL, /* PCCV_TIMER1 */
135 1.13 scw PCCREG_TMR2_INTR_CTRL, /* PCCV_TIMER2 */
136 1.13 scw PCCREG_SOFT1_INTR_CTRL, /* PCCV_SOFT1 */
137 1.13 scw PCCREG_SOFT2_INTR_CTRL /* PCCV_SOFT2 */
138 1.3 chuck };
139 1.1 chuck
140 1.14 scw extern phys_ram_seg_t mem_clusters[];
141 1.13 scw struct pcc_softc *sys_pcc;
142 1.13 scw
143 1.14 scw /* The base address of the MVME147 from the VMEbus */
144 1.14 scw bus_addr_t pcc_slave_base_addr;
145 1.14 scw
146 1.14 scw
147 1.13 scw /* ARGSUSED */
148 1.1 chuck int
149 1.9 gwr pccmatch(parent, cf, args)
150 1.1 chuck struct device *parent;
151 1.9 gwr struct cfdata *cf;
152 1.9 gwr void *args;
153 1.1 chuck {
154 1.13 scw struct mainbus_attach_args *ma;
155 1.13 scw
156 1.13 scw ma = args;
157 1.3 chuck
158 1.3 chuck /* Only attach one PCC. */
159 1.3 chuck if (sys_pcc)
160 1.3 chuck return (0);
161 1.1 chuck
162 1.13 scw return (strcmp(ma->ma_name, pcc_cd.cd_name) == 0);
163 1.1 chuck }
164 1.1 chuck
165 1.13 scw /* ARGSUSED */
166 1.1 chuck void
167 1.1 chuck pccattach(parent, self, args)
168 1.13 scw struct device *parent;
169 1.13 scw struct device *self;
170 1.1 chuck void *args;
171 1.1 chuck {
172 1.13 scw struct mainbus_attach_args *ma;
173 1.3 chuck struct pcc_attach_args npa;
174 1.13 scw struct pcc_softc *sc;
175 1.13 scw u_int8_t reg;
176 1.6 thorpej int i;
177 1.1 chuck
178 1.13 scw ma = args;
179 1.13 scw sc = sys_pcc = (struct pcc_softc *) self;
180 1.1 chuck
181 1.13 scw /* Get a handle to the PCC's registers. */
182 1.13 scw sc->sc_bust = ma->ma_bust;
183 1.20 scw bus_space_map(sc->sc_bust, ma->ma_offset, PCCREG_SIZE, 0, &sc->sc_bush);
184 1.1 chuck
185 1.13 scw /* Tell the chip the base interrupt vector */
186 1.13 scw pcc_reg_write(sc, PCCREG_VECTOR_BASE, PCC_VECBASE);
187 1.1 chuck
188 1.8 christos printf(": Peripheral Channel Controller, "
189 1.13 scw "rev %d, vecbase 0x%x\n", pcc_reg_read(sc, PCCREG_REVISION),
190 1.13 scw pcc_reg_read(sc, PCCREG_VECTOR_BASE));
191 1.3 chuck
192 1.18 scw evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
193 1.18 scw isrlink_evcnt(7), "nmi", "abort sw");
194 1.18 scw
195 1.13 scw /* Hook up interrupt handler for abort button, and enable it */
196 1.18 scw pccintr_establish(PCCV_ABORT, pccintr, 7, NULL, &sc->sc_evcnt);
197 1.13 scw pcc_reg_write(sc, PCCREG_ABORT_INTR_CTRL,
198 1.13 scw PCC_ABORT_IEN | PCC_ABORT_ACK);
199 1.3 chuck
200 1.19 scw /*
201 1.19 scw * Install a handler for Software Interrupt 1
202 1.19 scw * and arrange to schedule soft interrupts on demand.
203 1.19 scw */
204 1.19 scw pccintr_establish(PCCV_SOFT1, pccsoftintr, 1, sc, &sc->sc_evcnt);
205 1.19 scw _softintr_chipset_assert = pccsoftintrassert;
206 1.19 scw
207 1.3 chuck /* Make sure the global interrupt line is hot. */
208 1.13 scw reg = pcc_reg_read(sc, PCCREG_GENERAL_CONTROL) | PCC_GENCR_IEN;
209 1.13 scw pcc_reg_write(sc, PCCREG_GENERAL_CONTROL, reg);
210 1.14 scw
211 1.14 scw /*
212 1.14 scw * Calculate the board's VMEbus slave base address, for the
213 1.14 scw * benefit of the VMEchip driver.
214 1.14 scw * (Weird that this register is in the PCC ...)
215 1.14 scw */
216 1.14 scw reg = pcc_reg_read(sc, PCCREG_SLAVE_BASE_ADDR) & PCC_SLAVE_BASE_MASK;
217 1.14 scw pcc_slave_base_addr = (bus_addr_t)reg * mem_clusters[0].size;
218 1.3 chuck
219 1.3 chuck /*
220 1.3 chuck * Attach configured children.
221 1.3 chuck */
222 1.15 scw npa._pa_base = ma->ma_offset;
223 1.3 chuck for (i = 0; pcc_devices[i].pcc_name != NULL; ++i) {
224 1.3 chuck /*
225 1.3 chuck * Note that IPL is filled in by match function.
226 1.3 chuck */
227 1.3 chuck npa.pa_name = pcc_devices[i].pcc_name;
228 1.3 chuck npa.pa_ipl = -1;
229 1.13 scw npa.pa_dmat = ma->ma_dmat;
230 1.13 scw npa.pa_bust = ma->ma_bust;
231 1.13 scw npa.pa_offset = pcc_devices[i].pcc_offset + ma->ma_offset;
232 1.3 chuck
233 1.3 chuck /* Attach the device if configured. */
234 1.13 scw (void) config_found(self, &npa, pccprint);
235 1.3 chuck }
236 1.1 chuck }
237 1.1 chuck
238 1.1 chuck int
239 1.3 chuck pccprint(aux, cp)
240 1.3 chuck void *aux;
241 1.5 cgd const char *cp;
242 1.1 chuck {
243 1.13 scw struct pcc_attach_args *pa;
244 1.13 scw
245 1.13 scw pa = aux;
246 1.3 chuck
247 1.3 chuck if (cp)
248 1.8 christos printf("%s at %s", pa->pa_name, cp);
249 1.3 chuck
250 1.15 scw printf(" offset 0x%lx", pa->pa_offset - pa->_pa_base);
251 1.3 chuck if (pa->pa_ipl != -1)
252 1.8 christos printf(" ipl %d", pa->pa_ipl);
253 1.1 chuck
254 1.3 chuck return (UNCONF);
255 1.1 chuck }
256 1.1 chuck
257 1.1 chuck /*
258 1.1 chuck * pccintr_establish: establish pcc interrupt
259 1.1 chuck */
260 1.3 chuck void
261 1.18 scw pccintr_establish(pccvec, hand, lvl, arg, evcnt)
262 1.3 chuck int pccvec;
263 1.3 chuck int (*hand) __P((void *)), lvl;
264 1.1 chuck void *arg;
265 1.18 scw struct evcnt *evcnt;
266 1.1 chuck {
267 1.3 chuck
268 1.13 scw #ifdef DEBUG
269 1.13 scw if (pccvec < 0 || pccvec >= PCC_NVEC) {
270 1.8 christos printf("pcc: illegal vector offset: 0x%x\n", pccvec);
271 1.1 chuck panic("pccintr_establish");
272 1.1 chuck }
273 1.13 scw if (lvl < 1 || lvl > 7) {
274 1.8 christos printf("pcc: illegal interrupt level: %d\n", lvl);
275 1.1 chuck panic("pccintr_establish");
276 1.1 chuck }
277 1.13 scw #endif
278 1.1 chuck
279 1.18 scw isrlink_vectored(hand, arg, lvl, pccvec + PCC_VECBASE, evcnt);
280 1.3 chuck }
281 1.3 chuck
282 1.3 chuck void
283 1.3 chuck pccintr_disestablish(pccvec)
284 1.3 chuck int pccvec;
285 1.3 chuck {
286 1.3 chuck
287 1.13 scw #ifdef DEBUG
288 1.13 scw if (pccvec < 0 || pccvec >= PCC_NVEC) {
289 1.8 christos printf("pcc: illegal vector offset: 0x%x\n", pccvec);
290 1.13 scw panic("pccintr_disestablish");
291 1.3 chuck }
292 1.13 scw #endif
293 1.3 chuck
294 1.13 scw /* Disable the interrupt */
295 1.13 scw pcc_reg_write(sys_pcc, pcc_vec2intctrl[pccvec], PCC_ICLEAR);
296 1.3 chuck isrunlink_vectored(pccvec + PCC_VECBASE);
297 1.3 chuck }
298 1.3 chuck
299 1.3 chuck /*
300 1.3 chuck * Handle NMI from abort switch.
301 1.3 chuck */
302 1.13 scw static int
303 1.3 chuck pccintr(frame)
304 1.3 chuck void *frame;
305 1.3 chuck {
306 1.3 chuck
307 1.3 chuck /* XXX wait until button pops out */
308 1.13 scw pcc_reg_write(sys_pcc, PCCREG_ABORT_INTR_CTRL,
309 1.13 scw PCC_ABORT_IEN | PCC_ABORT_ACK);
310 1.13 scw
311 1.13 scw return (nmihand(frame));
312 1.19 scw }
313 1.19 scw
314 1.19 scw static void
315 1.19 scw pccsoftintrassert(void)
316 1.19 scw {
317 1.19 scw
318 1.19 scw /* Request a software interrupt at ipl 1 */
319 1.19 scw pcc_reg_write(sys_pcc, PCCREG_SOFT1_INTR_CTRL, 1 | PCC_IENABLE);
320 1.19 scw }
321 1.19 scw
322 1.19 scw /*
323 1.19 scw * Handle PCC soft interupt #1
324 1.19 scw */
325 1.19 scw static int
326 1.19 scw pccsoftintr(arg)
327 1.19 scw void *arg;
328 1.19 scw {
329 1.19 scw struct pcc_softc *sc = arg;
330 1.19 scw
331 1.19 scw /* Clear the interrupt */
332 1.19 scw pcc_reg_write(sc, PCCREG_SOFT1_INTR_CTRL, 0);
333 1.19 scw
334 1.19 scw /* Call the soft interrupt dispatcher */
335 1.19 scw softintr_dispatch();
336 1.19 scw
337 1.19 scw return (1);
338 1.1 chuck }
339