eisa.c revision 1.3 1 1.3 cgd /* $NetBSD: eisa.c,v 1.3 1996/03/02 01:09:37 cgd 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.1 cgd
41 1.1 cgd #include <sys/param.h>
42 1.1 cgd #include <sys/systm.h>
43 1.1 cgd #include <sys/device.h>
44 1.1 cgd
45 1.1 cgd #include <dev/eisa/eisareg.h>
46 1.1 cgd #include <dev/eisa/eisavar.h>
47 1.1 cgd #include <dev/eisa/eisadevs.h>
48 1.1 cgd
49 1.1 cgd #include <machine/pio.h> /* XXX shouldn't use inb directly */
50 1.1 cgd
51 1.1 cgd struct eisa_softc {
52 1.1 cgd struct device sc_dev; /* this is it, for now */
53 1.1 cgd };
54 1.1 cgd
55 1.1 cgd int eisamatch __P((struct device *, void *, void *));
56 1.1 cgd void eisaattach __P((struct device *, struct device *, void *));
57 1.1 cgd
58 1.1 cgd struct cfdriver eisacd = {
59 1.1 cgd NULL, "eisa", eisamatch, eisaattach, DV_DULL, sizeof(struct eisa_softc)
60 1.1 cgd };
61 1.1 cgd
62 1.1 cgd int eisasubmatch __P((struct device *, void *, void *));
63 1.1 cgd int eisaprint __P((void *, char *));
64 1.1 cgd void eisa_devinfo __P((const char *, char *));
65 1.1 cgd
66 1.1 cgd int
67 1.1 cgd eisamatch(parent, match, aux)
68 1.1 cgd struct device *parent;
69 1.1 cgd void *match, *aux;
70 1.1 cgd {
71 1.1 cgd struct cfdata *cf = match;
72 1.1 cgd struct eisabus_attach_args *eba = aux;
73 1.1 cgd
74 1.1 cgd if (strcmp(eba->eba_busname, cf->cf_driver->cd_name))
75 1.1 cgd return (0);
76 1.1 cgd
77 1.1 cgd /* XXX check other indicators */
78 1.1 cgd
79 1.1 cgd return (1);
80 1.1 cgd }
81 1.1 cgd
82 1.1 cgd int
83 1.2 cgd eisaprint(aux, pnp)
84 1.1 cgd void *aux;
85 1.2 cgd char *pnp;
86 1.1 cgd {
87 1.1 cgd register struct eisa_attach_args *ea = aux;
88 1.2 cgd char devinfo[256];
89 1.1 cgd
90 1.2 cgd if (pnp) {
91 1.2 cgd eisa_devinfo(ea->ea_idstring, devinfo);
92 1.2 cgd printf("%s at %s", devinfo, pnp);
93 1.2 cgd }
94 1.1 cgd printf(" slot %d", ea->ea_slot);
95 1.1 cgd return (UNCONF);
96 1.1 cgd }
97 1.1 cgd
98 1.1 cgd int
99 1.1 cgd eisasubmatch(parent, match, aux)
100 1.1 cgd struct device *parent;
101 1.1 cgd void *match, *aux;
102 1.1 cgd {
103 1.1 cgd struct cfdata *cf = match;
104 1.1 cgd struct eisa_attach_args *ea = aux;
105 1.1 cgd
106 1.1 cgd if (cf->eisacf_slot != EISA_UNKNOWN_SLOT &&
107 1.1 cgd cf->eisacf_slot != ea->ea_slot)
108 1.1 cgd return 0;
109 1.1 cgd return ((*cf->cf_driver->cd_match)(parent, match, aux));
110 1.1 cgd }
111 1.1 cgd
112 1.1 cgd void
113 1.1 cgd eisaattach(parent, self, aux)
114 1.1 cgd struct device *parent, *self;
115 1.1 cgd void *aux;
116 1.1 cgd {
117 1.1 cgd struct eisa_softc *sc = (struct eisa_softc *)self;
118 1.1 cgd int slot;
119 1.1 cgd
120 1.1 cgd printf("\n");
121 1.1 cgd
122 1.1 cgd /*
123 1.1 cgd * Search for and attach subdevices.
124 1.1 cgd *
125 1.1 cgd * Slot 0 is the "motherboard" slot, and the code attaching
126 1.1 cgd * the EISA bus should have already attached an ISA bus there.
127 1.1 cgd */
128 1.1 cgd for (slot = 1; slot < EISA_MAX_SLOT; slot++) {
129 1.1 cgd struct eisa_attach_args ea;
130 1.1 cgd struct cfdata *cf;
131 1.1 cgd u_int slotaddr;
132 1.1 cgd int i;
133 1.1 cgd
134 1.1 cgd ea.ea_slot = slot;
135 1.1 cgd slotaddr = EISA_SLOT_ADDR(slot);
136 1.1 cgd #if 0
137 1.1 cgd printf("%s slot %d: at 0x%x\n", sc->sc_dev.dv_xname, slot,
138 1.1 cgd slotaddr);
139 1.1 cgd #endif
140 1.1 cgd
141 1.1 cgd /* Get the vendor ID bytes */
142 1.1 cgd for (i = 0; i < EISA_NVIDREGS; i++)
143 1.1 cgd ea.ea_vid[i] = inb(slotaddr + EISA_SLOTOFF_VID + i);
144 1.1 cgd
145 1.1 cgd /* Check for device existence */
146 1.1 cgd if (EISA_VENDID_NODEV(ea.ea_vid)) {
147 1.1 cgd #if 0
148 1.1 cgd printf("%s slot %d: no device\n", sc->sc_dev.dv_xname,
149 1.1 cgd slot);
150 1.1 cgd printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0],
151 1.1 cgd ea.ea_vid[1]);
152 1.1 cgd #endif
153 1.1 cgd continue;
154 1.1 cgd }
155 1.1 cgd
156 1.1 cgd /* And check that the firmware didn't biff something badly */
157 1.1 cgd if (EISA_VENDID_IDDELAY(ea.ea_vid)) {
158 1.1 cgd printf("%s slot %d: slot not configured by BIOS?\n",
159 1.1 cgd self->dv_xname, slot);
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.1 cgd ea.ea_pid[i] = inb(slotaddr + EISA_SLOTOFF_PID + i);
166 1.1 cgd
167 1.1 cgd /* Create the ID string from the vendor and product IDs */
168 1.1 cgd ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid);
169 1.1 cgd ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid);
170 1.1 cgd ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid);
171 1.1 cgd ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid);
172 1.1 cgd ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid);
173 1.1 cgd ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid);
174 1.1 cgd ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid);
175 1.1 cgd ea.ea_idstring[7] = '\0'; /* sanity */
176 1.1 cgd
177 1.2 cgd /* Attach matching device. */
178 1.2 cgd config_found_sm(self, &ea, eisaprint, eisasubmatch);
179 1.1 cgd }
180 1.1 cgd }
181 1.1 cgd
182 1.1 cgd #ifdef EISAVERBOSE
183 1.1 cgd /*
184 1.1 cgd * Descriptions of of known vendors and devices ("products").
185 1.1 cgd */
186 1.1 cgd struct eisa_knowndev {
187 1.1 cgd int flags;
188 1.1 cgd const char *id, *name;
189 1.1 cgd };
190 1.1 cgd #define EISA_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
191 1.1 cgd
192 1.1 cgd #include <dev/eisa/eisadevs_data.h>
193 1.1 cgd #endif /* EISAVERBOSE */
194 1.1 cgd
195 1.1 cgd void
196 1.1 cgd eisa_devinfo(id, cp)
197 1.1 cgd const char *id;
198 1.1 cgd char *cp;
199 1.1 cgd {
200 1.1 cgd const char *name;
201 1.1 cgd int onlyvendor;
202 1.1 cgd #ifdef EISAVERBOSE
203 1.1 cgd struct eisa_knowndev *edp;
204 1.1 cgd int match;
205 1.3 cgd const char *unmatched = "unknown device ";
206 1.3 cgd #else
207 1.3 cgd const char *unmatched = "";
208 1.1 cgd #endif
209 1.1 cgd
210 1.1 cgd onlyvendor = 0;
211 1.1 cgd name = NULL;
212 1.1 cgd
213 1.1 cgd #ifdef EISAVERBOSE
214 1.1 cgd /* find the device in the table, if possible. */
215 1.1 cgd edp = eisa_knowndevs;
216 1.1 cgd while (edp->id != NULL) {
217 1.1 cgd /* check this entry for a match */
218 1.1 cgd if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0)
219 1.1 cgd match = !strncmp(edp->id, id, 3);
220 1.1 cgd else
221 1.1 cgd match = !strcmp(edp->id, id);
222 1.1 cgd if (match) {
223 1.1 cgd name = edp->name;
224 1.1 cgd onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0;
225 1.1 cgd break;
226 1.1 cgd }
227 1.1 cgd edp++;
228 1.1 cgd }
229 1.1 cgd #endif
230 1.1 cgd
231 1.1 cgd if (name == NULL)
232 1.3 cgd cp += sprintf(cp, "%s%s", unmatched, id);
233 1.3 cgd else if (onlyvendor) /* never if not EISAVERBOSE */
234 1.1 cgd cp += sprintf(cp, "unknown %s device %s", name, id);
235 1.1 cgd else
236 1.1 cgd cp += sprintf(cp, "%s", name);
237 1.1 cgd }
238