xref: /netbsd-src/sys/dev/acpi/acpi_tz.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /* $NetBSD: acpi_tz.c,v 1.14 2004/06/06 17:27:05 martin Exp $ */
2 
3 /*
4  * Copyright (c) 2003 Jared D. McNeill <jmcneill@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.14 2004/06/06 17:27:05 martin 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/lock.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 const struct envsys_range acpitz_ranges[] = {
73 	{ 0, 1,	ATZ_SENSOR_TEMP },
74 };
75 
76 static int	acpitz_match(struct device *, struct cfdata *, void *);
77 static void	acpitz_attach(struct device *, struct device *, void *);
78 
79 /*
80  * ACPI Temperature Zone information. Note all temperatures are reported
81  * in tenths of degrees Kelvin
82  */
83 struct acpitz_zone {
84 	/* Active cooling temperature threshold */
85 	UINT32 ac[ATZ_NLEVELS];
86 	/* Package of references to all active cooling devices for a level */
87 	ACPI_BUFFER al[ATZ_NLEVELS];
88 	/* Critical temperature threshold for system shutdown */
89 	UINT32 crt;
90 	/* Critical temperature threshold for S4 sleep */
91 	UINT32 hot;
92 	/* Package of references to processor objects for passive cooling */
93 	ACPI_BUFFER psl;
94 	/* Passive cooling temperature threshold */
95 	UINT32 psv;
96 	/* Thermal constants for use in passive cooling formulas */
97 	UINT32 tc1, tc2;
98 	/* Current temperature of the thermal zone */
99 	UINT32 tmp;
100 	/* Thermal sampling period for passive cooling, in tenths of seconds */
101 	UINT32 tsp;
102 	/* Package of references to devices in this TZ (optional) */
103 	ACPI_BUFFER tzd;
104 	/* Recommended TZ polling frequency, in tenths of seconds */
105 	UINT32 tzp;
106 };
107 
108 struct acpitz_softc {
109 	struct device sc_dev;
110 	struct acpi_devnode *sc_devnode;
111 	struct acpitz_zone sc_zone;
112 	struct callout sc_callout;
113 	struct envsys_tre_data sc_data[ATZ_NUMSENSORS];
114 	struct envsys_basic_info sc_info[ATZ_NUMSENSORS];
115 	struct sysmon_envsys sc_sysmon;
116 	struct simplelock sc_slock;
117 	int sc_active;		/* active cooling level */
118 	int sc_flags;
119 	int sc_rate;		/* tz poll rate */
120 	int sc_zone_expire;
121 };
122 
123 static void	acpitz_get_status(void *);
124 static void	acpitz_get_zone(void *, int);
125 static void	acpitz_get_zone_quiet(void *);
126 static char*	acpitz_celcius_string(int);
127 static void	acpitz_print_status(struct acpitz_softc *);
128 static void	acpitz_power_off(struct acpitz_softc *);
129 static void	acpitz_power_zone(struct acpitz_softc *, int, int);
130 static void	acpitz_sane_temp(UINT32 *tmp);
131 static ACPI_STATUS
132 		acpitz_switch_cooler(ACPI_OBJECT *, void *);
133 static void	acpitz_notify_handler(ACPI_HANDLE, UINT32, void *);
134 static int	acpitz_get_integer(struct acpitz_softc *, char *, UINT32 *);
135 static void	acpitz_tick(void *);
136 static void	acpitz_init_envsys(struct acpitz_softc *);
137 static int	acpitz_gtredata(struct sysmon_envsys *,
138 				struct envsys_tre_data *);
139 static int	acpitz_streinfo(struct sysmon_envsys *,
140 				struct envsys_basic_info *);
141 
142 CFATTACH_DECL(acpitz, sizeof(struct acpitz_softc), acpitz_match,
143     acpitz_attach, NULL, NULL);
144 
145 /*
146  * acpitz_match: autoconf(9) match routine
147  */
148 static int
149 acpitz_match(struct device *parent, struct cfdata *match, void *aux)
150 {
151 	struct acpi_attach_args *aa = aux;
152 
153 	if (aa->aa_node->ad_type != ACPI_TYPE_THERMAL)
154 		return 0;
155 
156 	return 1;
157 }
158 
159 /*
160  * acpitz_attach: autoconf(9) attach routine
161  */
162 static void
163 acpitz_attach(struct device *parent, struct device *self, void *aux)
164 {
165 	struct acpitz_softc *sc = (struct acpitz_softc *)self;
166 	struct acpi_attach_args *aa = aux;
167 	ACPI_STATUS rv;
168 	ACPI_INTEGER v;
169 
170 #if 0
171 	sc->sc_flags = ATZ_F_VERBOSE;
172 #endif
173 	sc->sc_devnode = aa->aa_node;
174 
175 	printf(": ACPI Thermal Zone\n");
176 
177 	rv = acpi_eval_integer(sc->sc_devnode->ad_handle, "_TZP", &v);
178 	if (ACPI_FAILURE(rv)) {
179 		printf("%s: unable to get polling interval; using default of",
180 		    sc->sc_dev.dv_xname);
181 		sc->sc_zone.tzp = ATZ_TZP_RATE;
182 	} else {
183 		sc->sc_zone.tzp = v;
184 		printf("%s: polling interval is", sc->sc_dev.dv_xname);
185 	}
186 	printf(" %d.%ds\n", sc->sc_zone.tzp / 10, sc->sc_zone.tzp % 10);
187 
188 	/* XXX a value of 0 means "polling is not necessary" */
189 	if (sc->sc_zone.tzp == 0)
190 		sc->sc_zone.tzp = ATZ_TZP_RATE;
191 
192 	sc->sc_zone_expire = ATZ_ZONE_EXPIRE / sc->sc_zone.tzp;
193 
194 	acpitz_get_zone(sc, 1);
195 	acpitz_get_status(sc);
196 
197 	rv = AcpiInstallNotifyHandler(sc->sc_devnode->ad_handle,
198 	    ACPI_SYSTEM_NOTIFY, acpitz_notify_handler, sc);
199 	if (ACPI_FAILURE(rv)) {
200 		printf("%s: unable to install SYSTEM NOTIFY handler: %s\n",
201 		    sc->sc_dev.dv_xname, AcpiFormatException(rv));
202 		return;
203 	}
204 
205 	callout_init(&sc->sc_callout);
206 	callout_reset(&sc->sc_callout, sc->sc_zone.tzp * hz / 10,
207 	    acpitz_tick, sc);
208 
209 	acpitz_init_envsys(sc);
210 }
211 
212 static void
213 acpitz_get_zone_quiet(void *opaque)
214 {
215 	acpitz_get_zone(opaque, 0);
216 }
217 
218 static void
219 acpitz_get_status(void *opaque)
220 {
221 	struct acpitz_softc *sc = opaque;
222 	UINT32 tmp, active;
223 	int i, flags;
224 
225 	sc->sc_zone_expire--;
226 	if (sc->sc_zone_expire <= 0) {
227 		sc->sc_zone_expire = ATZ_ZONE_EXPIRE / sc->sc_zone.tzp;
228 		if (sc->sc_flags & ATZ_F_VERBOSE)
229 			printf("%s: force refetch zone\n", sc->sc_dev.dv_xname);
230 		acpitz_get_zone(sc, 0);
231 	}
232 
233 	if (acpitz_get_integer(sc, "_TMP", &tmp)) {
234 		printf("%s: failed to evaluate _TMP\n", sc->sc_dev.dv_xname);
235 		return;
236 	}
237 	sc->sc_zone.tmp = tmp;
238 	/* XXX sanity check for tmp here? */
239 
240 	/*
241 	 * The temperature unit for envsys(4) is microKelvin, so convert to
242 	 * that from ACPI's microKelvin. Also, the ACPI specification assumes
243 	 * that K = C + 273.2 rather than the nominal 273.15 used by envsys(4),
244 	 * so we correct for that too.
245 	 */
246 	sc->sc_data[ATZ_SENSOR_TEMP].cur.data_us =
247 	    sc->sc_zone.tmp * 100000 - 50000;
248 	sc->sc_data[ATZ_SENSOR_TEMP].validflags |= ENVSYS_FCURVALID;
249 
250 	if (sc->sc_flags & ATZ_F_VERBOSE)
251 		acpitz_print_status(sc);
252 
253 	if (sc->sc_flags & ATZ_F_PASSIVEONLY) {
254 		/* Passive Cooling: XXX not yet */
255 
256 	} else {
257 		/* Active Cooling */
258 
259 		/* temperature threshold: _AC0 > ... > _AC9 */
260 		active = ATZ_ACTIVE_NONE;
261 		for (i = ATZ_NLEVELS - 1; i >= 0; i--) {
262 			if (sc->sc_zone.ac[i] == ATZ_TMP_INVALID)
263 				continue;
264 
265 			/* we want to keep highest cooling mode in 'active' */
266 			if (sc->sc_zone.ac[i] <= tmp)
267 				active = i;
268 		}
269 
270 		flags = sc->sc_flags & ~(ATZ_F_CRITICAL|ATZ_F_HOT|ATZ_F_PASSIVE);
271 		if (sc->sc_zone.psv != ATZ_TMP_INVALID &&
272 		    tmp >= sc->sc_zone.psv)
273 			flags |= ATZ_F_PASSIVE;
274 		if (sc->sc_zone.hot != ATZ_TMP_INVALID &&
275 		    tmp >= sc->sc_zone.hot)
276 			flags |= ATZ_F_HOT;
277 		if (sc->sc_zone.crt != ATZ_TMP_INVALID &&
278 		    tmp >= sc->sc_zone.crt)
279 			flags |= ATZ_F_CRITICAL;
280 
281 		if (flags != sc->sc_flags) {
282 			int changed = (sc->sc_flags ^ flags) & flags;
283 			sc->sc_flags = flags;
284 			if (changed & ATZ_F_CRITICAL)
285 				printf("%s: zone went critical at temp %sC\n",
286 				    sc->sc_dev.dv_xname,
287 				    acpitz_celcius_string(tmp));
288 			else if (changed & ATZ_F_HOT)
289 				printf("%s: zone went hot at temp %sC\n",
290 				    sc->sc_dev.dv_xname,
291 				    acpitz_celcius_string(tmp));
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 			printf("failed getting _AL%d", i);
440 			sc->sc_zone.al[i].Pointer = NULL;
441 			continue;
442 		}
443 
444 		obj = sc->sc_zone.al[i].Pointer;
445 		if (obj != NULL) {
446 			if (obj->Type != ACPI_TYPE_PACKAGE) {
447 				printf("%s: ac%d not package\n",
448 				    sc->sc_dev.dv_xname, i);
449 				AcpiOsFree(obj);
450 				sc->sc_zone.al[i].Pointer = NULL;
451 				continue;
452 			}
453 		}
454 
455 		if (first)
456 			printf("%s: active cooling level %d: %sC\n",
457 			    sc->sc_dev.dv_xname, i,
458 			    acpitz_celcius_string(sc->sc_zone.ac[i]));
459 
460 		valid_levels++;
461 	}
462 
463 	if (valid_levels == 0) {
464 		sc->sc_flags |= ATZ_F_PASSIVEONLY;
465 		if (first)
466 			printf("%s: passive cooling mode only\n",
467 			    sc->sc_dev.dv_xname);
468 	}
469 
470 	acpitz_get_integer(sc, "_TMP", &sc->sc_zone.tmp);
471 	acpitz_get_integer(sc, "_CRT", &sc->sc_zone.crt);
472 	acpitz_get_integer(sc, "_HOT", &sc->sc_zone.hot);
473 	sc->sc_zone.psl.Length = ACPI_ALLOCATE_BUFFER;
474 	sc->sc_zone.psl.Pointer = NULL;
475 	AcpiEvaluateObject(sc, "_PSL", NULL, &sc->sc_zone.psl);
476 	acpitz_get_integer(sc, "_PSV", &sc->sc_zone.psv);
477 	acpitz_get_integer(sc, "_TC1", &sc->sc_zone.tc1);
478 	acpitz_get_integer(sc, "_TC2", &sc->sc_zone.tc2);
479 
480 	acpitz_sane_temp(&sc->sc_zone.tmp);
481 	acpitz_sane_temp(&sc->sc_zone.crt);
482 	acpitz_sane_temp(&sc->sc_zone.hot);
483 	acpitz_sane_temp(&sc->sc_zone.psv);
484 
485 	if (verbose) {
486 		printf("%s:", sc->sc_dev.dv_xname);
487 		if (sc->sc_zone.crt != ATZ_TMP_INVALID)
488 			printf(" critical %sC",
489 			    acpitz_celcius_string(sc->sc_zone.crt));
490 		if (sc->sc_zone.hot != ATZ_TMP_INVALID)
491 			printf(" hot %sC",
492 			    acpitz_celcius_string(sc->sc_zone.hot));
493 		if (sc->sc_zone.psv != ATZ_TMP_INVALID)
494 			printf(" passive %sC",
495 			    acpitz_celcius_string(sc->sc_zone.tmp));
496 		printf("\n");
497 	}
498 
499 	for (i = 0; i < ATZ_NLEVELS; i++)
500 		acpitz_sane_temp(&sc->sc_zone.ac[i]);
501 
502 	acpitz_power_off(sc);
503 	first = 0;
504 }
505 
506 
507 static void
508 acpitz_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque)
509 {
510 	struct acpitz_softc *sc = opaque;
511 	OSD_EXECUTION_CALLBACK func = NULL;
512 	const char *name;
513 	int rv;
514 
515 	switch (notify) {
516 	case ACPI_NOTIFY_ThermalZoneStatusChanged:
517 		func = acpitz_get_status;
518 		name = "status check";
519 		break;
520 	case ACPI_NOTIFY_ThermalZoneTripPointsChanged:
521 	case ACPI_NOTIFY_DeviceListsChanged:
522 		func = acpitz_get_zone_quiet;
523 		name = "get zone";
524 		break;
525 	default:
526 		printf("%s: received unhandled notify message 0x%x\n",
527 		    sc->sc_dev.dv_xname, notify);
528 		return;
529 	}
530 
531 	KASSERT(func != NULL);
532 
533 	rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO, func, sc);
534 	if (rv != AE_OK)
535 		printf("%s: unable to queue %s\n", sc->sc_dev.dv_xname, name);
536 
537 	return;
538 }
539 
540 static void
541 acpitz_sane_temp(UINT32 *tmp)
542 {
543 	/* Sane temperatures are beteen 0 and 150 C */
544 	if (*tmp < ATZ_ZEROC || *tmp > ATZ_ZEROC + 1500)
545 		*tmp = ATZ_TMP_INVALID;
546 }
547 
548 static int
549 acpitz_get_integer(struct acpitz_softc *sc, char *cm, UINT32 *val)
550 {
551 	ACPI_STATUS rv;
552 	ACPI_INTEGER tmp;
553 
554 	rv = acpi_eval_integer(sc->sc_devnode->ad_handle, cm, &tmp);
555 	if (ACPI_FAILURE(rv)) {
556 #ifdef ACPI_DEBUG
557 		printf("%s: failed to evaluate %s: %s\n", sc->sc_dev.dv_xname,
558 		    cm, AcpiFormatException(rv));
559 #endif
560 		*val = ATZ_TMP_INVALID;
561 		return 1;
562 	}
563 
564 	*val = tmp;
565 
566 	return 0;
567 }
568 
569 static void
570 acpitz_tick(void *opaque)
571 {
572 	struct acpitz_softc *sc = opaque;
573 
574 	callout_reset(&sc->sc_callout, sc->sc_zone.tzp * hz / 10,
575 	    acpitz_tick, opaque);
576 	AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpitz_get_status, sc);
577 
578 	return;
579 }
580 
581 static void
582 acpitz_init_envsys(struct acpitz_softc *sc)
583 {
584 	int i;
585 
586 	simple_lock_init(&sc->sc_slock);
587 
588 	for (i = 0; i < ATZ_NUMSENSORS; i++) {
589 		sc->sc_data[i].sensor = sc->sc_info[i].sensor = i;
590 		sc->sc_data[i].validflags = ENVSYS_FVALID;
591 		sc->sc_info[i].validflags = ENVSYS_FVALID;
592 		sc->sc_data[i].warnflags = ENVSYS_WARN_OK;
593 	}
594 #define INITDATA(index, unit, string) \
595 	sc->sc_data[index].units = unit;				   \
596 	sc->sc_info[index].units = unit;				   \
597 	snprintf(sc->sc_info[index].desc, sizeof(sc->sc_info[index].desc), \
598 	    "%s %s", sc->sc_dev.dv_xname, string);
599 
600 	INITDATA(ATZ_SENSOR_TEMP, ENVSYS_STEMP, "temperature");
601 
602 	/* hook into sysmon */
603 	sc->sc_sysmon.sme_ranges = acpitz_ranges;
604 	sc->sc_sysmon.sme_sensor_info = sc->sc_info;
605 	sc->sc_sysmon.sme_sensor_data = sc->sc_data;
606 	sc->sc_sysmon.sme_cookie = sc;
607 	sc->sc_sysmon.sme_gtredata = acpitz_gtredata;
608 	sc->sc_sysmon.sme_streinfo = acpitz_streinfo;
609 	sc->sc_sysmon.sme_nsensors = ATZ_NUMSENSORS;
610 	sc->sc_sysmon.sme_envsys_version = 1000;
611 
612 	if (sysmon_envsys_register(&sc->sc_sysmon))
613 		printf("%s: unable to register with sysmon\n",
614 		    sc->sc_dev.dv_xname);
615 }
616 
617 int
618 acpitz_gtredata(struct sysmon_envsys *sme, struct envsys_tre_data *tred)
619 {
620 	struct acpitz_softc *sc = sme->sme_cookie;
621 
622 	simple_lock(&sc->sc_slock);
623 
624 	*tred = sc->sc_data[tred->sensor];
625 
626 	simple_unlock(&sc->sc_slock);
627 
628 	return 0;
629 }
630 
631 static int
632 acpitz_streinfo(struct sysmon_envsys *sme, struct envsys_basic_info *binfo)
633 {
634 
635 	/* XXX not implemented */
636 	binfo->validflags = 0;
637 
638 	return 0;
639 }
640