xref: /netbsd-src/sys/dev/bi/uba_bi.c (revision 96c646f762cb6f483f3c55939207c109ca9fc03b)
1*96c646f7Sandvar /*	$NetBSD: uba_bi.c,v 1.16 2024/02/04 18:52:35 andvar Exp $ */
2497378ceSragge /*
3497378ceSragge  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
4497378ceSragge  * All rights reserved.
5497378ceSragge  *
6497378ceSragge  * Redistribution and use in source and binary forms, with or without
7497378ceSragge  * modification, are permitted provided that the following conditions
8497378ceSragge  * are met:
9497378ceSragge  * 1. Redistributions of source code must retain the above copyright
10497378ceSragge  *    notice, this list of conditions and the following disclaimer.
11497378ceSragge  * 2. Redistributions in binary form must reproduce the above copyright
12497378ceSragge  *    notice, this list of conditions and the following disclaimer in the
13497378ceSragge  *    documentation and/or other materials provided with the distribution.
14497378ceSragge  * 3. All advertising materials mentioning features or use of this software
15497378ceSragge  *    must display the following acknowledgement:
16497378ceSragge  *	This product includes software developed at Ludd, University of
17497378ceSragge  *	Lule}, Sweden and its contributors.
18497378ceSragge  * 4. The name of the author may not be used to endorse or promote products
19497378ceSragge  *    derived from this software without specific prior written permission
20497378ceSragge  *
21497378ceSragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22497378ceSragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23497378ceSragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24497378ceSragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25497378ceSragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26497378ceSragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27497378ceSragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28497378ceSragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29497378ceSragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30497378ceSragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31497378ceSragge  */
32497378ceSragge 
33497378ceSragge /*
34497378ceSragge  * DWBUA BI-Unibus adapter
35497378ceSragge  */
36497378ceSragge 
37f61cbe74Slukem #include <sys/cdefs.h>
38*96c646f7Sandvar __KERNEL_RCSID(0, "$NetBSD: uba_bi.c,v 1.16 2024/02/04 18:52:35 andvar Exp $");
39f61cbe74Slukem 
40497378ceSragge #include <sys/param.h>
41497378ceSragge #include <sys/kernel.h>
42497378ceSragge #include <sys/buf.h>
43497378ceSragge #include <sys/device.h>
44497378ceSragge #include <sys/proc.h>
45497378ceSragge #include <sys/malloc.h>
46497378ceSragge #include <sys/systm.h>
47497378ceSragge 
48497378ceSragge #include <machine/sid.h>
49497378ceSragge #include <machine/pte.h>
50497378ceSragge #include <machine/pcb.h>
51497378ceSragge #include <machine/trap.h>
52497378ceSragge #include <machine/scb.h>
53497378ceSragge 
54497378ceSragge #include <vax/bi/bireg.h>
55497378ceSragge #include <vax/bi/bivar.h>
56497378ceSragge 
57497378ceSragge #include <vax/uba/ubareg.h>
58497378ceSragge #include <vax/uba/ubavar.h>
59497378ceSragge 
60497378ceSragge #include "locators.h"
61497378ceSragge 
62497378ceSragge #define	BUA(uba)	((struct dwbua_regs *)(uba))
63497378ceSragge 
64dfba8166Smatt static	int uba_bi_match(device_t, cfdata_t, void *);
65dfba8166Smatt static	void uba_bi_attach(device_t, device_t, void *);
6618db93c7Sperry static	void bua_init(struct uba_softc *);
6718db93c7Sperry static	void bua_purge(struct uba_softc *, int);
68497378ceSragge 
69497378ceSragge /* bua_csr */
70497378ceSragge #define BUACSR_ERR      0x80000000      /* composite error */
71497378ceSragge #define BUACSR_BIF      0x10000000      /* BI failure */
72497378ceSragge #define BUACSR_SSYNTO   0x08000000      /* slave sync timeout */
73497378ceSragge #define BUACSR_UIE      0x04000000      /* unibus interlock error */
74497378ceSragge #define BUACSR_IVMR     0x02000000      /* invalid map register */
75497378ceSragge #define BUACSR_BADBDP   0x01000000      /* bad BDP select */
76497378ceSragge #define BUACSR_BUAEIE   0x00100000      /* bua error interrupt enable (?) */
77497378ceSragge #define BUACSR_UPI      0x00020000      /* unibus power init */
78497378ceSragge #define BUACSR_UREGDUMP 0x00010000      /* microdiag register dump */
79*96c646f7Sandvar #define BUACSR_IERRNO   0x000000ff      /* mask for internal error number */
80497378ceSragge 
81497378ceSragge /* bua_offset */
82497378ceSragge #define BUAOFFSET_MASK  0x00003e00      /* hence max offset = 15872 */
83497378ceSragge 
84497378ceSragge /* bua_dpr */
85497378ceSragge #define BUADPR_DPSEL    0x00e00000      /* data path select (?) */
86497378ceSragge #define BUADPR_PURGE    0x00000001      /* purge bdp */
87497378ceSragge 
88497378ceSragge /* bua_map -- in particular, those bits that are not in DW780s & DW750s */
89497378ceSragge #define BUAMR_IOADR     0x40000000      /* I/O address space */
90497378ceSragge #define BUAMR_LAE       0x04000000      /* longword access enable */
91497378ceSragge 
92497378ceSragge static	int allocvec;
93497378ceSragge 
94dfba8166Smatt CFATTACH_DECL_NEW(uba_bi, sizeof(struct uba_softc),
95c9b3657cSthorpej     uba_bi_match, uba_bi_attach, NULL, NULL);
96497378ceSragge 
97497378ceSragge struct dwbua_regs {
98497378ceSragge 	struct  biiregs bn_biic;   /* interface */
99497378ceSragge 	int	pad1[396];
100497378ceSragge 	int	bn_csr;
101497378ceSragge 	int	bn_vor;		/* Vector offset from SCB */
102497378ceSragge 	int	bn_fubar;	/* Failed Unibus address register */
103497378ceSragge 	int	bn_bifar;	/* BI failed address register */
104497378ceSragge 	int	bn_mdiag[5];	/* microdiag regs for BDP */
105497378ceSragge 	int	pad2[3];
106497378ceSragge 	int	bn_dpcsr[6];	/* Data path control and status register */
107497378ceSragge 	int	pad3[38];
108497378ceSragge 	struct	pte bn_map[UBAPAGES];	/* Unibus map registers */
109497378ceSragge 	int	pad4[UBAIOPAGES];
110497378ceSragge };
111497378ceSragge 
112497378ceSragge /*
113497378ceSragge  * Poke at a supposed DWBUA to see if it is there.
114497378ceSragge  */
115497378ceSragge static int
uba_bi_match(device_t parent,cfdata_t cf,void * aux)116dfba8166Smatt uba_bi_match(device_t parent, cfdata_t cf, void *aux)
117497378ceSragge {
118497378ceSragge 	struct bi_attach_args *ba = aux;
119497378ceSragge 
120497378ceSragge 	if ((ba->ba_node->biic.bi_dtype != BIDT_DWBUA) &&
121497378ceSragge 	    (ba->ba_node->biic.bi_dtype != BIDT_KLESI))
122497378ceSragge 		return 0;
123497378ceSragge 
124497378ceSragge 	if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
125497378ceSragge 	    cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
126497378ceSragge 		return 0;
127497378ceSragge 
128497378ceSragge 	return 1;
129497378ceSragge }
130497378ceSragge 
131497378ceSragge void
uba_bi_attach(device_t parent,device_t self,void * aux)132dfba8166Smatt uba_bi_attach(device_t parent, device_t self, void *aux)
133497378ceSragge {
134dfba8166Smatt 	struct uba_softc *sc = device_private(self);
135497378ceSragge 	struct bi_attach_args *ba = aux;
136497378ceSragge 	volatile int timo;
137497378ceSragge 
138497378ceSragge 	if (ba->ba_node->biic.bi_dtype == BIDT_DWBUA)
139497378ceSragge 		printf(": DWBUA\n");
140497378ceSragge 	else
141497378ceSragge 		printf(": KLESI-B\n");
142497378ceSragge 
143497378ceSragge 	/*
144497378ceSragge 	 * Fill in bus specific data.
145497378ceSragge 	 */
146dfba8166Smatt 	sc->uh_dev = self;
147497378ceSragge 	sc->uh_uba = (void *)ba->ba_node;
148497378ceSragge 	sc->uh_nbdp = NBDPBUA;
149497378ceSragge /*	sc->uh_nr is 0; uninteresting here */
150497378ceSragge /*	sc->uh_afterscan; not used */
151497378ceSragge /*	sc->uh_errchk; not used */
152497378ceSragge /*	sc->uh_beforescan */
153497378ceSragge 	sc->uh_ubapurge = bua_purge;
154497378ceSragge 	sc->uh_ubainit = bua_init;
155497378ceSragge /*	sc->uh_type not used */
156497378ceSragge 	sc->uh_memsize = UBAPAGES;
157497378ceSragge 	sc->uh_mr = BUA(sc->uh_uba)->bn_map;
158497378ceSragge 
159497378ceSragge #ifdef notdef
160497378ceSragge 	/* Can we get separate interrupts? */
161497378ceSragge 	scb->scb_nexvec[1][ba->ba_nodenr] = &sc->sc_ivec;
162497378ceSragge #endif
163497378ceSragge 	BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_ARB_NONE;
164497378ceSragge 	BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_STS | BICSR_INIT;
165497378ceSragge 	DELAY(1000);
166497378ceSragge 	timo = 1000;
167497378ceSragge 	while (BUA(sc->uh_uba)->bn_biic.bi_csr & BICSR_BROKE)
168497378ceSragge 		if (timo == 0) {
169f5bd7c21Scegger 			aprint_error_dev(self, "BROKE bit set\n");
170497378ceSragge 			return;
171497378ceSragge 		}
172497378ceSragge 
173497378ceSragge 	BUA(sc->uh_uba)->bn_biic.bi_intrdes = ba->ba_intcpu;
174497378ceSragge 	BUA(sc->uh_uba)->bn_biic.bi_csr =
175497378ceSragge 	    (BUA(sc->uh_uba)->bn_biic.bi_csr&~BICSR_ARB_MASK) | BICSR_ARB_HIGH;
176497378ceSragge 	BUA(sc->uh_uba)->bn_vor = VAX_NBPG + (VAX_NBPG * allocvec++);
177497378ceSragge 
178497378ceSragge 	uba_attach(sc, BUA(sc->uh_uba)->bn_biic.bi_sadr + UBAPAGES * VAX_NBPG);
179497378ceSragge }
180497378ceSragge 
181497378ceSragge 
182497378ceSragge void
bua_init(struct uba_softc * sc)183454af1c0Sdsl bua_init(struct uba_softc *sc)
184497378ceSragge {
185497378ceSragge 	BUA(sc->uh_uba)->bn_csr |= BUACSR_UPI;
186497378ceSragge 	DELAY(500000);
187497378ceSragge };
188497378ceSragge 
189497378ceSragge void
bua_purge(struct uba_softc * sc,int bdp)190454af1c0Sdsl bua_purge(struct uba_softc *sc, int bdp)
191497378ceSragge {
192497378ceSragge 	BUA(sc->uh_uba)->bn_dpcsr[bdp] |= BUADPR_PURGE;
193497378ceSragge }
194