gpio-v2-lineinfo-changed-read.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. _GPIO_V2_LINEINFO_CHANGED_READ:
  3. *****************************
  4. GPIO_V2_LINEINFO_CHANGED_READ
  5. *****************************
  6. Name
  7. ====
  8. GPIO_V2_LINEINFO_CHANGED_READ - Read line info changed events for watched
  9. lines from the chip.
  10. Synopsis
  11. ========
  12. ``int read(int chip_fd, void *buf, size_t count)``
  13. Arguments
  14. =========
  15. ``chip_fd``
  16. The file descriptor of the GPIO character device returned by `open()`.
  17. ``buf``
  18. The buffer to contain the :c:type:`events<gpio_v2_line_info_changed>`.
  19. ``count``
  20. The number of bytes available in ``buf``, which must be at least the size
  21. of a :c:type:`gpio_v2_line_info_changed` event.
  22. Description
  23. ===========
  24. Read line info changed events for watched lines from the chip.
  25. .. note::
  26. Monitoring line info changes is not generally required, and would typically
  27. only be performed by a system monitoring component.
  28. These events relate to changes in a line's request state or configuration,
  29. not its value. Use gpio-v2-line-event-read.rst to receive events when a
  30. line changes value.
  31. A line must be watched using gpio-v2-get-lineinfo-watch-ioctl.rst to generate
  32. info changed events. Subsequently, a request, release, or reconfiguration
  33. of the line will generate an info changed event.
  34. The kernel timestamps events when they occur and stores them in a buffer
  35. from where they can be read by userspace at its convenience using `read()`.
  36. The size of the kernel event buffer is fixed at 32 events per ``chip_fd``.
  37. The buffer may overflow if bursts of events occur quicker than they are read
  38. by userspace. If an overflow occurs then the most recent event is discarded.
  39. Overflow cannot be detected from userspace.
  40. Events read from the buffer are always in the same order that they were
  41. detected by the kernel, including when multiple lines are being monitored by
  42. the one ``chip_fd``.
  43. To minimize the number of calls required to copy events from the kernel to
  44. userspace, `read()` supports copying multiple events. The number of events
  45. copied is the lower of the number available in the kernel buffer and the
  46. number that will fit in the userspace buffer (``buf``).
  47. A `read()` will block if no event is available and the ``chip_fd`` has not
  48. been set **O_NONBLOCK**.
  49. The presence of an event can be tested for by checking that the ``chip_fd`` is
  50. readable using `poll()` or an equivalent.
  51. Return Value
  52. ============
  53. On success the number of bytes read, which will be a multiple of the size
  54. of a :c:type:`gpio_v2_line_info_changed` event.
  55. On error -1 and the ``errno`` variable is set appropriately.
  56. Common error codes are described in error-codes.rst.