summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>2004-09-22 21:44:46 +0000
committerJason Wright <jason@cvs.openbsd.org>2004-09-22 21:44:46 +0000
commit9189c5b5e7dc31301ae42764f26aabae1717993e (patch)
tree6c82e8a400876ffac381cec8d70d1ec0ac0e8bc6
parent140f69fc93dbf0784e374d98d45d5ddd910300f5 (diff)
firehose controller driver (not quite working) for the e4500 (and others)
-rw-r--r--sys/arch/sparc64/dev/fhc.c197
-rw-r--r--sys/arch/sparc64/dev/fhc_central.c126
-rw-r--r--sys/arch/sparc64/dev/fhc_mainbus.c74
-rw-r--r--sys/arch/sparc64/dev/fhcvar.h70
4 files changed, 467 insertions, 0 deletions
diff --git a/sys/arch/sparc64/dev/fhc.c b/sys/arch/sparc64/dev/fhc.c
new file mode 100644
index 00000000000..34c4c46e702
--- /dev/null
+++ b/sys/arch/sparc64/dev/fhc.c
@@ -0,0 +1,197 @@
+/* $OpenBSD: fhc.c,v 1.1 2004/09/22 21:44:45 jason Exp $ */
+
+/*
+ * Copyright (c) 2004 Jason L. Wright (jason@thought.net)
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/timeout.h>
+#include <sys/malloc.h>
+
+#include <machine/bus.h>
+#include <machine/autoconf.h>
+#include <machine/openfirm.h>
+
+#include <sparc64/dev/fhcvar.h>
+
+struct cfdriver fhc_cd = {
+ NULL, "fhc", DV_DULL
+};
+
+int fhc_print(void *, const char *);
+
+bus_space_tag_t fhc_alloc_bus_tag(struct fhc_softc *);
+int _fhc_bus_map(bus_space_tag_t, bus_space_tag_t, bus_addr_t, bus_size_t,
+ int, bus_space_handle_t *);
+
+void
+fhc_attach(struct fhc_softc *sc)
+{
+ int node0, node;
+
+ printf(": %s\n", getpropstring(sc->sc_node, "board-model"));
+
+ sc->sc_cbt = fhc_alloc_bus_tag(sc);
+
+ getprop(sc->sc_node, "ranges", sizeof(struct fhc_range),
+ &sc->sc_nrange, (void **)&sc->sc_range);
+
+#if 0
+ for (node = 0; node < sc->sc_nrange; node++)
+ printf("%d: cs %08x co %08x ps %08x po %08x sz %08x\n",
+ node, sc->sc_range[node].cspace,
+ sc->sc_range[node].coffset, sc->sc_range[node].pspace,
+ sc->sc_range[node].poffset, sc->sc_range[node].size);
+#endif
+
+ node0 = firstchild(sc->sc_node);
+ for (node = node0; node; node = nextsibling(node)) {
+ struct fhc_attach_args fa;
+
+ bzero(&fa, sizeof(fa));
+
+ fa.fa_node = node;
+ fa.fa_bustag = sc->sc_cbt;
+
+ if (fhc_get_string(fa.fa_node, "name", &fa.fa_name)) {
+ printf("can't fetch name for node 0x%x\n", node);
+ continue;
+ }
+ getprop(node, "reg", sizeof(struct fhc_reg),
+ &fa.fa_nreg, (void **)&fa.fa_reg);
+
+#if 0
+ printf("%s registers:\n", fa.fa_name);
+ for (i = 0; i < fa.fa_nreg; i++) {
+ printf(" %d slot 0x%x offset 0x%x size 0x%x\n", i,
+ fa.fa_reg[i].fbr_slot,
+ fa.fa_reg[i].fbr_offset,
+ fa.fa_reg[i].fbr_size);
+ }
+
+ (void)config_found(&sc->sc_dv, (void *)&fa, fhc_print);
+#endif
+
+ if (fa.fa_name != NULL)
+ free(fa.fa_name, M_DEVBUF);
+ if (fa.fa_reg != NULL)
+ free(fa.fa_reg, M_DEVBUF);
+ }
+}
+
+int
+fhc_print(void *args, const char *busname)
+{
+ struct fhc_attach_args *fa = args;
+ char *class;
+
+ if (busname != NULL) {
+ printf("%s at %s", fa->fa_name, busname);
+ class = getpropstring(fa->fa_node, "device_type");
+ if (*class != '\0')
+ printf(" class %s", class);
+ }
+ return (UNCONF);
+}
+
+int
+fhc_get_string(int node, char *name, char **buf)
+{
+ int len;
+
+ len = getproplen(node, name);
+ if (len < 0)
+ return (len);
+ *buf = (char *)malloc(len + 1, M_DEVBUF, M_NOWAIT);
+ if (buf == NULL)
+ return (-1);
+
+ if (len != 0)
+ getpropstringA(node, name, *buf);
+ (*buf)[len] = '\0';
+ return (0);
+}
+
+bus_space_tag_t
+fhc_alloc_bus_tag(struct fhc_softc *sc)
+{
+ struct sparc_bus_space_tag *bt;
+
+ bt = malloc(sizeof(*bt), M_DEVBUF, M_NOWAIT);
+ if (bt == NULL)
+ panic("fhc: couldn't alloc bus tag");
+
+ bzero(bt, sizeof(*bt));
+ snprintf(bt->name, sizeof(bt->name), "%s", sc->sc_dv.dv_xname);
+ bt->cookie = sc;
+ bt->parent = sc->sc_bt;
+ bt->asi = bt->parent->asi;
+ bt->sasi = bt->parent->sasi;
+ bt->sparc_bus_map = _fhc_bus_map;
+ /* XXX bt->sparc_bus_mmap = fhc_bus_mmap; */
+ /* XXX bt->sparc_intr_establish = upa_intr_establish; */
+ return (bt);
+}
+
+int
+_fhc_bus_map(bus_space_tag_t t, bus_space_tag_t t0, bus_addr_t addr,
+ bus_size_t size, int flags, bus_space_handle_t *hp)
+{
+ struct fhc_softc *sc = t->cookie;
+ int64_t slot = BUS_ADDR_IOSPACE(addr);
+ int64_t offset = BUS_ADDR_PADDR(addr);
+ int i;
+
+ if (t->parent == NULL || t->parent->sparc_bus_map == NULL) {
+ printf("\n_fhc_bus_map: invalid parent");
+ return (EINVAL);
+ }
+
+ if (flags & BUS_SPACE_MAP_PROMADDRESS)
+ return ((*t->parent->sparc_bus_map)(t, t0, addr,
+ size, flags, hp));
+
+ for (i = 0; i < sc->sc_nrange; i++) {
+ bus_addr_t paddr;
+
+ if (sc->sc_range[i].cspace != slot)
+ continue;
+
+ paddr = offset - sc->sc_range[i].coffset;
+ paddr += sc->sc_range[i].poffset;
+ paddr |= ((bus_addr_t)sc->sc_range[i].pspace << 32);
+
+ printf("[fhc %llx]", (unsigned long long)paddr);
+ return ((*t->parent->sparc_bus_map)(t, t0, paddr,
+ size, flags, hp));
+ }
+
+ return (EINVAL);
+}
diff --git a/sys/arch/sparc64/dev/fhc_central.c b/sys/arch/sparc64/dev/fhc_central.c
new file mode 100644
index 00000000000..c72fc9150ea
--- /dev/null
+++ b/sys/arch/sparc64/dev/fhc_central.c
@@ -0,0 +1,126 @@
+/* $OpenBSD: fhc_central.c,v 1.1 2004/09/22 21:44:45 jason Exp $ */
+
+/*
+ * Copyright (c) 2004 Jason L. Wright (jason@thought.net).
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/timeout.h>
+
+#include <machine/bus.h>
+#include <machine/autoconf.h>
+#include <machine/openfirm.h>
+
+#include <sparc64/dev/centralvar.h>
+#include <sparc64/dev/fhcvar.h>
+
+int fhc_central_match(struct device *, void *, void *);
+void fhc_central_attach(struct device *, struct device *, void *);
+
+struct cfattach fhc_central_ca = {
+ sizeof(struct fhc_softc), fhc_central_match, fhc_central_attach
+};
+
+int
+fhc_central_match(parent, match, aux)
+ struct device *parent;
+ void *match, *aux;
+{
+ struct central_attach_args *ca = aux;
+
+ if (strcmp(ca->ca_name, "fhc") == 0)
+ return (1);
+ return (0);
+}
+
+void
+fhc_central_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+{
+ struct fhc_softc *sc = (struct fhc_softc *)self;
+ struct central_attach_args *ca = aux;
+ int i;
+
+ sc->sc_node = ca->ca_node;
+ sc->sc_bt = ca->ca_bustag;
+
+ for (i = 0; i < ca->ca_nreg; i++) {
+ printf("\n r%d slot %08x offset %08x size %08x\n", i,
+ ca->ca_reg[i].cbr_slot,
+ ca->ca_reg[i].cbr_offset,
+ ca->ca_reg[i].cbr_size);
+ }
+
+ if (central_bus_map(sc->sc_bt, ca->ca_reg[0].cbr_slot,
+ ca->ca_reg[0].cbr_offset, ca->ca_reg[0].cbr_size, 0,
+ &sc->sc_preg)) {
+ printf(": failed to map preg\n");
+ return;
+ }
+
+ if (central_bus_map(sc->sc_bt, ca->ca_reg[1].cbr_slot,
+ ca->ca_reg[1].cbr_offset, ca->ca_reg[1].cbr_size, 0,
+ &sc->sc_ireg)) {
+ printf(": failed to map ireg\n");
+ return;
+ }
+
+ if (central_bus_map(sc->sc_bt, ca->ca_reg[2].cbr_slot,
+ ca->ca_reg[2].cbr_offset, ca->ca_reg[2].cbr_size, 0,
+ &sc->sc_freg)) {
+ printf(": failed to map freg\n");
+ return;
+ }
+
+ if (central_bus_map(sc->sc_bt, ca->ca_reg[3].cbr_slot,
+ ca->ca_reg[3].cbr_offset, ca->ca_reg[3].cbr_size, 0,
+ &sc->sc_sreg)) {
+ printf(": failed to map sreg\n");
+ return;
+ }
+
+ if (central_bus_map(sc->sc_bt, ca->ca_reg[4].cbr_slot,
+ ca->ca_reg[4].cbr_offset, ca->ca_reg[4].cbr_size, 0,
+ &sc->sc_ureg)) {
+ printf(": failed to map ureg\n");
+ return;
+ }
+
+ if (central_bus_map(sc->sc_bt, ca->ca_reg[5].cbr_slot,
+ ca->ca_reg[5].cbr_offset, ca->ca_reg[5].cbr_size, 0,
+ &sc->sc_treg)) {
+ printf(": failed to map treg\n");
+ return;
+ }
+
+ fhc_attach(sc);
+ return;
+}
diff --git a/sys/arch/sparc64/dev/fhc_mainbus.c b/sys/arch/sparc64/dev/fhc_mainbus.c
new file mode 100644
index 00000000000..acc213bae3b
--- /dev/null
+++ b/sys/arch/sparc64/dev/fhc_mainbus.c
@@ -0,0 +1,74 @@
+/* $OpenBSD: fhc_mainbus.c,v 1.1 2004/09/22 21:44:45 jason Exp $ */
+
+/*
+ * Copyright (c) 2004 Jason L. Wright (jason@thought.net).
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/timeout.h>
+
+#include <machine/bus.h>
+#include <machine/autoconf.h>
+#include <machine/openfirm.h>
+
+#include <sparc64/dev/fhcvar.h>
+
+int fhc_mainbus_match(struct device *, void *, void *);
+void fhc_mainbus_attach(struct device *, struct device *, void *);
+
+struct cfattach fhc_mainbus_ca = {
+ sizeof(struct fhc_softc), fhc_mainbus_match, fhc_mainbus_attach
+};
+
+int
+fhc_mainbus_match(parent, match, aux)
+ struct device *parent;
+ void *match, *aux;
+{
+ struct mainbus_attach_args *ma = aux;
+
+ if (strcmp(ma->ma_name, "fhc") == 0)
+ return (1);
+ return (0);
+}
+
+void
+fhc_mainbus_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+{
+ struct fhc_softc *sc = (struct fhc_softc *)self;
+ struct mainbus_attach_args *ma = aux;
+
+ sc->sc_node = ma->ma_node;
+ sc->sc_bt = ma->ma_bustag;
+ fhc_attach(sc);
+ return;
+}
diff --git a/sys/arch/sparc64/dev/fhcvar.h b/sys/arch/sparc64/dev/fhcvar.h
new file mode 100644
index 00000000000..879614eb55b
--- /dev/null
+++ b/sys/arch/sparc64/dev/fhcvar.h
@@ -0,0 +1,70 @@
+/* $OpenBSD: fhcvar.h,v 1.1 2004/09/22 21:44:45 jason Exp $ */
+
+/*
+ * Copyright (c) 2004 Jason L. Wright (jason@thought.net).
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+struct fhc_reg {
+ u_int32_t fbr_slot;
+ u_int32_t fbr_offset;
+ u_int32_t fbr_size;
+};
+
+struct fhc_range {
+ u_int32_t cspace; /* Client space */
+ u_int32_t coffset; /* Client offset */
+ u_int32_t pspace; /* Parent space */
+ u_int32_t poffset; /* Parent offset */
+ u_int32_t size; /* Size in bytes of this range */
+};
+
+struct fhc_softc {
+ struct device sc_dv;
+ int sc_node;
+ bus_space_tag_t sc_bt;
+ bus_space_tag_t sc_cbt;
+ int sc_nrange;
+ struct fhc_range *sc_range;
+ bus_space_handle_t sc_preg; /* internal regs */
+ bus_space_handle_t sc_ireg; /* ign regs */
+ bus_space_handle_t sc_freg; /* fanfail regs */
+ bus_space_handle_t sc_sreg; /* system regs */
+ bus_space_handle_t sc_ureg; /* uart regs */
+ bus_space_handle_t sc_treg; /* tod regs */
+};
+
+void fhc_attach(struct fhc_softc *);
+int fhc_get_string(int, char *, char **);
+
+struct fhc_attach_args {
+ char *fa_name;
+ int fa_node;
+ int fa_nreg;
+ struct fhc_reg *fa_reg;
+ bus_space_tag_t fa_bustag;
+};
+
+#define fhc_bus_map(t, slot, offset, sz, flags, hp) \
+ bus_space_map(t, BUS_ADDR(slot, offset), sz, flags, hp)