2000-10-28 06:59:48 +00:00
|
|
|
/*-
|
2001-06-28 06:17:16 +00:00
|
|
|
* Copyright (c) 2000, 2001 Michael Smith
|
2000-10-28 06:59:48 +00:00
|
|
|
* Copyright (c) 2000 BSDi
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#include "opt_acpi.h"
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-08-13 06:22:17 +00:00
|
|
|
#include <sys/bus.h>
|
2005-07-18 20:12:23 +00:00
|
|
|
#include <sys/cpu.h>
|
2002-02-23 05:29:23 +00:00
|
|
|
#include <sys/kthread.h>
|
2004-08-13 06:22:17 +00:00
|
|
|
#include <sys/malloc.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2002-02-23 05:29:23 +00:00
|
|
|
#include <sys/proc.h>
|
2004-05-06 02:57:24 +00:00
|
|
|
#include <sys/reboot.h>
|
2001-07-05 07:19:17 +00:00
|
|
|
#include <sys/sysctl.h>
|
2002-02-23 05:29:23 +00:00
|
|
|
#include <sys/unistd.h>
|
2002-03-04 18:46:13 +00:00
|
|
|
#include <sys/power.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2005-07-18 20:12:23 +00:00
|
|
|
#include "cpufreq_if.h"
|
|
|
|
|
2009-06-05 18:44:36 +00:00
|
|
|
#include <contrib/dev/acpica/include/acpi.h>
|
|
|
|
#include <contrib/dev/acpica/include/accommon.h>
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Hooks for the ACPI CA debugging infrastructure */
|
2001-06-29 21:20:46 +00:00
|
|
|
#define _COMPONENT ACPI_THERMAL
|
2002-02-23 05:29:23 +00:00
|
|
|
ACPI_MODULE_NAME("THERMAL")
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2001-01-31 09:33:51 +00:00
|
|
|
#define TZ_ZEROC 2732
|
2006-07-25 02:27:38 +00:00
|
|
|
#define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), abs(((x) - TZ_ZEROC) % 10)
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2004-02-03 04:18:56 +00:00
|
|
|
#define TZ_NOTIFY_TEMPERATURE 0x80 /* Temperature changed. */
|
|
|
|
#define TZ_NOTIFY_LEVELS 0x81 /* Cooling levels changed. */
|
|
|
|
#define TZ_NOTIFY_DEVICES 0x82 /* Device lists changed. */
|
|
|
|
#define TZ_NOTIFY_CRITICAL 0xcc /* Fake notify that _CRT/_HOT reached. */
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2004-02-02 18:03:35 +00:00
|
|
|
/* Check for temperature changes every 10 seconds by default */
|
|
|
|
#define TZ_POLLRATE 10
|
|
|
|
|
|
|
|
/* Make sure the reported temperature is valid for this number of polls. */
|
|
|
|
#define TZ_VALIDCHECKS 3
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2004-02-03 04:18:56 +00:00
|
|
|
/* Notify the user we will be shutting down in one more poll cycle. */
|
|
|
|
#define TZ_NOTIFYCOUNT (TZ_VALIDCHECKS - 1)
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* ACPI spec defines this */
|
|
|
|
#define TZ_NUMLEVELS 10
|
2001-07-07 01:49:15 +00:00
|
|
|
struct acpi_tz_zone {
|
2001-06-28 06:17:16 +00:00
|
|
|
int ac[TZ_NUMLEVELS];
|
|
|
|
ACPI_BUFFER al[TZ_NUMLEVELS];
|
|
|
|
int crt;
|
|
|
|
int hot;
|
|
|
|
ACPI_BUFFER psl;
|
|
|
|
int psv;
|
|
|
|
int tc1;
|
|
|
|
int tc2;
|
|
|
|
int tsp;
|
|
|
|
int tzp;
|
|
|
|
};
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
struct acpi_tz_softc {
|
2003-08-28 16:06:30 +00:00
|
|
|
device_t tz_dev;
|
|
|
|
ACPI_HANDLE tz_handle; /*Thermal zone handle*/
|
|
|
|
int tz_temperature; /*Current temperature*/
|
|
|
|
int tz_active; /*Current active cooling*/
|
2001-07-07 01:49:15 +00:00
|
|
|
#define TZ_ACTIVE_NONE -1
|
2008-04-25 16:45:13 +00:00
|
|
|
#define TZ_ACTIVE_UNKNOWN -2
|
2003-08-28 16:06:30 +00:00
|
|
|
int tz_requested; /*Minimum active cooling*/
|
|
|
|
int tz_thflags; /*Current temp-related flags*/
|
2001-07-07 01:49:15 +00:00
|
|
|
#define TZ_THFLAG_NONE 0
|
|
|
|
#define TZ_THFLAG_PSV (1<<0)
|
|
|
|
#define TZ_THFLAG_HOT (1<<2)
|
2005-07-18 20:12:23 +00:00
|
|
|
#define TZ_THFLAG_CRT (1<<3)
|
2001-07-05 07:19:17 +00:00
|
|
|
int tz_flags;
|
2003-08-28 16:06:30 +00:00
|
|
|
#define TZ_FLAG_NO_SCP (1<<0) /*No _SCP method*/
|
|
|
|
#define TZ_FLAG_GETPROFILE (1<<1) /*Get power_profile in timeout*/
|
2004-08-13 06:22:17 +00:00
|
|
|
#define TZ_FLAG_GETSETTINGS (1<<2) /*Get devs/setpoints*/
|
2003-08-28 16:06:30 +00:00
|
|
|
struct timespec tz_cooling_started;
|
|
|
|
/*Current cooling starting time*/
|
2001-07-05 07:19:17 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
struct sysctl_ctx_list tz_sysctl_ctx;
|
2001-07-05 07:19:17 +00:00
|
|
|
struct sysctl_oid *tz_sysctl_tree;
|
2004-08-13 06:22:17 +00:00
|
|
|
eventhandler_tag tz_event;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
struct acpi_tz_zone tz_zone; /*Thermal zone parameters*/
|
2004-02-02 18:03:35 +00:00
|
|
|
int tz_validchecks;
|
2013-08-30 19:21:12 +00:00
|
|
|
int tz_insane_tmp_notified;
|
2005-07-18 20:12:23 +00:00
|
|
|
|
|
|
|
/* passive cooling */
|
|
|
|
struct proc *tz_cooling_proc;
|
2005-08-04 18:34:26 +00:00
|
|
|
int tz_cooling_proc_running;
|
2005-07-18 20:12:23 +00:00
|
|
|
int tz_cooling_enabled;
|
|
|
|
int tz_cooling_active;
|
|
|
|
int tz_cooling_updated;
|
2005-08-17 17:01:25 +00:00
|
|
|
int tz_cooling_saved_freq;
|
2000-10-28 06:59:48 +00:00
|
|
|
};
|
|
|
|
|
2012-10-14 09:32:38 +00:00
|
|
|
#define TZ_ACTIVE_LEVEL(act) ((act) >= 0 ? (act) : TZ_NUMLEVELS)
|
|
|
|
|
2005-07-18 20:12:23 +00:00
|
|
|
#define CPUFREQ_MAX_LEVELS 64 /* XXX cpufreq should export this */
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static int acpi_tz_probe(device_t dev);
|
|
|
|
static int acpi_tz_attach(device_t dev);
|
2001-06-28 06:17:16 +00:00
|
|
|
static int acpi_tz_establish(struct acpi_tz_softc *sc);
|
2003-08-28 16:06:30 +00:00
|
|
|
static void acpi_tz_monitor(void *Context);
|
2001-06-28 06:17:16 +00:00
|
|
|
static void acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg);
|
|
|
|
static void acpi_tz_switch_cooler_on(ACPI_OBJECT *obj, void *arg);
|
2003-08-28 16:06:30 +00:00
|
|
|
static void acpi_tz_getparam(struct acpi_tz_softc *sc, char *node,
|
|
|
|
int *data);
|
2001-07-05 07:19:17 +00:00
|
|
|
static void acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what);
|
2001-07-07 01:49:15 +00:00
|
|
|
static int acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS);
|
2005-07-18 20:12:23 +00:00
|
|
|
static int acpi_tz_cooling_sysctl(SYSCTL_HANDLER_ARGS);
|
2006-07-25 02:27:38 +00:00
|
|
|
static int acpi_tz_temp_sysctl(SYSCTL_HANDLER_ARGS);
|
2007-12-24 16:32:14 +00:00
|
|
|
static int acpi_tz_passive_sysctl(SYSCTL_HANDLER_ARGS);
|
2003-08-28 16:06:30 +00:00
|
|
|
static void acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify,
|
|
|
|
void *context);
|
2004-08-13 06:22:17 +00:00
|
|
|
static void acpi_tz_signal(struct acpi_tz_softc *sc, int flags);
|
|
|
|
static void acpi_tz_timeout(struct acpi_tz_softc *sc, int flags);
|
2002-03-04 18:46:13 +00:00
|
|
|
static void acpi_tz_power_profile(void *arg);
|
2002-02-23 05:29:23 +00:00
|
|
|
static void acpi_tz_thread(void *arg);
|
2005-07-18 20:12:23 +00:00
|
|
|
static int acpi_tz_cooling_is_available(struct acpi_tz_softc *sc);
|
|
|
|
static int acpi_tz_cooling_thread_start(struct acpi_tz_softc *sc);
|
2002-02-23 05:29:23 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static device_method_t acpi_tz_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, acpi_tz_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_tz_attach),
|
|
|
|
|
2013-01-30 18:01:20 +00:00
|
|
|
DEVMETHOD_END
|
2000-10-28 06:59:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_tz_driver = {
|
|
|
|
"acpi_tz",
|
|
|
|
acpi_tz_methods,
|
|
|
|
sizeof(struct acpi_tz_softc),
|
|
|
|
};
|
|
|
|
|
2013-08-30 19:21:12 +00:00
|
|
|
static char *acpi_tz_tmp_name = "_TMP";
|
|
|
|
|
2002-01-08 06:46:01 +00:00
|
|
|
static devclass_t acpi_tz_devclass;
|
2000-10-28 06:59:48 +00:00
|
|
|
DRIVER_MODULE(acpi_tz, acpi, acpi_tz_driver, acpi_tz_devclass, 0, 0);
|
2004-04-09 18:14:32 +00:00
|
|
|
MODULE_DEPEND(acpi_tz, acpi, 1, 1, 1);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-07-05 07:19:17 +00:00
|
|
|
static struct sysctl_ctx_list acpi_tz_sysctl_ctx;
|
|
|
|
static struct sysctl_oid *acpi_tz_sysctl_tree;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Minimum cooling run time */
|
2006-07-25 02:27:38 +00:00
|
|
|
static int acpi_tz_min_runtime;
|
2001-12-22 16:05:41 +00:00
|
|
|
static int acpi_tz_polling_rate = TZ_POLLRATE;
|
2006-07-25 02:27:38 +00:00
|
|
|
static int acpi_tz_override;
|
2001-10-29 18:09:43 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Timezone polling thread */
|
|
|
|
static struct proc *acpi_tz_proc;
|
2004-08-13 06:22:17 +00:00
|
|
|
ACPI_LOCK_DECL(thermal, "ACPI thermal zone");
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2008-02-16 07:15:34 +00:00
|
|
|
static int acpi_tz_cooling_unit = -1;
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static int
|
|
|
|
acpi_tz_probe(device_t dev)
|
|
|
|
{
|
2001-06-29 21:20:46 +00:00
|
|
|
int result;
|
2005-07-18 20:12:23 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (acpi_get_type(dev) == ACPI_TYPE_THERMAL && !acpi_disabled("thermal")) {
|
2003-09-26 05:24:55 +00:00
|
|
|
device_set_desc(dev, "Thermal Zone");
|
2001-06-29 21:20:46 +00:00
|
|
|
result = -10;
|
2004-08-13 06:22:17 +00:00
|
|
|
} else
|
2001-06-29 21:20:46 +00:00
|
|
|
result = ENXIO;
|
2003-08-28 16:06:30 +00:00
|
|
|
return (result);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2000-12-22 14:41:55 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static int
|
|
|
|
acpi_tz_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_tz_softc *sc;
|
2001-07-05 07:19:17 +00:00
|
|
|
struct acpi_softc *acpi_sc;
|
2001-06-28 06:17:16 +00:00
|
|
|
int error;
|
2001-07-05 07:19:17 +00:00
|
|
|
char oidname[8];
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
sc->tz_dev = dev;
|
|
|
|
sc->tz_handle = acpi_get_handle(dev);
|
2001-07-07 01:49:15 +00:00
|
|
|
sc->tz_requested = TZ_ACTIVE_NONE;
|
2008-04-25 16:45:13 +00:00
|
|
|
sc->tz_active = TZ_ACTIVE_UNKNOWN;
|
2004-09-21 18:39:10 +00:00
|
|
|
sc->tz_thflags = TZ_THFLAG_NONE;
|
2005-07-18 20:12:23 +00:00
|
|
|
sc->tz_cooling_proc = NULL;
|
2005-08-04 18:34:26 +00:00
|
|
|
sc->tz_cooling_proc_running = FALSE;
|
2005-07-18 20:12:23 +00:00
|
|
|
sc->tz_cooling_active = FALSE;
|
|
|
|
sc->tz_cooling_updated = FALSE;
|
2008-02-16 07:15:34 +00:00
|
|
|
sc->tz_cooling_enabled = FALSE;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Parse the current state of the thermal zone and build control
|
2004-08-13 06:22:17 +00:00
|
|
|
* structures. We don't need to worry about interference with the
|
|
|
|
* control thread since we haven't fully attached this device yet.
|
2001-06-28 06:17:16 +00:00
|
|
|
*/
|
|
|
|
if ((error = acpi_tz_establish(sc)) != 0)
|
2004-08-13 06:22:17 +00:00
|
|
|
return (error);
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Register for any Notify events sent to this zone.
|
|
|
|
*/
|
2005-07-18 20:12:23 +00:00
|
|
|
AcpiInstallNotifyHandler(sc->tz_handle, ACPI_DEVICE_NOTIFY,
|
2001-06-29 21:20:46 +00:00
|
|
|
acpi_tz_notify_handler, sc);
|
2000-12-22 14:41:55 +00:00
|
|
|
|
2001-07-05 07:19:17 +00:00
|
|
|
/*
|
|
|
|
* Create our sysctl nodes.
|
|
|
|
*
|
|
|
|
* XXX we need a mechanism for adding nodes under ACPI.
|
|
|
|
*/
|
|
|
|
if (device_get_unit(dev) == 0) {
|
|
|
|
acpi_sc = acpi_device_get_parent_softc(dev);
|
|
|
|
sysctl_ctx_init(&acpi_tz_sysctl_ctx);
|
|
|
|
acpi_tz_sysctl_tree = SYSCTL_ADD_NODE(&acpi_tz_sysctl_ctx,
|
2003-08-28 16:06:30 +00:00
|
|
|
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "thermal", CTLFLAG_RD, 0, "");
|
2001-10-29 18:09:43 +00:00
|
|
|
SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
|
2006-06-10 08:04:38 +00:00
|
|
|
OID_AUTO, "min_runtime", CTLFLAG_RW,
|
2003-08-28 16:06:30 +00:00
|
|
|
&acpi_tz_min_runtime, 0,
|
|
|
|
"minimum cooling run time in sec");
|
2001-12-22 16:05:41 +00:00
|
|
|
SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
|
2006-06-10 08:04:38 +00:00
|
|
|
OID_AUTO, "polling_rate", CTLFLAG_RW,
|
2011-11-17 23:04:43 +00:00
|
|
|
&acpi_tz_polling_rate, 0, "monitor polling interval in seconds");
|
2006-07-25 02:27:38 +00:00
|
|
|
SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_tz_sysctl_tree), OID_AUTO,
|
|
|
|
"user_override", CTLFLAG_RW, &acpi_tz_override, 0,
|
|
|
|
"allow override of thermal settings");
|
2001-07-05 07:19:17 +00:00
|
|
|
}
|
|
|
|
sysctl_ctx_init(&sc->tz_sysctl_ctx);
|
|
|
|
sprintf(oidname, "tz%d", device_get_unit(dev));
|
|
|
|
sc->tz_sysctl_tree = SYSCTL_ADD_NODE(&sc->tz_sysctl_ctx,
|
2003-08-28 16:06:30 +00:00
|
|
|
SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
|
|
|
|
OID_AUTO, oidname, CTLFLAG_RD, 0, "");
|
2011-04-18 19:02:41 +00:00
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD,
|
|
|
|
&sc->tz_temperature, 0, sysctl_handle_int,
|
|
|
|
"IK", "current thermal zone temperature");
|
2001-07-07 01:49:15 +00:00
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "active", CTLTYPE_INT | CTLFLAG_RW,
|
2006-07-25 02:27:38 +00:00
|
|
|
sc, 0, acpi_tz_active_sysctl, "I", "cooling is active");
|
2005-07-18 20:12:23 +00:00
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "passive_cooling", CTLTYPE_INT | CTLFLAG_RW,
|
2006-07-25 02:27:38 +00:00
|
|
|
sc, 0, acpi_tz_cooling_sysctl, "I",
|
|
|
|
"enable passive (speed reduction) cooling");
|
2005-07-18 20:12:23 +00:00
|
|
|
|
2001-07-05 07:19:17 +00:00
|
|
|
SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
2001-07-07 01:49:15 +00:00
|
|
|
OID_AUTO, "thermal_flags", CTLFLAG_RD,
|
|
|
|
&sc->tz_thflags, 0, "thermal zone flags");
|
2006-07-25 02:27:38 +00:00
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_PSV", CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
sc, offsetof(struct acpi_tz_softc, tz_zone.psv),
|
|
|
|
acpi_tz_temp_sysctl, "IK", "passive cooling temp setpoint");
|
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_HOT", CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
sc, offsetof(struct acpi_tz_softc, tz_zone.hot),
|
|
|
|
acpi_tz_temp_sysctl, "IK",
|
|
|
|
"too hot temp setpoint (suspend now)");
|
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_CRT", CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
sc, offsetof(struct acpi_tz_softc, tz_zone.crt),
|
|
|
|
acpi_tz_temp_sysctl, "IK",
|
|
|
|
"critical temp setpoint (shutdown now)");
|
2011-04-18 19:02:41 +00:00
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_ACx", CTLTYPE_INT | CTLFLAG_RD,
|
2011-04-19 20:44:43 +00:00
|
|
|
&sc->tz_zone.ac, sizeof(sc->tz_zone.ac),
|
|
|
|
sysctl_handle_opaque, "IK", "");
|
2007-12-24 16:32:14 +00:00
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_TC1", CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
sc, offsetof(struct acpi_tz_softc, tz_zone.tc1),
|
|
|
|
acpi_tz_passive_sysctl, "I",
|
|
|
|
"thermal constant 1 for passive cooling");
|
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_TC2", CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
sc, offsetof(struct acpi_tz_softc, tz_zone.tc2),
|
|
|
|
acpi_tz_passive_sysctl, "I",
|
|
|
|
"thermal constant 2 for passive cooling");
|
|
|
|
SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_TSP", CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
sc, offsetof(struct acpi_tz_softc, tz_zone.tsp),
|
|
|
|
acpi_tz_passive_sysctl, "I",
|
|
|
|
"thermal sampling period for passive cooling");
|
2001-11-15 12:00:48 +00:00
|
|
|
|
2001-07-07 01:49:15 +00:00
|
|
|
/*
|
2005-07-18 20:12:23 +00:00
|
|
|
* Create thread to service all of the thermal zones. Register
|
|
|
|
* our power profile event handler.
|
2001-07-07 01:49:15 +00:00
|
|
|
*/
|
2004-08-13 06:22:17 +00:00
|
|
|
sc->tz_event = EVENTHANDLER_REGISTER(power_profile_change,
|
|
|
|
acpi_tz_power_profile, sc, 0);
|
|
|
|
if (acpi_tz_proc == NULL) {
|
2007-10-20 23:23:23 +00:00
|
|
|
error = kproc_create(acpi_tz_thread, NULL, &acpi_tz_proc,
|
2004-08-13 06:22:17 +00:00
|
|
|
RFHIGHPID, 0, "acpi_thermal");
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->tz_dev, "could not create thread - %d", error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2001-07-07 01:49:15 +00:00
|
|
|
|
2008-02-16 07:15:34 +00:00
|
|
|
/*
|
|
|
|
* Create a thread to handle passive cooling for 1st zone which
|
|
|
|
* has _PSV, _TSP, _TC1 and _TC2. Users can enable it for other
|
|
|
|
* zones manually for now.
|
|
|
|
*
|
|
|
|
* XXX We enable only one zone to avoid multiple zones conflict
|
|
|
|
* with each other since cpufreq currently sets all CPUs to the
|
|
|
|
* given frequency whereas it's possible for different thermal
|
|
|
|
* zones to specify independent settings for multiple CPUs.
|
|
|
|
*/
|
|
|
|
if (acpi_tz_cooling_unit < 0 && acpi_tz_cooling_is_available(sc))
|
|
|
|
sc->tz_cooling_enabled = TRUE;
|
2005-07-18 20:12:23 +00:00
|
|
|
if (sc->tz_cooling_enabled) {
|
2008-02-16 07:15:34 +00:00
|
|
|
error = acpi_tz_cooling_thread_start(sc);
|
|
|
|
if (error != 0) {
|
2005-07-18 20:12:23 +00:00
|
|
|
sc->tz_cooling_enabled = FALSE;
|
2008-02-16 07:15:34 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
acpi_tz_cooling_unit = device_get_unit(dev);
|
2005-07-18 20:12:23 +00:00
|
|
|
}
|
|
|
|
|
2001-01-31 09:33:51 +00:00
|
|
|
/*
|
2004-08-13 06:22:17 +00:00
|
|
|
* Flag the event handler for a manual invocation by our timeout.
|
|
|
|
* We defer it like this so that the rest of the subsystem has time
|
|
|
|
* to come up. Don't bother evaluating/printing the temperature at
|
|
|
|
* this point; on many systems it'll be bogus until the EC is running.
|
2001-01-31 09:33:51 +00:00
|
|
|
*/
|
2004-08-13 06:22:17 +00:00
|
|
|
sc->tz_flags |= TZ_FLAG_GETPROFILE;
|
2001-06-29 21:20:46 +00:00
|
|
|
|
2004-08-13 06:22:17 +00:00
|
|
|
out:
|
|
|
|
if (error != 0) {
|
|
|
|
EVENTHANDLER_DEREGISTER(power_profile_change, sc->tz_event);
|
|
|
|
AcpiRemoveNotifyHandler(sc->tz_handle, ACPI_DEVICE_NOTIFY,
|
|
|
|
acpi_tz_notify_handler);
|
|
|
|
sysctl_ctx_free(&sc->tz_sysctl_ctx);
|
2002-02-23 05:29:23 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (error);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2000-12-22 14:41:55 +00:00
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Parse the current state of this thermal zone and set up to use it.
|
|
|
|
*
|
|
|
|
* Note that we may have previous state, which will have to be discarded.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_tz_establish(struct acpi_tz_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT *obj;
|
|
|
|
int i;
|
|
|
|
char nbuf[8];
|
2005-07-18 20:12:23 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2004-09-07 17:02:08 +00:00
|
|
|
/* Erase any existing state. */
|
2001-06-28 06:17:16 +00:00
|
|
|
for (i = 0; i < TZ_NUMLEVELS; i++)
|
2001-07-07 01:49:15 +00:00
|
|
|
if (sc->tz_zone.al[i].Pointer != NULL)
|
|
|
|
AcpiOsFree(sc->tz_zone.al[i].Pointer);
|
|
|
|
if (sc->tz_zone.psl.Pointer != NULL)
|
|
|
|
AcpiOsFree(sc->tz_zone.psl.Pointer);
|
2005-08-25 10:50:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: We initialize only ACPI_BUFFER to avoid race condition
|
|
|
|
* with passive cooling thread which refers psv, tc1, tc2 and tsp.
|
|
|
|
*/
|
|
|
|
bzero(sc->tz_zone.ac, sizeof(sc->tz_zone.ac));
|
|
|
|
bzero(sc->tz_zone.al, sizeof(sc->tz_zone.al));
|
|
|
|
bzero(&sc->tz_zone.psl, sizeof(sc->tz_zone.psl));
|
2001-07-07 01:49:15 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Evaluate thermal zone parameters. */
|
2001-06-28 06:17:16 +00:00
|
|
|
for (i = 0; i < TZ_NUMLEVELS; i++) {
|
|
|
|
sprintf(nbuf, "_AC%d", i);
|
2001-07-07 01:49:15 +00:00
|
|
|
acpi_tz_getparam(sc, nbuf, &sc->tz_zone.ac[i]);
|
2001-06-28 06:17:16 +00:00
|
|
|
sprintf(nbuf, "_AL%d", i);
|
2002-02-23 05:29:23 +00:00
|
|
|
sc->tz_zone.al[i].Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
sc->tz_zone.al[i].Pointer = NULL;
|
|
|
|
AcpiEvaluateObject(sc->tz_handle, nbuf, NULL, &sc->tz_zone.al[i]);
|
2001-07-07 01:49:15 +00:00
|
|
|
obj = (ACPI_OBJECT *)sc->tz_zone.al[i].Pointer;
|
2001-06-28 06:17:16 +00:00
|
|
|
if (obj != NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Should be a package containing a list of power objects */
|
2001-06-28 06:17:16 +00:00
|
|
|
if (obj->Type != ACPI_TYPE_PACKAGE) {
|
2003-08-28 16:06:30 +00:00
|
|
|
device_printf(sc->tz_dev, "%s has unknown type %d, rejecting\n",
|
2001-06-28 06:17:16 +00:00
|
|
|
nbuf, obj->Type);
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (ENXIO);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-07-07 01:49:15 +00:00
|
|
|
acpi_tz_getparam(sc, "_CRT", &sc->tz_zone.crt);
|
|
|
|
acpi_tz_getparam(sc, "_HOT", &sc->tz_zone.hot);
|
2002-02-23 05:29:23 +00:00
|
|
|
sc->tz_zone.psl.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
sc->tz_zone.psl.Pointer = NULL;
|
|
|
|
AcpiEvaluateObject(sc->tz_handle, "_PSL", NULL, &sc->tz_zone.psl);
|
2001-07-07 01:49:15 +00:00
|
|
|
acpi_tz_getparam(sc, "_PSV", &sc->tz_zone.psv);
|
|
|
|
acpi_tz_getparam(sc, "_TC1", &sc->tz_zone.tc1);
|
|
|
|
acpi_tz_getparam(sc, "_TC2", &sc->tz_zone.tc2);
|
|
|
|
acpi_tz_getparam(sc, "_TSP", &sc->tz_zone.tsp);
|
|
|
|
acpi_tz_getparam(sc, "_TZP", &sc->tz_zone.tzp);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2001-07-05 07:19:17 +00:00
|
|
|
/*
|
|
|
|
* Sanity-check the values we've been given.
|
|
|
|
*
|
|
|
|
* XXX what do we do about systems that give us the same value for
|
|
|
|
* more than one of these setpoints?
|
|
|
|
*/
|
2001-07-07 01:49:15 +00:00
|
|
|
acpi_tz_sanity(sc, &sc->tz_zone.crt, "_CRT");
|
|
|
|
acpi_tz_sanity(sc, &sc->tz_zone.hot, "_HOT");
|
|
|
|
acpi_tz_sanity(sc, &sc->tz_zone.psv, "_PSV");
|
2001-07-05 07:19:17 +00:00
|
|
|
for (i = 0; i < TZ_NUMLEVELS; i++)
|
2001-07-07 01:49:15 +00:00
|
|
|
acpi_tz_sanity(sc, &sc->tz_zone.ac[i], "_ACx");
|
2001-07-05 07:19:17 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (0);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 06:22:17 +00:00
|
|
|
static char *aclevel_string[] = {
|
|
|
|
"NONE", "_AC0", "_AC1", "_AC2", "_AC3", "_AC4",
|
|
|
|
"_AC5", "_AC6", "_AC7", "_AC8", "_AC9"
|
|
|
|
};
|
2001-10-29 18:09:43 +00:00
|
|
|
|
|
|
|
static __inline const char *
|
|
|
|
acpi_tz_aclevel_string(int active)
|
|
|
|
{
|
2004-08-13 06:22:17 +00:00
|
|
|
if (active < -1 || active >= TZ_NUMLEVELS)
|
|
|
|
return (aclevel_string[0]);
|
2001-10-29 18:09:43 +00:00
|
|
|
|
2004-08-13 06:22:17 +00:00
|
|
|
return (aclevel_string[active + 1]);
|
2001-10-29 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
2005-08-25 11:31:30 +00:00
|
|
|
/*
|
|
|
|
* Get the current temperature.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_tz_get_temperature(struct acpi_tz_softc *sc)
|
|
|
|
{
|
|
|
|
int temp;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2005-08-26 02:21:02 +00:00
|
|
|
ACPI_FUNCTION_NAME ("acpi_tz_get_temperature");
|
|
|
|
|
2007-03-05 21:39:53 +00:00
|
|
|
/* Evaluate the thermal zone's _TMP method. */
|
2013-08-30 19:21:12 +00:00
|
|
|
status = acpi_GetInteger(sc->tz_handle, acpi_tz_tmp_name, &temp);
|
2005-08-25 11:31:30 +00:00
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
|
|
|
|
"error fetching current temperature -- %s\n",
|
|
|
|
AcpiFormatException(status));
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
2007-03-05 21:39:53 +00:00
|
|
|
/* Check it for validity. */
|
2013-08-30 19:21:12 +00:00
|
|
|
acpi_tz_sanity(sc, &temp, acpi_tz_tmp_name);
|
2007-03-05 21:39:53 +00:00
|
|
|
if (temp == -1)
|
|
|
|
return (FALSE);
|
|
|
|
|
2005-08-25 11:31:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "got %d.%dC\n", TZ_KELVTOC(temp)));
|
|
|
|
sc->tz_temperature = temp;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Evaluate the condition of a thermal zone, take appropriate actions.
|
|
|
|
*/
|
2001-01-31 09:33:51 +00:00
|
|
|
static void
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_tz_monitor(void *Context)
|
2001-01-31 09:33:51 +00:00
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
struct acpi_tz_softc *sc;
|
|
|
|
struct timespec curtime;
|
2001-07-05 07:19:17 +00:00
|
|
|
int temp;
|
2001-06-28 06:17:16 +00:00
|
|
|
int i;
|
2001-07-05 07:19:17 +00:00
|
|
|
int newactive, newflags;
|
2001-01-31 09:33:51 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-01-31 09:33:51 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
sc = (struct acpi_tz_softc *)Context;
|
2001-12-22 16:05:41 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Get the current temperature. */
|
2005-08-25 11:31:30 +00:00
|
|
|
if (!acpi_tz_get_temperature(sc)) {
|
2001-12-22 16:05:41 +00:00
|
|
|
/* XXX disable zone? go to max cooling? */
|
2004-08-13 06:22:17 +00:00
|
|
|
return_VOID;
|
2001-12-22 16:05:41 +00:00
|
|
|
}
|
2005-08-25 11:31:30 +00:00
|
|
|
temp = sc->tz_temperature;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Work out what we ought to be doing right now.
|
2001-07-05 07:19:17 +00:00
|
|
|
*
|
|
|
|
* Note that the _ACx levels sort from hot to cold.
|
2001-06-28 06:17:16 +00:00
|
|
|
*/
|
2001-07-05 07:19:17 +00:00
|
|
|
newactive = TZ_ACTIVE_NONE;
|
2001-07-07 01:49:15 +00:00
|
|
|
for (i = TZ_NUMLEVELS - 1; i >= 0; i--) {
|
2013-01-10 21:38:31 +00:00
|
|
|
if (sc->tz_zone.ac[i] != -1 && temp >= sc->tz_zone.ac[i])
|
2001-07-05 07:19:17 +00:00
|
|
|
newactive = i;
|
2001-07-07 01:49:15 +00:00
|
|
|
}
|
|
|
|
|
2001-10-29 18:09:43 +00:00
|
|
|
/*
|
|
|
|
* We are going to get _ACx level down (colder side), but give a guaranteed
|
|
|
|
* minimum cooling run time if requested.
|
|
|
|
*/
|
|
|
|
if (acpi_tz_min_runtime > 0 && sc->tz_active != TZ_ACTIVE_NONE &&
|
2008-04-25 16:45:13 +00:00
|
|
|
sc->tz_active != TZ_ACTIVE_UNKNOWN &&
|
2001-10-29 18:09:43 +00:00
|
|
|
(newactive == TZ_ACTIVE_NONE || newactive > sc->tz_active)) {
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2001-10-29 18:09:43 +00:00
|
|
|
getnanotime(&curtime);
|
|
|
|
timespecsub(&curtime, &sc->tz_cooling_started);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (curtime.tv_sec < acpi_tz_min_runtime)
|
2001-10-29 18:09:43 +00:00
|
|
|
newactive = sc->tz_active;
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Handle user override of active mode */
|
2008-02-16 02:09:05 +00:00
|
|
|
if (sc->tz_requested != TZ_ACTIVE_NONE && (newactive == TZ_ACTIVE_NONE
|
|
|
|
|| sc->tz_requested < newactive))
|
2001-07-07 01:49:15 +00:00
|
|
|
newactive = sc->tz_requested;
|
2001-07-05 07:19:17 +00:00
|
|
|
|
2001-07-07 01:49:15 +00:00
|
|
|
/* update temperature-related flags */
|
|
|
|
newflags = TZ_THFLAG_NONE;
|
2004-01-12 17:59:10 +00:00
|
|
|
if (sc->tz_zone.psv != -1 && temp >= sc->tz_zone.psv)
|
2001-07-07 01:49:15 +00:00
|
|
|
newflags |= TZ_THFLAG_PSV;
|
2004-01-12 17:59:10 +00:00
|
|
|
if (sc->tz_zone.hot != -1 && temp >= sc->tz_zone.hot)
|
2001-07-07 01:49:15 +00:00
|
|
|
newflags |= TZ_THFLAG_HOT;
|
2004-01-12 17:59:10 +00:00
|
|
|
if (sc->tz_zone.crt != -1 && temp >= sc->tz_zone.crt)
|
2001-07-07 01:49:15 +00:00
|
|
|
newflags |= TZ_THFLAG_CRT;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* If the active cooling state has changed, we have to switch things. */
|
2008-04-25 16:45:13 +00:00
|
|
|
if (sc->tz_active == TZ_ACTIVE_UNKNOWN) {
|
|
|
|
/*
|
|
|
|
* We don't know which cooling device is on or off,
|
|
|
|
* so stop them all, because we now know which
|
|
|
|
* should be on (if any).
|
|
|
|
*/
|
|
|
|
for (i = 0; i < TZ_NUMLEVELS; i++) {
|
|
|
|
if (sc->tz_zone.al[i].Pointer != NULL) {
|
|
|
|
acpi_ForeachPackageObject(
|
|
|
|
(ACPI_OBJECT *)sc->tz_zone.al[i].Pointer,
|
|
|
|
acpi_tz_switch_cooler_off, sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* now we know that all devices are off */
|
|
|
|
sc->tz_active = TZ_ACTIVE_NONE;
|
|
|
|
}
|
|
|
|
|
2001-07-05 07:19:17 +00:00
|
|
|
if (newactive != sc->tz_active) {
|
2012-10-14 09:32:38 +00:00
|
|
|
/* Turn off unneeded cooling devices that are on, if any are */
|
|
|
|
for (i = TZ_ACTIVE_LEVEL(sc->tz_active);
|
|
|
|
i < TZ_ACTIVE_LEVEL(newactive); i++) {
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_ForeachPackageObject(
|
2012-10-14 09:32:38 +00:00
|
|
|
(ACPI_OBJECT *)sc->tz_zone.al[i].Pointer,
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_tz_switch_cooler_off, sc);
|
2012-10-14 09:32:38 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Turn on cooling devices that are required, if any are */
|
2012-10-14 09:32:38 +00:00
|
|
|
for (i = TZ_ACTIVE_LEVEL(sc->tz_active) - 1;
|
|
|
|
i >= TZ_ACTIVE_LEVEL(newactive); i--) {
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_ForeachPackageObject(
|
2012-10-14 09:32:38 +00:00
|
|
|
(ACPI_OBJECT *)sc->tz_zone.al[i].Pointer,
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_tz_switch_cooler_on, sc);
|
|
|
|
}
|
2012-10-14 09:32:38 +00:00
|
|
|
|
2001-11-18 18:12:07 +00:00
|
|
|
ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
|
2003-08-28 16:06:30 +00:00
|
|
|
"switched from %s to %s: %d.%dC\n",
|
|
|
|
acpi_tz_aclevel_string(sc->tz_active),
|
|
|
|
acpi_tz_aclevel_string(newactive), TZ_KELVTOC(temp));
|
2001-07-05 07:19:17 +00:00
|
|
|
sc->tz_active = newactive;
|
2005-02-22 00:40:13 +00:00
|
|
|
getnanotime(&sc->tz_cooling_started);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* XXX (de)activate any passive cooling that may be required. */
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
2004-02-02 18:03:35 +00:00
|
|
|
* If the temperature is at _HOT or _CRT, increment our event count.
|
|
|
|
* If it has occurred enough times, shutdown the system. This is
|
|
|
|
* needed because some systems will report an invalid high temperature
|
|
|
|
* for one poll cycle. It is suspected this is due to the embedded
|
|
|
|
* controller timing out. A typical value is 138C for one cycle on
|
|
|
|
* a system that is otherwise 65C.
|
2004-02-03 04:18:56 +00:00
|
|
|
*
|
|
|
|
* If we're almost at that threshold, notify the user through devd(8).
|
2001-06-28 06:17:16 +00:00
|
|
|
*/
|
2004-02-02 18:03:35 +00:00
|
|
|
if ((newflags & (TZ_THFLAG_HOT | TZ_THFLAG_CRT)) != 0) {
|
2004-02-03 04:18:56 +00:00
|
|
|
sc->tz_validchecks++;
|
|
|
|
if (sc->tz_validchecks == TZ_VALIDCHECKS) {
|
2004-02-02 18:03:35 +00:00
|
|
|
device_printf(sc->tz_dev,
|
|
|
|
"WARNING - current temperature (%d.%dC) exceeds safe limits\n",
|
|
|
|
TZ_KELVTOC(sc->tz_temperature));
|
|
|
|
shutdown_nice(RB_POWEROFF);
|
2004-02-03 04:18:56 +00:00
|
|
|
} else if (sc->tz_validchecks == TZ_NOTIFYCOUNT)
|
|
|
|
acpi_UserNotify("Thermal", sc->tz_handle, TZ_NOTIFY_CRITICAL);
|
2004-02-02 18:03:35 +00:00
|
|
|
} else {
|
|
|
|
sc->tz_validchecks = 0;
|
2001-01-31 09:33:51 +00:00
|
|
|
}
|
2001-07-07 01:49:15 +00:00
|
|
|
sc->tz_thflags = newflags;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-07-18 20:12:23 +00:00
|
|
|
* Given an object, verify that it's a reference to a device of some sort,
|
2001-06-28 06:17:16 +00:00
|
|
|
* and try to switch it off.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg)
|
|
|
|
{
|
2004-04-09 06:55:50 +00:00
|
|
|
ACPI_HANDLE cooler;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2004-04-09 06:55:50 +00:00
|
|
|
cooler = acpi_GetReference(NULL, obj);
|
|
|
|
if (cooler == NULL) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get handle\n"));
|
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s off\n",
|
|
|
|
acpi_name(cooler)));
|
2004-04-12 05:04:47 +00:00
|
|
|
acpi_pwr_switch_consumer(cooler, ACPI_STATE_D3);
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2001-07-07 01:49:15 +00:00
|
|
|
return_VOID;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-07-18 20:12:23 +00:00
|
|
|
* Given an object, verify that it's a reference to a device of some sort,
|
2001-06-28 06:17:16 +00:00
|
|
|
* and try to switch it on.
|
|
|
|
*
|
2004-04-09 06:55:50 +00:00
|
|
|
* XXX replication of off/on function code is bad.
|
2001-06-28 06:17:16 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_switch_cooler_on(ACPI_OBJECT *obj, void *arg)
|
|
|
|
{
|
|
|
|
struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_HANDLE cooler;
|
2001-07-07 01:49:15 +00:00
|
|
|
ACPI_STATUS status;
|
2005-07-18 20:12:23 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2004-04-09 06:55:50 +00:00
|
|
|
cooler = acpi_GetReference(NULL, obj);
|
|
|
|
if (cooler == NULL) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get handle\n"));
|
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s on\n",
|
|
|
|
acpi_name(cooler)));
|
|
|
|
status = acpi_pwr_switch_consumer(cooler, ACPI_STATE_D0);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
|
|
|
|
"failed to activate %s - %s\n", acpi_name(cooler),
|
|
|
|
AcpiFormatException(status));
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return_VOID;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read/debug-print a parameter, default it to -1.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_getparam(struct acpi_tz_softc *sc, char *node, int *data)
|
|
|
|
{
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2004-03-03 18:34:42 +00:00
|
|
|
if (ACPI_FAILURE(acpi_GetInteger(sc->tz_handle, node, data))) {
|
2001-06-28 06:17:16 +00:00
|
|
|
*data = -1;
|
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "%s.%s = %d\n",
|
|
|
|
acpi_name(sc->tz_handle), node, *data));
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2005-07-18 20:12:23 +00:00
|
|
|
return_VOID;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2001-07-05 07:19:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity-check a temperature value. Assume that setpoints
|
2007-03-05 21:39:53 +00:00
|
|
|
* should be between 0C and 200C.
|
2001-07-05 07:19:17 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what)
|
|
|
|
{
|
2007-03-05 21:39:53 +00:00
|
|
|
if (*val != -1 && (*val < TZ_ZEROC || *val > TZ_ZEROC + 2000)) {
|
2013-08-30 19:21:12 +00:00
|
|
|
/*
|
|
|
|
* If the value we are checking is _TMP, warn the user only
|
|
|
|
* once. This avoids spamming messages if, for instance, the
|
|
|
|
* sensor is broken and always returns an invalid temperature.
|
|
|
|
*
|
|
|
|
* This is only done for _TMP; other values always emit a
|
|
|
|
* warning.
|
|
|
|
*/
|
|
|
|
if (what != acpi_tz_tmp_name || !sc->tz_insane_tmp_notified) {
|
|
|
|
device_printf(sc->tz_dev, "%s value is absurd, ignored (%d.%dC)\n",
|
|
|
|
what, TZ_KELVTOC(*val));
|
|
|
|
|
|
|
|
/* Don't warn the user again if the read value doesn't improve. */
|
|
|
|
if (what == acpi_tz_tmp_name)
|
|
|
|
sc->tz_insane_tmp_notified = 1;
|
|
|
|
}
|
2001-07-05 07:19:17 +00:00
|
|
|
*val = -1;
|
2013-08-30 19:21:12 +00:00
|
|
|
return;
|
2001-07-05 07:19:17 +00:00
|
|
|
}
|
2013-08-30 19:21:12 +00:00
|
|
|
|
|
|
|
/* This value is correct. Warn if it's incorrect again. */
|
|
|
|
if (what == acpi_tz_tmp_name)
|
|
|
|
sc->tz_insane_tmp_notified = 0;
|
2001-07-05 07:19:17 +00:00
|
|
|
}
|
2001-07-07 01:49:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Respond to a sysctl on the active state node.
|
2005-07-18 20:12:23 +00:00
|
|
|
*/
|
2001-07-07 01:49:15 +00:00
|
|
|
static int
|
|
|
|
acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_tz_softc *sc;
|
|
|
|
int active;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc = (struct acpi_tz_softc *)oidp->oid_arg1;
|
|
|
|
active = sc->tz_active;
|
|
|
|
error = sysctl_handle_int(oidp, &active, 0, req);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Error or no new value */
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
2004-08-13 06:22:17 +00:00
|
|
|
return (error);
|
|
|
|
if (active < -1 || active >= TZ_NUMLEVELS)
|
|
|
|
return (EINVAL);
|
2001-07-07 01:49:15 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Set new preferred level and re-switch */
|
2001-07-07 01:49:15 +00:00
|
|
|
sc->tz_requested = active;
|
2004-08-13 06:22:17 +00:00
|
|
|
acpi_tz_signal(sc, 0);
|
|
|
|
return (0);
|
2001-07-07 01:49:15 +00:00
|
|
|
}
|
|
|
|
|
2005-07-18 20:12:23 +00:00
|
|
|
static int
|
|
|
|
acpi_tz_cooling_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_tz_softc *sc;
|
|
|
|
int enabled, error;
|
|
|
|
|
|
|
|
sc = (struct acpi_tz_softc *)oidp->oid_arg1;
|
|
|
|
enabled = sc->tz_cooling_enabled;
|
|
|
|
error = sysctl_handle_int(oidp, &enabled, 0, req);
|
|
|
|
|
|
|
|
/* Error or no new value */
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
if (enabled != TRUE && enabled != FALSE)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
if (acpi_tz_cooling_is_available(sc))
|
|
|
|
error = acpi_tz_cooling_thread_start(sc);
|
|
|
|
else
|
|
|
|
error = ENODEV;
|
|
|
|
if (error)
|
|
|
|
enabled = FALSE;
|
|
|
|
}
|
|
|
|
sc->tz_cooling_enabled = enabled;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2006-07-25 02:27:38 +00:00
|
|
|
static int
|
|
|
|
acpi_tz_temp_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_tz_softc *sc;
|
|
|
|
int temp, *temp_ptr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc = oidp->oid_arg1;
|
|
|
|
temp_ptr = (int *)((uintptr_t)sc + oidp->oid_arg2);
|
|
|
|
temp = *temp_ptr;
|
|
|
|
error = sysctl_handle_int(oidp, &temp, 0, req);
|
|
|
|
|
|
|
|
/* Error or no new value */
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* Only allow changing settings if override is set. */
|
|
|
|
if (!acpi_tz_override)
|
|
|
|
return (EPERM);
|
|
|
|
|
|
|
|
/* Check user-supplied value for sanity. */
|
|
|
|
acpi_tz_sanity(sc, &temp, "user-supplied temp");
|
|
|
|
if (temp == -1)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
*temp_ptr = temp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-12-24 16:32:14 +00:00
|
|
|
static int
|
|
|
|
acpi_tz_passive_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_tz_softc *sc;
|
|
|
|
int val, *val_ptr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc = oidp->oid_arg1;
|
|
|
|
val_ptr = (int *)((uintptr_t)sc + oidp->oid_arg2);
|
|
|
|
val = *val_ptr;
|
|
|
|
error = sysctl_handle_int(oidp, &val, 0, req);
|
|
|
|
|
|
|
|
/* Error or no new value */
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* Only allow changing settings if override is set. */
|
|
|
|
if (!acpi_tz_override)
|
|
|
|
return (EPERM);
|
|
|
|
|
|
|
|
*val_ptr = val;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-01-31 09:33:51 +00:00
|
|
|
static void
|
|
|
|
acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
|
|
|
|
{
|
2001-06-28 06:17:16 +00:00
|
|
|
struct acpi_tz_softc *sc = (struct acpi_tz_softc *)context;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-01-31 09:33:51 +00:00
|
|
|
|
2004-08-13 06:22:17 +00:00
|
|
|
switch (notify) {
|
2001-06-28 06:17:16 +00:00
|
|
|
case TZ_NOTIFY_TEMPERATURE:
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Temperature change occurred */
|
2004-08-13 06:22:17 +00:00
|
|
|
acpi_tz_signal(sc, 0);
|
2001-06-28 06:17:16 +00:00
|
|
|
break;
|
|
|
|
case TZ_NOTIFY_DEVICES:
|
|
|
|
case TZ_NOTIFY_LEVELS:
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Zone devices/setpoints changed */
|
2004-08-13 06:22:17 +00:00
|
|
|
acpi_tz_signal(sc, TZ_FLAG_GETSETTINGS);
|
2001-06-28 06:17:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
2001-11-18 18:12:07 +00:00
|
|
|
ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
|
2003-08-28 16:06:30 +00:00
|
|
|
"unknown Notify event 0x%x\n", notify);
|
2001-06-28 06:17:16 +00:00
|
|
|
break;
|
2001-01-31 09:33:51 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2003-10-25 05:03:25 +00:00
|
|
|
acpi_UserNotify("Thermal", h, notify);
|
|
|
|
|
2001-01-31 09:33:51 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
2000-12-22 14:41:55 +00:00
|
|
|
|
2004-08-13 06:22:17 +00:00
|
|
|
static void
|
|
|
|
acpi_tz_signal(struct acpi_tz_softc *sc, int flags)
|
|
|
|
{
|
|
|
|
ACPI_LOCK(thermal);
|
|
|
|
sc->tz_flags |= flags;
|
|
|
|
ACPI_UNLOCK(thermal);
|
|
|
|
wakeup(&acpi_tz_proc);
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
2004-09-07 17:02:08 +00:00
|
|
|
* Notifies can be generated asynchronously but have also been seen to be
|
|
|
|
* triggered by other thermal methods. One system generates a notify of
|
|
|
|
* 0x81 when the fan is turned on or off. Another generates it when _SCP
|
|
|
|
* is called. To handle these situations, we check the zone via
|
|
|
|
* acpi_tz_monitor() before evaluating changes to setpoints or the cooling
|
|
|
|
* policy.
|
2001-06-28 06:17:16 +00:00
|
|
|
*/
|
|
|
|
static void
|
2004-08-13 06:22:17 +00:00
|
|
|
acpi_tz_timeout(struct acpi_tz_softc *sc, int flags)
|
2001-06-28 06:17:16 +00:00
|
|
|
{
|
2004-09-07 17:02:08 +00:00
|
|
|
|
|
|
|
/* Check the current temperature and take action based on it */
|
|
|
|
acpi_tz_monitor(sc);
|
|
|
|
|
2004-08-13 06:22:17 +00:00
|
|
|
/* If requested, get the power profile settings. */
|
|
|
|
if (flags & TZ_FLAG_GETPROFILE)
|
|
|
|
acpi_tz_power_profile(sc);
|
2001-07-07 01:49:15 +00:00
|
|
|
|
2004-09-07 17:02:08 +00:00
|
|
|
/*
|
|
|
|
* If requested, check for new devices/setpoints. After finding them,
|
|
|
|
* check if we need to switch fans based on the new values.
|
|
|
|
*/
|
|
|
|
if (flags & TZ_FLAG_GETSETTINGS) {
|
2004-08-13 06:22:17 +00:00
|
|
|
acpi_tz_establish(sc);
|
2004-09-07 17:02:08 +00:00
|
|
|
acpi_tz_monitor(sc);
|
|
|
|
}
|
2001-06-29 21:20:46 +00:00
|
|
|
|
2002-02-23 05:29:23 +00:00
|
|
|
/* XXX passive cooling actions? */
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
2001-07-07 01:49:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* System power profile may have changed; fetch and notify the
|
|
|
|
* thermal zone accordingly.
|
|
|
|
*
|
|
|
|
* Since this can be called from an arbitrary eventhandler, it needs
|
|
|
|
* to get the ACPI lock itself.
|
|
|
|
*/
|
|
|
|
static void
|
2002-03-04 18:46:13 +00:00
|
|
|
acpi_tz_power_profile(void *arg)
|
2001-07-07 01:49:15 +00:00
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
|
2002-03-04 18:46:13 +00:00
|
|
|
int state;
|
|
|
|
|
|
|
|
state = power_profile_get_state();
|
2003-08-28 16:06:30 +00:00
|
|
|
if (state != POWER_PROFILE_PERFORMANCE && state != POWER_PROFILE_ECONOMY)
|
|
|
|
return;
|
2001-07-07 01:49:15 +00:00
|
|
|
|
|
|
|
/* check that we haven't decided there's no _SCP method */
|
2003-08-28 16:06:30 +00:00
|
|
|
if ((sc->tz_flags & TZ_FLAG_NO_SCP) == 0) {
|
2001-07-07 01:49:15 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Call _SCP to set the new profile */
|
2005-07-18 20:12:23 +00:00
|
|
|
status = acpi_SetInteger(sc->tz_handle, "_SCP",
|
2004-03-03 18:34:42 +00:00
|
|
|
(state == POWER_PROFILE_PERFORMANCE) ? 0 : 1);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (ACPI_FAILURE(status)) {
|
2001-07-07 10:17:22 +00:00
|
|
|
if (status != AE_NOT_FOUND)
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_VPRINT(sc->tz_dev,
|
|
|
|
acpi_device_get_parent_softc(sc->tz_dev),
|
|
|
|
"can't evaluate %s._SCP - %s\n",
|
|
|
|
acpi_name(sc->tz_handle),
|
|
|
|
AcpiFormatException(status));
|
2001-07-07 01:49:15 +00:00
|
|
|
sc->tz_flags |= TZ_FLAG_NO_SCP;
|
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
/* We have to re-evaluate the entire zone now */
|
2004-08-13 06:22:17 +00:00
|
|
|
acpi_tz_signal(sc, TZ_FLAG_GETSETTINGS);
|
2001-07-07 01:49:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-23 05:29:23 +00:00
|
|
|
/*
|
|
|
|
* Thermal zone monitor thread.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_thread(void *arg)
|
|
|
|
{
|
|
|
|
device_t *devs;
|
|
|
|
int devcount, i;
|
2004-08-13 06:22:17 +00:00
|
|
|
int flags;
|
|
|
|
struct acpi_tz_softc **sc;
|
2002-02-23 05:29:23 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2002-02-23 05:29:23 +00:00
|
|
|
|
|
|
|
devs = NULL;
|
|
|
|
devcount = 0;
|
2004-08-13 06:22:17 +00:00
|
|
|
sc = NULL;
|
2002-02-23 05:29:23 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2004-08-13 06:22:17 +00:00
|
|
|
/* If the number of devices has changed, re-evaluate. */
|
2007-12-31 15:56:03 +00:00
|
|
|
if (devclass_get_count(acpi_tz_devclass) != devcount) {
|
2004-08-13 06:22:17 +00:00
|
|
|
if (devs != NULL) {
|
|
|
|
free(devs, M_TEMP);
|
|
|
|
free(sc, M_TEMP);
|
|
|
|
}
|
2002-02-23 05:29:23 +00:00
|
|
|
devclass_get_devices(acpi_tz_devclass, &devs, &devcount);
|
2004-08-13 06:22:17 +00:00
|
|
|
sc = malloc(sizeof(struct acpi_tz_softc *) * devcount, M_TEMP,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
for (i = 0; i < devcount; i++)
|
|
|
|
sc[i] = device_get_softc(devs[i]);
|
|
|
|
}
|
2002-02-23 05:29:23 +00:00
|
|
|
|
2004-08-13 06:22:17 +00:00
|
|
|
/* Check for temperature events and act on them. */
|
|
|
|
for (i = 0; i < devcount; i++) {
|
|
|
|
ACPI_LOCK(thermal);
|
|
|
|
flags = sc[i]->tz_flags;
|
|
|
|
sc[i]->tz_flags &= TZ_FLAG_NO_SCP;
|
|
|
|
ACPI_UNLOCK(thermal);
|
|
|
|
acpi_tz_timeout(sc[i], flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If more work to do, don't go to sleep yet. */
|
|
|
|
ACPI_LOCK(thermal);
|
|
|
|
for (i = 0; i < devcount; i++) {
|
|
|
|
if (sc[i]->tz_flags & ~TZ_FLAG_NO_SCP)
|
|
|
|
break;
|
|
|
|
}
|
2002-02-25 02:21:22 +00:00
|
|
|
|
2004-08-13 06:22:17 +00:00
|
|
|
/*
|
|
|
|
* If we have no more work, sleep for a while, setting PDROP so that
|
|
|
|
* the mutex will not be reacquired. Otherwise, drop the mutex and
|
|
|
|
* loop to handle more events.
|
|
|
|
*/
|
|
|
|
if (i == devcount)
|
|
|
|
msleep(&acpi_tz_proc, &thermal_mutex, PZERO | PDROP, "tzpoll",
|
|
|
|
hz * acpi_tz_polling_rate);
|
|
|
|
else
|
|
|
|
ACPI_UNLOCK(thermal);
|
2002-02-23 05:29:23 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-18 20:12:23 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_tz_cpufreq_restore(struct acpi_tz_softc *sc)
|
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (!sc->tz_cooling_updated)
|
|
|
|
return (0);
|
|
|
|
if ((dev = devclass_get_device(devclass_find("cpufreq"), 0)) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
|
2005-08-17 17:01:25 +00:00
|
|
|
"temperature %d.%dC: resuming previous clock speed (%d MHz)\n",
|
|
|
|
TZ_KELVTOC(sc->tz_temperature), sc->tz_cooling_saved_freq);
|
2005-07-18 20:12:23 +00:00
|
|
|
error = CPUFREQ_SET(dev, NULL, CPUFREQ_PRIO_KERN);
|
|
|
|
if (error == 0)
|
|
|
|
sc->tz_cooling_updated = FALSE;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_tz_cpufreq_update(struct acpi_tz_softc *sc, int req)
|
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
struct cf_level *levels;
|
|
|
|
int num_levels, error, freq, desired_freq, perf, i;
|
|
|
|
|
|
|
|
levels = malloc(CPUFREQ_MAX_LEVELS * sizeof(*levels), M_TEMP, M_NOWAIT);
|
|
|
|
if (levels == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the main device, cpufreq0. We don't yet support independent
|
|
|
|
* CPU frequency control on SMP.
|
|
|
|
*/
|
|
|
|
if ((dev = devclass_get_device(devclass_find("cpufreq"), 0)) == NULL) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the current frequency. */
|
|
|
|
error = CPUFREQ_GET(dev, &levels[0]);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
freq = levels[0].total_set.freq;
|
|
|
|
|
|
|
|
/* Get the current available frequency levels. */
|
|
|
|
num_levels = CPUFREQ_MAX_LEVELS;
|
|
|
|
error = CPUFREQ_LEVELS(dev, levels, &num_levels);
|
|
|
|
if (error) {
|
|
|
|
if (error == E2BIG)
|
|
|
|
printf("cpufreq: need to increase CPUFREQ_MAX_LEVELS\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the desired frequency as a percent of the max frequency. */
|
|
|
|
perf = 100 * freq / levels[0].total_set.freq - req;
|
|
|
|
if (perf < 0)
|
|
|
|
perf = 0;
|
|
|
|
else if (perf > 100)
|
|
|
|
perf = 100;
|
|
|
|
desired_freq = levels[0].total_set.freq * perf / 100;
|
|
|
|
|
2005-08-17 17:01:25 +00:00
|
|
|
if (desired_freq < freq) {
|
2005-07-18 20:12:23 +00:00
|
|
|
/* Find the closest available frequency, rounding down. */
|
|
|
|
for (i = 0; i < num_levels; i++)
|
|
|
|
if (levels[i].total_set.freq <= desired_freq)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If we didn't find a relevant setting, use the lowest. */
|
|
|
|
if (i == num_levels)
|
|
|
|
i--;
|
|
|
|
} else {
|
2005-08-17 17:01:25 +00:00
|
|
|
/* If we didn't decrease frequency yet, don't increase it. */
|
|
|
|
if (!sc->tz_cooling_updated) {
|
|
|
|
sc->tz_cooling_active = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use saved cpu frequency as maximum value. */
|
|
|
|
if (desired_freq > sc->tz_cooling_saved_freq)
|
|
|
|
desired_freq = sc->tz_cooling_saved_freq;
|
|
|
|
|
2005-07-18 20:12:23 +00:00
|
|
|
/* Find the closest available frequency, rounding up. */
|
|
|
|
for (i = num_levels - 1; i >= 0; i--)
|
|
|
|
if (levels[i].total_set.freq >= desired_freq)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If we didn't find a relevant setting, use the highest. */
|
|
|
|
if (i == -1)
|
|
|
|
i++;
|
|
|
|
|
2005-08-17 17:01:25 +00:00
|
|
|
/* If we're going to the highest frequency, restore the old setting. */
|
|
|
|
if (i == 0 || desired_freq == sc->tz_cooling_saved_freq) {
|
|
|
|
error = acpi_tz_cpufreq_restore(sc);
|
|
|
|
if (error == 0)
|
|
|
|
sc->tz_cooling_active = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-07-18 20:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we are going to a new frequency, activate it. */
|
|
|
|
if (levels[i].total_set.freq != freq) {
|
|
|
|
ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
|
|
|
|
"temperature %d.%dC: %screasing clock speed "
|
|
|
|
"from %d MHz to %d MHz\n",
|
|
|
|
TZ_KELVTOC(sc->tz_temperature),
|
|
|
|
(freq > levels[i].total_set.freq) ? "de" : "in",
|
|
|
|
freq, levels[i].total_set.freq);
|
|
|
|
error = CPUFREQ_SET(dev, &levels[i], CPUFREQ_PRIO_KERN);
|
2005-08-17 17:01:25 +00:00
|
|
|
if (error == 0 && !sc->tz_cooling_updated) {
|
|
|
|
sc->tz_cooling_saved_freq = freq;
|
2005-07-18 20:12:23 +00:00
|
|
|
sc->tz_cooling_updated = TRUE;
|
2005-08-17 17:01:25 +00:00
|
|
|
}
|
2005-07-18 20:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (levels)
|
|
|
|
free(levels, M_TEMP);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Passive cooling thread; monitors current temperature according to the
|
|
|
|
* cooling interval and calculates whether to scale back CPU frequency.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_cooling_thread(void *arg)
|
|
|
|
{
|
|
|
|
struct acpi_tz_softc *sc;
|
2005-08-25 11:31:30 +00:00
|
|
|
int error, perf, curr_temp, prev_temp;
|
2005-07-18 20:12:23 +00:00
|
|
|
|
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
|
|
|
sc = (struct acpi_tz_softc *)arg;
|
|
|
|
|
2005-08-25 11:31:30 +00:00
|
|
|
prev_temp = sc->tz_temperature;
|
2005-07-18 20:12:23 +00:00
|
|
|
while (sc->tz_cooling_enabled) {
|
2005-08-25 11:31:30 +00:00
|
|
|
if (sc->tz_cooling_active)
|
|
|
|
(void)acpi_tz_get_temperature(sc);
|
|
|
|
curr_temp = sc->tz_temperature;
|
|
|
|
if (curr_temp >= sc->tz_zone.psv)
|
2005-07-18 20:12:23 +00:00
|
|
|
sc->tz_cooling_active = TRUE;
|
|
|
|
if (sc->tz_cooling_active) {
|
2005-08-25 11:31:30 +00:00
|
|
|
perf = sc->tz_zone.tc1 * (curr_temp - prev_temp) +
|
|
|
|
sc->tz_zone.tc2 * (curr_temp - sc->tz_zone.psv);
|
2005-07-18 20:12:23 +00:00
|
|
|
perf /= 10;
|
|
|
|
|
|
|
|
if (perf != 0) {
|
|
|
|
error = acpi_tz_cpufreq_update(sc, perf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If error and not simply a higher priority setting was
|
|
|
|
* active, disable cooling.
|
|
|
|
*/
|
|
|
|
if (error != 0 && error != EPERM) {
|
|
|
|
device_printf(sc->tz_dev,
|
|
|
|
"failed to set new freq, disabling passive cooling\n");
|
|
|
|
sc->tz_cooling_enabled = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-25 11:31:30 +00:00
|
|
|
prev_temp = curr_temp;
|
2005-07-18 20:12:23 +00:00
|
|
|
tsleep(&sc->tz_cooling_proc, PZERO, "cooling",
|
|
|
|
hz * sc->tz_zone.tsp / 10);
|
|
|
|
}
|
|
|
|
if (sc->tz_cooling_active) {
|
|
|
|
acpi_tz_cpufreq_restore(sc);
|
|
|
|
sc->tz_cooling_active = FALSE;
|
|
|
|
}
|
|
|
|
sc->tz_cooling_proc = NULL;
|
2005-08-04 18:34:26 +00:00
|
|
|
ACPI_LOCK(thermal);
|
|
|
|
sc->tz_cooling_proc_running = FALSE;
|
2005-07-18 20:12:23 +00:00
|
|
|
ACPI_UNLOCK(thermal);
|
2007-10-20 23:23:23 +00:00
|
|
|
kproc_exit(0);
|
2005-07-18 20:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: We ignore _PSL (list of cooling devices) since cpufreq enumerates
|
|
|
|
* all CPUs for us. However, it's possible in the future _PSL will
|
|
|
|
* reference non-CPU devices so we may want to support it then.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_tz_cooling_is_available(struct acpi_tz_softc *sc)
|
|
|
|
{
|
|
|
|
return (sc->tz_zone.tc1 != -1 && sc->tz_zone.tc2 != -1 &&
|
|
|
|
sc->tz_zone.tsp != -1 && sc->tz_zone.tsp != 0 &&
|
|
|
|
sc->tz_zone.psv != -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_tz_cooling_thread_start(struct acpi_tz_softc *sc)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ACPI_LOCK(thermal);
|
2005-08-04 18:34:26 +00:00
|
|
|
if (sc->tz_cooling_proc_running) {
|
|
|
|
ACPI_UNLOCK(thermal);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
sc->tz_cooling_proc_running = TRUE;
|
|
|
|
ACPI_UNLOCK(thermal);
|
|
|
|
error = 0;
|
2005-07-18 20:12:23 +00:00
|
|
|
if (sc->tz_cooling_proc == NULL) {
|
2007-10-20 23:23:23 +00:00
|
|
|
error = kproc_create(acpi_tz_cooling_thread, sc,
|
2010-06-11 19:27:21 +00:00
|
|
|
&sc->tz_cooling_proc, RFHIGHPID, 0, "acpi_cooling%d",
|
|
|
|
device_get_unit(sc->tz_dev));
|
2005-08-04 18:34:26 +00:00
|
|
|
if (error != 0) {
|
2005-07-18 20:12:23 +00:00
|
|
|
device_printf(sc->tz_dev, "could not create thread - %d", error);
|
2005-08-04 18:34:26 +00:00
|
|
|
ACPI_LOCK(thermal);
|
|
|
|
sc->tz_cooling_proc_running = FALSE;
|
|
|
|
ACPI_UNLOCK(thermal);
|
|
|
|
}
|
2005-07-18 20:12:23 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|