Source-Changes-HG archive

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

[src/trunk]: src/sys Convert to use cpufreq(9).



details:   https://anonhg.NetBSD.org/src/rev/658a88cee9b5
branches:  trunk
changeset: 770465:658a88cee9b5
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Tue Oct 18 05:08:24 2011 +0000

description:
Convert to use cpufreq(9).

diffstat:

 sys/arch/x86/acpi/acpi_cpu_md.c |   26 +++--
 sys/dev/acpi/acpi_cpu.c         |   63 +++++++++++-
 sys/dev/acpi/acpi_cpu.h         |    7 +-
 sys/dev/acpi/acpi_cpu_pstate.c  |  186 ++++++++++-----------------------------
 4 files changed, 121 insertions(+), 161 deletions(-)

diffs (truncated from 632 to 300 lines):

diff -r ec3c5efb57ed -r 658a88cee9b5 sys/arch/x86/acpi/acpi_cpu_md.c
--- a/sys/arch/x86/acpi/acpi_cpu_md.c   Tue Oct 18 04:51:01 2011 +0000
+++ b/sys/arch/x86/acpi/acpi_cpu_md.c   Tue Oct 18 05:08:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_md.c,v 1.67 2011/09/24 19:41:40 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_md.c,v 1.68 2011/10/18 05:08:24 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,10 +27,11 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.67 2011/09/24 19:41:40 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.68 2011/10/18 05:08:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
+#include <sys/cpufreq.h>
 #include <sys/device.h>
 #include <sys/kcore.h>
 #include <sys/sysctl.h>
@@ -749,7 +750,7 @@
 
        /*
         * Pick any P-state for the status address.
-       */
+        */
        for (i = 0; i < sc->sc_pstate_count; i++) {
 
                ps = &sc->sc_pstate[i];
@@ -791,6 +792,9 @@
         */
        if ((sc->sc_flags & ACPICPU_FLAG_P_HWF) != 0) {
 
+               KASSERT(sc->sc_pstate_count > 0);
+               KASSERT(sc->sc_pstate[0].ps_freq != 0);
+
                if (acpicpu_md_pstate_hwf(sc->sc_ci) == 100) {
                        *freq = sc->sc_pstate[0].ps_freq;
                        return 0;
@@ -1136,15 +1140,14 @@
 static int
 acpicpu_md_pstate_sysctl_get(SYSCTLFN_ARGS)
 {
-       struct cpu_info *ci = curcpu();
        struct sysctlnode node;
        uint32_t freq;
        int err;
 
-       err = acpicpu_pstate_get(ci, &freq);
+       freq = cpufreq_get(curcpu());
 
-       if (err != 0)
-               return err;
+       if (freq == 0)
+               return ENXIO;
 
        node = *rnode;
        node.sysctl_data = &freq;
@@ -1160,15 +1163,14 @@
 static int
 acpicpu_md_pstate_sysctl_set(SYSCTLFN_ARGS)
 {
-       struct cpu_info *ci = curcpu();
        struct sysctlnode node;
        uint32_t freq;
        int err;
 
-       err = acpicpu_pstate_get(ci, &freq);
+       freq = cpufreq_get(curcpu());
 
-       if (err != 0)
-               return err;
+       if (freq == 0)
+               return ENXIO;
 
        node = *rnode;
        node.sysctl_data = &freq;
@@ -1178,7 +1180,7 @@
        if (err != 0 || newp == NULL)
                return err;
 
-       acpicpu_pstate_set(ci, freq);
+       cpufreq_set_all(freq);
 
        return 0;
 }
diff -r ec3c5efb57ed -r 658a88cee9b5 sys/dev/acpi/acpi_cpu.c
--- a/sys/dev/acpi/acpi_cpu.c   Tue Oct 18 04:51:01 2011 +0000
+++ b/sys/dev/acpi/acpi_cpu.c   Tue Oct 18 05:08:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.c,v 1.44 2011/06/22 08:49:54 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.c,v 1.45 2011/10/18 05:08:24 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.44 2011/06/22 08:49:54 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.45 2011/10/18 05:08:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -37,6 +37,7 @@
 #include <sys/module.h>
 #include <sys/mutex.h>
 #include <sys/sysctl.h>
+#include <sys/cpufreq.h>
 
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
@@ -66,7 +67,8 @@
 static void              acpicpu_evcnt_attach(device_t);
 static void              acpicpu_evcnt_detach(device_t);
 static void              acpicpu_debug_print(device_t);
-static const char       *acpicpu_debug_print_method(uint8_t);
+static const char       *acpicpu_debug_print_method_c(uint8_t);
+static const char       *acpicpu_debug_print_method_pt(uint8_t);
 static const char       *acpicpu_debug_print_dep(uint32_t);
 
 static uint32_t                  acpicpu_count = 0;
@@ -247,6 +249,7 @@
 static int
 acpicpu_once_detach(void)
 {
+       struct cpu_info *ci = curcpu();
        struct acpicpu_softc *sc;
 
        if (acpicpu_count != 0)
@@ -255,8 +258,15 @@
        if (acpicpu_log != NULL)
                sysctl_teardown(&acpicpu_log);
 
-       if (acpicpu_sc != NULL)
+       if (acpicpu_sc != NULL) {
+
+               sc = acpicpu_sc[ci->ci_acpiid];
+
+               if ((sc->sc_flags & ACPICPU_FLAG_P) != 0)
+                       cpufreq_deregister();
+
                kmem_free(acpicpu_sc, maxcpus * sizeof(*sc));
+       }
 
        return 0;
 }
@@ -266,6 +276,8 @@
 {
        struct acpicpu_softc *sc = device_private(self);
        static uint32_t count = 0;
+       struct cpufreq cf;
+       uint32_t i;
 
        /*
         * Run the state-specific initialization routines. These
@@ -294,6 +306,34 @@
 
        acpicpu_sysctl(self);
        aprint_debug_dev(self, "ACPI CPUs started\n");
+
+       /*
+        * Register with cpufreq(9).
+        */
+       if ((sc->sc_flags & ACPICPU_FLAG_P) != 0) {
+
+               (void)memset(&cf, 0, sizeof(struct cpufreq));
+
+               cf.cf_mp = false;
+               cf.cf_cookie = NULL;
+               cf.cf_get_freq = acpicpu_pstate_get;
+               cf.cf_set_freq = acpicpu_pstate_set;
+               cf.cf_state_count = sc->sc_pstate_count;
+
+               (void)strlcpy(cf.cf_name, "acpicpu", sizeof(cf.cf_name));
+
+               for (i = 0; i < sc->sc_pstate_count; i++) {
+
+                       if (sc->sc_pstate[i].ps_freq == 0)
+                               continue;
+
+                       cf.cf_state[i].cfs_freq = sc->sc_pstate[i].ps_freq;
+                       cf.cf_state[i].cfs_power = sc->sc_pstate[i].ps_power;
+               }
+
+               if (cpufreq_register(&cf) != 0)
+                       aprint_error_dev(self, "failed to register cpufreq\n");
+       }
 }
 
 static void
@@ -726,7 +766,7 @@
 
                        aprint_verbose_dev(sc->sc_dev, "C%d: %3s, "
                            "lat %3u us, pow %5u mW%s\n", i,
-                           acpicpu_debug_print_method(cs->cs_method),
+                           acpicpu_debug_print_method_c(cs->cs_method),
                            cs->cs_latency, cs->cs_power,
                            (cs->cs_flags != 0) ? ", bus master check" : "");
                }
@@ -742,7 +782,7 @@
 
                        aprint_verbose_dev(sc->sc_dev, "P%d: %3s, "
                            "lat %3u us, pow %5u mW, %4u MHz%s\n", i,
-                           acpicpu_debug_print_method(method),
+                           acpicpu_debug_print_method_pt(method),
                            ps->ps_latency, ps->ps_power, ps->ps_freq,
                            (ps->ps_flags & ACPICPU_FLAG_P_TURBO) != 0 ?
                            ", turbo boost" : "");
@@ -759,7 +799,7 @@
 
                        aprint_verbose_dev(sc->sc_dev, "T%u: %3s, "
                            "lat %3u us, pow %5u mW, %3u %%\n", i,
-                           acpicpu_debug_print_method(method),
+                           acpicpu_debug_print_method_pt(method),
                            ts->ts_latency, ts->ts_power, ts->ts_percent);
                }
 
@@ -799,7 +839,7 @@
 }
 
 static const char *
-acpicpu_debug_print_method(uint8_t val)
+acpicpu_debug_print_method_c(uint8_t val)
 {
 
        if (val == ACPICPU_C_STATE_FFH)
@@ -811,6 +851,13 @@
        if (val == ACPICPU_C_STATE_SYSIO)
                return "I/O";
 
+       return "???";
+}
+
+static const char *
+acpicpu_debug_print_method_pt(uint8_t val)
+{
+
        if (val == ACPI_ADR_SPACE_SYSTEM_IO)
                return "I/O";
 
diff -r ec3c5efb57ed -r 658a88cee9b5 sys/dev/acpi/acpi_cpu.h
--- a/sys/dev/acpi/acpi_cpu.h   Tue Oct 18 04:51:01 2011 +0000
+++ b/sys/dev/acpi/acpi_cpu.h   Tue Oct 18 05:08:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.h,v 1.42 2011/06/22 08:49:54 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.h,v 1.43 2011/10/18 05:08:24 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -84,7 +84,6 @@
  */
 #define ACPICPU_P_STATE_MAX     255            /* Arbitrary upper limit     */
 #define ACPICPU_P_STATE_RETRY   100
-#define ACPICPU_P_STATE_UNKNOWN         0x0
 
 /*
  * T-states.
@@ -245,8 +244,8 @@
 void            acpicpu_pstate_suspend(void *);
 void            acpicpu_pstate_resume(void *);
 void            acpicpu_pstate_callback(void *);
-int             acpicpu_pstate_get(struct cpu_info *, uint32_t *);
-void            acpicpu_pstate_set(struct cpu_info *, uint32_t);
+void            acpicpu_pstate_get(void *, void *);
+void            acpicpu_pstate_set(void *, void *);
 
 void            acpicpu_tstate_attach(device_t);
 void            acpicpu_tstate_detach(device_t);
diff -r ec3c5efb57ed -r 658a88cee9b5 sys/dev/acpi/acpi_cpu_pstate.c
--- a/sys/dev/acpi/acpi_cpu_pstate.c    Tue Oct 18 04:51:01 2011 +0000
+++ b/sys/dev/acpi/acpi_cpu_pstate.c    Tue Oct 18 05:08:24 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_pstate.c,v 1.51 2011/06/22 08:49:54 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_pstate.c,v 1.52 2011/10/18 05:08:24 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,11 +27,11 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.51 2011/06/22 08:49:54 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.52 2011/10/18 05:08:24 jruoho Exp $");
 
 #include <sys/param.h>
+#include <sys/cpufreq.h>
 #include <sys/kmem.h>
-#include <sys/xcall.h>
 
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
@@ -53,7 +53,6 @@
 static void             acpicpu_pstate_change(struct acpicpu_softc *);
 static void             acpicpu_pstate_reset(struct acpicpu_softc *);
 static void             acpicpu_pstate_bios(void);
-static void             acpicpu_pstate_set_xcall(void *, void *);
 



Home | Main Index | Thread Index | Old Index