eisa.c revision 1.4 1 /* $NetBSD: eisa.c,v 1.4 1996/03/02 02:25:40 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
137 /* Get the vendor ID bytes */
138 for (i = 0; i < EISA_NVIDREGS; i++)
139 ea.ea_vid[i] = inb(slotaddr + EISA_SLOTOFF_VID + i);
140
141 /* Check for device existence */
142 if (EISA_VENDID_NODEV(ea.ea_vid)) {
143 #if 0
144 printf("no device at %s slot %d\n", sc->sc_dev.dv_xname,
145 slot);
146 printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0],
147 ea.ea_vid[1]);
148 #endif
149 continue;
150 }
151
152 /* And check that the firmware didn't biff something badly */
153 if (EISA_VENDID_IDDELAY(ea.ea_vid)) {
154 printf("%s slot %d not configured by BIOS?\n",
155 self->dv_xname, slot);
156 continue;
157 }
158
159 /* Get the product ID bytes */
160 for (i = 0; i < EISA_NPIDREGS; i++)
161 ea.ea_pid[i] = inb(slotaddr + EISA_SLOTOFF_PID + i);
162
163 /* Create the ID string from the vendor and product IDs */
164 ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid);
165 ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid);
166 ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid);
167 ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid);
168 ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid);
169 ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid);
170 ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid);
171 ea.ea_idstring[7] = '\0'; /* sanity */
172
173 /* Attach matching device. */
174 config_found_sm(self, &ea, eisaprint, eisasubmatch);
175 }
176 }
177
178 #ifdef EISAVERBOSE
179 /*
180 * Descriptions of of known vendors and devices ("products").
181 */
182 struct eisa_knowndev {
183 int flags;
184 const char *id, *name;
185 };
186 #define EISA_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
187
188 #include <dev/eisa/eisadevs_data.h>
189 #endif /* EISAVERBOSE */
190
191 void
192 eisa_devinfo(id, cp)
193 const char *id;
194 char *cp;
195 {
196 const char *name;
197 int onlyvendor;
198 #ifdef EISAVERBOSE
199 struct eisa_knowndev *edp;
200 int match;
201 const char *unmatched = "unknown device ";
202 #else
203 const char *unmatched = "";
204 #endif
205
206 onlyvendor = 0;
207 name = NULL;
208
209 #ifdef EISAVERBOSE
210 /* find the device in the table, if possible. */
211 edp = eisa_knowndevs;
212 while (edp->id != NULL) {
213 /* check this entry for a match */
214 if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0)
215 match = !strncmp(edp->id, id, 3);
216 else
217 match = !strcmp(edp->id, id);
218 if (match) {
219 name = edp->name;
220 onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0;
221 break;
222 }
223 edp++;
224 }
225 #endif
226
227 if (name == NULL)
228 cp += sprintf(cp, "%s%s", unmatched, id);
229 else if (onlyvendor) /* never if not EISAVERBOSE */
230 cp += sprintf(cp, "unknown %s device %s", name, id);
231 else
232 cp += sprintf(cp, "%s", name);
233 }
234