Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Oct 2013 17:24:22 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r256994 - in head/sys: dev/ofw powerpc/ofw powerpc/powerpc powerpc/pseries
Message-ID:  <201310231724.r9NHOM31068574@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Wed Oct 23 17:24:21 2013
New Revision: 256994
URL: http://svnweb.freebsd.org/changeset/base/256994

Log:
  Add two new interfaces to ofw_bus:
  - ofw_bus_map_intr()
    Maps an (iparent, IRQ) tuple to a system-global interrupt number in some
    platform dependent way. This is meant to be implemented as a replacement
    for [FDT_]MAP_IRQ() that is an MI interface that knows about the bus
    hierarchy.
  - ofw_bus_config_intr()
    Configures an interrupt (previously mapped) based on firmware sense flags.
    This replaces manual interpretation of the sense field in bus drivers and
    will, in a follow-up, allow that interpretation to be redirected to the PIC
    drivers where it belongs. This will eventually replace the tables in
    /sys/dev/fdt/fdt_ARCH.c
  
  The PowerPC/AIM code has been converted to use these globally, with an
  implementation in terms of MAP_IRQ() and powerpc_config_intr(), assuming
  OpenPIC, at the bus root in nexus(4). The ofw_bus_config_intr() will shortly
  be integrated into pic_if.m and bounced through nexus into the PIC tree.
  
  FDT integration will happen significantly later due to larger testing
  requirements. This patch in general also lays the groundwork for the removal
  of /sys/dev/fdt/fdt_ARCH.c and machine/fdt.h.

Modified:
  head/sys/dev/ofw/ofw_bus.h
  head/sys/dev/ofw/ofw_bus_if.m
  head/sys/powerpc/ofw/ofw_pci.c
  head/sys/powerpc/ofw/ofw_pcib_pci.c
  head/sys/powerpc/ofw/ofw_pcibus.c
  head/sys/powerpc/powerpc/nexus.c
  head/sys/powerpc/pseries/vdevice.c

Modified: head/sys/dev/ofw/ofw_bus.h
==============================================================================
--- head/sys/dev/ofw/ofw_bus.h	Wed Oct 23 17:18:53 2013	(r256993)
+++ head/sys/dev/ofw/ofw_bus.h	Wed Oct 23 17:24:21 2013	(r256994)
@@ -70,4 +70,16 @@ ofw_bus_get_type(device_t dev)
 	return (OFW_BUS_GET_TYPE(device_get_parent(dev), dev));
 }
 
+static __inline int
+ofw_bus_map_intr(device_t dev, phandle_t iparent, int irq)
+{
+	return (OFW_BUS_MAP_INTR(dev, dev, iparent, irq));
+}
+
+static __inline int
+ofw_bus_config_intr(device_t dev, int irq, int sense)
+{
+	return (OFW_BUS_CONFIG_INTR(dev, dev, irq, sense));
+}
+
 #endif /* !_DEV_OFW_OFW_BUS_H_ */

Modified: head/sys/dev/ofw/ofw_bus_if.m
==============================================================================
--- head/sys/dev/ofw/ofw_bus_if.m	Wed Oct 23 17:18:53 2013	(r256993)
+++ head/sys/dev/ofw/ofw_bus_if.m	Wed Oct 23 17:24:21 2013	(r256994)
@@ -56,6 +56,8 @@ CODE {
 	static ofw_bus_get_name_t ofw_bus_default_get_name;
 	static ofw_bus_get_node_t ofw_bus_default_get_node;
 	static ofw_bus_get_type_t ofw_bus_default_get_type;
+	static ofw_bus_map_intr_t ofw_bus_default_map_intr;
+	static ofw_bus_config_intr_t ofw_bus_default_config_intr;
 
 	static const struct ofw_bus_devinfo *
 	ofw_bus_default_get_devinfo(device_t bus, device_t dev)
@@ -98,6 +100,31 @@ CODE {
 
 		return (NULL);
 	}
+
+	int
+	ofw_bus_default_map_intr(device_t bus, device_t dev, phandle_t iparent,
+	    int irq)
+	{
+		/* Propagate up the bus hierarchy until someone handles it. */	
+		if (device_get_parent(bus) != NULL)
+			return OFW_BUS_MAP_INTR(device_get_parent(bus), dev,
+			    iparent, irq);
+
+		/* If that fails, then assume a one-domain system */
+		return (irq);
+	}
+
+	int
+	ofw_bus_default_config_intr(device_t bus, device_t dev, int irq,
+	    int sense)
+	{
+		/* Propagate up the bus hierarchy until someone handles it. */	
+		if (device_get_parent(bus) != NULL)
+			return OFW_BUS_CONFIG_INTR(device_get_parent(bus), dev,
+			    irq, sense);
+
+		return (ENXIO);
+	}
 };
 
 # Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus
@@ -143,3 +170,22 @@ METHOD const char * get_type {
 	device_t bus;
 	device_t dev;
 } DEFAULT ofw_bus_default_get_type;
+
+# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number.
+METHOD int map_intr {
+	device_t bus;
+	device_t dev;
+	phandle_t iparent;
+	int irq;
+} DEFAULT ofw_bus_default_map_intr;
+
+# Configure an interrupt using the device-tree encoded sense key (the second
+# value in the interrupts property if interrupt-cells is 2). IRQ should be
+# encoded as from ofw_bus_map_intr().
+METHOD int config_intr {
+	device_t bus;
+	device_t dev;
+	int irq;
+	int sense;
+} DEFAULT ofw_bus_default_config_intr;
+

Modified: head/sys/powerpc/ofw/ofw_pci.c
==============================================================================
--- head/sys/powerpc/ofw/ofw_pci.c	Wed Oct 23 17:18:53 2013	(r256993)
+++ head/sys/powerpc/ofw/ofw_pci.c	Wed Oct 23 17:24:21 2013	(r256994)
@@ -272,7 +272,7 @@ ofw_pci_route_interrupt(device_t bus, de
 	if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo, &reg,
 	    sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr),
 	    &iparent, maskbuf))
-		return (MAP_IRQ(iparent, mintr));
+		return (ofw_bus_map_intr(dev, iparent, mintr));
 
 	/* Maybe it's a real interrupt, not an intpin */
 	if (pin > 4)

Modified: head/sys/powerpc/ofw/ofw_pcib_pci.c
==============================================================================
--- head/sys/powerpc/ofw/ofw_pcib_pci.c	Wed Oct 23 17:18:53 2013	(r256993)
+++ head/sys/powerpc/ofw/ofw_pcib_pci.c	Wed Oct 23 17:24:21 2013	(r256994)
@@ -157,7 +157,7 @@ ofw_pcib_pci_route_interrupt(device_t br
 			 * it again on higher levels - that causes problems
 			 * in some cases, and never seems to be required.
 			 */
-			return (MAP_IRQ(iparent, mintr));
+			return (ofw_bus_map_intr(dev, iparent, mintr));
 		}
 	} else if (intpin >= 1 && intpin <= 4) {
 		/*

Modified: head/sys/powerpc/ofw/ofw_pcibus.c
==============================================================================
--- head/sys/powerpc/ofw/ofw_pcibus.c	Wed Oct 23 17:18:53 2013	(r256993)
+++ head/sys/powerpc/ofw/ofw_pcibus.c	Wed Oct 23 17:24:21 2013	(r256994)
@@ -218,15 +218,13 @@ ofw_pcibus_enum_devtree(device_t dev, u_
 					OF_getprop(OF_xref_phandle(iparent),
 					    "#interrupt-cells", &icells,
 					    sizeof(icells));
-					intr[0] = MAP_IRQ(iparent, intr[0]);
+					intr[0] = ofw_bus_map_intr(dev, iparent,
+					    intr[0]);
 				}
 
-				if (iparent != 0 && icells > 1) {
-					powerpc_config_intr(intr[0],
-					    (intr[1] & 1) ? INTR_TRIGGER_LEVEL :
-					    INTR_TRIGGER_EDGE,
-					    INTR_POLARITY_LOW);
-				}
+				if (iparent != 0 && icells > 1)
+					ofw_bus_config_intr(dev, intr[0],
+					    intr[1]);
 
 				resource_list_add(&dinfo->opd_dinfo.resources,
 				    SYS_RES_IRQ, 0, intr[0], intr[0], 1);
@@ -343,12 +341,13 @@ ofw_pcibus_assign_interrupt(device_t dev
 
 	isz = OF_getprop(node, "AAPL,interrupts", &intr, sizeof(intr));
 	if (isz == sizeof(intr))
-		return ((iparent == -1) ? intr : MAP_IRQ(iparent, intr));
+		return ((iparent == -1) ? intr : ofw_bus_map_intr(dev, iparent,
+		    intr));
 
 	isz = OF_getprop(node, "interrupts", &intr, sizeof(intr));
 	if (isz == sizeof(intr)) {
 		if (iparent != -1)
-			intr = MAP_IRQ(iparent, intr);
+			intr = ofw_bus_map_intr(dev, iparent, intr);
 	} else {
 		/* No property: our best guess is the intpin. */
 		intr = pci_get_intpin(child);

Modified: head/sys/powerpc/powerpc/nexus.c
==============================================================================
--- head/sys/powerpc/powerpc/nexus.c	Wed Oct 23 17:18:53 2013	(r256993)
+++ head/sys/powerpc/powerpc/nexus.c	Wed Oct 23 17:24:21 2013	(r256994)
@@ -96,6 +96,8 @@ static bus_get_resource_list_t nexus_get
 static bus_bind_intr_t nexus_bind_intr;
 #endif
 static bus_config_intr_t nexus_config_intr;
+static ofw_bus_map_intr_t nexus_ofw_map_intr;
+static ofw_bus_config_intr_t nexus_ofw_config_intr;
 static ofw_bus_get_devinfo_t nexus_get_devinfo;
 
 static int nexus_inlist(const char *, const char *const *);
@@ -141,6 +143,8 @@ static device_method_t nexus_methods[] =
 	DEVMETHOD(ofw_bus_get_name,	ofw_bus_gen_get_name),
 	DEVMETHOD(ofw_bus_get_node,	ofw_bus_gen_get_node),
 	DEVMETHOD(ofw_bus_get_type,	ofw_bus_gen_get_type),
+	DEVMETHOD(ofw_bus_map_intr,	nexus_ofw_map_intr),
+	DEVMETHOD(ofw_bus_config_intr,	nexus_ofw_config_intr),
 
 	DEVMETHOD_END
 };
@@ -370,6 +374,21 @@ nexus_config_intr(device_t dev, int irq,
 	return (powerpc_config_intr(irq, trig, pol));
 } 
 
+static int
+nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, int irq)
+{
+	return (MAP_IRQ(iparent, irq));
+}
+
+static int
+nexus_ofw_config_intr(device_t dev, device_t child, int irq, int sense)
+{
+ 
+	return (bus_generic_config_intr(child, irq, (sense & 1) ?
+	    INTR_TRIGGER_LEVEL : INTR_TRIGGER_EDGE,
+	    INTR_POLARITY_LOW));
+} 
+
 static struct resource *
 nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
     u_long start, u_long end, u_long count, u_int flags)
@@ -600,14 +619,11 @@ nexus_setup_dinfo(device_t dev, phandle_
 		OF_searchprop(iparent, "#interrupt-cells", &icells,
 		    sizeof(icells));
 		for (i = 0; i < nintr; i+= icells) {
-			intr[i] = MAP_IRQ(iparent, intr[i]);
+			intr[i] = ofw_bus_map_intr(dev, iparent, intr[i]);
 			resource_list_add(&ndi->ndi_rl, SYS_RES_IRQ, i, intr[i],
 			    intr[i], 1);
-			if (icells > 1) {
-				powerpc_config_intr(intr[i], (intr[i+1] & 1) ?
-				    INTR_TRIGGER_LEVEL : INTR_TRIGGER_EDGE,
-				    INTR_POLARITY_LOW);
-			}
+			if (icells > 1)
+				ofw_bus_config_intr(dev, intr[i], intr[i+1]);
 		}
 		free(intr, M_OFWPROP);
 	}

Modified: head/sys/powerpc/pseries/vdevice.c
==============================================================================
--- head/sys/powerpc/pseries/vdevice.c	Wed Oct 23 17:18:53 2013	(r256993)
+++ head/sys/powerpc/pseries/vdevice.c	Wed Oct 23 17:24:21 2013	(r256994)
@@ -156,7 +156,8 @@ vdevice_attach(device_t dev) 
 			for (i = 0; i < nintr; i += icells) {
 				u_int irq = intr[i];
 				if (iparent != -1)
-					irq = MAP_IRQ(iparent, intr[i]);
+					irq = ofw_bus_map_intr(dev, iparent,
+					    intr[i]);
 
 				resource_list_add(&dinfo->mdi_resources,
 				    SYS_RES_IRQ, i, irq, irq, i);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310231724.r9NHOM31068574>