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