xref: /netbsd/sys/dev/bi/uba_bi.c (revision bf9ec67e)
1 /*	$NetBSD: uba_bi.c,v 1.5 2001/11/13 12:51:34 lukem Exp $ */
2 /*
3  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
4  * All rights reserved.
5  *
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. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed at Ludd, University of
17  *	Lule}, Sweden and its contributors.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * DWBUA BI-Unibus adapter
35  */
36 
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: uba_bi.c,v 1.5 2001/11/13 12:51:34 lukem Exp $");
39 
40 #include <sys/param.h>
41 #include <sys/kernel.h>
42 #include <sys/buf.h>
43 #include <sys/device.h>
44 #include <sys/proc.h>
45 #include <sys/user.h>
46 #include <sys/malloc.h>
47 #include <sys/systm.h>
48 
49 #include <machine/sid.h>
50 #include <machine/pte.h>
51 #include <machine/pcb.h>
52 #include <machine/trap.h>
53 #include <machine/scb.h>
54 
55 #include <vax/bi/bireg.h>
56 #include <vax/bi/bivar.h>
57 
58 #include <vax/uba/ubareg.h>
59 #include <vax/uba/ubavar.h>
60 
61 #include "locators.h"
62 
63 #define	BUA(uba)	((struct dwbua_regs *)(uba))
64 
65 static	int uba_bi_match __P((struct device *, struct cfdata *, void *));
66 static	void uba_bi_attach __P((struct device *, struct device *, void *));
67 static	void bua_init __P((struct uba_softc *));
68 static	void bua_purge __P((struct uba_softc *, int));
69 
70 /* bua_csr */
71 #define BUACSR_ERR      0x80000000      /* composite error */
72 #define BUACSR_BIF      0x10000000      /* BI failure */
73 #define BUACSR_SSYNTO   0x08000000      /* slave sync timeout */
74 #define BUACSR_UIE      0x04000000      /* unibus interlock error */
75 #define BUACSR_IVMR     0x02000000      /* invalid map register */
76 #define BUACSR_BADBDP   0x01000000      /* bad BDP select */
77 #define BUACSR_BUAEIE   0x00100000      /* bua error interrupt enable (?) */
78 #define BUACSR_UPI      0x00020000      /* unibus power init */
79 #define BUACSR_UREGDUMP 0x00010000      /* microdiag register dump */
80 #define BUACSR_IERRNO   0x000000ff      /* mask for internal errror number */
81 
82 /* bua_offset */
83 #define BUAOFFSET_MASK  0x00003e00      /* hence max offset = 15872 */
84 
85 /* bua_dpr */
86 #define BUADPR_DPSEL    0x00e00000      /* data path select (?) */
87 #define BUADPR_PURGE    0x00000001      /* purge bdp */
88 
89 /* bua_map -- in particular, those bits that are not in DW780s & DW750s */
90 #define BUAMR_IOADR     0x40000000      /* I/O address space */
91 #define BUAMR_LAE       0x04000000      /* longword access enable */
92 
93 static	int allocvec;
94 
95 struct	cfattach uba_bi_ca = {
96 	sizeof(struct uba_softc), uba_bi_match, uba_bi_attach,
97 };
98 
99 struct dwbua_regs {
100 	struct  biiregs bn_biic;   /* interface */
101 	int	pad1[396];
102 	int	bn_csr;
103 	int	bn_vor;		/* Vector offset from SCB */
104 	int	bn_fubar;	/* Failed Unibus address register */
105 	int	bn_bifar;	/* BI failed address register */
106 	int	bn_mdiag[5];	/* microdiag regs for BDP */
107 	int	pad2[3];
108 	int	bn_dpcsr[6];	/* Data path control and status register */
109 	int	pad3[38];
110 	struct	pte bn_map[UBAPAGES];	/* Unibus map registers */
111 	int	pad4[UBAIOPAGES];
112 };
113 
114 /*
115  * Poke at a supposed DWBUA to see if it is there.
116  */
117 static int
118 uba_bi_match(parent, cf, aux)
119 	struct	device *parent;
120 	struct	cfdata *cf;
121 	void	*aux;
122 {
123 	struct bi_attach_args *ba = aux;
124 
125 	if ((ba->ba_node->biic.bi_dtype != BIDT_DWBUA) &&
126 	    (ba->ba_node->biic.bi_dtype != BIDT_KLESI))
127 		return 0;
128 
129 	if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
130 	    cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
131 		return 0;
132 
133 	return 1;
134 }
135 
136 void
137 uba_bi_attach(parent, self, aux)
138 	struct device *parent, *self;
139 	void *aux;
140 {
141 	struct	uba_softc *sc = (void *)self;
142 	struct	bi_attach_args *ba = aux;
143 	volatile int timo;
144 
145 	if (ba->ba_node->biic.bi_dtype == BIDT_DWBUA)
146 		printf(": DWBUA\n");
147 	else
148 		printf(": KLESI-B\n");
149 
150 	/*
151 	 * Fill in bus specific data.
152 	 */
153 	sc->uh_uba = (void *)ba->ba_node;
154 	sc->uh_nbdp = NBDPBUA;
155 /*	sc->uh_nr is 0; uninteresting here */
156 /*	sc->uh_afterscan; not used */
157 /*	sc->uh_errchk; not used */
158 /*	sc->uh_beforescan */
159 	sc->uh_ubapurge = bua_purge;
160 	sc->uh_ubainit = bua_init;
161 /*	sc->uh_type not used */
162 	sc->uh_memsize = UBAPAGES;
163 	sc->uh_mr = BUA(sc->uh_uba)->bn_map;
164 
165 #ifdef notdef
166 	/* Can we get separate interrupts? */
167 	scb->scb_nexvec[1][ba->ba_nodenr] = &sc->sc_ivec;
168 #endif
169 	BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_ARB_NONE;
170 	BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_STS | BICSR_INIT;
171 	DELAY(1000);
172 	timo = 1000;
173 	while (BUA(sc->uh_uba)->bn_biic.bi_csr & BICSR_BROKE)
174 		if (timo == 0) {
175 			printf("%s: BROKE bit set\n", self->dv_xname);
176 			return;
177 		}
178 
179 	BUA(sc->uh_uba)->bn_biic.bi_intrdes = ba->ba_intcpu;
180 	BUA(sc->uh_uba)->bn_biic.bi_csr =
181 	    (BUA(sc->uh_uba)->bn_biic.bi_csr&~BICSR_ARB_MASK) | BICSR_ARB_HIGH;
182 	BUA(sc->uh_uba)->bn_vor = VAX_NBPG + (VAX_NBPG * allocvec++);
183 
184 	uba_attach(sc, BUA(sc->uh_uba)->bn_biic.bi_sadr + UBAPAGES * VAX_NBPG);
185 }
186 
187 
188 void
189 bua_init(sc)
190 	struct uba_softc *sc;
191 {
192 	BUA(sc->uh_uba)->bn_csr |= BUACSR_UPI;
193 	DELAY(500000);
194 };
195 
196 void
197 bua_purge(sc, bdp)
198 	struct uba_softc *sc;
199 	int bdp;
200 {
201 	BUA(sc->uh_uba)->bn_dpcsr[bdp] |= BUADPR_PURGE;
202 }
203