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