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. 143ce53722SRobert 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 36*1045e13aSRobert Mustacchi #define SENSOR_KIND_VOLTAGE 0x02 37*1045e13aSRobert Mustacchi #define SENSOR_KIND_CURRENT 0x03 38f2dbfd32SRobert Mustacchi 39f2dbfd32SRobert Mustacchi /* 40f2dbfd32SRobert Mustacchi * Lists of units that senors may have. 41f2dbfd32SRobert Mustacchi */ 42f2dbfd32SRobert Mustacchi #define SENSOR_UNIT_UNKNOWN 0x00 43f2dbfd32SRobert Mustacchi #define SENSOR_UNIT_CELSIUS 0x01 44f2dbfd32SRobert Mustacchi #define SENSOR_UNIT_FAHRENHEIT 0x02 45f2dbfd32SRobert Mustacchi #define SENSOR_UNIT_KELVIN 0x03 46*1045e13aSRobert Mustacchi #define SENSOR_UNIT_VOLTS 0x04 47*1045e13aSRobert Mustacchi #define SENSOR_UNIT_AMPS 0x05 48f2dbfd32SRobert Mustacchi 49f2dbfd32SRobert Mustacchi #define SENSOR_IOCTL (('s' << 24) | ('e' << 16) | ('n' << 8)) 50f2dbfd32SRobert Mustacchi 51f2dbfd32SRobert Mustacchi /* 52f2dbfd32SRobert Mustacchi * Ask the sensor what kind of sensor it is. 53f2dbfd32SRobert Mustacchi */ 54*1045e13aSRobert Mustacchi #define SENSOR_IOCTL_KIND (SENSOR_IOCTL | 0x01) 55f2dbfd32SRobert Mustacchi 56f2dbfd32SRobert Mustacchi typedef struct sensor_ioctl_kind { 57f2dbfd32SRobert Mustacchi uint64_t sik_kind; 58f2dbfd32SRobert Mustacchi } sensor_ioctl_kind_t; 59f2dbfd32SRobert Mustacchi 60f2dbfd32SRobert Mustacchi /* 61*1045e13aSRobert Mustacchi * Ask the sensor for a scalar measurement. The sensor is responsible for 62*1045e13aSRobert Mustacchi * returning the units it's in. A scalar measurement is broken down into a 63f2dbfd32SRobert Mustacchi * signed value and a notion of its granularity. The sit_gran member indicates 64*1045e13aSRobert Mustacchi * the granularity: the number of increments per unit in the measurement (the 65*1045e13aSRobert Mustacchi * sit_value member). sit_gran is signed and the sign indicates whether one 66*1045e13aSRobert Mustacchi * needs to multiply or divide the granularity. The sit_prec member describes a 67*1045e13aSRobert Mustacchi * +/- value (taking sit_gran into account) that describes the precision of the 68*1045e13aSRobert Mustacchi * sensor. 69*1045e13aSRobert Mustacchi * 70*1045e13aSRobert Mustacchi * For example, consider a temperature sensor that set sit_gran to 10. This 71*1045e13aSRobert Mustacchi * would mean that the value in sit_value was in 10ths of a degree and that to 72*1045e13aSRobert Mustacchi * get the actual value in degrees, one would divide by 10. On the other hand, a 73*1045e13aSRobert Mustacchi * negative value means that we effectively have to multiply to get there. For 74*1045e13aSRobert Mustacchi * example, a value of -2 would indicate that each value in sit_value indicated 75*1045e13aSRobert Mustacchi * two degrees and to get the temperature in degrees you would multiply 76*1045e13aSRobert Mustacchi * sit_value * by two. 77f2dbfd32SRobert Mustacchi */ 78*1045e13aSRobert Mustacchi #define SENSOR_IOCTL_SCALAR (SENSOR_IOCTL | 0x02) 79f2dbfd32SRobert Mustacchi 80*1045e13aSRobert Mustacchi typedef struct sensor_ioctl_scalar { 81*1045e13aSRobert Mustacchi uint32_t sis_unit; 82*1045e13aSRobert Mustacchi int32_t sis_gran; 83*1045e13aSRobert Mustacchi uint32_t sis_prec; 84*1045e13aSRobert Mustacchi uint32_t sis_pad; 85*1045e13aSRobert Mustacchi int64_t sis_value; 86*1045e13aSRobert Mustacchi } sensor_ioctl_scalar_t; 87f2dbfd32SRobert Mustacchi 883ce53722SRobert Mustacchi #ifdef _KERNEL 893ce53722SRobert Mustacchi typedef int (*ksensor_kind_f)(void *, sensor_ioctl_kind_t *); 90*1045e13aSRobert Mustacchi typedef int (*ksensor_scalar_f)(void *, sensor_ioctl_scalar_t *); 913ce53722SRobert Mustacchi 923ce53722SRobert Mustacchi typedef struct { 93*1045e13aSRobert Mustacchi ksensor_kind_f kso_kind; 94*1045e13aSRobert Mustacchi ksensor_scalar_f kso_scalar; 953ce53722SRobert Mustacchi } ksensor_ops_t; 963ce53722SRobert Mustacchi 973ce53722SRobert Mustacchi extern int ksensor_kind_temperature(void *, sensor_ioctl_kind_t *); 98*1045e13aSRobert Mustacchi extern int ksensor_kind_voltage(void *, sensor_ioctl_kind_t *); 99*1045e13aSRobert Mustacchi extern int ksensor_kind_current(void *, sensor_ioctl_kind_t *); 1003ce53722SRobert Mustacchi 1013ce53722SRobert Mustacchi /* 1023ce53722SRobert Mustacchi * Create a sensor where the class and name is supplied. 1033ce53722SRobert Mustacchi */ 1043ce53722SRobert Mustacchi extern int ksensor_create(dev_info_t *, const ksensor_ops_t *, void *, 1053ce53722SRobert Mustacchi const char *, const char *, id_t *); 1063ce53722SRobert Mustacchi 1073ce53722SRobert Mustacchi /* 108*1045e13aSRobert Mustacchi * Create a scalar sensor for a PCI device. If this is not a device-wide 1093ce53722SRobert Mustacchi * (e.g. per-function) sensor, this should not be used. 1103ce53722SRobert Mustacchi */ 111*1045e13aSRobert Mustacchi extern int ksensor_create_scalar_pcidev(dev_info_t *, uint_t, 112*1045e13aSRobert Mustacchi const ksensor_ops_t *, void *, const char *, id_t *); 1133ce53722SRobert Mustacchi 1143ce53722SRobert Mustacchi /* 1153ce53722SRobert Mustacchi * Remove a named or all sensors from this driver. 1163ce53722SRobert Mustacchi */ 1173ce53722SRobert Mustacchi #define KSENSOR_ALL_IDS INT_MIN 1183ce53722SRobert Mustacchi extern int ksensor_remove(dev_info_t *, id_t); 1193ce53722SRobert Mustacchi 1203ce53722SRobert Mustacchi #endif 1213ce53722SRobert Mustacchi 122f2dbfd32SRobert Mustacchi #ifdef __cplusplus 123f2dbfd32SRobert Mustacchi } 124f2dbfd32SRobert Mustacchi #endif 125f2dbfd32SRobert Mustacchi 126f2dbfd32SRobert Mustacchi #endif /* _SYS_SENSORS_H */ 127