summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authortmm <tmm@FreeBSD.org>2001-11-09 20:10:55 +0000
committertmm <tmm@FreeBSD.org>2001-11-09 20:10:55 +0000
commitdcba1df2157c55e7fe21c0fe64ad9975bdd3eccb (patch)
tree19d0b7b2b3098a323022a70d89201b2b94c25d8a /sys
parentadebde5f2dad30fc257378410fd8f6132bfc82d1 (diff)
downloadFreeBSD-src-dcba1df2157c55e7fe21c0fe64ad9975bdd3eccb.zip
FreeBSD-src-dcba1df2157c55e7fe21c0fe64ad9975bdd3eccb.tar.gz
Add some OpenFirmware bus support code and definitions.
Diffstat (limited to 'sys')
-rw-r--r--sys/sparc64/include/ofw_bus.h34
-rw-r--r--sys/sparc64/include/ofw_machdep.h38
-rw-r--r--sys/sparc64/include/ofw_nexus.h68
-rw-r--r--sys/sparc64/include/ofw_upa.h68
-rw-r--r--sys/sparc64/sparc64/ofw_bus.c90
-rw-r--r--sys/sparc64/sparc64/ofw_machdep.c50
6 files changed, 348 insertions, 0 deletions
diff --git a/sys/sparc64/include/ofw_bus.h b/sys/sparc64/include/ofw_bus.h
new file mode 100644
index 0000000..55f15f9
--- /dev/null
+++ b/sys/sparc64/include/ofw_bus.h
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
+ * 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 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_OFW_BUS_H_
+#define _MACHINE_OFW_BUS_H_
+
+u_int32_t ofw_bus_route_intr(int intr, void *regs, int regsz, int physz,
+ int nregs, void *imap, int nimap, void *imapmsk, char *regm);
+
+#endif /* !_MACHINE_OFW_BUS_H_ */
diff --git a/sys/sparc64/include/ofw_machdep.h b/sys/sparc64/include/ofw_machdep.h
new file mode 100644
index 0000000..bd4c651
--- /dev/null
+++ b/sys/sparc64/include/ofw_machdep.h
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
+ * 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 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_OFW_MACHDEP_H_
+#define _MACHINE_OFW_MACHDEP_H_
+
+#include <sys/bus.h>
+
+void OF_getetheraddr(device_t dev, u_char *addr);
+
+void openfirmware_exit(void *);
+
+#endif /* _MACHINE_OFW_MACHDEP_H_ */
+
diff --git a/sys/sparc64/include/ofw_nexus.h b/sys/sparc64/include/ofw_nexus.h
new file mode 100644
index 0000000..c920a9c
--- /dev/null
+++ b/sys/sparc64/include/ofw_nexus.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 1998, 1999 Eduardo E. Horvath
+ * Copyright (c) 1999 Matthew R. Green
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * 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.
+ *
+ * from: NetBSD: psychoreg.h,v 1.8 2001/09/10 16:17:06 eeh Exp
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_OFW_UPA_H_
+#define _MACHINE_OFW_UPA_H_
+
+/*
+ * These are the regs and ranges property the psycho uses. They should be
+ * applicable to all UPA devices. XXX: verify this.
+ */
+
+struct upa_regs {
+ u_int32_t phys_hi;
+ u_int32_t phys_mid;
+ u_int32_t phys_lo;
+ u_int32_t size_hi;
+ u_int32_t size_lo;
+};
+
+struct upa_ranges {
+ u_int32_t cspace;
+ u_int32_t child_hi;
+ u_int32_t child_lo;
+ u_int32_t phys_hi;
+ u_int32_t phys_lo;
+ u_int32_t size_hi;
+ u_int32_t size_lo;
+};
+
+#define UPA_RANGE_CHILD(r) \
+ (((u_int64_t)(r)->child_hi << 32) | (u_int64_t)(r)->child_lo)
+#define UPA_RANGE_PHYS(r) \
+ (((u_int64_t)(r)->phys_hi << 32) | (u_int64_t)(r)->phys_lo)
+#define UPA_RANGE_SIZE(r) \
+ (((u_int64_t)(r)->size_hi << 32) | (u_int64_t)(r)->size_lo)
+#define UPA_RANGE_CS(r) (((r)->cspace >> 24) & 0x03)
+
+#endif /* !_MACHINE_OFW_UPA_H_ */
diff --git a/sys/sparc64/include/ofw_upa.h b/sys/sparc64/include/ofw_upa.h
new file mode 100644
index 0000000..c920a9c
--- /dev/null
+++ b/sys/sparc64/include/ofw_upa.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 1998, 1999 Eduardo E. Horvath
+ * Copyright (c) 1999 Matthew R. Green
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * 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.
+ *
+ * from: NetBSD: psychoreg.h,v 1.8 2001/09/10 16:17:06 eeh Exp
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_OFW_UPA_H_
+#define _MACHINE_OFW_UPA_H_
+
+/*
+ * These are the regs and ranges property the psycho uses. They should be
+ * applicable to all UPA devices. XXX: verify this.
+ */
+
+struct upa_regs {
+ u_int32_t phys_hi;
+ u_int32_t phys_mid;
+ u_int32_t phys_lo;
+ u_int32_t size_hi;
+ u_int32_t size_lo;
+};
+
+struct upa_ranges {
+ u_int32_t cspace;
+ u_int32_t child_hi;
+ u_int32_t child_lo;
+ u_int32_t phys_hi;
+ u_int32_t phys_lo;
+ u_int32_t size_hi;
+ u_int32_t size_lo;
+};
+
+#define UPA_RANGE_CHILD(r) \
+ (((u_int64_t)(r)->child_hi << 32) | (u_int64_t)(r)->child_lo)
+#define UPA_RANGE_PHYS(r) \
+ (((u_int64_t)(r)->phys_hi << 32) | (u_int64_t)(r)->phys_lo)
+#define UPA_RANGE_SIZE(r) \
+ (((u_int64_t)(r)->size_hi << 32) | (u_int64_t)(r)->size_lo)
+#define UPA_RANGE_CS(r) (((r)->cspace >> 24) & 0x03)
+
+#endif /* !_MACHINE_OFW_UPA_H_ */
diff --git a/sys/sparc64/sparc64/ofw_bus.c b/sys/sparc64/sparc64/ofw_bus.c
new file mode 100644
index 0000000..22fb7da
--- /dev/null
+++ b/sys/sparc64/sparc64/ofw_bus.c
@@ -0,0 +1,90 @@
+/*-
+ * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
+ * 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 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * OpenFirmware bus support code that is (hopefully) independent from the used
+ * hardware.
+ * Maybe this should go into dev/ofw/; there may however be sparc specific
+ * bits left.
+ */
+
+#include <sys/param.h>
+#include <sys/malloc.h>
+#include <sys/systm.h>
+
+#include <ofw/openfirm.h>
+
+#include <machine/ofw_bus.h>
+
+
+/*
+ * Route an interrupt using the firmware. This takes an interrupt map and mask,
+ * as retrieved from the firmware (this must be done by the caller, since it
+ * is not bus-independent).
+ * regs points to a "reg" property as returned by the firmware. regsz ist the
+ * the size of one reg element, physz is the size of the physical address member
+ * at the start of each reg (this is matched against the interrupt map).
+ * The interrupt map has entries of the size (physsz + 12), the 12 being the
+ * size of two u_int32_t that hold the interrupt number to compare against, the
+ * node the map belongs to and the interrupt that the child interrupt is mapped
+ * to (if the map entry matches).
+ * The first nregs registers are checked against the map; in some cases (e.g.
+ * PCI), only the first must be checked.
+ * The mask consists of a mask wich must be and-ed to the checked physical
+ * address part of the ofw reg and to the interrupt number before checking
+ * against the map.
+ * regm should point to a buffer of physsz size (this is not malloc'ed because
+ * malloc cannot be called in all situations).
+ */
+u_int32_t
+ofw_bus_route_intr(int intr, void *regs, int regsz, int physsz, int nregs,
+ void *imap, int nimap, void *imapmsk, char *regm)
+{
+ u_int8_t *mptr;
+ u_int32_t mintr, cintr;
+ int r, i;
+
+ cintr = -1;
+ bcopy((u_int8_t *)imapmsk + physsz, &mintr, sizeof(mintr));
+ mintr &= intr;
+ for (r = 0; r < nregs; r++) {
+ for (i = 0; i < physsz; i++) {
+ regm[i] = ((u_int8_t *)regs)[r * regsz + i] &
+ ((u_int8_t *)imapmsk)[i];
+ }
+ for (i = 0; i < nimap; i++) {
+ mptr = (u_int8_t *)imap + i * (physsz + 12);
+ if (bcmp(regm, mptr, physsz) == 0 &&
+ bcmp(&mintr, mptr + physsz, sizeof(mintr)) == 0) {
+ bcopy(mptr + physsz + 8, &cintr,
+ sizeof(cintr));
+ break;
+ }
+ }
+ }
+ return (cintr);
+}
diff --git a/sys/sparc64/sparc64/ofw_machdep.c b/sys/sparc64/sparc64/ofw_machdep.c
new file mode 100644
index 0000000..b247e71
--- /dev/null
+++ b/sys/sparc64/sparc64/ofw_machdep.c
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
+ * 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 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Some OpenFirmware helper functions that are likely machine dependent.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <ofw/openfirm.h>
+
+#include <machine/idprom.h>
+#include <machine/ofw_machdep.h>
+
+void
+OF_getetheraddr(device_t dev, u_char *addr)
+{
+ phandle_t node;
+ struct idprom idp;
+
+ node = OF_peer(0);
+ if (node <= 0 || OF_getprop(node, "idprom", &idp, sizeof(idp)) == -1)
+ panic("Could not determine the machine ethernet address");
+ bcopy(&idp.id_ether, addr, sizeof(addr));
+}
OpenPOWER on IntegriCloud