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