No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / vax / uba / uba_sbi.c
blob6e06095380e3053d187b8da6f561c64bb9b2b6e6
1 /* $NetBSD: uba_sbi.c,v 1.26 2008/12/16 22:35:27 christos Exp $ */
2 /*
3 * Copyright (c) 1982, 1986 The Regents of the University of California.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
30 * @(#)uba.c 7.10 (Berkeley) 12/16/90
31 * @(#)autoconf.c 7.20 (Berkeley) 5/9/91
35 * Copyright (c) 1996 Jonathan Stone.
36 * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
66 * @(#)uba.c 7.10 (Berkeley) 12/16/90
67 * @(#)autoconf.c 7.20 (Berkeley) 5/9/91
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: uba_sbi.c,v 1.26 2008/12/16 22:35:27 christos Exp $");
73 #include <sys/param.h>
74 #include <sys/device.h>
75 #include <sys/systm.h>
76 #include <sys/kernel.h>
78 #define _VAX_BUS_DMA_PRIVATE
79 #include <machine/bus.h>
80 #include <machine/mtpr.h>
81 #include <machine/nexus.h>
82 #include <machine/cpu.h>
83 #include <machine/sgmap.h>
84 #include <machine/scb.h>
86 #include <dev/qbus/ubavar.h>
88 #include <vax/uba/uba_common.h>
90 #include "locators.h"
91 #include "ioconf.h"
93 /* Some SBI-specific defines */
94 #define UBASIZE (UBAPAGES * VAX_NBPG)
95 #define UMEMA8600(i) (0x20100000+(i)*0x40000)
96 #define UMEMB8600(i) (0x22100000+(i)*0x40000)
99 * Some status registers.
101 #define UBACNFGR_UBIC 0x00010000 /* unibus init complete */
102 #define UBACNFGR_BITS \
103 "\40\40PARFLT\37WSQFLT\36URDFLT\35ISQFLT\34MXTFLT\33XMTFLT\30ADPDN\27ADPUP\23UBINIT\22UBPDN\21UBIC"
105 #define UBACR_IFS 0x00000040 /* interrupt field switch */
106 #define UBACR_BRIE 0x00000020 /* BR interrupt enable */
107 #define UBACR_USEFIE 0x00000010 /* UNIBUS to SBI error field IE */
108 #define UBACR_SUEFIE 0x00000008 /* SBI to UNIBUS error field IE */
109 #define UBACR_ADINIT 0x00000001 /* adapter init */
111 #define UBADPR_BNE 0x80000000 /* buffer not empty - purge */
113 #define UBABRRVR_DIV 0x0000ffff /* device interrupt vector field */
115 #define UBASR_BITS \
116 "\20\13RDTO\12RDS\11CRD\10CXTER\7CXTMO\6DPPE\5IVMR\4MRPF\3LEB\2UBSTO\1UBSSYNTO"
118 const char ubasr_bits[] = UBASR_BITS;
121 * The DW780 are directly connected to the SBI on 11/780 and 8600.
123 static int dw780_match(device_t, cfdata_t, void *);
124 static void dw780_attach(device_t, device_t, void *);
125 static void dw780_init(struct uba_softc*);
126 static void dw780_beforescan(struct uba_softc *);
127 static void dw780_afterscan(struct uba_softc *);
128 static int dw780_errchk(struct uba_softc *);
129 static inline void uba_dw780int_common(void *, int);
130 static void uba_dw780int_0x14(void *);
131 static void uba_dw780int_0x15(void *);
132 static void uba_dw780int_0x16(void *);
133 static void uba_dw780int_0x17(void *);
134 static void ubaerror(struct uba_softc *, int *, int *);
135 #ifdef notyet
136 static void dw780_purge(struct uba_softc *, int);
137 #endif
139 CFATTACH_DECL_NEW(uba_sbi, sizeof(struct uba_vsoftc),
140 dw780_match, dw780_attach, NULL, NULL);
142 static struct evcnt strayint = EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "uba","stray intr");
143 static int strayinit = 0;
145 extern struct vax_bus_space vax_mem_bus_space;
148 dw780_match(device_t parent, cfdata_t cf, void *aux)
150 struct sbi_attach_args * const sa = aux;
152 if (cf->cf_loc[SBICF_TR] != sa->sa_nexnum &&
153 cf->cf_loc[SBICF_TR] != SBICF_TR_DEFAULT)
154 return 0;
156 * The uba type is actually only telling where the uba
157 * space is in nexus space.
159 if ((sa->sa_type & ~3) != NEX_UBA0)
160 return 0;
162 return 1;
165 void
166 dw780_attach(device_t parent, device_t self, void *aux)
168 struct uba_vsoftc * const sc = device_private(self);
169 struct sbi_attach_args * const sa = aux;
170 int ubaddr = sa->sa_type & 3;
172 aprint_normal(": DW780\n");
175 * Fill in bus specific data.
177 sc->uv_sc.uh_dev = self;
178 sc->uv_sc.uh_ubainit = dw780_init;
179 #ifdef notyet
180 sc->uv_sc.uh_ubapurge = dw780_purge;
181 #endif
182 sc->uv_sc.uh_beforescan = dw780_beforescan;
183 sc->uv_sc.uh_afterscan = dw780_afterscan;
184 sc->uv_sc.uh_errchk = dw780_errchk;
185 sc->uv_sc.uh_iot = sa->sa_iot;
186 sc->uv_sc.uh_dmat = &sc->uv_dmat;
187 sc->uv_sc.uh_nr = ubaddr;
188 sc->uv_uba = (void *)sa->sa_ioh;
189 sc->uh_ibase = VAX_NBPG + ubaddr * VAX_NBPG;
190 sc->uv_sc.uh_type = UBA_UBA;
192 if (strayinit++ == 0) evcnt_attach_static(&strayint); /* Setup stray
193 interrupt
194 counter. */
197 * Set up dispatch vectors for DW780.
199 #define SCB_VECALLOC_DW780(br) \
200 scb_vecalloc(vecnum(0, br, sa->sa_nexnum), uba_dw780int_ ## br, \
201 sc, SCB_ISTACK, &sc->uv_sc.uh_intrcnt) \
203 SCB_VECALLOC_DW780(0x14);
204 SCB_VECALLOC_DW780(0x15);
205 SCB_VECALLOC_DW780(0x16);
206 SCB_VECALLOC_DW780(0x17);
208 evcnt_attach_dynamic(&sc->uv_sc.uh_intrcnt, EVCNT_TYPE_INTR, NULL,
209 device_xname(sc->uv_sc.uh_dev), "intr");
212 * Fill in variables used by the sgmap system.
214 sc->uv_size = UBASIZE; /* Size in bytes of Unibus space */
216 uba_dma_init(sc);
217 uba_attach(&sc->uv_sc, (sa->sa_sbinum ? UMEMB8600(ubaddr) :
218 UMEMA8600(ubaddr)) + (UBAPAGES * VAX_NBPG));
221 void
222 dw780_beforescan(struct uba_softc *sc)
224 struct uba_vsoftc * const vc = (void *)sc;
225 volatile int *hej = &vc->uv_uba->uba_sr;
227 *hej = *hej;
228 vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE;
231 void
232 dw780_afterscan(struct uba_softc *sc)
234 struct uba_vsoftc * const vc = (void *)sc;
236 vc->uv_uba->uba_cr = UBACR_IFS | UBACR_BRIE |
237 UBACR_USEFIE | UBACR_SUEFIE |
238 (vc->uv_uba->uba_cr & 0x7c000000);
243 dw780_errchk(struct uba_softc *sc)
245 struct uba_vsoftc * const vc = (void *)sc;
246 volatile int *hej = &vc->uv_uba->uba_sr;
248 if (*hej) {
249 *hej = *hej;
250 return 1;
252 return 0;
255 static inline void
256 uba_dw780int_common(void *arg, int br)
258 extern void scb_stray(void *);
259 struct uba_vsoftc *vc = arg;
260 struct uba_regs *ur = vc->uv_uba;
261 struct ivec_dsp *ivec;
262 struct evcnt *uvec;
263 int vec;
265 uvec = &vc->uv_sc.uh_intrcnt;
266 vec = ur->uba_brrvr[br - 0x14];
267 if (vec <= 0) {
268 ubaerror(&vc->uv_sc, &br, &vec);
269 if (vec == 0)
270 return;
273 uvec->ev_count--; /* This interrupt should not be counted against
274 the uba. */
275 ivec = &scb_vec[(vc->uh_ibase + vec)/4];
276 if (cold && *ivec->hoppaddr == scb_stray) {
277 scb_fake(vec + vc->uh_ibase, br);
278 } else {
279 if (*ivec->hoppaddr == scb_stray)
280 strayint.ev_count++; /* Count against stray int */
281 else
282 ivec->ev->ev_count++; /* Count against device */
283 (*ivec->hoppaddr)(ivec->pushlarg);
287 #define UBA_DW780INT(br) \
288 void \
289 uba_dw780int_ ## br(void *arg) \
291 uba_dw780int_common(arg, br); \
294 UBA_DW780INT(0x14);
295 UBA_DW780INT(0x15);
296 UBA_DW780INT(0x16);
297 UBA_DW780INT(0x17);
299 void
300 dw780_init(struct uba_softc *sc)
302 struct uba_vsoftc *vc = (void *)sc;
304 vc->uv_uba->uba_cr = UBACR_ADINIT;
305 vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
306 while ((vc->uv_uba->uba_cnfgr & UBACNFGR_UBIC) == 0)
310 #ifdef notyet
311 void
312 dw780_purge(struct uba_softc *sc, int bdp)
314 struct uba_vsoftc *vc = (void *)sc;
316 vc->uv_uba->uba_dpr[bdp] |= UBADPR_BNE;
318 #endif
320 int ubawedgecnt = 10;
321 int ubacrazy = 500;
322 int zvcnt_max = 5000; /* in 8 sec */
323 int ubaerrcnt;
325 * This routine is called by the locore code to process a UBA
326 * error on an 11/780 or 8600. The arguments are passed
327 * on the stack, and value-result (through some trickery).
328 * In particular, the uvec argument is used for further
329 * uba processing so the result aspect of it is very important.
331 /*ARGSUSED*/
332 void
333 ubaerror(struct uba_softc *uh, int *ipl, int *uvec)
335 struct uba_vsoftc *vc = (void *)uh;
336 struct uba_regs *uba = vc->uv_uba;
337 int sr, s;
338 char sbuf[256], sbuf2[256];
340 if (*uvec == 0) {
342 * Declare dt as unsigned so that negative values
343 * are handled as >8 below, in case time was set back.
345 u_long dt = time_second - vc->uh_zvtime;
347 vc->uh_zvtotal++;
348 if (dt > 8) {
349 vc->uh_zvtime = time_second;
350 vc->uh_zvcnt = 0;
352 if (++vc->uh_zvcnt > zvcnt_max) {
353 aprint_error_dev(vc->uv_sc.uh_dev,
354 "too many zero vectors (%d in <%d sec)\n",
355 vc->uh_zvcnt, (int)dt + 1);
357 snprintb(sbuf, sizeof(sbuf), UBACNFGR_BITS,
358 uba->uba_cnfgr & ~0xff);
359 aprint_error(
360 "\tIPL 0x%x\n"
361 "\tcnfgr: %s\tAdapter Code: 0x%x\n",
362 *ipl, sbuf, uba->uba_cnfgr&0xff);
364 snprintb(sbuf, sizeof(sbuf), ubasr_bits, uba->uba_sr);
365 aprint_error(
366 "\tsr: %s\n"
367 "\tdcr: %x (MIC %sOK)\n",
368 sbuf, uba->uba_dcr,
369 (uba->uba_dcr&0x8000000)?"":"NOT ");
371 ubareset(&vc->uv_sc);
373 return;
375 if (uba->uba_cnfgr & NEX_CFGFLT) {
376 snprintb(sbuf, sizeof(sbuf), ubasr_bits, uba->uba_sr);
377 snprintb(sbuf2, sizeof(sbuf2), NEXFLT_BITS, uba->uba_cnfgr);
378 aprint_error_dev(vc->uv_sc.uh_dev,
379 "sbi fault sr=%s cnfgr=%s\n", sbuf, sbuf2);
380 ubareset(&vc->uv_sc);
381 *uvec = 0;
382 return;
384 sr = uba->uba_sr;
385 s = spluba();
386 snprintb(sbuf, sizeof(sbuf), ubasr_bits, uba->uba_sr);
387 aprint_error_dev(vc->uv_sc.uh_dev,
388 "uba error sr=%s fmer=%x fubar=%o\n",
389 sbuf, uba->uba_fmer, 4*uba->uba_fubar);
390 splx(s);
391 uba->uba_sr = sr;
392 *uvec &= UBABRRVR_DIV;
393 if (++ubaerrcnt % ubawedgecnt == 0) {
394 if (ubaerrcnt > ubacrazy)
395 panic("uba crazy");
396 printf("ERROR LIMIT ");
397 ubareset(&vc->uv_sc);
398 *uvec = 0;