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