2 * Copyright (c) 2000, 2001 Michael Smith
3 * Copyright (c) 2000 BSDi
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/acpica/acpi_thermal.c,v 1.47 2004/05/30 20:08:23 phk Exp $
28 * $DragonFly: src/sys/dev/acpica5/acpi_thermal.c,v 1.7 2007/01/17 17:31:19 y0netan1 Exp $
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/kthread.h>
35 #include <sys/module.h>
38 #include <sys/reboot.h>
39 #include <sys/sysctl.h>
40 #include <sys/unistd.h>
41 #include <sys/power.h>
42 #include <sys/thread2.h>
43 #include <sys/sensors.h>
47 #include <dev/acpica5/acpivar.h>
49 /* Hooks for the ACPI CA debugging infrastructure */
50 #define _COMPONENT ACPI_THERMAL
51 ACPI_MODULE_NAME("THERMAL")
54 #define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), (((x) - TZ_ZEROC) % 10)
56 #define TZ_NOTIFY_TEMPERATURE 0x80 /* Temperature changed. */
57 #define TZ_NOTIFY_LEVELS 0x81 /* Cooling levels changed. */
58 #define TZ_NOTIFY_DEVICES 0x82 /* Device lists changed. */
59 #define TZ_NOTIFY_CRITICAL 0xcc /* Fake notify that _CRT/_HOT reached. */
61 /* Check for temperature changes every 10 seconds by default */
62 #define TZ_POLLRATE 10
64 /* Make sure the reported temperature is valid for this number of polls. */
65 #define TZ_VALIDCHECKS 3
67 /* Notify the user we will be shutting down in one more poll cycle. */
68 #define TZ_NOTIFYCOUNT (TZ_VALIDCHECKS - 1)
70 /* ACPI spec defines this */
71 #define TZ_NUMLEVELS 10
74 ACPI_BUFFER al[TZ_NUMLEVELS];
85 struct acpi_tz_softc {
87 ACPI_HANDLE tz_handle; /*Thermal zone handle*/
88 int tz_temperature; /*Current temperature*/
89 int tz_active; /*Current active cooling*/
90 #define TZ_ACTIVE_NONE -1
91 int tz_requested; /*Minimum active cooling*/
92 int tz_thflags; /*Current temp-related flags*/
93 #define TZ_THFLAG_NONE 0
94 #define TZ_THFLAG_PSV (1<<0)
95 #define TZ_THFLAG_HOT (1<<2)
96 #define TZ_THFLAG_CRT (1<<3)
98 #define TZ_FLAG_NO_SCP (1<<0) /*No _SCP method*/
99 #define TZ_FLAG_GETPROFILE (1<<1) /*Get power_profile in timeout*/
100 struct timespec tz_cooling_started;
101 /*Current cooling starting time*/
103 struct sysctl_ctx_list tz_sysctl_ctx;
104 struct sysctl_oid *tz_sysctl_tree;
106 struct acpi_tz_zone tz_zone; /*Thermal zone parameters*/
109 /* sensors(9) related */
110 struct ksensordev sensordev;
111 struct ksensor sensor;
114 static int acpi_tz_probe(device_t dev);
115 static int acpi_tz_attach(device_t dev);
116 static int acpi_tz_establish(struct acpi_tz_softc *sc);
117 static void acpi_tz_monitor(void *Context);
118 static void acpi_tz_all_off(struct acpi_tz_softc *sc);
119 static void acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg);
120 static void acpi_tz_switch_cooler_on(ACPI_OBJECT *obj, void *arg);
121 static void acpi_tz_getparam(struct acpi_tz_softc *sc, char *node,
123 static void acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what);
124 static int acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS);
125 static void acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify,
127 static void acpi_tz_timeout(struct acpi_tz_softc *sc);
128 static void acpi_tz_power_profile(void *arg);
129 static void acpi_tz_thread(void *arg);
131 static device_method_t acpi_tz_methods[] = {
132 /* Device interface */
133 DEVMETHOD(device_probe, acpi_tz_probe),
134 DEVMETHOD(device_attach, acpi_tz_attach),
139 static driver_t acpi_tz_driver = {
142 sizeof(struct acpi_tz_softc),
145 static devclass_t acpi_tz_devclass;
146 DRIVER_MODULE(acpi_tz, acpi, acpi_tz_driver, acpi_tz_devclass, 0, 0);
147 MODULE_DEPEND(acpi_tz, acpi, 1, 1, 1);
149 static struct sysctl_ctx_list acpi_tz_sysctl_ctx;
150 static struct sysctl_oid *acpi_tz_sysctl_tree;
152 /* Minimum cooling run time */
153 static int acpi_tz_min_runtime = 0;
154 static int acpi_tz_polling_rate = TZ_POLLRATE;
156 /* Timezone polling thread */
157 static struct thread *acpi_tz_td;
160 * Match an ACPI thermal zone.
163 acpi_tz_probe(device_t dev)
170 /* No FUNCTION_TRACE - too noisy */
172 if (acpi_get_type(dev) == ACPI_TYPE_THERMAL && !acpi_disabled("thermal")) {
173 device_set_desc(dev, "Thermal Zone");
183 * Attach to an ACPI thermal zone.
186 acpi_tz_attach(device_t dev)
188 struct acpi_tz_softc *sc;
189 struct acpi_softc *acpi_sc;
194 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
198 sc = device_get_softc(dev);
200 sc->tz_handle = acpi_get_handle(dev);
201 sc->tz_requested = TZ_ACTIVE_NONE;
202 sc->tz_tmp_updating = 0;
205 * Parse the current state of the thermal zone and build control
208 if ((error = acpi_tz_establish(sc)) != 0)
212 * Register for any Notify events sent to this zone.
214 AcpiInstallNotifyHandler(sc->tz_handle, ACPI_DEVICE_NOTIFY,
215 acpi_tz_notify_handler, sc);
218 * Create our sysctl nodes.
220 * XXX we need a mechanism for adding nodes under ACPI.
222 if (device_get_unit(dev) == 0) {
223 acpi_sc = acpi_device_get_parent_softc(dev);
224 sysctl_ctx_init(&acpi_tz_sysctl_ctx);
225 acpi_tz_sysctl_tree = SYSCTL_ADD_NODE(&acpi_tz_sysctl_ctx,
226 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
227 OID_AUTO, "thermal", CTLFLAG_RD, 0, "");
228 SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
229 SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
230 OID_AUTO, "min_runtime", CTLFLAG_RD | CTLFLAG_RW,
231 &acpi_tz_min_runtime, 0,
232 "minimum cooling run time in sec");
233 SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
234 SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
235 OID_AUTO, "polling_rate", CTLFLAG_RD | CTLFLAG_RW,
236 &acpi_tz_polling_rate, 0, "monitor polling rate");
238 sysctl_ctx_init(&sc->tz_sysctl_ctx);
239 ksprintf(oidname, "tz%d", device_get_unit(dev));
240 sc->tz_sysctl_tree = SYSCTL_ADD_NODE(&sc->tz_sysctl_ctx,
241 SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
242 OID_AUTO, oidname, CTLFLAG_RD, 0, "");
243 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
244 OID_AUTO, "temperature", CTLFLAG_RD,
245 &sc->tz_temperature, 0, "current thermal zone temperature");
246 SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
247 OID_AUTO, "active", CTLTYPE_INT | CTLFLAG_RW,
248 sc, 0, acpi_tz_active_sysctl, "I", "");
250 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
251 OID_AUTO, "thermal_flags", CTLFLAG_RD,
252 &sc->tz_thflags, 0, "thermal zone flags");
253 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
254 OID_AUTO, "_PSV", CTLFLAG_RD,
255 &sc->tz_zone.psv, 0, "");
256 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
257 OID_AUTO, "_HOT", CTLFLAG_RD,
258 &sc->tz_zone.hot, 0, "");
259 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
260 OID_AUTO, "_CRT", CTLFLAG_RD,
261 &sc->tz_zone.crt, 0, "");
262 SYSCTL_ADD_OPAQUE(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
263 OID_AUTO, "_ACx", CTLFLAG_RD, &sc->tz_zone.ac,
264 sizeof(sc->tz_zone.ac), "I", "");
267 * Register our power profile event handler, and flag it for a manual
268 * invocation by our timeout. We defer it like this so that the rest
269 * of the subsystem has time to come up.
271 EVENTHANDLER_REGISTER(power_profile_change, acpi_tz_power_profile, sc, 0);
272 sc->tz_flags |= TZ_FLAG_GETPROFILE;
275 * Don't bother evaluating/printing the temperature at this point;
276 * on many systems it'll be bogus until the EC is running.
280 * Create our thread; we only need one, it will service all of the
283 if (acpi_tz_td == NULL) {
284 error = kthread_create(acpi_tz_thread, NULL, &acpi_tz_td,
285 RFHIGHPID, 0, "acpi_thermal");
287 device_printf(sc->tz_dev, "could not create thread - %d",
292 /* Attach sensors(9). */
293 strlcpy(sc->sensordev.xname, device_get_nameunit(sc->tz_dev),
294 sizeof(sc->sensordev.xname));
296 sc->sensor.type = SENSOR_TEMP;
297 sensor_attach(&sc->sensordev, &sc->sensor);
299 sensordev_install(&sc->sensordev);
304 return_VALUE (error);
308 * Parse the current state of this thermal zone and set up to use it.
310 * Note that we may have previous state, which will have to be discarded.
313 acpi_tz_establish(struct acpi_tz_softc *sc)
319 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
323 /* Power everything off and erase any existing state. */
325 for (i = 0; i < TZ_NUMLEVELS; i++)
326 if (sc->tz_zone.al[i].Pointer != NULL)
327 AcpiOsFree(sc->tz_zone.al[i].Pointer);
328 if (sc->tz_zone.psl.Pointer != NULL)
329 AcpiOsFree(sc->tz_zone.psl.Pointer);
330 bzero(&sc->tz_zone, sizeof(sc->tz_zone));
332 /* Evaluate thermal zone parameters. */
333 for (i = 0; i < TZ_NUMLEVELS; i++) {
334 ksprintf(nbuf, "_AC%d", i);
335 acpi_tz_getparam(sc, nbuf, &sc->tz_zone.ac[i]);
336 ksprintf(nbuf, "_AL%d", i);
337 sc->tz_zone.al[i].Length = ACPI_ALLOCATE_BUFFER;
338 sc->tz_zone.al[i].Pointer = NULL;
339 AcpiEvaluateObject(sc->tz_handle, nbuf, NULL, &sc->tz_zone.al[i]);
340 obj = (ACPI_OBJECT *)sc->tz_zone.al[i].Pointer;
342 /* Should be a package containing a list of power objects */
343 if (obj->Type != ACPI_TYPE_PACKAGE) {
344 device_printf(sc->tz_dev, "%s has unknown type %d, rejecting\n",
346 return_VALUE (ENXIO);
350 acpi_tz_getparam(sc, "_CRT", &sc->tz_zone.crt);
351 acpi_tz_getparam(sc, "_HOT", &sc->tz_zone.hot);
352 sc->tz_zone.psl.Length = ACPI_ALLOCATE_BUFFER;
353 sc->tz_zone.psl.Pointer = NULL;
354 AcpiEvaluateObject(sc->tz_handle, "_PSL", NULL, &sc->tz_zone.psl);
355 acpi_tz_getparam(sc, "_PSV", &sc->tz_zone.psv);
356 acpi_tz_getparam(sc, "_TC1", &sc->tz_zone.tc1);
357 acpi_tz_getparam(sc, "_TC2", &sc->tz_zone.tc2);
358 acpi_tz_getparam(sc, "_TSP", &sc->tz_zone.tsp);
359 acpi_tz_getparam(sc, "_TZP", &sc->tz_zone.tzp);
362 * Sanity-check the values we've been given.
364 * XXX what do we do about systems that give us the same value for
365 * more than one of these setpoints?
367 acpi_tz_sanity(sc, &sc->tz_zone.crt, "_CRT");
368 acpi_tz_sanity(sc, &sc->tz_zone.hot, "_HOT");
369 acpi_tz_sanity(sc, &sc->tz_zone.psv, "_PSV");
370 for (i = 0; i < TZ_NUMLEVELS; i++)
371 acpi_tz_sanity(sc, &sc->tz_zone.ac[i], "_ACx");
374 * Power off everything that we've just been given.
381 static char *aclevel_string[] = {
382 "NONE", "_AC0", "_AC1", "_AC2", "_AC3", "_AC4",
383 "_AC5", "_AC6", "_AC7", "_AC8", "_AC9" };
385 static __inline const char *
386 acpi_tz_aclevel_string(int active)
388 if (active < -1 || active >= TZ_NUMLEVELS)
389 return (aclevel_string[0]);
391 return (aclevel_string[active+1]);
395 * Evaluate the condition of a thermal zone, take appropriate actions.
398 acpi_tz_monitor(void *Context)
400 struct acpi_tz_softc *sc;
401 struct timespec curtime;
404 int newactive, newflags;
407 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
411 sc = (struct acpi_tz_softc *)Context;
412 if (sc->tz_tmp_updating)
414 sc->tz_tmp_updating = 1;
416 /* Get the current temperature. */
417 status = acpi_GetInteger(sc->tz_handle, "_TMP", &temp);
418 if (ACPI_FAILURE(status)) {
419 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
420 "error fetching current temperature -- %s\n",
421 AcpiFormatException(status));
422 /* XXX disable zone? go to max cooling? */
426 ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "got %d.%dC\n", TZ_KELVTOC(temp)));
427 sc->tz_temperature = temp;
429 if(sc->tz_temperature == -1)
430 sc->sensor.flags &= ~SENSOR_FINVALID;
431 sc->sensor.value = sc->tz_temperature * 100000;
434 * Work out what we ought to be doing right now.
436 * Note that the _ACx levels sort from hot to cold.
438 newactive = TZ_ACTIVE_NONE;
439 for (i = TZ_NUMLEVELS - 1; i >= 0; i--) {
440 if ((sc->tz_zone.ac[i] != -1) && (temp >= sc->tz_zone.ac[i])) {
442 if (sc->tz_active != newactive) {
443 ACPI_VPRINT(sc->tz_dev,
444 acpi_device_get_parent_softc(sc->tz_dev),
445 "_AC%d: temperature %d.%d >= setpoint %d.%d\n", i,
446 TZ_KELVTOC(temp), TZ_KELVTOC(sc->tz_zone.ac[i]));
447 getnanotime(&sc->tz_cooling_started);
453 * We are going to get _ACx level down (colder side), but give a guaranteed
454 * minimum cooling run time if requested.
456 if (acpi_tz_min_runtime > 0 && sc->tz_active != TZ_ACTIVE_NONE &&
457 (newactive == TZ_ACTIVE_NONE || newactive > sc->tz_active)) {
459 getnanotime(&curtime);
460 timespecsub(&curtime, &sc->tz_cooling_started);
461 if (curtime.tv_sec < acpi_tz_min_runtime)
462 newactive = sc->tz_active;
465 /* Handle user override of active mode */
466 if (sc->tz_requested != TZ_ACTIVE_NONE && sc->tz_requested < newactive)
467 newactive = sc->tz_requested;
469 /* update temperature-related flags */
470 newflags = TZ_THFLAG_NONE;
471 if (sc->tz_zone.psv != -1 && temp >= sc->tz_zone.psv)
472 newflags |= TZ_THFLAG_PSV;
473 if (sc->tz_zone.hot != -1 && temp >= sc->tz_zone.hot)
474 newflags |= TZ_THFLAG_HOT;
475 if (sc->tz_zone.crt != -1 && temp >= sc->tz_zone.crt)
476 newflags |= TZ_THFLAG_CRT;
478 /* If the active cooling state has changed, we have to switch things. */
479 if (newactive != sc->tz_active) {
480 /* Turn off the cooling devices that are on, if any are */
481 if (sc->tz_active != TZ_ACTIVE_NONE)
482 acpi_ForeachPackageObject(
483 (ACPI_OBJECT *)sc->tz_zone.al[sc->tz_active].Pointer,
484 acpi_tz_switch_cooler_off, sc);
486 /* Turn on cooling devices that are required, if any are */
487 if (newactive != TZ_ACTIVE_NONE) {
488 acpi_ForeachPackageObject(
489 (ACPI_OBJECT *)sc->tz_zone.al[newactive].Pointer,
490 acpi_tz_switch_cooler_on, sc);
492 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
493 "switched from %s to %s: %d.%dC\n",
494 acpi_tz_aclevel_string(sc->tz_active),
495 acpi_tz_aclevel_string(newactive), TZ_KELVTOC(temp));
496 sc->tz_active = newactive;
499 /* XXX (de)activate any passive cooling that may be required. */
502 * If the temperature is at _HOT or _CRT, increment our event count.
503 * If it has occurred enough times, shutdown the system. This is
504 * needed because some systems will report an invalid high temperature
505 * for one poll cycle. It is suspected this is due to the embedded
506 * controller timing out. A typical value is 138C for one cycle on
507 * a system that is otherwise 65C.
509 * If we're almost at that threshold, notify the user through devd(8).
511 if ((newflags & (TZ_THFLAG_HOT | TZ_THFLAG_CRT)) != 0) {
512 sc->tz_validchecks++;
513 if (sc->tz_validchecks == TZ_VALIDCHECKS) {
514 device_printf(sc->tz_dev,
515 "WARNING - current temperature (%d.%dC) exceeds safe limits\n",
516 TZ_KELVTOC(sc->tz_temperature));
517 shutdown_nice(RB_POWEROFF);
518 } else if (sc->tz_validchecks == TZ_NOTIFYCOUNT)
519 acpi_UserNotify("Thermal", sc->tz_handle, TZ_NOTIFY_CRITICAL);
521 sc->tz_validchecks = 0;
523 sc->tz_thflags = newflags;
526 sc->tz_tmp_updating = 0;
531 * Turn off all the cooling devices.
534 acpi_tz_all_off(struct acpi_tz_softc *sc)
538 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
542 /* Scan all the _ALx objects and turn them all off. */
543 for (i = 0; i < TZ_NUMLEVELS; i++) {
544 if (sc->tz_zone.al[i].Pointer == NULL)
546 acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[i].Pointer,
547 acpi_tz_switch_cooler_off, sc);
551 * XXX revert any passive-cooling options.
554 sc->tz_active = TZ_ACTIVE_NONE;
555 sc->tz_thflags = TZ_THFLAG_NONE;
561 * Given an object, verify that it's a reference to a device of some sort,
562 * and try to switch it off.
565 acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg)
569 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
573 cooler = acpi_GetReference(NULL, obj);
574 if (cooler == NULL) {
575 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get handle\n"));
579 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s off\n",
581 acpi_pwr_switch_consumer(cooler, ACPI_STATE_D3);
587 * Given an object, verify that it's a reference to a device of some sort,
588 * and try to switch it on.
590 * XXX replication of off/on function code is bad.
593 acpi_tz_switch_cooler_on(ACPI_OBJECT *obj, void *arg)
595 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
599 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
603 cooler = acpi_GetReference(NULL, obj);
604 if (cooler == NULL) {
605 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get handle\n"));
609 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s on\n",
611 status = acpi_pwr_switch_consumer(cooler, ACPI_STATE_D0);
612 if (ACPI_FAILURE(status)) {
613 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
614 "failed to activate %s - %s\n", acpi_name(cooler),
615 AcpiFormatException(status));
622 * Read/debug-print a parameter, default it to -1.
625 acpi_tz_getparam(struct acpi_tz_softc *sc, char *node, int *data)
628 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
632 if (ACPI_FAILURE(acpi_GetInteger(sc->tz_handle, node, data))) {
635 ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "%s.%s = %d\n",
636 acpi_name(sc->tz_handle), node, *data));
643 * Sanity-check a temperature value. Assume that setpoints
644 * should be between 0C and 150C.
647 acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what)
649 if (*val != -1 && (*val < TZ_ZEROC || *val > TZ_ZEROC + 1500)) {
650 device_printf(sc->tz_dev, "%s value is absurd, ignored (%d.%dC)\n",
651 what, TZ_KELVTOC(*val));
657 * Respond to a sysctl on the active state node.
660 acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS)
662 struct acpi_tz_softc *sc;
669 sc = (struct acpi_tz_softc *)oidp->oid_arg1;
670 active = sc->tz_active;
671 error = sysctl_handle_int(oidp, &active, 0, req);
673 /* Error or no new value */
674 if (error != 0 || req->newptr == NULL)
676 if (active < -1 || active >= TZ_NUMLEVELS) {
681 /* Set new preferred level and re-switch */
682 sc->tz_requested = active;
691 * Respond to a Notify event sent to the zone.
694 acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
696 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)context;
698 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
703 case TZ_NOTIFY_TEMPERATURE:
704 /* Temperature change occurred */
705 AcpiOsExecute(OSL_NOTIFY_HANDLER, acpi_tz_monitor, sc);
707 case TZ_NOTIFY_DEVICES:
708 case TZ_NOTIFY_LEVELS:
709 /* Zone devices/setpoints changed */
710 AcpiOsExecute(OSL_NOTIFY_HANDLER,
711 (ACPI_OSD_EXEC_CALLBACK)acpi_tz_establish, sc);
714 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
715 "unknown Notify event 0x%x\n", notify);
719 acpi_UserNotify("Thermal", h, notify);
725 * Poll the thermal zone.
728 acpi_tz_timeout(struct acpi_tz_softc *sc)
730 /* Do we need to get the power profile settings? */
731 if (sc->tz_flags & TZ_FLAG_GETPROFILE) {
732 acpi_tz_power_profile((void *)sc);
733 sc->tz_flags &= ~TZ_FLAG_GETPROFILE;
738 /* Check the current temperature and take action based on it */
741 /* XXX passive cooling actions? */
745 * System power profile may have changed; fetch and notify the
746 * thermal zone accordingly.
748 * Since this can be called from an arbitrary eventhandler, it needs
749 * to get the ACPI lock itself.
752 acpi_tz_power_profile(void *arg)
755 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
759 state = power_profile_get_state();
760 if (state != POWER_PROFILE_PERFORMANCE && state != POWER_PROFILE_ECONOMY)
765 /* check that we haven't decided there's no _SCP method */
766 if ((sc->tz_flags & TZ_FLAG_NO_SCP) == 0) {
768 /* Call _SCP to set the new profile */
769 status = acpi_SetInteger(sc->tz_handle, "_SCP",
770 (state == POWER_PROFILE_PERFORMANCE) ? 0 : 1);
771 if (ACPI_FAILURE(status)) {
772 if (status != AE_NOT_FOUND)
773 ACPI_VPRINT(sc->tz_dev,
774 acpi_device_get_parent_softc(sc->tz_dev),
775 "can't evaluate %s._SCP - %s\n",
776 acpi_name(sc->tz_handle),
777 AcpiFormatException(status));
778 sc->tz_flags |= TZ_FLAG_NO_SCP;
780 /* We have to re-evaluate the entire zone now */
781 AcpiOsExecute(OSL_NOTIFY_HANDLER,
782 (ACPI_OSD_EXEC_CALLBACK)acpi_tz_establish,
791 * Thermal zone monitor thread.
794 acpi_tz_thread(void *arg)
800 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
806 tsleep(&acpi_tz_td, 0, "tzpoll", hz * acpi_tz_polling_rate);
808 #if __FreeBSD_version >= 500000
813 devclass_get_devices(acpi_tz_devclass, &devs, &devcount);
816 for (i = 0; i < devcount; i++)
817 acpi_tz_timeout(device_get_softc(devs[i]));
820 #if __FreeBSD_version >= 500000