eisa.c revision 1.17 1 1.17 thorpej /* $NetBSD: eisa.c,v 1.17 1997/06/06 23:30:06 thorpej Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.1 cgd * Copyright (c) 1995, 1996 Christopher G. Demetriou
5 1.1 cgd * All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by Christopher G. Demetriou
18 1.1 cgd * for the NetBSD Project.
19 1.1 cgd * 4. The name of the author may not be used to endorse or promote products
20 1.1 cgd * derived from this software without specific prior written permission
21 1.1 cgd *
22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 cgd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 cgd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 cgd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 cgd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 cgd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 cgd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 cgd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 cgd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 cgd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd /*
35 1.1 cgd * EISA Bus device
36 1.1 cgd *
37 1.1 cgd * Makes sure an EISA bus is present, and finds and attaches devices
38 1.1 cgd * living on it.
39 1.1 cgd */
40 1.1 cgd
41 1.1 cgd #include <sys/param.h>
42 1.1 cgd #include <sys/systm.h>
43 1.1 cgd #include <sys/device.h>
44 1.1 cgd
45 1.6 cgd #include <machine/bus.h>
46 1.6 cgd
47 1.1 cgd #include <dev/eisa/eisareg.h>
48 1.1 cgd #include <dev/eisa/eisavar.h>
49 1.1 cgd #include <dev/eisa/eisadevs.h>
50 1.1 cgd
51 1.16 cgd #ifdef __BROKEN_INDIRECT_CONFIG
52 1.1 cgd int eisamatch __P((struct device *, void *, void *));
53 1.16 cgd #else
54 1.16 cgd int eisamatch __P((struct device *, struct cfdata *, void *));
55 1.16 cgd #endif
56 1.1 cgd void eisaattach __P((struct device *, struct device *, void *));
57 1.1 cgd
58 1.8 thorpej struct cfattach eisa_ca = {
59 1.8 thorpej sizeof(struct device), eisamatch, eisaattach
60 1.8 thorpej };
61 1.8 thorpej
62 1.8 thorpej struct cfdriver eisa_cd = {
63 1.10 cgd NULL, "eisa", DV_DULL
64 1.1 cgd };
65 1.1 cgd
66 1.16 cgd #ifdef __BROKEN_INDIRECT_CONFIG
67 1.1 cgd int eisasubmatch __P((struct device *, void *, void *));
68 1.16 cgd #else
69 1.16 cgd int eisasubmatch __P((struct device *, struct cfdata *, void *));
70 1.16 cgd #endif
71 1.12 cgd int eisaprint __P((void *, const char *));
72 1.1 cgd void eisa_devinfo __P((const char *, char *));
73 1.1 cgd
74 1.1 cgd int
75 1.16 cgd #ifdef __BROKEN_INDIRECT_CONFIG
76 1.1 cgd eisamatch(parent, match, aux)
77 1.16 cgd #else
78 1.16 cgd eisamatch(parent, cf, aux)
79 1.16 cgd #endif
80 1.10 cgd struct device *parent;
81 1.16 cgd #ifdef __BROKEN_INDIRECT_CONFIG
82 1.16 cgd void *match;
83 1.16 cgd #else
84 1.16 cgd struct cfdata *cf;
85 1.16 cgd #endif
86 1.16 cgd void *aux;
87 1.1 cgd {
88 1.16 cgd #ifdef __BROKEN_INDIRECT_CONFIG
89 1.1 cgd struct cfdata *cf = match;
90 1.16 cgd #endif
91 1.1 cgd struct eisabus_attach_args *eba = aux;
92 1.1 cgd
93 1.1 cgd if (strcmp(eba->eba_busname, cf->cf_driver->cd_name))
94 1.1 cgd return (0);
95 1.1 cgd
96 1.1 cgd /* XXX check other indicators */
97 1.1 cgd
98 1.10 cgd return (1);
99 1.1 cgd }
100 1.1 cgd
101 1.1 cgd int
102 1.2 cgd eisaprint(aux, pnp)
103 1.1 cgd void *aux;
104 1.12 cgd const char *pnp;
105 1.1 cgd {
106 1.1 cgd register struct eisa_attach_args *ea = aux;
107 1.2 cgd char devinfo[256];
108 1.1 cgd
109 1.2 cgd if (pnp) {
110 1.2 cgd eisa_devinfo(ea->ea_idstring, devinfo);
111 1.14 christos printf("%s at %s", devinfo, pnp);
112 1.2 cgd }
113 1.14 christos printf(" slot %d", ea->ea_slot);
114 1.1 cgd return (UNCONF);
115 1.1 cgd }
116 1.1 cgd
117 1.1 cgd int
118 1.16 cgd #ifdef __BROKEN_INDIRECT_CONFIG
119 1.1 cgd eisasubmatch(parent, match, aux)
120 1.16 cgd #else
121 1.16 cgd eisasubmatch(parent, cf, aux)
122 1.16 cgd #endif
123 1.1 cgd struct device *parent;
124 1.16 cgd #ifdef __BROKEN_INDIRECT_CONFIG
125 1.16 cgd void *match;
126 1.16 cgd #else
127 1.16 cgd struct cfdata *cf;
128 1.16 cgd #endif
129 1.16 cgd void *aux;
130 1.1 cgd {
131 1.16 cgd #ifdef __BROKEN_INDIRECT_CONFIG
132 1.1 cgd struct cfdata *cf = match;
133 1.16 cgd #endif
134 1.1 cgd struct eisa_attach_args *ea = aux;
135 1.1 cgd
136 1.1 cgd if (cf->eisacf_slot != EISA_UNKNOWN_SLOT &&
137 1.1 cgd cf->eisacf_slot != ea->ea_slot)
138 1.1 cgd return 0;
139 1.16 cgd return ((*cf->cf_attach->ca_match)(parent, cf, aux));
140 1.1 cgd }
141 1.1 cgd
142 1.1 cgd void
143 1.1 cgd eisaattach(parent, self, aux)
144 1.10 cgd struct device *parent, *self;
145 1.10 cgd void *aux;
146 1.1 cgd {
147 1.6 cgd struct eisabus_attach_args *eba = aux;
148 1.15 thorpej bus_space_tag_t iot, memt;
149 1.17 thorpej bus_dma_tag_t dmat;
150 1.11 cgd eisa_chipset_tag_t ec;
151 1.11 cgd int slot, maxnslots;
152 1.1 cgd
153 1.11 cgd eisa_attach_hook(parent, self, eba);
154 1.14 christos printf("\n");
155 1.1 cgd
156 1.15 thorpej iot = eba->eba_iot;
157 1.15 thorpej memt = eba->eba_memt;
158 1.11 cgd ec = eba->eba_ec;
159 1.17 thorpej dmat = eba->eba_dmat;
160 1.6 cgd
161 1.1 cgd /*
162 1.1 cgd * Search for and attach subdevices.
163 1.1 cgd *
164 1.1 cgd * Slot 0 is the "motherboard" slot, and the code attaching
165 1.1 cgd * the EISA bus should have already attached an ISA bus there.
166 1.1 cgd */
167 1.11 cgd maxnslots = eisa_maxslots(ec);
168 1.11 cgd for (slot = 1; slot < maxnslots; slot++) {
169 1.1 cgd struct eisa_attach_args ea;
170 1.1 cgd u_int slotaddr;
171 1.15 thorpej bus_space_handle_t slotioh;
172 1.1 cgd int i;
173 1.1 cgd
174 1.15 thorpej ea.ea_iot = iot;
175 1.15 thorpej ea.ea_memt = memt;
176 1.11 cgd ea.ea_ec = ec;
177 1.17 thorpej ea.ea_dmat = dmat;
178 1.1 cgd ea.ea_slot = slot;
179 1.1 cgd slotaddr = EISA_SLOT_ADDR(slot);
180 1.1 cgd
181 1.6 cgd /*
182 1.6 cgd * Get a mapping for the whole slot-specific address
183 1.6 cgd * space. If we can't, assume nothing's there but warn
184 1.6 cgd * about it.
185 1.6 cgd */
186 1.15 thorpej if (bus_space_map(iot, slotaddr, EISA_SLOT_SIZE, 0, &slotioh)) {
187 1.14 christos printf("%s: can't map I/O space for slot %d\n",
188 1.9 christos self->dv_xname, slot);
189 1.6 cgd continue;
190 1.6 cgd }
191 1.6 cgd
192 1.1 cgd /* Get the vendor ID bytes */
193 1.1 cgd for (i = 0; i < EISA_NVIDREGS; i++)
194 1.15 thorpej ea.ea_vid[i] = bus_space_read_1(iot, slotioh,
195 1.6 cgd EISA_SLOTOFF_VID + i);
196 1.1 cgd
197 1.1 cgd /* Check for device existence */
198 1.1 cgd if (EISA_VENDID_NODEV(ea.ea_vid)) {
199 1.1 cgd #if 0
200 1.14 christos printf("no device at %s slot %d\n", self->dv_xname,
201 1.1 cgd slot);
202 1.14 christos printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0],
203 1.1 cgd ea.ea_vid[1]);
204 1.1 cgd #endif
205 1.15 thorpej bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
206 1.1 cgd continue;
207 1.1 cgd }
208 1.1 cgd
209 1.1 cgd /* And check that the firmware didn't biff something badly */
210 1.1 cgd if (EISA_VENDID_IDDELAY(ea.ea_vid)) {
211 1.14 christos printf("%s slot %d not configured by BIOS?\n",
212 1.1 cgd self->dv_xname, slot);
213 1.15 thorpej bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
214 1.1 cgd continue;
215 1.1 cgd }
216 1.1 cgd
217 1.1 cgd /* Get the product ID bytes */
218 1.1 cgd for (i = 0; i < EISA_NPIDREGS; i++)
219 1.15 thorpej ea.ea_pid[i] = bus_space_read_1(iot, slotioh,
220 1.6 cgd EISA_SLOTOFF_PID + i);
221 1.1 cgd
222 1.1 cgd /* Create the ID string from the vendor and product IDs */
223 1.1 cgd ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid);
224 1.1 cgd ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid);
225 1.1 cgd ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid);
226 1.1 cgd ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid);
227 1.1 cgd ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid);
228 1.1 cgd ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid);
229 1.1 cgd ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid);
230 1.1 cgd ea.ea_idstring[7] = '\0'; /* sanity */
231 1.6 cgd
232 1.6 cgd /* We no longer need the I/O handle; free it. */
233 1.15 thorpej bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
234 1.1 cgd
235 1.2 cgd /* Attach matching device. */
236 1.2 cgd config_found_sm(self, &ea, eisaprint, eisasubmatch);
237 1.1 cgd }
238 1.1 cgd }
239 1.1 cgd
240 1.1 cgd #ifdef EISAVERBOSE
241 1.10 cgd /*
242 1.1 cgd * Descriptions of of known vendors and devices ("products").
243 1.10 cgd */
244 1.1 cgd struct eisa_knowndev {
245 1.1 cgd int flags;
246 1.1 cgd const char *id, *name;
247 1.10 cgd };
248 1.10 cgd #define EISA_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
249 1.1 cgd
250 1.1 cgd #include <dev/eisa/eisadevs_data.h>
251 1.1 cgd #endif /* EISAVERBOSE */
252 1.1 cgd
253 1.1 cgd void
254 1.1 cgd eisa_devinfo(id, cp)
255 1.1 cgd const char *id;
256 1.1 cgd char *cp;
257 1.1 cgd {
258 1.1 cgd const char *name;
259 1.1 cgd int onlyvendor;
260 1.1 cgd #ifdef EISAVERBOSE
261 1.1 cgd struct eisa_knowndev *edp;
262 1.1 cgd int match;
263 1.5 cgd const char *unmatched = "unknown ";
264 1.3 cgd #else
265 1.3 cgd const char *unmatched = "";
266 1.1 cgd #endif
267 1.1 cgd
268 1.1 cgd onlyvendor = 0;
269 1.1 cgd name = NULL;
270 1.1 cgd
271 1.1 cgd #ifdef EISAVERBOSE
272 1.1 cgd /* find the device in the table, if possible. */
273 1.1 cgd edp = eisa_knowndevs;
274 1.1 cgd while (edp->id != NULL) {
275 1.1 cgd /* check this entry for a match */
276 1.1 cgd if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0)
277 1.1 cgd match = !strncmp(edp->id, id, 3);
278 1.1 cgd else
279 1.1 cgd match = !strcmp(edp->id, id);
280 1.1 cgd if (match) {
281 1.1 cgd name = edp->name;
282 1.1 cgd onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0;
283 1.1 cgd break;
284 1.1 cgd }
285 1.1 cgd edp++;
286 1.1 cgd }
287 1.1 cgd #endif
288 1.1 cgd
289 1.1 cgd if (name == NULL)
290 1.14 christos cp += sprintf(cp, "%sdevice %s", unmatched, id);
291 1.3 cgd else if (onlyvendor) /* never if not EISAVERBOSE */
292 1.14 christos cp += sprintf(cp, "unknown %s device %s", name, id);
293 1.1 cgd else
294 1.14 christos cp += sprintf(cp, "%s", name);
295 1.1 cgd }
296