xref: /illumos-gate/usr/src/uts/common/sys/sensors.h (revision d3b5f56344d8bfcdd6cfb82446af0e5e55ad9ebe)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2019, Joyent, Inc.
14  */
15 
16 #ifndef _SYS_SENSORS_H
17 #define	_SYS_SENSORS_H
18 
19 /*
20  * Consolidated sensor ioctls for various parts of the operating system. These
21  * interfaces should not be relied on at all. They are evolving and will change
22  * as we add more to the system for this. This may eventually become a larger
23  * framework, though it's more likely we'll consolidate that in userland.
24  */
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /*
31  * List of different possible kinds of sensors.
32  */
33 #define	SENSOR_KIND_UNKNOWN		0x00
34 #define	SENSOR_KIND_TEMPERATURE		0x01
35 
36 /*
37  * Lists of units that senors may have.
38  */
39 #define	SENSOR_UNIT_UNKNOWN		0x00
40 #define	SENSOR_UNIT_CELSIUS		0x01
41 #define	SENSOR_UNIT_FAHRENHEIT		0x02
42 #define	SENSOR_UNIT_KELVIN		0x03
43 
44 #define	SENSOR_IOCTL	(('s' << 24) | ('e' << 16) | ('n' << 8))
45 
46 /*
47  * Ask the sensor what kind of sensor it is.
48  */
49 #define	SENSOR_IOCTL_TYPE	(SENSOR_IOCTL | 0x01)
50 
51 typedef struct sensor_ioctl_kind {
52 	uint64_t	sik_kind;
53 } sensor_ioctl_kind_t;
54 
55 /*
56  * Ask the sensor for a temperature measurement. The sensor is responsible for
57  * returning the units it's in.  A temperature measurement is broken down into a
58  * signed value and a notion of its granularity. The sit_gran member indicates
59  * the granularity: the number of increments per degree in the temperature
60  * measurement (the sit_temp member). sit_gran is signed and the sign indicates
61  * whether one needs to multiply or divide the granularity. For example, a
62  * value that set sit_gran to 10 would mean that the value in sit_temp was in
63  * 10ths of a degree and that to get the actual value in degrees, one would
64  * divide by 10. On the other hand, a negative value means that we effectively
65  * have to multiply to get there. For example, a value of -2 would indicate that
66  * each value in sit_temp indicated two degrees and to get the temperature in
67  * degrees you would multiply sit_temp by two.
68  */
69 #define	SENSOR_IOCTL_TEMPERATURE	(SENSOR_IOCTL | 0x02)
70 
71 typedef struct sensor_ioctl_temperature {
72 	uint32_t	sit_unit;
73 	int32_t		sit_gran;
74 	int64_t		sit_temp;
75 } sensor_ioctl_temperature_t;
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif /* _SYS_SENSORS_H */
82