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