isa.c revision 1.55.2.2 1 /*-
2 * Copyright (c) 1993, 1994 Charles Hannum.
3 * Copyright (c) 1991 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * William Jolitz.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * from: @(#)isa.c 7.2 (Berkeley) 5/13/91
38 * $Id: isa.c,v 1.55.2.2 1994/10/11 09:46:36 mycroft Exp $
39 */
40
41 /*
42 * Code to manage AT bus
43 */
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/conf.h>
49 #include <sys/malloc.h>
50 #include <sys/device.h>
51
52 #include <machine/pio.h>
53
54 #include <i386/isa/isareg.h>
55 #include <i386/isa/isa_device.h>
56 #include <i386/isa/isavar.h>
57 #include <i386/isa/ic/i8042.h>
58
59 /* sorry, has to be here, no place else really suitable */
60 #include <machine/pc/display.h>
61 u_short *Crtat = (u_short *)MONO_BUF;
62
63 /*
64 * Configure all ISA devices
65 *
66 * XXX This code is a hack. It wants to be new config, but can't be until the
67 * interrupt system is redone. For now, we do some gross hacks to make it look
68 * 99% like new config.
69 */
70 static char *msgs[3] = { "", " not configured\n", " unsupported\n" };
71
72 struct cfdata *
73 config_search(fn, parent, aux)
74 cfmatch_t fn;
75 struct device *parent;
76 void *aux;
77 {
78 struct cfdata *cf = 0;
79 struct device *dv = 0;
80 size_t devsize;
81 struct cfdriver *cd;
82 struct isa_device *id,
83 *idp = parent ? (void *)parent->dv_cfdata->cf_loc : 0;
84
85 for (id = isa_devtab; id->id_driver; id++) {
86 if (id->id_state == FSTATE_FOUND)
87 continue;
88 if (id->id_parent != idp)
89 continue;
90 cd = id->id_driver;
91 if (id->id_unit < cd->cd_ndevs) {
92 if (cd->cd_devs[id->id_unit] != 0)
93 continue;
94 } else {
95 int old = cd->cd_ndevs, new;
96 void **nsp;
97
98 if (old == 0)
99 new = MINALLOCSIZE / sizeof(void *);
100 else
101 new = old * 2;
102 while (new <= id->id_unit)
103 new *= 2;
104 cd->cd_ndevs = new;
105 nsp = malloc(new * sizeof(void *), M_DEVBUF, M_NOWAIT);
106 if (nsp == 0)
107 panic("config_search: %sing dev array",
108 old != 0 ? "expand" : "creat");
109 bzero(nsp + old, (new - old) * sizeof(void *));
110 if (old != 0) {
111 bcopy(cd->cd_devs, nsp, old * sizeof(void *));
112 free(cd->cd_devs, M_DEVBUF);
113 }
114 cd->cd_devs = nsp;
115 }
116 if (!cf) {
117 cf = malloc(sizeof(struct cfdata), M_DEVBUF, M_NOWAIT);
118 if (!cf)
119 panic("config_search: creating cfdata");
120 }
121 cf->cf_driver = cd;
122 cf->cf_unit = id->id_unit;
123 cf->cf_fstate = 0;
124 cf->cf_loc = (void *)id;
125 cf->cf_flags = id->id_flags;
126 cf->cf_parents = 0;
127 cf->cf_ivstubs = 0;
128 if (dv && devsize != cd->cd_devsize) {
129 free(dv, M_DEVBUF);
130 dv = 0;
131 }
132 if (!dv) {
133 devsize = cd->cd_devsize;
134 dv = malloc(devsize, M_DEVBUF, M_NOWAIT);
135 if (!dv)
136 panic("config_search: creating softc");
137 }
138 bzero(dv, cd->cd_devsize);
139 dv->dv_class = cd->cd_class;
140 dv->dv_cfdata = cf;
141 dv->dv_unit = id->id_unit;
142 sprintf(dv->dv_xname, "%s%d", cd->cd_name, id->id_unit);
143 dv->dv_parent = parent;
144 cd->cd_devs[id->id_unit] = dv;
145 if (fn) {
146 if ((*fn)(parent, dv, aux))
147 return cf;
148 } else {
149 if ((*cd->cd_match)(parent, dv, aux))
150 return cf;
151 }
152 cd->cd_devs[id->id_unit] = 0;
153 }
154 if (cf)
155 free(cf, M_DEVBUF);
156 if (dv)
157 free(dv, M_DEVBUF);
158 return 0;
159 }
160
161 void
162 config_attach(parent, cf, aux, print)
163 struct device *parent;
164 struct cfdata *cf;
165 void *aux;
166 cfprint_t print;
167 {
168 struct isa_device *id = (void *)cf->cf_loc;
169 struct cfdriver *cd = cf->cf_driver;
170 struct device *dv = cd->cd_devs[id->id_unit];
171
172 cf->cf_fstate = id->id_state = FSTATE_FOUND;
173 printf("%s at %s", dv->dv_xname, parent ? parent->dv_xname : "isa0");
174 if (print)
175 (void) (*print)(aux, (char *)0);
176 (*cd->cd_attach)(parent, dv, aux);
177 }
178
179 int
180 config_found(parent, aux, print)
181 struct device *parent;
182 void *aux;
183 cfprint_t print;
184 {
185 struct cfdata *cf;
186
187 if ((cf = config_search((cfmatch_t)NULL, parent, aux)) != NULL) {
188 config_attach(parent, cf, aux, print);
189 return 1;
190 }
191 if (print)
192 printf(msgs[(*print)(aux, parent->dv_xname)]);
193 return 0;
194 }
195
196 int
197 isaprint(aux, isa)
198 void *aux;
199 char *isa;
200 {
201 struct isa_attach_args *ia = aux;
202
203 if (ia->ia_iosize)
204 printf(" port 0x%x", ia->ia_iobase);
205 if (ia->ia_iosize > 1)
206 printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
207 if (ia->ia_msize)
208 printf(" iomem 0x%x", ia->ia_maddr - atdevbase + 0xa0000);
209 if (ia->ia_msize > 1)
210 printf("-0x%x",
211 ia->ia_maddr - atdevbase + 0xa0000 + ia->ia_msize - 1);
212 if (ia->ia_irq)
213 printf(" irq %d", ffs(ia->ia_irq) - 1);
214 if (ia->ia_drq != (u_short)-1)
215 printf(" drq %d", ia->ia_drq);
216 /* XXXX print flags */
217 return QUIET;
218 }
219
220 int
221 isasubmatch(parent, self, aux)
222 struct device *parent, *self;
223 void *aux;
224 {
225 struct isa_device *id = (void *)self->dv_cfdata->cf_loc;
226 struct isa_attach_args ia;
227
228 ia.ia_iobase = id->id_iobase;
229 ia.ia_iosize = 0x666;
230 ia.ia_irq = id->id_irq;
231 ia.ia_drq = id->id_drq;
232 ia.ia_maddr = id->id_maddr - 0xa0000 + atdevbase;
233 ia.ia_msize = id->id_msize;
234
235 if (!(*id->id_driver->cd_match)(parent, self, &ia)) {
236 /*
237 * If we don't do this, isa_configure() will repeatedly try to
238 * probe devices that weren't found. But we need to be careful
239 * to do it only for the ISA bus, or we would cause things like
240 * `com0 at ast? slave ?' to not probe on the second ast.
241 */
242 if (!parent)
243 id->id_state = FSTATE_FOUND;
244
245 return 0;
246 }
247
248 config_attach(parent, self->dv_cfdata, &ia, isaprint);
249
250 return 1;
251 }
252
253 void
254 isa_configure()
255 {
256
257 startrtclock();
258
259 while (config_search(isasubmatch, NULL, NULL));
260
261 printf("biomask %x netmask %x ttymask %x\n",
262 (u_short)imask[IPL_BIO], (u_short)imask[IPL_NET],
263 (u_short)imask[IPL_TTY]);
264
265 spl0();
266 }
267