uba_sbi.c revision 1.4 1 /* $NetBSD: uba_sbi.c,v 1.4 2000/05/27 21:44:35 ragge Exp $ */
2 /*
3 * Copyright (c) 1996 Jonathan Stone.
4 * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
5 * Copyright (c) 1982, 1986 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)uba.c 7.10 (Berkeley) 12/16/90
37 * @(#)autoconf.c 7.20 (Berkeley) 5/9/91
38 */
39
40 #include <sys/param.h>
41 #include <sys/device.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44
45 #define _VAX_BUS_DMA_PRIVATE
46 #include <machine/bus.h>
47 #include <machine/mtpr.h>
48 #include <machine/nexus.h>
49 #include <machine/cpu.h>
50 #include <machine/sgmap.h>
51 #include <machine/scb.h>
52
53 #include <dev/qbus/ubavar.h>
54
55 #include <arch/vax/uba/uba_common.h>
56
57 #include "ioconf.h"
58
59 /* Some SBI-specific defines */
60 #define UBASIZE (UBAPAGES * VAX_NBPG)
61 #define UMEMA8600(i) (0x20100000+(i)*0x40000)
62 #define UMEMB8600(i) (0x22100000+(i)*0x40000)
63
64 /*
65 * Some status registers.
66 */
67 #define UBACNFGR_UBIC 0x00010000 /* unibus init complete */
68 #define UBACNFGR_BITS \
69 "\40\40PARFLT\37WSQFLT\36URDFLT\35ISQFLT\34MXTFLT\33XMTFLT\30ADPDN\27ADPUP\23UBINIT\22UBPDN\21UBIC"
70
71 #define UBACR_IFS 0x00000040 /* interrupt field switch */
72 #define UBACR_BRIE 0x00000020 /* BR interrupt enable */
73 #define UBACR_USEFIE 0x00000010 /* UNIBUS to SBI error field IE */
74 #define UBACR_SUEFIE 0x00000008 /* SBI to UNIBUS error field IE */
75 #define UBACR_ADINIT 0x00000001 /* adapter init */
76
77 #define UBADPR_BNE 0x80000000 /* buffer not empty - purge */
78
79 #define UBABRRVR_DIV 0x0000ffff /* device interrupt vector field */
80
81 #define UBASR_BITS \
82 "\20\13RDTO\12RDS\11CRD\10CXTER\7CXTMO\6DPPE\5IVMR\4MRPF\3LEB\2UBSTO\1UBSSYNTO"
83
84 char ubasr_bits[] = UBASR_BITS;
85
86 /*
87 * The DW780 are directly connected to the SBI on 11/780 and 8600.
88 */
89 static int dw780_match __P((struct device *, struct cfdata *, void *));
90 static void dw780_attach __P((struct device *, struct device *, void *));
91 static void dw780_init __P((struct uba_softc*));
92 static void dw780_beforescan __P((struct uba_softc *));
93 static void dw780_afterscan __P((struct uba_softc *));
94 static int dw780_errchk __P((struct uba_softc *));
95 static void uba_dw780int __P((void *));
96 static void ubaerror __P((struct uba_softc *, int *, int *));
97 #ifdef notyet
98 static void dw780_purge __P((struct uba_softc *, int));
99 #endif
100
101 struct cfattach uba_sbi_ca = {
102 sizeof(struct uba_vsoftc), dw780_match, dw780_attach
103 };
104
105 extern struct vax_bus_space vax_mem_bus_space;
106
107 volatile int svec;
108
109 int
110 dw780_match(parent, cf, aux)
111 struct device *parent;
112 struct cfdata *cf;
113 void *aux;
114 {
115 struct sbi_attach_args *sa = (struct sbi_attach_args *)aux;
116
117 if ((cf->cf_loc[0] != sa->nexnum) && (cf->cf_loc[0] > -1 ))
118 return 0;
119 /*
120 * The uba type is actually only telling where the uba
121 * space is in nexus space.
122 */
123 if ((sa->type & ~3) != NEX_UBA0)
124 return 0;
125
126 return 1;
127 }
128
129 void
130 dw780_attach(parent, self, aux)
131 struct device *parent, *self;
132 void *aux;
133 {
134 struct uba_vsoftc *sc = (void *)self;
135 struct sbi_attach_args *sa = aux;
136 int ubaddr = sa->type & 3;
137 int i;
138
139 printf(": DW780\n");
140 /*
141 * Fill in bus specific data.
142 */
143 sc->uv_sc.uh_ubainit = dw780_init;
144 #ifdef notyet
145 sc->uv_sc.uh_ubapurge = dw780_purge;
146 #endif
147 sc->uv_sc.uh_beforescan = dw780_beforescan;
148 sc->uv_sc.uh_afterscan = dw780_afterscan;
149 sc->uv_sc.uh_errchk = dw780_errchk;
150 sc->uv_sc.uh_iot = &vax_mem_bus_space;
151 sc->uv_sc.uh_dmat = &sc->uv_dmat;
152 sc->uv_uba = (void *)sa->nexaddr;
153 sc->uh_ibase = VAX_NBPG + ubaddr * VAX_NBPG;
154
155 /*
156 * Set up dispatch vectors for DW780.
157 */
158 for (i = 0; i < 4; i++)
159 scb_vecalloc(256 + i * 64 + sa->nexnum * 4, uba_dw780int,
160 sc, SCB_ISTACK);
161 /*
162 * Fill in variables used by the sgmap system.
163 */
164 sc->uv_size = UBASIZE; /* Size in bytes of Unibus space */
165
166 uba_dma_init(sc);
167 uba_attach(&sc->uv_sc, (parent->dv_unit ? UMEMB8600(ubaddr) :
168 UMEMA8600(ubaddr)) + (UBAPAGES * VAX_NBPG));
169 }
170
171 void
172 dw780_beforescan(sc)
173 struct uba_softc *sc;
174 {
175 struct uba_vsoftc *vc = (void *)sc;
176 volatile int *hej = &vc->uv_uba->uba_sr;
177
178 *hej = *hej;
179 vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE;
180 }
181
182 void
183 dw780_afterscan(sc)
184 struct uba_softc *sc;
185 {
186 struct uba_vsoftc *vc = (void *)sc;
187
188 vc->uv_uba->uba_cr = UBACR_IFS | UBACR_BRIE |
189 UBACR_USEFIE | UBACR_SUEFIE |
190 (vc->uv_uba->uba_cr & 0x7c000000);
191 }
192
193
194 int
195 dw780_errchk(sc)
196 struct uba_softc *sc;
197 {
198 struct uba_vsoftc *vc = (void *)sc;
199 volatile int *hej = &vc->uv_uba->uba_sr;
200
201 if (*hej) {
202 *hej = *hej;
203 return 1;
204 }
205 return 0;
206 }
207
208 void
209 uba_dw780int(arg)
210 void *arg;
211 {
212 struct uba_vsoftc *vc = arg;
213 struct uba_regs *ur = vc->uv_uba;
214 struct ivec_dsp *scb_vec;
215 int br, vec;
216
217 br = mfpr(PR_IPL);
218 vec = ur->uba_brrvr[br - 0x14];
219 if (vec <= 0) {
220 ubaerror(&vc->uv_sc, &br, (int *)&vec);
221 if (svec == 0)
222 return;
223 }
224 if (cold)
225 scb_fake(vec + vc->uh_ibase, br);
226 else {
227 scb_vec = (struct ivec_dsp *)((int)scb + 512 + 4 * vec);
228 (*scb_vec->hoppaddr)(scb_vec->pushlarg);
229 }
230 }
231
232 void
233 dw780_init(sc)
234 struct uba_softc *sc;
235 {
236 struct uba_vsoftc *vc = (void *)sc;
237
238 vc->uv_uba->uba_cr = UBACR_ADINIT;
239 vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
240 while ((vc->uv_uba->uba_cnfgr & UBACNFGR_UBIC) == 0)
241 ;
242 }
243
244 #ifdef notyet
245 void
246 dw780_purge(sc, bdp)
247 struct uba_softc *sc;
248 int bdp;
249 {
250 struct uba_vsoftc *vc = (void *)sc;
251
252 vc->uv_uba->uba_dpr[bdp] |= UBADPR_BNE;
253 }
254 #endif
255
256 int ubawedgecnt = 10;
257 int ubacrazy = 500;
258 int zvcnt_max = 5000; /* in 8 sec */
259 int ubaerrcnt;
260 /*
261 * This routine is called by the locore code to process a UBA
262 * error on an 11/780 or 8600. The arguments are passed
263 * on the stack, and value-result (through some trickery).
264 * In particular, the uvec argument is used for further
265 * uba processing so the result aspect of it is very important.
266 * It must not be declared register.
267 */
268 /*ARGSUSED*/
269 void
270 ubaerror(uh, ipl, uvec)
271 register struct uba_softc *uh;
272 int *ipl, *uvec;
273 {
274 struct uba_vsoftc *vc = (void *)uh;
275 struct uba_regs *uba = vc->uv_uba;
276 register int sr, s;
277
278 if (*uvec == 0) {
279 /*
280 * Declare dt as unsigned so that negative values
281 * are handled as >8 below, in case time was set back.
282 */
283 u_long dt = time.tv_sec - vc->uh_zvtime;
284
285 vc->uh_zvtotal++;
286 if (dt > 8) {
287 vc->uh_zvtime = time.tv_sec;
288 vc->uh_zvcnt = 0;
289 }
290 if (++vc->uh_zvcnt > zvcnt_max) {
291 printf("%s: too many zero vectors (%d in <%d sec)\n",
292 vc->uv_sc.uh_dev.dv_xname, vc->uh_zvcnt, (int)dt + 1);
293 printf("\tIPL 0x%x\n\tcnfgr: %b Adapter Code: 0x%x\n",
294 *ipl, uba->uba_cnfgr&(~0xff), UBACNFGR_BITS,
295 uba->uba_cnfgr&0xff);
296 printf("\tsr: %b\n\tdcr: %x (MIC %sOK)\n",
297 uba->uba_sr, ubasr_bits, uba->uba_dcr,
298 (uba->uba_dcr&0x8000000)?"":"NOT ");
299 ubareset(&vc->uv_sc);
300 }
301 return;
302 }
303 if (uba->uba_cnfgr & NEX_CFGFLT) {
304 printf("%s: sbi fault sr=%b cnfgr=%b\n",
305 vc->uv_sc.uh_dev.dv_xname, uba->uba_sr, ubasr_bits,
306 uba->uba_cnfgr, NEXFLT_BITS);
307 ubareset(&vc->uv_sc);
308 *uvec = 0;
309 return;
310 }
311 sr = uba->uba_sr;
312 s = splimp();
313 printf("%s: uba error sr=%b fmer=%x fubar=%o\n", vc->uv_sc.uh_dev.dv_xname,
314 uba->uba_sr, ubasr_bits, uba->uba_fmer, 4*uba->uba_fubar);
315 splx(s);
316 uba->uba_sr = sr;
317 *uvec &= UBABRRVR_DIV;
318 if (++ubaerrcnt % ubawedgecnt == 0) {
319 if (ubaerrcnt > ubacrazy)
320 panic("uba crazy");
321 printf("ERROR LIMIT ");
322 ubareset(&vc->uv_sc);
323 *uvec = 0;
324 }
325 }
326