pcc.c revision 1.19 1 1.19 scw /* $NetBSD: pcc.c,v 1.19 2001/07/06 19:00: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.13 scw {"clock", PCC_RTC_OFF},
116 1.13 scw {"nvram", PCC_NVRAM_OFF},
117 1.13 scw {"zsc", PCC_ZS0_OFF},
118 1.13 scw {"zsc", PCC_ZS1_OFF},
119 1.13 scw {"le", PCC_LE_OFF},
120 1.13 scw {"wdsc", PCC_WDSC_OFF},
121 1.13 scw {"lpt", PCC_LPT_OFF},
122 1.13 scw {"vmepcc", PCC_VME_OFF},
123 1.13 scw {NULL, 0},
124 1.13 scw };
125 1.13 scw
126 1.13 scw static int pcc_vec2intctrl[] = {
127 1.13 scw PCCREG_ACFAIL_INTR_CTRL,/* PCCV_ACFAIL */
128 1.13 scw PCCREG_BUSERR_INTR_CTRL,/* PCCV_BERR */
129 1.13 scw PCCREG_ABORT_INTR_CTRL, /* PCCV_ABORT */
130 1.13 scw PCCREG_SERIAL_INTR_CTRL,/* PCCV_ZS */
131 1.13 scw PCCREG_LANCE_INTR_CTRL, /* PCCV_LE */
132 1.13 scw PCCREG_SCSI_INTR_CTRL, /* PCCV_SCSI */
133 1.13 scw PCCREG_DMA_INTR_CTRL, /* PCCV_DMA */
134 1.13 scw PCCREG_PRNT_INTR_CTRL, /* PCCV_PRINTER */
135 1.13 scw PCCREG_TMR1_INTR_CTRL, /* PCCV_TIMER1 */
136 1.13 scw PCCREG_TMR2_INTR_CTRL, /* PCCV_TIMER2 */
137 1.13 scw PCCREG_SOFT1_INTR_CTRL, /* PCCV_SOFT1 */
138 1.13 scw PCCREG_SOFT2_INTR_CTRL /* PCCV_SOFT2 */
139 1.3 chuck };
140 1.1 chuck
141 1.14 scw extern phys_ram_seg_t mem_clusters[];
142 1.13 scw struct pcc_softc *sys_pcc;
143 1.13 scw
144 1.14 scw /* The base address of the MVME147 from the VMEbus */
145 1.14 scw bus_addr_t pcc_slave_base_addr;
146 1.14 scw
147 1.14 scw
148 1.13 scw /* ARGSUSED */
149 1.1 chuck int
150 1.9 gwr pccmatch(parent, cf, args)
151 1.1 chuck struct device *parent;
152 1.9 gwr struct cfdata *cf;
153 1.9 gwr void *args;
154 1.1 chuck {
155 1.13 scw struct mainbus_attach_args *ma;
156 1.13 scw
157 1.13 scw ma = args;
158 1.3 chuck
159 1.3 chuck /* Only attach one PCC. */
160 1.3 chuck if (sys_pcc)
161 1.3 chuck return (0);
162 1.1 chuck
163 1.13 scw return (strcmp(ma->ma_name, pcc_cd.cd_name) == 0);
164 1.1 chuck }
165 1.1 chuck
166 1.13 scw /* ARGSUSED */
167 1.1 chuck void
168 1.1 chuck pccattach(parent, self, args)
169 1.13 scw struct device *parent;
170 1.13 scw struct device *self;
171 1.1 chuck void *args;
172 1.1 chuck {
173 1.13 scw struct mainbus_attach_args *ma;
174 1.3 chuck struct pcc_attach_args npa;
175 1.13 scw struct pcc_softc *sc;
176 1.13 scw u_int8_t reg;
177 1.6 thorpej int i;
178 1.1 chuck
179 1.13 scw ma = args;
180 1.13 scw sc = sys_pcc = (struct pcc_softc *) self;
181 1.1 chuck
182 1.13 scw /* Get a handle to the PCC's registers. */
183 1.13 scw sc->sc_bust = ma->ma_bust;
184 1.13 scw bus_space_map(sc->sc_bust, PCC_REG_OFF + ma->ma_offset,
185 1.13 scw PCCREG_SIZE, 0, &sc->sc_bush);
186 1.1 chuck
187 1.13 scw /* Tell the chip the base interrupt vector */
188 1.13 scw pcc_reg_write(sc, PCCREG_VECTOR_BASE, PCC_VECBASE);
189 1.1 chuck
190 1.8 christos printf(": Peripheral Channel Controller, "
191 1.13 scw "rev %d, vecbase 0x%x\n", pcc_reg_read(sc, PCCREG_REVISION),
192 1.13 scw pcc_reg_read(sc, PCCREG_VECTOR_BASE));
193 1.3 chuck
194 1.18 scw evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
195 1.18 scw isrlink_evcnt(7), "nmi", "abort sw");
196 1.18 scw
197 1.13 scw /* Hook up interrupt handler for abort button, and enable it */
198 1.18 scw pccintr_establish(PCCV_ABORT, pccintr, 7, NULL, &sc->sc_evcnt);
199 1.13 scw pcc_reg_write(sc, PCCREG_ABORT_INTR_CTRL,
200 1.13 scw PCC_ABORT_IEN | PCC_ABORT_ACK);
201 1.3 chuck
202 1.19 scw /*
203 1.19 scw * Install a handler for Software Interrupt 1
204 1.19 scw * and arrange to schedule soft interrupts on demand.
205 1.19 scw */
206 1.19 scw pccintr_establish(PCCV_SOFT1, pccsoftintr, 1, sc, &sc->sc_evcnt);
207 1.19 scw _softintr_chipset_assert = pccsoftintrassert;
208 1.19 scw
209 1.3 chuck /* Make sure the global interrupt line is hot. */
210 1.13 scw reg = pcc_reg_read(sc, PCCREG_GENERAL_CONTROL) | PCC_GENCR_IEN;
211 1.13 scw pcc_reg_write(sc, PCCREG_GENERAL_CONTROL, reg);
212 1.14 scw
213 1.14 scw /*
214 1.14 scw * Calculate the board's VMEbus slave base address, for the
215 1.14 scw * benefit of the VMEchip driver.
216 1.14 scw * (Weird that this register is in the PCC ...)
217 1.14 scw */
218 1.14 scw reg = pcc_reg_read(sc, PCCREG_SLAVE_BASE_ADDR) & PCC_SLAVE_BASE_MASK;
219 1.14 scw pcc_slave_base_addr = (bus_addr_t)reg * mem_clusters[0].size;
220 1.3 chuck
221 1.3 chuck /*
222 1.3 chuck * Attach configured children.
223 1.3 chuck */
224 1.15 scw npa._pa_base = ma->ma_offset;
225 1.3 chuck for (i = 0; pcc_devices[i].pcc_name != NULL; ++i) {
226 1.3 chuck /*
227 1.3 chuck * Note that IPL is filled in by match function.
228 1.3 chuck */
229 1.3 chuck npa.pa_name = pcc_devices[i].pcc_name;
230 1.3 chuck npa.pa_ipl = -1;
231 1.13 scw npa.pa_dmat = ma->ma_dmat;
232 1.13 scw npa.pa_bust = ma->ma_bust;
233 1.13 scw npa.pa_offset = pcc_devices[i].pcc_offset + ma->ma_offset;
234 1.3 chuck
235 1.3 chuck /* Attach the device if configured. */
236 1.13 scw (void) config_found(self, &npa, pccprint);
237 1.3 chuck }
238 1.1 chuck }
239 1.1 chuck
240 1.1 chuck int
241 1.3 chuck pccprint(aux, cp)
242 1.3 chuck void *aux;
243 1.5 cgd const char *cp;
244 1.1 chuck {
245 1.13 scw struct pcc_attach_args *pa;
246 1.13 scw
247 1.13 scw pa = aux;
248 1.3 chuck
249 1.3 chuck if (cp)
250 1.8 christos printf("%s at %s", pa->pa_name, cp);
251 1.3 chuck
252 1.15 scw printf(" offset 0x%lx", pa->pa_offset - pa->_pa_base);
253 1.3 chuck if (pa->pa_ipl != -1)
254 1.8 christos printf(" ipl %d", pa->pa_ipl);
255 1.1 chuck
256 1.3 chuck return (UNCONF);
257 1.1 chuck }
258 1.1 chuck
259 1.1 chuck /*
260 1.1 chuck * pccintr_establish: establish pcc interrupt
261 1.1 chuck */
262 1.3 chuck void
263 1.18 scw pccintr_establish(pccvec, hand, lvl, arg, evcnt)
264 1.3 chuck int pccvec;
265 1.3 chuck int (*hand) __P((void *)), lvl;
266 1.1 chuck void *arg;
267 1.18 scw struct evcnt *evcnt;
268 1.1 chuck {
269 1.3 chuck
270 1.13 scw #ifdef DEBUG
271 1.13 scw if (pccvec < 0 || pccvec >= PCC_NVEC) {
272 1.8 christos printf("pcc: illegal vector offset: 0x%x\n", pccvec);
273 1.1 chuck panic("pccintr_establish");
274 1.1 chuck }
275 1.13 scw if (lvl < 1 || lvl > 7) {
276 1.8 christos printf("pcc: illegal interrupt level: %d\n", lvl);
277 1.1 chuck panic("pccintr_establish");
278 1.1 chuck }
279 1.13 scw #endif
280 1.1 chuck
281 1.18 scw isrlink_vectored(hand, arg, lvl, pccvec + PCC_VECBASE, evcnt);
282 1.3 chuck }
283 1.3 chuck
284 1.3 chuck void
285 1.3 chuck pccintr_disestablish(pccvec)
286 1.3 chuck int pccvec;
287 1.3 chuck {
288 1.3 chuck
289 1.13 scw #ifdef DEBUG
290 1.13 scw if (pccvec < 0 || pccvec >= PCC_NVEC) {
291 1.8 christos printf("pcc: illegal vector offset: 0x%x\n", pccvec);
292 1.13 scw panic("pccintr_disestablish");
293 1.3 chuck }
294 1.13 scw #endif
295 1.3 chuck
296 1.13 scw /* Disable the interrupt */
297 1.13 scw pcc_reg_write(sys_pcc, pcc_vec2intctrl[pccvec], PCC_ICLEAR);
298 1.3 chuck isrunlink_vectored(pccvec + PCC_VECBASE);
299 1.3 chuck }
300 1.3 chuck
301 1.3 chuck /*
302 1.3 chuck * Handle NMI from abort switch.
303 1.3 chuck */
304 1.13 scw static int
305 1.3 chuck pccintr(frame)
306 1.3 chuck void *frame;
307 1.3 chuck {
308 1.3 chuck
309 1.3 chuck /* XXX wait until button pops out */
310 1.13 scw pcc_reg_write(sys_pcc, PCCREG_ABORT_INTR_CTRL,
311 1.13 scw PCC_ABORT_IEN | PCC_ABORT_ACK);
312 1.13 scw
313 1.13 scw return (nmihand(frame));
314 1.19 scw }
315 1.19 scw
316 1.19 scw static void
317 1.19 scw pccsoftintrassert(void)
318 1.19 scw {
319 1.19 scw
320 1.19 scw /* Request a software interrupt at ipl 1 */
321 1.19 scw pcc_reg_write(sys_pcc, PCCREG_SOFT1_INTR_CTRL, 1 | PCC_IENABLE);
322 1.19 scw }
323 1.19 scw
324 1.19 scw /*
325 1.19 scw * Handle PCC soft interupt #1
326 1.19 scw */
327 1.19 scw static int
328 1.19 scw pccsoftintr(arg)
329 1.19 scw void *arg;
330 1.19 scw {
331 1.19 scw struct pcc_softc *sc = arg;
332 1.19 scw
333 1.19 scw /* Clear the interrupt */
334 1.19 scw pcc_reg_write(sc, PCCREG_SOFT1_INTR_CTRL, 0);
335 1.19 scw
336 1.19 scw /* Call the soft interrupt dispatcher */
337 1.19 scw softintr_dispatch();
338 1.19 scw
339 1.19 scw return (1);
340 1.1 chuck }
341