Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Now that the deferred configuration actually wo...



details:   https://anonhg.NetBSD.org/src/rev/1f02bd0f766d
branches:  trunk
changeset: 757154:1f02bd0f766d
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Mon Aug 16 17:58:42 2010 +0000

description:
Now that the deferred configuration actually works as expected and documented,
use config_defer(9) instead of config_finalize_register(9), and simplify the
code paths around the initialization.

diffstat:

 sys/dev/acpi/acpi_cpu.c        |  55 +++++++++++++++++++++++++++++------------
 sys/dev/acpi/acpi_cpu.h        |   8 +++---
 sys/dev/acpi/acpi_cpu_cstate.c |  26 +++++--------------
 sys/dev/acpi/acpi_cpu_pstate.c |  31 ++++++++++++----------
 sys/dev/acpi/acpi_cpu_tstate.c |   9 +++---
 5 files changed, 71 insertions(+), 58 deletions(-)

diffs (truncated from 314 to 300 lines):

diff -r 9e730b9bd735 -r 1f02bd0f766d sys/dev/acpi/acpi_cpu.c
--- a/sys/dev/acpi/acpi_cpu.c   Mon Aug 16 17:33:52 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu.c   Mon Aug 16 17:58:42 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.c,v 1.16 2010/08/14 11:16:14 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.c,v 1.17 2010/08/16 17:58:42 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 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.16 2010/08/14 11:16:14 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.17 2010/08/16 17:58:42 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -51,6 +51,7 @@
 static int               acpicpu_detach(device_t, int);
 static int               acpicpu_once_attach(void);
 static int               acpicpu_once_detach(void);
+static void              acpicpu_start(device_t);
 
 static int               acpicpu_object(ACPI_HANDLE, struct acpicpu_object *);
 static cpuid_t           acpicpu_id(uint32_t);
@@ -112,10 +113,8 @@
        if (rv != 0)
                return;
 
-       KASSERT(acpicpu_sc != NULL);
-
        sc->sc_dev = self;
-       sc->sc_cold = false;
+       sc->sc_cold = true;
        sc->sc_mapped = false;
        sc->sc_iot = aa->aa_iot;
        sc->sc_node = aa->aa_node;
@@ -159,15 +158,9 @@
        acpicpu_pstate_attach(self);
        acpicpu_tstate_attach(self);
 
-       (void)config_finalize_register(self, acpicpu_cstate_start);
-       (void)config_finalize_register(self, acpicpu_pstate_start);
-       (void)config_finalize_register(self, acpicpu_tstate_start);
-
+       (void)config_defer(self, acpicpu_start);
        (void)acpi_register_notify(sc->sc_node, acpicpu_notify);
        (void)pmf_device_register(self, acpicpu_suspend, acpicpu_resume);
-
-       aprint_debug_dev(sc->sc_dev, "cap 0x%02x, "
-           "flags 0x%06x\n", sc->sc_cap, sc->sc_flags);
 }
 
 static int
@@ -234,14 +227,44 @@
 {
        struct acpicpu_softc *sc;
 
-       KASSERT(acpicpu_sc != NULL);
-
-       kmem_free(acpicpu_sc, maxcpus * sizeof(*sc));
-       acpicpu_sc = NULL;
+       if (acpicpu_sc != NULL)
+               kmem_free(acpicpu_sc, maxcpus * sizeof(*sc));
 
        return 0;
 }
 
+static void
+acpicpu_start(device_t self)
+{
+       struct acpicpu_softc *sc = device_private(self);
+       static bool once = false;
+
+       if (once != false) {
+               sc->sc_cold = false;
+               return;
+       }
+
+       /*
+        * Run the state-specific initialization
+        * routines. These should be called only
+        * once, after all ACPI CPUs have attached.
+        */
+       if ((sc->sc_flags & ACPICPU_FLAG_C) != 0)
+               acpicpu_cstate_start(self);
+
+       if ((sc->sc_flags & ACPICPU_FLAG_P) != 0)
+               acpicpu_pstate_start(self);
+
+       if ((sc->sc_flags & ACPICPU_FLAG_T) != 0)
+               acpicpu_tstate_start(self);
+
+       aprint_debug_dev(sc->sc_dev, "ACPI CPUs started (cap "
+           "0x%02x, flags 0x%06x)\n", sc->sc_cap, sc->sc_flags);
+
+       once = true;
+       sc->sc_cold = false;
+}
+
 static int
 acpicpu_object(ACPI_HANDLE hdl, struct acpicpu_object *ao)
 {
diff -r 9e730b9bd735 -r 1f02bd0f766d sys/dev/acpi/acpi_cpu.h
--- a/sys/dev/acpi/acpi_cpu.h   Mon Aug 16 17:33:52 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu.h   Mon Aug 16 17:58:42 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.h,v 1.16 2010/08/16 07:38:38 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.h,v 1.17 2010/08/16 17:58:42 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -207,7 +207,7 @@
 
 void           acpicpu_cstate_attach(device_t);
 int            acpicpu_cstate_detach(device_t);
-int            acpicpu_cstate_start(device_t);
+void           acpicpu_cstate_start(device_t);
 bool           acpicpu_cstate_suspend(device_t);
 bool           acpicpu_cstate_resume(device_t);
 void           acpicpu_cstate_callback(void *);
@@ -215,7 +215,7 @@
 
 void           acpicpu_pstate_attach(device_t);
 int            acpicpu_pstate_detach(device_t);
-int            acpicpu_pstate_start(device_t);
+void           acpicpu_pstate_start(device_t);
 bool           acpicpu_pstate_suspend(device_t);
 bool           acpicpu_pstate_resume(device_t);
 void           acpicpu_pstate_callback(void *);
@@ -224,7 +224,7 @@
 
 void           acpicpu_tstate_attach(device_t);
 int            acpicpu_tstate_detach(device_t);
-int            acpicpu_tstate_start(device_t);
+void           acpicpu_tstate_start(device_t);
 bool           acpicpu_tstate_suspend(device_t);
 bool           acpicpu_tstate_resume(device_t);
 void           acpicpu_tstate_callback(void *);
diff -r 9e730b9bd735 -r 1f02bd0f766d sys/dev/acpi/acpi_cpu_cstate.c
--- a/sys/dev/acpi/acpi_cpu_cstate.c    Mon Aug 16 17:33:52 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu_cstate.c    Mon Aug 16 17:58:42 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_cstate.c,v 1.28 2010/08/15 08:53:19 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_cstate.c,v 1.29 2010/08/16 17:58:42 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.28 2010/08/15 08:53:19 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.29 2010/08/16 17:58:42 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -99,6 +99,8 @@
                break;
        }
 
+       sc->sc_flags |= ACPICPU_FLAG_C;
+
        acpicpu_cstate_quirks(sc);
        acpicpu_cstate_attach_evcnt(sc);
        acpicpu_cstate_attach_print(sc);
@@ -211,23 +213,11 @@
        }
 }
 
-int
+void
 acpicpu_cstate_start(device_t self)
 {
-       struct acpicpu_softc *sc = device_private(self);
-       static ONCE_DECL(once_start);
-       int rv;
 
-       /*
-        * Save the existing idle-mechanism and claim the cpu_idle(9).
-        * This should be called after all ACPI CPUs have been attached.
-        */
-       rv = RUN_ONCE(&once_start, acpicpu_md_idle_start);
-
-       if (rv == 0)
-               sc->sc_flags |= ACPICPU_FLAG_C;
-
-       return rv;
+       (void)acpicpu_md_idle_start();
 }
 
 bool
@@ -675,6 +665,7 @@
        KASSERT(acpicpu_sc != NULL);
        KASSERT(ci->ci_acpiid < maxcpus);
        KASSERT(ci->ci_ilevel == IPL_NONE);
+       KASSERT((sc->sc_flags & ACPICPU_FLAG_C) != 0);
 
        sc = acpicpu_sc[ci->ci_acpiid];
 
@@ -684,9 +675,6 @@
        if (__predict_false(sc->sc_cold != false))
                goto halt;
 
-       if (__predict_false((sc->sc_flags & ACPICPU_FLAG_C) == 0))
-               goto halt;
-
        if (__predict_false(mutex_tryenter(&sc->sc_mtx) == 0))
                goto halt;
 
diff -r 9e730b9bd735 -r 1f02bd0f766d sys/dev/acpi/acpi_cpu_pstate.c
--- a/sys/dev/acpi/acpi_cpu_pstate.c    Mon Aug 16 17:33:52 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu_pstate.c    Mon Aug 16 17:58:42 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_pstate.c,v 1.23 2010/08/16 10:23:25 jmcneill Exp $ */
+/* $NetBSD: acpi_cpu_pstate.c,v 1.24 2010/08/16 17:58:42 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.23 2010/08/16 10:23:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.24 2010/08/16 17:58:42 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/evcnt.h>
@@ -62,13 +62,6 @@
        const char *str;
        ACPI_STATUS rv;
 
-       /*
-        * The ACPI 3.0 and 4.0 specifications mandate three
-        * objects for P-states: _PSS, _PCT, and _PPC. A less
-        * strict wording is however used in the earlier 2.0
-        * standard, and some systems conforming to ACPI 2.0
-        * do not have _PPC, the method for dynamic maximum.
-        */
        rv = acpicpu_pstate_pss(sc);
 
        if (ACPI_FAILURE(rv)) {
@@ -102,6 +95,13 @@
                goto fail;
        }
 
+       /*
+        * The ACPI 3.0 and 4.0 specifications mandate three
+        * objects for P-states: _PSS, _PCT, and _PPC. A less
+        * strict wording is however used in the earlier 2.0
+        * standard, and some systems conforming to ACPI 2.0
+        * do not have _PPC, the method for dynamic maximum.
+        */
        (void)acpicpu_pstate_max(sc);
 
        sc->sc_flags |= ACPICPU_FLAG_P;
@@ -221,16 +221,19 @@
        }
 }
 
-int
+void
 acpicpu_pstate_start(device_t self)
 {
        struct acpicpu_softc *sc = device_private(self);
-       static ONCE_DECL(once_start);
+       int rv;
+
+       rv = acpicpu_md_pstate_start();
 
-       if ((sc->sc_flags & ACPICPU_FLAG_P) == 0)
-               return 0;
+       if (rv == 0)
+               return;
 
-       return RUN_ONCE(&once_start, acpicpu_md_pstate_start);
+       sc->sc_flags &= ~ACPICPU_FLAG_P;
+       aprint_error_dev(self, "failed to start P-states (err %d)\n", rv);
 }
 
 bool
diff -r 9e730b9bd735 -r 1f02bd0f766d sys/dev/acpi/acpi_cpu_tstate.c
--- a/sys/dev/acpi/acpi_cpu_tstate.c    Mon Aug 16 17:33:52 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu_tstate.c    Mon Aug 16 17:58:42 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_tstate.c,v 1.10 2010/08/16 04:31:21 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_tstate.c,v 1.11 2010/08/16 17:58:42 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_tstate.c,v 1.10 2010/08/16 04:31:21 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_tstate.c,v 1.11 2010/08/16 17:58:42 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/evcnt.h>



Home | Main Index | Thread Index | Old Index