Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / bi / uba_bi.c
blobffb225e22dae32fbb36fe0dabff02447581a39f4
1 /* $NetBSD: uba_bi.c,v 1.14 2009/03/14 15:36:16 dsl Exp $ */
2 /*
3 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
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. 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
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.
34 * DWBUA BI-Unibus adapter
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: uba_bi.c,v 1.14 2009/03/14 15:36:16 dsl Exp $");
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/malloc.h>
46 #include <sys/systm.h>
48 #include <machine/sid.h>
49 #include <machine/pte.h>
50 #include <machine/pcb.h>
51 #include <machine/trap.h>
52 #include <machine/scb.h>
54 #include <vax/bi/bireg.h>
55 #include <vax/bi/bivar.h>
57 #include <vax/uba/ubareg.h>
58 #include <vax/uba/ubavar.h>
60 #include "locators.h"
62 #define BUA(uba) ((struct dwbua_regs *)(uba))
64 static int uba_bi_match(device_t, cfdata_t, void *);
65 static void uba_bi_attach(device_t, device_t, void *);
66 static void bua_init(struct uba_softc *);
67 static void bua_purge(struct uba_softc *, int);
69 /* bua_csr */
70 #define BUACSR_ERR 0x80000000 /* composite error */
71 #define BUACSR_BIF 0x10000000 /* BI failure */
72 #define BUACSR_SSYNTO 0x08000000 /* slave sync timeout */
73 #define BUACSR_UIE 0x04000000 /* unibus interlock error */
74 #define BUACSR_IVMR 0x02000000 /* invalid map register */
75 #define BUACSR_BADBDP 0x01000000 /* bad BDP select */
76 #define BUACSR_BUAEIE 0x00100000 /* bua error interrupt enable (?) */
77 #define BUACSR_UPI 0x00020000 /* unibus power init */
78 #define BUACSR_UREGDUMP 0x00010000 /* microdiag register dump */
79 #define BUACSR_IERRNO 0x000000ff /* mask for internal errror number */
81 /* bua_offset */
82 #define BUAOFFSET_MASK 0x00003e00 /* hence max offset = 15872 */
84 /* bua_dpr */
85 #define BUADPR_DPSEL 0x00e00000 /* data path select (?) */
86 #define BUADPR_PURGE 0x00000001 /* purge bdp */
88 /* bua_map -- in particular, those bits that are not in DW780s & DW750s */
89 #define BUAMR_IOADR 0x40000000 /* I/O address space */
90 #define BUAMR_LAE 0x04000000 /* longword access enable */
92 static int allocvec;
94 CFATTACH_DECL_NEW(uba_bi, sizeof(struct uba_softc),
95 uba_bi_match, uba_bi_attach, NULL, NULL);
97 struct dwbua_regs {
98 struct biiregs bn_biic; /* interface */
99 int pad1[396];
100 int bn_csr;
101 int bn_vor; /* Vector offset from SCB */
102 int bn_fubar; /* Failed Unibus address register */
103 int bn_bifar; /* BI failed address register */
104 int bn_mdiag[5]; /* microdiag regs for BDP */
105 int pad2[3];
106 int bn_dpcsr[6]; /* Data path control and status register */
107 int pad3[38];
108 struct pte bn_map[UBAPAGES]; /* Unibus map registers */
109 int pad4[UBAIOPAGES];
113 * Poke at a supposed DWBUA to see if it is there.
115 static int
116 uba_bi_match(device_t parent, cfdata_t cf, void *aux)
118 struct bi_attach_args *ba = aux;
120 if ((ba->ba_node->biic.bi_dtype != BIDT_DWBUA) &&
121 (ba->ba_node->biic.bi_dtype != BIDT_KLESI))
122 return 0;
124 if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
125 cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
126 return 0;
128 return 1;
131 void
132 uba_bi_attach(device_t parent, device_t self, void *aux)
134 struct uba_softc *sc = device_private(self);
135 struct bi_attach_args *ba = aux;
136 volatile int timo;
138 if (ba->ba_node->biic.bi_dtype == BIDT_DWBUA)
139 printf(": DWBUA\n");
140 else
141 printf(": KLESI-B\n");
144 * Fill in bus specific data.
146 sc->uh_dev = self;
147 sc->uh_uba = (void *)ba->ba_node;
148 sc->uh_nbdp = NBDPBUA;
149 /* sc->uh_nr is 0; uninteresting here */
150 /* sc->uh_afterscan; not used */
151 /* sc->uh_errchk; not used */
152 /* sc->uh_beforescan */
153 sc->uh_ubapurge = bua_purge;
154 sc->uh_ubainit = bua_init;
155 /* sc->uh_type not used */
156 sc->uh_memsize = UBAPAGES;
157 sc->uh_mr = BUA(sc->uh_uba)->bn_map;
159 #ifdef notdef
160 /* Can we get separate interrupts? */
161 scb->scb_nexvec[1][ba->ba_nodenr] = &sc->sc_ivec;
162 #endif
163 BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_ARB_NONE;
164 BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_STS | BICSR_INIT;
165 DELAY(1000);
166 timo = 1000;
167 while (BUA(sc->uh_uba)->bn_biic.bi_csr & BICSR_BROKE)
168 if (timo == 0) {
169 aprint_error_dev(self, "BROKE bit set\n");
170 return;
173 BUA(sc->uh_uba)->bn_biic.bi_intrdes = ba->ba_intcpu;
174 BUA(sc->uh_uba)->bn_biic.bi_csr =
175 (BUA(sc->uh_uba)->bn_biic.bi_csr&~BICSR_ARB_MASK) | BICSR_ARB_HIGH;
176 BUA(sc->uh_uba)->bn_vor = VAX_NBPG + (VAX_NBPG * allocvec++);
178 uba_attach(sc, BUA(sc->uh_uba)->bn_biic.bi_sadr + UBAPAGES * VAX_NBPG);
182 void
183 bua_init(struct uba_softc *sc)
185 BUA(sc->uh_uba)->bn_csr |= BUACSR_UPI;
186 DELAY(500000);
189 void
190 bua_purge(struct uba_softc *sc, int bdp)
192 BUA(sc->uh_uba)->bn_dpcsr[bdp] |= BUADPR_PURGE;