Module Name: src Committed By: jruoho Date: Mon Aug 16 17:58:42 UTC 2010
Modified Files: src/sys/dev/acpi: acpi_cpu.c acpi_cpu.h acpi_cpu_cstate.c acpi_cpu_pstate.c acpi_cpu_tstate.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/acpi/acpi_cpu.c \ src/sys/dev/acpi/acpi_cpu.h cvs rdiff -u -r1.28 -r1.29 src/sys/dev/acpi/acpi_cpu_cstate.c cvs rdiff -u -r1.23 -r1.24 src/sys/dev/acpi/acpi_cpu_pstate.c cvs rdiff -u -r1.10 -r1.11 src/sys/dev/acpi/acpi_cpu_tstate.c 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/acpi/acpi_cpu.c diff -u src/sys/dev/acpi/acpi_cpu.c:1.16 src/sys/dev/acpi/acpi_cpu.c:1.17 --- src/sys/dev/acpi/acpi_cpu.c:1.16 Sat Aug 14 11:16:14 2010 +++ src/sys/dev/acpi/acpi_cpu.c Mon Aug 16 17:58:42 2010 @@ -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 <jruoho...@iki.fi> @@ -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) { Index: src/sys/dev/acpi/acpi_cpu.h diff -u src/sys/dev/acpi/acpi_cpu.h:1.16 src/sys/dev/acpi/acpi_cpu.h:1.17 --- src/sys/dev/acpi/acpi_cpu.h:1.16 Mon Aug 16 07:38:38 2010 +++ src/sys/dev/acpi/acpi_cpu.h Mon Aug 16 17:58:42 2010 @@ -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 <jruoho...@iki.fi> @@ -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 *); Index: src/sys/dev/acpi/acpi_cpu_cstate.c diff -u src/sys/dev/acpi/acpi_cpu_cstate.c:1.28 src/sys/dev/acpi/acpi_cpu_cstate.c:1.29 --- src/sys/dev/acpi/acpi_cpu_cstate.c:1.28 Sun Aug 15 08:53:19 2010 +++ src/sys/dev/acpi/acpi_cpu_cstate.c Mon Aug 16 17:58:42 2010 @@ -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 <jruoho...@iki.fi> @@ -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; Index: src/sys/dev/acpi/acpi_cpu_pstate.c diff -u src/sys/dev/acpi/acpi_cpu_pstate.c:1.23 src/sys/dev/acpi/acpi_cpu_pstate.c:1.24 --- src/sys/dev/acpi/acpi_cpu_pstate.c:1.23 Mon Aug 16 10:23:25 2010 +++ src/sys/dev/acpi/acpi_cpu_pstate.c Mon Aug 16 17:58:42 2010 @@ -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 <jruoho...@iki.fi> @@ -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; - if ((sc->sc_flags & ACPICPU_FLAG_P) == 0) - return 0; + rv = acpicpu_md_pstate_start(); - return RUN_ONCE(&once_start, acpicpu_md_pstate_start); + if (rv == 0) + return; + + sc->sc_flags &= ~ACPICPU_FLAG_P; + aprint_error_dev(self, "failed to start P-states (err %d)\n", rv); } bool Index: src/sys/dev/acpi/acpi_cpu_tstate.c diff -u src/sys/dev/acpi/acpi_cpu_tstate.c:1.10 src/sys/dev/acpi/acpi_cpu_tstate.c:1.11 --- src/sys/dev/acpi/acpi_cpu_tstate.c:1.10 Mon Aug 16 04:31:21 2010 +++ src/sys/dev/acpi/acpi_cpu_tstate.c Mon Aug 16 17:58:42 2010 @@ -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 <jruoho...@iki.fi> @@ -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> @@ -190,11 +190,10 @@ } } -int +void acpicpu_tstate_start(device_t self) { - - return 0; + /* Nothing. */ } bool