Module Name: src
Committed By: jmcneill
Date: Mon Oct 28 21:14:58 UTC 2019
Modified Files:
src/sys/dev/fdt: cpufreq_dt.c fdtvar.h
Log Message:
Add support for platform specific opp table filters.
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/fdt/cpufreq_dt.c
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/fdt/fdtvar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/fdt/cpufreq_dt.c
diff -u src/sys/dev/fdt/cpufreq_dt.c:1.11 src/sys/dev/fdt/cpufreq_dt.c:1.12
--- src/sys/dev/fdt/cpufreq_dt.c:1.11 Mon Oct 28 10:43:08 2019
+++ src/sys/dev/fdt/cpufreq_dt.c Mon Oct 28 21:14:58 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.11 2019/10/28 10:43:08 jmcneill Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.12 2019/10/28 21:14:58 jmcneill Exp $ */
/*-
* Copyright (c) 2015-2017 Jared McNeill <[email protected]>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.11 2019/10/28 10:43:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.12 2019/10/28 21:14:58 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -356,11 +356,46 @@ cpufreq_dt_parse_opp(struct cpufreq_dt_s
return 0;
}
+static const struct fdt_opp_info *
+cpufreq_dt_lookup_opp_info(const int opp_table)
+{
+ __link_set_decl(fdt_opps, struct fdt_opp_info);
+ struct fdt_opp_info * const *opp;
+ const struct fdt_opp_info *best_opp = NULL;
+ int match, best_match = 0;
+
+ __link_set_foreach(opp, fdt_opps) {
+ const char * const compat[] = { (*opp)->opp_compat, NULL };
+ match = of_match_compatible(opp_table, compat);
+ if (match > best_match) {
+ best_match = match;
+ best_opp = *opp;
+ }
+ }
+
+ return best_opp;
+}
+
+static bool
+cpufreq_dt_node_supported(const struct fdt_opp_info *opp_info, const int opp_table, const int opp_node)
+{
+ if (!fdtbus_status_okay(opp_node))
+ return false;
+ if (of_hasprop(opp_node, "opp-suspend"))
+ return false;
+
+ if (opp_info != NULL)
+ return opp_info->opp_supported(opp_table, opp_node);
+
+ return true;
+}
+
static int
cpufreq_dt_parse_opp_v2(struct cpufreq_dt_softc *sc)
{
const int phandle = sc->sc_phandle;
struct cpufreq_dt_table *table;
+ const struct fdt_opp_info *opp_info;
const u_int *opp_uv;
uint64_t opp_hz;
int opp_node, len, i, index;
@@ -378,10 +413,10 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_d
TAILQ_INSERT_TAIL(&cpufreq_dt_tables, &sc->sc_table, next);
}
+ opp_info = cpufreq_dt_lookup_opp_info(opp_table);
+
for (opp_node = OF_child(opp_table); opp_node; opp_node = OF_peer(opp_node)) {
- if (!fdtbus_status_okay(opp_node))
- continue;
- if (of_hasprop(opp_node, "opp-suspend"))
+ if (!cpufreq_dt_node_supported(opp_info, opp_table, opp_node))
continue;
sc->sc_nopp++;
}
@@ -392,9 +427,7 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_d
sc->sc_opp = kmem_zalloc(sizeof(*sc->sc_opp) * sc->sc_nopp, KM_SLEEP);
index = sc->sc_nopp - 1;
for (opp_node = OF_child(opp_table), i = 0; opp_node; opp_node = OF_peer(opp_node), i++) {
- if (!fdtbus_status_okay(opp_node))
- continue;
- if (of_hasprop(opp_node, "opp-suspend"))
+ if (!cpufreq_dt_node_supported(opp_info, opp_table, opp_node))
continue;
if (of_getprop_uint64(opp_node, "opp-hz", &opp_hz) != 0)
return EINVAL;
Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.54 src/sys/dev/fdt/fdtvar.h:1.55
--- src/sys/dev/fdt/fdtvar.h:1.54 Tue Oct 1 23:32:52 2019
+++ src/sys/dev/fdt/fdtvar.h Mon Oct 28 21:14:58 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.54 2019/10/01 23:32:52 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.55 2019/10/28 21:14:58 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -251,6 +251,21 @@ static const struct fdt_console_info __C
}; \
_FDT_CONSOLE_REGISTER(_name)
+struct fdt_opp_info {
+ const char * opp_compat;
+ bool (*opp_supported)(const int, const int);
+};
+
+#define _FDT_OPP_REGISTER(name) \
+ __link_set_add_rodata(fdt_opps, __CONCAT(name,_oppinfo));
+
+#define FDT_OPP(_name, _compat, _suppfn) \
+static const struct fdt_opp_info __CONCAT(_name,_oppinfo) = { \
+ .opp_compat = (_compat), \
+ .opp_supported = (_suppfn) \
+}; \
+_FDT_OPP_REGISTER(_name)
+
TAILQ_HEAD(fdt_conslist, fdt_console_info);
int fdtbus_register_interrupt_controller(device_t, int,