1 /* $OpenBSD: sensors.h,v 1.23 2007/03/22 16:55:31 deraadt Exp $ */
4 * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org>
5 * Copyright (c) 2006 Constantine A. Murenin <cnst+openbsd@bugmail.mojo.ru>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef _SYS_SENSORS_H_
30 #define _SYS_SENSORS_H_
32 #include <sys/types.h>
36 SENSOR_TEMP, /* temperature (muK) */
37 SENSOR_FANRPM, /* fan revolution speed */
38 SENSOR_VOLTS_DC, /* voltage (muV DC) */
39 SENSOR_VOLTS_AC, /* voltage (muV AC) */
40 SENSOR_OHMS, /* resistance */
41 SENSOR_WATTS, /* power */
42 SENSOR_AMPS, /* current (muA) */
43 SENSOR_WATTHOUR, /* power capacity */
44 SENSOR_AMPHOUR, /* power capacity */
45 SENSOR_INDICATOR, /* boolean indicator */
46 SENSOR_INTEGER, /* generic integer value */
47 SENSOR_PERCENT, /* percent */
48 SENSOR_LUX, /* illuminance (mulx) */
49 SENSOR_DRIVE, /* disk */
50 SENSOR_TIMEDELTA, /* system time error (nSec) */
51 SENSOR_ECC, /* memory ecc */
52 SENSOR_FREQ, /* frequency */
53 SENSOR_RESERVED_B, /* reserved */
54 SENSOR_RESERVED_C, /* reserved */
55 SENSOR_RESERVED_D, /* reserved */
56 SENSOR_RESERVED_E, /* reserved */
57 SENSOR_RESERVED_F, /* reserved */
61 static const char * const sensor_type_s[SENSOR_MAX_TYPES + 1] = {
87 #define SENSOR_DRIVE_EMPTY 1
88 #define SENSOR_DRIVE_READY 2
89 #define SENSOR_DRIVE_POWERUP 3
90 #define SENSOR_DRIVE_ONLINE 4
91 #define SENSOR_DRIVE_IDLE 5
92 #define SENSOR_DRIVE_ACTIVE 6
93 #define SENSOR_DRIVE_REBUILD 7
94 #define SENSOR_DRIVE_POWERDOWN 8
95 #define SENSOR_DRIVE_FAIL 9
96 #define SENSOR_DRIVE_PFAIL 10
100 SENSOR_S_UNSPEC, /* status is unspecified */
101 SENSOR_S_OK, /* status is ok */
102 SENSOR_S_WARN, /* status is warning */
103 SENSOR_S_CRIT, /* status is critical */
104 SENSOR_S_UNKNOWN /* status is unknown */
109 * New fields should be added at the end to encourage backwards compat
112 char desc[32]; /* sensor description, may be empty */
113 struct timeval tv; /* sensor value last change time */
114 int64_t value; /* current value */
115 enum sensor_type type; /* sensor type */
116 enum sensor_status status; /* sensor status */
117 int numt; /* sensor number of .type type */
118 int flags; /* sensor flags */
119 #define SENSOR_FINVALID 0x0001 /* sensor is invalid */
120 #define SENSOR_FUNKNOWN 0x0002 /* sensor value is unknown */
124 * Sensor device data:
125 * New fields should be added at the end to encourage backwards compat
128 int num; /* sensordev number */
129 char xname[16]; /* unix device name */
130 int maxnumt[SENSOR_MAX_TYPES];
134 #define MAXSENSORDEVICES 32
138 #include <sys/queue.h>
139 #include <sys/sysctl.h>
143 SLIST_ENTRY(ksensor) list; /* device-scope list */
144 char desc[32]; /* sensor description, may be empty */
145 struct timeval tv; /* sensor value last change time */
146 int64_t value; /* current value */
147 enum sensor_type type; /* sensor type */
148 enum sensor_status status; /* sensor status */
149 int numt; /* sensor number of .type type */
150 int flags; /* sensor flags, ie. SENSOR_FINVALID */
151 struct sysctl_oid *oid;
153 SLIST_HEAD(ksensors_head, ksensor);
155 /* Sensor device data */
157 TAILQ_ENTRY(ksensordev) list;
158 int num; /* sensordev number */
159 char xname[16]; /* unix device name */
160 int maxnumt[SENSOR_MAX_TYPES];
162 struct ksensors_head sensors_list;
163 struct sysctl_oid *oid;
164 struct sysctl_ctx_list clist;
167 /* struct ksensordev */
168 void sensordev_install(struct ksensordev *);
169 void sensordev_deinstall(struct ksensordev *);
172 void sensor_attach(struct ksensordev *, struct ksensor *);
173 void sensor_detach(struct ksensordev *, struct ksensor *);
177 * Deprecated; use sensor_task_{register,unregiser}2() instead.
179 void sensor_task_register(void *, void (*)(void *), int);
180 void sensor_task_unregister(void *);
187 sensor_task_register2(void *, void (*)(void *),
188 int period, int cpu);
189 void sensor_task_unregister2(struct sensor_task *);
192 sensor_set_invalid(struct ksensor *sens)
194 sens->status = SENSOR_S_UNSPEC;
195 sens->flags &= ~(SENSOR_FUNKNOWN | SENSOR_FINVALID);
196 sens->flags |= SENSOR_FINVALID;
201 sensor_set_unknown(struct ksensor *sens)
203 sens->status = SENSOR_S_UNKNOWN;
204 sens->flags &= ~(SENSOR_FUNKNOWN | SENSOR_FINVALID);
205 sens->flags |= SENSOR_FUNKNOWN;
210 sensor_set(struct ksensor *sens, int64_t val, enum sensor_status status)
212 sens->status = status;
213 sens->flags &= ~(SENSOR_FUNKNOWN | SENSOR_FINVALID);
218 sensor_set_temp_degc(struct ksensor *sens, int degc, enum sensor_status status)
220 sensor_set(sens, (degc * 1000000) + 273150000, status);
225 #endif /* !_SYS_SENSORS_H_ */