Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Mar 2018 22:39:38 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r331501 - in stable/11/sys: arm/conf arm/freescale/imx dev/iicbus dev/sdhci dev/usb/controller modules modules/i2c/iicbus modules/imx modules/imx/imx_i2c
Message-ID:  <201803242239.w2OMdct9011839@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Sat Mar 24 22:39:38 2018
New Revision: 331501
URL: https://svnweb.freebsd.org/changeset/base/331501

Log:
  MFC r329479-r329480, r329483, r329506-r329507, r329526, r329529, r329536,
      r329541, r329730, r329841, r329988, r330397
  
  r329479:
  Do not try to deallocate memory that wasn't allocated (you'd think that
  would be safe, but the function also tries to destroy mutexes that never
  got created).
  
  I guess this can only happen when imx_ehci_detach() is called on the
  error-exit path from imx_ehci_attach(), and that path never got exercised
  before today.
  
  r329480:
  Don't call sdhci_cleanup_slot() if sdhci_init_slot() never got called.
  Also, do callout_init() very early in attach, so that callout_drain()
  can be called in detach without worrying about whether it ever got init'd.
  
  r329483:
  Fix fallout from the import of fresh dts source files from linux 4.15.  It
  appears that node names no longer include leading zeroes in the @address
  qualifiers, so we have to search for the nodes involved in interrupt fixup
  using both flavors of name to be compatible with old and new .dtb files.
  
  (You know you're in a bad place when you're applying a workaround to code
  that exists only as a workaround for another problem.)
  
  r329506:
  Add a detach method so that this can be a kldunload-friendly module.
  
  r329507:
  Build modules specific to imx5/imx6 only when building those kernels.
  
  This adds sys/modules/imx with a SUBDIR makefile to make the whole
  collection of modules that are specific to these SoCs.  Initially, that
  "whole collection" consists of the if_ffec and imx_i2c drivers.
  
  The if_ffec driver is referenced in its existing home in ../ffec rather
  than moving it into the imx directory, because it's used by powerpc too,
  but it is no longer built for all armv6/7 systems.
  
  The imx_i2c driver is newly added as a module.
  
  r329526:
  Allow i2c hardware drivers to declare their own relationships to ofw_iicbus
  rather than relying on a set of canned EARLY_DRIVER_MODULE() statements in
  the ofw_iicbus source.  This means hw drivers will no longer be required to
  use one of a few predefined driver names.  They will also now be able to
  decide themselves if they want to use DRIVER_MODULE or EARLY_DRIVER_MODULE
  and to set which pass to attach on for early modules.
  
  Mainly, this adds extern declarations for the driver and devclass variables.
  It also renames ofwiicbus_devclass to ofw_iicbus_devclass to be consistant
  with the way we use ofw_ prefixes on this stuff.
  
  r329529:
  Give the imx_i2c driver its own name, set up its relationship to ofw_iicbus.
  Previously it called itself 'iichb' to link up with the EARLY_DRIVER_MODULE
  declaration in ofw_iicbus.c.
  
  r329536:
  Add the MODULE_DEPEND()s needed so that the kernel linker can resolve all
  the symbols at load time when iicbus is not compiled into the kernel.
  
  r329541:
  Build ofw_iicbus as a module if OPT_FDT is defined.
  
  r329730:
  Add required header files.
  
  Reported by:	andreast@
  
  r329841:
  Add a missing line continuation.
  
  How many commits does it take to get a simple module makefile working?
  Apparently at least three.
  
  Pointy hat to:  ian
  
  r329988:
  Instead of building ofw_iicbus as a separate module, just compile it in to
  the iicbus module for FDT-based systems.
  
  The primary motivation for this is that host controller drivers which
  declare DRIVER_MODULE(ofw_iicbus, thisdriver, etc, etc) now only need a
  single MODULE_DEPEND(thisdriver, ofw_iicbus) for runtime linking to resolve
  all the symbols.  With ofw_iicbus and iicbus in separate modules, drivers
  would need to declare a MODULE_DEPEND() on both, because symbol lookup is
  non-recursive through the dependency chain.  Requiring a driver to have
  MODULE_DEPENDS() on both amounts to requiring the drivers to understand the
  kobj inheritence details of how ofw_iicbus is implemented, which seems like
  something they shouldn't have to know (and could even change some day).
  
  Also, this is somewhat analogous to how the drivers get built when compiled
  into the kernel.  You don't have to ask for ofw_iicbus separately, it just
  gets built in along with iicbus when option FDT is in effect.
  
  r330397:
  Fix a paste-o: use the IICBUS version constants, not IICBB bitbang driver's.

Added:
  stable/11/sys/modules/imx/
     - copied from r329507, head/sys/modules/imx/
Modified:
  stable/11/sys/arm/conf/IMX53
  stable/11/sys/arm/conf/IMX6
  stable/11/sys/arm/freescale/imx/imx6_machdep.c
  stable/11/sys/arm/freescale/imx/imx_i2c.c
  stable/11/sys/dev/iicbus/iicbus.h
  stable/11/sys/dev/iicbus/nxprtc.c
  stable/11/sys/dev/iicbus/ofw_iicbus.c
  stable/11/sys/dev/sdhci/fsl_sdhci.c
  stable/11/sys/dev/usb/controller/ehci_imx.c
  stable/11/sys/modules/Makefile
  stable/11/sys/modules/i2c/iicbus/Makefile
  stable/11/sys/modules/imx/imx_i2c/Makefile
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/arm/conf/IMX53
==============================================================================
--- stable/11/sys/arm/conf/IMX53	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/arm/conf/IMX53	Sat Mar 24 22:39:38 2018	(r331501)
@@ -117,6 +117,6 @@ device		wlan_amrr		# AMRR transmit rate control algori
 
 # Flattened Device Tree
 options 	FDT			# Configure using FDT/DTB data
-makeoptions	MODULES_EXTRA=dtb/imx5
+makeoptions	MODULES_EXTRA="dtb/imx5 imx"
 
 options 	INTRNG

Modified: stable/11/sys/arm/conf/IMX6
==============================================================================
--- stable/11/sys/arm/conf/IMX6	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/arm/conf/IMX6	Sat Mar 24 22:39:38 2018	(r331501)
@@ -117,7 +117,7 @@ device		hdmi
 
 # Flattened Device Tree
 options 	FDT			# Configure using FDT/DTB data
-makeoptions	MODULES_EXTRA=dtb/imx6
+makeoptions	MODULES_EXTRA="dtb/imx6 imx"
 
 # SoC-specific devices
 device		ffec			# Freescale Fast Ethernet Controller

Modified: stable/11/sys/arm/freescale/imx/imx6_machdep.c
==============================================================================
--- stable/11/sys/arm/freescale/imx/imx6_machdep.c	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/arm/freescale/imx/imx6_machdep.c	Sat Mar 24 22:39:38 2018	(r331501)
@@ -80,6 +80,12 @@ __FBSDID("$FreeBSD$");
  * per-soc logic.  We handle this at platform attach time rather than via the
  * fdt_fixup_table, because the latter requires matching on the FDT "model"
  * property, and this applies to all boards including those not yet invented.
+ *
+ * This just in:  as of the import of dts files from linux 4.15 on 2018-02-10,
+ * they appear to have applied a new style rule to the dts which forbids leading
+ * zeroes in the @address qualifiers on node names.  Since we have to find those
+ * nodes by string matching we now have to search for both flavors of each node
+ * name involved.
  */
 static void
 fix_fdt_interrupt_data(void)
@@ -99,9 +105,13 @@ fix_fdt_interrupt_data(void)
 
 	/* GIC node may be child of soc node, or appear directly at root. */
 	gicnode = OF_finddevice("/soc/interrupt-controller@00a01000");
+	if (gicnode == -1)
+		gicnode = OF_finddevice("/soc/interrupt-controller@a01000");
 	if (gicnode == -1) {
 		gicnode = OF_finddevice("/interrupt-controller@00a01000");
 		if (gicnode == -1)
+			gicnode = OF_finddevice("/interrupt-controller@a01000");
+		if (gicnode == -1)
 			return;
 	}
 	gicxref = OF_xref_from_node(gicnode);
@@ -113,6 +123,8 @@ fix_fdt_interrupt_data(void)
 		gicipar = gicxref;
 
 	gpcnode = OF_finddevice("/soc/aips-bus@02000000/gpc@020dc000");
+	if (gpcnode == -1)
+		gpcnode = OF_finddevice("/soc/aips-bus@2000000/gpc@20dc000");
 	if (gpcnode == -1)
 		return;
 	result = OF_getencprop(gpcnode, "interrupt-parent", &gpcipar,

Modified: stable/11/sys/arm/freescale/imx/imx_i2c.c
==============================================================================
--- stable/11/sys/arm/freescale/imx/imx_i2c.c	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/arm/freescale/imx/imx_i2c.c	Sat Mar 24 22:39:38 2018	(r331501)
@@ -155,6 +155,7 @@ struct i2c_softc {
 static phandle_t i2c_get_node(device_t, device_t);
 static int i2c_probe(device_t);
 static int i2c_attach(device_t);
+static int i2c_detach(device_t);
 
 static int i2c_repeated_start(device_t, u_char, int);
 static int i2c_start(device_t, u_char, int);
@@ -166,6 +167,7 @@ static int i2c_write(device_t, const char *, int, int 
 static device_method_t i2c_methods[] = {
 	DEVMETHOD(device_probe,			i2c_probe),
 	DEVMETHOD(device_attach,		i2c_attach),
+	DEVMETHOD(device_detach,		i2c_detach),
 
 	/* OFW methods */
 	DEVMETHOD(ofw_bus_get_node,		i2c_get_node),
@@ -183,14 +185,16 @@ static device_method_t i2c_methods[] = {
 };
 
 static driver_t i2c_driver = {
-	"iichb",
+	"imx_i2c",
 	i2c_methods,
 	sizeof(struct i2c_softc),
 };
 static devclass_t  i2c_devclass;
 
-DRIVER_MODULE(i2c, simplebus, i2c_driver, i2c_devclass, 0, 0);
-DRIVER_MODULE(iicbus, i2c, iicbus_driver, iicbus_devclass, 0, 0);
+DRIVER_MODULE(imx_i2c, simplebus, i2c_driver, i2c_devclass, 0, 0);
+DRIVER_MODULE(ofw_iicbus, imx_i2c, ofw_iicbus_driver, ofw_iicbus_devclass, 0, 0);
+MODULE_DEPEND(imx_i2c, iicbus, 1, 1, 1);
+MODULE_DEPEND(imx_i2c, ofw_iicbus, 1, 1, 1);
 
 static phandle_t
 i2c_get_node(device_t bus, device_t dev)
@@ -446,6 +450,28 @@ no_recovery:
 
 	/* Probe and attach the iicbus when interrupts are available. */
 	config_intrhook_oneshot((ich_func_t)bus_generic_attach, dev);
+	return (0);
+}
+
+static int
+i2c_detach(device_t dev)
+{
+	struct i2c_softc *sc;
+	int error;
+
+	sc = device_get_softc(dev);
+
+	if ((error = bus_generic_detach(sc->dev)) != 0) {
+		device_printf(sc->dev, "cannot detach child devices\n");
+		return (error);
+	}
+
+	if (sc->iicbus != NULL)
+		device_delete_child(dev, sc->iicbus);
+
+	if (sc->res != NULL)
+		bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->res);
+
 	return (0);
 }
 

Modified: stable/11/sys/dev/iicbus/iicbus.h
==============================================================================
--- stable/11/sys/dev/iicbus/iicbus.h	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/dev/iicbus/iicbus.h	Sat Mar 24 22:39:38 2018	(r331501)
@@ -77,5 +77,7 @@ void iicbus_init_frequency(device_t dev, u_int bus_fre
 
 extern driver_t iicbus_driver;
 extern devclass_t iicbus_devclass;
+extern driver_t ofw_iicbus_driver;
+extern devclass_t ofw_iicbus_devclass;
 
 #endif

Modified: stable/11/sys/dev/iicbus/nxprtc.c
==============================================================================
--- stable/11/sys/dev/iicbus/nxprtc.c	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/dev/iicbus/nxprtc.c	Sat Mar 24 22:39:38 2018	(r331501)
@@ -823,4 +823,4 @@ static devclass_t nxprtc_devclass;
 
 DRIVER_MODULE(nxprtc, iicbus, nxprtc_driver, nxprtc_devclass, NULL, NULL);
 MODULE_VERSION(nxprtc, 1);
-MODULE_DEPEND(nxprtc, iicbus, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER);
+MODULE_DEPEND(nxprtc, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER);

Modified: stable/11/sys/dev/iicbus/ofw_iicbus.c
==============================================================================
--- stable/11/sys/dev/iicbus/ofw_iicbus.c	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/dev/iicbus/ofw_iicbus.c	Sat Mar 24 22:39:38 2018	(r331501)
@@ -76,13 +76,15 @@ struct ofw_iicbus_devinfo {
 	struct ofw_bus_devinfo	opd_obdinfo;
 };
 
-devclass_t ofwiicbus_devclass;
+devclass_t ofw_iicbus_devclass;
 
 DEFINE_CLASS_1(iicbus, ofw_iicbus_driver, ofw_iicbus_methods,
     sizeof(struct iicbus_softc), iicbus_driver);
-EARLY_DRIVER_MODULE(ofw_iicbus, iicbb, ofw_iicbus_driver, ofwiicbus_devclass,
+EARLY_DRIVER_MODULE(ofw_iicbus, iicbb, ofw_iicbus_driver, ofw_iicbus_devclass,
     0, 0, BUS_PASS_BUS);
-EARLY_DRIVER_MODULE(ofw_iicbus, iichb, ofw_iicbus_driver, ofwiicbus_devclass,
+EARLY_DRIVER_MODULE(ofw_iicbus, iichb, ofw_iicbus_driver, ofw_iicbus_devclass,
+    0, 0, BUS_PASS_BUS);
+EARLY_DRIVER_MODULE(ofw_iicbus, twsi, ofw_iicbus_driver, ofw_iicbus_devclass,
     0, 0, BUS_PASS_BUS);
 MODULE_VERSION(ofw_iicbus, 1);
 MODULE_DEPEND(ofw_iicbus, iicbus, 1, 1, 1);

Modified: stable/11/sys/dev/sdhci/fsl_sdhci.c
==============================================================================
--- stable/11/sys/dev/sdhci/fsl_sdhci.c	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/dev/sdhci/fsl_sdhci.c	Sat Mar 24 22:39:38 2018	(r331501)
@@ -86,6 +86,7 @@ struct fsl_sdhci_softc {
 	uint16_t		sdclockreg_freq_bits;
 	uint8_t			r1bfix_type;
 	uint8_t			hwtype;
+	bool			slot_init_done;
 };
 
 #define	R1BFIX_NONE	0	/* No fix needed at next interrupt. */
@@ -814,6 +815,9 @@ fsl_sdhci_detach(device_t dev)
 
 	callout_drain(&sc->r1bfix_callout);
 
+	if (sc->slot_init_done)
+		sdhci_cleanup_slot(&sc->slot);
+
 	if (sc->intr_cookie != NULL)
 		bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie);
 	if (sc->irq_res != NULL)
@@ -821,7 +825,6 @@ fsl_sdhci_detach(device_t dev)
 		    rman_get_rid(sc->irq_res), sc->irq_res);
 
 	if (sc->mem_res != NULL) {
-		sdhci_cleanup_slot(&sc->slot);
 		bus_release_resource(dev, SYS_RES_MEMORY,
 		    rman_get_rid(sc->mem_res), sc->mem_res);
 	}
@@ -841,6 +844,8 @@ fsl_sdhci_attach(device_t dev)
 
 	sc->dev = dev;
 
+	callout_init(&sc->r1bfix_callout, 1);
+
 	sc->hwtype = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
 	if (sc->hwtype == HWTYPE_NONE)
 		panic("Impossible: not compatible in fsl_sdhci_attach()");
@@ -928,8 +933,8 @@ fsl_sdhci_attach(device_t dev)
 	WR4(sc, SDHC_PROT_CTRL, protctl);
 #endif
 
-	callout_init(&sc->r1bfix_callout, 1);
 	sdhci_init_slot(dev, &sc->slot, 0);
+	sc->slot_init_done = true;
 
 	bus_generic_probe(dev);
 	bus_generic_attach(dev);

Modified: stable/11/sys/dev/usb/controller/ehci_imx.c
==============================================================================
--- stable/11/sys/dev/usb/controller/ehci_imx.c	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/dev/usb/controller/ehci_imx.c	Sat Mar 24 22:39:38 2018	(r331501)
@@ -268,6 +268,7 @@ struct imx_ehci_softc {
 	device_t	dev;
 	struct resource	*ehci_mem_res;	/* EHCI core regs. */
 	struct resource	*ehci_irq_res;	/* EHCI core IRQ. */ 
+	bool		usb_mem_allocated;
 };
 
 static struct ofw_compat_data compat_data[] = {
@@ -331,7 +332,8 @@ imx_ehci_detach(device_t dev)
 		bus_release_resource(dev, SYS_RES_MEMORY, 0,
 		    sc->ehci_mem_res);
 
-	usb_bus_mem_free_all(&esc->sc_bus, &ehci_iterate_hw_softc);
+	if (sc->usb_mem_allocated)
+		usb_bus_mem_free_all(&esc->sc_bus, &ehci_iterate_hw_softc);
 
 	/* During module unload there are lots of children leftover */
 	device_delete_children(dev);
@@ -413,6 +415,7 @@ imx_ehci_attach(device_t dev)
 		err = ENOMEM;
 		goto out;
 	}
+	sc->usb_mem_allocated = true;
 
 	/*
 	 * Set handle to USB related registers subregion used by

Modified: stable/11/sys/modules/Makefile
==============================================================================
--- stable/11/sys/modules/Makefile	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/modules/Makefile	Sat Mar 24 22:39:38 2018	(r331501)
@@ -824,8 +824,9 @@ _cloudabi64=	cloudabi64
 
 .endif
 
-.if ${MACHINE_ARCH} == "armv6"
-_ffec=		ffec
+.if ${MACHINE_ARCH:Marmv[67]*} != "" || ${MACHINE_CPUARCH} == "aarch64"
+_bcm283x_clkman=  bcm283x_clkman
+_bcm283x_pwm=  bcm283x_pwm
 .endif
 
 SUBDIR+=${MODULES_EXTRA}

Modified: stable/11/sys/modules/i2c/iicbus/Makefile
==============================================================================
--- stable/11/sys/modules/i2c/iicbus/Makefile	Sat Mar 24 21:53:01 2018	(r331500)
+++ stable/11/sys/modules/i2c/iicbus/Makefile	Sat Mar 24 22:39:38 2018	(r331501)
@@ -5,4 +5,8 @@ KMOD		= iicbus
 SRCS		= device_if.h bus_if.h iicbus_if.h iicbus_if.c \
 		  iiconf.h iiconf.c iicbus.h iicbus.c
 
+.if !empty(OPT_FDT)
+SRCS+=	ofw_iicbus.c ofw_bus_if.h
+.endif
+
 .include <bsd.kmod.mk>

Modified: stable/11/sys/modules/imx/imx_i2c/Makefile
==============================================================================
--- head/sys/modules/imx/imx_i2c/Makefile	Sun Feb 18 02:48:54 2018	(r329507)
+++ stable/11/sys/modules/imx/imx_i2c/Makefile	Sat Mar 24 22:39:38 2018	(r331501)
@@ -8,6 +8,8 @@ SRCS=	imx_i2c.c
 SRCS+=	\
 	bus_if.h \
 	device_if.h \
+	fdt_pinctrl_if.h \
+	gpio_if.h \
 	iicbus_if.h \
 	ofw_bus_if.h \
 	opt_platform.h \



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