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