sysfs-interface 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. Naming and data format standards for sysfs files
  2. ------------------------------------------------
  3. The libsensors library offers an interface to the raw sensors data
  4. through the sysfs interface. Since lm-sensors 3.0.0, libsensors is
  5. completely chip-independent. It assumes that all the kernel drivers
  6. implement the standard sysfs interface described in this document.
  7. This makes adding or updating support for any given chip very easy, as
  8. libsensors, and applications using it, do not need to be modified.
  9. This is a major improvement compared to lm-sensors 2.
  10. Note that motherboards vary widely in the connections to sensor chips.
  11. There is no standard that ensures, for example, that the second
  12. temperature sensor is connected to the CPU, or that the second fan is on
  13. the CPU. Also, some values reported by the chips need some computation
  14. before they make full sense. For example, most chips can only measure
  15. voltages between 0 and +4V. Other voltages are scaled back into that
  16. range using external resistors. Since the values of these resistors
  17. can change from motherboard to motherboard, the conversions cannot be
  18. hard coded into the driver and have to be done in user space.
  19. For this reason, even if we aim at a chip-independent libsensors, it will
  20. still require a configuration file (e.g. /etc/sensors.conf) for proper
  21. values conversion, labeling of inputs and hiding of unused inputs.
  22. An alternative method that some programs use is to access the sysfs
  23. files directly. This document briefly describes the standards that the
  24. drivers follow, so that an application program can scan for entries and
  25. access this data in a simple and consistent way. That said, such programs
  26. will have to implement conversion, labeling and hiding of inputs. For
  27. this reason, it is still not recommended to bypass the library.
  28. Each chip gets its own directory in the sysfs /sys/devices tree. To
  29. find all sensor chips, it is easier to follow the device symlinks from
  30. /sys/class/hwmon/hwmon*.
  31. Up to lm-sensors 3.0.0, libsensors looks for hardware monitoring attributes
  32. in the "physical" device directory. Since lm-sensors 3.0.1, attributes found
  33. in the hwmon "class" device directory are also supported. Complex drivers
  34. (e.g. drivers for multifunction chips) may want to use this possibility to
  35. avoid namespace pollution. The only drawback will be that older versions of
  36. libsensors won't support the driver in question.
  37. All sysfs values are fixed point numbers.
  38. There is only one value per file, unlike the older /proc specification.
  39. The common scheme for files naming is: <type><number>_<item>. Usual
  40. types for sensor chips are "in" (voltage), "temp" (temperature) and
  41. "fan" (fan). Usual items are "input" (measured value), "max" (high
  42. threshold, "min" (low threshold). Numbering usually starts from 1,
  43. except for voltages which start from 0 (because most data sheets use
  44. this). A number is always used for elements that can be present more
  45. than once, even if there is a single element of the given type on the
  46. specific chip. Other files do not refer to a specific element, so
  47. they have a simple name, and no number.
  48. Alarms are direct indications read from the chips. The drivers do NOT
  49. make comparisons of readings to thresholds. This allows violations
  50. between readings to be caught and alarmed. The exact definition of an
  51. alarm (for example, whether a threshold must be met or must be exceeded
  52. to cause an alarm) is chip-dependent.
  53. When setting values of hwmon sysfs attributes, the string representation of
  54. the desired value must be written, note that strings which are not a number
  55. are interpreted as 0! For more on how written strings are interpreted see the
  56. "sysfs attribute writes interpretation" section at the end of this file.
  57. -------------------------------------------------------------------------
  58. [0-*] denotes any positive number starting from 0
  59. [1-*] denotes any positive number starting from 1
  60. RO read only value
  61. RW read/write value
  62. Read/write values may be read-only for some chips, depending on the
  63. hardware implementation.
  64. All entries (except name) are optional, and should only be created in a
  65. given driver if the chip has the feature.
  66. ********
  67. * Name *
  68. ********
  69. name The chip name.
  70. This should be a short, lowercase string, not containing
  71. spaces nor dashes, representing the chip name. This is
  72. the only mandatory attribute.
  73. I2C devices get this attribute created automatically.
  74. RO
  75. ************
  76. * Voltages *
  77. ************
  78. in[0-*]_min Voltage min value.
  79. Unit: millivolt
  80. RW
  81. in[0-*]_max Voltage max value.
  82. Unit: millivolt
  83. RW
  84. in[0-*]_input Voltage input value.
  85. Unit: millivolt
  86. RO
  87. Voltage measured on the chip pin.
  88. Actual voltage depends on the scaling resistors on the
  89. motherboard, as recommended in the chip datasheet.
  90. This varies by chip and by motherboard.
  91. Because of this variation, values are generally NOT scaled
  92. by the chip driver, and must be done by the application.
  93. However, some drivers (notably lm87 and via686a)
  94. do scale, because of internal resistors built into a chip.
  95. These drivers will output the actual voltage. Rule of
  96. thumb: drivers should report the voltage values at the
  97. "pins" of the chip.
  98. in[0-*]_label Suggested voltage channel label.
  99. Text string
  100. Should only be created if the driver has hints about what
  101. this voltage channel is being used for, and user-space
  102. doesn't. In all other cases, the label is provided by
  103. user-space.
  104. RO
  105. cpu[0-*]_vid CPU core reference voltage.
  106. Unit: millivolt
  107. RO
  108. Not always correct.
  109. vrm Voltage Regulator Module version number.
  110. RW (but changing it should no more be necessary)
  111. Originally the VRM standard version multiplied by 10, but now
  112. an arbitrary number, as not all standards have a version
  113. number.
  114. Affects the way the driver calculates the CPU core reference
  115. voltage from the vid pins.
  116. Also see the Alarms section for status flags associated with voltages.
  117. ********
  118. * Fans *
  119. ********
  120. fan[1-*]_min Fan minimum value
  121. Unit: revolution/min (RPM)
  122. RW
  123. fan[1-*]_max Fan maximum value
  124. Unit: revolution/min (RPM)
  125. Only rarely supported by the hardware.
  126. RW
  127. fan[1-*]_input Fan input value.
  128. Unit: revolution/min (RPM)
  129. RO
  130. fan[1-*]_div Fan divisor.
  131. Integer value in powers of two (1, 2, 4, 8, 16, 32, 64, 128).
  132. RW
  133. Some chips only support values 1, 2, 4 and 8.
  134. Note that this is actually an internal clock divisor, which
  135. affects the measurable speed range, not the read value.
  136. fan[1-*]_target
  137. Desired fan speed
  138. Unit: revolution/min (RPM)
  139. RW
  140. Only makes sense if the chip supports closed-loop fan speed
  141. control based on the measured fan speed.
  142. fan[1-*]_label Suggested fan channel label.
  143. Text string
  144. Should only be created if the driver has hints about what
  145. this fan channel is being used for, and user-space doesn't.
  146. In all other cases, the label is provided by user-space.
  147. RO
  148. Also see the Alarms section for status flags associated with fans.
  149. *******
  150. * PWM *
  151. *******
  152. pwm[1-*] Pulse width modulation fan control.
  153. Integer value in the range 0 to 255
  154. RW
  155. 255 is max or 100%.
  156. pwm[1-*]_enable
  157. Fan speed control method:
  158. 0: no fan speed control (i.e. fan at full speed)
  159. 1: manual fan speed control enabled (using pwm[1-*])
  160. 2+: automatic fan speed control enabled
  161. Check individual chip documentation files for automatic mode
  162. details.
  163. RW
  164. pwm[1-*]_mode 0: DC mode (direct current)
  165. 1: PWM mode (pulse-width modulation)
  166. RW
  167. pwm[1-*]_freq Base PWM frequency in Hz.
  168. Only possibly available when pwmN_mode is PWM, but not always
  169. present even then.
  170. RW
  171. pwm[1-*]_auto_channels_temp
  172. Select which temperature channels affect this PWM output in
  173. auto mode. Bitfield, 1 is temp1, 2 is temp2, 4 is temp3 etc...
  174. Which values are possible depend on the chip used.
  175. RW
  176. pwm[1-*]_auto_point[1-*]_pwm
  177. pwm[1-*]_auto_point[1-*]_temp
  178. pwm[1-*]_auto_point[1-*]_temp_hyst
  179. Define the PWM vs temperature curve. Number of trip points is
  180. chip-dependent. Use this for chips which associate trip points
  181. to PWM output channels.
  182. RW
  183. OR
  184. temp[1-*]_auto_point[1-*]_pwm
  185. temp[1-*]_auto_point[1-*]_temp
  186. temp[1-*]_auto_point[1-*]_temp_hyst
  187. Define the PWM vs temperature curve. Number of trip points is
  188. chip-dependent. Use this for chips which associate trip points
  189. to temperature channels.
  190. RW
  191. ****************
  192. * Temperatures *
  193. ****************
  194. temp[1-*]_type Sensor type selection.
  195. Integers 1 to 6
  196. RW
  197. 1: PII/Celeron Diode
  198. 2: 3904 transistor
  199. 3: thermal diode
  200. 4: thermistor
  201. 5: AMD AMDSI
  202. 6: Intel PECI
  203. Not all types are supported by all chips
  204. temp[1-*]_max Temperature max value.
  205. Unit: millidegree Celsius (or millivolt, see below)
  206. RW
  207. temp[1-*]_min Temperature min value.
  208. Unit: millidegree Celsius
  209. RW
  210. temp[1-*]_max_hyst
  211. Temperature hysteresis value for max limit.
  212. Unit: millidegree Celsius
  213. Must be reported as an absolute temperature, NOT a delta
  214. from the max value.
  215. RW
  216. temp[1-*]_input Temperature input value.
  217. Unit: millidegree Celsius
  218. RO
  219. temp[1-*]_crit Temperature critical value, typically greater than
  220. corresponding temp_max values.
  221. Unit: millidegree Celsius
  222. RW
  223. temp[1-*]_crit_hyst
  224. Temperature hysteresis value for critical limit.
  225. Unit: millidegree Celsius
  226. Must be reported as an absolute temperature, NOT a delta
  227. from the critical value.
  228. RW
  229. temp[1-*]_offset
  230. Temperature offset which is added to the temperature reading
  231. by the chip.
  232. Unit: millidegree Celsius
  233. Read/Write value.
  234. temp[1-*]_label Suggested temperature channel label.
  235. Text string
  236. Should only be created if the driver has hints about what
  237. this temperature channel is being used for, and user-space
  238. doesn't. In all other cases, the label is provided by
  239. user-space.
  240. RO
  241. Some chips measure temperature using external thermistors and an ADC, and
  242. report the temperature measurement as a voltage. Converting this voltage
  243. back to a temperature (or the other way around for limits) requires
  244. mathematical functions not available in the kernel, so the conversion
  245. must occur in user space. For these chips, all temp* files described
  246. above should contain values expressed in millivolt instead of millidegree
  247. Celsius. In other words, such temperature channels are handled as voltage
  248. channels by the driver.
  249. Also see the Alarms section for status flags associated with temperatures.
  250. ************
  251. * Currents *
  252. ************
  253. Note that no known chip provides current measurements as of writing,
  254. so this part is theoretical, so to say.
  255. curr[1-*]_max Current max value
  256. Unit: milliampere
  257. RW
  258. curr[1-*]_min Current min value.
  259. Unit: milliampere
  260. RW
  261. curr[1-*]_input Current input value
  262. Unit: milliampere
  263. RO
  264. *********
  265. * Power *
  266. *********
  267. power[1-*]_average Average power use
  268. Unit: microWatt
  269. RO
  270. power[1-*]_average_interval Power use averaging interval
  271. Unit: milliseconds
  272. RW
  273. power[1-*]_average_highest Historical average maximum power use
  274. Unit: microWatt
  275. RO
  276. power[1-*]_average_lowest Historical average minimum power use
  277. Unit: microWatt
  278. RO
  279. power[1-*]_input Instantaneous power use
  280. Unit: microWatt
  281. RO
  282. power[1-*]_input_highest Historical maximum power use
  283. Unit: microWatt
  284. RO
  285. power[1-*]_input_lowest Historical minimum power use
  286. Unit: microWatt
  287. RO
  288. power[1-*]_reset_history Reset input_highest, input_lowest,
  289. average_highest and average_lowest.
  290. WO
  291. **********
  292. * Energy *
  293. **********
  294. energy[1-*]_input Cumulative energy use
  295. Unit: microJoule
  296. RO
  297. **********
  298. * Alarms *
  299. **********
  300. Each channel or limit may have an associated alarm file, containing a
  301. boolean value. 1 means than an alarm condition exists, 0 means no alarm.
  302. Usually a given chip will either use channel-related alarms, or
  303. limit-related alarms, not both. The driver should just reflect the hardware
  304. implementation.
  305. in[0-*]_alarm
  306. fan[1-*]_alarm
  307. temp[1-*]_alarm
  308. Channel alarm
  309. 0: no alarm
  310. 1: alarm
  311. RO
  312. OR
  313. in[0-*]_min_alarm
  314. in[0-*]_max_alarm
  315. fan[1-*]_min_alarm
  316. fan[1-*]_max_alarm
  317. temp[1-*]_min_alarm
  318. temp[1-*]_max_alarm
  319. temp[1-*]_crit_alarm
  320. Limit alarm
  321. 0: no alarm
  322. 1: alarm
  323. RO
  324. Each input channel may have an associated fault file. This can be used
  325. to notify open diodes, unconnected fans etc. where the hardware
  326. supports it. When this boolean has value 1, the measurement for that
  327. channel should not be trusted.
  328. in[0-*]_fault
  329. fan[1-*]_fault
  330. temp[1-*]_fault
  331. Input fault condition
  332. 0: no fault occured
  333. 1: fault condition
  334. RO
  335. Some chips also offer the possibility to get beeped when an alarm occurs:
  336. beep_enable Master beep enable
  337. 0: no beeps
  338. 1: beeps
  339. RW
  340. in[0-*]_beep
  341. fan[1-*]_beep
  342. temp[1-*]_beep
  343. Channel beep
  344. 0: disable
  345. 1: enable
  346. RW
  347. In theory, a chip could provide per-limit beep masking, but no such chip
  348. was seen so far.
  349. Old drivers provided a different, non-standard interface to alarms and
  350. beeps. These interface files are deprecated, but will be kept around
  351. for compatibility reasons:
  352. alarms Alarm bitmask.
  353. RO
  354. Integer representation of one to four bytes.
  355. A '1' bit means an alarm.
  356. Chips should be programmed for 'comparator' mode so that
  357. the alarm will 'come back' after you read the register
  358. if it is still valid.
  359. Generally a direct representation of a chip's internal
  360. alarm registers; there is no standard for the position
  361. of individual bits. For this reason, the use of this
  362. interface file for new drivers is discouraged. Use
  363. individual *_alarm and *_fault files instead.
  364. Bits are defined in kernel/include/sensors.h.
  365. beep_mask Bitmask for beep.
  366. Same format as 'alarms' with the same bit locations,
  367. use discouraged for the same reason. Use individual
  368. *_beep files instead.
  369. RW
  370. ***********************
  371. * Intrusion detection *
  372. ***********************
  373. intrusion[0-*]_alarm
  374. Chassis intrusion detection
  375. 0: OK
  376. 1: intrusion detected
  377. RW
  378. Contrary to regular alarm flags which clear themselves
  379. automatically when read, this one sticks until cleared by
  380. the user. This is done by writing 0 to the file. Writing
  381. other values is unsupported.
  382. intrusion[0-*]_beep
  383. Chassis intrusion beep
  384. 0: disable
  385. 1: enable
  386. RW
  387. sysfs attribute writes interpretation
  388. -------------------------------------
  389. hwmon sysfs attributes always contain numbers, so the first thing to do is to
  390. convert the input to a number, there are 2 ways todo this depending whether
  391. the number can be negative or not:
  392. unsigned long u = simple_strtoul(buf, NULL, 10);
  393. long s = simple_strtol(buf, NULL, 10);
  394. With buf being the buffer with the user input being passed by the kernel.
  395. Notice that we do not use the second argument of strto[u]l, and thus cannot
  396. tell when 0 is returned, if this was really 0 or is caused by invalid input.
  397. This is done deliberately as checking this everywhere would add a lot of
  398. code to the kernel.
  399. Notice that it is important to always store the converted value in an
  400. unsigned long or long, so that no wrap around can happen before any further
  401. checking.
  402. After the input string is converted to an (unsigned) long, the value should be
  403. checked if its acceptable. Be careful with further conversions on the value
  404. before checking it for validity, as these conversions could still cause a wrap
  405. around before the check. For example do not multiply the result, and only
  406. add/subtract if it has been divided before the add/subtract.
  407. What to do if a value is found to be invalid, depends on the type of the
  408. sysfs attribute that is being set. If it is a continuous setting like a
  409. tempX_max or inX_max attribute, then the value should be clamped to its
  410. limits using SENSORS_LIMIT(value, min_limit, max_limit). If it is not
  411. continuous like for example a tempX_type, then when an invalid value is
  412. written, -EINVAL should be returned.
  413. Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees):
  414. long v = simple_strtol(buf, NULL, 10) / 1000;
  415. v = SENSORS_LIMIT(v, -128, 127);
  416. /* write v to register */
  417. Example2, fan divider setting, valid values 2, 4 and 8:
  418. unsigned long v = simple_strtoul(buf, NULL, 10);
  419. switch (v) {
  420. case 2: v = 1; break;
  421. case 4: v = 2; break;
  422. case 8: v = 3; break;
  423. default:
  424. return -EINVAL;
  425. }
  426. /* write v to register */