1 /* $NetBSD: eisa.c,v 1.15 1996/10/21 22:31:01 thorpej 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 <machine/bus.h> 46 47 #include <dev/eisa/eisareg.h> 48 #include <dev/eisa/eisavar.h> 49 #include <dev/eisa/eisadevs.h> 50 51 int eisamatch __P((struct device *, void *, void *)); 52 void eisaattach __P((struct device *, struct device *, void *)); 53 54 struct cfattach eisa_ca = { 55 sizeof(struct device), eisamatch, eisaattach 56 }; 57 58 struct cfdriver eisa_cd = { 59 NULL, "eisa", DV_DULL 60 }; 61 62 int eisasubmatch __P((struct device *, void *, void *)); 63 int eisaprint __P((void *, const 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 const 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_attach->ca_match)(parent, match, aux)); 110 } 111 112 void 113 eisaattach(parent, self, aux) 114 struct device *parent, *self; 115 void *aux; 116 { 117 struct eisabus_attach_args *eba = aux; 118 bus_space_tag_t iot, memt; 119 eisa_chipset_tag_t ec; 120 int slot, maxnslots; 121 122 eisa_attach_hook(parent, self, eba); 123 printf("\n"); 124 125 iot = eba->eba_iot; 126 memt = eba->eba_memt; 127 ec = eba->eba_ec; 128 129 /* 130 * Search for and attach subdevices. 131 * 132 * Slot 0 is the "motherboard" slot, and the code attaching 133 * the EISA bus should have already attached an ISA bus there. 134 */ 135 maxnslots = eisa_maxslots(ec); 136 for (slot = 1; slot < maxnslots; slot++) { 137 struct eisa_attach_args ea; 138 u_int slotaddr; 139 bus_space_handle_t slotioh; 140 int i; 141 142 ea.ea_iot = iot; 143 ea.ea_memt = memt; 144 ea.ea_ec = ec; 145 ea.ea_slot = slot; 146 slotaddr = EISA_SLOT_ADDR(slot); 147 148 /* 149 * Get a mapping for the whole slot-specific address 150 * space. If we can't, assume nothing's there but warn 151 * about it. 152 */ 153 if (bus_space_map(iot, slotaddr, EISA_SLOT_SIZE, 0, &slotioh)) { 154 printf("%s: can't map I/O space for slot %d\n", 155 self->dv_xname, slot); 156 continue; 157 } 158 159 /* Get the vendor ID bytes */ 160 for (i = 0; i < EISA_NVIDREGS; i++) 161 ea.ea_vid[i] = bus_space_read_1(iot, slotioh, 162 EISA_SLOTOFF_VID + i); 163 164 /* Check for device existence */ 165 if (EISA_VENDID_NODEV(ea.ea_vid)) { 166 #if 0 167 printf("no device at %s slot %d\n", self->dv_xname, 168 slot); 169 printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0], 170 ea.ea_vid[1]); 171 #endif 172 bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE); 173 continue; 174 } 175 176 /* And check that the firmware didn't biff something badly */ 177 if (EISA_VENDID_IDDELAY(ea.ea_vid)) { 178 printf("%s slot %d not configured by BIOS?\n", 179 self->dv_xname, slot); 180 bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE); 181 continue; 182 } 183 184 /* Get the product ID bytes */ 185 for (i = 0; i < EISA_NPIDREGS; i++) 186 ea.ea_pid[i] = bus_space_read_1(iot, slotioh, 187 EISA_SLOTOFF_PID + i); 188 189 /* Create the ID string from the vendor and product IDs */ 190 ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid); 191 ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid); 192 ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid); 193 ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid); 194 ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid); 195 ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid); 196 ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid); 197 ea.ea_idstring[7] = '\0'; /* sanity */ 198 199 /* We no longer need the I/O handle; free it. */ 200 bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE); 201 202 /* Attach matching device. */ 203 config_found_sm(self, &ea, eisaprint, eisasubmatch); 204 } 205 } 206 207 #ifdef EISAVERBOSE 208 /* 209 * Descriptions of of known vendors and devices ("products"). 210 */ 211 struct eisa_knowndev { 212 int flags; 213 const char *id, *name; 214 }; 215 #define EISA_KNOWNDEV_NOPROD 0x01 /* match on vendor only */ 216 217 #include <dev/eisa/eisadevs_data.h> 218 #endif /* EISAVERBOSE */ 219 220 void 221 eisa_devinfo(id, cp) 222 const char *id; 223 char *cp; 224 { 225 const char *name; 226 int onlyvendor; 227 #ifdef EISAVERBOSE 228 struct eisa_knowndev *edp; 229 int match; 230 const char *unmatched = "unknown "; 231 #else 232 const char *unmatched = ""; 233 #endif 234 235 onlyvendor = 0; 236 name = NULL; 237 238 #ifdef EISAVERBOSE 239 /* find the device in the table, if possible. */ 240 edp = eisa_knowndevs; 241 while (edp->id != NULL) { 242 /* check this entry for a match */ 243 if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0) 244 match = !strncmp(edp->id, id, 3); 245 else 246 match = !strcmp(edp->id, id); 247 if (match) { 248 name = edp->name; 249 onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0; 250 break; 251 } 252 edp++; 253 } 254 #endif 255 256 if (name == NULL) 257 cp += sprintf(cp, "%sdevice %s", unmatched, id); 258 else if (onlyvendor) /* never if not EISAVERBOSE */ 259 cp += sprintf(cp, "unknown %s device %s", name, id); 260 else 261 cp += sprintf(cp, "%s", name); 262 } 263