sysfs-interface 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. WO write only value
  62. RW read/write value
  63. Read/write values may be read-only for some chips, depending on the
  64. hardware implementation.
  65. All entries (except name) are optional, and should only be created in a
  66. given driver if the chip has the feature.
  67. *********************
  68. * Global attributes *
  69. *********************
  70. name The chip name.
  71. This should be a short, lowercase string, not containing
  72. whitespace, dashes, or the wildcard character '*'.
  73. This attribute represents the chip name. It is the only
  74. mandatory attribute.
  75. I2C devices get this attribute created automatically.
  76. RO
  77. update_interval The interval at which the chip will update readings.
  78. Unit: millisecond
  79. RW
  80. Some devices have a variable update rate or interval.
  81. This attribute can be used to change it to the desired value.
  82. ************
  83. * Voltages *
  84. ************
  85. in[0-*]_min Voltage min value.
  86. Unit: millivolt
  87. RW
  88. in[0-*]_lcrit Voltage critical min value.
  89. Unit: millivolt
  90. RW
  91. If voltage drops to or below this limit, the system may
  92. take drastic action such as power down or reset. At the very
  93. least, it should report a fault.
  94. in[0-*]_max Voltage max value.
  95. Unit: millivolt
  96. RW
  97. in[0-*]_crit Voltage critical max value.
  98. Unit: millivolt
  99. RW
  100. If voltage reaches or exceeds this limit, the system may
  101. take drastic action such as power down or reset. At the very
  102. least, it should report a fault.
  103. in[0-*]_input Voltage input value.
  104. Unit: millivolt
  105. RO
  106. Voltage measured on the chip pin.
  107. Actual voltage depends on the scaling resistors on the
  108. motherboard, as recommended in the chip datasheet.
  109. This varies by chip and by motherboard.
  110. Because of this variation, values are generally NOT scaled
  111. by the chip driver, and must be done by the application.
  112. However, some drivers (notably lm87 and via686a)
  113. do scale, because of internal resistors built into a chip.
  114. These drivers will output the actual voltage. Rule of
  115. thumb: drivers should report the voltage values at the
  116. "pins" of the chip.
  117. in[0-*]_average
  118. Average voltage
  119. Unit: millivolt
  120. RO
  121. in[0-*]_lowest
  122. Historical minimum voltage
  123. Unit: millivolt
  124. RO
  125. in[0-*]_highest
  126. Historical maximum voltage
  127. Unit: millivolt
  128. RO
  129. in[0-*]_reset_history
  130. Reset inX_lowest and inX_highest
  131. WO
  132. in_reset_history
  133. Reset inX_lowest and inX_highest for all sensors
  134. WO
  135. in[0-*]_label Suggested voltage channel label.
  136. Text string
  137. Should only be created if the driver has hints about what
  138. this voltage channel is being used for, and user-space
  139. doesn't. In all other cases, the label is provided by
  140. user-space.
  141. RO
  142. in[0-*]_enable
  143. Enable or disable the sensors.
  144. When disabled the sensor read will return -ENODATA.
  145. 1: Enable
  146. 0: Disable
  147. RW
  148. cpu[0-*]_vid CPU core reference voltage.
  149. Unit: millivolt
  150. RO
  151. Not always correct.
  152. vrm Voltage Regulator Module version number.
  153. RW (but changing it should no more be necessary)
  154. Originally the VRM standard version multiplied by 10, but now
  155. an arbitrary number, as not all standards have a version
  156. number.
  157. Affects the way the driver calculates the CPU core reference
  158. voltage from the vid pins.
  159. Also see the Alarms section for status flags associated with voltages.
  160. ********
  161. * Fans *
  162. ********
  163. fan[1-*]_min Fan minimum value
  164. Unit: revolution/min (RPM)
  165. RW
  166. fan[1-*]_max Fan maximum value
  167. Unit: revolution/min (RPM)
  168. Only rarely supported by the hardware.
  169. RW
  170. fan[1-*]_input Fan input value.
  171. Unit: revolution/min (RPM)
  172. RO
  173. fan[1-*]_div Fan divisor.
  174. Integer value in powers of two (1, 2, 4, 8, 16, 32, 64, 128).
  175. RW
  176. Some chips only support values 1, 2, 4 and 8.
  177. Note that this is actually an internal clock divisor, which
  178. affects the measurable speed range, not the read value.
  179. fan[1-*]_pulses Number of tachometer pulses per fan revolution.
  180. Integer value, typically between 1 and 4.
  181. RW
  182. This value is a characteristic of the fan connected to the
  183. device's input, so it has to be set in accordance with the fan
  184. model.
  185. Should only be created if the chip has a register to configure
  186. the number of pulses. In the absence of such a register (and
  187. thus attribute) the value assumed by all devices is 2 pulses
  188. per fan revolution.
  189. fan[1-*]_target
  190. Desired fan speed
  191. Unit: revolution/min (RPM)
  192. RW
  193. Only makes sense if the chip supports closed-loop fan speed
  194. control based on the measured fan speed.
  195. fan[1-*]_label Suggested fan channel label.
  196. Text string
  197. Should only be created if the driver has hints about what
  198. this fan channel is being used for, and user-space doesn't.
  199. In all other cases, the label is provided by user-space.
  200. RO
  201. fan[1-*]_enable
  202. Enable or disable the sensors.
  203. When disabled the sensor read will return -ENODATA.
  204. 1: Enable
  205. 0: Disable
  206. RW
  207. Also see the Alarms section for status flags associated with fans.
  208. *******
  209. * PWM *
  210. *******
  211. pwm[1-*] Pulse width modulation fan control.
  212. Integer value in the range 0 to 255
  213. RW
  214. 255 is max or 100%.
  215. pwm[1-*]_enable
  216. Fan speed control method:
  217. 0: no fan speed control (i.e. fan at full speed)
  218. 1: manual fan speed control enabled (using pwm[1-*])
  219. 2+: automatic fan speed control enabled
  220. Check individual chip documentation files for automatic mode
  221. details.
  222. RW
  223. pwm[1-*]_mode 0: DC mode (direct current)
  224. 1: PWM mode (pulse-width modulation)
  225. RW
  226. pwm[1-*]_freq Base PWM frequency in Hz.
  227. Only possibly available when pwmN_mode is PWM, but not always
  228. present even then.
  229. RW
  230. pwm[1-*]_auto_channels_temp
  231. Select which temperature channels affect this PWM output in
  232. auto mode. Bitfield, 1 is temp1, 2 is temp2, 4 is temp3 etc...
  233. Which values are possible depend on the chip used.
  234. RW
  235. pwm[1-*]_auto_point[1-*]_pwm
  236. pwm[1-*]_auto_point[1-*]_temp
  237. pwm[1-*]_auto_point[1-*]_temp_hyst
  238. Define the PWM vs temperature curve. Number of trip points is
  239. chip-dependent. Use this for chips which associate trip points
  240. to PWM output channels.
  241. RW
  242. temp[1-*]_auto_point[1-*]_pwm
  243. temp[1-*]_auto_point[1-*]_temp
  244. temp[1-*]_auto_point[1-*]_temp_hyst
  245. Define the PWM vs temperature curve. Number of trip points is
  246. chip-dependent. Use this for chips which associate trip points
  247. to temperature channels.
  248. RW
  249. There is a third case where trip points are associated to both PWM output
  250. channels and temperature channels: the PWM values are associated to PWM
  251. output channels while the temperature values are associated to temperature
  252. channels. In that case, the result is determined by the mapping between
  253. temperature inputs and PWM outputs. When several temperature inputs are
  254. mapped to a given PWM output, this leads to several candidate PWM values.
  255. The actual result is up to the chip, but in general the highest candidate
  256. value (fastest fan speed) wins.
  257. ****************
  258. * Temperatures *
  259. ****************
  260. temp[1-*]_type Sensor type selection.
  261. Integers 1 to 6
  262. RW
  263. 1: CPU embedded diode
  264. 2: 3904 transistor
  265. 3: thermal diode
  266. 4: thermistor
  267. 5: AMD AMDSI
  268. 6: Intel PECI
  269. Not all types are supported by all chips
  270. temp[1-*]_max Temperature max value.
  271. Unit: millidegree Celsius (or millivolt, see below)
  272. RW
  273. temp[1-*]_min Temperature min value.
  274. Unit: millidegree Celsius
  275. RW
  276. temp[1-*]_max_hyst
  277. Temperature hysteresis value for max limit.
  278. Unit: millidegree Celsius
  279. Must be reported as an absolute temperature, NOT a delta
  280. from the max value.
  281. RW
  282. temp[1-*]_min_hyst
  283. Temperature hysteresis value for min limit.
  284. Unit: millidegree Celsius
  285. Must be reported as an absolute temperature, NOT a delta
  286. from the min value.
  287. RW
  288. temp[1-*]_input Temperature input value.
  289. Unit: millidegree Celsius
  290. RO
  291. temp[1-*]_crit Temperature critical max value, typically greater than
  292. corresponding temp_max values.
  293. Unit: millidegree Celsius
  294. RW
  295. temp[1-*]_crit_hyst
  296. Temperature hysteresis value for critical limit.
  297. Unit: millidegree Celsius
  298. Must be reported as an absolute temperature, NOT a delta
  299. from the critical value.
  300. RW
  301. temp[1-*]_emergency
  302. Temperature emergency max value, for chips supporting more than
  303. two upper temperature limits. Must be equal or greater than
  304. corresponding temp_crit values.
  305. Unit: millidegree Celsius
  306. RW
  307. temp[1-*]_emergency_hyst
  308. Temperature hysteresis value for emergency limit.
  309. Unit: millidegree Celsius
  310. Must be reported as an absolute temperature, NOT a delta
  311. from the emergency value.
  312. RW
  313. temp[1-*]_lcrit Temperature critical min value, typically lower than
  314. corresponding temp_min values.
  315. Unit: millidegree Celsius
  316. RW
  317. temp[1-*]_lcrit_hyst
  318. Temperature hysteresis value for critical min limit.
  319. Unit: millidegree Celsius
  320. Must be reported as an absolute temperature, NOT a delta
  321. from the critical min value.
  322. RW
  323. temp[1-*]_offset
  324. Temperature offset which is added to the temperature reading
  325. by the chip.
  326. Unit: millidegree Celsius
  327. Read/Write value.
  328. temp[1-*]_label Suggested temperature channel label.
  329. Text string
  330. Should only be created if the driver has hints about what
  331. this temperature channel is being used for, and user-space
  332. doesn't. In all other cases, the label is provided by
  333. user-space.
  334. RO
  335. temp[1-*]_lowest
  336. Historical minimum temperature
  337. Unit: millidegree Celsius
  338. RO
  339. temp[1-*]_highest
  340. Historical maximum temperature
  341. Unit: millidegree Celsius
  342. RO
  343. temp[1-*]_reset_history
  344. Reset temp_lowest and temp_highest
  345. WO
  346. temp_reset_history
  347. Reset temp_lowest and temp_highest for all sensors
  348. WO
  349. temp[1-*]_enable
  350. Enable or disable the sensors.
  351. When disabled the sensor read will return -ENODATA.
  352. 1: Enable
  353. 0: Disable
  354. RW
  355. Some chips measure temperature using external thermistors and an ADC, and
  356. report the temperature measurement as a voltage. Converting this voltage
  357. back to a temperature (or the other way around for limits) requires
  358. mathematical functions not available in the kernel, so the conversion
  359. must occur in user space. For these chips, all temp* files described
  360. above should contain values expressed in millivolt instead of millidegree
  361. Celsius. In other words, such temperature channels are handled as voltage
  362. channels by the driver.
  363. Also see the Alarms section for status flags associated with temperatures.
  364. ************
  365. * Currents *
  366. ************
  367. curr[1-*]_max Current max value
  368. Unit: milliampere
  369. RW
  370. curr[1-*]_min Current min value.
  371. Unit: milliampere
  372. RW
  373. curr[1-*]_lcrit Current critical low value
  374. Unit: milliampere
  375. RW
  376. curr[1-*]_crit Current critical high value.
  377. Unit: milliampere
  378. RW
  379. curr[1-*]_input Current input value
  380. Unit: milliampere
  381. RO
  382. curr[1-*]_average
  383. Average current use
  384. Unit: milliampere
  385. RO
  386. curr[1-*]_lowest
  387. Historical minimum current
  388. Unit: milliampere
  389. RO
  390. curr[1-*]_highest
  391. Historical maximum current
  392. Unit: milliampere
  393. RO
  394. curr[1-*]_reset_history
  395. Reset currX_lowest and currX_highest
  396. WO
  397. curr_reset_history
  398. Reset currX_lowest and currX_highest for all sensors
  399. WO
  400. curr[1-*]_enable
  401. Enable or disable the sensors.
  402. When disabled the sensor read will return -ENODATA.
  403. 1: Enable
  404. 0: Disable
  405. RW
  406. Also see the Alarms section for status flags associated with currents.
  407. *********
  408. * Power *
  409. *********
  410. power[1-*]_average Average power use
  411. Unit: microWatt
  412. RO
  413. power[1-*]_average_interval Power use averaging interval. A poll
  414. notification is sent to this file if the
  415. hardware changes the averaging interval.
  416. Unit: milliseconds
  417. RW
  418. power[1-*]_average_interval_max Maximum power use averaging interval
  419. Unit: milliseconds
  420. RO
  421. power[1-*]_average_interval_min Minimum power use averaging interval
  422. Unit: milliseconds
  423. RO
  424. power[1-*]_average_highest Historical average maximum power use
  425. Unit: microWatt
  426. RO
  427. power[1-*]_average_lowest Historical average minimum power use
  428. Unit: microWatt
  429. RO
  430. power[1-*]_average_max A poll notification is sent to
  431. power[1-*]_average when power use
  432. rises above this value.
  433. Unit: microWatt
  434. RW
  435. power[1-*]_average_min A poll notification is sent to
  436. power[1-*]_average when power use
  437. sinks below this value.
  438. Unit: microWatt
  439. RW
  440. power[1-*]_input Instantaneous power use
  441. Unit: microWatt
  442. RO
  443. power[1-*]_input_highest Historical maximum power use
  444. Unit: microWatt
  445. RO
  446. power[1-*]_input_lowest Historical minimum power use
  447. Unit: microWatt
  448. RO
  449. power[1-*]_reset_history Reset input_highest, input_lowest,
  450. average_highest and average_lowest.
  451. WO
  452. power[1-*]_accuracy Accuracy of the power meter.
  453. Unit: Percent
  454. RO
  455. power[1-*]_cap If power use rises above this limit, the
  456. system should take action to reduce power use.
  457. A poll notification is sent to this file if the
  458. cap is changed by the hardware. The *_cap
  459. files only appear if the cap is known to be
  460. enforced by hardware.
  461. Unit: microWatt
  462. RW
  463. power[1-*]_cap_hyst Margin of hysteresis built around capping and
  464. notification.
  465. Unit: microWatt
  466. RW
  467. power[1-*]_cap_max Maximum cap that can be set.
  468. Unit: microWatt
  469. RO
  470. power[1-*]_cap_min Minimum cap that can be set.
  471. Unit: microWatt
  472. RO
  473. power[1-*]_max Maximum power.
  474. Unit: microWatt
  475. RW
  476. power[1-*]_crit Critical maximum power.
  477. If power rises to or above this limit, the
  478. system is expected take drastic action to reduce
  479. power consumption, such as a system shutdown or
  480. a forced powerdown of some devices.
  481. Unit: microWatt
  482. RW
  483. power[1-*]_enable Enable or disable the sensors.
  484. When disabled the sensor read will return
  485. -ENODATA.
  486. 1: Enable
  487. 0: Disable
  488. RW
  489. Also see the Alarms section for status flags associated with power readings.
  490. **********
  491. * Energy *
  492. **********
  493. energy[1-*]_input Cumulative energy use
  494. Unit: microJoule
  495. RO
  496. energy[1-*]_enable Enable or disable the sensors.
  497. When disabled the sensor read will return
  498. -ENODATA.
  499. 1: Enable
  500. 0: Disable
  501. RW
  502. ************
  503. * Humidity *
  504. ************
  505. humidity[1-*]_input Humidity
  506. Unit: milli-percent (per cent mille, pcm)
  507. RO
  508. humidity[1-*]_enable Enable or disable the sensors
  509. When disabled the sensor read will return
  510. -ENODATA.
  511. 1: Enable
  512. 0: Disable
  513. RW
  514. **********
  515. * Alarms *
  516. **********
  517. Each channel or limit may have an associated alarm file, containing a
  518. boolean value. 1 means than an alarm condition exists, 0 means no alarm.
  519. Usually a given chip will either use channel-related alarms, or
  520. limit-related alarms, not both. The driver should just reflect the hardware
  521. implementation.
  522. in[0-*]_alarm
  523. curr[1-*]_alarm
  524. power[1-*]_alarm
  525. fan[1-*]_alarm
  526. temp[1-*]_alarm
  527. Channel alarm
  528. 0: no alarm
  529. 1: alarm
  530. RO
  531. OR
  532. in[0-*]_min_alarm
  533. in[0-*]_max_alarm
  534. in[0-*]_lcrit_alarm
  535. in[0-*]_crit_alarm
  536. curr[1-*]_min_alarm
  537. curr[1-*]_max_alarm
  538. curr[1-*]_lcrit_alarm
  539. curr[1-*]_crit_alarm
  540. power[1-*]_cap_alarm
  541. power[1-*]_max_alarm
  542. power[1-*]_crit_alarm
  543. fan[1-*]_min_alarm
  544. fan[1-*]_max_alarm
  545. temp[1-*]_min_alarm
  546. temp[1-*]_max_alarm
  547. temp[1-*]_lcrit_alarm
  548. temp[1-*]_crit_alarm
  549. temp[1-*]_emergency_alarm
  550. Limit alarm
  551. 0: no alarm
  552. 1: alarm
  553. RO
  554. Each input channel may have an associated fault file. This can be used
  555. to notify open diodes, unconnected fans etc. where the hardware
  556. supports it. When this boolean has value 1, the measurement for that
  557. channel should not be trusted.
  558. fan[1-*]_fault
  559. temp[1-*]_fault
  560. Input fault condition
  561. 0: no fault occurred
  562. 1: fault condition
  563. RO
  564. Some chips also offer the possibility to get beeped when an alarm occurs:
  565. beep_enable Master beep enable
  566. 0: no beeps
  567. 1: beeps
  568. RW
  569. in[0-*]_beep
  570. curr[1-*]_beep
  571. fan[1-*]_beep
  572. temp[1-*]_beep
  573. Channel beep
  574. 0: disable
  575. 1: enable
  576. RW
  577. In theory, a chip could provide per-limit beep masking, but no such chip
  578. was seen so far.
  579. Old drivers provided a different, non-standard interface to alarms and
  580. beeps. These interface files are deprecated, but will be kept around
  581. for compatibility reasons:
  582. alarms Alarm bitmask.
  583. RO
  584. Integer representation of one to four bytes.
  585. A '1' bit means an alarm.
  586. Chips should be programmed for 'comparator' mode so that
  587. the alarm will 'come back' after you read the register
  588. if it is still valid.
  589. Generally a direct representation of a chip's internal
  590. alarm registers; there is no standard for the position
  591. of individual bits. For this reason, the use of this
  592. interface file for new drivers is discouraged. Use
  593. individual *_alarm and *_fault files instead.
  594. Bits are defined in kernel/include/sensors.h.
  595. beep_mask Bitmask for beep.
  596. Same format as 'alarms' with the same bit locations,
  597. use discouraged for the same reason. Use individual
  598. *_beep files instead.
  599. RW
  600. ***********************
  601. * Intrusion detection *
  602. ***********************
  603. intrusion[0-*]_alarm
  604. Chassis intrusion detection
  605. 0: OK
  606. 1: intrusion detected
  607. RW
  608. Contrary to regular alarm flags which clear themselves
  609. automatically when read, this one sticks until cleared by
  610. the user. This is done by writing 0 to the file. Writing
  611. other values is unsupported.
  612. intrusion[0-*]_beep
  613. Chassis intrusion beep
  614. 0: disable
  615. 1: enable
  616. RW
  617. sysfs attribute writes interpretation
  618. -------------------------------------
  619. hwmon sysfs attributes always contain numbers, so the first thing to do is to
  620. convert the input to a number, there are 2 ways todo this depending whether
  621. the number can be negative or not:
  622. unsigned long u = simple_strtoul(buf, NULL, 10);
  623. long s = simple_strtol(buf, NULL, 10);
  624. With buf being the buffer with the user input being passed by the kernel.
  625. Notice that we do not use the second argument of strto[u]l, and thus cannot
  626. tell when 0 is returned, if this was really 0 or is caused by invalid input.
  627. This is done deliberately as checking this everywhere would add a lot of
  628. code to the kernel.
  629. Notice that it is important to always store the converted value in an
  630. unsigned long or long, so that no wrap around can happen before any further
  631. checking.
  632. After the input string is converted to an (unsigned) long, the value should be
  633. checked if its acceptable. Be careful with further conversions on the value
  634. before checking it for validity, as these conversions could still cause a wrap
  635. around before the check. For example do not multiply the result, and only
  636. add/subtract if it has been divided before the add/subtract.
  637. What to do if a value is found to be invalid, depends on the type of the
  638. sysfs attribute that is being set. If it is a continuous setting like a
  639. tempX_max or inX_max attribute, then the value should be clamped to its
  640. limits using clamp_val(value, min_limit, max_limit). If it is not continuous
  641. like for example a tempX_type, then when an invalid value is written,
  642. -EINVAL should be returned.
  643. Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees):
  644. long v = simple_strtol(buf, NULL, 10) / 1000;
  645. v = clamp_val(v, -128, 127);
  646. /* write v to register */
  647. Example2, fan divider setting, valid values 2, 4 and 8:
  648. unsigned long v = simple_strtoul(buf, NULL, 10);
  649. switch (v) {
  650. case 2: v = 1; break;
  651. case 4: v = 2; break;
  652. case 8: v = 3; break;
  653. default:
  654. return -EINVAL;
  655. }
  656. /* write v to register */