Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/fdt Add support for platform specific opp table filt...



details:   https://anonhg.NetBSD.org/src/rev/dc0b7eca4179
branches:  trunk
changeset: 460614:dc0b7eca4179
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Oct 28 21:14:58 2019 +0000

description:
Add support for platform specific opp table filters.

diffstat:

 sys/dev/fdt/cpufreq_dt.c |  49 ++++++++++++++++++++++++++++++++++++++++-------
 sys/dev/fdt/fdtvar.h     |  17 +++++++++++++++-
 2 files changed, 57 insertions(+), 9 deletions(-)

diffs (121 lines):

diff -r c36ae3e7f56b -r dc0b7eca4179 sys/dev/fdt/cpufreq_dt.c
--- a/sys/dev/fdt/cpufreq_dt.c  Mon Oct 28 21:13:48 2019 +0000
+++ b/sys/dev/fdt/cpufreq_dt.c  Mon Oct 28 21:14:58 2019 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
        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 @@
                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 @@
        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;
diff -r c36ae3e7f56b -r dc0b7eca4179 sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h      Mon Oct 28 21:13:48 2019 +0000
+++ b/sys/dev/fdt/fdtvar.h      Mon Oct 28 21:14:58 2019 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -251,6 +251,21 @@
 };                                                                     \
 _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,



Home | Main Index | Thread Index | Old Index