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>
|
2002-02-23 05:29:23 +00:00
|
|
|
#include <sys/kthread.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
#include <sys/bus.h>
|
2002-02-23 05:29:23 +00:00
|
|
|
#include <sys/proc.h>
|
2001-06-28 06:17:16 +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
|
|
|
|
|
|
|
#include "acpi.h"
|
|
|
|
#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
|
|
|
|
#define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), (((x) - TZ_ZEROC) % 10)
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
#define TZ_NOTIFY_TEMPERATURE 0x80
|
|
|
|
#define TZ_NOTIFY_DEVICES 0x81
|
|
|
|
#define TZ_NOTIFY_LEVELS 0x82
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Check for temperature changes every 30 seconds by default */
|
|
|
|
#define TZ_POLLRATE 30
|
2001-06-28 06:17:16 +00:00
|
|
|
|
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
|
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)
|
|
|
|
#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*/
|
|
|
|
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;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
struct acpi_tz_zone tz_zone; /*Thermal zone parameters*/
|
2001-12-22 16:05:41 +00:00
|
|
|
int tz_tmp_updating;
|
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_all_off(struct acpi_tz_softc *sc);
|
|
|
|
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);
|
2003-08-28 16:06:30 +00:00
|
|
|
static void acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify,
|
|
|
|
void *context);
|
2002-02-23 05:29:23 +00:00
|
|
|
static void acpi_tz_timeout(struct acpi_tz_softc *sc);
|
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);
|
|
|
|
|
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),
|
|
|
|
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_tz_driver = {
|
|
|
|
"acpi_tz",
|
|
|
|
acpi_tz_methods,
|
|
|
|
sizeof(struct acpi_tz_softc),
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
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 */
|
|
|
|
static int acpi_tz_min_runtime = 0;
|
2001-12-22 16:05:41 +00:00
|
|
|
static int acpi_tz_polling_rate = TZ_POLLRATE;
|
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;
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Match an ACPI thermal zone.
|
|
|
|
*/
|
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;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
2001-06-29 21:20:46 +00:00
|
|
|
|
|
|
|
ACPI_LOCK;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* No FUNCTION_TRACE - too noisy */
|
2000-12-08 09:16:20 +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;
|
|
|
|
} else {
|
|
|
|
result = ENXIO;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_UNLOCK;
|
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
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Attach to an ACPI thermal zone.
|
|
|
|
*/
|
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];
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
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
|
|
|
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_LOCK;
|
|
|
|
|
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;
|
2001-12-22 16:05:41 +00:00
|
|
|
sc->tz_tmp_updating = 0;
|
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
|
|
|
|
* structures.
|
|
|
|
*/
|
|
|
|
if ((error = acpi_tz_establish(sc)) != 0)
|
2001-06-29 21:20:46 +00:00
|
|
|
goto out;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register for any Notify events sent to this zone.
|
|
|
|
*/
|
2001-01-31 09:33:51 +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),
|
|
|
|
OID_AUTO, "min_runtime", CTLFLAG_RD | 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),
|
|
|
|
OID_AUTO, "polling_rate", CTLFLAG_RD | CTLFLAG_RW,
|
|
|
|
&acpi_tz_polling_rate, 0, "monitor polling rate");
|
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, "");
|
2001-07-05 07:19:17 +00:00
|
|
|
SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "temperature", CTLFLAG_RD,
|
|
|
|
&sc->tz_temperature, 0, "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,
|
|
|
|
sc, 0, acpi_tz_active_sysctl, "I", "");
|
|
|
|
|
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");
|
2001-07-05 07:19:17 +00:00
|
|
|
SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_PSV", CTLFLAG_RD,
|
2001-07-07 01:49:15 +00:00
|
|
|
&sc->tz_zone.psv, 0, "");
|
2001-07-05 07:19:17 +00:00
|
|
|
SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_HOT", CTLFLAG_RD,
|
2001-07-07 01:49:15 +00:00
|
|
|
&sc->tz_zone.hot, 0, "");
|
2001-07-05 07:19:17 +00:00
|
|
|
SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_CRT", CTLFLAG_RD,
|
2001-07-07 01:49:15 +00:00
|
|
|
&sc->tz_zone.crt, 0, "");
|
2001-11-15 12:00:48 +00:00
|
|
|
SYSCTL_ADD_OPAQUE(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
|
|
|
|
OID_AUTO, "_ACx", CTLFLAG_RD, &sc->tz_zone.ac,
|
|
|
|
sizeof(sc->tz_zone.ac), "I", "");
|
|
|
|
|
2001-07-07 01:49:15 +00:00
|
|
|
/*
|
|
|
|
* Register our power profile event handler, and flag it for a manual
|
|
|
|
* invocation by our timeout. We defer it like this so that the rest
|
|
|
|
* of the subsystem has time to come up.
|
|
|
|
*/
|
2002-03-04 18:46:13 +00:00
|
|
|
EVENTHANDLER_REGISTER(power_profile_change, acpi_tz_power_profile, sc, 0);
|
2001-07-07 01:49:15 +00:00
|
|
|
sc->tz_flags |= TZ_FLAG_GETPROFILE;
|
|
|
|
|
2001-01-31 09:33:51 +00:00
|
|
|
/*
|
|
|
|
* Don't bother evaluating/printing the temperature at this point;
|
|
|
|
* on many systems it'll be bogus until the EC is running.
|
|
|
|
*/
|
2001-06-29 21:20:46 +00:00
|
|
|
|
2001-07-07 01:49:15 +00:00
|
|
|
/*
|
2002-02-23 05:29:23 +00:00
|
|
|
* Create our thread; we only need one, it will service all of the
|
|
|
|
* thermal zones.
|
2001-07-07 01:49:15 +00:00
|
|
|
*/
|
2002-02-23 05:29:23 +00:00
|
|
|
if (acpi_tz_proc == NULL) {
|
|
|
|
error = kthread_create(acpi_tz_thread, NULL, &acpi_tz_proc,
|
2002-10-02 07:44:29 +00:00
|
|
|
RFHIGHPID, 0, "acpi_thermal");
|
2002-02-23 05:29:23 +00:00
|
|
|
if (error != 0) {
|
2003-08-28 16:06:30 +00:00
|
|
|
device_printf(sc->tz_dev, "could not create thread - %d",
|
|
|
|
error);
|
2002-02-23 05:29:23 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2001-07-07 01:49:15 +00:00
|
|
|
|
2002-02-23 05:29:23 +00:00
|
|
|
out:
|
|
|
|
ACPI_UNLOCK;
|
|
|
|
|
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];
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Power everything off and erase any existing state. */
|
2001-06-28 06:17:16 +00:00
|
|
|
acpi_tz_all_off(sc);
|
|
|
|
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);
|
|
|
|
bzero(&sc->tz_zone, sizeof(sc->tz_zone));
|
|
|
|
|
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
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Power off everything that we've just been given.
|
|
|
|
*/
|
|
|
|
acpi_tz_all_off(sc);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (0);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2001-10-29 18:09:43 +00:00
|
|
|
static char *aclevel_string[] = {
|
|
|
|
"NONE", "_AC0", "_AC1", "_AC2", "_AC3", "_AC4",
|
|
|
|
"_AC5", "_AC6", "_AC7", "_AC8", "_AC9" };
|
|
|
|
|
|
|
|
static __inline const char *
|
|
|
|
acpi_tz_aclevel_string(int active)
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
if (active < -1 || active >= TZ_NUMLEVELS)
|
2001-10-29 18:09:43 +00:00
|
|
|
return (aclevel_string[0]);
|
|
|
|
|
|
|
|
return (aclevel_string[active+1]);
|
|
|
|
}
|
|
|
|
|
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-11-15 12:00:48 +00:00
|
|
|
ACPI_STATUS status;
|
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
|
|
|
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
sc = (struct acpi_tz_softc *)Context;
|
|
|
|
if (sc->tz_tmp_updating)
|
2001-12-22 16:05:41 +00:00
|
|
|
goto out;
|
|
|
|
sc->tz_tmp_updating = 1;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Get the current temperature. */
|
|
|
|
status = acpi_EvaluateInteger(sc->tz_handle, "_TMP", &temp);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2001-12-22 16:05:41 +00:00
|
|
|
ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
|
|
|
|
"error fetching current temperature -- %s\n",
|
|
|
|
AcpiFormatException(status));
|
|
|
|
/* XXX disable zone? go to max cooling? */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "got %d.%dC\n", TZ_KELVTOC(temp)));
|
2001-07-05 07:19:17 +00:00
|
|
|
sc->tz_temperature = temp;
|
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--) {
|
|
|
|
if ((sc->tz_zone.ac[i] != -1) && (temp >= sc->tz_zone.ac[i])) {
|
2001-07-05 07:19:17 +00:00
|
|
|
newactive = i;
|
2001-09-04 15:40:12 +00:00
|
|
|
if (sc->tz_active != newactive) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_VPRINT(sc->tz_dev,
|
|
|
|
acpi_device_get_parent_softc(sc->tz_dev),
|
|
|
|
"_AC%d: temperature %d.%d >= setpoint %d.%d\n", i,
|
|
|
|
TZ_KELVTOC(temp), TZ_KELVTOC(sc->tz_zone.ac[i]));
|
2001-10-29 18:09:43 +00:00
|
|
|
getnanotime(&sc->tz_cooling_started);
|
2001-09-04 15:40:12 +00:00
|
|
|
}
|
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 &&
|
|
|
|
(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 */
|
2001-07-07 01:49:15 +00:00
|
|
|
if (sc->tz_requested > newactive)
|
|
|
|
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;
|
|
|
|
if ((sc->tz_zone.psv != -1) && (temp >= sc->tz_zone.psv))
|
|
|
|
newflags |= TZ_THFLAG_PSV;
|
|
|
|
if ((sc->tz_zone.hot != -1) && (temp >= sc->tz_zone.hot))
|
|
|
|
newflags |= TZ_THFLAG_HOT;
|
|
|
|
if ((sc->tz_zone.crt != -1) && (temp >= sc->tz_zone.crt))
|
|
|
|
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. */
|
2001-07-05 07:19:17 +00:00
|
|
|
if (newactive != sc->tz_active) {
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Turn off the cooling devices that are on, if any are */
|
2001-07-05 07:19:17 +00:00
|
|
|
if (sc->tz_active != TZ_ACTIVE_NONE)
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_ForeachPackageObject(
|
|
|
|
(ACPI_OBJECT *)sc->tz_zone.al[sc->tz_active].Pointer,
|
|
|
|
acpi_tz_switch_cooler_off, sc);
|
|
|
|
|
|
|
|
/* Turn on cooling devices that are required, if any are */
|
|
|
|
if (newactive != TZ_ACTIVE_NONE) {
|
|
|
|
acpi_ForeachPackageObject(
|
|
|
|
(ACPI_OBJECT *)sc->tz_zone.al[newactive].Pointer,
|
|
|
|
acpi_tz_switch_cooler_on, sc);
|
|
|
|
}
|
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;
|
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
|
|
|
|
|
|
|
/*
|
2001-07-05 07:19:17 +00:00
|
|
|
* If we have just become _HOT or _CRT, warn the user.
|
|
|
|
*
|
|
|
|
* We should actually shut down at this point, but it's not clear
|
|
|
|
* that some systems don't actually map _CRT to the same value as _AC0.
|
2001-06-28 06:17:16 +00:00
|
|
|
*/
|
2003-08-28 16:06:30 +00:00
|
|
|
if ((newflags & (TZ_THFLAG_HOT | TZ_THFLAG_CRT)) != 0 &&
|
|
|
|
(sc->tz_thflags & (TZ_THFLAG_HOT | TZ_THFLAG_CRT)) == 0) {
|
|
|
|
|
|
|
|
device_printf(sc->tz_dev,
|
|
|
|
"WARNING - current temperature (%d.%dC) exceeds system limits\n",
|
2002-05-25 11:18:03 +00:00
|
|
|
TZ_KELVTOC(sc->tz_temperature));
|
2001-07-05 07:19:17 +00:00
|
|
|
/* shutdown_nice(RB_POWEROFF);*/
|
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
|
|
|
|
2001-12-22 16:05:41 +00:00
|
|
|
out:
|
|
|
|
sc->tz_tmp_updating = 0;
|
2001-06-28 06:17:16 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn off all the cooling devices.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_all_off(struct acpi_tz_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-29 21:20:46 +00:00
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
2001-01-31 09:33:51 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Scan all the _ALx objects and turn them all off. */
|
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)
|
2001-06-28 06:17:16 +00:00
|
|
|
continue;
|
2001-07-07 01:49:15 +00:00
|
|
|
acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[i].Pointer,
|
2001-06-28 06:17:16 +00:00
|
|
|
acpi_tz_switch_cooler_off, sc);
|
2001-06-23 10:38:25 +00:00
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX revert any passive-cooling options.
|
|
|
|
*/
|
|
|
|
|
2001-07-05 07:19:17 +00:00
|
|
|
sc->tz_active = TZ_ACTIVE_NONE;
|
2001-07-07 01:49:15 +00:00
|
|
|
sc->tz_thflags = TZ_THFLAG_NONE;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2001-01-31 09:33:51 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Given an object, verify that it's a reference to a device of some sort,
|
|
|
|
* and try to switch it off.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg)
|
|
|
|
{
|
2001-07-07 01:49:15 +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
|
|
|
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
switch(obj->Type) {
|
2002-08-27 07:53:55 +00:00
|
|
|
case ACPI_TYPE_ANY:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s off\n",
|
|
|
|
acpi_name(obj->Reference.Handle)));
|
2002-08-27 07:53:55 +00:00
|
|
|
|
|
|
|
acpi_pwr_switch_consumer(obj->Reference.Handle, ACPI_STATE_D3);
|
|
|
|
break;
|
2001-06-28 06:17:16 +00:00
|
|
|
case ACPI_TYPE_STRING:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s off\n",
|
|
|
|
obj->String.Pointer));
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the handle for the device and turn it off.
|
|
|
|
* The String object here seems to contain a fully-qualified path, so we
|
|
|
|
* don't have to search for it in our parents.
|
|
|
|
*
|
|
|
|
* XXX This may not always be the case.
|
|
|
|
*/
|
2002-02-23 05:29:23 +00:00
|
|
|
if (ACPI_SUCCESS(AcpiGetHandle(NULL, obj->String.Pointer, &cooler)))
|
2001-06-28 06:17:16 +00:00
|
|
|
acpi_pwr_switch_consumer(cooler, ACPI_STATE_D3);
|
|
|
|
break;
|
|
|
|
default:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
|
|
|
|
"called to handle unsupported object type %d\n",
|
|
|
|
obj->Type));
|
2001-06-28 06:17:16 +00:00
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given an object, verify that it's a reference to a device of some sort,
|
|
|
|
* and try to switch it on.
|
|
|
|
*
|
|
|
|
* XXX replication of off/on function code is bad, mmmkay?
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
switch(obj->Type) {
|
2002-08-27 07:53:55 +00:00
|
|
|
case ACPI_TYPE_ANY:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s on\n",
|
|
|
|
acpi_name(obj->Reference.Handle)));
|
2002-08-27 07:53:55 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
status = acpi_pwr_switch_consumer(obj->Reference.Handle, ACPI_STATE_D0);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2002-08-27 07:53:55 +00:00
|
|
|
ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
|
2003-08-28 16:06:30 +00:00
|
|
|
"failed to activate %s - %s\n",
|
|
|
|
acpi_name(obj->Reference.Handle),
|
|
|
|
AcpiFormatException(status));
|
2002-08-27 07:53:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-06-28 06:17:16 +00:00
|
|
|
case ACPI_TYPE_STRING:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s on\n",
|
|
|
|
obj->String.Pointer));
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2001-06-29 21:20:46 +00:00
|
|
|
/*
|
|
|
|
* Find the handle for the device and turn it off.
|
|
|
|
* The String object here seems to contain a fully-qualified path, so we
|
|
|
|
* don't have to search for it in our parents.
|
|
|
|
*
|
|
|
|
* XXX This may not always be the case.
|
|
|
|
*/
|
2002-02-23 05:29:23 +00:00
|
|
|
if (ACPI_SUCCESS(AcpiGetHandle(NULL, obj->String.Pointer, &cooler))) {
|
2003-08-28 16:06:30 +00:00
|
|
|
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",
|
|
|
|
obj->String.Pointer, AcpiFormatException(status));
|
2001-07-07 01:49:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
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
|
|
|
"couldn't find %s\n", obj->String.Pointer);
|
2001-07-07 01:49:15 +00:00
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "unsupported object type %d\n",
|
2001-08-26 22:50:15 +00:00
|
|
|
obj->Type));
|
2001-06-28 06:17:16 +00:00
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2002-02-23 05:29:23 +00:00
|
|
|
if (ACPI_FAILURE(acpi_EvaluateInteger(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
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
2001-07-05 07:19:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity-check a temperature value. Assume that setpoints
|
|
|
|
* should be between 0C and 150C.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what)
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
if (*val != -1 && (*val < TZ_ZEROC || *val > TZ_ZEROC + 1500)) {
|
2001-07-05 07:19:17 +00:00
|
|
|
device_printf(sc->tz_dev, "%s value is absurd, ignored (%d.%dC)\n",
|
|
|
|
what, TZ_KELVTOC(*val));
|
|
|
|
*val = -1;
|
|
|
|
}
|
|
|
|
}
|
2001-07-07 01:49:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Respond to a sysctl on the active state node.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_tz_softc *sc;
|
|
|
|
int active;
|
|
|
|
int error;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
2001-07-07 01:49:15 +00:00
|
|
|
|
|
|
|
ACPI_LOCK;
|
|
|
|
|
|
|
|
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)
|
2001-07-07 01:49:15 +00:00
|
|
|
goto out;
|
2003-08-28 16:06:30 +00:00
|
|
|
if (active < -1 || active >= TZ_NUMLEVELS) {
|
2001-07-07 01:49:15 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
acpi_tz_monitor(sc);
|
|
|
|
|
|
|
|
out:
|
|
|
|
ACPI_UNLOCK;
|
2003-08-28 16:06:30 +00:00
|
|
|
return (error);
|
2001-07-07 01:49:15 +00:00
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Respond to a Notify event sent to the zone.
|
|
|
|
*/
|
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
|
|
|
|
2001-06-29 21:20:46 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
switch(notify) {
|
|
|
|
case TZ_NOTIFY_TEMPERATURE:
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Temperature change occurred */
|
|
|
|
AcpiOsQueueForExecution(OSD_PRIORITY_HIGH, acpi_tz_monitor, sc);
|
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 */
|
|
|
|
AcpiOsQueueForExecution(OSD_PRIORITY_HIGH,
|
|
|
|
(OSD_EXECUTION_CALLBACK)acpi_tz_establish, sc);
|
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
|
|
|
|
2001-01-31 09:33:51 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
2000-12-22 14:41:55 +00:00
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Poll the thermal zone.
|
|
|
|
*/
|
|
|
|
static void
|
2002-02-23 05:29:23 +00:00
|
|
|
acpi_tz_timeout(struct acpi_tz_softc *sc)
|
2001-06-28 06:17:16 +00:00
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Do we need to get the power profile settings? */
|
2001-07-07 01:49:15 +00:00
|
|
|
if (sc->tz_flags & TZ_FLAG_GETPROFILE) {
|
2002-03-04 18:46:13 +00:00
|
|
|
acpi_tz_power_profile((void *)sc);
|
2001-07-07 01:49:15 +00:00
|
|
|
sc->tz_flags &= ~TZ_FLAG_GETPROFILE;
|
|
|
|
}
|
|
|
|
|
2002-02-23 05:29:23 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Check the current temperature and take action based on it */
|
2002-02-23 05:29:23 +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_OBJECT_LIST args;
|
|
|
|
ACPI_OBJECT obj;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
|
2002-03-04 18:46:13 +00:00
|
|
|
int state;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
2002-03-04 18:46:13 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
ACPI_LOCK;
|
|
|
|
|
|
|
|
/* 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 */
|
2001-07-07 01:49:15 +00:00
|
|
|
obj.Type = ACPI_TYPE_INTEGER;
|
2002-03-04 18:46:13 +00:00
|
|
|
obj.Integer.Value = (state == POWER_PROFILE_PERFORMANCE) ? 0 : 1;
|
2001-07-07 01:49:15 +00:00
|
|
|
args.Count = 1;
|
|
|
|
args.Pointer = &obj;
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEvaluateObject(sc->tz_handle, "_SCP", &args, NULL);
|
|
|
|
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 */
|
|
|
|
AcpiOsQueueForExecution(OSD_PRIORITY_HIGH,
|
|
|
|
(OSD_EXECUTION_CALLBACK)acpi_tz_establish,
|
|
|
|
sc);
|
2001-07-07 01:49:15 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2001-07-07 01:49:15 +00:00
|
|
|
ACPI_UNLOCK;
|
|
|
|
}
|
|
|
|
|
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;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
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;
|
|
|
|
|
|
|
|
for (;;) {
|
2003-08-28 16:06:30 +00:00
|
|
|
tsleep(&acpi_tz_proc, PZERO, "tzpoll", hz * acpi_tz_polling_rate);
|
2002-02-23 05:29:23 +00:00
|
|
|
|
2002-10-16 17:28:53 +00:00
|
|
|
#if __FreeBSD_version >= 500000
|
2002-02-25 02:21:22 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-10-16 17:28:53 +00:00
|
|
|
#endif
|
2002-02-25 02:21:22 +00:00
|
|
|
|
2002-02-23 05:29:23 +00:00
|
|
|
if (devcount == 0)
|
|
|
|
devclass_get_devices(acpi_tz_devclass, &devs, &devcount);
|
|
|
|
|
|
|
|
ACPI_LOCK;
|
|
|
|
for (i = 0; i < devcount; i++)
|
|
|
|
acpi_tz_timeout(device_get_softc(devs[i]));
|
|
|
|
ACPI_UNLOCK;
|
2002-02-25 02:21:22 +00:00
|
|
|
|
2002-10-16 17:28:53 +00:00
|
|
|
#if __FreeBSD_version >= 500000
|
2002-02-25 02:21:22 +00:00
|
|
|
mtx_unlock(&Giant);
|
2002-10-16 17:28:53 +00:00
|
|
|
#endif
|
2002-02-23 05:29:23 +00:00
|
|
|
}
|
|
|
|
}
|