1.\" $OpenBSD: sensor_attach.9,v 1.13 2015/09/14 15:14:55 schwarze Exp $ 2.\" 3.\" Copyright (c) 2006 Michael Knudsen <mk@openbsd.org> 4.\" Copyright (c) 2006 Constantine A. Murenin <cnst+openbsd@bugmail.mojo.ru> 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.\" 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. The name of the author may not be used to endorse or promote products 14.\" derived from this software without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 18.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 19.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.Dd $Mdocdate: September 14 2015 $ 28.Dt SENSOR_ATTACH 9 29.Os 30.Sh NAME 31.Nm sensor_attach , 32.Nm sensor_detach , 33.Nm sensor_find , 34.Nm sensordev_install , 35.Nm sensordev_deinstall , 36.Nm sensordev_get , 37.Nm sensor_task_register , 38.Nm sensor_task_unregister 39.Nd sensors framework 40.Sh SYNOPSIS 41.In sys/sensors.h 42.Ft void 43.Fn sensordev_install "struct ksensordev *sensdev" 44.Ft void 45.Fn sensordev_deinstall "struct ksensordev *sensdev" 46.Ft struct ksensordev * 47.Fn sensordev_get "int devnum" 48.Pp 49.Ft void 50.Fn sensor_attach "struct ksensordev *sensdev" "struct ksensor *sens" 51.Ft void 52.Fn sensor_detach "struct ksensordev *sensdev" "struct ksensor *sens" 53.Ft struct ksensor * 54.Fn sensor_find "int devnum" "enum sensor_type stype" "int numt" 55.Pp 56.Ft struct sensor_task * 57.Fn sensor_task_register "void *arg" "void (*func)(void *)" "int period" 58.Ft void 59.Fn sensor_task_unregister "struct sensor_task *st" 60.Sh DESCRIPTION 61The 62sensors 63framework API provides a mechanism for manipulation of hardware sensors 64that are available under the 65.Va hw.sensors 66.Xr sysctl 8 67tree. 68.Pp 69.Fn sensor_attach 70adds the sensor specified by the 71.Fa sens 72argument to the sensor device specified by the 73.Fa sensdev 74argument. 75.Fn sensor_detach 76can be used to remove sensors previously added by 77.Fn sensor_attach . 78.Pp 79.Fn sensordev_install 80registers the sensor device specified by the 81.Fa sensdev 82argument so that all sensors that are attached to the device become 83accessible via the sysctl interface. 84.Fn sensordev_deinstall 85can be used to remove sensor devices previously registered by 86.Fn sensordev_install . 87.Pp 88.Fn sensordev_get 89takes ordinal number 90.Fa devnum 91specifying a sensor device and 92returns a pointer to the corresponding 93.Vt struct ksensordev , 94or 95.Dv NULL 96if no such sensor device exists. 97.Pp 98.Fn sensor_find 99takes ordinal number 100.Fa devnum 101specifying a sensor device, sensor type 102.Fa stype 103and ordinal number of sensor of such type 104.Fa numt , 105and returns a pointer to the corresponding 106.Vt struct ksensor , 107or 108.Dv NULL 109if no such sensor exists. 110.Fn sensor_find 111will always return 112.Dv NULL 113if the corresponding sensor devices are not registered by 114.Fn sensordev_install . 115.Pp 116Drivers are responsible for retrieving, interpreting, and normalising 117sensor values and updating the sensor struct periodically. 118If the driver needs process context, for example to sleep, it can 119register a task with the sensor framework. 120.Pp 121.Fn sensor_task_register 122is used to register a periodic task to update sensors. 123The 124.Fa func 125argument is a pointer to the function to run with an interval of 126.Fa period 127seconds. 128The 129.Fa arg 130parameter is the argument given to the 131.Fa func 132function. 133.Fn sensor_task_unregister 134ensures that the task specified by the 135.Fa st 136argument is no longer running, and then removes it from the queue. 137.Pp 138All the functions in the sensor framework must be called during 139.Xr autoconf 9 140or from a process context. 141Additionally, 142.Fn sensor_task_unregister 143must not be called from the sensor task that it is about to remove. 144.Sh SEE ALSO 145.Xr sysctl 8 , 146.Xr autoconf 9 147.Sh HISTORY 148The sensor framework was written by 149.An Alexander Yurchenko Aq Mt grange@openbsd.org 150and first appeared in 151.Ox 3.4 . 152.An David Gwynne Aq Mt dlg@openbsd.org 153later extended it for 154.Ox 3.8 . 155.An Constantine A. Murenin Aq Mt cnst+openbsd@bugmail.mojo.ru 156extended it even further by introducing the concept of sensor devices in 157.Ox 4.1 . 158