1*01869ca4Swiz.\" $NetBSD: sysmon_envsys.9,v 1.46 2017/07/03 21:28:48 wiz Exp $ 208d5afa2Sxtraeme.\" 351e43163Sxtraeme.\" Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. 408d5afa2Sxtraeme.\" All rights reserved. 508d5afa2Sxtraeme.\" 608d5afa2Sxtraeme.\" This code is derived from software contributed to The NetBSD Foundation 708d5afa2Sxtraeme.\" by Juan Romero Pardines. 808d5afa2Sxtraeme.\" 908d5afa2Sxtraeme.\" Redistribution and use in source and binary forms, with or without 1008d5afa2Sxtraeme.\" modification, are permitted provided that the following conditions 1108d5afa2Sxtraeme.\" are met: 1208d5afa2Sxtraeme.\" 1. Redistributions of source code must retain the above copyright 1308d5afa2Sxtraeme.\" notice, this list of conditions and the following disclaimer. 1408d5afa2Sxtraeme.\" 2. Redistributions in binary form must reproduce the above copyright 1508d5afa2Sxtraeme.\" notice, this list of conditions and the following disclaimer in the 1608d5afa2Sxtraeme.\" documentation and/or other materials provided with the distribution. 1708d5afa2Sxtraeme.\" 1808d5afa2Sxtraeme.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1908d5afa2Sxtraeme.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2008d5afa2Sxtraeme.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2108d5afa2Sxtraeme.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2208d5afa2Sxtraeme.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2308d5afa2Sxtraeme.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2408d5afa2Sxtraeme.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2508d5afa2Sxtraeme.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2608d5afa2Sxtraeme.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2708d5afa2Sxtraeme.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2808d5afa2Sxtraeme.\" POSSIBILITY OF SUCH DAMAGE. 2908d5afa2Sxtraeme.\" 305c630951Spgoyette.Dd July 13, 2012 3108d5afa2Sxtraeme.Dt SYSMON_ENVSYS 9 3208d5afa2Sxtraeme.Os 3308d5afa2Sxtraeme.Sh NAME 3408d5afa2Sxtraeme.Nm sysmon_envsys 3508d5afa2Sxtraeme.Nd kernel part of the envsys 2 framework 3608d5afa2Sxtraeme.Sh SYNOPSIS 3708d5afa2Sxtraeme.In dev/sysmon/sysmonvar.h 3831962fc6Sxtraeme.Ft struct sysmon_envsys * 3931962fc6Sxtraeme.Fn sysmon_envsys_create "void" 4008d5afa2Sxtraeme.Ft void 4131962fc6Sxtraeme.Fn sysmon_envsys_destroy "struct sysmon_envsys *" 4231962fc6Sxtraeme.Ft int 4331962fc6Sxtraeme.Fn sysmon_envsys_register "struct sysmon_envsys *" 4431962fc6Sxtraeme.Ft void 4531962fc6Sxtraeme.Fn sysmon_envsys_unregister "struct sysmon_envsys *" 4631962fc6Sxtraeme.Ft int 471e4a5a2dSwiz.Fn sysmon_envsys_sensor_attach "struct sysmon_envsys *" "envsys_data_t *" 4831962fc6Sxtraeme.Ft int 491e4a5a2dSwiz.Fn sysmon_envsys_sensor_detach "struct sysmon_envsys *" "envsys_data_t *" 5003645b1cSpgoyette.Ft void 5103645b1cSpgoyette.Fn sysmon_envsys_sensor_event "struct sysmon_envsys *" "envsys_data_t *" "int" 52fd126623Spgoyette.Ft void 53730da129Spgoyette.Fn sysmon_envsys_foreach_sensor "sysmon_envsys_callback_t" "void *" "bool" 54fd126623Spgoyette.Ft int 55fd126623Spgoyette.Fn sysmon_envsys_update_limits "struct sysmon_envsys *" "envsys_data_t *" 5608d5afa2Sxtraeme.Sh DESCRIPTION 5708d5afa2Sxtraeme.Pp 5808d5afa2Sxtraeme.Nm 5908d5afa2Sxtraemeis the kernel part of the 6008d5afa2Sxtraeme.Xr envsys 4 6108d5afa2Sxtraemeframework. 62b3893f8dSxtraemeWith this framework you are able to register and unregister a 6308d5afa2Sxtraeme.Nm 6490d0830cSjruohodevice, attach or detach sensors into a device, and enable or disable 6531962fc6Sxtraemeautomatic monitoring for some sensors without any user interactivity, 6631962fc6Sxtraemeamong other things. 6708d5afa2Sxtraeme.Ss HOW TO USE THE FRAMEWORK 6831962fc6SxtraemeTo register a new driver to the 6908d5afa2Sxtraeme.Nm 7031962fc6Sxtraemeframework, a 7190d0830cSjruoho.Em sysmon_envsys 7231962fc6Sxtraemeobject must be allocated and initialized; the 7331962fc6Sxtraeme.Fn sysmon_envsys_create 741e4a5a2dSwizfunction is used for this. 7590d0830cSjruohoThis returns a zero'ed pointer to a 7690d0830cSjruoho.Em sysmon_envsys 7790d0830cSjruohostructure. 7831962fc6Sxtraeme.Pp 7990d0830cSjruohoOnce the object has been initialized, 8090d0830cSjruohoactual sensors may be initialized and attached (see the 8160a29410Swiz.Sx SENSOR DETAILS 8290d0830cSjruohosection for more information). 8390d0830cSjruohoThis is accomplished by the 8431962fc6Sxtraeme.Fn sysmon_envsys_sensor_attach 8590d0830cSjruohofunction, which will attach the 8690d0830cSjruoho.Em envsys_data_t 8790d0830cSjruoho(a sensor) specified as second argument into the 8890d0830cSjruoho.Em sysmon_envsys 8990d0830cSjruohoobject specified in the first argument. 9031962fc6Sxtraeme.Pp 9190d0830cSjruohoFinally, after all sensors have been attached, 9290d0830cSjruohothe device needs to set some required (and optional) members of the 9390d0830cSjruoho.Em sysmon_envsys 9490d0830cSjruohostructure before calling the 9531962fc6Sxtraeme.Fn sysmon_envsys_register 9631962fc6Sxtraemefunction to register the device. 9731962fc6Sxtraeme.Pp 9890d0830cSjruohoIn case of errors during the initialization, the 9931962fc6Sxtraeme.Fn sysmon_envsys_destroy 10090d0830cSjruohofunction should be used. 101e725035aSabhinavThis detaches all previously attached sensors and deallocates the 10290d0830cSjruoho.Em sysmon_envsys 10390d0830cSjruohoobject. 104b3893f8dSxtraeme.Pp 10503645b1cSpgoyetteSome sensors can be monitored, and when the sensor value changes an event 10603645b1cSpgoyettecan be delivered to the 10703645b1cSpgoyette.Xr powerd 8 10803645b1cSpgoyettedaemon. 10903645b1cSpgoyetteSensor monitoring can be performed by the 110598aaef0Swiz.Nm 11103645b1cSpgoyetteframework on a polled basis. 11203645b1cSpgoyetteAlternatively, the sensor's device driver can call the 11303645b1cSpgoyette.Fn sysmon_envsys_sensor_event 11403645b1cSpgoyettefunction to deliver the event without waiting for the device to be polled. 11503645b1cSpgoyette.Pp 116b3893f8dSxtraemeThe 117fd126623Spgoyette.Fn sysmon_envsys_foreach_sensor 118fd126623Spgoyettefunction can be used by other parts of the kernel to iterate over all 119fd126623Spgoyetteregistered sensors. 120fd126623SpgoyetteThis capability is used by the 121730da129Spgoyette.Xr i386/apm 4 122fd126623Spgoyettedriver to summarize the state of all battery sensors. 123fd126623Spgoyette.Pp 124fd126623SpgoyetteDrivers can also call the 125fd126623Spgoyette.Fn sysmon_envsys_update_limits 126e725035aSabhinavfunction when it is necessary to reinitialize a sensor's threshold values. 127fd126623SpgoyetteThis is used by the 128fd126623Spgoyette.Xr acpibat 4 129fd126623Spgoyettedriver when a new battery is inserted. 130fd126623Spgoyette.Pp 131fd126623SpgoyetteThe 132b3893f8dSxtraeme.Em sysmon_envsys 133946a137eSsnjstructure is defined as follows 13408d5afa2Sxtraeme(only the public members are shown): 13508d5afa2Sxtraeme.Bd -literal 13608d5afa2Sxtraemestruct sysmon_envsys { 13708d5afa2Sxtraeme const char *sme_name; 13808d5afa2Sxtraeme int sme_flags; 1397ade6d03Sxtraeme int sme_class; 14031962fc6Sxtraeme uint64_t sme_events_timeout; 14108d5afa2Sxtraeme void *sme_cookie; 14231962fc6Sxtraeme void (*sme_refresh)(struct sysmon_envsys *, envsys_data_t *); 14345f47178Spgoyette void (*sme_set_limits)(struct sysmon_envsys *, envsys_data_t *, 144534b0807Spgoyette sysmon_envsys_lim_t *, uint32_t *); 14545f47178Spgoyette void (*sme_get_limits)(struct sysmon_envsys *, envsys_data_t *, 146534b0807Spgoyette sysmon_envsys_lim_t *, uint32_t *); 14708d5afa2Sxtraeme}; 14808d5afa2Sxtraeme.Ed 14908d5afa2Sxtraeme.Pp 150b3893f8dSxtraemeThe members have the following meaning: 15108d5afa2Sxtraeme.Pp 15290d0830cSjruoho.Bl -tag -width "sme_events_timeout" 153b3893f8dSxtraeme.It Fa sme_class 1541e4a5a2dSwizThis specifies the class of the sysmon envsys device. 1551e4a5a2dSwizSee the 156b3893f8dSxtraeme.Sy DEVICE CLASSES 157b3893f8dSxtraemesection for more information (OPTIONAL). 15808d5afa2Sxtraeme.It Fa sme_name 159b3893f8dSxtraemeThe name that will be used in the driver (REQUIRED). 16008d5afa2Sxtraeme.It Fa sme_flags 16108d5afa2SxtraemeAdditional flags for the 16208d5afa2Sxtraeme.Nm 1631e4a5a2dSwizdevice. 1641e4a5a2dSwizCurrently supporting 16531962fc6Sxtraeme.Ar SME_DISABLE_REFRESH . 16608d5afa2SxtraemeIf enabled, the 16731962fc6Sxtraeme.Ar sme_refresh 16808d5afa2Sxtraemefunction callback won't be used 16990d0830cSjruohoto refresh sensor data and the driver will use its own method (OPTIONAL). 17031962fc6Sxtraeme.It Fa sme_events_timeout 171c2357777SpgoyetteThis is used to specify the default timeout value (in seconds) that will be 172c2357777Spgoyetteused to check for critical events if any monitoring flag was set (OPTIONAL). 17308d5afa2Sxtraeme.El 17408d5afa2Sxtraeme.Pp 17508d5afa2SxtraemeIf the driver wants to refresh sensors data via the 17608d5afa2Sxtraeme.Nm 1779310b4d9Spgoyetteframework, the following members may be specified: 17808d5afa2Sxtraeme.Pp 17990d0830cSjruoho.Bl -tag -width "sme_events_timeout" 18008d5afa2Sxtraeme.It Fa sme_cookie 18190d0830cSjruohoTypically a pointer to the device struct (also called 1821e4a5a2dSwiz.Dq softc ) . 1831e4a5a2dSwizThis may be used in the 184c2357777Spgoyette.Sy sme_refresh , 185c2357777Spgoyette.Sy sme_get_limits , 186c2357777Spgoyetteor 187c2357777Spgoyette.Sy sme_set_limits 188c2357777Spgoyettefunction callbacks. 18931962fc6Sxtraeme.It Fa sme_refresh 190b3893f8dSxtraemePointer to a function that will be used to refresh sensor data in 1911e4a5a2dSwizthe device. 1921e4a5a2dSwizThis can be used to set the state and other properties of the 1939310b4d9Spgoyettesensor depending on the data returned by the driver. 19408d5afa2Sxtraeme.Em NOTE : 19508d5afa2Sxtraeme.Em You don't have to refresh all sensors, only the sensor specified by the 196*01869ca4Swiz.Sy edata->sensor 19708d5afa2Sxtraeme.Em index . 1989310b4d9SpgoyetteIf this member is not specified, the device driver will be totally 1999310b4d9Spgoyetteresponsible for all updates of this sensor; the 2009310b4d9Spgoyette.Nm 2019310b4d9Spgoyetteframework will not be able to update the sensor value. 202c2357777Spgoyette.It Fa sme_get_limits 203c2357777SpgoyettePointer to a function that will be used to obtain from the driver the 204c2357777Spgoyetteinitial limits (or thresholds) used when monitoring a sensor's value. 205c2357777Spgoyette(See the 206c2357777Spgoyette.Sx SENSOR DETAILS 207c2357777Spgoyettesection for more information.) 208f362df9bSwizIf this member is not specified, the 209f362df9bSwiz.Dv ENVSYS_FMONLIMITS 210f362df9bSwizflag will be ignored, and limit monitoring will not occur until 211f362df9bSwizappropriate limits are enabled from userland via 2129310b4d9Spgoyette.Xr envstat 8 . 213c2357777Spgoyette.It Fa sme_set_limits 214c2357777SpgoyettePointer to a function that alerts the device driver whenever monitoring 215c2357777Spgoyettelimits (or thresholds) are updated by the user. 216c2357777SpgoyetteSetting this function allows the device driver to reprogram hardware 217fd126623Spgoyettelimits (if provided by the device) when the user-specificied limits are 218fd126623Spgoyetteupdated, and gives the driver direct control over setting the sensor's 219fd126623Spgoyettestate based on hardware status. 220fd126623Spgoyette.Pp 221fd126623SpgoyetteThe 222fd126623Spgoyette.Fa sme_set_limits 223fd126623Spgoyettecallback can be invoked with the third argument (a pointer to the new 2248936a2b7Swizlimits) set to a 2258936a2b7Swiz.Dv NULL 2268936a2b7Swizpointer. 227fd126623SpgoyetteDevice drivers must recognize this as a request to restore the sensor 228fd126623Spgoyettelimits to their original, boot-time values. 229fd126623Spgoyette.Pp 230fd126623SpgoyetteIf the 231fd126623Spgoyette.Fa sme_set_limits 232fd126623Spgoyettemember is not specified, the device driver is not informed of changes to 233fd126623Spgoyettethe sensor's limit values, and the 2349310b4d9Spgoyette.Nm 2359310b4d9Spgoyetteframework performs all limit checks in software. 23608d5afa2Sxtraeme.El 23708d5afa2Sxtraeme.Pp 238b3893f8dSxtraemeNote that it's not necessary to refresh the sensors data before the 23987777651Sxtraemedriver is registered, only do it if you need the data in your driver 24087777651Sxtraemeto check for a specific condition. 24108d5afa2Sxtraeme.Pp 24231962fc6SxtraemeThe timeout value for the monitoring events on a device may be changed via the 24360a29410Swiz.Dv ENVSYS_SETDICTIONARY 24431962fc6Sxtraeme.Xr ioctl 2 24531962fc6Sxtraemeor the 24631962fc6Sxtraeme.Xr envstat 8 24731962fc6Sxtraemecommand. 248e7193335Sxtraeme.Pp 24908d5afa2SxtraemeTo unregister a driver previously registered with the 25008d5afa2Sxtraeme.Nm 25108d5afa2Sxtraemeframework, the 25208d5afa2Sxtraeme.Fn sysmon_envsys_unregister 2531e4a5a2dSwizfunction must be used. 2541e4a5a2dSwizIf there were monitoring events registered for the 25531962fc6Sxtraemedriver, they all will be destroyed before the device is unregistered and 25690d0830cSjruohoits sensors are detached. 25790d0830cSjruohoFinally the 25890d0830cSjruoho.Em sysmon_envsys 25931962fc6Sxtraemeobject will be freed, so there's no need to call 26090d0830cSjruoho.Fn sysmon_envsys_destroy . 261b3893f8dSxtraeme.Ss DEVICE CLASSES 262b3893f8dSxtraemeThe 263b3893f8dSxtraeme.Fa sme_class 264b3893f8dSxtraememember of the 265b3893f8dSxtraeme.Fa sysmon_envsys 266b3893f8dSxtraemestructure is an optional flag that specifies the class of the 2671e4a5a2dSwizsysmon envsys device. 2681e4a5a2dSwizCurrently there are two classes: 26908d5afa2Sxtraeme.Pp 270b3893f8dSxtraeme.Bl -tag -width ident 271b3893f8dSxtraeme.It SME_CLASS_ACADAPTER 272b3893f8dSxtraeme.Pp 273b3893f8dSxtraemeThis class is for devices that want to act as an 274b3893f8dSxtraeme.Em AC adapter . 275b3893f8dSxtraemeThe device writer must ensure that at least there is a 276b3893f8dSxtraemesensor with 277b3893f8dSxtraeme.Em units 278b3893f8dSxtraemeof 279f362df9bSwiz.Dv ENVSYS_INDICATOR . 280b3893f8dSxtraemeThis will be used to report its current state (on/off). 281b3893f8dSxtraeme.It SME_CLASS_BATTERY 282b3893f8dSxtraeme.Pp 283c2357777SpgoyetteThis class is for devices that want to act as a 284b3893f8dSxtraeme.Em Battery . 285b3893f8dSxtraemeThe device writer must ensure that at least there are two sensors with 286b3893f8dSxtraemeunits of 287f362df9bSwiz.Dv ENVSYS_BATTERY_CAPACITY 288b3893f8dSxtraemeand 289f362df9bSwiz.Dv ENVSYS_BATTERY_CHARGE . 290b3893f8dSxtraeme.Pp 291c2357777SpgoyetteThese two sensors are used to ensure that the battery device can 292c2357777Spgoyettesend a 293b3893f8dSxtraeme.Em low-power 294b3893f8dSxtraemeevent to the 295b3893f8dSxtraeme.Xr powerd 8 296b3893f8dSxtraemedaemon (if running) when all battery devices are in a critical state. 297c2357777Spgoyette(The critical state occurs when a battery is not currently charging 29890d0830cSjruohoand its charge state is low or critical.) 299b3893f8dSxtraemeWhen the 300b3893f8dSxtraeme.Em low-power 301b3893f8dSxtraemecondition is met, an event is sent to the 302b3893f8dSxtraeme.Xr powerd 8 30390d0830cSjruohodaemon (if running), which will shutdown the system gracefully 30490d0830cSjruohoby executing the 30539d81999Snjoly.Pa /etc/powerd/scripts/sensor_battery 306b3893f8dSxtraemescript. 307b3893f8dSxtraeme.Pp 308b3893f8dSxtraemeIf 309b3893f8dSxtraeme.Xr powerd 8 310b3893f8dSxtraemeis not running, the system will be powered off via the 311b3893f8dSxtraeme.Xr cpu_reboot 9 312b3893f8dSxtraemecall with the 31360a29410Swiz.Dv RB_POWERDOWN 314b3893f8dSxtraemeflag. 315b3893f8dSxtraeme.Pp 316b3893f8dSxtraeme.El 317b3893f8dSxtraeme.Em NOTE : 318b3893f8dSxtraemeIf a 31960a29410Swiz.Dv SME_CLASS_ACADAPTER 320b3893f8dSxtraemeor 32160a29410Swiz.Dv SME_CLASS_BATTERY 322c2357777Spgoyetteclass device doesn't have the sensors required, the 323b3893f8dSxtraeme.Em low-power 324b3893f8dSxtraemeevent will never be sent, and the graceful shutdown won't be possible. 32508d5afa2Sxtraeme.Ss SENSOR DETAILS 32608d5afa2SxtraemeEach sensor uses a 32708d5afa2Sxtraeme.Sy envsys_data_t 328946a137eSsnjstructure, it's defined as follows (only the public members are shown); 32908d5afa2Sxtraeme.Bd -literal 33008d5afa2Sxtraemetypedef struct envsys_data { 33108d5afa2Sxtraeme uint32_t units; 33208d5afa2Sxtraeme uint32_t state; 33308d5afa2Sxtraeme uint32_t flags; 33408d5afa2Sxtraeme uint32_t rpms; 33508d5afa2Sxtraeme int32_t rfact; 33608d5afa2Sxtraeme int32_t value_cur; 33708d5afa2Sxtraeme int32_t value_max; 33808d5afa2Sxtraeme int32_t value_min; 33908d5afa2Sxtraeme int32_t value_avg; 340534b0807Spgoyette sysmon_envsys_lim_t limits; 341534b0807Spgoyette int upropset; 34208d5afa2Sxtraeme char desc[ENVSYS_DESCLEN]; 34308d5afa2Sxtraeme} envsys_data_t; 34408d5afa2Sxtraeme.Ed 34508d5afa2Sxtraeme.Pp 34608d5afa2SxtraemeThe members for the 34708d5afa2Sxtraeme.Sy envsys_data_t 34808d5afa2Sxtraemestructure have the following meaning: 34908d5afa2Sxtraeme.Pp 35008d5afa2Sxtraeme.Bl -tag -width cdoscdosrunru 35108d5afa2Sxtraeme.It Fa units 35231962fc6SxtraemeUsed to set the units type. 35308d5afa2Sxtraeme.It Fa state 35408d5afa2SxtraemeUsed to set the current state. 35508d5afa2Sxtraeme.It Fa flags 35608d5afa2SxtraemeUsed to set additional flags. 3570dfc1448SpgoyetteAmong other uses, if one or more of the 3580dfc1448Spgoyette.Dv ENVSYS_FMONxxx 3590dfc1448Spgoyetteflags are set, automatic sensor monitoring will be enabled. 3600dfc1448SpgoyettePeriodically, the sensor's value will be checked and if certain 3610dfc1448Spgoyetteconditions are met, an event will be sent to the 3620dfc1448Spgoyette.Xr powerd 8 3630dfc1448Spgoyettedaemon. 3640dfc1448Spgoyette.Em NOTE 3650dfc1448Spgoyette.Em that limits (or thresholds) can be set at any time to enable 3660dfc1448Spgoyette.Em monitoring that the sensor's value remains within those limits . 36708d5afa2Sxtraeme.It Fa rpms 36808d5afa2SxtraemeUsed to set the nominal RPM value for 36908d5afa2Sxtraeme.Sy fan 37008d5afa2Sxtraemesensors. 37108d5afa2Sxtraeme.It Fa rfact 37208d5afa2SxtraemeUsed to set the rfact value for 37308d5afa2Sxtraeme.Sy voltage 37408d5afa2Sxtraemesensors. 37508d5afa2Sxtraeme.It Fa value_cur 37608d5afa2SxtraemeUsed to set the current value. 37708d5afa2Sxtraeme.It Fa value_max 37808d5afa2SxtraemeUsed to set the maximum value. 37908d5afa2Sxtraeme.It Fa value_min 38008d5afa2SxtraemeUsed to set the minimum value. 38108d5afa2Sxtraeme.It Fa value_avg 38208d5afa2SxtraemeUsed to set the average value. 383534b0807Spgoyette.It Fa limits 384534b0807SpgoyetteStructure used to contain the sensor's alarm thresholds. 385534b0807Spgoyette.It Fa upropset 386534b0807SpgoyetteUsed to keep track of which sensor properties are set. 38708d5afa2Sxtraeme.It Fa desc 38808d5afa2SxtraemeUsed to set the description string. 38992f4397eSxtraeme.Em NOTE 39092f4397eSxtraeme.Em that the description string must be unique in a device, and sensors with 391b5822e79Sxtraeme.Em duplicate or empty description will simply be ignored . 39208d5afa2Sxtraeme.El 39308d5afa2Sxtraeme.Pp 39408d5afa2SxtraemeUsers of this framework must take care about the following points: 39508d5afa2Sxtraeme.Bl -bullet 39608d5afa2Sxtraeme.It 39731962fc6SxtraemeThe 39831962fc6Sxtraeme.Ar desc 39931962fc6Sxtraememember needs to have a valid description, unique in a device and non empty 40031962fc6Sxtraemeto be valid. 40108d5afa2Sxtraeme.It 40208d5afa2SxtraemeThe 40308d5afa2Sxtraeme.Ar units 4041e4a5a2dSwiztype must be valid. 4051e4a5a2dSwizThe following units are defined: 40608d5afa2Sxtraeme.Pp 40721ba5835Sxtraeme.Bl -tag -width "ENVSYS_BATTERY_CAPACITY" -compact 408f362df9bSwiz.It Dv ENVSYS_STEMP 409582662caSriastradhFor temperature sensors, in microkelvins. 410f362df9bSwiz.It Dv ENVSYS_SFANRPM 41108d5afa2SxtraemeFor fan sensors. 412f362df9bSwiz.It Dv ENVSYS_SVOLTS_AC 41308d5afa2SxtraemeFor AC Voltage. 414f362df9bSwiz.It Dv ENVSYS_SVOLTS_DC 41508d5afa2SxtraemeFor DC Voltage. 416f362df9bSwiz.It Dv ENVSYS_SOHMS 41708d5afa2SxtraemeFor Ohms. 418f362df9bSwiz.It Dv ENVSYS_SWATTS 41908d5afa2SxtraemeFor Watts. 420f362df9bSwiz.It Dv ENVSYS_SAMPS 42108d5afa2SxtraemeFor Ampere. 422f362df9bSwiz.It Dv ENVSYS_SWATTHOUR 42308d5afa2SxtraemeFor Watts hour. 424f362df9bSwiz.It Dv ENVSYS_SAMPHOUR 42508d5afa2SxtraemeFor Ampere hour. 426f362df9bSwiz.It Dv ENVSYS_INDICATOR 42708d5afa2SxtraemeFor sensors that only want a boolean type. 428f362df9bSwiz.It Dv ENVSYS_INTEGER 42908d5afa2SxtraemeFor sensors that only want an integer type. 430f362df9bSwiz.It Dv ENVSYS_DRIVE 43108d5afa2SxtraemeFor drive sensors. 432f362df9bSwiz.It Dv ENVSYS_BATTERY_CAPACITY 4331e4a5a2dSwizFor Battery device classes. 434f362df9bSwizThis sensor unit uses the 435f362df9bSwiz.Dv ENVSYS_BATTERY_CAPACITY_* 436b5822e79Sxtraemevalues in 437b5822e79Sxtraeme.Ar value_cur 4381e4a5a2dSwizto report its current capacity to userland. 4391e4a5a2dSwizMandatory if 44060a29410Swiz.Fa sme_class 441b3893f8dSxtraemeis set to 44260a29410Swiz.Dv SME_CLASS_BATTERY . 443f362df9bSwiz.It Dv ENVSYS_BATTERY_CHARGE 4441e4a5a2dSwizFor Battery device classes. 4451e4a5a2dSwizThis sensor is equivalent to the Indicator type, it's a boolean. 4461e4a5a2dSwizUse it to specify in what state is the Battery state: 447b3893f8dSxtraeme.Sy true 448b3893f8dSxtraemeif the battery is currently charging or 449b3893f8dSxtraeme.Sy false 4501e4a5a2dSwizotherwise. 4511e4a5a2dSwizMandatory if 45260a29410Swiz.Fa sme_class 453b3893f8dSxtraemeis set to 45460a29410Swiz.Dv SME_CLASS_BATTERY . 45508d5afa2Sxtraeme.El 45608d5afa2Sxtraeme.It 4578ac95dc8SxtraemeWhen initializing or refreshing the sensor, the 45808d5afa2Sxtraeme.Ar state 4598ac95dc8Sxtraememember should be set to a known state (otherwise it will be in 4601e4a5a2dSwizunknown state). 4611e4a5a2dSwizPossible values: 46208d5afa2Sxtraeme.Pp 46308d5afa2Sxtraeme.Bl -tag -width "ENVSYS_SCRITUNDERXX" -compact 464f362df9bSwiz.It Dv ENVSYS_SVALID 46508d5afa2SxtraemeSets the sensor to a valid state. 466f362df9bSwiz.It Dv ENVSYS_SINVALID 46708d5afa2SxtraemeSets the sensor to an invalid state. 468f362df9bSwiz.It Dv ENVSYS_SCRITICAL 46908d5afa2SxtraemeSets the sensor to a critical state. 470f362df9bSwiz.It Dv ENVSYS_SCRITUNDER 47108d5afa2SxtraemeSets the sensor to a critical under state. 472f362df9bSwiz.It Dv ENVSYS_SCRITOVER 47308d5afa2SxtraemeSets the sensor to a critical over state. 474f362df9bSwiz.It Dv ENVSYS_SWARNUNDER 47508d5afa2SxtraemeSets the sensor to a warning under state. 476f362df9bSwiz.It Dv ENVSYS_SWARNOVER 47708d5afa2SxtraemeSets the sensor to a warning over state. 47808d5afa2Sxtraeme.El 47908d5afa2Sxtraeme.Pp 48008d5afa2Sxtraeme.It 48108d5afa2SxtraemeThe 48208d5afa2Sxtraeme.Ar flags 48308d5afa2Sxtraememember accepts one or more of the following flags: 48408d5afa2Sxtraeme.Pp 48508d5afa2Sxtraeme.Bl -tag -width "ENVSYS_FCHANGERFACTXX" 486f362df9bSwiz.It Dv ENVSYS_FCHANGERFACT 48708d5afa2SxtraemeMarks the sensor with ability to change the 48808d5afa2Sxtraeme.Ar rfact 4891e4a5a2dSwizvalue on the fly (in voltage sensors). 4901e4a5a2dSwizThe 49108d5afa2Sxtraeme.Ar rfact 49208d5afa2Sxtraememember must be used in the correct place of the code 49308d5afa2Sxtraemethat retrieves and converts the value of the sensor. 494f362df9bSwiz.It Dv ENVSYS_FPERCENT 49508d5afa2SxtraemeThis uses the 49608d5afa2Sxtraeme.Ar value_cur 49708d5afa2Sxtraemeand 49808d5afa2Sxtraeme.Ar value_max 4991e4a5a2dSwizmembers to make a percentage. 5001e4a5a2dSwizBoth values must be enabled and have data. 501f362df9bSwiz.It Dv ENVSYS_FVALID_MAX 50208d5afa2SxtraemeMarks the 50308d5afa2Sxtraeme.Ar value_max 50408d5afa2Sxtraemevalue as valid. 505f362df9bSwiz.It Dv ENVSYS_FVALID_MIN 50608d5afa2SxtraemeMarks the 50708d5afa2Sxtraeme.Ar value_min 50808d5afa2Sxtraemevalue as valid. 509f362df9bSwiz.It Dv ENVSYS_FVALID_AVG 51008d5afa2SxtraemeMarks the 51108d5afa2Sxtraeme.Ar value_avg 51208d5afa2Sxtraemevalue as valid. 513f362df9bSwiz.It Dv ENVSYS_FMONCRITICAL 51408d5afa2SxtraemeEnables and registers a new event to monitor a critical state. 515f362df9bSwiz.It Dv ENVSYS_FMONLIMITS 5165a84f306SpgoyetteEnables and registers a new event to monitor a sensor's value crossing 5175a84f306Spgoyettelimits or thresholds. 518f362df9bSwiz.It Dv ENVSYS_FMONSTCHANGED 51990d0830cSjruohoEnables and registers a new event to monitor battery capacity or drive state 5201e4a5a2dSwizsensors. 52190d0830cSjruohoThe flag is not effective if the 522b5822e79Sxtraeme.Ar units 52390d0830cSjruohomember is not 524f362df9bSwiz.Dv ENVSYS_DRIVE 525b5822e79Sxtraemeor 526f362df9bSwiz.Dv ENVSYS_BATTERY_CAPACITY . 527f362df9bSwiz.It Dv ENVSYS_FMONNOTSUPP 528c2357777SpgoyetteDisallows setting of limits (or thresholds) via the 52960a29410Swiz.Dv ENVSYS_SETDICTIONARY 5301e4a5a2dSwiz.Xr ioctl 2 . 53190d0830cSjruohoThis flag only disables setting the limits from userland. 53290d0830cSjruohoIt has no effect on monitoring flags set by the driver. 5335c630951Spgoyette.It Dv ENVSYS_FHAS_ENTROPY 5345c630951SpgoyetteAllows this sensor to provide entropy for 5355c630951Spgoyette.Xr rnd 4 . 53608d5afa2Sxtraeme.El 53708d5afa2Sxtraeme.Pp 53808d5afa2Sxtraeme.Em If the driver has to use any of the 53908d5afa2Sxtraeme.Ar value_max , 54090d0830cSjruoho.Ar value_min , 54108d5afa2Sxtraeme.Em or 54208d5afa2Sxtraeme.Ar value_avg 54348bffe7fSwiz.Em members, they should be marked as valid with the appropriate flag . 54408d5afa2Sxtraeme.Pp 54508d5afa2Sxtraeme.It 54608d5afa2SxtraemeIf 54708d5afa2Sxtraeme.Ar units 54808d5afa2Sxtraemeis set to 549f362df9bSwiz.Dv ENVSYS_DRIVE , 550c2357777Spgoyettethe 55108d5afa2Sxtraeme.Ar value_cur 552c2357777Spgoyettemember must be set to one of the following predefined states: 55308d5afa2Sxtraeme.Pp 55408d5afa2Sxtraeme.Bl -tag -width "ENVSYS_DRIVE_POWERDOWNXX" -compact 555f362df9bSwiz.It Dv ENVSYS_DRIVE_EMPTY 55608d5afa2SxtraemeDrive state is unknown. 557f362df9bSwiz.It Dv ENVSYS_DRIVE_READY 55808d5afa2SxtraemeDrive is ready. 559f362df9bSwiz.It Dv ENVSYS_DRIVE_POWERUP 56008d5afa2SxtraemeDrive is powering up. 561f362df9bSwiz.It Dv ENVSYS_DRIVE_ONLINE 56208d5afa2SxtraemeDrive is online. 563f362df9bSwiz.It Dv ENVSYS_DRIVE_OFFLINE 56451e43163SxtraemeDrive is offline. 565f362df9bSwiz.It Dv ENVSYS_DRIVE_IDLE 56608d5afa2SxtraemeDrive is idle. 567f362df9bSwiz.It Dv ENVSYS_DRIVE_ACTIVE 56808d5afa2SxtraemeDrive is active. 569f362df9bSwiz.It Dv ENVSYS_DRIVE_BUILD 57051e43163SxtraemeDrive is building. 571f362df9bSwiz.It Dv ENVSYS_DRIVE_REBUILD 57208d5afa2SxtraemeDrive is rebuilding. 573f362df9bSwiz.It Dv ENVSYS_DRIVE_POWERDOWN 57408d5afa2SxtraemeDrive is powering down. 575f362df9bSwiz.It Dv ENVSYS_DRIVE_FAIL 57608d5afa2SxtraemeDrive has failed. 577f362df9bSwiz.It Dv ENVSYS_DRIVE_PFAIL 57808d5afa2SxtraemeDrive has been degraded. 579f362df9bSwiz.It Dv ENVSYS_DRIVE_MIGRATING 580820f120bSxtraemeDrive is migrating. 581f362df9bSwiz.It Dv ENVSYS_DRIVE_CHECK 58251e43163SxtraemeDrive is checking its state. 58308d5afa2Sxtraeme.El 584b5822e79Sxtraeme.Pp 585b5822e79Sxtraeme.It 586b5822e79SxtraemeIf 587b5822e79Sxtraeme.Ar units 588b5822e79Sxtraemeis set to 589f362df9bSwiz.Dv ENVSYS_BATTERY_CAPACITY , 590c2357777Spgoyettethe 591b5822e79Sxtraeme.Ar value_cur 592c2357777Spgoyettemember must be set to one of the following predefined capacity states: 593b5822e79Sxtraeme.Pp 594e96c9940Snjoly.Bl -tag -width "ENVSYS_BATTERY_CAPACITY_CRITICAL" -compact 595f362df9bSwiz.It Dv ENVSYS_BATTERY_CAPACITY_NORMAL 59690d0830cSjruohoBattery charge is normal. 597f362df9bSwiz.It Dv ENVSYS_BATTERY_CAPACITY_CRITICAL 59890d0830cSjruohoBattery charge is critical. 599f362df9bSwiz.It Dv ENVSYS_BATTERY_CAPACITY_LOW 60090d0830cSjruohoBattery charge is low. 601f362df9bSwiz.It Dv ENVSYS_BATTERY_CAPACITY_WARNING 60290d0830cSjruohoBattery charge is on or below the warning capacity. 603b5822e79Sxtraeme.El 60408d5afa2Sxtraeme.It 60508d5afa2SxtraemeThe 60608d5afa2Sxtraeme.Xr envsys 4 60708d5afa2Sxtraemeframework expects to have the values converted to 6081e4a5a2dSwiza unit that can be converted to another one easily. 6091e4a5a2dSwizThat means the user 61048bffe7fSwizshould convert the value returned by the driver to the appropriate unit. 61108d5afa2SxtraemeFor example voltage sensors to 61208d5afa2Sxtraeme.Sy mV , 61308d5afa2Sxtraemetemperature sensors to 61408d5afa2Sxtraeme.Sy uK , 61508d5afa2SxtraemeWatts to 61608d5afa2Sxtraeme.Sy mW , 61708d5afa2SxtraemeAmpere to 61808d5afa2Sxtraeme.Sy mA , 61908d5afa2Sxtraemeetc. 62008d5afa2Sxtraeme.Pp 62108d5afa2SxtraemeThe following types shouldn't need any conversion: 622f362df9bSwiz.Dv ENVSYS_BATTERY_CAPACITY , 623f362df9bSwiz.Dv ENVSYS_BATTERY_CHARGE , 624f362df9bSwiz.Dv ENVSYS_INDICATOR , 62590d0830cSjruoho.Dv ENVSYS_INTEGER , 62608d5afa2Sxtraemeand 627f362df9bSwiz.Dv ENVSYS_DRIVE . 62808d5afa2Sxtraeme.Pp 62908d5afa2Sxtraeme.Em PLEASE NOTE THAT YOU MUST AVOID USING FLOATING POINT OPERATIONS 63008d5afa2Sxtraeme.Em IN KERNEL WHEN CONVERTING THE DATA RETURNED BY THE DRIVER TO THE 63148bffe7fSwiz.Em APPROPRIATE UNIT, IT'S NOT ALLOWED . 63208d5afa2Sxtraeme.Pp 63308d5afa2Sxtraeme.El 63408d5afa2Sxtraeme.Ss HOW TO ENABLE AUTOMATIC MONITORING IN SENSORS 63508d5afa2SxtraemeThe following example illustrates how to enable automatic monitoring 63608d5afa2Sxtraemein a virtual driver for a 63708d5afa2Sxtraeme.Em critical 63808d5afa2Sxtraemestate in the first sensor 63960a29410Swiz.Fa ( sc_sensor[0] ) : 64008d5afa2Sxtraeme.Pp 64108d5afa2Sxtraeme.Bd -literal 64208d5afa2Sxtraemeint 64308d5afa2Sxtraememydriver_initialize_sensors(struct mysoftc *sc) 64408d5afa2Sxtraeme{ 64508d5afa2Sxtraeme ... 64608d5afa2Sxtraeme /* sensor is initialized with a valid state */ 647*01869ca4Swiz sc->sc_sensor[0].state = ENVSYS_SVALID; 64808d5afa2Sxtraeme 64908d5afa2Sxtraeme /* 65008d5afa2Sxtraeme * the monitor member must be true to enable 65108d5afa2Sxtraeme * automatic monitoring. 65208d5afa2Sxtraeme */ 653*01869ca4Swiz sc->sc_sensor[0].monitor = true; 65408d5afa2Sxtraeme 65508d5afa2Sxtraeme /* and now we specify the type of the monitoring event */ 656*01869ca4Swiz sc->sc_sensor[0].flags |= ENVSYS_FMONCRITICAL; 65708d5afa2Sxtraeme ... 65808d5afa2Sxtraeme} 65908d5afa2Sxtraeme 66008d5afa2Sxtraemeint 66131962fc6Sxtraememydriver_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) 66208d5afa2Sxtraeme{ 663*01869ca4Swiz struct mysoftc *sc = sme->sme_cookie; 66408d5afa2Sxtraeme 66508d5afa2Sxtraeme /* we get current data from the driver */ 666*01869ca4Swiz edata->value_cur = sc->sc_getdata(); 66708d5afa2Sxtraeme 66808d5afa2Sxtraeme /* 66908d5afa2Sxtraeme * if value is too high, mark the sensor in 67008d5afa2Sxtraeme * critical state. 67108d5afa2Sxtraeme */ 672*01869ca4Swiz if (edata->value_cur > MYDRIVER_SENSOR0_HIWAT) { 673*01869ca4Swiz edata->state = ENVSYS_SCRITICAL; 67408d5afa2Sxtraeme /* a critical event will be sent now automatically */ 67508d5afa2Sxtraeme } else { 67608d5afa2Sxtraeme /* 67708d5afa2Sxtraeme * if value is within the limits, and we came from 67808d5afa2Sxtraeme * a critical state make sure to change sensor's state 67908d5afa2Sxtraeme * to valid. 68008d5afa2Sxtraeme */ 681*01869ca4Swiz edata->state = ENVSYS_SVALID; 68208d5afa2Sxtraeme } 68308d5afa2Sxtraeme ... 68408d5afa2Sxtraeme} 68508d5afa2Sxtraeme.Ed 686c51a1c15Sxtraeme.Sh CODE REFERENCES 687c51a1c15SxtraemeThe 688c51a1c15Sxtraeme.Sy envsys 2 689c51a1c15Sxtraemeframework is implemented within the files: 690c51a1c15Sxtraeme.Pp 691c51a1c15Sxtraeme.Pa sys/dev/sysmon/sysmon_envsys.c 692c51a1c15Sxtraeme.Pp 693b3893f8dSxtraeme.Pa sys/dev/sysmon/sysmon_envsys_events.c 694b3893f8dSxtraeme.Pp 695b3893f8dSxtraeme.Pa sys/dev/sysmon/sysmon_envsys_tables.c 696b3893f8dSxtraeme.Pp 697b3893f8dSxtraeme.Pa sys/dev/sysmon/sysmon_envsys_util.c 6987ade6d03Sxtraeme.Sh SEE ALSO 6997ade6d03Sxtraeme.Xr envsys 4 , 7007ade6d03Sxtraeme.Xr envstat 8 701b3893f8dSxtraeme.Sh HISTORY 702b3893f8dSxtraemeThe first 703b3893f8dSxtraeme.Em envsys 704b3893f8dSxtraemeframework first appeared in 705b3893f8dSxtraeme.Nx 1.5 . 70608d5afa2SxtraemeThe 707b3893f8dSxtraeme.Em envsys 2 708b3893f8dSxtraemeframework first appeared in 70908d5afa2Sxtraeme.Nx 5.0 . 710b3893f8dSxtraeme.Sh AUTHORS 711b3893f8dSxtraemeThe (current) 712b3893f8dSxtraeme.Em envsys 2 713b3893f8dSxtraemeframework was implemented by 714b3893f8dSxtraeme.An Juan Romero Pardines . 715b3893f8dSxtraemeAdditional input on the design was provided by many 716b3893f8dSxtraeme.Nx 717b3893f8dSxtraemedevelopers around the world. 718b3893f8dSxtraeme.Pp 719b3893f8dSxtraemeThe first 720b3893f8dSxtraeme.Em envsys 72190d0830cSjruohoframework was implemented by 72290d0830cSjruohoJason R. Thorpe, Tim Rightnour, and Bill Squier. 723