Home | History | Annotate | Line # | Download | only in dev
sbus.c revision 1.8
      1 /*	$NetBSD: sbus.c,v 1.8 1996/03/17 02:01:14 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. All advertising materials mentioning features or use of this software
     25  *    must display the following acknowledgement:
     26  *	This product includes software developed by the University of
     27  *	California, Berkeley and its contributors.
     28  * 4. Neither the name of the University nor the names of its contributors
     29  *    may be used to endorse or promote products derived from this software
     30  *    without specific prior written permission.
     31  *
     32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  * SUCH DAMAGE.
     43  *
     44  *	@(#)sbus.c	8.1 (Berkeley) 6/11/93
     45  */
     46 
     47 /*
     48  * Sbus stuff.
     49  */
     50 
     51 #include <sys/param.h>
     52 #include <sys/systm.h>
     53 #include <sys/device.h>
     54 
     55 #include <machine/autoconf.h>
     56 
     57 #include <sparc/dev/sbusreg.h>
     58 #include <sparc/dev/sbusvar.h>
     59 
     60 int sbus_print __P((void *, char *));
     61 void sbusreset __P((int));
     62 
     63 /* autoconfiguration driver */
     64 void	sbus_attach __P((struct device *, struct device *, void *));
     65 int	sbus_match __P((struct device *, void *, void *));
     66 
     67 struct cfattach sbus_ca = {
     68 	sizeof(struct sbus_softc), sbus_match, sbus_attach
     69 };
     70 
     71 struct cfdriver sbus_cd = {
     72 	NULL, "sbus", DV_DULL
     73 };
     74 
     75 /*
     76  * Print the location of some sbus-attached device (called just
     77  * before attaching that device).  If `sbus' is not NULL, the
     78  * device was found but not configured; print the sbus as well.
     79  * Return UNCONF (config_find ignores this if the device was configured).
     80  */
     81 int
     82 sbus_print(args, sbus)
     83 	void *args;
     84 	char *sbus;
     85 {
     86 	register struct confargs *ca = args;
     87 
     88 	if (sbus)
     89 		printf("%s at %s", ca->ca_ra.ra_name, sbus);
     90 	printf(" slot %d offset 0x%x", ca->ca_slot, ca->ca_offset);
     91 	return (UNCONF);
     92 }
     93 
     94 int
     95 sbus_match(parent, vcf, aux)
     96 	struct device *parent;
     97 	void *vcf, *aux;
     98 {
     99 	struct cfdata *cf = vcf;
    100 	register struct confargs *ca = aux;
    101 	register struct romaux *ra = &ca->ca_ra;
    102 
    103 	if (cputyp==CPU_SUN4)
    104 		return (0);
    105 	return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
    106 }
    107 
    108 /*
    109  * Attach an Sbus.
    110  */
    111 void
    112 sbus_attach(parent, self, aux)
    113 	struct device *parent;
    114 	struct device *self;
    115 	void *aux;
    116 {
    117 	register struct sbus_softc *sc = (struct sbus_softc *)self;
    118 	struct confargs *ca = aux;
    119 	register struct romaux *ra = &ca->ca_ra;
    120 	register int base, node, slot;
    121 	register int i;
    122 	register char *name;
    123 	struct confargs oca;
    124 
    125 	/*
    126 	 * XXX there is only one Sbus, for now -- do not know how to
    127 	 * address children on others
    128 	 */
    129 	if (sc->sc_dev.dv_unit > 0) {
    130 		printf(" unsupported\n");
    131 		return;
    132 	}
    133 
    134 	/*
    135 	 * Record clock frequency for synchronous SCSI.
    136 	 * IS THIS THE CORRECT DEFAULT??
    137 	 */
    138 	node = ra->ra_node;
    139 	sc->sc_clockfreq = getpropint(node, "clock-frequency", 25*1000*1000);
    140 	printf(": clock = %s MHz\n", clockfreq(sc->sc_clockfreq));
    141 
    142 	if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "sbus") == 0)
    143 		oca.ca_ra.ra_bp = ra->ra_bp + 1;
    144 	else
    145 		oca.ca_ra.ra_bp = NULL;
    146 
    147 	/*
    148 	 * Loop through ROM children, fixing any relative addresses
    149 	 * and then configuring each device.
    150 	 */
    151 	for (node = firstchild(node); node; node = nextsibling(node)) {
    152 		name = getpropstring(node, "name");
    153 		if (!romprop(&oca.ca_ra, name, node))
    154 			continue;
    155 		base = (int)oca.ca_ra.ra_paddr;
    156 		if (SBUS_ABS(base)) {
    157 			oca.ca_slot = SBUS_ABS_TO_SLOT(base);
    158 			oca.ca_offset = SBUS_ABS_TO_OFFSET(base);
    159 		} else {
    160 			oca.ca_slot = slot = oca.ca_ra.ra_iospace;
    161 			oca.ca_offset = base;
    162 			oca.ca_ra.ra_paddr = (void *)SBUS_ADDR(slot, base);
    163 			/* Fix any remaining register banks */
    164 			for (i = 1; i < oca.ca_ra.ra_nreg; i++) {
    165 				base = (int)oca.ca_ra.ra_reg[i].rr_paddr;
    166 				oca.ca_ra.ra_reg[i].rr_paddr =
    167 					(void *)SBUS_ADDR(slot, base);
    168 			}
    169 		}
    170 		oca.ca_bustype = BUS_SBUS;
    171 		(void) config_found(&sc->sc_dev, (void *)&oca, sbus_print);
    172 	}
    173 }
    174 
    175 /*
    176  * Each attached device calls sbus_establish after it initializes
    177  * its sbusdev portion.
    178  */
    179 void
    180 sbus_establish(sd, dev)
    181 	register struct sbusdev *sd;
    182 	register struct device *dev;
    183 {
    184 	register struct sbus_softc *sc = (struct sbus_softc *)dev->dv_parent;
    185 
    186 	sd->sd_dev = dev;
    187 	sd->sd_bchain = sc->sc_sbdev;
    188 	sc->sc_sbdev = sd;
    189 }
    190 
    191 /*
    192  * Reset the given sbus. (???)
    193  */
    194 void
    195 sbusreset(sbus)
    196 	int sbus;
    197 {
    198 	register struct sbusdev *sd;
    199 	struct sbus_softc *sc = sbus_cd.cd_devs[sbus];
    200 	struct device *dev;
    201 
    202 	printf("reset %s:", sc->sc_dev.dv_xname);
    203 	for (sd = sc->sc_sbdev; sd != NULL; sd = sd->sd_bchain) {
    204 		if (sd->sd_reset) {
    205 			dev = sd->sd_dev;
    206 			(*sd->sd_reset)(dev);
    207 			printf(" %s", dev->dv_xname);
    208 		}
    209 	}
    210 }
    211