xref: /openbsd-src/share/man/man9/sensor_attach.9 (revision daf88648c0e349d5c02e1504293082072c981640)
1.\"	$OpenBSD: sensor_attach.9,v 1.3 2006/12/28 11:36:14 jmc 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 December 23, 2006
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.Fd #include <sys/sensors.h>
42.Ft void
43.Fn "sensordev_install" "struct sensordev *sensdev"
44.Ft void
45.Fn "sensordev_deinstall" "struct sensordev *sensdev"
46.Ft struct sensordev
47.Fn "*sensordev_get" "int devnum"
48.Pp
49.Ft void
50.Fn "sensor_attach" "struct sensordev *sensdev" "struct sensor *sens"
51.Ft void
52.Fn "sensor_detach" "struct sensordev *sensdev" "struct sensor *sens"
53.Ft struct sensor
54.Fn "*sensor_find" "int devnum" "enum sensor_type stype" "int numt"
55.Pp
56.Ft int
57.Fn "sensor_task_register" "void *arg" "void (*func)(void *)" "int period"
58.Ft void
59.Fn "sensor_task_unregister" "void *arg"
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.Pa sens
72argument to the sensor device specified by the
73.Pa 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.Pa 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.Pa devnum
91specifying a sensor device and
92returns a pointer to the corresponding
93.Vt struct sensordev ,
94or
95.Dv NULL
96if no such sensor device exists.
97.Pp
98.Fn sensor_find
99takes ordinal number
100.Pa devnum
101specifying a sensor device, sensor type
102.Pa stype
103and ordinal number of sensor of such type
104.Pa numt ,
105and returns a pointer to the corresponding
106.Vt struct sensor ,
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.
133The
134.Fn sensor_task_unregister
135removes all tasks previously registered with
136.Fn sensor_task_register
137with an argument of
138.Fa arg .
139.Pp
140All the functions in the sensor framework must be called during
141.Xr autoconf 9
142or from a process context.
143Additionally,
144.Fn sensor_task_unregister
145must not be called while a function previously registered with
146.Fn sensor_task_register
147is running.
148.Sh SEE ALSO
149.Xr sysctl 8 ,
150.Xr autoconf 9
151.Sh HISTORY
152The sensor framework was written by
153.An Alexander Yurchenko Aq grange@openbsd.org
154and first appeared in
155.Ox 3.4 .
156.An David Gwynne Aq dlg@openbsd.org
157later extended it for
158.Ox 3.8 .
159.An Constantine A. Murenin Aq cnst+openbsd@bugmail.mojo.ru
160extended it even further by introducing the concept of sensor devices in
161.Ox 4.1 .
162