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