1995-02-01 15:37:21 +03:00
|
|
|
/* $NetBSD: sbus.c,v 1.6 1995/02/01 12:37:28 pk Exp $ */
|
1994-11-20 23:51:32 +03:00
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)sbus.c 8.1 (Berkeley) 6/11/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sbus stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <machine/autoconf.h>
|
|
|
|
|
1994-09-18 03:57:27 +04:00
|
|
|
#include <sparc/dev/sbusreg.h>
|
|
|
|
#include <sparc/dev/sbusvar.h>
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/* autoconfiguration driver */
|
|
|
|
void sbus_attach __P((struct device *, struct device *, void *));
|
1994-11-23 10:02:02 +03:00
|
|
|
int sbus_match __P((struct device *, void *, void *));
|
1994-09-18 03:57:27 +04:00
|
|
|
struct cfdriver sbuscd = {
|
1994-10-03 00:59:56 +03:00
|
|
|
NULL, "sbus", sbus_match, sbus_attach,
|
1994-09-18 03:57:27 +04:00
|
|
|
DV_DULL, sizeof(struct sbus_softc)
|
|
|
|
};
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the location of some sbus-attached device (called just
|
|
|
|
* before attaching that device). If `sbus' is not NULL, the
|
|
|
|
* device was found but not configured; print the sbus as well.
|
|
|
|
* Return UNCONF (config_find ignores this if the device was configured).
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sbus_print(args, sbus)
|
|
|
|
void *args;
|
|
|
|
char *sbus;
|
|
|
|
{
|
1994-09-18 03:57:27 +04:00
|
|
|
register struct confargs *ca = args;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
if (sbus)
|
1994-09-18 03:57:27 +04:00
|
|
|
printf("%s at %s", ca->ca_ra.ra_name, sbus);
|
|
|
|
printf(" slot %d offset 0x%x", ca->ca_slot, ca->ca_offset);
|
1993-10-02 13:22:00 +03:00
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
1994-10-03 00:59:56 +03:00
|
|
|
int
|
1994-11-23 10:02:02 +03:00
|
|
|
sbus_match(parent, vcf, aux)
|
1994-10-03 00:59:56 +03:00
|
|
|
struct device *parent;
|
1994-11-23 10:02:02 +03:00
|
|
|
void *vcf, *aux;
|
1994-10-03 00:59:56 +03:00
|
|
|
{
|
1994-11-23 10:02:02 +03:00
|
|
|
struct cfdata *cf = vcf;
|
1994-10-03 00:59:56 +03:00
|
|
|
register struct confargs *ca = aux;
|
|
|
|
register struct romaux *ra = &ca->ca_ra;
|
|
|
|
|
|
|
|
if (cputyp==CPU_SUN4)
|
|
|
|
return (0);
|
|
|
|
return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
|
|
|
|
}
|
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
|
|
|
* Attach an Sbus.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbus_attach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
register struct sbus_softc *sc = (struct sbus_softc *)self;
|
1994-09-18 03:57:27 +04:00
|
|
|
struct confargs *ca = aux;
|
|
|
|
register struct romaux *ra = &ca->ca_ra;
|
1993-10-02 13:22:00 +03:00
|
|
|
register int base, node, slot;
|
1995-02-01 15:37:21 +03:00
|
|
|
register int i;
|
1993-10-02 13:22:00 +03:00
|
|
|
register char *name;
|
1994-09-18 03:57:27 +04:00
|
|
|
struct confargs oca;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX there is only one Sbus, for now -- do not know how to
|
|
|
|
* address children on others
|
|
|
|
*/
|
|
|
|
if (sc->sc_dev.dv_unit > 0) {
|
|
|
|
printf(" unsupported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record clock frequency for synchronous SCSI.
|
|
|
|
* IS THIS THE CORRECT DEFAULT??
|
|
|
|
*/
|
|
|
|
node = ra->ra_node;
|
|
|
|
sc->sc_clockfreq = getpropint(node, "clock-frequency", 25*1000*1000);
|
|
|
|
printf(": clock = %s MHz\n", clockfreq(sc->sc_clockfreq));
|
|
|
|
|
|
|
|
if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "sbus") == 0)
|
1994-09-18 03:57:27 +04:00
|
|
|
oca.ca_ra.ra_bp = ra->ra_bp + 1;
|
1993-10-02 13:22:00 +03:00
|
|
|
else
|
1994-09-18 03:57:27 +04:00
|
|
|
oca.ca_ra.ra_bp = NULL;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through ROM children, fixing any relative addresses
|
|
|
|
* and then configuring each device.
|
|
|
|
*/
|
|
|
|
for (node = firstchild(node); node; node = nextsibling(node)) {
|
|
|
|
name = getpropstring(node, "name");
|
1994-09-18 03:57:27 +04:00
|
|
|
if (!romprop(&oca.ca_ra, name, node))
|
1993-10-02 13:22:00 +03:00
|
|
|
continue;
|
1994-09-18 03:57:27 +04:00
|
|
|
base = (int)oca.ca_ra.ra_paddr;
|
1993-10-02 13:22:00 +03:00
|
|
|
if (SBUS_ABS(base)) {
|
1994-09-18 03:57:27 +04:00
|
|
|
oca.ca_slot = SBUS_ABS_TO_SLOT(base);
|
|
|
|
oca.ca_offset = SBUS_ABS_TO_OFFSET(base);
|
1993-10-02 13:22:00 +03:00
|
|
|
} else {
|
1994-09-18 03:57:27 +04:00
|
|
|
oca.ca_slot = slot = oca.ca_ra.ra_iospace;
|
|
|
|
oca.ca_offset = base;
|
|
|
|
oca.ca_ra.ra_paddr = (void *)SBUS_ADDR(slot, base);
|
1995-02-01 15:37:21 +03:00
|
|
|
/* Fix any remaining register banks */
|
|
|
|
for (i = 1; i < oca.ca_ra.ra_nreg; i++) {
|
|
|
|
base = (int)oca.ca_ra.ra_reg[i].rr_paddr;
|
|
|
|
oca.ca_ra.ra_reg[i].rr_paddr =
|
|
|
|
(void *)SBUS_ADDR(slot, base);
|
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
1994-09-18 03:57:27 +04:00
|
|
|
oca.ca_bustype = BUS_SBUS;
|
|
|
|
(void) config_found(&sc->sc_dev, (void *)&oca, sbus_print);
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each attached device calls sbus_establish after it initializes
|
|
|
|
* its sbusdev portion.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbus_establish(sd, dev)
|
|
|
|
register struct sbusdev *sd;
|
|
|
|
register struct device *dev;
|
|
|
|
{
|
|
|
|
register struct sbus_softc *sc = (struct sbus_softc *)dev->dv_parent;
|
|
|
|
|
|
|
|
sd->sd_dev = dev;
|
|
|
|
sd->sd_bchain = sc->sc_sbdev;
|
|
|
|
sc->sc_sbdev = sd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the given sbus. (???)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbusreset(sbus)
|
|
|
|
int sbus;
|
|
|
|
{
|
|
|
|
register struct sbusdev *sd;
|
|
|
|
struct sbus_softc *sc = sbuscd.cd_devs[sbus];
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
printf("reset %s:", sc->sc_dev.dv_xname);
|
|
|
|
for (sd = sc->sc_sbdev; sd != NULL; sd = sd->sd_bchain) {
|
|
|
|
if (sd->sd_reset) {
|
|
|
|
dev = sd->sd_dev;
|
|
|
|
(*sd->sd_reset)(dev);
|
|
|
|
printf(" %s", dev->dv_xname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|