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