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