Home | History | Annotate | Line # | Download | only in eisa
eisa.c revision 1.16
      1 /*	$NetBSD: eisa.c,v 1.16 1996/12/05 01:25:36 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 <machine/bus.h>
     46 
     47 #include <dev/eisa/eisareg.h>
     48 #include <dev/eisa/eisavar.h>
     49 #include <dev/eisa/eisadevs.h>
     50 
     51 #ifdef __BROKEN_INDIRECT_CONFIG
     52 int	eisamatch __P((struct device *, void *, void *));
     53 #else
     54 int	eisamatch __P((struct device *, struct cfdata *, void *));
     55 #endif
     56 void	eisaattach __P((struct device *, struct device *, void *));
     57 
     58 struct cfattach eisa_ca = {
     59 	sizeof(struct device), eisamatch, eisaattach
     60 };
     61 
     62 struct cfdriver eisa_cd = {
     63 	NULL, "eisa", DV_DULL
     64 };
     65 
     66 #ifdef __BROKEN_INDIRECT_CONFIG
     67 int	eisasubmatch __P((struct device *, void *, void *));
     68 #else
     69 int	eisasubmatch __P((struct device *, struct cfdata *, void *));
     70 #endif
     71 int	eisaprint __P((void *, const char *));
     72 void	eisa_devinfo __P((const char *, char *));
     73 
     74 int
     75 #ifdef __BROKEN_INDIRECT_CONFIG
     76 eisamatch(parent, match, aux)
     77 #else
     78 eisamatch(parent, cf, aux)
     79 #endif
     80 	struct device *parent;
     81 #ifdef __BROKEN_INDIRECT_CONFIG
     82 	void *match;
     83 #else
     84 	struct cfdata *cf;
     85 #endif
     86 	void *aux;
     87 {
     88 #ifdef __BROKEN_INDIRECT_CONFIG
     89 	struct cfdata *cf = match;
     90 #endif
     91 	struct eisabus_attach_args *eba = aux;
     92 
     93 	if (strcmp(eba->eba_busname, cf->cf_driver->cd_name))
     94 		return (0);
     95 
     96 	/* XXX check other indicators */
     97 
     98 	return (1);
     99 }
    100 
    101 int
    102 eisaprint(aux, pnp)
    103 	void *aux;
    104 	const char *pnp;
    105 {
    106 	register struct eisa_attach_args *ea = aux;
    107 	char devinfo[256];
    108 
    109 	if (pnp) {
    110 		eisa_devinfo(ea->ea_idstring, devinfo);
    111 		printf("%s at %s", devinfo, pnp);
    112 	}
    113 	printf(" slot %d", ea->ea_slot);
    114 	return (UNCONF);
    115 }
    116 
    117 int
    118 #ifdef __BROKEN_INDIRECT_CONFIG
    119 eisasubmatch(parent, match, aux)
    120 #else
    121 eisasubmatch(parent, cf, aux)
    122 #endif
    123 	struct device *parent;
    124 #ifdef __BROKEN_INDIRECT_CONFIG
    125 	void *match;
    126 #else
    127 	struct cfdata *cf;
    128 #endif
    129 	void *aux;
    130 {
    131 #ifdef __BROKEN_INDIRECT_CONFIG
    132 	struct cfdata *cf = match;
    133 #endif
    134 	struct eisa_attach_args *ea = aux;
    135 
    136 	if (cf->eisacf_slot != EISA_UNKNOWN_SLOT &&
    137 	    cf->eisacf_slot != ea->ea_slot)
    138 		return 0;
    139 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    140 }
    141 
    142 void
    143 eisaattach(parent, self, aux)
    144 	struct device *parent, *self;
    145 	void *aux;
    146 {
    147 	struct eisabus_attach_args *eba = aux;
    148 	bus_space_tag_t iot, memt;
    149 	eisa_chipset_tag_t ec;
    150 	int slot, maxnslots;
    151 
    152 	eisa_attach_hook(parent, self, eba);
    153 	printf("\n");
    154 
    155 	iot = eba->eba_iot;
    156 	memt = eba->eba_memt;
    157 	ec = eba->eba_ec;
    158 
    159 	/*
    160 	 * Search for and attach subdevices.
    161 	 *
    162 	 * Slot 0 is the "motherboard" slot, and the code attaching
    163 	 * the EISA bus should have already attached an ISA bus there.
    164 	 */
    165 	maxnslots = eisa_maxslots(ec);
    166 	for (slot = 1; slot < maxnslots; slot++) {
    167 		struct eisa_attach_args ea;
    168 		u_int slotaddr;
    169 		bus_space_handle_t slotioh;
    170 		int i;
    171 
    172 		ea.ea_iot = iot;
    173 		ea.ea_memt = memt;
    174 		ea.ea_ec = ec;
    175 		ea.ea_slot = slot;
    176 		slotaddr = EISA_SLOT_ADDR(slot);
    177 
    178 		/*
    179 		 * Get a mapping for the whole slot-specific address
    180 		 * space.  If we can't, assume nothing's there but warn
    181 		 * about it.
    182 		 */
    183 		if (bus_space_map(iot, slotaddr, EISA_SLOT_SIZE, 0, &slotioh)) {
    184 			printf("%s: can't map I/O space for slot %d\n",
    185 			    self->dv_xname, slot);
    186 			continue;
    187 		}
    188 
    189 		/* Get the vendor ID bytes */
    190 		for (i = 0; i < EISA_NVIDREGS; i++)
    191 			ea.ea_vid[i] = bus_space_read_1(iot, slotioh,
    192 			    EISA_SLOTOFF_VID + i);
    193 
    194 		/* Check for device existence */
    195 		if (EISA_VENDID_NODEV(ea.ea_vid)) {
    196 #if 0
    197 			printf("no device at %s slot %d\n", self->dv_xname,
    198 			    slot);
    199 			printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0],
    200 			    ea.ea_vid[1]);
    201 #endif
    202 			bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
    203 			continue;
    204 		}
    205 
    206 		/* And check that the firmware didn't biff something badly */
    207 		if (EISA_VENDID_IDDELAY(ea.ea_vid)) {
    208 			printf("%s slot %d not configured by BIOS?\n",
    209 			    self->dv_xname, slot);
    210 			bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
    211 			continue;
    212 		}
    213 
    214 		/* Get the product ID bytes */
    215 		for (i = 0; i < EISA_NPIDREGS; i++)
    216 			ea.ea_pid[i] = bus_space_read_1(iot, slotioh,
    217 			    EISA_SLOTOFF_PID + i);
    218 
    219 		/* Create the ID string from the vendor and product IDs */
    220 		ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid);
    221 		ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid);
    222 		ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid);
    223 		ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid);
    224 		ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid);
    225 		ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid);
    226 		ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid);
    227 		ea.ea_idstring[7] = '\0';		/* sanity */
    228 
    229 		/* We no longer need the I/O handle; free it. */
    230 		bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
    231 
    232 		/* Attach matching device. */
    233 		config_found_sm(self, &ea, eisaprint, eisasubmatch);
    234 	}
    235 }
    236 
    237 #ifdef EISAVERBOSE
    238 /*
    239  * Descriptions of of known vendors and devices ("products").
    240  */
    241 struct eisa_knowndev {
    242 	int	flags;
    243 	const char *id, *name;
    244 };
    245 #define EISA_KNOWNDEV_NOPROD	0x01		/* match on vendor only */
    246 
    247 #include <dev/eisa/eisadevs_data.h>
    248 #endif /* EISAVERBOSE */
    249 
    250 void
    251 eisa_devinfo(id, cp)
    252 	const char *id;
    253 	char *cp;
    254 {
    255 	const char *name;
    256 	int onlyvendor;
    257 #ifdef EISAVERBOSE
    258 	struct eisa_knowndev *edp;
    259 	int match;
    260 	const char *unmatched = "unknown ";
    261 #else
    262 	const char *unmatched = "";
    263 #endif
    264 
    265 	onlyvendor = 0;
    266 	name = NULL;
    267 
    268 #ifdef EISAVERBOSE
    269 	/* find the device in the table, if possible. */
    270 	edp = eisa_knowndevs;
    271 	while (edp->id != NULL) {
    272 		/* check this entry for a match */
    273 		if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0)
    274 			match = !strncmp(edp->id, id, 3);
    275 		else
    276 			match = !strcmp(edp->id, id);
    277 		if (match) {
    278 			name = edp->name;
    279 			onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0;
    280 			break;
    281 		}
    282 		edp++;
    283 	}
    284 #endif
    285 
    286 	if (name == NULL)
    287 		cp += sprintf(cp, "%sdevice %s", unmatched, id);
    288 	else if (onlyvendor)			/* never if not EISAVERBOSE */
    289 		cp += sprintf(cp, "unknown %s device %s", name, id);
    290 	else
    291 		cp += sprintf(cp, "%s", name);
    292 }
    293