svn commit: r327936 - in head: share/man/man4 sys/arm/allwinner sys/dev/extres/syscon

Kyle Evans kevans at FreeBSD.org
Sat Jan 13 18:46:33 UTC 2018


Author: kevans
Date: Sat Jan 13 18:46:31 2018
New Revision: 327936
URL: https://svnweb.freebsd.org/changeset/base/327936

Log:
  Introduce aw_syscon(4) for earlier attachment
  
  Attaching syscon_generic earlier than BUS_PASS_DEFAULT makes it more
  difficult for specific syscon drivers to attach to the syscon node and to
  get ordering right. Further discussion yielded the following set of
  decisions:
  
  - Move syscon_generic to BUS_PASS_DEFAULT
  - If a platform needs a syscon with different attach order or probe
  behavior, it should subclass syscon_generic and match on the SoC specific
  compat string
  - When we come across a need for a syscon that attaches earlier but only
  specifies compatible = "syscon", we should create a syscon_exclusive driver
  that provides generic access but probes earlier and only matches if "syscon"
  is the only compatible. Such fdt nodes do exist in the wild right now, but
  we don't really use them at the moment.
  
  Additionally:
  
  - Any syscon provider that has needs any more complex than a spinlock solely
  for syscon access and a single memory resource should subclass syscon
  directly rather than attempting to subclass syscon_generic or add complexity
  to it. syscon_generic's attach/detach methods may be made public should the
  need arise to subclass it with additional attach/detach behavior.
  
  We introduce aw_syscon(4) that just subclasses syscon_generic but probes
  earlier to meet our requirements for if_awg and implements #2 above for this
  specific situation. It currently only matches a64/a83t/h3 since these are
  the only platforms that really need it at the time being.
  
  Discussed with:	ian
  Reviewed by:	manu, andrew, bcr (manpages, content unchanged since review)
  Differential Revision:	https://reviews.freebsd.org/D13793

Added:
  head/share/man/man4/aw_syscon.4   (contents, props changed)
  head/sys/arm/allwinner/aw_syscon.c   (contents, props changed)
  head/sys/dev/extres/syscon/syscon_generic.h   (contents, props changed)
Modified:
  head/share/man/man4/Makefile
  head/sys/arm/allwinner/files.allwinner
  head/sys/dev/extres/syscon/syscon_generic.c

Modified: head/share/man/man4/Makefile
==============================================================================
--- head/share/man/man4/Makefile	Sat Jan 13 18:28:30 2018	(r327935)
+++ head/share/man/man4/Makefile	Sat Jan 13 18:46:31 2018	(r327936)
@@ -74,6 +74,7 @@ MAN=	aac.4 \
 	${_aw_mmc.4} \
 	${_aw_rtc.4} \
 	${_aw_sid.4} \
+	${_aw_syscon.4} \
 	axe.4 \
 	axge.4 \
 	bce.4 \
@@ -765,6 +766,7 @@ _aw_gpio.4=	aw_gpio.4
 _aw_mmc.4=	aw_mmc.4
 _aw_rtc.4=	aw_rtc.4
 _aw_sid.4=	aw_sid.4
+_aw_syscon.4=	aw_syscon.4
 .endif
 
 .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"

Added: head/share/man/man4/aw_syscon.4
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man4/aw_syscon.4	Sat Jan 13 18:46:31 2018	(r327936)
@@ -0,0 +1,60 @@
+.\"-
+.\" Copyright (c) 2018 Kyle Evans <kevans at 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 AND CONTRIBUTORS ``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$
+.\"
+.Dd January 7, 2018
+.Dt AW_SYSCON 4
+.Os
+.Sh NAME
+.Nm aw_syscon
+.Nd driver for the system controller in Allwinner SoC
+.Sh DESCRIPTION
+The
+.Nm
+device driver provides support for the Allwinner system controller.
+This controller provides registers for tying together related functionality in a
+common space.
+.Nm
+is required for ethernet functionality on supported devices.
+.Sh HARDWARE
+The
+.Nm
+driver supports the system controller with one of the following compatible
+strings:
+.Pp
+.Bl -bullet -compact
+.It
+allwinner,sun50i-a64-system-controller
+.It
+allwinner,sun8i-a83t-system-controller
+.It
+allwinner,sun8i-h3-system-controller
+.El
+.Sh AUTHORS
+The
+.Nm
+device driver was written by
+.An Kyle Evans Aq Mt kevans at FreeBSD.org .

Added: head/sys/arm/allwinner/aw_syscon.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/arm/allwinner/aw_syscon.c	Sat Jan 13 18:46:31 2018	(r327936)
@@ -0,0 +1,82 @@
+/*-
+ * Copyright (c) 2018 Kyle Evans <kevans at 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 AND CONTRIBUTORS ``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.
+ */
+
+/*
+ * Allwinner syscon driver
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/rman.h>
+#include <machine/bus.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include <dev/extres/syscon/syscon.h>
+#include <dev/extres/syscon/syscon_generic.h>
+
+static struct ofw_compat_data compat_data[] = {
+	{"allwinner,sun50i-a64-system-controller", 1},
+	{"allwinner,sun8i-a83t-system-controller", 1},
+	{"allwinner,sun8i-h3-system-controller", 1},
+	{NULL,             0}
+};
+
+static int
+aw_syscon_probe(device_t dev)
+{
+
+	if (!ofw_bus_status_okay(dev))
+		return (ENXIO);
+	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
+		return (ENXIO);
+
+	device_set_desc(dev, "Allwinner syscon");
+	return (BUS_PROBE_DEFAULT);
+}
+
+static device_method_t aw_syscon_methods[] = {
+	DEVMETHOD(device_probe, aw_syscon_probe),
+
+	DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(aw_syscon, aw_syscon_driver, aw_syscon_methods,
+    sizeof(struct syscon_generic_softc), syscon_generic_driver);
+
+static devclass_t aw_syscon_devclass;
+/* aw_syscon needs to attach prior to if_awg */
+EARLY_DRIVER_MODULE(aw_syscon, simplebus, aw_syscon_driver, aw_syscon_devclass,
+    0, 0, BUS_PASS_DEFAULT - 1000);
+MODULE_VERSION(aw_syscon, 1);

Modified: head/sys/arm/allwinner/files.allwinner
==============================================================================
--- head/sys/arm/allwinner/files.allwinner	Sat Jan 13 18:28:30 2018	(r327935)
+++ head/sys/arm/allwinner/files.allwinner	Sat Jan 13 18:46:31 2018	(r327936)
@@ -15,6 +15,7 @@ arm/allwinner/aw_mp.c			optional	smp
 arm/allwinner/aw_nmi.c			optional	intrng
 arm/allwinner/aw_rsb.c			optional	rsb | p2wi
 arm/allwinner/aw_rtc.c			standard
+arm/allwinner/aw_syscon.c		optional	ext_resources syscon
 arm/allwinner/aw_ts.c			standard
 arm/allwinner/aw_usbphy.c		optional	ehci | ohci
 arm/allwinner/aw_wdog.c			standard

Modified: head/sys/dev/extres/syscon/syscon_generic.c
==============================================================================
--- head/sys/dev/extres/syscon/syscon_generic.c	Sat Jan 13 18:28:30 2018	(r327935)
+++ head/sys/dev/extres/syscon/syscon_generic.c	Sat Jan 13 18:46:31 2018	(r327936)
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
 
 #include "syscon_if.h"
 #include "syscon.h"
+#include "syscon_generic.h"
 
 MALLOC_DECLARE(M_SYSCON);
 
@@ -60,22 +61,15 @@ static int syscon_generic_modify_4(struct syscon *sysc
 /*
  * Generic syscon driver (FDT)
  */
-struct syscon_generic_softc {
-	device_t		dev;
-	struct syscon		*syscon;
-	struct resource		*mem_res;
-	struct mtx		mtx;
-};
-
 static struct ofw_compat_data compat_data[] = {
 	{"syscon",	1},
 	{NULL,		0}
 };
 
-#define SYSCON_LOCK(_sc)		mtx_lock(&(_sc)->mtx)
-#define	SYSCON_UNLOCK(_sc)		mtx_unlock(&(_sc)->mtx)
+#define SYSCON_LOCK(_sc)		mtx_lock_spin(&(_sc)->mtx)
+#define	SYSCON_UNLOCK(_sc)		mtx_unlock_spin(&(_sc)->mtx)
 #define SYSCON_LOCK_INIT(_sc)		mtx_init(&(_sc)->mtx,		\
-	    device_get_nameunit((_sc)->dev), "syscon", MTX_DEF)
+	    device_get_nameunit((_sc)->dev), "syscon", MTX_SPIN)
 #define SYSCON_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->mtx);
 #define SYSCON_ASSERT_LOCKED(_sc)	mtx_assert(&(_sc)->mtx, MA_OWNED);
 #define SYSCON_ASSERT_UNLOCKED(_sc)	mtx_assert(&(_sc)->mtx, MA_NOTOWNED);
@@ -156,8 +150,8 @@ syscon_generic_attach(device_t dev)
 
 	sc = device_get_softc(dev);
 	sc->dev = dev;
-
 	rid = 0;
+
 	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
 	    RF_ACTIVE);
 	if (sc->mem_res == NULL) {
@@ -181,7 +175,6 @@ syscon_generic_detach(device_t dev)
 	struct syscon_generic_softc *sc;
 
 	sc = device_get_softc(dev);
-
 	if (sc->syscon != NULL) {
 		syscon_unregister(sc->syscon);
 		free(sc->syscon, M_SYSCON);
@@ -206,11 +199,7 @@ static device_method_t syscon_generic_dmethods[] = {
 DEFINE_CLASS_0(syscon_generic, syscon_generic_driver, syscon_generic_dmethods,
     sizeof(struct syscon_generic_softc));
 static devclass_t syscon_generic_devclass;
-/*
- * syscon_generic needs to attach before other devices that may require it, such
- * as if_awg, but later than others to give way for more specialized syscon
- * implementations.
- */
+
 EARLY_DRIVER_MODULE(syscon_generic, simplebus, syscon_generic_driver,
-    syscon_generic_devclass, 0, 0, BUS_PASS_DEFAULT - 1000);
+    syscon_generic_devclass, 0, 0, BUS_PASS_DEFAULT);
 MODULE_VERSION(syscon_generic, 1);

Added: head/sys/dev/extres/syscon/syscon_generic.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/extres/syscon/syscon_generic.h	Sat Jan 13 18:46:31 2018	(r327936)
@@ -0,0 +1,40 @@
+/*-
+ * Copyright 2018 Kyle Evans <kevans at 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 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 DEV_SYSCON_GENERIC_H
+#define DEV_SYSCON_GENERIC_H
+
+struct syscon_generic_softc {
+	device_t		dev;
+	struct syscon		*syscon;
+	struct resource		*mem_res;
+	struct mtx		mtx;
+};
+
+DECLARE_CLASS(syscon_generic_driver);
+
+#endif /* DEV_SYSCON_GENERIC_H */


More information about the svn-src-head mailing list