xref: /netbsd/sys/sys/envsys.h (revision b73c2b02)
1 /* $NetBSD: envsys.h,v 1.39 2022/11/21 21:24:01 brad Exp $ */
2 
3 /*-
4  * Copyright (c) 1999, 2007, 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Tim Rightnour, Juan Romero Pardines and Bill Squier.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _SYS_ENVSYS_H_
33 #define _SYS_ENVSYS_H_
34 
35 #ifndef _KERNEL
36 #include <stdbool.h>
37 #endif
38 
39 #include <sys/ioccom.h>
40 #include <sys/power.h>
41 #include <sys/queue.h>
42 
43 /*
44  * ENVironmental SYStem version 2 (aka ENVSYS 2)
45  */
46 
47 #define ENVSYS_MAXSENSORS	512
48 #define ENVSYS_DESCLEN		32
49 
50 /* sensor units */
51 enum envsys_units {
52 	ENVSYS_STEMP		= 0,	/* Temperature (microkelvins) */
53 	ENVSYS_SFANRPM,			/* Fan RPM */
54 	ENVSYS_SVOLTS_AC,		/* AC Volts */
55 	ENVSYS_SVOLTS_DC,		/* DC Volts */
56 	ENVSYS_SOHMS,			/* Ohms */
57 	ENVSYS_SWATTS,			/* Watts */
58 	ENVSYS_SAMPS,			/* Ampere */
59 	ENVSYS_SWATTHOUR,		/* Watt hour */
60 	ENVSYS_SAMPHOUR,		/* Ampere hour */
61 	ENVSYS_INDICATOR,		/* Indicator */
62 	ENVSYS_INTEGER,			/* Integer */
63 	ENVSYS_DRIVE,			/* Drive */
64 	ENVSYS_BATTERY_CAPACITY,	/* Battery capacity */
65 	ENVSYS_BATTERY_CHARGE,		/* Battery charging/discharging */
66 	ENVSYS_SRELHUMIDITY,		/* relative humidity */
67 	ENVSYS_LUX,			/* illuminance in lux */
68 	ENVSYS_PRESSURE,		/* pressure in hPa */
69 	ENVSYS_NSENSORS
70 };
71 
72 /* sensor states */
73 enum envsys_states {
74 	ENVSYS_SVALID		= 10,	/* sensor state is valid */
75 	ENVSYS_SINVALID,		/* sensor state is invalid */
76 	ENVSYS_SCRITICAL,		/* sensor state is critical */
77 	ENVSYS_SCRITUNDER,		/* sensor state is critical under */
78 	ENVSYS_SCRITOVER,		/* sensor state is critical over */
79 	ENVSYS_SWARNUNDER,		/* sensor state is warn under */
80 	ENVSYS_SWARNOVER		/* sensor state is warn over */
81 };
82 
83 /* sensor drive states */
84 enum envsys_drive_states {
85 	ENVSYS_DRIVE_EMPTY	= 1,	/* drive is empty */
86 	ENVSYS_DRIVE_READY,		/* drive is ready */
87 	ENVSYS_DRIVE_POWERUP,		/* drive is powered up */
88 	ENVSYS_DRIVE_ONLINE,		/* drive is online */
89 	ENVSYS_DRIVE_IDLE,		/* drive is idle */
90 	ENVSYS_DRIVE_ACTIVE,		/* drive is active */
91 	ENVSYS_DRIVE_REBUILD,		/* drive is rebuilding */
92 	ENVSYS_DRIVE_POWERDOWN,		/* drive is powered down */
93 	ENVSYS_DRIVE_FAIL,		/* drive failed */
94 	ENVSYS_DRIVE_PFAIL,		/* drive is degraded */
95 	ENVSYS_DRIVE_MIGRATING,		/* drive is migrating */
96 	ENVSYS_DRIVE_OFFLINE,		/* drive is offline */
97 	ENVSYS_DRIVE_BUILD,		/* drive is building */
98 	ENVSYS_DRIVE_CHECK		/* drive is checking its state */
99 };
100 
101 /* sensor battery capacity states */
102 enum envsys_battery_capacity_states {
103 	ENVSYS_BATTERY_CAPACITY_NORMAL	= 1,	/* normal cap in battery */
104 	ENVSYS_BATTERY_CAPACITY_WARNING,	/* warning cap in battery */
105 	ENVSYS_BATTERY_CAPACITY_CRITICAL,	/* critical cap in battery */
106 	ENVSYS_BATTERY_CAPACITY_HIGH,		/* high cap in battery */
107 	ENVSYS_BATTERY_CAPACITY_MAX,		/* maximum cap in battery */
108 	ENVSYS_BATTERY_CAPACITY_LOW		/* low cap in battery */
109 };
110 
111 /* sensor indicator states */
112 enum envsys_indicator_states {
113 	ENVSYS_INDICATOR_FALSE		= 0,
114 	ENVSYS_INDICATOR_TRUE		= 1
115 };
116 
117 /*
118  * IOCTLs
119  */
120 #define ENVSYS_GETDICTIONARY	_IOWR('E', 0, struct plistref)
121 #define ENVSYS_SETDICTIONARY	_IOWR('E', 1, struct plistref)
122 #define ENVSYS_REMOVEPROPS	_IOWR('E', 2, struct plistref)
123 
124 /*
125  * Compatibility with old interface. Only ENVSYS_GTREDATA
126  * and ENVSYS_GTREINFO ioctls are supported.
127  */
128 
129 /* get sensor data */
130 
131 struct envsys_tre_data {
132 	unsigned int sensor;
133 	union {				/* all data is given */
134 		uint32_t data_us;	/* in microKelvins, */
135 		int32_t data_s;		/* rpms, volts, amps, */
136 	} cur, min, max, avg;		/* ohms, watts, etc */
137 					/* see units below */
138 
139 	uint32_t	warnflags;	/* warning flags */
140 	uint32_t	validflags;	/* sensor valid flags */
141 	unsigned int	units;		/* type of sensor */
142 };
143 typedef struct envsys_tre_data envsys_tre_data_t;
144 
145 /* flags for warnflags */
146 #define ENVSYS_WARN_OK		0x00000000  /* All is well */
147 #define ENVSYS_WARN_UNDER	0x00000001  /* an under condition */
148 #define ENVSYS_WARN_CRITUNDER	0x00000002  /* a critical under condition */
149 #define ENVSYS_WARN_OVER	0x00000004  /* an over condition */
150 #define ENVSYS_WARN_CRITOVER	0x00000008  /* a critical over condition */
151 
152 /* drive status */
153 #define ENVSYS_DRIVE_EMPTY      1
154 #define ENVSYS_DRIVE_READY      2
155 #define ENVSYS_DRIVE_POWERUP    3
156 #define ENVSYS_DRIVE_ONLINE     4
157 #define ENVSYS_DRIVE_IDLE       5
158 #define ENVSYS_DRIVE_ACTIVE     6
159 #define ENVSYS_DRIVE_REBUILD    7
160 #define ENVSYS_DRIVE_POWERDOWN  8
161 #define ENVSYS_DRIVE_FAIL       9
162 #define ENVSYS_DRIVE_PFAIL      10
163 
164 #ifdef ENVSYSUNITNAMES
165 static const char * const envsysunitnames[] = {
166     "degC", "RPM", "VAC", "V", "Ohms", "W",
167     "A", "Wh", "Ah", "bool", "integer", "drive", "%rH", "lux", "Unk"
168 };
169 static const char * const envsysdrivestatus[] = {
170     "unknown", "empty", "ready", "powering up", "online", "idle", "active",
171     "rebuilding", "powering down", "failed", "degraded"
172 };
173 #endif
174 
175 
176 /* flags for validflags */
177 #define ENVSYS_FVALID		0x00000001  /* sensor is valid */
178 #define ENVSYS_FCURVALID	0x00000002  /* cur for this sens is valid */
179 #define ENVSYS_FMINVALID	0x00000004  /* min for this sens is valid */
180 #define ENVSYS_FMAXVALID	0x00000008  /* max for this sens is valid */
181 #define ENVSYS_FAVGVALID	0x00000010  /* avg for this sens is valid */
182 #define ENVSYS_FFRACVALID	0x00000020  /* display fraction of max */
183 
184 #define ENVSYS_GTREDATA 	_IOWR('E', 2, envsys_tre_data_t)
185 
186 /* set and check sensor info */
187 
188 struct envsys_basic_info {
189 	unsigned int sensor;	/* sensor number */
190 	unsigned int units;	/* type of sensor */
191 	char	desc[33];	/* sensor description */
192 	unsigned int rfact;	/* for volts, (int)(factor x 10^4) */
193 	unsigned int rpms;	/* for fans, set nominal RPMs */
194 	uint32_t validflags;	/* sensor valid flags */
195 };
196 typedef struct envsys_basic_info envsys_basic_info_t;
197 
198 #define ENVSYS_GTREINFO 	_IOWR('E', 4, envsys_basic_info_t)
199 
200 #endif /* _SYS_ENVSYS_H_ */
201