xref: /netbsd-src/sys/dev/eisa/eisa.c (revision fdecd6a253f999ae92b139670d9e15cc9df4497c)
1 /*	$NetBSD: eisa.c,v 1.17 1997/06/06 23:30:06 thorpej 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 #ifdef __BROKEN_INDIRECT_CONFIG
52 int	eisamatch __P((struct device *, void *, void *));
53 #else
54 int	eisamatch __P((struct device *, struct cfdata *, void *));
55 #endif
56 void	eisaattach __P((struct device *, struct device *, void *));
57 
58 struct cfattach eisa_ca = {
59 	sizeof(struct device), eisamatch, eisaattach
60 };
61 
62 struct cfdriver eisa_cd = {
63 	NULL, "eisa", DV_DULL
64 };
65 
66 #ifdef __BROKEN_INDIRECT_CONFIG
67 int	eisasubmatch __P((struct device *, void *, void *));
68 #else
69 int	eisasubmatch __P((struct device *, struct cfdata *, void *));
70 #endif
71 int	eisaprint __P((void *, const char *));
72 void	eisa_devinfo __P((const char *, char *));
73 
74 int
75 #ifdef __BROKEN_INDIRECT_CONFIG
76 eisamatch(parent, match, aux)
77 #else
78 eisamatch(parent, cf, aux)
79 #endif
80 	struct device *parent;
81 #ifdef __BROKEN_INDIRECT_CONFIG
82 	void *match;
83 #else
84 	struct cfdata *cf;
85 #endif
86 	void *aux;
87 {
88 #ifdef __BROKEN_INDIRECT_CONFIG
89 	struct cfdata *cf = match;
90 #endif
91 	struct eisabus_attach_args *eba = aux;
92 
93 	if (strcmp(eba->eba_busname, cf->cf_driver->cd_name))
94 		return (0);
95 
96 	/* XXX check other indicators */
97 
98 	return (1);
99 }
100 
101 int
102 eisaprint(aux, pnp)
103 	void *aux;
104 	const char *pnp;
105 {
106 	register struct eisa_attach_args *ea = aux;
107 	char devinfo[256];
108 
109 	if (pnp) {
110 		eisa_devinfo(ea->ea_idstring, devinfo);
111 		printf("%s at %s", devinfo, pnp);
112 	}
113 	printf(" slot %d", ea->ea_slot);
114 	return (UNCONF);
115 }
116 
117 int
118 #ifdef __BROKEN_INDIRECT_CONFIG
119 eisasubmatch(parent, match, aux)
120 #else
121 eisasubmatch(parent, cf, aux)
122 #endif
123 	struct device *parent;
124 #ifdef __BROKEN_INDIRECT_CONFIG
125 	void *match;
126 #else
127 	struct cfdata *cf;
128 #endif
129 	void *aux;
130 {
131 #ifdef __BROKEN_INDIRECT_CONFIG
132 	struct cfdata *cf = match;
133 #endif
134 	struct eisa_attach_args *ea = aux;
135 
136 	if (cf->eisacf_slot != EISA_UNKNOWN_SLOT &&
137 	    cf->eisacf_slot != ea->ea_slot)
138 		return 0;
139 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
140 }
141 
142 void
143 eisaattach(parent, self, aux)
144 	struct device *parent, *self;
145 	void *aux;
146 {
147 	struct eisabus_attach_args *eba = aux;
148 	bus_space_tag_t iot, memt;
149 	bus_dma_tag_t dmat;
150 	eisa_chipset_tag_t ec;
151 	int slot, maxnslots;
152 
153 	eisa_attach_hook(parent, self, eba);
154 	printf("\n");
155 
156 	iot = eba->eba_iot;
157 	memt = eba->eba_memt;
158 	ec = eba->eba_ec;
159 	dmat = eba->eba_dmat;
160 
161 	/*
162 	 * Search for and attach subdevices.
163 	 *
164 	 * Slot 0 is the "motherboard" slot, and the code attaching
165 	 * the EISA bus should have already attached an ISA bus there.
166 	 */
167 	maxnslots = eisa_maxslots(ec);
168 	for (slot = 1; slot < maxnslots; slot++) {
169 		struct eisa_attach_args ea;
170 		u_int slotaddr;
171 		bus_space_handle_t slotioh;
172 		int i;
173 
174 		ea.ea_iot = iot;
175 		ea.ea_memt = memt;
176 		ea.ea_ec = ec;
177 		ea.ea_dmat = dmat;
178 		ea.ea_slot = slot;
179 		slotaddr = EISA_SLOT_ADDR(slot);
180 
181 		/*
182 		 * Get a mapping for the whole slot-specific address
183 		 * space.  If we can't, assume nothing's there but warn
184 		 * about it.
185 		 */
186 		if (bus_space_map(iot, slotaddr, EISA_SLOT_SIZE, 0, &slotioh)) {
187 			printf("%s: can't map I/O space for slot %d\n",
188 			    self->dv_xname, slot);
189 			continue;
190 		}
191 
192 		/* Get the vendor ID bytes */
193 		for (i = 0; i < EISA_NVIDREGS; i++)
194 			ea.ea_vid[i] = bus_space_read_1(iot, slotioh,
195 			    EISA_SLOTOFF_VID + i);
196 
197 		/* Check for device existence */
198 		if (EISA_VENDID_NODEV(ea.ea_vid)) {
199 #if 0
200 			printf("no device at %s slot %d\n", self->dv_xname,
201 			    slot);
202 			printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0],
203 			    ea.ea_vid[1]);
204 #endif
205 			bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
206 			continue;
207 		}
208 
209 		/* And check that the firmware didn't biff something badly */
210 		if (EISA_VENDID_IDDELAY(ea.ea_vid)) {
211 			printf("%s slot %d not configured by BIOS?\n",
212 			    self->dv_xname, slot);
213 			bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
214 			continue;
215 		}
216 
217 		/* Get the product ID bytes */
218 		for (i = 0; i < EISA_NPIDREGS; i++)
219 			ea.ea_pid[i] = bus_space_read_1(iot, slotioh,
220 			    EISA_SLOTOFF_PID + i);
221 
222 		/* Create the ID string from the vendor and product IDs */
223 		ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid);
224 		ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid);
225 		ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid);
226 		ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid);
227 		ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid);
228 		ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid);
229 		ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid);
230 		ea.ea_idstring[7] = '\0';		/* sanity */
231 
232 		/* We no longer need the I/O handle; free it. */
233 		bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
234 
235 		/* Attach matching device. */
236 		config_found_sm(self, &ea, eisaprint, eisasubmatch);
237 	}
238 }
239 
240 #ifdef EISAVERBOSE
241 /*
242  * Descriptions of of known vendors and devices ("products").
243  */
244 struct eisa_knowndev {
245 	int	flags;
246 	const char *id, *name;
247 };
248 #define EISA_KNOWNDEV_NOPROD	0x01		/* match on vendor only */
249 
250 #include <dev/eisa/eisadevs_data.h>
251 #endif /* EISAVERBOSE */
252 
253 void
254 eisa_devinfo(id, cp)
255 	const char *id;
256 	char *cp;
257 {
258 	const char *name;
259 	int onlyvendor;
260 #ifdef EISAVERBOSE
261 	struct eisa_knowndev *edp;
262 	int match;
263 	const char *unmatched = "unknown ";
264 #else
265 	const char *unmatched = "";
266 #endif
267 
268 	onlyvendor = 0;
269 	name = NULL;
270 
271 #ifdef EISAVERBOSE
272 	/* find the device in the table, if possible. */
273 	edp = eisa_knowndevs;
274 	while (edp->id != NULL) {
275 		/* check this entry for a match */
276 		if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0)
277 			match = !strncmp(edp->id, id, 3);
278 		else
279 			match = !strcmp(edp->id, id);
280 		if (match) {
281 			name = edp->name;
282 			onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0;
283 			break;
284 		}
285 		edp++;
286 	}
287 #endif
288 
289 	if (name == NULL)
290 		cp += sprintf(cp, "%sdevice %s", unmatched, id);
291 	else if (onlyvendor)			/* never if not EISAVERBOSE */
292 		cp += sprintf(cp, "unknown %s device %s", name, id);
293 	else
294 		cp += sprintf(cp, "%s", name);
295 }
296