Module Name: src Committed By: jruoho Date: Sat Apr 24 19:11:48 UTC 2010
Modified Files: src/sys/dev/acpi: acpi_tz.c Log Message: Some purely cosmetic editing in the name of readability: clean up the softc and remove unused variables therein, remove unused constants, use ACPI_DEBUG_PRINT, add more detailed comments, et cetera. To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 src/sys/dev/acpi/acpi_tz.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/acpi/acpi_tz.c diff -u src/sys/dev/acpi/acpi_tz.c:1.68 src/sys/dev/acpi/acpi_tz.c:1.69 --- src/sys/dev/acpi/acpi_tz.c:1.68 Sat Apr 24 06:31:44 2010 +++ src/sys/dev/acpi/acpi_tz.c Sat Apr 24 19:11:48 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_tz.c,v 1.68 2010/04/24 06:31:44 jruoho Exp $ */ +/* $NetBSD: acpi_tz.c,v 1.69 2010/04/24 19:11:48 jruoho Exp $ */ /* * Copyright (c) 2003 Jared D. McNeill <jmcne...@invisible.ca> @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.68 2010/04/24 06:31:44 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.69 2010/04/24 19:11:48 jruoho Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -42,110 +42,92 @@ #include <dev/acpi/acpivar.h> #include <dev/acpi/acpi_power.h> -#define _COMPONENT ACPI_TZ_COMPONENT -ACPI_MODULE_NAME ("acpi_tz") +#define _COMPONENT ACPI_TZ_COMPONENT +ACPI_MODULE_NAME ("acpi_tz") -/* flags */ -#define ATZ_F_VERBOSE 0x01 /* show events to console */ -#define ATZ_F_CRITICAL 0x02 /* zone critical */ -#define ATZ_F_HOT 0x04 /* zone hot */ -#define ATZ_F_PASSIVE 0x08 /* zone passive cooling */ -#define ATZ_F_PASSIVEONLY 0x10 /* zone is passive cooling only */ - -/* no active cooling level */ -#define ATZ_ACTIVE_NONE -1 - -/* constants */ -#define ATZ_TZP_RATE 300 /* default if no _TZP CM present (30 secs) */ -#define ATZ_NLEVELS 10 /* number of cooling levels, from ACPI spec */ -#define ATZ_ZEROC 2732 /* 0C, measured in 0.1 Kelvin */ -#define ATZ_TMP_INVALID 0xffffffff /* invalid temperature */ -#define ATZ_ZONE_EXPIRE 9000 /* zone info refetch interval (15min) */ +#define ATZ_F_CRITICAL 0x01 /* zone critical */ +#define ATZ_F_HOT 0x02 /* zone hot */ +#define ATZ_F_PASSIVE 0x04 /* zone passive cooling */ +#define ATZ_F_PASSIVEONLY 0x08 /* zone is passive cooling only */ -/* sensor indexes */ -#define ATZ_SENSOR_TEMP 0 /* thermal zone temperature */ +#define ATZ_ACTIVE_NONE -1 /* - * ACPI Temperature Zone information. Note all temperatures are reported - * in 0.1 Kelvin, and that the ACPI specification assumes that - * K = C + 273.2 rather than the nominal 273.15 used by envsys(4). - * So define an appropriate conversion. + * The constants are as follows: + * + * ATZ_TZP_RATE default polling interval (30 seconds) if no _TZP + * ATZ_NLEVELS number of cooling levels for _ACx and _ALx + * ATZ_ZEROC 0 C, measured in 0.1 Kelvin + * ATZ_TMP_INVALID temporarily invalid temperature + * ATZ_ZONE_EXPIRE zone info refetch interval (15 minutes) */ +#define ATZ_TZP_RATE 300 +#define ATZ_NLEVELS 10 +#define ATZ_ZEROC 2732 +#define ATZ_TMP_INVALID 0xffffffff +#define ATZ_ZONE_EXPIRE 9000 +/* + * All temperatures are reported in 0.1 Kelvin. + * The ACPI specification assumes that K = C + 273.2 + * rather than the nominal 273.15 used by envsys(4). + */ #define ATZ2UKELVIN(t) ((t) * 100000 - 50000) struct acpitz_zone { - /* Active cooling temperature threshold */ - uint32_t ac[ATZ_NLEVELS]; - /* Package of references to all active cooling devices for a level */ - ACPI_BUFFER al[ATZ_NLEVELS]; - /* Critical temperature threshold for system shutdown */ - uint32_t crt; - /* Critical temperature threshold for S4 sleep */ - uint32_t hot; - /* Package of references to processor objects for passive cooling */ - ACPI_BUFFER psl; - /* Conveys if temperatures are absolute or relative values. */ - uint32_t rtv; - /* Passive cooling temperature threshold */ - uint32_t psv; - /* Thermal constants for use in passive cooling formulas */ - uint32_t tc1, tc2; - /* Current temperature of the thermal zone */ - uint32_t prevtmp, tmp; - /* Thermal sampling period for passive cooling, in tenths of seconds */ - uint32_t tsp; - /* Package of references to devices in this TZ (optional) */ - ACPI_BUFFER tzd; - /* Recommended TZ polling frequency, in tenths of seconds */ - uint32_t tzp; - /* Thermal zone name */ - char *name; - /* FAN min, max, current rpms */ - uint32_t fanmin, fanmax, fancurrent; + char *name; + ACPI_BUFFER al[ATZ_NLEVELS]; + uint32_t ac[ATZ_NLEVELS]; + uint32_t crt; + uint32_t hot; + uint32_t rtv; + uint32_t psv; + uint32_t tc1; + uint32_t tc2; + uint32_t tmp; + uint32_t prevtmp; + uint32_t tzp; + uint32_t fanmin; + uint32_t fanmax; + uint32_t fancurrent; }; struct acpitz_softc { - struct acpi_devnode *sc_devnode; - struct acpitz_zone sc_zone; - struct callout sc_callout; - struct sysmon_envsys *sc_sme; - envsys_data_t sc_temp_sensor; - envsys_data_t sc_fan_sensor; - int sc_active; /* active cooling level */ - int sc_flags; - int sc_rate; /* tz poll rate */ - int sc_zone_expire; - - int sc_first; - int sc_have_fan; /* FAN sensor is optional */ + struct acpi_devnode *sc_node; + struct sysmon_envsys *sc_sme; + struct acpitz_zone sc_zone; + struct callout sc_callout; + envsys_data_t sc_temp_sensor; + envsys_data_t sc_fan_sensor; + int sc_active; + int sc_flags; + int sc_zone_expire; + bool sc_first; + bool sc_have_fan; }; -static int acpitz_match(device_t, cfdata_t, void *); -static void acpitz_attach(device_t, device_t, void *); -static int acpitz_detach(device_t, int); - -static void acpitz_get_status(void *); -static void acpitz_get_zone(void *, int); -static void acpitz_get_zone_quiet(void *); -static char *acpitz_celcius_string(int); -static void acpitz_print_status(device_t); -static void acpitz_power_off(struct acpitz_softc *); -static void acpitz_power_zone(struct acpitz_softc *, int, int); -static void acpitz_sane_temp(uint32_t *tmp); -static ACPI_STATUS - acpitz_switch_cooler(ACPI_OBJECT *, void *); -static void acpitz_notify_handler(ACPI_HANDLE, uint32_t, void *); -static int acpitz_get_integer(device_t, const char *, uint32_t *); -static void acpitz_tick(void *); -static void acpitz_init_envsys(device_t); -static void acpitz_get_limits(struct sysmon_envsys *, envsys_data_t *, - sysmon_envsys_lim_t *, uint32_t *); -static int acpitz_get_fanspeed(device_t, uint32_t *, - uint32_t *, uint32_t *); +static int acpitz_match(device_t, cfdata_t, void *); +static void acpitz_attach(device_t, device_t, void *); +static int acpitz_detach(device_t, int); +static void acpitz_get_status(void *); +static void acpitz_get_zone(void *, int); +static void acpitz_get_zone_quiet(void *); +static char *acpitz_celcius_string(int); +static void acpitz_power_off(struct acpitz_softc *); +static void acpitz_power_zone(struct acpitz_softc *, int, int); +static void acpitz_sane_temp(uint32_t *tmp); +static ACPI_STATUS acpitz_switch_cooler(ACPI_OBJECT *, void *); +static void acpitz_notify_handler(ACPI_HANDLE, uint32_t, void *); +static int acpitz_get_integer(device_t, const char *, uint32_t *); +static void acpitz_tick(void *); +static void acpitz_init_envsys(device_t); +static void acpitz_get_limits(struct sysmon_envsys *, + envsys_data_t *, + sysmon_envsys_lim_t *, uint32_t *); +static int acpitz_get_fanspeed(device_t, uint32_t *, + uint32_t *, uint32_t *); #ifdef notyet -static ACPI_STATUS - acpitz_set_fanspeed(device_t, uint32_t); +static ACPI_STATUS acpitz_set_fanspeed(device_t, uint32_t); #endif CFATTACH_DECL_NEW(acpitz, sizeof(struct acpitz_softc), @@ -173,39 +155,42 @@ { struct acpitz_softc *sc = device_private(self); struct acpi_attach_args *aa = aux; + ACPI_INTEGER val; ACPI_STATUS rv; - ACPI_INTEGER v; - -#if 0 - sc->sc_flags = ATZ_F_VERBOSE; -#endif - sc->sc_devnode = aa->aa_node; aprint_naive("\n"); aprint_normal(": ACPI Thermal Zone\n"); - rv = acpi_eval_integer(sc->sc_devnode->ad_handle, "_TZP", &v); - if (ACPI_FAILURE(rv)) - sc->sc_zone.tzp = ATZ_TZP_RATE; - else - sc->sc_zone.tzp = v; + sc->sc_first = true; + sc->sc_have_fan = false; + sc->sc_node = aa->aa_node; + sc->sc_zone.tzp = ATZ_TZP_RATE; + + /* + * The _TZP (ACPI 4.0, p. 430) defines the recommended + * polling interval (in tenths of seconds). A value zero + * means that polling "should not be necessary". + */ + rv = acpi_eval_integer(sc->sc_node->ad_handle, "_TZP", &val); + + if (ACPI_SUCCESS(rv) && val != 0) + sc->sc_zone.tzp = val; aprint_debug_dev(self, "sample rate %d.%ds\n", sc->sc_zone.tzp / 10, sc->sc_zone.tzp % 10); - /* XXX a value of 0 means "polling is not necessary" */ - if (sc->sc_zone.tzp == 0) - sc->sc_zone.tzp = ATZ_TZP_RATE; - sc->sc_zone_expire = ATZ_ZONE_EXPIRE / sc->sc_zone.tzp; - sc->sc_first = 1; - sc->sc_have_fan = 0; - if (acpitz_get_fanspeed(self, - &sc->sc_zone.fanmin, &sc->sc_zone.fanmax, &sc->sc_zone.fancurrent) - == 0) - sc->sc_have_fan = 1; - rv = acpi_eval_string(sc->sc_devnode->ad_handle, + /* + * XXX: The fan controls seen here are available on + * some HP laptops. Arguably these should not + * appear in a generic device driver like this. + */ + if (acpitz_get_fanspeed(self, &sc->sc_zone.fanmin, + &sc->sc_zone.fanmax, &sc->sc_zone.fancurrent) == 0) + sc->sc_have_fan = true; + + rv = acpi_eval_string(sc->sc_node->ad_handle, "REGN", &sc->sc_zone.name); if (ACPI_FAILURE(rv)) @@ -215,7 +200,7 @@ acpitz_get_status(self); (void)pmf_device_register(self, NULL, NULL); - (void)acpi_register_notify(sc->sc_devnode, acpitz_notify_handler); + (void)acpi_register_notify(sc->sc_node, acpitz_notify_handler); callout_init(&sc->sc_callout, CALLOUT_MPSAFE); callout_setfunc(&sc->sc_callout, acpitz_tick, self); @@ -238,7 +223,7 @@ callout_destroy(&sc->sc_callout); pmf_device_deregister(self); - acpi_deregister_notify(sc->sc_devnode); + acpi_deregister_notify(sc->sc_node); /* * Although the device itself should not contain any power @@ -281,13 +266,16 @@ device_t dv = opaque; struct acpitz_softc *sc = device_private(dv); uint32_t tmp, active, fmin, fmax, fcurrent; - int i, flags; + int changed, flags, i; sc->sc_zone_expire--; + if (sc->sc_zone_expire <= 0) { sc->sc_zone_expire = ATZ_ZONE_EXPIRE / sc->sc_zone.tzp; - if (sc->sc_flags & ATZ_F_VERBOSE) - printf("%s: force refetch zone\n", device_xname(dv)); + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "%s: zone refetch forced\n", device_xname(dv))); + acpitz_get_zone(dv, 0); } @@ -296,94 +284,93 @@ sc->sc_zone.prevtmp = sc->sc_zone.tmp; sc->sc_zone.tmp = tmp; - if (sc->sc_first) - sc->sc_zone.prevtmp = tmp; - /* XXX sanity check for tmp here? */ + + if (sc->sc_first != false) + sc->sc_zone.prevtmp = tmp; /* XXX: Sanity check? */ if (acpitz_get_fanspeed(dv, &fmin, &fmax, &fcurrent) == 0) { + if (fcurrent != ATZ_TMP_INVALID) sc->sc_zone.fancurrent = fcurrent; } - /* - * The temperature unit for envsys(4) is microKelvin, so convert to - * that from ACPI's microKelvin. Also, the ACPI specification assumes - * that K = C + 273.2 rather than the nominal 273.15 used by envsys(4), - * so we correct for that too. - */ - sc->sc_temp_sensor.value_cur = ATZ2UKELVIN(sc->sc_zone.tmp); sc->sc_temp_sensor.state = ENVSYS_SVALID; + sc->sc_temp_sensor.value_cur = ATZ2UKELVIN(sc->sc_zone.tmp); - sc->sc_fan_sensor.value_cur = sc->sc_zone.fancurrent; sc->sc_fan_sensor.state = ENVSYS_SVALID; + sc->sc_fan_sensor.value_cur = sc->sc_zone.fancurrent; - if (sc->sc_flags & ATZ_F_VERBOSE) - acpitz_print_status(dv); + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: zone temperature is %s C\n", + device_xname(dv), acpitz_celcius_string(sc->sc_zone.tmp))); - if (sc->sc_flags & ATZ_F_PASSIVEONLY) { - /* Passive Cooling: XXX not yet */ + /* + * XXX: Passive cooling is not yet supported. + */ + if ((sc->sc_flags & ATZ_F_PASSIVEONLY) != 0) + return; - } else { - /* Active Cooling */ + /* + * As noted in ACPI 4.0 (p. 420), the temperature + * thresholds are conveyed in the optional _ACx + * object (x = 0 ... 9). The smaller the x, the + * greater the cooling level. We prefer to keep + * the highest cooling mode when in "active". + */ + active = ATZ_ACTIVE_NONE; - /* temperature threshold: _AC0 > ... > _AC9 */ - active = ATZ_ACTIVE_NONE; - for (i = ATZ_NLEVELS - 1; i >= 0; i--) { - if (sc->sc_zone.ac[i] == ATZ_TMP_INVALID) - continue; - - /* we want to keep highest cooling mode in 'active' */ - if (sc->sc_zone.ac[i] <= tmp) - active = i; - } - - flags = sc->sc_flags & - ~(ATZ_F_CRITICAL|ATZ_F_HOT|ATZ_F_PASSIVE); - if (sc->sc_zone.psv != ATZ_TMP_INVALID && - tmp >= sc->sc_zone.psv) - flags |= ATZ_F_PASSIVE; - if (sc->sc_zone.hot != ATZ_TMP_INVALID && - tmp >= sc->sc_zone.hot) - flags |= ATZ_F_HOT; - if (sc->sc_zone.crt != ATZ_TMP_INVALID && - tmp >= sc->sc_zone.crt) - flags |= ATZ_F_CRITICAL; - - if (flags != sc->sc_flags) { - int changed = (sc->sc_flags ^ flags) & flags; - sc->sc_flags = flags; - if (changed & ATZ_F_CRITICAL) { - sc->sc_temp_sensor.state = ENVSYS_SCRITOVER; - aprint_debug_dev(dv, - "zone went critical at temp %sC\n", - acpitz_celcius_string(tmp)); - } else if (changed & ATZ_F_HOT) { - sc->sc_temp_sensor.state = ENVSYS_SCRITOVER; - aprint_debug_dev(dv, - "zone went hot at temp %sC\n", - acpitz_celcius_string(tmp)); - } - } + for (i = ATZ_NLEVELS - 1; i >= 0; i--) { + + if (sc->sc_zone.ac[i] == ATZ_TMP_INVALID) + continue; + + if (sc->sc_zone.ac[i] <= tmp) + active = i; + } + + flags = sc->sc_flags & ~(ATZ_F_CRITICAL | ATZ_F_HOT | ATZ_F_PASSIVE); + + if (sc->sc_zone.psv != ATZ_TMP_INVALID && tmp >= sc->sc_zone.psv) + flags |= ATZ_F_PASSIVE; + + if (sc->sc_zone.hot != ATZ_TMP_INVALID && tmp >= sc->sc_zone.hot) + flags |= ATZ_F_HOT; - /* power on fans */ - if (sc->sc_active != active) { - if (sc->sc_active != ATZ_ACTIVE_NONE) - acpitz_power_zone(sc, sc->sc_active, 0); + if (sc->sc_zone.crt != ATZ_TMP_INVALID && tmp >= sc->sc_zone.crt) + flags |= ATZ_F_CRITICAL; - if (active != ATZ_ACTIVE_NONE) { - if (sc->sc_flags & ATZ_F_VERBOSE) - printf("%s: active cooling level %u\n", - device_xname(dv), active); - acpitz_power_zone(sc, active, 1); - } else if (sc->sc_flags & ATZ_F_VERBOSE) - printf("%s: no active cooling level\n", - device_xname(dv)); + if (flags != sc->sc_flags) { - sc->sc_active = active; + changed = (sc->sc_flags ^ flags) & flags; + sc->sc_flags = flags; + + if ((changed & ATZ_F_CRITICAL) != 0) { + sc->sc_temp_sensor.state = ENVSYS_SCRITOVER; + + aprint_debug_dev(dv, "zone went critical, %s C\n", + acpitz_celcius_string(tmp)); + + } else if ((changed & ATZ_F_HOT) != 0) { + sc->sc_temp_sensor.state = ENVSYS_SCRITOVER; + + aprint_debug_dev(dv, "zone went hot, %s C\n", + acpitz_celcius_string(tmp)); } } - return; + /* Power on the fans. */ + if (sc->sc_active != active) { + + if (sc->sc_active != ATZ_ACTIVE_NONE) + acpitz_power_zone(sc, sc->sc_active, 0); + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: active cooling " + "level %u\n", device_xname(dv), active)); + + if (active != ATZ_ACTIVE_NONE) + acpitz_power_zone(sc, active, 1); + + sc->sc_active = active; + } } static char * @@ -393,25 +380,11 @@ int dc; dc = abs(dk - ATZ_ZEROC); - snprintf(buf, sizeof(buf), "%s%d.%d", (dk >= ATZ_ZEROC)?"":"-", - dc / 10, dc % 10); - - return buf; -} - -static void -acpitz_print_status(device_t dv) -{ - struct acpitz_softc *sc = device_private(dv); - printf("%s: zone temperature is now %sC\n", device_xname(dv), - acpitz_celcius_string(sc->sc_zone.tmp)); - if (sc->sc_have_fan) { - printf("%s: fan rpm %u\n", device_xname(dv), - sc->sc_zone.fancurrent); - } + (void)snprintf(buf, sizeof(buf), "%s%d.%d", + (dk >= ATZ_ZEROC) ? "" : "-", dc / 10, dc % 10); - return; + return buf; } static ACPI_STATUS @@ -433,10 +406,8 @@ rv = acpi_eval_reference_handle(obj, &cooler); - if (ACPI_FAILURE(rv)) { - aprint_error("%s: failed to get reference handle\n", __func__); + if (ACPI_FAILURE(rv)) return rv; - } (void)acpi_power_set_from_handle(cooler, pwr_state); @@ -445,21 +416,24 @@ /* * acpitz_power_zone: - * power on or off the i:th part of the zone zone + * + * Power on or off the i:th part of the zone zone. */ static void acpitz_power_zone(struct acpitz_softc *sc, int i, int on) { + KASSERT(i >= 0 && i < ATZ_NLEVELS); - acpi_foreach_package_object(sc->sc_zone.al[i].Pointer, + (void)acpi_foreach_package_object(sc->sc_zone.al[i].Pointer, acpitz_switch_cooler, &on); } /* * acpitz_power_off: - * power off parts of the zone + * + * Power off parts of the zone. */ static void acpitz_power_off(struct acpitz_softc *sc) @@ -467,12 +441,15 @@ int i; for (i = 0 ; i < ATZ_NLEVELS; i++) { + if (sc->sc_zone.al[i].Pointer == NULL) continue; + acpitz_power_zone(sc, i, 0); } + sc->sc_active = ATZ_ACTIVE_NONE; - sc->sc_flags &= ~(ATZ_F_CRITICAL|ATZ_F_HOT|ATZ_F_PASSIVE); + sc->sc_flags &= ~(ATZ_F_CRITICAL | ATZ_F_HOT | ATZ_F_PASSIVE); } static void @@ -480,16 +457,19 @@ { device_t dv = opaque; struct acpitz_softc *sc = device_private(dv); + int comma, i, valid_levels; + ACPI_OBJECT *obj; ACPI_STATUS rv; - char buf[8]; - int i, valid_levels; + char buf[5]; - if (!sc->sc_first) { + if (sc->sc_first != true) { acpitz_power_off(sc); for (i = 0; i < ATZ_NLEVELS; i++) { + if (sc->sc_zone.al[i].Pointer != NULL) ACPI_FREE(sc->sc_zone.al[i].Pointer); + sc->sc_zone.al[i].Pointer = NULL; } } @@ -497,65 +477,70 @@ valid_levels = 0; for (i = 0; i < ATZ_NLEVELS; i++) { - ACPI_OBJECT *obj; - snprintf(buf, sizeof(buf), "_AC%d", i); + (void)snprintf(buf, sizeof(buf), "_AC%d", i); + if (acpitz_get_integer(dv, buf, &sc->sc_zone.ac[i])) continue; - snprintf(buf, sizeof(buf), "_AL%d", i); - rv = acpi_eval_struct(sc->sc_devnode->ad_handle, buf, + (void)snprintf(buf, sizeof(buf), "_AL%d", i); + + rv = acpi_eval_struct(sc->sc_node->ad_handle, buf, &sc->sc_zone.al[i]); + if (ACPI_FAILURE(rv)) { sc->sc_zone.al[i].Pointer = NULL; continue; } obj = sc->sc_zone.al[i].Pointer; - if (obj != NULL) { - if (obj->Type != ACPI_TYPE_PACKAGE) { - aprint_error("%d not package\n", i); - ACPI_FREE(obj); - sc->sc_zone.al[i].Pointer = NULL; - continue; - } + + if (obj->Type != ACPI_TYPE_PACKAGE) { + sc->sc_zone.al[i].Pointer = NULL; + ACPI_FREE(obj); + continue; } - if (sc->sc_first) + if (sc->sc_first != false) aprint_normal(" active cooling level %d: %sC", i, acpitz_celcius_string(sc->sc_zone.ac[i])); valid_levels++; } - acpitz_get_integer(dv, "_TMP", &sc->sc_zone.tmp); - acpitz_get_integer(dv, "_CRT", &sc->sc_zone.crt); - acpitz_get_integer(dv, "_HOT", &sc->sc_zone.hot); - acpitz_get_integer(dv, "_PSV", &sc->sc_zone.psv); - acpitz_get_integer(dv, "_TC1", &sc->sc_zone.tc1); - acpitz_get_integer(dv, "_TC2", &sc->sc_zone.tc2); - -#if 0 - sc->sc_zone.psl.Length = ACPI_ALLOCATE_LOCAL_BUFFER; - sc->sc_zone.psl.Pointer = NULL; - AcpiEvaluateObject(sc->sc_devnode->ad_handle, - "_PSL", NULL, &sc->sc_zone.psl); -#endif + /* + * A brief summary (ACPI 4.0, section 11.4): + * + * _TMP : current temperature (in tenths of degrees) + * _CRT : critical trip-point at which to shutdown + * _HOT : critical trip-point at which to go to S4 + * _PSV : passive cooling policy threshold + * _TC1 : thermal constant for passive cooling + * _TC2 : thermal constant for passive cooling + */ + (void)acpitz_get_integer(dv, "_TMP", &sc->sc_zone.tmp); + (void)acpitz_get_integer(dv, "_CRT", &sc->sc_zone.crt); + (void)acpitz_get_integer(dv, "_HOT", &sc->sc_zone.hot); + (void)acpitz_get_integer(dv, "_PSV", &sc->sc_zone.psv); + (void)acpitz_get_integer(dv, "_TC1", &sc->sc_zone.tc1); + (void)acpitz_get_integer(dv, "_TC2", &sc->sc_zone.tc2); - /* ACPI spec: If _RTV is not present or present and zero, - * values are absolute. */ + /* + * If _RTV is not present or present and zero, + * values are absolute (see ACPI 4.0, 425). + */ acpitz_get_integer(dv, "_RTV", &sc->sc_zone.rtv); + if (sc->sc_zone.rtv == ATZ_TMP_INVALID) sc->sc_zone.rtv = 0; - acpitz_sane_temp(&sc->sc_zone.tmp); acpitz_sane_temp(&sc->sc_zone.crt); acpitz_sane_temp(&sc->sc_zone.hot); acpitz_sane_temp(&sc->sc_zone.psv); if (verbose != 0) { - int comma = 0; + comma = 0; aprint_verbose_dev(dv, ""); @@ -580,7 +565,7 @@ if (valid_levels == 0) { sc->sc_flags |= ATZ_F_PASSIVEONLY; - if (sc->sc_first) + if (sc->sc_first != false) aprint_verbose("%spassive cooling", comma ? ", " : ""); } @@ -592,44 +577,38 @@ acpitz_sane_temp(&sc->sc_zone.ac[i]); acpitz_power_off(sc); - sc->sc_first = 0; + sc->sc_first = false; } static void acpitz_notify_handler(ACPI_HANDLE hdl, uint32_t notify, void *opaque) { - device_t dv = opaque; ACPI_OSD_EXEC_CALLBACK func = NULL; - const char *name; - ACPI_STATUS rv; + device_t dv = opaque; switch (notify) { + case ACPI_NOTIFY_ThermalZoneStatusChanged: func = acpitz_get_status; - name = "status check"; break; + case ACPI_NOTIFY_ThermalZoneTripPointsChanged: case ACPI_NOTIFY_DeviceListsChanged: func = acpitz_get_zone_quiet; - name = "get zone"; break; + default: - aprint_debug_dev(dv, - "received unhandled notify message 0x%x\n", notify); + aprint_debug_dev(dv, "unknown notify 0x%02X\n", notify); return; } - KASSERT(func != NULL); - - rv = AcpiOsExecute(OSL_NOTIFY_HANDLER, func, dv); - if (ACPI_FAILURE(rv)) - aprint_debug_dev(dv, "unable to queue %s\n", name); + (void)AcpiOsExecute(OSL_NOTIFY_HANDLER, func, dv); } static void acpitz_sane_temp(uint32_t *tmp) { - /* Sane temperatures are beteen 0 and 150 C */ + /* Sane temperatures are beteen 0 and 150 C. */ if (*tmp < ATZ_ZEROC || *tmp > ATZ_ZEROC + 1500) *tmp = ATZ_TMP_INVALID; } @@ -638,17 +617,17 @@ acpitz_get_integer(device_t dv, const char *cm, uint32_t *val) { struct acpitz_softc *sc = device_private(dv); - ACPI_STATUS rv; ACPI_INTEGER tmp; + ACPI_STATUS rv; - rv = acpi_eval_integer(sc->sc_devnode->ad_handle, cm, &tmp); + rv = acpi_eval_integer(sc->sc_node->ad_handle, cm, &tmp); if (ACPI_FAILURE(rv)) { *val = ATZ_TMP_INVALID; - if (rv != AE_NOT_FOUND) - aprint_debug_dev(dv, "failed to evaluate %s: %s\n", - cm, AcpiFormatException(rv)); + ACPI_DEBUG_PRINT((ACPI_DB_DEBUG_OBJECT, + "%s: failed to evaluate %s: %s\n", + device_xname(dv), cm, AcpiFormatException(rv))); return 1; } @@ -663,34 +642,42 @@ uint32_t *fanmin, uint32_t *fanmax, uint32_t *fancurrent) { struct acpitz_softc *sc = device_private(dv); - ACPI_STATUS rv; - ACPI_HANDLE handle; ACPI_INTEGER fmin, fmax, fcurr; + ACPI_HANDLE handle; + ACPI_STATUS rv; int rc = 0; - handle = sc->sc_devnode->ad_handle; + handle = sc->sc_node->ad_handle; + rv = acpi_eval_integer(handle, "FMIN", &fmin); + if (ACPI_FAILURE(rv)) { fmin = ATZ_TMP_INVALID; rc = 1; } + rv = acpi_eval_integer(handle, "FMAX", &fmax); + if (ACPI_FAILURE(rv)) { fmax = ATZ_TMP_INVALID; rc = 1; } rv = acpi_eval_integer(handle, "FRSP", &fcurr); + if (ACPI_FAILURE(rv)) { fcurr = ATZ_TMP_INVALID; rc = 1; } - if (fanmin) + if (fanmin != NULL) *fanmin = fmin; - if (fanmax) + + if (fanmax != NULL) *fanmax = fmax; - if (fancurrent) + + if (fancurrent != NULL) *fancurrent = fcurr; + return rc; } @@ -699,14 +686,17 @@ acpitz_set_fanspeed(device_t dv, uint32_t fanspeed) { struct acpitz_softc *sc = device_private(dv); - ACPI_STATUS rv; ACPI_HANDLE handle; - handle = sc->sc_devnode->ad_handle; + ACPI_STATUS rv; + + handle = sc->sc_node->ad_handle; rv = acpi_eval_set_integer(handle, "FSSP", fanspeed); + if (ACPI_FAILURE(rv)) - aprint_debug_dev(dv, "failed to set fanspeed to %u rpm: %s\n", - fanspeed, AcpiFormatException(rv)); + aprint_debug_dev(dv, "failed to set fan speed to %u RPM: %s\n", + fanspeed, AcpiFormatException(rv)); + return rv; } #endif @@ -717,7 +707,7 @@ device_t dv = opaque; struct acpitz_softc *sc = device_private(dv); - AcpiOsExecute(OSL_NOTIFY_HANDLER, acpitz_get_status, dv); + (void)AcpiOsExecute(OSL_NOTIFY_HANDLER, acpitz_get_status, dv); callout_schedule(&sc->sc_callout, sc->sc_zone.tzp * hz / 10); } @@ -744,7 +734,7 @@ if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_temp_sensor)) goto out; - if (sc->sc_have_fan != 0) { + if (sc->sc_have_fan != false) { sc->sc_fan_sensor.flags = flags; sc->sc_fan_sensor.units = ENVSYS_SFANRPM;