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