Merge branch 'vendor/BMAKE'
[dragonfly.git] / sys / sys / sensors.h
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 $ */
3
4 /*
5  * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org>
6  * Copyright (c) 2006 Constantine A. Murenin <cnst+openbsd@bugmail.mojo.ru>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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.
17  *
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.
28  */
29
30 #ifndef _SYS_SENSORS_H_
31 #define _SYS_SENSORS_H_
32
33 #define SENSORS_DEBUG
34
35 /* Sensor types */
36 enum sensor_type {
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_MAX_TYPES
53 };
54
55 static const char * const sensor_type_s[SENSOR_MAX_TYPES + 1] = {
56         "temp",
57         "fan",
58         "volt",
59         "acvolt",
60         "resistance",
61         "power",
62         "current",
63         "watthour",
64         "amphour",
65         "indicator",
66         "raw",
67         "percent",
68         "illuminance",
69         "drive",
70         "timedelta",
71         "undefined"
72 };
73
74 #define SENSOR_DRIVE_EMPTY      1
75 #define SENSOR_DRIVE_READY      2
76 #define SENSOR_DRIVE_POWERUP    3
77 #define SENSOR_DRIVE_ONLINE     4
78 #define SENSOR_DRIVE_IDLE       5
79 #define SENSOR_DRIVE_ACTIVE     6
80 #define SENSOR_DRIVE_REBUILD    7
81 #define SENSOR_DRIVE_POWERDOWN  8
82 #define SENSOR_DRIVE_FAIL       9
83 #define SENSOR_DRIVE_PFAIL      10
84
85 /* Sensor states */
86 enum sensor_status {
87         SENSOR_S_UNSPEC,                /* status is unspecified */
88         SENSOR_S_OK,                    /* status is ok */
89         SENSOR_S_WARN,                  /* status is warning */
90         SENSOR_S_CRIT,                  /* status is critical */
91         SENSOR_S_UNKNOWN                /* status is unknown */
92 };
93
94 /*
95  * Sensor data:
96  * New fields should be added at the end to encourage backwards compat
97  */
98 struct sensor {
99         char desc[32];                  /* sensor description, may be empty */
100         struct timeval tv;              /* sensor value last change time */
101         int64_t value;                  /* current value */
102         enum sensor_type type;          /* sensor type */
103         enum sensor_status status;      /* sensor status */
104         int numt;                       /* sensor number of .type type */
105         int flags;                      /* sensor flags */
106 #define SENSOR_FINVALID         0x0001  /* sensor is invalid */
107 #define SENSOR_FUNKNOWN         0x0002  /* sensor value is unknown */
108 };
109
110 /*
111  * Sensor device data:
112  * New fields should be added at the end to encourage backwards compat
113  */
114 struct sensordev {
115         int num;                        /* sensordev number */
116         char xname[16];                 /* unix device name */
117         int maxnumt[SENSOR_MAX_TYPES];
118         int sensors_count;
119 };
120
121 #define MAXSENSORDEVICES 32
122
123 #ifdef _KERNEL
124 #include <sys/queue.h>
125 #ifndef NOSYSCTL8HACK
126 #include <sys/sysctl.h>
127 #endif
128
129 /* Sensor data */
130 struct ksensor {
131         SLIST_ENTRY(ksensor) list;      /* device-scope list */
132         char desc[32];                  /* sensor description, may be empty */
133         struct timeval tv;              /* sensor value last change time */
134         int64_t value;                  /* current value */
135         enum sensor_type type;          /* sensor type */
136         enum sensor_status status;      /* sensor status */
137         int numt;                       /* sensor number of .type type */
138         int flags;                      /* sensor flags, ie. SENSOR_FINVALID */
139 };
140 SLIST_HEAD(ksensors_head, ksensor);
141
142 /* Sensor device data */
143 struct ksensordev {
144         SLIST_ENTRY(ksensordev) list;
145         int num;                        /* sensordev number */
146         char xname[16];                 /* unix device name */
147         int maxnumt[SENSOR_MAX_TYPES];
148         int sensors_count;
149         struct ksensors_head sensors_list;
150 #ifndef NOSYSCTL8HACK
151         struct sysctl_ctx_list clist;   /* XXX: sysctl(9) .oid_handler() for
152                                          * CTLTYPE_NODE type doesn't support
153                                          * the undocumented sysctl magic.
154                                          */
155 #endif /* !NOSYSCTL8HACK */
156 };
157
158 /* struct ksensordev */
159 void            sensordev_install(struct ksensordev *);
160 void            sensordev_deinstall(struct ksensordev *);
161
162 /* struct ksensor */
163 void            sensor_attach(struct ksensordev *, struct ksensor *);
164 void            sensor_detach(struct ksensordev *, struct ksensor *);
165
166 /* task scheduling */
167 int             sensor_task_register(void *, void (*)(void *), int);
168 void            sensor_task_unregister(void *);
169
170 #endif  /* _KERNEL */
171
172 #endif  /* !_SYS_SENSORS_H_ */