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