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