aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/extres
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-01-13 18:46:31 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-01-13 18:46:31 +0000
commita9f41deff61826e70c0050f46c37badfe0ec65d3 (patch)
treeae45e6e236871de4dbd207644931c83430406063 /sys/dev/extres
parente50584405cfd426bc90d86984995d46bf2aa6ee4 (diff)
downloadsrc-a9f41deff61826e70c0050f46c37badfe0ec65d3.tar.gz
src-a9f41deff61826e70c0050f46c37badfe0ec65d3.zip
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
Notes
Notes: svn path=/head/; revision=327936
Diffstat (limited to 'sys/dev/extres')
-rw-r--r--sys/dev/extres/syscon/syscon_generic.c25
-rw-r--r--sys/dev/extres/syscon/syscon_generic.h40
2 files changed, 47 insertions, 18 deletions
diff --git a/sys/dev/extres/syscon/syscon_generic.c b/sys/dev/extres/syscon/syscon_generic.c
index db7bade12f04..cf019020169f 100644
--- a/sys/dev/extres/syscon/syscon_generic.c
+++ b/sys/dev/extres/syscon/syscon_generic.c
@@ -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 *syscon, bus_size_t offset,
/*
* 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);
diff --git a/sys/dev/extres/syscon/syscon_generic.h b/sys/dev/extres/syscon/syscon_generic.h
new file mode 100644
index 000000000000..b36bf5b06da4
--- /dev/null
+++ b/sys/dev/extres/syscon/syscon_generic.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright 2018 Kyle Evans <kevans@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 */