Home | History | Annotate | Line # | Download | only in eisa
eisa.c revision 1.1
      1 /*	$NetBSD: eisa.c,v 1.1 1996/02/27 00:21:00 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 <dev/eisa/eisareg.h>
     46 #include <dev/eisa/eisavar.h>
     47 #include <dev/eisa/eisadevs.h>
     48 
     49 #include <machine/pio.h>		/* XXX shouldn't use inb directly */
     50 
     51 struct eisa_softc {
     52 	struct	device sc_dev;			/* this is it, for now */
     53 };
     54 
     55 int	eisamatch __P((struct device *, void *, void *));
     56 void	eisaattach __P((struct device *, struct device *, void *));
     57 
     58 struct cfdriver eisacd = {
     59         NULL, "eisa", eisamatch, eisaattach, DV_DULL, sizeof(struct eisa_softc)
     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, eisa)
     84 	void *aux;
     85 	char *eisa;
     86 {
     87 	register struct eisa_attach_args *ea = aux;
     88 
     89 	printf(" slot %d", ea->ea_slot);
     90 	return (UNCONF);
     91 }
     92 
     93 int
     94 eisasubmatch(parent, match, aux)
     95 	struct device *parent;
     96 	void *match, *aux;
     97 {
     98 	struct cfdata *cf = match;
     99 	struct eisa_attach_args *ea = aux;
    100 
    101 	if (cf->eisacf_slot != EISA_UNKNOWN_SLOT &&
    102 	    cf->eisacf_slot != ea->ea_slot)
    103 		return 0;
    104 	return ((*cf->cf_driver->cd_match)(parent, match, aux));
    105 }
    106 
    107 void
    108 eisaattach(parent, self, aux)
    109         struct device *parent, *self;
    110         void *aux;
    111 {
    112 	struct eisa_softc *sc = (struct eisa_softc *)self;
    113 	int slot;
    114 
    115 	printf("\n");
    116 
    117 	/*
    118 	 * Search for and attach subdevices.
    119 	 *
    120 	 * Slot 0 is the "motherboard" slot, and the code attaching
    121 	 * the EISA bus should have already attached an ISA bus there.
    122 	 */
    123 	for (slot = 1; slot < EISA_MAX_SLOT; slot++) {
    124 		struct eisa_attach_args ea;
    125 		struct cfdata *cf;
    126 		u_int slotaddr;
    127 		int i;
    128 
    129 		ea.ea_slot = slot;
    130 		slotaddr = EISA_SLOT_ADDR(slot);
    131 #if 0
    132 		printf("%s slot %d: at 0x%x\n", sc->sc_dev.dv_xname, slot,
    133 		    slotaddr);
    134 #endif
    135 
    136 		/* Get the vendor ID bytes */
    137 		for (i = 0; i < EISA_NVIDREGS; i++)
    138 			ea.ea_vid[i] = inb(slotaddr + EISA_SLOTOFF_VID + i);
    139 
    140 		/* Check for device existence */
    141 		if (EISA_VENDID_NODEV(ea.ea_vid)) {
    142 #if 0
    143 			printf("%s slot %d: no device\n", sc->sc_dev.dv_xname,
    144 			    slot);
    145 			printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0],
    146 			    ea.ea_vid[1]);
    147 #endif
    148 			continue;
    149 		}
    150 
    151 		/* And check that the firmware didn't biff something badly */
    152 		if (EISA_VENDID_IDDELAY(ea.ea_vid)) {
    153 			printf("%s slot %d: slot not configured by BIOS?\n",
    154 			    self->dv_xname, slot);
    155 			continue;
    156 		}
    157 
    158 		/* Get the product ID bytes */
    159 		for (i = 0; i < EISA_NPIDREGS; i++)
    160 			ea.ea_pid[i] = inb(slotaddr + EISA_SLOTOFF_PID + i);
    161 
    162 		/* Create the ID string from the vendor and product IDs */
    163 		ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid);
    164 		ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid);
    165 		ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid);
    166 		ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid);
    167 		ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid);
    168 		ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid);
    169 		ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid);
    170 		ea.ea_idstring[7] = '\0';		/* sanity */
    171 
    172 		/* Go hunt for devices that match. */
    173 		if ((cf = config_search(eisasubmatch, self, &ea)) != NULL)
    174 			config_attach(self, cf, &ea, eisaprint);
    175 		else {
    176 			char devinfo[256];
    177 
    178                         eisa_devinfo(ea.ea_idstring, devinfo);
    179                         printf("%s slot %d: %s not configured\n",
    180                             self->dv_xname, slot, devinfo);
    181 		}
    182 	}
    183 }
    184 
    185 #ifdef EISAVERBOSE
    186 /*
    187  * Descriptions of of known vendors and devices ("products").
    188  */
    189 struct eisa_knowndev {
    190 	int	flags;
    191 	const char *id, *name;
    192 };
    193 #define EISA_KNOWNDEV_NOPROD     0x01            /* match on vendor only */
    194 
    195 #include <dev/eisa/eisadevs_data.h>
    196 #endif /* EISAVERBOSE */
    197 
    198 void
    199 eisa_devinfo(id, cp)
    200 	const char *id;
    201 	char *cp;
    202 {
    203 	const char *name;
    204 	int onlyvendor;
    205 #ifdef EISAVERBOSE
    206 	struct eisa_knowndev *edp;
    207 	int match;
    208 #endif
    209 
    210 	onlyvendor = 0;
    211 	name = NULL;
    212 
    213 #ifdef EISAVERBOSE
    214 	/* find the device in the table, if possible. */
    215 	edp = eisa_knowndevs;
    216 	while (edp->id != NULL) {
    217 		/* check this entry for a match */
    218 		if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0)
    219 			match = !strncmp(edp->id, id, 3);
    220 		else
    221 			match = !strcmp(edp->id, id);
    222 		if (match) {
    223 			name = edp->name;
    224 			onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0;
    225 			break;
    226 		}
    227 		edp++;
    228 	}
    229 #endif
    230 
    231 	if (name == NULL)
    232 		cp += sprintf(cp, "unknown device %s", id);
    233 	else if (onlyvendor)
    234 		cp += sprintf(cp, "unknown %s device %s", name, id);
    235 	else
    236 		cp += sprintf(cp, "%s", name);
    237 }
    238