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.
143ce5372Robert Mustacchi * Copyright 2020 Oxide Computer Company
15f2dbfd3Robert Mustacchi */
16f2dbfd3Robert Mustacchi
17f2dbfd3Robert Mustacchi#ifndef _SYS_SENSORS_H
18f2dbfd3Robert Mustacchi#define	_SYS_SENSORS_H
19f2dbfd3Robert Mustacchi
20f2dbfd3Robert Mustacchi/*
21f2dbfd3Robert Mustacchi * Consolidated sensor ioctls for various parts of the operating system. These
22f2dbfd3Robert Mustacchi * interfaces should not be relied on at all. They are evolving and will change
23f2dbfd3Robert Mustacchi * as we add more to the system for this. This may eventually become a larger
24f2dbfd3Robert Mustacchi * framework, though it's more likely we'll consolidate that in userland.
25f2dbfd3Robert Mustacchi */
26f2dbfd3Robert Mustacchi
27f2dbfd3Robert Mustacchi#ifdef __cplusplus
28f2dbfd3Robert Mustacchiextern "C" {
29f2dbfd3Robert Mustacchi#endif
30f2dbfd3Robert Mustacchi
31f2dbfd3Robert Mustacchi/*
32f2dbfd3Robert Mustacchi * List of different possible kinds of sensors.
33f2dbfd3Robert Mustacchi */
34f2dbfd3Robert Mustacchi#define	SENSOR_KIND_UNKNOWN		0x00
35f2dbfd3Robert Mustacchi#define	SENSOR_KIND_TEMPERATURE		0x01
36f2dbfd3Robert Mustacchi
37f2dbfd3Robert Mustacchi/*
38f2dbfd3Robert Mustacchi * Lists of units that senors may have.
39f2dbfd3Robert Mustacchi */
40f2dbfd3Robert Mustacchi#define	SENSOR_UNIT_UNKNOWN		0x00
41f2dbfd3Robert Mustacchi#define	SENSOR_UNIT_CELSIUS		0x01
42f2dbfd3Robert Mustacchi#define	SENSOR_UNIT_FAHRENHEIT		0x02
43f2dbfd3Robert Mustacchi#define	SENSOR_UNIT_KELVIN		0x03
44f2dbfd3Robert Mustacchi
45f2dbfd3Robert Mustacchi#define	SENSOR_IOCTL	(('s' << 24) | ('e' << 16) | ('n' << 8))
46f2dbfd3Robert Mustacchi
47f2dbfd3Robert Mustacchi/*
48f2dbfd3Robert Mustacchi * Ask the sensor what kind of sensor it is.
49f2dbfd3Robert Mustacchi */
50f2dbfd3Robert Mustacchi#define	SENSOR_IOCTL_TYPE	(SENSOR_IOCTL | 0x01)
51f2dbfd3Robert Mustacchi
52f2dbfd3Robert Mustacchitypedef struct sensor_ioctl_kind {
53f2dbfd3Robert Mustacchi	uint64_t	sik_kind;
54f2dbfd3Robert Mustacchi} sensor_ioctl_kind_t;
55f2dbfd3Robert Mustacchi
56f2dbfd3Robert Mustacchi/*
57f2dbfd3Robert Mustacchi * Ask the sensor for a temperature measurement. The sensor is responsible for
58f2dbfd3Robert Mustacchi * returning the units it's in.  A temperature measurement is broken down into a
59f2dbfd3Robert Mustacchi * signed value and a notion of its granularity. The sit_gran member indicates
60f2dbfd3Robert Mustacchi * the granularity: the number of increments per degree in the temperature
61f2dbfd3Robert Mustacchi * measurement (the sit_temp member). sit_gran is signed and the sign indicates
62f2dbfd3Robert Mustacchi * whether one needs to multiply or divide the granularity. For example, a
63f2dbfd3Robert Mustacchi * value that set sit_gran to 10 would mean that the value in sit_temp was in
64f2dbfd3Robert Mustacchi * 10ths of a degree and that to get the actual value in degrees, one would
65f2dbfd3Robert Mustacchi * divide by 10. On the other hand, a negative value means that we effectively
66f2dbfd3Robert Mustacchi * have to multiply to get there. For example, a value of -2 would indicate that
67f2dbfd3Robert Mustacchi * each value in sit_temp indicated two degrees and to get the temperature in
68f2dbfd3Robert Mustacchi * degrees you would multiply sit_temp by two.
69f2dbfd3Robert Mustacchi */
70f2dbfd3Robert Mustacchi#define	SENSOR_IOCTL_TEMPERATURE	(SENSOR_IOCTL | 0x02)
71f2dbfd3Robert Mustacchi
72f2dbfd3Robert Mustacchitypedef struct sensor_ioctl_temperature {
73f2dbfd3Robert Mustacchi	uint32_t	sit_unit;
74f2dbfd3Robert Mustacchi	int32_t		sit_gran;
753ce5372Robert Mustacchi	uint32_t	sit_prec;
763ce5372Robert Mustacchi	uint32_t	sit_pad;
77f2dbfd3Robert Mustacchi	int64_t		sit_temp;
78f2dbfd3Robert Mustacchi} sensor_ioctl_temperature_t;
79f2dbfd3Robert Mustacchi
803ce5372Robert Mustacchi#ifdef	_KERNEL
813ce5372Robert Mustacchitypedef int (*ksensor_kind_f)(void *, sensor_ioctl_kind_t *);
823ce5372Robert Mustacchitypedef int (*ksensor_temp_f)(void *, sensor_ioctl_temperature_t *);
833ce5372Robert Mustacchi
843ce5372Robert Mustacchitypedef struct {
853ce5372Robert Mustacchi	ksensor_kind_f	kso_kind;
863ce5372Robert Mustacchi	ksensor_temp_f	kso_temp;
873ce5372Robert Mustacchi} ksensor_ops_t;
883ce5372Robert Mustacchi
893ce5372Robert Mustacchiextern int ksensor_kind_temperature(void *, sensor_ioctl_kind_t *);
903ce5372Robert Mustacchi
913ce5372Robert Mustacchi/*
923ce5372Robert Mustacchi * Create a sensor where the class and name is supplied.
933ce5372Robert Mustacchi */
943ce5372Robert Mustacchiextern int ksensor_create(dev_info_t *, const ksensor_ops_t *, void *,
953ce5372Robert Mustacchi    const char *, const char *, id_t *);
963ce5372Robert Mustacchi
973ce5372Robert Mustacchi/*
983ce5372Robert Mustacchi * Create a temperature sensor for a PCI device. If this is not a device-wide
993ce5372Robert Mustacchi * (e.g. per-function) sensor, this should not be used.
1003ce5372Robert Mustacchi */
1013ce5372Robert Mustacchiextern int ksensor_create_temp_pcidev(dev_info_t *, const ksensor_ops_t *,
1023ce5372Robert Mustacchi    void *, const char *, id_t *);
1033ce5372Robert Mustacchi
1043ce5372Robert Mustacchi/*
1053ce5372Robert Mustacchi * Remove a named or all sensors from this driver.
1063ce5372Robert Mustacchi */
1073ce5372Robert Mustacchi#define	KSENSOR_ALL_IDS	INT_MIN
1083ce5372Robert Mustacchiextern int ksensor_remove(dev_info_t *, id_t);
1093ce5372Robert Mustacchi
1103ce5372Robert Mustacchi#endif
1113ce5372Robert Mustacchi
112f2dbfd3Robert Mustacchi#ifdef __cplusplus
113f2dbfd3Robert Mustacchi}
114f2dbfd3Robert Mustacchi#endif
115f2dbfd3Robert Mustacchi
116f2dbfd3Robert Mustacchi#endif /* _SYS_SENSORS_H */
117