PERFORCE change 153068 for review

Nathan Whitehorn nwhitehorn at FreeBSD.org
Sun Nov 16 18:24:27 PST 2008


http://perforce.freebsd.org/chv.cgi?CH=153068

Change 153068 by nwhitehorn at nwhitehorn_trantor on 2008/11/17 02:23:57

	Very small changes in very many files -- move ofw_bus.* from sparc64
	into dev/ofw/ofw_bus_subr*. Both PowerPC and sparc64 now use this code,
	which works very nicely. This finishes the elimination of the 
	ofw_pci_fixup() hack on PPC.
	
	Tested on: Sun Ultra 5, iBook G4, Powermac G3

Affected files ...

.. //depot/projects/ppc-g5/sys/conf/files.powerpc#10 edit
.. //depot/projects/ppc-g5/sys/conf/files.sparc64#5 edit
.. //depot/projects/ppc-g5/sys/dev/ofw/ofw_bus_subr.c#2 edit
.. //depot/projects/ppc-g5/sys/dev/ofw/ofw_bus_subr.h#2 edit
.. //depot/projects/ppc-g5/sys/dev/ofw/ofw_imap.c#3 delete
.. //depot/projects/ppc-g5/sys/dev/ofw/ofw_imap.h#2 delete
.. //depot/projects/ppc-g5/sys/dev/ofw/openfirm.h#4 edit
.. //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_isa.c#2 edit
.. //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pcib_pci.c#5 edit
.. //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pcibus.c#4 edit
.. //depot/projects/ppc-g5/sys/powerpc/powermac/cpcht.c#10 edit
.. //depot/projects/ppc-g5/sys/powerpc/powermac/grackle.c#8 edit
.. //depot/projects/ppc-g5/sys/powerpc/powermac/uninorth.c#8 edit
.. //depot/projects/ppc-g5/sys/sparc64/ebus/ebus.c#2 edit
.. //depot/projects/ppc-g5/sys/sparc64/include/ofw_bus.h#2 delete
.. //depot/projects/ppc-g5/sys/sparc64/isa/ofw_isa.c#2 edit
.. //depot/projects/ppc-g5/sys/sparc64/pci/apb.c#2 edit
.. //depot/projects/ppc-g5/sys/sparc64/pci/ofw_pci.h#2 edit
.. //depot/projects/ppc-g5/sys/sparc64/pci/ofw_pcib.c#2 edit
.. //depot/projects/ppc-g5/sys/sparc64/pci/ofw_pcib_subr.c#2 edit
.. //depot/projects/ppc-g5/sys/sparc64/pci/ofw_pcibus.c#2 edit
.. //depot/projects/ppc-g5/sys/sparc64/pci/psycho.c#3 edit
.. //depot/projects/ppc-g5/sys/sparc64/pci/schizo.c#3 edit
.. //depot/projects/ppc-g5/sys/sparc64/sparc64/ofw_bus.c#2 delete
.. //depot/projects/ppc-g5/sys/sparc64/sparc64/ofw_machdep.c#4 edit

Differences ...

==== //depot/projects/ppc-g5/sys/conf/files.powerpc#10 (text+ko) ====

@@ -44,7 +44,6 @@
 dev/ofw/ofw_bus_subr.c		optional	aim
 dev/ofw/ofw_console.c		optional	aim
 dev/ofw/ofw_disk.c		optional	ofwd aim
-dev/ofw/ofw_imap.c		optional	aim
 dev/ofw/ofw_standard.c		optional	aim
 dev/powermac_nvram/powermac_nvram.c optional	powermac_nvram powermac
 dev/quicc/quicc_bfe_ocp.c	optional	quicc mpc85xx

==== //depot/projects/ppc-g5/sys/conf/files.sparc64#5 (text+ko) ====

@@ -123,7 +123,6 @@
 sparc64/sparc64/mp_locore.S	optional	smp
 sparc64/sparc64/mp_machdep.c	optional	smp
 sparc64/sparc64/nexus.c		standard
-sparc64/sparc64/ofw_bus.c	standard
 sparc64/sparc64/ofw_machdep.c	standard
 sparc64/sparc64/pmap.c		standard
 sparc64/sparc64/prof_machdep.c	optional	profiling-routine

==== //depot/projects/ppc-g5/sys/dev/ofw/ofw_bus_subr.c#2 (text+ko) ====

@@ -1,4 +1,6 @@
 /*-
+ * Copyright (C) 1996 Wolfgang Solfrank.
+ * Copyright (C) 1996 TooLs GmbH.
  * Copyright (c) 2005 Marius Strobl <marius at FreeBSD.org>
  * All rights reserved.
  *
@@ -126,3 +128,135 @@
 		return (NULL);
 	return (obd->obd_type);
 }
+
+static int
+ofw_bus_searchprop(phandle_t node, char *propname, void *buf, int buflen)
+{
+	int rv;
+
+	for (; node != 0; node = OF_parent(node)) {
+		if ((rv = OF_getprop(node, propname, buf, buflen)) != -1)
+			return (rv);
+	}
+	return (-1);
+}
+
+void
+ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz)
+{
+	pcell_t addrc;
+	int msksz;
+
+	if (OF_getprop(node, "#address-cells", &addrc, sizeof(addrc)) == -1)
+		addrc = 2;
+	ii->opi_addrc = addrc * sizeof(pcell_t);
+
+	ii->opi_imapsz = OF_getprop_alloc(node, "interrupt-map", 1,
+	    (void **)&ii->opi_imap);
+	if (ii->opi_imapsz > 0) {
+		msksz = OF_getprop_alloc(node, "interrupt-map-mask", 1,
+		    (void **)&ii->opi_imapmsk);
+		/*
+		 * Failure to get the mask is ignored; a full mask is used then.
+		 * Barf on bad mask sizes, however.
+		 */
+		if (msksz != -1 && msksz != ii->opi_addrc + intrsz) {
+			panic("ofw_bus_setup_iinfo: bad interrupt-map-mask "
+			    "property!");
+		}
+	}
+
+}
+
+int
+ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg,
+    int regsz, void *pintr, int pintrsz, void *mintr, int mintrsz,
+    void *maskbuf)
+{
+	int rv;
+
+	if (ii->opi_imapsz <= 0)
+		return (0);
+	KASSERT(regsz >= ii->opi_addrc,
+	    ("ofw_bus_lookup_imap: register size too small: %d < %d",
+		regsz, ii->opi_addrc));
+	rv = OF_getprop(node, "reg", reg, regsz);
+	if (rv < regsz)
+		panic("ofw_bus_lookup_imap: could not get reg property");
+	return (ofw_bus_search_intrmap(pintr, pintrsz, reg, ii->opi_addrc,
+	    ii->opi_imap, ii->opi_imapsz, ii->opi_imapmsk, maskbuf, mintr,
+	    mintrsz));
+}
+
+/*
+ * Map an interrupt using the firmware reg, interrupt-map and
+ * interrupt-map-mask properties.
+ * The interrupt property to be mapped must be of size intrsz, and pointed to
+ * by intr. The regs property of the node for which the mapping is done must
+ * be passed as regs. This property is an array of register specifications;
+ * the size of the address part of such a specification must be passed as
+ * physsz. Only the first element of the property is used.
+ * imap and imapsz hold the interrupt mask and it's size.
+ * imapmsk is a pointer to the interrupt-map-mask property, which must have
+ * a size of physsz + intrsz; it may be NULL, in which case a full mask is
+ * assumed.
+ * maskbuf must point to a buffer of length physsz + intrsz.
+ * The interrupt is returned in result, which must point to a buffer of length
+ * rintrsz (which gives the expected size of the mapped interrupt).
+ * Returns 1 if a mapping was found, 0 otherwise.
+ */
+int
+ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz,
+    void *imap, int imapsz, void *imapmsk, void *maskbuf, void *result,
+    int rintrsz)
+{
+	phandle_t parent;
+	u_int8_t *ref = maskbuf;
+	u_int8_t *uiintr = intr;
+	u_int8_t *uiregs = regs;
+	u_int8_t *uiimapmsk = imapmsk;
+	u_int8_t *mptr;
+	pcell_t pintrsz;
+	int i, rsz, tsz;
+
+	rsz = -1;
+	if (imapmsk != NULL) {
+		for (i = 0; i < physsz; i++)
+			ref[i] = uiregs[i] & uiimapmsk[i];
+		for (i = 0; i < intrsz; i++)
+			ref[physsz + i] = uiintr[i] & uiimapmsk[physsz + i];
+	} else {
+		bcopy(regs, ref, physsz);
+		bcopy(intr, ref + physsz, intrsz);
+	}
+
+	mptr = imap;
+	i = imapsz;
+	tsz = physsz + intrsz + sizeof(phandle_t) + rintrsz;
+	while (i > 0) {
+		KASSERT(i >= tsz, ("ofw_bus_search_intrmap: truncated map"));
+		bcopy(mptr + physsz + intrsz, &parent, sizeof(parent));
+		if (ofw_bus_searchprop(parent, "#interrupt-cells",
+		    &pintrsz, sizeof(pintrsz)) == -1)
+			pintrsz = 1;	/* default */
+		pintrsz *= sizeof(pcell_t);
+		if (pintrsz != rintrsz)
+			panic("ofw_bus_search_intrmap: expected interrupt cell "
+			    "size incorrect: %d > %d", rintrsz, pintrsz);
+	
+		/*
+		 * XXX: Apple hardware used a second cell to set information
+		 * on the interrupt trigger type. This information should
+		 * be used.
+		 */
+
+		if (bcmp(ref, mptr, physsz + intrsz) == 0) {
+			bcopy(mptr + physsz + intrsz + sizeof(parent),
+			    result, rintrsz);
+			return (1);
+		}
+		mptr += tsz;
+		i -= tsz;
+	}
+	return (0);
+}

==== //depot/projects/ppc-g5/sys/dev/ofw/ofw_bus_subr.h#2 (text+ko) ====

@@ -37,9 +37,27 @@
 
 #include "ofw_bus_if.h"
 
+#define	ORIP_NOINT	-1
+#define	ORIR_NOTFOUND	0xffffffff
+
+struct ofw_bus_iinfo {
+	u_int8_t		*opi_imap;
+	u_int8_t		*opi_imapmsk;
+	int			opi_imapsz;
+	pcell_t			opi_addrc;
+};
+
 int	ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *, phandle_t);
 void	ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *);
 
+/* Routines for processing firmware interrupt maps */
+
+void	ofw_bus_setup_iinfo(phandle_t, struct ofw_bus_iinfo *, int);
+int	ofw_bus_lookup_imap(phandle_t, struct ofw_bus_iinfo *, void *, int,
+	    void *, int, void *, int, void *);
+int	ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *,
+	    void *, void *, int);
+
 ofw_bus_get_compat_t	ofw_bus_gen_get_compat;
 ofw_bus_get_model_t	ofw_bus_gen_get_model;
 ofw_bus_get_name_t	ofw_bus_gen_get_name;

==== //depot/projects/ppc-g5/sys/dev/ofw/openfirm.h#4 (text+ko) ====

@@ -64,8 +64,9 @@
  * Prototypes for Open Firmware Interface Routines
  */
 
-typedef	unsigned int	ihandle_t;
-typedef unsigned int	phandle_t;
+typedef	uint32_t	ihandle_t;
+typedef uint32_t	phandle_t;
+typedef uint32_t	pcell_t;
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>

==== //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_isa.c#2 (text+ko) ====

@@ -42,9 +42,9 @@
 #include <sys/bus.h>
 
 #include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_imap.h>
 #include <dev/ofw/ofw_pci.h>
 #include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
 
 #include <dev/pci/pcivar.h>
 

==== //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pcib_pci.c#5 (text+ko) ====

@@ -35,8 +35,8 @@
 
 #include <dev/ofw/openfirm.h>
 #include <dev/ofw/ofw_pci.h>
-#include <dev/ofw/ofw_imap.h>
 #include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>

==== //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_pcibus.c#4 (text+ko) ====

@@ -40,7 +40,6 @@
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
 #include <dev/ofw/ofw_pci.h>
-#include <dev/ofw/ofw_imap.h>
 #include <dev/ofw/openfirm.h>
 
 #include <machine/bus.h>

==== //depot/projects/ppc-g5/sys/powerpc/powermac/cpcht.c#10 (text+ko) ====

@@ -46,7 +46,6 @@
 #include <sys/rman.h>
 
 #include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_imap.h>
 #include <dev/ofw/ofw_bus_subr.h>
 #include <powerpc/powermac/cpchtvar.h>
 

==== //depot/projects/ppc-g5/sys/powerpc/powermac/grackle.c#8 (text+ko) ====

@@ -37,7 +37,7 @@
 #include <dev/ofw/openfirm.h>
 #include <dev/ofw/ofw_pci.h>
 #include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_imap.h>
+#include <dev/ofw/ofw_bus_subr.h>
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>

==== //depot/projects/ppc-g5/sys/powerpc/powermac/uninorth.c#8 (text+ko) ====

@@ -35,7 +35,7 @@
 #include <dev/ofw/openfirm.h>
 #include <dev/ofw/ofw_pci.h>
 #include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_imap.h>
+#include <dev/ofw/ofw_bus_subr.h>
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>

==== //depot/projects/ppc-g5/sys/sparc64/ebus/ebus.c#2 (text+ko) ====

@@ -51,7 +51,6 @@
 #include <dev/ofw/ofw_bus_subr.h>
 #include <dev/ofw/openfirm.h>
 
-#include <machine/ofw_bus.h>
 #include <machine/resource.h>
 
 #include <dev/pci/pcireg.h>

==== //depot/projects/ppc-g5/sys/sparc64/isa/ofw_isa.c#2 (text+ko) ====

@@ -41,10 +41,10 @@
 #include <sys/bus.h>
 
 #include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
 
 #include <machine/bus.h>
 #include <machine/resource.h>
-#include <machine/ofw_bus.h>
 
 #include <sparc64/pci/ofw_pci.h>
 #include <sparc64/isa/ofw_isa.h>

==== //depot/projects/ppc-g5/sys/sparc64/pci/apb.c#2 (text+ko) ====

@@ -53,7 +53,6 @@
 #include <dev/ofw/openfirm.h>
 
 #include <machine/bus.h>
-#include <machine/ofw_bus.h>
 #include <machine/resource.h>
 
 #include <dev/pci/pcireg.h>

==== //depot/projects/ppc-g5/sys/sparc64/pci/ofw_pci.h#2 (text+ko) ====

@@ -34,7 +34,7 @@
 #ifndef _SPARC64_PCI_OFW_PCI_H_
 #define	_SPARC64_PCI_OFW_PCI_H_
 
-#include <machine/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
 
 typedef uint32_t ofw_pci_intr_t;
 

==== //depot/projects/ppc-g5/sys/sparc64/pci/ofw_pcib.c#2 (text+ko) ====

@@ -45,7 +45,6 @@
 #include <dev/ofw/openfirm.h>
 
 #include <machine/bus.h>
-#include <machine/ofw_bus.h>
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>

==== //depot/projects/ppc-g5/sys/sparc64/pci/ofw_pcib_subr.c#2 (text+ko) ====

@@ -37,7 +37,6 @@
 #include <dev/ofw/openfirm.h>
 
 #include <machine/bus.h>
-#include <machine/ofw_bus.h>
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>

==== //depot/projects/ppc-g5/sys/sparc64/pci/ofw_pcibus.c#2 (text+ko) ====

@@ -40,7 +40,6 @@
 #include <sys/pciio.h>
 
 #include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_bus_subr.h>
 #include <dev/ofw/ofw_pci.h>
 #include <dev/ofw/openfirm.h>
 

==== //depot/projects/ppc-g5/sys/sparc64/pci/psycho.c#3 (text+ko) ====

@@ -64,7 +64,6 @@
 #include <machine/bus_private.h>
 #include <machine/iommureg.h>
 #include <machine/iommuvar.h>
-#include <machine/ofw_bus.h>
 #include <machine/resource.h>
 #include <machine/ver.h>
 

==== //depot/projects/ppc-g5/sys/sparc64/pci/schizo.c#3 (text+ko) ====

@@ -64,7 +64,6 @@
 #include <machine/fsr.h>
 #include <machine/iommureg.h>
 #include <machine/iommuvar.h>
-#include <machine/ofw_bus.h>
 #include <machine/resource.h>
 
 #include <dev/pci/pcireg.h>

==== //depot/projects/ppc-g5/sys/sparc64/sparc64/ofw_machdep.c#4 (text+ko) ====

@@ -43,7 +43,6 @@
 
 #include <machine/bus.h>
 #include <machine/idprom.h>
-#include <machine/ofw_bus.h>
 #include <machine/ofw_machdep.h>
 
 void


More information about the p4-projects mailing list