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.29.6.1 2003/08/22 20:49:20 jhb Exp $
28 * $DragonFly: src/sys/dev/acpica/Attic/acpi_thermal.c,v 1.3 2004/02/13 00:25:17 joerg Exp $
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/kthread.h>
37 #include <sys/reboot.h>
38 #include <sys/sysctl.h>
39 #include <sys/unistd.h>
40 #include <sys/power.h>
44 #include <dev/acpica/acpivar.h>
47 * Hooks for the ACPI CA debugging infrastructure
49 #define _COMPONENT ACPI_THERMAL
50 ACPI_MODULE_NAME("THERMAL")
53 #define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), (((x) - TZ_ZEROC) % 10)
55 #define TZ_NOTIFY_TEMPERATURE 0x80
56 #define TZ_NOTIFY_DEVICES 0x81
57 #define TZ_NOTIFY_LEVELS 0x82
59 #define TZ_POLLRATE 30 /* every 30 seconds by default */
61 #define TZ_NUMLEVELS 10 /* defined by ACPI spec */
64 ACPI_BUFFER al[TZ_NUMLEVELS];
76 struct acpi_tz_softc {
77 device_t tz_dev; /* device handle */
78 ACPI_HANDLE tz_handle; /* thermal zone handle */
79 int tz_temperature; /* current temperature */
80 int tz_active; /* current active cooling */
81 #define TZ_ACTIVE_NONE -1
82 int tz_requested; /* user-requested minimum active cooling */
83 int tz_thflags; /* current temperature-related flags */
84 #define TZ_THFLAG_NONE 0
85 #define TZ_THFLAG_PSV (1<<0)
86 #define TZ_THFLAG_HOT (1<<2)
87 #define TZ_THFLAG_CRT (1<<3)
89 #define TZ_FLAG_NO_SCP (1<<0) /* no _SCP method */
90 #define TZ_FLAG_GETPROFILE (1<<1) /* fetch power_profile in timeout */
91 struct timespec tz_cooling_started; /* current cooling starting time */
93 struct sysctl_ctx_list tz_sysctl_ctx; /* sysctl tree */
94 struct sysctl_oid *tz_sysctl_tree;
96 struct acpi_tz_zone tz_zone; /* thermal zone parameters */
100 static int acpi_tz_probe(device_t dev);
101 static int acpi_tz_attach(device_t dev);
102 static int acpi_tz_establish(struct acpi_tz_softc *sc);
103 static void acpi_tz_monitor(struct acpi_tz_softc *sc);
104 static void acpi_tz_all_off(struct acpi_tz_softc *sc);
105 static void acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg);
106 static void acpi_tz_switch_cooler_on(ACPI_OBJECT *obj, void *arg);
107 static void acpi_tz_getparam(struct acpi_tz_softc *sc, char *node, int *data);
108 static void acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what);
109 static int acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS);
110 static void acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context);
111 static void acpi_tz_timeout(struct acpi_tz_softc *sc);
112 static void acpi_tz_power_profile(void *arg);
114 static void acpi_tz_thread(void *arg);
115 static struct thread *acpi_tz_proc;
117 static device_method_t acpi_tz_methods[] = {
118 /* Device interface */
119 DEVMETHOD(device_probe, acpi_tz_probe),
120 DEVMETHOD(device_attach, acpi_tz_attach),
125 static driver_t acpi_tz_driver = {
128 sizeof(struct acpi_tz_softc),
131 static devclass_t acpi_tz_devclass;
132 DRIVER_MODULE(acpi_tz, acpi, acpi_tz_driver, acpi_tz_devclass, 0, 0);
134 static struct sysctl_ctx_list acpi_tz_sysctl_ctx;
135 static struct sysctl_oid *acpi_tz_sysctl_tree;
137 static int acpi_tz_min_runtime = 0;/* minimum cooling run time */
138 static int acpi_tz_polling_rate = TZ_POLLRATE;
141 * Match an ACPI thermal zone.
144 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;
176 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
180 sc = device_get_softc(dev);
182 sc->tz_handle = acpi_get_handle(dev);
183 sc->tz_requested = TZ_ACTIVE_NONE;
184 sc->tz_tmp_updating = 0;
187 * Parse the current state of the thermal zone and build control
190 if ((error = acpi_tz_establish(sc)) != 0)
194 * Register for any Notify events sent to this zone.
196 AcpiInstallNotifyHandler(sc->tz_handle, ACPI_DEVICE_NOTIFY,
197 acpi_tz_notify_handler, sc);
200 * Create our sysctl nodes.
202 * XXX we need a mechanism for adding nodes under ACPI.
204 if (device_get_unit(dev) == 0) {
205 acpi_sc = acpi_device_get_parent_softc(dev);
206 sysctl_ctx_init(&acpi_tz_sysctl_ctx);
207 acpi_tz_sysctl_tree = SYSCTL_ADD_NODE(&acpi_tz_sysctl_ctx,
208 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
209 OID_AUTO, "thermal", CTLFLAG_RD, 0, "");
210 SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
211 SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
212 OID_AUTO, "min_runtime", CTLFLAG_RD | CTLFLAG_RW,
213 &acpi_tz_min_runtime, 0, "minimum cooling run time in sec");
214 SYSCTL_ADD_INT(&acpi_tz_sysctl_ctx,
215 SYSCTL_CHILDREN(acpi_tz_sysctl_tree),
216 OID_AUTO, "polling_rate", CTLFLAG_RD | CTLFLAG_RW,
217 &acpi_tz_polling_rate, 0, "monitor polling rate");
219 sysctl_ctx_init(&sc->tz_sysctl_ctx);
220 sprintf(oidname, "tz%d", device_get_unit(dev));
221 sc->tz_sysctl_tree = SYSCTL_ADD_NODE(&sc->tz_sysctl_ctx,
222 SYSCTL_CHILDREN(acpi_tz_sysctl_tree), OID_AUTO,
223 oidname, CTLFLAG_RD, 0, "");
224 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
225 OID_AUTO, "temperature", CTLFLAG_RD,
226 &sc->tz_temperature, 0, "current thermal zone temperature");
227 SYSCTL_ADD_PROC(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
228 OID_AUTO, "active", CTLTYPE_INT | CTLFLAG_RW,
229 sc, 0, acpi_tz_active_sysctl, "I", "");
231 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
232 OID_AUTO, "thermal_flags", CTLFLAG_RD,
233 &sc->tz_thflags, 0, "thermal zone flags");
234 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
235 OID_AUTO, "_PSV", CTLFLAG_RD,
236 &sc->tz_zone.psv, 0, "");
237 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
238 OID_AUTO, "_HOT", CTLFLAG_RD,
239 &sc->tz_zone.hot, 0, "");
240 SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
241 OID_AUTO, "_CRT", CTLFLAG_RD,
242 &sc->tz_zone.crt, 0, "");
243 SYSCTL_ADD_OPAQUE(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
244 OID_AUTO, "_ACx", CTLFLAG_RD, &sc->tz_zone.ac,
245 sizeof(sc->tz_zone.ac), "I", "");
249 * Register our power profile event handler, and flag it for a manual
250 * invocation by our timeout. We defer it like this so that the rest
251 * of the subsystem has time to come up.
253 EVENTHANDLER_REGISTER(power_profile_change, acpi_tz_power_profile, sc, 0);
254 sc->tz_flags |= TZ_FLAG_GETPROFILE;
257 * Don't bother evaluating/printing the temperature at this point;
258 * on many systems it'll be bogus until the EC is running.
262 * Create our thread; we only need one, it will service all of the
265 if (acpi_tz_proc == NULL) {
266 error = kthread_create(acpi_tz_thread, NULL, &acpi_tz_proc,
267 RFHIGHPID, 0, "acpi_thermal");
269 device_printf(sc->tz_dev, "could not create thread - %d", error);
281 * Parse the current state of this thermal zone and set up to use it.
283 * Note that we may have previous state, which will have to be discarded.
286 acpi_tz_establish(struct acpi_tz_softc *sc)
292 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
297 * Power everything off and erase any existing state.
300 for (i = 0; i < TZ_NUMLEVELS; i++)
301 if (sc->tz_zone.al[i].Pointer != NULL)
302 AcpiOsFree(sc->tz_zone.al[i].Pointer);
303 if (sc->tz_zone.psl.Pointer != NULL)
304 AcpiOsFree(sc->tz_zone.psl.Pointer);
305 bzero(&sc->tz_zone, sizeof(sc->tz_zone));
308 * Evaluate thermal zone parameters.
310 for (i = 0; i < TZ_NUMLEVELS; i++) {
311 sprintf(nbuf, "_AC%d", i);
312 acpi_tz_getparam(sc, nbuf, &sc->tz_zone.ac[i]);
313 sprintf(nbuf, "_AL%d", i);
314 sc->tz_zone.al[i].Length = ACPI_ALLOCATE_BUFFER;
315 sc->tz_zone.al[i].Pointer = NULL;
316 AcpiEvaluateObject(sc->tz_handle, nbuf, NULL, &sc->tz_zone.al[i]);
317 obj = (ACPI_OBJECT *)sc->tz_zone.al[i].Pointer;
319 /* should be a package containing a list of power objects */
320 if (obj->Type != ACPI_TYPE_PACKAGE) {
321 device_printf(sc->tz_dev, "%s has unknown object type %d, rejecting\n",
327 acpi_tz_getparam(sc, "_CRT", &sc->tz_zone.crt);
328 acpi_tz_getparam(sc, "_HOT", &sc->tz_zone.hot);
329 sc->tz_zone.psl.Length = ACPI_ALLOCATE_BUFFER;
330 sc->tz_zone.psl.Pointer = NULL;
331 AcpiEvaluateObject(sc->tz_handle, "_PSL", NULL, &sc->tz_zone.psl);
332 acpi_tz_getparam(sc, "_PSV", &sc->tz_zone.psv);
333 acpi_tz_getparam(sc, "_TC1", &sc->tz_zone.tc1);
334 acpi_tz_getparam(sc, "_TC2", &sc->tz_zone.tc2);
335 acpi_tz_getparam(sc, "_TSP", &sc->tz_zone.tsp);
336 acpi_tz_getparam(sc, "_TZP", &sc->tz_zone.tzp);
339 * Sanity-check the values we've been given.
341 * XXX what do we do about systems that give us the same value for
342 * more than one of these setpoints?
344 acpi_tz_sanity(sc, &sc->tz_zone.crt, "_CRT");
345 acpi_tz_sanity(sc, &sc->tz_zone.hot, "_HOT");
346 acpi_tz_sanity(sc, &sc->tz_zone.psv, "_PSV");
347 for (i = 0; i < TZ_NUMLEVELS; i++)
348 acpi_tz_sanity(sc, &sc->tz_zone.ac[i], "_ACx");
351 * Power off everything that we've just been given.
358 static char *aclevel_string[] = {
359 "NONE", "_AC0", "_AC1", "_AC2", "_AC3", "_AC4",
360 "_AC5", "_AC6", "_AC7", "_AC8", "_AC9" };
362 static __inline const char *
363 acpi_tz_aclevel_string(int active)
365 if (active < -1 || active >= TZ_NUMLEVELS) {
366 return (aclevel_string[0]);
369 return (aclevel_string[active+1]);
373 * Evaluate the condition of a thermal zone, take appropriate actions.
376 acpi_tz_monitor(struct acpi_tz_softc *sc)
380 int newactive, newflags;
381 struct timespec curtime;
384 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
388 if (sc->tz_tmp_updating) {
391 sc->tz_tmp_updating = 1;
394 * Get the current temperature.
396 if (ACPI_FAILURE(status = acpi_EvaluateInteger(sc->tz_handle, "_TMP", &temp))) {
397 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
398 "error fetching current temperature -- %s\n",
399 AcpiFormatException(status));
400 /* XXX disable zone? go to max cooling? */
404 ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "got %d.%dC\n", TZ_KELVTOC(temp)));
405 sc->tz_temperature = temp;
408 * Work out what we ought to be doing right now.
410 * Note that the _ACx levels sort from hot to cold.
412 newactive = TZ_ACTIVE_NONE;
413 for (i = TZ_NUMLEVELS - 1; i >= 0; i--) {
414 if ((sc->tz_zone.ac[i] != -1) && (temp >= sc->tz_zone.ac[i])) {
416 if (sc->tz_active != newactive) {
417 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
418 "_AC%d: temperature %d.%d >= setpoint %d.%d\n", i,
419 TZ_KELVTOC(temp), TZ_KELVTOC(sc->tz_zone.ac[i]));
420 getnanotime(&sc->tz_cooling_started);
426 * We are going to get _ACx level down (colder side), but give a guaranteed
427 * minimum cooling run time if requested.
429 if (acpi_tz_min_runtime > 0 && sc->tz_active != TZ_ACTIVE_NONE &&
430 (newactive == TZ_ACTIVE_NONE || newactive > sc->tz_active)) {
431 getnanotime(&curtime);
432 timespecsub(&curtime, &sc->tz_cooling_started);
433 if (curtime.tv_sec < acpi_tz_min_runtime) {
434 newactive = sc->tz_active;
438 /* handle user override of active mode */
439 if (sc->tz_requested > newactive)
440 newactive = sc->tz_requested;
442 /* update temperature-related flags */
443 newflags = TZ_THFLAG_NONE;
444 if ((sc->tz_zone.psv != -1) && (temp >= sc->tz_zone.psv))
445 newflags |= TZ_THFLAG_PSV;
446 if ((sc->tz_zone.hot != -1) && (temp >= sc->tz_zone.hot))
447 newflags |= TZ_THFLAG_HOT;
448 if ((sc->tz_zone.crt != -1) && (temp >= sc->tz_zone.crt))
449 newflags |= TZ_THFLAG_CRT;
452 * If the active cooling state has changed, we have to switch things.
454 if (newactive != sc->tz_active) {
456 /* turn off the cooling devices that are on, if any are */
457 if (sc->tz_active != TZ_ACTIVE_NONE)
458 acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[sc->tz_active].Pointer,
459 acpi_tz_switch_cooler_off, sc);
461 /* turn on cooling devices that are required, if any are */
462 if (newactive != TZ_ACTIVE_NONE)
463 acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[newactive].Pointer,
464 acpi_tz_switch_cooler_on, sc);
465 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
466 "switched from %s to %s: %d.%dC\n",
467 acpi_tz_aclevel_string(sc->tz_active),
468 acpi_tz_aclevel_string(newactive), TZ_KELVTOC(temp));
469 sc->tz_active = newactive;
473 * XXX (de)activate any passive cooling that may be required.
477 * If we have just become _HOT or _CRT, warn the user.
479 * We should actually shut down at this point, but it's not clear
480 * that some systems don't actually map _CRT to the same value as _AC0.
482 if ((newflags & (TZ_THFLAG_HOT | TZ_THFLAG_CRT)) &&
483 !(sc->tz_thflags & (TZ_THFLAG_HOT | TZ_THFLAG_CRT))) {
484 device_printf(sc->tz_dev, "WARNING - current temperature (%d.%dC) exceeds system limits\n",
485 TZ_KELVTOC(sc->tz_temperature));
486 /* shutdown_nice(RB_POWEROFF);*/
488 sc->tz_thflags = newflags;
491 sc->tz_tmp_updating = 0;
496 * Turn off all the cooling devices.
499 acpi_tz_all_off(struct acpi_tz_softc *sc)
503 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
508 * Scan all the _ALx objects, and turn them all off.
510 for (i = 0; i < TZ_NUMLEVELS; i++) {
511 if (sc->tz_zone.al[i].Pointer == NULL)
513 acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[i].Pointer,
514 acpi_tz_switch_cooler_off, sc);
518 * XXX revert any passive-cooling options.
521 sc->tz_active = TZ_ACTIVE_NONE;
522 sc->tz_thflags = TZ_THFLAG_NONE;
527 * Given an object, verify that it's a reference to a device of some sort,
528 * and try to switch it off.
531 acpi_tz_switch_cooler_off(ACPI_OBJECT *obj, void *arg)
535 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
541 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s off\n", acpi_name(obj->Reference.Handle)));
543 acpi_pwr_switch_consumer(obj->Reference.Handle, ACPI_STATE_D3);
546 case ACPI_TYPE_STRING:
547 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s off\n", obj->String.Pointer));
550 * Find the handle for the device and turn it off.
551 * The String object here seems to contain a fully-qualified path, so we
552 * don't have to search for it in our parents.
554 * XXX This may not always be the case.
556 if (ACPI_SUCCESS(AcpiGetHandle(NULL, obj->String.Pointer, &cooler)))
557 acpi_pwr_switch_consumer(cooler, ACPI_STATE_D3);
561 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to handle unsupported object type %d\n",
569 * Given an object, verify that it's a reference to a device of some sort,
570 * and try to switch it on.
572 * XXX replication of off/on function code is bad, mmmkay?
575 acpi_tz_switch_cooler_on(ACPI_OBJECT *obj, void *arg)
577 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
581 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
587 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s on\n", acpi_name(obj->Reference.Handle)));
589 if (ACPI_FAILURE(status = acpi_pwr_switch_consumer(obj->Reference.Handle, ACPI_STATE_D0))) {
590 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
591 "failed to activate %s - %s\n", acpi_name(obj->Reference.Handle),
592 AcpiFormatException(status));
596 case ACPI_TYPE_STRING:
597 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to turn %s on\n", obj->String.Pointer));
600 * Find the handle for the device and turn it off.
601 * The String object here seems to contain a fully-qualified path, so we
602 * don't have to search for it in our parents.
604 * XXX This may not always be the case.
606 if (ACPI_SUCCESS(AcpiGetHandle(NULL, obj->String.Pointer, &cooler))) {
607 if (ACPI_FAILURE(status = acpi_pwr_switch_consumer(cooler, ACPI_STATE_D0))) {
608 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
609 "failed to activate %s - %s\n",
610 obj->String.Pointer, AcpiFormatException(status));
613 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
614 "couldn't find %s\n", obj->String.Pointer);
619 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "called to handle unsupported object type %d\n",
627 * Read/debug-print a parameter, default it to -1.
630 acpi_tz_getparam(struct acpi_tz_softc *sc, char *node, int *data)
633 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
637 if (ACPI_FAILURE(acpi_EvaluateInteger(sc->tz_handle, node, data))) {
640 ACPI_DEBUG_PRINT((ACPI_DB_VALUES, "%s.%s = %d\n", acpi_name(sc->tz_handle),
647 * Sanity-check a temperature value. Assume that setpoints
648 * should be between 0C and 150C.
651 acpi_tz_sanity(struct acpi_tz_softc *sc, int *val, char *what)
653 if ((*val != -1) && ((*val < TZ_ZEROC) || (*val > (TZ_ZEROC + 1500)))) {
654 device_printf(sc->tz_dev, "%s value is absurd, ignored (%d.%dC)\n",
655 what, TZ_KELVTOC(*val));
661 * Respond to a sysctl on the active state node.
664 acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS)
666 struct acpi_tz_softc *sc;
673 sc = (struct acpi_tz_softc *)oidp->oid_arg1;
674 active = sc->tz_active;
675 error = sysctl_handle_int(oidp, &active, 0, req);
677 /* error or no new value */
678 if ((error != 0) || (req->newptr == NULL))
682 if ((active < -1) || (active >= TZ_NUMLEVELS)) {
687 /* set new preferred level and re-switch */
688 sc->tz_requested = active;
697 * Respond to a Notify event sent to the zone.
700 acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
702 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)context;
704 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
709 case TZ_NOTIFY_TEMPERATURE:
710 /* temperature change occurred */
711 AcpiOsQueueForExecution(OSD_PRIORITY_HIGH, (OSD_EXECUTION_CALLBACK)acpi_tz_monitor, sc);
713 case TZ_NOTIFY_DEVICES:
714 case TZ_NOTIFY_LEVELS:
715 /* zone devices/setpoints changed */
716 AcpiOsQueueForExecution(OSD_PRIORITY_HIGH, (OSD_EXECUTION_CALLBACK)acpi_tz_establish, sc);
719 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
720 "unknown Notify event 0x%x\n", notify);
727 * Poll the thermal zone.
730 acpi_tz_timeout(struct acpi_tz_softc *sc)
733 /* do we need to get the power profile settings? */
734 if (sc->tz_flags & TZ_FLAG_GETPROFILE) {
735 acpi_tz_power_profile((void *)sc);
736 sc->tz_flags &= ~TZ_FLAG_GETPROFILE;
741 /* check the current temperature and take action based on it */
744 /* XXX passive cooling actions? */
748 * System power profile may have changed; fetch and notify the
749 * thermal zone accordingly.
751 * Since this can be called from an arbitrary eventhandler, it needs
752 * to get the ACPI lock itself.
755 acpi_tz_power_profile(void *arg)
757 ACPI_OBJECT_LIST args;
760 struct acpi_tz_softc *sc = (struct acpi_tz_softc *)arg;
764 state = power_profile_get_state();
765 if (state != POWER_PROFILE_PERFORMANCE &&
766 state != POWER_PROFILE_ECONOMY) {
772 /* check that we haven't decided there's no _SCP method */
773 if (!(sc->tz_flags & TZ_FLAG_NO_SCP)) {
775 /* call _SCP to set the new profile */
776 obj.Type = ACPI_TYPE_INTEGER;
777 obj.Integer.Value = (state == POWER_PROFILE_PERFORMANCE) ? 0 : 1;
780 if (ACPI_FAILURE(status = AcpiEvaluateObject(sc->tz_handle, "_SCP", &args, NULL))) {
781 if (status != AE_NOT_FOUND)
782 ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
783 "can't evaluate %s._SCP - %s\n", acpi_name(sc->tz_handle),
784 AcpiFormatException(status));
785 sc->tz_flags |= TZ_FLAG_NO_SCP;
787 /* we have to re-evaluate the entire zone now */
788 AcpiOsQueueForExecution(OSD_PRIORITY_HIGH, (OSD_EXECUTION_CALLBACK)acpi_tz_establish, sc);
795 * Thermal zone monitor thread.
798 acpi_tz_thread(void *arg)
804 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
811 tsleep(&acpi_tz_proc, 0, "nothing", hz * acpi_tz_polling_rate);
813 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
818 devclass_get_devices(acpi_tz_devclass, &devs, &devcount);
821 for (i = 0; i < devcount; i++)
822 acpi_tz_timeout(device_get_softc(devs[i]));
825 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000