1 /* $OpenBSD: sensors.h,v 1.37 2020/07/15 07:13:57 kettenis Exp $ */ 2 3 /* 4 * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org> 5 * Copyright (c) 2006 Constantine A. Murenin <cnst+openbsd@bugmail.mojo.ru> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 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. 16 * 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. 27 */ 28 29 #ifndef _SYS_SENSORS_H_ 30 #define _SYS_SENSORS_H_ 31 32 /* Sensor types */ 33 enum sensor_type { 34 SENSOR_TEMP, /* temperature (uK) */ 35 SENSOR_FANRPM, /* fan revolution speed */ 36 SENSOR_VOLTS_DC, /* voltage (uV DC) */ 37 SENSOR_VOLTS_AC, /* voltage (uV AC) */ 38 SENSOR_OHMS, /* resistance */ 39 SENSOR_WATTS, /* power (uW) */ 40 SENSOR_AMPS, /* current (uA) */ 41 SENSOR_WATTHOUR, /* power capacity (uWh) */ 42 SENSOR_AMPHOUR, /* power capacity (uAh) */ 43 SENSOR_INDICATOR, /* boolean indicator */ 44 SENSOR_INTEGER, /* generic integer value */ 45 SENSOR_PERCENT, /* percent (m%) */ 46 SENSOR_LUX, /* illuminance (ulx) */ 47 SENSOR_DRIVE, /* disk */ 48 SENSOR_TIMEDELTA, /* system time error (nSec) */ 49 SENSOR_HUMIDITY, /* humidity (m%RH) */ 50 SENSOR_FREQ, /* frequency (uHz) */ 51 SENSOR_ANGLE, /* angle (uDegrees) */ 52 SENSOR_DISTANCE, /* distance (uMeter) */ 53 SENSOR_PRESSURE, /* pressure (mPa) */ 54 SENSOR_ACCEL, /* acceleration (u m/s^2) */ 55 SENSOR_VELOCITY, /* velocity (u m/s) */ 56 SENSOR_ENERGY, /* energy (uJ) */ 57 SENSOR_MAX_TYPES 58 }; 59 60 #ifndef _KERNEL 61 static const char * const sensor_type_s[SENSOR_MAX_TYPES + 1] = { 62 "temp", 63 "fan", 64 "volt", 65 "acvolt", 66 "resistance", 67 "power", 68 "current", 69 "watthour", 70 "amphour", 71 "indicator", 72 "raw", 73 "percent", 74 "illuminance", 75 "drive", 76 "timedelta", 77 "humidity", 78 "frequency", 79 "angle", 80 "distance", 81 "pressure", 82 "acceleration", 83 "velocity", 84 "energy", 85 "undefined" 86 }; 87 #endif /* !_KERNEL */ 88 89 #define SENSOR_DRIVE_EMPTY 1 90 #define SENSOR_DRIVE_READY 2 91 #define SENSOR_DRIVE_POWERUP 3 92 #define SENSOR_DRIVE_ONLINE 4 93 #define SENSOR_DRIVE_IDLE 5 94 #define SENSOR_DRIVE_ACTIVE 6 95 #define SENSOR_DRIVE_REBUILD 7 96 #define SENSOR_DRIVE_POWERDOWN 8 97 #define SENSOR_DRIVE_FAIL 9 98 #define SENSOR_DRIVE_PFAIL 10 99 100 /* Sensor states */ 101 enum sensor_status { 102 SENSOR_S_UNSPEC, /* status is unspecified */ 103 SENSOR_S_OK, /* status is ok */ 104 SENSOR_S_WARN, /* status is warning */ 105 SENSOR_S_CRIT, /* status is critical */ 106 SENSOR_S_UNKNOWN /* status is unknown */ 107 }; 108 109 /* Sensor data: 110 * New fields should be added at the end to encourage backwards compat 111 */ 112 struct sensor { 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 */ 122 }; 123 124 /* Sensor device data: 125 * New fields should be added at the end to encourage backwards compat 126 */ 127 struct sensordev { 128 int num; /* sensordev number */ 129 char xname[16]; /* unix device name */ 130 int maxnumt[SENSOR_MAX_TYPES]; 131 int sensors_count; 132 }; 133 134 #ifdef _KERNEL 135 136 /* Sensor data */ 137 struct ksensor { 138 SLIST_ENTRY(ksensor) list; /* device-scope list */ 139 char desc[32]; /* sensor description, may be empty */ 140 struct timeval tv; /* sensor value last change time */ 141 int64_t value; /* current value */ 142 enum sensor_type type; /* sensor type */ 143 enum sensor_status status; /* sensor status */ 144 int numt; /* sensor number of .type type */ 145 int flags; /* sensor flags, ie. SENSOR_FINVALID */ 146 }; 147 SLIST_HEAD(ksensors_head, ksensor); 148 149 /* Sensor device data */ 150 struct ksensordev { 151 SLIST_ENTRY(ksensordev) list; 152 int num; /* sensordev number */ 153 char xname[16]; /* unix device name */ 154 int maxnumt[SENSOR_MAX_TYPES]; 155 int sensors_count; 156 struct ksensors_head sensors_list; 157 }; 158 159 /* struct ksensordev */ 160 void sensordev_install(struct ksensordev *); 161 void sensordev_deinstall(struct ksensordev *); 162 int sensordev_get(int, struct ksensordev **); 163 164 /* struct ksensor */ 165 void sensor_attach(struct ksensordev *, struct ksensor *); 166 void sensor_detach(struct ksensordev *, struct ksensor *); 167 int sensor_find(int, enum sensor_type, int, struct ksensor **); 168 169 /* task scheduling */ 170 struct sensor_task; 171 struct sensor_task *sensor_task_register(void *, void (*)(void *), 172 unsigned int); 173 void sensor_task_unregister(struct sensor_task *); 174 void sensor_quiesce(void); 175 void sensor_restart(void); 176 177 #endif /* _KERNEL */ 178 179 #endif /* !_SYS_SENSORS_H_ */ 180