Skeleton code for the SBus expander box.

This commit is contained in:
pk 1998-04-18 19:00:17 +00:00
parent 1882b7131d
commit 90b5c246c6
5 changed files with 503 additions and 1 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sbus.c,v 1.23 1998/04/07 20:43:58 pk Exp $ */
/* $NetBSD: sbus.c,v 1.24 1998/04/18 19:00:18 pk Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -93,6 +93,7 @@
#include <machine/bus.h>
#include <sparc/dev/sbusreg.h>
#include <sparc/dev/sbusvar.h>
#include <sparc/dev/xboxvar.h>
#include <sparc/sparc/iommuvar.h>
#include <machine/autoconf.h>
@ -123,8 +124,10 @@ static void *sbus_intr_establish __P((
/* autoconfiguration driver */
int sbus_match_mainbus __P((struct device *, struct cfdata *, void *));
int sbus_match_iommu __P((struct device *, struct cfdata *, void *));
int sbus_match_xbox __P((struct device *, struct cfdata *, void *));
void sbus_attach_mainbus __P((struct device *, struct device *, void *));
void sbus_attach_iommu __P((struct device *, struct device *, void *));
void sbus_attach_xbox __P((struct device *, struct device *, void *));
struct cfattach sbus_mainbus_ca = {
sizeof(struct sbus_softc), sbus_match_mainbus, sbus_attach_mainbus
@ -132,6 +135,9 @@ struct cfattach sbus_mainbus_ca = {
struct cfattach sbus_iommu_ca = {
sizeof(struct sbus_softc), sbus_match_iommu, sbus_attach_iommu
};
struct cfattach sbus_xbox_ca = {
sizeof(struct sbus_softc), sbus_match_xbox, sbus_attach_xbox
};
extern struct cfdriver sbus_cd;
@ -230,6 +236,20 @@ sbus_match_iommu(parent, cf, aux)
return (strcmp(cf->cf_driver->cd_name, ia->iom_name) == 0);
}
int
sbus_match_xbox(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct xbox_attach_args *xa = aux;
if (CPU_ISSUN4)
return (0);
return (strcmp(cf->cf_driver->cd_name, xa->xa_name) == 0);
}
/*
* Attach an Sbus.
*/
@ -296,6 +316,32 @@ sbus_attach_iommu(parent, self, aux)
sbus_attach(sc, "sbus", node, ia->iom_bp, NULL);
}
void
sbus_attach_xbox(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct sbus_softc *sc = (struct sbus_softc *)self;
struct xbox_attach_args *xa = aux;
int node = xa->xa_node;
sc->sc_bustag = xa->xa_bustag;
sc->sc_dmatag = xa->xa_dmatag;
/* Setup interrupt translation tables */
sc->sc_intr2ipl = CPU_ISSUN4C ? intr_sbus2ipl_4c : intr_sbus2ipl_4m;
/*
* Record clock frequency for synchronous SCSI.
* IS THIS THE CORRECT DEFAULT??
*/
sc->sc_clockfreq = getpropint(node, "clock-frequency", 25*1000*1000);
printf(": clock = %s MHz\n", clockfreq(sc->sc_clockfreq));
sbus_attach(sc, "sbus", node, xa->xa_bp, NULL);
}
void
sbus_attach(sc, busname, busnode, bp, specials)
struct sbus_softc *sc;

176
sys/arch/sparc/dev/xbox.c Normal file
View File

@ -0,0 +1,176 @@
/* $NetBSD: xbox.c,v 1.1 1998/04/18 19:00:17 pk Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg.
*
* 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 NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 expansion box.
*/
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <vm/vm.h>
#include <machine/bus.h>
#include <sparc/dev/sbusvar.h>
#include <sparc/dev/xboxvar.h>
#include <machine/autoconf.h>
/*
* Xbox registers definitions.
*
* The xbox device can operate in two mode: "opaque" and "transparent".
* In opaque mode, all accesses to the xbox address space are directed
* to the xbox itself. In transparent mode, all accesses are mapped to
* the SBus cards in the expansion box.
*
* To access the xbox registers in transparent mode, you must write
* to the "write0" register. The layout of this register appears to
* be as follows:
*
* bit 31-24: xbox key (identifies device when you cascade them)
* bit 23-12: offset of register to access
* bit 11-0: value to write
*
* For instance, to switch to opaque mode:
* (*sc->write0_reg) = (sc->sc_key << 24) | XAC_CTL1_OFFSET;
*
* (note we're not currently using any of this)
*/
#define WRITE0_OFFSET 0
#define XAC_ERR_OFFSET 0x2000
#define XAC_CTL0_OFFSET 0x10000
#define XAC_CTL1_OFFSET 0x11000
#define XAC_ELUA_OFFSET 0x12000
#define XAC_ELLA_OFFSET 0x13000
#define XAC_ELE_OFFSET 0x14000
#define XBC_ERR_OFFSET 0x42000
#define XBC_CTL0_OFFSET 0x50000
#define XBC_CTL1_OFFSET 0x51000
#define XBC_ELUA_OFFSET 0x52000
#define XBC_ELLA_OFFSET 0x53000
#define XBC_ELE_OFFSET 0x54000
#define XBOX_NREG 13
struct xbox_softc {
struct device sc_dev; /* base device */
int sc_key; /* this xbox's unique key */
};
/* autoconfiguration driver */
int xbox_match __P((struct device *, struct cfdata *, void *));
void xbox_attach __P((struct device *, struct device *, void *));
int xbox_print __P(( void *, const char *));
struct cfattach xbox_ca = {
sizeof(struct xbox_softc), xbox_match, xbox_attach
};
int
xbox_print(args, busname)
void *args;
const char *busname;
{
struct xbox_attach_args *xa = args;
if (busname)
printf("%s at %s", xa->xa_name, busname);
return (UNCONF);
}
int
xbox_match(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct sbus_attach_args *sa = aux;
return (strcmp("SUNW,xbox", sa->sa_name) == 0);
}
/*
* Attach an Xbox.
*/
void
xbox_attach(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct xbox_softc *sc = (struct xbox_softc *)self;
struct sbus_attach_args *sa = aux;
struct bootpath *bp = sa->sa_bp;
int node = sa->sa_node;
struct xbox_attach_args xa;
char *cp;
sc->sc_key = getpropint(node, "write0-key", -1);
cp = getpropstring(node, "model");
printf(": model %s", cp);
cp = getpropstring(node, "child-present");
if (strcmp(cp, "true") != 0) {
printf(": no sbus devices\n");
return;
}
printf("\n");
/* Propagate bootpath */
if (bp != NULL && strcmp(bp->name, "xbox") == 0)
bp++;
else
bp = NULL;
/*
* Now pretend to be another Sbus.
*/
bzero(&xa, sizeof xa);
xa.xa_name = "sbus";
xa.xa_node = node;
xa.xa_bustag = sa->sa_bustag;
xa.xa_dmatag = sa->sa_dmatag;
xa.xa_bp = bp;
(void) config_found(&sc->sc_dev, (void *)&xa, xbox_print);
}

View File

@ -0,0 +1,52 @@
/* $NetBSD: xboxvar.h,v 1.1 1998/04/18 19:00:18 pk Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg.
*
* 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 NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef _XBOX_VAR_H
#define _XBOX_VAR_H
/*
* Xbox driver attach arguments.
*/
struct xbox_attach_args {
bus_space_tag_t xa_bustag;
bus_dma_tag_t xa_dmatag;
char *xa_name; /* PROM node name */
int xa_node; /* PROM handle */
struct bootpath *xa_bp; /* used for locating boot device */
};
#endif /* _XBOX_VAR_H */

176
sys/dev/sbus/xbox.c Normal file
View File

@ -0,0 +1,176 @@
/* $NetBSD: xbox.c,v 1.1 1998/04/18 19:00:17 pk Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg.
*
* 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 NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 expansion box.
*/
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <vm/vm.h>
#include <machine/bus.h>
#include <sparc/dev/sbusvar.h>
#include <sparc/dev/xboxvar.h>
#include <machine/autoconf.h>
/*
* Xbox registers definitions.
*
* The xbox device can operate in two mode: "opaque" and "transparent".
* In opaque mode, all accesses to the xbox address space are directed
* to the xbox itself. In transparent mode, all accesses are mapped to
* the SBus cards in the expansion box.
*
* To access the xbox registers in transparent mode, you must write
* to the "write0" register. The layout of this register appears to
* be as follows:
*
* bit 31-24: xbox key (identifies device when you cascade them)
* bit 23-12: offset of register to access
* bit 11-0: value to write
*
* For instance, to switch to opaque mode:
* (*sc->write0_reg) = (sc->sc_key << 24) | XAC_CTL1_OFFSET;
*
* (note we're not currently using any of this)
*/
#define WRITE0_OFFSET 0
#define XAC_ERR_OFFSET 0x2000
#define XAC_CTL0_OFFSET 0x10000
#define XAC_CTL1_OFFSET 0x11000
#define XAC_ELUA_OFFSET 0x12000
#define XAC_ELLA_OFFSET 0x13000
#define XAC_ELE_OFFSET 0x14000
#define XBC_ERR_OFFSET 0x42000
#define XBC_CTL0_OFFSET 0x50000
#define XBC_CTL1_OFFSET 0x51000
#define XBC_ELUA_OFFSET 0x52000
#define XBC_ELLA_OFFSET 0x53000
#define XBC_ELE_OFFSET 0x54000
#define XBOX_NREG 13
struct xbox_softc {
struct device sc_dev; /* base device */
int sc_key; /* this xbox's unique key */
};
/* autoconfiguration driver */
int xbox_match __P((struct device *, struct cfdata *, void *));
void xbox_attach __P((struct device *, struct device *, void *));
int xbox_print __P(( void *, const char *));
struct cfattach xbox_ca = {
sizeof(struct xbox_softc), xbox_match, xbox_attach
};
int
xbox_print(args, busname)
void *args;
const char *busname;
{
struct xbox_attach_args *xa = args;
if (busname)
printf("%s at %s", xa->xa_name, busname);
return (UNCONF);
}
int
xbox_match(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct sbus_attach_args *sa = aux;
return (strcmp("SUNW,xbox", sa->sa_name) == 0);
}
/*
* Attach an Xbox.
*/
void
xbox_attach(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct xbox_softc *sc = (struct xbox_softc *)self;
struct sbus_attach_args *sa = aux;
struct bootpath *bp = sa->sa_bp;
int node = sa->sa_node;
struct xbox_attach_args xa;
char *cp;
sc->sc_key = getpropint(node, "write0-key", -1);
cp = getpropstring(node, "model");
printf(": model %s", cp);
cp = getpropstring(node, "child-present");
if (strcmp(cp, "true") != 0) {
printf(": no sbus devices\n");
return;
}
printf("\n");
/* Propagate bootpath */
if (bp != NULL && strcmp(bp->name, "xbox") == 0)
bp++;
else
bp = NULL;
/*
* Now pretend to be another Sbus.
*/
bzero(&xa, sizeof xa);
xa.xa_name = "sbus";
xa.xa_node = node;
xa.xa_bustag = sa->sa_bustag;
xa.xa_dmatag = sa->sa_dmatag;
xa.xa_bp = bp;
(void) config_found(&sc->sc_dev, (void *)&xa, xbox_print);
}

52
sys/dev/sbus/xboxvar.h Normal file
View File

@ -0,0 +1,52 @@
/* $NetBSD: xboxvar.h,v 1.1 1998/04/18 19:00:18 pk Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg.
*
* 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 NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef _XBOX_VAR_H
#define _XBOX_VAR_H
/*
* Xbox driver attach arguments.
*/
struct xbox_attach_args {
bus_space_tag_t xa_bustag;
bus_dma_tag_t xa_dmatag;
char *xa_name; /* PROM node name */
int xa_node; /* PROM handle */
struct bootpath *xa_bp; /* used for locating boot device */
};
#endif /* _XBOX_VAR_H */