Home | History | Annotate | Line # | Download | only in eisa
eisa.c revision 1.38
      1 /*	$NetBSD: eisa.c,v 1.38 2005/08/25 22:33:18 drochner 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/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: eisa.c,v 1.38 2005/08/25 22:33:18 drochner Exp $");
     43 
     44 #include "opt_eisaverbose.h"
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/device.h>
     49 
     50 #include <machine/bus.h>
     51 
     52 #include <dev/eisa/eisareg.h>
     53 #include <dev/eisa/eisavar.h>
     54 #include <dev/eisa/eisadevs.h>
     55 
     56 #include "locators.h"
     57 
     58 static int	eisamatch(struct device *, struct cfdata *, void *);
     59 static void	eisaattach(struct device *, struct device *, void *);
     60 
     61 CFATTACH_DECL(eisa, sizeof(struct device),
     62     eisamatch, eisaattach, NULL, NULL);
     63 
     64 static int	eisaprint(void *, const char *);
     65 static void	eisa_devinfo(const char *, char *, size_t);
     66 
     67 static int
     68 eisamatch(struct device *parent, struct cfdata *cf, void *aux)
     69 {
     70 	/* XXX check other indicators */
     71 
     72 	return (1);
     73 }
     74 
     75 static int
     76 eisaprint(void *aux, const char *pnp)
     77 {
     78 	struct eisa_attach_args *ea = aux;
     79 	char devinfo[256];
     80 
     81 	if (pnp) {
     82 		eisa_devinfo(ea->ea_idstring, devinfo, sizeof(devinfo));
     83 		aprint_normal("%s at %s", devinfo, pnp);
     84 	}
     85 	aprint_normal(" slot %d", ea->ea_slot);
     86 	return (UNCONF);
     87 }
     88 
     89 static void
     90 eisaattach(struct device *parent, struct device *self, void *aux)
     91 {
     92 	struct eisabus_attach_args *eba = aux;
     93 	bus_space_tag_t iot, memt;
     94 	bus_dma_tag_t dmat;
     95 	eisa_chipset_tag_t ec;
     96 	int slot, maxnslots;
     97 
     98 	eisa_attach_hook(parent, self, eba);
     99 	printf("\n");
    100 
    101 	iot = eba->eba_iot;
    102 	memt = eba->eba_memt;
    103 	ec = eba->eba_ec;
    104 	dmat = eba->eba_dmat;
    105 
    106 	/*
    107 	 * Search for and attach subdevices.
    108 	 *
    109 	 * Slot 0 is the "motherboard" slot, and the code attaching
    110 	 * the EISA bus should have already attached an ISA bus there.
    111 	 */
    112 	maxnslots = eisa_maxslots(ec);
    113 	for (slot = 1; slot < maxnslots; slot++) {
    114 		struct eisa_attach_args ea;
    115 		u_int slotaddr;
    116 		bus_space_handle_t slotioh;
    117 		int i;
    118 		int locs[EISACF_NLOCS];
    119 
    120 		ea.ea_iot = iot;
    121 		ea.ea_memt = memt;
    122 		ea.ea_ec = ec;
    123 		ea.ea_dmat = dmat;
    124 		ea.ea_slot = slot;
    125 		slotaddr = EISA_SLOT_ADDR(slot);
    126 
    127 		/*
    128 		 * Get a mapping for the whole slot-specific address
    129 		 * space.  If we can't, assume nothing's there but warn
    130 		 * about it.
    131 		 */
    132 		if (bus_space_map(iot, slotaddr, EISA_SLOT_SIZE, 0, &slotioh)) {
    133 			printf("%s: can't map I/O space for slot %d\n",
    134 			    self->dv_xname, slot);
    135 			continue;
    136 		}
    137 
    138 		/* Get the vendor ID bytes */
    139 		for (i = 0; i < EISA_NVIDREGS; i++)
    140 			ea.ea_vid[i] = bus_space_read_1(iot, slotioh,
    141 			    EISA_SLOTOFF_VID + i);
    142 
    143 		/* Check for device existence */
    144 		if (EISA_VENDID_NODEV(ea.ea_vid)) {
    145 #if 0
    146 			printf("no device at %s slot %d\n", self->dv_xname,
    147 			    slot);
    148 			printf("\t(0x%x, 0x%x)\n", ea.ea_vid[0],
    149 			    ea.ea_vid[1]);
    150 #endif
    151 			bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
    152 			continue;
    153 		}
    154 
    155 		/* And check that the firmware didn't biff something badly */
    156 		if (EISA_VENDID_IDDELAY(ea.ea_vid)) {
    157 			printf("%s slot %d not configured by BIOS?\n",
    158 			    self->dv_xname, slot);
    159 			bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
    160 			continue;
    161 		}
    162 
    163 		/* Get the product ID bytes */
    164 		for (i = 0; i < EISA_NPIDREGS; i++)
    165 			ea.ea_pid[i] = bus_space_read_1(iot, slotioh,
    166 			    EISA_SLOTOFF_PID + i);
    167 
    168 		/* Create the ID string from the vendor and product IDs */
    169 		ea.ea_idstring[0] = EISA_VENDID_0(ea.ea_vid);
    170 		ea.ea_idstring[1] = EISA_VENDID_1(ea.ea_vid);
    171 		ea.ea_idstring[2] = EISA_VENDID_2(ea.ea_vid);
    172 		ea.ea_idstring[3] = EISA_PRODID_0(ea.ea_pid);
    173 		ea.ea_idstring[4] = EISA_PRODID_1(ea.ea_pid);
    174 		ea.ea_idstring[5] = EISA_PRODID_2(ea.ea_pid);
    175 		ea.ea_idstring[6] = EISA_PRODID_3(ea.ea_pid);
    176 		ea.ea_idstring[7] = '\0';		/* sanity */
    177 
    178 		/* We no longer need the I/O handle; free it. */
    179 		bus_space_unmap(iot, slotioh, EISA_SLOT_SIZE);
    180 
    181 		locs[EISACF_SLOT] = slot;
    182 
    183 		/* Attach matching device. */
    184 		config_found_sm_loc(self, "eisa", locs, &ea,
    185 				    eisaprint, config_stdsubmatch);
    186 	}
    187 }
    188 
    189 #ifdef EISAVERBOSE
    190 /*
    191  * Descriptions of of known vendors and devices ("products").
    192  */
    193 struct eisa_knowndev {
    194 	int	flags;
    195 	const char *id, *name;
    196 };
    197 #define EISA_KNOWNDEV_NOPROD	0x01		/* match on vendor only */
    198 
    199 #include <dev/eisa/eisadevs_data.h>
    200 #endif	/* EISAVEBSOSE */
    201 
    202 void
    203 eisa_devinfo(const char *id, char *cp, size_t l)
    204 {
    205 #ifdef EISAVERBOSE
    206 	const char *name;
    207 	const struct eisa_knowndev *edp;
    208 	int match, onlyvendor;
    209 
    210 	onlyvendor = 0;
    211 	name = NULL;
    212 
    213 	/* find the device in the table, if possible. */
    214 	for (edp = eisa_knowndevs; edp->id != NULL; edp++) {
    215 		if ((edp->flags & EISA_KNOWNDEV_NOPROD) != 0)
    216 			match = (strncmp(edp->id, id, 3) == 0);
    217 		else
    218 			match = (strcmp(edp->id, id) == 0);
    219 		if (match) {
    220 			name = edp->name;
    221 			onlyvendor = (edp->flags & EISA_KNOWNDEV_NOPROD) != 0;
    222 			break;
    223 		}
    224 	}
    225 
    226 	if (name == NULL)
    227 		snprintf(cp, l, "unknown device %s", id);
    228 	else if (onlyvendor)
    229 		snprintf(cp, l, "unknown %s device %s", name, id);
    230 	else
    231 		snprintf(cp, l, "%s", name);
    232 #else	/* EISAVERBOSE */
    233 
    234 	snprintf(cp, l, "device %s", id);
    235 #endif	/* EISAVERBOSE */
    236 }
    237