isa.c revision 1.56 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.56 mycroft * $Id: isa.c,v 1.56 1994/10/07 09:08:29 mycroft 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.56 mycroft if (old == 0)
100 1.56 mycroft new = MINALLOCSIZE / sizeof(void *);
101 1.56 mycroft else
102 1.56 mycroft new = old * 2;
103 1.56 mycroft while (new <= id->id_unit)
104 1.56 mycroft new *= 2;
105 1.56 mycroft cd->cd_ndevs = new;
106 1.56 mycroft nsp = malloc(new * sizeof(void *), M_DEVBUF, M_NOWAIT);
107 1.56 mycroft if (nsp == 0)
108 1.56 mycroft panic("config_search: %sing dev array",
109 1.56 mycroft old != 0 ? "expand" : "creat");
110 1.56 mycroft bzero(nsp + old, (new - old) * sizeof(void *));
111 1.56 mycroft if (old != 0) {
112 1.46 mycroft bcopy(cd->cd_devs, nsp, old * sizeof(void *));
113 1.46 mycroft free(cd->cd_devs, M_DEVBUF);
114 1.46 mycroft }
115 1.46 mycroft cd->cd_devs = nsp;
116 1.46 mycroft }
117 1.46 mycroft if (!cf) {
118 1.51 mycroft cf = malloc(sizeof(struct cfdata), M_DEVBUF, M_NOWAIT);
119 1.51 mycroft if (!cf)
120 1.46 mycroft panic("config_search: creating cfdata");
121 1.46 mycroft }
122 1.46 mycroft cf->cf_driver = cd;
123 1.46 mycroft cf->cf_unit = id->id_unit;
124 1.46 mycroft cf->cf_fstate = 0;
125 1.46 mycroft cf->cf_loc = (void *)id;
126 1.46 mycroft cf->cf_flags = id->id_flags;
127 1.46 mycroft cf->cf_parents = 0;
128 1.46 mycroft cf->cf_ivstubs = 0;
129 1.46 mycroft if (dv && devsize != cd->cd_devsize) {
130 1.46 mycroft free(dv, M_DEVBUF);
131 1.46 mycroft dv = 0;
132 1.46 mycroft }
133 1.46 mycroft if (!dv) {
134 1.46 mycroft devsize = cd->cd_devsize;
135 1.46 mycroft dv = malloc(devsize, M_DEVBUF, M_NOWAIT);
136 1.46 mycroft if (!dv)
137 1.46 mycroft panic("config_search: creating softc");
138 1.46 mycroft }
139 1.46 mycroft bzero(dv, cd->cd_devsize);
140 1.46 mycroft dv->dv_class = cd->cd_class;
141 1.46 mycroft dv->dv_cfdata = cf;
142 1.46 mycroft dv->dv_unit = id->id_unit;
143 1.46 mycroft sprintf(dv->dv_xname, "%s%d", cd->cd_name, id->id_unit);
144 1.46 mycroft dv->dv_parent = parent;
145 1.46 mycroft cd->cd_devs[id->id_unit] = dv;
146 1.46 mycroft if (fn) {
147 1.46 mycroft if ((*fn)(parent, dv, aux))
148 1.46 mycroft return cf;
149 1.46 mycroft } else {
150 1.46 mycroft if ((*cd->cd_match)(parent, dv, aux))
151 1.46 mycroft return cf;
152 1.46 mycroft }
153 1.47 mycroft cd->cd_devs[id->id_unit] = 0;
154 1.46 mycroft }
155 1.46 mycroft if (cf)
156 1.46 mycroft free(cf, M_DEVBUF);
157 1.46 mycroft if (dv)
158 1.46 mycroft free(dv, M_DEVBUF);
159 1.46 mycroft return 0;
160 1.46 mycroft }
161 1.46 mycroft
162 1.46 mycroft void
163 1.46 mycroft config_attach(parent, cf, aux, print)
164 1.46 mycroft struct device *parent;
165 1.46 mycroft struct cfdata *cf;
166 1.46 mycroft void *aux;
167 1.46 mycroft cfprint_t print;
168 1.46 mycroft {
169 1.46 mycroft struct isa_device *id = (void *)cf->cf_loc;
170 1.46 mycroft struct cfdriver *cd = cf->cf_driver;
171 1.46 mycroft struct device *dv = cd->cd_devs[id->id_unit];
172 1.46 mycroft
173 1.46 mycroft cf->cf_fstate = id->id_state = FSTATE_FOUND;
174 1.46 mycroft printf("%s at %s", dv->dv_xname, parent ? parent->dv_xname : "isa0");
175 1.46 mycroft if (print)
176 1.46 mycroft (void) (*print)(aux, (char *)0);
177 1.46 mycroft (*cd->cd_attach)(parent, dv, aux);
178 1.46 mycroft }
179 1.46 mycroft
180 1.46 mycroft int
181 1.46 mycroft config_found(parent, aux, print)
182 1.46 mycroft struct device *parent;
183 1.46 mycroft void *aux;
184 1.46 mycroft cfprint_t print;
185 1.46 mycroft {
186 1.46 mycroft struct cfdata *cf;
187 1.46 mycroft
188 1.46 mycroft if ((cf = config_search((cfmatch_t)NULL, parent, aux)) != NULL) {
189 1.46 mycroft config_attach(parent, cf, aux, print);
190 1.46 mycroft return 1;
191 1.46 mycroft }
192 1.46 mycroft if (print)
193 1.46 mycroft printf(msgs[(*print)(aux, parent->dv_xname)]);
194 1.46 mycroft return 0;
195 1.46 mycroft }
196 1.46 mycroft
197 1.46 mycroft int
198 1.46 mycroft isaprint(aux, isa)
199 1.46 mycroft void *aux;
200 1.46 mycroft char *isa;
201 1.46 mycroft {
202 1.46 mycroft struct isa_attach_args *ia = aux;
203 1.46 mycroft
204 1.46 mycroft if (ia->ia_iosize)
205 1.46 mycroft printf(" port 0x%x", ia->ia_iobase);
206 1.46 mycroft if (ia->ia_iosize > 1)
207 1.46 mycroft printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
208 1.46 mycroft if (ia->ia_msize)
209 1.46 mycroft printf(" iomem 0x%x", ia->ia_maddr - atdevbase + 0xa0000);
210 1.46 mycroft if (ia->ia_msize > 1)
211 1.46 mycroft printf("-0x%x",
212 1.46 mycroft ia->ia_maddr - atdevbase + 0xa0000 + ia->ia_msize - 1);
213 1.46 mycroft if (ia->ia_irq)
214 1.46 mycroft printf(" irq %d", ffs(ia->ia_irq) - 1);
215 1.46 mycroft if (ia->ia_drq != (u_short)-1)
216 1.46 mycroft printf(" drq %d", ia->ia_drq);
217 1.46 mycroft /* XXXX print flags */
218 1.46 mycroft return QUIET;
219 1.46 mycroft }
220 1.46 mycroft
221 1.46 mycroft int
222 1.46 mycroft isasubmatch(parent, self, aux)
223 1.46 mycroft struct device *parent, *self;
224 1.46 mycroft void *aux;
225 1.46 mycroft {
226 1.46 mycroft struct isa_device *id = (void *)self->dv_cfdata->cf_loc;
227 1.46 mycroft struct isa_attach_args ia;
228 1.46 mycroft
229 1.46 mycroft ia.ia_iobase = id->id_iobase;
230 1.46 mycroft ia.ia_iosize = 0x666;
231 1.46 mycroft ia.ia_irq = id->id_irq;
232 1.46 mycroft ia.ia_drq = id->id_drq;
233 1.46 mycroft ia.ia_maddr = id->id_maddr - 0xa0000 + atdevbase;
234 1.46 mycroft ia.ia_msize = id->id_msize;
235 1.46 mycroft
236 1.46 mycroft if (!(*id->id_driver->cd_match)(parent, self, &ia)) {
237 1.46 mycroft /*
238 1.46 mycroft * If we don't do this, isa_configure() will repeatedly try to
239 1.46 mycroft * probe devices that weren't found. But we need to be careful
240 1.46 mycroft * to do it only for the ISA bus, or we would cause things like
241 1.46 mycroft * `com0 at ast? slave ?' to not probe on the second ast.
242 1.46 mycroft */
243 1.46 mycroft if (!parent)
244 1.46 mycroft id->id_state = FSTATE_FOUND;
245 1.46 mycroft
246 1.46 mycroft return 0;
247 1.46 mycroft }
248 1.46 mycroft
249 1.46 mycroft config_attach(parent, self->dv_cfdata, &ia, isaprint);
250 1.46 mycroft
251 1.46 mycroft return 1;
252 1.46 mycroft }
253 1.46 mycroft
254 1.21 andrew void
255 1.30 mycroft isa_configure()
256 1.30 mycroft {
257 1.55 cgd
258 1.55 cgd startrtclock();
259 1.1 cgd
260 1.46 mycroft while (config_search(isasubmatch, NULL, NULL));
261 1.7 cgd
262 1.49 mycroft printf("biomask %x netmask %x ttymask %x\n",
263 1.49 mycroft (u_short)imask[IPL_BIO], (u_short)imask[IPL_NET],
264 1.49 mycroft (u_short)imask[IPL_TTY]);
265 1.26 mycroft
266 1.30 mycroft spl0();
267 1.1 cgd }
268