uba.c revision 1.48.2.2 1 1.48.2.2 thorpej /* $NetBSD: uba.c,v 1.48.2.2 1999/06/21 01:18:55 thorpej Exp $ */
2 1.48.2.2 thorpej /*
3 1.48.2.2 thorpej * Copyright (c) 1996 Jonathan Stone.
4 1.48.2.2 thorpej * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
5 1.48.2.2 thorpej * Copyright (c) 1982, 1986 The Regents of the University of California.
6 1.48.2.2 thorpej * All rights reserved.
7 1.48.2.2 thorpej *
8 1.48.2.2 thorpej * Redistribution and use in source and binary forms, with or without
9 1.48.2.2 thorpej * modification, are permitted provided that the following conditions
10 1.48.2.2 thorpej * are met:
11 1.48.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
12 1.48.2.2 thorpej * notice, this list of conditions and the following disclaimer.
13 1.48.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
14 1.48.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
15 1.48.2.2 thorpej * documentation and/or other materials provided with the distribution.
16 1.48.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
17 1.48.2.2 thorpej * must display the following acknowledgement:
18 1.48.2.2 thorpej * This product includes software developed by the University of
19 1.48.2.2 thorpej * California, Berkeley and its contributors.
20 1.48.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
21 1.48.2.2 thorpej * may be used to endorse or promote products derived from this software
22 1.48.2.2 thorpej * without specific prior written permission.
23 1.48.2.2 thorpej *
24 1.48.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.48.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.48.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.48.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.48.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.48.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.48.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.48.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.48.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.48.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.48.2.2 thorpej * SUCH DAMAGE.
35 1.48.2.2 thorpej *
36 1.48.2.2 thorpej * @(#)uba.c 7.10 (Berkeley) 12/16/90
37 1.48.2.2 thorpej * @(#)autoconf.c 7.20 (Berkeley) 5/9/91
38 1.48.2.2 thorpej */
39 1.48.2.2 thorpej
40 1.48.2.2 thorpej #include <sys/param.h>
41 1.48.2.2 thorpej #include <sys/types.h>
42 1.48.2.2 thorpej #include <sys/time.h>
43 1.48.2.2 thorpej #include <sys/systm.h>
44 1.48.2.2 thorpej #include <sys/map.h>
45 1.48.2.2 thorpej #include <sys/buf.h>
46 1.48.2.2 thorpej #include <sys/proc.h>
47 1.48.2.2 thorpej #include <sys/user.h>
48 1.48.2.2 thorpej #include <sys/conf.h>
49 1.48.2.2 thorpej #include <sys/dkstat.h>
50 1.48.2.2 thorpej #include <sys/kernel.h>
51 1.48.2.2 thorpej #include <sys/malloc.h>
52 1.48.2.2 thorpej #include <sys/device.h>
53 1.48.2.2 thorpej
54 1.48.2.2 thorpej #include <vm/vm.h>
55 1.48.2.2 thorpej #include <vm/vm_kern.h>
56 1.48.2.2 thorpej
57 1.48.2.2 thorpej #include <machine/bus.h>
58 1.48.2.2 thorpej #include <machine/scb.h>
59 1.48.2.2 thorpej #include <machine/cpu.h>
60 1.48.2.2 thorpej
61 1.48.2.2 thorpej #include <dev/qbus/ubavar.h>
62 1.48.2.2 thorpej
63 1.48.2.2 thorpej #include "ioconf.h"
64 1.48.2.2 thorpej
65 1.48.2.2 thorpej static int ubasearch __P((struct device *, struct cfdata *, void *));
66 1.48.2.2 thorpej static int ubaprint __P((void *, const char *));
67 1.48.2.2 thorpej
68 1.48.2.2 thorpej /*
69 1.48.2.2 thorpej * If we failed to allocate uba resources, put us on a queue to wait
70 1.48.2.2 thorpej * until there is available resources. Resources to compete about
71 1.48.2.2 thorpej * are map registers and BDPs. This is normally only a problem on
72 1.48.2.2 thorpej * Unibus systems, Qbus systems have more map registers than usable.
73 1.48.2.2 thorpej */
74 1.48.2.2 thorpej void
75 1.48.2.2 thorpej uba_enqueue(uu)
76 1.48.2.2 thorpej struct uba_unit *uu;
77 1.48.2.2 thorpej {
78 1.48.2.2 thorpej struct uba_softc *uh;
79 1.48.2.2 thorpej int s;
80 1.48.2.2 thorpej
81 1.48.2.2 thorpej uh = (void *)((struct device *)(uu->uu_softc))->dv_parent;
82 1.48.2.2 thorpej
83 1.48.2.2 thorpej s = splimp();
84 1.48.2.2 thorpej SIMPLEQ_INSERT_TAIL(&uh->uh_resq, uu, uu_resq);
85 1.48.2.2 thorpej splx(s);
86 1.48.2.2 thorpej }
87 1.48.2.2 thorpej
88 1.48.2.2 thorpej /*
89 1.48.2.2 thorpej * When a routine that uses resources is finished, the next device
90 1.48.2.2 thorpej * in queue for map registers etc is called. If it succeeds to get
91 1.48.2.2 thorpej * resources, call next, and next, and next...
92 1.48.2.2 thorpej * This routine must be called at splimp.
93 1.48.2.2 thorpej */
94 1.48.2.2 thorpej void
95 1.48.2.2 thorpej uba_done(uh)
96 1.48.2.2 thorpej struct uba_softc *uh;
97 1.48.2.2 thorpej {
98 1.48.2.2 thorpej struct uba_unit *uu;
99 1.48.2.2 thorpej
100 1.48.2.2 thorpej while ((uu = SIMPLEQ_FIRST(&uh->uh_resq))) {
101 1.48.2.2 thorpej SIMPLEQ_REMOVE_HEAD(&uh->uh_resq, uu, uu_resq);
102 1.48.2.2 thorpej if ((*uu->uu_ready)(uu) == 0) {
103 1.48.2.2 thorpej SIMPLEQ_INSERT_HEAD(&uh->uh_resq, uu, uu_resq);
104 1.48.2.2 thorpej break;
105 1.48.2.2 thorpej }
106 1.48.2.2 thorpej }
107 1.48.2.2 thorpej }
108 1.48.2.2 thorpej
109 1.48.2.2 thorpej /*
110 1.48.2.2 thorpej * Generate a reset on uba number uban. Then
111 1.48.2.2 thorpej * call each device that asked to be called during attach,
112 1.48.2.2 thorpej * giving it a chance to clean up so as to be able to continue.
113 1.48.2.2 thorpej */
114 1.48.2.2 thorpej void
115 1.48.2.2 thorpej ubareset(uban)
116 1.48.2.2 thorpej int uban;
117 1.48.2.2 thorpej {
118 1.48.2.2 thorpej register struct uba_softc *uh = uba_cd.cd_devs[uban];
119 1.48.2.2 thorpej int s, i;
120 1.48.2.2 thorpej
121 1.48.2.2 thorpej s = splimp();
122 1.48.2.2 thorpej SIMPLEQ_INIT(&uh->uh_resq);
123 1.48.2.2 thorpej printf("%s: reset", uh->uh_dev.dv_xname);
124 1.48.2.2 thorpej (*uh->uh_ubainit)(uh);
125 1.48.2.2 thorpej
126 1.48.2.2 thorpej for (i = 0; i < uh->uh_resno; i++)
127 1.48.2.2 thorpej (*uh->uh_reset[i])(uh->uh_resarg[i]);
128 1.48.2.2 thorpej printf("\n");
129 1.48.2.2 thorpej splx(s);
130 1.48.2.2 thorpej }
131 1.48.2.2 thorpej
132 1.48.2.2 thorpej /*
133 1.48.2.2 thorpej * The common attach routine:
134 1.48.2.2 thorpej * Calls the scan routine to search for uba devices.
135 1.48.2.2 thorpej */
136 1.48.2.2 thorpej void
137 1.48.2.2 thorpej uba_attach(sc, iopagephys)
138 1.48.2.2 thorpej struct uba_softc *sc;
139 1.48.2.2 thorpej paddr_t iopagephys;
140 1.48.2.2 thorpej {
141 1.48.2.2 thorpej
142 1.48.2.2 thorpej /*
143 1.48.2.2 thorpej * Set last free interrupt vector for devices with
144 1.48.2.2 thorpej * programmable interrupt vectors. Use is to decrement
145 1.48.2.2 thorpej * this number and use result as interrupt vector.
146 1.48.2.2 thorpej */
147 1.48.2.2 thorpej sc->uh_lastiv = 0x200;
148 1.48.2.2 thorpej SIMPLEQ_INIT(&sc->uh_resq);
149 1.48.2.2 thorpej
150 1.48.2.2 thorpej /*
151 1.48.2.2 thorpej * Allocate place for unibus I/O space in virtual space.
152 1.48.2.2 thorpej */
153 1.48.2.2 thorpej if (bus_space_map(sc->uh_iot, iopagephys, UBAIOSIZE, 0, &sc->uh_ioh))
154 1.48.2.2 thorpej return;
155 1.48.2.2 thorpej
156 1.48.2.2 thorpej if (sc->uh_beforescan)
157 1.48.2.2 thorpej (*sc->uh_beforescan)(sc);
158 1.48.2.2 thorpej /*
159 1.48.2.2 thorpej * Now start searching for devices.
160 1.48.2.2 thorpej */
161 1.48.2.2 thorpej config_search(ubasearch,(struct device *)sc, NULL);
162 1.48.2.2 thorpej
163 1.48.2.2 thorpej if (sc->uh_afterscan)
164 1.48.2.2 thorpej (*sc->uh_afterscan)(sc);
165 1.48.2.2 thorpej }
166 1.48.2.2 thorpej
167 1.48.2.2 thorpej int
168 1.48.2.2 thorpej ubasearch(parent, cf, aux)
169 1.48.2.2 thorpej struct device *parent;
170 1.48.2.2 thorpej struct cfdata *cf;
171 1.48.2.2 thorpej void *aux;
172 1.48.2.2 thorpej {
173 1.48.2.2 thorpej struct uba_softc *sc = (struct uba_softc *)parent;
174 1.48.2.2 thorpej struct uba_attach_args ua;
175 1.48.2.2 thorpej int i, vec, br;
176 1.48.2.2 thorpej
177 1.48.2.2 thorpej ua.ua_ioh = ubdevreg(cf->cf_loc[0]) + sc->uh_ioh;
178 1.48.2.2 thorpej ua.ua_iot = sc->uh_iot;
179 1.48.2.2 thorpej ua.ua_dmat = sc->uh_dmat;
180 1.48.2.2 thorpej ua.ua_reset = NULL;
181 1.48.2.2 thorpej
182 1.48.2.2 thorpej if (badaddr((caddr_t)ua.ua_ioh, 2) ||
183 1.48.2.2 thorpej (sc->uh_errchk ? (*sc->uh_errchk)(sc):0))
184 1.48.2.2 thorpej goto forgetit;
185 1.48.2.2 thorpej
186 1.48.2.2 thorpej scb_vecref(0, 0); /* Clear vector ref */
187 1.48.2.2 thorpej i = (*cf->cf_attach->ca_match) (parent, cf, &ua);
188 1.48.2.2 thorpej
189 1.48.2.2 thorpej if (sc->uh_errchk)
190 1.48.2.2 thorpej if ((*sc->uh_errchk)(sc))
191 1.48.2.2 thorpej goto forgetit;
192 1.48.2.2 thorpej if (i == 0)
193 1.48.2.2 thorpej goto forgetit;
194 1.48.2.2 thorpej
195 1.48.2.2 thorpej i = scb_vecref(&vec, &br);
196 1.48.2.2 thorpej if (i == 0)
197 1.48.2.2 thorpej goto fail;
198 1.48.2.2 thorpej if (vec == 0)
199 1.48.2.2 thorpej goto fail;
200 1.48.2.2 thorpej
201 1.48.2.2 thorpej scb_vecalloc(vec, ua.ua_ivec, cf->cf_unit, SCB_ISTACK);
202 1.48.2.2 thorpej if (ua.ua_reset) { /* device wants ubareset */
203 1.48.2.2 thorpej if (sc->uh_resno == 0) {
204 1.48.2.2 thorpej sc->uh_reset = malloc(sizeof(ua.ua_reset),
205 1.48.2.2 thorpej M_DEVBUF, M_NOWAIT);
206 1.48.2.2 thorpej sc->uh_resarg = (int *)sc->uh_reset + 128;
207 1.48.2.2 thorpej }
208 1.48.2.2 thorpej if (sc->uh_resno > 127) {
209 1.48.2.2 thorpej printf("%s: Expand reset table, skipping reset %s%d\n",
210 1.48.2.2 thorpej sc->uh_dev.dv_xname, cf->cf_driver->cd_name,
211 1.48.2.2 thorpej cf->cf_unit);
212 1.48.2.2 thorpej } else {
213 1.48.2.2 thorpej sc->uh_resarg[sc->uh_resno] = cf->cf_unit;
214 1.48.2.2 thorpej sc->uh_reset[sc->uh_resno++] = ua.ua_reset;
215 1.48.2.2 thorpej }
216 1.48.2.2 thorpej }
217 1.48.2.2 thorpej ua.ua_br = br;
218 1.48.2.2 thorpej ua.ua_cvec = vec;
219 1.48.2.2 thorpej ua.ua_iaddr = cf->cf_loc[0];
220 1.48.2.2 thorpej
221 1.48.2.2 thorpej config_attach(parent, cf, &ua, ubaprint);
222 1.48.2.2 thorpej return 0;
223 1.48.2.2 thorpej
224 1.48.2.2 thorpej fail:
225 1.48.2.2 thorpej printf("%s%d at %s csr %o %s\n",
226 1.48.2.2 thorpej cf->cf_driver->cd_name, cf->cf_unit, parent->dv_xname,
227 1.48.2.2 thorpej cf->cf_loc[0], (i ? "zero vector" : "didn't interrupt"));
228 1.48.2.2 thorpej
229 1.48.2.2 thorpej forgetit:
230 1.48.2.2 thorpej return 0;
231 1.48.2.2 thorpej }
232 1.48.2.2 thorpej
233 1.48.2.2 thorpej /*
234 1.48.2.2 thorpej * Print out some interesting info common to all unibus devices.
235 1.48.2.2 thorpej */
236 1.48.2.2 thorpej int
237 1.48.2.2 thorpej ubaprint(aux, uba)
238 1.48.2.2 thorpej void *aux;
239 1.48.2.2 thorpej const char *uba;
240 1.48.2.2 thorpej {
241 1.48.2.2 thorpej struct uba_attach_args *ua = aux;
242 1.48.2.2 thorpej
243 1.48.2.2 thorpej printf(" csr %o vec %o ipl %x", ua->ua_iaddr,
244 1.48.2.2 thorpej ua->ua_cvec & 511, ua->ua_br);
245 1.48.2.2 thorpej return UNCONF;
246 1.48.2.2 thorpej }
247