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
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/kthread.h>
35 #include <sys/mutex.h>
38 #include <sys/reboot.h>
39 #include <sys/sysctl.h>
40 #include <sys/unistd.h>
41 #include <sys/power.h>
45 #include <dev/acpica/acpivar.h>
48 * 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
57 #define TZ_NOTIFY_DEVICES 0x81
58 #define TZ_NOTIFY_LEVELS 0x82
60 #define TZ_POLLRATE 30 /* every 30 seconds by default */
62 #define TZ_NUMLEVELS 10 /* defined by ACPI spec */
65 ACPI_BUFFER al[TZ_NUMLEVELS];
77 struct acpi_tz_softc {
78 device_t tz_dev; /* device handle */
79 ACPI_HANDLE tz_handle; /* thermal zone handle */
80 int tz_temperature; /* current temperature */
81 int tz_active; /* current active cooling */
82 #define TZ_ACTIVE_NONE -1
83 int tz_requested; /* user-requested minimum active cooling */
84 int tz_thflags; /* current temperature-related flags */
85 #define TZ_THFLAG_NONE 0
86 #define TZ_THFLAG_PSV (1<<0)
87 #define TZ_THFLAG_HOT (1<<2)
88 #define TZ_THFLAG_CRT (1<<3)
90 #define TZ_FLAG_NO_SCP (1<<0) /* no _SCP method */
91 #define TZ_FLAG_GETPROFILE (1<<1) /* fetch power_profile in timeout */
92 struct timespec tz_cooling_started; /* current cooling starting time */
94 struct sysctl_ctx_list tz_sysctl_ctx; /* sysctl tree */
95 struct sysctl_oid *tz_sysctl_tree;
97 struct acpi_tz_zone tz_zone; /* thermal zone parameters */
101 static int acpi_tz_probe(device_t dev);
102 static int acpi_tz_attach(device_t dev);
103 static int acpi_tz_establish(struct acpi_tz_softc *sc);
104 static void acpi_tz_monitor(struct acpi_tz_softc *sc);
105 static void acpi_tz_all_off(struct acpi_tz_softc *sc);
106 static void acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg);
107 static void acpi_tz_switch_cooler_on(ACPI_OBJECT *obj, void *arg);
108 static void acpi_tz_getparam(struct acpi_tz_softc *sc, char *node, int *data);
109 static void acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what);
110 static int acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS);
111 static void acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context);
112 static void acpi_tz_timeout(struct acpi_tz_softc *sc);
113 static void acpi_tz_power_profile(void *arg);
115 static void acpi_tz_thread(void *arg);
116 static struct proc *acpi_tz_proc;
118 static device_method_t acpi_tz_methods[] = {
119 /* Device interface */
120 DEVMETHOD(device_probe, acpi_tz_probe),
121 DEVMETHOD(device_attach, acpi_tz_attach),
126 static driver_t acpi_tz_driver = {
129 sizeof(struct acpi_tz_softc),
132 static devclass_t acpi_tz_devclass;
133 DRIVER_MODULE(acpi_tz, acpi, acpi_tz_driver, acpi_tz_devclass, 0, 0);
135 static struct sysctl_ctx_list acpi_tz_sysctl_ctx;
136 static struct sysctl_oid *acpi_tz_sysctl_tree;
138 static int acpi_tz_min_runtime = 0;/* minimum cooling run time */
139 static int acpi_tz_polling_rate = TZ_POLLRATE;
142 * Match an ACPI thermal zone.
145 acpi_tz_probe(device_t dev)
151 /* no FUNCTION_TRACE - too noisy */
153 if ((acpi_get_type(dev) == ACPI_TYPE_THERMAL) &&
154 !acpi_disabled("thermal")) {
155 device_set_desc(dev, "thermal zone");
165 * Attach to an ACPI thermal zone.
168 acpi_tz_attach(device_t dev)
170 struct acpi_tz_softc *sc;
171 struct acpi_softc *acpi_sc;
175 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
179 sc = device_get_softc(dev);
181 sc->tz_handle = acpi_get_handle(dev);
182 sc->tz_requested = TZ_ACTIVE_NONE;
183 sc->tz_tmp_updating = 0;
186 * Parse the current state of the thermal zone and build control
189 if ((error = acpi_tz_establish(sc)) != 0)
193 * Register for any Notify events sent to this zone.
195 AcpiInstallNotifyHandler(sc->tz_handle, ACPI_DEVICE_NOTIFY,
196 acpi_tz_notify_handler, sc);
199 * Create our sysctl nodes.
201 * XXX we need a mechanism for adding nodes under ACPI.
203 if (device_get_unit(dev) == 0) {
204 acpi_sc = acpi_device_get_parent_softc(dev);
205 sysctl_ctx_init(&acpi_tz_sysctl_ctx);
206 acpi_tz_sysctl_tree = SYSCTL_ADD_NODE(&acpi_tz_sysctl_ctx,
207 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
208 OID_AUTO, "thermal", CTLFLAG_RD, 0, "");
209 SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
210 SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
211 OID_AUTO, "min_runtime", CTLFLAG_RD | CTLFLAG_RW,
212 &acpi_tz_min_runtime, 0, "minimum cooling run time in sec");
213 SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
214 SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
215 OID_AUTO, "polling_rate", CTLFLAG_RD | CTLFLAG_RW,
216 &acpi_tz_polling_rate, 0, "monitor polling rate");
218 sysctl_ctx_init(&sc->tz_sysctl_ctx);
219 sprintf(oidname, "tz%d", device_get_unit(dev));
220 sc->tz_sysctl_tree = SYSCTL_ADD_NODE(&sc->tz_sysctl_ctx,
221 SYSCTL_CHILDREN(acpi_tz_sysctl_tree), OID_AUTO,
222 oidname, CTLFLAG_RD, 0, "");
223 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
224 OID_AUTO, "temperature", CTLFLAG_RD,
225 &sc->tz_temperature, 0, "current thermal zone temperature");
226 SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
227 OID_AUTO, "active", CTLTYPE_INT | CTLFLAG_RW,
228 sc, 0, acpi_tz_active_sysctl, "I", "");
230 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
231 OID_AUTO, "thermal_flags", CTLFLAG_RD,
232 &sc->tz_thflags, 0, "thermal zone flags");
233 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
234 OID_AUTO, "_PSV", CTLFLAG_RD,
235 &sc->tz_zone.psv, 0, "");
236 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
237 OID_AUTO, "_HOT", CTLFLAG_RD,
238 &sc->tz_zone.hot, 0, "");
239 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
240 OID_AUTO, "_CRT", CTLFLAG_RD,
241 &sc->tz_zone.crt, 0, "");
242 SYSCTL_ADD_OPAQUE(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
243 OID_AUTO, "_ACx", CTLFLAG_RD, &sc->tz_zone.ac,
244 sizeof(sc->tz_zone.ac), "I", "");
248 * Register our power profile event handler, and flag it for a manual
249 * invocation by our timeout. We defer it like this so that the rest
250 * of the subsystem has time to come up.
252 EVENTHANDLER_REGISTER(power_profile_change, acpi_tz_power_profile, sc, 0);
253 sc->tz_flags |= TZ_FLAG_GETPROFILE;
256 * Don't bother evaluating/printing the temperature at this point;
257 * on many systems it'll be bogus until the EC is running.
261 * Create our thread; we only need one, it will service all of the
264 if (acpi_tz_proc == NULL) {
265 error = kthread_create(acpi_tz_thread, NULL, &acpi_tz_proc,
266 RFHIGHPID, "acpi_thermal");
268 device_printf(sc->tz_dev, "could not create thread - %d", error);
280 * Parse the current state of this thermal zone and set up to use it.
282 * Note that we may have previous state, which will have to be discarded.
285 acpi_tz_establish(struct acpi_tz_softc *sc)
291 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
296 * Power everything off and erase any existing state.
299 for (i = 0; i < TZ_NUMLEVELS; i++)
300 if (sc->tz_zone.al[i].Pointer != NULL)
301 AcpiOsFree(sc->tz_zone.al[i].Pointer);
302 if (sc->tz_zone.psl.Pointer != NULL)
303 AcpiOsFree(sc->tz_zone.psl.Pointer);
304 bzero(&sc->tz_zone, sizeof(sc->tz_zone));
307 * Evaluate thermal zone parameters.
309 for (i = 0; i < TZ_NUMLEVELS; i++) {
310 sprintf(nbuf, "_AC%d", i);
311 acpi_tz_getparam(sc, nbuf, &sc->tz_zone.ac[i]);
312 sprintf(nbuf, "_AL%d", i);
313 sc->tz_zone.al[i].Length = ACPI_ALLOCATE_BUFFER;
314 sc->tz_zone.al[i].Pointer = NULL;
315 AcpiEvaluateObject(sc->tz_handle, nbuf, NULL, &sc->tz_zone.al[i]);
316 obj = (ACPI_OBJECT *)sc->tz_zone.al[i].Pointer;
318 /* should be a package containing a list of power objects */
319 if (obj->Type != ACPI_TYPE_PACKAGE) {
320 device_printf(sc->tz_dev, "%s has unknown object type %d, rejecting\n",
326 acpi_tz_getparam(sc, "_CRT", &sc->tz_zone.crt);
327 acpi_tz_getparam(sc, "_HOT", &sc->tz_zone.hot);
328 sc->tz_zone.psl.Length = ACPI_ALLOCATE_BUFFER;
329 sc->tz_zone.psl.Pointer = NULL;
330 AcpiEvaluateObject(sc->tz_handle, "_PSL", NULL, &sc->tz_zone.psl);
331 acpi_tz_getparam(sc, "_PSV", &sc->tz_zone.psv);
332 acpi_tz_getparam(sc, "_TC1", &sc->tz_zone.tc1);
333 acpi_tz_getparam(sc, "_TC2", &sc->tz_zone.tc2);
334 acpi_tz_getparam(sc, "_TSP", &sc->tz_zone.tsp);
335 acpi_tz_getparam(sc, "_TZP", &sc->tz_zone.tzp);
338 * Sanity-check the values we've been given.
340 * XXX what do we do about systems that give us the same value for
341 * more than one of these setpoints?
343 acpi_tz_sanity(sc, &sc->tz_zone.crt, "_CRT");
344 acpi_tz_sanity(sc, &sc->tz_zone.hot, "_HOT");
345 acpi_tz_sanity(sc, &sc->tz_zone.psv, "_PSV");
346 for (i = 0; i < TZ_NUMLEVELS; i++)
347 acpi_tz_sanity(sc, &sc->tz_zone.ac[i], "_ACx");
350 * Power off everything that we've just been given.
357 static char *aclevel_string[] = {
358 "NONE", "_AC0", "_AC1", "_AC2", "_AC3", "_AC4",
359 "_AC5", "_AC6", "_AC7", "_AC8", "_AC9" };
361 static __inline const char *
362 acpi_tz_aclevel_string(int active)
364 if (active < -1 || active >= TZ_NUMLEVELS) {
365 return (aclevel_string[0]);
368 return (aclevel_string[active+1]);
372 * Evaluate the condition of a thermal zone, take appropriate actions.
375 acpi_tz_monitor(struct acpi_tz_softc *sc)
379 int newactive, newflags;
380 struct timespec curtime;
383 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
387 if (sc->tz_tmp_updating) {
390 sc->tz_tmp_updating = 1;
393 * Get the current temperature.
395 if (ACPI_FAILURE(status = acpi_EvaluateInteger(sc->tz_handle, "_TMP", &temp))) {
396 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
397 "error fetching current temperature -- %s\n",
398 AcpiFormatException(status));
399 /* XXX disable zone? go to max cooling? */
403 ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "got %d.%dC\n", TZ_KELVTOC(temp)));
404 sc->tz_temperature = temp;
407 * Work out what we ought to be doing right now.
409 * Note that the _ACx levels sort from hot to cold.
411 newactive = TZ_ACTIVE_NONE;
412 for (i = TZ_NUMLEVELS - 1; i >= 0; i--) {
413 if ((sc->tz_zone.ac[i] != -1) && (temp >= sc->tz_zone.ac[i])) {
415 if (sc->tz_active != newactive) {
416 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
417 "_AC%d: temperature %d.%d >= setpoint %d.%d\n", i,
418 TZ_KELVTOC(temp), TZ_KELVTOC(sc->tz_zone.ac[i]));
419 getnanotime(&sc->tz_cooling_started);
425 * We are going to get _ACx level down (colder side), but give a guaranteed
426 * minimum cooling run time if requested.
428 if (acpi_tz_min_runtime > 0 && sc->tz_active != TZ_ACTIVE_NONE &&
429 (newactive == TZ_ACTIVE_NONE || newactive > sc->tz_active)) {
430 getnanotime(&curtime);
431 timespecsub(&curtime, &sc->tz_cooling_started);
432 if (curtime.tv_sec < acpi_tz_min_runtime) {
433 newactive = sc->tz_active;
437 /* handle user override of active mode */
438 if (sc->tz_requested > newactive)
439 newactive = sc->tz_requested;
441 /* update temperature-related flags */
442 newflags = TZ_THFLAG_NONE;
443 if ((sc->tz_zone.psv != -1) && (temp >= sc->tz_zone.psv))
444 newflags |= TZ_THFLAG_PSV;
445 if ((sc->tz_zone.hot != -1) && (temp >= sc->tz_zone.hot))
446 newflags |= TZ_THFLAG_HOT;
447 if ((sc->tz_zone.crt != -1) && (temp >= sc->tz_zone.crt))
448 newflags |= TZ_THFLAG_CRT;
451 * If the active cooling state has changed, we have to switch things.
453 if (newactive != sc->tz_active) {
455 /* turn off the cooling devices that are on, if any are */
456 if (sc->tz_active != TZ_ACTIVE_NONE)
457 acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[sc->tz_active].Pointer,
458 acpi_tz_switch_cooler_off, sc);
460 /* turn on cooling devices that are required, if any are */
461 if (newactive != TZ_ACTIVE_NONE)
462 acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[newactive].Pointer,
463 acpi_tz_switch_cooler_on, sc);
464 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
465 "switched from %s to %s: %d.%dC\n",
466 acpi_tz_aclevel_string(sc->tz_active),
467 acpi_tz_aclevel_string(newactive), TZ_KELVTOC(temp));
468 sc->tz_active = newactive;
472 * XXX (de)activate any passive cooling that may be required.
476 * If we have just become _HOT or _CRT, warn the user.
478 * We should actually shut down at this point, but it's not clear
479 * that some systems don't actually map _CRT to the same value as _AC0.
481 if ((newflags & (TZ_THFLAG_HOT | TZ_THFLAG_CRT)) &&
482 !(sc->tz_thflags & (TZ_THFLAG_HOT | TZ_THFLAG_CRT))) {
483 device_printf(sc->tz_dev, "WARNING - current temperature (%d.%dC) exceeds system limits\n",
484 TZ_KELVTOC(sc->tz_temperature));
485 /* shutdown_nice(RB_POWEROFF);*/
487 sc->tz_thflags = newflags;
490 sc->tz_tmp_updating = 0;
495 * Turn off all the cooling devices.
498 acpi_tz_all_off(struct acpi_tz_softc *sc)
502 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
507 * Scan all the _ALx objects, and turn them all off.
509 for (i = 0; i < TZ_NUMLEVELS; i++) {
510 if (sc->tz_zone.al[i].Pointer == NULL)
512 acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[i].Pointer,
513 acpi_tz_switch_cooler_off, sc);
517 * XXX revert any passive-cooling options.
520 sc->tz_active = TZ_ACTIVE_NONE;
521 sc->tz_thflags = TZ_THFLAG_NONE;
526 * Given an object, verify that it's a reference to a device of some sort,
527 * and try to switch it off.
530 acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg)
534 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
540 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s off\n", acpi_name(obj->Reference.Handle)));
542 acpi_pwr_switch_consumer(obj->Reference.Handle, ACPI_STATE_D3);
545 case ACPI_TYPE_STRING:
546 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s off\n", obj->String.Pointer));
549 * Find the handle for the device and turn it off.
550 * The String object here seems to contain a fully-qualified path, so we
551 * don't have to search for it in our parents.
553 * XXX This may not always be the case.
555 if (ACPI_SUCCESS(AcpiGetHandle(NULL, obj->String.Pointer, &cooler)))
556 acpi_pwr_switch_consumer(cooler, ACPI_STATE_D3);
560 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to handle unsupported object type %d\n",
568 * Given an object, verify that it's a reference to a device of some sort,
569 * and try to switch it on.
571 * XXX replication of off/on function code is bad, mmmkay?
574 acpi_tz_switch_cooler_on(ACPI_OBJECT *obj, void *arg)
576 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
580 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
586 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s on\n", acpi_name(obj->Reference.Handle)));
588 if (ACPI_FAILURE(status = acpi_pwr_switch_consumer(obj->Reference.Handle, ACPI_STATE_D0))) {
589 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
590 "failed to activate %s - %s\n", acpi_name(obj->Reference.Handle),
591 AcpiFormatException(status));
595 case ACPI_TYPE_STRING:
596 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s on\n", obj->String.Pointer));
599 * Find the handle for the device and turn it off.
600 * The String object here seems to contain a fully-qualified path, so we
601 * don't have to search for it in our parents.
603 * XXX This may not always be the case.
605 if (ACPI_SUCCESS(AcpiGetHandle(NULL, obj->String.Pointer, &cooler))) {
606 if (ACPI_FAILURE(status = acpi_pwr_switch_consumer(cooler, ACPI_STATE_D0))) {
607 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
608 "failed to activate %s - %s\n",
609 obj->String.Pointer, AcpiFormatException(status));
612 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
613 "couldn't find %s\n", obj->String.Pointer);
618 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to handle unsupported object type %d\n",
626 * Read/debug-print a parameter, default it to -1.
629 acpi_tz_getparam(struct acpi_tz_softc *sc, char *node, int *data)
632 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
636 if (ACPI_FAILURE(acpi_EvaluateInteger(sc->tz_handle, node, data))) {
639 ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "%s.%s = %d\n", acpi_name(sc->tz_handle),
646 * Sanity-check a temperature value. Assume that setpoints
647 * should be between 0C and 150C.
650 acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what)
652 if ((*val != -1) && ((*val < TZ_ZEROC) || (*val > (TZ_ZEROC + 1500)))) {
653 device_printf(sc->tz_dev, "%s value is absurd, ignored (%d.%dC)\n",
654 what, TZ_KELVTOC(*val));
660 * Respond to a sysctl on the active state node.
663 acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS)
665 struct acpi_tz_softc *sc;
671 sc = (struct acpi_tz_softc *)oidp->oid_arg1;
672 active = sc->tz_active;
673 error = sysctl_handle_int(oidp, &active, 0, req);
675 /* error or no new value */
676 if ((error != 0) || (req->newptr == NULL))
680 if ((active < -1) || (active >= TZ_NUMLEVELS)) {
685 /* set new preferred level and re-switch */
686 sc->tz_requested = active;
695 * Respond to a Notify event sent to the zone.
698 acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
700 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)context;
702 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
707 case TZ_NOTIFY_TEMPERATURE:
708 /* temperature change occurred */
709 AcpiOsQueueForExecution(OSD_PRIORITY_HIGH, (OSD_EXECUTION_CALLBACK)acpi_tz_monitor, sc);
711 case TZ_NOTIFY_DEVICES:
712 case TZ_NOTIFY_LEVELS:
713 /* zone devices/setpoints changed */
714 AcpiOsQueueForExecution(OSD_PRIORITY_HIGH, (OSD_EXECUTION_CALLBACK)acpi_tz_establish, sc);
717 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
718 "unknown Notify event 0x%x\n", notify);
725 * Poll the thermal zone.
728 acpi_tz_timeout(struct acpi_tz_softc *sc)
731 /* do we need to get the power profile settings? */
732 if (sc->tz_flags & TZ_FLAG_GETPROFILE) {
733 acpi_tz_power_profile((void *)sc);
734 sc->tz_flags &= ~TZ_FLAG_GETPROFILE;
739 /* check the current temperature and take action based on it */
742 /* XXX passive cooling actions? */
746 * System power profile may have changed; fetch and notify the
747 * thermal zone accordingly.
749 * Since this can be called from an arbitrary eventhandler, it needs
750 * to get the ACPI lock itself.
753 acpi_tz_power_profile(void *arg)
755 ACPI_OBJECT_LIST args;
758 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
761 state = power_profile_get_state();
762 if (state != POWER_PROFILE_PERFORMANCE &&
763 state != POWER_PROFILE_ECONOMY) {
769 /* check that we haven't decided there's no _SCP method */
770 if (!(sc->tz_flags & TZ_FLAG_NO_SCP)) {
772 /* call _SCP to set the new profile */
773 obj.Type = ACPI_TYPE_INTEGER;
774 obj.Integer.Value = (state == POWER_PROFILE_PERFORMANCE) ? 0 : 1;
777 if (ACPI_FAILURE(status = AcpiEvaluateObject(sc->tz_handle, "_SCP", &args, NULL))) {
778 if (status != AE_NOT_FOUND)
779 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
780 "can't evaluate %s._SCP - %s\n", acpi_name(sc->tz_handle),
781 AcpiFormatException(status));
782 sc->tz_flags |= TZ_FLAG_NO_SCP;
784 /* we have to re-evaluate the entire zone now */
785 AcpiOsQueueForExecution(OSD_PRIORITY_HIGH, (OSD_EXECUTION_CALLBACK)acpi_tz_establish, sc);
792 * Thermal zone monitor thread.
795 acpi_tz_thread(void *arg)
800 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
807 tsleep(&acpi_tz_proc, PZERO, "nothing", hz * acpi_tz_polling_rate);
812 devclass_get_devices(acpi_tz_devclass, &devs, &devcount);
815 for (i = 0; i < devcount; i++)
816 acpi_tz_timeout(device_get_softc(devs[i]));