xref: /illumos-gate/usr/src/uts/common/sys/sensors.h (revision 3ce5372277f4657ad0e52d36c979527c4ca22de2)
1f2dbfd32SRobert Mustacchi /*
2f2dbfd32SRobert Mustacchi  * This file and its contents are supplied under the terms of the
3f2dbfd32SRobert Mustacchi  * Common Development and Distribution License ("CDDL"), version 1.0.
4f2dbfd32SRobert Mustacchi  * You may only use this file in accordance with the terms of version
5f2dbfd32SRobert Mustacchi  * 1.0 of the CDDL.
6f2dbfd32SRobert Mustacchi  *
7f2dbfd32SRobert Mustacchi  * A full copy of the text of the CDDL should have accompanied this
8f2dbfd32SRobert Mustacchi  * source.  A copy of the CDDL is also available via the Internet at
9f2dbfd32SRobert Mustacchi  * http://www.illumos.org/license/CDDL.
10f2dbfd32SRobert Mustacchi  */
11f2dbfd32SRobert Mustacchi 
12f2dbfd32SRobert Mustacchi /*
13f2dbfd32SRobert Mustacchi  * Copyright 2019, Joyent, Inc.
14*3ce53722SRobert Mustacchi  * Copyright 2020 Oxide Computer Company
15f2dbfd32SRobert Mustacchi  */
16f2dbfd32SRobert Mustacchi 
17f2dbfd32SRobert Mustacchi #ifndef _SYS_SENSORS_H
18f2dbfd32SRobert Mustacchi #define	_SYS_SENSORS_H
19f2dbfd32SRobert Mustacchi 
20f2dbfd32SRobert Mustacchi /*
21f2dbfd32SRobert Mustacchi  * Consolidated sensor ioctls for various parts of the operating system. These
22f2dbfd32SRobert Mustacchi  * interfaces should not be relied on at all. They are evolving and will change
23f2dbfd32SRobert Mustacchi  * as we add more to the system for this. This may eventually become a larger
24f2dbfd32SRobert Mustacchi  * framework, though it's more likely we'll consolidate that in userland.
25f2dbfd32SRobert Mustacchi  */
26f2dbfd32SRobert Mustacchi 
27f2dbfd32SRobert Mustacchi #ifdef __cplusplus
28f2dbfd32SRobert Mustacchi extern "C" {
29f2dbfd32SRobert Mustacchi #endif
30f2dbfd32SRobert Mustacchi 
31f2dbfd32SRobert Mustacchi /*
32f2dbfd32SRobert Mustacchi  * List of different possible kinds of sensors.
33f2dbfd32SRobert Mustacchi  */
34f2dbfd32SRobert Mustacchi #define	SENSOR_KIND_UNKNOWN		0x00
35f2dbfd32SRobert Mustacchi #define	SENSOR_KIND_TEMPERATURE		0x01
36f2dbfd32SRobert Mustacchi 
37f2dbfd32SRobert Mustacchi /*
38f2dbfd32SRobert Mustacchi  * Lists of units that senors may have.
39f2dbfd32SRobert Mustacchi  */
40f2dbfd32SRobert Mustacchi #define	SENSOR_UNIT_UNKNOWN		0x00
41f2dbfd32SRobert Mustacchi #define	SENSOR_UNIT_CELSIUS		0x01
42f2dbfd32SRobert Mustacchi #define	SENSOR_UNIT_FAHRENHEIT		0x02
43f2dbfd32SRobert Mustacchi #define	SENSOR_UNIT_KELVIN		0x03
44f2dbfd32SRobert Mustacchi 
45f2dbfd32SRobert Mustacchi #define	SENSOR_IOCTL	(('s' << 24) | ('e' << 16) | ('n' << 8))
46f2dbfd32SRobert Mustacchi 
47f2dbfd32SRobert Mustacchi /*
48f2dbfd32SRobert Mustacchi  * Ask the sensor what kind of sensor it is.
49f2dbfd32SRobert Mustacchi  */
50f2dbfd32SRobert Mustacchi #define	SENSOR_IOCTL_TYPE	(SENSOR_IOCTL | 0x01)
51f2dbfd32SRobert Mustacchi 
52f2dbfd32SRobert Mustacchi typedef struct sensor_ioctl_kind {
53f2dbfd32SRobert Mustacchi 	uint64_t	sik_kind;
54f2dbfd32SRobert Mustacchi } sensor_ioctl_kind_t;
55f2dbfd32SRobert Mustacchi 
56f2dbfd32SRobert Mustacchi /*
57f2dbfd32SRobert Mustacchi  * Ask the sensor for a temperature measurement. The sensor is responsible for
58f2dbfd32SRobert Mustacchi  * returning the units it's in.  A temperature measurement is broken down into a
59f2dbfd32SRobert Mustacchi  * signed value and a notion of its granularity. The sit_gran member indicates
60f2dbfd32SRobert Mustacchi  * the granularity: the number of increments per degree in the temperature
61f2dbfd32SRobert Mustacchi  * measurement (the sit_temp member). sit_gran is signed and the sign indicates
62f2dbfd32SRobert Mustacchi  * whether one needs to multiply or divide the granularity. For example, a
63f2dbfd32SRobert Mustacchi  * value that set sit_gran to 10 would mean that the value in sit_temp was in
64f2dbfd32SRobert Mustacchi  * 10ths of a degree and that to get the actual value in degrees, one would
65f2dbfd32SRobert Mustacchi  * divide by 10. On the other hand, a negative value means that we effectively
66f2dbfd32SRobert Mustacchi  * have to multiply to get there. For example, a value of -2 would indicate that
67f2dbfd32SRobert Mustacchi  * each value in sit_temp indicated two degrees and to get the temperature in
68f2dbfd32SRobert Mustacchi  * degrees you would multiply sit_temp by two.
69f2dbfd32SRobert Mustacchi  */
70f2dbfd32SRobert Mustacchi #define	SENSOR_IOCTL_TEMPERATURE	(SENSOR_IOCTL | 0x02)
71f2dbfd32SRobert Mustacchi 
72f2dbfd32SRobert Mustacchi typedef struct sensor_ioctl_temperature {
73f2dbfd32SRobert Mustacchi 	uint32_t	sit_unit;
74f2dbfd32SRobert Mustacchi 	int32_t		sit_gran;
75*3ce53722SRobert Mustacchi 	uint32_t	sit_prec;
76*3ce53722SRobert Mustacchi 	uint32_t	sit_pad;
77f2dbfd32SRobert Mustacchi 	int64_t		sit_temp;
78f2dbfd32SRobert Mustacchi } sensor_ioctl_temperature_t;
79f2dbfd32SRobert Mustacchi 
80*3ce53722SRobert Mustacchi #ifdef	_KERNEL
81*3ce53722SRobert Mustacchi typedef int (*ksensor_kind_f)(void *, sensor_ioctl_kind_t *);
82*3ce53722SRobert Mustacchi typedef int (*ksensor_temp_f)(void *, sensor_ioctl_temperature_t *);
83*3ce53722SRobert Mustacchi 
84*3ce53722SRobert Mustacchi typedef struct {
85*3ce53722SRobert Mustacchi 	ksensor_kind_f	kso_kind;
86*3ce53722SRobert Mustacchi 	ksensor_temp_f	kso_temp;
87*3ce53722SRobert Mustacchi } ksensor_ops_t;
88*3ce53722SRobert Mustacchi 
89*3ce53722SRobert Mustacchi extern int ksensor_kind_temperature(void *, sensor_ioctl_kind_t *);
90*3ce53722SRobert Mustacchi 
91*3ce53722SRobert Mustacchi /*
92*3ce53722SRobert Mustacchi  * Create a sensor where the class and name is supplied.
93*3ce53722SRobert Mustacchi  */
94*3ce53722SRobert Mustacchi extern int ksensor_create(dev_info_t *, const ksensor_ops_t *, void *,
95*3ce53722SRobert Mustacchi     const char *, const char *, id_t *);
96*3ce53722SRobert Mustacchi 
97*3ce53722SRobert Mustacchi /*
98*3ce53722SRobert Mustacchi  * Create a temperature sensor for a PCI device. If this is not a device-wide
99*3ce53722SRobert Mustacchi  * (e.g. per-function) sensor, this should not be used.
100*3ce53722SRobert Mustacchi  */
101*3ce53722SRobert Mustacchi extern int ksensor_create_temp_pcidev(dev_info_t *, const ksensor_ops_t *,
102*3ce53722SRobert Mustacchi     void *, const char *, id_t *);
103*3ce53722SRobert Mustacchi 
104*3ce53722SRobert Mustacchi /*
105*3ce53722SRobert Mustacchi  * Remove a named or all sensors from this driver.
106*3ce53722SRobert Mustacchi  */
107*3ce53722SRobert Mustacchi #define	KSENSOR_ALL_IDS	INT_MIN
108*3ce53722SRobert Mustacchi extern int ksensor_remove(dev_info_t *, id_t);
109*3ce53722SRobert Mustacchi 
110*3ce53722SRobert Mustacchi #endif
111*3ce53722SRobert Mustacchi 
112f2dbfd32SRobert Mustacchi #ifdef __cplusplus
113f2dbfd32SRobert Mustacchi }
114f2dbfd32SRobert Mustacchi #endif
115f2dbfd32SRobert Mustacchi 
116f2dbfd32SRobert Mustacchi #endif /* _SYS_SENSORS_H */
117