Home | History | Annotate | Line # | Download | only in acpi
acpi_tz.c revision 1.25
      1 /* $NetBSD: acpi_tz.c,v 1.25 2007/10/18 00:10:52 joerg Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2003 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. The name of the author may not be used to endorse or promote products
     13  *    derived from this software without specific prior written permission.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     22  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     23  * 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
     25  * SUCH DAMAGE.
     26  */
     27 
     28 /*
     29  * ACPI Thermal Zone driver
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.25 2007/10/18 00:10:52 joerg Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/kernel.h>
     38 #include <sys/errno.h>
     39 #include <sys/ioctl.h>
     40 #include <sys/syslog.h>
     41 #include <sys/device.h>
     42 #include <sys/callout.h>
     43 #include <sys/proc.h>
     44 #include <sys/mutex.h>
     45 #include <dev/sysmon/sysmonvar.h>
     46 
     47 #include <dev/acpi/acpica.h>
     48 #include <dev/acpi/acpireg.h>
     49 #include <dev/acpi/acpivar.h>
     50 
     51 /* flags */
     52 #define ATZ_F_VERBOSE		0x01	/* show events to console */
     53 #define ATZ_F_CRITICAL		0x02	/* zone critical */
     54 #define ATZ_F_HOT		0x04	/* zone hot */
     55 #define ATZ_F_PASSIVE		0x08	/* zone passive cooling */
     56 #define ATZ_F_PASSIVEONLY	0x10	/* zone is passive cooling only */
     57 
     58 /* no active cooling level */
     59 #define ATZ_ACTIVE_NONE -1
     60 
     61 /* constants */
     62 #define ATZ_TZP_RATE	300	/* default if no _TZP CM present (30 secs) */
     63 #define ATZ_NLEVELS	10	/* number of cooling levels, from ACPI spec */
     64 #define ATZ_ZEROC	2732	/* 0C in tenths degrees Kelvin */
     65 #define ATZ_TMP_INVALID	0xffffffff	/* invalid temperature */
     66 #define ATZ_ZONE_EXPIRE	9000	/* zone info refetch interval (15min) */
     67 
     68 /* sensor indexes */
     69 #define ATZ_SENSOR_TEMP	0	/* thermal zone temperature */
     70 #define ATZ_NUMSENSORS	1	/* number of sensors */
     71 
     72 static int	acpitz_match(struct device *, struct cfdata *, void *);
     73 static void	acpitz_attach(struct device *, struct device *, void *);
     74 
     75 /*
     76  * ACPI Temperature Zone information. Note all temperatures are reported
     77  * in tenths of degrees Kelvin
     78  */
     79 struct acpitz_zone {
     80 	/* Active cooling temperature threshold */
     81 	UINT32 ac[ATZ_NLEVELS];
     82 	/* Package of references to all active cooling devices for a level */
     83 	ACPI_BUFFER al[ATZ_NLEVELS];
     84 	/* Critical temperature threshold for system shutdown */
     85 	UINT32 crt;
     86 	/* Critical temperature threshold for S4 sleep */
     87 	UINT32 hot;
     88 	/* Package of references to processor objects for passive cooling */
     89 	ACPI_BUFFER psl;
     90 	/* Passive cooling temperature threshold */
     91 	UINT32 psv;
     92 	/* Thermal constants for use in passive cooling formulas */
     93 	UINT32 tc1, tc2;
     94 	/* Current temperature of the thermal zone */
     95 	UINT32 tmp;
     96 	/* Thermal sampling period for passive cooling, in tenths of seconds */
     97 	UINT32 tsp;
     98 	/* Package of references to devices in this TZ (optional) */
     99 	ACPI_BUFFER tzd;
    100 	/* Recommended TZ polling frequency, in tenths of seconds */
    101 	UINT32 tzp;
    102 };
    103 
    104 struct acpitz_softc {
    105 	struct device sc_dev;
    106 	struct acpi_devnode *sc_devnode;
    107 	struct acpitz_zone sc_zone;
    108 	struct callout sc_callout;
    109 	struct envsys_data sc_data[ATZ_NUMSENSORS];
    110 	struct sysmon_envsys sc_sysmon;
    111 	kmutex_t sc_mtx;
    112 	int sc_active;		/* active cooling level */
    113 	int sc_flags;
    114 	int sc_rate;		/* tz poll rate */
    115 	int sc_zone_expire;
    116 };
    117 
    118 static void	acpitz_get_status(void *);
    119 static void	acpitz_get_zone(void *, int);
    120 static void	acpitz_get_zone_quiet(void *);
    121 static char*	acpitz_celcius_string(int);
    122 static void	acpitz_print_status(struct acpitz_softc *);
    123 static void	acpitz_power_off(struct acpitz_softc *);
    124 static void	acpitz_power_zone(struct acpitz_softc *, int, int);
    125 static void	acpitz_sane_temp(UINT32 *tmp);
    126 static ACPI_STATUS
    127 		acpitz_switch_cooler(ACPI_OBJECT *, void *);
    128 static void	acpitz_notify_handler(ACPI_HANDLE, UINT32, void *);
    129 static int	acpitz_get_integer(struct acpitz_softc *, const char *, UINT32 *);
    130 static void	acpitz_tick(void *);
    131 static void	acpitz_init_envsys(struct acpitz_softc *);
    132 
    133 CFATTACH_DECL(acpitz, sizeof(struct acpitz_softc), acpitz_match,
    134     acpitz_attach, NULL, NULL);
    135 
    136 /*
    137  * acpitz_match: autoconf(9) match routine
    138  */
    139 static int
    140 acpitz_match(struct device *parent, struct cfdata *match, void *aux)
    141 {
    142 	struct acpi_attach_args *aa = aux;
    143 
    144 	if (aa->aa_node->ad_type != ACPI_TYPE_THERMAL)
    145 		return 0;
    146 
    147 	return 1;
    148 }
    149 
    150 /*
    151  * acpitz_attach: autoconf(9) attach routine
    152  */
    153 static void
    154 acpitz_attach(struct device *parent, struct device *self, void *aux)
    155 {
    156 	struct acpitz_softc *sc = (struct acpitz_softc *)self;
    157 	struct acpi_attach_args *aa = aux;
    158 	ACPI_STATUS rv;
    159 	ACPI_INTEGER v;
    160 
    161 	mutex_init(&sc->sc_mtx, MUTEX_DRIVER, IPL_NONE);
    162 
    163 #if 0
    164 	sc->sc_flags = ATZ_F_VERBOSE;
    165 #endif
    166 	sc->sc_devnode = aa->aa_node;
    167 
    168 	aprint_naive(": ACPI Thermal Zone\n");
    169 	aprint_normal(": ACPI Thermal Zone\n");
    170 
    171 	rv = acpi_eval_integer(sc->sc_devnode->ad_handle, "_TZP", &v);
    172 	if (ACPI_FAILURE(rv)) {
    173 		aprint_verbose("%s: unable to get polling interval; using default of",
    174 		    sc->sc_dev.dv_xname);
    175 		sc->sc_zone.tzp = ATZ_TZP_RATE;
    176 	} else {
    177 		sc->sc_zone.tzp = v;
    178 		aprint_verbose("%s: polling interval is", sc->sc_dev.dv_xname);
    179 	}
    180 	aprint_verbose(" %d.%ds\n", sc->sc_zone.tzp / 10, sc->sc_zone.tzp % 10);
    181 
    182 	/* XXX a value of 0 means "polling is not necessary" */
    183 	if (sc->sc_zone.tzp == 0)
    184 		sc->sc_zone.tzp = ATZ_TZP_RATE;
    185 
    186 	sc->sc_zone_expire = ATZ_ZONE_EXPIRE / sc->sc_zone.tzp;
    187 
    188 	acpitz_get_zone(sc, 1);
    189 	acpitz_get_status(sc);
    190 
    191 	rv = AcpiInstallNotifyHandler(sc->sc_devnode->ad_handle,
    192 	    ACPI_SYSTEM_NOTIFY, acpitz_notify_handler, sc);
    193 	if (ACPI_FAILURE(rv)) {
    194 		aprint_error("%s: unable to install SYSTEM NOTIFY handler: %s\n",
    195 		    sc->sc_dev.dv_xname, AcpiFormatException(rv));
    196 		return;
    197 	}
    198 
    199 	callout_init(&sc->sc_callout, 0);
    200 	callout_setfunc(&sc->sc_callout, acpitz_tick, sc);
    201 
    202 	acpitz_init_envsys(sc);
    203 
    204 	callout_schedule(&sc->sc_callout, sc->sc_zone.tzp * hz / 10);
    205 }
    206 
    207 static void
    208 acpitz_get_zone_quiet(void *opaque)
    209 {
    210 	acpitz_get_zone(opaque, 0);
    211 }
    212 
    213 static void
    214 acpitz_get_status(void *opaque)
    215 {
    216 	struct acpitz_softc *sc = opaque;
    217 	UINT32 tmp, active;
    218 	int i, flags;
    219 
    220 	sc->sc_zone_expire--;
    221 	if (sc->sc_zone_expire <= 0) {
    222 		sc->sc_zone_expire = ATZ_ZONE_EXPIRE / sc->sc_zone.tzp;
    223 		if (sc->sc_flags & ATZ_F_VERBOSE)
    224 			printf("%s: force refetch zone\n", sc->sc_dev.dv_xname);
    225 		acpitz_get_zone(sc, 0);
    226 	}
    227 
    228 	if (acpitz_get_integer(sc, "_TMP", &tmp)) {
    229 		printf("%s: failed to evaluate _TMP\n", sc->sc_dev.dv_xname);
    230 		return;
    231 	}
    232 	sc->sc_zone.tmp = tmp;
    233 	/* XXX sanity check for tmp here? */
    234 
    235 	/*
    236 	 * The temperature unit for envsys(4) is microKelvin, so convert to
    237 	 * that from ACPI's microKelvin. Also, the ACPI specification assumes
    238 	 * that K = C + 273.2 rather than the nominal 273.15 used by envsys(4),
    239 	 * so we correct for that too.
    240 	 */
    241 	sc->sc_data[ATZ_SENSOR_TEMP].value_cur =
    242 	    sc->sc_zone.tmp * 100000 - 50000;
    243 	sc->sc_data[ATZ_SENSOR_TEMP].state = ENVSYS_SVALID;
    244 
    245 	if (sc->sc_flags & ATZ_F_VERBOSE)
    246 		acpitz_print_status(sc);
    247 
    248 	if (sc->sc_flags & ATZ_F_PASSIVEONLY) {
    249 		/* Passive Cooling: XXX not yet */
    250 
    251 	} else {
    252 		/* Active Cooling */
    253 
    254 		/* temperature threshold: _AC0 > ... > _AC9 */
    255 		active = ATZ_ACTIVE_NONE;
    256 		for (i = ATZ_NLEVELS - 1; i >= 0; i--) {
    257 			if (sc->sc_zone.ac[i] == ATZ_TMP_INVALID)
    258 				continue;
    259 
    260 			/* we want to keep highest cooling mode in 'active' */
    261 			if (sc->sc_zone.ac[i] <= tmp)
    262 				active = i;
    263 		}
    264 
    265 		flags = sc->sc_flags & ~(ATZ_F_CRITICAL|ATZ_F_HOT|ATZ_F_PASSIVE);
    266 		if (sc->sc_zone.psv != ATZ_TMP_INVALID &&
    267 		    tmp >= sc->sc_zone.psv)
    268 			flags |= ATZ_F_PASSIVE;
    269 		if (sc->sc_zone.hot != ATZ_TMP_INVALID &&
    270 		    tmp >= sc->sc_zone.hot)
    271 			flags |= ATZ_F_HOT;
    272 		if (sc->sc_zone.crt != ATZ_TMP_INVALID &&
    273 		    tmp >= sc->sc_zone.crt)
    274 			flags |= ATZ_F_CRITICAL;
    275 
    276 		if (flags != sc->sc_flags) {
    277 			int changed = (sc->sc_flags ^ flags) & flags;
    278 			sc->sc_flags = flags;
    279 			if (changed & ATZ_F_CRITICAL) {
    280 				sc->sc_data[ATZ_SENSOR_TEMP].state =
    281 				    ENVSYS_SCRITICAL;
    282 				printf("%s: zone went critical at temp %sC\n",
    283 				    sc->sc_dev.dv_xname,
    284 				    acpitz_celcius_string(tmp));
    285 			} else if (changed & ATZ_F_HOT) {
    286 				sc->sc_data[ATZ_SENSOR_TEMP].state =
    287 				    ENVSYS_SWARNOVER;
    288 				printf("%s: zone went hot at temp %sC\n",
    289 				    sc->sc_dev.dv_xname,
    290 				    acpitz_celcius_string(tmp));
    291 			}
    292 		}
    293 
    294 		/* power on fans */
    295 		if (sc->sc_active != active) {
    296 			if (sc->sc_active != ATZ_ACTIVE_NONE)
    297 				acpitz_power_zone(sc, sc->sc_active, 0);
    298 
    299 			if (active != ATZ_ACTIVE_NONE) {
    300 				if (sc->sc_flags & ATZ_F_VERBOSE)
    301 					printf("%s: active cooling level %u\n",
    302 					    sc->sc_dev.dv_xname, active);
    303 				acpitz_power_zone(sc, active, 1);
    304 			}
    305 
    306 			sc->sc_active = active;
    307 		}
    308 	}
    309 
    310 	return;
    311 }
    312 
    313 static char *
    314 acpitz_celcius_string(int dk)
    315 {
    316 	static char buf[10];
    317 
    318 	snprintf(buf, sizeof(buf), "%d.%d", (dk - ATZ_ZEROC) / 10,
    319 	    (dk - ATZ_ZEROC) % 10);
    320 
    321 	return buf;
    322 }
    323 
    324 static void
    325 acpitz_print_status(struct acpitz_softc *sc)
    326 {
    327 
    328 	printf("%s: zone temperature is now %sC\n", sc->sc_dev.dv_xname,
    329 	    acpitz_celcius_string(sc->sc_zone.tmp));
    330 
    331 	return;
    332 }
    333 
    334 static ACPI_STATUS
    335 acpitz_switch_cooler(ACPI_OBJECT *obj, void *arg)
    336 {
    337 	ACPI_HANDLE cooler;
    338 	ACPI_STATUS rv;
    339 	int pwr_state, flag;
    340 
    341 	flag = *(int *)arg;
    342 
    343 	if (flag)
    344 		pwr_state = ACPI_STATE_D0;
    345 	else
    346 		pwr_state = ACPI_STATE_D3;
    347 
    348 	switch(obj->Type) {
    349 	case ACPI_TYPE_ANY:
    350 		cooler = obj->Reference.Handle;
    351 		break;
    352 	case ACPI_TYPE_STRING:
    353 		rv = AcpiGetHandle(NULL, obj->String.Pointer, &cooler);
    354 		if (ACPI_FAILURE(rv)) {
    355 			printf("failed to get handler from %s\n",
    356 			    obj->String.Pointer);
    357 			return rv;
    358 		}
    359 		break;
    360 	default:
    361 		printf("unknown power type: %d\n", obj->Type);
    362 		return AE_OK;
    363 	}
    364 
    365 	rv = acpi_pwr_switch_consumer(cooler, pwr_state);
    366 	if (rv != AE_BAD_PARAMETER && ACPI_FAILURE(rv)) {
    367 		printf("failed to change state for %s: %s\n",
    368 		    acpi_name(obj->Reference.Handle),
    369 		    AcpiFormatException(rv));
    370 	}
    371 
    372 	return AE_OK;
    373 }
    374 
    375 /*
    376  * acpitz_power_zone:
    377  *	power on or off the i:th part of the zone zone
    378  */
    379 static void
    380 acpitz_power_zone(struct acpitz_softc *sc, int i, int on)
    381 {
    382 	KASSERT(i >= 0 && i < ATZ_NLEVELS);
    383 
    384 	acpi_foreach_package_object(sc->sc_zone.al[i].Pointer,
    385 	    acpitz_switch_cooler, &on);
    386 }
    387 
    388 
    389 /*
    390  * acpitz_power_off:
    391  *	power off parts of the zone
    392  */
    393 static void
    394 acpitz_power_off(struct acpitz_softc *sc)
    395 {
    396 	int i;
    397 
    398 	for (i = 0 ; i < ATZ_NLEVELS; i++) {
    399 		if (sc->sc_zone.al[i].Pointer == NULL)
    400 			continue;
    401 		acpitz_power_zone(sc, i, 0);
    402 	}
    403 	sc->sc_active = ATZ_ACTIVE_NONE;
    404 	sc->sc_flags &= ~(ATZ_F_CRITICAL|ATZ_F_HOT|ATZ_F_PASSIVE);
    405 }
    406 
    407 static void
    408 acpitz_get_zone(void *opaque, int verbose)
    409 {
    410 	struct acpitz_softc *sc = opaque;
    411 	ACPI_STATUS rv;
    412 	char buf[8];
    413 	int i, valid_levels;
    414 	static int first = 1;
    415 
    416 	if (!first) {
    417 		acpitz_power_off(sc);
    418 
    419 		for (i = 0; i < ATZ_NLEVELS; i++) {
    420 			if (sc->sc_zone.al[i].Pointer != NULL)
    421 				AcpiOsFree(sc->sc_zone.al[i].Pointer);
    422 			sc->sc_zone.al[i].Pointer = NULL;
    423 		}
    424 	}
    425 
    426 	valid_levels = 0;
    427 
    428 	for (i = 0; i < ATZ_NLEVELS; i++) {
    429 		ACPI_OBJECT *obj;
    430 
    431 		snprintf(buf, sizeof(buf), "_AC%d", i);
    432 		if (acpitz_get_integer(sc, buf, &sc->sc_zone.ac[i]))
    433 			continue;
    434 
    435 		snprintf(buf, sizeof(buf), "_AL%d", i);
    436 		rv = acpi_eval_struct(sc->sc_devnode->ad_handle, buf,
    437 		    &sc->sc_zone.al[i]);
    438 		if (ACPI_FAILURE(rv)) {
    439 			sc->sc_zone.al[i].Pointer = NULL;
    440 			continue;
    441 		}
    442 
    443 		obj = sc->sc_zone.al[i].Pointer;
    444 		if (obj != NULL) {
    445 			if (obj->Type != ACPI_TYPE_PACKAGE) {
    446 				printf("%s: ac%d not package\n",
    447 				    sc->sc_dev.dv_xname, i);
    448 				AcpiOsFree(obj);
    449 				sc->sc_zone.al[i].Pointer = NULL;
    450 				continue;
    451 			}
    452 		}
    453 
    454 		if (first)
    455 			printf("%s: active cooling level %d: %sC\n",
    456 			    sc->sc_dev.dv_xname, i,
    457 			    acpitz_celcius_string(sc->sc_zone.ac[i]));
    458 
    459 		valid_levels++;
    460 	}
    461 
    462 	if (valid_levels == 0) {
    463 		sc->sc_flags |= ATZ_F_PASSIVEONLY;
    464 		if (first)
    465 			printf("%s: passive cooling mode only\n",
    466 			    sc->sc_dev.dv_xname);
    467 	}
    468 
    469 	acpitz_get_integer(sc, "_TMP", &sc->sc_zone.tmp);
    470 	acpitz_get_integer(sc, "_CRT", &sc->sc_zone.crt);
    471 	acpitz_get_integer(sc, "_HOT", &sc->sc_zone.hot);
    472 	sc->sc_zone.psl.Length = ACPI_ALLOCATE_BUFFER;
    473 	sc->sc_zone.psl.Pointer = NULL;
    474 	AcpiEvaluateObject(sc, "_PSL", NULL, &sc->sc_zone.psl);
    475 	acpitz_get_integer(sc, "_PSV", &sc->sc_zone.psv);
    476 	acpitz_get_integer(sc, "_TC1", &sc->sc_zone.tc1);
    477 	acpitz_get_integer(sc, "_TC2", &sc->sc_zone.tc2);
    478 
    479 	acpitz_sane_temp(&sc->sc_zone.tmp);
    480 	acpitz_sane_temp(&sc->sc_zone.crt);
    481 	acpitz_sane_temp(&sc->sc_zone.hot);
    482 	acpitz_sane_temp(&sc->sc_zone.psv);
    483 
    484 	if (verbose) {
    485 		printf("%s:", sc->sc_dev.dv_xname);
    486 		if (sc->sc_zone.crt != ATZ_TMP_INVALID)
    487 			printf(" critical %sC",
    488 			    acpitz_celcius_string(sc->sc_zone.crt));
    489 		if (sc->sc_zone.hot != ATZ_TMP_INVALID)
    490 			printf(" hot %sC",
    491 			    acpitz_celcius_string(sc->sc_zone.hot));
    492 		if (sc->sc_zone.psv != ATZ_TMP_INVALID)
    493 			printf(" passive %sC",
    494 			    acpitz_celcius_string(sc->sc_zone.tmp));
    495 		printf("\n");
    496 	}
    497 
    498 	for (i = 0; i < ATZ_NLEVELS; i++)
    499 		acpitz_sane_temp(&sc->sc_zone.ac[i]);
    500 
    501 	acpitz_power_off(sc);
    502 	first = 0;
    503 }
    504 
    505 
    506 static void
    507 acpitz_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque)
    508 {
    509 	struct acpitz_softc *sc = opaque;
    510 	ACPI_OSD_EXEC_CALLBACK func = NULL;
    511 	const char *name;
    512 	int rv;
    513 
    514 	switch (notify) {
    515 	case ACPI_NOTIFY_ThermalZoneStatusChanged:
    516 		func = acpitz_get_status;
    517 		name = "status check";
    518 		break;
    519 	case ACPI_NOTIFY_ThermalZoneTripPointsChanged:
    520 	case ACPI_NOTIFY_DeviceListsChanged:
    521 		func = acpitz_get_zone_quiet;
    522 		name = "get zone";
    523 		break;
    524 	default:
    525 		printf("%s: received unhandled notify message 0x%x\n",
    526 		    sc->sc_dev.dv_xname, notify);
    527 		return;
    528 	}
    529 
    530 	KASSERT(func != NULL);
    531 
    532 	rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO, func, sc);
    533 	if (rv != AE_OK)
    534 		printf("%s: unable to queue %s\n", sc->sc_dev.dv_xname, name);
    535 
    536 	return;
    537 }
    538 
    539 static void
    540 acpitz_sane_temp(UINT32 *tmp)
    541 {
    542 	/* Sane temperatures are beteen 0 and 150 C */
    543 	if (*tmp < ATZ_ZEROC || *tmp > ATZ_ZEROC + 1500)
    544 		*tmp = ATZ_TMP_INVALID;
    545 }
    546 
    547 static int
    548 acpitz_get_integer(struct acpitz_softc *sc, const char *cm, UINT32 *val)
    549 {
    550 	ACPI_STATUS rv;
    551 	ACPI_INTEGER tmp;
    552 
    553 	rv = acpi_eval_integer(sc->sc_devnode->ad_handle, cm, &tmp);
    554 	if (ACPI_FAILURE(rv)) {
    555 #ifdef ACPI_DEBUG
    556 		printf("%s: failed to evaluate %s: %s\n", sc->sc_dev.dv_xname,
    557 		    cm, AcpiFormatException(rv));
    558 #endif
    559 		*val = ATZ_TMP_INVALID;
    560 		return 1;
    561 	}
    562 
    563 	*val = tmp;
    564 
    565 	return 0;
    566 }
    567 
    568 static void
    569 acpitz_tick(void *opaque)
    570 {
    571 	struct acpitz_softc *sc = opaque;
    572 
    573 	AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpitz_get_status, sc);
    574 
    575 	callout_schedule(&sc->sc_callout, sc->sc_zone.tzp * hz / 10);
    576 }
    577 
    578 static void
    579 acpitz_init_envsys(struct acpitz_softc *sc)
    580 {
    581 	int i;
    582 
    583 	for (i = 0; i < ATZ_NUMSENSORS; i++) {
    584 		sc->sc_data[i].sensor = i;
    585 		sc->sc_data[i].state = ENVSYS_SVALID;
    586 		sc->sc_data[i].monitor = true;
    587 		sc->sc_data[i].flags =
    588 		    (ENVSYS_FMONCRITICAL|ENVSYS_FMONWARNOVER);
    589 	}
    590 #define INITDATA(index, unit, string) \
    591 	sc->sc_data[index].units = unit;				   \
    592 	snprintf(sc->sc_data[index].desc, sizeof(sc->sc_data[index].desc), \
    593 	    "%s %s", sc->sc_dev.dv_xname, string);
    594 
    595 	INITDATA(ATZ_SENSOR_TEMP, ENVSYS_STEMP, "temperature");
    596 
    597 	/* hook into sysmon */
    598 	sc->sc_sysmon.sme_sensor_data = sc->sc_data;
    599 	sc->sc_sysmon.sme_name = sc->sc_dev.dv_xname;
    600 	sc->sc_sysmon.sme_cookie = sc;
    601 	sc->sc_sysmon.sme_nsensors = ATZ_NUMSENSORS;
    602 	sc->sc_sysmon.sme_flags = SME_DISABLE_GTREDATA;
    603 
    604 	if (sysmon_envsys_register(&sc->sc_sysmon))
    605 		printf("%s: unable to register with sysmon\n",
    606 		    sc->sc_dev.dv_xname);
    607 }
    608