xref: /netbsd-src/sys/dev/bi/bi.c (revision 4472dbe5e3bd91ef2540bada7a7ca7384627ff9b)
1 /*	$NetBSD: bi.c,v 1.14 2000/03/26 11:45:04 ragge Exp $ */
2 /*
3  * Copyright (c) 1996 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 
35 /*
36  * VAXBI specific routines.
37  */
38 /*
39  * TODO
40  *   handle BIbus errors more gracefully.
41  */
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 
46 #include <machine/bus.h>
47 #include <machine/cpu.h>
48 
49 #include <dev/bi/bireg.h>
50 #include <dev/bi/bivar.h>
51 
52 static int bi_print __P((void *, const char *));
53 
54 struct bi_list bi_list[] = {
55 	{BIDT_MS820, 1, "ms820"},
56 	{BIDT_DRB32, 0, "drb32"},
57 	{BIDT_DWBUA, 0, "dwbua"},
58 	{BIDT_KLESI, 0, "klesi"},
59 	{BIDT_KA820, 1, "ka820"},
60 	{BIDT_DB88,  0, "db88"},
61 	{BIDT_CIBCA, 0, "cibca"},
62 	{BIDT_DMB32, 0, "dmb32"},
63 	{BIDT_CIBCI, 0, "cibci"},
64 	{BIDT_KA800, 0, "ka800"},
65 	{BIDT_KDB50, 0, "kdb50"},
66 	{BIDT_DWMBA, 0, "dwmba"},
67 	{BIDT_KFBTA, 0, "kfbta"},
68 	{BIDT_DEBNK, 0, "debnk"},
69 	{BIDT_DEBNA, 0, "debna"},
70 	{0,0,0}
71 };
72 
73 int
74 bi_print(aux, name)
75 	void *aux;
76 	const char *name;
77 {
78 	struct bi_attach_args *ba = aux;
79 	struct bi_list *bl;
80 
81 	for (bl = &bi_list[0]; bl->bl_nr; bl++)
82 		if (bl->bl_nr == bus_space_read_2(ba->ba_iot, ba->ba_ioh, 0))
83 			break;
84 
85 	if (name) {
86 		if (bl->bl_nr == 0)
87 			printf("unknown device 0x%x",
88 			    bus_space_read_2(ba->ba_iot, ba->ba_ioh, 0));
89 		else
90 			printf(bl->bl_name);
91 		printf(" at %s", name);
92 	}
93 	printf(" node %d", ba->ba_nodenr);
94 #ifdef DEBUG
95 	if (bus_space_read_4(ba->ba_iot, ba->ba_ioh, BIREG_SADR) &&
96 	    bus_space_read_4(ba->ba_iot, ba->ba_ioh, BIREG_EADR))
97 		printf(" [sadr %x eadr %x]",
98 		    bus_space_read_4(ba->ba_iot, ba->ba_ioh, BIREG_SADR),
99 		    bus_space_read_4(ba->ba_iot, ba->ba_ioh, BIREG_EADR));
100 #endif
101 	return bl->bl_havedriver ? UNCONF : UNSUPP;
102 }
103 
104 static	int lastiv = 0;
105 
106 void
107 bi_attach(sc)
108 	struct bi_softc *sc;
109 {
110 	struct bi_attach_args ba;
111 	int nodenr;
112 
113 	printf("\n");
114 
115 	ba.ba_iot = sc->sc_iot;
116 	ba.ba_busnr = sc->sc_busnr;
117 	ba.ba_dmat = sc->sc_dmat;
118 	ba.ba_intcpu = sc->sc_intcpu;
119 	/*
120 	 * Interrupt numbers. All vectors from 256-512 are free, use
121 	 * them for BI devices and just count them up.
122 	 * Above 512 are only interrupt vectors for unibus devices.
123 	 */
124 	for (nodenr = 0; nodenr < NNODEBI; nodenr++) {
125 		if (bus_space_map(sc->sc_iot, sc->sc_addr + BI_NODE(nodenr),
126 		    NODESIZE, 0, &ba.ba_ioh)) {
127 			printf("bi_attach: bus_space_map failed, node %d\n",
128 			    nodenr);
129 			return;
130 		}
131 		if (badaddr((caddr_t)ba.ba_ioh, 4)) {
132 			bus_space_unmap(sc->sc_iot, ba.ba_ioh, NODESIZE);
133 			continue;
134 		}
135 		ba.ba_nodenr = nodenr;
136 		ba.ba_ivec = 256 + lastiv;
137 		lastiv += 4;
138 		config_found(&sc->sc_dev, &ba, bi_print);
139 	}
140 }
141