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