| 1 | /* |
|---|
| 2 | sensors.h - Part of libsensors, a Linux library for reading sensor data. |
|---|
| 3 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
|---|
| 4 | Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | This program is distributed in the hope that it will be useful, |
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | You should have received a copy of the GNU General Public License |
|---|
| 17 | along with this program; if not, write to the Free Software |
|---|
| 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 19 | MA 02110-1301 USA. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #ifndef LIB_SENSORS_SENSORS_H |
|---|
| 23 | #define LIB_SENSORS_SENSORS_H |
|---|
| 24 | |
|---|
| 25 | #include <stdio.h> |
|---|
| 26 | #include <limits.h> |
|---|
| 27 | |
|---|
| 28 | /* Publicly accessible library functions */ |
|---|
| 29 | |
|---|
| 30 | /* libsensors API version define, first digit is the major version (changed |
|---|
| 31 | when the API + ABI breaks), the third digit is incremented to track small |
|---|
| 32 | API additions like new flags / enum values. The second digit is for tracking |
|---|
| 33 | larger additions like new methods. */ |
|---|
| 34 | #define SENSORS_API_VERSION 0x410 |
|---|
| 35 | |
|---|
| 36 | #define SENSORS_CHIP_NAME_PREFIX_ANY NULL |
|---|
| 37 | #define SENSORS_CHIP_NAME_ADDR_ANY (-1) |
|---|
| 38 | |
|---|
| 39 | #define SENSORS_BUS_TYPE_ANY (-1) |
|---|
| 40 | #define SENSORS_BUS_TYPE_I2C 0 |
|---|
| 41 | #define SENSORS_BUS_TYPE_ISA 1 |
|---|
| 42 | #define SENSORS_BUS_TYPE_PCI 2 |
|---|
| 43 | #define SENSORS_BUS_TYPE_SPI 3 |
|---|
| 44 | #define SENSORS_BUS_TYPE_VIRTUAL 4 |
|---|
| 45 | #define SENSORS_BUS_TYPE_ACPI 5 |
|---|
| 46 | #define SENSORS_BUS_NR_ANY (-1) |
|---|
| 47 | #define SENSORS_BUS_NR_IGNORE (-2) |
|---|
| 48 | |
|---|
| 49 | #ifdef __cplusplus |
|---|
| 50 | extern "C" { |
|---|
| 51 | #endif /* __cplusplus */ |
|---|
| 52 | |
|---|
| 53 | extern const char *libsensors_version; |
|---|
| 54 | |
|---|
| 55 | typedef struct sensors_bus_id { |
|---|
| 56 | short type; |
|---|
| 57 | short nr; |
|---|
| 58 | } sensors_bus_id; |
|---|
| 59 | |
|---|
| 60 | /* A chip name is encoded in this structure */ |
|---|
| 61 | typedef struct sensors_chip_name { |
|---|
| 62 | char *prefix; |
|---|
| 63 | sensors_bus_id bus; |
|---|
| 64 | int addr; |
|---|
| 65 | char *path; |
|---|
| 66 | } sensors_chip_name; |
|---|
| 67 | |
|---|
| 68 | /* Load the configuration file and the detected chips list. If this |
|---|
| 69 | returns a value unequal to zero, you are in trouble; you can not |
|---|
| 70 | assume anything will be initialized properly. If you want to |
|---|
| 71 | reload the configuration file, call sensors_cleanup() below before |
|---|
| 72 | calling sensors_init() again. */ |
|---|
| 73 | int sensors_init(FILE *input); |
|---|
| 74 | |
|---|
| 75 | /* Clean-up function: You can't access anything after |
|---|
| 76 | this, until the next sensors_init() call! */ |
|---|
| 77 | void sensors_cleanup(void); |
|---|
| 78 | |
|---|
| 79 | /* Parse a chip name to the internal representation. Return 0 on success, <0 |
|---|
| 80 | on error. */ |
|---|
| 81 | int sensors_parse_chip_name(const char *orig_name, sensors_chip_name *res); |
|---|
| 82 | |
|---|
| 83 | /* Print a chip name from its internal representation. Note that chip should |
|---|
| 84 | not contain wildcard values! Return the number of characters printed on |
|---|
| 85 | success (same as snprintf), <0 on error. */ |
|---|
| 86 | int sensors_snprintf_chip_name(char *str, size_t size, |
|---|
| 87 | const sensors_chip_name *chip); |
|---|
| 88 | |
|---|
| 89 | /* This function returns the adapter name of a bus, |
|---|
| 90 | as used within the sensors_chip_name structure. If it could not be found, |
|---|
| 91 | it returns NULL */ |
|---|
| 92 | const char *sensors_get_adapter_name(const sensors_bus_id *bus); |
|---|
| 93 | |
|---|
| 94 | typedef struct sensors_feature sensors_feature; |
|---|
| 95 | |
|---|
| 96 | /* Look up the label for a given feature. Note that chip should not |
|---|
| 97 | contain wildcard values! The returned string is newly allocated (free it |
|---|
| 98 | yourself). On failure, NULL is returned. |
|---|
| 99 | If no label exists for this feature, its name is returned itself. */ |
|---|
| 100 | char *sensors_get_label(const sensors_chip_name *name, |
|---|
| 101 | const sensors_feature *feature); |
|---|
| 102 | |
|---|
| 103 | /* Read the value of a subfeature of a certain chip. Note that chip should not |
|---|
| 104 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 105 | on failure. */ |
|---|
| 106 | int sensors_get_value(const sensors_chip_name *name, int subfeat_nr, |
|---|
| 107 | double *value); |
|---|
| 108 | |
|---|
| 109 | /* Set the value of a subfeature of a certain chip. Note that chip should not |
|---|
| 110 | contain wildcard values! This function will return 0 on success, and <0 |
|---|
| 111 | on failure. */ |
|---|
| 112 | int sensors_set_value(const sensors_chip_name *name, int subfeat_nr, |
|---|
| 113 | double value); |
|---|
| 114 | |
|---|
| 115 | /* Execute all set statements for this particular chip. The chip may contain |
|---|
| 116 | wildcards! This function will return 0 on success, and <0 on failure. */ |
|---|
| 117 | int sensors_do_chip_sets(const sensors_chip_name *name); |
|---|
| 118 | |
|---|
| 119 | /* This function returns all detected chips that match a given chip name, |
|---|
| 120 | one by one. If no chip name is provided, all detected chips are returned. |
|---|
| 121 | To start at the beginning of the list, use 0 for nr; NULL is returned if |
|---|
| 122 | we are at the end of the list. Do not try to change these chip names, as |
|---|
| 123 | they point to internal structures! */ |
|---|
| 124 | const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name |
|---|
| 125 | *match, int *nr); |
|---|
| 126 | |
|---|
| 127 | /* These defines are used in the flags field of sensors_subfeature */ |
|---|
| 128 | #define SENSORS_MODE_R 1 |
|---|
| 129 | #define SENSORS_MODE_W 2 |
|---|
| 130 | #define SENSORS_COMPUTE_MAPPING 4 |
|---|
| 131 | |
|---|
| 132 | typedef enum sensors_feature_type { |
|---|
| 133 | SENSORS_FEATURE_IN = 0x00, |
|---|
| 134 | SENSORS_FEATURE_FAN = 0x01, |
|---|
| 135 | SENSORS_FEATURE_TEMP = 0x02, |
|---|
| 136 | SENSORS_FEATURE_POWER = 0x03, |
|---|
| 137 | SENSORS_FEATURE_ENERGY = 0x04, |
|---|
| 138 | SENSORS_FEATURE_CURR = 0x05, |
|---|
| 139 | SENSORS_FEATURE_VID = 0x10, |
|---|
| 140 | SENSORS_FEATURE_BEEP_ENABLE = 0x18, |
|---|
| 141 | SENSORS_FEATURE_UNKNOWN = INT_MAX, |
|---|
| 142 | } sensors_feature_type; |
|---|
| 143 | |
|---|
| 144 | /* All the sensor types (in, fan, temp, vid) are a multiple of 0x100 apart, |
|---|
| 145 | and sensor subfeatures which have no compute mapping have bit 7 set. */ |
|---|
| 146 | typedef enum sensors_subfeature_type { |
|---|
| 147 | SENSORS_SUBFEATURE_IN_INPUT = SENSORS_FEATURE_IN << 8, |
|---|
| 148 | SENSORS_SUBFEATURE_IN_MIN, |
|---|
| 149 | SENSORS_SUBFEATURE_IN_MAX, |
|---|
| 150 | SENSORS_SUBFEATURE_IN_ALARM = (SENSORS_FEATURE_IN << 8) | 0x80, |
|---|
| 151 | SENSORS_SUBFEATURE_IN_MIN_ALARM, |
|---|
| 152 | SENSORS_SUBFEATURE_IN_MAX_ALARM, |
|---|
| 153 | SENSORS_SUBFEATURE_IN_BEEP, |
|---|
| 154 | |
|---|
| 155 | SENSORS_SUBFEATURE_FAN_INPUT = SENSORS_FEATURE_FAN << 8, |
|---|
| 156 | SENSORS_SUBFEATURE_FAN_MIN, |
|---|
| 157 | SENSORS_SUBFEATURE_FAN_ALARM = (SENSORS_FEATURE_FAN << 8) | 0x80, |
|---|
| 158 | SENSORS_SUBFEATURE_FAN_FAULT, |
|---|
| 159 | SENSORS_SUBFEATURE_FAN_DIV, |
|---|
| 160 | SENSORS_SUBFEATURE_FAN_BEEP, |
|---|
| 161 | |
|---|
| 162 | SENSORS_SUBFEATURE_TEMP_INPUT = SENSORS_FEATURE_TEMP << 8, |
|---|
| 163 | SENSORS_SUBFEATURE_TEMP_MAX, |
|---|
| 164 | SENSORS_SUBFEATURE_TEMP_MAX_HYST, |
|---|
| 165 | SENSORS_SUBFEATURE_TEMP_MIN, |
|---|
| 166 | SENSORS_SUBFEATURE_TEMP_CRIT, |
|---|
| 167 | SENSORS_SUBFEATURE_TEMP_CRIT_HYST, |
|---|
| 168 | SENSORS_SUBFEATURE_TEMP_ALARM = (SENSORS_FEATURE_TEMP << 8) | 0x80, |
|---|
| 169 | SENSORS_SUBFEATURE_TEMP_MAX_ALARM, |
|---|
| 170 | SENSORS_SUBFEATURE_TEMP_MIN_ALARM, |
|---|
| 171 | SENSORS_SUBFEATURE_TEMP_CRIT_ALARM, |
|---|
| 172 | SENSORS_SUBFEATURE_TEMP_FAULT, |
|---|
| 173 | SENSORS_SUBFEATURE_TEMP_TYPE, |
|---|
| 174 | SENSORS_SUBFEATURE_TEMP_OFFSET, |
|---|
| 175 | SENSORS_SUBFEATURE_TEMP_BEEP, |
|---|
| 176 | |
|---|
| 177 | SENSORS_SUBFEATURE_POWER_AVERAGE = SENSORS_FEATURE_POWER << 8, |
|---|
| 178 | SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST, |
|---|
| 179 | SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST, |
|---|
| 180 | SENSORS_SUBFEATURE_POWER_INPUT, |
|---|
| 181 | SENSORS_SUBFEATURE_POWER_INPUT_HIGHEST, |
|---|
| 182 | SENSORS_SUBFEATURE_POWER_INPUT_LOWEST, |
|---|
| 183 | SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL = (SENSORS_FEATURE_POWER << 8) | 0x80, |
|---|
| 184 | |
|---|
| 185 | SENSORS_SUBFEATURE_ENERGY_INPUT = SENSORS_FEATURE_ENERGY << 8, |
|---|
| 186 | |
|---|
| 187 | SENSORS_SUBFEATURE_CURR_INPUT = SENSORS_FEATURE_CURR << 8, |
|---|
| 188 | SENSORS_SUBFEATURE_CURR_MIN, |
|---|
| 189 | SENSORS_SUBFEATURE_CURR_MAX, |
|---|
| 190 | SENSORS_SUBFEATURE_CURR_ALARM = (SENSORS_FEATURE_CURR << 8) | 0x80, |
|---|
| 191 | SENSORS_SUBFEATURE_CURR_MIN_ALARM, |
|---|
| 192 | SENSORS_SUBFEATURE_CURR_MAX_ALARM, |
|---|
| 193 | SENSORS_SUBFEATURE_CURR_BEEP, |
|---|
| 194 | |
|---|
| 195 | SENSORS_SUBFEATURE_VID = SENSORS_FEATURE_VID << 8, |
|---|
| 196 | |
|---|
| 197 | SENSORS_SUBFEATURE_BEEP_ENABLE = SENSORS_FEATURE_BEEP_ENABLE << 8, |
|---|
| 198 | |
|---|
| 199 | SENSORS_SUBFEATURE_UNKNOWN = INT_MAX, |
|---|
| 200 | } sensors_subfeature_type; |
|---|
| 201 | |
|---|
| 202 | /* Data about a single chip feature (or category leader) */ |
|---|
| 203 | struct sensors_feature { |
|---|
| 204 | char *name; |
|---|
| 205 | int number; |
|---|
| 206 | sensors_feature_type type; |
|---|
| 207 | /* Members below are for libsensors internal use only */ |
|---|
| 208 | int first_subfeature; |
|---|
| 209 | int padding1; |
|---|
| 210 | }; |
|---|
| 211 | |
|---|
| 212 | /* Data about a single chip subfeature: |
|---|
| 213 | name is the string name used to refer to this subfeature (in config files) |
|---|
| 214 | number is the internal subfeature number, used in many functions to refer |
|---|
| 215 | to this subfeature |
|---|
| 216 | type is the subfeature type |
|---|
| 217 | mapping is the number of a main feature this subfeature belongs to |
|---|
| 218 | (for example subfeatures fan1_input, fan1_min, fan1_div and fan1_alarm |
|---|
| 219 | are mapped to main feature fan1) |
|---|
| 220 | flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable), |
|---|
| 221 | SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the |
|---|
| 222 | computation rules of the main feature) */ |
|---|
| 223 | typedef struct sensors_subfeature { |
|---|
| 224 | char *name; |
|---|
| 225 | int number; |
|---|
| 226 | sensors_subfeature_type type; |
|---|
| 227 | int mapping; |
|---|
| 228 | unsigned int flags; |
|---|
| 229 | } sensors_subfeature; |
|---|
| 230 | |
|---|
| 231 | /* This returns all main features of a specific chip. nr is an internally |
|---|
| 232 | used variable. Set it to zero to start at the begin of the list. If no |
|---|
| 233 | more features are found NULL is returned. |
|---|
| 234 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 235 | data structures. */ |
|---|
| 236 | const sensors_feature * |
|---|
| 237 | sensors_get_features(const sensors_chip_name *name, int *nr); |
|---|
| 238 | |
|---|
| 239 | /* This returns all subfeatures of a given main feature. nr is an internally |
|---|
| 240 | used variable. Set it to zero to start at the begin of the list. If no |
|---|
| 241 | more features are found NULL is returned. |
|---|
| 242 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 243 | data structures. */ |
|---|
| 244 | const sensors_subfeature * |
|---|
| 245 | sensors_get_all_subfeatures(const sensors_chip_name *name, |
|---|
| 246 | const sensors_feature *feature, int *nr); |
|---|
| 247 | |
|---|
| 248 | /* This returns the subfeature of the given type for a given main feature, |
|---|
| 249 | if it exists, NULL otherwise. |
|---|
| 250 | Do not try to change the returned structure; you will corrupt internal |
|---|
| 251 | data structures. */ |
|---|
| 252 | const sensors_subfeature * |
|---|
| 253 | sensors_get_subfeature(const sensors_chip_name *name, |
|---|
| 254 | const sensors_feature *feature, |
|---|
| 255 | sensors_subfeature_type type); |
|---|
| 256 | |
|---|
| 257 | #ifdef __cplusplus |
|---|
| 258 | } |
|---|
| 259 | #endif /* __cplusplus */ |
|---|
| 260 | |
|---|
| 261 | #endif /* def LIB_SENSORS_ERROR_H */ |
|---|