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